Example #1
0
    public override void Enter(ActorController entityType)
    {
        StringBuilder animName = new StringBuilder(entityType.MyActor.RaceType + "_");

        animName.Append(entityType.MyActor.ActorType);
        animName.Append("_Walk_");
        animName.Append(entityType.MyActor.FactionType);
        entityType.SelfAnimator.Play(animName.ToString());

        List <GameObject> enemies = entityType.SeekAndGetEnemies();

        if (enemies == null || enemies.Count == 0)
        {
            enemies = entityType.SeekAndGetEnemyBuildings();
            if (enemies == null || enemies.Count == 0)
            {
                entityType.GetFSM().ChangeState(Actor_StateWalk.Instance());
            }
            else
            {
                if (enemies[0] != null)
                {
                    entityType.TargetEnemy = enemies[0].GetComponent <BuildingController>();
                }
            }
        }
        else
        {
            if (enemies[0] != null)
            {
                entityType.TargetEnemy = enemies[0].GetComponent <ActorController>();
            }
        }
    }
Example #2
0
    public override void Execute(ActorController entityType)
    {
        if (entityType.IsStun || entityType.IsCaught)
        {
            return;
        }

        if (entityType.TargetEnemy == null)
        {
            entityType.GetFSM().ChangeState(Actor_StateWalk.Instance());
            return;
        }

        Vector3 moveDistance = entityType.moveSpeed * Time.deltaTime
                               * (entityType.TargetEnemy.transform.position - entityType.myTransform.position)
                               .normalized;

        entityType.myTransform.Translate(moveDistance, Space.World);

        if ((entityType.TargetEnemy.transform.position - entityType.myTransform.position).sqrMagnitude
            <= Mathf.Max(Mathf.Pow(entityType.MyActor.ActorAttack.AttackRange, 2), Mathf.Pow(30, 2)))
        {
            entityType.GetFSM().ChangeState(Actor_StateFight.Instance());
        }
    }
Example #3
0
    private void InitActor()
    {
        if (this._myActor == null)
        {
            Debug.LogError("Actor cannot be null !");
        }

        this.myTransform = this.gameObject.transform;
        this.ResetMoveSpeed();
        this.AttackPlusRatio   = 1;
        this.BloodSuckingRatio = 0;
        this.ResetAttackInterval();
        this.hpbarLength = 200;
        this.RefreshHpBar();
        this.SwitchAnimation();

        this.m_PStateMachine = new StateMachine <ActorController>(this);
        this.m_PStateMachine.SetCurrentState(Actor_StateWalk.Instance());
        this.m_PStateMachine.SetGlobalState(Actor_GlobalState.Instance());
    }