Esempio n. 1
0
    void Update()
    {
        if (isManualModeOn)
        {
            return;
        }
        if (minion.CurrentTarget != null && minion.CurrentTarget.IsDead)
        {
            minion.SetTarget(null);
        }

        switch (currentState)
        {
        case MinionAIState.move:
            OnStateMove();
            break;

        case MinionAIState.attack:
            OnStateAttack();
            break;

        case MinionAIState.idle:
            OnStateIdle();
            break;

        default:
            currentState = MinionAIState.idle;
            break;
        }
    }
Esempio n. 2
0
 void Start()
 {
     minion = GetComponent <Minion>();
     if (minion == null)
     {
         throw new Exception("gameObject must contain Unit component");
     }
     minion.OnDestinationReached  += OnDestinationReached;
     minion.OnForceDestinationSet += OnForceDestinationSet;
     minion.OnTargetUpdated       += OnTargetUpdated;
     currentState = MinionAIState.idle;
 }
Esempio n. 3
0
        public override void Update()
        {
            if (m_Players.Count == 0 || m_Players.Count < Server.ServerManager.instance.NumClients())
            {
                m_Players = GameSimulation.instance.GetPlayers();
            }

            if (m_Players.Count == 0)
            {
                return;
            }

            m_AnimTick += DT;

            if (m_PickedTarget == 0)
            {
                // Get Random target
                m_PlayerTargetIndex = GameSimulation.RandomRange(0, m_Players.Count);
                m_PickedTarget      = 1;
            }

            // Get distance of closest player
            Vector2 player_centre = m_Players[m_PlayerTargetIndex].Position;
            Vector2 my_centre     = this.Position;

            if (player_centre.X < my_centre.X)
            {
                m_Facing = Facing.Left;
            }
            else
            {
                m_Facing = Facing.Right;
            }

            if (m_Facing == Facing.Left)
            {
                frameY = 0.0f;
            }
            else
            {
                frameY = 2.0f;
            }

            if (m_AnimTick >= k_MillisPerFrame)
            {
                ++frameX;

                if (frameX >= m_NumFramesX)
                {
                    frameX = 0;
                }

                m_AnimTick = 0.0f;
            }

            float dist = Vector2.Distance(my_centre, player_centre);

            // Dash Attack the player
            switch (m_AIState)
            {
            case MinionAIState.Idle:
            {
                if (m_FoundTarget == 0)
                {
                    this.Velocity = new Vector2(0.0f, 0.0f);

                    if (dist < k_MoveToPlayerDist)
                    {
                        m_FoundTarget = 1;
                        m_Direction   = Vector2.Normalize(player_centre - my_centre);
                    }
                }
                else
                {
                    this.Velocity      = m_Direction * 3.0f;
                    m_AttackWaitCount += DT;
                }

                if (m_AttackWaitCount > ATTK_COUNT)
                {
                    m_AttackWaitCount = 0.0f;
                    m_AIState         = MinionAIState.Charge;
                    m_FoundTarget     = 0;
                }
                break;
            }

            case MinionAIState.Charge:
            {
                if (dist < k_MinChargeDistance)
                {
                    if ((player_centre.Y > this.Position.Y) && (player_centre.Y < this.Position.Y))
                    {
                        this.Velocity.X = 10.0f * (float)m_Facing;
                        m_AIState       = MinionAIState.Dash;
                        break;
                    }
                }

                // Give up and try and get nearer
                m_AttackWaitCount += DT;
                if (m_AttackWaitCount > ATTK_COUNT)
                {
                    m_AttackWaitCount = 0.0f;
                    m_AIState         = MinionAIState.Idle;
                }

                break;
            }

            case MinionAIState.Dash:
            {
                float m_friction = 0.2f;

                // Apply friction
                if (this.Velocity.X < 0)
                {
                    this.Velocity.X += m_friction;
                }
                if (this.Velocity.X > 0)
                {
                    this.Velocity.X -= m_friction;
                }

                // Set to Zero when speed is low enough
                if (this.Velocity.X > 0 && this.Velocity.X < m_friction)
                {
                    this.Velocity.X = 0;
                    m_AIState       = MinionAIState.Idle;
                }
                if (this.Velocity.X < 0 && this.Velocity.X > -m_friction)
                {
                    this.Velocity.X = 0;
                    m_AIState       = MinionAIState.Idle;
                    m_PickedTarget  = 0;
                }
                break;
            }
            }

            this.Position += this.Velocity;
        }
Esempio n. 4
0
 private void SwitchState(MinionAIState state)
 {
     currentState = state;
 }