Skip to content

Commit

Permalink
see desc (CPlayerCustomDataChanged)
Browse files Browse the repository at this point in the history
- Fix destroy items
- Fix get total items
  • Loading branch information
Sicdex committed Nov 24, 2024
1 parent 43046c7 commit 96a9c45
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions wrapper/Managers/Monitors/PlayerCustomDataChanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PlayerCustomData } from "../../Objects/DataBook/PlayerCustomData"
import { EntityManager } from "../EntityManager"
import { EventsSDK } from "../EventsSDK"

new (class CPlayerDataCustomChanged {
new (class CPlayerCustomDataChanged {
private readonly playersItems = new Map<number, Map<number, number>>()

constructor() {
Expand Down Expand Up @@ -112,7 +112,7 @@ new (class CPlayerDataCustomChanged {
this.playersItems.delete(playerID)
return
}
const totalItems = this.getTotalItems(unit)
const totalItems = this.getTotalItems(unit, playerID)
const oldItems = this.playersItems.get(playerID)
if (oldItems === undefined) {
this.playersItems.set(playerID, totalItems)
Expand Down Expand Up @@ -169,15 +169,11 @@ new (class CPlayerDataCustomChanged {
if (!(owner instanceof Unit) || this.isIllusion(owner) || owner.IsClone) {
return
}
let playerID = owner.PlayerID
if (playerID === -1) {
playerID = owner.OwnerPlayerID // example: courier
}
const playerData = PlayerCustomData.get(owner.PlayerID)
const playerData = PlayerCustomData.get(item.PlayerOwnerID)
if (playerData === undefined || !playerData.IsValid) {
return
}
const oldItems = this.playersItems.get(playerID)
const oldItems = this.playersItems.get(item.PlayerOwnerID)
if (oldItems !== undefined) {
oldItems.delete(item.Index)
this.updateGoldByItems(playerData, oldItems)
Expand All @@ -190,19 +186,22 @@ new (class CPlayerDataCustomChanged {
playerData.ItemsGold = gold
}

private getTotalItems(unit: Unit) {
private getTotalItems(unit: Unit, playerID: number) {
const arr = unit.TotalItems
const newMap = new Map<number, number>()
for (let i = arr.length - 1; i > -1; i--) {
const item = arr[i]
if (item !== undefined && item.Cost > 0) {
if (!item?.IsValid || item.Cost <= 0) {
continue
}
if (item.PlayerOwnerID === playerID) {
newMap.set(item.Index, item.Cost)
}
}
return newMap
}

protected isIllusion(entity: Unit) {
private isIllusion(entity: Unit) {
return entity.IsIllusion || entity.IsStrongIllusion
}
})()

0 comments on commit 96a9c45

Please sign in to comment.