forked from roflmuffin/CounterStrikeSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventSystem.cs
122 lines (97 loc) · 4.25 KB
/
EventSystem.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
/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
using System;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Events;
using CounterStrikeSharp.API.Modules.Utils;
namespace WarcraftPlugin
{
public class EventSystem
{
private WarcraftPlugin _plugin;
public EventSystem(WarcraftPlugin plugin)
{
_plugin = plugin;
}
public void Initialize()
{
_plugin.RegisterEventHandler<EventPlayerDeath>(PlayerDeathHandler);
_plugin.RegisterEventHandler<EventPlayerSpawn>(PlayerSpawnHandler);
_plugin.RegisterEventHandler<EventPlayerHurt>(PlayerHurtHandler);
}
private HookResult PlayerHurtHandler(EventPlayerHurt @event, GameEventInfo _)
{
var victim = @event.Userid;
var attacker = @event.Attacker;
victim?.GetWarcraftPlayer()?.GetRace()?.InvokeEvent("player_hurt", @event);
attacker?.GetWarcraftPlayer()?.GetRace()?.InvokeEvent("player_hurt_other", @event);
return HookResult.Continue;
}
private HookResult PlayerSpawnHandler(EventPlayerSpawn @event, GameEventInfo _)
{
var player = @event.Userid;
var race = player.GetWarcraftPlayer()?.GetRace();
if (race != null)
{
var name = @event.EventName;
Server.NextFrame(() =>
{
WarcraftPlugin.Instance.EffectManager.ClearEffects(player);
race.InvokeEvent(name, @event);
});
}
return HookResult.Continue;
}
private HookResult PlayerDeathHandler(EventPlayerDeath @event, GameEventInfo _)
{
var attacker = @event.Attacker;
var victim = @event.Userid;
var headshot = @event.Headshot;
if (attacker.IsValid && victim.IsValid && (attacker != victim) && !attacker.IsBot)
{
var weaponName = attacker.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value.DesignerName;
int xpToAdd = 0;
int xpHeadshot = 0;
int xpKnife = 0;
xpToAdd = _plugin.XpPerKill;
if (headshot)
xpHeadshot = Convert.ToInt32(_plugin.XpPerKill * _plugin.XpHeadshotModifier);
if (weaponName == "weapon_knife")
xpKnife = Convert.ToInt32(_plugin.XpPerKill * _plugin.XpKnifeModifier);
xpToAdd += xpHeadshot + xpKnife;
_plugin.XpSystem.AddXp(attacker, xpToAdd);
string hsBonus = "";
if (xpHeadshot != 0)
{
hsBonus = $"(+{xpHeadshot} HS bonus)";
}
string knifeBonus = "";
if (xpKnife != 0)
{
knifeBonus = $"(+{xpKnife} knife bonus)";
}
string xpString = $" {ChatColors.Gold}+{xpToAdd} XP {ChatColors.Default}for killing {ChatColors.Green}{victim.PlayerName} {ChatColors.Default}{hsBonus}{knifeBonus}";
_plugin.GetWcPlayer(attacker).SetStatusMessage(xpString);
attacker.PrintToChat(xpString);
}
victim?.GetWarcraftPlayer()?.GetRace()?.InvokeEvent("player_death", @event);
attacker?.GetWarcraftPlayer()?.GetRace()?.InvokeEvent("player_kill", @event);
WarcraftPlugin.Instance.EffectManager.ClearEffects(victim);
return HookResult.Continue;
}
}
}