Merge pull request #12358 from reaperrr/cashtrickler-upgrade
Add upgrade support to CashTrickler and split off GivesCashOnCapture
This commit is contained in:
@@ -332,6 +332,7 @@
|
|||||||
<Compile Include="Traits\ExternalCapturableBar.cs" />
|
<Compile Include="Traits\ExternalCapturableBar.cs" />
|
||||||
<Compile Include="Traits\ExternalCaptures.cs" />
|
<Compile Include="Traits\ExternalCaptures.cs" />
|
||||||
<Compile Include="Traits\GainsExperience.cs" />
|
<Compile Include="Traits\GainsExperience.cs" />
|
||||||
|
<Compile Include="Traits\GivesCashOnCapture.cs" />
|
||||||
<Compile Include="Traits\GivesBounty.cs" />
|
<Compile Include="Traits\GivesBounty.cs" />
|
||||||
<Compile Include="Traits\GivesExperience.cs" />
|
<Compile Include="Traits\GivesExperience.cs" />
|
||||||
<Compile Include="Traits\GrantConditionOnPrerequisite.cs" />
|
<Compile Include="Traits\GrantConditionOnPrerequisite.cs" />
|
||||||
|
|||||||
@@ -9,58 +9,87 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using OpenRA.Mods.Common.Effects;
|
using OpenRA.Mods.Common.Effects;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Lets the actor generate cash in a set periodic time.")]
|
[Desc("Lets the actor generate cash in a set periodic time.")]
|
||||||
class CashTricklerInfo : ITraitInfo
|
public class CashTricklerInfo : ConditionalTraitInfo
|
||||||
{
|
{
|
||||||
[Desc("Number of ticks to wait between giving money.")]
|
[Desc("Number of ticks to wait between giving money.")]
|
||||||
public readonly int Period = 50;
|
public readonly int Interval = 50;
|
||||||
|
|
||||||
[Desc("Amount of money to give each time.")]
|
[Desc("Amount of money to give each time.")]
|
||||||
public readonly int Amount = 15;
|
public readonly int Amount = 15;
|
||||||
[Desc("Whether to show the cash tick indicators (+$15 rising from actor).")]
|
|
||||||
public readonly bool ShowTicks = true;
|
|
||||||
[Desc("Amount of money awarded for capturing the actor.")]
|
|
||||||
public readonly int CaptureAmount = 0;
|
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new CashTrickler(this); }
|
[Desc("Whether to show the cash tick indicators rising from the actor.")]
|
||||||
|
public readonly bool ShowTicks = true;
|
||||||
|
|
||||||
|
[Desc("How long to show the cash tick indicator when enabled.")]
|
||||||
|
public readonly int DisplayDuration = 30;
|
||||||
|
|
||||||
|
public override object Create(ActorInitializer init) { return new CashTrickler(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class CashTrickler : ITick, ISync, INotifyCapture
|
public class CashTrickler : ConditionalTrait<CashTricklerInfo>, ITick, ISync, INotifyCreated, INotifyOwnerChanged
|
||||||
{
|
{
|
||||||
readonly CashTricklerInfo info;
|
readonly CashTricklerInfo info;
|
||||||
|
PlayerResources resources;
|
||||||
[Sync] int ticks;
|
[Sync] int ticks;
|
||||||
|
|
||||||
public CashTrickler(CashTricklerInfo info)
|
public CashTrickler(CashTricklerInfo info)
|
||||||
|
: base(info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
{
|
{
|
||||||
|
resources = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||||
|
{
|
||||||
|
resources = newOwner.PlayerActor.Trait<PlayerResources>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ITick.Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (IsTraitDisabled)
|
||||||
|
return;
|
||||||
|
|
||||||
if (--ticks < 0)
|
if (--ticks < 0)
|
||||||
{
|
{
|
||||||
ticks = info.Period;
|
ticks = info.Interval;
|
||||||
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(info.Amount);
|
ModifyCash(self, self.Owner, info.Amount);
|
||||||
MaybeAddCashTick(self, info.Amount);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
void AddCashTick(Actor self, int amount)
|
||||||
{
|
{
|
||||||
if (info.CaptureAmount > 0)
|
self.World.AddFrameEndTask(w => w.Add(
|
||||||
{
|
new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), info.DisplayDuration)));
|
||||||
newOwner.PlayerActor.Trait<PlayerResources>().GiveCash(info.CaptureAmount);
|
|
||||||
MaybeAddCashTick(self, info.CaptureAmount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaybeAddCashTick(Actor self, int amount)
|
void ModifyCash(Actor self, Player newOwner, int amount)
|
||||||
{
|
{
|
||||||
|
if (amount < 0)
|
||||||
|
{
|
||||||
|
// Check whether the amount of cash to be removed would exceed available player cash, in that case only remove all the player cash
|
||||||
|
var drain = Math.Min(resources.Cash + resources.Resources, -amount);
|
||||||
|
resources.TakeCash(drain);
|
||||||
|
|
||||||
if (info.ShowTicks)
|
if (info.ShowTicks)
|
||||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), 30)));
|
AddCashTick(self, -drain);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resources.GiveCash(amount);
|
||||||
|
if (info.ShowTicks)
|
||||||
|
AddCashTick(self, amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
70
OpenRA.Mods.Common/Traits/GivesCashOnCapture.cs
Normal file
70
OpenRA.Mods.Common/Traits/GivesCashOnCapture.cs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2017 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;
|
||||||
|
using OpenRA.Mods.Common.Effects;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
[Desc("Lets the actor grant cash when captured.")]
|
||||||
|
public class GivesCashOnCaptureInfo : ConditionalTraitInfo
|
||||||
|
{
|
||||||
|
[Desc("Whether to show the cash tick indicators rising from the actor.")]
|
||||||
|
public readonly bool ShowTicks = true;
|
||||||
|
|
||||||
|
[Desc("How long to show the Amount tick indicator when enabled.")]
|
||||||
|
public readonly int DisplayDuration = 30;
|
||||||
|
|
||||||
|
[Desc("Amount of money awarded for capturing the actor.")]
|
||||||
|
public readonly int Amount = 0;
|
||||||
|
|
||||||
|
public override object Create(ActorInitializer init) { return new GivesCashOnCapture(this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GivesCashOnCapture : ConditionalTrait<GivesCashOnCaptureInfo>, INotifyCapture
|
||||||
|
{
|
||||||
|
readonly GivesCashOnCaptureInfo info;
|
||||||
|
|
||||||
|
public GivesCashOnCapture(GivesCashOnCaptureInfo info)
|
||||||
|
: base(info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||||
|
{
|
||||||
|
if (IsTraitDisabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var resources = newOwner.PlayerActor.Trait<PlayerResources>();
|
||||||
|
var amount = info.Amount;
|
||||||
|
|
||||||
|
if (amount < 0)
|
||||||
|
{
|
||||||
|
// Check whether the amount of cash to be removed would exceed available player cash, in that case only remove all the player cash
|
||||||
|
amount = Math.Min(resources.Cash + resources.Resources, -amount);
|
||||||
|
resources.TakeCash(amount);
|
||||||
|
|
||||||
|
// For correct cash tick display
|
||||||
|
amount = -amount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
resources.GiveCash(amount);
|
||||||
|
|
||||||
|
if (!info.ShowTicks)
|
||||||
|
return;
|
||||||
|
|
||||||
|
self.World.AddFrameEndTask(w => w.Add(
|
||||||
|
new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), info.DisplayDuration)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -719,6 +719,33 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Capture bonus was decoupled from CashTrickler to a separate trait.
|
||||||
|
if (engineVersion < 20170108 && depth == 0)
|
||||||
|
{
|
||||||
|
var trickler = node.Value.Nodes.FirstOrDefault(n => n.Key == "CashTrickler");
|
||||||
|
if (trickler != null)
|
||||||
|
{
|
||||||
|
var capture = trickler.Value.Nodes.FirstOrDefault(n => n.Key == "CaptureAmount");
|
||||||
|
if (capture != null)
|
||||||
|
{
|
||||||
|
var gcoc = new MiniYamlNode("GivesCashOnCapture", "");
|
||||||
|
gcoc.Value.Nodes.Add(capture);
|
||||||
|
trickler.Value.Nodes.Remove(capture);
|
||||||
|
|
||||||
|
var show = trickler.Value.Nodes.FirstOrDefault(n => n.Key == "ShowTicks");
|
||||||
|
if (show != null)
|
||||||
|
gcoc.Value.Nodes.Add(show);
|
||||||
|
|
||||||
|
node.Value.Nodes.Add(gcoc);
|
||||||
|
RenameNodeKey(capture, "Amount");
|
||||||
|
}
|
||||||
|
|
||||||
|
var period = trickler.Value.Nodes.FirstOrDefault(n => n.Key == "Period");
|
||||||
|
if (period != null)
|
||||||
|
period.Key = "Interval";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ MNLYR:
|
|||||||
Offset: 0,0
|
Offset: 0,0
|
||||||
Facing: 96
|
Facing: 96
|
||||||
CashTrickler:
|
CashTrickler:
|
||||||
Period: 150
|
Interval: 150
|
||||||
Amount: 20
|
Amount: 20
|
||||||
RenderSprites:
|
RenderSprites:
|
||||||
Image: MNLY
|
Image: MNLY
|
||||||
@@ -108,7 +108,7 @@ FTUR:
|
|||||||
MustBeDestroyed:
|
MustBeDestroyed:
|
||||||
RequiredForShortGame: true
|
RequiredForShortGame: true
|
||||||
CashTrickler:
|
CashTrickler:
|
||||||
Period: 150
|
Interval: 150
|
||||||
Amount: 30
|
Amount: 30
|
||||||
ChronoshiftPower:
|
ChronoshiftPower:
|
||||||
Icon: chrono
|
Icon: chrono
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ OILB:
|
|||||||
RevealsShroud:
|
RevealsShroud:
|
||||||
Range: 3c0
|
Range: 3c0
|
||||||
CashTrickler:
|
CashTrickler:
|
||||||
Period: 250
|
Interval: 250
|
||||||
Amount: 50
|
Amount: 50
|
||||||
|
|
||||||
MOBILETENT:
|
MOBILETENT:
|
||||||
|
|||||||
@@ -364,15 +364,16 @@ OILB:
|
|||||||
ExternalCapturableBar:
|
ExternalCapturableBar:
|
||||||
EngineerRepairable:
|
EngineerRepairable:
|
||||||
CashTrickler:
|
CashTrickler:
|
||||||
Period: 375
|
Interval: 375
|
||||||
Amount: 100
|
Amount: 100
|
||||||
CaptureAmount: 100
|
|
||||||
Tooltip:
|
Tooltip:
|
||||||
Name: Oil Derrick
|
Name: Oil Derrick
|
||||||
Explodes:
|
Explodes:
|
||||||
Weapon: BarrelExplode
|
Weapon: BarrelExplode
|
||||||
GpsDot:
|
GpsDot:
|
||||||
String: Oil
|
String: Oil
|
||||||
|
GivesCashOnCapture:
|
||||||
|
Amount: 100
|
||||||
|
|
||||||
BR1:
|
BR1:
|
||||||
Inherits: ^Bridge
|
Inherits: ^Bridge
|
||||||
|
|||||||
Reference in New Issue
Block a user