Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CustomCurrencyManager.cs
Go to the documentation of this file.
4using Terraria.ID;
5
7
9{
10 private static int _nextCurrencyIndex;
11
13
14 public static void Initialize()
15 {
17 CustomCurrencyID.DefenderMedals = RegisterCurrency(new CustomCurrencySingleCoin(3817, 999L));
18 }
19
20 public static int RegisterCurrency(CustomCurrencySystem collection)
21 {
24 _currencies[nextCurrencyIndex] = collection;
25 return nextCurrencyIndex;
26 }
27
28 public static void DrawSavings(SpriteBatch sb, int currencyIndex, float shopx, float shopy, bool horizontal = false)
29 {
31 Player player = Main.player[Main.myPlayer];
32 bool overFlowing;
33 long num = customCurrencySystem.CountCurrency(out overFlowing, player.bank.item);
34 long num2 = customCurrencySystem.CountCurrency(out overFlowing, player.bank2.item);
35 long num3 = customCurrencySystem.CountCurrency(out overFlowing, player.bank3.item);
36 long num4 = customCurrencySystem.CountCurrency(out overFlowing, player.bank4.item);
37 long num5 = customCurrencySystem.CombineStacks(out overFlowing, num, num2, num3, num4);
38 if (num5 > 0)
39 {
40 Main.GetItemDrawFrame(4076, out var itemTexture, out var itemFrame);
44 if (num4 > 0)
45 {
46 sb.Draw(itemTexture, Utils.CenteredRectangle(new Vector2(shopx + 96f, shopy + 50f), itemFrame.Size() * 0.65f), null, Color.White);
47 }
48 if (num3 > 0)
49 {
50 sb.Draw(itemTexture2, Utils.CenteredRectangle(new Vector2(shopx + 80f, shopy + 50f), itemFrame2.Size() * 0.65f), null, Color.White);
51 }
52 if (num2 > 0)
53 {
54 sb.Draw(itemTexture3, Utils.CenteredRectangle(new Vector2(shopx + 80f, shopy + 50f), itemFrame3.Size() * 0.65f), null, Color.White);
55 }
56 if (num > 0)
57 {
58 sb.Draw(itemTexture4, Utils.CenteredRectangle(new Vector2(shopx + 70f, shopy + 60f), itemFrame4.Size() * 0.65f), null, Color.White);
59 }
61 customCurrencySystem.DrawSavingsMoney(sb, Lang.inter[66].Value, shopx, shopy, num5, horizontal);
62 }
63 }
64
65 public static void GetPriceText(int currencyIndex, string[] lines, ref int currentLine, long price)
66 {
68 }
69
70 public static bool BuyItem(Player player, long price, int currencyIndex)
71 {
73 bool overFlowing;
74 long num = customCurrencySystem.CountCurrency(out overFlowing, player.inventory, 58, 57, 56, 55, 54);
75 long num2 = customCurrencySystem.CountCurrency(out overFlowing, player.bank.item);
76 long num3 = customCurrencySystem.CountCurrency(out overFlowing, player.bank2.item);
77 long num4 = customCurrencySystem.CountCurrency(out overFlowing, player.bank3.item);
78 long num5 = customCurrencySystem.CountCurrency(out overFlowing, player.bank4.item);
79 if (customCurrencySystem.CombineStacks(out overFlowing, num, num2, num3, num4, num5) < price)
80 {
81 return false;
82 }
83 List<Item[]> list = new List<Item[]>();
91 list.Add(player.inventory);
92 list.Add(player.bank.item);
93 list.Add(player.bank2.item);
94 list.Add(player.bank3.item);
95 list.Add(player.bank4.item);
96 for (int i = 0; i < list.Count; i++)
97 {
98 dictionary[i] = new List<int>();
99 }
100 dictionary[0] = new List<int> { 58, 57, 56, 55, 54 };
101 for (int j = 0; j < list.Count; j++)
102 {
103 for (int k = 0; k < list[j].Length; k++)
104 {
105 if (!dictionary[j].Contains(k) && customCurrencySystem.Accepts(list[j][k]))
106 {
107 list3.Add(new Point(j, k));
108 }
109 }
110 }
111 FindEmptySlots(list, dictionary, list2, 0);
112 FindEmptySlots(list, dictionary, list4, 1);
113 FindEmptySlots(list, dictionary, list5, 2);
114 FindEmptySlots(list, dictionary, list6, 3);
115 FindEmptySlots(list, dictionary, list7, 4);
116 if (!customCurrencySystem.TryPurchasing(price, list, list3, list2, list4, list5, list6, list7))
117 {
118 return false;
119 }
120 return true;
121 }
122
124 {
125 for (int num = inventories[currentInventoryIndex].Length - 1; num >= 0; num--)
126 {
128 {
130 }
131 }
132 }
133
134 public static bool IsCustomCurrency(Item item)
135 {
137 {
138 if (currency.Value.Accepts(item))
139 {
140 return true;
141 }
142 }
143 return false;
144 }
145
146 public static void GetPrices(Item item, out long calcForSelling, out long calcForBuying)
147 {
148 _currencies[item.shopSpecialCurrency].GetItemExpectedPrice(item, out calcForSelling, out calcForBuying);
149 }
150}
void Draw(Texture2D texture, Vector2 position, Color color)
void Add(TKey key, TValue value)
Item[] item
Definition Chest.cs:41
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
static void DrawSavings(SpriteBatch sb, int currencyIndex, float shopx, float shopy, bool horizontal=false)
static void GetPrices(Item item, out long calcForSelling, out long calcForBuying)
static void FindEmptySlots(List< Item[]> inventories, Dictionary< int, List< int > > slotsToIgnore, List< Point > emptySlots, int currentInventoryIndex)
static bool BuyItem(Player player, long price, int currencyIndex)
static void GetPriceText(int currencyIndex, string[] lines, ref int currentLine, long price)
static Dictionary< int, CustomCurrencySystem > _currencies
static int RegisterCurrency(CustomCurrencySystem collection)
static LocalizedText[] inter
Definition Lang.cs:28
static int myPlayer
Definition Main.cs:1801
static byte mouseTextColor
Definition Main.cs:1751
static void GetItemDrawFrame(int item, out Texture2D itemTexture, out Microsoft.Xna.Framework.Rectangle itemFrame)
Definition Main.cs:25221
static Player[] player
Definition Main.cs:1803
Item[] inventory
Definition Player.cs:1257
static void DrawBorderStringFourWay(SpriteBatch sb, DynamicSpriteFont font, string text, float x, float y, Color textColor, Color borderColor, Vector2 origin, float scale=1f)
Definition Utils.cs:1857
static Rectangle CenteredRectangle(Vector2 center, Vector2 size)
Definition Utils.cs:604