Guest User

Untitled

a guest
Sep 12th, 2019
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. 1~3 => Element Type
  3. 4~6 => Total Time (segundos - 20 h)
  4. 7~9 => Time Passed (seconds)
  5. ]]
  6.  
  7. --[[ Icon List --
  8. 0 = NONE
  9. 1 ~ 3 = Critical
  10. 4 ~ 6 = Death
  11. 7 ~ 9 = Earth
  12. 10 ~ 12 = Energy
  13. 13 ~ 15 = Fire
  14. 16 ~ 18 = Holy
  15. 19 ~ 21 = Ice
  16. 22 ~ 24 = Fire (grey | not used)
  17. 25 ~ 27 = Shielding (grey | not used)
  18. 28 ~ 30 = Reduction Earth
  19. 31 ~ 33 = Reduction Energy
  20. 34 ~ 36 = Reduction Fire
  21. 37 ~ 39 = Reduction Holy
  22. 40 ~ 42 = Reduction Ice
  23. 43 ~ 45 = Shielding (white | not used)
  24. 46 ~ 48 = Life Leech
  25. 49 ~ 51 = Mana Leech
  26. 52 ~ 54 = Axe Fighting
  27. 55 ~ 57 = Club Fighting
  28. 58 ~ 60 = Distance Fighting
  29. 61 ~ 63 = Fist Fighting
  30. 64 ~ 66 = Magic Level
  31. 67 ~ 69 = Shielding Fighting
  32. 70 ~ 72 = Sword Fighting
  33. 73 ~ 75 = Speed
  34. ]]
  35.  
  36. ImbuingSystem = {
  37. Developer = "Charles (Cjaker)",
  38. Version = "1.0",
  39. LastUpdate = "24/05/2017 - 03:50 (AM)"
  40. }
  41.  
  42. local Imbuements = {
  43. {
  44. Name = "Scorch",
  45. Category = "Elemental Damage (Fire)",
  46. Type = "firedamage",
  47. IconID = 13,
  48. Description = "Converts % of the physical damage to fire damage.",
  49. Levels = {"Basic", "Intricate", "Powerful"},
  50. LevelsPercent = {10, 25, 50},
  51. Weapons = {"axe", "club", "sword"},
  52. Items = {{10553, 25}, {5920, 5}, {5954, 5}}
  53. },
  54. {
  55. Name = "Venom",
  56. Category = "Elemental Damage (Earth)",
  57. Type = "earthdamage",
  58. IconID = 7,
  59. Description = "Converts % of the physical damage to earth damage.",
  60. Levels = {"Basic", "Intricate", "Powerful"},
  61. LevelsPercent = {10, 25, 50},
  62. Weapons = {"axe", "club", "sword"},
  63. Items = {{10603, 25}, {10557, 5}, {23565, 5}}
  64. },
  65. {
  66. Name = "Frost",
  67. Category = "Elemental Damage (Ice)",
  68. Type = "icedamage",
  69. IconID = 19,
  70. Description = "Converts % of the physical damage to ice damage.",
  71. Levels = {"Basic", "Intricate", "Powerful"},
  72. LevelsPercent = {10, 25, 50},
  73. Weapons = {"axe", "club", "sword"},
  74. Items = {{10567, 25}, {10578, 20}, {24170, 1}}
  75. },
  76. {
  77. Name = "Electrify",
  78. Category = "Elemental Damage (Energy)",
  79. Type = "energydamage",
  80. IconID = 10,
  81. Description = "Converts % of the physical damage to energy damage.",
  82. Levels = {"Basic", "Intricate", "Powerful"},
  83. LevelsPercent = {10, 25, 50},
  84. Weapons = {"axe", "club", "sword"},
  85. Items = {{21310, 25}, {24631, 5}, {26164, 1}}
  86. },
  87. {
  88. Name = "Reap",
  89. Category = "Elemental Damage (Death)",
  90. Type = "deathdamage",
  91. IconID = 4,
  92. Description = "Converts % of the physical damage to death damage.",
  93. Levels = {"Basic", "Intricate", "Powerful"},
  94. LevelsPercent = {10, 25, 50},
  95. Weapons = {"axe", "club", "sword"},
  96. Items = {{12440, 25}, {10564, 20}, {11337, 5}}
  97. },
  98. {
  99. Name = "Vampirism",
  100. Category = "Life Leech",
  101. Type = "hitpointsleech",
  102. IconID = 46,
  103. Description = "converts % of damage to HP with a chance of 100%.",
  104. Levels = {"Basic", "Intricate", "Powerful"},
  105. LevelsPercent = {5, 10, 25},
  106. Weapons = {"axe", "club", "sword", "wand", "rod", "bow", "armor"},
  107. Items = {{10602, 25}, {10550, 15}, {10580, 5}}
  108. },
  109. {
  110. Name = "Void",
  111. Category = "Mana Leech",
  112. Type = "manapointsleech",
  113. IconID = 49,
  114. Description = "converts % of damage to MP with a chance of 100%.",
  115. Levels = {"Basic", "Intricate", "Powerful"},
  116. LevelsPercent = {3, 5, 8},
  117. Weapons = {"axe", "club", "sword", "wand", "rod", "bow", "helmet"},
  118. Items = {{12448, 25}, {22534, 25}, {25386, 5}}
  119. },
  120. {
  121. Name = "Strike",
  122. Category = "Critical Hit",
  123. Type = "criticaldamage",
  124. IconID = 1,
  125. Description = "raises crit hit damage by % and crit hit chance by 10%.",
  126. Levels = {"Basic", "Intricate", "Powerful"},
  127. LevelsPercent = {15, 25, 50},
  128. Weapons = {"axe", "club", "sword", "bow"},
  129. Items = {{12400, 20}, {11228, 25}, {25384, 5}}
  130. },
  131. {
  132. Name = "Lich Shroud",
  133. Category = "Death Damage",
  134. Type = "absorbPercentDeath",
  135. IconID = 25,
  136. Description = "reduces death damage by %.",
  137. Levels = {"Basic", "Intricate", "Powerful"},
  138. LevelsPercent = {3, 8, 15},
  139. Weapons = {"armor", "shield"},
  140. Items = {{12422, 25}, {24663, 20}, {10577, 5}}
  141. },
  142. {
  143. Name = "Snake Skin",
  144. Category = "Eart Damage",
  145. Type = "absorbPercentEarth",
  146. IconID = 28,
  147. Description = "reduces earth damage by %.",
  148. Levels = {"Basic", "Intricate", "Powerful"},
  149. LevelsPercent = {3, 8, 15},
  150. Weapons = {"armor", "shield"},
  151. Items = {{20103, 25}, {10611, 20}, {12658, 10}}
  152. },
  153. {
  154. Name = "Hide Dragon",
  155. Category = "Fire Damage",
  156. Type = "absorbPercentFire",
  157. IconID = 34,
  158. Description = "reduces fire damage by %.",
  159. Levels = {"Basic", "Intricate", "Powerful"},
  160. LevelsPercent = {3, 8, 15},
  161. Weapons = {"armor", "shield"},
  162. Items = {{5877, 25}, {18425, 10}, {12614, 5}}
  163. },
  164. {
  165. Name = "Quara Scale",
  166. Category = "Ice Damage",
  167. Type = "absorbPercentIce",
  168. IconID = 40,
  169. Description = "reduces ice damage by %.",
  170. Levels = {"Basic", "Intricate", "Powerful"},
  171. LevelsPercent = {3, 8, 15},
  172. Weapons = {"armor", "shield"},
  173. Items = {{11212, 25}, {11224, 15}, {15425, 10}}
  174. },
  175. {
  176. Name = "Cloud Fabric",
  177. Category = "Energy Damage",
  178. Type = "absorbPercentEnergy",
  179. IconID = 31,
  180. Description = "reduces energy damage by %.",
  181. Levels = {"Basic", "Intricate", "Powerful"},
  182. LevelsPercent = {3, 8, 15},
  183. Weapons = {"armor", "shield"},
  184. Items = {{10561, 25}, {15482, 15}, {10582, 10}}
  185. },
  186. {
  187. Name = "Demon Presence",
  188. Category = "Holy Damage",
  189. Type = "absorbPercentHoly",
  190. IconID = 37,
  191. Description = "reduces holy damage by %.",
  192. Levels = {"Basic", "Intricate", "Powerful"},
  193. LevelsPercent = {3, 8, 15},
  194. Weapons = {"armor", "shield"},
  195. Items = {{10556, 25}, {10555, 25}, {11221, 20}}
  196. },
  197. {
  198. Name = "Swiftness",
  199. Category = "Increase Speed",
  200. Type = "speed",
  201. IconID = 73,
  202. Description = "raises walking speed by %.",
  203. Levels = {"Basic", "Intricate", "Powerful"},
  204. LevelsPercent = {10, 15, 20},
  205. Weapons = {"boots"},
  206. Items = {{19738, 15}, {11219, 25}, {15484, 20}}
  207. },
  208. {
  209. Name = "Chop",
  210. Category = "Increase Axe Fighting",
  211. Type = "skillAxe",
  212. IconID = 52,
  213. Description = "raises axe fighting skill by %.",
  214. Levels = {"Basic", "Intricate", "Powerful"},
  215. LevelsPercent = {1, 2, 4},
  216. Weapons = {"axe", "helmet"},
  217. Items = {{11113, 20}, {12403, 25}, {23571, 20}}
  218. },
  219. {
  220. Name = "Slash",
  221. Category = "Increase Sword Fighting",
  222. Type = "skillSword",
  223. IconID = 70,
  224. Description = "raises sword fighting skill by %.",
  225. Levels = {"Basic", "Intricate", "Powerful"},
  226. LevelsPercent = {1, 2, 4},
  227. Weapons = {"sword", "helmet"},
  228. Items = {{10608, 25}, {23573, 25}, {10571, 5}}
  229. },
  230. {
  231. Name = "Bash",
  232. Category = "Increase Club Fighting",
  233. Type = "skillClub",
  234. IconID = 52,
  235. Description = "raises club fighting skill by %.",
  236. Levels = {"Basic", "Intricate", "Powerful"},
  237. LevelsPercent = {1, 2, 4},
  238. Weapons = {"club", "helmet"},
  239. Items = {{10574, 20}, {24845, 15}, {11322, 10}}
  240. },
  241. {
  242. Name = "Precision",
  243. Category = "Increase Distance Fighting",
  244. Type = "skillDist",
  245. IconID = 58,
  246. Description = "raises distance fighting skill by %.",
  247. Levels = {"Basic", "Intricate", "Powerful"},
  248. LevelsPercent = {1, 2, 4},
  249. Weapons = {"bow", "helmet"},
  250. Items = {{12420, 25}, {21311, 20}, {11215, 10}}
  251. },
  252. {
  253. Name = "Blockade",
  254. Category = "Increase Shielding",
  255. Type = "skillShield",
  256. IconID = 67,
  257. Description = "raises shielding skill by %.",
  258. Levels = {"Basic", "Intricate", "Powerful"},
  259. LevelsPercent = {1, 2, 4},
  260. Weapons = {"shield", "helmet"},
  261. Items = {{10558, 20}, {12659, 25}, {22533, 25}}
  262. },
  263. {
  264. Name = "Epiphany",
  265. Category = "Increase Magic Level",
  266. Type = "magiclevelpoints",
  267. IconID = 64,
  268. Description = "raises magic level by %.",
  269. Levels = {"Basic", "Intricate", "Powerful"},
  270. LevelsPercent = {1, 2, 4},
  271. Weapons = {"wand", "rod", "helmetmage"},
  272. Items = {{10552, 25}, {12408, 15}, {11226, 15}}
  273. },
  274. {
  275. Name = "Featherweight",
  276. Category = "Increase Capacity",
  277. Type = "capacity",
  278. IconID = 64,
  279. Description = "raises capacity by %.",
  280. Levels = {"Basic", "Intricate", "Powerful"},
  281. LevelsPercent = {3, 8, 15},
  282. Weapons = {"backpack"},
  283. Items = {{28998, 25}, {29006, 10}, {22539, 5}}
  284. }
  285. }
  286.  
  287. local Weapons = {
  288. ["armor"] = {21692, 2500, 2656, 2464, 2487, 2494, 15407, 2492, 2503, 12607, 2505, 2466, 23538, 10296, 2476, 3968, 2472, 7463, 8888, 23537, 2486, 15406, 8891, 18404},
  289. ["shield"] = {2528, 2537, 2518, 15491, 2534, 2535, 2536, 2542, 2539, 2519, 2520, 25382, 25414, 15411, 2516, 2514, 2522, 2533, 2531, 21707, 10289, 6433, 6391, 7460, 2524, 15413, 21697, 3974, 12644, 10297, 10294, 2509, 10364, 15453, 25411, 2217, 2175, 8900, 8901, 29003, 22422, 22423, 22424},
  290. ["boots"] = {9931, 3982, 15410, 2646, 24637, 5462, 18406, 2645, 25412, 21708},
  291. ["helmet"] = {2499, 2139, 3972, 2458, 2491, 2497, 2493, 2502, 12645, 7458, 2471, 10298, 10299, 20132, 2662, 10291, 2498, 24848, 5741, 25410, 2475, 11302},
  292. ["helmetmage"] = {10016, 2323, 12630, 11368, 8820, 10570, 9778},
  293. ["bow"] = {8855, 7438, 15643, 21696, 10295, 18454, 25522, 8857, 8854, 22416, 22417, 22418, 8850, 8851, 8852, 8853, 2455, 8849, 25523, 16111, 21690, 22419, 22420, 22421, 25885, 25886, 25943, 25947, 25983, 25987, 29058},
  294. ["backpack"] = {1988, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 3940, 5801, 3960, 5926, 5949, 7342, 9774, 10518, 10519, 10521, 10522, 11119, 11241, 11243, 11244, 11263, 15645, 15646, 16007, 18393, 18394, 21475, 22696, 23666, 23816, 24740, 26181, 27061, 27063},
  295. ["wand"] = {8920, 8921, 8922, 2191, 29006, 29004, 25887, 25951, 25991},
  296. ["rod"] = {8910, 8911, 24839, 29006, 29004, 25888, 25955, 30725, 25995, 31985},
  297. ["axe"] = {2429, 2454, 2426, 2427, 2414, 2415, 2443, 7380, 7389, 11323, 7455, 2447, 7412, 8926, 7419, 7453, 2430, 2435, 3962, 15451, 7434, 7435, 6553, 15492, 7456, 18451, 2431, 8924, 25931, 11305, 25383, 22404, 22405, 22407, 22408, 22409, 25881, 25882, 25927, 25931, 25967, 25971},
  298. ["club"] = {2391, 2423, 7415, 2445, 7424, 2452, 2444, 7426, 7414, 7452, 7429, 7421, 15414, 7410, 15647, 20093, 7430, 7431, 23543, 2453, 8929, 12648, 7423, 2436, 2424, 7451, 7437, 2421, 8928, 25418, 22410, 22411, 22412, 22413, 22414, 22415, 25883, 25884, 25935, 25939},
  299. ["sword"] = {7407, 2393, 2383, 7382, 7383, 7384, 7385, 7403, 2413, 7405, 7406, 7391, 7392, 11309, 12613, 7417, 2376, 2400, 7404, 7402, 12649, 2438, 8930, 2451, 11395, 2407, 7416, 11307, 7418, 6528, 7408, 8931, 22398, 22399, 22400, 22401, 22402, 22403, 25879, 25880, 25919, 25923, 25959, 25963}
  300. }
  301.  
  302. local ImbuingInfo = {
  303. [1] = {Price = 5000, Protection = 10000, Percent = 90},
  304. [2] = {Price = 25000, Protection = 30000, Percent = 70},
  305. [3] = {Price = 100000, Protection = 50000, Percent = 50}
  306. }
  307.  
  308. local imbuingShrineIds = {
  309. 27728, 27729, 27850, 27851
  310. }
  311.  
  312. local ImbuementElements = {
  313. "firedamage", "earthdamage", "energydamage", "deathdamage", "icedamage"
  314. }
  315.  
  316. local ErrorMessages = {
  317. MESSAGEDIALOG_IMBUEMENT_ERROR = 1,
  318. MESSAGEDIALOG_IMBUEMENT_ROLL_FAILED = 2,
  319. MESSAGEDIALOG_IMBUING_STATION_NOT_FOUND = 3,
  320. MESSAGEDIALOG_CLEARING_CHARM_SUCCESS = 10,
  321. MESSAGEDIALOG_CLEARING_CHARM_ERROR = 11
  322. }
  323.  
  324. local ClientPackets = {
  325. ApplyImbuement = 0xD5,
  326. ClearImbuement = 0xD6
  327. }
  328.  
  329. function onRecvbyte(player, msg, byte)
  330. if (byte == ClientPackets.ApplyImbuement) then
  331. -- Apply Imbuement
  332. player:applyImbuement(msg)
  333. elseif (byte == ClientPackets.ClearImbuement) then
  334. -- Clear Imbuement
  335. player:clearImbuement(msg)
  336. end
  337. end
  338.  
  339. local function tableContains(table, value)
  340. for i = 1, #table do
  341. if (table[i] == value) then
  342. return true
  343. end
  344. end
  345.  
  346. return false
  347. end
  348.  
  349. local function haveImbuingShrine(player)
  350. for x = -1, 1 do
  351. for y = -1, 1 do
  352. local posX, posY, posZ = player:getPosition().x+x, player:getPosition().y+y, player:getPosition().z
  353. local tile = Tile(posX, posY, posZ)
  354. if (tile) then
  355. for index, id in pairs(imbuingShrineIds) do
  356. if tile:getItemById(id) then
  357. return true
  358. end
  359. end
  360. end
  361. end
  362. end
  363.  
  364. return false
  365. end
  366.  
  367. local function getEquipById(id)
  368. for i, v in pairs(Weapons) do
  369. if (tableContains(v, id)) then
  370. return i
  371. end
  372. end
  373.  
  374. return nil
  375. end
  376.  
  377. local function getImbuementEquip(equip)
  378. local tableReturn = {}
  379. for i = 1, #Imbuements do
  380. if (tableContains(Imbuements[i].Weapons, equip)) then
  381. tableReturn[#tableReturn+1] = Imbuements[i]
  382. end
  383. end
  384.  
  385. return tableReturn
  386. end
  387.  
  388. local function getActiveImbuement(item, slot)
  389. for i = 1, #Imbuements do
  390. for j = 1, 3 do
  391. local level = Imbuements[i].Levels[j]
  392. local enchant = item:getSpecialAttribute(slot)
  393. if (enchant and type(enchant) ~= 'number' and enchant:find(level) and enchant:find(Imbuements[i].Name)) then
  394. return Imbuements[i], j
  395. end
  396. end
  397. end
  398.  
  399. return nil
  400. end
  401.  
  402. local function getImbuementByIndex(index, id)
  403. local equip = getEquipById(id)
  404. local myImbuements = getImbuementEquip(equip)
  405. local tmpIndex = 0
  406. for i = 1, #myImbuements do
  407. for k = 1, 3 do
  408. tmpIndex = tmpIndex + 1
  409. if (index == tmpIndex) then
  410. return myImbuements[i], k
  411. end
  412. end
  413. end
  414.  
  415. return nil
  416. end
  417.  
  418. local function sendImbuementError(self, message, errorType)
  419. local msg = NetworkMessage()
  420. msg:addByte(0xED)
  421. msg:addByte(errorType or 0x01)
  422. msg:addString(message)
  423. msg:sendToPlayer(self)
  424. end
  425.  
  426. local function mergeImbuementList(table1, table2)
  427. local newTable = {}
  428. for i, v in pairs(table1) do
  429. if (v.Name ~= table2.Name and not (tableContains(ImbuementElements, v.Type) and tableContains(ImbuementElements, table2.Type))) then
  430. newTable[#newTable+1] = v
  431. end
  432. end
  433.  
  434. return newTable
  435. end
  436.  
  437. function Player.applyImbuement(self, msg)
  438. if (not haveImbuingShrine(self)) then
  439. sendImbuementError(self, "An error ocurred, please reopen imbuement window.", ErrorMessages.MESSAGEDIALOG_IMBUEMENT_ERROR)
  440. return false
  441. end
  442.  
  443. local item = lastItemImbuing[self:getGuid()]
  444. if not item then
  445. sendImbuementError(self, "Cannot find item, please contact an Administrator.", ErrorMessages.MESSAGEDIALOG_IMBUEMENT_ERROR)
  446. return false
  447. end
  448.  
  449. local slot, choiceId, useProtection = msg:getByte(), msg:getU32(), msg:getByte()
  450. local myImbuements = getImbuementEquip(getEquipById(item:getId()))
  451. local imbuingLevel = 0
  452. local imbuementNow, index = nil, 0
  453.  
  454. for i = 1, item:getType():getImbuingSlots() do
  455. existsImbuement, enchantLevel = getActiveImbuement(item, i)
  456. if existsImbuement then
  457. myImbuements = mergeImbuementList(myImbuements, existsImbuement)
  458. end
  459. end
  460.  
  461. for k = 1, #myImbuements do
  462. for i = 1, 3 do
  463. index = index + 1
  464. if not imbuementNow and index == choiceId then
  465. imbuementNow = myImbuements[k]
  466. end
  467. end
  468. end
  469.  
  470. for i = 3, index, 3 do
  471. if choiceId >= i-2 and choiceId <= i then
  472. imbuingLevel = math.abs((i - 2) - choiceId) + 1
  473. break
  474. end
  475. end
  476.  
  477. if (not imbuementNow) then
  478. sendImbuementError(self, "Cannot find imbuement data, please contact an Administrator.", ErrorMessages.MESSAGEDIALOG_IMBUEMENT_ERROR)
  479. return false
  480. end
  481.  
  482. local imbuingPrice = ImbuingInfo[imbuingLevel].Price
  483. if (useProtection == 1) then
  484. imbuingPrice = imbuingPrice + ImbuingInfo[imbuingLevel].Protection
  485. end
  486.  
  487. if (not self:removeMoneyNpc(imbuingPrice)) then
  488. sendImbuementError(self, "You don't have enough money " ..imbuingPrice.. " gps.", ErrorMessages.MESSAGEDIALOG_IMBUEMENT_ROLL_FAILED)
  489. return false
  490. end
  491.  
  492. slot = slot + 1
  493. if self:getAccountType() < 5 then
  494. for j = 1, imbuingLevel do
  495. local itemID, itemCount = imbuementNow.Items[j][1], imbuementNow.Items[j][2]
  496. if (self:getItemCount(itemID) < itemCount) then
  497. sendImbuementError(self, "You don't have all necessary items.", ErrorMessages.MESSAGEDIALOG_IMBUEMENT_ROLL_FAILED)
  498. return false
  499. end
  500.  
  501. self:removeItem(itemID, itemCount)
  502. end
  503. end
  504.  
  505. if (item:isActiveImbuement(slot+3)) then
  506. sendImbuementError(self, "An error ocurred, please reopen imbuement window.", ErrorMessages.MESSAGEDIALOG_IMBUEMENT_ERROR)
  507. return false
  508. end
  509.  
  510. local applyChance = math.random(100)
  511. if (ImbuingInfo[imbuingLevel].Percent < applyChance and useProtection == 0) then
  512. sendImbuementError(self, "Item failed to apply imbuement.", ErrorMessages.MESSAGEDIALOG_IMBUEMENT_ROLL_FAILED)
  513. return false
  514. end
  515.  
  516. item:setSpecialAttribute(slot, imbuementNow.Levels[imbuingLevel].. " " ..imbuementNow.Name, slot+3, 72000, slot+6, 0)
  517. self:openImbuementWindow(item)
  518. end
  519.  
  520. function Player.clearImbuement(self, msg)
  521. if (not haveImbuingShrine(self)) then
  522. sendImbuementError(self, "Sorry, not possible.", ErrorMessages.MESSAGEDIALOG_CLEARING_CHARM_ERROR)
  523. return false
  524. end
  525.  
  526. local item = lastItemImbuing[self:getGuid()]
  527. if (item == nil) then
  528. sendImbuementError(self, "Cannot find item, please send this message to a Administrator.", ErrorMessages.MESSAGEDIALOG_CLEARING_CHARM_ERROR)
  529. return false
  530. end
  531.  
  532. local weaponSlot = msg:getByte()
  533. if (not weaponSlot) then
  534. sendImbuementError(self, "Sorry, not possible.", ErrorMessages.MESSAGEDIALOG_CLEARING_CHARM_ERROR)
  535. return false
  536. end
  537.  
  538. weaponSlot = weaponSlot + 1
  539. if (not item:isActiveImbuement(weaponSlot + 3)) then
  540. sendImbuementError(self, "Sorry, not possible.", ErrorMessages.MESSAGEDIALOG_CLEARING_CHARM_ERROR)
  541. return false
  542. end
  543.  
  544. if (not self:removeMoneyNpc(15000)) then
  545. sendImbuementError(self, "You don't have enough money 15000 gps.", ErrorMessages.MESSAGEDIALOG_CLEARING_CHARM_ERROR)
  546. return false
  547. end
  548.  
  549. item:setSpecialAttribute(weaponSlot, 0, weaponSlot+3, 0, weaponSlot+6, 0)
  550. self:openImbuementWindow(item)
  551. sendImbuementError(self, "Item clean success!", ErrorMessages.MESSAGEDIALOG_CLEARING_CHARM_SUCCESS)
  552. end
  553.  
  554. function Player.closeImbuementWindow(self)
  555. local msg = NetworkMessage()
  556. msg:addByte(0xEC)
  557. msg:sendToPlayer(self)
  558. end
  559.  
  560. function Player.openImbuementWindow(self, item)
  561. if (not item or not item:isItem() or not item:isImbuementEquip()) then
  562. self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This item is not imbuable.")
  563. return false
  564. end
  565.  
  566. for slot = 1, 10 do
  567. if (self:getSlotItem(slot) and self:getSlotItem(slot):getUniqueId() == item:getUniqueId()) then
  568. self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You cannot imbue an equipped item.")
  569. return false
  570. end
  571. end
  572.  
  573. local msg = NetworkMessage()
  574. local itemID = item:getId()
  575. local equip = getEquipById(item:getId())
  576. local myImbuements = getImbuementEquip(equip)
  577. local imbuingSlots = item:getType():getImbuingSlots()
  578. lastItemImbuing[self:getGuid()] = item
  579.  
  580. msg:addByte(0xEB)
  581. msg:addItemId(itemID) -- Item to put slots imbuement
  582. msg:addByte(imbuingSlots) -- Loop Exists Imbuement and slot (soon)
  583.  
  584. for i = 1, imbuingSlots do
  585. if (item:isActiveImbuement(i+3)) then
  586. local existsImbuement, enchantLevel = getActiveImbuement(item, i)
  587. myImbuements = mergeImbuementList(myImbuements, existsImbuement)
  588. msg:addByte(0x01) -- No have imbuement (byte 1 need more packets)
  589. msg:addU32(900) -- Start Read Imbuement Data
  590. msg:addString(existsImbuement.Levels[enchantLevel].. " " ..existsImbuement.Name) -- Name Element
  591.  
  592. local newDescription = existsImbuement.Description:gsub(" %%", " " ..existsImbuement.LevelsPercent[enchantLevel].."%%")
  593. msg:addString(newDescription.. "\nLasts for 20h 0min while fighting.") -- Description
  594. msg:addString(existsImbuement.Category) -- Type Imbuement
  595. msg:addU16(existsImbuement.IconID+(enchantLevel-1)) -- Icon ID (wtf?)
  596. msg:addU32(72000) -- duration in seconds (20hrs)
  597. msg:addByte(0x01) -- premium true
  598. msg:addByte(enchantLevel) -- Loop Length astral sources
  599. for j = 1, enchantLevel do
  600. local itemID, itemName = existsImbuement.Items[j][1], ItemType(existsImbuement.Items[j][1]):getName()
  601. msg:addItemId(itemID or 2160) -- Astral ID
  602. msg:addString(itemName or "") -- Astral Name
  603. msg:addU16(existsImbuement.Items[j][2]) -- Astral Necessary count
  604. end
  605.  
  606. msg:addU32(ImbuingInfo[enchantLevel].Price)
  607. msg:addByte(ImbuingInfo[enchantLevel].Percent)
  608. msg:addU32(ImbuingInfo[enchantLevel].Protection) -- End Read Imbuement Data
  609. msg:addU32(item:getTimeImbuement(i+3)) -- Remaining Seconds
  610. msg:addU32(15000) -- Clear Cost Gold
  611. else
  612. msg:addByte(0x00)
  613. end
  614. end
  615.  
  616. msg:addU16(#myImbuements*3) -- Loop Read Imbuement data
  617. local index = 0
  618. for k = 1, #myImbuements do
  619. for i = 1, 3 do
  620. index = index + 1
  621. msg:addU32(index) -- Start Read Imbuement Data
  622. msg:addString(myImbuements[k].Levels[i].. " " ..myImbuements[k].Name) -- Name Element
  623.  
  624. local newDescription = myImbuements[k].Description:gsub(" %%", " " ..myImbuements[k].LevelsPercent[i].."%%")
  625. msg:addString(newDescription.. "\nLasts for 20h 0min while fighting.") -- Description
  626. msg:addString(myImbuements[k].Category) -- Type Imbuement
  627. msg:addU16(1) -- Icon ID (wtf?)
  628. msg:addU32(72000) -- duration in seconds (20hrs)
  629. if (i > 1) then
  630. msg:addByte(0x01) -- premium true
  631. else
  632. msg:addByte(0x00) -- premium false
  633. end
  634.  
  635. msg:addByte(i) -- Loop Length astral sources
  636. for j = 1, i do
  637. local itemID, itemName = myImbuements[k].Items[j][1], ItemType(myImbuements[k].Items[j][1]):getName()
  638. msg:addItemId(itemID or 2160) -- Astral ID
  639. msg:addString(itemName or "") -- Astral Name
  640. msg:addU16(myImbuements[k].Items[j][2]) -- Astral Necessary count
  641. end
  642.  
  643. msg:addU32(ImbuingInfo[i].Price)
  644. msg:addByte(ImbuingInfo[i].Percent)
  645. msg:addU32(ImbuingInfo[i].Protection) -- End Read Imbuement Data
  646. end
  647. end
  648.  
  649. msg:addU32(#myImbuements*3)
  650. for k = 1, #myImbuements do
  651. for j = 1, 3 do
  652. msg:addItemId(myImbuements[k].Items[j][1])
  653. if self:getAccountType() < 5 then
  654. msg:addU16(self:getItemCount(myImbuements[k].Items[j][1]))
  655. else
  656. msg:addU16(999)
  657. end
  658. end
  659. end
  660.  
  661. self:sendResource("bank", self:getBankBalance())
  662. self:sendResource("inventory", self:getMoney())
  663. msg:sendToPlayer(self)
  664. end
  665.  
  666. function Item:isActiveImbuement(index)
  667. local time = self:getSpecialAttribute(index)
  668. if (time and time > 0) then
  669. return true
  670. end
  671.  
  672. return false
  673. end
  674.  
  675. function Item:getTimeImbuement(index)
  676. local time = self:getSpecialAttribute(index)
  677. if (time and time > 0) then
  678. return time
  679. end
  680.  
  681. return false
  682. end
  683.  
  684. function Item:isImbuementEquip()
  685. if (not self) then
  686. return false
  687. end
  688.  
  689. if (self:getType() and self:getType():getImbuingSlots() > 0) then
  690. return true
  691. end
  692.  
  693. return false
  694. end
  695.  
  696. function Item:getImbuementType(slot)
  697. local enchant = self:getSpecialAttribute(slot)
  698. if (enchant == 0) then
  699. return false
  700. end
  701.  
  702. for i, v in pairs(Imbuements) do
  703. for j = 1, 3 do
  704. if (enchant:find(v.Name) and enchant:find(v.Levels[j])) then
  705. return v.Type
  706. end
  707. end
  708. end
  709.  
  710. return nil
  711. end
  712.  
  713. function Item:getImbuementPercent(name)
  714. for i, v in pairs(Imbuements) do
  715. for j = 1, 3 do
  716. if (name:find(v.Name) and name:find(v.Levels[j]) and name ~= 0) then
  717. return v.LevelsPercent[j]
  718. end
  719. end
  720. end
  721.  
  722. return nil
  723. end
RAW Paste Data