forked from GabeHasWon/spritersguildwip
/
biomehandler.cs
191 lines (174 loc) · 7.25 KB
/
biomehandler.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
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.World.Generation;
using Microsoft.Xna.Framework;
using Terraria.GameContent.Generation;
using Terraria.ModLoader.IO;
using Terraria.DataStructures;
using Microsoft.Xna.Framework.Graphics;
using System;
using StarlightRiver.GUI;
using StarlightRiver.Abilities;
using StarlightRiver.Codex.Entries;
using StarlightRiver.Codex;
namespace StarlightRiver
{
public class BiomeHandler : ModPlayer
{
public bool ZoneGlass = false;
public bool GlassBG = false;
public bool ZoneVoidPre = false;
public bool ZoneJungleCorrupt = false;
public bool ZoneJungleBloody = false;
public bool ZoneJungleHoly = false;
public bool ZoneOvergrow = false;
public override void UpdateBiomes()
{
ZoneGlass = (LegendWorld.glassTiles > 50);
GlassBG = LegendWorld.vitricBiome.Contains((player.Center / 16).ToPoint()) && ZoneGlass;
ZoneVoidPre = (LegendWorld.voidTiles > 50);
ZoneJungleCorrupt = (LegendWorld.evilJungleTiles > 50);
ZoneJungleBloody = (LegendWorld.bloodJungleTiles > 50);
ZoneJungleHoly = (LegendWorld.holyJungleTiles > 50);
ZoneOvergrow = Main.tile[(int)(player.Center.X / 16), (int)(player.Center.Y / 16)].wall == ModContent.WallType<Tiles.Overgrow.WallOvergrowGrass>() ||
Main.tile[(int)(player.Center.X / 16), (int)(player.Center.Y / 16)].wall == ModContent.WallType<Tiles.Overgrow.WallOvergrowBrick>() ||
Main.tile[(int)(player.Center.X / 16), (int)(player.Center.Y / 16)].wall == ModContent.WallType<Tiles.Overgrow.WallOvergrowInvisible>();
}
public override bool CustomBiomesMatch(Player other)
{
BiomeHandler modOther = other.GetModPlayer<BiomeHandler>();
bool allMatch = true;
allMatch &= ZoneGlass == modOther.ZoneGlass;
allMatch &= ZoneVoidPre == modOther.ZoneVoidPre;
allMatch &= ZoneJungleCorrupt == modOther.ZoneJungleCorrupt;
allMatch &= ZoneJungleBloody == modOther.ZoneJungleBloody;
allMatch &= ZoneJungleHoly == modOther.ZoneJungleHoly;
allMatch &= ZoneOvergrow == modOther.ZoneOvergrow;
return allMatch;
}
public override void CopyCustomBiomesTo(Player other)
{
BiomeHandler modOther = other.GetModPlayer<BiomeHandler>();
modOther.ZoneGlass = ZoneGlass;
modOther.ZoneVoidPre = ZoneVoidPre;
modOther.ZoneJungleCorrupt = ZoneJungleCorrupt;
modOther.ZoneJungleBloody = ZoneJungleBloody;
modOther.ZoneJungleHoly = ZoneJungleHoly;
modOther.ZoneOvergrow = ZoneOvergrow;
}
public override void SendCustomBiomes(BinaryWriter writer)
{
BitsByte flags = new BitsByte();
flags[0] = ZoneGlass;
flags[1] = ZoneVoidPre;
flags[2] = ZoneJungleCorrupt;
flags[3] = ZoneJungleBloody;
flags[4] = ZoneJungleHoly;
flags[5] = ZoneOvergrow;
writer.Write(flags);
}
public override void ReceiveCustomBiomes(BinaryReader reader)
{
BitsByte flags = reader.ReadByte();
ZoneGlass = flags[0];
ZoneVoidPre = flags[1];
ZoneJungleCorrupt = flags[2];
ZoneJungleBloody = flags[3];
ZoneJungleHoly = flags[4];
ZoneOvergrow = flags[5];
}
public override void PreUpdate()
{
float distance = Vector2.Distance(Main.LocalPlayer.Center, LegendWorld.RiftLocation);
if (distance <= 1500)
{
float val = (1500 / distance - 1) * 2;
if (val <= 1) val = 1;
if (val >= 2.5f) val = 2.5f;
Lighting.brightness = 1 / val;
}
if (ZoneVoidPre)
{
Overlay.state = 1;
if (player.GetModPlayer<AbilityHandler>().pure.Locked)
{
player.AddBuff(mod.BuffType("DarkSlow"), 5);
}
}
else if (ZoneJungleCorrupt)
{
Overlay.state = 2;
}
else if (ZoneJungleBloody)
{
Overlay.state = 3;
}
else if (ZoneJungleHoly)
{
Overlay.state = (int)OverlayState.HolyJungle;
}
if (ZoneOvergrow && Main.rand.Next(5) == 0)
{
Dust.NewDustPerfect(Main.screenPosition - Vector2.One * 100 + new Vector2(Main.rand.Next(Main.screenWidth + 200), Main.rand.Next(Main.screenHeight + 200)),
ModContent.DustType<Dusts.OvergrowDust>(), Vector2.Zero, 0, new Color(255, 255, 205) * 0.05f, 2);
}
//Codex Unlocks
if (ZoneGlass && player.GetModPlayer<CodexHandler>().Entries.Any(entry => entry is VitricEntry && entry.Locked))
{
Helper.UnlockEntry<VitricEntry>(player);
}
}
}
public partial class LegendWorld
{
public static int glassTiles;
public static int voidTiles;
public static int evilJungleTiles;
public static int bloodJungleTiles;
public static int holyJungleTiles;
public override void TileCountsAvailable(int[] tileCounts)
{
glassTiles = tileCounts[mod.TileType("VitricSand")];
voidTiles = tileCounts[mod.TileType("Void1")] + tileCounts[mod.TileType("Void2")];
evilJungleTiles = tileCounts[mod.TileType("GrassJungleCorrupt")];
bloodJungleTiles = tileCounts[mod.TileType("GrassJungleBloody")];
holyJungleTiles = tileCounts[mod.TileType("GrassJungleHoly")];
}
}
public partial class StarlightRiver : Mod
{
public override void ModifySunLightColor(ref Color tileColor, ref Color backgroundColor)
{
if (Main.LocalPlayer.GetModPlayer<BiomeHandler>().ZoneJungleCorrupt)
{
tileColor = tileColor.MultiplyRGB(new Color(130, 100, 145));
backgroundColor = backgroundColor.MultiplyRGB(new Color(130, 100, 145));
}
if (Main.LocalPlayer.GetModPlayer<BiomeHandler>().ZoneJungleBloody)
{
tileColor = tileColor.MultiplyRGB(new Color(155, 120, 90));
backgroundColor = backgroundColor.MultiplyRGB(new Color(155, 120, 90));
}
if (Main.LocalPlayer.GetModPlayer<BiomeHandler>().ZoneJungleHoly)
{
tileColor = tileColor.MultiplyRGB(new Color(70, 150, 165));
backgroundColor = backgroundColor.MultiplyRGB(new Color(70, 150, 165));
}
if (Main.LocalPlayer.GetModPlayer<BiomeHandler>().ZoneVoidPre)
{
tileColor = tileColor.MultiplyRGB(Color.Purple);
backgroundColor = backgroundColor.MultiplyRGB(Color.Purple);
}
if (LegendWorld.starfall)
{
tileColor = new Color(20, 50, 60);
backgroundColor = new Color(10, 15, 20);
}
}
}
}