Added a levelup command
This commit is contained in:
committed by
Christopher Grant
parent
98fd875a43
commit
66c33452e8
@@ -11,6 +11,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Commands
|
namespace OpenRA.Mods.Common.Commands
|
||||||
@@ -42,7 +43,8 @@ namespace OpenRA.Mods.Common.Commands
|
|||||||
register("enabletech", "toggles the ability to build everything.");
|
register("enabletech", "toggles the ability to build everything.");
|
||||||
register("instantcharge", "toggles instant support power charging.");
|
register("instantcharge", "toggles instant support power charging.");
|
||||||
register("all", "toggles all cheats and gives you some cash for your trouble.");
|
register("all", "toggles all cheats and gives you some cash for your trouble.");
|
||||||
register("crash", "crashes the game");
|
register("crash", "crashes the game.");
|
||||||
|
register("levelup", "adds a specified number of levels to the selected actors.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InvokeCommand(string name, string arg)
|
public void InvokeCommand(string name, string arg)
|
||||||
@@ -59,14 +61,14 @@ namespace OpenRA.Mods.Common.Commands
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "givecash":
|
case "givecash":
|
||||||
var order = new Order("DevGiveCash", world.LocalPlayer.PlayerActor, false);
|
var givecashorder = new Order("DevGiveCash", world.LocalPlayer.PlayerActor, false);
|
||||||
int cash;
|
int cash;
|
||||||
|
|
||||||
if (int.TryParse(arg, out cash))
|
if (int.TryParse(arg, out cash))
|
||||||
order.ExtraData = (uint)cash;
|
givecashorder.ExtraData = (uint)cash;
|
||||||
|
|
||||||
Game.Debug("Giving {0} credits to player {1}.", cash == 0 ? "cheat default" : cash.ToString(CultureInfo.InvariantCulture), world.LocalPlayer.PlayerName);
|
Game.Debug("Giving {0} credits to player {1}.", cash == 0 ? "cheat default" : cash.ToString(CultureInfo.InvariantCulture), world.LocalPlayer.PlayerName);
|
||||||
world.IssueOrder(order);
|
world.IssueOrder(givecashorder);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -85,10 +87,29 @@ namespace OpenRA.Mods.Common.Commands
|
|||||||
IssueDevCommand(world, "DevEnableTech");
|
IssueDevCommand(world, "DevEnableTech");
|
||||||
IssueDevCommand(world, "DevFastCharge");
|
IssueDevCommand(world, "DevFastCharge");
|
||||||
IssueDevCommand(world, "DevGiveCash");
|
IssueDevCommand(world, "DevGiveCash");
|
||||||
|
IssueDevCommand(world, "DevLevelUp");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "crash":
|
case "crash":
|
||||||
throw new DevException();
|
throw new DevException();
|
||||||
|
|
||||||
|
case "levelup":
|
||||||
|
var level = 0;
|
||||||
|
int.TryParse(arg, out level);
|
||||||
|
|
||||||
|
foreach (var actor in world.Selection.Actors)
|
||||||
|
{
|
||||||
|
if (actor.IsDead || actor.Destroyed)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var leveluporder = new Order("DevLevelUp", actor, false);
|
||||||
|
leveluporder.ExtraData = (uint)level;
|
||||||
|
|
||||||
|
if (actor.HasTrait<GainsExperience>())
|
||||||
|
world.IssueOrder(leveluporder);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GainsExperience : ISync
|
public class GainsExperience : ISync, IResolveOrder
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly GainsExperienceInfo info;
|
readonly GainsExperienceInfo info;
|
||||||
@@ -119,6 +119,20 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ResolveOrder(Actor self, Order order)
|
||||||
|
{
|
||||||
|
if (!self.World.AllowDevCommands)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (order.OrderString == "DevLevelUp")
|
||||||
|
{
|
||||||
|
if ((int)order.ExtraData > 0)
|
||||||
|
GiveLevels((int)order.ExtraData);
|
||||||
|
else
|
||||||
|
GiveLevels(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExperienceInit : IActorInit<int>
|
class ExperienceInit : IActorInit<int>
|
||||||
|
|||||||
Reference in New Issue
Block a user