Skip to content

Commit

Permalink
add event handler for elder drake fix for #546
Browse files Browse the repository at this point in the history
  • Loading branch information
Himyu committed Nov 30, 2023
1 parent 58335e0 commit cd8f613
Showing 1 changed file with 135 additions and 0 deletions.
135 changes: 135 additions & 0 deletions controller/InGameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ export class InGameState {
event.eventname === EventType.DragonKill &&
this.config.events?.includes('Dragons')
) {
if (event.other === MobType.ElderDragon) {
this.elderKill(event)
}

this.ctx.LPTE.emit({
meta: {
namespace: this.namespace,
Expand Down Expand Up @@ -503,6 +507,137 @@ export class InGameState {
})
}

private elderKill(event: InGameEvent): void {
const cAllGameData = this.gameData[this.gameData.length - 1]

const team = event.sourceTeam === TeamType.Order ? 100 : 200
const time = Math.round(cAllGameData?.gameData?.gameTime || 0)
const type = 'Dragon'

this.ctx.LPTE.emit({
meta: {
namespace: this.namespace,
type: 'event',
version: 1
},
name: 'Elder',
type,
team,
time
})

if (!this.config.ppTimer) return

const respawnAt = time + 60 * 3

const data = {
time,
ongoing: true,
goldDiff: 1500,
goldBaseBlue: this.gameState.gold[100],
goldBaseRed: this.gameState.gold[200],
alive: cAllGameData.allPlayers
.filter(
(p) =>
!p.isDead &&
(team === 100 ? p.team === 'ORDER' : p.team === 'CHAOS')
)
.map((p) => p.summonerName),
dead: cAllGameData.allPlayers
.filter(
(p) =>
p.isDead && (team === 100 ? p.team === 'ORDER' : p.team === 'CHAOS')
)
.map((p) => p.summonerName),
team,
respawnAt: respawnAt,
respawnIn: 60 * 3,
percent: 100
}

this.ctx.LPTE.emit({
meta: {
namespace: this.namespace,
type: 'pp-update',
version: 1
},
type,
team,
goldDiff: data.goldDiff,
ongoing: data.ongoing,
percent: data.percent,
respawnIn: data.respawnIn,
respawnAt: data.respawnAt
})

this.actions.set(type + '-' + randomUUID(), (allGameData, i) => {
const gameState = allGameData.gameData
const diff = respawnAt - Math.round(gameState.gameTime)
const percent = Math.round((diff * 100) / (60 * 3))

const goldDifBlue = this.gameState.gold[100] - data.goldBaseBlue
const goldDifRed = this.gameState.gold[200] - data.goldBaseRed

const goldDiff = team === 100 ? 1500 + goldDifBlue - goldDifRed : 1500 + goldDifRed - goldDifBlue

data.alive = allGameData.allPlayers
.filter(
(p) =>
!p.isDead &&
(team === 100 ? p.team === 'ORDER' : p.team === 'CHAOS') &&
!data.dead.includes(p.summonerName)
)
.map((p) => p.summonerName)
data.dead = [
...data.dead,
...allGameData.allPlayers
.filter(
(p) =>
p.isDead &&
(team === 100 ? p.team === 'ORDER' : p.team === 'CHAOS')
)
.map((p) => p.summonerName)
]

this.ctx.LPTE.emit({
meta: {
namespace: this.namespace,
type: 'pp-update',
version: 1
},
type: 'Dragon',
team,
goldDiff,
ongoing: data.ongoing,
percent,
respawnIn: diff
})

if (
diff <= 0 ||
data.alive.length <= 0 ||
time > gameState.gameTime + this.config.delay / 1000
) {
data.ongoing = false
this.ctx.LPTE.emit({
meta: {
namespace: this.namespace,
type: 'pp-update',
version: 1
},
type: 'Dragon',
team,
goldDiff,
ongoing: data.ongoing,
percent: 100,
respawnIn: 60 * 3
})

this.actions.delete(i)
}
})
}

private checkPlayerUpdate(allGameData: AllGameData) {
if (allGameData.allPlayers.length === 0) return

Expand Down

0 comments on commit cd8f613

Please sign in to comment.