Replace burns with more modular and testable trait combinations.
This commit is contained in:
committed by
teinarss
parent
728e0c6600
commit
06ad9666e8
@@ -1,53 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2020 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 OpenRA.Graphics;
|
|
||||||
using OpenRA.Mods.Common.Traits.Render;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
|
||||||
{
|
|
||||||
[Desc("This actor will play a fire animation over its body and take damage over time.")]
|
|
||||||
class BurnsInfo : TraitInfo, Requires<RenderSpritesInfo>
|
|
||||||
{
|
|
||||||
public readonly string Anim = "1";
|
|
||||||
public readonly int Damage = 1;
|
|
||||||
public readonly int Interval = 8;
|
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new Burns(init.Self, this); }
|
|
||||||
}
|
|
||||||
|
|
||||||
class Burns : ITick, ISync
|
|
||||||
{
|
|
||||||
readonly BurnsInfo info;
|
|
||||||
[Sync]
|
|
||||||
int ticks;
|
|
||||||
|
|
||||||
public Burns(Actor self, BurnsInfo info)
|
|
||||||
{
|
|
||||||
this.info = info;
|
|
||||||
|
|
||||||
var anim = new Animation(self.World, "fire");
|
|
||||||
anim.IsDecoration = true;
|
|
||||||
anim.PlayRepeating(info.Anim);
|
|
||||||
self.Trait<RenderSprites>().Add(anim);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ITick.Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (--ticks <= 0)
|
|
||||||
{
|
|
||||||
self.InflictDamage(self, new Damage(info.Damage));
|
|
||||||
ticks = info.Interval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
63
OpenRA.Mods.Common/UpdateRules/Rules/ReplaceBurns.cs
Normal file
63
OpenRA.Mods.Common/UpdateRules/Rules/ReplaceBurns.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2020 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 ReplaceBurns : UpdateRule
|
||||||
|
{
|
||||||
|
public override string Name { get { return "Replaced Burns with separate render and health change traits."; } }
|
||||||
|
public override string Description
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Burns can be replaced using WithIdleOverlay and ChangesHealth.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
|
||||||
|
{
|
||||||
|
var addNodes = new List<MiniYamlNode>();
|
||||||
|
|
||||||
|
foreach (var burns in actorNode.ChildrenMatching("Burns"))
|
||||||
|
{
|
||||||
|
var anim = burns.LastChildMatching("Anim");
|
||||||
|
var animValue = anim != null ? anim.NodeValue<string>() : "1";
|
||||||
|
|
||||||
|
var damage = burns.LastChildMatching("Damage");
|
||||||
|
var damageValue = damage != null ? damage.NodeValue<int>() : 1;
|
||||||
|
|
||||||
|
var interval = burns.LastChildMatching("Interval");
|
||||||
|
var intervalValue = interval != null ? interval.NodeValue<int>() : 8;
|
||||||
|
|
||||||
|
var overlay = new MiniYamlNode("WithIdleOverlay@Burns", "");
|
||||||
|
overlay.AddNode("Image", FieldSaver.FormatValue("fire"));
|
||||||
|
overlay.AddNode("Sequence", FieldSaver.FormatValue(animValue));
|
||||||
|
overlay.AddNode("IsDecoration", FieldSaver.FormatValue(true));
|
||||||
|
addNodes.Add(overlay);
|
||||||
|
|
||||||
|
var changesHealth = new MiniYamlNode("ChangesHealth", "");
|
||||||
|
changesHealth.AddNode("Step", FieldSaver.FormatValue(-damageValue));
|
||||||
|
changesHealth.AddNode("StartIfBelow", FieldSaver.FormatValue(101));
|
||||||
|
changesHealth.AddNode("Delay", FieldSaver.FormatValue(intervalValue));
|
||||||
|
addNodes.Add(changesHealth);
|
||||||
|
}
|
||||||
|
|
||||||
|
actorNode.RemoveNodes("Burns");
|
||||||
|
|
||||||
|
foreach (var addNode in addNodes)
|
||||||
|
actorNode.AddNode(addNode);
|
||||||
|
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,6 +71,7 @@ namespace OpenRA.Mods.Common.UpdateRules
|
|||||||
new ChangeTargetLineDelayToMilliseconds(),
|
new ChangeTargetLineDelayToMilliseconds(),
|
||||||
new ReplaceFacingAngles(),
|
new ReplaceFacingAngles(),
|
||||||
new RenameSelfHealing(),
|
new RenameSelfHealing(),
|
||||||
|
new ReplaceBurns(),
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1042,9 +1042,6 @@
|
|||||||
Inherits: ^CommonHuskDefaults
|
Inherits: ^CommonHuskDefaults
|
||||||
Husk:
|
Husk:
|
||||||
AllowedTerrain: Clear, Rough, Road, Tiberium, BlueTiberium, Beach
|
AllowedTerrain: Clear, Rough, Road, Tiberium, BlueTiberium, Beach
|
||||||
Burns:
|
|
||||||
Damage: 100
|
|
||||||
Interval: 6
|
|
||||||
Targetable:
|
Targetable:
|
||||||
RequiresForceFire: true
|
RequiresForceFire: true
|
||||||
TargetTypes: Ground, Husk
|
TargetTypes: Ground, Husk
|
||||||
@@ -1062,6 +1059,14 @@
|
|||||||
Explodes:
|
Explodes:
|
||||||
Weapon: UnitExplodeSmall
|
Weapon: UnitExplodeSmall
|
||||||
EmptyWeapon: UnitExplodeSmall
|
EmptyWeapon: UnitExplodeSmall
|
||||||
|
WithIdleOverlay@Burns:
|
||||||
|
Image: fire
|
||||||
|
Sequence: 1
|
||||||
|
IsDecoration: True
|
||||||
|
ChangesHealth:
|
||||||
|
Step: -100
|
||||||
|
StartIfBelow: 101
|
||||||
|
Delay: 6
|
||||||
|
|
||||||
^LightHusk:
|
^LightHusk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
|
|||||||
@@ -265,9 +265,6 @@
|
|||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
Husk:
|
Husk:
|
||||||
AllowedTerrain: Sand, Rock, Transition, Concrete, Spice, SpiceSand, SpiceBlobs, Dune
|
AllowedTerrain: Sand, Rock, Transition, Concrete, Spice, SpiceSand, SpiceBlobs, Dune
|
||||||
Burns:
|
|
||||||
Damage: 10
|
|
||||||
Interval: 4
|
|
||||||
Targetable:
|
Targetable:
|
||||||
TargetTypes: Ground, Vehicle
|
TargetTypes: Ground, Vehicle
|
||||||
RequiresForceFire: true
|
RequiresForceFire: true
|
||||||
@@ -276,6 +273,14 @@
|
|||||||
Explodes:
|
Explodes:
|
||||||
Weapon: UnitExplodeMed
|
Weapon: UnitExplodeMed
|
||||||
EmptyWeapon: UnitExplodeMed
|
EmptyWeapon: UnitExplodeMed
|
||||||
|
WithIdleOverlay@Burns:
|
||||||
|
Image: fire
|
||||||
|
Sequence: 1
|
||||||
|
IsDecoration: True
|
||||||
|
ChangesHealth:
|
||||||
|
Step: -10
|
||||||
|
StartIfBelow: 101
|
||||||
|
Delay: 4
|
||||||
|
|
||||||
^AircraftHusk:
|
^AircraftHusk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
|
|||||||
@@ -46,8 +46,10 @@ OILB:
|
|||||||
ShowTicks: false
|
ShowTicks: false
|
||||||
|
|
||||||
TRAN.Husk2:
|
TRAN.Husk2:
|
||||||
Burns:
|
WithIdleOverlay@Burns:
|
||||||
Damage: 0
|
Image: fire
|
||||||
|
Sequence: 1
|
||||||
|
IsDecoration: True
|
||||||
|
|
||||||
MISS:
|
MISS:
|
||||||
DamageMultiplier@INVULNERABLE:
|
DamageMultiplier@INVULNERABLE:
|
||||||
|
|||||||
@@ -40,12 +40,16 @@ DOG:
|
|||||||
ScriptTags:
|
ScriptTags:
|
||||||
|
|
||||||
TRAN.Husk1:
|
TRAN.Husk1:
|
||||||
Burns:
|
WithIdleOverlay@Burns:
|
||||||
Damage: 0
|
Image: fire
|
||||||
|
Sequence: 1
|
||||||
|
IsDecoration: True
|
||||||
|
|
||||||
TRAN.Husk2:
|
TRAN.Husk2:
|
||||||
Burns:
|
WithIdleOverlay@Burns:
|
||||||
Damage: 0
|
Image: fire
|
||||||
|
Sequence: 1
|
||||||
|
IsDecoration: True
|
||||||
|
|
||||||
E7:
|
E7:
|
||||||
Passenger:
|
Passenger:
|
||||||
|
|||||||
@@ -983,8 +983,14 @@
|
|||||||
Inherits@2: ^ClassicFacingSpriteActor
|
Inherits@2: ^ClassicFacingSpriteActor
|
||||||
Husk:
|
Husk:
|
||||||
AllowedTerrain: Clear, Rough, Road, Ore, Gems, Beach
|
AllowedTerrain: Clear, Rough, Road, Ore, Gems, Beach
|
||||||
Burns:
|
WithIdleOverlay@Burns:
|
||||||
Damage: 200
|
Image: fire
|
||||||
|
Sequence: 1
|
||||||
|
IsDecoration: true
|
||||||
|
ChangesHealth:
|
||||||
|
Step: -200
|
||||||
|
StartIfBelow: 101
|
||||||
|
Delay: 8
|
||||||
OwnerLostAction:
|
OwnerLostAction:
|
||||||
Action: ChangeOwner
|
Action: ChangeOwner
|
||||||
CaptureManager:
|
CaptureManager:
|
||||||
|
|||||||
Reference in New Issue
Block a user