-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreatureDeath_Patch.cs
85 lines (79 loc) · 3.5 KB
/
CreatureDeath_Patch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using static ErrorMessage;
namespace Tweaks_Fixes
{
[HarmonyPatch(typeof(CreatureDeath))]
internal class CreatureDeath_Patch
{
public static HashSet<CreatureDeath> creatureDeathsToDestroy = new HashSet<CreatureDeath>();
public static HashSet<TechType> notRespawningCreatures;
public static HashSet<TechType> notRespawningCreaturesIfKilledByPlayer;
public static Dictionary<TechType, int> respawnTime = new Dictionary<TechType, int>();
public static void TryRemoveCorpses()
{
//AddDebug("TryRemoveCorpses " + creatureDeathsToDestroy.Count);
foreach (var cd in creatureDeathsToDestroy)
{
Pickupable pickupable = cd.GetComponent<Pickupable>();
if (pickupable)
{
if (pickupable._isInSub || pickupable.inventoryItem != null)
{
//AddDebug("try RemoveCorpse inventoryItem " + cd.name);
continue;
}
}
//AddDebug("RemoveCorpse " + cd.name);
if (ConfigToEdit.removeDeadCreaturesOnLoad.Value)
UnityEngine.Object.Destroy(cd.gameObject);
}
}
[HarmonyPostfix]
[HarmonyPatch("Start")]
static void StartPostfix(CreatureDeath __instance)
{
TechType techType = CraftData.GetTechType(__instance.gameObject);
//if (!creatureDeaths.Contains(techType))
//{
// creatureDeaths.Add(techType);
// Main.logger.LogMessage("CreatureDeath " + techType + " respawns " + __instance.respawn + " respawnOnlyIfKilledByCreature " + __instance.respawnOnlyIfKilledByCreature + " respawnInterval " + __instance.respawnInterval);
//}
__instance.respawn = !notRespawningCreatures.Contains(techType);
__instance.respawnOnlyIfKilledByCreature = notRespawningCreaturesIfKilledByPlayer.Contains(techType);
//Main.logger.LogMessage("CreatureDeath Start " + techType + " respawn " + __instance.respawn);
//Main.logger.LogMessage("CreatureDeath Start " + techType + " respawnOnlyIfKilledByCreature " + __instance.respawnOnlyIfKilledByCreature);
if (respawnTime.ContainsKey(techType))
__instance.respawnInterval = respawnTime[techType] * DayNightCycle.kDayLengthSeconds;
}
[HarmonyPostfix]
[HarmonyPatch("OnTakeDamage")]
static void OnTakeDamagePostfix(CreatureDeath __instance, DamageInfo damageInfo)
{
//AddDebug(__instance.name + " OnTakeDamage " + damageInfo.dealer.name);
if (!ConfigToEdit.heatBladeCooks.Value && damageInfo.type == DamageType.Heat && damageInfo.dealer == Player.mainObject)
__instance.lastDamageWasHeat = false;
}
[HarmonyPrefix]
[HarmonyPatch("RemoveCorpse")]
static bool RemoveCorpsePrefix(CreatureDeath __instance)
{
if (!Main.gameLoaded)
{
creatureDeathsToDestroy.Add(__instance);
return false;
}
return true;
}
//[HarmonyPostfix]
//[HarmonyPatch("SpawnRespawner")]
static void SpawnRespawnerPostfix(CreatureDeath __instance)
{
//AddDebug(__instance.name + " SpawnRespawner ");
}
}
}