Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool ConvertToShopItemTable(IN CGroupNode* pNode, OUT TShopTableEx& shopTable)
- {
- if (!pNode->GetValue("vnum", 0, shopTable.dwVnum))
- {
- sys_err("Group %s does not have vnum.", pNode->GetNodeName().c_str());
- return false;
- }
- if (!pNode->GetValue("name", 0, shopTable.name))
- {
- sys_err("Group %s does not have name.", pNode->GetNodeName().c_str());
- return false;
- }
- if (shopTable.name.length() >= SHOP_TAB_NAME_MAX)
- {
- sys_err("Shop name length must be less than %d. Error in Group %s, name %s", SHOP_TAB_NAME_MAX, pNode->GetNodeName().c_str(), shopTable.name.c_str());
- return false;
- }
- std::string stCoinType;
- if (!pNode->GetValue("cointype", 0, stCoinType))
- {
- stCoinType = "Gold";
- }
- if (boost::iequals(stCoinType, "Gold"))
- {
- shopTable.coinType = SHOP_COIN_TYPE_GOLD;
- }
- else if (boost::iequals(stCoinType, "SecondaryCoin"))
- {
- shopTable.coinType = SHOP_COIN_TYPE_SECONDARY_COIN;
- }
- else
- {
- sys_err("Group %s has undefine cointype(%s).", pNode->GetNodeName().c_str(), stCoinType.c_str());
- return false;
- }
- CGroupNode* pItemGroup = pNode->GetChildNode("items");
- if (!pItemGroup)
- {
- sys_err("Group %s does not have 'group items'.", pNode->GetNodeName().c_str());
- return false;
- }
- int itemGroupSize = pItemGroup->GetRowCount();
- std::vector <TShopItemTable> shopItems(itemGroupSize);
- if (itemGroupSize >= SHOP_HOST_ITEM_MAX_NUM)
- {
- sys_err("count(%d) of rows of group items of group %s must be smaller than %d", itemGroupSize, pNode->GetNodeName().c_str(), SHOP_HOST_ITEM_MAX_NUM);
- return false;
- }
- for (int i = 0; i < itemGroupSize; i++)
- {
- if (!pItemGroup->GetValue(i, "vnum", shopItems[i].vnum))
- {
- sys_err("row(%d) of group items of group %s does not have vnum column", i, pNode->GetNodeName().c_str());
- return false;
- }
- if (!pItemGroup->GetValue(i, "count", shopItems[i].count))
- {
- sys_err("row(%d) of group items of group %s does not have count column", i, pNode->GetNodeName().c_str());
- return false;
- }
- if (!pItemGroup->GetValue(i, "price", shopItems[i].price))
- {
- sys_err("row(%d) of group items of group %s does not have price column", i, pNode->GetNodeName().c_str());
- return false;
- }
- }
- std::string stSort;
- if (!pNode->GetValue("sort", 0, stSort))
- {
- stSort = "None";
- }
- if (boost::iequals(stSort, "Asc"))
- {
- std::sort(shopItems.begin(), shopItems.end(), CompareShopItemName);
- }
- else if(boost::iequals(stSort, "Desc"))
- {
- std::sort(shopItems.rbegin(), shopItems.rend(), CompareShopItemName);
- }
- CGrid grid = CGrid(5, 9);
- int iPos;
- memset(&shopTable.items[0], 0, sizeof(shopTable.items));
- for (int i = 0; i < shopItems.size(); i++)
- {
- TItemTable * item_table = ITEM_MANAGER::instance().GetTable(shopItems[i].vnum);
- if (!item_table)
- {
- sys_err("vnum(%d) of group items of group %s does not exist", shopItems[i].vnum, pNode->GetNodeName().c_str());
- return false;
- }
- iPos = grid.FindBlank(1, item_table->bSize);
- grid.Put(iPos, 1, item_table->bSize);
- shopTable.items[iPos] = shopItems[i];
- }
- shopTable.byItemCount = shopItems.size();
- return true;
- }
- bool CShopManager::ReadShopTableEx(const char* stFileName)
- {
- // file 유무 체크.
- // 없는 경우는 에러로 처리하지 않는다.
- FILE* fp = fopen(stFileName, "rb");
- if (NULL == fp)
- return true;
- fclose(fp);
- CGroupTextParseTreeLoader loader;
- if (!loader.Load(stFileName))
- {
- sys_err("%s Load fail.", stFileName);
- return false;
- }
- CGroupNode* pShopNPCGroup = loader.GetGroup("shopnpc");
- if (NULL == pShopNPCGroup)
- {
- sys_err("Group ShopNPC is not exist.");
- return false;
- }
- typedef std::multimap <DWORD, TShopTableEx> TMapNPCshop;
- TMapNPCshop map_npcShop;
- for (int i = 0; i < pShopNPCGroup->GetRowCount(); i++)
- {
- DWORD npcVnum;
- std::string shopName;
- if (!pShopNPCGroup->GetValue(i, "npc", npcVnum) || !pShopNPCGroup->GetValue(i, "group", shopName))
- {
- sys_err("Invalid row(%d). Group ShopNPC rows must have 'npc', 'group' columns", i);
- return false;
- }
- std::transform(shopName.begin(), shopName.end(), shopName.begin(), (int(*)(int))std::tolower);
- CGroupNode* pShopGroup = loader.GetGroup(shopName.c_str());
- if (!pShopGroup)
- {
- sys_err("Group %s is not exist.", shopName.c_str());
- return false;
- }
- TShopTableEx table;
- if (!ConvertToShopItemTable(pShopGroup, table))
- {
- sys_err("Cannot read Group %s.", shopName.c_str());
- return false;
- }
- if (m_map_pkShopByNPCVnum.find(npcVnum) != m_map_pkShopByNPCVnum.end())
- {
- sys_err("%d cannot have both original shop and extended shop", npcVnum);
- return false;
- }
- map_npcShop.insert(TMapNPCshop::value_type(npcVnum, table));
- }
- for (TMapNPCshop::iterator it = map_npcShop.begin(); it != map_npcShop.end(); ++it)
- {
- DWORD npcVnum = it->first;
- TShopTableEx& table = it->second;
- if (m_map_pkShop.find(table.dwVnum) != m_map_pkShop.end())
- {
- sys_err("Shop vnum(%d) already exists", table.dwVnum);
- return false;
- }
- TShopMap::iterator shop_it = m_map_pkShopByNPCVnum.find(npcVnum);
- LPSHOPEX pkShopEx = NULL;
- if (m_map_pkShopByNPCVnum.end() == shop_it)
- {
- pkShopEx = M2_NEW CShopEx;
- pkShopEx->Create(0, npcVnum);
- m_map_pkShopByNPCVnum.insert(TShopMap::value_type(npcVnum, pkShopEx));
- }
- else
- {
- pkShopEx = dynamic_cast <CShopEx*> (shop_it->second);
- if (NULL == pkShopEx)
- {
- sys_err("WTF!!! It can't be happend. NPC(%d) Shop is not extended version.", shop_it->first);
- return false;
- }
- }
- if (pkShopEx->GetTabCount() >= SHOP_TAB_COUNT_MAX)
- {
- sys_err("ShopEx cannot have tab more than %d", SHOP_TAB_COUNT_MAX);
- return false;
- }
- if (pkShopEx->GetVnum() != 0 && m_map_pkShop.find(pkShopEx->GetVnum()) != m_map_pkShop.end())
- {
- sys_err("Shop vnum(%d) already exist.", pkShopEx->GetVnum());
- return false;
- }
- m_map_pkShop.insert(TShopMap::value_type (pkShopEx->GetVnum(), pkShopEx));
- pkShopEx->AddShopTable(table);
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement