Ejemplo n.º 1
0
        public static void assignThrowableMissileSpeed(MissionWeapon throwable, int index, int correctiveMissileSpeed)
        {
            float        ammoWeight = throwable.GetWeight() / throwable.Amount;
            int          calculatedThrowingSpeed = Utilities.calculateThrowableSpeed(ammoWeight);
            PropertyInfo property = typeof(WeaponComponentData).GetProperty("MissileSpeed");

            property.DeclaringType.GetProperty("MissileSpeed");
            throwable.CurrentUsageIndex = index;
            calculatedThrowingSpeed    += correctiveMissileSpeed;
            property.SetValue(throwable.CurrentUsageItem, calculatedThrowingSpeed, BindingFlags.NonPublic | BindingFlags.SetProperty, null, null, null);
            throwable.CurrentUsageIndex = 0;
        }
Ejemplo n.º 2
0
        public static int assignThrowableMissileSpeed(MissionWeapon throwable, int correctiveMissileSpeed, int effectiveSkill)
        {
            float ammoWeight = throwable.GetWeight() / throwable.Amount;
            int   calculatedThrowingSpeed = calculateThrowableSpeed(ammoWeight, effectiveSkill);

            //PropertyInfo property = typeof(WeaponComponentData).GetProperty("MissileSpeed");
            //property.DeclaringType.GetProperty("MissileSpeed");
            //throwable.CurrentUsageIndex = index;
            calculatedThrowingSpeed += correctiveMissileSpeed;
            return(calculatedThrowingSpeed);
            //property.SetValue(throwable.CurrentUsageItem, calculatedThrowingSpeed, BindingFlags.NonPublic | BindingFlags.SetProperty, null, null, null);
            //throwable.CurrentUsageIndex = 0;
        }
            static bool Prefix(Agent __instance)
            {
                ArrayList     stringRangedWeapons = new ArrayList();
                MissionWeapon arrow           = MissionWeapon.Invalid;
                bool          firstProjectile = true;

                for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; equipmentIndex++)
                {
                    if (__instance.Equipment != null && !__instance.Equipment[equipmentIndex].IsEmpty)
                    {
                        WeaponStatsData[] wsd = __instance.Equipment[equipmentIndex].GetWeaponStatsData();
                        if ((wsd[0].WeaponClass == (int)WeaponClass.Bow) || (wsd[0].WeaponClass == (int)WeaponClass.Crossbow))
                        {
                            stringRangedWeapons.Add(__instance.Equipment[equipmentIndex]);
                        }
                        if ((wsd[0].WeaponClass == (int)WeaponClass.Arrow) || (wsd[0].WeaponClass == (int)WeaponClass.Bolt))
                        {
                            if (firstProjectile)
                            {
                                arrow           = __instance.Equipment[equipmentIndex];
                                firstProjectile = false;
                            }
                        }
                        if ((wsd[0].WeaponClass == (int)WeaponClass.OneHandedPolearm) || (wsd[0].WeaponClass == (int)WeaponClass.LowGripPolearm))
                        {
                            for (int i = 0; i < wsd.Length; i++)
                            {
                                if (wsd[i].MissileSpeed != 0)
                                {
                                    Utilities.assignThrowableMissileSpeed(__instance.Equipment[equipmentIndex], i, 5);
                                }
                            }
                        }
                        if (wsd[0].WeaponClass == (int)WeaponClass.Javelin)
                        {
                            for (int i = 0; i < wsd.Length; i++)
                            {
                                if (wsd[i].MissileSpeed != 0)
                                {
                                    Utilities.assignThrowableMissileSpeed(__instance.Equipment[equipmentIndex], i, 10);
                                }
                            }
                        }
                        if ((wsd[0].WeaponClass == (int)WeaponClass.ThrowingAxe) || (wsd[0].WeaponClass == (int)WeaponClass.ThrowingKnife))
                        {
                            for (int i = 0; i < wsd.Length; i++)
                            {
                                if (wsd[i].MissileSpeed != 0)
                                {
                                    Utilities.assignThrowableMissileSpeed(__instance.Equipment[equipmentIndex], i, 0);
                                }
                            }
                        }
                        if (wsd[0].WeaponClass == (int)WeaponClass.Stone)
                        {
                            for (int i = 0; i < wsd.Length; i++)
                            {
                                if (wsd[i].MissileSpeed != 0)
                                {
                                    Utilities.assignStoneMissileSpeed(__instance.Equipment[equipmentIndex], i);
                                }
                            }
                        }
                    }
                }
                foreach (MissionWeapon missionWeapon in stringRangedWeapons)
                {
                    int calculatedMissileSpeed = 50;
                    if (!missionWeapon.Equals(MissionWeapon.Invalid) && !arrow.Equals(MissionWeapon.Invalid))
                    {
                        if (missionWeapon.ItemModifier != null)
                        {
                            FieldInfo field = typeof(ItemModifier).GetField("_missileSpeed", BindingFlags.NonPublic | BindingFlags.Instance);
                            field.DeclaringType.GetField("_missileSpeed");
                            int missileSpeedModifier = (int)field.GetValue(missionWeapon.ItemModifier);

                            _oldMissileSpeeds.Add(missionWeapon.GetModifiedMissileSpeedForUsage(0) - missileSpeedModifier);
                        }
                        else
                        {
                            _oldMissileSpeeds.Add(missionWeapon.GetModifiedMissileSpeedForUsage(0));
                        }
                        float ammoWeight = arrow.GetWeight() / arrow.Amount;
                        calculatedMissileSpeed = Utilities.calculateMissileSpeed(ammoWeight, missionWeapon, missionWeapon.GetModifiedMissileSpeedForUsage(0));

                        PropertyInfo property = typeof(WeaponComponentData).GetProperty("MissileSpeed");
                        property.DeclaringType.GetProperty("MissileSpeed");
                        property.SetValue(missionWeapon.CurrentUsageItem, calculatedMissileSpeed, BindingFlags.NonPublic | BindingFlags.SetProperty, null, null, null);
                    }
                    else if (!missionWeapon.Equals(MissionWeapon.Invalid))
                    {
                        if (missionWeapon.ItemModifier != null)
                        {
                            FieldInfo field = typeof(ItemModifier).GetField("_missileSpeed", BindingFlags.NonPublic | BindingFlags.Instance);
                            field.DeclaringType.GetField("_missileSpeed");
                            int missileSpeedModifier = (int)field.GetValue(missionWeapon.ItemModifier);

                            _oldMissileSpeeds.Add(missionWeapon.GetModifiedMissileSpeedForUsage(0) - missileSpeedModifier);
                        }
                        else
                        {
                            _oldMissileSpeeds.Add(missionWeapon.GetModifiedMissileSpeedForUsage(0));
                        }
                        PropertyInfo property = typeof(WeaponComponentData).GetProperty("MissileSpeed");
                        property.DeclaringType.GetProperty("MissileSpeed");
                        property.SetValue(missionWeapon.CurrentUsageItem, calculatedMissileSpeed, BindingFlags.NonPublic | BindingFlags.SetProperty, null, null, null);
                    }
                }

                return(true);
            }