Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryPurchasing()

static bool Terraria.Player.TryPurchasing ( long price,
List< Item[]> inv,
List< Point > slotCoins,
List< Point > slotsEmpty,
List< Point > slotEmptyBank,
List< Point > slotEmptyBank2,
List< Point > slotEmptyBank3,
List< Point > slotEmptyBank4 )
inlinestaticprivate

Definition at line 33675 of file Player.cs.

33676 {
33677 long num = price;
33679 bool result = false;
33680 while (num > 0)
33681 {
33682 long num2 = 1000000L;
33683 for (int i = 0; i < 4; i++)
33684 {
33685 if (num >= num2)
33686 {
33687 foreach (Point slotCoin in slotCoins)
33688 {
33689 if (inv[slotCoin.X][slotCoin.Y].type == 74 - i)
33690 {
33691 long num3 = num / num2;
33692 dictionary[slotCoin] = inv[slotCoin.X][slotCoin.Y].Clone();
33693 if (num3 < inv[slotCoin.X][slotCoin.Y].stack)
33694 {
33695 inv[slotCoin.X][slotCoin.Y].stack -= (int)num3;
33696 }
33697 else
33698 {
33699 inv[slotCoin.X][slotCoin.Y].SetDefaults();
33701 }
33702 num -= num2 * (dictionary[slotCoin].stack - inv[slotCoin.X][slotCoin.Y].stack);
33703 }
33704 }
33705 }
33706 num2 /= 100;
33707 }
33708 if (num <= 0)
33709 {
33710 continue;
33711 }
33712 if (slotsEmpty.Count > 0)
33713 {
33714 slotsEmpty.Sort(DelegateMethods.CompareYReverse);
33715 Point item = new Point(-1, -1);
33716 for (int j = 0; j < inv.Count; j++)
33717 {
33718 num2 = 10000L;
33719 for (int k = 0; k < 3; k++)
33720 {
33721 if (num >= num2)
33722 {
33723 foreach (Point slotCoin2 in slotCoins)
33724 {
33725 if (slotCoin2.X == j && inv[slotCoin2.X][slotCoin2.Y].type == 74 - k && inv[slotCoin2.X][slotCoin2.Y].stack >= 1)
33726 {
33728 if (j == 1 && slotEmptyBank.Count > 0)
33729 {
33731 }
33732 if (j == 2 && slotEmptyBank2.Count > 0)
33733 {
33735 }
33736 if (j == 3 && slotEmptyBank3.Count > 0)
33737 {
33739 }
33740 if (j == 4 && slotEmptyBank4.Count > 0)
33741 {
33743 }
33744 if (--inv[slotCoin2.X][slotCoin2.Y].stack <= 0)
33745 {
33746 inv[slotCoin2.X][slotCoin2.Y].SetDefaults();
33748 }
33749 dictionary[list[0]] = inv[list[0].X][list[0].Y].Clone();
33750 inv[list[0].X][list[0].Y].SetDefaults(73 - k);
33751 inv[list[0].X][list[0].Y].stack = 100;
33752 item = list[0];
33753 list.RemoveAt(0);
33754 break;
33755 }
33756 }
33757 }
33758 if (item.X != -1 || item.Y != -1)
33759 {
33760 break;
33761 }
33762 num2 /= 100;
33763 }
33764 for (int l = 0; l < 2; l++)
33765 {
33766 if (item.X != -1 || item.Y != -1)
33767 {
33768 continue;
33769 }
33770 foreach (Point slotCoin3 in slotCoins)
33771 {
33772 if (slotCoin3.X == j && inv[slotCoin3.X][slotCoin3.Y].type == 73 + l && inv[slotCoin3.X][slotCoin3.Y].stack >= 1)
33773 {
33775 if (j == 1 && slotEmptyBank.Count > 0)
33776 {
33778 }
33779 if (j == 2 && slotEmptyBank2.Count > 0)
33780 {
33782 }
33783 if (j == 3 && slotEmptyBank3.Count > 0)
33784 {
33786 }
33787 if (j == 4 && slotEmptyBank4.Count > 0)
33788 {
33790 }
33791 if (--inv[slotCoin3.X][slotCoin3.Y].stack <= 0)
33792 {
33793 inv[slotCoin3.X][slotCoin3.Y].SetDefaults();
33795 }
33796 dictionary[list2[0]] = inv[list2[0].X][list2[0].Y].Clone();
33797 inv[list2[0].X][list2[0].Y].SetDefaults(72 + l);
33798 inv[list2[0].X][list2[0].Y].stack = 100;
33799 item = list2[0];
33800 list2.RemoveAt(0);
33801 break;
33802 }
33803 }
33804 }
33805 if (item.X != -1 && item.Y != -1)
33806 {
33808 break;
33809 }
33810 }
33811 slotsEmpty.Sort(DelegateMethods.CompareYReverse);
33812 slotEmptyBank.Sort(DelegateMethods.CompareYReverse);
33813 slotEmptyBank2.Sort(DelegateMethods.CompareYReverse);
33814 slotEmptyBank3.Sort(DelegateMethods.CompareYReverse);
33815 slotEmptyBank4.Sort(DelegateMethods.CompareYReverse);
33816 continue;
33817 }
33819 {
33820 inv[item2.Key.X][item2.Key.Y] = item2.Value.Clone();
33821 }
33822 result = true;
33823 break;
33824 }
33825 return result;
33826 }
void Add(TKey key, TValue value)

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), Terraria.DelegateMethods.CompareYReverse(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.dictionary, System.item, System.L, and System.list.