forked from GabeHasWon/spritersguildwip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkMode.cs
180 lines (162 loc) · 5.26 KB
/
LinkMode.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
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System;
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 StarlightRiver.Projectiles;
using StarlightRiver.GUI;
namespace StarlightRiver
{
public class LinkMode : ModWorld
{
public static bool Enabled = false;
public static int MaxWorldHP = 1;
public static int WorldHP = 100;
int ticker = 0;
public override void PreUpdate()
{
//Enabled = true;
MaxWorldHP = 0;
foreach(Player player in Main.player.Where(player => player.active))
{
MaxWorldHP += player.statLifeMax2;
}
if (Enabled && WorldHP < 0)
{
WorldHP = 0;
LinkPlayer.sendpacket();
}
if(WorldHP > MaxWorldHP && MaxWorldHP != 0)
{
WorldHP = MaxWorldHP;
LinkPlayer.sendpacket();
}
if (Main.player.Any(player => player.active && player.respawnTimer == 60))
{
WorldHP = MaxWorldHP / 2;
LinkPlayer.sendpacket();
}
int heal = 0;
foreach(Player player in Main.player.Where(player => player.active && player.lifeRegen/2 > 0))
{
heal += (int)(player.lifeRegen / 2);
}
if (ticker++ >= 60 && heal > 0 && WorldHP < MaxWorldHP)
{
WorldHP += heal;
LinkPlayer.sendpacket();
ticker = 0;
}
}
public override TagCompound Save()
{
return new TagCompound
{
[nameof(Enabled)] = Enabled
};
}
public override void Load(TagCompound tag)
{
Enabled = tag.GetBool(nameof(Enabled));
LinkPlayer.sendpacket();
}
}
public class LinkPlayer : ModPlayer
{
public override void PlayerConnect(Player player)
{
if (LinkMode.Enabled)
{
LinkMode.WorldHP += player.statLife;
sendpacket();
}
}
public override bool PreKill(double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
{
if (LinkMode.Enabled && LinkMode.WorldHP > 0)
{
return false;
}
return true;
}
public override bool PreHurt(bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
{
if (LinkMode.Enabled && LinkMode.WorldHP > 0)
{
int hitfor = damage - (int)(player.statDefense * ((Main.expertMode) ? 0.75f : 0.5f));
if (hitfor >= 1)
{
LinkMode.WorldHP -= hitfor;
player.statLife += hitfor;
}
else
{
LinkMode.WorldHP -= 1;
player.statLife += 1;
}
sendpacket();
}
return true;
}
int healCD = 60;
public override void PostUpdate()
{
if (LinkMode.Enabled)
{
player.statLife = player.statLifeMax2 - 1;
if (LinkMode.WorldHP <= 0)
{
player.KillMe(PlayerDeathReason.ByCustomReason(player.name + " died with their teammates..."), 99999, 0);
sendpacket();
}
if(healCD-- <= 0)
{
healCD = 0;
}
LinkHP.visible = true;
}
else
{
LinkHP.visible = false;
}
}
public override void GetHealLife(Item item, bool quickHeal, ref int healValue)
{
if ((player.controlUseItem || player.controlQuickHeal) && LinkMode.Enabled && healCD == 0)
{
LinkMode.WorldHP += healValue;
//Main.NewText("Before the Packer", 255, 0, 0);
Console.WriteLine("PreHeal");
sendpacket();
//Main.NewText("After the Packer", 0, 255, 0);
Console.WriteLine("PostHeal");
}
}
public override void OnRespawn(Player player)
{
sendpacket();
}
public static void sendpacket()
{
//Main.NewText("The Packet", 255, 255, 0);
Console.WriteLine("Server Packet Sent!");
if (Main.netMode == 2)
{
ModPacket packet = StarlightRiver.Instance.GetPacket();
packet.Write(LinkMode.Enabled);
packet.Write(LinkMode.MaxWorldHP);
packet.Write(LinkMode.WorldHP);
packet.Send();
}
}
}
}