public bool ForwardAction(TimeMachine timeMachine, GameState state) { this._combatant1Specialists = _combatant1.GetSpecialistManager().GetSpecialists(); this._combatant2Specialists = _combatant1.GetSpecialistManager().GetSpecialists(); List <Specialist> specialists = new List <Specialist>(); specialists.AddRange(_combatant1.GetSpecialistManager().GetSpecialists()); specialists.AddRange(_combatant2.GetSpecialistManager().GetSpecialists()); while (specialists.Count > 0) { Specialist topPriority = null; foreach (Specialist s in specialists) { // If any of the specialists are invalid, cancel the event. if (!Validator.ValidateSpecialist(s)) { this._eventSuccess = false; return(false); } if (topPriority == null || s.GetPriority() < topPriority.GetPriority()) { topPriority = s; } } // Apply the specialist effect to the enemey. ICombatable enemy = _combatant1.GetOwner() == topPriority.GetOwner() ? _combatant2 : _combatant1; ICombatable friendly = _combatant1.GetOwner() == topPriority.GetOwner() ? _combatant1 : _combatant2; topPriority.ApplyEffect(friendly, enemy); } return(true); }
public CombatCleanup(ICombatable combatant1, ICombatable combatant2) { // Determine the losing sub: if (combatant1.GetDrillerCount() < combatant2.GetDrillerCount()) { loser = combatant1; winner = combatant2; } else if (combatant1.GetDrillerCount() > combatant2.GetDrillerCount()) { loser = combatant2; winner = combatant1; } else { // Tie. Compare specialist count. if (combatant1.GetSpecialistManager().GetSpecialistCount() < combatant2.GetSpecialistManager().GetSpecialistCount()) { loser = combatant1; winner = combatant2; } else if (combatant2.GetSpecialistManager().GetSpecialistCount() > combatant2.GetSpecialistManager().GetSpecialistCount()) { loser = combatant2; winner = combatant1; } else if (combatant1 is Outpost || combatant2 is Outpost) { winner = combatant1 is Outpost ? combatant1 : combatant2; loser = combatant1 is Outpost ? combatant2 : combatant1; } else { // Complete tie. isTie = true; // winner & loser don't matter in a tie. winner = combatant1; loser = combatant2; } } initialLoserDrillerCount = loser.GetDrillerCount(); losingPlayer = loser.GetOwner(); loserSpecialists = loser.GetSpecialistManager().GetSpecialists(); }
public bool ForwardAction(TimeMachine timeMachine, GameState state) { if (isTie) { // TODO: Handle tie. return(false); } if (loser is Sub) { // Cleanup the sub. if (loser.GetSpecialistManager().GetSpecialistCount() > 0) { loser.GetSpecialistManager().captureAll(); ((Sub)loser).IsCaptured = true; } else { // Remove the sub state.RemoveSub((Sub)loser); } } if (loser is Outpost) { // Transfer Ownership and give drillers. loser.SetOwner(winner.GetOwner()); // Remove the winning sub and make it arrive at the outpost. loser.SetDrillerCount(0); loser.AddDrillers(winner.GetDrillerCount()); // Transfer any specialists to the outpost. loser.GetSpecialistManager().captureAll(); winner.GetSpecialistManager().transferSpecialistsTo(loser.GetSpecialistManager()); // Remove the incoming sub. state.RemoveSub((Sub)winner); } this.isSuccess = true; return(isSuccess); }
/// <summary> /// Performs the reverse action of the driller combat to undo. /// </summary> /// <returns>if the event was reversed</returns> public bool BackwardAction() { if (_eventSuccess) { // Add any removed subs back. if (_combatant1 is Sub && (_combatant1.GetDrillerCount() < 0 || (_combatant1.GetDrillerCount() == 0 && _combatant1.GetSpecialistManager().GetSpecialistCount() == 0))) { Game.TimeMachine.GetState().AddSub((Sub)_combatant1); } if (_combatant2 is Sub && (_combatant2.GetDrillerCount() < 0 || (_combatant2.GetDrillerCount() == 0 && _combatant2.GetSpecialistManager().GetSpecialistCount() == 0))) { Game.TimeMachine.GetState().AddSub((Sub)_combatant2); } // Restore driller counts. _combatant1.SetDrillerCount(_preCombatDrillers1); _combatant2.SetDrillerCount(_preCombatDrillers2); } return(_eventSuccess); }