示例#1
0
 public static int Distance(this Tile tile1, Tile tile2 )
 {
     var result = Convert.ToInt32(Math.Sqrt(Math.Pow((tile2.X - tile1.X), 2) + Math.Pow((tile2.Y - tile1.Y), 2)));
     return result;
 }
示例#2
0
        private bool TryAttack(Combatant attacker, Tile @from, Tile @to)
        {
            var distance = @from.Distance(to);
            var defender = @to.Combatant;
            var weapon = attacker.Items.FirstOrDefault(x => x.IsWeapon);

            var range = 1.5;

            if (weapon != null)
            {
                range = weapon.WeaponRange + 0.5;
            }

            if (distance > range + 0.5)
            {
                return false;
            }

            var attackerRoll = GameHelpers.RollDie(attacker.Threat);
            var defenderRoll = GameHelpers.RollDie(defender.Survivability);
            var healthloss = 0;

            if (attackerRoll.Sum() > defenderRoll.Sum())
            {
                healthloss = attackerRoll.Sum() - defenderRoll.Sum();
                defender.Health -= healthloss;
            }

            attacker.Results.Add(new Result(CurrentGame.CurrentTurnNumber, CurrentGame.CurrentTurnOrder)
            {
                Rolls = attackerRoll.ConvertNumberListToString(),
                IsAttack = true
            });

            defender.Results.Add(new Result(CurrentGame.CurrentTurnNumber, CurrentGame.CurrentTurnOrder)
            {
                Healthloss = healthloss,
                Rolls = defenderRoll.ConvertNumberListToString(),
                IsAttack = true
            });

            if (defender.Health <= 0)
            {
                defender.Killer = attacker;
                RecordAction(Action.Kill, $"Killed {to.Combatant.Name} at {@to.X},{@to.Y}.", attacker);

            }
            else
            {
                RecordAction(Action.Attack, $"Attacked {to.Combatant.Name} at {@to.X},{@to.Y}.", attacker);

            }

            _db.SaveChanges();

            return true;
        }
示例#3
0
 public static bool CanMove(this Combatant c, Tile tile)
 {
     var distance = c.Tile.Distance(tile);
     return distance < c.Speed + 0.5;
 }