public static void ClearSosig(Sosig __instance) { SosigLinkLootWrapper lootWrapper = __instance.GetComponentInChildren <SosigLinkLootWrapper>(); if (lootWrapper != null) { lootWrapper.dontDrop = !lootWrapper.shouldDropOnCleanup; } }
private void SosigKillEvent(Sosig sosig) { if (sosig == null) { return; } if (Attachment != null && Attachment.GetRootObject() != null && Attachment.GetRootObject() is FVRFireArm && Attachment.GetRootObject().m_hand != null) { //this is dirty as it counts all sosigs dying while the attachment is on a gun if (sosig.E.IFFCode != sosig.GetDiedFromIFF() && MeatTrak != null && TrackingMode == TrackingModes.Kills) { MeatTrak.NumberTarget++; } } }
public static void EquipSosigWeapon(Sosig sosig, GameObject weaponPrefab, TNHModifier_AIDifficulty difficulty) { SosigWeapon weapon = UnityEngine.Object.Instantiate(weaponPrefab, sosig.transform.position + Vector3.up * 0.1f, sosig.transform.rotation).GetComponent <SosigWeapon>(); weapon.SetAutoDestroy(true); weapon.O.SpawnLockable = false; TNHTweakerLogger.Log("TNHTWEAKER -- Equipping sosig weapon: " + weapon.gameObject.name, TNHTweakerLogger.LogType.TNH); //Equip the sosig weapon to the sosig sosig.ForceEquip(weapon); weapon.SetAmmoClamping(true); if (difficulty == TNHModifier_AIDifficulty.Arcade) { weapon.FlightVelocityMultiplier = 0.3f; } }
public static Sosig SpawnEnemy(SosigTemplate template, CustomCharacter character, Vector3 spawnLocation, Quaternion spawnRotation, TNHModifier_AIDifficulty difficulty, int IFF, bool isAssault, Vector3 pointOfInterest, bool allowAllWeapons) { if (character.ForceAllAgentWeapons) { allowAllWeapons = true; } TNHTweakerLogger.Log("TNHTWEAKER -- Spawning sosig: " + template.SosigEnemyID, TNHTweakerLogger.LogType.TNH); //Create the sosig object GameObject sosigPrefab = UnityEngine.Object.Instantiate(IM.OD[template.SosigPrefabs.GetRandom <string>()].GetGameObject(), spawnLocation, spawnRotation); Sosig sosigComponent = sosigPrefab.GetComponentInChildren <Sosig>(); //Fill out the sosigs config based on the difficulty SosigConfig config; if (difficulty == TNHModifier_AIDifficulty.Arcade && template.ConfigsEasy.Count > 0) { config = template.ConfigsEasy.GetRandom <SosigConfig>(); } else if (template.Configs.Count > 0) { config = template.Configs.GetRandom <SosigConfig>(); } else { TNHTweakerLogger.LogError("TNHTweaker -- Sosig did not have normal difficulty config when playing on normal difficulty! Not spawning this enemy!"); return(null); } sosigComponent.Configure(config.GetConfigTemplate()); sosigComponent.SetIFF(IFF); //Setup the sosigs inventory sosigComponent.Inventory.Init(); sosigComponent.Inventory.FillAllAmmo(); sosigComponent.InitHands(); //Equip the sosigs weapons if (template.WeaponOptions.Count > 0) { GameObject weaponPrefab = IM.OD[template.WeaponOptions.GetRandom <string>()].GetGameObject(); EquipSosigWeapon(sosigComponent, weaponPrefab, difficulty); } if (template.WeaponOptionsSecondary.Count > 0 && allowAllWeapons && template.SecondaryChance >= UnityEngine.Random.value) { GameObject weaponPrefab = IM.OD[template.WeaponOptionsSecondary.GetRandom <string>()].GetGameObject(); EquipSosigWeapon(sosigComponent, weaponPrefab, difficulty); } if (template.WeaponOptionsTertiary.Count > 0 && allowAllWeapons && template.TertiaryChance >= UnityEngine.Random.value) { GameObject weaponPrefab = IM.OD[template.WeaponOptionsTertiary.GetRandom <string>()].GetGameObject(); EquipSosigWeapon(sosigComponent, weaponPrefab, difficulty); } //Equip clothing to the sosig OutfitConfig outfitConfig = template.OutfitConfigs.GetRandom <OutfitConfig>(); if (outfitConfig.Chance_Headwear >= UnityEngine.Random.value) { EquipSosigClothing(outfitConfig.Headwear, sosigComponent.Links[0], outfitConfig.ForceWearAllHead); } if (outfitConfig.Chance_Facewear >= UnityEngine.Random.value) { EquipSosigClothing(outfitConfig.Facewear, sosigComponent.Links[0], outfitConfig.ForceWearAllFace); } if (outfitConfig.Chance_Eyewear >= UnityEngine.Random.value) { EquipSosigClothing(outfitConfig.Eyewear, sosigComponent.Links[0], outfitConfig.ForceWearAllEye); } if (outfitConfig.Chance_Torsowear >= UnityEngine.Random.value) { EquipSosigClothing(outfitConfig.Torsowear, sosigComponent.Links[1], outfitConfig.ForceWearAllTorso); } if (outfitConfig.Chance_Pantswear >= UnityEngine.Random.value) { EquipSosigClothing(outfitConfig.Pantswear, sosigComponent.Links[2], outfitConfig.ForceWearAllPants); } if (outfitConfig.Chance_Pantswear_Lower >= UnityEngine.Random.value) { EquipSosigClothing(outfitConfig.Pantswear_Lower, sosigComponent.Links[3], outfitConfig.ForceWearAllPantsLower); } if (outfitConfig.Chance_Backpacks >= UnityEngine.Random.value) { EquipSosigClothing(outfitConfig.Backpacks, sosigComponent.Links[1], outfitConfig.ForceWearAllBackpacks); } //Setup the sosigs orders if (isAssault) { sosigComponent.CurrentOrder = Sosig.SosigOrder.Assault; sosigComponent.FallbackOrder = Sosig.SosigOrder.Assault; sosigComponent.CommandAssaultPoint(pointOfInterest); } else { sosigComponent.CurrentOrder = Sosig.SosigOrder.Wander; sosigComponent.FallbackOrder = Sosig.SosigOrder.Wander; sosigComponent.CommandGuardPoint(pointOfInterest, true); sosigComponent.SetDominantGuardDirection(UnityEngine.Random.onUnitSphere); } sosigComponent.SetGuardInvestigateDistanceThreshold(25f); //Handle sosig dropping custom loot if (UnityEngine.Random.value < template.DroppedLootChance && template.DroppedObjectPool != null) { SosigLinkLootWrapper component = sosigComponent.Links[2].gameObject.AddComponent <SosigLinkLootWrapper>(); component.shouldDropOnCleanup = !character.DisableCleanupSosigDrops; component.group = template.DroppedObjectPool; } return(sosigComponent); }
static bool Prefix(Sosig __instance) { if (__instance.Agent.isOnOffMeshLink && __instance.Agent.currentOffMeshLinkData.offMeshLink == null) { if (!__instance.ReflectGet <bool>("m_isOnOffMeshLink")) { // Setup fake link, which is added as a component to the Sosig. NavMeshLinkExtension fakeLink; if (genData.ContainsKey(__instance)) { fakeLink = genData[__instance]; } else { fakeLink = __instance.gameObject.AddComponent <NavMeshLinkExtension>(); genData[__instance] = fakeLink; } // Force fields on the fake link to match the type of jump. Vector3 jump = __instance.Agent.currentOffMeshLinkData.endPos - __instance.Agent.currentOffMeshLinkData.startPos; float horzMag = new Vector3(jump.x, 0, jump.z).magnitude; float vertMag = Mathf.Abs(jump.y); bool jumpDown = jump.y < 0; if (!jumpDown && vertMag > (2 * horzMag)) { fakeLink.Type = NavMeshLinkExtension.NavMeshLinkType.Climb; } else if (jumpDown && vertMag > (2 * horzMag)) { fakeLink.Type = NavMeshLinkExtension.NavMeshLinkType.Drop; } else { fakeLink.Type = NavMeshLinkExtension.NavMeshLinkType.LateralJump; } // Arbitrary number. fakeLink.ReflectSet("m_xySpeed", 0.5f); // Clean up the dictionary. // Destroyed Unity objects sure have some confusing properties. List <Sosig> nullCheck = new List <Sosig>(); foreach (var pair in genData) { if (pair.Key == null) { nullCheck.Add(pair.Key); } } foreach (Sosig destroyed in nullCheck) { genData.Remove(destroyed); } __instance.ReflectSet("m_isOnOffMeshLink", true); __instance.ReflectInvoke("InitiateLink", fakeLink); } } return(true); }