Advertisement
Guest User

Pokeball System

a guest
Sep 28th, 2017
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 24.42 KB | None | 0 0
  1. From 5f36834a1c24d39e378e694f1bbfab47115bd7fd Mon Sep 17 00:00:00 2001
  2. From: eduardovicente <dudugt500@gmail.com>
  3. Date: Fri, 22 Sep 2017 19:16:04 -0300
  4. Subject: [PATCH] Pokeball System 1.0
  5.  
  6. ---
  7. forgottenserver-1.2/data/actions/actions.xml       |   3 +
  8.  .../data/actions/scripts/tools/pokeball.lua        |  32 ++++
  9.  forgottenserver-1.2/data/events/scripts/player.lua |  94 ++++++-----
  10.  forgottenserver-1.2/data/items/items.xml           |   1 +
  11.  forgottenserver-1.2/src/enums.h                    |  10 ++
  12.  forgottenserver-1.2/src/item.cpp                   |  10 ++
  13.  forgottenserver-1.2/src/item.h                     |   8 +
  14.  forgottenserver-1.2/src/items.cpp                  |   2 +
  15.  forgottenserver-1.2/src/items.h                    |   6 +-
  16.  forgottenserver-1.2/src/luascript.cpp              | 186 +++++++++++++++++++++
  17.  forgottenserver-1.2/src/luascript.h                |  21 +++
  18.  forgottenserver-1.2/src/pokeball.cpp               |  98 +++++++++++
  19.  forgottenserver-1.2/src/pokeball.h                 |  49 ++++++
  20.  13 files changed, 476 insertions(+), 44 deletions(-)
  21.  create mode 100644 forgottenserver-1.2/data/actions/scripts/tools/pokeball.lua
  22.  create mode 100644 forgottenserver-1.2/src/pokeball.cpp
  23.  create mode 100644 forgottenserver-1.2/src/pokeball.h
  24.  
  25. diff --git a/forgottenserver-1.2/data/actions/actions.xml b/forgottenserver-1.2/data/actions/actions.xml
  26. index af4f559..89695bf 100644
  27. --- a/forgottenserver-1.2/data/actions/actions.xml
  28. +++ b/forgottenserver-1.2/data/actions/actions.xml
  29. @@ -1,5 +1,8 @@
  30.  <?xml version="1.0" encoding="UTF-8"?>
  31.  <actions>
  32. +   <!-- Pokeball -->
  33. +   <action itemid="2467" script="tools/pokeball.lua" />
  34. +
  35.     <!-- Quests -->
  36.     <action itemid="1740" script="quests/quests.lua" />
  37.     <action fromid="1747" toid="1749" script="quests/quests.lua" />
  38. diff --git a/forgottenserver-1.2/data/actions/scripts/tools/pokeball.lua b/forgottenserver-1.2/data/actions/scripts/tools/pokeball.lua
  39. new file mode 100644
  40. index 0000000..de6d6f2
  41. --- /dev/null
  42. +++ b/forgottenserver-1.2/data/actions/scripts/tools/pokeball.lua
  43. @@ -0,0 +1,32 @@
  44. +function table.dump(t, depth)
  45. +  if not depth then depth = 0 end
  46. +  for k,v in pairs(t) do
  47. +    str = (' '):rep(depth * 2) .. k .. ': '
  48. +    if type(v) ~= "table" then
  49. +      print(str .. tostring(v))
  50. +    else
  51. +      print(str)
  52. +      table.dump(v, depth+1)
  53. +    end
  54. +  end
  55. +end
  56. +
  57. +function onUse(player, pokeball, fromPosition, target, toPosition, isHotkey)
  58. +    local nameList = {"Amazon", "Troll", "Orc", "Fire Devil", "Dragon", "Frost Dragon"}
  59. +
  60. +    if (pokeball:getPokemonName() == "") then
  61. +        pokeball:setPokemonName(nameList[math.random(1, 6)])
  62. +        pokeball:setLevel(math.random(1,100))
  63. +        pokeball:setMaxHealth(100 * pokeball:getLevel())
  64. +        pokeball:setHealth(pokeball:getMaxHealth())
  65. +    else
  66. +        local pokemon = Game.createMonster(pokeball:getPokemonName(), player:getPosition())
  67. +        pokemon:setMaster(player)
  68. +
  69. +        pokemon:setMaxHealth(pokeball:getMaxHealth())
  70. +        local currentHealth = -(pokemon:getHealth() - 1)
  71. +        pokemon:addHealth(currentHealth)
  72. +        pokemon:addHealth(pokeball:getHealth() - 1)
  73. +    end
  74. +    return true
  75. +end
  76. \ No newline at end of file
  77. diff --git a/forgottenserver-1.2/data/events/scripts/player.lua b/forgottenserver-1.2/data/events/scripts/player.lua
  78. index 472f1ac..40d1694 100644
  79. --- a/forgottenserver-1.2/data/events/scripts/player.lua
  80. +++ b/forgottenserver-1.2/data/events/scripts/player.lua
  81. @@ -3,55 +3,63 @@ function Player:onBrowseField(position)
  82.  end
  83.  
  84.  function Player:onLook(thing, position, distance)
  85. -   local description = "You see " .. thing:getDescription(distance)
  86. -   if self:getGroup():getAccess() then
  87. -       if thing:isItem() then
  88. -           description = string.format("%s\nItem ID: %d", description, thing:getId())
  89. -
  90. -           local actionId = thing:getActionId()
  91. -           if actionId ~= 0 then
  92. -               description = string.format("%s, Action ID: %d", description, actionId)
  93. -           end
  94. -
  95. -           local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
  96. -           if uniqueId > 0 and uniqueId < 65536 then
  97. -               description = string.format("%s, Unique ID: %d", description, uniqueId)
  98. -           end
  99. -
  100. -           local itemType = thing:getType()
  101. -
  102. -           local transformEquipId = itemType:getTransformEquipId()
  103. -           local transformDeEquipId = itemType:getTransformDeEquipId()
  104. -           if transformEquipId ~= 0 then
  105. -               description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
  106. -           elseif transformDeEquipId ~= 0 then
  107. -               description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
  108. -           end
  109. -
  110. -           local decayId = itemType:getDecayId()
  111. -           if decayId ~= -1 then
  112. -               description = string.format("%s\nDecays to: %d", description, decayId)
  113. -           end
  114. -       elseif thing:isCreature() then
  115. -           local str = "%s\nHealth: %d / %d"
  116. -           if thing:getMaxMana() > 0 then
  117. -               str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
  118. +   local description = ""
  119. +  
  120. +   if thing:isPokeball() then
  121. +       description = "You see an ".. thing:getPokemonName()
  122. +       description = description.. ", Level: ".. thing:getLevel().. ", [Hp: ".. thing:getHealth().. " / Max.Hp: ".. thing:getMaxHealth().. "]."
  123. +   else
  124. +       description = "You see " .. thing:getDescription(distance)
  125. +       if self:getGroup():getAccess() then
  126. +           if thing:isItem() then
  127. +               description = string.format("%s\nItem ID: %d", description, thing:getId())
  128. +
  129. +               local actionId = thing:getActionId()
  130. +               if actionId ~= 0 then
  131. +                   description = string.format("%s, Action ID: %d", description, actionId)
  132. +               end
  133. +
  134. +               local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
  135. +               if uniqueId > 0 and uniqueId < 65536 then
  136. +                   description = string.format("%s, Unique ID: %d", description, uniqueId)
  137. +               end
  138. +
  139. +               local itemType = thing:getType()
  140. +
  141. +               local transformEquipId = itemType:getTransformEquipId()
  142. +               local transformDeEquipId = itemType:getTransformDeEquipId()
  143. +               if transformEquipId ~= 0 then
  144. +                   description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
  145. +               elseif transformDeEquipId ~= 0 then
  146. +                   description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
  147. +               end
  148. +
  149. +               local decayId = itemType:getDecayId()
  150. +               if decayId ~= -1 then
  151. +                   description = string.format("%s\nDecays to: %d", description, decayId)
  152. +               end
  153. +           elseif thing:isCreature() then
  154. +               local str = "%s\nHealth: %d / %d"
  155. +               if thing:getMaxMana() > 0 then
  156. +                   str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
  157. +               end
  158. +               description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
  159.             end
  160. -           description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
  161. -       end
  162.  
  163. -       local position = thing:getPosition()
  164. -       description = string.format(
  165. -           "%s\nPosition: %d, %d, %d",
  166. -           description, position.x, position.y, position.z
  167. -       )
  168. +           local position = thing:getPosition()
  169. +           description = string.format(
  170. +               "%s\nPosition: %d, %d, %d",
  171. +               description, position.x, position.y, position.z
  172. +           )
  173.  
  174. -       if thing:isCreature() then
  175. -           if thing:isPlayer() then
  176. -               description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
  177. +           if thing:isCreature() then
  178. +               if thing:isPlayer() then
  179. +                   description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
  180. +               end
  181.             end
  182.         end
  183.     end
  184. +
  185.     self:sendTextMessage(MESSAGE_INFO_DESCR, description)
  186.  end
  187.  
  188. diff --git a/forgottenserver-1.2/data/items/items.xml b/forgottenserver-1.2/data/items/items.xml
  189. index 134c7cd..da0c5be 100644
  190. --- a/forgottenserver-1.2/data/items/items.xml
  191. +++ b/forgottenserver-1.2/data/items/items.xml
  192. @@ -3753,6 +3753,7 @@
  193.         <attribute key="weight" value="6000" />
  194.         <attribute key="armor" value="4" />
  195.         <attribute key="slotType" value="body" />
  196. +       <attribute key="type" value="pokeball" />
  197.     </item>
  198.     <item id="2468" name="studded legs">
  199.         <attribute key="weight" value="2600" />
  200. diff --git a/forgottenserver-1.2/src/enums.h b/forgottenserver-1.2/src/enums.h
  201. index 032dada..f927825 100644
  202. --- a/forgottenserver-1.2/src/enums.h
  203. +++ b/forgottenserver-1.2/src/enums.h
  204. @@ -546,6 +546,16 @@ struct CombatDamage
  205.     }
  206.  };
  207.  
  208. +struct PokemonStatus
  209. +{
  210. +   double attack = 0;
  211. +   double defense = 0;
  212. +   double hp = 0;
  213. +   double specialAttack = 0;
  214. +   double specialDefense = 0;
  215. +   double speed = 0;
  216. +};
  217. +
  218.  typedef std::list<MarketOffer> MarketOfferList;
  219.  typedef std::list<HistoryMarketOffer> HistoryMarketOfferList;
  220.  typedef std::list<ShopInfo> ShopInfoList;
  221. diff --git a/forgottenserver-1.2/src/item.cpp b/forgottenserver-1.2/src/item.cpp
  222. index ca23ee4..a0bc884 100644
  223. --- a/forgottenserver-1.2/src/item.cpp
  224. +++ b/forgottenserver-1.2/src/item.cpp
  225. @@ -27,6 +27,7 @@
  226.  #include "house.h"
  227.  #include "game.h"
  228.  #include "bed.h"
  229. +#include "pokeball.h"
  230.  
  231.  #include "actions.h"
  232.  #include "spells.h"
  233. @@ -67,6 +68,8 @@ Item* Item::CreateItem(const uint16_t type, uint16_t count /*= 0*/)
  234.             newItem = new Mailbox(type);
  235.         } else if (it.isBed()) {
  236.             newItem = new BedItem(type);
  237. +       } else if (it.isPokeball()) {
  238. +           newItem = new Pokeball(type);
  239.         } else if (it.id >= 2210 && it.id <= 2212) {
  240.             newItem = new Item(type - 3, count);
  241.         } else if (it.id == 2215 || it.id == 2216) {
  242. @@ -617,6 +620,13 @@ Attr_ReadValue Item::readAttr(AttrTypes_t attr, PropStream& propStream)
  243.             return ATTR_READ_ERROR;
  244.         }
  245.  
  246. +       //Pokeball class
  247. +       case ATTR_POKEBALLINFO: {
  248. +           if (!propStream.skip(6)) {
  249. +               return ATTR_READ_ERROR;
  250. +           }
  251. +           break;
  252. +       }
  253.         default:
  254.             return ATTR_READ_ERROR;
  255.     }
  256. diff --git a/forgottenserver-1.2/src/item.h b/forgottenserver-1.2/src/item.h
  257. index 0004522..a8be5fb 100644
  258. --- a/forgottenserver-1.2/src/item.h
  259. +++ b/forgottenserver-1.2/src/item.h
  260. @@ -36,6 +36,7 @@ class Mailbox;
  261.  class Door;
  262.  class MagicField;
  263.  class BedItem;
  264. +class Pokeball;
  265.  
  266.  enum ITEMPROPERTY {
  267.     CONST_PROP_BLOCKSOLID = 0,
  268. @@ -97,6 +98,7 @@ enum AttrTypes_t {
  269.     ATTR_ARMOR = 31,
  270.     ATTR_HITCHANCE = 32,
  271.     ATTR_SHOOTRANGE = 33,
  272. +   ATTR_POKEBALLINFO = 34,
  273.  };
  274.  
  275.  enum Attr_ReadValue {
  276. @@ -360,6 +362,12 @@ class Item : virtual public Thing
  277.         virtual const BedItem* getBed() const {
  278.             return nullptr;
  279.         }
  280. +       virtual Pokeball* getPokeball() {
  281. +           return nullptr;
  282. +       }
  283. +       virtual const Pokeball* getPokeball() const {
  284. +           return nullptr;
  285. +       }
  286.  
  287.         const std::string& getStrAttr(itemAttrTypes type) const {
  288.             if (!attributes) {
  289. diff --git a/forgottenserver-1.2/src/items.cpp b/forgottenserver-1.2/src/items.cpp
  290. index a05149e..37a1201 100644
  291. --- a/forgottenserver-1.2/src/items.cpp
  292. +++ b/forgottenserver-1.2/src/items.cpp
  293. @@ -400,6 +400,8 @@ void Items::parseItemNode(const pugi::xml_node& itemNode, uint16_t id)
  294.                 it.type = ITEM_TYPE_BED;
  295.             } else if (tmpStrValue == "rune") {
  296.                 it.type = ITEM_TYPE_RUNE;
  297. +           } else if (tmpStrValue == "pokeball") {
  298. +               it.type = ITEM_TYPE_POKEBALL;
  299.             } else {
  300.                 std::cout << "[Warning - Items::parseItemNode] Unknown type: " << valueAttribute.as_string() << std::endl;
  301.             }
  302. diff --git a/forgottenserver-1.2/src/items.h b/forgottenserver-1.2/src/items.h
  303. index 44c9a0c..de58d18 100644
  304. --- a/forgottenserver-1.2/src/items.h
  305. +++ b/forgottenserver-1.2/src/items.h
  306. @@ -54,6 +54,7 @@ enum ItemTypes_t {
  307.     ITEM_TYPE_BED,
  308.     ITEM_TYPE_KEY,
  309.     ITEM_TYPE_RUNE,
  310. +   ITEM_TYPE_POKEBALL,
  311.     ITEM_TYPE_LAST
  312.  };
  313.  
  314. @@ -142,7 +143,10 @@ class ItemType
  315.             return (type == ITEM_TYPE_BED);
  316.         }
  317.         bool isRune() const {
  318. -           return type == ITEM_TYPE_RUNE;
  319. +           return (type == ITEM_TYPE_RUNE);
  320. +       }
  321. +       bool isPokeball() const {
  322. +           return (type == ITEM_TYPE_POKEBALL);
  323.         }
  324.         bool hasSubType() const {
  325.             return (isFluidContainer() || isSplash() || stackable || charges != 0);
  326. diff --git a/forgottenserver-1.2/src/luascript.cpp b/forgottenserver-1.2/src/luascript.cpp
  327. index bd2d52f..6c975d6 100644
  328. --- a/forgottenserver-1.2/src/luascript.cpp
  329. +++ b/forgottenserver-1.2/src/luascript.cpp
  330. @@ -35,6 +35,7 @@
  331.  #include "monster.h"
  332.  #include "scheduler.h"
  333.  #include "databasetasks.h"
  334. +#include "pokeball.h"
  335.  
  336.  extern Chat* g_chat;
  337.  extern Game g_game;
  338. @@ -674,6 +675,8 @@ void LuaScriptInterface::setItemMetatable(lua_State* L, int32_t index, const Ite
  339.         luaL_getmetatable(L, "Container");
  340.     } else if (item->getTeleport()) {
  341.         luaL_getmetatable(L, "Teleport");
  342. +   } else if (item->getPokeball()) {
  343. +       luaL_getmetatable(L, "Pokeball");
  344.     } else {
  345.         luaL_getmetatable(L, "Item");
  346.     }
  347. @@ -807,6 +810,9 @@ Thing* LuaScriptInterface::getThing(lua_State* L, int32_t arg)
  348.             case LuaData_Npc:
  349.                 thing = getUserdata<Npc>(L, arg);
  350.                 break;
  351. +           case LuaData_Pokeball:
  352. +               thing = getUserdata<Pokeball>(L, arg);
  353. +               break;
  354.             default:
  355.                 thing = nullptr;
  356.                 break;
  357. @@ -1427,6 +1433,7 @@ void LuaScriptInterface::registerFunctions()
  358.     registerEnum(ITEM_TYPE_BED)
  359.     registerEnum(ITEM_TYPE_KEY)
  360.     registerEnum(ITEM_TYPE_RUNE)
  361. +   registerEnum(ITEM_TYPE_POKEBALL)
  362.  
  363.     registerEnum(ITEM_BAG)
  364.     registerEnum(ITEM_GOLD_COIN)
  365. @@ -1954,6 +1961,7 @@ void LuaScriptInterface::registerFunctions()
  366.     registerMetaMethod("Item", "__eq", LuaScriptInterface::luaUserdataCompare);
  367.  
  368.     registerMethod("Item", "isItem", LuaScriptInterface::luaItemIsItem);
  369. +   registerMethod("Item", "isPokeball", LuaScriptInterface::luaItemIsPokeball);
  370.  
  371.     registerMethod("Item", "getParent", LuaScriptInterface::luaItemGetParent);
  372.     registerMethod("Item", "getTopParent", LuaScriptInterface::luaItemGetTopParent);
  373. @@ -2018,6 +2026,25 @@ void LuaScriptInterface::registerFunctions()
  374.     registerMethod("Teleport", "getDestination", LuaScriptInterface::luaTeleportGetDestination);
  375.     registerMethod("Teleport", "setDestination", LuaScriptInterface::luaTeleportSetDestination);
  376.  
  377. +   // Pokeball
  378. +   registerClass("Pokeball", "Item", LuaScriptInterface::luaPokeballCreate);
  379. +   registerMetaMethod("Pokeball", "__eq", LuaScriptInterface::luaUserdataCompare);
  380. +
  381. +   registerMethod("Pokeball", "getPokemonName", LuaScriptInterface::luaPokeballGetPokemonName);
  382. +   registerMethod("Pokeball", "setPokemonName", LuaScriptInterface::luaPokeballSetPokemonName);
  383. +
  384. +   registerMethod("Pokeball", "getLevel", LuaScriptInterface::luaPokeballGetLevel);
  385. +   registerMethod("Pokeball", "setLevel", LuaScriptInterface::luaPokeballSetLevel);
  386. +
  387. +   registerMethod("Pokeball", "getExperience", LuaScriptInterface::luaPokeballGetExperience);
  388. +   registerMethod("Pokeball", "setExperience", LuaScriptInterface::luaPokeballSetExperience);
  389. +
  390. +   registerMethod("Pokeball", "getHealth", LuaScriptInterface::luaPokeballGetHealth);
  391. +   registerMethod("Pokeball", "setHealth", LuaScriptInterface::luaPokeballSetHealth);
  392. +
  393. +   registerMethod("Pokeball", "getMaxHealth", LuaScriptInterface::luaPokeballGetMaxHealth);
  394. +   registerMethod("Pokeball", "setMaxHealth", LuaScriptInterface::luaPokeballSetMaxHealth);
  395. +
  396.     // Creature
  397.     registerClass("Creature", "", LuaScriptInterface::luaCreatureCreate);
  398.     registerMetaMethod("Creature", "__eq", LuaScriptInterface::luaUserdataCompare);
  399. @@ -2613,6 +2640,8 @@ void LuaScriptInterface::registerClass(const std::string& className, const std::
  400.         lua_pushnumber(luaState, LuaData_Npc);
  401.     } else if (className == "Tile") {
  402.         lua_pushnumber(luaState, LuaData_Tile);
  403. +   } else if (className == "Pokeball") {
  404. +       lua_pushnumber(luaState, LuaData_Pokeball);
  405.     } else {
  406.         lua_pushnumber(luaState, LuaData_Unknown);
  407.     }
  408. @@ -3594,6 +3623,7 @@ int LuaScriptInterface::luaAddEvent(lua_State* L)
  409.                     switch (entry.second) {
  410.                         case LuaData_Item:
  411.                         case LuaData_Container:
  412. +                       case LuaData_Pokeball:
  413.                         case LuaData_Teleport: {
  414.                             lua_getglobal(globalState, "Item");
  415.                             lua_getfield(globalState, -1, "getUniqueId");
  416. @@ -5767,6 +5797,14 @@ int LuaScriptInterface::luaItemIsItem(lua_State* L)
  417.     return 1;
  418.  }
  419.  
  420. +
  421. +int LuaScriptInterface::luaItemIsPokeball(lua_State* L)
  422. +{
  423. +   // item:isPokeball()
  424. +   pushBoolean(L, getUserdata<const Item>(L, 1)->getPokeball() != nullptr);
  425. +   return 1;
  426. +}
  427. +
  428.  int LuaScriptInterface::luaItemGetParent(lua_State* L)
  429.  {
  430.     // item:getParent()
  431. @@ -6580,6 +6618,154 @@ int LuaScriptInterface::luaTeleportSetDestination(lua_State* L)
  432.     return 1;
  433.  }
  434.  
  435. +// Pokeball
  436. +int LuaScriptInterface::luaPokeballCreate(lua_State* L)
  437. +{
  438. +   // Pokeball(uid)
  439. +   uint32_t id = getNumber<uint32_t>(L, 2);
  440. +   Item* item = getScriptEnv()->getItemByUID(id);
  441. +
  442. +   if (item && item->getPokeball()) {
  443. +       pushUserdata<Pokeball>(L, item->getPokeball());
  444. +       setMetatable(L, -1, "Pokeball");
  445. +   } else {
  446. +       lua_pushnil(L);
  447. +   }
  448. +   return 1;
  449. +}
  450. +
  451. +int LuaScriptInterface::luaPokeballGetPokemonName(lua_State* L)
  452. +{
  453. +   // Pokeball:getPokemonName()
  454. +   Pokeball* pokeball = getUserdata<Pokeball>(L, 1);
  455. +   if (pokeball) {
  456. +       pushString(L, pokeball->getPokemonName());
  457. +   } else {
  458. +       lua_pushnil(L);
  459. +   }
  460. +
  461. +   return 1;
  462. +}
  463. +
  464. +int LuaScriptInterface::luaPokeballSetPokemonName(lua_State* L)
  465. +{
  466. +   // Pokeball:setPokemonName(name)
  467. +   Pokeball* pokeball = getUserdata<Pokeball>(L, 1);
  468. +   if (pokeball) {
  469. +       std::string name = getString(L, 2);
  470. +       pokeball->setPokemonName(name);
  471. +   } else {
  472. +       lua_pushnil(L);
  473. +   }
  474. +
  475. +   return 1;
  476. +}
  477. +
  478. +int LuaScriptInterface::luaPokeballGetLevel(lua_State* L)
  479. +{
  480. +   // Pokeball:getLevel()
  481. +   Pokeball* pokeball = getUserdata<Pokeball>(L, 1);
  482. +   if (pokeball) {
  483. +       lua_pushnumber(L, pokeball->getLevel());
  484. +   } else {
  485. +       lua_pushnil(L);
  486. +   }
  487. +   return 1;
  488. +}
  489. +
  490. +int LuaScriptInterface::luaPokeballSetLevel(lua_State* L)
  491. +{
  492. +   // Pokeball:setLevel(lvl)
  493. +   Pokeball* pokeball = getUserdata<Pokeball>(L, 1);
  494. +   if (pokeball) {
  495. +       uint32_t lvl = getNumber<uint32_t>(L, 2);
  496. +       pokeball->setLevel(lvl);
  497. +   }
  498. +   else {
  499. +       lua_pushnil(L);
  500. +   }
  501. +
  502. +   return 1;
  503. +}
  504. +
  505. +int LuaScriptInterface::luaPokeballGetExperience(lua_State* L)
  506. +{
  507. +   // Pokeball:getExperience()
  508. +   Pokeball* pokeball = getUserdata<Pokeball>(L, 1);
  509. +   if (pokeball) {
  510. +       lua_pushnumber(L, pokeball->getExperience());
  511. +   } else {
  512. +       lua_pushnil(L);
  513. +   }
  514. +   return 1;
  515. +}
  516. +
  517. +int LuaScriptInterface::luaPokeballSetExperience(lua_State* L)
  518. +{
  519. +   // Pokeball:setExperience(exp)
  520. +   Pokeball* pokeball = getUserdata<Pokeball>(L, 1);
  521. +   if (pokeball) {
  522. +       uint64_t experience = getNumber<uint64_t>(L, 2);
  523. +       pokeball->setExperience(experience);
  524. +   } else {
  525. +       lua_pushnil(L);
  526. +   }
  527. +
  528. +   return 1;
  529. +}
  530. +
  531. +int LuaScriptInterface::luaPokeballGetHealth(lua_State* L)
  532. +{
  533. +   // Pokeball:getHealth()
  534. +   Pokeball* pokeball = getUserdata<Pokeball>(L, 1);
  535. +   if (pokeball) {
  536. +       lua_pushnumber(L, pokeball->getHealth());
  537. +   } else {
  538. +       lua_pushnil(L);
  539. +   }
  540. +   return 1;
  541. +}
  542. +
  543. +int LuaScriptInterface::luaPokeballSetHealth(lua_State* L)
  544. +{
  545. +   // Pokeball:setHealth(health)
  546. +   Pokeball* pokeball = getUserdata<Pokeball>(L, 1);
  547. +   if (pokeball) {
  548. +       int32_t health = getNumber<int32_t>(L, 2);
  549. +       pokeball->setHealth(health);
  550. +   } else {
  551. +       lua_pushnil(L);
  552. +   }
  553. +
  554. +   return 1;
  555. +}
  556. +
  557. +int LuaScriptInterface::luaPokeballGetMaxHealth(lua_State* L)
  558. +{
  559. +   // Pokeball:getMaxHealth()
  560. +   Pokeball* pokeball = getUserdata<Pokeball>(L, 1);
  561. +   if (pokeball) {
  562. +       lua_pushnumber(L, pokeball->getMaxHealth());
  563. +   } else {
  564. +       lua_pushnil(L);
  565. +   }
  566. +   return 1;
  567. +}
  568. +
  569. +int LuaScriptInterface::luaPokeballSetMaxHealth(lua_State* L)
  570. +{
  571. +   // Pokeball:setMaxHealth(mHealth)
  572. +   Pokeball* pokeball = getUserdata<Pokeball>(L, 1);
  573. +   if (pokeball) {
  574. +       int32_t mHealth = getNumber<int32_t>(L, 2);
  575. +       pokeball->setMaxHealth(mHealth);
  576. +   } else {
  577. +       lua_pushnil(L);
  578. +   }
  579. +
  580. +   return 1;
  581. +}
  582. +
  583.  // Creature
  584.  int LuaScriptInterface::luaCreatureCreate(lua_State* L)
  585.  {
  586. diff --git a/forgottenserver-1.2/src/luascript.h b/forgottenserver-1.2/src/luascript.h
  587. index b109527..6b3e933 100644
  588. --- a/forgottenserver-1.2/src/luascript.h
  589. +++ b/forgottenserver-1.2/src/luascript.h
  590. @@ -46,6 +46,7 @@ class Combat;
  591.  class Condition;
  592.  class Npc;
  593.  class Monster;
  594. +class Pokeball;
  595.  
  596.  enum {
  597.     EVENT_ID_LOADING = 1,
  598. @@ -71,6 +72,7 @@ enum LuaDataType {
  599.     LuaData_Monster,
  600.     LuaData_Npc,
  601.     LuaData_Tile,
  602. +   LuaData_Pokeball,
  603.  };
  604.  
  605.  struct LuaVariant {
  606. @@ -668,6 +670,7 @@ class LuaScriptInterface
  607.         static int luaItemCreate(lua_State* L);
  608.  
  609.         static int luaItemIsItem(lua_State* L);
  610. +       static int luaItemIsPokeball(lua_State* L);
  611.  
  612.         static int luaItemGetParent(lua_State* L);
  613.         static int luaItemGetTopParent(lua_State* L);
  614. @@ -730,6 +733,24 @@ class LuaScriptInterface
  615.         static int luaTeleportGetDestination(lua_State* L);
  616.         static int luaTeleportSetDestination(lua_State* L);
  617.  
  618. +       // Pokeball
  619. +       static int luaPokeballCreate(lua_State* L);
  620. +
  621. +       static int luaPokeballGetPokemonName(lua_State* L);
  622. +       static int luaPokeballSetPokemonName(lua_State* L);    
  623. +
  624. +       static int luaPokeballGetLevel(lua_State* L);
  625. +       static int luaPokeballSetLevel(lua_State* L);      
  626. +
  627. +       static int luaPokeballGetExperience(lua_State* L);
  628. +       static int luaPokeballSetExperience(lua_State* L);
  629. +
  630. +       static int luaPokeballGetHealth(lua_State* L);
  631. +       static int luaPokeballSetHealth(lua_State* L);
  632. +
  633. +       static int luaPokeballGetMaxHealth(lua_State* L);
  634. +       static int luaPokeballSetMaxHealth(lua_State* L);
  635. +
  636.         // Creature
  637.         static int luaCreatureCreate(lua_State* L);
  638.  
  639. diff --git a/forgottenserver-1.2/src/pokeball.cpp b/forgottenserver-1.2/src/pokeball.cpp
  640. new file mode 100644
  641. index 0000000..129f8d7
  642. --- /dev/null
  643. +++ b/forgottenserver-1.2/src/pokeball.cpp
  644. @@ -0,0 +1,98 @@
  645. +#include "otpch.h"
  646. +#include "Pokeball.h"
  647. +
  648. +Attr_ReadValue Pokeball::readAttr(AttrTypes_t attr, PropStream& propStream)
  649. +{
  650. +   if (attr == ATTR_POKEBALLINFO) {
  651. +       if (!propStream.read<std::string>(name)) {
  652. +           return ATTR_READ_ERROR;
  653. +       }
  654. +       else if (!propStream.read<uint32_t>(level)) {
  655. +           return ATTR_READ_ERROR;
  656. +       }
  657. +       else if (!propStream.read<uint64_t>(experience)) {
  658. +           return ATTR_READ_ERROR;
  659. +       }
  660. +       else if (!propStream.read<int32_t>(health)) {
  661. +           return ATTR_READ_ERROR;
  662. +       }
  663. +       else if (!propStream.read<int32_t>(healthMax)) {
  664. +           return ATTR_READ_ERROR;
  665. +       }
  666. +       return ATTR_READ_CONTINUE;
  667. +   }
  668. +
  669. +   return Item::readAttr(attr, propStream);
  670. +
  671. +}
  672. +void Pokeball::serializeAttr(PropWriteStream& propWriteStream) const
  673. +{
  674. +   Item::serializeAttr(propWriteStream);
  675. +
  676. +   propWriteStream.write<uint8_t>(ATTR_POKEBALLINFO);
  677. +   propWriteStream.write<std::string>(name);
  678. +   propWriteStream.write<uint32_t>(level);
  679. +   propWriteStream.write<uint64_t>(experience);
  680. +   propWriteStream.write<int32_t>(health);
  681. +   propWriteStream.write<int32_t>(healthMax);
  682. +}
  683. +
  684. +std::string Pokeball::getPokemonName()
  685. +{
  686. +   return name;
  687. +}
  688. +
  689. +void Pokeball::setPokemonName(std::string nName)
  690. +{
  691. +   name = nName;
  692. +}
  693. +
  694. +uint32_t Pokeball::getLevel()
  695. +{
  696. +   return level;
  697. +}
  698. +
  699. +void Pokeball::setLevel(uint32_t lvl)
  700. +{
  701. +   level = lvl;
  702. +}
  703. +
  704. +uint64_t Pokeball::getExperience()
  705. +{
  706. +   return experience;
  707. +}
  708. +
  709. +void Pokeball::setExperience(uint64_t exp)
  710. +{
  711. +   experience = exp;
  712. +
  713. +}
  714. +int32_t Pokeball::getHealth()
  715. +{
  716. +   return health;
  717. +}
  718. +
  719. +void Pokeball::setHealth(int32_t nhealth)
  720. +{
  721. +   health = nhealth;
  722. +}
  723. +
  724. +int32_t Pokeball::getMaxHealth()
  725. +{
  726. +   return healthMax;
  727. +}
  728. +
  729. +void Pokeball::setMaxHealth(int32_t mhealth)
  730. +{
  731. +   healthMax = mhealth;
  732. +}
  733. +
  734. +PokemonStatus Pokeball::getPokemonStatus()
  735. +{
  736. +   return status;
  737. +}
  738. +
  739. +void Pokeball::setPokemonStatus(PokemonStatus nStatus)
  740. +{
  741. +   status = nStatus;
  742. +}
  743. \ No newline at end of file
  744. diff --git a/forgottenserver-1.2/src/pokeball.h b/forgottenserver-1.2/src/pokeball.h
  745. new file mode 100644
  746. index 0000000..859098f
  747. --- /dev/null
  748. +++ b/forgottenserver-1.2/src/pokeball.h
  749. @@ -0,0 +1,49 @@
  750. +#include "item.h"
  751. +
  752. +class Pokeball final : public Item {
  753. +public:
  754. +   explicit Pokeball(uint16_t type) : Item(type) {};
  755. +
  756. +   Pokeball* getPokeball() final {
  757. +       return this;
  758. +   }
  759. +
  760. +   const Pokeball* getPokeball() const final {
  761. +       return this;
  762. +   }
  763. +
  764. +   Attr_ReadValue readAttr(AttrTypes_t attr, PropStream& propStream) final;
  765. +   void serializeAttr(PropWriteStream& propWriteStream) const;
  766. +
  767. +   std::string getPokemonName();
  768. +   void setPokemonName(std::string name);
  769. +
  770. +   uint32_t getLevel();
  771. +   void setLevel(uint32_t health);
  772. +
  773. +   uint64_t getExperience();
  774. +   void setExperience(uint64_t exp);
  775. +
  776. +   int32_t getHealth();
  777. +   void setHealth(int32_t health);
  778. +
  779. +   int32_t getMaxHealth();
  780. +   void setMaxHealth(int32_t maxHealth);
  781. +
  782. +   PokemonStatus getPokemonStatus();
  783. +   void setPokemonStatus(PokemonStatus status);
  784. +
  785. +private:
  786. +   std::string name = "";
  787. +   std::string nick = "";
  788. +
  789. +   uint32_t level = 1;
  790. +   uint64_t experience = 100;
  791. +
  792. +   int32_t health = 100;
  793. +   int32_t healthMax = 100;
  794. +
  795. +   PokemonStatus status;
  796. +};
  797. +
  798. +
  799. --
  800. 2.7.4.1.g5468f9e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement