Example #1
0
 public static void chestStack(Item[] chest, bool isChest)
 {
     for (int i = 0; i < 20; i++)
     {
         if (chest[i].type <= 0 || chest[i].stack >= chest[i].maxStack)
         {
             continue;
         }
         for (int j = 0; j < 48; j++)
         {
             if (chest[i].IsTheSameAs(Main.player[Main.myPlayer].inventory[j]))
             {
                 int num = Main.player[Main.myPlayer].inventory[j].stack;
                 if (chest[i].stack + num > chest[i].maxStack)
                 {
                     num = chest[i].maxStack - chest[i].stack;
                 }
                 Main.PlaySound(7);
                 chest[i].stack += num;
                 Main.player[Main.myPlayer].inventory[j].stack -= num;
                 if (isChest)
                 {
                     Main.ChestCoins();
                 }
                 else
                 {
                     Main.BankCoins();
                 }
                 if (Main.player[Main.myPlayer].inventory[j].stack == 0)
                 {
                     Main.player[Main.myPlayer].inventory[j].SetDefaults(0);
                 }
                 else if (chest[i].type == 0)
                 {
                     chest[i] = (Item)Main.player[Main.myPlayer].inventory[j].Clone();
                     Main.player[Main.myPlayer].inventory[j].SetDefaults(0);
                 }
                 if (isChest && Main.netMode == 1)
                 {
                     NetMessage.SendData(32, -1, -1, "", Main.player[Main.myPlayer].chest, i);
                 }
             }
         }
     }
 }
Example #2
0
 public static void chestDeposit(Item[] chest, bool isChest)
 {
     for (int num = 40; num >= 10; num--)
     {
         if (Main.player[Main.myPlayer].inventory[num].stack > 0 && Main.player[Main.myPlayer].inventory[num].type > 0)
         {
             if (Main.player[Main.myPlayer].inventory[num].maxStack > 1)
             {
                 for (int i = 0; i < 20; i++)
                 {
                     if (chest[i].stack >= chest[i].maxStack || !Main.player[Main.myPlayer].inventory[num].IsTheSameAs(chest[i]))
                     {
                         continue;
                     }
                     int num2 = Main.player[Main.myPlayer].inventory[num].stack;
                     if (Main.player[Main.myPlayer].inventory[num].stack + chest[i].stack > chest[i].maxStack)
                     {
                         num2 = chest[i].maxStack - chest[i].stack;
                     }
                     Main.player[Main.myPlayer].inventory[num].stack -= num2;
                     chest[i].stack += num2;
                     if (isChest)
                     {
                         Main.ChestCoins();
                     }
                     else
                     {
                         Main.BankCoins();
                     }
                     Main.PlaySound(7);
                     if (Main.player[Main.myPlayer].inventory[num].stack <= 0)
                     {
                         Main.player[Main.myPlayer].inventory[num].SetDefaults(0);
                         if (isChest && Main.netMode == 1)
                         {
                             NetMessage.SendData(32, -1, -1, "", Main.player[Main.myPlayer].chest, i);
                         }
                         break;
                     }
                     if (chest[i].type == 0)
                     {
                         chest[i] = (Item)Main.player[Main.myPlayer].inventory[num].Clone();
                         Main.player[Main.myPlayer].inventory[num].SetDefaults(0);
                     }
                     if (isChest && Main.netMode == 1)
                     {
                         NetMessage.SendData(32, -1, -1, "", Main.player[Main.myPlayer].chest, i);
                     }
                 }
             }
             if (Main.player[Main.myPlayer].inventory[num].stack > 0)
             {
                 for (int j = 0; j < 20; j++)
                 {
                     if (chest[j].stack == 0)
                     {
                         Main.PlaySound(7);
                         chest[j] = (Item)Main.player[Main.myPlayer].inventory[num].Clone();
                         Main.player[Main.myPlayer].inventory[num].SetDefaults(0);
                         if (isChest && Main.netMode == 1)
                         {
                             NetMessage.SendData(32, -1, -1, "", Main.player[Main.myPlayer].chest, j);
                         }
                         break;
                     }
                 }
             }
         }
     }
 }