Esempio n. 1
0
        public static FormationClass FallbackClass(this FormationClass formationClass)
        {
            switch (formationClass)
            {
            case FormationClass.Infantry:
            case FormationClass.HeavyInfantry:
            case FormationClass.NumberOfRegularFormations:
            case FormationClass.Bodyguard:
                return(FormationClass.Infantry);

            case FormationClass.Ranged:
            case FormationClass.NumberOfDefaultFormations:
                return(FormationClass.Ranged);

            case FormationClass.Cavalry:
            case FormationClass.HeavyCavalry:
                return(FormationClass.Cavalry);

            case FormationClass.HorseArcher:
            case FormationClass.LightCavalry:
                return(FormationClass.HorseArcher);

            default:
                return(FormationClass.Infantry);
            }
        }
Esempio n. 2
0
        private FormationDeploymentOrder(FormationClass formationClass, int offset = 0)
        {
            int formationClassPriority = FormationDeploymentOrder.GetFormationClassPriority(formationClass);

            this.Offset = Math.Max(0, offset);
            this.Key    = formationClassPriority + this.Offset * 11;
        }
Esempio n. 3
0
        public static void SetPlayerFormation(FormationClass formationClass)
        {
            var mission = Mission.Current;

            if (mission.MainAgent != null && Mission.Current.PlayerTeam != null &&
                mission.MainAgent.Formation?.FormationIndex != formationClass)
            {
                var formation = mission.PlayerTeam.GetFormation(formationClass);
                if (formation.CountOfUnits == 0)
                {
                    if (formation.IsAIControlled)
                    {
                        formation.IsAIControlled = false;
                    }
                    // fix crash when begin a battle and assign player to an empty formation, then give it an shield wall order.
                    formation.MovementOrder = MovementOrder.MovementOrderMove(mission.MainAgent.GetWorldPosition());
                }

                if (mission.MainAgent.Formation != null)
                {
                    SetHasPlayer(mission.MainAgent.Formation, false);
                }
                mission.MainAgent.Formation = formation;
            }
        }
Esempio n. 4
0
        public static void SetPlayerFormation(FormationClass formationClass)
        {
            var mission = Mission.Current;

            if (mission.MainAgent != null && Mission.Current.PlayerTeam != null &&
                mission.MainAgent.Formation?.FormationIndex != formationClass)
            {
                var formation = mission.PlayerTeam.GetFormation(formationClass);
                if (formation.CountOfUnits == 0)
                {
                    // Fix the bug when player does not lead a formation, and the formation is assigned with another sergeant, the formation will not be controlled by AI.
                    if (Mission.Current.PlayerTeam.IsPlayerGeneral && formation.IsAIControlled)
                    {
                        formation.IsAIControlled = false;
                    }
                    // fix crash when begin a battle and assign player to an empty formation, then give it an shield wall order.
                    formation.MovementOrder = MovementOrder.MovementOrderMove(mission.MainAgent.GetWorldPosition());
                }

                if (mission.MainAgent.Formation != null)
                {
                    SetHasPlayer(mission.MainAgent.Formation, false);
                }
                mission.MainAgent.Formation = formation;
            }
        }
Esempio n. 5
0
 public void AddTroops(BattleSideEnum battleSide, FormationClass formationClass, int troopCount)
 {
     if (troopCount <= 0 || battleSide == BattleSideEnum.None)
     {
         return;
     }
     this._battleSideDeploymentPlans[(int)battleSide].AddTroops(formationClass, troopCount);
 }
        protected override bool OnRead()
        {
            bool bufferReadValid = true;

            this.Peer           = GameNetworkMessage.ReadNetworkPeerReferenceFromPacket(ref bufferReadValid);
            this.FormationClass = (FormationClass)GameNetworkMessage.ReadIntFromPacket(CompressionOrder.FormationClassCompressionInfo, ref bufferReadValid);
            return(bufferReadValid);
        }
Esempio n. 7
0
        private (Agent agent, Agent companion) AgentPreferenceFromFormation(FormationClass formationClass,
                                                                            Vec3 position)
        {
            var preference = new ControlAgentPreference();

            preference.UpdateAgentPreferenceFromFormation(formationClass, position);
            return(preference.NearestAgent, preference.NearestCompanion);
        }
Esempio n. 8
0
 public SPGroup(FormationClass formationClass)
     : base(
         new GroupInfo(formationClass.ToString(),
                       GameTexts.FindText("str_troop_group_name", ((int)formationClass).ToString()),
                       formationClass))
 {
     FormationClass     = formationClass;
     OccupationsInGroup = new Dictionary <Occupation, CharactersInOccupation>();
 }
Esempio n. 9
0
        public void AddTroops(FormationClass formationClass, int troopCount)
        {
            int index = (int)formationClass;

            if (troopCount <= 0 || index >= this._formationTroopCounts.Length)
            {
                return;
            }
            this._formationTroopCounts[index] += troopCount;
        }
Esempio n. 10
0
 public TeamQuery(Team team)
 {
     Formations = new FormationQuery[(int)FormationClass.NumberOfAllFormations];
     for (FormationClass formationClass = 0;
          formationClass < FormationClass.NumberOfAllFormations;
          ++formationClass)
     {
         Formations[(int)formationClass] = new FormationQuery(team.FormationsIncludingSpecialAndEmpty[(int)formationClass]);
     }
 }
Esempio n. 11
0
        public void UpdateAgentPreferenceFromFormation(FormationClass formationClass, Vec3 position)
        {
            if (formationClass < 0 || formationClass > FormationClass.NumberOfAllFormations)
            {
                return;
            }

            var formation = Mission.PlayerTeam.GetFormation(formationClass);

            formation.ApplyActionOnEachUnit(agent => UpdateAgentPreference(agent, position));
        }
        float getInitialFormationWidth(Team team, FormationClass fc)
        {
            var bp                   = this.CaptureTheBannerLordParams;
            var formation            = team.GetFormation(fc);
            var mounted              = fc == FormationClass.Cavalry || fc == FormationClass.HorseArcher;
            var unitDiameter         = Formation.GetDefaultUnitDiameter(mounted);
            var unitSpacing          = 1;
            var interval             = mounted ? Formation.CavalryInterval(unitSpacing) : Formation.InfantryInterval(unitSpacing);
            var actualSoldiersPerRow = System.Math.Min(bp.soldiersPerRow, bp.playerSoldierCount);
            var width                = (actualSoldiersPerRow - 1) * (unitDiameter + interval) + unitDiameter + 0.1f;

            return(width);
        }
 public AssignPlayerRoleInTeamMissionController(
     bool isPlayerGeneral,
     bool isPlayerSergeant,
     bool isPlayerInArmy,
     List <string> charactersInPlayerSideByPriority = null,
     FormationClass preassignedFormationClass       = FormationClass.NumberOfRegularFormations)
 {
     this.IsPlayerGeneral   = isPlayerGeneral;
     this._isPlayerSergeant = isPlayerSergeant;
     this.IsPlayerInArmy    = isPlayerInArmy;
     this._charactersInPlayerSideByPriority = charactersInPlayerSideByPriority;
     this._preassignedFormationClass        = preassignedFormationClass;
 }
 private static int GetLineOrderByClass(FormationClass formationClass)
 {
     return(Array.IndexOf(new FormationClass[8]
     {
         FormationClass.HeavyInfantry,
         FormationClass.Infantry,
         FormationClass.HeavyCavalry,
         FormationClass.Cavalry,
         FormationClass.LightCavalry,
         FormationClass.NumberOfDefaultFormations,
         FormationClass.Ranged,
         FormationClass.HorseArcher
     }, formationClass));
 }
Esempio n. 15
0
        public static (float, float) GetFormationSpawnWidthAndDepth(
            FormationClass formationNo,
            int troopCount,
            bool considerCavalryAsInfantry = false)
        {
            bool  isMounted           = !considerCavalryAsInfantry && formationNo.IsMounted();
            float defaultUnitDiameter = Formation.GetDefaultUnitDiameter(isMounted);
            int   unitSpacing         = 1;
            float num1 = isMounted ? Formation.CavalryInterval(unitSpacing) : Formation.InfantryInterval(unitSpacing);
            float num2 = isMounted ? Formation.CavalryDistance(unitSpacing) : Formation.InfantryDistance(unitSpacing);
            int   num3 = Math.Max(1, (int)(((double)Math.Max(0, troopCount - 1) * ((double)num1 + (double)defaultUnitDiameter) + (double)defaultUnitDiameter) / Math.Sqrt((isMounted ? 24.0 : 12.0) * (double)troopCount + 1.0)));

            return(Math.Max(0.0f, (float)troopCount / (float)num3 - 1f) * (num1 + defaultUnitDiameter) + defaultUnitDiameter, (float)(num3 - 1) * (num2 + defaultUnitDiameter) + defaultUnitDiameter);
        }
Esempio n. 16
0
 public BattleSideDeploymentPlan(BattleSideEnum side)
 {
     this.Side            = side;
     this.SpawnWithHorses = false;
     for (int index = 0; index < this._formationDeploymentPlans.Length; ++index)
     {
         FormationClass fClass = (FormationClass)index;
         this._formationDeploymentPlans[index] = new FormationDeploymentPlan(fClass);
     }
     for (int index = 0; index < 4; ++index)
     {
         this._deploymentFlanks[index] = new SortedList <FormationDeploymentOrder, FormationDeploymentPlan>((IComparer <FormationDeploymentOrder>)FormationDeploymentOrder.GetComparer());
     }
     this.ClearTroops();
     this.ClearPlan();
 }
Esempio n. 17
0
 public void GetPreSuppliedFormationTroopCounts(int[] formationTroopCounts)
 {
     if (formationTroopCounts == null || formationTroopCounts.Length != 11)
     {
         return;
     }
     for (int index = 0; index < formationTroopCounts.Length; ++index)
     {
         formationTroopCounts[index] = 0;
     }
     foreach (IAgentOriginBase preSuppliedTroop in this._preSuppliedTroops)
     {
         FormationClass formationClass = preSuppliedTroop.Troop.GetFormationClass(preSuppliedTroop.BattleCombatant);
         ++formationTroopCounts[(int)formationClass];
     }
 }
        private void ArrangePriorities()
        {
            this._characters = new PriorityQueue <float, BasicCharacterObject>((IComparer <float>) new GenericComparer <float>());
            int[] numArray = new int[8];
            for (int i = 0; i < 8; i++)
            {
                numArray[i] = this._customBattleCombatant.Characters.Count <BasicCharacterObject>((Func <BasicCharacterObject, bool>)(character => character.DefaultFormationClass == (FormationClass)i));
            }
            int num = 1000;

            foreach (BasicCharacterObject character in this._customBattleCombatant.Characters)
            {
                FormationClass formationClass = character.GetFormationClass((IBattleCombatant)this._customBattleCombatant);
                this._characters.Enqueue(character.IsHero ? (float)num-- : (float)(numArray[(int)formationClass] / ((IEnumerable <int>)numArray).Sum()), character);
                --numArray[(int)formationClass];
            }
        }
        public void OnPlayerChoiceMade(
            FormationClass chosenFormationClass,
            FormationAI.BehaviorSide formationBehaviorSide = FormationAI.BehaviorSide.Middle)
        {
            Team      playerTeam = this.Mission.PlayerTeam;
            Formation formation  = playerTeam.Formations.Where <Formation>((Func <Formation, bool>)(f => f.PrimaryClass == chosenFormationClass && f.AI.Side == formationBehaviorSide)).MaxBy <Formation, float>((Func <Formation, float>)(f => f.QuerySystem.FormationPower));

            if (playerTeam.IsPlayerSergeant)
            {
                formation.PlayerOwner         = Agent.Main;
                formation.IsAIControlled      = false;
                formation.IsPlayerInFormation = true;
            }
            else
            {
                formation.IsPlayerInFormation = true;
            }
            Agent.Main.Formation = formation;
            playerTeam.TriggerOnFormationsChanged(formation);
        }
        protected virtual void CreateTroop(
            string troopName,
            Team troopTeam,
            int troopCount,
            bool isReinforcement = false)
        {
            BasicCharacterObject characterObject       = Game.Current.ObjectManager.GetObject <BasicCharacterObject>(troopName);
            FormationClass       defaultFormationClass = characterObject.DefaultFormationClass;
            Formation            formation             = troopTeam.GetFormation(defaultFormationClass);
            WorldFrame           formationSpawnFrame   = this.Mission.GetFormationSpawnFrame(troopTeam.Side, defaultFormationClass, isReinforcement);

            formation.SetPositioning(new WorldPosition?(formationSpawnFrame.Origin), new Vec2?(formationSpawnFrame.Rotation.f.AsVec2));
            for (int formationTroopIndex = 0; formationTroopIndex < troopCount; ++formationTroopIndex)
            {
                Agent agent = this.Mission.SpawnAgent(new AgentBuildData(characterObject).Team(troopTeam).Formation(formation).FormationTroopCount(troopCount).FormationTroopIndex(formationTroopIndex).ClothingColor1(5398358U));
                agent.SetWatchState(AgentAIStateFlagComponent.WatchState.Alarmed);
                agent.SetAlwaysAttackInMelee(true);
                this.IncrementDeploymedTroops(troopTeam.Side);
            }
        }
        public static CharacterCode CreateFrom(
            string equipmentCode,
            BodyProperties bodyProperties,
            bool isFemale,
            bool isHero,
            uint color1,
            uint color2,
            FormationClass formationClass)
        {
            CharacterCode characterCode = new CharacterCode();

            characterCode.EquipmentCode  = equipmentCode;
            characterCode.BodyProperties = bodyProperties;
            characterCode.IsFemale       = isFemale;
            characterCode.IsHero         = isHero;
            characterCode.Color1         = color1;
            characterCode.Color2         = color2;
            characterCode.FormationClass = formationClass;
            MBStringBuilder mbStringBuilder = new MBStringBuilder();

            mbStringBuilder.Initialize(callerMemberName: nameof(CreateFrom));
            mbStringBuilder.Append <string>("@---@");
            mbStringBuilder.Append <string>(equipmentCode);
            mbStringBuilder.Append <string>("@---@");
            mbStringBuilder.Append <string>(characterCode.BodyProperties.ToString());
            mbStringBuilder.Append <string>("@---@");
            mbStringBuilder.Append <string>(characterCode.IsFemale ? "1" : "0");
            mbStringBuilder.Append <string>("@---@");
            mbStringBuilder.Append <string>(characterCode.IsHero ? "1" : "0");
            mbStringBuilder.Append <string>("@---@");
            mbStringBuilder.Append <string>(((int)characterCode.FormationClass).ToString());
            mbStringBuilder.Append <string>("@---@");
            mbStringBuilder.Append <string>(characterCode.Color1.ToString());
            mbStringBuilder.Append <string>("@---@");
            mbStringBuilder.Append <string>(characterCode.Color2.ToString());
            mbStringBuilder.Append <string>("@---@");
            characterCode.Code = mbStringBuilder.ToStringAndRelease();
            return(characterCode);
        }
        public static string GetName(this FormationClass formationClass)
        {
            switch (formationClass)
            {
            case FormationClass.Infantry:
                return("Infantry");

            case FormationClass.Ranged:
                return("Ranged");

            case FormationClass.Cavalry:
                return("Cavalry");

            case FormationClass.HorseArcher:
                return("HorseArcher");

            case FormationClass.NumberOfDefaultFormations:
                return("Skirmisher");

            case FormationClass.HeavyInfantry:
                return("HeavyInfantry");

            case FormationClass.LightCavalry:
                return("LightCavalry");

            case FormationClass.HeavyCavalry:
                return("HeavyCavalry");

            case FormationClass.NumberOfRegularFormations:
                return("General");

            case FormationClass.Bodyguard:
                return("Bodyguard");

            default:
                return("Unset");
            }
        }
Esempio n. 23
0
        private static int GetFormationClassPriority(FormationClass fClass)
        {
            switch (fClass)
            {
            case FormationClass.Infantry:
                return(2);

            case FormationClass.Ranged:
                return(5);

            case FormationClass.Cavalry:
                return(4);

            case FormationClass.HorseArcher:
                return(6);

            case FormationClass.NumberOfDefaultFormations:
                return(0);

            case FormationClass.HeavyInfantry:
                return(1);

            case FormationClass.LightCavalry:
                return(7);

            case FormationClass.HeavyCavalry:
                return(3);

            case FormationClass.NumberOfRegularFormations:
                return(9);

            case FormationClass.Bodyguard:
                return(8);

            default:
                return(10);
            }
        }
Esempio n. 24
0
        public static void Prefix(ref WorldFrame __result, ref Mission __instance, BattleSideEnum side, FormationClass formationClass, bool isReinforcement, int customAgentCount = -1, float offsetAwayFrom = 0f, bool isSpawningWithHorses = true)
        {
            int _usedSpawnPathIndex = (int)ReflectUtils.ReflectField("_usedSpawnPathIndex", __instance);
            //int _spawnPoints = (int)ReflectUtils.ReflectField("_spawnPoints", __instance);
            int   _agentCount                = (int)ReflectUtils.ReflectField("_agentCount", __instance);
            Path  _usedSpawnPath             = (Path)ReflectUtils.ReflectField("_usedSpawnPath", __instance);
            float _randomMiddlePointAddition = (float)ReflectUtils.ReflectField("_randomMiddlePointAddition", __instance);

            MatrixFrame[] _spawnPoints = (MatrixFrame[])ReflectUtils.ReflectField("_spawnPoints", __instance);
            int           num;

            if (customAgentCount != -1)
            {
                num = customAgentCount;
            }
            else
            {
                num = _agentCount;
            }
            if (_usedSpawnPathIndex < 0)
            {
                int num2 = 0;
                int num3;
                do
                {
                    num3           = ((num2 <= 20) ? (MBRandom.RandomInt(3) + 1) : ((num2 - 20) % 3 + 1));
                    _usedSpawnPath = __instance.Scene.GetPathWithName("spawn_path_0" + num3);
                    num2++;
                }while (_usedSpawnPath == null && num2 < 24);
                _usedSpawnPathIndex        = num3;
                _randomMiddlePointAddition = -0.13f + MBRandom.RandomFloat * 0.26f;
            }
            else
            {
                _usedSpawnPath = __instance.Scene.GetPathWithName("spawn_path_0" + _usedSpawnPathIndex);
            }
            if (_usedSpawnPath != null)
            {
                _usedSpawnPath.GetPoints(_spawnPoints);
                float totalLength = _usedSpawnPath.GetTotalLength();
                float num4        = 800f / totalLength;
                float num5        = 0.5f + _randomMiddlePointAddition;
                float num6        = -1f;
                if (num > 0)
                {
                    num6  = 0.04f + 0.08f * (float)Math.Pow((double)(num + (isReinforcement ? 25 : 0)), 0.40000000596046448);
                    num6 *= num4;
                }
                num6 = MBMath.ClampFloat(num6, 0.15f, 1f);
                float num7 = 0f;
                if (formationClass >= FormationClass.Ranged)
                {
                    Formation formation = ((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Infantry);
                    num7 += formation.Depth;
                }
                if (formationClass >= FormationClass.Cavalry)
                {
                    Formation formation = ((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Ranged);
                    num7 += formation.Depth;
                }
                if (!isSpawningWithHorses && formationClass >= FormationClass.HorseArcher)
                {
                    Formation formation = ((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Cavalry);
                    num7 += formation.Depth;
                }
                float       num8              = Math.Max(0f, num5 - 0.44f * num6);
                float       num9              = Math.Min(1f, num5 + 0.44f * num6);
                MatrixFrame frameForDistance  = _usedSpawnPath.GetFrameForDistance(totalLength * num8 - offsetAwayFrom - num7);
                MatrixFrame frameForDistance2 = _usedSpawnPath.GetFrameForDistance(totalLength * num9 + offsetAwayFrom + num7);
                MatrixFrame matrixFrame       = (side == BattleSideEnum.Attacker) ? frameForDistance2 : frameForDistance;
                Vec2        v = ((side == BattleSideEnum.Defender) ? frameForDistance2 : frameForDistance).origin.AsVec2 - matrixFrame.origin.AsVec2;
                v.Normalize();
                Mat3 identity = Mat3.Identity;
                identity.RotateAboutUp(v.RotationInRadians);
                WorldPosition worldPosition = new WorldPosition(__instance.Scene, UIntPtr.Zero, matrixFrame.origin, false);
                if (formationClass == FormationClass.NumberOfRegularFormations)
                {
                    worldPosition.SetVec2(worldPosition.AsVec2 - v * 12f);
                }
                if (isSpawningWithHorses && (formationClass == FormationClass.Cavalry || formationClass == FormationClass.HorseArcher))
                {
                    WorldPosition worldPosition2 = worldPosition;
                    float         num10          = ((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Cavalry).Width * 0.5f;
                    float         num11          = Math.Max(((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Infantry).Width, ((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Ranged).Width) * 0.5f;
                    worldPosition2.SetVec2(worldPosition.AsVec2 + ((formationClass == FormationClass.Cavalry) ? v.LeftVec() : v.RightVec()) * (num10 + num11));
                    if (worldPosition2.GetNavMesh() != UIntPtr.Zero)
                    {
                        worldPosition.SetVec2(worldPosition2.AsVec2);
                    }
                }
                __result = new WorldFrame(identity, worldPosition);
            }
            if (__instance.IsFieldBattle)
            {
                GameEntity gameEntity  = __instance.Scene.FindEntityWithTag("defender_" + ((formationClass != FormationClass.NumberOfRegularFormations) ? formationClass.GetName().ToLower() : "infantry"));
                GameEntity gameEntity2 = __instance.Scene.FindEntityWithTag("attacker_" + ((formationClass != FormationClass.NumberOfRegularFormations) ? formationClass.GetName().ToLower() : "infantry"));
                if (gameEntity != null && gameEntity2 != null)
                {
                    Vec3  globalPosition = gameEntity.GlobalPosition;
                    Vec3  v2             = gameEntity2.GlobalPosition - globalPosition;
                    Vec3  arg_4E7_0      = globalPosition;
                    float num12          = v2.Normalize();
                    float num13          = 1000f / num12;
                    float num14          = 0.08f + 0.08f * (float)Math.Pow((double)(num + (isReinforcement ? 25 : 0)), 0.30000001192092896);
                    num14 *= num13;
                    float num15 = Math.Max(0f, 0.5f - 0.5f * num14);
                    float num16 = Math.Min(1f, 0.5f + 0.5f * num14);
                    Vec3  vec   = arg_4E7_0 + v2 * (num12 * num15);
                    Vec3  vec2  = arg_4E7_0 + v2 * (num12 * num16);
                    Vec3  vec3  = (side == BattleSideEnum.Attacker) ? vec2 : vec;
                    Vec3  vec4  = ((side == BattleSideEnum.Defender) ? vec2 : vec) - vec3;
                    vec4.Normalize();
                    Mat3 identity2 = Mat3.Identity;
                    identity2.RotateAboutUp(vec4.AsVec2.RotationInRadians);
                    WorldPosition origin = new WorldPosition(__instance.Scene, UIntPtr.Zero, vec3, false);
                    __result = new WorldFrame(identity2, origin);
                }
                Vec2 v3 = Vec2.Invalid;
                ICollection <Vec2> value = __instance.Boundaries.First <KeyValuePair <string, ICollection <Vec2> > >().Value;
                if (value.Count > 0)
                {
                    v3  = value.Aggregate((a, b) => a + b);
                    v3 *= 1f / (float)value.Count;
                }
                WorldPosition origin2 = new WorldPosition(__instance.Scene, UIntPtr.Zero, v3.ToVec3(0f), false);
                __result = new WorldFrame(Mat3.Identity, origin2);
            }
            else
            {
                SiegeMissionController expr_609 = __instance.GetMissionBehaviour <SiegeMissionController>();
                if (expr_609 != null)
                {
                    bool arg_614_0 = expr_609.IsSallyOut;
                }
                string text = side.ToString().ToLower() + "_" + ((formationClass != FormationClass.NumberOfRegularFormations) ? formationClass.GetName().ToLower() : "infantry");
                if (isReinforcement)
                {
                    text += "_reinforcement";
                }
                GameEntity gameEntity3 = __instance.Scene.FindEntityWithTag(text);
                if (gameEntity3 != null)
                {
                    MatrixFrame globalFrame = gameEntity3.GetGlobalFrame();
                    globalFrame.rotation.OrthonormalizeAccordingToForwardAndKeepUpAsZAxis();
                    WorldPosition origin3 = new WorldPosition(__instance.Scene, UIntPtr.Zero, globalFrame.origin, false);
                    __result = new WorldFrame(globalFrame.rotation, origin3);
                }
                Vec2 v4 = Vec2.Invalid;
                ICollection <Vec2> value2 = __instance.Boundaries.First <KeyValuePair <string, ICollection <Vec2> > >().Value;
                if (value2.Count > 0)
                {
                    v4  = value2.Aggregate((a, b) => a + b);
                    v4 *= 1f / (float)value2.Count;
                }
                WorldPosition origin4 = new WorldPosition(__instance.Scene, UIntPtr.Zero, v4.ToVec3(0f), false);
                __result = new WorldFrame(Mat3.Identity, origin4);
            }
        }
Esempio n. 25
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);
        }
        public override void OnMissionTick(float dt)
        {
            var mainAgent = Agent.Main;

            // TODO: listen/subscribe to formation change handler
            if (InputKey.D1.IsPressed())
            {
                SelectedFormation = FormationClass.Infantry;
            }
            else if (InputKey.D2.IsPressed())
            {
                SelectedFormation = FormationClass.Ranged;
            }
            else if (InputKey.D3.IsPressed())
            {
                SelectedFormation = FormationClass.Cavalry;
            }
            else if (InputKey.D4.IsPressed())
            {
                SelectedFormation = FormationClass.HorseArcher;
            }
            else if (InputKey.D5.IsPressed())
            {
                SelectedFormation = FormationClass.Skirmisher;
            }
            else if (InputKey.D6.IsPressed())
            {
                SelectedFormation = FormationClass.HeavyInfantry;
            }
            else if (InputKey.D7.IsPressed())
            {
                SelectedFormation = FormationClass.LightCavalry;
            }
            else if (InputKey.D8.IsPressed())
            {
                SelectedFormation = FormationClass.HeavyCavalry;
            }
            else if (InputKey.D9.IsPressed())
            {
                SelectedFormation = FormationClass.General;
            }
            else if (InputKey.D0.IsPressed())
            {
                SelectedFormation = FormationClass.Bodyguard;
            }

            var keyExists = VolleyActiveMap.TryGetValue(SelectedFormation, out var volleyEnabled);

            if (!keyExists)
            {
                VolleyActiveMap[SelectedFormation] = false;
            }

            // Volley key pressed
            if (InputKey.U.IsPressed())
            {
                // Toggle volley for formation
                VolleyActiveMap[SelectedFormation] = !VolleyActiveMap[SelectedFormation];
                // Output status
                var enabledString = VolleyActiveMap[SelectedFormation] ? "enabled" : "disabled";
                InformationManager.DisplayMessage(new InformationMessage($"Volley { enabledString } for { SelectedFormation }"));

                // When disabled, make sure that formation can continue/resume attack
                if (!VolleyActiveMap[SelectedFormation])
                {
                    var disabledFormations = Mission.Current.Agents
                                             .Where(agent => IsAgentUnderPlayer(agent) && agent.Formation != null && agent.Formation.FormationIndex == SelectedFormation)
                                             .Select(x => x.Formation);
                    foreach (var formation in disabledFormations)
                    {
                        formation.ApplyActionOnEachUnit(agent => agent.SetAgentFlags(agent.GetAgentFlags() | AgentFlag.CanAttack));
                    }
                    mainAgent.MakeVoice(SkinVoiceManager.VoiceType.FireAtWill, SkinVoiceManager.CombatVoiceNetworkPredictionType.Prediction);
                }
            }

            var agents = Mission.Current.Agents
                         .Where(agent => IsAgentInEnabledFormations(agent));

            foreach (var agent in agents)
            {
                if (agent == null || agent.Formation == null)
                {
                    continue;
                }
                if (IsUnitFormationUnderMeleeAttack(agent))
                {
                    agent.SetAgentFlags(agent.GetAgentFlags() | AgentFlag.CanAttack);
                }
                else if (agent.WieldedWeapon.ReloadPhase != (short)ReloadPhase.CanAttack)
                {
                    agent.SetAgentFlags(agent.GetAgentFlags() | AgentFlag.CanAttack);
                }
                else
                {
                    var agentWeaponClassIsReloading = agent.Formation.HasUnitsWithCondition(otherAgent => otherAgent.WieldedWeapon.ReloadPhase != (short)ReloadPhase.CanAttack && WeaponClassesMatch(agent, otherAgent));
                    if (agentWeaponClassIsReloading)
                    {
                        agent.SetAgentFlags(agent.GetAgentFlags() & ~AgentFlag.CanAttack);
                    }
                    else
                    {
                        agent.SetAgentFlags(agent.GetAgentFlags() | AgentFlag.CanAttack);
                    }
                }
            }
        }
Esempio n. 27
0
        public static bool SpawnTroops_Prefix(int number, bool isReinforcement, bool enforceSpawningOnInitialPoint, ref int __result,
                                              IMissionTroopSupplier ____troopSupplier,
                                              bool ____spawnWithHorses, BattleSideEnum ____side, MBList <Formation> ____spawnedFormations, ref List <IAgentOriginBase> ____preSuppliedTroops)
        {
            if (number <= 0)
            {
                __result = 0;
            }
            int num = 0;
            List <IAgentOriginBase> list = new List <IAgentOriginBase>();
            int num2 = Math.Min(____preSuppliedTroops.Count, number);

            if (num2 > 0)
            {
                for (int i = 0; i < num2; i++)
                {
                    list.Add(____preSuppliedTroops[i]);
                }
                ____preSuppliedTroops.RemoveRange(0, num2);
            }
            int numberToAllocate = number - num2;

            list.AddRange(____troopSupplier.SupplyTroops(numberToAllocate));
            List <EnhancedBattleTestAgentOrigin> list2 = new List <EnhancedBattleTestAgentOrigin>();

            for (int j = 0; j < 8; j++)
            {
                list2.Clear();
                EnhancedBattleTestAgentOrigin agentOriginBase = null;
                FormationClass formationClass = (FormationClass)j;
                foreach (EnhancedBattleTestAgentOrigin item in list)
                {
                    if (formationClass == item.Troop.GetFormationClass(item.BattleCombatant))
                    {
                        if (item.Troop == Game.Current.PlayerTroop)
                        {
                            agentOriginBase = item;
                        }
                        else
                        {
                            list2.Add(item);
                        }
                    }
                }
                if (agentOriginBase != null)
                {
                    list2.Add(agentOriginBase);
                }
                int count = list2.Count;
                if (count > 0)
                {
                    foreach (EnhancedBattleTestAgentOrigin item2 in list2)
                    {
                        Formation formation;
                        if (((SPTroopSupplier)____troopSupplier)._isPlayerSide)
                        {
                            formation = Mission.GetAgentTeam(item2, true).GetFormation(formationClass);
                        }
                        else
                        {
                            formation = Mission.GetAgentTeam(item2, false).GetFormation(formationClass);
                        }
                        bool isMounted = ____spawnWithHorses && (formationClass == FormationClass.Cavalry || formationClass == FormationClass.LightCavalry || formationClass == FormationClass.HeavyCavalry || formationClass == FormationClass.HorseArcher);
                        if (formation != null && !(bool)HasBeenPositionedProperty.GetValue(formation))
                        {
                            formation.BeginSpawn(count, isMounted);
                            Mission.Current.SpawnFormation(formation, count, ____spawnWithHorses, isMounted, isReinforcement);
                            ____spawnedFormations.Add(formation);
                        }
                        if (((SPTroopSupplier)____troopSupplier)._isPlayerSide)
                        {
                            Mission.Current.SpawnTroop(item2, true, hasFormation: true, ____spawnWithHorses, isReinforcement, enforceSpawningOnInitialPoint, count, num, isAlarmed: true, wieldInitialWeapons: true);
                        }
                        else
                        {
                            Mission.Current.SpawnTroop(item2, false, hasFormation: true, ____spawnWithHorses, isReinforcement, enforceSpawningOnInitialPoint, count, num, isAlarmed: true, wieldInitialWeapons: true);
                        }
                        num++;
                    }
                }
            }
            if (num > 0)
            {
                foreach (Team team in Mission.Current.Teams)
                {
                    //team.QuerySystem.Expire();
                }
                Debug.Print(string.Concat(num, " troops spawned on ", ____side, " side."), 0, Debug.DebugColor.DarkGreen, 64uL);
            }
            foreach (Team team2 in Mission.Current.Teams)
            {
                foreach (Formation formation2 in team2.Formations)
                {
                    typeof(Formation).GetField("GroupSpawnIndex", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(formation2, 0);
                }
            }
            __result = num;
            return(false);
        }
 public static string GetLocalizedName(this FormationClass formationClass) => GameTexts.FindText("str_troop_group_name", ((int)formationClass).ToString()).ToString();
Esempio n. 29
0
        private static SPScoreboardUnitVM CreateScoreEntry(SPScoreboardPartyVM party, FormationClass formationClass)
        {
            BasicCharacterObject character = new BasicCharacterObject
            {
                Name = new TextObject(formationClass.ToString())
            };

            int kills = party.Members.Where(vm => vm.Character.CurrentFormationClass == formationClass)
                        .Sum(vm => vm.Score.Kill);
            int deaths = party.Members.Where(vm => vm.Character.CurrentFormationClass == formationClass)
                         .Sum(vm => vm.Score.Dead);
            int wounded = party.Members.Where(vm => vm.Character.CurrentFormationClass == formationClass)
                          .Sum(vm => vm.Score.Wounded);
            int routed = party.Members.Where(vm => vm.Character.CurrentFormationClass == formationClass)
                         .Sum(vm => vm.Score.Routed);
            int readyToUpgrade = party.Members.Where(vm => vm.Character.CurrentFormationClass == formationClass)
                                 .Sum(vm => vm.Score.ReadyToUpgrade);
            int remaining = party.Members.Where(vm => vm.Character.CurrentFormationClass == formationClass)
                            .Sum(vm => vm.Score.Remaining);

            if (remaining + routed + wounded + deaths == 0)
            {
                return(null);
            }

            SPScoreboardUnitVM score = new SPScoreboardUnitVM(character)
            {
                Score = new SPScoreboardStatsVM(character.Name)
                {
                    Kill           = kills,
                    Dead           = deaths,
                    Wounded        = wounded,
                    Routed         = routed,
                    ReadyToUpgrade = readyToUpgrade,
                    Remaining      = remaining + routed + wounded + deaths,
                }
            };

            return(score);
        }
Esempio n. 30
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);
            }