-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathModExpedition.cs
More file actions
432 lines (394 loc) · 18.3 KB
/
ModExpedition.cs
File metadata and controls
432 lines (394 loc) · 18.3 KB
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
using System;
using System.Collections.Generic;
using System.Reflection;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Expeditions
{
public class ModExpedition
{
public Expedition expedition
{
get;
internal set;
}
public Mod mod
{
get;
internal set;
}
public ModExpedition()
{
this.expedition = new Expedition();
this.expedition.mex = this;
}
/// <summary>
/// Should this expedition be included when AutoloadExpeditions is called?
/// </summary>
/// <returns>True by default</returns>
public virtual bool AutoLoad()
{
return true; //Assuming true since you have to call the method to autoload in the first place...
}
/// <summary>
/// Add an item with a specified required stack to the expedition deliver conditions.
/// </summary>
/// <param name="itemID">Item type</param>
/// <param name="itemStack">The total amount in the stack, up to the maxStack</param>
public void AddDeliverable(int itemID, int itemStack = 1)
{
expedition.AddDeliverable(itemID, itemStack);
}
internal List<int[]> deliveryItemGroups = new List<int[]>();
/// <summary>
/// Adds a group of items with a specified required stack to the expedition deliver conditions. This can be used for optional deliveries, such as Cobalt OR Palladium sword.
/// </summary>
/// <param name="itemIDs"></param>
/// <param name="itemStack"></param>
public void AddDeliverableAnyOf(int[] itemIDs, int itemStack = 1)
{
if (itemIDs.Length <= 0) return;
deliveryItemGroups.Add(itemIDs);
expedition.AddDeliverable(itemIDs[0], itemStack);
}
internal bool ConvertCustomItems(ref int itemID)
{
foreach(int[] itemGroup in deliveryItemGroups)
{
foreach(int itemType in itemGroup)
{
if(itemID == itemType)
{
itemID = itemGroup[0];
return true;
}
}
}
return false;
}
internal string GetCustomItemGroupName(int firstItemIDInGroup)
{
foreach (int[] itemGroup in deliveryItemGroups)
{
if (firstItemIDInGroup == itemGroup[0]) // ItemID matches this group
{
string itemNames = "";
Item i = new Item();
int index = 0;
foreach (int itemType in itemGroup)
{
i.SetDefaults(itemType);
itemNames += i.Name;
if(itemGroup.Length > 1)
{
if(index < itemGroup.Length - 2)
{
itemNames += ", ";
}
else if (index < itemGroup.Length - 1)
{
itemNames += " or ";
}
}
index++;
}
return itemNames;
}
}
return "Unknown Item Group";
}
/// <summary>
/// Add an item with a specified stack to the expedition rewards.
/// </summary>
/// <param name="itemID">Item type</param>
/// <param name="itemStack">The total amount in the stack, up to the maxStack</param>
/// <param name="onlyOnce">Only will reward once, hidden after completion</param>
/// <param name="addTag">Should the item have [addTag] appended to it (eg. as a bonus item)</param>
public void AddRewardItem(int itemID, int itemStack = 1, bool onlyOnce = false, string addTag = "")
{
Item i = new Item();
i.SetDefaults(itemID);
if (i.maxStack < itemStack) itemStack = i.maxStack;
i.stack = itemStack;
if (addTag != "")
{
i.SetNameOverride(string.Concat("[", addTag, "] ", i.Name));
}
if (onlyOnce)
{ expedition.AddRewardOnce(i); }
else
{ expedition.AddReward(i); }
}
/// <summary>
/// Add an item with a prefix to the expedition rewards.
/// </summary>
/// <param name="itemID">Item type</param>
/// <param name="prefix">See AffixName_Old for a list of prefixes</param>
/// <param name="onlyOnce">Only will reward once, hidden after completion</param>
/// <param name="addTag">Should the item have [addTag] appended to it (eg. as a bonus item)</param>
public void AddRewardPrefix(int itemID, byte prefix = 0, bool onlyOnce = false, string addTag = "")
{
Item i = new Item();
i.SetDefaults(itemID);
i.prefix = prefix;
i.Prefix(i.prefix);
if (addTag != "")
{
i.SetNameOverride(string.Concat("[", addTag, "] ", i.Name));
}
if (onlyOnce)
{ expedition.AddRewardOnce(i); }
else
{ expedition.AddReward(i); }
}
/// <summary>
/// Add money reward. For simplicities sake use Item.buyPrice(int platinum, int gold, int silver, int copper) to get your value.
/// </summary>
/// <param name="value"></param>
/// <param name="onlyOnce">Only will reward once, hidden after completion</param>
/// <param name="addTag">Should the item have [addTag] appended to it (eg. as a bonus item)</param>
public void AddRewardMoney(int value, bool onlyOnce = false, string addTag = "")
{
int[] stacks = Expeditions.DivideValueIntoMoneyStack(value);
if (stacks[0] > 0) AddRewardItem(74, stacks[0], onlyOnce, addTag);
if (stacks[1] > 0) AddRewardItem(73, stacks[1], onlyOnce, addTag);
if (stacks[2] > 0) AddRewardItem(72, stacks[2], onlyOnce, addTag);
if (stacks[3] > 0) AddRewardItem(71, stacks[3], onlyOnce, addTag);
}
/// <summary>
/// Attempts to set the head sprite associated with this npc.
/// </summary>
/// <param name="npcType">Type of NPC. Clerk's type is accessed via API.NPCIDClerk </param>
/// <param name="npcIsRequired">Can this quest be continued/completed without the presence of this NPC? </param>
public void SetNPCHead(int npcType, bool npcIsRequired = true)
{
//First run through known vanilla NPC head slots
switch (npcType)
{
case NPCID.Guide: expedition.npcHead = 1; return;
case NPCID.Merchant: expedition.npcHead = 2; return;
case NPCID.Nurse: expedition.npcHead = 3; return;
case NPCID.Demolitionist: expedition.npcHead = 4; return;
case NPCID.Dryad: expedition.npcHead = 5; return;
case NPCID.ArmsDealer: expedition.npcHead = 6; return;
case NPCID.Clothier: expedition.npcHead = 7; return;
case NPCID.Mechanic: expedition.npcHead = 8; return;
case NPCID.GoblinTinkerer: expedition.npcHead = 9; return;
case NPCID.Wizard: expedition.npcHead = 10; return;
case NPCID.SantaClaus: expedition.npcHead = 11; return;
case NPCID.Truffle: expedition.npcHead = 12; return;
case NPCID.Steampunker: expedition.npcHead = 13; return;
case NPCID.DyeTrader: expedition.npcHead = 14; return;
case NPCID.PartyGirl: expedition.npcHead = 15; return;
case NPCID.Cyborg: expedition.npcHead = 16; return;
case NPCID.Painter: expedition.npcHead = 17; return;
case NPCID.WitchDoctor: expedition.npcHead = 18; return;
case NPCID.Pirate: expedition.npcHead = 19; return;
case NPCID.Stylist: expedition.npcHead = 20; return;
case NPCID.TravellingMerchant: expedition.npcHead = 21; return;
case NPCID.Angler: expedition.npcHead = 22; return;
case NPCID.TaxCollector: expedition.npcHead = 23; return;
case NPCID.DD2Bartender: expedition.npcHead = 24; return;
default:
try
{
//Then if all else fails, see if a modded one exists
MethodInfo method = typeof(NPCHeadLoader).GetMethod("GetNPCHeadSlot", BindingFlags.NonPublic | BindingFlags.Static);
object result = method.Invoke(null, new object[] { npcType });
expedition.npcHead = (int)result;
//PlayerExplorer.dbgmsg += "\ninvoke result: " + result;
}
catch { }
break;
}
// If the npc is required, we'll also set it up as such
if (npcIsRequired)
{
expedition.requireNPC = npcType;
}
}
public ModExpedition Clone()
{
// Clone the class
ModExpedition me = (ModExpedition)Activator.CreateInstance(this.GetType());
me.mod = this.mod;
Expedition ex = me.expedition;
ex.name = expedition.name;
ex.npcHead = expedition.npcHead;
ex.requireNPC = expedition.requireNPC;
ex.conditionDescription1 = expedition.conditionDescription1;
ex.conditionDescription2 = expedition.conditionDescription2;
ex.conditionDescription3 = expedition.conditionDescription3;
ex.conditionDescriptionCountable = expedition.conditionDescriptionCountable;
ex.difficulty = expedition.difficulty;
ex.trackingActive = expedition.trackingActive;
ex.ctgImportant = expedition.ctgImportant;
ex.ctgExplore = expedition.ctgExplore;
ex.ctgCollect = expedition.ctgCollect;
ex.ctgSlay = expedition.ctgSlay;
ex.condition1Met = expedition.condition1Met;
ex.condition2Met = expedition.condition2Met;
ex.condition3Met = expedition.condition3Met;
ex.conditionCounted = expedition.conditionCounted;
ex.conditionCountedMax = expedition.conditionCountedMax;
ex.condition3Met = expedition.condition3Met;
ex.conditionCountedTrackHalfCompleted = expedition.conditionCountedTrackHalfCompleted;
ex.conditionCountedTrackQuarterCompleted = expedition.conditionCountedTrackQuarterCompleted;
ex.hideQuestUnlock = expedition.hideQuestUnlock;
ex.completed = expedition.completed;
ex.repeatable = expedition.repeatable;
ex.partyShare = expedition.partyShare;
ex.anyWood = expedition.anyWood;
ex.anySameTierOreBar = expedition.anySameTierOreBar;
return me;
}
#region Virtual Methods
/// <summary>
/// The initialisation method for mods using this. Use it to set the title and category
/// </summary>
public virtual void SetDefaults()
{
}
/// <summary>
/// Called on world load, used to initialise the deliverables and rewards.
/// </summary>
public virtual void AddItemsOnLoad()
{
}
/// <summary>
/// Set the description of the expedition here.
/// </summary>
/// <param name="complete">Expedition is completed, sometimes you want to display different text.</param>
/// <returns></returns>
public virtual string Description(bool complete)
{
return "";
}
/// <summary>
/// Put in any checks here to determine whether to modify count.
/// If count >= max, this condition is cleared.
/// </summary>
/// <param name="player"></param>
/// <param name="count"></param>
/// <param name="max"></param>
public virtual void CheckConditionCountable(Player player, ref int count, int max)
{
}
/// <summary>
/// Put in any checks here to determine whether the expedition is complete, sans deliverables and the counted condition.
/// </summary>
/// <param name="player">Main.myPlayer</param>
/// <param name="cond1">Used to keep track of a saved condition</param>
/// <param name="cond2">Used to keep track of a saved condition</param>
/// <param name="cond3">Used to keep track of a saved condition</param>
/// <param name="condCount">Used to keep track of a the counted condition</param>
/// <returns>True if custom conditions are met</returns>
public virtual bool CheckConditions(Player player, ref bool cond1, ref bool cond2, ref bool cond3, bool condCount)
{
return true;
}
/// <summary>
/// Put in any checks here to determine whether the expedition is visible yet. Until they are met, expeditions will not call to check conditions, and do not appear in the browser. Effectively acts as if it is active or not.
/// </summary>
/// <param name="player">Main.myPlayer</param>
/// <param name="cond1">Used to keep track of a saved condition</param>
/// <param name="cond2">Used to keep track of a saved condition</param>
/// <param name="cond3">Used to keep track of a saved condition</param>
/// <param name="condCount">Used to keep track of a the counted condition</param>
/// <returns>True if prerequisites are met</returns>
public virtual bool CheckPrerequisites(Player player, ref bool cond1, ref bool cond2, ref bool cond3, bool condCount)
{
return true;
}
/// <summary>
/// Called before deducting items and granting the rewards of an expedition.
/// Use this to modify the rewards before distributing, and checking which
/// of the "any deliverables" were turned in, in inventory order.
/// A caution, the lists won't necessarily be correct in multiplayer if a
/// quest is completed through party share.
/// </summary>
/// <param name="rewards">List of items to be rewarded. </param>
/// <param name="deliveredItems">List of items being delivered. </param>
public virtual void PreCompleteExpedition(List<Item> rewards, List<Item> deliveredItems)
{
return;
}
/// <summary>
/// Called after expedition is completed.
/// </summary>
public virtual void PostCompleteExpedition()
{
return;
}
/// <summary>
/// Checks on a new day to see if this expedition should be added to the random daily expedition. KEEP IN IN MIND: This is a world-based method, not client-based.
/// Make sure you are checking against conditions accessible by the server in multiplayer,
/// otherwise the quest will likely not get added to the daily quest pool.
/// </summary>
/// <returns></returns>
public virtual bool IncludeAsDaily()
{
return false;
}
/// <summary>
/// Called on the dawn of each day, can be used to track day activities.
/// </summary>
public virtual void OnNewDay(Player player, ref bool cond1, ref bool cond2, ref bool cond3, bool condCount)
{
}
/// <summary>
/// Called on the start of each night, can be used to track the start of night activities.
/// </summary>
public virtual void OnNewNight(Player player, ref bool cond1, ref bool cond2, ref bool cond3, bool condCount)
{
}
/// <summary>
/// Called when player engages in most forms of combat against any NPC.
/// </summary>
/// <param name="npc">The NPC fighting with</param>
/// <param name="playerGotHit">If called by player getting bodied by the npc</param>
public virtual void OnCombatWithNPC(NPC npc, bool playerGotHit, Player player, ref bool cond1, ref bool cond2, ref bool cond3, bool condCount)
{
}
/// <summary>
/// Called when an NPC is directly killed by the player, not including debuffs.
/// </summary>
/// <param name="npc">NPC that was killed</param>param>
public virtual void OnKillNPC(NPC npc, Player player, ref bool cond1, ref bool cond2, ref bool cond3, bool condCount)
{
}
/// <summary>
/// Called when an NPC dies somewhere for any reason. May be useful for bosses or group killing missions.
/// </summary>
/// <param name="npc">NPC that was killed</param>param>
public virtual void OnAnyNPCDeath(NPC npc, Player player, ref bool cond1, ref bool cond2, ref bool cond3, bool condCount)
{
}
/// <summary>
/// Called when the player crafts an item. To see how to use recipes, look at recipe.requiredItem[], with each type assigned a stack amount
/// </summary>
/// <param name="item">Item crafted</param>
/// <param name="recipe">Recipe used to craft the item</param>
public virtual void OnCraftItem(Item item, Recipe recipe, Player player, ref bool cond1, ref bool cond2, ref bool cond3, bool condCount)
{
}
/// <summary>
/// Called when the player picks up an item from the world.
/// </summary>
/// <param name="item">Item being picked up</param>
public virtual void OnPickupItem(Item item, Player player, ref bool cond1, ref bool cond2, ref bool cond3, bool condCount)
{
}
/// <summary>
/// Called when a tile is destroyed that's targetting by the player
/// </summary>
/// <param name="x">player tileTargetX</param>
/// <param name="y">player tileTargetY</param>
/// <param name="type">type tile</param>
public virtual void OnKillTile(int x, int y, int type, Player player, ref bool cond1, ref bool cond2, ref bool cond3, bool condCount)
{
}
#endregion
}
}