player.js 2.8 KB

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