internal static bool Prefix(CreatureDeath __instance) { if (!__instance.respawn || __instance.respawnOnlyIfKilledByCreature) // trigger respawner if it normally wouldn't trigger { __instance.SpawnRespawner(); } return(true); }
public static bool TryKillCreature(Creature creature) { if (creature != null && creature.enabled && creature.Friendliness.Value != 1 && creature.version == 3 && creature.gameObject != null) { var creatureConfiguration = settings.UnwantedCreaturesList.FirstOrDefault(c => c.Name.ToLowerInvariant() == creature.name.Replace("(Clone)", String.Empty).ToLowerInvariant()); if (creatureConfiguration != null) { if (rEngine.Next(0, 100) >= creatureConfiguration.SpawnConfiguration.SpawnChance) { creature.tag = "Untagged"; creature.version = 4; creature.leashPosition = UnityEngine.Vector3.zero; CreatureDeath cDeath = creature.gameObject.GetComponent <CreatureDeath>(); if (cDeath != null) { cDeath.eatable = null; cDeath.respawn = creatureConfiguration.SpawnConfiguration.CanRespawn; cDeath.removeCorpseAfterSeconds = 1.0f; } if (creature.liveMixin != null && creature.liveMixin.IsAlive()) { if (creature.liveMixin.data != null) { creature.liveMixin.data.deathEffect = null; creature.liveMixin.data.passDamageDataOnDeath = false; creature.liveMixin.data.broadcastKillOnDeath = true; creature.liveMixin.data.destroyOnDeath = true; creature.liveMixin.data.explodeOnDestroy = false; } creature.liveMixin.Kill(); } else { creature.BroadcastMessage("OnKill"); } return(true); } else { creature.version = 4; CreatureDeath cDeath = creature.gameObject.GetComponent <CreatureDeath>(); if (cDeath != null) { cDeath.respawn = creatureConfiguration.SpawnConfiguration.CanRespawn; } } } } return(false); }
static void Postfix(CreatureDeath __instance) { __instance.gameObject.callAfterDelay(timeToStopAnimator, new UnityAction(() => { if (__instance.gameObject.GetComponentInChildren <Animator>() is Animator animator) { animator.enabled = false; } })); }
static void KillFish(LiveMixin liveMixin) { //ErrorMessage.AddDebug("Kill " + liveMixin.gameObject.name); //Main.Log("Kill " + liveMixin.gameObject.name); liveMixin.health = 0f; liveMixin.tempDamage = 0f; liveMixin.SyncUpdatingState(); if (liveMixin.deathClip) { Utils.PlayEnvSound(liveMixin.deathClip, liveMixin.transform.position, 25f); } //if (this.deathEffect != null) // Utils.InstantiateWrap(this.deathEffect, this.transform.position, Quaternion.identity); if (liveMixin.passDamageDataOnDeath) { liveMixin.gameObject.BroadcastMessage("OnKill", DamageType.Normal, SendMessageOptions.DontRequireReceiver); } else if (liveMixin.broadcastKillOnDeath) { liveMixin.gameObject.BroadcastMessage("OnKill", SendMessageOptions.DontRequireReceiver); } CreatureDeath creatureDeath = liveMixin.GetComponent <CreatureDeath>(); Eatable eatable = liveMixin.GetComponent <Eatable>(); eatable.SetDecomposes(true); Rigidbody rb = liveMixin.GetComponent <Rigidbody>(); if (rb) { rb.isKinematic = false; rb.constraints = RigidbodyConstraints.None; WorldForces worldForces = liveMixin.GetComponent <WorldForces>(); if (worldForces) { worldForces.handleDrag = false; } rb.drag = Mathf.Max(rb.drag, 1f); rb.angularDrag = Mathf.Max(rb.angularDrag, 1f); } liveMixin.gameObject.EnsureComponent <EcoTarget>().SetTargetType(EcoTargetType.DeadMeat); if (creatureDeath) { if (creatureDeath.respawn && !creatureDeath.respawnOnlyIfKilledByCreature) { creatureDeath.SpawnRespawner(); } if (creatureDeath.removeCorpseAfterSeconds >= 0.0) { creatureDeath.Invoke("RemoveCorpse", creatureDeath.removeCorpseAfterSeconds); } creatureDeath.SyncFixedUpdatingState(); } }
public static void Postfix(CreatureDeath __instance) { if (__instance.TryGetComponent(out WaterParkCreature waterParkCreature) && waterParkCreature.IsInsideWaterPark()) { return; } if (__instance.liveMixin == null || !Main.typesToMakePickupable.Contains(CraftData.GetTechType(__instance.gameObject))) { return; } if (__instance.liveMixin.IsAlive() && __instance.liveMixin.health <= (__instance.liveMixin.initialHealth / 5)) { var pickupable = __instance.gameObject.EnsureComponent <Pickupable>(); pickupable.isPickupable = true; pickupable.randomizeRotationWhenDropped = true; } else if (__instance.gameObject.TryGetComponent(out Pickupable pickupable)) { pickupable.isPickupable = false; } }
/// <summary> /// (Cross-Game compatible) Returns a new string containing just the creatures actual name. Removes all extra characters from it /// </summary> /// <param name="__instance">CreatureDeath __instance</param> /// <returns>Cleaned creature name</returns> public static string GetName(CreatureDeath __instance) { return(__instance.gameObject.name.Split('(')[0]); }
public static void Postfix(CreatureDeath __instance) { AddExperience(__instance.liveMixin.maxHealth * Config.GetConfig().OnKillcreatureKillXP_Modifier *Config.GetConfig().XP_Multiplier); }
public static void Postfix(CreatureDeath __instance) { ErrorMessage.AddDebug("OnKill " + __instance.gameObject.name); }
static void KillFish(LiveMixin liveMixin) { //AddDebug("KillFish " + liveMixin.gameObject.name); //Main.Log("Kill " + liveMixin.gameObject.name); liveMixin.health = 0f; liveMixin.tempDamage = 0f; liveMixin.SyncUpdatingState(); //if (liveMixin.deathClip) // liveMixin.deathClip.Play(); //if (liveMixin.deathSound) // Utils.PlayFMODAsset(liveMixin.deathSound, liveMixin.transform); //if (liveMixin.passDamageDataOnDeath) // liveMixin.gameObject.BroadcastMessage("OnKill", DamageType.Normal, SendMessageOptions.DontRequireReceiver); //else if (liveMixin.broadcastKillOnDeath) // liveMixin.gameObject.BroadcastMessage("OnKill", SendMessageOptions.DontRequireReceiver); //if (liveMixin.sendKillOnDeath) //{ // if (liveMixin.passDamageDataOnDeath) // liveMixin.gameObject.SendMessage("OnKill", DamageType.Normal, SendMessageOptions.DontRequireReceiver); // else // liveMixin.gameObject.SendMessage("OnKill", SendMessageOptions.DontRequireReceiver); //} AquariumFish af = liveMixin.GetComponent <AquariumFish>(); if (af) { UnityEngine.Object.Destroy(af); } Locomotion locomotion = liveMixin.GetComponent <Locomotion>(); locomotion.enabled = false; CreatureDeath creatureDeath = liveMixin.GetComponent <CreatureDeath>(); Eatable eatable = liveMixin.GetComponent <Eatable>(); eatable.SetDecomposes(true); Rigidbody rb = liveMixin.GetComponent <Rigidbody>(); if (rb) { rb.isKinematic = false; rb.constraints = RigidbodyConstraints.None; WorldForces worldForces = liveMixin.GetComponent <WorldForces>(); if (worldForces) { worldForces.handleDrag = false; } rb.drag = Mathf.Max(rb.drag, 1f); rb.angularDrag = Mathf.Max(rb.angularDrag, 1f); } liveMixin.gameObject.EnsureComponent <EcoTarget>().SetTargetType(EcoTargetType.DeadMeat); if (creatureDeath) { if (creatureDeath.respawn && !creatureDeath.respawnOnlyIfKilledByCreature) { creatureDeath.SpawnRespawner(); } if (creatureDeath.removeCorpseAfterSeconds >= 0.0) { creatureDeath.Invoke("RemoveCorpse", creatureDeath.removeCorpseAfterSeconds); } creatureDeath.SyncFixedUpdatingState(); } Pickupable pickupable = liveMixin.GetComponent <Pickupable>(); ItemsContainer container = pickupable.inventoryItem.container as ItemsContainer; if (container != null) { // fix offset decay bar container.RemoveItem(pickupable, true); container.AddItem(pickupable); } }
public static bool TryKillCreature(Creature creature) { if (creature != null && creature.enabled && creature.gameObject != null) { string realName = creature.name.Replace("(Clone)", String.Empty); var creatureConfiguration = settings.UnwantedCreaturesList.FirstOrDefault(c => c.Name.ToLowerInvariant() == realName.ToLowerInvariant()); if (settings.IsDebugEnabled && settings.IsCreatureListEnabled) { if (creaturesFound.Add(realName)) { List <string> listOfCreatures = creaturesFound.ToList(); listOfCreatures.Sort(); log(Logger.Level.Debug, "Found creatures:\n'{0}'", String.Join("',\n'", listOfCreatures)); } } if (creatureConfiguration != null) { randomMutex.WaitOne(); int random = rEngine.Next(1, 101); randomMutex.ReleaseMutex(); if (isDebugEnabled) { statsMutex.WaitOne(); string creatureName = creatureConfiguration.Name; HashSet <Creature> creatures; if (!creatureMap.TryGetValue(creatureName, out creatures)) { creatures = new HashSet <Creature>(); } creatures.Add(creature); creatureMap[creatureName] = creatures; if (!creatureConfiguration.SpawnConfiguration.CanSpawn || random >= creatureConfiguration.SpawnConfiguration.SpawnChance) { int killed = 0; if (!creaturesKilled.TryGetValue(creatureName, out killed)) { killed = 0; } killed++; creaturesKilled[creatureName] = killed; } foreach (var pair in creatureMap) { string name = pair.Key; int numFound = pair.Value.Count; int numKilled = creaturesKilled[name]; double percSpawned = ((double)(numFound - numKilled) / (double)numFound) * 100d; log(Logger.Level.Debug, "{0}: {1} {0}(s) found. {2} {0}(s) killed. {3}% of {0}(s) spawned.", name, numFound, numKilled, percSpawned); } log(Logger.Level.Debug, ""); statsMutex.ReleaseMutex(); } if (!creatureConfiguration.SpawnConfiguration.CanSpawn || random >= creatureConfiguration.SpawnConfiguration.SpawnChance) { creature.tag = "Untagged"; creature.leashPosition = UnityEngine.Vector3.zero; CreatureDeath cDeath = creature.gameObject.GetComponent <CreatureDeath>(); if (cDeath != null) { cDeath.eatable = null; cDeath.respawn = false; cDeath.removeCorpseAfterSeconds = 1.0f; } if (creature.liveMixin != null && creature.liveMixin.IsAlive()) { if (creature.liveMixin.data != null) { creature.liveMixin.data.deathEffect = null; creature.liveMixin.data.passDamageDataOnDeath = false; creature.liveMixin.data.broadcastKillOnDeath = true; creature.liveMixin.data.destroyOnDeath = true; creature.liveMixin.data.explodeOnDestroy = false; } creature.liveMixin.Kill(); } else { creature.BroadcastMessage("OnKill"); } return(true); } } } return(false); }