Пример #1
0
    public void ExecuteRoute()
    {
        SoundManager.Instance.Play("ExecuteRoute");
        SwarmManager.Instance.m_CurrentRoute = m_CurrentRoute;

        m_CurrentRoute.Execute();
        Tribe.Instance.Travel(m_CurrentRoute);
        m_CurrentHub = null;

        m_ConsumptionTimer.Reset(m_TravelFoodConsumptionTime);
        m_SelectedRoutePresentation = null;
    }
Пример #2
0
    //////////////////////////////////////////////////////////////////////////
    private void FixedUpdate()
    {
        if (m_Expiered)
        {
            return;
        }

        if (m_Timer.AddTime(Time.deltaTime))
        {
            m_Expired.Invoke();
            if (m_Loop)
            {
                m_Timer.Reset();
            }
            else
            {
                m_Expiered = true;
            }
        }
    }
Пример #3
0
    private void FixedUpdate()
    {
        if (m_State != CharacterState.Fight)            // issue of non state machine implementation
        {
            m_Animator.SetBool("Hit", false);
        }

        // rude state machine implementation
        switch (m_State)
        {
        case CharacterState.Fight:
        {
            // find closest enemy, get close, make hit
            m_AttackTarget = implIsNative()
                                        ? PlayerManager.Instance.GetClosestUnit(transform.position, Tribe.Instance.m_CharacterList)
                                        : PlayerManager.Instance.GetClosestUnit(transform.position, m_CurrentHub.m_HubDefenderList);

            if (m_AttackTarget == null)
            {
                m_State = CharacterState.Idle;
                return;
            }

            if (m_AttackTarget.m_CurrentHub != m_CurrentHub)
            {
                m_AttackTarget = null;
                return;
            }


            iTargertPosition = m_AttackTarget.transform.position;
            implGoToTarget(m_FightSpeed);

            m_Animator.SetBool("Hit", m_DistanceToTarget <= 0.35f);

            var toTargetNormal = (iTargertPosition - iGetCurrentPosition()).normalized;
            if (implIsStay(0.1f))                       // make delayed call, for fair fight
            {
                Instantiate(m_HitEffect).transform.position = transform.position;


                SoundManager.Instance.Play("Hit");
                m_AttackTarget.TakeDamage(m_HitDamage, toTargetNormal);
                if (m_AttackTarget.m_AttackTarget == this)
                {
                    ;
                }
                TakeDamage(m_AttackTarget.m_HitDamage, -toTargetNormal);
            }
        }
        break;

        case CharacterState.Loot:
        {
            // follow to position and interract
            if (m_LootTarget == null)
            {
                Idle();
                return;
            }

            iTargertPosition = m_LootTarget.transform.position;

            if (implIsStay(0.05f))
            {
                m_LootTarget.Use(this);
                m_LootTarget = m_CurrentHub.GetClosestLoot(transform.position, m_CurrentHub.m_ValidLootList);
            }
            else
            {
                implGoToTarget(m_LootSpeed);
            }
        }
        break;

        case CharacterState.Idle:
        {
            // wander

            // wait random, time, or move to random position
            if (implIsStay(0.05f))
            {
                m_WanderTimer.AddTime(Time.fixedDeltaTime);

                if (m_WanderTimer.Expired)
                {
                    m_WanderTimer.Reset(UnityEngine.Random.Range(m_WanderTimerRange.x, m_WanderTimerRange.y));
                    iTargertPosition = m_CurrentHub.RandomHubPos();
                }
            }
            else
            {
                implGoToTarget(m_WanderSpeed);
            }
        }
        break;

        case CharacterState.Travel:
        {
            // follow to the target
            implGoToTarget(m_TravelSpeed);
        }
        break;
        }

        // dirty orientation update
        foreach (var n in m_SpriteList)
        {
            n.flipX = m_VectorToTarget.x < 0.0f;
        }
    }