-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add endpoints for most recent pvp kills (#11)
- Loading branch information
Showing
8 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
### Get player characters | ||
GET http://localhost:25570/v-rising-discord-bot/characters | ||
|
||
### Get player activities | ||
GET http://localhost:25570/v-rising-discord-bot/player-activities | ||
|
||
### Get pvp kills | ||
GET http://localhost:25570/v-rising-discord-bot/pvp-kills |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace v_rising_discord_bot_companion.killfeed; | ||
|
||
public readonly record struct PvpKill( | ||
Player Killer, | ||
Player Victim, | ||
DateTime Occurred | ||
); | ||
|
||
public readonly record struct Player( | ||
string Name, | ||
int GearLevel | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
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 readonly static 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.__OnUpdate_LambdaJob0_entityQuery == null) { | ||
return; | ||
} | ||
|
||
var entities = __instance.__OnUpdate_LambdaJob0_entityQuery.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 | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters