-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VampireDownedServerEventSystemPatches.cs
69 lines (55 loc) · 2.23 KB
/
VampireDownedServerEventSystemPatches.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
using System;
using System.Collections.Generic;
using Bloodstone.API;
using HarmonyLib;
using ProjectM;
using Unity.Collections;
using Unity.Entities;
using v_rising_discord_bot_companion.game;
namespace v_rising_discord_bot_companion.killfeed;
[HarmonyPatch(typeof(VampireDownedServerEventSystem))]
public class VampireDownedServerEventSystemPatches {
private static readonly List<PvpKill> _pvpKills = new();
public static List<PvpKill> getPvpKills() {
removeExpiredPvpKills();
return _pvpKills;
}
private static void removeExpiredPvpKills() {
_pvpKills.RemoveAll(pvpKill => DateTime.UtcNow > pvpKill.Occurred.AddMinutes(10));
}
[HarmonyPostfix]
[HarmonyPatch("OnUpdate")]
public static void Postfix(VampireDownedServerEventSystem __instance) {
if (__instance.__query_1174204813_0 == null) {
return;
}
var entities = __instance.__query_1174204813_0.ToEntityArray(Allocator.Temp);
foreach (var entity in entities) {
handleDownedEntity(entity);
}
removeExpiredPvpKills();
}
private static void handleDownedEntity(Entity entity) {
VampireDownedServerEventSystem.TryFindRootOwner(entity, 1, VWorld.Server.EntityManager, out var victimEntity);
VWorld.Server.EntityManager.TryGetComponentData<VampireDownedBuff>(entity, out var buff);
VampireDownedServerEventSystem.TryFindRootOwner(buff.Source, 1, VWorld.Server.EntityManager, out var killerEntity);
if (!VWorld.Server.EntityManager.HasComponent<PlayerCharacter>(killerEntity)
|| !VWorld.Server.EntityManager.HasComponent<PlayerCharacter>(victimEntity)
|| victimEntity.Equals(killerEntity)) {
return;
}
var killer = VCharacter.from(killerEntity);
var victim = VCharacter.from(victimEntity);
_pvpKills.Add(new PvpKill(
Killer: new Player(
Name: killer.Character.Name.ToString(),
GearLevel: killer.getGearLevel()
),
Victim: new Player(
Name: victim.Character.Name.ToString(),
GearLevel: victim.getGearLevel()
),
Occurred: DateTime.UtcNow
));
}
}