示例#1
0
 public static void registerComponentsForVFX(this AbstractActor unit)
 {
     Log.LogWrite("registerComponentsForVFX " + unit.DisplayName + ":" + unit.GUID + "\n");
     foreach (MechComponent component in unit.allComponents)
     {
         string wGUID;
         if (CustomAmmoCategories.checkExistance(component.StatCollection, CustomAmmoCategories.GUIDStatisticName) == false)
         {
             wGUID = Guid.NewGuid().ToString();
             component.StatCollection.AddStatistic <string>(CustomAmmoCategories.GUIDStatisticName, wGUID);
         }
         else
         {
             wGUID = component.StatCollection.GetStatistic(CustomAmmoCategories.GUIDStatisticName).Value <string>();
         }
         Log.LogWrite(" " + component.defId + ":" + wGUID + "\n");
         ComponentVFXHelper.componentsVFXObjects[wGUID] = new VFXObjects(component);
     }
 }
示例#2
0
        public static ObjectSpawnDataSelf DestroyedVFX(this MechComponent component)
        {
            string wGUID;

            if (CustomAmmoCategories.checkExistance(component.StatCollection, CustomAmmoCategories.GUIDStatisticName) == false)
            {
                wGUID = Guid.NewGuid().ToString();
                component.StatCollection.AddStatistic <string>(CustomAmmoCategories.GUIDStatisticName, wGUID);
            }
            else
            {
                wGUID = component.StatCollection.GetStatistic(CustomAmmoCategories.GUIDStatisticName).Value <string>();
            }
            Log.LogWrite("DestroyedVFX(" + component.defId + ":" + wGUID + ")\n");
            if (ComponentVFXHelper.componentsVFXObjects.ContainsKey(wGUID))
            {
                return(ComponentVFXHelper.componentsVFXObjects[wGUID].destroyedObject);
            }
            return(null);
        }
示例#3
0
        public static bool Prefix(AttackDirector.AttackSequence __instance, Weapon weapon, int groupIdx, int weaponIdx, int numberOfShots, bool indirectFire, float dodgedDamage, ref WeaponHitInfo __result)
        {
            WeaponHitInfo hitInfo = new WeaponHitInfo();

            hitInfo.attackerId        = __instance.attacker.GUID;
            hitInfo.targetId          = __instance.target.GUID;
            hitInfo.numberOfShots     = numberOfShots;
            hitInfo.stackItemUID      = __instance.stackItemUID;
            hitInfo.attackSequenceId  = __instance.id;
            hitInfo.attackGroupIndex  = groupIdx;
            hitInfo.attackWeaponIndex = weaponIdx;
            hitInfo.toHitRolls        = new float[numberOfShots];
            hitInfo.locationRolls     = new float[numberOfShots];
            hitInfo.dodgeRolls        = new float[numberOfShots];
            hitInfo.dodgeSuccesses    = new bool[numberOfShots];
            hitInfo.hitLocations      = new int[numberOfShots];
            hitInfo.hitPositions      = new Vector3[numberOfShots];
            hitInfo.hitVariance       = new int[numberOfShots];
            hitInfo.hitQualities      = new AttackImpactQuality[numberOfShots];
            if (AttackDirector.hitLogger.IsLogEnabled)
            {
                Vector3         collisionWorldPos;
                LineOfFireLevel lineOfFire           = __instance.Director.Combat.LOS.GetLineOfFire(__instance.attacker, __instance.attackPosition, __instance.target, __instance.target.CurrentPosition, __instance.target.CurrentRotation, out collisionWorldPos);
                float           allModifiers         = __instance.Director.Combat.ToHit.GetAllModifiers(__instance.attacker, weapon, __instance.target, __instance.attackPosition + __instance.attacker.HighestLOSPosition, __instance.target.TargetPosition, lineOfFire, __instance.isMoraleAttack);
                string          modifiersDescription = __instance.Director.Combat.ToHit.GetAllModifiersDescription(__instance.attacker, weapon, __instance.target, __instance.attackPosition + __instance.attacker.HighestLOSPosition, __instance.target.TargetPosition, lineOfFire, __instance.isMoraleAttack);
                Pilot           pilot = __instance.attacker.GetPilot();
                AttackDirector.hitLogger.Log((object)string.Format("======================================== Unit Firing: {0} | Weapon: {1} | Shots: {2}", (object)__instance.attacker.DisplayName, (object)weapon.Name, (object)numberOfShots));
                AttackDirector.hitLogger.Log((object)string.Format("======================================== Hit Info: GROUP {0} | ID {1}", (object)groupIdx, (object)weaponIdx));
                AttackDirector.hitLogger.Log((object)string.Format("======================================== MODIFIERS: {0}... FINAL: [[ {1} ]] ", (object)modifiersDescription, (object)allModifiers));
                if (pilot != null)
                {
                    AttackDirector.hitLogger.Log((object)__instance.Director.Combat.ToHit.GetBaseToHitChanceDesc(__instance.attacker));
                }
                else
                {
                    AttackDirector.hitLogger.Log((object)string.Format("======================================== Gunnery Check: NO PILOT"));
                }
            }
            float toHitChance = __instance.Director.Combat.ToHit.GetToHitChance(__instance.attacker, weapon, __instance.target, __instance.attackPosition, __instance.target.CurrentPosition, __instance.numTargets, __instance.meleeAttackType, __instance.isMoraleAttack);

            if (Mech.TEST_KNOCKDOWN)
            {
                toHitChance = 1f;
            }
            if (AttackDirector.hitLogger.IsLogEnabled)
            {
                AttackDirector.hitLogger.Log((object)string.Format("======================================== HIT CHANCE: [[ {0:P2} ]]", (object)toHitChance));
            }
            hitInfo.attackDirection       = __instance.Director.Combat.HitLocation.GetAttackDirection(__instance.attackPosition, __instance.target);
            hitInfo.attackDirectionVector = __instance.Director.Combat.HitLocation.GetAttackDirectionVector(__instance.attackPosition, __instance.target);
            object[]         args       = new object[6];
            HitGeneratorType hitGenType = HitGeneratorType.NotSet;

            if (weapon.weaponDef.ComponentTags.Contains("wr-clustered_shots"))
            {
                hitGenType = HitGeneratorType.Individual;
            }
            if (hitGenType == HitGeneratorType.NotSet)
            {
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
                {
                    string           ammoId  = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
                    ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId);
                    hitGenType = extAmmo.HitGenerator;
                }
                if (hitGenType == HitGeneratorType.NotSet)
                {
                    ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.weaponDef.Description.Id);
                    hitGenType = extWeapon.HitGenerator;
                }
            }
            if (hitGenType != HitGeneratorType.NotSet)
            {
                switch (hitGenType)
                {
                case HitGeneratorType.Individual:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    break;

                case HitGeneratorType.Cluster:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetClusteredHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetClusteredHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                case HitGeneratorType.Streak:
                    //args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    //typeof(AttackDirector.AttackSequence).GetMethod("GetClusteredHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    //hitInfo = (WeaponHitInfo)args[0];
                    AttackSequence_GenerateHitInfo.GetStreakHits(__instance, ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    //__instance.GetClusteredHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                default:
                    AttackDirector.attackLogger.LogError((object)string.Format("GenerateHitInfo found invalid weapon type: {0}, using basic hit info", (object)hitGenType));
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetIndividualHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;
                }
            }
            else
            {
                switch (weapon.Type)
                {
                case WeaponType.Autocannon:
                case WeaponType.Gauss:
                case WeaponType.Laser:
                case WeaponType.PPC:
                case WeaponType.Flamer:
                case WeaponType.Melee:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetIndividualHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                case WeaponType.LRM:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetClusteredHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetClusteredHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                case WeaponType.SRM:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetIndividualHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                case WeaponType.MachineGun:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetIndividualHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                default:
                    AttackDirector.attackLogger.LogError((object)string.Format("GenerateHitInfo found invalid weapon type: {0}, using basic hit info", (object)weapon.Type));
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetIndividualHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;
                }
            }
            __result = hitInfo;
            return(false);
            //return hitInfo;
        }