Esempio n. 1
0
        public static void Prefix(TurnDirector __instance)
        {
            Mod.Log.Trace?.Write("TD:OEB:pre entered.");

            // Initialize the probabilities
            ModState.InitializeCheckResults();
            ModState.InitMapConfig();
            ModState.TurnDirectorStarted = true;

            // Do a pre-encounter populate
            if (__instance != null && __instance.Combat != null && __instance.Combat.AllActors != null)
            {
                // If we are coming from a save, don't recalculate everything - just roll with what we already have
                if (!IsFromSave)
                {
                    AbstractActor randomPlayerActor = null;
                    foreach (AbstractActor actor in __instance.Combat.AllActors)
                    {
                        if (actor != null)
                        {
                            // Make a pre-encounter detectCheck for them
                            ActorHelper.UpdateSensorCheck(actor, false);

                            bool isPlayer = actor.TeamId == __instance.Combat.LocalPlayerTeamGuid;
                            if (isPlayer && randomPlayerActor == null)
                            {
                                randomPlayerActor = actor;
                            }
                        }
                        else
                        {
                            Mod.Log.Debug?.Write($"  Actor:{CombatantUtils.Label(actor)} was NULL!");
                        }
                    }

                    if (randomPlayerActor != null)
                    {
                        Mod.Log.Debug?.Write($"Assigning actor: {CombatantUtils.Label(randomPlayerActor)} as lastActive.");
                        ModState.LastPlayerActorActivated = randomPlayerActor;
                    }
                }
            }

            // Initialize the VFX materials
            // TODO: Do a pooled instantiate here?
            VfxHelper.Initialize(__instance.Combat);

            // Attach to the message bus so we get updates on selected actor
            SelectedActorHelper.Combat = __instance.Combat;
            __instance.Combat.MessageCenter.Subscribe(MessageCenterMessageType.ActorSelectedMessage,
                                                      new ReceiveMessageCenterMessage(SelectedActorHelper.OnActorSelectedMessage), true);
            __instance.Combat.MessageCenter.Subscribe(MessageCenterMessageType.OnAuraAdded,
                                                      new ReceiveMessageCenterMessage(SelectedActorHelper.OnAuraAddedMessage), true);
            __instance.Combat.MessageCenter.Subscribe(MessageCenterMessageType.OnAuraRemoved,
                                                      new ReceiveMessageCenterMessage(SelectedActorHelper.OnAuraRemovedMessage), true);
        }