Пример #1
0
        private bool PerformAttack(IEnt target)
        {
            var targetUnitCom   = target.GetCom <HealthCom>();
            var attackerUnitCom = _unitInfoCom;

            var damageVariation = attackerUnitCom.DamageAmount * GameConstants.UNIT_DAMAGE_VARIATION;
            var damageModifer   = Utility.RandomDouble(-(damageVariation), damageVariation);

            var result = targetUnitCom.CurrentHealth - attackerUnitCom.DamageAmount + damageModifer >= 0;

            target.GetCom <UnitActionContCom>().OnNotify
            (
                Owner,
                GameEvent.RECEIVE_DAMAGE
            );

            return(result);
        }
Пример #2
0
        public void OnNotify(IEnt ent, GameEvent evt)
        {
            switch (evt)
            {
            case GameEvent.UNIT_SELECTED:
                Engine.Instance.Sound.PlayRandomSound(_unitInfoCom.SoundInfo.SelectSound);
                break;

            case GameEvent.MOVE_TO_CELL:
                Debug.Assert(!_unitInfoCom.MoveTaken);
                Debug.Assert(ent.GetCom <CellInfoCom>().Inside.Count() == 0);
                _unitInfoCom.MoveTaken = true;
                MoveToEnt(ent);
                Engine.Instance.Sound.PlayRandomSound(_unitInfoCom.SoundInfo.MoveSound);
                CheckTurnComplete();
                break;

            case GameEvent.ATTACK_TARGET:
                Debug.Assert(!_unitInfoCom.AttackTaken);
                _unitInfoCom.AttackTaken = true;
                if (PerformAttack(ent))
                {
                    Engine.Instance.Sound.PlayRandomSound(_unitInfoCom.SoundInfo.AttackSound);
                }
                CheckTurnComplete();
                break;

            case GameEvent.RECEIVE_DAMAGE:
                Debug.Assert(ent.Tags.Contains(Tags.UNIT));
                Owner.GetCom <HealthCom>().ReceiveDamage(ent.GetCom <IDamageInfoCom>());
                Engine.Instance.Sound.PlayRandomSound(_unitInfoCom.SoundInfo.DamageSound);
                break;

            case GameEvent.UNIT_DIED:
                Engine.Instance.Sound.PlayRandomSound(_unitInfoCom.SoundInfo.DeathSound);
                Engine.Instance.DestoryEnt(Owner);
                break;

            case GameEvent.TURN_START:
                TurnEnd();
                break;
            }
        }
Пример #3
0
        public void OnNotify(IEnt ent, GameEvent evt)
        {
            switch (evt)
            {
            case GameEvent.AI_TAKE_TURN:
            {
                _cellInfoCom = Owner.Parent.GetCom <CellInfoCom>();
                _gridCom     = ent.GetCom <GridCom>();

                var action = _decisionTrees[_currentState].GetAction();
                action.TakeAction();

                _gridCom           = null;
                _closestEnemyCords = null;
                _cellInfoCom       = null;
                break;
            }
            }
        }
Пример #4
0
 private bool IsEnemy(IEnt other)
 {
     return(other.Tags.Contains(Tags.UNIT) && other.GetCom <UnitInfoCom>().Faction != _unitInfoCom.Faction);
 }