Advertisement
joadson

Protocolgame.cpp

Jan 13th, 2021
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.48 KB | None | 0 0
  1. void ProtocolGame::sendMarketLeave()
  2. {
  3.     NetworkMessage_ptr msg = getOutputBuffer();
  4.     if(msg)
  5.     {
  6.         TRACK_MESSAGE(msg);
  7.         msg->AddByte(0xF7);
  8.     }
  9.    
  10. }
  11.  
  12. void ProtocolGame::sendMarketBrowseItem(uint16_t itemId, const MarketOfferList& buyOffers, const MarketOfferList& sellOffers)
  13. {
  14.     NetworkMessage_ptr msg = getOutputBuffer();
  15.     if(msg)
  16.     {
  17.         TRACK_MESSAGE(msg);
  18.         msg->AddByte(0xF9);
  19.         msg->AddU16(2160);
  20.         msg->AddU32(buyOffers.size());
  21.         for(MarketOfferList::const_iterator it = buyOffers.begin(), end = buyOffers.end(); it != end; ++it)
  22.         {
  23.             msg->AddU32(it->timestamp);
  24.             msg->AddU16(it->counter);
  25.             msg->AddU16(it->amount);
  26.             msg->AddItemId(it->itemId);
  27.             msg->AddU32(it->price);
  28.             msg->AddString(it->playerName);
  29.             const ItemType& itt = Item::items[it->itemId];
  30.             Item* item = Item::CreateItem(itt.id, 1);
  31.             std::stringstream test(it->Attrs);
  32.             std::string segment;
  33.             std::vector<std::string> seglist;
  34.             if(it->Attrs != "false"){
  35.                 while(std::getline(test, segment, 'º'))
  36.                 {
  37.                     seglist.push_back(segment);
  38.                 }
  39.                 for(int i = 0; i < seglist.size(); i++) {
  40.                     std::stringstream test2(seglist[i]);
  41.                     std::string segment2;
  42.                     std::vector<std::string> seglist2;
  43.                     while(std::getline(test2, segment2, '#'))
  44.                     {
  45.                         seglist2.push_back(segment2);
  46.                     }
  47.                     if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
  48.                         item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
  49.                     }else{
  50.                         item->setAttribute(seglist2[0], seglist2[1]);
  51.                     }
  52.                 }
  53.             }
  54.             if(item->hasStringAttribute("poke")){
  55.                 msg->AddString(item->getPoke());
  56.             }else{
  57.                 msg->AddString(item->getName());
  58.             }
  59.             delete item;
  60.         }
  61.  
  62.         msg->AddU32(sellOffers.size());
  63.         for(MarketOfferList::const_iterator it = sellOffers.begin(), end = sellOffers.end(); it != end; ++it)
  64.         {
  65.             msg->AddU32(it->timestamp);
  66.             msg->AddU16(it->counter);
  67.             msg->AddItemId(it->itemId);
  68.             msg->AddU16(it->amount);
  69.             msg->AddU32(it->price);
  70.             msg->AddString(it->playerName);
  71.             const ItemType& itt = Item::items[it->itemId];
  72.             Item* item = Item::CreateItem(itt.id, 1);
  73.             std::stringstream test(it->Attrs);
  74.             std::string segment;
  75.             std::vector<std::string> seglist;
  76.             if(it->Attrs != "false"){
  77.                 while(std::getline(test, segment, 'º'))
  78.                 {
  79.                     seglist.push_back(segment);
  80.                 }
  81.                 for(int i = 0; i < seglist.size(); i++) {
  82.                     std::stringstream test2(seglist[i]);
  83.                     std::string segment2;
  84.                     std::vector<std::string> seglist2;
  85.                     while(std::getline(test2, segment2, '#'))
  86.                     {
  87.                         seglist2.push_back(segment2);
  88.                     }
  89.                     if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
  90.                         item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
  91.                     }else{
  92.                         item->setAttribute(seglist2[0], seglist2[1]);
  93.                     }
  94.                 }
  95.             }
  96.             if(item->hasStringAttribute("poke")){
  97.                 msg->AddString(item->getPoke());
  98.             }else{
  99.                 msg->AddString(item->getName());
  100.             }
  101.             delete item;
  102.         }
  103.     }
  104. }
  105.  
  106. void ProtocolGame::sendMarketAcceptOffer(MarketOfferEx offer)
  107. {
  108.     NetworkMessage_ptr msg = getOutputBuffer();
  109.     if(msg)
  110.     {
  111.         TRACK_MESSAGE(msg);
  112.         msg->AddByte(0xF9);
  113.         msg->AddItemId(offer.itemId);
  114.         if(offer.type == MARKETACTION_BUY)
  115.         {
  116.             msg->AddU32(0x01);
  117.             msg->AddU32(offer.timestamp);
  118.             msg->AddU16(offer.counter);
  119.             msg->AddU16(offer.amount);
  120.             msg->AddItemId(offer.itemId);
  121.             msg->AddU32(offer.price);
  122.             msg->AddString(offer.playerName);
  123.             msg->AddU32(0x00);
  124.             const ItemType& itt = Item::items[offer.itemId];
  125.             Item* item = Item::CreateItem(itt.id, 1);
  126.             std::stringstream test(offer.Attrs);
  127.             std::string segment;
  128.             std::vector<std::string> seglist;
  129.             if(offer.Attrs != "false"){
  130.                 while(std::getline(test, segment, 'º'))
  131.                 {
  132.                     seglist.push_back(segment);
  133.                 }
  134.                 for(int i = 0; i < seglist.size(); i++) {
  135.                     std::stringstream test2(seglist[i]);
  136.                     std::string segment2;
  137.                     std::vector<std::string> seglist2;
  138.                     while(std::getline(test2, segment2, '#'))
  139.                     {
  140.                         seglist2.push_back(segment2);
  141.                     }
  142.                     if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
  143.                         item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
  144.                     }else{
  145.                         item->setAttribute(seglist2[0], seglist2[1]);
  146.                     }
  147.                 }
  148.             }
  149.             if(item->hasStringAttribute("poke")){
  150.                 msg->AddString(item->getPoke());
  151.             }else{
  152.                 msg->AddString(item->getName());
  153.             }
  154.             delete item;
  155.         }
  156.         else
  157.         {
  158.             msg->AddU32(0x00);
  159.             msg->AddU32(0x01);
  160.             msg->AddU32(offer.timestamp);
  161.             msg->AddU16(offer.counter);
  162.             msg->AddU16(offer.amount);
  163.             msg->AddItemId(offer.itemId);
  164.             msg->AddU32(offer.price);
  165.             msg->AddString(offer.playerName);
  166.             const ItemType& itt = Item::items[offer.itemId];
  167.             Item* item = Item::CreateItem(itt.id, 1);
  168.             std::stringstream test(offer.Attrs);
  169.             std::string segment;
  170.             std::vector<std::string> seglist;
  171.             if(offer.Attrs != "false"){
  172.                 while(std::getline(test, segment, 'º'))
  173.                 {
  174.                     seglist.push_back(segment);
  175.                 }
  176.                 for(int i = 0; i < seglist.size(); i++) {
  177.                     std::stringstream test2(seglist[i]);
  178.                     std::string segment2;
  179.                     std::vector<std::string> seglist2;
  180.                     while(std::getline(test2, segment2, '#'))
  181.                     {
  182.                         seglist2.push_back(segment2);
  183.                     }
  184.                     if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
  185.                         item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
  186.                     }else{
  187.                         item->setAttribute(seglist2[0], seglist2[1]);
  188.                     }
  189.                 }
  190.             }
  191.             if(item->hasStringAttribute("poke")){
  192.                 msg->AddString(item->getPoke());
  193.             }else{
  194.                 msg->AddString(item->getName());
  195.             }
  196.             delete item;
  197.         }
  198.     }
  199. }
  200.  
  201. void ProtocolGame::sendMarketItemDesc(const std::string& desc, uint16_t itemId)
  202. {
  203.     NetworkMessage_ptr msg = getOutputBuffer();
  204.     if(msg)
  205.     {
  206.         TRACK_MESSAGE(msg);
  207.         msg->AddByte(0xFF);
  208.         msg->AddString(desc);
  209.         msg->AddItemId(itemId);
  210.     }
  211. }
  212.  
  213. void ProtocolGame::sendMarketBrowseOwnOffers(const MarketOfferList& buyOffers, const MarketOfferList& sellOffers)
  214. {
  215.     NetworkMessage_ptr msg = getOutputBuffer();
  216.     if(msg)
  217.     {
  218.         TRACK_MESSAGE(msg);
  219.         msg->AddByte(0xF9);
  220.         msg->AddU16(MARKETREQUEST_OWN_OFFERS);
  221.  
  222.         msg->AddU32(buyOffers.size());
  223.         for(MarketOfferList::const_iterator it = buyOffers.begin(), end = buyOffers.end(); it != end; ++it)
  224.         {
  225.             msg->AddU32(it->timestamp);
  226.             msg->AddU16(it->counter);
  227.             msg->AddItemId(it->itemId);
  228.             msg->AddU16(it->amount);
  229.             msg->AddU32(it->price);
  230.             const ItemType& itt = Item::items[it->itemId];
  231.             Item* item = Item::CreateItem(itt.id, 1);
  232.             std::stringstream test(it->Attrs);
  233.             std::string segment;
  234.             std::vector<std::string> seglist;
  235.             if(it->Attrs != "false"){
  236.                 while(std::getline(test, segment, 'º'))
  237.                 {
  238.                     seglist.push_back(segment);
  239.                 }
  240.                 for(int i = 0; i < seglist.size(); i++) {
  241.                     std::stringstream test2(seglist[i]);
  242.                     std::string segment2;
  243.                     std::vector<std::string> seglist2;
  244.                     while(std::getline(test2, segment2, '#'))
  245.                     {
  246.                         seglist2.push_back(segment2);
  247.                     }
  248.                     if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
  249.                         item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
  250.                     }else{
  251.                         item->setAttribute(seglist2[0], seglist2[1]);
  252.                     }
  253.                 }
  254.             }
  255.             if(item->hasStringAttribute("poke")){
  256.                 msg->AddString(item->getPoke());
  257.             }else{
  258.                 msg->AddString(item->getName());
  259.             }
  260.             delete item;
  261.         }
  262.  
  263.         msg->AddU32(sellOffers.size());
  264.         for(MarketOfferList::const_iterator it = sellOffers.begin(), end = sellOffers.end(); it != end; ++it)
  265.         {
  266.             msg->AddU32(it->timestamp);
  267.             msg->AddU16(it->counter);
  268.             msg->AddItemId(it->itemId);
  269.             msg->AddU16(it->amount);
  270.             msg->AddU32(it->price);
  271.             const ItemType& itt = Item::items[it->itemId];
  272.             Item* item = Item::CreateItem(itt.id, 1);
  273.             std::stringstream test(it->Attrs);
  274.             std::string segment;
  275.             std::vector<std::string> seglist;
  276.             if(it->Attrs != "false"){
  277.                 while(std::getline(test, segment, 'º'))
  278.                 {
  279.                     seglist.push_back(segment);
  280.                 }
  281.                 for(int i = 0; i < seglist.size(); i++) {
  282.                     std::stringstream test2(seglist[i]);
  283.                     std::string segment2;
  284.                     std::vector<std::string> seglist2;
  285.                     while(std::getline(test2, segment2, '#'))
  286.                     {
  287.                         seglist2.push_back(segment2);
  288.                     }
  289.                     if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
  290.                         item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
  291.                     }else{
  292.                         item->setAttribute(seglist2[0], seglist2[1]);
  293.                     }
  294.                 }
  295.             }
  296.             if(item->hasStringAttribute("poke")){
  297.                 msg->AddString(item->getPoke());
  298.             }else{
  299.                 msg->AddString(item->getName());
  300.             }
  301.             delete item;
  302.         }
  303.     }  
  304. }
  305.  
  306. void ProtocolGame::sendMarketCancelOffer(MarketOfferEx offer)
  307. {
  308.     NetworkMessage_ptr msg = getOutputBuffer();
  309.     if(msg)
  310.     {
  311.         TRACK_MESSAGE(msg);
  312.         msg->AddByte(0xF9);
  313.         msg->AddU16(MARKETREQUEST_OWN_OFFERS);
  314.         if(offer.type == MARKETACTION_BUY)
  315.         {
  316.             msg->AddU32(0x01);
  317.             msg->AddU32(offer.timestamp);
  318.             msg->AddU16(offer.counter);
  319.             msg->AddItemId(offer.itemId);
  320.             msg->AddU16(offer.amount);
  321.             msg->AddU32(offer.price);
  322.             const ItemType& itt = Item::items[offer.itemId];
  323.             Item* item = Item::CreateItem(itt.id, 1);
  324.             std::stringstream test(offer.Attrs);
  325.             std::string segment;
  326.             std::vector<std::string> seglist;
  327.             if(offer.Attrs != "false"){
  328.                 while(std::getline(test, segment, 'º'))
  329.                 {
  330.                     seglist.push_back(segment);
  331.                 }
  332.                 for(int i = 0; i < seglist.size(); i++) {
  333.                     std::stringstream test2(seglist[i]);
  334.                     std::string segment2;
  335.                     std::vector<std::string> seglist2;
  336.                     while(std::getline(test2, segment2, '#'))
  337.                     {
  338.                         seglist2.push_back(segment2);
  339.                     }
  340.                     if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
  341.                         item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
  342.                     }else{
  343.                         item->setAttribute(seglist2[0], seglist2[1]);
  344.                     }
  345.                 }
  346.             }
  347.             if(item->hasStringAttribute("poke")){
  348.                 msg->AddString(item->getPoke());
  349.             }else{
  350.                 msg->AddString(item->getName());
  351.             }
  352.             msg->AddU32(0x00);
  353.             delete item;
  354.         }
  355.         else
  356.         {
  357.             msg->AddU32(0x00);
  358.             msg->AddU32(0x01);
  359.             msg->AddU32(offer.timestamp);
  360.             msg->AddU16(offer.counter);
  361.             msg->AddItemId(offer.itemId);
  362.             msg->AddU16(offer.amount);
  363.             msg->AddU32(offer.price);
  364.             const ItemType& itt = Item::items[offer.itemId];
  365.             Item* item = Item::CreateItem(itt.id, 1);
  366.             std::stringstream test(offer.Attrs);
  367.             std::string segment;
  368.             std::vector<std::string> seglist;
  369.             if(offer.Attrs != "false"){
  370.                 while(std::getline(test, segment, 'º'))
  371.                 {
  372.                     seglist.push_back(segment);
  373.                 }
  374.                 for(int i = 0; i < seglist.size(); i++) {
  375.                     std::stringstream test2(seglist[i]);
  376.                     std::string segment2;
  377.                     std::vector<std::string> seglist2;
  378.                     while(std::getline(test2, segment2, '#'))
  379.                     {
  380.                         seglist2.push_back(segment2);
  381.                     }
  382.                     if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
  383.                         item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
  384.                     }else{
  385.                         item->setAttribute(seglist2[0], seglist2[1]);
  386.                     }
  387.                 }
  388.             }
  389.             if(item->hasStringAttribute("poke")){
  390.                 msg->AddString(item->getPoke());
  391.             }else{
  392.                 msg->AddString(item->getName());
  393.             }
  394.             delete item;
  395.         }
  396.     }
  397. }
  398.  
  399. void ProtocolGame::sendMarketBrowseOwnHistory(const HistoryMarketOfferList& buyOffers, const HistoryMarketOfferList& sellOffers)
  400. {
  401.     NetworkMessage_ptr msg = getOutputBuffer();
  402.     if(msg)
  403.     {
  404.         TRACK_MESSAGE(msg);
  405.         msg->AddByte(0xF9);
  406.         msg->AddU16(MARKETREQUEST_OWN_HISTORY);
  407.  
  408.         std::map<uint32_t, uint16_t> counterMap;
  409.  
  410.         uint32_t i = 0;
  411.         msg->AddU32(std::min<int32_t>(800, buyOffers.size()));
  412.         for(HistoryMarketOfferList::const_iterator it = buyOffers.begin(), end = buyOffers.end(); it != end && i < 800; ++it, ++i)
  413.         {
  414.             msg->AddU32(it->timestamp);
  415.             msg->AddU16(counterMap[it->timestamp]++);
  416.             msg->AddItemId(it->itemId);
  417.             msg->AddU16(it->amount);
  418.             msg->AddU32(it->price);
  419.             msg->AddByte(it->state);
  420.             const ItemType& itt = Item::items[it->itemId];
  421.             Item* item = Item::CreateItem(itt.id, 1);
  422.             std::stringstream test(it->Attrs);
  423.             std::string segment;
  424.             std::vector<std::string> seglist;
  425.             if(it->Attrs != "false"){
  426.                 while(std::getline(test, segment, 'º'))
  427.                 {
  428.                     seglist.push_back(segment);
  429.                 }
  430.                 for(int i = 0; i < seglist.size(); i++) {
  431.                     std::stringstream test2(seglist[i]);
  432.                     std::string segment2;
  433.                     std::vector<std::string> seglist2;
  434.                     while(std::getline(test2, segment2, '#'))
  435.                     {
  436.                         seglist2.push_back(segment2);
  437.                     }
  438.                     if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
  439.                         item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
  440.                     }else{
  441.                         item->setAttribute(seglist2[0], seglist2[1]);
  442.                     }
  443.                 }
  444.             }
  445.             if(item->hasStringAttribute("poke")){
  446.                 msg->AddString(item->getPoke());
  447.             }else{
  448.                 msg->AddString(item->getName());
  449.             }
  450.             delete item;
  451.         }
  452.  
  453.         counterMap.clear();
  454.         i = 0;
  455.  
  456.         msg->AddU32(std::min<int32_t>(800, sellOffers.size()));
  457.         for(HistoryMarketOfferList::const_iterator it = sellOffers.begin(), end = sellOffers.end(); it != end && i < 800; ++it, ++i)
  458.         {
  459.             msg->AddU32(it->timestamp);
  460.             msg->AddU16(counterMap[it->timestamp]++);
  461.             msg->AddItemId(it->itemId);
  462.             msg->AddU16(it->amount);
  463.             msg->AddU32(it->price);
  464.             msg->AddByte(it->state);
  465.             const ItemType& itt = Item::items[it->itemId];
  466.             Item* item = Item::CreateItem(itt.id, 1);
  467.             std::stringstream test(it->Attrs);
  468.             std::string segment;
  469.             std::vector<std::string> seglist;
  470.             if(it->Attrs != "false"){
  471.                 while(std::getline(test, segment, 'º'))
  472.                 {
  473.                     seglist.push_back(segment);
  474.                 }
  475.                 for(int i = 0; i < seglist.size(); i++) {
  476.                     std::stringstream test2(seglist[i]);
  477.                     std::string segment2;
  478.                     std::vector<std::string> seglist2;
  479.                     while(std::getline(test2, segment2, '#'))
  480.                     {
  481.                         seglist2.push_back(segment2);
  482.                     }
  483.                     if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
  484.                         item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
  485.                     }else{
  486.                         item->setAttribute(seglist2[0], seglist2[1]);
  487.                     }
  488.                 }
  489.             }
  490.             if(item->hasStringAttribute("poke")){
  491.                 msg->AddString(item->getPoke());
  492.             }else{
  493.                 msg->AddString(item->getName());
  494.             }
  495.             delete item;
  496.         }
  497.     }
  498. }
  499.  
  500. void ProtocolGame::sendMarketDetail(uint16_t itemId)
  501. {
  502.     NetworkMessage_ptr msg = getOutputBuffer();
  503.     if(msg)
  504.     {
  505.         TRACK_MESSAGE(msg);
  506.     msg->AddByte(0xF8);
  507.     msg->AddItemId(itemId);
  508.  
  509.     const ItemType& it = Item::items[itemId];
  510.     std::ostringstream ss;
  511.     if(it.armor != 0)
  512.     {
  513.         ss << it.armor;
  514.         msg->AddString(ss.str());
  515.     }
  516.     else
  517.         msg->AddU16(0x00);
  518.  
  519.     if(it.attack != 0)
  520.     {
  521.         ss.str("");
  522.         ss << it.attack;
  523.         if(it.abilities.elementType != COMBAT_NONE && it.decayTo > 0)
  524.             ss << " physical +" << it.abilities.elementDamage << " " << getCombatName(it.abilities.elementType);
  525.  
  526.         // TODO: chance to hit, range
  527.         // example:
  528.         // "attack +x, chance to hit +y%, z fields"
  529.  
  530.         msg->AddString(ss.str());
  531.     }
  532.     else
  533.         msg->AddU16(0x00);
  534.  
  535.     if(it.isContainer())
  536.     {
  537.         ss.str("");
  538.         ss << it.maxItems;
  539.         msg->AddString(ss.str());
  540.     }
  541.     else
  542.         msg->AddU16(0x00);
  543.  
  544.     if(it.defense != 0)
  545.     {
  546.         ss.str("");
  547.         ss << it.defense;
  548.         if(it.extraDefense != 0)
  549.             ss << " " << std::showpos << it.extraDefense << std::noshowpos;
  550.  
  551.         msg->AddString(ss.str());
  552.     }
  553.     else
  554.         msg->AddU16(0x00);
  555.  
  556.     if(!it.description.empty())
  557.     {
  558.         std::string descr = it.description;
  559.         if(descr[descr.length() - 1] == '.')
  560.             descr.erase(descr.length() - 1);
  561.  
  562.         msg->AddString(descr);
  563.     }
  564.     else
  565.         msg->AddU16(0x00);
  566.  
  567.     if(it.decayTime != 0)
  568.     {
  569.         ss.str("");
  570.         ss << it.decayTime << " seconds";
  571.         msg->AddString(ss.str());
  572.     }
  573.     else
  574.         msg->AddU16(0x00);
  575.  
  576.     ss.str("");
  577.     if(it.abilities.absorb)
  578.     {
  579.         bool separator = false;
  580.         for(uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; ++i)
  581.         {
  582.             if(!it.abilities.absorb[i])
  583.                 continue;
  584.  
  585.             if(separator)
  586.                 ss << ", ";
  587.             else
  588.                 separator = true;
  589.  
  590.             ss << getCombatName(indexToCombatType(i)) << " " << std::showpos << it.abilities.absorb[i] << std::noshowpos << "%";
  591.         }
  592.     }
  593.     msg->AddString(ss.str());
  594.  
  595.     if(it.minReqLevel != 0)
  596.     {
  597.         ss.str("");
  598.         ss << it.minReqLevel;
  599.         msg->AddString(ss.str());
  600.     }
  601.     else
  602.         msg->AddU16(0x00);
  603.  
  604.     if(it.minReqMagicLevel != 0)
  605.     {
  606.         ss.str("");
  607.         ss << it.minReqMagicLevel;
  608.         msg->AddString(ss.str());
  609.     }
  610.     else
  611.         msg->AddU16(0x00);
  612.  
  613.     msg->AddString(it.vocationString);
  614.  
  615.     msg->AddString(it.runeSpellName);
  616.  
  617.     ss.str("");
  618.     if(it.abilities.skills)
  619.     {
  620.         bool separator = false;
  621.         for(uint16_t i = SKILL_FIRST; i <= SKILL_LAST; i++)
  622.         {
  623.             if(!it.abilities.skills[i])
  624.                 continue;
  625.  
  626.             if(separator)
  627.                 ss << ", ";
  628.             else
  629.                 separator = true;
  630.  
  631.             ss << getSkillName(i) << " " << std::showpos << it.abilities.skills[i] << std::noshowpos;
  632.         }
  633.  
  634.         if(it.abilities.stats[STAT_MAGICLEVEL] != 0)
  635.         {
  636.             if(separator)
  637.                 ss << ", ";
  638.             else
  639.                 separator = true;
  640.  
  641.             ss << "magic level " << std::showpos << it.abilities.stats[STAT_MAGICLEVEL] << std::noshowpos;
  642.         }
  643.  
  644.         if(it.abilities.speed != 0)
  645.         {
  646.             if(separator)
  647.                 ss << ", ";
  648.  
  649.             ss << "speed" << " " << std::showpos << (int32_t)(it.abilities.speed / 2) << std::noshowpos;
  650.         }
  651.     }
  652.     msg->AddString(ss.str());
  653.  
  654.     if(it.charges != 0)
  655.     {
  656.         ss.str("");
  657.         ss << it.charges;
  658.         msg->AddString(ss.str());
  659.     }
  660.     else
  661.         msg->AddU16(0x00);
  662.  
  663.     std::string weaponName = getWeaponName(it.weaponType);
  664.     if(it.slotPosition & SLOTP_TWO_HAND)
  665.     {
  666.         if(!weaponName.empty())
  667.             weaponName += ", two-handed";
  668.         else
  669.             weaponName = "two-handed";
  670.     }
  671.     msg->AddString(weaponName);
  672.  
  673.     if(it.weight > 0)
  674.     {
  675.         ss.str("");
  676.         ss << std::fixed << std::setprecision(2) << it.weight << " oz";
  677.         msg->AddString(ss.str());
  678.     }
  679.     else
  680.         msg->AddU16(0x00);
  681.  
  682.     MarketStatistics* statistics = IOMarket::getInstance()->getPurchaseStatistics(itemId);
  683.     if(statistics)
  684.     {
  685.         msg->AddByte(0x01);
  686.         msg->AddU32(statistics->numTransactions);
  687.         msg->AddU32(std::min<uint64_t>(0xFFFFFFFF, statistics->totalPrice));
  688.         msg->AddU32(statistics->highestPrice);
  689.         msg->AddU32(statistics->lowestPrice);
  690.     }
  691.     else
  692.         msg->AddByte(0x00);
  693.  
  694.     statistics = IOMarket::getInstance()->getSaleStatistics(itemId);
  695.     if(statistics)
  696.     {
  697.         msg->AddByte(0x01);
  698.         msg->AddU32(statistics->numTransactions);
  699.         msg->AddU32(std::min<uint64_t>(0xFFFFFFFF, statistics->totalPrice));
  700.         msg->AddU32(statistics->highestPrice);
  701.         msg->AddU32(statistics->lowestPrice);
  702.     }
  703.     else
  704.         msg->AddByte(0x00);
  705.  
  706.     }
  707. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement