Use INotifyOwnerChanged for updating internal references.

This commit is contained in:
Paul Chote
2014-10-13 19:43:11 +13:00
parent 8508fc5155
commit a08a3a3869
12 changed files with 45 additions and 33 deletions

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA
public virtual object Create(ActorInitializer init) { return new OreRefinery(init.self, this); }
}
public class OreRefinery : ITick, IAcceptOre, INotifyKilled, INotifySold, INotifyCapture, IExplodeModifier, ISync
public class OreRefinery : ITick, IAcceptOre, INotifyKilled, INotifySold, INotifyCapture, INotifyOwnerChanged, IExplodeModifier, ISync
{
readonly Actor self;
readonly OreRefineryInfo Info;
@@ -117,18 +117,25 @@ namespace OpenRA.Mods.RA
harv.QueueActivity(new CallFunc(() => harv.Trait<Harvester>().ContinueHarvesting(harv)));
}
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
// Unlink any harvesters
foreach (var harv in GetLinkedHarvesters())
harv.Trait.UnlinkProc(harv.Actor, self);
PlayerResources = newOwner.PlayerActor.Trait<PlayerResources>();
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
// Steal any docked harv too
if (dockedHarv != null)
{
dockedHarv.ChangeOwner(newOwner);
// Unlink any non-docked harvs
foreach (var harv in GetLinkedHarvesters())
if (harv.Actor.Owner == oldOwner)
harv.Trait.UnlinkProc(harv.Actor, self);
PlayerResources = newOwner.PlayerActor.Trait<PlayerResources>();
// Relink to this refinery
dockedHarv.Trait<Harvester>().LinkProc(dockedHarv, self);
}
}
public void Selling(Actor self) { CancelDock(self); }