Move Guard, CashTrickler, Explodes, SelfHealing, Sellable and Crushable to Mods.Common.
Extract Guardable trait from Guard into own file.
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Sell : Activity
|
||||
{
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
var h = self.TraitOrDefault<Health>();
|
||||
var si = self.Info.Traits.Get<SellableInfo>();
|
||||
var pr = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||
|
||||
var cost = self.GetSellValue();
|
||||
|
||||
var refund = (cost * si.RefundPercent * (h == null ? 1 : h.HP)) / (100 * (h == null ? 1 : h.MaxHP));
|
||||
pr.GiveCash(refund);
|
||||
|
||||
foreach (var ns in self.TraitsImplementing<INotifySold>())
|
||||
ns.Sold(self);
|
||||
|
||||
if (refund > 0 && self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(refund), 30)));
|
||||
|
||||
self.Destroy();
|
||||
return this;
|
||||
}
|
||||
|
||||
// Cannot be cancelled
|
||||
public override void Cancel(Actor self) { }
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("Lets the actor generate cash in a set periodic time.")]
|
||||
class CashTricklerInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Number of ticks to wait between giving money.")]
|
||||
public readonly int Period = 50;
|
||||
[Desc("Amount of money to give each time.")]
|
||||
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); }
|
||||
}
|
||||
|
||||
class CashTrickler : ITick, ISync, INotifyCapture
|
||||
{
|
||||
readonly CashTricklerInfo info;
|
||||
[Sync] int ticks;
|
||||
public CashTrickler(CashTricklerInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (--ticks < 0)
|
||||
{
|
||||
ticks = info.Period;
|
||||
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(info.Amount);
|
||||
MaybeAddCashTick(self, info.Amount);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
if (info.CaptureAmount > 0)
|
||||
{
|
||||
newOwner.PlayerActor.Trait<PlayerResources>().GiveCash(info.CaptureAmount);
|
||||
MaybeAddCashTick(self, info.CaptureAmount);
|
||||
}
|
||||
}
|
||||
|
||||
void MaybeAddCashTick(Actor self, int amount)
|
||||
{
|
||||
if (info.ShowTicks)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), 30)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("This actor is crushable.")]
|
||||
class CrushableInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Sound to play when being crushed.")]
|
||||
public readonly string CrushSound = null;
|
||||
[Desc("Which crush classes does this actor belong to.")]
|
||||
public readonly string[] CrushClasses = { "infantry" };
|
||||
[Desc("Probability of mobile actors noticing and evading a crush attempt.")]
|
||||
public readonly int WarnProbability = 75;
|
||||
[Desc("Will friendly units just crush me instead of pathing around.")]
|
||||
public readonly bool CrushedByFriendlies = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Crushable(init.Self, this); }
|
||||
}
|
||||
|
||||
class Crushable : ICrushable
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly CrushableInfo info;
|
||||
|
||||
public Crushable(Actor self, CrushableInfo info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void WarnCrush(Actor crusher)
|
||||
{
|
||||
var mobile = self.TraitOrDefault<Mobile>();
|
||||
if (mobile != null && self.World.SharedRandom.Next(100) <= info.WarnProbability)
|
||||
mobile.Nudge(self, crusher, true);
|
||||
}
|
||||
|
||||
public void OnCrush(Actor crusher)
|
||||
{
|
||||
Sound.Play(info.CrushSound, crusher.CenterPosition);
|
||||
var wda = self.TraitOrDefault<WithDeathAnimation>();
|
||||
if (wda != null)
|
||||
{
|
||||
var palette = wda.Info.CrushedSequencePalette;
|
||||
if (wda.Info.CrushedPaletteIsPlayerPalette)
|
||||
palette += self.Owner.InternalName;
|
||||
|
||||
wda.SpawnDeathAnimation(self, wda.Info.CrushedSequence, palette);
|
||||
}
|
||||
|
||||
self.Kill(crusher);
|
||||
}
|
||||
|
||||
public bool CrushableBy(string[] crushClasses, Player crushOwner)
|
||||
{
|
||||
if (!info.CrushedByFriendlies && crushOwner.IsAlliedWith(self.Owner))
|
||||
return false;
|
||||
|
||||
return info.CrushClasses.Intersect(crushClasses).Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class ExplodesInfo : ITraitInfo
|
||||
{
|
||||
[WeaponReference]
|
||||
public readonly string Weapon = "UnitExplode";
|
||||
[WeaponReference]
|
||||
public readonly string EmptyWeapon = "UnitExplode";
|
||||
|
||||
public readonly int Chance = 100;
|
||||
public readonly string[] DeathType = null;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Explodes(this); }
|
||||
}
|
||||
|
||||
class Explodes : INotifyKilled
|
||||
{
|
||||
readonly ExplodesInfo explodesInfo;
|
||||
|
||||
public Explodes(ExplodesInfo info) { explodesInfo = info; }
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
if (!self.IsInWorld)
|
||||
return;
|
||||
|
||||
if (self.World.SharedRandom.Next(100) > explodesInfo.Chance)
|
||||
return;
|
||||
|
||||
if (explodesInfo.DeathType != null && e.Warhead != null && !explodesInfo.DeathType.Contains(e.Warhead.DeathType))
|
||||
return;
|
||||
|
||||
var weaponName = ChooseWeaponForExplosion(self);
|
||||
if (weaponName != null)
|
||||
{
|
||||
var weapon = e.Attacker.World.Map.Rules.Weapons[weaponName.ToLowerInvariant()];
|
||||
if (weapon.Report != null && weapon.Report.Any())
|
||||
Sound.Play(weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition);
|
||||
|
||||
// Use .FromPos since this actor is killed. Cannot use Target.FromActor
|
||||
weapon.Impact(Target.FromPos(self.CenterPosition), e.Attacker, Enumerable.Empty<int>());
|
||||
}
|
||||
}
|
||||
|
||||
string ChooseWeaponForExplosion(Actor self)
|
||||
{
|
||||
var shouldExplode = self.TraitsImplementing<IExplodeModifier>().All(a => a.ShouldExplode(self));
|
||||
return shouldExplode ? explodesInfo.Weapon : explodesInfo.EmptyWeapon;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("The player can give this unit the order to follow and protect friendly units with the Guardable trait.")]
|
||||
class GuardInfo : TraitInfo<Guard> { }
|
||||
|
||||
class Guard : IResolveOrder, IOrderVoice
|
||||
{
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Guard")
|
||||
{
|
||||
var target = Target.FromActor(order.TargetActor);
|
||||
|
||||
GuardTarget(self, target);
|
||||
}
|
||||
}
|
||||
|
||||
public void GuardTarget(Actor self, Target target)
|
||||
{
|
||||
self.SetTargetLine(target, Color.Yellow);
|
||||
|
||||
var range = WRange.FromCells(target.Actor.Info.Traits.Get<GuardableInfo>().Range);
|
||||
self.QueueActivity(false, new AttackMoveActivity(self, self.Trait<IMove>().MoveFollow(self, target, WRange.Zero, range)));
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return order.OrderString == "Guard" ? "Move" : null;
|
||||
}
|
||||
}
|
||||
|
||||
class GuardOrderGenerator : IOrderGenerator
|
||||
{
|
||||
readonly IEnumerable<Actor> subjects;
|
||||
|
||||
public GuardOrderGenerator(IEnumerable<Actor> subjects)
|
||||
{
|
||||
this.subjects = subjects;
|
||||
}
|
||||
|
||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == MouseButton.Left)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
yield break;
|
||||
}
|
||||
|
||||
var target = FriendlyGuardableUnits(world, mi).FirstOrDefault();
|
||||
|
||||
if (target == null || subjects.All(s => s.IsDead))
|
||||
yield break;
|
||||
|
||||
foreach (var subject in subjects)
|
||||
if (subject != target)
|
||||
yield return new Order("Guard", subject, false) { TargetActor = target };
|
||||
}
|
||||
|
||||
public void Tick(World world)
|
||||
{
|
||||
if (subjects.All(s => s.IsDead || !s.HasTrait<Guard>()))
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
||||
|
||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
if (!subjects.Any())
|
||||
return null;
|
||||
|
||||
var multiple = subjects.Count() > 1;
|
||||
var canGuard = FriendlyGuardableUnits(world, mi)
|
||||
.Any(a => multiple || a != subjects.First());
|
||||
|
||||
return canGuard ? "guard" : "move-blocked";
|
||||
}
|
||||
|
||||
static IEnumerable<Actor> FriendlyGuardableUnits(World world, MouseInput mi)
|
||||
{
|
||||
return world.ScreenMap.ActorsAt(mi)
|
||||
.Where(a => !world.FogObscures(a) && !a.IsDead &&
|
||||
a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor) &&
|
||||
a.HasTrait<Guardable>());
|
||||
}
|
||||
}
|
||||
|
||||
[Desc("This unit can be guarded (followed and protected) by a Guard unit.")]
|
||||
class GuardableInfo : TraitInfo<Guardable>
|
||||
{
|
||||
public readonly int Range = 2;
|
||||
}
|
||||
|
||||
class Guardable { }
|
||||
}
|
||||
@@ -95,11 +95,9 @@
|
||||
<Compile Include="Activities\LayMines.cs" />
|
||||
<Compile Include="Activities\Leap.cs" />
|
||||
<Compile Include="Activities\RAHarvesterDockSequence.cs" />
|
||||
<Compile Include="Activities\Sell.cs" />
|
||||
<Compile Include="Activities\Teleport.cs" />
|
||||
<Compile Include="Activities\Transform.cs" />
|
||||
<Compile Include="AI\SupportPowerDecision.cs" />
|
||||
<Compile Include="Crushable.cs" />
|
||||
<Compile Include="Effects\GpsSatellite.cs" />
|
||||
<Compile Include="Effects\SatelliteLaunch.cs" />
|
||||
<Compile Include="Effects\TeslaZap.cs" />
|
||||
@@ -116,7 +114,6 @@
|
||||
<Compile Include="ExternalCapturableBar.cs" />
|
||||
<Compile Include="Capturable.cs" />
|
||||
<Compile Include="ExternalCaptures.cs" />
|
||||
<Compile Include="CashTrickler.cs" />
|
||||
<Compile Include="Traits\PaletteEffects\ChronoshiftPaletteEffect.cs" />
|
||||
<Compile Include="Traits\Chronoshiftable.cs" />
|
||||
<Compile Include="CrateSpawner.cs" />
|
||||
@@ -138,8 +135,6 @@
|
||||
<Compile Include="Effects\Parachute.cs" />
|
||||
<Compile Include="Effects\RepairIndicator.cs" />
|
||||
<Compile Include="EmitInfantryOnSell.cs" />
|
||||
<Compile Include="Explodes.cs" />
|
||||
<Compile Include="Guard.cs" />
|
||||
<Compile Include="Invulnerable.cs" />
|
||||
<Compile Include="Captures.cs" />
|
||||
<Compile Include="Lint\CheckActorReferences.cs" />
|
||||
@@ -178,8 +173,6 @@
|
||||
<Compile Include="Repairable.cs" />
|
||||
<Compile Include="RepairableNear.cs" />
|
||||
<Compile Include="ScaredyCat.cs" />
|
||||
<Compile Include="SelfHealing.cs" />
|
||||
<Compile Include="Sellable.cs" />
|
||||
<Compile Include="SpawnMPUnits.cs" />
|
||||
<Compile Include="Disguise.cs" />
|
||||
<Compile Include="StoresResources.cs" />
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("Attach this to actors which should be able to regenerate their health points.")]
|
||||
class SelfHealingInfo : UpgradableTraitInfo, ITraitInfo, Requires<HealthInfo>
|
||||
{
|
||||
public readonly int Step = 5;
|
||||
public readonly int Ticks = 5;
|
||||
public readonly float HealIfBelow = .5f;
|
||||
public readonly int DamageCooldown = 0;
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new SelfHealing(init.Self, this); }
|
||||
}
|
||||
|
||||
class SelfHealing : UpgradableTrait<SelfHealingInfo>, ITick, INotifyDamage
|
||||
{
|
||||
readonly Health health;
|
||||
|
||||
[Sync] int ticks;
|
||||
[Sync] int damageTicks;
|
||||
|
||||
public SelfHealing(Actor self, SelfHealingInfo info)
|
||||
: base(info)
|
||||
{
|
||||
health = self.Trait<Health>();
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (self.IsDead || IsTraitDisabled)
|
||||
return;
|
||||
|
||||
if (health.HP >= Info.HealIfBelow * health.MaxHP)
|
||||
return;
|
||||
|
||||
if (damageTicks > 0)
|
||||
{
|
||||
--damageTicks;
|
||||
return;
|
||||
}
|
||||
|
||||
if (--ticks <= 0)
|
||||
{
|
||||
ticks = Info.Ticks;
|
||||
self.InflictDamage(self, -Info.Step, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (e.Damage > 0)
|
||||
damageTicks = Info.DamageCooldown;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Actor can be sold")]
|
||||
public class SellableInfo : UpgradableTraitInfo, ITraitInfo
|
||||
{
|
||||
public readonly int RefundPercent = 50;
|
||||
public readonly string[] SellSounds = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new Sellable(this); }
|
||||
}
|
||||
|
||||
public class Sellable : UpgradableTrait<SellableInfo>, IResolveOrder
|
||||
{
|
||||
public Sellable(SellableInfo info)
|
||||
: base(info) { }
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Sell")
|
||||
Sell(self);
|
||||
}
|
||||
|
||||
public void Sell(Actor self)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return;
|
||||
|
||||
var building = self.TraitOrDefault<Building>();
|
||||
if (building != null && !building.Lock())
|
||||
return;
|
||||
|
||||
self.CancelActivity();
|
||||
|
||||
foreach (var s in Info.SellSounds)
|
||||
Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
|
||||
|
||||
foreach (var ns in self.TraitsImplementing<INotifySold>())
|
||||
ns.Selling(self);
|
||||
|
||||
var makeAnimation = self.TraitOrDefault<WithMakeAnimation>();
|
||||
if (makeAnimation != null)
|
||||
makeAnimation.Reverse(self, new Sell());
|
||||
else
|
||||
self.QueueActivity(new Sell());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
|
||||
Reference in New Issue
Block a user