Beispiel #1
0
 static void Postfix(ref Agent.UsageDirection __result, Formation formation, Agent unit, ArrangementOrderEnum orderEnum)
 {
     if (!formation.QuerySystem.IsCavalryFormation && !formation.QuerySystem.IsRangedCavalryFormation)
     {
         switch (orderEnum)
         {
         case ArrangementOrderEnum.Line:
         case ArrangementOrderEnum.Loose:
         {
             float currentTime         = MBCommon.TimeType.Mission.GetTime();
             float lastMeleeAttackTime = unit.LastMeleeAttackTime;
             float lastMeleeHitTime    = unit.LastMeleeHitTime;
             float lastRangedHit       = unit.LastRangedHitTime;
             if ((currentTime - lastMeleeAttackTime < 4f) || (currentTime - lastMeleeHitTime < 4f))
             {
                 __result = Agent.UsageDirection.None;
             }
             else if ((currentTime - lastRangedHit < 10f) || formation.QuerySystem.UnderRangedAttackRatio >= 0.1f)
             {
                 __result = Agent.UsageDirection.DefendDown;
             }
             else
             {
                 __result = Agent.UsageDirection.None;
             }
             break;
         }
         }
     }
 }
Beispiel #2
0
 internal void OnApply(Formation formation)
 {
     formation.SetPositioning(unitSpacing: new int?(this.GetUnitSpacing()));
     this.Rearrange(formation);
     if (this.OrderEnum == ArrangementOrder.ArrangementOrderEnum.Scatter)
     {
         this.TickOccasionally(formation);
     }
     ArrangementOrder.ArrangementOrderEnum orderEnum = this.OrderEnum;
     formation.ApplyActionOnEachUnit((Action <Agent>)(agent =>
     {
         if (agent.IsAIControlled)
         {
             Agent.UsageDirection shieldDirectionOfUnit = ArrangementOrder.GetShieldDirectionOfUnit(formation, agent, orderEnum);
             agent.EnforceShieldUsage(shieldDirectionOfUnit);
         }
         agent.UpdateAgentProperties();
     }));
     if (formation.MovementOrder.OrderEnum != MovementOrder.MovementOrderEnum.Charge && formation.MovementOrder.OrderEnum != MovementOrder.MovementOrderEnum.ChargeToTarget)
     {
         if (this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Circle && this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.ShieldWall && (this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Square && this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Column))
         {
             formation.ApplyActionOnEachUnit(new Action <Agent>(MovementOrder.SetDefaultMoveBehaviorValues));
         }
         else if (this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Column)
         {
             formation.ApplyActionOnEachUnit(new Action <Agent>(MovementOrder.SetDefensiveArrangementMoveBehaviorValues));
         }
         else
         {
             formation.ApplyActionOnEachUnit(new Action <Agent>(MovementOrder.SetFollowBehaviorValues));
         }
     }
     this.tickTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.5f);
 }
Beispiel #3
0
 public abstract bool DecideCrushedThrough(
     Agent attackerAgent,
     Agent defenderAgent,
     float totalAttackEnergy,
     Agent.UsageDirection attackDirection,
     StrikeType strikeType,
     WeaponComponentData defendItem,
     bool isPassiveUsageHit);
        protected override bool OnRead()
        {
            bool bufferReadValid = true;

            this.Agent          = GameNetworkMessage.ReadAgentReferenceFromPacket(ref bufferReadValid);
            this.EquipmentIndex = (EquipmentIndex)GameNetworkMessage.ReadIntFromPacket(CompressionMission.ItemSlotCompressionInfo, ref bufferReadValid);
            this.UsageIndex     = (int)(short)GameNetworkMessage.ReadIntFromPacket(CompressionMission.WeaponUsageIndexCompressionInfo, ref bufferReadValid);
            this.CurrentMovementFlagUsageDirection = (Agent.UsageDirection)GameNetworkMessage.ReadIntFromPacket(CompressionMission.UsageDirectionCompressionInfo, ref bufferReadValid);
            return(bufferReadValid);
        }
 public StartSwitchingWeaponUsageIndex(
     Agent agent,
     EquipmentIndex equipmentIndex,
     int usageIndex,
     Agent.UsageDirection currentMovementFlagUsageDirection)
 {
     this.Agent          = agent;
     this.EquipmentIndex = equipmentIndex;
     this.UsageIndex     = usageIndex;
     this.CurrentMovementFlagUsageDirection = currentMovementFlagUsageDirection;
 }
Beispiel #6
0
        public override Agent.UsageDirection GetBlockDirection(Mission mission)
        {
            Agent mainAgent = mission.MainAgent;
            float num1      = float.MinValue;

            Agent.UsageDirection usageDirection = Agent.UsageDirection.AttackDown;
            foreach (Agent agent in (IEnumerable <Agent>)mission.Agents)
            {
                if (agent.IsHuman)
                {
                    switch (agent.GetCurrentActionStage(1))
                    {
                    case Agent.ActionStage.AttackReady:
                    case Agent.ActionStage.AttackQuickReady:
                    case Agent.ActionStage.AttackRelease:
                        if (agent.IsEnemyOf(mainAgent))
                        {
                            Vec3   v1   = agent.Position - mainAgent.Position;
                            float  num2 = v1.Normalize();
                            double num3 = (double)MBMath.ClampFloat(Vec3.DotProduct(v1, mainAgent.LookDirection) + 0.8f, 0.0f, 1f);
                            float  num4 = MBMath.ClampFloat((float)(1.0 / ((double)num2 + 0.5)), 0.0f, 1f);
                            float  num5 = MBMath.ClampFloat((float)(-(double)Vec3.DotProduct(v1, agent.LookDirection) + 0.5), 0.0f, 1f);
                            double num6 = (double)num4;
                            float  num7 = (float)(num3 * num6) * num5;
                            if ((double)num7 > (double)num1)
                            {
                                num1           = num7;
                                usageDirection = agent.GetCurrentActionDirection(1);
                                if (usageDirection == Agent.UsageDirection.None)
                                {
                                    usageDirection = Agent.UsageDirection.AttackDown;
                                    continue;
                                }
                                continue;
                            }
                            continue;
                        }
                        continue;

                    default:
                        continue;
                    }
                }
            }
            return(usageDirection);
        }
        private static void OnApply(ref ArrangementOrder __instance, Formation formation)
        {
            var instanceOrderEnum  = __instance.GetOrderEnumField();
            var formationOrderEnum = formation.MovementOrder.GetOrderEnumField();

            formation.SetPositioning(new WorldPosition?(), new Vec2?(), new int?(__instance.GetUnitSpacingField()));
            __instance.Rearrange(formation);

            if (instanceOrderEnum == ArrangementOrderEnum.Scatter)
            {
                __instance.TickOccasionally(formation);
            }

            foreach (Agent agent in formation.Units.Where(u => u.IsAIControlled))
            {
                Agent.UsageDirection shieldDirectionOfUnit = __instance.GetShieldDirectionOfUnit(formation, agent);
                agent.EnforceShieldUsage(shieldDirectionOfUnit);
            }

            if (formationOrderEnum != MovementOrderEnum.Charge && formationOrderEnum != MovementOrderEnum.ChargeToTarget)
            {
                if (instanceOrderEnum != ArrangementOrderEnum.Circle && instanceOrderEnum != ArrangementOrderEnum.ShieldWall && instanceOrderEnum != ArrangementOrderEnum.Square && instanceOrderEnum != ArrangementOrderEnum.Column)
                {
                    foreach (Agent unit in formation.Units)
                    {
                        MovementOrderMethods.SetDefaultMoveBehaviorValues(unit);
                    }
                }
                else if (instanceOrderEnum != ArrangementOrderEnum.Column)
                {
                    foreach (Agent unit in formation.Units)
                    {
                        MovementOrderMethods.SetDefensiveArrangementMoveBehaviorValues(unit);
                    }
                }
                else
                {
                    foreach (Agent unit in formation.Units)
                    {
                        MovementOrderMethods.SetFollowBehaviorValues(unit);
                    }
                }
            }

            __instance.SetTickTimerField(new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.5f, true));
        }
 public static AttackCollisionData GetAttackCollisionDataForDebugPurpose(
     bool _attackBlockedWithShield,
     bool _correctSideShieldBlock,
     bool _isAlternativeAttack,
     bool _isColliderAgent,
     bool _collidedWithShieldOnBack,
     bool _isMissile,
     bool _isMissileBlockedWithWeapon,
     bool _missileHasPhysics,
     bool _entityExists,
     bool _thrustTipHit,
     bool _missileGoneUnderWater,
     CombatCollisionResult collisionResult,
     int affectorWeaponSlotOrMissileIndex,
     int StrikeType,
     int DamageType,
     sbyte CollisionBoneIndex,
     BoneBodyPartType VictimHitBodyPart,
     sbyte AttackBoneIndex,
     Agent.UsageDirection AttackDirection,
     int PhysicsMaterialIndex,
     CombatHitResultFlags CollisionHitResultFlags,
     float AttackProgress,
     float CollisionDistanceOnWeapon,
     float AttackerStunPeriod,
     float DefenderStunPeriod,
     float MissileTotalDamage,
     float MissileInitialSpeed,
     float ChargeVelocity,
     float FallSpeed,
     Vec3 WeaponRotUp,
     Vec3 _weaponBlowDir,
     Vec3 CollisionGlobalPosition,
     Vec3 MissileVelocity,
     Vec3 MissileStartingPosition,
     Vec3 VictimAgentCurVelocity,
     Vec3 GroundNormal)
 {
     return(new AttackCollisionData(_attackBlockedWithShield, _correctSideShieldBlock, _isAlternativeAttack, _isColliderAgent, _collidedWithShieldOnBack, _isMissile, _isMissileBlockedWithWeapon, _missileHasPhysics, _entityExists, _thrustTipHit, _missileGoneUnderWater, collisionResult, affectorWeaponSlotOrMissileIndex, StrikeType, DamageType, CollisionBoneIndex, VictimHitBodyPart, AttackBoneIndex, AttackDirection, PhysicsMaterialIndex, CollisionHitResultFlags, AttackProgress, CollisionDistanceOnWeapon, AttackerStunPeriod, DefenderStunPeriod, MissileTotalDamage, MissileInitialSpeed, ChargeVelocity, FallSpeed, WeaponRotUp, _weaponBlowDir, CollisionGlobalPosition, MissileVelocity, MissileStartingPosition, VictimAgentCurVelocity, GroundNormal));
 }
 static void Postfix(ref Agent.UsageDirection __result, Formation formation, Agent unit, ArrangementOrderEnum orderEnum)
 {
     if (!formation.QuerySystem.IsCavalryFormation && !formation.QuerySystem.IsRangedCavalryFormation)
     {
         float currentTime = Mission.Current.CurrentTime;
         if (currentTime - unit.LastRangedAttackTime < 7f)
         {
             __result = Agent.UsageDirection.None;
             return;
         }
         switch (orderEnum)
         {
         case ArrangementOrderEnum.Line:
         case ArrangementOrderEnum.Loose:
         {
             //float currentTime = MBCommon.TimeType.Mission.GetTime();
             float lastMeleeAttackTime = unit.LastMeleeAttackTime;
             float lastMeleeHitTime    = unit.LastMeleeHitTime;
             float lastRangedHit       = unit.LastRangedHitTime;
             if ((currentTime - lastMeleeAttackTime < 4f) || (currentTime - lastMeleeHitTime < 4f))
             {
                 __result = Agent.UsageDirection.None;
                 return;
             }
             if (Mission.Current.MissionTeamAIType == Mission.MissionTeamAITypeEnum.FieldBattle && (((currentTime - lastRangedHit < 2f) || formation.QuerySystem.UnderRangedAttackRatio >= 0.08f)))
             {
                 __result = Agent.UsageDirection.DefendDown;
                 return;
             }
             //else
             //{
             //    __result = Agent.UsageDirection.None;
             //}
             break;
         }
         }
     }
 }
 public void EnforceShieldUsage(Agent.UsageDirection shieldDirection) => this.Agent.EnforceShieldUsage = shieldDirection;
Beispiel #11
0
 public static void DecideCrushedThrough(Agent attackerAgent, Agent defenderAgent, float totalAttackEnergy, Agent.UsageDirection attackDirection, StrikeType strikeType, WeaponComponentData defendItem, bool isPassiveUsage, ref bool __result)
 {
     try
     {
         if (attackerAgent.IsPlayer() &&
             BannerlordCheatsSettings.Instance?.AlwaysCrushThroughShields == true)
         {
             __result = true;
         }
     }
     catch (Exception e)
     {
         SubModule.LogError(e, typeof(AlwaysCrushThroughShields));
     }
 }
Beispiel #12
0
 public static void DecideCrushedThrough(Agent attackerAgent, Agent defenderAgent, float totalAttackEnergy, Agent.UsageDirection attackDirection, StrikeType strikeType, WeaponComponentData defendItem, bool isPassiveUsage, ref bool __result)
 {
     if ((attackerAgent?.IsPlayerControlled ?? false) &&
         BannerlordCheatsSettings.Instance.AlwaysCrushThroughShields)
     {
         __result = true;
     }
 }
 private AttackCollisionData(
     bool attackBlockedWithShield,
     bool correctSideShieldBlock,
     bool isAlternativeAttack,
     bool isColliderAgent,
     bool collidedWithShieldOnBack,
     bool isMissile,
     bool missileBlockedWithWeapon,
     bool missileHasPhysics,
     bool entityExists,
     bool thrustTipHit,
     bool missileGoneUnderWater,
     CombatCollisionResult collisionResult,
     int affectorWeaponSlotOrMissileIndex,
     int StrikeType,
     int DamageType,
     sbyte CollisionBoneIndex,
     BoneBodyPartType VictimHitBodyPart,
     sbyte AttackBoneIndex,
     Agent.UsageDirection AttackDirection,
     int PhysicsMaterialIndex,
     CombatHitResultFlags CollisionHitResultFlags,
     float AttackProgress,
     float CollisionDistanceOnWeapon,
     float AttackerStunPeriod,
     float DefenderStunPeriod,
     float MissileTotalDamage,
     float MissileStartingBaseSpeed,
     float ChargeVelocity,
     float FallSpeed,
     Vec3 WeaponRotUp,
     Vec3 weaponBlowDir,
     Vec3 CollisionGlobalPosition,
     Vec3 MissileVelocity,
     Vec3 MissileStartingPosition,
     Vec3 VictimAgentCurVelocity,
     Vec3 GroundNormal)
 {
     this._attackBlockedWithShield  = attackBlockedWithShield;
     this._correctSideShieldBlock   = correctSideShieldBlock;
     this._isAlternativeAttack      = isAlternativeAttack;
     this._isColliderAgent          = isColliderAgent;
     this._collidedWithShieldOnBack = collidedWithShieldOnBack;
     this._isMissile = isMissile;
     this._missileBlockedWithWeapon        = missileBlockedWithWeapon;
     this._missileHasPhysics               = missileHasPhysics;
     this._entityExists                    = entityExists;
     this._thrustTipHit                    = thrustTipHit;
     this._missileGoneUnderWater           = missileGoneUnderWater;
     this._collisionResult                 = (int)collisionResult;
     this.AffectorWeaponSlotOrMissileIndex = affectorWeaponSlotOrMissileIndex;
     this.StrikeType                = StrikeType;
     this.DamageType                = DamageType;
     this.CollisionBoneIndex        = CollisionBoneIndex;
     this.VictimHitBodyPart         = VictimHitBodyPart;
     this.AttackBoneIndex           = AttackBoneIndex;
     this.AttackDirection           = AttackDirection;
     this.PhysicsMaterialIndex      = PhysicsMaterialIndex;
     this.CollisionHitResultFlags   = CollisionHitResultFlags;
     this.AttackProgress            = AttackProgress;
     this.CollisionDistanceOnWeapon = CollisionDistanceOnWeapon;
     this.AttackerStunPeriod        = AttackerStunPeriod;
     this.DefenderStunPeriod        = DefenderStunPeriod;
     this.MissileTotalDamage        = MissileTotalDamage;
     this.MissileStartingBaseSpeed  = MissileStartingBaseSpeed;
     this.ChargeVelocity            = ChargeVelocity;
     this.FallSpeed                   = FallSpeed;
     this.WeaponRotUp                 = WeaponRotUp;
     this._weaponBlowDir              = weaponBlowDir;
     this.CollisionGlobalPosition     = CollisionGlobalPosition;
     this.MissileVelocity             = MissileVelocity;
     this.MissileStartingPosition     = MissileStartingPosition;
     this.VictimAgentCurVelocity      = VictimAgentCurVelocity;
     this.CollisionGlobalNormal       = GroundNormal;
     this.BaseMagnitude               = 0.0f;
     this.MovementSpeedDamageModifier = 0.0f;
     this.AbsorbedByArmor             = 0;
     this.InflictedDamage             = 0;
     this.SelfInflictedDamage         = 0;
     this.IsShieldBroken              = false;
 }
        internal static bool GetDefendCollisionResultsAuxPrefix(Mission __instance, Agent attackerAgent, Agent defenderAgent,
                                                                CombatCollisionResult collisionResult, int weaponKind, int currentUsageIndex, bool isAlternativeAttack,
                                                                StrikeType strikeType, Agent.UsageDirection attackDirection, float currentAttackSpeed, float collisionDistanceOnWeapon,
                                                                float attackProgress, bool attackIsParried, ref float defenderStunPeriod, ref float attackerStunPeriod, ref bool crushedThrough,
                                                                ref bool chamber)
        {
            ItemObject          itemFromWeaponKind  = ItemObject.GetItemFromWeaponKind(weaponKind);
            WeaponComponentData weaponComponentData = (itemFromWeaponKind != null) ? itemFromWeaponKind.GetWeaponWithUsageIndex(currentUsageIndex) : null;
            EquipmentIndex      wieldedItemIndex    = defenderAgent.GetWieldedItemIndex(Agent.HandIndex.OffHand);

            if (wieldedItemIndex == EquipmentIndex.None)
            {
                wieldedItemIndex = defenderAgent.GetWieldedItemIndex(Agent.HandIndex.MainHand);
            }
            WeaponComponentData weaponComponentData2 = (wieldedItemIndex != EquipmentIndex.None) ? defenderAgent.Equipment[wieldedItemIndex].CurrentUsageItem : null;
            float num = 10f;

            attackerStunPeriod = ((strikeType == StrikeType.Thrust) ? ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunPeriodAttackerThrust) : ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunPeriodAttackerSwing));
            chamber            = false;
            float num2 = 0f;

            if (weaponComponentData != null)
            {
                float z    = attackerAgent.GetCurWeaponOffset().z;
                float num3 = weaponComponentData.GetRealWeaponLength() + z;
                num2 = MBMath.ClampFloat((0.2f + collisionDistanceOnWeapon) / num3, 0.1f, 0.98f);
                float exraLinearSpeed = MissionReversePatches.ComputeRelativeSpeedDiffOfAgents(attackerAgent, defenderAgent);
                float num4;
                if (strikeType == StrikeType.Thrust)
                {
                    num4 = CombatStatCalculator.CalculateBaseBlowMagnitudeForThrust((float)itemFromWeaponKind.PrimaryWeapon.ThrustSpeed / 11.7647057f * MissionReversePatches.SpeedGraphFunction(Mission.Current, attackProgress, strikeType, attackDirection), itemFromWeaponKind.Weight, exraLinearSpeed);
                }
                else
                {
                    num4 = CombatStatCalculator.CalculateBaseBlowMagnitudeForSwing((float)itemFromWeaponKind.PrimaryWeapon.SwingSpeed / 4.5454545f * MissionReversePatches.SpeedGraphFunction(Mission.Current, strikeType, attackDirection), weaponComponentData.GetRealWeaponLength(), itemFromWeaponKind.Weight, weaponComponentData.Inertia, weaponComponentData.CenterOfMass, num2, exraLinearSpeed);
                }
                if (strikeType == StrikeType.Thrust)
                {
                    num4 *= 0.8f;
                }
                else if (attackDirection == Agent.UsageDirection.AttackUp)
                {
                    num4 *= 1.25f;
                }
                num += num4;
            }
            float num5 = 1f;

            defenderStunPeriod = num * ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunMomentumTransferFactor);
            if (weaponComponentData2 != null)
            {
                if (weaponComponentData2.IsShield)
                {
                    float managedParameter = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunDefendWeaponWeightOffsetShield);
                    num5 += managedParameter * weaponComponentData2.Item.Weight;
                }
                else
                {
                    num5 = 0.9f;
                    float managedParameter2 = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunDefendWeaponWeightMultiplierWeaponWeight);
                    num5 += managedParameter2 * weaponComponentData2.Item.Weight;
                    ItemObject.ItemTypeEnum itemType = weaponComponentData2.Item.ItemType;
                    if (itemType == ItemObject.ItemTypeEnum.TwoHandedWeapon)
                    {
                        managedParameter2 = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunDefendWeaponWeightBonusTwoHanded);
                    }
                    else if (itemType == ItemObject.ItemTypeEnum.Polearm)
                    {
                        num5 += ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunDefendWeaponWeightBonusPolearm);
                    }
                }
                if (collisionResult == CombatCollisionResult.Parried)
                {
                    attackerStunPeriod += 0.1f;
                    num5 += ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunDefendWeaponWeightBonusActiveBlocked);


                    if (GCOToolbox.GCOToolbox.MeleeBalance.GCOCheckHyperArmorConfiguration(defenderAgent))
                    {
                        GCOToolbox.GCOToolbox.MeleeBalance.CreateHyperArmorBuff(defenderAgent);
                    }
                }
                else if (collisionResult == CombatCollisionResult.Blocked)
                {
                    if (GCOToolbox.GCOToolbox.MeleeBalance.GCOCheckHyperArmorConfiguration(defenderAgent))
                    {
                        GCOToolbox.GCOToolbox.MeleeBalance.CreateHyperArmorBuff(defenderAgent);
                    }
                }
                else if (collisionResult == CombatCollisionResult.ChamberBlocked)
                {
                    attackerStunPeriod += 0.2f;
                    num5   += ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunDefendWeaponWeightBonusChamberBlocked);
                    chamber = true;
                }
            }
            if (!defenderAgent.GetIsLeftStance())
            {
                num5 += ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunDefendWeaponWeightBonusRightStance);
            }
            defenderStunPeriod /= num5;
            float managedParameter3 = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.StunPeriodMax);

            attackerStunPeriod = Math.Min(attackerStunPeriod, managedParameter3);
            defenderStunPeriod = Math.Min(defenderStunPeriod, managedParameter3);
            crushedThrough     = (num > 38f && defenderStunPeriod > managedParameter3 - 0.03f && num2 > 0.5f);
            MissionGameModels.Current.AgentApplyDamageModel.CalculateEffects(attackerAgent, ref crushedThrough);
            if (chamber)
            {
                crushedThrough = false;
            }

            return(false);
        }
 internal static float SpeedGraphFunction(this Mission current, StrikeType strikeType, Agent.UsageDirection attackDirection)
 {
     throw new NotImplementedException("Need to patch first");
 }
Beispiel #16
0
 public static void EnforceShieldUsage(this Agent agent, Agent.UsageDirection shieldDirection) => agent.GetComponent <FormationOrderComponent>()?.EnforceShieldUsage(shieldDirection);
 internal static float SpeedGraphFunction(this Mission __instance, float progress, StrikeType strikeType, Agent.UsageDirection attackDir)
 {
     throw new NotImplementedException("Need to patch first");
 }