public virtual void Die() { this.isDead = true; if (gameObject.tag.Equals("Player")) { gameObject.GetComponent <MeshRenderer>().enabled = false; var renderers = gameObject.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer mr in renderers) { mr.enabled = false; } gameObject.GetComponent <BoxCollider>().enabled = false; gameObject.GetComponent <Rigidbody>().isKinematic = true; StartCoroutine(LoadGameOver()); //SceneManager.LoadScene(SceneManager.GetActiveScene().name); } //Drop Item Or Key ItemDrop dropper = gameObject.GetComponent <ItemDrop>(); if (dropper) { if (HoldingKey) { //Debug.Log("I Should Drop A Key"); //Drop Key dropper.DropKey(this.gameObject.transform); } else { //Drop Item dropper.DropItem(this.gameObject.transform); } } }
static void Prefix(Player __instance) { if (!modEnabled.Value || !Player.m_localPlayer || backpackInventory == null || __instance.GetPlayerID() != Player.m_localPlayer.GetPlayerID() || backpackInventory.NrOfItems() == 0) { return; } if (dropInventoryOnDeath.Value) { if (createTombStone.Value) { GameObject gameObject = Instantiate(__instance.m_tombstone, __instance.GetCenterPoint() + Vector3.forward, __instance.transform.rotation); gameObject.GetComponent <Container>().GetInventory().MoveInventoryToGrave(backpackInventory); TombStone component = gameObject.GetComponent <TombStone>(); PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); component.Setup(playerProfile.GetName(), playerProfile.GetPlayerID()); } else { List <ItemDrop.ItemData> allItems = backpackInventory.GetAllItems(); foreach (ItemDrop.ItemData item in allItems) { Vector3 position = __instance.transform.position + Vector3.up * 0.5f + UnityEngine.Random.insideUnitSphere * 0.3f; Quaternion rotation = Quaternion.Euler(0f, UnityEngine.Random.Range(0, 360), 0f); ItemDrop.DropItem(item, 0, position, rotation); backpackInventory.RemoveAll(); } } } }
void DropItem() { if (itemDrop != null) { itemDrop.DropItem(); } }
// This is an exact copy of the ingame method "DropItem" to provide a reliable way of controlling it later static bool Prefix(Humanoid __instance, ref bool __result, Inventory inventory, ItemDrop.ItemData item, int amount, ItemDrop.ItemData ___m_hiddenLeftItem, ItemDrop.ItemData ___m_hiddenRightItem, ZSyncAnimation ___m_zanim, EffectList ___m_dropEffects, VisEquipment ___m_visEquipment) { if (item.m_shared.m_questItem) { __instance.Message(MessageHud.MessageType.Center, "$msg_cantdrop"); __result = false; return(false); } __instance.RemoveFromEquipQueue(item); __instance.UnequipItem(item, triggerEquipEffects: false); if (___m_hiddenLeftItem == item) { ___m_hiddenLeftItem = null; _setupVisEquipment.Invoke(__instance, new [] { ___m_visEquipment, (object)false }); } if (___m_hiddenRightItem == item) { ___m_hiddenRightItem = null; _setupVisEquipment.Invoke(__instance, new [] { ___m_visEquipment, (object)false }); } if (amount == item.m_stack) { // ZLog.Log("drop all " + amount + " " + item.m_stack); if (!inventory.RemoveItem(item)) { // ZLog.Log("Was not removed"); __result = false; return(false); } } else { // ZLog.Log("drop some " + amount + " " + item.m_stack); inventory.RemoveItem(item, amount); } ItemDrop itemDrop = ItemDrop.DropItem(item, amount, __instance.transform.position + __instance.transform.forward + __instance.transform.up, __instance.transform.rotation); Longship.Instance.EventManager.DispatchEvent(new HumanoidDropItemEvent(__instance, item, amount)); if (__instance.IsPlayer()) { itemDrop.OnPlayerDrop(); } itemDrop.GetComponent <Rigidbody>().velocity = (__instance.transform.forward + Vector3.up) * 5f; ___m_zanim.SetTrigger("interact"); ___m_dropEffects.Create(__instance.transform.position, Quaternion.identity); __instance.Message(MessageHud.MessageType.TopLeft, "$msg_dropped " + itemDrop.m_itemData.m_shared.m_name, itemDrop.m_itemData.m_stack, itemDrop.m_itemData.GetIcon()); __result = true; return(false); }
public override void DoCrafting(InventoryGui __instance, Player player) { if (SelectedRecipe >= 0 && SelectedRecipe < Recipes.Count) { var recipe = Recipes[SelectedRecipe]; var inventory = player.GetInventory(); var disenchantCount = _disenchantAllFlag ? recipe.FromItem.m_stack : 1; inventory.RemoveItem(recipe.FromItem, disenchantCount); var didntAdd = new List <KeyValuePair <ItemDrop.ItemData, int> >(); foreach (var product in recipe.Products) { var amountToAdd = product.Value * disenchantCount; var addSuccess = false; var canAdd = player.GetInventory().CanAddItem(product.Key.m_itemData, amountToAdd); if (canAdd) { var itemData = player.GetInventory().AddItem(product.Key.name, amountToAdd, 1, 0, 0, ""); addSuccess = itemData != null; if (itemData != null && itemData.IsMagicCraftingMaterial()) { itemData.m_variant = EpicLoot.GetRarityIconIndex(itemData.GetRarity()); } } if (!addSuccess) { var newItem = product.Key.m_itemData.Clone(); newItem.m_dropPrefab = ObjectDB.instance.GetItemPrefab(product.Key.GetPrefabName(product.Key.gameObject.name)); didntAdd.Add(new KeyValuePair <ItemDrop.ItemData, int>(newItem, amountToAdd)); } } __instance.UpdateCraftingPanel(); foreach (var itemNotAdded in didntAdd) { var itemDrop = ItemDrop.DropItem(itemNotAdded.Key, itemNotAdded.Value, player.transform.position + player.transform.forward + player.transform.up, player.transform.rotation); itemDrop.GetComponent <Rigidbody>().velocity = (player.transform.forward + Vector3.up) * 5f; player.Message(MessageHud.MessageType.TopLeft, $"$msg_dropped {itemDrop.m_itemData.m_shared.m_name} $mod_epicloot_sacrifice_inventoryfullexplanation", itemDrop.m_itemData.m_stack, itemDrop.m_itemData.GetIcon()); } if (player.GetCurrentCraftingStation() != null) { player.GetCurrentCraftingStation().m_craftItemDoneEffects.Create(player.transform.position, Quaternion.identity); } Game.instance.GetPlayerProfile().m_playerStats.m_crafts++; Gogan.LogEvent("Game", "Disenchanted", recipe.FromItem.m_shared.m_name, 1); } _disenchantAllFlag = false; }
public static void Postfix() { var player = Player.m_localPlayer; if (player == null) { return; } EquipmentAndQuickSlots.LogWarning("Recovered Tombstone Items, verifying inventory..."); var droppedItems = new List <ItemDrop.ItemData>(); foreach (var inventory in player.GetAllInventories()) { foreach (var itemData in inventory.m_inventory) { var isOutsideInventoryGrid = itemData.m_gridPos.x < 0 || itemData.m_gridPos.x >= inventory.m_width || itemData.m_gridPos.y < 0 || itemData.m_gridPos.y >= inventory.m_height; if (isOutsideInventoryGrid) { var itemText = Localization.instance.Localize(itemData.m_shared.m_name) + (itemData.m_stack > 1 ? $" x{itemData.m_stack}" : ""); EquipmentAndQuickSlots.LogWarning($"> Item Outside Inventory Grid! ({itemText}, <{itemData.m_gridPos.x},{itemData.m_gridPos.y}>)"); inventory.RemoveItem(itemData); var addSuccess = inventory.AddItem(itemData); if (!addSuccess) { EquipmentAndQuickSlots.LogError($"> Could not add item to inventory, item dropped! ({itemText})"); droppedItems.Add(itemData); ItemDrop.DropItem(itemData, itemData.m_stack, player.transform.position + player.transform.forward * 2 + Vector3.up, Quaternion.identity); } } } } if (droppedItems.Count > 0) { var droppedItemTexts = droppedItems.Select(x => Localization.instance.Localize(x.m_shared.m_name) + (x.m_stack > 1 ? $" x{x.m_stack}" : "")); var droppedItemsMessage = ">>>> ERROR IN TOMBSTONE RECOVERY - ITEMS DROPPED: " + string.Join(", ", droppedItemTexts); player.Message(MessageHud.MessageType.Center, droppedItemsMessage); Debug.LogError(droppedItemsMessage); EquipmentAndQuickSlots.LogError(droppedItemsMessage); } else { EquipmentAndQuickSlots.LogWarning("> No issues!"); } }
// Token: 0x06000CA7 RID: 3239 RVA: 0x0005AAE0 File Offset: 0x00058CE0 private void DropAllItems() { List <ItemDrop.ItemData> allItems = this.m_inventory.GetAllItems(); int num = 1; foreach (ItemDrop.ItemData item in allItems) { Vector3 position = base.transform.position + Vector3.up * 0.5f + UnityEngine.Random.insideUnitSphere * 0.3f; Quaternion rotation = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); ItemDrop.DropItem(item, 0, position, rotation); num++; } this.m_inventory.RemoveAll(); this.Save(); }
private void UpdateList(List <INpc> list) { List <int> indicesToRemove = new List <int>(); for (int i = 0; i < list.Count; i++) { ISpawnable item = list[i]; item.Update(); if (item.SafeToDespawn) { if (item.GetType() == typeof(Aquamentus) || item.GetType() == typeof(Skeleton) || item.GetType() == typeof(Goriya) || item.GetType() == typeof(Hand)) { itemDropper.DropItem(item.Position); } indicesToRemove.Add(i); } } for (int i = 0; i < indicesToRemove.Count; i++) { list.RemoveAt(indicesToRemove[i] - i); } }
private void OnDeath() { if (m_inventory.SlotsUsedPercentage() == 0) { return; } List <ItemDrop.ItemData> allItems = m_inventory.GetAllItems(); int num = 1; foreach (ItemDrop.ItemData item in allItems) { Vector3 position = base.transform.position + Vector3.up * 0.5f + UnityEngine.Random.insideUnitSphere * 0.3f; Quaternion rotation = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); ItemDrop.DropItem(item, 0, position, rotation); num++; } //m_inventory.RemoveAll(); //Traverse.Create(container).Method("Save").GetValue(); }
// Token: 0x0600030A RID: 778 RVA: 0x0001A06C File Offset: 0x0001826C private void SpawnOnHit(GameObject go, Collider collider) { if (this.m_groundHitOnly && go.GetComponent <Heightmap>() == null) { return; } if (this.m_staticHitOnly) { if (collider && collider.attachedRigidbody != null) { return; } if (go && go.GetComponent <IDestructible>() != null) { return; } } if (this.m_spawnOnHitChance < 1f && UnityEngine.Random.value > this.m_spawnOnHitChance) { return; } Vector3 vector = base.transform.position + base.transform.TransformDirection(this.m_spawnOffset); Quaternion rotation = base.transform.rotation; if (this.m_spawnRandomRotation) { rotation = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); } if (this.m_spawnOnHit != null) { IProjectile component = UnityEngine.Object.Instantiate <GameObject>(this.m_spawnOnHit, vector, rotation).GetComponent <IProjectile>(); if (component != null) { component.Setup(this.m_owner, this.m_vel, this.m_hitNoise, null, null); } } if (this.m_spawnItem != null) { ItemDrop.DropItem(this.m_spawnItem, 0, vector, base.transform.rotation); } this.m_spawnOnHitEffects.Create(vector, Quaternion.identity, null, 1f); }
static void Postfix(InventoryGui __instance, ItemDrop.ItemData ___m_dragItem, Inventory ___m_dragInventory, int ___m_dragAmount, ref GameObject ___m_dragGo) { if (Input.GetKeyDown(m_hotkey.Value) && ___m_dragItem != null && ___m_dragInventory.ContainsItem(___m_dragItem)) { Dbgl($"Discarding {___m_dragAmount}/{___m_dragItem.m_stack} {___m_dragItem.m_shared.m_name}"); if (returnResources.Value) { Recipe recipe = ObjectDB.instance.GetRecipe(___m_dragItem); if (recipe != null) { for (int i = 0; i < ___m_dragAmount; i++) { foreach (Piece.Requirement req in recipe.m_resources) { ItemDrop.ItemData newItem = req.m_resItem.m_itemData.Clone(); newItem.m_stack = recipe.m_amount; if (!Player.m_localPlayer.GetInventory().AddItem(newItem)) { ItemDrop itemDrop = ItemDrop.DropItem(newItem, newItem.m_stack, Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward + Player.m_localPlayer.transform.up, Player.m_localPlayer.transform.rotation); itemDrop.GetComponent <Rigidbody>().velocity = (Player.m_localPlayer.transform.forward + Vector3.up) * 5f; } } } } } if (___m_dragAmount == ___m_dragItem.m_stack) { ___m_dragInventory.RemoveItem(___m_dragItem); } else { ___m_dragInventory.RemoveItem(___m_dragItem, ___m_dragAmount); } Destroy(___m_dragGo); ___m_dragGo = null; __instance.GetType().GetMethod("UpdateCraftingPanel", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { false }); } }
void Death() { isDead = true; boxCollider.enabled = false; if (gameObject.tag == "Skeleton") { Animator2.SetTrigger("Dead"); itemDrop.DropItem(); } else if (gameObject.tag == "Enemy") { Animator.SetTrigger("Dead"); ScorePoints(); if (DidStole) { StartCoroutine("Drop"); } } }
static bool Prefix(Player __instance, Inventory ___m_inventory, ref float ___m_timeSinceDeath, float ___m_hardDeathCooldown, ZNetView ___m_nview, List <Player.Food> ___m_foods, Skills ___m_skills) { if (!modEnabled.Value) { return(true); } ___m_nview.GetZDO().Set("dead", true); ___m_nview.InvokeRPC(ZNetView.Everybody, "OnDeath", new object[] { }); Game.instance.GetPlayerProfile().m_playerStats.m_deaths++; Game.instance.GetPlayerProfile().SetDeathPoint(__instance.transform.position); if (createDeathEffects.Value) { Traverse.Create(__instance).Method("CreateDeathEffects").GetValue(); } List <ItemDrop.ItemData> dropItems = new List <ItemDrop.ItemData>(); if (!keepAllItems.Value) { List <Inventory> inventories = new List <Inventory>(); if (quickSlotsAssembly != null) { var extendedInventory = quickSlotsAssembly.GetType("EquipmentAndQuickSlots.InventoryExtensions").GetMethod("Extended", BindingFlags.Public | BindingFlags.Static).Invoke(null, new object[] { ___m_inventory }); inventories = (List <Inventory>)quickSlotsAssembly.GetType("EquipmentAndQuickSlots.ExtendedInventory").GetField("_inventories", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(extendedInventory); } else { inventories.Add(___m_inventory); } for (int i = 0; i < inventories.Count; i++) { Inventory inv = inventories[i]; if (quickSlotsAssembly != null && keepQuickSlotItems.Value && inv == (Inventory)quickSlotsAssembly.GetType("EquipmentAndQuickSlots.PlayerExtensions").GetMethod("GetQuickSlotInventory", BindingFlags.Public | BindingFlags.Static).Invoke(null, new object[] { __instance })) { Dbgl("Skipping quick slot inventory"); continue; } List <ItemDrop.ItemData> keepItems = Traverse.Create(inv).Field("m_inventory").GetValue <List <ItemDrop.ItemData> >(); if (destroyAllItems.Value) { keepItems.Clear(); } else { for (int j = keepItems.Count - 1; j >= 0; j--) { ItemDrop.ItemData item = keepItems[j]; if (keepEquippedItems.Value && item.m_equiped) { continue; } if (keepHotbarItems.Value && item.m_gridPos.y == 0) { continue; } if (item.m_shared.m_questItem) { continue; } if (destroyItemTypes.Value.Length > 0) { string[] destroyTypes = destroyItemTypes.Value.Split(','); if (destroyTypes.Contains(Enum.GetName(typeof(ItemDrop.ItemData.ItemType), item.m_shared.m_itemType))) { keepItems.RemoveAt(j); continue; } } if (keepItemTypes.Value.Length > 0) { string[] keepTypes = keepItemTypes.Value.Split(','); if (keepTypes.Contains(Enum.GetName(typeof(ItemDrop.ItemData.ItemType), item.m_shared.m_itemType))) { continue; } } else if (dropItemTypes.Value.Length > 0) { string[] dropTypes = dropItemTypes.Value.Split(','); if (dropTypes.Contains(Enum.GetName(typeof(ItemDrop.ItemData.ItemType), item.m_shared.m_itemType))) { dropItems.Add(item); keepItems.RemoveAt(j); } continue; } dropItems.Add(item); keepItems.RemoveAt(j); } } Traverse.Create(inv).Method("Changed").GetValue(); } } if (useTombStone.Value && dropItems.Any()) { GameObject gameObject = Instantiate(__instance.m_tombstone, __instance.GetCenterPoint(), __instance.transform.rotation); gameObject.GetComponent <Container>().GetInventory().RemoveAll(); int width = Traverse.Create(___m_inventory).Field("m_width").GetValue <int>(); int height = Traverse.Create(___m_inventory).Field("m_height").GetValue <int>(); Traverse.Create(gameObject.GetComponent <Container>().GetInventory()).Field("m_width").SetValue(width); Traverse.Create(gameObject.GetComponent <Container>().GetInventory()).Field("m_height").SetValue(height); Traverse.Create(gameObject.GetComponent <Container>().GetInventory()).Field("m_inventory").SetValue(dropItems); Traverse.Create(gameObject.GetComponent <Container>().GetInventory()).Method("Changed").GetValue(); TombStone component = gameObject.GetComponent <TombStone>(); PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); component.Setup(playerProfile.GetName(), playerProfile.GetPlayerID()); } else { foreach (ItemDrop.ItemData item in dropItems) { Vector3 position = __instance.transform.position + Vector3.up * 0.5f + UnityEngine.Random.insideUnitSphere * 0.3f; Quaternion rotation = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); ItemDrop.DropItem(item, 0, position, rotation); } } if (!keepFoodLevels.Value) { ___m_foods.Clear(); } bool hardDeath = noSkillProtection.Value || ___m_timeSinceDeath > ___m_hardDeathCooldown; if (hardDeath && reduceSkills.Value) { ___m_skills.OnDeath(); } Game.instance.RequestRespawn(10f); ___m_timeSinceDeath = 0; if (!hardDeath) { __instance.Message(MessageHud.MessageType.TopLeft, "$msg_softdeath", 0, null); } __instance.Message(MessageHud.MessageType.Center, "$msg_youdied", 0, null); __instance.ShowTutorial("death", false); string eventLabel = "biome:" + __instance.GetCurrentBiome().ToString(); Gogan.LogEvent("Game", "Death", eventLabel, 0L); return(false); }
public static void RefreshEquipmentInSlots(Player player) { var inventories = player.GetAllInventories(); var equipSlotInventory = player.GetEquipmentSlotInventory(); var swaps = new List <SwapData>(); var drops = new List <SwapData>(); // Swap in newly equipped items foreach (var inventory in inventories) { if (inventory != equipSlotInventory) { foreach (var item in inventory.m_inventory) { if (item.m_equiped && EquipmentAndQuickSlots.IsSlotEquippable(item)) { var equipSlot = EquipmentAndQuickSlots.GetEquipmentSlotForType(item.m_shared.m_itemType); if (equipSlot.x < 0 || equipSlot.y < 0) { continue; } swaps.Add(new SwapData(inventory, item, equipSlotInventory, equipSlot)); EquipmentAndQuickSlots.LogWarning($"move ({item.m_shared.m_name}) to equip slot"); } } } } foreach (var swap in swaps) { Swap(swap.InventoryA, swap.Item, swap.InventoryB, swap.SlotB); } swaps.Clear(); // Swap out unequipped items and incorrectly added foreach (var item in equipSlotInventory.m_inventory) { if (!item.m_equiped || !EquipmentAndQuickSlots.IsSlotEquippable(item)) { var destInventories = player.GetAllInventories(); bool moved = false; foreach (var destInventory in destInventories) { if (!destInventory.CountAsEmptySlots(player)) { continue; } var emptySlot = destInventory.FindEmptySlot(false); if (emptySlot.x >= 0 && emptySlot.y >= 0) { moved = true; swaps.Add(new SwapData(equipSlotInventory, item, destInventory, emptySlot)); break; } } EquipmentAndQuickSlots.LogWarning($"move ({item.m_shared.m_name}) to main inventory"); if (!moved) { if (!CanEquip(item, player)) { player.Message(MessageHud.MessageType.Center, "Item force unequipped, inventory full, dropped item"); drops.Add(new SwapData(equipSlotInventory, item, null, new Vector2i())); } else { item.m_equiped = true; player.Message(MessageHud.MessageType.Center, "Could not unequip, inventory full"); } } } else { var equipSlot = EquipmentAndQuickSlots.GetEquipmentSlotForType(item.m_shared.m_itemType); if ((equipSlot.x >= 0 && equipSlot.y >= 0) && item.m_gridPos != equipSlot) { item.m_gridPos = equipSlot; EquipmentAndQuickSlots.LogWarning($"move ({item.m_shared.m_name}) to correct slot ({equipSlot})"); } } } foreach (var drop in drops) { ItemDrop.DropItem(drop.Item, drop.Item.m_stack, player.transform.position, Quaternion.identity); drop.InventoryA.RemoveItem(drop.Item); } drops.Clear(); foreach (var swap in swaps) { Swap(swap.InventoryA, swap.Item, swap.InventoryB, swap.SlotB); } swaps.Clear(); }
private static bool DropItem(Inventory inventory, ItemDrop.ItemData item, int amount, Humanoid __instance, ref bool __result) { // return and run the original if disabled or if this is not the player if (!Settings.MMDropItemUsingCameraDirection.Value || !__instance.IsPlayer()) { return(true); } // run the original code if the player has chosen to use Character Facing modifier and the modifier key is being held if (Settings.DropModifierBehavior.Value == Plugin.DropModifierBehavior.CharacterFacing && UtilityClass.CheckKeyHeld(Settings.DropModifierKey.Value)) { return(true); } // run the original code if the player has chosen to use Camera Facing modifier and the modifier key is NOT being held if (Settings.DropModifierBehavior.Value == Plugin.DropModifierBehavior.CameraDirection && !UtilityClass.CheckKeyHeld(Settings.DropModifierKey.Value)) { return(true); } // run the updated code... if (amount == 0) { __result = false; return(false); } if (item.m_shared.m_questItem) { __instance.Message(MessageHud.MessageType.Center, "$msg_cantdrop"); __result = false; return(false); } if (amount > item.m_stack) { amount = item.m_stack; } __instance.RemoveFromEquipQueue(item); __instance.UnequipItem(item, triggerEquipEffects: false); if (__instance.m_hiddenLeftItem == item) { __instance.m_hiddenLeftItem = null; __instance.SetupVisEquipment(__instance.m_visEquipment, isRagdoll: false); } if (__instance.m_hiddenRightItem == item) { __instance.m_hiddenRightItem = null; __instance.SetupVisEquipment(__instance.m_visEquipment, isRagdoll: false); } if (amount == item.m_stack) { ZLog.Log((object)("drop all " + amount + " " + item.m_stack)); Plugin.LogVerbose("drop all " + amount + " " + item.m_stack); if (!inventory.RemoveItem(item)) { ZLog.Log((object)"Was not removed"); __result = false; return(false); } } else { ZLog.Log((object)("drop some " + amount + " " + item.m_stack)); Plugin.Log("drop some " + amount + " " + item.m_stack); inventory.RemoveItem(item, amount); } //our change to support dropping on camera direction ItemDrop itemDrop; Plugin.Log($"Drop by player... using camera rotation"); itemDrop = ItemDrop.DropItem(item, amount, (__instance as Character).transform.position + GameCamera.instance.transform.forward + GameCamera.instance.transform.up, GameCamera.instance.transform.rotation); itemDrop.OnPlayerDrop(); itemDrop.GetComponent <Rigidbody>().velocity = (GameCamera.instance.transform.forward + Vector3.up) * 5f; //end our change.. __instance.m_zanim.SetTrigger("interact"); __instance.m_dropEffects.Create((__instance as Character).transform.position, Quaternion.identity); __instance.Message(MessageHud.MessageType.TopLeft, "$msg_dropped " + itemDrop.m_itemData.m_shared.m_name, itemDrop.m_itemData.m_stack, itemDrop.m_itemData.GetIcon()); __result = true; return(false); }
public static bool Prefix(Inventory __instance, ZPackage pkg) { var version = pkg.ReadInt(); var itemCount = pkg.ReadInt(); __instance.m_inventory.Clear(); OutsideItems.Clear(); GraveItems.Clear(); DroppedItems.Clear(); for (var index = 0; index < itemCount; ++index) { var name = pkg.ReadString(); var stack = pkg.ReadInt(); var durability = pkg.ReadSingle(); var pos = pkg.ReadVector2i(); var equiped = pkg.ReadBool(); var quality = 1; if (version >= 101) { quality = pkg.ReadInt(); } var variant = 0; if (version >= 102) { variant = pkg.ReadInt(); } long crafterID = 0; var crafterName = ""; if (version >= 103) { crafterID = pkg.ReadLong(); crafterName = pkg.ReadString(); } if (name != "") { __instance.AddItem(name, stack, durability, pos, equiped, quality, variant, crafterID, crafterName); if (IsOutsideInventory(__instance, pos)) { Debug.LogWarning($"Item ({name}) was outside inventory ({pos}), finding new position."); var item = __instance.GetItemAt(pos.x, pos.y); OutsideItems.Add(item); } } } foreach (var item in OutsideItems) { var addedItem = __instance.AddItem(item); if (!addedItem) { Debug.LogWarning($"Could not add item ({item.m_shared.m_name}) to regular inventory, adding item to grave"); GraveItems.Add(item); } } if (GraveItems.Count > 0) { if (Player.m_localPlayer.GetInventory() == __instance) { var graveInventory = CreateTempGrave(Player.m_localPlayer); foreach (var item in GraveItems) { bool addedItem = graveInventory.AddItem(item); if (!addedItem) { Debug.LogWarning($"Could not add item ({item.m_shared.m_name}) to temp grave, dropping on ground"); DroppedItems.Add(item); } } } else { DroppedItems.AddRange(GraveItems); } } foreach (var item in DroppedItems) { if (Player.m_localPlayer.GetInventory() == __instance) { Player.m_localPlayer.DropItem(__instance, item, item.m_stack); } else { Debug.LogError($"Could not recover item from non-Player inventory ({__instance.GetName()}), dropping at origin?!?!"); ItemDrop.DropItem(item, item.m_stack, Vector3.zero + Vector3.up * 10, Quaternion.identity); } } __instance.Changed(); return(false); }