private void MaybeAwardLoot(On.RoR2.CharacterBody.orig_OnInventoryChanged orig, CharacterBody self) { orig(self); var amount = self.inventory.GetItemCount(Definition.itemIndex); if (amount > 0 && amount % 3 == 0) { self.inventory.RemoveItem(Definition.itemIndex, 3); PickupIndex loot; if (Util.CheckRoll(5, self.master)) { loot = Run.instance.treasureRng.NextElementUniform(Run.instance.availableTier3DropList); } else { loot = Run.instance.treasureRng.NextElementUniform(Run.instance.availableTier2DropList); } if (self.isPlayerControlled) { PickupDropletController.CreatePickupDroplet(loot, self.corePosition, Vector3.up * 5); } else { PickupDef def = PickupCatalog.GetPickupDef(loot); self.inventory.GiveItem(def.itemIndex); var lootCount = self.inventory.GetItemCount(def.itemIndex); Chat.AddPickupMessage(self, def.nameToken, ColorCatalog.GetColor(ItemCatalog.GetItemDef(def.itemIndex).colorIndex), (uint)lootCount); } } }
static IEnumerator <int> SpawnItemsCoroutine(uint connectionID) { while (characterMasters[connectionID].GetBody() == null) { yield return(0); } foreach (int itemID in items[connectionID].Keys) { for (int itemCount = 0; itemCount < items[connectionID][itemID]; itemCount++) { if (Data.allItemIDs.ContainsKey(itemID)) { characterMasters[connectionID].GetBody().inventory.GiveItem(Data.allItemIDs[itemID]); } else if (Data.allEquipmentIDs.ContainsKey(itemID)) { characterMasters[connectionID].GetBody().inventory.SetEquipmentIndex(Data.allEquipmentIDs[itemID]); } } PickupIndex pickupIndex = new PickupIndex(); bool pickupCreated = false; if (Data.allItemIDs.ContainsKey(itemID)) { pickupCreated = true; pickupIndex = new PickupIndex(Data.allItemIDs[itemID]); } else if (Data.allEquipmentIDs.ContainsKey(itemID)) { pickupCreated = true; pickupIndex = new PickupIndex(Data.allEquipmentIDs[itemID]); } if (pickupCreated) { Chat.AddPickupMessage(characterMasters[connectionID].GetBody(), pickupIndex.GetPickupNameToken(), pickupIndex.GetPickupColor(), System.Convert.ToUInt32(items[connectionID][itemID])); } } if (Data.mode == DataEarntConsumable.mode) { Connection connection = new Connection { _connectionID = connectionID }; connection.Send(R2API.Networking.NetworkDestination.Clients); } yield return(0); }
private void GiveRandomRed(On.RoR2.CharacterBody.orig_OnInventoryChanged orig, CharacterBody self) //ripped from harbcrate, i did credit though. { orig(self); var amount = GetCount(self); if (amount > 1) { self.inventory.RemoveItem(catalogIndex); PickupIndex loot = Run.instance.treasureRng.NextElementUniform(Run.instance.availableTier3DropList); if (self.isPlayerControlled) { PickupDropletController.CreatePickupDroplet(loot, self.corePosition, Vector3.up * 5); } else { PickupDef def = PickupCatalog.GetPickupDef(loot); self.inventory.GiveItem(def.itemIndex); var lootCount = self.inventory.GetItemCount(def.itemIndex); Chat.AddPickupMessage(self, def.nameToken, ColorCatalog.GetColor(ItemCatalog.GetItemDef(def.itemIndex).colorIndex), (uint)lootCount); } } }
public void Awake() { ReadConfig(); SetupArtifact(); On.RoR2.CharacterMaster.OnBodyDeath += (orig, master, body) => { bool couldrespawn = false; if (master.inventory.GetItemCount(RoR2Content.Items.ExtraLife) > 0) { couldrespawn = true; } orig(master, body); if (!couldrespawn) { DropStolenInventory(body); } }; On.RoR2.CharacterBody.Start += (orig, body) => { UpdateThiefBuff(body); orig(body); }; //Enemy Item Pickup Related Hooks On.RoR2.GenericPickupController.BodyHasPickupPermission += (orig, body) => { if (body.masterObject) { if (body.inventory) { if (RunArtifactManager.instance.IsArtifactEnabled(Grief.artifactIndex) && EnemyCanPickup.Value) { MinionOwnership minionowner = body.master.minionOwnership; if (!minionowner || !minionowner.ownerMaster) { return(true); } } else if (body.masterObject.GetComponent <PlayerCharacterMasterController>()) { TeamComponent component = body.GetComponent <TeamComponent>(); if (component && component.teamIndex == TeamIndex.Player) { return(true); } } } } return(false); }; On.RoR2.GenericPickupController.AttemptGrant += (orig, gpc, body) => { orig(gpc, body); if (RunArtifactManager.instance.IsArtifactEnabled(Grief.artifactIndex) && EnemyCanPickup.Value) { TeamComponent component = body.GetComponent <TeamComponent>(); if (component && component.teamIndex != TeamIndex.Player) { Inventory inventory = body.inventory; if (inventory) { PickupDef pickupDef = PickupCatalog.GetPickupDef(gpc.pickupIndex); if (pickupDef.itemIndex != ItemIndex.None) { gpc.gameObject.SetActive(false); inventory.GiveItem(pickupDef.itemIndex, 1); Chat.AddPickupMessage(body, ((pickupDef != null) ? pickupDef.nameToken : null) ?? PickupCatalog.invalidPickupToken, (pickupDef != null) ? pickupDef.baseColor : Color.black, 1); if (body) { Util.PlaySound("Play_UI_item_pickup", body.gameObject); } AddToStolenInventory(body, body.master.gameObject, pickupDef.itemIndex, 1); UnityEngine.Object.Destroy(gpc.gameObject); } } } } }; //Setup Grief from Damage Report On.RoR2.CharacterBody.OnTakeDamageServer += (orig, charbody, damageReport) => { orig(charbody, damageReport); if (RunArtifactManager.instance.IsArtifactEnabled(Grief.artifactIndex)) { if (charbody.master) { CharacterMaster master = charbody.master; if (master.playerCharacterMasterController) { SetupGriefFromDamageReport(master, damageReport); } } } }; }