player.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. 'use strict'
  2. const NOCTAN = new Set([1206, 1210, 1230, 1300, 1301, 1302, 1303, 81212, 201225]),
  3. HOOK_LAST = { order: 100, filter: { fake: null } }
  4. class SPPlayer {
  5. reset() {
  6. Object.assign(this, {
  7. // Session
  8. gameId: -1n,
  9. templateId: -1,
  10. race: -1,
  11. job: -1,
  12. kdId: 0,
  13. // Status
  14. mounted: false,
  15. // Combat stats
  16. attackSpeed: 1,
  17. stamina: 0,
  18. // Passivity stuff
  19. crests: new Set(), // Crests
  20. epPerks: new Set(), // EP
  21. skillPolishing: new Set(), // Skill Polishing (Talyphs)
  22. // Equipment / Inventory
  23. hasWeapon: false,
  24. hasNocTan: false,
  25. itemPassives: []
  26. })
  27. }
  28. constructor(mod) {
  29. this.reset()
  30. mod.hook('S_LOGIN', mod.majorPatchVersion >= 86 ? 14 : 13, HOOK_LAST, event => {
  31. this.reset()
  32. Object.assign(this, {
  33. gameId: event.gameId,
  34. templateId: event.templateId,
  35. race: Math.floor(event.templateId / 100) % 100 - 1,
  36. job: event.templateId % 100 - 1,
  37. })
  38. this.kdId = this.templateId === 10911 ? 1101102 : (this.templateId * 100 + 2)
  39. })
  40. mod.hook('S_RETURN_TO_LOBBY', 'raw', { order: 100, filter: { fake: false } }, () => { this.reset() })
  41. // Status
  42. mod.hook('S_MOUNT_VEHICLE', 2, event => { if (event.gameId === this.gameId) this.mounted = true })
  43. mod.hook('S_UNMOUNT_VEHICLE', 2, event => { if (event.gameId === this.gameId) this.mounted = false })
  44. // Combat stats
  45. mod.hook('S_PLAYER_STAT_UPDATE', mod.majorPatchVersion >= 93 ? 14 : 13, HOOK_LAST, event => {
  46. Object.assign(this, {
  47. // Newer classes use a different speed algorithm
  48. attackSpeed: (event.attackSpeed + event.attackSpeedBonus) / (this.job >= 8 ? 100 : event.attackSpeed),
  49. stamina: event.stamina
  50. })
  51. })
  52. mod.hook('S_PLAYER_CHANGE_STAMINA', 1, HOOK_LAST, event => { this.stamina = event.current })
  53. // Crests
  54. mod.game.initialize('glyphs');
  55. mod.game.glyphs.on('change', () => {
  56. this.crests = new Set(mod.game.glyphs.enabled)
  57. })
  58. // EP
  59. mod.game.initialize('talents');
  60. mod.game.talents.on('change_perks', () => {
  61. this.epPerks.clear()
  62. for (let [id, level] of Object.entries(mod.game.talents.perks)) this.epPerks.add(`${id},${level}`)
  63. })
  64. // Skill Polishing
  65. mod.hook('S_RP_SKILL_POLISHING_LIST', 1, event => {
  66. this.skillPolishing.clear()
  67. // Skill Advancement
  68. for (let sp of event.levelEffects)
  69. this.skillPolishing.add(sp.id)
  70. // Skill Optimization
  71. for (let sp of event.optionEffects)
  72. if (sp.active)
  73. this.skillPolishing.add(sp.id)
  74. })
  75. // Equipment / Inventory
  76. mod.game.initialize('inventory');
  77. mod.game.initialize("contract");
  78. mod.game.inventory.on('update', () => {
  79. this.hasWeapon = mod.game.inventory.weaponEquipped
  80. this.itemPassives = mod.game.inventory.equipmentPassivities
  81. //this.hasNocTan = !!mod.game.inventory.findInBagOrPockets(NOCTAN)
  82. })
  83. }
  84. }
  85. module.exports = SPPlayer