Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Himyu committed Feb 1, 2022
0 parents commit 72fb04c
Show file tree
Hide file tree
Showing 20 changed files with 1,445 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
dist/
.idea/
core-build/
cache/
.DS_Store
296 changes: 296 additions & 0 deletions controller/InGameState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
import type { PluginContext } from 'league-prod-toolkit/core/modules/Module'
import { AllGameData, Player, Event } from '../types/AllGameData'
import { Config } from '../types/Config'
import { ItemEpicness } from '../types/Items'
import { InGameState as InGameStateType } from '../types/InGameState'

export class InGameState {

public gameState : InGameStateType
public gameData : any[] = []
public itemEpicness : number[]

public actions : Array<(allGameData : AllGameData, i: number) => void> = []

constructor (
private namespace: string,
private ctx: PluginContext,
private config: Config,
private statics: any
) {
this.itemEpicness = this.config.items.map(i => ItemEpicness[i])

this.gameState = {
towers : {
100 : {
L : {},
C : {},
R : {}
},
200 : {
L : {},
C : {},
R : {}
},
},
showInhibitors : null,
inhibitors : {
100 : {
L1 : {
alive : true,
respawnAt : 0,
respawnIn : 0,
percent : 0
},
C1 : {
alive : true,
respawnAt : 0,
respawnIn : 0,
percent : 0
},
R1 : {
alive : true,
respawnAt : 0,
respawnIn : 0,
percent : 0
}
},
200 : {
L1 : {
alive : true,
respawnAt : 0,
respawnIn : 0,
percent : 0
},
C1 : {
alive : true,
respawnAt : 0,
respawnIn : 0,
percent : 0
},
R1 : {
alive : true,
respawnAt : 0,
respawnIn : 0,
percent : 0
}
},
},
player : {
0 : {
level : 0,
items : new Set(),
},
1 : {
level : 0,
items : new Set(),
},
2 : {
level : 0,
items : new Set(),
},
3 : {
level : 0,
items : new Set(),
},
4 : {
level : 0,
items : new Set(),
},
5 : {
level : 0,
items : new Set(),
},
6 : {
level : 0,
items : new Set(),
},
7 : {
level : 0,
items : new Set(),
},
8 : {
level : 0,
items : new Set(),
},
9 : {
level : 0,
items : new Set(),
}
}
}

this.ctx.LPTE.emit({
meta: {
namespace: this.namespace,
type: 'update',
version: 1
},
state : this.gameState
})
}

public handelData (allGameData: AllGameData) : void {
if (this.gameData.length > 0) {
const previousGameData = this.gameData[this.gameData.length -1]
this.checkPlayerUpdate(allGameData)
this.checkEventUpdate(allGameData, previousGameData)

this.actions.forEach((func, i) => {
func(allGameData, i)
})
}

this.gameData.push(allGameData)
}

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

allGameData.allPlayers.forEach((player, i) => {
this.checkItemUpdate(player, i)
this.checkLevelUpdate(player, i)
})
}

private checkLevelUpdate (currentPlayerState: Player, id: number) {
if (currentPlayerState.level === this.gameState.player[id].level) return
if (!this.config.level.includes(currentPlayerState.level.toString())) return

this.gameState.player[id].level = currentPlayerState.level

this.ctx.LPTE.emit({
meta: {
type: 'level-update',
namespace: this.namespace,
version: 1
},
team: currentPlayerState.team === "ORDER" ? 100 : 200,
player: id,
level: currentPlayerState.level
})
}

private checkItemUpdate (currentPlayerState: Player, id: number) {
const previousItems = this.gameState.player[id].items

for (const item of currentPlayerState.items) {

const itemID = item.itemID
if (previousItems.has(itemID)) continue

const itemBinFind = this.statics.itemBin.find((i: any) => i.itemID === itemID)
if (itemBinFind === undefined) continue

if (!this.itemEpicness.includes(itemBinFind.epicness)) continue

this.gameState.player[id].items.add(itemID)

this.ctx.LPTE.emit({
meta: {
type: 'item-update',
namespace: this.namespace,
version: 1
},
team: currentPlayerState.team === "ORDER" ? 100 : 200,
player: id,
item: itemID
})
}
}

// ---

private checkEventUpdate (allGameData: AllGameData, previousGameData: AllGameData) {
if (allGameData.events.Events.length === 0 || previousGameData.events.Events.length === 0) return

const newEvents = allGameData.events.Events.slice(previousGameData.events.Events.length)

newEvents.forEach(event => {
if (event.EventName === "InhibKilled") {
this.handleInhibEvent(event)
} else if (event.EventName === "TurretKilled") {
this.handleTowerEvent(event)
}
})
}

private handleInhibEvent (event: Event) {
console.log(event)
const split = event.InhibKilled.split('_') as string[]
const team = split[1] === 'T1' ? 100 : 200
const lane = split[2] as 'L1' | 'C1' | 'R1'
const respawnAt = Math.round(event.EventTime) + (60 * 5)

console.log(this.gameState.inhibitors[team][lane].alive)

if (!this.gameState.inhibitors[team][lane].alive) return

this.gameState.inhibitors[team][lane] = {
alive : false,
respawnAt : respawnAt,
respawnIn : (60 * 5),
percent : 100
}

this.actions.push((allGameData, i) => {
const gameState = allGameData.gameData
const diff = respawnAt - Math.round(gameState.gameTime)
const percent = Math.round((diff * 100) / (60 * 5))

this.gameState.inhibitors[team][lane] = {
alive : false,
respawnAt : respawnAt,
respawnIn : diff,
percent : 100
}

this.ctx.LPTE.emit({
meta: {
namespace: this.namespace,
type: 'inhib-update',
version: 1
},
team,
lane,
percent,
respawnIn: diff
})

if (diff <= 0) {
this.gameState.inhibitors[team][lane] = {
alive : true,
respawnAt : 0,
respawnIn : 0,
percent : 0
}
this.actions.splice(i, 1)
}
})
}

private handleTowerEvent (event: Event) {
console.log(event)
const split = event.TurretKilled.split('_') as string[]
const team = split[1] === 'T1' ? 100 : 200
const lane = split[2] as 'L' | 'C' | 'R'
const turret = split[3]

console.log(this.gameState.towers[team][lane][turret])
if (this.gameState.towers[team][lane][turret] === false) return

this.gameState.towers[team][lane][turret] = false

this.ctx.LPTE.emit({
meta: {
namespace: this.namespace,
type: 'tower-update',
version: 1
},
team,
lane,
turret
})
}
}
56 changes: 56 additions & 0 deletions frontend/frontend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
$('#ingame-embed').val(`${location.href}/gfx/ingmae.html`);

const namespace = 'league-in-game';

$('#settings').on('submit', (e) => {
e.preventDefault()

LPTE.emit({
meta: {
namespace,
type: 'set-settings',
version: 1
},
items: $('#items').val(),
level: $('#level').val()
})
})

function showInhibs (side) {
LPTE.emit({
meta: {
namespace,
type: 'show-inhibs',
version: 1
},
side
})
}

function hideInhibs () {
LPTE.emit({
meta: {
namespace,
type: 'hide-inhibs',
version: 1
}
})
}

function initSettings (settings) {
$('#items').val(settings.items)
$('#level').val(settings.level)
}

LPTE.onready(async () => {
const settings = await LPTE.request({
meta: {
namespace,
type: 'get-settings',
version: 1
}
})
initSettings(settings)

LPTE.on(namespace, 'set-settings', initSettings)
})
1 change: 1 addition & 0 deletions frontend/gfx/img/bottom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/gfx/img/inhibbadge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/gfx/img/mid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/gfx/img/top.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/gfx/img/turret.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 72fb04c

Please sign in to comment.