Add D2k harvester insurance on worm frenzy
This commit is contained in:
@@ -70,7 +70,23 @@ namespace OpenRA.Mods.D2k.Activities
|
|||||||
sandworm.IsAttacking = true;
|
sandworm.IsAttacking = true;
|
||||||
|
|
||||||
foreach (var actor in lunch)
|
foreach (var actor in lunch)
|
||||||
actor.World.AddFrameEndTask(_ => actor.Destroy());
|
{
|
||||||
|
var actor1 = actor; // loop variable in closure hazard
|
||||||
|
|
||||||
|
actor.World.AddFrameEndTask(_ =>
|
||||||
|
{
|
||||||
|
actor1.Destroy();
|
||||||
|
|
||||||
|
// Harvester insurance
|
||||||
|
if (!actor1.HasTrait<Harvester>())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var insurance = actor1.Owner.PlayerActor.TraitOrDefault<HarvesterInsurance>();
|
||||||
|
|
||||||
|
if (insurance != null)
|
||||||
|
actor1.World.AddFrameEndTask(__ => insurance.TryActivate());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
positionable.SetPosition(worm, targetLocation);
|
positionable.SetPosition(worm, targetLocation);
|
||||||
foreach (var notify in worm.TraitsImplementing<INotifyAttack>())
|
foreach (var notify in worm.TraitsImplementing<INotifyAttack>())
|
||||||
|
|||||||
@@ -79,6 +79,7 @@
|
|||||||
<Compile Include="Traits\Buildings\DamagedWithoutFoundation.cs" />
|
<Compile Include="Traits\Buildings\DamagedWithoutFoundation.cs" />
|
||||||
<Compile Include="Traits\Buildings\LaysTerrain.cs" />
|
<Compile Include="Traits\Buildings\LaysTerrain.cs" />
|
||||||
<Compile Include="Traits\Carryable.cs" />
|
<Compile Include="Traits\Carryable.cs" />
|
||||||
|
<Compile Include="Traits\Player\HarvesterInsurance.cs" />
|
||||||
<Compile Include="Traits\Render\WithCrumbleOverlay.cs" />
|
<Compile Include="Traits\Render\WithCrumbleOverlay.cs" />
|
||||||
<Compile Include="Traits\Render\WithDockingOverlay.cs" />
|
<Compile Include="Traits\Render\WithDockingOverlay.cs" />
|
||||||
<Compile Include="Traits\Render\WithDeliveryOverlay.cs" />
|
<Compile Include="Traits\Render\WithDeliveryOverlay.cs" />
|
||||||
|
|||||||
48
OpenRA.Mods.D2k/Traits/Player/HarvesterInsurance.cs
Normal file
48
OpenRA.Mods.D2k/Traits/Player/HarvesterInsurance.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 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.D2k.Traits
|
||||||
|
{
|
||||||
|
[Desc("A player with this trait will receive a free harvester when his last one gets eaten by a sandworm, provided he has at least one refinery.")]
|
||||||
|
public class HarvesterInsuranceInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public object Create(ActorInitializer init) { return new HarvesterInsurance(init.Self); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HarvesterInsurance
|
||||||
|
{
|
||||||
|
readonly Actor self;
|
||||||
|
|
||||||
|
public HarvesterInsurance(Actor self)
|
||||||
|
{
|
||||||
|
this.self = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TryActivate()
|
||||||
|
{
|
||||||
|
var harvesters = self.World.ActorsWithTrait<Harvester>().Where(x => x.Actor.Owner == self.Owner);
|
||||||
|
if (harvesters.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var refineries = self.World.ActorsWithTrait<Refinery>().Where(x => x.Actor.Owner == self.Owner);
|
||||||
|
if (!refineries.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var refinery = refineries.First().Actor;
|
||||||
|
var delivery = refinery.Trait<FreeActorWithDelivery>();
|
||||||
|
delivery.DoDelivery(refinery.Location + delivery.Info.DeliveryOffset, delivery.Info.Actor,
|
||||||
|
delivery.Info.DeliveringActor, delivery.Info.InitialActivity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,3 +73,4 @@ Player:
|
|||||||
Name: Unrestricted
|
Name: Unrestricted
|
||||||
Prerequisites: techlevel.low, techlevel.medium, techlevel.high, techlevel.superweapons
|
Prerequisites: techlevel.low, techlevel.medium, techlevel.high, techlevel.superweapons
|
||||||
EnemyWatcher:
|
EnemyWatcher:
|
||||||
|
HarvesterInsurance:
|
||||||
|
|||||||
Reference in New Issue
Block a user