Otclient  14/8/2020
itemtype.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 
24 #include "thingtypemanager.h"
25 #include "thingtype.h"
26 #include "game.h"
27 
30 
32 {
33  m_category = ItemCategoryInvalid;
34 }
35 
37 {
38  m_null = false;
39 
40  m_category = (ItemCategory)node->getU8();
41 
42  node->getU32(); // flags
43 
44  static uint16 lastId = 99;
45  while(node->canRead()) {
46  uint8 attr = node->getU8();
47  if(attr == 0 || attr == 0xFF)
48  break;
49 
50  uint16 len = node->getU16();
51  switch(attr) {
52  case ItemTypeAttrServerId: {
53  uint16 serverId = node->getU16();
54  if(g_game.getClientVersion() < 960) {
55  if(serverId > 20000 && serverId < 20100) {
56  serverId -= 20000;
57  } else if(lastId > 99 && lastId != serverId - 1) {
58  while(lastId != serverId - 1) {
59  ItemTypePtr tmp(new ItemType);
60  tmp->setServerId(lastId++);
61  g_things.addItemType(tmp);
62  }
63  }
64  } else {
65  if(serverId > 30000 && serverId < 30100) {
66  serverId -= 30000;
67  } else if(lastId > 99 && lastId != serverId - 1) {
68  while(lastId != serverId - 1) {
69  ItemTypePtr tmp(new ItemType);
70  tmp->setServerId(lastId++);
71  g_things.addItemType(tmp);
72  }
73  }
74  }
75  setServerId(serverId);
76  lastId = serverId;
77  break;
78  }
80  setClientId(node->getU16());
81  break;
82  case ItemTypeAttrName:
83  setName(node->getString(len));
84  break;
86  m_attribs.set(ItemTypeAttrWritable, true);
87  break;
88  default:
89  node->skip(len); // skip attribute
90  break;
91  }
92  }
93 }
binarytree.h
ItemCategoryInvalid
@ ItemCategoryInvalid
Definition: itemtype.h:32
thingtypemanager.h
ItemType::unserialize
void unserialize(const BinaryTreePtr &node)
Definition: itemtype.cpp:36
ItemTypeAttrWritable
@ ItemTypeAttrWritable
Definition: itemtype.h:64
ItemTypeAttrClientId
@ ItemTypeAttrClientId
Definition: itemtype.h:52
Game::getClientVersion
int getClientVersion()
Definition: game.h:316
ItemTypeAttrServerId
@ ItemTypeAttrServerId
Definition: itemtype.h:51
g_game
Game g_game
Definition: game.cpp:37
ItemType::setServerId
void setServerId(uint16 serverId)
Definition: itemtype.h:137
uint16
uint16_t uint16
Definition: types.h:36
stdext::dynamic_storage::set
void set(const Key &k, const T &value)
Definition: dynamic_storage.h:35
ItemType::ItemType
ItemType()
Definition: itemtype.cpp:31
ItemCategory
ItemCategory
Definition: itemtype.h:31
ItemType
Definition: itemtype.h:130
ItemType::setName
void setName(const std::string &name)
Definition: itemtype.h:146
filestream.h
stdext::shared_object_ptr
Definition: shared_object.h:39
ThingTypeManager::addItemType
void addItemType(const ItemTypePtr &itemType)
Definition: thingtypemanager.cpp:332
game.h
ItemType::setClientId
void setClientId(uint16 clientId)
Definition: itemtype.h:140
ItemTypeAttrName
@ ItemTypeAttrName
Definition: itemtype.h:53
thingtype.h
g_things
ThingTypeManager g_things
Definition: thingtypemanager.cpp:38
uint8
uint8_t uint8
Definition: types.h:37