init: cs player_status CDK demo
This commit is contained in:
106
logic/event_detector.py
Normal file
106
logic/event_detector.py
Normal file
@@ -0,0 +1,106 @@
|
||||
from hashlib import new
|
||||
|
||||
from logic import events
|
||||
from logic.events import *
|
||||
|
||||
|
||||
class EventDetector:
|
||||
|
||||
|
||||
def detect(self, old, new):
|
||||
|
||||
events=[]
|
||||
|
||||
old_hp = old.get("health")
|
||||
new_hp = new.get("health")
|
||||
old_flashes = old.get("flashed")
|
||||
new_flashes = new.get("flashed")
|
||||
old_burning = old.get("burning")
|
||||
new_burning = new.get("burning")
|
||||
old_kills = old.get("kills")
|
||||
new_kills = new.get("kills")
|
||||
old_headshots = old.get("headshots")
|
||||
new_headshots = new.get("headshots")
|
||||
|
||||
|
||||
# 死亡
|
||||
if (
|
||||
old_hp > 0
|
||||
and new_hp == 0
|
||||
):
|
||||
events.append(
|
||||
DeathEvent()
|
||||
)
|
||||
|
||||
# 受伤
|
||||
if new_hp < old_hp:
|
||||
|
||||
damage = old_hp-new_hp
|
||||
|
||||
if damage >= 50:
|
||||
events.append(
|
||||
DamageEvent(
|
||||
damage
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
events.append(
|
||||
DamageEvent(
|
||||
old_hp - new_hp
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 闪光
|
||||
if new_flashes > old_flashes:
|
||||
events.append(
|
||||
FlashEvent(
|
||||
new_flashes
|
||||
)
|
||||
)
|
||||
elif new_flashes < old_flashes:
|
||||
events.append(
|
||||
FlashEndEvent()
|
||||
)
|
||||
|
||||
# 燃烧
|
||||
if old_burning == 0 and new_burning > 0:
|
||||
|
||||
events.append(
|
||||
BurnEvent(
|
||||
new_burning
|
||||
)
|
||||
)
|
||||
# 燃烧结束
|
||||
elif old_burning > 0 and new_burning == 0:
|
||||
|
||||
events.append(
|
||||
BurnEndEvent()
|
||||
)
|
||||
|
||||
|
||||
# 击杀
|
||||
if new_kills > old_kills:
|
||||
|
||||
events.append(
|
||||
KillEvent(
|
||||
new_kills
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# 爆头
|
||||
if new_headshots > old_headshots:
|
||||
|
||||
events.append(
|
||||
HeadshotEvent(
|
||||
new_headshots
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
return events
|
||||
Reference in New Issue
Block a user