Shift temporary owner-change logic from D2k to Common.
This commit is contained in:
committed by
abcdefg30
parent
38f415255b
commit
c4b5ec5241
@@ -74,14 +74,12 @@
|
||||
<Compile Include="Traits\Render\WithDeliveryOverlay.cs" />
|
||||
<Compile Include="Traits\Sandworm.cs" />
|
||||
<Compile Include="Traits\SpiceBloom.cs" />
|
||||
<Compile Include="Traits\TemporaryOwnerManager.cs" />
|
||||
<Compile Include="Traits\World\BuildableTerrainLayer.cs" />
|
||||
<Compile Include="Traits\World\D2kResourceLayer.cs" />
|
||||
<Compile Include="Traits\World\FogPaletteFromR8.cs" />
|
||||
<Compile Include="Traits\World\PaletteFromR8.cs" />
|
||||
<Compile Include="Traits\World\PaletteFromScaledPalette.cs" />
|
||||
<Compile Include="Traits\AttractsWorms.cs" />
|
||||
<Compile Include="Warheads\ChangeOwnerWarhead.cs" />
|
||||
<Compile Include="UtilityCommands\D2kMapImporter.cs" />
|
||||
<Compile Include="UtilityCommands\ImportD2kMapCommand.cs" />
|
||||
<Compile Include="Traits\World\D2kEditorResourceLayer.cs" />
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2018 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.Drawing;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.D2k.Traits
|
||||
{
|
||||
[Desc("Interacts with the ChangeOwner warhead.",
|
||||
"Displays a bar how long this actor is affected and reverts back to the old owner on temporary changes.")]
|
||||
public class TemporaryOwnerManagerInfo : ITraitInfo
|
||||
{
|
||||
public readonly Color BarColor = Color.Orange;
|
||||
|
||||
public object Create(ActorInitializer init) { return new TemporaryOwnerManager(init.Self, this); }
|
||||
}
|
||||
|
||||
public class TemporaryOwnerManager : ISelectionBar, ITick, ISync, INotifyOwnerChanged
|
||||
{
|
||||
readonly TemporaryOwnerManagerInfo info;
|
||||
|
||||
Player originalOwner;
|
||||
Player changingOwner;
|
||||
|
||||
[Sync] int remaining = -1;
|
||||
int duration;
|
||||
|
||||
public TemporaryOwnerManager(Actor self, TemporaryOwnerManagerInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
originalOwner = self.Owner;
|
||||
}
|
||||
|
||||
public void ChangeOwner(Actor self, Player newOwner, int duration)
|
||||
{
|
||||
remaining = this.duration = duration;
|
||||
changingOwner = newOwner;
|
||||
self.ChangeOwner(newOwner);
|
||||
}
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
{
|
||||
if (!self.IsInWorld)
|
||||
return;
|
||||
|
||||
if (--remaining == 0)
|
||||
{
|
||||
changingOwner = originalOwner;
|
||||
self.ChangeOwner(originalOwner);
|
||||
self.CancelActivity(); // Stop shooting, you have got new enemies
|
||||
}
|
||||
}
|
||||
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
if (changingOwner == null || changingOwner != newOwner)
|
||||
originalOwner = newOwner; // It wasn't a temporary change, so we need to update here
|
||||
else
|
||||
changingOwner = null; // It was triggered by this trait: reset
|
||||
}
|
||||
|
||||
float ISelectionBar.GetValue()
|
||||
{
|
||||
if (remaining <= 0)
|
||||
return 0;
|
||||
|
||||
return (float)remaining / duration;
|
||||
}
|
||||
|
||||
Color ISelectionBar.GetColor()
|
||||
{
|
||||
return info.BarColor;
|
||||
}
|
||||
|
||||
bool ISelectionBar.DisplayWhenEmpty { get { return false; } }
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2018 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.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Warheads;
|
||||
using OpenRA.Mods.D2k.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.D2k.Warheads
|
||||
{
|
||||
[Desc("Interacts with the DynamicOwnerChange trait.")]
|
||||
public class ChangeOwnerWarhead : Warhead
|
||||
{
|
||||
[Desc("Duration of the owner change (in ticks). Set to 0 to make it permanent.")]
|
||||
public readonly int Duration = 0;
|
||||
|
||||
public readonly WDist Range = WDist.FromCells(1);
|
||||
|
||||
public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
|
||||
{
|
||||
var actors = target.Type == TargetType.Actor ? new[] { target.Actor } :
|
||||
firedBy.World.FindActorsInCircle(target.CenterPosition, Range);
|
||||
|
||||
foreach (var a in actors)
|
||||
{
|
||||
// Don't do anything on friendly fire
|
||||
if (a.Owner == firedBy.Owner)
|
||||
continue;
|
||||
|
||||
if (Duration == 0)
|
||||
a.ChangeOwner(firedBy.Owner); // Permanent
|
||||
else
|
||||
{
|
||||
var tempOwnerManager = a.TraitOrDefault<TemporaryOwnerManager>();
|
||||
if (tempOwnerManager == null)
|
||||
continue;
|
||||
|
||||
tempOwnerManager.ChangeOwner(a, firedBy.Owner, Duration);
|
||||
}
|
||||
|
||||
// Stop shooting, you have new enemies
|
||||
a.CancelActivity();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user