Esempio n. 1
0
 // start state and initialize some active AI State Data
 public virtual void Execute()
 {
     if (ParentState != null)
     {
         ParentState.Execute();
     }
 }
Esempio n. 2
0
        public void GetHashCode_should_be_the_state_hashcode()
        {
            var id    = ParentEntityId.Generate();
            var state = new ParentState().Apply(new ParentCreated(id, "test parent", DateTime.UtcNow));

            var parent = new ParentEntity(Enumerable.Empty <IEvent>(), state);

            parent.GetHashCode().Should().Be(parent.StateModel.GetHashCode());
        }
Esempio n. 3
0
        public void Entity_updates_StateModel_by_inital_state()
        {
            var id    = ParentEntityId.Generate();
            var state = new ParentState().Apply(new ParentCreated(id, "test parent", DateTime.UtcNow));

            var parent = new ParentEntity(Enumerable.Empty <IEvent>(), state);

            parent.StateModel.Id.Should().Be(id);
            parent.StateModel.Name.Should().Be("test parent");
        }
Esempio n. 4
0
        /*
         * /// <summary>
         * ///some ideas, implement if actualy needed
         * /// </summary>
         * public BaseDataBlob ThisRelatedDatablob;
         *
         * public InstancesDB ThisEntitesInstancesDB;
         *
         * (call this from Set Parent, virtual would be empty, inherited classes would have something below eg)
         * protected virtual void FilterParents(ComponentTreeHeirarchyAbilityState parentToSet)
         * {
         *  Type T = typeof(FireControlAbilityState)
         *  if(parentToSet is T)
         *  {
         *      if (ParentState != null)
         *      {
         *          ParentState.ChildrenStates.Remove(this);
         *      }
         *
         *      ParentState = newParent;
         *      if(newParent != null)
         *          ParentState.ChildrenStates.Add(this);
         *  }
         *  else
         *      throw exception? fail silently? log?
         * }
         *
         * protected virtual void FilterChildren(ComponentTreeHeirarchyAbilityState childToAdd)
         * {
         *  if(childToAdd is T)
         *      ChildrenState.Add(childToAdd);
         *  else
         *      throw exception? fail silently? log?
         * }
         *
         *
         *      /// <summary>
         * /// If parent is null, will return an empty list
         * /// </summary>
         * /// <typeparam name="T"></typeparam>
         * /// <returns></returns>
         * public List<T> GetSiblingsOfType<T>()
         *  where T : ComponentTreeHeirarchyAbilityState
         * {
         *  if(ParentState == null)
         *      return new List<T>();
         *  return ParentState.GetChildrenOfType<T>();
         * }
         *
         *
         * public List<T> GetChildrenOfType<T>() where T: ComponentTreeHeirarchyAbilityState
         * {
         *  List<T> children = new List<T>();
         *  foreach (var child in ChildrenStates)
         *  {
         *      if(child is T)
         *          children.Add((T)child);
         *  }
         *  return children;
         * }
         *
         * public ComponentInstance[] GetChildrenInstancesOfType<T>() where T: ComponentTreeHeirarchyAbilityState
         * {
         *  var childrenStates = GetChildrenOfType<T>();
         *  ComponentInstance[] instances = new ComponentInstance[childrenStates.Count];
         *  for (int i = 0; i < childrenStates.Count; i++)
         *  {
         *      instances[i] = childrenStates[i].ComponentInstance;
         *  }
         *  return instances;
         * }
         *
         */

        public ComponentTreeHeirarchyAbilityState GetRoot()
        {
            if (ParentState != null)
            {
                return(ParentState.GetRoot());
            }
            else
            {
                return(this);
            }
        }
 // check if a given state is on this state's active path
 public bool StateOnPath(GameState state)
 {
     if (this == state)
     {
         return(true);
     }
     if (ParentState == null)
     {
         return(false);
     }
     return(ParentState.StateOnPath(state));
 }
Esempio n. 6
0
 // check if given state is on this state's path
 public bool IsOnMyPath(AIState state)
 {
     if (ParentState == null)
     {
         return(false);
     }
     if (ParentState == state)
     {
         return(true);
     }
     return(ParentState.IsOnMyPath(state));
 }
 // attempt to enter this state
 public virtual void Enter()
 {
     // CustomLogger.Log(this.name, $"Entering game state {StateId}");
     IsLoading = true;
     // enter parent state first, if necessary
     if (ParentState != null && !ParentState.IsActive)
     {
         ParentState.OnGameStateEnter += OnParentStateEntered;
         ParentState.Enter();
         return;
     }
     OnReadyToEnter();
 }
 // initialize StateId and Parent's StateId
 public void InitializeId()
 {
     if (_initialized)
     {
         return;
     }
     StateId = name;
     if (ParentState != null)
     {
         ParentState.InitializeId();
         StateId = $"{ParentState.StateId}/{StateId}";
     }
     _initialized = true;
 }
 // attempt to exit this state
 public virtual void Exit(GameState nextState)
 {
     // check to see if we actually need to exit
     if (nextState.StateOnPath(this))
     {
         return;
     }
     // have the parent exit as well if necessary
     if (ParentState != null)
     {
         ParentState.Exit(nextState);
     }
     ConfirmExitState();
 }
Esempio n. 10
0
 // enter state behaviour
 public virtual void Enter(AIStateInitializationData initData = null)
 {
     // if has parent and parent is not active, enter parent state
     if (_active)
     {
         return;
     }
     if (ParentState != null)
     {
         ParentState.OnReadyToTransitionState += SetReadyToTransition;
         ParentState.Enter(initData);
     }
     OnEnter();
 }
Esempio n. 11
0
 // exit state behaviour
 public virtual void Exit(AIState nextState)
 {
     // if this state is on the next state's path, ignore
     if (nextState?.IsOnMyPath(this) ?? false)
     {
         return;
     }
     // Exit the parent state, if available
     if (ParentState != null)
     {
         ParentState.Exit(nextState);
         ParentState.OnReadyToTransitionState -= SetReadyToTransition;
     }
     OnExit();
 }
Esempio n. 12
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.CompareTag("Ammunition"))
        {
            state = other.gameObject.GetComponent <Ammunition>().isAlcohol ? ParentState.Drinking : ParentState.Angry;
        }

        if (other.gameObject.CompareTag("Wall"))
        {
            if (state == ParentState.Walking)
            {
                _walkDirection = -_walkDirection;
            }
        }
    }
 // get a game state using a given transition id
 public GameState GetGameStateByTransitionName(string transitionName)
 {
     for (int i = 0; i < _transitions.Count; i++)
     {
         if (transitionName.Equals(_transitions[i].TransitionName))
         {
             return(_transitions[i].GameState);
         }
     }
     if (ParentState != null)
     {
         return(ParentState.GetGameStateByTransitionName(transitionName));
     }
     return(null);
 }
Esempio n. 14
0
        public void Equals_should_call_equals_of_state()
        {
            var id    = ParentEntityId.Generate();
            var state = new ParentState().Apply(new ParentCreated(id, "test parent", DateTime.UtcNow));

            var parent = new ParentEntity(Enumerable.Empty <IEvent>(), state);

            parent.Equals(parent.StateModel).Should().Be(true);

            var state2  = new ParentState().Apply(new ParentCreated(id, "test parent", DateTime.UtcNow));
            var parent2 = new ParentEntity(Enumerable.Empty <IEvent>(), state2);

            parent.Equals(parent2).Should().Be(true);

            parent.Equals(null).Should().Be(false);
        }
Esempio n. 15
0
        protected override void OnDraw(IRenderArgs args)
        {
            if (_skyBox != null)
            {
                if (!_skyBox.Loaded)
                {
                    _skyBox.Load(Alex.GuiRenderer);
                }

                _skyBox.Draw(args);
            }

            if (Alex.InGame)
            {
                ParentState.Draw(args);
            }

            base.OnDraw(args);
        }
Esempio n. 16
0
 /// <inheritdoc />
 protected override void OnUpdate(GameTime gameTime)
 {
     base.OnUpdate(gameTime);
     ParentState?.Update(gameTime);
 }
Esempio n. 17
0
 protected override void OnDraw(IRenderArgs args)
 {
     ParentState.Draw(args);
 }