public void createBattleRound(Ship Shooter, Ship Target, int defenseBonus, int battleCounter, bool defenderFights) { if (Shooter.refitCounter > 0) { return; } if (!Shooter.shipModules.Any(shipModule => shipModule.module.moduleGain != null && shipModule.module.moduleGain.damageoutput > 0)) { return; } var shootingModules = Shooter.shipModules.Where(module => module.module.moduleGain != null && module.module.moduleGain.damageoutput > 0) .ToList(); for (int i = 0; i < shootingModules.Count(); i++) { var shootingModule = shootingModules[i]; CombatRound round = new CombatRound(); round.CombatId = this.CombatId; round.RoundNumber = battleCounter; round.ShotNumber = i; round.Side = defenderFights ? 0 : 1; round.ModuleId = shootingModules[i].moduleId; round.HitPropability = Combat.moduleToHitRatio(shootingModules[i], Shooter, Target, round.Side, this.CombatField); round.Damage = (int)Combat.moduleToDamage(shootingModules[i], Shooter, Target, round.Side, this.CombatField); //create random hitValue and reduce hitpoints double HitValue = Lockable.rnd.Next(0, 100) / 100.0; if (round.HitPropability > HitValue) { round.IsHit = true; Target.hitpoints -= (short)round.Damage; if (defenderFights) { this.AttackerHitPointsRemain -= (short)round.Damage; this.DefenderDamageDealt += round.Damage; } else { this.DefenderHitPointsRemain -= (short)round.Damage; this.AttackerDamageDealt += round.Damage; } } else { round.IsHit = false; } this.CombatRounds.Add(round); } this.AttackerHitPointsRemain = Math.Max(this.AttackerHitPointsRemain, 0); this.DefenderHitPointsRemain = Math.Max(this.DefenderHitPointsRemain, 0); }
public void saveCombat(SpacegameServer.Core.Combat message) { }
public void updateCombatIsRead(SpacegameServer.Core.Combat message) { }
public void fieldCombat(List <Ship> ShipsFighting, User Attacker, Tuple <byte, byte> SysXY) { Core core = Core.Instance; //check attacker ships, find the one with the best combat ratio against any defender Ship AttackingShip = this.detectAttackingShip(Attacker, SysXY); if (AttackingShip == null) { return; } Ship Defender = this.StrongestEnemyOnField(AttackingShip, SysXY); if (Defender == null) { return; } //if Attacker has only non-Combatants and defender has combatants, destroy them and quit if (AttackingShip.attack == 0) { if (!ShipsFighting.Any(e => e.id == AttackingShip.id)) { ShipsFighting.Add(AttackingShip); } AttackingShip.destroy(); this.fieldCombat(ShipsFighting, Attacker, SysXY); return; } if (Defender.attack == 0) { if (!ShipsFighting.Any(e => e.id == Defender.id)) { ShipsFighting.Add(Defender); } Defender.destroy(); this.fieldCombat(ShipsFighting, Attacker, SysXY); return; } //let them fight if (!ShipsFighting.Any(e => e.id == AttackingShip.id)) { ShipsFighting.Add(AttackingShip); } if (!ShipsFighting.Any(e => e.id == Defender.id)) { ShipsFighting.Add(Defender); } Combat Combat = new Combat((int)Core.Instance.identities.combat.getNext()); Combat.fight(AttackingShip, Defender, this); //save Combat and both ships Core.Instance.combats[Combat.CombatId] = Combat; Core.Instance.dataConnection.saveCombat(Combat); //continue with evaluation this.fieldCombat(ShipsFighting, Attacker, SysXY); }