Move ScaredyCat, TakeCover, RenderInfantry, WithBuildingExplosion and SpawnMPUnits as well as Hunt activity to Mods.Common.
This commit is contained in:
91
OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs
Normal file
91
OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
#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.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Makes the unit automatically run around when taking damage.")]
|
||||
class ScaredyCatInfo : ITraitInfo
|
||||
{
|
||||
[Desc("How long (in ticks) the actor should panic for.")]
|
||||
public readonly int PanicLength = 25 * 10;
|
||||
|
||||
[Desc("Panic movement speed as a precentage of the normal speed.")]
|
||||
public readonly int PanicSpeedModifier = 200;
|
||||
|
||||
[Desc("Chance (out of 100) the unit has to enter panic mode when attacked.")]
|
||||
public readonly int AttackPanicChance = 20;
|
||||
|
||||
public object Create(ActorInitializer init) { return new ScaredyCat(init.Self, this); }
|
||||
}
|
||||
|
||||
class ScaredyCat : ITick, INotifyIdle, INotifyDamage, INotifyAttack, ISpeedModifier, ISync, IRenderInfantrySequenceModifier
|
||||
{
|
||||
readonly ScaredyCatInfo info;
|
||||
[Sync] readonly Actor self;
|
||||
[Sync] int panicStartedTick;
|
||||
bool Panicking { get { return panicStartedTick > 0; } }
|
||||
|
||||
public bool IsModifyingSequence { get { return Panicking; } }
|
||||
public string SequencePrefix { get { return "panic-"; } }
|
||||
|
||||
public ScaredyCat(Actor self, ScaredyCatInfo info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void Panic()
|
||||
{
|
||||
if (!Panicking)
|
||||
self.CancelActivity();
|
||||
|
||||
panicStartedTick = self.World.WorldTick;
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (!Panicking)
|
||||
return;
|
||||
|
||||
if (self.World.WorldTick >= panicStartedTick + info.PanicLength)
|
||||
{
|
||||
self.CancelActivity();
|
||||
panicStartedTick = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void TickIdle(Actor self)
|
||||
{
|
||||
if (!Panicking)
|
||||
return;
|
||||
|
||||
self.Trait<Mobile>().Nudge(self, self, true);
|
||||
}
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (e.Damage > 0)
|
||||
Panic();
|
||||
}
|
||||
|
||||
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
||||
{
|
||||
if (self.World.SharedRandom.Next(100 / info.AttackPanicChance) == 0)
|
||||
Panic();
|
||||
}
|
||||
|
||||
public int GetSpeedModifier()
|
||||
{
|
||||
return Panicking ? info.PanicSpeedModifier : 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user