This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ErilipahTile.cs
104 lines (91 loc) · 3.82 KB
/
ErilipahTile.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
using Erilipah.Biomes.ErilipahBiome.Tiles;
using Erilipah.Items;
using Erilipah.Items.ErilipahBiome;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
namespace Erilipah
{
internal class ErilipahTile : GlobalTile
{
public static bool OffScreen(int i, int j)
{
bool offScreenX = i < Main.screenPosition.X / 16 || i > (Main.screenPosition.X + Main.screenWidth) / 16;
bool offScreenY = j < Main.screenPosition.Y / 16 || j > (Main.screenPosition.Y + Main.screenHeight) / 16;
return offScreenX & offScreenY;
}
public override void RandomUpdate(int i, int j, int type)
{
if (Main.tile[i, j].IsErilipahTile() && Main.rand.Chance(0.012f) && OffScreen(i, j))
{
/* 0= 3x stalk
* 1= 1x bubble
* 2= 3x vine
* 3= 1x geyser
* 4= 1.5x giant pf
* 5= 0.85x vent
* 6= 1.25x hive */
Terraria.Utilities.WeightedRandom<int> rand = new Terraria.Utilities.WeightedRandom<int>();
rand.Add(0, 3);
rand.Add(1, 1);
rand.Add(2, 3);
rand.Add(3, 1);
rand.Add(4, 1.5);
rand.Add(5, 0.85);
rand.Add(6, 1.25);
ErilipahWorld.PlaceHazard(i, j, rand.Get());
if (Main.netMode == 2 /*Sync to clients when run on the server*/)
NetMessage.SendTileSquare(-1, i, j, 1, TileChangeType.None);
}
if (Main.tile[i, j].IsErilipahTile() && Main.rand.Chance(0.002f))
{
Biomes.ErilipahBiome.Hazards.Mushroom.TryPlace(i, j - 1);
Biomes.ErilipahBiome.Hazards.Mushroom.TryPlace(i, j + 1);
}
}
public override void NearbyEffects(int i, int j, int type, bool closer)
{
if (Main.netMode != 1 && Main.rand.Chance(ErilipahItem.LightSnuffRate))
Snuff(i, j);
}
public static void Snuff(int i, int j, bool ignoreArken = false)
{
try
{
Tile tile = Main.tile[i, j];
int type = tile.type;
Mod mod = GetInstance<Erilipah>();
bool light = tile.type == TileID.Torches || tile.type == TileID.Campfire || TileLoader.IsTorch(type);
if (!ignoreArken)
light &= type != TileType<ArkenTorchTile>();
else
light &= type != TileType<ArkenTorchTile>() || Main.rand.NextBool();
if (light)
{
if (!ignoreArken && type == TileType<CrystallineTorchTile>() && Main.rand.Chance(0.50f))
{
return;
}
if (Main.LocalPlayer.InErilipah())
{
ErilipahItem.SnuffFx(new Vector2(i * 16 + 8, j * 16 + 8));
Main.PlaySound(SoundID.LiquidsWaterLava.WithPitchVariance(-0.35f), new Vector2(i * 16 + 8, j * 16 + 8));
WorldGen.KillTile(i, j, false, noItem: type != TileType<ArkenTorchTile>());
WorldGen.TileFrame(i, j);
}
}
}
catch { Main.NewText("PEE"); }
}
public override bool CanKillTile(int i, int j, int type, ref bool blockDamaged)
{
Tile tileAbove = Main.tile[i, j - 1];
bool tileAboveImportant = false;
tileAboveImportant |= tileAbove.type == TileType<SoulStatue>();
tileAboveImportant |= tileAbove.type == TileType<Altar>();
return !tileAboveImportant;
}
}
}