-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAssWorld.cs
277 lines (255 loc) · 10.5 KB
/
AssWorld.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
using AssortedCrazyThings.NPCs;
using AssortedCrazyThings.NPCs.DungeonBird;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.IO;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace AssortedCrazyThings
{
public class AssWorld : ModWorld
{
//basically "if they were alive last update"
public bool lilmegalodonAlive = false;
public bool megalodonAlive = false;
public bool miniocramAlive = false;
//"are they alive this update"
bool isLilmegalodonSpawned;
bool isMegalodonSpawned;
bool isMiniocramSpawned;
//static names, in case you want to change them later
public static string lilmegalodonName = LittleMegalodon.name;
public static string megalodonName = Megalodon.name;
public static string miniocramName = SpawnOfOcram.name;
public static string lilmegalodonMessage = Megalodon.message;
public static string megalodonMessage = Megalodon.message;
public static string miniocramMessage = SpawnOfOcram.message;
//the megalodon messages are modified down below in the Disappear message
//Soul stuff
public static int[] harvesterTypes = new int[5];
public static int harvesterTalonLeft;
public static int harvesterTalonRight;
public static int harvesterIndex = -1;
public static bool downedHarvester;
//To prevent the item dropping more than once in a single game instance if boss is not defeated
public static bool droppedHarvesterSpawnItemThisSession;
public static bool slimeRainSky = false;
private void InitHarvesterSouls()
{
harvesterTypes[0] = ModContent.NPCType<Harvester1>();
harvesterTypes[1] = ModContent.NPCType<Harvester2>();
harvesterTypes[2] = ModContent.NPCType<Harvester>();
harvesterTypes[3] = harvesterTalonLeft = ModContent.NPCType<HarvesterTalonLeft>();
harvesterTypes[4] = harvesterTalonRight = ModContent.NPCType<HarvesterTalonRight>();
downedHarvester = false;
droppedHarvesterSpawnItemThisSession = false;
}
public override void Initialize()
{
InitHarvesterSouls();
}
public override TagCompound Save()
{
var downed = new List<string>();
if (downedHarvester)
{
downed.Add("harvester");
}
return new TagCompound {
{"downed", downed}
};
}
public override void Load(TagCompound tag)
{
var downed = tag.GetList<string>("downed");
downedHarvester = downed.Contains("harvester");
}
public override void NetSend(BinaryWriter writer)
{
BitsByte flags = new BitsByte();
flags[0] = downedHarvester;
writer.Write(flags);
}
public override void NetReceive(BinaryReader reader)
{
BitsByte flags = reader.ReadByte();
downedHarvester = flags[0];
}
//small methods I made for myself to not make the code cluttered since I have to use these six times
public static void AwakeningMessage(string message, Vector2 pos = default(Vector2), int soundStyle = -1)
{
if (soundStyle != -1) Main.PlaySound(SoundID.Roar, pos, soundStyle); //soundStyle 2 for screech, 0 for regular roar
if (Main.netMode == NetmodeID.SinglePlayer)
{
Main.NewText(message, 175, 75, 255);
}
else if (Main.netMode == NetmodeID.Server)
{
NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(message), new Color(175, 75, 255));
}
}
public static void DisappearMessage(string message)
{
if (Main.netMode == NetmodeID.SinglePlayer)
{
Main.NewText(message, 175, 255, 175);
}
else if (Main.netMode == NetmodeID.Server)
{
NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(message), new Color(175, 255, 175));
}
}
public static void ToggleSlimeRainSky()
{
if (!Main.slimeRain && Main.netMode != NetmodeID.MultiplayerClient)
{
if (!slimeRainSky)
{
SkyManager.Instance.Activate("Slime", default(Vector2));
CombatText.NewText(Main.LocalPlayer.getRect(), CombatText.HealLife, "Background Activated");
slimeRainSky = true;
}
else
{
SkyManager.Instance.Deactivate("Slime");
CombatText.NewText(Main.LocalPlayer.getRect(), CombatText.DamagedFriendly, "Background Deactivated");
slimeRainSky = false;
}
}
}
public static void DisableSlimeRainSky()
{
if (!Main.slimeRain && slimeRainSky && Main.netMode != NetmodeID.MultiplayerClient)
{
SkyManager.Instance.Deactivate("Slime");
CombatText.NewText(Main.LocalPlayer.getRect(), CombatText.DamagedFriendly, "Background Deactivated");
slimeRainSky = false;
}
}
private void LimitSoulCount()
{
if (Main.netMode != NetmodeID.MultiplayerClient)
{
if (Main.time % 30 == 15 && NPC.CountNPCS(ModContent.NPCType<DungeonSoul>()) > 10) //limit soul count in the world to 15
{
short oldest = 200;
int timeleftmin = int.MaxValue;
for (short j = 0; j < Main.maxNPCs; j++)
{
NPC npc = Main.npc[j];
if (npc.active && npc.type == ModContent.NPCType<DungeonSoul>())
{
if (npc.timeLeft < timeleftmin)
{
timeleftmin = npc.timeLeft;
oldest = j;
}
}
}
if (oldest != Main.maxNPCs)
{
NPC oldestnpc = Main.npc[oldest];
oldestnpc.active = false;
oldestnpc.netUpdate = true;
if (Main.netMode == NetmodeID.Server && oldest < Main.maxNPCs)
{
NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, oldest);
}
//poof visual
for (int i = 0; i < 15; i++)
{
Dust dust = Dust.NewDustPerfect(oldestnpc.Center, 59, new Vector2(Main.rand.NextFloat(-2f, 2f), Main.rand.NextFloat(-2f, 1.5f)), 26, Color.White, Main.rand.NextFloat(1.5f, 2.4f));
dust.noLight = true;
dust.noGravity = true;
dust.fadeIn = Main.rand.NextFloat(0.1f, 0.6f);
}
}
}
}
}
private void UpdateEmpoweringFactor()
{
if (NPC.downedPlantBoss && AssPlayer.empoweringTotal < 1f)
AssPlayer.empoweringTotal = 1f;
else if (Main.hardMode && AssPlayer.empoweringTotal < 0.75f)
AssPlayer.empoweringTotal = 0.75f;
}
public override void ResetNearbyTileEffects()
{
Main.LocalPlayer.GetModPlayer<AssPlayer>().wyvernCampfire = false;
}
public override void PostUpdate()
{
//this code is when I first started modding, terrible stuff
//those flags are checked for trueness each update
isLilmegalodonSpawned = false;
isMegalodonSpawned = false;
isMiniocramSpawned = false;
for (short j = 0; j < Main.maxNPCs; j++)
{
NPC npc = Main.npc[j];
if (npc.active)
{
if (npc.TypeName == lilmegalodonName && !isLilmegalodonSpawned)
{
isLilmegalodonSpawned = true;
//check if it wasnt alive in previous update
if (!lilmegalodonAlive)
{
AwakeningMessage(lilmegalodonMessage, npc.position, 0);
lilmegalodonAlive = true;
}
}
if (npc.TypeName == megalodonName && !isMegalodonSpawned)
{
isMegalodonSpawned = true;
if (!megalodonAlive)
{
AwakeningMessage(megalodonMessage, npc.position, 0);
megalodonAlive = true;
}
}
if (npc.TypeName == miniocramName && !isMiniocramSpawned)
{
isMiniocramSpawned = true;
if (!miniocramAlive)
{
AwakeningMessage(miniocramMessage, npc.position, 0);
miniocramAlive = true;
}
}
}
}
//after this we know that either atleast one miniboss is active or not
//if alive, but not active, print disappear message
if (!isLilmegalodonSpawned && lilmegalodonAlive)
{
lilmegalodonAlive = false;
DisappearMessage("The " + megalodonName + " disappeared... for now");
}
if (!isMegalodonSpawned && megalodonAlive)
{
megalodonAlive = false;
DisappearMessage("The " + megalodonName + " disappeared... for now");
}
if (!isMiniocramSpawned && miniocramAlive)
{
miniocramAlive = false;
DisappearMessage("The " + miniocramName + " disappeared... for now");
}
}
public override void PreUpdate()
{
LimitSoulCount();
UpdateEmpoweringFactor();
if (harvesterIndex >= 0 && !Main.npc[harvesterIndex].active)
{
harvesterIndex = -1;
}
}
}
}