Convert GainsExperience to conditions.

This commit is contained in:
Paul Chote
2016-12-09 23:58:01 +00:00
parent f4e0b91e04
commit 736d66d2c2
7 changed files with 45 additions and 23 deletions

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Effects; using OpenRA.Mods.Common.Effects;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
@@ -18,13 +19,13 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("This actor's experience increases when it has killed a GivesExperience actor.")] [Desc("This actor's experience increases when it has killed a GivesExperience actor.")]
public class GainsExperienceInfo : ITraitInfo, Requires<ValuedInfo>, Requires<UpgradeManagerInfo> public class GainsExperienceInfo : ITraitInfo, Requires<ValuedInfo>
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Upgrades to grant at each level.", [Desc("Condition to grant at each level.",
"Key is the XP requirements for each level as a percentage of our own value.", "Key is the XP requirements for each level as a percentage of our own value.",
"Value is a list of the upgrade types to grant")] "Value is a list of the upgrade types to grant")]
public readonly Dictionary<int, string[]> Upgrades = null; public readonly Dictionary<int, string> Conditions = null;
[Desc("Palette for the level up sprite.")] [Desc("Palette for the level up sprite.")]
[PaletteReference] public readonly string LevelUpPalette = "effect"; [PaletteReference] public readonly string LevelUpPalette = "effect";
@@ -35,13 +36,14 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new GainsExperience(init, this); } public object Create(ActorInitializer init) { return new GainsExperience(init, this); }
} }
public class GainsExperience : ISync, IResolveOrder public class GainsExperience : INotifyCreated, ISync, IResolveOrder
{ {
readonly Actor self; readonly Actor self;
readonly GainsExperienceInfo info; readonly GainsExperienceInfo info;
readonly UpgradeManager um; readonly int initialExperience;
readonly List<Pair<int, string[]>> nextLevel = new List<Pair<int, string[]>>(); readonly List<Pair<int, string>> nextLevel = new List<Pair<int, string>>();
UpgradeManager um;
// Stored as a percentage of our value // Stored as a percentage of our value
[Sync] int experience = 0; [Sync] int experience = 0;
@@ -54,16 +56,20 @@ namespace OpenRA.Mods.Common.Traits
self = init.Self; self = init.Self;
this.info = info; this.info = info;
MaxLevel = info.Upgrades.Count; MaxLevel = info.Conditions.Count;
var cost = self.Info.TraitInfo<ValuedInfo>().Cost; var cost = self.Info.TraitInfo<ValuedInfo>().Cost;
foreach (var kv in info.Upgrades) foreach (var kv in info.Conditions)
nextLevel.Add(Pair.New(kv.Key * cost, kv.Value)); nextLevel.Add(Pair.New(kv.Key * cost, kv.Value));
if (init.Contains<ExperienceInit>()) if (init.Contains<ExperienceInit>())
GiveExperience(init.Get<ExperienceInit, int>(), info.SuppressLevelupAnimation); initialExperience = init.Get<ExperienceInit, int>();
}
um = self.Trait<UpgradeManager>(); void INotifyCreated.Created(Actor self)
{
um = self.TraitOrDefault<UpgradeManager>();
if (initialExperience > 0)
GiveExperience(initialExperience, info.SuppressLevelupAnimation);
} }
public bool CanGainLevel { get { return Level < MaxLevel; } } public bool CanGainLevel { get { return Level < MaxLevel; } }
@@ -76,17 +82,18 @@ namespace OpenRA.Mods.Common.Traits
public void GiveExperience(int amount, bool silent = false) public void GiveExperience(int amount, bool silent = false)
{ {
if (amount < 0)
throw new ArgumentException("Revoking experience is not implemented.", "amount");
experience += amount; experience += amount;
while (Level < MaxLevel && experience >= nextLevel[Level].First) while (Level < MaxLevel && experience >= nextLevel[Level].First)
{ {
var upgrades = nextLevel[Level].Second; if (um != null)
um.GrantCondition(self, nextLevel[Level].Second);
Level++; Level++;
foreach (var u in upgrades)
um.GrantUpgrade(self, u, this);
if (!silent) if (!silent)
{ {
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", "LevelUp", self.Owner.Faction.InternalName); Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", "LevelUp", self.Owner.Faction.InternalName);

View File

@@ -675,6 +675,21 @@ namespace OpenRA.Mods.Common.UtilityCommands
ConvertUpgradesToCondition(parent, node, "UndeployedUpgrades", "UndeployedCondition"); ConvertUpgradesToCondition(parent, node, "UndeployedUpgrades", "UndeployedCondition");
ConvertUpgradesToCondition(parent, node, "DeployedUpgrades", "DeployedCondition"); ConvertUpgradesToCondition(parent, node, "DeployedUpgrades", "DeployedCondition");
} }
if (node.Key == "GainsExperience")
{
var upgrades = node.Value.Nodes.FirstOrDefault(n => n.Key == "Upgrades");
if (upgrades != null)
{
upgrades.Key = "Conditions";
foreach (var n in upgrades.Value.Nodes)
{
var conditions = FieldLoader.GetValue<string[]>("", n.Value.Value);
if (conditions.Length > 1)
Console.WriteLine("Unable to automatically migrate multiple GainsExperience upgrades to a condition. This must be corrected manually");
}
}
}
} }
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);

View File

@@ -16,7 +16,7 @@
^GainsExperience: ^GainsExperience:
GainsExperience: GainsExperience:
Upgrades: Conditions:
200: rank-veteran-1 200: rank-veteran-1
400: rank-veteran-2 400: rank-veteran-2
800: rank-veteran-3 800: rank-veteran-3

View File

@@ -16,7 +16,7 @@
^GainsExperience: ^GainsExperience:
GainsExperience: GainsExperience:
Upgrades: Conditions:
200: rank-veteran-1 200: rank-veteran-1
400: rank-veteran-2 400: rank-veteran-2
800: rank-veteran-3 800: rank-veteran-3

View File

@@ -17,7 +17,7 @@ World:
GivesBounty: GivesBounty:
Percentage: 0 Percentage: 0
GainsExperience: GainsExperience:
Upgrades: Conditions:
DamageMultiplier@UNKILLABLE: DamageMultiplier@UNKILLABLE:
RequiresCondition: unkillable RequiresCondition: unkillable
Modifier: 0 Modifier: 0
@@ -28,7 +28,7 @@ World:
GivesBounty: GivesBounty:
Percentage: 0 Percentage: 0
GainsExperience: GainsExperience:
Upgrades: Conditions:
DamageMultiplier@UNKILLABLE: DamageMultiplier@UNKILLABLE:
RequiresCondition: unkillable RequiresCondition: unkillable
Modifier: 0 Modifier: 0
@@ -39,7 +39,7 @@ World:
GivesBounty: GivesBounty:
Percentage: 0 Percentage: 0
GainsExperience: GainsExperience:
Upgrades: Conditions:
DeathSounds@NORMAL: DeathSounds@NORMAL:
VolumeMultiplier: 0.1 VolumeMultiplier: 0.1
DeathSounds@BURNED: DeathSounds@BURNED:
@@ -56,7 +56,7 @@ World:
GivesBounty: GivesBounty:
Percentage: 0 Percentage: 0
GainsExperience: GainsExperience:
Upgrades: Conditions:
DamageMultiplier@UNKILLABLE: DamageMultiplier@UNKILLABLE:
RequiresCondition: unkillable RequiresCondition: unkillable
Modifier: 0 Modifier: 0

View File

@@ -15,7 +15,7 @@
^GainsExperience: ^GainsExperience:
GainsExperience: GainsExperience:
Upgrades: Conditions:
200: rank-veteran-1 200: rank-veteran-1
400: rank-veteran-2 400: rank-veteran-2
800: rank-veteran-3 800: rank-veteran-3

View File

@@ -17,7 +17,7 @@
^GainsExperience: ^GainsExperience:
GainsExperience: GainsExperience:
Upgrades: Conditions:
500: rank-veteran 500: rank-veteran
1000: rank-elite 1000: rank-elite
FirepowerMultiplier@VETERAN: FirepowerMultiplier@VETERAN: