Ejemplo n.º 1
0
        public override void Trigger(MessageCenterMessage inMessage, string triggeringName)
        {
            Main.LogDebug($"[SetTeamByTagResult] Setting Team '{Team}' with tags '{String.Concat(Tags)}'");
            List <ICombatant> combatants = ObjectiveGameLogic.GetTaggedCombatants(UnityGameInstance.BattleTechGame.Combat, new TagSet(Tags));

            Main.LogDebug($"[SetTeamByTagResult] Found '{combatants.Count}' combatants");
            Team  newTeam  = UnityGameInstance.BattleTechGame.Combat.ItemRegistry.GetItemByGUID <Team>(TeamUtils.GetTeamGuid(Team));
            Lance newLance = new Lance(newTeam);

            newLance.team = newTeam;

            foreach (ICombatant combatant in combatants)
            {
                if (combatant is AbstractActor)
                {
                    /*
                     * AbstractActor actor = combatant as AbstractActor;
                     *
                     * actor.lance.RemoveUnitGUID(actor.GUID);
                     * actor.RemoveFromLance();
                     * actor.team.RemoveUnit(actor);
                     *
                     * actor.AddToTeam(newTeam);
                     * newLance.AddUnitGUID(actor.GUID);
                     * actor.AddToLance(newLance);
                     * newLance.team.AddUnit(actor);
                     *
                     * actor.team.lances.Add(newLance);
                     */
                    Main.Logger.LogError($"[SetTeamByTagResult] Using this result with AbstractActors isn't supported yet");
                }
                else
                {
                    combatant.RemoveFromTeam();
                    combatant.AddToTeam(newTeam);
                }

                if (ApplyTags != null)
                {
                    combatant.EncounterTags.AddRange(ApplyTags);
                }

                CombatantSwitchedTeams message = new CombatantSwitchedTeams(combatant.GUID, newTeam.GUID);
                this.combat.MessageCenter.PublishMessage(message);

                LazySingletonBehavior <FogOfWarView> .Instance.FowSystem.Rebuild();
            }

            if (newLance.unitGuids.Count > 0)
            {
                newTeam.lances.Add(newLance);
                UnityGameInstance.BattleTechGame.Combat.ItemRegistry.AddItem(newLance);

                if (this.AlertLance)
                {
                    newLance.BroadcastAlert();
                }
            }
        }
        public override void Trigger(MessageCenterMessage inMessage, string triggeringName)
        {
            Main.LogDebug($"[SetTeamByLanceSpawnerGuid] Setting Team '{Team}' with Spawner Guid '{LanceSpawnerGuid}'");
            LanceSpawnerGameLogic spawnerGameLogic = UnityGameInstance.BattleTechGame.Combat.ItemRegistry.GetItemByGUID <LanceSpawnerGameLogic>(LanceSpawnerGuid);
            Lance lance = spawnerGameLogic.GetLance();
            List <AbstractActor> lanceUnits = spawnerGameLogic.GetLance().GetLanceUnits();

            Main.LogDebug($"[SetTeamByLanceSpawnerGuid] Found '{lanceUnits.Count}' lance units");
            Team oldTeam = UnityGameInstance.BattleTechGame.Combat.ItemRegistry.GetItemByGUID <Team>(spawnerGameLogic.teamDefinitionGuid);
            Team newTeam = UnityGameInstance.BattleTechGame.Combat.ItemRegistry.GetItemByGUID <Team>(TeamUtils.GetTeamGuid(Team));

            spawnerGameLogic.teamDefinitionGuid = TeamUtils.GetTeamGuid(Team);
            spawnerGameLogic.encounterTags.Remove(oldTeam.Name);
            spawnerGameLogic.encounterTags.Add(newTeam.Name);

            oldTeam.lances.Remove(lance);
            newTeam.lances.Add(lance);

            foreach (AbstractActor actor in lanceUnits)
            {
                oldTeam.RemoveUnit(actor);
                actor.AddToTeam(newTeam);
                newTeam.AddUnit(actor);

                actor.EncounterTags.Remove(oldTeam.Name);
                actor.EncounterTags.Add(newTeam.Name);

                if (ApplyTags != null)
                {
                    actor.EncounterTags.AddRange(ApplyTags);
                }

                CombatHUDInWorldElementMgr inworldElementManager = GameObject.Find("uixPrfPanl_HUD(Clone)").GetComponent <CombatHUDInWorldElementMgr>();
                if (oldTeam.GUID == TeamUtils.NEUTRAL_TO_ALL_TEAM_ID)
                {
                    AccessTools.Method(typeof(CombatHUDInWorldElementMgr), "AddInWorldActorElements").Invoke(inworldElementManager, new object[] { actor });
                }
                else if (newTeam.GUID == TeamUtils.NEUTRAL_TO_ALL_TEAM_ID)
                {
                    AccessTools.Method(typeof(CombatHUDInWorldElementMgr), "RemoveInWorldUI").Invoke(inworldElementManager, new object[] { actor.GUID });
                }

                CombatantSwitchedTeams message = new CombatantSwitchedTeams(actor.GUID, newTeam.GUID);
                this.combat.MessageCenter.PublishMessage(message);

                LazySingletonBehavior <FogOfWarView> .Instance.FowSystem.Rebuild();
            }

            if (this.AlertLance)
            {
                lance.BroadcastAlert();
            }
        }