-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheddarMod.cs
300 lines (268 loc) · 9.87 KB
/
CheddarMod.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
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
using System.ComponentModel;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;
namespace CheddarMod
{
public class CheddarMod : Mod
{
public CheddarMod() { }
public static CheddarMod Instance;
public override void Load()
{
Instance = this;
}
public override void Unload()
{
Instance = null;
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
NetHelper.HandlePacket(reader, whoAmI);
}
public override void AddRecipeGroups()
{
RecipeGroup group = new RecipeGroup(() => "Silver or Tungsten bar", new int[]
{
ItemID.SilverBar,
ItemID.TungstenBar
});
RecipeGroup.RegisterGroup("Cheddar:SilverBars", group);
RecipeGroup gold = new RecipeGroup(() => "Gold or Platinum bar", new int[]
{
ItemID.GoldBar,
ItemID.PlatinumBar
});
RecipeGroup.RegisterGroup("Cheddar:GoldBars", gold);
RecipeGroup goldOre = new RecipeGroup(() => "Gold or Platinum ore", new int[]
{
ItemID.GoldOre,
ItemID.PlatinumOre
});
RecipeGroup.RegisterGroup("Cheddar:GoldOres", goldOre);
RecipeGroup earlyHMOre = new RecipeGroup(() => "Cobalt or Palladium ore", new int[]
{
ItemID.CobaltOre,
ItemID.PalladiumOre
});
RecipeGroup.RegisterGroup("Cheddar:CobaltOres", earlyHMOre);
}
}
public class CheddarWorld : ModWorld
{
// Don't need/want to save this
public static bool timeWheel = false;
public override void Initialize()
{
timeWheel = false;
}
public override void NetSend(BinaryWriter writer)
{
writer.Write(timeWheel);
}
public override void NetReceive(BinaryReader reader)
{
timeWheel = reader.ReadBoolean();
}
public override void PreUpdate()
{
// TODO This effect pauses briefly at 4:30am in multiplayer, why?
if (Main.sundialCooldown == 8)
{
return; // Regular sundial effect in use, don't do anything
}
if (timeWheel)
{
Main.dayRate = 60;
Main.fastForwardTime = true;
}
else
{
Main.fastForwardTime = false; // dayRate should be reset automatically by this
}
}
}
public class CheddarItem : GlobalItem
{
bool RealAutoReuseValue = false;
bool FakeAutoReuse = false;
int oldDuration = 0;
public override bool InstancePerEntity => true;
public override bool CloneNewInstances => true;
public override bool ConsumeAmmo(Item item, Player player)
{
CheddarModPlayer modPlayer = player.GetModPlayer<CheddarModPlayer>();
return !modPlayer.tome && !modPlayer.stuff && !modPlayer.omega && (!modPlayer.ammomancer || !Main.rand.NextBool(2));
}
public override bool ConsumeItem(Item item, Player player)
{
CheddarModPlayer modPlayer = player.GetModPlayer<CheddarModPlayer>();
if (modPlayer.stuff || modPlayer.omega)
{
return false;
}
else if (item.thrown && (modPlayer.scroll || (modPlayer.pocket && Main.rand.NextBool(2))))
{
return false;
}
else if ((item.buffType > 0 || item.potion || item.healLife > 0 || item.healMana > 0) && modPlayer.potionSaver)
{
return false;
}
return true;
}
public override bool CanUseItem(Item item, Player player)
{
CheddarModPlayer modPlayer = player.GetModPlayer<CheddarModPlayer>();
if ((modPlayer.trueHero && item.damage > 0) || (item.melee && modPlayer.hero))
{
if (!FakeAutoReuse)
{
RealAutoReuseValue = item.autoReuse;
FakeAutoReuse = true;
}
item.autoReuse = true;
}
else
{
if (FakeAutoReuse)
{
item.autoReuse = RealAutoReuseValue;
FakeAutoReuse = false;
}
}
return base.CanUseItem(item, player);
}
public override void UpdateInventory(Item item, Player player)
{
if (item.buffTime > 0)
{
oldDuration = oldDuration > 0 ? oldDuration : item.buffTime;
// This method runs after ResetDefaults, but before UpdateAccessories
// bBoost is therefore always 1, so bBoost2 updates one tick after actual changes to bBoost
item.buffTime = (int)(oldDuration * player.GetModPlayer<CheddarModPlayer>().bBoost2);
}
}
public override void GrabRange(Item item, Player player, ref int grabRange)
{
grabRange += player.GetModPlayer<CheddarModPlayer>().grabBoost;
}
}
public class CheddarProjectile : GlobalProjectile
{
public override void AI(Projectile projectile)
{
CheddarModPlayer modPlayer = Main.player[projectile.owner].GetModPlayer<CheddarModPlayer>();
if ((projectile.aiStyle == 19 || projectile.aiStyle == 699)
&& Main.player[projectile.owner].HeldItem.melee
&& (modPlayer.hero || modPlayer.trueHero)
&& projectile.timeLeft > Main.player[projectile.owner].itemAnimation)
{
projectile.timeLeft = Main.player[projectile.owner].itemAnimation;
projectile.netUpdate = true;
}
}
}
public class CheddarGlobalNPC : GlobalNPC
{
private int coinCount = 0;
public bool midasCurse = false;
public override bool InstancePerEntity => true;
public override void ResetEffects(NPC npc)
{
midasCurse = false;
}
public override void UpdateLifeRegen(NPC npc, ref int damage)
{
if (midasCurse)
{
if (npc.lifeRegen > 0)
{
npc.lifeRegen = 0;
}
npc.lifeRegen -= 40;
if (damage < 5)
{
damage = 5;
}
coinCount++;
if (coinCount > 120)
{
float r = Main.rand.NextFloat();
int coin;
int num;
if (r < 0.6f)
{
coin = ItemID.CopperCoin;
num = Main.rand.Next(20, 100);
}
else if (r < 0.9f)
{
coin = ItemID.SilverCoin;
num = Main.rand.Next(10, 60);
}
else
{
coin = ItemID.GoldCoin;
num = Main.rand.Next(3, 13);
}
Item.NewItem(npc.getRect(), coin, num);
coinCount = 0;
}
}
else
{
coinCount = 0;
}
}
public override void NPCLoot(NPC npc)
{
if (npc.type == NPCID.KingSlime && Main.rand.NextBool(5))
{
Item.NewItem(npc.getRect(), mod.ItemType("RadiantOoze"));
}
else if ((((npc.type == NPCID.EaterofWorldsHead || npc.type == NPCID.EaterofWorldsBody || npc.type == NPCID.EaterofWorldsTail) && npc.boss)
|| npc.type == NPCID.BrainofCthulhu) && Main.rand.NextFloat() < 0.15f)
{
Item.NewItem(npc.getRect(), mod.ItemType("WornEmblem"));
}
else if (npc.type == NPCID.EyeofCthulhu && Main.rand.NextBool(5))
{
Item.NewItem(npc.getRect(), mod.ItemType("EngravedLens"));
}
else if (npc.type == NPCID.QueenBee && Main.rand.NextFloat() < 0.15f)
{
Item.NewItem(npc.getRect(), mod.ItemType("StarRose"));
}
else if (npc.type == NPCID.SkeletronHead && Main.rand.NextFloat() < 0.15f)
{
Item.NewItem(npc.getRect(), mod.ItemType("CarvedBone"));
}
else if ((npc.type == NPCID.CultistBoss
|| npc.type == NPCID.LunarTowerSolar
|| npc.type == NPCID.LunarTowerStardust
|| npc.type == NPCID.LunarTowerNebula
|| npc.type == NPCID.LunarTowerVortex)
&& Main.rand.NextBool(npc.type == NPCID.CultistBoss ? 10 : 20))
{
Item.NewItem(npc.getRect(), mod.ItemType("CosmicSeal"));
}
// The set of enemies from StardustWormHead to VortexSoldier is a continuous set of Lunar Events enemies
// BUG: One of the pillars is in this set, but whatever
else if (Main.rand.NextBool(500) && npc.type >= NPCID.StardustWormHead && npc.type <= NPCID.VortexSoldier)
{
Item.NewItem(npc.getRect(), mod.ItemType("CosmicSeal"));
}
}
}
public class CheddarModConfig : ModConfig
{
public override ConfigScope Mode => ConfigScope.ServerSide;
[Label("Glass Omega removes mana consumption")]
[Tooltip("Toggle whether or not the Glass Omega item's effect will remove mana consumption.")]
[DefaultValue(false)]
public bool GlassOmegaMana { get; set; }
}
}