Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ProtocolGame::sendMarketLeave()
- {
- NetworkMessage_ptr msg = getOutputBuffer();
- if(msg)
- {
- TRACK_MESSAGE(msg);
- msg->AddByte(0xF7);
- }
- }
- void ProtocolGame::sendMarketBrowseItem(uint16_t itemId, const MarketOfferList& buyOffers, const MarketOfferList& sellOffers)
- {
- NetworkMessage_ptr msg = getOutputBuffer();
- if(msg)
- {
- TRACK_MESSAGE(msg);
- msg->AddByte(0xF9);
- msg->AddU16(2160);
- msg->AddU32(buyOffers.size());
- for(MarketOfferList::const_iterator it = buyOffers.begin(), end = buyOffers.end(); it != end; ++it)
- {
- msg->AddU32(it->timestamp);
- msg->AddU16(it->counter);
- msg->AddU16(it->amount);
- msg->AddItemId(it->itemId);
- msg->AddU32(it->price);
- msg->AddString(it->playerName);
- const ItemType& itt = Item::items[it->itemId];
- Item* item = Item::CreateItem(itt.id, 1);
- std::stringstream test(it->Attrs);
- std::string segment;
- std::vector<std::string> seglist;
- if(it->Attrs != "false"){
- while(std::getline(test, segment, 'º'))
- {
- seglist.push_back(segment);
- }
- for(int i = 0; i < seglist.size(); i++) {
- std::stringstream test2(seglist[i]);
- std::string segment2;
- std::vector<std::string> seglist2;
- while(std::getline(test2, segment2, '#'))
- {
- seglist2.push_back(segment2);
- }
- if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
- item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
- }else{
- item->setAttribute(seglist2[0], seglist2[1]);
- }
- }
- }
- if(item->hasStringAttribute("poke")){
- msg->AddString(item->getPoke());
- }else{
- msg->AddString(item->getName());
- }
- delete item;
- }
- msg->AddU32(sellOffers.size());
- for(MarketOfferList::const_iterator it = sellOffers.begin(), end = sellOffers.end(); it != end; ++it)
- {
- msg->AddU32(it->timestamp);
- msg->AddU16(it->counter);
- msg->AddItemId(it->itemId);
- msg->AddU16(it->amount);
- msg->AddU32(it->price);
- msg->AddString(it->playerName);
- const ItemType& itt = Item::items[it->itemId];
- Item* item = Item::CreateItem(itt.id, 1);
- std::stringstream test(it->Attrs);
- std::string segment;
- std::vector<std::string> seglist;
- if(it->Attrs != "false"){
- while(std::getline(test, segment, 'º'))
- {
- seglist.push_back(segment);
- }
- for(int i = 0; i < seglist.size(); i++) {
- std::stringstream test2(seglist[i]);
- std::string segment2;
- std::vector<std::string> seglist2;
- while(std::getline(test2, segment2, '#'))
- {
- seglist2.push_back(segment2);
- }
- if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
- item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
- }else{
- item->setAttribute(seglist2[0], seglist2[1]);
- }
- }
- }
- if(item->hasStringAttribute("poke")){
- msg->AddString(item->getPoke());
- }else{
- msg->AddString(item->getName());
- }
- delete item;
- }
- }
- }
- void ProtocolGame::sendMarketAcceptOffer(MarketOfferEx offer)
- {
- NetworkMessage_ptr msg = getOutputBuffer();
- if(msg)
- {
- TRACK_MESSAGE(msg);
- msg->AddByte(0xF9);
- msg->AddItemId(offer.itemId);
- if(offer.type == MARKETACTION_BUY)
- {
- msg->AddU32(0x01);
- msg->AddU32(offer.timestamp);
- msg->AddU16(offer.counter);
- msg->AddU16(offer.amount);
- msg->AddItemId(offer.itemId);
- msg->AddU32(offer.price);
- msg->AddString(offer.playerName);
- msg->AddU32(0x00);
- const ItemType& itt = Item::items[offer.itemId];
- Item* item = Item::CreateItem(itt.id, 1);
- std::stringstream test(offer.Attrs);
- std::string segment;
- std::vector<std::string> seglist;
- if(offer.Attrs != "false"){
- while(std::getline(test, segment, 'º'))
- {
- seglist.push_back(segment);
- }
- for(int i = 0; i < seglist.size(); i++) {
- std::stringstream test2(seglist[i]);
- std::string segment2;
- std::vector<std::string> seglist2;
- while(std::getline(test2, segment2, '#'))
- {
- seglist2.push_back(segment2);
- }
- if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
- item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
- }else{
- item->setAttribute(seglist2[0], seglist2[1]);
- }
- }
- }
- if(item->hasStringAttribute("poke")){
- msg->AddString(item->getPoke());
- }else{
- msg->AddString(item->getName());
- }
- delete item;
- }
- else
- {
- msg->AddU32(0x00);
- msg->AddU32(0x01);
- msg->AddU32(offer.timestamp);
- msg->AddU16(offer.counter);
- msg->AddU16(offer.amount);
- msg->AddItemId(offer.itemId);
- msg->AddU32(offer.price);
- msg->AddString(offer.playerName);
- const ItemType& itt = Item::items[offer.itemId];
- Item* item = Item::CreateItem(itt.id, 1);
- std::stringstream test(offer.Attrs);
- std::string segment;
- std::vector<std::string> seglist;
- if(offer.Attrs != "false"){
- while(std::getline(test, segment, 'º'))
- {
- seglist.push_back(segment);
- }
- for(int i = 0; i < seglist.size(); i++) {
- std::stringstream test2(seglist[i]);
- std::string segment2;
- std::vector<std::string> seglist2;
- while(std::getline(test2, segment2, '#'))
- {
- seglist2.push_back(segment2);
- }
- if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
- item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
- }else{
- item->setAttribute(seglist2[0], seglist2[1]);
- }
- }
- }
- if(item->hasStringAttribute("poke")){
- msg->AddString(item->getPoke());
- }else{
- msg->AddString(item->getName());
- }
- delete item;
- }
- }
- }
- void ProtocolGame::sendMarketItemDesc(const std::string& desc, uint16_t itemId)
- {
- NetworkMessage_ptr msg = getOutputBuffer();
- if(msg)
- {
- TRACK_MESSAGE(msg);
- msg->AddByte(0xFF);
- msg->AddString(desc);
- msg->AddItemId(itemId);
- }
- }
- void ProtocolGame::sendMarketBrowseOwnOffers(const MarketOfferList& buyOffers, const MarketOfferList& sellOffers)
- {
- NetworkMessage_ptr msg = getOutputBuffer();
- if(msg)
- {
- TRACK_MESSAGE(msg);
- msg->AddByte(0xF9);
- msg->AddU16(MARKETREQUEST_OWN_OFFERS);
- msg->AddU32(buyOffers.size());
- for(MarketOfferList::const_iterator it = buyOffers.begin(), end = buyOffers.end(); it != end; ++it)
- {
- msg->AddU32(it->timestamp);
- msg->AddU16(it->counter);
- msg->AddItemId(it->itemId);
- msg->AddU16(it->amount);
- msg->AddU32(it->price);
- const ItemType& itt = Item::items[it->itemId];
- Item* item = Item::CreateItem(itt.id, 1);
- std::stringstream test(it->Attrs);
- std::string segment;
- std::vector<std::string> seglist;
- if(it->Attrs != "false"){
- while(std::getline(test, segment, 'º'))
- {
- seglist.push_back(segment);
- }
- for(int i = 0; i < seglist.size(); i++) {
- std::stringstream test2(seglist[i]);
- std::string segment2;
- std::vector<std::string> seglist2;
- while(std::getline(test2, segment2, '#'))
- {
- seglist2.push_back(segment2);
- }
- if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
- item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
- }else{
- item->setAttribute(seglist2[0], seglist2[1]);
- }
- }
- }
- if(item->hasStringAttribute("poke")){
- msg->AddString(item->getPoke());
- }else{
- msg->AddString(item->getName());
- }
- delete item;
- }
- msg->AddU32(sellOffers.size());
- for(MarketOfferList::const_iterator it = sellOffers.begin(), end = sellOffers.end(); it != end; ++it)
- {
- msg->AddU32(it->timestamp);
- msg->AddU16(it->counter);
- msg->AddItemId(it->itemId);
- msg->AddU16(it->amount);
- msg->AddU32(it->price);
- const ItemType& itt = Item::items[it->itemId];
- Item* item = Item::CreateItem(itt.id, 1);
- std::stringstream test(it->Attrs);
- std::string segment;
- std::vector<std::string> seglist;
- if(it->Attrs != "false"){
- while(std::getline(test, segment, 'º'))
- {
- seglist.push_back(segment);
- }
- for(int i = 0; i < seglist.size(); i++) {
- std::stringstream test2(seglist[i]);
- std::string segment2;
- std::vector<std::string> seglist2;
- while(std::getline(test2, segment2, '#'))
- {
- seglist2.push_back(segment2);
- }
- if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
- item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
- }else{
- item->setAttribute(seglist2[0], seglist2[1]);
- }
- }
- }
- if(item->hasStringAttribute("poke")){
- msg->AddString(item->getPoke());
- }else{
- msg->AddString(item->getName());
- }
- delete item;
- }
- }
- }
- void ProtocolGame::sendMarketCancelOffer(MarketOfferEx offer)
- {
- NetworkMessage_ptr msg = getOutputBuffer();
- if(msg)
- {
- TRACK_MESSAGE(msg);
- msg->AddByte(0xF9);
- msg->AddU16(MARKETREQUEST_OWN_OFFERS);
- if(offer.type == MARKETACTION_BUY)
- {
- msg->AddU32(0x01);
- msg->AddU32(offer.timestamp);
- msg->AddU16(offer.counter);
- msg->AddItemId(offer.itemId);
- msg->AddU16(offer.amount);
- msg->AddU32(offer.price);
- const ItemType& itt = Item::items[offer.itemId];
- Item* item = Item::CreateItem(itt.id, 1);
- std::stringstream test(offer.Attrs);
- std::string segment;
- std::vector<std::string> seglist;
- if(offer.Attrs != "false"){
- while(std::getline(test, segment, 'º'))
- {
- seglist.push_back(segment);
- }
- for(int i = 0; i < seglist.size(); i++) {
- std::stringstream test2(seglist[i]);
- std::string segment2;
- std::vector<std::string> seglist2;
- while(std::getline(test2, segment2, '#'))
- {
- seglist2.push_back(segment2);
- }
- if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
- item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
- }else{
- item->setAttribute(seglist2[0], seglist2[1]);
- }
- }
- }
- if(item->hasStringAttribute("poke")){
- msg->AddString(item->getPoke());
- }else{
- msg->AddString(item->getName());
- }
- msg->AddU32(0x00);
- delete item;
- }
- else
- {
- msg->AddU32(0x00);
- msg->AddU32(0x01);
- msg->AddU32(offer.timestamp);
- msg->AddU16(offer.counter);
- msg->AddItemId(offer.itemId);
- msg->AddU16(offer.amount);
- msg->AddU32(offer.price);
- const ItemType& itt = Item::items[offer.itemId];
- Item* item = Item::CreateItem(itt.id, 1);
- std::stringstream test(offer.Attrs);
- std::string segment;
- std::vector<std::string> seglist;
- if(offer.Attrs != "false"){
- while(std::getline(test, segment, 'º'))
- {
- seglist.push_back(segment);
- }
- for(int i = 0; i < seglist.size(); i++) {
- std::stringstream test2(seglist[i]);
- std::string segment2;
- std::vector<std::string> seglist2;
- while(std::getline(test2, segment2, '#'))
- {
- seglist2.push_back(segment2);
- }
- if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
- item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
- }else{
- item->setAttribute(seglist2[0], seglist2[1]);
- }
- }
- }
- if(item->hasStringAttribute("poke")){
- msg->AddString(item->getPoke());
- }else{
- msg->AddString(item->getName());
- }
- delete item;
- }
- }
- }
- void ProtocolGame::sendMarketBrowseOwnHistory(const HistoryMarketOfferList& buyOffers, const HistoryMarketOfferList& sellOffers)
- {
- NetworkMessage_ptr msg = getOutputBuffer();
- if(msg)
- {
- TRACK_MESSAGE(msg);
- msg->AddByte(0xF9);
- msg->AddU16(MARKETREQUEST_OWN_HISTORY);
- std::map<uint32_t, uint16_t> counterMap;
- uint32_t i = 0;
- msg->AddU32(std::min<int32_t>(800, buyOffers.size()));
- for(HistoryMarketOfferList::const_iterator it = buyOffers.begin(), end = buyOffers.end(); it != end && i < 800; ++it, ++i)
- {
- msg->AddU32(it->timestamp);
- msg->AddU16(counterMap[it->timestamp]++);
- msg->AddItemId(it->itemId);
- msg->AddU16(it->amount);
- msg->AddU32(it->price);
- msg->AddByte(it->state);
- const ItemType& itt = Item::items[it->itemId];
- Item* item = Item::CreateItem(itt.id, 1);
- std::stringstream test(it->Attrs);
- std::string segment;
- std::vector<std::string> seglist;
- if(it->Attrs != "false"){
- while(std::getline(test, segment, 'º'))
- {
- seglist.push_back(segment);
- }
- for(int i = 0; i < seglist.size(); i++) {
- std::stringstream test2(seglist[i]);
- std::string segment2;
- std::vector<std::string> seglist2;
- while(std::getline(test2, segment2, '#'))
- {
- seglist2.push_back(segment2);
- }
- if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
- item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
- }else{
- item->setAttribute(seglist2[0], seglist2[1]);
- }
- }
- }
- if(item->hasStringAttribute("poke")){
- msg->AddString(item->getPoke());
- }else{
- msg->AddString(item->getName());
- }
- delete item;
- }
- counterMap.clear();
- i = 0;
- msg->AddU32(std::min<int32_t>(800, sellOffers.size()));
- for(HistoryMarketOfferList::const_iterator it = sellOffers.begin(), end = sellOffers.end(); it != end && i < 800; ++it, ++i)
- {
- msg->AddU32(it->timestamp);
- msg->AddU16(counterMap[it->timestamp]++);
- msg->AddItemId(it->itemId);
- msg->AddU16(it->amount);
- msg->AddU32(it->price);
- msg->AddByte(it->state);
- const ItemType& itt = Item::items[it->itemId];
- Item* item = Item::CreateItem(itt.id, 1);
- std::stringstream test(it->Attrs);
- std::string segment;
- std::vector<std::string> seglist;
- if(it->Attrs != "false"){
- while(std::getline(test, segment, 'º'))
- {
- seglist.push_back(segment);
- }
- for(int i = 0; i < seglist.size(); i++) {
- std::stringstream test2(seglist[i]);
- std::string segment2;
- std::vector<std::string> seglist2;
- while(std::getline(test2, segment2, '#'))
- {
- seglist2.push_back(segment2);
- }
- if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
- item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
- }else{
- item->setAttribute(seglist2[0], seglist2[1]);
- }
- }
- }
- if(item->hasStringAttribute("poke")){
- msg->AddString(item->getPoke());
- }else{
- msg->AddString(item->getName());
- }
- delete item;
- }
- }
- }
- void ProtocolGame::sendMarketDetail(uint16_t itemId)
- {
- NetworkMessage_ptr msg = getOutputBuffer();
- if(msg)
- {
- TRACK_MESSAGE(msg);
- msg->AddByte(0xF8);
- msg->AddItemId(itemId);
- const ItemType& it = Item::items[itemId];
- std::ostringstream ss;
- if(it.armor != 0)
- {
- ss << it.armor;
- msg->AddString(ss.str());
- }
- else
- msg->AddU16(0x00);
- if(it.attack != 0)
- {
- ss.str("");
- ss << it.attack;
- if(it.abilities.elementType != COMBAT_NONE && it.decayTo > 0)
- ss << " physical +" << it.abilities.elementDamage << " " << getCombatName(it.abilities.elementType);
- // TODO: chance to hit, range
- // example:
- // "attack +x, chance to hit +y%, z fields"
- msg->AddString(ss.str());
- }
- else
- msg->AddU16(0x00);
- if(it.isContainer())
- {
- ss.str("");
- ss << it.maxItems;
- msg->AddString(ss.str());
- }
- else
- msg->AddU16(0x00);
- if(it.defense != 0)
- {
- ss.str("");
- ss << it.defense;
- if(it.extraDefense != 0)
- ss << " " << std::showpos << it.extraDefense << std::noshowpos;
- msg->AddString(ss.str());
- }
- else
- msg->AddU16(0x00);
- if(!it.description.empty())
- {
- std::string descr = it.description;
- if(descr[descr.length() - 1] == '.')
- descr.erase(descr.length() - 1);
- msg->AddString(descr);
- }
- else
- msg->AddU16(0x00);
- if(it.decayTime != 0)
- {
- ss.str("");
- ss << it.decayTime << " seconds";
- msg->AddString(ss.str());
- }
- else
- msg->AddU16(0x00);
- ss.str("");
- if(it.abilities.absorb)
- {
- bool separator = false;
- for(uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; ++i)
- {
- if(!it.abilities.absorb[i])
- continue;
- if(separator)
- ss << ", ";
- else
- separator = true;
- ss << getCombatName(indexToCombatType(i)) << " " << std::showpos << it.abilities.absorb[i] << std::noshowpos << "%";
- }
- }
- msg->AddString(ss.str());
- if(it.minReqLevel != 0)
- {
- ss.str("");
- ss << it.minReqLevel;
- msg->AddString(ss.str());
- }
- else
- msg->AddU16(0x00);
- if(it.minReqMagicLevel != 0)
- {
- ss.str("");
- ss << it.minReqMagicLevel;
- msg->AddString(ss.str());
- }
- else
- msg->AddU16(0x00);
- msg->AddString(it.vocationString);
- msg->AddString(it.runeSpellName);
- ss.str("");
- if(it.abilities.skills)
- {
- bool separator = false;
- for(uint16_t i = SKILL_FIRST; i <= SKILL_LAST; i++)
- {
- if(!it.abilities.skills[i])
- continue;
- if(separator)
- ss << ", ";
- else
- separator = true;
- ss << getSkillName(i) << " " << std::showpos << it.abilities.skills[i] << std::noshowpos;
- }
- if(it.abilities.stats[STAT_MAGICLEVEL] != 0)
- {
- if(separator)
- ss << ", ";
- else
- separator = true;
- ss << "magic level " << std::showpos << it.abilities.stats[STAT_MAGICLEVEL] << std::noshowpos;
- }
- if(it.abilities.speed != 0)
- {
- if(separator)
- ss << ", ";
- ss << "speed" << " " << std::showpos << (int32_t)(it.abilities.speed / 2) << std::noshowpos;
- }
- }
- msg->AddString(ss.str());
- if(it.charges != 0)
- {
- ss.str("");
- ss << it.charges;
- msg->AddString(ss.str());
- }
- else
- msg->AddU16(0x00);
- std::string weaponName = getWeaponName(it.weaponType);
- if(it.slotPosition & SLOTP_TWO_HAND)
- {
- if(!weaponName.empty())
- weaponName += ", two-handed";
- else
- weaponName = "two-handed";
- }
- msg->AddString(weaponName);
- if(it.weight > 0)
- {
- ss.str("");
- ss << std::fixed << std::setprecision(2) << it.weight << " oz";
- msg->AddString(ss.str());
- }
- else
- msg->AddU16(0x00);
- MarketStatistics* statistics = IOMarket::getInstance()->getPurchaseStatistics(itemId);
- if(statistics)
- {
- msg->AddByte(0x01);
- msg->AddU32(statistics->numTransactions);
- msg->AddU32(std::min<uint64_t>(0xFFFFFFFF, statistics->totalPrice));
- msg->AddU32(statistics->highestPrice);
- msg->AddU32(statistics->lowestPrice);
- }
- else
- msg->AddByte(0x00);
- statistics = IOMarket::getInstance()->getSaleStatistics(itemId);
- if(statistics)
- {
- msg->AddByte(0x01);
- msg->AddU32(statistics->numTransactions);
- msg->AddU32(std::min<uint64_t>(0xFFFFFFFF, statistics->totalPrice));
- msg->AddU32(statistics->highestPrice);
- msg->AddU32(statistics->lowestPrice);
- }
- else
- msg->AddByte(0x00);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement