示例#1
0
        private bool TryAttack(GeneticGridDirection direction)
        {
            GridPosition myPosition     = GameObjectGrid.WorldToGridPosition(this.transform.position);
            GridPosition victimPosition = myPosition.GetPositionInDirection(direction.Value);

            if (!GameObjectGrid.PositionIsAlive(victimPosition))
            {
                return(false);
            }

            GameObject         victim        = GameObjectGrid.GetObjectAt(victimPosition);
            EntBehaviorManager victimManager = victim.GetComponent <EntBehaviorManager>();

            int damage = (this.AttackStrength.Value * this.Health.Value) / InitialHealth;

            victimManager.TakeDamage(damage);

            // Will succeed if we killed the victim
            if (this.TryMove(direction))
            {
                this.TryAddHealth(victimManager.GrowFoodStrength.Value);
            }

            if (this.AttackStrength.Value < StaticController.GlobalMaxInt)
            {
                ++this.AttackStrength.Value;
            }

            if (this.GrowFoodStrength.Value > 1)
            {
                --this.GrowFoodStrength.Value;
            }

            return(true);
        }
        private byte TryAttack(byte direction)
        {
            GridPosition myPosition     = GameObjectGrid.WorldToGridPosition(this.transform.position);
            GridPosition victimPosition = myPosition.GetPositionInDirection(direction);

            if (!GameObjectGrid.PositionIsAlive(victimPosition))
            {
                return(0);
            }

            GameObject         victim        = GameObjectGrid.GetObjectAt(victimPosition);
            EntBehaviorManager victimManager = victim.GetComponent <EntBehaviorManager>();

            int damage = (this.AttackStrength * this.Health) / InitialHealth;

            if (damage > byte.MaxValue)
            {
                damage = byte.MaxValue;
            }

            victimManager.TakeDamage((byte)damage);

            // Will succeed if we killed the victim
            if (this.TryMove(direction) == 1)
            {
                this.TryAddHealth(victimManager.GrowFoodStrength);
            }

            if (this.AttackStrength < byte.MaxValue)
            {
                ++this.AttackStrength;
            }

            if (this.GrowFoodStrength > byte.MinValue)
            {
                --this.GrowFoodStrength;
            }

            return(1);
        }