| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 'use strict'
- const NOCTAN = new Set([1206, 1210, 1230, 1300, 1301, 1302, 1303, 81212, 201225]),
- HOOK_LAST = { order: 100, filter: { fake: null } }
- class SPPlayer {
- reset() {
- Object.assign(this, {
- // Session
- gameId: -1n,
- templateId: -1,
- race: -1,
- job: -1,
- kdId: 0,
- // Status
- mounted: false,
- // Combat stats
- attackSpeed: 1,
- stamina: 0,
- // Passivity stuff
- crests: new Set(), // Crests
- epPerks: new Set(), // EP
- skillPolishing: new Set(), // Skill Polishing (Talyphs)
- // Equipment / Inventory
- hasWeapon: false,
- hasNocTan: false,
- itemPassives: []
- })
- }
- constructor(mod) {
- this.reset()
- mod.hook('S_LOGIN', mod.majorPatchVersion >= 86 ? 14 : 13, HOOK_LAST, event => {
- this.reset()
- Object.assign(this, {
- gameId: event.gameId,
- templateId: event.templateId,
- race: Math.floor(event.templateId / 100) % 100 - 1,
- job: event.templateId % 100 - 1,
- })
- this.kdId = this.templateId === 10911 ? 1101102 : (this.templateId * 100 + 2)
- })
- mod.hook('S_RETURN_TO_LOBBY', 'raw', { order: 100, filter: { fake: false } }, () => { this.reset() })
- // Status
- mod.hook('S_MOUNT_VEHICLE', 2, event => { if (event.gameId === this.gameId) this.mounted = true })
- mod.hook('S_UNMOUNT_VEHICLE', 2, event => { if (event.gameId === this.gameId) this.mounted = false })
- // Combat stats
- mod.hook('S_PLAYER_STAT_UPDATE', mod.majorPatchVersion >= 93 ? 14 : 13, HOOK_LAST, event => {
- Object.assign(this, {
- // Newer classes use a different speed algorithm
- attackSpeed: (event.attackSpeed + event.attackSpeedBonus) / (this.job >= 8 ? 100 : event.attackSpeed),
- stamina: event.stamina
- })
- })
- mod.hook('S_PLAYER_CHANGE_STAMINA', 1, HOOK_LAST, event => { this.stamina = event.current })
- // Crests
- mod.game.initialize('glyphs');
- mod.game.glyphs.on('change', () => {
- this.crests = new Set(mod.game.glyphs.enabled)
- })
- // EP
- mod.game.initialize('talents');
- mod.game.talents.on('change_perks', () => {
- this.epPerks.clear()
- for (let [id, level] of Object.entries(mod.game.talents.perks)) this.epPerks.add(`${id},${level}`)
- })
- // Skill Polishing
- mod.hook('S_RP_SKILL_POLISHING_LIST', 1, event => {
- this.skillPolishing.clear()
- // Skill Advancement
- for (let sp of event.levelEffects)
- this.skillPolishing.add(sp.id)
- // Skill Optimization
- for (let sp of event.optionEffects)
- if (sp.active)
- this.skillPolishing.add(sp.id)
- })
- // Equipment / Inventory
- mod.game.initialize('inventory');
- mod.game.initialize("contract");
- mod.game.inventory.on('update', () => {
- this.hasWeapon = mod.game.inventory.weaponEquipped
- this.itemPassives = mod.game.inventory.equipmentPassivities
- //this.hasNocTan = !!mod.game.inventory.findInBagOrPockets(NOCTAN)
- })
- }
- }
- module.exports = SPPlayer
|