Add WormAttack notification, fix worm min count and spawn interval

Enhance usage of WormManager Minimum and Maximum properties, add escape radius to AttackSwallow
This commit is contained in:
penev92
2014-12-03 06:29:49 +02:00
parent b4d1a605da
commit f57625f9e6
8 changed files with 89 additions and 54 deletions

View File

@@ -8,11 +8,12 @@
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.D2k
@@ -21,9 +22,13 @@ namespace OpenRA.Mods.D2k
class SwallowActor : Activity
{
const int NearEnough = 1;
readonly CPos location;
readonly Target target;
readonly WeaponInfo weapon;
readonly RenderUnit renderUnit;
readonly RadarPings radarPings;
readonly AttackSwallow swallow;
readonly IPositionable positionable;
@@ -34,18 +39,23 @@ namespace OpenRA.Mods.D2k
{
this.target = target;
this.weapon = weapon;
positionable = self.TraitOrDefault<Mobile>();
swallow = self.TraitOrDefault<AttackSwallow>();
renderUnit = self.TraitOrDefault<RenderUnit>();
countdown = swallow.AttackSwallowInfo.AttackTime;
positionable = self.Trait<Mobile>();
swallow = self.Trait<AttackSwallow>();
renderUnit = self.Trait<RenderUnit>();
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
countdown = swallow.Info.AttackTime;
renderUnit.DefaultAnimation.ReplaceAnim("burrowed");
stance = AttackState.Burrowed;
location = target.Actor.Location;
}
bool WormAttack(Actor worm)
{
var targetLocation = target.Actor.Location;
// The target has moved too far away
if ((location - targetLocation).Length > NearEnough)
return false;
var lunch = worm.World.ActorMap.GetUnitsAt(targetLocation)
.Where(t => !t.Equals(worm) && weapon.IsValidAgainst(t, worm));
@@ -54,11 +64,17 @@ namespace OpenRA.Mods.D2k
stance = AttackState.EmergingAboveGround;
lunch.Do(t => t.World.AddFrameEndTask(_ => { t.World.Remove(t); t.Kill(t); })); // Dispose of the evidence (we don't want husks)
foreach (var actor in lunch)
actor.World.AddFrameEndTask(_ => actor.Destroy());
positionable.SetPosition(worm, targetLocation);
PlayAttackAnimation(worm);
var attackPosition = worm.CenterPosition;
var affectedPlayers = lunch.Select(x => x.Owner).Distinct();
foreach (var affectedPlayer in affectedPlayers)
NotifyPlayer(affectedPlayer, attackPosition);
return true;
}
@@ -68,6 +84,12 @@ namespace OpenRA.Mods.D2k
renderUnit.PlayCustomAnim(self, "mouth");
}
void NotifyPlayer(Player player, WPos location)
{
Sound.PlayNotification(player.World.Map.Rules, player, "Speech", swallow.Info.WormAttackNotification, player.Country.Race);
radarPings.Add(() => true, location, Color.Red, 50);
}
public override Activity Tick(Actor self)
{
if (countdown > 0)
@@ -78,17 +100,17 @@ namespace OpenRA.Mods.D2k
if (stance == AttackState.ReturningUnderground) // Wait for the worm to get back underground
{
if (self.World.SharedRandom.Next()%2 == 0) // There is a 50-50 chance that the worm would just go away
if (self.World.SharedRandom.Next() % 2 == 0) // There is a 50-50 chance that the worm would just go away
{
self.CancelActivity();
self.World.AddFrameEndTask(w => w.Remove(self));
var wormManager = self.World.WorldActor.TraitOrDefault<WormManager>();
if (wormManager != null)
wormManager.DecreaseWorms();
self.CancelActivity();
self.World.AddFrameEndTask(w => w.Remove(self));
var wormManager = self.World.WorldActor.TraitOrDefault<WormManager>();
if (wormManager != null)
wormManager.DecreaseWorms();
}
else
{
renderUnit.DefaultAnimation.ReplaceAnim("idle");
renderUnit.DefaultAnimation.ReplaceAnim("idle");
}
return NextActivity;
}
@@ -96,14 +118,17 @@ namespace OpenRA.Mods.D2k
if (stance == AttackState.Burrowed) // Wait for the worm to get in position
{
// This is so that the worm cancels an attack against a target that has reached solid rock
if (positionable == null || !positionable.CanEnterCell(target.Actor.Location, null, false))
if (!positionable.CanEnterCell(target.Actor.Location, null, false))
return NextActivity;
var success = WormAttack(self);
if (!success)
{
renderUnit.DefaultAnimation.ReplaceAnim("idle");
return NextActivity;
}
countdown = swallow.AttackSwallowInfo.ReturnTime;
countdown = swallow.Info.ReturnTime;
stance = AttackState.ReturningUnderground;
}