public void AcceptSurrenderWithGoods() { // Add good 1 to player 1 player1.Ship.AddGood(1, 10); combat.OfferSurrender(); combat.AcceptSurrender(); ShipGood good1 = player2.Ship.GetGood(1); Assert.That(good1.Quantity, Is.EqualTo(10), "Player 2 should have 10 of good 1 now"); }
public JsonResult AcceptSurrender(int combatId) { Combat selectedCombat = this.ControllerGame.GetCombat(combatId); if (selectedCombat != null) { string message = null; // Check that it is the current players turn if (selectedCombat.ShipTurn == this.ControllerGame.CurrentPlayer.Ship) { try { selectedCombat.AcceptSurrender(); } catch (InvalidOperationException ex) { // Log this exception ExceptionPolicy.HandleException(ex, "Controller Policy"); // No surrender offered? message = ex.Message; } } return(Json(new { message = message, status = BuildCombatStatus(selectedCombat) })); } return(Json(false)); }
/// <summary> /// Handles Police Combat /// </summary> public void DoCombat() { Ship npcShip = this.npcRow.Ship; Combat combat = npcShip.InProgressCombat; bool policeTurn = (combat.ShipTurn.ShipId == npcShip.ShipId); Dictionary <string, object> props = new Dictionary <string, object> { { "NpcId", this.npcRow.NpcId }, { "CombatId", combat.CombatId }, { "TurnShipId", combat.ShipTurn.ShipId }, { "ShipId", npcShip.ShipId }, { "PoliceTurn", policeTurn } }; Logger.Write("Police in Combat", "NPC", 150, 0, TraceEventType.Verbose, "Police in Combat", props); if (policeTurn) { try { // Has the other ship offered a surrender? if (combat.Surrendered) { // Do we accept? // Accept surrender combat.AcceptSurrender(); } else if (combat.CargoJettisoned) { // Pickup the cargo combat.PickupCargo(); } // We fire our weapon twice for (int i = 0; i < 2; i++) { // Check if our turn is over if (combat.ShipTurn.ShipId != npcShip.ShipId || combat.Status != Combat.CombatStatus.Incomplete) { // Break out break; } // Fire weapon! combat.FireWeapon(); Logger.Write("Fired weapon", "NPC", 50, 0, TraceEventType.Verbose, "Police Combat Turn", props); } } catch (ArgumentOutOfRangeException ex) { // Out of turn points ExceptionPolicy.HandleException(ex, "NPC Policy"); // Escape combat.ChargeJumpDrive(); Logger.Write("Charged JumpDrive", "NPC", 50, 0, TraceEventType.Verbose, "Police Combat Turn", props); } // Set a shorter delay before the next action this.SetNextActionDelay(NpcShipBase.DelayBeforeNextActionCombat); } }
/// <summary> /// Handles Pirate Combat /// </summary> private void DoCombat() { Ship npcShip = this.npcRow.Ship; Combat combat = npcShip.InProgressCombat; bool pirateTurn = (combat.ShipTurn.ShipId == npcShip.ShipId); Dictionary <string, object> props = new Dictionary <string, object> { { "NpcId", this.npcRow.NpcId }, { "CombatId", combat.CombatId }, { "TurnShipId", combat.ShipTurn.ShipId }, { "ShipId", npcShip.ShipId }, { "PirateTurn", pirateTurn } }; Logger.Write("Pirate in Combat", "NPC", 150, 0, TraceEventType.Verbose, "Pirate in Combat", props); if (pirateTurn) { try { // Has the other ship offered a surrender? if (combat.Surrendered) { // Do we accept? // Add the aggression to a random number, if non-negative we accept surrender int netResult = this.rnd.Next(-5, 10) + this.npcRow.Aggression; if (netResult >= 0) { // Accept surrender combat.AcceptSurrender(); return; } } else if (combat.CargoJettisoned) { // Do we pickup the jettisoned cargo? // We only even look at the cargo if there are more than 6-12 items int cargoCount = combat.CargoJettisonedCount; int minPickupAmount = this.rnd.Next(6, 12); if (cargoCount >= minPickupAmount) { // Check if we have space for at least 50% of the of the items if (npcShip.CargoSpaceFree >= cargoCount / 2) { // Pickup the cargo combat.PickupCargo(); return; } } } // We fire our weapon twice for (int i = 0; i < 2; i++) { // Check if our turn is over if (combat.ShipTurn.ShipId != npcShip.ShipId || combat.Status != Combat.CombatStatus.Incomplete) { // Break out break; } // Fire weapon! combat.FireWeapon(); Logger.Write("Fired weapon", "NPC", 50, 0, TraceEventType.Verbose, "Pirate Combat Turn", props); } } catch (ArgumentOutOfRangeException ex) { // Out of turn points ExceptionPolicy.HandleException(ex, "NPC Policy"); // Escape combat.ChargeJumpDrive(); Logger.Write("Charged JumpDrive", "NPC", 50, 0, TraceEventType.Verbose, "Pirate Combat Turn", props); } // Set a shorter delay before the next action this.SetNextActionDelay(NpcShipBase.DelayBeforeNextActionCombat); } }