Skip to content

Commit

Permalink
Merge pull request #7 from DevilVsLive2/main
Browse files Browse the repository at this point in the history
Add missing unit events
  • Loading branch information
kirill-782 authored Dec 20, 2023
2 parents 41b7eae + 75c4036 commit 90af9c8
Show file tree
Hide file tree
Showing 14 changed files with 499 additions and 1,929 deletions.
2,104 changes: 175 additions & 1,929 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/handles/Unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ import {
import { UnitEventStateLimit } from "../triggerEvents/unit/UnitEventStateLimit.js";
import { UnitStateEmiter } from "../services/emitters/UnitStateEmiter.js";
import { LimitOp, UnitState } from "./../services/emitters/UnitStateEmiter.js";
import { UnitEventBuffReceived } from "../triggerEvents/unit/UnitEventBuffReceived.js";
import { UnitEventBuffRefreshed } from "../triggerEvents/unit/UnitEventBuffRefreshed.js";
import { UnitEventBuffEnded } from "../triggerEvents/unit/UnitEventBuffEnded.js";
import { UnitEventProjectileLaunch } from "../triggerEvents/unit/UnitEventProjectileLaunch.js";
import { UnitEventProjectileHit } from "../triggerEvents/unit/UnitEventProjectileHit.js";
import { UnitEventSpellChannel } from "../triggerEvents/unit/UnitEventSpellChannel.js";
import { UnitEventSpellCast } from "../triggerEvents/unit/UnitEventSpellCast.js";
import { UnitEventSpellEffect } from "../triggerEvents/unit/UnitEventSpellEffect.js";
import { UnitEventSpellFinish } from "../triggerEvents/unit/UnitEventSpellFinish.js";
import { UnitEventSpellEndcast } from "../triggerEvents/unit/UnitEventSpellEndcast.js";

const eventUnitEmiter = unitEmiter;

Expand Down Expand Up @@ -87,6 +97,20 @@ export interface UnitEventMap extends WidgetEventMap {
loaded: (event: UnitEventLoaded) => void;
attackFinished: (event: TriggerUnitEvent<"attackFinished">) => void;
decayFinished: (event: TriggerUnitEvent<"decayFinished">) => void;
buffReceived: (event: UnitEventBuffReceived) => void;
buffRefreshed: (event: UnitEventBuffRefreshed) => void;
buffEnded: (event: UnitEventBuffEnded) => void;
projectileLaunch: (event: UnitEventProjectileLaunch) => void;
projectileHit: (event: UnitEventProjectileHit) => void;
abilityAdded: (event: TriggerUnitEvent<"abilityAdded">) => void;
abilityRemoved: (event: TriggerUnitEvent<"abilityRemoved">) => void;
abilityAutocastOn: (event: TriggerUnitEvent<"abilityAutocastOn">) => void;
abilityAutocastOff: (event: TriggerUnitEvent<"abilityAutocastOff">) => void;
spellChannel: (event: UnitEventSpellChannel) => void;
spellCast: (event: UnitEventSpellCast) => void;
spellEffect: (event: UnitEventSpellEffect) => void;
spellFinish: (event: UnitEventSpellFinish) => void;
spellEndcast: (event: UnitEventSpellEndcast) => void;
[stateEvent]: (event: UnitEventStateLimit, emiter: UnitStateEmiter) => void;
}

Expand Down
58 changes: 58 additions & 0 deletions src/services/emitters/UnitEmiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ import { UnitEventDropItem } from "../../triggerEvents/unit/UnitEventDropItem.js
import { UnitEventPickupItem } from "../../triggerEvents/unit/UnitEventPickupItem.js";
import { UnitEventUseItem } from "../../triggerEvents/unit/UnitEventUseItem.js";
import { UnitEventLoaded } from "../../triggerEvents/unit/UnitEventLoaded.js";
import { UnitEventBuffReceived } from "../../triggerEvents/unit/UnitEventBuffReceived.js";
import { UnitEventBuffRefreshed } from "../../triggerEvents/unit/UnitEventBuffRefreshed.js";
import { UnitEventBuffEnded } from "../../triggerEvents/unit/UnitEventBuffEnded.js";
import { UnitEventProjectileLaunch } from "../../triggerEvents/unit/UnitEventProjectileLaunch.js";
import { UnitEventProjectileHit } from "../../triggerEvents/unit/UnitEventProjectileHit.js";
import { UnitEventSpellChannel } from "../../triggerEvents/unit/UnitEventSpellChannel.js";
import { UnitEventSpellCast } from "../../triggerEvents/unit/UnitEventSpellCast.js";
import { UnitEventSpellEffect } from "../../triggerEvents/unit/UnitEventSpellEffect.js";
import { UnitEventSpellFinish } from "../../triggerEvents/unit/UnitEventSpellFinish.js";
import { UnitEventSpellEndcast } from "../../triggerEvents/unit/UnitEventSpellEndcast.js";

export type UnitEventType = keyof typeof stringToHandle;

Expand Down Expand Up @@ -79,6 +89,20 @@ const stringToHandle = {
loaded: UnitEvents.EVENT_UNIT_LOADED,
attackFinished: UnitEvents.EVENT_UNIT_ATTACK_FINISHED,
decayFinished: UnitEvents.EVENT_UNIT_DECAY_FINISHED,
buffReceived: UnitEvents.EVENT_UNIT_BUFF_RECEIVED,
buffRefreshed: UnitEvents.EVENT_UNIT_BUFF_REFRESHED,
buffEnded: UnitEvents.EVENT_UNIT_BUFF_ENDED,
projectileLaunch: UnitEvents.EVENT_UNIT_PROJECTILE_LAUNCH,
projectileHit: UnitEvents.EVENT_UNIT_PROJECTILE_HIT,
abilityAdded: UnitEvents.EVENT_UNIT_ABILITY_ADDED,
abilityRemoved: UnitEvents.EVENT_UNIT_ABILITY_REMOVED,
abilityAutocastOn: UnitEvents.EVENT_UNIT_ABILITY_AUTOCAST_ON,
abilityAutocastOff: UnitEvents.EVENT_UNIT_ABILITY_AUTOCAST_OFF,
spellChannel: UnitEvents.EVENT_UNIT_SPELL_CHANNEL,
spellCast: UnitEvents.EVENT_UNIT_SPELL_CAST,
spellEffect: UnitEvents.EVENT_UNIT_SPELL_EFFECT,
spellFinish: UnitEvents.EVENT_UNIT_SPELL_FINISH,
spellEndcast: UnitEvents.EVENT_UNIT_SPELL_ENDCAST,
};

type UnitTriggerInfo = {
Expand All @@ -98,6 +122,10 @@ const dispatchUnitEvent = (unit: Unit, eventType: string) => {
case "heroLevel":
case "attackFinished":
case "decayFinished":
case "abilityAdded":
case "abilityRemoved":
case "abilityAutocastOn":
case "abilityAutocastOff":
unit.emit(eventType, new TriggerUnitEvent(eventType));
break;
case "damaged":
Expand Down Expand Up @@ -187,6 +215,36 @@ const dispatchUnitEvent = (unit: Unit, eventType: string) => {
case "loaded":
unit.emit("loaded", new UnitEventLoaded());
break;
case "buffRecieved":
unit.emit("buffReceived", new UnitEventBuffReceived());
break;
case "buffRefreshed":
unit.emit("buffRefreshed", new UnitEventBuffRefreshed());
break;
case "buffEnded":
unit.emit("buffEnded", new UnitEventBuffEnded());
break;
case "projectileLaunch":
unit.emit("projectileLaunch", new UnitEventProjectileLaunch());
break;
case "projectileHit":
unit.emit("projectileHit", new UnitEventProjectileHit());
break;
case "spellChannel":
unit.emit("spellChannel", new UnitEventSpellChannel());
break;
case "spellCast":
unit.emit("spellCast", new UnitEventSpellCast());
break;
case "spellEffect":
unit.emit("spellEffect", new UnitEventSpellEffect());
break;
case "spellFinish":
unit.emit("spellFinish", new UnitEventSpellFinish());
break;
case "spellEndcast":
unit.emit("spellEndcast", new UnitEventSpellEndcast());
break;
default:
throw new TypeError(`Unexpected eventType: ${eventType}`);
}
Expand Down
16 changes: 16 additions & 0 deletions src/triggerEvents/unit/UnitEventBuffEnded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Unit } from "../../handles/Unit.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";
import { GetTriggerBuff, GetTriggerBuffSourceAbility, GetTriggerBuffSourceUnit, HAbility, HBuff } from "../../utils/common.js";

export class UnitEventBuffEnded extends TriggerUnitEvent<"buffEnded"> {
readonly recievedBuff: HBuff;
readonly sourceAbility: HAbility;
readonly sourceUnit: Unit;
constructor() {
super("buffEnded");
this.recievedBuff = fromHandleHolderSoft(GetTriggerBuff());
this.sourceAbility = fromHandleHolderSoft(GetTriggerBuffSourceAbility());
this.sourceUnit = fromHandleHolderSoft(GetTriggerBuffSourceUnit());
}
}
16 changes: 16 additions & 0 deletions src/triggerEvents/unit/UnitEventBuffReceived.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Unit } from "../../handles/Unit.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";
import { GetTriggerBuff, GetTriggerBuffSourceAbility, GetTriggerBuffSourceUnit, HAbility, HBuff } from "../../utils/common.js";

export class UnitEventBuffReceived extends TriggerUnitEvent<"buffReceived"> {
readonly recievedBuff: HBuff;
readonly sourceAbility: HAbility;
readonly sourceUnit: Unit;
constructor() {
super("buffReceived");
this.recievedBuff = fromHandleHolderSoft(GetTriggerBuff());
this.sourceAbility = fromHandleHolderSoft(GetTriggerBuffSourceAbility());
this.sourceUnit = fromHandleHolderSoft(GetTriggerBuffSourceUnit());
}
}
16 changes: 16 additions & 0 deletions src/triggerEvents/unit/UnitEventBuffRefreshed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Unit } from "../../handles/Unit.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";
import { GetTriggerBuff, GetTriggerBuffSourceAbility, GetTriggerBuffSourceUnit, HAbility, HBuff } from "../../utils/common.js";

export class UnitEventBuffRefreshed extends TriggerUnitEvent<"buffRefreshed"> {
readonly recievedBuff: HBuff;
readonly sourceAbility: HAbility;
readonly sourceUnit: Unit;
constructor() {
super("buffRefreshed");
this.recievedBuff = fromHandleHolderSoft(GetTriggerBuff());
this.sourceAbility = fromHandleHolderSoft(GetTriggerBuffSourceAbility());
this.sourceUnit = fromHandleHolderSoft(GetTriggerBuffSourceUnit());
}
}
14 changes: 14 additions & 0 deletions src/triggerEvents/unit/UnitEventProjectileHit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";
import { GetTriggerProjectile, GetTriggerProjectileSource, HProjectile } from "../../utils/common.js";
import { Unit } from "../../handles/Unit.js";

export class UnitEventProjectileHit extends TriggerUnitEvent<"projectileHit"> {
readonly source:Unit;
readonly projectile:HProjectile;
constructor() {
super("projectileHit");
this.source = fromHandleHolderSoft(GetTriggerProjectileSource());
this.projectile = fromHandleHolderSoft(GetTriggerProjectile());
}
}
14 changes: 14 additions & 0 deletions src/triggerEvents/unit/UnitEventProjectileLaunch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";
import { Widget } from "../../handles/Widget.js";
import { GetTriggerProjectile, GetTriggerProjectileTarget, HProjectile } from "../../utils/common.js";

export class UnitEventProjectileLaunch extends TriggerUnitEvent<"projectileLaunch"> {
readonly target:Widget;
readonly projecitle:HProjectile;
constructor() {
super("projectileLaunch");
this.target = fromHandleHolderSoft(GetTriggerProjectileTarget());
this.projecitle = fromHandleHolderSoft(GetTriggerProjectile());
}
}
27 changes: 27 additions & 0 deletions src/triggerEvents/unit/UnitEventSpellCast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Unit } from "../../handles/Unit.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";
import { GetSpellAbility, GetSpellAbilityId, GetSpellTargetDestructable, GetSpellTargetItem, GetSpellTargetUnit, GetSpellTargetX, GetSpellTargetY, HAbility } from "../../utils/common.js";
import { Destructable } from "../../handles/Destructable.js";
import { Item } from "../../handles/Item.js";

export class UnitEventSpellCast extends TriggerUnitEvent<"spellCast"> {
readonly abilityId: number;
readonly ability: HAbility;
readonly targetX: number;
readonly targetY: number;
// there is no "GetSpellTarget()" for this event that would return widget
readonly targetDestructable: Destructable;
readonly targetItem: Item;
readonly targetUnit: Unit;
constructor() {
super("spellCast");
this.abilityId = GetSpellAbilityId();
this.ability = fromHandleHolderSoft(GetSpellAbility());
this.targetX = GetSpellTargetX();
this.targetY = GetSpellTargetY();
this.targetDestructable = fromHandleHolderSoft(GetSpellTargetDestructable());
this.targetItem = fromHandleHolderSoft(GetSpellTargetItem());
this.targetUnit = fromHandleHolderSoft(GetSpellTargetUnit());
}
}
27 changes: 27 additions & 0 deletions src/triggerEvents/unit/UnitEventSpellChannel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Unit } from "../../handles/Unit.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";
import { GetSpellAbility, GetSpellAbilityId, GetSpellTargetDestructable, GetSpellTargetItem, GetSpellTargetUnit, GetSpellTargetX, GetSpellTargetY, HAbility } from "../../utils/common.js";
import { Destructable } from "../../handles/Destructable.js";
import { Item } from "../../handles/Item.js";

export class UnitEventSpellChannel extends TriggerUnitEvent<"spellChannel"> {
readonly abilityId: number;
readonly ability: HAbility;
readonly targetX: number;
readonly targetY: number;
// there is no "GetSpellTarget()" for this event that would return widget
readonly targetDestructable: Destructable;
readonly targetItem: Item;
readonly targetUnit: Unit;
constructor() {
super("spellChannel");
this.abilityId = GetSpellAbilityId();
this.ability = fromHandleHolderSoft(GetSpellAbility());
this.targetX = GetSpellTargetX();
this.targetY = GetSpellTargetY();
this.targetDestructable = fromHandleHolderSoft(GetSpellTargetDestructable());
this.targetItem = fromHandleHolderSoft(GetSpellTargetItem());
this.targetUnit = fromHandleHolderSoft(GetSpellTargetUnit());
}
}
27 changes: 27 additions & 0 deletions src/triggerEvents/unit/UnitEventSpellEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Unit } from "../../handles/Unit.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";
import { GetSpellAbility, GetSpellAbilityId, GetSpellTargetDestructable, GetSpellTargetItem, GetSpellTargetUnit, GetSpellTargetX, GetSpellTargetY, HAbility } from "../../utils/common.js";
import { Destructable } from "../../handles/Destructable.js";
import { Item } from "../../handles/Item.js";

export class UnitEventSpellEffect extends TriggerUnitEvent<"spellEffect"> {
readonly abilityId: number;
readonly ability: HAbility;
readonly targetX: number;
readonly targetY: number;
// there is no "GetSpellTarget()" for this event that would return widget
readonly targetDestructable: Destructable;
readonly targetItem: Item;
readonly targetUnit: Unit;
constructor() {
super("spellEffect");
this.abilityId = GetSpellAbilityId();
this.ability = fromHandleHolderSoft(GetSpellAbility());
this.targetX = GetSpellTargetX();
this.targetY = GetSpellTargetY();
this.targetDestructable = fromHandleHolderSoft(GetSpellTargetDestructable());
this.targetItem = fromHandleHolderSoft(GetSpellTargetItem());
this.targetUnit = fromHandleHolderSoft(GetSpellTargetUnit());
}
}
27 changes: 27 additions & 0 deletions src/triggerEvents/unit/UnitEventSpellEndcast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Unit } from "../../handles/Unit.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";
import { GetSpellAbility, GetSpellAbilityId, GetSpellTargetDestructable, GetSpellTargetItem, GetSpellTargetUnit, GetSpellTargetX, GetSpellTargetY, HAbility } from "../../utils/common.js";
import { Destructable } from "../../handles/Destructable.js";
import { Item } from "../../handles/Item.js";

export class UnitEventSpellEndcast extends TriggerUnitEvent<"spellEndcast"> {
readonly abilityId: number;
readonly ability: HAbility;
readonly targetX: number;
readonly targetY: number;
// there is no "GetSpellTarget()" for this event that would return widget
readonly targetDestructable: Destructable;
readonly targetItem: Item;
readonly targetUnit: Unit;
constructor() {
super("spellEndcast");
this.abilityId = GetSpellAbilityId();
this.ability = fromHandleHolderSoft(GetSpellAbility());
this.targetX = GetSpellTargetX();
this.targetY = GetSpellTargetY();
this.targetDestructable = fromHandleHolderSoft(GetSpellTargetDestructable());
this.targetItem = fromHandleHolderSoft(GetSpellTargetItem());
this.targetUnit = fromHandleHolderSoft(GetSpellTargetUnit());
}
}
27 changes: 27 additions & 0 deletions src/triggerEvents/unit/UnitEventSpellFinish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Unit } from "../../handles/Unit.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";
import { GetSpellAbility, GetSpellAbilityId, GetSpellTargetDestructable, GetSpellTargetItem, GetSpellTargetUnit, GetSpellTargetX, GetSpellTargetY, HAbility } from "../../utils/common.js";
import { Destructable } from "../../handles/Destructable.js";
import { Item } from "../../handles/Item.js";

export class UnitEventSpellFinish extends TriggerUnitEvent<"spellFinish"> {
readonly abilityId: number;
readonly ability: HAbility;
readonly targetX: number;
readonly targetY: number;
// there is no "GetSpellTarget()" for this event that would return widget
readonly targetDestructable: Destructable;
readonly targetItem: Item;
readonly targetUnit: Unit;
constructor() {
super("spellFinish");
this.abilityId = GetSpellAbilityId();
this.ability = fromHandleHolderSoft(GetSpellAbility());
this.targetX = GetSpellTargetX();
this.targetY = GetSpellTargetY();
this.targetDestructable = fromHandleHolderSoft(GetSpellTargetDestructable());
this.targetItem = fromHandleHolderSoft(GetSpellTargetItem());
this.targetUnit = fromHandleHolderSoft(GetSpellTargetUnit());
}
}
Loading

0 comments on commit 90af9c8

Please sign in to comment.