forked from steven4547466/Advanced-Subclassing-Redux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbility.cs
More file actions
174 lines (147 loc) · 6.46 KB
/
Ability.cs
File metadata and controls
174 lines (147 loc) · 6.46 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
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
using AdvancedSubclassingRedux.Managers;
using Exiled.API.Features;
using Exiled.API.Features.DamageHandlers;
using MEC;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace AdvancedSubclassingRedux
{
public class Ability
{
public string Name { get; set; }
public string Command { get; set; }
public List<string> Aliases { get; set; } = new List<string>();
public bool Enabled { get; set; } = true;
public Dictionary<string, List<Dictionary<string, object>>> Events { get; set; } = new Dictionary<string, List<Dictionary<string, object>>>();
public List<Dictionary<string, object>> Update { get; set; } = new List<Dictionary<string, object>>();
public List<Dictionary<string, object>> OnGiven { get; set; } = new List<Dictionary<string, object>>();
public List<Dictionary<string, object>> OnDied { get; set; } = new List<Dictionary<string, object>>();
public List<Dictionary<string, object>> OnCommandExecute { get; set; } = new List<Dictionary<string, object>>();
public List<EventInfo> EventInfos { get; set; } = new List<EventInfo>();
public static Ability Get(string name)
{
if (AbilityManager.Abilities.TryGetValue(name, out Ability ability))
return ability;
return null;
}
public bool Use(Player player)
{
if (Tracking.PlayersWithClasses.TryGetValue(player, out Subclass subclass))
{
if (subclass.AbilitiesList.Contains(this))
{
bool hasMax = false;
if (subclass.MaxAbilityUses.TryGetValue(Name, out int maxUses))
{
if (maxUses <= 0) return false;
hasMax = true;
if (Tracking.PlayerAbilityUses.TryGetValue(player, out Dictionary<Ability, int> abilityUses))
{
if (abilityUses.TryGetValue(this, out int uses))
{
if (maxUses >= uses)
{
if (subclass.StringOptions.TryGetValue("OutOfAbilityUses", out string message))
{
player.Broadcast(3, message.Replace("{ability}", Name), Broadcast.BroadcastFlags.Normal, true);
}
return false;
}
}
else
{
abilityUses.Add(this, 0);
}
}
else
{
Dictionary<Ability, int> dict = new Dictionary<Ability, int>();
dict.Add(this, 0);
Tracking.PlayerAbilityUses.Add(player, dict);
}
}
if (!subclass.AbilityCooldowns.TryGetValue(Name, out double cooldown))
{
if (hasMax)
Tracking.PlayerAbilityUses[player][this]++;
return true;
}
if (Tracking.PlayerAbilityCooldowns[player].TryGetValue(this, out DateTime nextAvilable))
{
TimeSpan time = nextAvilable - DateTime.Now;
if (time > TimeSpan.FromSeconds(0))
{
if (subclass.StringOptions.TryGetValue("AbilityOnCooldownMessage", out string message))
{
player.Broadcast(3, message.Replace("{ability}", Name).Replace("{cooldown}", (time.TotalSeconds).ToString("0.0")), Broadcast.BroadcastFlags.Normal, true);
}
return false;
}
Tracking.PlayerAbilityCooldowns[player][this] = DateTime.Now.AddSeconds(cooldown);
if (hasMax)
Tracking.PlayerAbilityUses[player][this]++;
return true;
}
else
{
Tracking.PlayerAbilityCooldowns[player][this] = DateTime.Now.AddSeconds(cooldown);
if (hasMax)
Tracking.PlayerAbilityUses[player][this]++;
return true;
}
}
return false;
}
return false;
}
public bool ExecuteCommand(Player player, List<string> arguments)
{
if (!Use(player))
return false;
if (Tracking.PlayersWithClasses.TryGetValue(player, out Subclass subclass))
{
Timing.RunCoroutine(Helpers.Eval(typeof(AbilityExecuteData), new AbilityExecuteData(player, subclass, arguments), OnCommandExecute));
return true;
}
return false;
}
public void Unload()
{
foreach (EventInfo eventInfo in AbilityManager.EventsConnected.Keys)
{
AbilityManager.EventsConnected[eventInfo]--;
if (AbilityManager.EventsConnected[eventInfo] == 0)
{
AbilityManager.DisconnectFromEvent(eventInfo);
}
}
}
}
public class AbilityExecuteData
{
public Player Player { get; set; }
public Subclass Subclass { get; set; }
public List<string> Arguments { get; set; }
public AbilityExecuteData(Player player, Subclass subclass, List<string> arguments)
{
Player = player;
Subclass = subclass;
Arguments = arguments;
}
}
public class AbilityOnDiedData
{
public Player Target { get; set; }
public Player Attacker { get; set; }
public CustomDamageHandler DamageHandler { get; set; }
public Subclass Subclass { get; set; }
public AbilityOnDiedData(Player target, Player attacker, CustomDamageHandler damageHandler, Subclass subclass)
{
Target = target;
Attacker = attacker;
DamageHandler = damageHandler;
Subclass = subclass;
}
}
}