-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathBundleGenerator.cs
246 lines (240 loc) · 8.3 KB
/
BundleGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// Decompiled with JetBrains decompiler
// Type: StardewValley.BundleGenerator
// Assembly: Stardew Valley, Version=1.5.6.22018, Culture=neutral, PublicKeyToken=null
// MVID: BEBB6D18-4941-4529-AC12-B54F0C61CC20
// Assembly location: C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley\Stardew Valley.dll
using Microsoft.Xna.Framework;
using StardewValley.GameData;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace StardewValley
{
public class BundleGenerator
{
public List<RandomBundleData> randomBundleData;
public Dictionary<string, string> bundleData;
public Dictionary<string, int> itemNameLookup;
public Random random;
public Dictionary<string, string> Generate(string bundle_data_path, Random rng)
{
this.random = rng;
this.randomBundleData = Game1.content.Load<List<RandomBundleData>>(bundle_data_path);
this.bundleData = new Dictionary<string, string>();
Dictionary<string, string> dictionary1 = Game1.content.LoadBase<Dictionary<string, string>>("Data\\Bundles");
foreach (string key in dictionary1.Keys)
this.bundleData[key] = dictionary1[key];
foreach (RandomBundleData randomBundleData in this.randomBundleData)
{
List<int> intList = new List<int>();
string[] strArray1 = randomBundleData.Keys.Trim().Split(' ');
Dictionary<int, BundleData> dictionary2 = new Dictionary<int, BundleData>();
foreach (string s in strArray1)
intList.Add(int.Parse(s));
BundleSetData random1 = Utility.GetRandom<BundleSetData>(randomBundleData.BundleSets, this.random);
if (random1 != null)
{
foreach (BundleData bundle in random1.Bundles)
dictionary2[bundle.Index] = bundle;
}
List<BundleData> bundleDataList = new List<BundleData>();
foreach (BundleData bundle in randomBundleData.Bundles)
bundleDataList.Add(bundle);
for (int key = 0; key < intList.Count; ++key)
{
if (!dictionary2.ContainsKey(key))
{
List<BundleData> list = new List<BundleData>();
foreach (BundleData bundleData in bundleDataList)
{
if (bundleData.Index == key)
list.Add(bundleData);
}
if (list.Count > 0)
{
BundleData random2 = Utility.GetRandom<BundleData>(list, this.random);
bundleDataList.Remove(random2);
dictionary2[key] = random2;
}
else
{
foreach (BundleData bundleData in bundleDataList)
{
if (bundleData.Index == -1)
list.Add(bundleData);
}
if (list.Count > 0)
{
BundleData random3 = Utility.GetRandom<BundleData>(list, this.random);
bundleDataList.Remove(random3);
dictionary2[key] = random3;
}
}
}
}
foreach (int key in dictionary2.Keys)
{
BundleData bundleData = dictionary2[key];
StringBuilder builder = new StringBuilder();
builder.Append(bundleData.Name);
builder.Append("/");
string str = bundleData.Reward;
if (str.Length > 0)
{
try
{
if (char.IsDigit(str[0]))
{
string[] strArray2 = str.Split(' ');
int stack_count = int.Parse(strArray2[0]);
Item obj = Utility.fuzzyItemSearch(string.Join(" ", strArray2, 1, strArray2.Length - 1), stack_count);
if (obj != null)
str = Utility.getStandardDescriptionFromItem(obj, obj.Stack);
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR: Malformed reward string in bundle: " + str);
str = bundleData.Reward;
}
}
builder.Append(str);
builder.Append("/");
int color = 0;
if (bundleData.Color == "Red")
color = 4;
else if (bundleData.Color == "Blue")
color = 5;
else if (bundleData.Color == "Green")
color = 0;
else if (bundleData.Color == "Orange")
color = 2;
else if (bundleData.Color == "Purple")
color = 1;
else if (bundleData.Color == "Teal")
color = 6;
else if (bundleData.Color == "Yellow")
color = 3;
this.ParseItemList(builder, bundleData.Items, bundleData.Pick, bundleData.RequiredItems, color);
builder.Append("/");
builder.Append(bundleData.Sprite);
this.bundleData[randomBundleData.AreaName + "/" + intList[key].ToString()] = builder.ToString();
}
}
return this.bundleData;
}
public string ParseRandomTags(string data)
{
int startIndex;
do
{
startIndex = data.LastIndexOf('[');
if (startIndex >= 0)
{
int num = data.IndexOf(']', startIndex);
if (num == -1)
return data;
string random = Utility.GetRandom<string>(new List<string>((IEnumerable<string>) data.Substring(startIndex + 1, num - startIndex - 1).Split('|')), this.random);
data = data.Remove(startIndex, num - startIndex + 1);
data = data.Insert(startIndex, random);
}
}
while (startIndex >= 0);
return data;
}
public Item ParseItemString(string item_string)
{
string[] strArray = item_string.Trim().Split(' ');
int index = 0;
int initialStack = int.Parse(strArray[index]);
int startIndex = index + 1;
int num = 0;
if (strArray[startIndex] == "NQ")
{
num = 0;
++startIndex;
}
else if (strArray[startIndex] == "SQ")
{
num = 1;
++startIndex;
}
else if (strArray[startIndex] == "GQ")
{
num = 2;
++startIndex;
}
else if (strArray[startIndex] == "IQ")
{
num = 3;
++startIndex;
}
string str = string.Join(" ", strArray, startIndex, strArray.Length - startIndex);
if (char.IsDigit(str[0]))
{
Object itemString = new Object(int.Parse(str), initialStack);
(itemString as Object).Quality = num;
return (Item) itemString;
}
Item itemString1 = (Item) null;
if (str.ToLowerInvariant().EndsWith("category"))
{
try
{
FieldInfo field = typeof (Object).GetField(str);
if (field != (FieldInfo) null)
itemString1 = (Item) new Object(Vector2.Zero, (int) field.GetValue((object) null), 1);
}
catch (Exception ex)
{
}
}
if (itemString1 == null)
{
itemString1 = Utility.fuzzyItemSearch(str);
if (itemString1 is Object)
(itemString1 as Object).Quality = num;
}
if (itemString1 == null)
throw new Exception("Invalid item name '" + str + "' encountered while generating a bundle.");
itemString1.Stack = initialStack;
return itemString1;
}
public void ParseItemList(
StringBuilder builder,
string item_list,
int pick_count,
int required_items,
int color)
{
item_list = this.ParseRandomTags(item_list);
string[] strArray = item_list.Split(',');
List<string> stringList = new List<string>();
for (int index = 0; index < strArray.Length; ++index)
{
Item itemString = this.ParseItemString(strArray[index]);
stringList.Add(itemString.ParentSheetIndex.ToString() + " " + itemString.Stack.ToString() + " " + (itemString as Object).Quality.ToString());
}
if (pick_count < 0)
pick_count = stringList.Count;
if (required_items < 0)
required_items = pick_count;
while (stringList.Count > pick_count)
{
int index = this.random.Next(stringList.Count);
stringList.RemoveAt(index);
}
for (int index = 0; index < stringList.Count; ++index)
{
builder.Append(stringList[index]);
if (index < stringList.Count - 1)
builder.Append(" ");
}
builder.Append("/");
builder.Append(color);
builder.Append("/");
builder.Append(required_items);
}
}
}