Guest User

acce.cpp

a guest
Nov 19th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.61 KB | None | 0 0
  1. #define _acce_cpp_
  2. #include "stdafx.h"
  3. #include "config.h"
  4. #include "constants.h"
  5. #include "utils.h"
  6. #include "log.h"
  7. #include "char.h"
  8. #include "dev_log.h"
  9. #include "locale_service.h"
  10. #include "item.h"
  11. #include "item_manager.h"
  12. #include <stdlib.h>
  13. #include <sstream>
  14. #define RETURN_IF_ACCE_IS_NOT_OPENED(ch) if (!(ch)->IsAcceOpen()) return
  15.  
  16. extern int test_server;
  17. static std::vector<ACCE_DATA*>  s_acce_proto;
  18. static bool s_isInitializedAcceMaterialInformation = false;
  19.  
  20. enum EAcceResultCategory
  21. {
  22.     ACCE_CATEGORY_POTION,
  23.     ACCE_CATEGORY_WEAPON,
  24.     ACCE_CATEGORY_ARMOR,
  25.     ACCE_CATEGORY_ACCESSORY,
  26.     ACCE_CATEGORY_ETC,
  27. };
  28.  
  29. typedef std::vector<ACCE_VALUE> TAcceValueVector;
  30.  
  31. struct SAcceMaterialInfo
  32. {
  33.     SAcceMaterialInfo()
  34.     {
  35.         bHaveComplicateMaterial = false;
  36.     };
  37.    
  38.     ACCE_VALUE          reward;
  39.     TAcceValueVector    material;
  40.     DWORD               gold;
  41.     TAcceValueVector    complicateMaterial;
  42.    
  43.     std::string         infoText;
  44.     bool                bHaveComplicateMaterial;
  45. };
  46.  
  47. struct SItemNameAndLevel
  48. {
  49.     SItemNameAndLevel() { level = 0; }
  50.    
  51.     std::string     name;
  52.     int             level;
  53. };
  54.  
  55. typedef std::vector<SAcceMaterialInfo>                              TAcceResultList;
  56. typedef boost::unordered_map<DWORD, TAcceResultList>                TAcceMapByNPC;
  57. typedef boost::unordered_map<DWORD, std::string>                    TAcceResultInfoTextByNPC;
  58.  
  59. TAcceMapByNPC acce_info_map;
  60. TAcceResultInfoTextByNPC acce_result_info_map_by_npc;
  61.  
  62. class CAcceMaterialInfoHelper
  63. {
  64. public:
  65. public:
  66. };
  67.  
  68. static bool FN_check_item_count(LPITEM *items, DWORD item_vnum, int need_count)
  69. {
  70.     int count = 0;
  71.     for (int i=0; i<ACCE_MAX_NUM; ++i)
  72.     {
  73.         if (NULL == items[i])
  74.             continue;
  75.        
  76.         if (item_vnum==items[i]->GetVnum())
  77.         {
  78.             count += items[i]->GetCount();
  79.         }
  80.     }
  81.    
  82.     return (count>=need_count);
  83. }
  84.  
  85. static void FN_remove_material(LPITEM *items, DWORD item_vnum, int need_count, int result)
  86. {
  87.     int     count = 0;
  88.     LPITEM  item = NULL;
  89.    
  90.     item = items[1];
  91.     if (item != NULL)
  92.     {
  93.         item->SetCount(0);
  94.         items[1] = NULL;
  95.     }
  96.    
  97.     if (result == 1)
  98.     {
  99.         item = items[0];
  100.         if (item != NULL)
  101.         {
  102.             item->SetCount(0);
  103.             items[0] = NULL;
  104.         }
  105.     }
  106. }
  107.  
  108. static ACCE_DATA* FN_find_acce(LPITEM *items, WORD npc_vnum)
  109. {
  110.     DWORD   i, end_index;
  111.    
  112.     if (npc_vnum == 0)
  113.         return NULL;
  114.    
  115.     end_index = s_acce_proto.size();
  116.     for (i = 0; i < end_index; ++i)
  117.     {
  118.         if ( s_acce_proto[i]->can_make_item(items, npc_vnum) )
  119.             return s_acce_proto[i];
  120.     }
  121.    
  122.     return NULL;
  123. }
  124.  
  125. static bool FN_check_valid_npc(WORD vnum)
  126. {
  127.     for (std::vector<ACCE_DATA*>::iterator iter = s_acce_proto.begin(); iter != s_acce_proto.end(); iter++)
  128.     {
  129.         if (std::find((*iter)->npc_vnum.begin(), (*iter)->npc_vnum.end(), vnum) != (*iter)->npc_vnum.end())
  130.             return true;
  131.     }
  132.    
  133.     return false;
  134. }
  135.  
  136. static bool FN_check_acce_data(ACCE_DATA *acce_data)
  137. {
  138.     DWORD   i = 0;
  139.     DWORD   end_index = 0;
  140.    
  141.     end_index = acce_data->npc_vnum.size();
  142.     for (i=0; i<end_index; ++i)
  143.     {
  144.         if ( acce_data->npc_vnum[i] == 0 )
  145.             return false;
  146.     }
  147.    
  148.     end_index = acce_data->item.size();
  149.     for (i=0; i<end_index; ++i)
  150.     {
  151.         if ( acce_data->item[i].vnum == 0 )
  152.             return false;
  153.        
  154.         if ( acce_data->item[i].count == 0 )
  155.             return false;
  156.     }
  157.    
  158.     end_index = acce_data->reward.size();
  159.     for (i=0; i<end_index; ++i)
  160.     {
  161.         if (acce_data->reward[i].vnum == 0)
  162.             return false;
  163.        
  164.         if (acce_data->reward[i].count == 0)
  165.             return false;
  166.     }
  167.    
  168.     return true;
  169. }
  170.  
  171. ACCE_DATA::ACCE_DATA()
  172. {
  173.     this->percent = 0;
  174.     this->gold = 0;
  175.     this->abs_chance_min = 0;
  176.     this->abs_chance_max = 0;
  177. }
  178.  
  179. bool ACCE_DATA::can_make_item(LPITEM *items, WORD npc_vnum)
  180. {
  181.     DWORD   i, end_index;
  182.     DWORD   need_vnum;
  183.     int     need_count;
  184.     int     found_npc = false;
  185.    
  186.     end_index = this->npc_vnum.size();
  187.     for (i=0; i<end_index; ++i)
  188.     {
  189.         if (npc_vnum == this->npc_vnum[i])
  190.             found_npc = true;
  191.     }
  192.    
  193.     if (false == found_npc)
  194.         return false;
  195.    
  196.     end_index = this->item.size();
  197.     for (i=0; i<end_index; ++i)
  198.     {
  199.         need_vnum = this->item[i].vnum;
  200.         need_count = this->item[i].count;
  201.        
  202.         if (false == FN_check_item_count(items, need_vnum, need_count))
  203.             return false;
  204.     }
  205.    
  206.     return true;
  207. }
  208.  
  209. ACCE_VALUE* ACCE_DATA::reward_value()
  210. {
  211.     int     end_index       = 0;
  212.     DWORD   reward_index    = 0;
  213.    
  214.     end_index = this->reward.size();
  215.     reward_index = number(0, end_index);
  216.     reward_index = number(0, end_index-1);
  217.     return &this->reward[reward_index];
  218. }
  219.  
  220. void ACCE_DATA::remove_material(LPCHARACTER ch, int result)
  221. {
  222.     DWORD   i, end_index;
  223.     DWORD   need_vnum;
  224.     int     need_count;
  225.     LPITEM  *items = ch->GetAcceItem();
  226.    
  227.     end_index = this->item.size();
  228.     for (i = 0; i < ACCE_MAX_NUM; ++i)
  229.     {
  230.         need_vnum = this->item[i].vnum;
  231.         need_count = this->item[i].count;
  232.        
  233.         FN_remove_material(items, need_vnum, need_count, result);
  234.     }
  235. }
  236.  
  237. void Acce_clean_item(LPCHARACTER ch)
  238. {
  239.     LPITEM  *acce_item;
  240.    
  241.     acce_item = ch->GetAcceItem();
  242.     for (int i=0; i<ACCE_MAX_NUM; ++i)
  243.     {
  244.         if (acce_item[i] == NULL)
  245.             continue;
  246.        
  247.         if (acce_item[i]->GetType() == ITEM_COSTUME && acce_item[i]->GetSubType() == COSTUME_ACCE && acce_item[i]->GetType() != ITEM_WEAPON && acce_item[i]->GetType() != ITEM_ARMOR)
  248.             acce_item[i]->SetSocket(0, 0);
  249.        
  250.         acce_item[i] = NULL;
  251.     }
  252. }
  253.  
  254. void Acce_open(LPCHARACTER ch)
  255. {
  256.     if (false == s_isInitializedAcceMaterialInformation)
  257.     {
  258.         Acce_InformationInitialize();
  259.     }
  260.    
  261.     if (NULL == ch)
  262.         return;
  263.    
  264.     LPCHARACTER npc;
  265.     npc = ch->GetQuestNPC();
  266.     if (NULL == npc)
  267.     {
  268.         if (test_server)
  269.             dev_log(LOG_DEB0, "acce_npc is NULL");
  270.        
  271.         return;
  272.     }
  273.    
  274.     if (FN_check_valid_npc(npc->GetRaceNum()) == false)
  275.     {
  276.         if ( test_server == true )
  277.         {
  278.             dev_log(LOG_DEB0, "Acce not valid NPC");
  279.         }
  280.        
  281.         return;
  282.     }
  283.    
  284.     if (ch->IsAcceOpen())
  285.     {
  286.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("The Acce creation window is already opened."));
  287.         return;
  288.     }
  289.    
  290.     if ( ch->GetExchange() || ch->GetMyShop() || ch->GetShopOwner() || ch->IsOpenSafebox() || ch->IsAcceOpen() )
  291.     {
  292.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("다른 거래중(창고,교환,상점)에는 사용할 수 없습니다."));
  293.         return;
  294.     }
  295.    
  296.     long distance = DISTANCE_APPROX(ch->GetX() - npc->GetX(), ch->GetY() - npc->GetY());
  297.     if (distance >= ACCE_MAX_DISTANCE)
  298.     {
  299.         sys_log(1, "Acce: TOO_FAR: %s distance %d", ch->GetName(), distance);
  300.         return;
  301.     }
  302.    
  303.     Acce_clean_item(ch);
  304.     ch->SetAcceNpc(npc);
  305.     ch->ChatPacket(CHAT_TYPE_COMMAND, "Acce open %d", npc->GetRaceNum());
  306. }
  307.  
  308. void Acce_absorption_open(LPCHARACTER ch)
  309. {
  310.     if (false == s_isInitializedAcceMaterialInformation)
  311.     {
  312.         Acce_InformationInitialize();
  313.     }
  314.    
  315.     if (NULL == ch)
  316.         return;
  317.    
  318.     LPCHARACTER npc;
  319.     npc = ch->GetQuestNPC();
  320.     if (NULL == npc)
  321.     {
  322.         if (test_server)
  323.             dev_log(LOG_DEB0, "acce_npc is NULL");
  324.        
  325.         return;
  326.     }
  327.    
  328.     if (FN_check_valid_npc(npc->GetRaceNum()) == false)
  329.     {
  330.         if ( test_server == true )
  331.         {
  332.             dev_log(LOG_DEB0, "Acce not valid NPC");
  333.         }
  334.        
  335.         return;
  336.     }
  337.    
  338.     if (ch->IsAcceOpen())
  339.     {
  340.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("The Acce creation window is already opened."));
  341.         return;
  342.     }
  343.    
  344.     if ( ch->GetExchange() || ch->GetMyShop() || ch->GetShopOwner() || ch->IsOpenSafebox() || ch->IsAcceOpen() )
  345.     {
  346.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("다른 거래중(창고,교환,상점)에는 사용할 수 없습니다."));
  347.         return;
  348.     }
  349.    
  350.     long distance = DISTANCE_APPROX(ch->GetX() - npc->GetX(), ch->GetY() - npc->GetY());
  351.     if (distance >= ACCE_MAX_DISTANCE)
  352.     {
  353.         sys_log(1, "Acce: TOO_FAR: %s distance %d", ch->GetName(), distance);
  354.         return;
  355.     }
  356.    
  357.     Acce_clean_item(ch);
  358.     ch->SetAcceNpc(npc);
  359.     ch->ChatPacket(CHAT_TYPE_COMMAND, "Acce open_absorption %d", npc->GetRaceNum());
  360. }
  361.  
  362. void Acce_close(LPCHARACTER ch)
  363. {
  364.     RETURN_IF_ACCE_IS_NOT_OPENED(ch);
  365.     Acce_clean_item(ch);
  366.     ch->SetAcceNpc(NULL);
  367.     ch->ChatPacket(CHAT_TYPE_COMMAND, "Acce close");
  368.     dev_log(LOG_DEB0, "<Acce> close (%s)", ch->GetName());
  369. }
  370.  
  371. void Acce_init()
  372. {
  373.     ACCE_DATA * p_acce = NULL;
  374.     std::vector<ACCE_DATA*>::iterator iter;
  375.     char file_name[256+1];
  376.    
  377.     snprintf(file_name, sizeof(file_name), "%s/acce.txt", LocaleService_GetBasePath().c_str());
  378.     sys_log(0, "Acce_Init %s", file_name);
  379.     for (iter = s_acce_proto.begin(); iter!=s_acce_proto.end(); iter++)
  380.     {
  381.         p_acce = *iter;
  382.         M2_DELETE(p_acce);
  383.     }
  384.    
  385.     s_acce_proto.clear();
  386.     if (false == Acce_load(file_name))
  387.         sys_err("Acce_Init failed");
  388. }
  389.  
  390. bool Acce_load(const char *file)
  391. {
  392.     FILE    *fp;
  393.     char    one_line[256];
  394.     int     value1, value2;
  395.     const char  *delim = " \t\r\n";
  396.     char    *v, *token_string;
  397.     ACCE_DATA   *acce_data = NULL;
  398.     ACCE_VALUE  acce_value = {0, 0};
  399.    
  400.     if (0 == file || 0 == file[0])
  401.         return false;
  402.    
  403.     if ((fp = fopen(file, "r")) == 0)
  404.         return false;
  405.    
  406.     while (fgets(one_line, 256, fp))
  407.     {
  408.         value1 = value2 = 0;
  409.         if (one_line[0] == '#')
  410.             continue;
  411.        
  412.         token_string = strtok(one_line, delim);
  413.         if (NULL == token_string)
  414.             continue;
  415.        
  416.         if ((v = strtok(NULL, delim)))
  417.             str_to_number(value1, v);
  418.        
  419.         if ((v = strtok(NULL, delim)))
  420.             str_to_number(value2, v);
  421.        
  422.         TOKEN("section")
  423.         {
  424.             acce_data = M2_NEW ACCE_DATA;
  425.         }
  426.         else TOKEN("npc")
  427.         {
  428.             acce_data->npc_vnum.push_back((WORD)value1);
  429.         }
  430.         else TOKEN("item")
  431.         {
  432.             acce_value.vnum = value1;
  433.             acce_value.count = value2;
  434.             acce_data->item.push_back(acce_value);
  435.         }
  436.         else TOKEN("reward")
  437.         {
  438.             acce_value.vnum = value1;
  439.             acce_value.count = value2;
  440.             acce_data->reward.push_back(acce_value);
  441.         }
  442.         else TOKEN("abs_chance_min")
  443.         {
  444.             acce_data->abs_chance_min = value1;
  445.         }
  446.         else TOKEN("abs_chance_max")
  447.         {
  448.             acce_data->abs_chance_max = value1;
  449.         }
  450.         else TOKEN("percent")
  451.         {
  452.             acce_data->percent = value1;
  453.         }
  454.         else TOKEN("gold")
  455.         {
  456.             acce_data->gold = value1;
  457.         }
  458.         else TOKEN("end")
  459.         {
  460.             if (false == FN_check_acce_data(acce_data))
  461.             {
  462.                 dev_log(LOG_DEB0, "something wrong");
  463.                 M2_DELETE(acce_data);
  464.                 continue;
  465.             }
  466.            
  467.             s_acce_proto.push_back(acce_data);
  468.         }
  469.     }
  470.    
  471.     fclose(fp);
  472.     return true;
  473. }
  474.  
  475. static void FN_acce_print(ACCE_DATA *data, DWORD index)
  476. {
  477.     DWORD   i;
  478.     dev_log(LOG_DEB0, "--------------------------------");
  479.     dev_log(LOG_DEB0, "ACCE_DATA[%d]", index);
  480.     for (i = 0; i < data->npc_vnum.size(); ++i)
  481.     {
  482.         dev_log(LOG_DEB0, "\tNPC_VNUM[%d] = %d", i, data->npc_vnum[i]);
  483.     }
  484.     for (i = 0; i < data->item.size(); ++i)
  485.     {
  486.         dev_log(LOG_DEB0, "\tITEM[%d]   = (%d, %d)", i, data->item[i].vnum, data->item[i].count);
  487.     }
  488.     for (i = 0; i < data->reward.size(); ++i)
  489.     {
  490.         dev_log(LOG_DEB0, "\tREWARD[%d] = (%d, %d)", i, data->reward[i].vnum, data->reward[i].count);
  491.     }
  492.    
  493.     dev_log(LOG_DEB0, "\tPERCENT = %d", data->percent);
  494.     dev_log(LOG_DEB0, "--------------------------------");
  495. }
  496.  
  497. void Acce_print ()
  498. {
  499.     for (DWORD i=0; i<s_acce_proto.size(); ++i)
  500.     {
  501.         FN_acce_print(s_acce_proto[i], i);
  502.     }
  503. }
  504.  
  505. static bool FN_update_acce_status(LPCHARACTER ch)
  506. {
  507.     if (NULL == ch)
  508.         return false;
  509.    
  510.     if (!ch->IsAcceOpen())
  511.         return false;
  512.    
  513.     LPCHARACTER npc = ch->GetQuestNPC();
  514.     if (NULL == npc)
  515.         return false;
  516.    
  517.     ACCE_DATA* Acce = FN_find_acce(ch->GetAcceItem(), npc->GetRaceNum());
  518.     if (NULL == Acce)
  519.     {
  520.         ch->ChatPacket(CHAT_TYPE_COMMAND, "Acce info 0 0 0 0 0");
  521.         return false;
  522.     }
  523.    
  524.     ch->ChatPacket(CHAT_TYPE_COMMAND, "Acce info %d %d %d %d %d", Acce->gold, 0, 0, Acce->reward[0], Acce->reward[1]);
  525.     return true;
  526. }
  527.  
  528. bool Acce_make(LPCHARACTER ch)
  529. {
  530.     LPCHARACTER npc;
  531.     int         percent_number = 0;
  532.     ACCE_DATA   *acce_proto;
  533.     LPITEM  *items;
  534.     LPITEM  new_item;
  535.     int reward_vnum = 0;
  536.    
  537.     if (!(ch)->IsAcceOpen())
  538.     {
  539.         (ch)->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("The Acce creation window is not open."));
  540.         return false;
  541.     }
  542.    
  543.     npc = ch->GetQuestNPC();
  544.     if (NULL == npc)
  545.     {
  546.         return false;
  547.     }
  548.    
  549.     items = ch->GetAcceItem();
  550.     if (items[0] == NULL || items[1] == NULL || items[0]->GetValue(0) != items[1]->GetValue(0))
  551.     {
  552.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Drag the items into the window."));
  553.         return false;
  554.     }
  555.  
  556.     acce_proto = FN_find_acce(items, npc->GetRaceNum());
  557.     if (NULL == acce_proto)
  558.     {
  559.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("제조 재료가 부족합니다"));
  560.         return false;
  561.     }
  562.  
  563.     reward_vnum = items[0]->GetValue(1);
  564.     if (reward_vnum == 0)
  565.     {
  566.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Drag the items into the window."));
  567.         return false;
  568.     }
  569.  
  570.     ACCE_VALUE  *reward_value = acce_proto->reward_value();
  571.     if (0 < acce_proto->gold)
  572.         ch->PointChange(POINT_GOLD, -(acce_proto->gold), false);
  573.    
  574.     percent_number = number(1, 100);
  575.     if (percent_number <= acce_proto->percent)
  576.     {
  577.         acce_proto->remove_material(ch, 1);
  578.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Success!"));
  579.         ch->ChatPacket(CHAT_TYPE_COMMAND, "acce success %d %d", reward_vnum, reward_value->count);
  580.         ch->EffectPacket(SE_ACCE_SUCCEDED_1);
  581.         int abs_chance = 0;
  582.         if (acce_proto->abs_chance_min < 1 || acce_proto->abs_chance_max < 1)
  583.         {
  584.             abs_chance = 1;
  585.         }
  586.         else if (acce_proto->abs_chance_min > acce_proto->abs_chance_max)
  587.         {
  588.             abs_chance = 1;
  589.         }
  590.         else if (acce_proto->abs_chance_min == acce_proto->abs_chance_max)
  591.         {
  592.             abs_chance = acce_proto->abs_chance_min;
  593.         }
  594.         else
  595.         {
  596.             abs_chance = number(acce_proto->abs_chance_min, acce_proto->abs_chance_max);
  597.         }
  598.        
  599.         new_item = ch->AutoGiveAcce(reward_vnum, reward_value->count, abs_chance);
  600.         LogManager::instance().AcceLog(ch->GetPlayerID(), ch->GetX(), ch->GetY(), reward_vnum, new_item->GetID(), reward_value->count, abs_chance, 1);
  601.         return true;
  602.     }
  603.     else
  604.     {
  605.         acce_proto->remove_material(ch, 0);
  606.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Failed!"));
  607.         ch->ChatPacket(CHAT_TYPE_COMMAND, "Acce fail");
  608.         LogManager::instance().AcceLog(ch->GetPlayerID(), ch->GetX(), ch->GetY(), reward_vnum, 0, 0, 0, 0);
  609.         return false;
  610.     }
  611.    
  612.     return false;
  613. }
  614.  
  615. bool Acce_absorption_make(LPCHARACTER ch)
  616. {
  617.     LPCHARACTER npc;
  618.     LPITEM  *items;
  619.     int absorption_chance = 0;
  620.     BYTE    type1 = 0, type2 = 0, type3 = 0, type4 = 0, type5 = 0, type6 = 0, type7 = 0, type8 = 0, type9 = 0, type10 = 0, type11 = 0, type12 = 0, type13 = 0, type14 = 0, type15 = 0;
  621.     float   value1 = 0, value2 = 0, value3 = 0, value4 = 0, value5 = 0, value6 = 0, value7 = 0, value8 = 0, value9 = 0, value10 = 0, value11 = 0, value12 = 0, value13 = 0, value14 = 0, value15 = 0;
  622.    
  623.     if (!(ch)->IsAcceOpen())
  624.     {
  625.         (ch)->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("The Acce creation window is not open."));
  626.         return false;
  627.     }
  628.    
  629.     npc = ch->GetQuestNPC();
  630.     if (NULL == npc)
  631.     {
  632.         return false;
  633.     }
  634.    
  635.     items = ch->GetAcceItem();
  636.     if (items[0] == NULL || items[1] == NULL)
  637.     {
  638.         (ch)->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Drag the items into the window."));
  639.         return false;
  640.     }
  641.     else if (items[1]->GetType() != ITEM_WEAPON && items[1]->GetType() != ITEM_ARMOR)
  642.     {
  643.         (ch)->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You can use a sash to absorb the bonus just from weapons or armours."));
  644.         return false;
  645.     }
  646.     else if (items[0]->GetAcceAttributeCount() > 0)
  647.     {
  648.         (ch)->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You must remove the bonus from sash before continue."));
  649.         return false;
  650.     }
  651.    
  652.     absorption_chance = items[0]->GetSocket(1);
  653.     type1 = items[1]->GetAttributeType(0);
  654.     value1 = items[1]->GetAttributeValue(0) * absorption_chance / 100;
  655.     type2 = items[1]->GetAttributeType(1);
  656.     value2 = items[1]->GetAttributeValue(1) * absorption_chance / 100;
  657.     type3 = items[1]->GetAttributeType(2);
  658.     value3 = items[1]->GetAttributeValue(2) * absorption_chance / 100;
  659.     type4 = items[1]->GetAttributeType(3);
  660.     value4 = items[1]->GetAttributeValue(3) * absorption_chance / 100;
  661.     type5 = items[1]->GetAttributeType(4);
  662.     value5 = items[1]->GetAttributeValue(4) * absorption_chance / 100;
  663.     type6 = items[1]->GetAttributeType(5);
  664.     value6 = items[1]->GetAttributeValue(5) * absorption_chance / 100;
  665.     type7 = items[1]->GetAttributeType(6);
  666.     value7 = items[1]->GetAttributeValue(6) * absorption_chance / 100;
  667.    
  668.     if (items[1]->GetType() == ITEM_ARMOR)
  669.     {
  670.         type8 = 54;
  671.         value8 = (items[1]->GetValue(1) + items[1]->GetValue(5)) * absorption_chance / 100;
  672.     }
  673.     else
  674.     {
  675.         type8 = 0;
  676.         value8 = 0;
  677.     }
  678.    
  679.     if (items[1]->GetType() == ITEM_WEAPON)
  680.     {
  681.         type9 = 53;
  682.         value9 = (items[1]->GetValue(3) + items[1]->GetValue(5)) * absorption_chance / 100;
  683.         type10 = 53;
  684.         value10 = (items[1]->GetValue(4) + items[1]->GetValue(5)) * absorption_chance / 100;
  685.         value11 = (items[1]->GetValue(1) + items[1]->GetValue(5)) * absorption_chance / 100;
  686.         value12 = (items[1]->GetValue(2) + items[1]->GetValue(5)) * absorption_chance / 100;
  687.         if (items[1]->GetValue(1) <= 0)
  688.         {
  689.             type11 = 0;
  690.             value11 = 0;
  691.         }
  692.         else
  693.         {
  694.             type11 = 55;
  695.         }
  696.        
  697.         if (items[1]->GetValue(2) <= 0)
  698.         {
  699.             type12 = 0;
  700.             value12 = 0;
  701.         }
  702.         else
  703.         {
  704.             type12 = 55;
  705.         }
  706.     }
  707.     else
  708.     {
  709.         type9 = 0;
  710.         value9 = 0;
  711.         type10 = 0;
  712.         value10 = 0;
  713.         type11 = 0;
  714.         value11 = 0;
  715.         type12 = 0;
  716.         value12 = 0;
  717.     }
  718.    
  719.     type13 = items[1]->GetNewAttributeType(0);
  720.     value13 = items[1]->GetNewAttributeValue(0) * absorption_chance / 100;
  721.     type14 = items[1]->GetNewAttributeType(1);
  722.     value14 = items[1]->GetNewAttributeValue(1) * absorption_chance / 100;
  723.     type15 = items[1]->GetNewAttributeType(2);
  724.     value15 = items[1]->GetNewAttributeValue(2) * absorption_chance / 100;
  725.    
  726.     int value1_final = (value1 <= 0) ? (int)(1) : (int)(value1);
  727.     int value2_final = (value2 <= 0) ? (int)(1) : (int)(value2);
  728.     int value3_final = (value3 <= 0) ? (int)(1) : (int)(value3);
  729.     int value4_final = (value4 <= 0) ? (int)(1) : (int)(value4);
  730.     int value5_final = (value5 <= 0) ? (int)(1) : (int)(value5);
  731.     int value6_final = (value6 <= 0) ? (int)(1) : (int)(value6);
  732.     int value7_final = (value7 <= 0) ? (int)(1) : (int)(value7);
  733.     int value8_final = (value8 <= 0) ? (int)(1) : (int)(value8);
  734.     int value9_final = (value10 - value9 <= 0) ? (int)(1) : (int)(value10 - value9);
  735.     int value10_final = (value10 <= 0) ? (int)(1) : (int)(value10);
  736.     int value11_final = (value11 - value11 <= 0) ? (int)(1) : (int)(value12 - value11);
  737.     int value12_final = (value12 <= 0) ? (int)(1) : (int)(value12);
  738.     int value13_final = (value13 <= 0) ? (int)(1) : (int)(value13);
  739.     int value14_final = (value14 <= 0) ? (int)(1) : (int)(value14);
  740.     int value15_final = (value15 <= 0) ? (int)(1) : (int)(value15);
  741.    
  742.     items[0]->SetForceAttribute(0, type1, value1_final);
  743.     items[0]->SetForceAttribute(1, type2, value2_final);
  744.     items[0]->SetForceAttribute(2, type3, value3_final);
  745.     items[0]->SetForceAttribute(3, type4, value4_final);
  746.     items[0]->SetForceAttribute(4, type5, value5_final);
  747.     items[0]->SetForceAttribute(5, type6, value6_final);
  748.     items[0]->SetForceAttribute(6, type7, value7_final);
  749.     items[0]->SetForceAttribute(7, type8, value8_final);
  750.     items[0]->SetForceAttribute(8, type9, value9_final);
  751.     items[0]->SetForceAttribute(9, type10, value10_final);
  752.     items[0]->SetForceAttribute(10, type11, value11_final);
  753.     items[0]->SetForceAttribute(11, type12, value12_final);
  754.     items[0]->SetForceAttribute(12, type13, value13_final);
  755.     items[0]->SetForceAttribute(13, type14, value14_final);
  756.     items[0]->SetForceAttribute(14, type15, value15_final);
  757.    
  758.     ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("The absorption process had success!"));
  759.     ch->ChatPacket(CHAT_TYPE_COMMAND, "acce success_absorption");
  760.    
  761.     items[1]->SetCount(0);
  762.     items[1] = NULL;
  763.     return true;
  764. }
  765.  
  766. void Acce_show_list(LPCHARACTER ch)
  767. {
  768.     LPITEM  *acce_item;
  769.     LPITEM  item;
  770.    
  771.     RETURN_IF_ACCE_IS_NOT_OPENED(ch);
  772.    
  773.     acce_item = ch->GetAcceItem();
  774.     for (int i=0; i<ACCE_MAX_NUM; ++i)
  775.     {
  776.         item = acce_item[i];
  777.         if (item == NULL)
  778.             continue;
  779.        
  780.         ch->ChatPacket(CHAT_TYPE_INFO, "Acce[%d]: inventory[%d]: %s", i, item->GetCell(), item->GetName());
  781.     }
  782. }
  783.  
  784. void Acce_add_item(LPCHARACTER ch, int acce_index, int inven_index)
  785. {
  786.     LPITEM  item;
  787.     LPITEM  *acce_item;
  788.    
  789.     RETURN_IF_ACCE_IS_NOT_OPENED(ch);
  790.    
  791.     if (inven_index < 0 || INVENTORY_MAX_NUM <= inven_index)
  792.         return;
  793.    
  794.     if (acce_index<0 || ACCE_MAX_NUM <= acce_index)
  795.         return;
  796.    
  797.     item = ch->GetInventoryItem(inven_index);
  798.     if (item == NULL)
  799.         return;
  800.    
  801.     if (item->GetType() == ITEM_COSTUME && item->GetSubType() == COSTUME_ACCE && item->GetType() != ITEM_WEAPON && item->GetType() != ITEM_ARMOR)
  802.         item->SetSocket(0, 1);
  803.    
  804.     acce_item = ch->GetAcceItem();
  805.     for (int i=0; i<ACCE_MAX_NUM; ++i)
  806.     {
  807.         if (item==acce_item[i])
  808.         {
  809.             acce_item[i] = NULL;
  810.             break;
  811.         }
  812.     }
  813.    
  814.     acce_item[acce_index] = item;
  815.     if (acce_index == 1)
  816.     {
  817.         if (item->GetType() == ITEM_WEAPON || item->GetType() == ITEM_ARMOR)
  818.         {
  819.             ch->ChatPacket(CHAT_TYPE_COMMAND, "AcceAbsMessage");
  820.         }
  821.         else
  822.         {
  823.             ch->ChatPacket(CHAT_TYPE_COMMAND, "AcceMessage");
  824.         }
  825.     }
  826.    
  827.     if (test_server)
  828.         ch->ChatPacket(CHAT_TYPE_INFO, "Acce[%d]: inventory[%d]: %s added", acce_index, inven_index, item->GetName());
  829.    
  830.     if (acce_index == 0)
  831.     {
  832.         FN_update_acce_status(ch);
  833.     }
  834.     return;
  835. }
  836.  
  837. void Acce_delete_item(LPCHARACTER ch, int acce_index)
  838. {
  839.     LPITEM  item;
  840.     LPITEM  *acce_item;
  841.    
  842.     RETURN_IF_ACCE_IS_NOT_OPENED(ch);
  843.     if (acce_index < 0 || ACCE_MAX_NUM <= acce_index)
  844.         return;
  845.    
  846.     acce_item = ch->GetAcceItem();
  847.     if (acce_item[acce_index] == NULL)
  848.         return;
  849.    
  850.     item = acce_item[acce_index];
  851.     if (item->GetType() == ITEM_COSTUME && item->GetSubType() == COSTUME_ACCE && item->GetType() != ITEM_WEAPON && item->GetType() != ITEM_ARMOR)
  852.         item->SetSocket(0, 0);
  853.    
  854.     acce_item[acce_index] = NULL;
  855.     if (test_server)
  856.         ch->ChatPacket(CHAT_TYPE_INFO, "Acce[%d]: Acce[%d]: %s deleted", acce_index, item->GetCell(), item->GetName());
  857.  
  858.     if (acce_index == 0)
  859.     {
  860.         FN_update_acce_status(ch);
  861.     }
  862.     return;
  863. }
  864.  
  865. SItemNameAndLevel SplitItemNameAndLevelFromHName(const std::string& name)
  866. {
  867.     int level = 0;
  868.     SItemNameAndLevel info;
  869.     info.name = name;
  870.    
  871.     size_t pos = name.find("+");
  872.     if (std::string::npos != pos)
  873.     {
  874.         const std::string levelStr = name.substr(pos + 1, name.size() - pos - 1);
  875.         str_to_number(level, levelStr.c_str());
  876.  
  877.         info.name = name.substr(0, pos);
  878.     }
  879.    
  880.     info.level = level;
  881.     return info;
  882. };
  883.  
  884. bool FIsEqualAcceValue(const ACCE_VALUE& a, const ACCE_VALUE& b)
  885. {
  886.     return (a.vnum == b.vnum) && (a.count == b.count);
  887. }
  888.  
  889. bool FIsLessAcceValue(const ACCE_VALUE& a, const ACCE_VALUE& b)
  890. {
  891.     return a.vnum < b.vnum;
  892. }
  893.  
  894. void Acce_MakeAcceInformationText()
  895. {
  896.     for (TAcceMapByNPC::iterator iter = acce_info_map.begin(); acce_info_map.end() != iter; ++iter)
  897.     {
  898.         TAcceResultList& resultList = iter->second;
  899.         for (TAcceResultList::iterator resultIter = resultList.begin(); resultList.end() != resultIter; ++resultIter)
  900.         {
  901.             SAcceMaterialInfo& materialInfo = *resultIter;
  902.             std::string& infoText = materialInfo.infoText;
  903.             if (0 < materialInfo.complicateMaterial.size())
  904.             {
  905.                 std::sort(materialInfo.complicateMaterial.begin(), materialInfo.complicateMaterial.end(), FIsLessAcceValue);
  906.                 std::sort(materialInfo.material.begin(), materialInfo.material.end(), FIsLessAcceValue);
  907.                 for (TAcceValueVector::iterator iter = materialInfo.complicateMaterial.begin(); materialInfo.complicateMaterial.end() != iter; ++iter)
  908.                 {
  909.                     for (TAcceValueVector::iterator targetIter = materialInfo.material.begin(); materialInfo.material.end() != targetIter; ++targetIter)
  910.                     {
  911.                         if (*targetIter == *iter)
  912.                         {
  913.                             targetIter = materialInfo.material.erase(targetIter);
  914.                         }
  915.                     }
  916.                 }
  917.                
  918.                 for (TAcceValueVector::iterator iter = materialInfo.complicateMaterial.begin(); materialInfo.complicateMaterial.end() != iter; ++iter)
  919.                 {
  920.                     char tempBuffer[128];
  921.                     sprintf(tempBuffer, "%d,%d|", iter->vnum, iter->count);
  922.                    
  923.                     infoText += std::string(tempBuffer);
  924.                 }
  925.                
  926.                 infoText.erase(infoText.size() - 1);
  927.                 if (0 < materialInfo.material.size())
  928.                     infoText.push_back('&');
  929.             }
  930.            
  931.             for (TAcceValueVector::iterator iter = materialInfo.material.begin(); materialInfo.material.end() != iter; ++iter)
  932.             {
  933.                 char tempBuffer[128];
  934.                 sprintf(tempBuffer, "%d,%d&", iter->vnum, iter->count);
  935.                 infoText += std::string(tempBuffer);
  936.             }
  937.            
  938.             infoText.erase(infoText.size() - 1);
  939.             if (0 < materialInfo.gold)
  940.             {
  941.                 char temp[128];
  942.                 sprintf(temp, "%d", materialInfo.gold);
  943.                 infoText += std::string("/") + temp;
  944.             }
  945.         }
  946.     }
  947. }
  948.  
  949. bool Acce_InformationInitialize()
  950. {
  951.     for (int i = 0; i < s_acce_proto.size(); ++i)
  952.     {
  953.         ACCE_DATA* acceData = s_acce_proto[i];
  954.         const std::vector<ACCE_VALUE>& rewards = acceData->reward;
  955.         if (rewards.size() != 1)
  956.         {
  957.             sys_err("[AcceInfo] WARNING! Does not support multiple rewards (count: %d)", rewards.size());          
  958.             continue;
  959.         }
  960.        
  961.         const ACCE_VALUE& reward = rewards.at(0);
  962.         const WORD& npcVNUM = acceData->npc_vnum.at(0);
  963.         bool bComplicate = false;
  964.        
  965.         TAcceMapByNPC& acceMap = acce_info_map;
  966.         TAcceResultList& resultList = acceMap[npcVNUM];
  967.         SAcceMaterialInfo materialInfo;
  968.        
  969.         materialInfo.reward = reward;
  970.         materialInfo.gold = acceData->gold;
  971.         materialInfo.material = acceData->item;
  972.        
  973.         for (TAcceResultList::iterator iter = resultList.begin(); resultList.end() != iter; ++iter)
  974.         {
  975.             SAcceMaterialInfo& existInfo = *iter;
  976.             if (reward.vnum == existInfo.reward.vnum)
  977.             {
  978.                 for (TAcceValueVector::iterator existMaterialIter = existInfo.material.begin(); existInfo.material.end() != existMaterialIter; ++existMaterialIter)
  979.                 {
  980.                     TItemTable* existMaterialProto = ITEM_MANAGER::Instance().GetTable(existMaterialIter->vnum);
  981.                     if (NULL == existMaterialProto)
  982.                     {
  983.                         sys_err("There is no item(%u)", existMaterialIter->vnum);
  984.                         return false;
  985.                     }
  986.                    
  987.                     SItemNameAndLevel existItemInfo = SplitItemNameAndLevelFromHName(existMaterialProto->szName);
  988.                     if (0 < existItemInfo.level)
  989.                     {
  990.                         for (TAcceValueVector::iterator currentMaterialIter = materialInfo.material.begin(); materialInfo.material.end() != currentMaterialIter; ++currentMaterialIter)
  991.                         {
  992.                             TItemTable* currentMaterialProto = ITEM_MANAGER::Instance().GetTable(currentMaterialIter->vnum);
  993.                             SItemNameAndLevel currentItemInfo = SplitItemNameAndLevelFromHName(currentMaterialProto->szName);
  994.                             if (currentItemInfo.name == existItemInfo.name)
  995.                             {
  996.                                 bComplicate = true;
  997.                                 existInfo.complicateMaterial.push_back(*currentMaterialIter);
  998.                                 if (std::find(existInfo.complicateMaterial.begin(), existInfo.complicateMaterial.end(), *existMaterialIter) == existInfo.complicateMaterial.end())
  999.                                     existInfo.complicateMaterial.push_back(*existMaterialIter);
  1000.                                
  1001.                                 break;
  1002.                             }
  1003.                         }
  1004.                     }
  1005.                 }
  1006.             }
  1007.         }
  1008.        
  1009.         if (false == bComplicate)
  1010.             resultList.push_back(materialInfo);
  1011.     }
  1012.    
  1013.     Acce_MakeAcceInformationText();
  1014.     s_isInitializedAcceMaterialInformation = true;
  1015.     return true;
  1016. }
  1017.  
  1018. void Acce_request_result_list(LPCHARACTER ch)
  1019. {
  1020.     RETURN_IF_ACCE_IS_NOT_OPENED(ch);
  1021.     LPCHARACTER npc = ch->GetQuestNPC();
  1022.     if (NULL == npc)
  1023.         return;
  1024.    
  1025.     DWORD npcVNUM = npc->GetRaceNum();
  1026.     size_t resultCount = 0;
  1027.     std::string& resultText = acce_result_info_map_by_npc[npcVNUM];
  1028.     if (resultText.length() == 0)
  1029.     {
  1030.         resultText.clear();
  1031.         const TAcceResultList& resultList = acce_info_map[npcVNUM];
  1032.         for (TAcceResultList::const_iterator iter = resultList.begin(); resultList.end() != iter; ++iter)
  1033.         {
  1034.             const SAcceMaterialInfo& materialInfo = *iter;
  1035.             char temp[128];
  1036.             sprintf(temp, "%d,%d", materialInfo.reward.vnum, materialInfo.reward.count);
  1037.            
  1038.             resultText += std::string(temp) + "/";
  1039.         }
  1040.        
  1041.         resultCount = resultList.size();
  1042.         resultText.erase(resultText.size() - 1);
  1043.         if (resultCount == 0)
  1044.         {
  1045.             return;
  1046.         }
  1047.        
  1048.         if (resultText.size() - 20 >= CHAT_MAX_LEN)
  1049.         {
  1050.             sys_err("[AcceInfo] Too long Acce result list text. (NPC: %d, length: %d)", npcVNUM, resultText.size());
  1051.             resultText.clear();
  1052.             resultCount = 0;
  1053.         }
  1054.     }
  1055.    
  1056.     ch->ChatPacket(CHAT_TYPE_COMMAND, "Acce r_list %d %d %s", npcVNUM, resultCount, resultText.c_str());
  1057. }
  1058.  
  1059. void Acce_request_material_info(LPCHARACTER ch, int requestStartIndex, int requestCount)
  1060. {
  1061.     RETURN_IF_ACCE_IS_NOT_OPENED(ch);
  1062.     LPCHARACTER npc = ch->GetQuestNPC();
  1063.     if (NULL == npc)
  1064.         return;
  1065.    
  1066.     DWORD npcVNUM = npc->GetRaceNum();
  1067.     std::string materialInfoText = "";
  1068.    
  1069.     int index = 0;
  1070.     bool bCatchInfo = false;
  1071.     const TAcceResultList& resultList = acce_info_map[npcVNUM];
  1072.    
  1073.     for (TAcceResultList::const_iterator iter = resultList.begin(); resultList.end() != iter; ++iter)
  1074.     {
  1075.         const SAcceMaterialInfo& materialInfo = *iter;
  1076.         if (index++ == requestStartIndex)
  1077.         {
  1078.             bCatchInfo = true;
  1079.         }
  1080.        
  1081.         if (bCatchInfo)
  1082.         {
  1083.             materialInfoText += materialInfo.infoText + "@";
  1084.         }
  1085.        
  1086.         if (index >= requestStartIndex + requestCount)
  1087.             break;
  1088.     }
  1089.    
  1090.     if (false == bCatchInfo)
  1091.     {
  1092.         sys_err("[AcceInfo] Can't find matched material info (NPC: %d, index: %d, request count: %d)", npcVNUM, requestStartIndex, requestCount);
  1093.         return;
  1094.     }
  1095.    
  1096.     materialInfoText.erase(materialInfoText.size() - 1);
  1097.     if (materialInfoText.size() - 20 >= CHAT_MAX_LEN)
  1098.     {
  1099.         sys_err("[AcceInfo] Too long material info. (NPC: %d, requestStart: %d, requestCount: %d, length: %d)", npcVNUM, requestStartIndex, requestCount, materialInfoText.size());
  1100.     }
  1101.    
  1102.     ch->ChatPacket(CHAT_TYPE_COMMAND, "Acce m_info %d %d %s", requestStartIndex, requestCount, materialInfoText.c_str());
  1103. }
Advertisement
Add Comment
Please, Sign In to add comment