forked from PoctorDepper/LevelPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalNPC.cs
More file actions
58 lines (46 loc) · 2.09 KB
/
GlobalNPC.cs
File metadata and controls
58 lines (46 loc) · 2.09 KB
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
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace levelplus {
class levelplusGlobalNPC : GlobalNPC {
public override bool InstancePerEntity => true;
public override void ScaleExpertStats(NPC npc, int numPlayers, float bossLifeScale) {
base.ScaleExpertStats(npc, numPlayers, bossLifeScale);
float averageLevel = 0;
foreach (Player i in Main.player)
if (i.active) {
numPlayers++;
averageLevel += i.GetModPlayer<levelplusModPlayer>().GetLevel();
}
averageLevel /= numPlayers;
npc.damage += (int)(npc.damage * (averageLevel * levelplusConfig.Instance.ScalingDamage));
npc.lifeMax += (int)(npc.lifeMax * (averageLevel * levelplusConfig.Instance.ScalingHealth));
}
public override void OnKill(NPC npc) {
base.OnKill(npc);
if (npc.type != NPCID.TargetDummy && !npc.SpawnedFromStatue && !npc.friendly && !npc.townNPC) {
ulong amount;
if (npc.boss) {
amount = (ulong)(npc.lifeMax / levelplusConfig.Instance.BossXP);
} else {
amount = (ulong)(npc.lifeMax / levelplusConfig.Instance.MobXP);
}
if (Main.netMode == NetmodeID.SinglePlayer) {
Main.LocalPlayer.GetModPlayer<levelplusModPlayer>().AddXp(amount);
} else if (Main.netMode == NetmodeID.Server) {
levelplus.Instance.Logger.WarnFormat("" + npc.playerInteraction.Length);
for (int i = 0; i < npc.playerInteraction.Length; ++i)
{
if (npc.playerInteraction[i])
{
ModPacket packet = levelplus.Instance.GetPacket();
packet.Write((byte)PacketType.XP);
packet.Write(amount);
packet.Send(i);
}
}
}
}
}
}
}