From ea73d0861429060267df3ac20d4b3dc86dec3a27 Mon Sep 17 00:00:00 2001 From: kdovtdc Date: Fri, 20 Sep 2024 18:40:03 +0200 Subject: [PATCH 1/2] Add `Source` to `HPChange` event's emit * adds `Source` field to `HPChange` event for tracking the entity responsible for HP change (`Source` already existed in service method `emitHPChangeEvents`) * run tygo for corresponding TypeScript file * fix impls with `HPChange` events requiring `Source` --- pkg/engine/attribute/event.go | 1 + pkg/engine/event/attribute.go | 1 + ui/packages/types/src/event.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/pkg/engine/attribute/event.go b/pkg/engine/attribute/event.go index 6b2135df..01f4e00a 100644 --- a/pkg/engine/attribute/event.go +++ b/pkg/engine/attribute/event.go @@ -19,6 +19,7 @@ func (s *Service) emitHPChangeEvents( s.event.HPChange.Emit(event.HPChange{ Key: key, Target: target, + Source: source, OldHPRatio: oldRatio, NewHPRatio: newRatio, OldHP: maxHP * oldRatio, diff --git a/pkg/engine/event/attribute.go b/pkg/engine/event/attribute.go index 3e75dde0..c02c0939 100644 --- a/pkg/engine/event/attribute.go +++ b/pkg/engine/event/attribute.go @@ -9,6 +9,7 @@ type HPChangeEventHandler = handler.EventHandler[HPChange] type HPChange struct { Key key.Reason `json:"key"` Target key.TargetID `json:"target"` + Source key.TargetID `json:"source"` OldHPRatio float64 `json:"old_hp_ratio"` NewHPRatio float64 `json:"new_hp_ratio"` OldHP float64 `json:"old_hp"` diff --git a/ui/packages/types/src/event.ts b/ui/packages/types/src/event.ts index b74a7108..20d53ef7 100755 --- a/ui/packages/types/src/event.ts +++ b/ui/packages/types/src/event.ts @@ -13,6 +13,7 @@ export type HPChangeEventHandler = Handler; export interface HPChange { key: string; target: string; + source: string; old_hp_ratio: number /* float64 */; new_hp_ratio: number /* float64 */; old_hp: number /* float64 */; From 0a93e5f40084cb56b7fbf46665e33fd988ef05f4 Mon Sep 17 00:00:00 2001 From: kdovtdc Date: Fri, 20 Sep 2024 19:53:46 +0200 Subject: [PATCH 2/2] fix impls with `HPChange` events requiring `Source` --- internal/character/herta/talent.go | 4 ++-- .../destruction/theunreachableside/theunreachableside.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/character/herta/talent.go b/internal/character/herta/talent.go index cf677f1a..d6245d89 100644 --- a/internal/character/herta/talent.go +++ b/internal/character/herta/talent.go @@ -35,8 +35,8 @@ func (c *char) talentListener(e event.HPChange) { onCD, ok := passiveCooldowns[e.Target] if e.NewHPRatio <= 0.5 { - // Check if enemy, is either not in the map (never seen before) or is in there and - if c.engine.IsEnemy(e.Target) && (!ok || !onCD) && !c.engine.HasBehaviorFlag(c.id, model.BehaviorFlag_STAT_CTRL) { + // Check if enemy, is either not in the map (never seen before) or is in there, the source is an ally and Herta is not under a status control effect + if c.engine.IsEnemy(e.Target) && (!ok || !onCD) && c.engine.IsCharacter(e.Source) && !c.engine.HasBehaviorFlag(c.id, model.BehaviorFlag_STAT_CTRL) { if len(c.engine.Enemies()) > 0 { c.engine.Events().AttackEnd.Subscribe(c.talentAfterAttackListener) hertaCount += 1 diff --git a/internal/lightcone/destruction/theunreachableside/theunreachableside.go b/internal/lightcone/destruction/theunreachableside/theunreachableside.go index 2008b9d3..476e0c5a 100644 --- a/internal/lightcone/destruction/theunreachableside/theunreachableside.go +++ b/internal/lightcone/destruction/theunreachableside/theunreachableside.go @@ -63,7 +63,7 @@ func buffOnAttacked(mod *modifier.Instance, e event.AttackEnd) { func buffOnHPConsume(mod *modifier.Instance, e event.HPChange) { // bypass if: hpchangebydmg is true, hpchange source isn't lc holder, hpchange increase hp. - if e.IsHPChangeByDamage || e.Target != mod.Owner() || e.NewHP > e.OldHP { + if e.IsHPChangeByDamage || e.Source != mod.Owner() || e.NewHP > e.OldHP { return } dmgAmt := mod.State().(float64)