Assign Player.IsBot before calling INotifyCreated.Created

This commit is contained in:
abcdefg30
2020-05-25 17:24:13 +02:00
committed by reaperrr
parent 27d0465891
commit 44d3691fa1
2 changed files with 5 additions and 10 deletions

View File

@@ -166,6 +166,9 @@ namespace OpenRA
if (!Spectating)
PlayerMask = new LongBitSet<PlayerBitMask>(InternalName);
// Set this property before running any Created callbacks on the player actor
IsBot = BotType != null;
// Special case handling is required for the Player actor:
// Since Actor.Created would be called before PlayerActor is assigned here
// querying player traits in INotifyCreated.Created would crash.
@@ -179,7 +182,6 @@ namespace OpenRA
FrozenActorLayer = PlayerActor.TraitOrDefault<FrozenActorLayer>();
// Enable the bot logic on the host
IsBot = BotType != null;
if (IsBot && Game.IsHost)
{
var logic = PlayerActor.TraitsImplementing<IBot>().FirstOrDefault(b => b.Info.Type == BotType);

View File

@@ -42,15 +42,8 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.IsBot is set, so we
// must use a different method to enable this trait if
// it's defined on the PlayerActor.
self.World.AddFrameEndTask(w =>
{
if (self.Owner.IsBot && info.Bots.Contains(self.Owner.BotType))
conditionToken = self.GrantCondition(info.Condition);
});
if (self.Owner.IsBot && info.Bots.Contains(self.Owner.BotType))
conditionToken = self.GrantCondition(info.Condition);
}
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)