Add a time limit lobby option

This commit is contained in:
Oliver Brakmann
2018-12-22 03:26:07 +01:00
committed by abcdefg30
parent 1364581696
commit a63cc2d317
8 changed files with 205 additions and 2 deletions

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Network;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -44,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new StrategicVictoryConditions(init.Self, this); }
}
public class StrategicVictoryConditions : ITick, ISync, INotifyWinStateChanged
public class StrategicVictoryConditions : ITick, ISync, INotifyWinStateChanged, INotifyTimeLimit
{
readonly StrategicVictoryConditionsInfo info;
@@ -108,6 +109,27 @@ namespace OpenRA.Mods.Common.Traits
}
}
void INotifyTimeLimit.NotifyTimerExpired(Actor self)
{
if (objectiveID < 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 => new Pair<Player, PlayerStatistics>(p, p.PlayerActor.TraitOrDefault<PlayerStatistics>()))
.OrderByDescending(p => p.Second != null ? p.Second.Experience : 0)
.GroupBy(p => (self.World.LobbyInfo.ClientWithIndex(p.First.ClientIndex) ?? new Session.Client()).Team)
.OrderByDescending(g => g.Sum(gg => gg.Second != null ? gg.Second.Experience : 0));
if (teams.First().Key == myTeam && (myTeam != 0 || teams.First().First().First == self.Owner))
{
mo.MarkCompleted(self.Owner, objectiveID);
return;
}
mo.MarkFailed(self.Owner, objectiveID);
}
void INotifyWinStateChanged.OnPlayerLost(Player player)
{
foreach (var a in player.World.ActorsWithTrait<INotifyOwnerLost>().Where(a => a.Actor.Owner == player))