-
Notifications
You must be signed in to change notification settings - Fork 0
/
FishermanNPC.cs
188 lines (170 loc) · 7.79 KB
/
FishermanNPC.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
using FishermanNPC.NPCs;
using FishermanNPC.NPCs.TownNPCs;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Drawing;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
namespace FishermanNPC
{
public class FishermanNPC : Mod
{
internal static FishermanNPCConfigServer ConfigServer;
internal static FishermanNPC Instance;
public override void Load()
{
if (ModLoader.TryGetMod("Wikithis", out Mod wikithis) && !Main.dedServ)
{
wikithis.Call("AddModURL", this, "https://terrariamods.wiki.gg/wiki/User:Rijam/Fisherman_NPC/{}");
wikithis.Call("AddWikiTexture", this, ModContent.Request<Texture2D>("FishermanNPC/icon_small"));
}
if (ModLoader.TryGetMod("ItemCheckBlacklist", out Mod itemCheckBlacklist))
{
itemCheckBlacklist.Call("ItemCheckBlacklist", new List<int>() { ModContent.ItemType<Items.DebugAnglerQuestChanger>(), ModContent.ItemType<Items.CaughtFisherman>() });
}
if (ModLoader.TryGetMod("DialogueTweak", out Mod dialogueTweak))
{
// I couldn't get the frame to work. So ugly 8 mod calls it is.
// Func<Rectangle> frame = () => new(0, (NPCHelper.StatusShopCycle() - 1) * 44, 44, 44); // 184;
Func<Rectangle> frame = () => new(0, 0, 44, 44);
dialogueTweak.Call("ReplaceShopButtonIcon",
ModContent.NPCType<Fisherman>(),
"FishermanNPC/NPCs/Icon_ShopsBait",
() => NPCHelper.StatusShopCycle() == 1,
frame);
dialogueTweak.Call("ReplaceShopButtonIcon",
ModContent.NPCType<Fisherman>(),
"FishermanNPC/NPCs/Icon_ShopsFish",
() => NPCHelper.StatusShopCycle() == 2,
frame);
dialogueTweak.Call("ReplaceShopButtonIcon",
ModContent.NPCType<Fisherman>(),
"FishermanNPC/NPCs/Icon_ShopsRods",
() => NPCHelper.StatusShopCycle() == 3,
frame);
dialogueTweak.Call("ReplaceShopButtonIcon",
ModContent.NPCType<Fisherman>(),
"FishermanNPC/NPCs/Icon_ShopsExtras",
() => NPCHelper.StatusShopCycle() == 4,
frame);
dialogueTweak.Call("ReplaceExtraButtonIcon",
ModContent.NPCType<Fisherman>(),
"FishermanNPC/NPCs/Icon_CycleShops1",
() => NPCHelper.StatusShopCycle() == 1,
frame);
dialogueTweak.Call("ReplaceExtraButtonIcon",
ModContent.NPCType<Fisherman>(),
"FishermanNPC/NPCs/Icon_CycleShops2",
() => NPCHelper.StatusShopCycle() == 2,
frame);
dialogueTweak.Call("ReplaceExtraButtonIcon",
ModContent.NPCType<Fisherman>(),
"FishermanNPC/NPCs/Icon_CycleShops3",
() => NPCHelper.StatusShopCycle() == 3,
frame);
dialogueTweak.Call("ReplaceExtraButtonIcon",
ModContent.NPCType<Fisherman>(),
"FishermanNPC/NPCs/Icon_CycleShops4",
() => NPCHelper.StatusShopCycle() == 4,
frame);
}
}
public override void Unload()
{
ConfigServer = null;
Instance = null;
}
//Adapted from absoluteAquarian's GraphicsLib
public override object Call(params object[] args)
{
ArgumentNullException.ThrowIfNull(args);
if (args[0] is not string function)
throw new ArgumentException("Expected a function name for the first argument");
void CheckArgsLength(int expected, params string[] argNames)
{
if (args.Length != expected)
throw new ArgumentOutOfRangeException($"Expected {expected} arguments for Mod.Call(\"{function}\", {string.Join(",", argNames)}), got {args.Length} arguments instead");
}
switch (function)
{
case "SellModdedItems":
return ModContent.GetInstance<FishermanNPCConfigServer>().SellModdedItems;
case "SellBait":
return ModContent.GetInstance<FishermanNPCConfigServer>().SellBait;
case "SellFish":
return ModContent.GetInstance<FishermanNPCConfigServer>().SellFish;
case "SellFishingRods":
return ModContent.GetInstance<FishermanNPCConfigServer>().SellFishingRods;
case "SellExtraItems":
return ModContent.GetInstance<FishermanNPCConfigServer>().SellExtraItems;
case "shopMulti":
return (ModContent.GetInstance<FishermanNPCConfigServer>().ShopPriceScaling / 100f);
case "TownNPCsCrossModSupport":
return ModContent.GetInstance<FishermanNPCConfigServer>().TownNPCsCrossModSupport;
case "CatchNPCs":
return ModContent.GetInstance<FishermanNPCConfigServer>().CatchNPCs;
case "GetStatusShopCycle": // Legacy
Logger.Warn($"Function \"{function}\" has been removed by FishermanNPC. Please use \"AddToShop\"");
return -1;
case "GetStatusShop1": // Legacy
Logger.Warn($"Function \"{function}\" has been removed by FishermanNPC. Please use \"AddToShop\"");
return false;
case "GetStatusShop2": // Legacy
Logger.Warn($"Function \"{function}\" has been removed by FishermanNPC. Please use \"AddToShop\"");
return false;
case "GetCondition":
CheckArgsLength(2, new string[] { args[0].ToString(), args[1].ToString() });
return args[1].ToString() switch
{
"SellModdedItems" => ShopConditions.SellModdedItems,
"SellBait" => ShopConditions.SellBait,
"SellFish" => ShopConditions.SellFish,
"SellFishingRods" => ShopConditions.SellFishingRods,
"SellExtraItems" => ShopConditions.SellExtraItems,
"TownNPCsCrossModSupport" => ShopConditions.TownNPCsCrossModSupport,
"AnyUnderground" => ShopConditions.AnyUnderground,
"AnyUndergroundOrHardmode" => ShopConditions.AnyUndergroundOrHardmode,
"AnyUndergroundNotDesert" => ShopConditions.AnyUndergroundNotDesert,
"InCavernsOrUnderworld" => ShopConditions.InCavernsOrUnderworld,
"DownedBocOrEoWCrimsonOrHardmode" => ShopConditions.DownedBocOrEoWCrimsonOrHardmode,
"DownedBocOrEoWCorruptionOrHardmode" => ShopConditions.DownedBocOrEoWCorruptionOrHardmode,
"InJungleOrHardmode" => ShopConditions.InJungleOrHardmode,
"InUnderworldOrHardmode" => ShopConditions.InUnderworldOrHardmode,
_ => throw new ArgumentException($"Argument \"{args[1]}\" of Function \"{function}\" is not defined by Fisherman NPC"),
};
case "AddToShop":
switch (args[1].ToString())
{
case "DefaultPrice":
CheckArgsLength(5, new string[] { args[0].ToString(), args[1].ToString(), args[2].ToString(), args[3].ToString(), args[4].ToString() });
// string shop, int item, List<Condition> condition
return FishermanShops.SetShopItem(args[2].ToString(), (int)args[3], (List<Condition>)args[4]);
case "CustomPrice":
CheckArgsLength(6, new string[] { args[0].ToString(), args[1].ToString(), args[2].ToString(), args[3].ToString(), args[4].ToString(), args[5].ToString() });
// string shop, int item, List<Condition> condition, int customPrice
return FishermanShops.SetShopItem(args[2].ToString(), (int)args[3], (List<Condition>)args[4], (int)args[5]);
case "WithMulti":
CheckArgsLength(6, new string[] { args[0].ToString(), args[1].ToString(), args[2].ToString(), args[3].ToString(), args[4].ToString(), args[5].ToString() });
// string shop, int item, List<Condition> condition, float priceMulti
return FishermanShops.SetShopItem(args[2].ToString(), (int)args[3], (List<Condition>)args[4], (float)args[5]);
default:
throw new ArgumentException($"Argument \"{args[1]}\" of Function \"{function}\" is not defined by Fisherman NPC");
}
case "DisableInternalCrossModSupport":
CheckArgsLength(2, new string[] { args[0].ToString(), args[1].ToString() });
Logger.DebugFormat("Internal cross mod support for {0} has been disabled.", args[1].ToString());
return args[1].ToString() switch
{
"CalamityMod" => FishermanShops.CalamityMod = false,
"ThoriumMod" => FishermanShops.ThoriumMod = false,
_ => throw new ArgumentException($"Argument \"{args[1]}\" of Function \"{function}\" is not defined by Fisherman NPC"),
};
default:
throw new ArgumentException($"Function \"{function}\" is not defined by Fisherman NPC");
}
}
}
}