Locate devmode code largely in the trait, reduce exploitability.

This commit is contained in:
alzeih
2010-07-26 14:58:23 +12:00
parent 10c7674433
commit 30241ddccc
7 changed files with 85 additions and 74 deletions

View File

@@ -16,6 +16,8 @@ namespace OpenRA.Traits
public int Cash = 20000;
public bool FastBuild = false;
public bool FastCharge = false;
public bool DisableShroud = false;
public bool PathDebug = false;
public object Create (ActorInitializer init) { return new DeveloperMode(this); }
}
@@ -26,31 +28,76 @@ namespace OpenRA.Traits
[Sync]
public bool FastCharge;
public bool FastBuild;
public bool DisableShroud;
public bool PathDebug;
public DeveloperMode(DeveloperModeInfo info)
{
Info = info;
FastBuild = Info.FastBuild;
FastCharge = Info.FastCharge;
DisableShroud = Info.DisableShroud;
PathDebug = Info.PathDebug;
}
public void ResolveOrder (Actor self, Order order)
{
if (!Game.LobbyInfo.GlobalSettings.AllowCheats) return;
switch(order.OrderString)
{
case "DevModeFastCharge":
{
FastCharge ^= true;
break;
}
case "DevModeFastBuild":
{
FastBuild ^= true;
break;
}
case "DevFastCharge":
{
FastCharge ^= true;
IssueNotification(FastCharge);
break;
}
case "DevFastBuild":
{
FastBuild ^= true;
IssueNotification(FastBuild);
break;
}
case "DevGiveCash":
{
self.traits.Get<PlayerResources>().GiveCash(Info.Cash);
IssueNotification(true);
break;
}
case "DevShroud":
{
DisableShroud ^= true;
Game.world.LocalPlayer.Shroud.Disabled = DisableShroud;
IssueNotification(DisableShroud);
break;
}
case "DevPathDebug":
{
PathDebug ^= true;
IssueNotification(PathDebug);
break;
}
case "DevIndexDebug":
{
Game.Settings.IndexDebug ^= true;
IssueNotification(Game.Settings.IndexDebug);
break;
}
case "DevUnitDebug":
{
Game.Settings.UnitDebug ^= true;
IssueNotification(Game.Settings.UnitDebug);
break;
}
}
}
void IssueNotification(bool enabled)
{
if (enabled)
Game.IssueOrder(Order.Chat("I used a devmode option"));
}
}
}

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Traits
public object Create(ActorInitializer init) { return new PlayerResources(init.self); }
}
public class PlayerResources : ITick, IResolveOrder
public class PlayerResources : ITick
{
Player Owner;
int AdviceInterval;
@@ -186,23 +186,6 @@ namespace OpenRA.Traits
{
TickPower();
TickOre(self);
}
public void ResolveOrder (Actor self, Order order)
{
switch (order.OrderString)
{
case "DevModeGiveCash":
{
if (!Game.LobbyInfo.GlobalSettings.AllowCheats) break;
self.World.AddFrameEndTask( w =>
{
var amt = order.Subject.Info.Traits.Get<DeveloperModeInfo>().Cash;
GiveCash(amt);
});
}
break;
}
}
}
}

View File

@@ -101,7 +101,7 @@ namespace OpenRA.Traits
if (unit == null || ! unit.Traits.Contains<BuildableInfo>())
return 0;
if (self.traits.Get<DeveloperMode>().FastBuild) return 0;
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.traits.Get<DeveloperMode>().FastBuild) return 0;
var ui = unit.Traits.Get<BuildableInfo>();
var time = ui.Cost
* self.Owner.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().BuildSpeed /* todo: country-specific build speed bonus */

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Traits
if (IsAvailable && (!Info.RequiresPower || IsPowered()))
{
if (self.traits.Get<DeveloperMode>().FastCharge) RemainingTime = 0;
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.traits.Get<DeveloperMode>().FastCharge) RemainingTime = 0;
if (RemainingTime > 0) --RemainingTime;
if (!notifiedCharging)
{