Пример #1
0
            public int SpawnTroops(int number, bool isReinforcement, bool enforceSpawningOnInitialPoint = false)
            {
                if (number <= 0)
                {
                    return(0);
                }
                int formationTroopIndex = 0;
                List <IAgentOriginBase> agentOriginBaseList1 = new List <IAgentOriginBase>();
                int count1 = Math.Min(this._preSuppliedTroops.Count, number);

                if (count1 > 0)
                {
                    for (int index = 0; index < count1; ++index)
                    {
                        agentOriginBaseList1.Add(this._preSuppliedTroops[index]);
                    }
                    this._preSuppliedTroops.RemoveRange(0, count1);
                }
                int numberToAllocate = number - count1;

                agentOriginBaseList1.AddRange(this._troopSupplier.SupplyTroops(numberToAllocate));
                List <IAgentOriginBase> agentOriginBaseList2 = new List <IAgentOriginBase>();

                for (int index = 0; index < 8; ++index)
                {
                    agentOriginBaseList2.Clear();
                    IAgentOriginBase agentOriginBase1 = (IAgentOriginBase)null;
                    FormationClass   formationClass   = (FormationClass)index;
                    foreach (IAgentOriginBase agentOriginBase2 in agentOriginBaseList1)
                    {
                        if (formationClass == agentOriginBase2.Troop.GetFormationClass(agentOriginBase2.BattleCombatant))
                        {
                            if (agentOriginBase2.Troop == Game.Current.PlayerTroop)
                            {
                                agentOriginBase1 = agentOriginBase2;
                            }
                            else
                            {
                                agentOriginBaseList2.Add(agentOriginBase2);
                            }
                        }
                    }
                    if (agentOriginBase1 != null)
                    {
                        agentOriginBaseList2.Add(agentOriginBase1);
                    }
                    int count2 = agentOriginBaseList2.Count;
                    if (count2 > 0)
                    {
                        foreach (IAgentOriginBase troopOrigin in agentOriginBaseList2)
                        {
                            Formation formation = Mission.GetAgentTeam(troopOrigin, this.IsPlayerSide).GetFormation(formationClass);
                            bool      isMounted = this._spawnWithHorses && (formationClass == FormationClass.Cavalry || formationClass == FormationClass.LightCavalry || formationClass == FormationClass.HeavyCavalry || formationClass == FormationClass.HorseArcher);
                            if (formation != null && !formation.HasBeenPositioned)
                            {
                                formation.BeginSpawn(count2, isMounted);
                                Mission.Current.SpawnFormation(formation, count2, this._spawnWithHorses, isMounted, isReinforcement);
                                this._spawnedFormations.Add(formation);
                            }
                            Mission.Current.SpawnTroop(troopOrigin, this.IsPlayerSide, true, this._spawnWithHorses, isReinforcement, enforceSpawningOnInitialPoint, count2, formationTroopIndex, true, true);
                            ++formationTroopIndex;
                        }
                    }
                }
                if (formationTroopIndex > 0)
                {
                    foreach (Team team in (ReadOnlyCollection <Team>)Mission.Current.Teams)
                    {
                        team.QuerySystem.Expire();
                    }
                    Debug.Print(formationTroopIndex.ToString() + " troops spawned on " + (object)this._side + " side.", color: Debug.DebugColor.DarkGreen, debugFilter: 64UL);
                }
                foreach (Team team in (ReadOnlyCollection <Team>)Mission.Current.Teams)
                {
                    foreach (Formation formation in team.Formations)
                    {
                        formation.GroupSpawnIndex = 0;
                    }
                }
                return(formationTroopIndex);
            }
Пример #2
0
        public static bool SpawnTroops_Prefix(int number, bool isReinforcement, bool enforceSpawningOnInitialPoint, ref int __result,
                                              IMissionTroopSupplier ____troopSupplier,
                                              bool ____spawnWithHorses, BattleSideEnum ____side, MBList <Formation> ____spawnedFormations)
        {
            if (number <= 0)
            {
                __result = 0;
                return(false);
            }
            int formationTroopIndex      = 0;
            List <IAgentOriginBase> list = ____troopSupplier.SupplyTroops(number).ToList();

            Mission.Current.ResetTotalWidth();
            for (int index = 0; index < 8; ++index)
            {
                var originToSpawn = new List <EnhancedBattleTestAgentOrigin>();
                EnhancedBattleTestAgentOrigin player = null;
                bool           isMounted             = false;
                FormationClass formationIndex        = (FormationClass)index;
                foreach (IAgentOriginBase agentOriginBase in list)
                {
                    if (agentOriginBase is EnhancedBattleTestAgentOrigin agentOrigin &&
                        formationIndex == agentOrigin.FormationIndex)
                    {
                        if (agentOrigin.SpawnableCharacter.IsPlayer)
                        {
                            player = agentOrigin;
                        }
                        else
                        {
                            originToSpawn.Add(agentOrigin);
                        }

                        isMounted = isMounted || agentOrigin.Troop.HasMount();
                    }
                }

                if (player != null)
                {
                    originToSpawn.Add(player);
                }

                int count = originToSpawn.Count;
                if (count <= 0)
                {
                    continue;
                }

                float num1 = isMounted ? 3f : 1f;
                float num2 = isMounted ? 0.75f : 0.6f;
                Mission.Current.SetTotalWidthBeforeNewFormation(num1 * (float)Math.Pow(count, num2));
                foreach (EnhancedBattleTestAgentOrigin agentOriginBase in originToSpawn)
                {
                    try
                    {
                        FormationClass formationClass = agentOriginBase.SpawnableCharacter.FormationIndex;
                        var            team           = agentOriginBase.IsUnderPlayersCommand ? Mission.Current.PlayerTeam : Mission.Current.PlayerEnemyTeam;
                        Formation      formation      = team.GetFormation(formationClass);
                        if (formation != null && !(bool)HasBeenPositionedProperty.GetValue(formation))
                        {
                            formation.BeginSpawn(count, isMounted);
                            Mission.Current.SpawnFormation(formation, count, ____spawnWithHorses, isMounted, isReinforcement);
                            ____spawnedFormations.Add(formation);
                        }
                        agentOriginBase.SpawnTroop(____side, true, ____spawnWithHorses, isReinforcement,
                                                   enforceSpawningOnInitialPoint, count, formationTroopIndex, true, true,
                                                   false, null, new MatrixFrame?());
                        ++formationTroopIndex;
                    }
                    catch (Exception e)
                    {
                        Utility.DisplayMessage(e.ToString());
                    }
                }
            }
            if (formationTroopIndex > 0)
            {
                foreach (Team team in Mission.Current.Teams)
                {
                    team.ExpireAIQuerySystem();
                }
                Debug.Print(formationTroopIndex + " troops spawned on " + ____side + " side.", 0, Debug.DebugColor.DarkGreen, 64UL);
            }
            foreach (Team team in Mission.Current.Teams)
            {
                foreach (Formation formation in team.Formations)
                {
                    typeof(Formation).GetField("GroupSpawnIndex", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(formation, 0);
                }
            }
            __result = formationTroopIndex;
            return(false);
        }