public override long addItem(Item itm) { if (order == null) { setupItemList(); } try { string itmTag = ItemToTag(itm); if (itmTag == "" + ItemID.PlatinumCoin || itmTag == "" + ItemID.GoldCoin || itmTag == "" + ItemID.SilverCoin || itmTag == "" + ItemID.CopperCoin) { long ans = addItemToDown(itm); if (ans > 0) { rebalanceCoins(); } return(ans); } else { return(base.addItem(itm)); } } catch (Exception ex) { BagsOfHoldingMod.debugChat("Error: " + ex); return(0); } }
protected override void DrawSelf(SpriteBatch spriteBatch) { if (!Main.playerInventory || player.chest != -1 || !isSameBag()) { close(true); return; } try{ DrawButtons(spriteBatch); DrawSlots(spriteBatch); }catch (Exception ex) { BagsOfHoldingMod.debugChat("Error: " + ex); } }
public virtual long addItem(Item itm) { if (order == null || order.Count == 0) { setupItemList(); } try{ if (itm.stack <= 0) { return(0); } string type = ItemToTag(itm); bool isToInsert = order.Contains(type); if (isToInsert) { long total = itm.stack; if (items.ContainsKey(type)) { total += ((long)items[type]); } if (total < 0) { long remain = Int64.MaxValue - items.GetAsLong(type); items.Remove(type); items[type] = Int64.MaxValue; itm.stack = (int)(itm.stack - remain); recalculateValue(); return(remain); } long stored = itm.stack; items.Remove(type); items[type] = (long)total; itm.stack = 0; itm.type = 0; recalculateValue(); return(stored); } else { //BagsOfHoldingMod.debugChat("Item not found: " + type); return(0); } }catch (Exception ex) { BagsOfHoldingMod.debugChat("Error: " + ex); return(0); } }
public virtual void emptyBagOnMagicStorage(Player p, int x, int y) { Mod magicStorage = ModLoader.GetMod("MagicStorage"); if (magicStorage != null) { try { if (Main.tile[x, y].frameX % 36 == 18) { x--; } if (Main.tile[x, y].frameY % 36 == 18) { y--; } ModTile t = TileLoader.GetTile(Main.tile[x, y].type); MethodInfo getHeart = (t.GetType()).GetMethod("GetHeart", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(int), typeof(int) }, null); if (getHeart == null) { BagsOfHoldingMod.debugChat("GetHeart() is null. Report to author."); ErrorLogger.Log("GetHeart() is null on " + (Main.netMode == NetmodeID.MultiplayerClient ? "client" : "server")); return; } object[] param = new object[2]; param[0] = x; param[1] = y; TileEntity heart = (TileEntity)getHeart.Invoke(t, param); if (heart == null) { BagsOfHoldingMod.sendChat("This Access does not have an associated Storage Heart."); return; } Type[] depCal = new Type[1]; depCal[0] = typeof(Item); MethodInfo deposit = heart.GetType().GetMethod("DepositItem", BindingFlags.Public | BindingFlags.Instance, null, depCal, null); if (deposit == null) { BagsOfHoldingMod.debugChat("DepositItem(Item) is null. Report to author."); ErrorLogger.Log("DepositItem(Item) is null on " + (Main.netMode == NetmodeID.MultiplayerClient ? "client" : "server")); return; } for (int i = 0; i < order.Count; i++) { if (items.ContainsKey(order[i])) { long remain = items.GetAsLong(order[i]); bool prematureBreak = false; while (remain > 0 && !prematureBreak) { Item itm = getItemFromTag(order[i]); int stackSize = (int)Math.Min(remain, itm.maxStack); itm.stack = stackSize; deposit.Invoke(heart, new object[] { itm }); if (itm.IsAir) { remain -= stackSize; } else { remain -= (stackSize - itm.stack); prematureBreak = true; } } items.Remove(order[i]); if (remain > 0) { items[order[i]] = remain; } } } }catch (Exception e) { BagsOfHoldingMod.debugChat(e.ToString()); } if (Main.netMode == NetmodeID.MultiplayerClient) { ModPacket pack = mod.GetPacket(); pack.Write((byte)2); pack.Write((byte)p.whoAmI); pack.Write((byte)p.selectedItem); TagIO.Write(items, pack); pack.Send(); } } }
public override bool OnPickup(Item item, Player player) { try{ int quantityRemoved = 0; if (BagsOfHoldingMod.tryPlace) { quantityRemoved = tryPlaceInInventory(item, player); if (item.stack <= 0) { item.stack = quantityRemoved; return(true); } } if (BagsOfHoldingMod.checkAccessories) { for (int i = 3; i < 8 + player.extraAccessorySlots; i++) { if (player.armor[i] != null && player.armor[i].type != 0 && player.armor[i].modItem != null && player.armor[i].modItem is GenericHoldingBag) { addItemIfPossible(item, player.armor[i].modItem as GenericHoldingBag); if (item.stack <= 0) { if (quantityRemoved > 0) { item.stack = quantityRemoved; return(true); } if (BagsOfHoldingMod.playSoundOnPickup) { playSound(item, player); } return(false); } } } } if (BagsOfHoldingMod.checkVanity) { for (int i = 13; i < 18 + player.extraAccessorySlots; i++) { if (player.armor[i] != null && player.armor[i].type != 0 && player.armor[i].modItem != null && player.armor[i].modItem is GenericHoldingBag) { addItemIfPossible(item, player.armor[i].modItem as GenericHoldingBag); if (item.stack <= 0) { if (quantityRemoved > 0) { item.stack = quantityRemoved; return(true); } if (BagsOfHoldingMod.playSoundOnPickup) { playSound(item, player); } return(false); } } } } if (BagsOfHoldingMod.checkInventory) { for (int i = 49; i >= 10; i--) { if (player.inventory[i] != null && player.inventory[i].type != 0 && player.inventory[i].modItem != null && player.inventory[i].modItem is GenericHoldingBag) { addItemIfPossible(item, player.inventory[i].modItem as GenericHoldingBag); if (item.stack <= 0) { if (quantityRemoved > 0) { item.stack = quantityRemoved; return(true); } if (BagsOfHoldingMod.playSoundOnPickup) { playSound(item, player); } return(false); } } } } if (BagsOfHoldingMod.checkHotbar) { for (int i = 0; i < 10; i++) { if (player.inventory[i] != null && player.inventory[i].type != 0 && player.inventory[i].modItem != null && player.inventory[i].modItem is GenericHoldingBag) { addItemIfPossible(item, player.inventory[i].modItem as GenericHoldingBag); if (item.stack <= 0) { if (quantityRemoved > 0) { item.stack = quantityRemoved; return(true); } if (BagsOfHoldingMod.playSoundOnPickup) { playSound(item, player); } return(false); } } } } item.stack += quantityRemoved; return(true); } catch (Exception ex) { BagsOfHoldingMod.debugChat("Error: " + ex); return(true); } }