void OnWarDeclareCommand(User user, string[] args) { Faction attacker = Factions.GetByMember(user); if (!EnsureUserAndFactionCanEngageInDiplomacy(user, attacker)) { return; } if (args.Length < 2) { user.SendChatMessage(Messages.Usage, "/war declare FACTION \"REASON\""); return; } Faction defender = Factions.Get(Util.NormalizeFactionId(args[0])); if (defender == null) { user.SendChatMessage(Messages.FactionDoesNotExist, args[0]); return; } if (attacker.Id == defender.Id) { user.SendChatMessage(Messages.CannotDeclareWarAgainstYourself); return; } War existingWar = Wars.GetActiveWarBetween(attacker, defender); if (existingWar != null) { user.SendChatMessage(Messages.CannotDeclareWarAlreadyAtWar, defender.Id); return; } string cassusBelli = args[1].Trim(); if (cassusBelli.Length < Options.War.MinCassusBelliLength) { user.SendChatMessage(Messages.CannotDeclareWarInvalidCassusBelli, defender.Id); return; } War war = Wars.DeclareWar(attacker, defender, user, cassusBelli); PrintToChat(Messages.WarDeclaredAnnouncement, war.AttackerId, war.DefenderId, war.CassusBelli); Log($"{Util.Format(user)} declared war on faction {war.DefenderId} on behalf of {war.AttackerId} for reason: {war.CassusBelli}"); }
void OnWarEndCommand(User user, string[] args) { Faction faction = Factions.GetByMember(user); if (!EnsureUserAndFactionCanEngageInDiplomacy(user, faction)) { return; } Faction enemy = Factions.Get(Util.NormalizeFactionId(args[0])); if (enemy == null) { user.SendChatMessage(Messages.FactionDoesNotExist, args[0]); return; } War war = Wars.GetActiveWarBetween(faction, enemy); if (war == null) { user.SendChatMessage(Messages.NotAtWar, enemy.Id); return; } if (war.IsOfferingPeace(faction)) { user.SendChatMessage(Messages.CannotOfferPeaceAlreadyOfferedPeace, enemy.Id); return; } war.OfferPeace(faction); if (war.IsAttackerOfferingPeace && war.IsDefenderOfferingPeace) { PrintToChat(Messages.WarEndedTreatyAcceptedAnnouncement, faction.Id, enemy.Id); Log($"{Util.Format(user)} accepted the peace offering of {enemy.Id} on behalf of {faction.Id}"); Wars.EndWar(war, WarEndReason.Treaty); OnDiplomacyChanged(); } else { user.SendChatMessage(Messages.PeaceOffered, enemy.Id); Log($"{Util.Format(user)} offered peace to faction {enemy.Id} on behalf of {faction.Id}"); } }