/// <summary> /// Each Recruit Attacks an enemy /// </summary> /// <param name="enemy"></param> private void Attack(IEnemy enemy) { _writer.Information(); _writer.WriteMessage($"\n{" ",-80}"); _writer.WriteMessage($"{"-----------",22} {"The Army begins its Attack!!",5} {"-----------",10}{" ",17}"); _writer.WriteMessage($"{" ",-80}\n"); _writer.Default(); foreach (var soldier in Recruits.Where(r => !r.IsDead)) { if (enemy.HitPoints > 0) { var attackDamage = soldier.Attack(); _writer.WriteMessage(soldier.AttackMessage()); // Enemy Defends the Attack enemy.Defend(attackDamage); } else { enemy.IsDead = true; break; } } }
/// <summary> /// Count all the Ranks /// </summary> private void CountRanks() { GeneralCount = Recruits.Count(s => s.Rank == Rank.General); CaptainCount = Recruits.Count(s => s.Rank == Rank.Captain); SergeantCount = Recruits.Count(s => s.Rank == Rank.Sergeant); PrivateCount = Recruits.Count(s => s.Rank == Rank.Private); MaxSergeantCount = PrivateCount / PrivatesNeededPerSergeant; }
public static void ConvertLootersToKingdomCultureRecruits(ref TroopRoster troopRoster, CultureObject culture, int numberToUpgrade) { var recruit = Recruits.Where(x => x.Culture == Clan.All.FirstOrDefault(k => k.Culture == culture)?.Culture) .ToList().GetRandomElement() ?? Recruits.ToList().GetRandomElement(); troopRoster.AddToCounts(recruit, numberToUpgrade); }
/// <summary> /// Demote Sergeants to Privates /// </summary> private void DemoteNecessarySergeantsToPrivates() { _writer.WriteMessage($"You can't have more than {MaxSergeantCount} Sergeant(s)!"); for (int i = SergeantCount; i > MaxSergeantCount; i--) { var sergeantToDemote = Recruits.First(s => s.Rank == Rank.Sergeant); sergeantToDemote.Rank = Rank.Private; _writer.WriteMessage($"{sergeantToDemote.Name} has been demoted from {Rank.Sergeant} to {Rank.Private}"); } }
/// <summary> /// Demote Captains to Privates /// </summary> private void DemoteNecessaryCaptainsToPrivates() { _writer.WriteMessage($"You can't have more than {MaxCaptainCount} Captains!"); for (int i = CaptainCount; i > MaxCaptainCount; i--) { var captainToDemote = Recruits.First(s => s.Rank == Rank.Captain); captainToDemote.Rank = Rank.Private; _writer.WriteMessage($"{captainToDemote.Name} has been demoted from {Rank.Captain} to {Rank.Private}"); } }
/// <summary> /// Demote Generals to Captains /// </summary> private void DemoteNecessaryGeneralsToCaptains() { _writer.WriteMessage($"You can't have more than {MaxGeneralCount} General!"); for (int i = GeneralCount; i > MaxGeneralCount; i--) { var generalToDemote = Recruits.First(s => s.Rank == Rank.General); generalToDemote.Rank = Rank.Captain; _writer.WriteMessage($"{generalToDemote.Name} has been demoted from {Rank.General} to {Rank.Captain}"); } }
/// <summary> /// Battle against an enemy. The Army will Attack first and Defend Second. /// </summary> /// <param name="enemy"></param> public void Battle(IEnemy enemy) { while (true) { if (!ReadyForBattle()) { continue; } DisplayBeginBattleMessage(enemy); while (!(enemy.IsDead || IsDefeated)) { Attack(enemy); if (enemy.IsDead) { break; } Defend(enemy); var soldierCount = Recruits.Count(r => !r.IsDead); if (soldierCount <= 0) { break; } var soldierCasualties = Recruits.Count(r => r.IsDead); var battleReport = BuildBattleReport(soldierCasualties, soldierCount, enemy.HitPoints); _writer.WriteMessage(battleReport); UserInputForNextRound(); } if (enemy.IsDead) { ArmyVictoriousMessage(enemy); } else { ArmyDefeatedMessage(enemy); } break; } }
/// <summary> /// Army Defends against the Enemy /// </summary> /// <param name="enemy"></param> private void Defend(IEnemy enemy) { var liveSoldiers = Recruits.Where(r => !r.IsDead); DisplayDefendMessage(); foreach (var soldier in liveSoldiers) { var attackDamage = enemy.Attack(); _writer.WriteMessage(enemy.AttackMessage()); soldier.Defend(enemy.AttackType, attackDamage); // Wonder about putting this inside Defend, but then defend would need to return a string which might be weird? _writer.WriteMessage(soldier.DefendMessage(enemy.AttackType, attackDamage)); } }
/// <summary> /// Update the set of recruits /// </summary> internal void CreateRecruits() { var recuritsToRemove = new List <string>(); //remove recruits from iat and randomly select to remove them from pool of available recruits foreach (var member in Recruits) { var path = Path.Combine(storageLocation, member.Value.RolePlayCharacter.VoiceName + ".rpc").Replace("\\", "/"); iat.RemoveCharacters(new List <int> { iat.GetAllCharacterSources().First(c => c.Source.Replace("\\", "/") == path).Id }); if (StaticRandom.Int(0, 100) % ConfigKey.RecruitChangeChance.GetIntValue() != 0) { recuritsToRemove.Add(member.Key); } } foreach (var member in recuritsToRemove) { Recruits.Remove(member); } //for the amount of empty recruit spaces, create a new recruit var amount = ConfigKey.RecruitCount.GetIntValue() - Recruits.Count; for (var i = 0; i < amount; i++) { var position = Boat.GetWeakestPosition(CrewMembers.Values.Concat(Recruits.Values).ToList()); var newMember = new CrewMember(position, Nationality); UniqueNameCheck(newMember); Recruits.Add(newMember.Name, newMember); } var storeNum = 0; //set up the files for each recruit and their avatar foreach (var recruit in Recruits) { recruit.Value.CreateRecruitFile(iat, storageLocation, storeNum); storeNum++; } iat.Save(); }
/// <summary> /// Add a recruit into crewMembers /// </summary> internal void AddRecruit(CrewMember member) { //remove recruit from the current list of characters in the game var path = Path.Combine(storageLocation, member.RolePlayCharacter.VoiceName + ".rpc").Replace("\\", "/"); iat.RemoveCharacters(new List <int> { iat.GetAllCharacterSources().First(c => c.Source.Replace("\\", "/") == path).Id }); //set up recruit as a 'proper' character in the game var currentNames = crewMembers.Keys.ToList(); currentNames.Add(ManagerName); member.CreateTeamMemberFile(iat, storageLocation, currentNames, TeamColorsPrimary, TeamColorsSecondary); foreach (var cm in crewMembers.Values) { cm.CreateInitialOpinions(new List <string> { member.Name }, true); } AddCrewMember(member); Recruits.Remove(member.Name); iat.Save(); }
/// <summary> /// Check that a CrewMember name is unique within this Team /// </summary> internal void UniqueNameCheck(CrewMember cm) { var unqiue = false; var partialFailCount = 0; //if the name is already in use by another character, reset their name while (!unqiue) { if (partialFailCount < 5) { partialFailCount++; var firstNames = crewMembers.Select(c => c.Value.FirstName).Concat(RetiredCrew.Select(c => c.Value.FirstName)).Concat(Recruits.Select(c => c.Value.FirstName)).ToList(); var lastNames = crewMembers.Select(c => c.Value.LastName).Concat(RetiredCrew.Select(c => c.Value.LastName)).Concat(Recruits.Select(c => c.Value.LastName)).ToList(); if (firstNames.Contains(cm.FirstName) || lastNames.Contains(cm.LastName) || cm.Name == ManagerName) { cm.SelectRandomName(); } else { unqiue = true; } } else { if (crewMembers.ContainsKey(cm.Name) || RetiredCrew.ContainsKey(cm.Name) || Recruits.ContainsKey(cm.Name) || cm.Name == ManagerName) { cm.SelectRandomName(); } else { unqiue = true; } } } }