public static int DepositItem(Player player, MSAccessPort port, ItemBase item, int amount) { if (!WorldScript.mbIsServer) { NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceDepositItem, amount.ToString(), item, port, 0.0f); } //Handle special case items by getting the exact item from inventory based on the example ID if (item.mType != ItemType.ItemStack && item.mType != ItemType.ItemCubeStack) { for (int index = 0; index < amount; index++) { if (item != null) { // This is required due to the dubious item type associated with MasterList item = player.mInventory.TryAndGetItem(item.mnItemID); if (!player.mInventory.RemoveSpecificItem(item)) { if (player.mbIsLocalPlayer) { FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Item not found!", Color.red, 1.5f); } if (index != 0) { player.mInventory.MarkEverythingDirty(); port.MarkDirtyDelayed(); port.mbJustTransmitted = true; } return(amount - index); } if (port.DepositItem(item) != 0) { if (player.mbIsLocalPlayer) { FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Mass Storage full!", Color.red, 1.5f); } //Return item to player if it failed to deposit player.mInventory.AddItem(item); if (index != 0) { player.mInventory.MarkEverythingDirty(); port.MarkDirtyDelayed(); port.mbJustTransmitted = true; } return(amount - index); } else { port.mrCurrentPower -= port.mrTransportCost; } } } } else { if (!player.mInventory.RemoveItemByExample(item)) { if (player.mbIsLocalPlayer) { FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Item not found!", Color.red, 1.5f); } return(item.GetAmount()); } int remainder = port.DepositItem(item); if (remainder != 0) { if (player.mbIsLocalPlayer) { FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Mass Storage full!", Color.red, 1.5f); } //Return item to player if it failed to deposit player.mInventory.AddItem(ItemManager.CloneItem(item).SetAmount(remainder)); port.mrCurrentPower -= port.mrTransportCost * (item.GetAmount() - remainder); player.mInventory.MarkEverythingDirty(); port.MarkDirtyDelayed(); port.mbJustTransmitted = true; return(remainder); } else { port.mrCurrentPower -= port.mrTransportCost * item.GetAmount(); } } player.mInventory.MarkEverythingDirty(); port.MarkDirtyDelayed(); port.mbJustTransmitted = true; return(0); }
public static int WithdrawItem(Player player, MSAccessPort port, ItemBase item, int amount) { if (item == null) { Debug.LogWarning("MSAccessPort is trying to withdraw null item!"); return(amount); } if (!WorldScript.mbIsServer) { NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceWithdrawItem, amount.ToString(), item, port, 0.0f); } ItemBase itemout; //Handle special items by copying the full data on retrieval and inserting into the player inventory if (item.mType != ItemType.ItemStack && item.mType != ItemType.ItemCubeStack) { for (int index = 0; index < amount; index++) { if (!player.mInventory.CanFit(item)) { if (player.mbIsLocalPlayer) { FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Inventory full!", Color.red, 1.5f); } if (index != 0) { player.mInventory.MarkEverythingDirty(); port.MarkDirtyDelayed(); port.mbJustTransmitted = true; } return(amount - index); } if (port.WithdrawItem(item, out itemout) == 0) { if (itemout == null) { Debug.LogWarning("MSAccessPort attempted to withdraw item: " + item.ToString() + " but found null on withdraw"); return(amount - index); } port.mrCurrentPower -= port.mrTransportCost; if (itemout != null && !player.mInventory.AddItem(itemout)) { ItemManager.instance.DropItem(itemout, player.mnWorldX, player.mnWorldY, player.mnWorldZ, Vector3.zero); } else if (itemout == null) { Debug.LogWarning("MSAccessPort tried to withdraw single item but returned null itemout?"); } } else { if (index != 0) { player.mInventory.MarkEverythingDirty(); port.MarkDirtyDelayed(); port.mbJustTransmitted = true; } return(amount - index); } } } else { //Stacked items have all necessary info stored in the passed itembase and don't need the original from mass storage if (!player.mInventory.CanFit(item)) { if (player.mbIsLocalPlayer) { FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Inventory full!", Color.red, 1.5f); } return(item.GetAmount()); } int remainder = port.WithdrawItem(item, out itemout); if (remainder != 0) { port.mrCurrentPower -= port.mrTransportCost * (item.GetAmount() - remainder); if (itemout != null && !player.mInventory.AddItem(itemout)) { ItemManager.instance.DropItem(item, player.mnWorldX, player.mnWorldY, player.mnWorldZ, Vector3.zero); } else if (itemout == null) { Debug.LogWarning("MSAccessPort tried to withdraw item stack but returned null itemout?"); } player.mInventory.MarkEverythingDirty(); port.MarkDirtyDelayed(); port.mbJustTransmitted = true; } else { if (itemout != null && !player.mInventory.AddItem(itemout)) { ItemManager.instance.DropItem(item, player.mnWorldX, player.mnWorldY, player.mnWorldZ, Vector3.zero); } else if (itemout == null) { Debug.LogWarning("MSAccessPort tried to withdraw item stack but returned null itemout?"); } port.mrCurrentPower -= port.mrTransportCost * item.GetAmount(); } } player.mInventory.MarkEverythingDirty(); port.MarkDirtyDelayed(); port.mbJustTransmitted = true; return(0); }