void ITick.Tick(Actor self) { if (self.Owner.WinState != WinState.Undefined || self.Owner.NonCombatant) { return; } if (conquestObjectiveID < 0) { conquestObjectiveID = missionObjectives.Add(self.Owner, info.ConquestObjective, "Primary", inhibitAnnouncement: true); } if (colonyObjectiveID < 0) { colonyObjectiveID = missionObjectives.Add(self.Owner, info.ColonyObjective, "Primary", inhibitAnnouncement: true); } // Nothing can be done in this case so don't frustrate human players and lose immediately. if (!self.Owner.NonCombatant && !self.Owner.IsBot && !colonies.Any(c => c.Owner == self.Owner) && self.Owner.HasNoRequiredUnits(shortGame)) { missionObjectives.MarkFailed(self.Owner, conquestObjectiveID); missionObjectives.MarkFailed(self.Owner, colonyObjectiveID); } // Require neutral colonies to get captured first. if (self.World.ActorsHavingTrait <DefeatedColony>().Any()) { return; } // Players, NonCombatants, and IsAlliedWith are all fixed once the game starts, so we can cache the result. if (otherPlayers == null) { otherPlayers = self.World.Players.Where(p => !p.NonCombatant && !p.IsAlliedWith(self.Owner)).ToArray(); } // Don't win the game on enemy colony defeat, but on re-capture. if (colonies.All(c => c.Owner == self.Owner || c.Owner.IsAlliedWith(self.Owner))) { missionObjectives.MarkCompleted(self.Owner, colonyObjectiveID); } // Also require all units to be killed. if (otherPlayers.All(o => o.HasNoRequiredUnits(shortGame))) { missionObjectives.MarkCompleted(self.Owner, conquestObjectiveID); } }
public void MarkFailedObjective(int id) { if (id < 0 || id >= mo.Objectives.Count) { throw new LuaException("Objective ID is out of range."); } mo.MarkFailed(Player, id); }
void INotifyTimeLimit.NotifyTimerExpired(Actor self) { if (colonyObjectiveID < 0 || conquestObjectiveID < 0) { return; } var myTeam = self.World.LobbyInfo.ClientWithIndex(self.Owner.ClientIndex).Team; var teams = self.World.Players.Where(p => !p.NonCombatant && p.Playable) .Select(p => (Player: p, PlayerStatistics: p.PlayerActor.TraitOrDefault <PlayerStatistics>())) .OrderByDescending(p => p.PlayerStatistics != null ? p.PlayerStatistics.Experience : 0) .GroupBy(p => (self.World.LobbyInfo.ClientWithIndex(p.Player.ClientIndex) ?? new Session.Client()).Team) .OrderByDescending(g => g.Sum(gg => gg.PlayerStatistics != null ? gg.PlayerStatistics.Experience : 0)); if (teams.First().Key == myTeam && (myTeam != 0 || teams.First().First().Player == self.Owner)) { missionObjectives.MarkCompleted(self.Owner, colonyObjectiveID); missionObjectives.MarkCompleted(self.Owner, conquestObjectiveID); return; } missionObjectives.MarkFailed(self.Owner, colonyObjectiveID); missionObjectives.MarkFailed(self.Owner, conquestObjectiveID); }