Hmm...still don't know what's going on. Still compiles fine after changing INotifyCreated to INotifyAddedToWorld, but condition still doesn't respond as expected. The flaw in my code is not apparent to me.
My flow goes something like this:
1. If actor exists in the world, LoadedCondition is not null, and the actor is not loaded into anything else, grant LoadedCondition to the actor
2. If actor does not exist in the world and the actor is loaded, revoke LoadedCondition.
I don't know why GrantCondition turns on when the actor is loaded / does not exist in the world, and why RevokeCondition does not turn on when the actor is unloaded / exists in the world.
Code: Select all
protected override void Created(Actor self)
{
conditionManager = self.Trait<ConditionManager>();
base.Created(self);
}
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self) {
Unreserve(self);
if (!self.World.Map.Contains(self.Location) && conditionManager != null && loadedToken == ConditionManager.InvalidConditionToken &&
!string.IsNullOrEmpty(Info.LoadedCondition))
loadedToken = conditionManager.GrantCondition(self, Info.LoadedCondition);
}
void INotifyAddedToWorld.AddedToWorld(Actor self)
{
if (self.World.Map.Contains(self.Location) && loadedToken != ConditionManager.InvalidConditionToken)
loadedToken = conditionManager.RevokeCondition(self, loadedToken);
}
public void Unreserve(Actor self)
{
if (ReservedCargo == null)
return;
ReservedCargo.UnreserveSpace(self);
ReservedCargo = null;
}