Beispiel #1
0
        public override void OnAttach(Entity owner)
        {
            base.OnAttach(owner);

            thinkerState = new ThinkState();

            owner.AddEventResponse(typeof(ENewTurn), Event_NewTurn);
            owner.AddEventResponse(typeof(EDied), Event_OnDeath);
        }
Beispiel #2
0
 internal void SetState(ThinkState st)
 {
     mState = st;
 }
Beispiel #3
0
        //Decide action based on current state
        protected FighterState GetCurrentAction(ThinkState thinkState)
        {
            // Report Current  Think State
            //print(thinkState.ToString());

            // Wants to attack
            if (thinkState == ThinkState.Attack)
            {
                Vector2 targetDistance = currentTarget.position - transform.position;

                // Debug print print(fighterScript.attackRange.ToString() + "/" + (currentTarget.position - transform.position).magnitude.ToString());
                //if AI is far from Player
                if (fighterScript.GetAttackRange() - (attackThreshold) <= targetDistance.magnitude)
                {
                    if (targetDistance.x > 0)
                    {
                        return(FighterState.WalkRight);
                    }

                    else
                    {
                        return(FighterState.WalkLeft);
                    }
                }

                else
                {
                    return(FighterState.Attacking);
                }
            }

            else if (thinkState == ThinkState.Escape)
            {
                Vector2 targetDistance = currentTarget.position - transform.position;

                // Try to Escape
                if (targetDistance.x < 0)
                {
                    return(FighterState.WalkRight);
                }

                else
                {
                    return(FighterState.WalkLeft);
                }
            }

            else if (thinkState == ThinkState.Defensive)
            {
                Vector2 targetDistance = currentTarget.position - transform.position;

                // If close
                if (fighterScript.GetAttackRange() - (attackThreshold) > targetDistance.magnitude)
                {
                    return(FighterState.Blocking);
                }

                return(FighterState.Idle);
            }

            else if (thinkState == ThinkState.Evasive)
            {
                Vector2 targetDistance = currentTarget.position - transform.position;

                // If close
                if (fighterScript.GetAttackRange() - (attackThreshold) > targetDistance.magnitude)
                {
                    return(FighterState.Crouching);
                }

                return(FighterState.Idle);
            }

            // If nothing else, then satd put
            return(FighterState.Idle);
        }
Beispiel #4
0
        // Update is called once per frame
        protected override void Update()
        {
            // if fighter last action is diferent, than Update
            if (fighterScript.currentState != lastState)
            {
                lastState = fighterScript.currentState;
            }

            // Check conditions if it can receive Input
            if (!CanReceiveInput())
            {
                return;
            }


            // Check if it is about to performang a action
            if (isInDelayTime)
            {
                // After Delay Time -> Act New action + End Delay
                if (timeSinceDelay > thinkDelay)
                {
                    ProcessAction(nextState);
                    lastState = nextState;
                    ResetDelayTime();
                }

                // Add to Delay time + Perform previus Action
                else
                {
                    timeSinceDelay += Time.deltaTime;
                    ProcessAction(lastState);
                }
            }


            // Check for possible new actions -> Check new States
            else
            {
                // Think AI state
                currentThinkState = GetCurrentThink();

                // Controler Action
                FighterState newAction = GetCurrentAction(currentThinkState);

                //If new action -> Start Delay
                if (newAction != lastState)
                {
                    nextState = newAction;
                    ProcessAction(lastState);

                    // Random Delay Time
                    SetNewDelayTime();
                }

                //Repeat last Action
                else
                {
                    ProcessAction(lastState);
                }
            }
        }