This repository has been archived by the owner on Nov 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IceWorld.cs
111 lines (104 loc) · 3.6 KB
/
IceWorld.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Terraria.World.Generation;
using Terraria.GameContent.Generation;
using Terraria.ID;
using Terraria.ModLoader.IO;
using StructureHelper;
using Terraria.DataStructures;
namespace IceKracken
{
class IceWorld : ModWorld
{
public static Rectangle IceZone = new Rectangle();
public static bool BossOpen;
public static bool BossDowned;
#region Worldgen
public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
{
int DesertIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Micro Biomes"));
tasks.Insert(DesertIndex + 1, new PassLegacy("Ice Kracken Arena Gen", ArenaGen));
}
private void ArenaGen(GenerationProgress progress)
{
progress.Message = "Unleashing the Kracken";
int left = FindFirstSnow();
int right = FindFirstSnow(true);
int width = right - left;
int center = left + width / 2;
int bottom = FindIceDepth(center);
IceZone = new Rectangle(center - 40, bottom - 100, 80, 200);
StructureHelper.StructureHelper.GenerateStructure("SquidTemple", new Point16(center - 40, bottom - 150), mod);
}
private int FindIceDepth(int start)
{
for (int x = start; x < start + 20; x++)
{
for (int y = Main.maxTilesY; y > 0; y--)
{
if (WorldGen.InWorld(x, y))
if (Main.tile[x, y].type == TileID.IceBlock) return y;
}
}
return 0;
}
private int FindFirstSnow(bool startFromRight = false)
{
if (startFromRight)
{
for (int x = Main.maxTilesX; x > 0; x--)
{
for (int y = 0; y < Main.worldSurface; y++)
{
if(WorldGen.InWorld(x, y))
if (Main.tile[x, y].type == TileID.SnowBlock) return x;
}
}
}
else
{
for(int x = 0; x < Main.maxTilesX; x++)
{
for(int y = 0; y < Main.worldSurface; y++)
{
if (WorldGen.InWorld(x, y))
if (Main.tile[x, y].type == TileID.SnowBlock) return x;
}
}
}
return 0;
}
#endregion
public override void PreUpdate()
{
if(!Main.npc.Any(n => n.active && n.type == ModContent.NPCType<Boss.ArenaActor>()))
{
NPC.NewNPC(IceZone.Center.X * 16 + 232, IceZone.Center.Y * 16 - 64, ModContent.NPCType<Boss.ArenaActor>());
}
}
public override TagCompound Save()
{
return new TagCompound()
{
["Left"] = IceZone.X,
["Top"] = IceZone.Y,
["Width"] = IceZone.Width,
["Height"] = IceZone.Height,
["Open"] = BossOpen,
["Downed"] = BossDowned
};
}
public override void Load(TagCompound tag)
{
IceZone = new Rectangle(tag.GetInt("Left"), tag.GetInt("Top"), tag.GetInt("Width"), tag.GetInt("Height"));
BossOpen = tag.GetBool("Open");
BossDowned = tag.GetBool("Downed");
}
}
}