// Ammo // -------------------------------------------------------------------------------- /// <summary>Fills the player's inventory with random items</summary> /// <param name="self">The Ammo instance</param> /// <param name="fillTo"></param> public static void DebugFillRandomAmmo(this Ammo self) { var potentialAmmo = GetFieldOrPropertyValue <Ammo, GameObject[]>("potentialAmmo", self); var numSlots = GetFieldOrPropertyValue <Ammo, int>("numSlots", self); var ammoSlot = typeof(Ammo).GetNestedType("Slot", all); var slots = GetFieldOrPropertyValue <Ammo, object[]>("slots", self); var emotions = ammoSlot.GetField("emotions", all); for (var i = 0; i < numSlots; i++) { int fillTo = self.GetSlotMaxCount(i); // pick a random item to insert into the slot var plucked = Randoms.SHARED.Pluck(new List <GameObject>(potentialAmmo), null); // instantiate ammo slot var constructor = ammoSlot.GetConstructors()[0]; var parameters = constructor.GetParameters(); if (parameters[0].ParameterType == typeof(GameObject)) { slots[i] = Activator.CreateInstance(ammoSlot, plucked, fillTo); } else if (parameters[0].ParameterType == typeof(Identifiable.Id)) // 0.6.0+ { slots[i] = Activator.CreateInstance(ammoSlot, plucked.GetComponent <Identifiable>().id, fillTo); } if (!Identifiable.IsSlime(plucked.GetComponent <Identifiable>().id)) { continue; } var emotionData = new SlimeEmotionData { [SlimeEmotions.Emotion.AGITATION] = 0, [SlimeEmotions.Emotion.HUNGER] = .5f, [SlimeEmotions.Emotion.FEAR] = 0, }; emotions?.SetValue(slots[i], emotionData); } // Refill Ammo again, because some mods might change the max value depending on what is in the slot DebugRefillAmmo(self); }
// Ammo // -------------------------------------------------------------------------------- /// <summary>Fills the player's inventory with random items</summary> /// <param name="self">The Ammo instance</param> /// <param name="fillTo"></param> public static void DebugFillRandomAmmo(this Ammo self, int fillTo) { var potentialAmmo = GetPrivateField <Ammo, GameObject[]>("potentialAmmo", self); var numSlots = GetPrivateField <Ammo, int>("numSlots", self); var ammoSlot = typeof(Ammo).GetNestedType("Slot", BindingFlags.NonPublic | BindingFlags.Instance); var slots = GetPrivateField <Ammo, object[]>("slots", self); var emotions = ammoSlot.GetField("emotions", BindingFlags.Public | BindingFlags.Instance); for (var i = 0; i < numSlots; i++) { // pick a random item to insert into the slot var plucked = Randoms.SHARED.Pluck(new List <GameObject>(potentialAmmo), null); // instantiate ammo slot var constructor = ammoSlot.GetConstructors()[0]; var parameters = constructor.GetParameters(); if (parameters[0].ParameterType == typeof(GameObject)) { slots[i] = Activator.CreateInstance(ammoSlot, plucked, fillTo); } else if (parameters[0].ParameterType == typeof(Identifiable.Id)) // 0.6.0+ { slots[i] = Activator.CreateInstance(ammoSlot, plucked.GetComponent <Identifiable>().id, fillTo); } if (!Identifiable.IsSlime(plucked.GetComponent <Identifiable>().id)) { continue; } var emotionData = new SlimeEmotionData { [SlimeEmotions.Emotion.AGITATION] = 0, [SlimeEmotions.Emotion.HUNGER] = .5f, [SlimeEmotions.Emotion.FEAR] = 0, }; emotions?.SetValue(slots[i], emotionData); } }
// Ammo // -------------------------------------------------------------------------------- /// <summary>Fills the player's inventory with random items</summary> /// <param name="self">The Ammo instance</param> public static void DebugFillRandomAmmo(this Ammo self) { var potentialAmmo = self.potentialAmmo; var numSlots = self.numSlots; var ammoSlot = typeof(Ammo).GetNestedType("Slot", all); var slots = self.Slots; var emotions = ammoSlot.GetField("emotions", all); for (var i = 0; i < numSlots; i++) { int fillTo = self.GetSlotMaxCount(i); // pick a random item to insert into the slot var plucked = Randoms.SHARED.Pluck(new HashSet <Identifiable.Id>(potentialAmmo), Identifiable.Id.NONE); // instantiate ammo slot var constructor = ammoSlot.GetConstructors()[0]; var parameters = constructor.GetParameters(); if (parameters[0].ParameterType == typeof(Identifiable.Id)) { slots[i] = (Ammo.Slot)Activator.CreateInstance(ammoSlot, plucked, fillTo); } if (!Identifiable.IsSlime(plucked)) { continue; } var emotiondata = new SlimeEmotionData { [SlimeEmotions.Emotion.AGITATION] = 0, [SlimeEmotions.Emotion.HUNGER] = .5f, [SlimeEmotions.Emotion.FEAR] = 0, }; emotions?.SetValue(slots[i], emotiondata); } // Refill Ammo again, because some mods might change the max value depending on what is in the slot DebugRefillAmmo(self); }