Remove CrateEffect in favor of using updated SpriteEffect

This commit is contained in:
reaperrr
2018-10-07 17:55:06 +02:00
committed by Paul Chote
parent 4de0d0fcb9
commit eb86160021
15 changed files with 102 additions and 74 deletions

View File

@@ -1,48 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2018 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using OpenRA.Effects;
using OpenRA.Graphics;
namespace OpenRA.Mods.Common.Effects
{
public class CrateEffect : IEffect, ISpatiallyPartitionable
{
readonly string palette;
readonly Actor a;
readonly Animation anim;
public CrateEffect(Actor a, string seq, string palette)
{
this.a = a;
this.palette = palette;
anim = new Animation(a.World, "crate-effects");
anim.PlayThen(seq, () => a.World.AddFrameEndTask(w => { w.Remove(this); w.ScreenMap.Remove(this); }));
a.World.ScreenMap.Add(this, a.CenterPosition, anim.Image);
}
public void Tick(World world)
{
anim.Tick();
world.ScreenMap.Update(this, a.CenterPosition, anim.Image);
}
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
if (!a.IsInWorld || a.World.FogObscures(a.CenterPosition))
return SpriteRenderable.None;
return anim.Render(a.CenterPosition, wr.Palette(palette));
}
}
}

View File

@@ -139,7 +139,6 @@
<Compile Include="AudioLoaders\WavLoader.cs" />
<Compile Include="Effects\Beacon.cs" />
<Compile Include="Effects\ContrailFader.cs" />
<Compile Include="Effects\CrateEffect.cs" />
<Compile Include="Effects\RevealShroudEffect.cs" />
<Compile Include="Effects\FlashTarget.cs" />
<Compile Include="Effects\FloatingText.cs" />
@@ -942,6 +941,7 @@
<Compile Include="UpdateRules\Rules\20180923\AddRearmable.cs" />
<Compile Include="UpdateRules\Rules\20180923\MergeAttackPlaneAndHeli.cs" />
<Compile Include="UpdateRules\Rules\20180923\ExtractHackyAIModules.cs" />
<Compile Include="UpdateRules\Rules\20180923\DefineLevelUpImageDefault.cs" />
<Compile Include="Traits\Player\PlayerResources.cs" />
<Compile Include="UtilityCommands\DumpSequenceSheetsCommand.cs" />
<Compile Include="Traits\Render\WithBuildingRepairDecoration.cs" />

View File

@@ -20,8 +20,11 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Chance of getting this crate, assuming the collector is compatible.")]
public readonly int SelectionShares = 10;
[Desc("An animation defined in sequence yaml(s) to draw.")]
public readonly string Effect = null;
[Desc("Image containing the crate effect animation sequence.")]
public readonly string Image = "crate-effects";
[Desc("Animation sequence played when collected. Leave empty for no effect.")]
[SequenceReference("Image")] public readonly string Sequence = null;
[Desc("Palette to draw the animation in.")]
[PaletteReference] public readonly string Palette = "effect";
@@ -84,8 +87,8 @@ namespace OpenRA.Mods.Common.Traits
Game.Sound.PlayNotification(self.World.Map.Rules, collector.Owner, "Speech",
Info.Notification, collector.Owner.Faction.InternalName);
if (Info.Effect != null)
collector.World.AddFrameEndTask(w => w.Add(new CrateEffect(collector, Info.Effect, Info.Palette)));
if (Info.Image != null && Info.Sequence != null)
collector.World.AddFrameEndTask(w => w.Add(new SpriteEffect(collector, w, Info.Image, Info.Sequence, Info.Palette)));
}
}
}

View File

@@ -29,6 +29,12 @@ namespace OpenRA.Mods.Common.Traits
[GrantedConditionReference]
public IEnumerable<string> LinterConditions { get { return Conditions.Values; } }
[Desc("Image for the level up sprite.")]
public readonly string LevelUpImage = null;
[Desc("Sequence for the level up sprite. Needs to be present on Image.")]
[SequenceReference("Image")] public readonly string LevelUpSequence = "levelup";
[Desc("Palette for the level up sprite.")]
[PaletteReference] public readonly string LevelUpPalette = "effect";
@@ -107,7 +113,8 @@ namespace OpenRA.Mods.Common.Traits
if (!silent)
{
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", info.LevelUpNotification, self.Owner.Faction.InternalName);
self.World.AddFrameEndTask(w => w.Add(new CrateEffect(self, "levelup", info.LevelUpPalette)));
if (info.LevelUpImage != null && info.LevelUpSequence != null)
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(self, w, info.LevelUpImage, info.LevelUpSequence, info.LevelUpPalette)));
}
}
}

View File

@@ -0,0 +1,61 @@
#region Copyright & License Information
/*
* Copyright 2007-2018 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class DefineLevelUpImageDefault : UpdateRule
{
public override string Name { get { return "Unhardcoded LevelUpImage and LevelUpSequence on GainsExperience"; } }
public override string Description
{
get
{
return "GainsExperience was hardcoded to play a 'levelup' crate effect from 'crate-effects' image.";
}
}
static readonly string[] CrateActionTraits =
{
"DuplicateUnitCrateAction",
"ExplodeCrateAction",
"GiveCashCrateAction",
"GiveMcvCrateAction",
"GiveUnitCrateAction",
"GrantExternalConditionCrateAction",
"HealUnitsCrateAction",
"HideMapCrateAction",
"LevelUpCrateAction",
"RevealMapCrateAction",
"SupportPowerCrateAction"
};
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
var levelUpImageNode = new MiniYamlNode("LevelUpImage", "crate-effects");
foreach (var ge in actorNode.ChildrenMatching("GainsExperience"))
ge.AddNode(levelUpImageNode);
foreach (var t in CrateActionTraits)
{
foreach (var ca in actorNode.ChildrenMatching(t))
{
var effect = ca.LastChildMatching("Effect");
if (effect != null)
effect.RenameKey("Sequence");
}
}
yield break;
}
}
}

View File

@@ -108,6 +108,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new ExtractHackyAIModules(),
new RemoveNegativeDamageFullHealthCheck(),
new RemoveResourceExplodeModifier(),
new DefineLevelUpImageDefault(),
})
};

View File

@@ -49,6 +49,7 @@
400: rank-veteran
800: rank-veteran
1600: rank-veteran
LevelUpImage: crate-effects
GrantCondition@RANK-ELITE:
RequiresCondition: rank-veteran >= 4
Condition: rank-elite

View File

@@ -12,13 +12,13 @@ CRATE:
UseCashTick: yes
RevealMapCrateAction:
SelectionShares: 1
Effect: reveal-map
Sequence: reveal-map
ExplodeCrateAction@fire:
Weapon: Napalm.Crate
SelectionShares: 5
GrantExternalConditionCrateAction@cloak:
SelectionShares: 5
Effect: cloak
Sequence: cloak
Condition: cloak-crate-collected
GiveMcvCrateAction:
SelectionShares: 0

View File

@@ -21,6 +21,7 @@
400: rank-veteran
800: rank-veteran
1600: rank-veteran
LevelUpImage: crate-effects
GrantCondition@RANK-ELITE:
RequiresCondition: rank-veteran >= 4
Condition: rank-elite

View File

@@ -22,12 +22,12 @@ crate:
SelectionShares: 5
HideMapCrateAction:
SelectionShares: 5
Effect: hide-map
Sequence: hide-map
LevelUpCrateAction:
SelectionShares: 40
RevealMapCrateAction:
SelectionShares: 2
Effect: reveal-map
Sequence: reveal-map
GiveUnitCrateAction@LightInfantry:
SelectionShares: 15
Units: light_inf, light_inf, light_inf, light_inf, light_inf

View File

@@ -63,11 +63,11 @@ FORTCRATE:
SupportPowerCrateAction@parabombs:
SelectionShares: 30
Proxy: powerproxy.parabombs
Effect: parabombs
Sequence: parabombs
HealUnitsCrateAction:
SelectionShares: 30
Sound: heal2.aud
Effect: heal
Sequence: heal
GiveCashCrateAction:
Amount: 400
UseCashTick: true
@@ -77,7 +77,7 @@ FORTCRATE:
SelectionShares: 10
GrantExternalConditionCrateAction@ironcurtain:
SelectionShares: 10
Effect: invuln
Sequence: invuln
Sound: ironcur9.aud
Condition: invulnerability
Duration: 1200

View File

@@ -48,6 +48,7 @@
400: rank-veteran
800: rank-veteran
1600: rank-veteran
LevelUpImage: crate-effects
GrantCondition@RANK-ELITE:
RequiresCondition: rank-veteran >= 4
Condition: rank-elite

View File

@@ -31,14 +31,14 @@ CRATE:
SelectionShares: 5
HideMapCrateAction:
SelectionShares: 5
Effect: hide-map
Sequence: hide-map
HealUnitsCrateAction:
Sound: heal2.aud
SelectionShares: 2
Effect: heal
Sequence: heal
RevealMapCrateAction:
SelectionShares: 1
Effect: reveal-map
Sequence: reveal-map
DuplicateUnitCrateAction:
SelectionShares: 10
MaxAmount: 5
@@ -104,7 +104,7 @@ CRATE:
TimeDelay: 4500
GrantExternalConditionCrateAction@invuln:
SelectionShares: 5
Effect: invuln
Sequence: invuln
Sound: ironcur9.aud
Condition: invulnerability
Duration: 600
@@ -127,7 +127,7 @@ HEALCRATE:
HealUnitsCrateAction:
Sound: heal2.aud
SelectionShares: 1
Effect: heal
Sequence: heal
WCRATE:
Inherits: ^Crate

View File

@@ -21,6 +21,7 @@
Conditions:
500: rank
1000: rank
LevelUpImage: crate-effects
GrantCondition@RANK-VETERAN:
RequiresCondition: rank == 1
Condition: rank-veteran

View File

@@ -69,37 +69,37 @@ CRATE:
GiveCashCrateAction:
Amount: 1000
SelectionShares: 50
Effect: dollar
Sequence: dollar
UseCashTick: true
LevelUpCrateAction:
SelectionShares: 40
Effect: levelup
Sequence: levelup
HideMapCrateAction:
SelectionShares: 5
Effect: hide-map
Sequence: hide-map
HealUnitsCrateAction:
SelectionShares: 2
Effect: heal
Sequence: heal
RevealMapCrateAction:
SelectionShares: 1
Effect: reveal-map
Sequence: reveal-map
GiveMcvCrateAction:
SelectionShares: 0
NoBaseSelectionShares: 100
Units: mcv
GrantExternalConditionCrateAction@cloak:
SelectionShares: 5
Effect: stealth
Sequence: stealth
Condition: crate-cloak
Sound: cloak5.aud
GrantExternalConditionCrateAction@firepower:
SelectionShares: 5
Effect: firepower
Sequence: firepower
Condition: crate-firepower
Notification: UnitFirepowerUpgraded
GrantExternalConditionCrateAction@armor:
SelectionShares: 5
Effect: armor
Sequence: armor
Condition: crate-damage
Notification: UnitArmourUpgraded
GrantExternalConditionCrateAction@speed: