Berntan

/core/Player.lua

Nov 27th, 2023
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. local foodCondition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
  2.  
  3. function Player.feed(self, food)
  4. local condition = self:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
  5. if condition then
  6. condition:setTicks(condition:getTicks() + (food * 1000))
  7. else
  8. local vocation = self:getVocation()
  9. if not vocation then
  10. return nil
  11. end
  12.  
  13. foodCondition:setTicks(food * 1000)
  14. foodCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, vocation:getHealthGainAmount())
  15. foodCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, vocation:getHealthGainTicks() * 1000)
  16. foodCondition:setParameter(CONDITION_PARAM_MANAGAIN, vocation:getManaGainAmount())
  17. foodCondition:setParameter(CONDITION_PARAM_MANATICKS, vocation:getManaGainTicks() * 1000)
  18.  
  19. self:addCondition(foodCondition)
  20. end
  21. return true
  22. end
  23.  
  24. function Player.getClosestFreePosition(self, position, extended)
  25. if self:getGroup():getAccess() and self:getAccountType() >= ACCOUNT_TYPE_GOD then
  26. return position
  27. end
  28. return Creature.getClosestFreePosition(self, position, extended)
  29. end
  30.  
  31. function Player.getDepotItems(self, depotId)
  32. return self:getDepotChest(depotId, true):getItemHoldingCount()
  33. end
  34.  
  35. function Player.hasFlag(self, flag)
  36. return self:getGroup():hasFlag(flag)
  37. end
  38.  
  39. local lossPercent = {
  40. [0] = 100,
  41. [1] = 70,
  42. [2] = 45,
  43. [3] = 25,
  44. [4] = 10,
  45. [5] = 0
  46. }
  47.  
  48. function Player.getLossPercent(self)
  49. local blessings = 0
  50. for i = 1, 5 do
  51. if self:hasBlessing(i) then
  52. blessings = blessings + 1
  53. end
  54. end
  55. return lossPercent[blessings]
  56. end
  57.  
  58. function Player.isPremium(self)
  59. return self:getPremiumDays() > 0 or configManager.getBoolean(configKeys.FREE_PREMIUM)
  60. end
  61.  
  62. function Player.sendCancelMessage(self, message)
  63. if type(message) == "number" then
  64. message = Game.getReturnMessage(message)
  65. end
  66. return self:sendTextMessage(MESSAGE_STATUS_SMALL, message)
  67. end
  68.  
  69. function Player.isUsingOtClient(self)
  70. return self:getClient().os >= CLIENTOS_OTCLIENT_LINUX
  71. end
  72.  
  73. function Player.sendExtendedOpcode(self, opcode, buffer)
  74. if not self:isUsingOtClient() then
  75. return false
  76. end
  77.  
  78. local networkMessage = NetworkMessage()
  79. networkMessage:addByte(0x32)
  80. networkMessage:addByte(opcode)
  81. networkMessage:addString(buffer)
  82. networkMessage:sendToPlayer(self)
  83. networkMessage:delete()
  84. return true
  85. end
  86.  
  87. APPLY_SKILL_MULTIPLIER = true
  88. local addSkillTriesFunc = Player.addSkillTries
  89. function Player.addSkillTries(...)
  90. APPLY_SKILL_MULTIPLIER = false
  91. local ret = addSkillTriesFunc(...)
  92. APPLY_SKILL_MULTIPLIER = true
  93. return ret
  94. end
  95.  
  96. local addManaSpentFunc = Player.addManaSpent
  97. function Player.addManaSpent(...)
  98. APPLY_SKILL_MULTIPLIER = false
  99. local ret = addManaSpentFunc(...)
  100. APPLY_SKILL_MULTIPLIER = true
  101. return ret
  102. end
  103.  
  104.  
  105. function Player.getExhaustion(self, value)
  106. local storage = self:getStorageValue(value)
  107. if storage <= 0 then
  108. return 0
  109. end
  110. return storage - os.time()
  111. end
  112.  
  113. function Player.depositMoney(self, amount)
  114. if not self:removeMoney(amount) then
  115. return false
  116. end
  117.  
  118. self:setBankBalance(self:getBankBalance() + amount)
  119. return true
  120. end
  121.  
  122.  
  123. function Player.setExhaustion(self, value, time)
  124. return self:setStorageValue(value, time + os.time())
  125. end
  126.  
  127. function Player.withdrawMoney(self, amount)
  128. local balance = self:getBankBalance()
  129. if amount > balance or not self:addMoney(amount) then
  130. return false
  131. end
  132.  
  133. self:setBankBalance(balance - amount)
  134. return true
  135. end
  136.  
  137.  
  138. function Player.isDruid(self)
  139. return isInArray({2, 6}, self:getVocation():getId())
  140. end
  141.  
  142. function Player.isKnight(self)
  143. return isInArray({4, 8}, self:getVocation():getId())
  144. end
  145.  
  146. function Player.isPaladin(self)
  147. return isInArray({3, 7}, self:getVocation():getId())
  148. end
  149.  
  150. function Player.isMage(self)
  151. return isInArray({1, 2, 5, 6}, self:getVocation():getId())
  152. end
  153.  
  154. function Player.isSorcerer(self)
  155. return isInArray({1, 5}, self:getVocation():getId())
  156. end
  157.  
  158. function Player.getCookiesDelivered(self)
  159. local storage, amount = {
  160. Storage.WhatAFoolishQuest.CookieDelivery.SimonTheBeggar,
  161. Storage.WhatAFoolishQuest.CookieDelivery.Markwin,
  162. Storage.WhatAFoolishQuest.CookieDelivery.Ariella,
  163. Storage.WhatAFoolishQuest.CookieDelivery.Hairycles,
  164. Storage.WhatAFoolishQuest.CookieDelivery.Djinn,
  165. Storage.WhatAFoolishQuest.CookieDelivery.AvarTar,
  166. Storage.WhatAFoolishQuest.CookieDelivery.OrcKing,
  167. Storage.WhatAFoolishQuest.CookieDelivery.Lorbas,
  168. Storage.WhatAFoolishQuest.CookieDelivery.Wyda,
  169. Storage.WhatAFoolishQuest.CookieDelivery.Hjaern
  170. }, 0
  171. for i = 1, #storage do
  172. if self:getStorageValue(storage[i]) == 1 then
  173. amount = amount + 1
  174. end
  175. end
  176. return amount
  177. end
  178.  
  179.  
  180.  
Add Comment
Please, Sign In to add comment