Prepare DeveloperMode code for trait-defined lobby options.
This commit is contained in:
@@ -59,16 +59,26 @@ namespace OpenRA.Traits
|
||||
public object Create(ActorInitializer init) { return new DeveloperMode(this); }
|
||||
}
|
||||
|
||||
public class DeveloperMode : IResolveOrder, ISync
|
||||
public class DeveloperMode : IResolveOrder, ISync, INotifyCreated
|
||||
{
|
||||
DeveloperModeInfo info;
|
||||
[Sync] public bool FastCharge;
|
||||
[Sync] public bool AllTech;
|
||||
[Sync] public bool FastBuild;
|
||||
[Sync] public bool DisableShroud;
|
||||
[Sync] public bool PathDebug;
|
||||
[Sync] public bool UnlimitedPower;
|
||||
[Sync] public bool BuildAnywhere;
|
||||
readonly DeveloperModeInfo info;
|
||||
public bool Enabled { get; private set; }
|
||||
|
||||
[Sync] bool fastCharge;
|
||||
[Sync] bool allTech;
|
||||
[Sync] bool fastBuild;
|
||||
[Sync] bool disableShroud;
|
||||
[Sync] bool pathDebug;
|
||||
[Sync] bool unlimitedPower;
|
||||
[Sync] bool buildAnywhere;
|
||||
|
||||
public bool FastCharge { get { return Enabled && fastCharge; } }
|
||||
public bool AllTech { get { return Enabled && allTech; } }
|
||||
public bool FastBuild { get { return Enabled && fastBuild; } }
|
||||
public bool DisableShroud { get { return Enabled && disableShroud; } }
|
||||
public bool PathDebug { get { return Enabled && pathDebug; } }
|
||||
public bool UnlimitedPower { get { return Enabled && unlimitedPower; } }
|
||||
public bool BuildAnywhere { get { return Enabled && buildAnywhere; } }
|
||||
|
||||
// Client side only
|
||||
public bool ShowCombatGeometry;
|
||||
@@ -76,128 +86,134 @@ namespace OpenRA.Traits
|
||||
public bool ShowDepthPreview;
|
||||
public bool ShowActorTags;
|
||||
|
||||
public bool EnableAll;
|
||||
bool enableAll;
|
||||
|
||||
public DeveloperMode(DeveloperModeInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
FastBuild = info.FastBuild;
|
||||
FastCharge = info.FastCharge;
|
||||
DisableShroud = info.DisableShroud;
|
||||
PathDebug = info.PathDebug;
|
||||
UnlimitedPower = info.UnlimitedPower;
|
||||
BuildAnywhere = info.BuildAnywhere;
|
||||
fastBuild = info.FastBuild;
|
||||
fastCharge = info.FastCharge;
|
||||
disableShroud = info.DisableShroud;
|
||||
pathDebug = info.PathDebug;
|
||||
unlimitedPower = info.UnlimitedPower;
|
||||
buildAnywhere = info.BuildAnywhere;
|
||||
|
||||
ShowCombatGeometry = info.ShowCombatGeometry;
|
||||
ShowDebugGeometry = info.ShowDebugGeometry;
|
||||
ShowDepthPreview = info.ShowDepthPreview;
|
||||
ShowActorTags = info.ShowActorTags;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
Enabled = self.World.LobbyInfo.GlobalSettings.AllowCheats || self.World.LobbyInfo.IsSinglePlayer;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (!self.World.AllowDevCommands)
|
||||
if (!Enabled)
|
||||
return;
|
||||
|
||||
switch (order.OrderString)
|
||||
{
|
||||
case "DevAll":
|
||||
{
|
||||
EnableAll ^= true;
|
||||
AllTech = FastCharge = FastBuild = DisableShroud = UnlimitedPower = BuildAnywhere = EnableAll;
|
||||
{
|
||||
enableAll ^= true;
|
||||
allTech = fastCharge = fastBuild = disableShroud = unlimitedPower = buildAnywhere = enableAll;
|
||||
|
||||
if (EnableAll)
|
||||
{
|
||||
self.Owner.Shroud.ExploreAll();
|
||||
|
||||
var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
|
||||
self.Trait<PlayerResources>().GiveCash(amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.Owner.Shroud.ResetExploration();
|
||||
}
|
||||
|
||||
self.Owner.Shroud.Disabled = DisableShroud;
|
||||
if (self.World.LocalPlayer == self.Owner)
|
||||
self.World.RenderPlayer = DisableShroud ? null : self.Owner;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevEnableTech":
|
||||
{
|
||||
AllTech ^= true;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevFastCharge":
|
||||
{
|
||||
FastCharge ^= true;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevFastBuild":
|
||||
{
|
||||
FastBuild ^= true;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevGiveCash":
|
||||
{
|
||||
var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
|
||||
self.Trait<PlayerResources>().GiveCash(amount);
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevGrowResources":
|
||||
{
|
||||
foreach (var a in self.World.ActorsWithTrait<ISeedableResource>())
|
||||
{
|
||||
for (var i = 0; i < info.ResourceGrowth; i++)
|
||||
a.Trait.Seed(a.Actor);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevVisibility":
|
||||
{
|
||||
DisableShroud ^= true;
|
||||
self.Owner.Shroud.Disabled = DisableShroud;
|
||||
if (self.World.LocalPlayer == self.Owner)
|
||||
self.World.RenderPlayer = DisableShroud ? null : self.Owner;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevPathDebug":
|
||||
{
|
||||
PathDebug ^= true;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevGiveExploration":
|
||||
if (enableAll)
|
||||
{
|
||||
self.Owner.Shroud.ExploreAll();
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevResetExploration":
|
||||
var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
|
||||
self.Trait<PlayerResources>().GiveCash(amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.Owner.Shroud.ResetExploration();
|
||||
break;
|
||||
}
|
||||
|
||||
self.Owner.Shroud.Disabled = DisableShroud;
|
||||
if (self.World.LocalPlayer == self.Owner)
|
||||
self.World.RenderPlayer = DisableShroud ? null : self.Owner;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevEnableTech":
|
||||
{
|
||||
allTech ^= true;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevFastCharge":
|
||||
{
|
||||
fastCharge ^= true;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevFastBuild":
|
||||
{
|
||||
fastBuild ^= true;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevGiveCash":
|
||||
{
|
||||
var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
|
||||
self.Trait<PlayerResources>().GiveCash(amount);
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevGrowResources":
|
||||
{
|
||||
foreach (var a in self.World.ActorsWithTrait<ISeedableResource>())
|
||||
{
|
||||
for (var i = 0; i < info.ResourceGrowth; i++)
|
||||
a.Trait.Seed(a.Actor);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevVisibility":
|
||||
{
|
||||
disableShroud ^= true;
|
||||
self.Owner.Shroud.Disabled = DisableShroud;
|
||||
if (self.World.LocalPlayer == self.Owner)
|
||||
self.World.RenderPlayer = DisableShroud ? null : self.Owner;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevPathDebug":
|
||||
{
|
||||
pathDebug ^= true;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevGiveExploration":
|
||||
{
|
||||
self.Owner.Shroud.ExploreAll();
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevResetExploration":
|
||||
{
|
||||
self.Owner.Shroud.ResetExploration();
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevUnlimitedPower":
|
||||
{
|
||||
UnlimitedPower ^= true;
|
||||
break;
|
||||
}
|
||||
{
|
||||
unlimitedPower ^= true;
|
||||
break;
|
||||
}
|
||||
|
||||
case "DevBuildAnywhere":
|
||||
{
|
||||
BuildAnywhere ^= true;
|
||||
break;
|
||||
}
|
||||
{
|
||||
buildAnywhere ^= true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
|
||||
@@ -85,11 +85,6 @@ namespace OpenRA
|
||||
get { return OrderManager.Connection is ReplayConnection; }
|
||||
}
|
||||
|
||||
public bool AllowDevCommands
|
||||
{
|
||||
get { return LobbyInfo.GlobalSettings.AllowCheats || LobbyInfo.IsSinglePlayer; }
|
||||
}
|
||||
|
||||
void SetLocalPlayer(Player localPlayer)
|
||||
{
|
||||
if (localPlayer == null)
|
||||
|
||||
@@ -24,10 +24,15 @@ namespace OpenRA.Mods.Common.Commands
|
||||
public class DevCommands : IChatCommand, IWorldLoaded
|
||||
{
|
||||
World world;
|
||||
DeveloperMode developerMode;
|
||||
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
{
|
||||
world = w;
|
||||
|
||||
if (world.LocalPlayer != null)
|
||||
developerMode = world.LocalPlayer.PlayerActor.Trait<DeveloperMode>();
|
||||
|
||||
var console = world.WorldActor.Trait<ChatCommands>();
|
||||
var help = world.WorldActor.Trait<HelpCommand>();
|
||||
|
||||
@@ -55,7 +60,7 @@ namespace OpenRA.Mods.Common.Commands
|
||||
if (world.LocalPlayer == null)
|
||||
return;
|
||||
|
||||
if (!world.AllowDevCommands)
|
||||
if (!developerMode.Enabled)
|
||||
{
|
||||
Game.Debug("Cheats are disabled.");
|
||||
return;
|
||||
|
||||
@@ -97,11 +97,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (!self.World.AllowDevCommands)
|
||||
return;
|
||||
|
||||
if (order.OrderString == "DevLevelUp")
|
||||
{
|
||||
var developerMode = self.Owner.PlayerActor.Trait<DeveloperMode>();
|
||||
if (!developerMode.Enabled)
|
||||
return;
|
||||
|
||||
if ((int)order.ExtraData > 0)
|
||||
GiveLevels((int)order.ExtraData);
|
||||
else
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
|
||||
{
|
||||
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
|
||||
if (developerMode.FastBuild)
|
||||
return 0;
|
||||
|
||||
var time = unit.GetBuildTime() * Info.BuildSpeed / 100;
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public virtual IEnumerable<ActorInfo> AllItems()
|
||||
{
|
||||
if (self.World.AllowDevCommands && developerMode.AllTech)
|
||||
if (developerMode.AllTech)
|
||||
return producible.Keys;
|
||||
|
||||
return allProducibles;
|
||||
@@ -214,7 +214,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!Enabled)
|
||||
return Enumerable.Empty<ActorInfo>();
|
||||
if (self.World.AllowDevCommands && developerMode.AllTech)
|
||||
if (developerMode.AllTech)
|
||||
return producible.Keys;
|
||||
|
||||
return buildableProducibles;
|
||||
@@ -226,7 +226,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!producible.TryGetValue(actor, out ps))
|
||||
return false;
|
||||
|
||||
return ps.Buildable || (self.World.AllowDevCommands && developerMode.AllTech);
|
||||
return ps.Buildable || developerMode.AllTech;
|
||||
}
|
||||
|
||||
public virtual void Tick(Actor self)
|
||||
@@ -316,7 +316,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
|
||||
{
|
||||
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
|
||||
if (developerMode.FastBuild)
|
||||
return 0;
|
||||
|
||||
var time = unit.GetBuildTime() * Info.BuildSpeed / 100;
|
||||
|
||||
Reference in New Issue
Block a user