Esempio n. 1
0
        public static void Team_AddUnit_Postfix(Team __instance, AbstractActor unit)
        {
            // The added unit is a reinforcement if round > 0
            if (__instance.Combat.TurnDirector.CurrentRound > 1 && Mod.Config.Combat.SpawnProtection.ApplyToReinforcements)
            {
                HostilityMatrix hm = __instance.Combat.HostilityMatrix;

                Mod.Log.Info($"Checking actor:{CombatantUtils.Label(unit)} that belongs to team:{unit?.team?.Name}");

                List <AbstractActor> actor = new List <AbstractActor>();
                if (hm.IsLocalPlayerEnemy(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToEnemies)
                {
                    actor.Add(unit);
                }
                else if (hm.IsLocalPlayerNeutral(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToNeutrals)
                {
                    actor.Add(unit);
                }
                else if (hm.IsLocalPlayerFriendly(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToAllies)
                {
                    actor.Add(unit);
                }

                if (actor.Count == 1)
                {
                    Mod.Log.Info($"Applying protection to reinforcement:{CombatantUtils.Label(unit)}");
                    ProtectionHelper.ProtectActors(actor);
                }
            }
        }
Esempio n. 2
0
        public static void ProtectOnFirstRound()
        {
            Mod.Log.Info($"Protecting units on first turn'");
            CombatGameState combatState = UnityGameInstance.BattleTechGame.Combat;
            HostilityMatrix hm          = combatState.HostilityMatrix;
            Team            playerTeam  = combatState.LocalPlayerTeam;

            // Includes player units
            List <AbstractActor> actors = new List <AbstractActor>();

            foreach (AbstractActor actor in combatState.AllActors)
            {
                if (hm.IsLocalPlayerEnemy(actor.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToEnemies)
                {
                    actors.Add(actor);
                }
                else if (hm.IsLocalPlayerNeutral(actor.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToNeutrals)
                {
                    actors.Add(actor);
                }
                else if (hm.IsLocalPlayerFriendly(actor.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToAllies)
                {
                    actors.Add(actor);
                }
            }
            actors.AddRange(playerTeam.units);
            List <AbstractActor> actorsToProtect = actors.Distinct().ToList();

            ProtectActors(actorsToProtect);
        }
Esempio n. 3
0
        static void Postfix(Team __instance, AbstractActor unit)
        {
            if (__instance.Combat.TurnDirector.CurrentRound <= 1) // always protect on first round of contract.
            {
                HostilityMatrix hm = __instance.Combat.HostilityMatrix;

                Mod.Log.Info?.Write($"Checking actor:{CombatantUtils.Label(unit)} that belongs to team:{unit?.team?.Name}");

                if (hm.IsLocalPlayerEnemy(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToEnemies)
                {
                    ProtectionHelper.ProtectActor(unit);
                }
                else if (hm.IsLocalPlayerNeutral(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToNeutrals)
                {
                    ProtectionHelper.ProtectActor(unit);
                }
                else if (hm.IsLocalPlayerFriendly(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToAllies)
                {
                    ProtectionHelper.ProtectActor(unit);
                }
                else if (unit.team.IsLocalPlayer)
                {
                    ProtectionHelper.ProtectActor(unit);
                }
                else
                {
                    Mod.Log.Info?.Write($" -- skipping unknown actor: {unit.DistinctId()}");
                }
            }

            // The added unit is a reinforcement if round > 1
            else if (__instance.Combat.TurnDirector.CurrentRound > 1 && Mod.Config.Combat.SpawnProtection.ApplyToReinforcements)
            {
                HostilityMatrix hm = __instance.Combat.HostilityMatrix;

                Mod.Log.Info?.Write($"Checking actor:{CombatantUtils.Label(unit)} that belongs to team:{unit?.team?.Name}");

                if (hm.IsLocalPlayerEnemy(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToEnemies)
                {
                    ProtectionHelper.ProtectActor(unit);
                }
                else if (hm.IsLocalPlayerNeutral(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToNeutrals)
                {
                    ProtectionHelper.ProtectActor(unit);
                }
                else if (hm.IsLocalPlayerFriendly(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToAllies)
                {
                    ProtectionHelper.ProtectActor(unit);
                }
                else if (unit.team.IsLocalPlayer)
                {
                    ProtectionHelper.ProtectActor(unit);
                }
                else
                {
                    Mod.Log.Info?.Write($" -- skipping unknown actor: {unit.DistinctId()}");
                }
            }
        }
Esempio n. 4
0
        static void Postfix(TurnDirector __instance)
        {
            Mod.Log.Info?.Write($"Protecting lances on firstContact during first round:{__instance.CurrentRound}");
            if (__instance.CurrentRound == 1)
            {
                Mod.Log.Info?.Write($"Protecting units on first turn");
                CombatGameState combatState = UnityGameInstance.BattleTechGame.Combat;
                HostilityMatrix hm          = combatState.HostilityMatrix;
                Team            playerTeam  = combatState.LocalPlayerTeam;

                // Includes player units
                List <AbstractActor> actors = new List <AbstractActor>();
                foreach (AbstractActor actor in combatState.AllActors)
                {
                    if (hm.IsLocalPlayerEnemy(actor.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToEnemies)
                    {
                        Mod.Log.Info?.Write($" -- adding enemy actor: {actor.DistinctId()}");
                        actors.Add(actor);
                    }
                    else if (hm.IsLocalPlayerNeutral(actor.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToNeutrals)
                    {
                        Mod.Log.Info?.Write($" -- adding neutral actor: {actor.DistinctId()}");
                        actors.Add(actor);
                    }
                    else if (hm.IsLocalPlayerFriendly(actor.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToAllies)
                    {
                        Mod.Log.Info?.Write($" -- adding allied actor: {actor.DistinctId()}");
                        actors.Add(actor);
                    }
                    else if (actor.team.IsLocalPlayer)
                    {
                        Mod.Log.Info?.Write($" -- adding player actor: {actor.DistinctId()}");
                        actors.Add(actor);
                    }
                    else
                    {
                        Mod.Log.Info?.Write($" -- skipping unknown actor: {actor.DistinctId()}");
                    }
                }

                List <AbstractActor> actorsToProtect = actors.Distinct().ToList();

                ProtectionHelper.ProtectActors(actorsToProtect);
            }
        }