Example #1
0
        ///// <summary>
        ///// 在子类中运行的方法
        ///// </summary>
        //public void RunMethodInChildren() {
        //	_FloCurHp = IntMaxHP;

        //	////判断是否存活
        //	//StartCoroutine("CheckLifeContinue");
        //}



        /// <summary>
        /// 伤害处理
        /// </summary>
        /// <param name="heroAtk"></param>
        public void OnHurt(int heroAtk)
        {
            _CurrentState = EnemyActionState.Hurt;

            //Debug.Log("进行伤害处理!");
            int hurtValue;

            if (heroAtk > IntDEF)
            {
                hurtValue = heroAtk - IntDEF;
            }
            else
            {
                hurtValue = 1;
            }

            if (_FloCurHp - hurtValue > 0)
            {
                _FloCurHp -= hurtValue;
            }
            else
            {
                _FloCurHp = 0;
            }
            //Debug.Log("当前HP:" + _FloCurHp);
        }
Example #2
0
 /// <summary>
 /// 公共方法:伤害处理
 /// </summary>
 /// <param name="damage">伤害</param>
 public void OnHurt(float damage)
 {
     //设置当前动画状态
     _CurrentState = EnemyActionState.Hurt;
     //处理敌人的生命值
     SubCurHP(damage);
 }
 void Awake()
 {
     enemyStateMachine = GetComponent <EnemyStateMachine> ();
     navMeshController = GetComponent <NavMeshController> ();
     visionController  = GetComponent <VisionController> ();
     enemyActionState  = GetComponent <EnemyActionState> ();
 }
Example #4
0
 public void CheckPlayer()
 {
     if (Vector3.Distance(GameDirector.instance.player.transform.position, gameObject.transform.position) <= sightRange)
     {
         actionState = EnemyActionState.ChaseAndAttack;
         ChaseAndAttackPlayer();
     }
 }
Example #5
0
 //Updates if the hero is dead and returns if it is
 public override bool IsDead()
 {
     if (enemy.currHP <= 0f)
     {
         currState = EnemyActionState.DEAD;
         return(true);
     }
     return(currState == EnemyActionState.DEAD);
 }
Example #6
0
        /// <summary>
        /// 回收对象(敌人)
        /// </summary>
        /// <returns></returns>
        IEnumerator Recover()
        {
            yield return(new WaitForSeconds(5f));

            //敌人回收前的状态重置
            _FloCurHp     = IntMaxHP;
            _CurrentState = EnemyActionState.Idle;
            //回收对象
            PoolManager.PoolsArray["_"].RecoverGameObject(this.gameObject);
        }
Example #7
0
 IEnumerator WaitWalkingOutsideSpawnZone()
 {
     while (!NavEntity.ReachedDestination)
     {
         yield return(null);
     }
     ActionState  = EnemyActionState.Following;
     Spawned      = true;
     CanDamage    = true;
     CanBeDamaged = true;
 }
Example #8
0
 public void AfterAttack()
 {
     if (GameDirector.instance.player.unitState != UnitState.Dead)
     {
         ChaseAndAttackPlayer();
     }
     else
     {
         actionState = EnemyActionState.Idle;
     }
 }
Example #9
0
        //private static Texture2D[] textureArray;
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="Velocity"></param>
        /// <param name="tex"></param>
        /// <param name="Shape"></param>
        public Enemy(Rectangle rect, Texture2D tex, string name, ObjectShape Shape)
            : base(rect, tex, Shape)
        {
            shoots = false;

            projectileTexture = null;
            EnemyName = name;
            state = LifeState.Alive;
            actionState = EnemyActionState.Standing;
            RunTextures = new List<Texture2D>();
            AttackTextures = new List<Texture2D>();
        }
Example #10
0
 protected virtual void Die()
 {
     NavEntity.DisableMoving();
     ActionState  = EnemyActionState.Dead;
     CanBeDamaged = false;
     CanDamage    = false;
     IsDead       = true;
     _animator.SetInteger("state", (int)AnimationStates.Dead);
     Invoke("RecoverFromDeathAnimation", GameController.Instance.DEATH_ANIMATION_INTERVAL);
     GameEvents.Instance.OnEnemyDead(new GameEvents.OnEnemyDeadEventArgs {
         EnemyType = EnemyType
     });
 }
Example #11
0
        public override void Initialize(int x, int y)
        {
            base.Initialize(x, y);

            ActionState  = EnemyActionState.Waiting;
            Life         = GameController.Instance.SMALL_LIFE;
            IsDead       = false;
            CanBeDamaged = false;
            CanDamage    = false;
            _animator.SetInteger("state", (int)AnimationStates.Idle);
            NavEntity.SetSpeed(GameController.Instance.ENEMY_SLOW_SPEED);
            NavEntity.DisableMoving();
            CancelInvoke();
        }
Example #12
0
    public void ChooseAction()
    {
        ActionHandler myAction = new ActionHandler()
        {
            actionID        = enemy.actionOptions[Random.Range(0, enemy.actionOptions.Count)],//Decides random action
            actorName       = enemy.name,
            actorGameObject = this.gameObject,
            stateMachine    = this,
            unitType        = ActionHandler.UnitType.ENEMY,
            actionTarget    = battleManager.heroList[Random.Range(0, battleManager.heroList.Count)]
        };//initializes random targets and attack

        battleManager.actionQueue.Add(myAction);
        //Debug.Log("Enemy action added to actionqueue");
        currState = EnemyActionState.WAITING;
    }
Example #13
0
        protected virtual void OnPowerActiveUpListener(object sender, GameEvents.PowerUpActiveEventArgs args)
        {
            if (IsDead)
            {
                return;
            }

            if (args.PowerUpStatus)
            {
                CanDamage   = false;
                ActionState = EnemyActionState.Fleeing;
            }
            else
            {
                CanDamage   = true;
                ActionState = EnemyActionState.Following;
            }
        }
Example #14
0
        /*
         *
         * public void AddCurHP(float addValue) {}
         * public void GetCurHP() { }
         * public void AddMaxHP(float addValue) { }
         * public void GetMaxHP() { }
         *
         * public void UpdateATK(float atkByItem) { }
         * public void AddATK(float addValue) { }
         * public void SubATK(float aubValue) {}
         * public void GetATK() { }
         * public void UpdateDEF(float defByItem) { }
         * public void AddDEF(float addValue) { }
         * public void SubDEF(float subValue) { }
         * public void GetDEF() { }
         *
         * public void AddEnemyEXP(int addValue) { }
         * public void SubEnemyEXP(int subValue) { }
         * public void AddEnemyGold(int addValue) { }
         * public void SubEnemyGold(int subValue) { }
         *
         */



        #endregion



        #region 【私有协程】

        /// <summary>
        /// 协程:检查敌人是否存活
        /// </summary>
        /// <returns></returns>
        IEnumerator CheckLifeContinue()
        {
            while (true)
            {
                //如果生命值已经为0
                if (CurHP == 0)
                {
                    if (_CurrentState != EnemyActionState.Dead)
                    {
                        //设置为死亡状态
                        _CurrentState = EnemyActionState.Dead;
                        //玩家得到各种奖励(获得经验值、金钱,增加杀敌量等)
                        DeathReward();
                        //开始协程:回收对象
                        StartCoroutine(RecoverGO());
                    }
                }
                yield return(new WaitForSeconds(CON_RecheckTime));
            }
        }
Example #15
0
        public Enemy(Rectangle rect, int type, ObjectShape Shape, int vr, int projectileNum)
            : base(rect, null, Shape)
        {
            myType = (EnemyType) type;
            visionrange = vr;
            state = LifeState.Alive;
            actionState = EnemyActionState.Standing;

            if (vr == 0)
            {
                shoots = false;
                projectileTexture = null;
                projectiles = null;
            }
            else
            {
                shoots = true;
                projectileTexture = ProjectileTextures[0];
                projectiles = new List<Projectile>();
            }
        }
Example #16
0
        /// <summary>
        /// 检查是否存活
        /// </summary>
        /// <returns></returns>
        IEnumerator CheckLifeContinue()
        {
            //协程需要重复执行
            while (true)
            {
                //这里需要加以改动
                if (_FloCurHp <= 0)
                {
                    if (_CurrentState != EnemyActionState.Dead)
                    {
                        _CurrentState = EnemyActionState.Dead;

                        Ctrl_HeroProperty.Instance.AddEXP(IntEnemyEXP);                     //玩家获得经验值
                        Ctrl_HeroProperty.Instance.AddKillNum();                            //增加玩家的杀敌数量

                        //Destroy(this.gameObject, 5f);   //销毁对象(敌人死亡),5s的延迟
                        StartCoroutine("Recover");                              //回收对象(作为代替)
                    }
                }
                yield return(new WaitForSeconds(GlobalParameter.CHECK_TIME));                   //每0.02s判断一次
            }
        }
Example #17
0
        /// <summary>
        /// Move the enemy
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(int timeElapsed, Player n)
        {
            if (patrol != null)
                velocity = patrol.getCurrentVector(timeElapsed);

            Point c = GetCenter();

            if(shoots){
                if(facingLeft){
                    if (new Rectangle(c.X - visionrange, c.Y, visionrange, 1).Intersects(n.DrawFrame())){
                        projectiles.Add(new Projectile(c, new Vector2(-6, new Random().Next(-3, 3)), projectileTexture));
                    }
                }

               else{
                   if (new Rectangle(c.X, c.Y, visionrange, 1).Intersects(n.DrawFrame()))
                   {
                       projectiles.Add(new Projectile(c, new Vector2(6, new Random().Next(-3, 3)), projectileTexture));
                   }
                }

                List<Projectile> hitlist = new List<Projectile>();

                foreach (Projectile p in projectiles)
                {
                    p.Update();
                    if (p.lifespan < 0)
                        hitlist.Add(p);
                    else if (p.DrawFrame().Intersects(n.DrawFrame()))
                        n.death();
                }
                foreach (Projectile p in hitlist)
                    projectiles.Remove(p);
            }

            if (velocity.X == 0)
            {
                actionState = EnemyActionState.Standing;
            }
            else
            {
                actionState = EnemyActionState.Running;
                facingLeft = velocity.X < 0;
            }

            switch (actionState)
            {
                case EnemyActionState.Standing:

                    break;
                case EnemyActionState.Running:
                    running.Update(timeElapsed);
                    break;
                case EnemyActionState.Attacking:
                    attacking.Update(timeElapsed);
                    break;
                case EnemyActionState.Dying:

                    break;
            }

            base.Update(timeElapsed);
        }
Example #18
0
 public Enemy(Rectangle rect, Texture2D tex, string name, ObjectShape Shape, int vr)
     : base(rect, tex, Shape)
 {
     shoots = true;
     visionrange = vr;
     projectiles = new List<Projectile>();
     EnemyName = name;
     state = LifeState.Alive;
     actionState = EnemyActionState.Standing;
     RunTextures = new List<Texture2D>();
     AttackTextures = new List<Texture2D>();
 }
Example #19
0
 /// <summary>
 /// 私有方法:初始化或重置敌人的状态
 /// </summary>
 private void InitStatus()
 {
     _CurrentState = EnemyActionState.Idle;
     CurHP         = MaxHP;
 }
Example #20
0
 void Start()
 {
     battleManager = BattleManager.instance;
     currState     = EnemyActionState.WAITING;
 }
Example #21
0
 /// <summary>
 /// Kills the enemy preventing him from being updated or drawn
 /// </summary>
 public void death()
 {
     state = LifeState.Dead;
     actionState = EnemyActionState.Dying;
 }
Example #22
0
 public void attack()
 {
     actionState = EnemyActionState.Attacking;
 }
Example #23
0
 public void Init()
 {
     actionState  = EnemyActionState.Idle;
     currentPoise = poise;
 }
Example #24
0
 void updateActState()
 {
     if (isAttacking)
         actState = EnemyActionState.Attaccking;
     else if (currSpeed > 1.0f)
     {
         actState = EnemyActionState.Moving;
     }
     else if (currSpeed < 1.0f)
         actState = EnemyActionState.Idle;
 }
Example #25
0
 void Awake()
 {
     patrolState = GetComponent <EnemyPatrolState> ();
     actionState = GetComponent <EnemyActionState> ();
 }
Example #26
0
    private void ChangeState()
    {
        if (this.ai == EnemyAI.Normal) {

        } else if (this.ai == EnemyAI.Wait) {
            if (this.actionState == EnemyActionState.Wait) {
                this.aiPath.speed = 0;
                GameObject player = this.GetSameUnitPlayer ();
                if (player != null) {
                    this.SetActionState (EnemyActionState.Search);
                }
            }
        } else if (this.ai == EnemyAI.Escape) {
            GameObject player = this.GetNearestPlayer ();
            Unit playerUnit = this.levelManager.GetUnit (player.transform.position);
            if (playerUnit == this.levelManager.GetUnit (this.transform.position)) {
                this.SetActionState (EnemyActionState.Escape);
            }
        } else if (this.ai == EnemyAI.Boss) {
            GameObject player = this.GetSameUnitPlayer ();
            if (player == null) {
                this.actionState = EnemyActionState.Wait;
                this.ChangeTarget ();
            } else {
                this.actionState = EnemyActionState.Follow;
            }
        }
    }
Example #27
0
 private void SetActionState(EnemyActionState aState)
 {
     this.actionState = aState;
     this.ChangeTarget ();
 }
Example #28
0
    //global hash id
    //private HashIDs hash;
    void Awake()
    {
        isPlayerSighted = false;
        player = GameObject.FindGameObjectWithTag(Tags.player);
        playerTransform = player.transform;
        playerNotSightedPos = new Vector3(99999f, 99999f, 99999f);
        navAgent = GetComponent<NavMeshAgent>();
        enemyStats = GetComponent<EnemyStats>();

        anim = GetComponent<Animator>();
        currSpeed = navAgent.speed;

        actState = EnemyActionState.Idle;

        //hash = GameObject.FindGameObjectWithTag(Tags.GameController).GetComponent<HashIDs>();
    }
Example #29
0
 private void Action()
 {
     if (this.actionState == EnemyActionState.Search) {
         this.aiPath.speed = this.normalSpeed;
         GameObject player = this.GetSameUnitPlayer ();
         if (player != null) {
             this.SetActionState (EnemyActionState.Follow);
         }
     } else if (this.actionState == EnemyActionState.Follow) {
         this.aiPath.speed = this.fastSpeed;
         GameObject player = this.GetNearestPlayer ();
         if (player != null) {
             if (Vector3.Distance (this.transform.position, player.transform.position) > 100) {
                 this.actionState = EnemyActionState.Search;
                 this.SetActionState (EnemyActionState.Search);
             } else {
                 this.aiPath.target = player.transform;
             }
         }
     } else if (this.actionState == EnemyActionState.Escape) {
         GameObject player = this.GetNearestPlayer ();
         Unit playerUnit = this.levelManager.GetUnit (player.transform.position);
         if (playerUnit == this.levelManager.GetUnit (this.transform.position)) {
             this.aiPath.speed = this.fastSpeed;
             if (this.aiPath.target && playerUnit == this.levelManager.GetUnit (this.aiPath.target.position)) {
                 this.SetRandomRoom ();
             }
         }
     }
 }
Example #30
0
        /// <summary>
        /// Move the enemy
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(int timeElapsed, Player n)
        {
            if (deathEffectEmitter != null)
            {
                deathEffectEmitter.Update();
                if (deathEffectEmitter.atMaxParticles())
                    deathEffectEmitter.isEmitting = false;
            }

            if (state == LifeState.Dead) return;

            if (patrol != null)
                velocity = patrol.getCurrentVector(timeElapsed);

            Point c = Center();

            if(shoots)
            {
                if(facingLeft)
                {
                    if (new Rectangle(c.X - visionrange, c.Y, visionrange, 1).Intersects(n.drawRect))
                    {
                        projectiles.Add(new Projectile(c, new Vector2(-6, Game1.RapperRandomDiggityDawg.Next(-3, 3)), projectileTexture));
                    }
                }

               else
                {
                   if (new Rectangle(c.X, c.Y, visionrange, 1).Intersects(n.drawRect))
                   {
                       projectiles.Add(new Projectile(c, new Vector2(6, Game1.RapperRandomDiggityDawg.Next(-3, 3)), projectileTexture));
                   }
                }

                List<Projectile> hitlist = new List<Projectile>();

                foreach (Projectile p in projectiles)
                {
                    p.Update();
                    if (p.lifespan < 0)
                        hitlist.Add(p);
                    else if (p.Contains(n.drawRect))
                        n.villainDeath();
                }
                foreach (Projectile p in hitlist)
                    projectiles.Remove(p);
            }

            if (velocity.X == 0 && velocity.Y == 0)
            {
                actionState = EnemyActionState.Standing;
            }
            else if( Math.Abs(velocity.X) > 0 || Math.Abs(velocity.Y) > 0)
            {
                actionState = EnemyActionState.Running;
                facingLeft = velocity.X < 0;
            }

            switch (actionState)
            {
                case EnemyActionState.Standing:

                    break;
                case EnemyActionState.Running:
                    running[(int)myType].Update(timeElapsed);
                    break;
                case EnemyActionState.Attacking:
                    attacking[(int)myType].Update(timeElapsed);
                    break;
                case EnemyActionState.Dying:

                    break;
            }

            base.Update(timeElapsed);
        }