From 44d3691fa1e36b7e38ef976e246f1af74ac13d46 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Mon, 25 May 2020 17:24:13 +0200 Subject: [PATCH] Assign Player.IsBot before calling INotifyCreated.Created --- OpenRA.Game/Player.cs | 4 +++- .../Traits/Conditions/GrantConditionOnBotOwner.cs | 11 ++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 5752bfd80a..165792c055 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -166,6 +166,9 @@ namespace OpenRA if (!Spectating) PlayerMask = new LongBitSet(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(); // Enable the bot logic on the host - IsBot = BotType != null; if (IsBot && Game.IsHost) { var logic = PlayerActor.TraitsImplementing().FirstOrDefault(b => b.Info.Type == BotType); diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnBotOwner.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnBotOwner.cs index a47154d438..c9e9e52501 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnBotOwner.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnBotOwner.cs @@ -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)