This repository has been archived by the owner on Mar 31, 2022. It is now read-only.
forked from gw2scratch/evtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventFilters.cs
70 lines (63 loc) · 1.45 KB
/
EventFilters.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
using GW2Scratch.EVTCAnalytics.Events;
using GW2Scratch.EVTCAnalytics.Model.Agents;
namespace GW2Scratch.EVTCInspector
{
public static class EventFilters
{
public static bool IsAgentInEvent(Event ev, string agentName)
{
if (!string.IsNullOrWhiteSpace(agentName))
{
if (ev is AgentEvent agentEvent)
{
var agent = agentEvent.Agent;
if (agent == null)
{
return false;
}
return agent.Name.Contains(agentName);
}
else if (ev is DamageEvent damageEvent)
{
var attacker = damageEvent.Attacker;
var defender = damageEvent.Defender;
if (attacker == null || defender == null)
{
return false;
}
return attacker.Name.Contains(agentName) || defender.Name.Contains(agentName);
}
else
{
return false;
}
}
return true;
}
public static bool IsAgentInEvent(Event ev, Agent agent, bool ifAttacker = true, bool ifDefender = true)
{
if (ev is AgentEvent agentEvent)
{
return agentEvent.Agent == agent;
}
else if (ev is DamageEvent damageEvent)
{
var attacker = damageEvent.Attacker;
var defender = damageEvent.Defender;
return (ifAttacker && agent == attacker) || (ifDefender && agent == defender);
}
else
{
return false;
}
}
public static bool IsTypeName(Event ev, string eventName)
{
if (!string.IsNullOrWhiteSpace(eventName))
{
return ev.GetType().Name.Contains(eventName);
}
return true;
}
}
}