-
Notifications
You must be signed in to change notification settings - Fork 1
/
XPForKills.cs
164 lines (153 loc) · 4.71 KB
/
XPForKills.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
using Rocket.API.Collections;
using Rocket.Unturned.Events;
using Rocket.Unturned.Player;
using Rocket.Unturned.Chat;
using Rocket.Core.Plugins;
using SDG.Unturned;
using UnityEngine;
using System;
namespace PhaserArray.XPForKills
{
public class XPForKills : RocketPlugin<XPForKillsConfiguration>
{
public static XPForKills Instance;
public static XPForKillsConfiguration Config;
protected override void Load()
{
Instance = this;
Config = Instance.Configuration.Instance;
UnturnedPlayerEvents.OnPlayerDeath += OnPlayerDeath;
Log("Plugin Loaded");
}
public void OnPlayerDeath(UnturnedPlayer player, EDeathCause deathCause, ELimb limb, Steamworks.CSteamID murdererID)
{
// From observations, ID is only invalid if the player was killed by an admin command.
if (murdererID.IsValid())
{
// Killed
if (player.CSteamID != murdererID)
{
var murderer = UnturnedPlayer.FromCSteamID(murdererID);
// Murderer exists (doesn't exist in cases like bleeding and explosions)
if (murderer.Player != null)
{
// Teamkilling
if (Config.CheckSteamGroupTeamkill && player.SteamGroupID == murderer.SteamGroupID)
{
TeamkillPenalty(murderer);
}
// Killed by Player
else
{
KillReward(murderer, player, limb);
DeathPenalty(player);
}
}
// Killed w/o Murderer
else
{
DeathPenalty(player);
}
}
// Suicide
else
{
SuicidePenalty(player);
}
}
}
private void KillReward(UnturnedPlayer murderer, UnturnedPlayer victim, ELimb limb)
{
var limbModifier = GetLimbModifier(limb);
var experience = (int)(Config.KillXP * limbModifier);
UnturnedChat.Say(murderer, Instance.Translate("experience_kill_reward", victim.CharacterName, experience));
ChangeExperience(murderer, experience);
}
private void DeathPenalty(UnturnedPlayer player)
{
if(Config.DeathXP != 0)
{
UnturnedChat.Say(player, Instance.Translate("experience_death_penalty", Mathf.Abs(Config.DeathXP)));
ChangeExperience(player, Config.DeathXP);
}
}
private void SuicidePenalty(UnturnedPlayer player)
{
if (Config.SuicideXP != 0)
{
UnturnedChat.Say(player, Instance.Translate("experience_suicide_penalty", Mathf.Abs(Config.SuicideXP)));
ChangeExperience(player, Config.SuicideXP);
}
}
private void TeamkillPenalty(UnturnedPlayer player)
{
if (Config.TeamkillXP != 0)
{
UnturnedChat.Say(player, Instance.Translate("experience_teamkill_penalty", Mathf.Abs(Config.TeamkillXP)));
ChangeExperience(player, Config.TeamkillXP);
}
}
// If I expand this plugin, a separate logger class would be nice.
private void Log(string message)
{
Console.WriteLine("[XPForKills]: " + message);
}
public void ChangeExperience(UnturnedPlayer player, int change)
{
// The clamp should make sure that experience can't under- or overflow.
player.Experience = (uint)Mathf.Clamp(player.Experience + change, uint.MinValue, uint.MaxValue);
}
public float GetLimbModifier(ELimb limb)
{
// There's probably a better way to connect the
// limb to the experience modifier but this works.
// I'm not sure if the feet, hand, front and back
// limbs are actually used.
switch (limb)
{
case SDG.Unturned.ELimb.LEFT_FOOT:
return Config.LegModifier;
case SDG.Unturned.ELimb.LEFT_LEG:
return Config.LegModifier;
case SDG.Unturned.ELimb.RIGHT_FOOT:
return Config.LegModifier;
case SDG.Unturned.ELimb.RIGHT_LEG:
return Config.LegModifier;
case SDG.Unturned.ELimb.LEFT_HAND:
return Config.ArmModifier;
case SDG.Unturned.ELimb.LEFT_ARM:
return Config.ArmModifier;
case SDG.Unturned.ELimb.RIGHT_HAND:
return Config.ArmModifier;
case SDG.Unturned.ELimb.RIGHT_ARM:
return Config.ArmModifier;
case SDG.Unturned.ELimb.LEFT_BACK:
return Config.TorsoModifier;
case SDG.Unturned.ELimb.RIGHT_BACK:
return Config.TorsoModifier;
case SDG.Unturned.ELimb.LEFT_FRONT:
return Config.TorsoModifier;
case SDG.Unturned.ELimb.RIGHT_FRONT:
return Config.TorsoModifier;
case SDG.Unturned.ELimb.SPINE:
return Config.TorsoModifier;
case SDG.Unturned.ELimb.SKULL:
return Config.HeadModifier;
default:
return Config.DefaultModifier;
}
}
public override TranslationList DefaultTranslations
{
get
{
return new TranslationList(){
{"experience_kill_reward", "You killed {0} and gained {1} experience!"},
{"experience_death_penalty", "You died and lost {0} experience!"},
{"experience_suicide_penalty", "You killed yourself and lost {0} experience!"},
{"experience_teamkill_penalty", "You killed a teammate and lost {0} experience!"}
};
}
}
}
}