Advertisement
Lighta

stats-mod Ea statslof.c

Feb 11th, 2012
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 50.07 KB | None | 0 0
  1. // Copyright (c) Lof Dev Teams
  2. // Legend Of Fea Statistics modules
  3. // Plz check statslof.h for config before trying any hardcoding style.
  4.  
  5. //Include all files
  6. #include "../common/cbasetypes.h"
  7. #include "../common/timer.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/malloc.h"
  10. #include "../common/showmsg.h"
  11. #include "../common/strlib.h"
  12. #include "../common/utils.h"
  13. #include "../common/ers.h"
  14. #include "../common/sql.h"
  15.  
  16. #include "statslof.h"
  17. #include "skill.h"
  18. #include "map.h"
  19. #include "path.h"
  20. #include "clif.h"
  21. #include "pc.h"
  22. #include "status.h"
  23. #include "pet.h"
  24. #include "homunculus.h"
  25. #include "mercenary.h"
  26. #include "mob.h"
  27. #include "npc.h"
  28. #include "battle.h"
  29. #include "battleground.h"
  30. #include "party.h"
  31. #include "itemdb.h"
  32. #include "script.h"
  33. #include "intif.h"
  34. #include "log.h"
  35. #include "chrif.h"
  36. #include "guild.h"
  37. #include "date.h"
  38. #include "unit.h"
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <time.h>
  43. #include <math.h>
  44. #include <sys/types.h>
  45. #include <sys/stat.h>
  46. #ifndef WIN32
  47. #include <unistd.h>
  48. #else
  49. #include <winsock2.h>
  50. #endif
  51.  
  52. //Config part (edit as you want on your system)
  53. static char stats_pathfile[MAX_BUFFER] = "/home/lighta/Assembla/lof_v2/statslof/";
  54. static int autopath=1; //0-1 this will override stats_pathfile defined
  55. static char stats_player_skillfile[MAX_BUFFER] = "player_count_skill.txt";
  56. static char stats_player_killfile[MAX_BUFFER] = "player_count_kill.txt";
  57. static char stats_player_consofile[MAX_BUFFER] = "player_count_conso.txt";
  58. static char stats_player_dmgfile[MAX_BUFFER] = "player_count_dmg.txt";
  59. static char stats_player_healfile[MAX_BUFFER] = "player_count_heal.txt";
  60. static char stats_guild_skillfile[MAX_BUFFER] = "guild_count_skill.txt";
  61. static char stats_guild_killfile[MAX_BUFFER] = "guild_count_kill.txt";
  62. static char stats_data[MAX_BUFFER] = "Stats_Woe_Data";
  63. static char stats_player_skill_db[MAX_BUFFER] = "Stats_Woe_Skill";
  64. static char stats_player_kill_db[MAX_BUFFER] = "Stats_Woe_Kill";
  65. static char stats_player_conso_db[MAX_BUFFER] = "Stats_Woe_Conso";
  66. static char stats_player_dmg_db[MAX_BUFFER] = "Stats_Woe_Dammage";
  67. static char stats_player_heal_db[MAX_BUFFER] = "Stats_Woe_Heal";
  68. static char stats_guild_skill_db[MAX_BUFFER] = "Stats_Woe_GSkill";
  69. static char stats_guild_kill_db[MAX_BUFFER] = "Stats_Woe_GKill";
  70.  
  71. //@TODO prevoir script_agitstart2 (second tab ?)
  72. //Construction tab and index
  73. static unsigned int cpt_id_skill=0;     //Compteur de char recorded
  74. static unsigned int cpt_rec_skill=0;     //Compteur de skill recorded
  75. static unsigned int statswoe_skill[MAX_CHAR_ID+2][MAX_SKILL_CNT+1]; //Tab de stats skills players
  76. static unsigned int cpt_id_conso=0;     //Compteur de conso par char recorded
  77. static unsigned int cpt_rec_conso=0;     //Compteur de conso recorded
  78. static unsigned int statswoe_conso[MAX_CHAR_ID][MAX_CONSO_CNT+1]; //Tab de stats conso players
  79. static unsigned int cpt_id_dmg=0;     //Compteur de dmg par char recorded
  80. static unsigned int cpt_rec_dmg=0;     //Compteur de dmg recorded
  81. static unsigned int statswoe_dmg[MAX_CHAR_ID][MAX_DMG_DONE+1];  //Tab de stats dmg players
  82. static unsigned int cpt_id_kill=0;     //Compteur de kill par char recorded
  83. static unsigned int statswoe_kill[MAX_CHAR_ID][MAX_KILL_CNT+1];  //Tab de stats kill players
  84. static unsigned int cpt_id_heal=0;     //Compteur de heal par char recorded
  85. static unsigned int statswoe_heal[MAX_CHAR_ID][MAX_HEAL_CNT+1];  //Tab de stats heal players
  86. static unsigned int cpt_id_gskill=0;     //Compteur de guild recorded (skill)
  87. static unsigned int cpt_rec_gskill=0;     //Compteur de guildskill recorded
  88. static unsigned int statswoe_gskill[MAX_GUILD_ID][MAX_GSKILL_CNT+1]; //Tab de stats skills guild
  89. static unsigned int cpt_id_gkill=0;     //Compteur de guild recorded (kill)
  90. static unsigned int statswoe_gkill[MAX_GUILD_ID][MAX_GKILL_CNT+1]; //Tab de stats skills guild
  91. static unsigned int idwoe=1;      //IDWoe for permanente save table
  92. static unsigned int enable=0;       //Var d'activation des stats
  93. static unsigned int curdate=0;      //Var date courrante
  94. char query[QUERY_LENGTH];      //Query String
  95. int cmds=CMDDEF;       //Command status result
  96. //lof_dammagecount statslof_dmgcount[MAX_CHAR_ID];    //Dammage tab.
  97. int statslof_init() {
  98. #ifndef WIN32
  99. char cCurrentPath[MAX_BUFFER];
  100. cmds=CMDDEF;
  101. //Path file
  102. if (autopath==1) {
  103.   getcwd(cCurrentPath, sizeof(cCurrentPath));
  104.   sprintf(stats_pathfile, "%s/statslof/", cCurrentPath);
  105. }
  106. #else
  107.   ShowWarning("Windows plateform detected, OS unsuported, map-server may crash");
  108. #endif
  109. //ShowWarning("Init done stats_pathfile=%s\n",stats_pathfile);
  110.  
  111. return cmds;
  112. }
  113. /*
  114. * Inner fonction d'ajout d'un char dans les stats
  115. * @Return new index
  116. */
  117. int statslof_addchar(int statstype,int index, int idplayers) {
  118. int ichar=0;
  119. if(index >= MAX_CHAR_ID) return 0; //Chk Array bound
  120. ichar=index;
  121.  
  122. switch(statstype) {
  123.   case STATSKILL :
  124.    //ShowWarning("Skill : Char not found, index=%d\n",index);
  125.    statswoe_skill[ichar][0]=idplayers; //insert new char id
  126.    cpt_id_skill++;    //increment nb char in woe for statskill tab
  127.   break;
  128.  
  129.   case STATCONSO :
  130.    //ShowWarning("Conso : Char not found, index=%d\n",index);
  131.    statswoe_conso[ichar][0]=idplayers; //insert new char id
  132.    cpt_id_conso++;    //increment nb char in woe for statsconso tab
  133.   break;
  134.  
  135.   case STATDMG :
  136.    //ShowWarning("DmgRec : Char not found, index=%d\n",index);
  137.    statswoe_dmg[ichar][0]=idplayers; //insert new char id
  138.    cpt_id_dmg++;    //increment nb char in woe for statsdmg tab
  139.   break;
  140.   case STATDMGDONE :
  141.    //ShowWarning("DmgDone : Char not found, index=%d\n",index);
  142.    statswoe_dmg[ichar][0]=idplayers; //insert new char id
  143.    cpt_id_dmg++;    //increment nb char in woe for statsdmg tab
  144.   break;
  145.  
  146.   case STATKILL :
  147.    //ShowWarning("Kill : Char not found, index=%d\n",index);
  148.    statswoe_kill[ichar][0]=idplayers; //insert new char id
  149.    cpt_id_kill++;    //increment nb char in woe for statkill tab
  150.   break;
  151.  
  152.   case STATHEAL :
  153.    //ShowWarning("Heal : Char not found, index=%d\n",index);
  154.    statswoe_heal[ichar][0]=idplayers; //insert new char id
  155.    cpt_id_heal++;   //increment nb char in woe for statkill tab
  156.   break;
  157. }
  158. return ichar;
  159. }
  160. /*
  161. * Fonction d'incrementation des skills
  162. * Appeler à  chaque utilisation de skill par player.
  163. * Mapflag should be used before calling this
  164. *
  165. * statswoe_skill[i][j] structure :
  166. * [x][0]=charid, x=[2;MAX_CHAR_ID]
  167. * [0][x]=skillid x=[1;MAX_SKILL_CNT]
  168. * [1][x]=skilltype, x=[1; MAX_SKILL_CNT]
  169. */
  170. int statslof_skill_cnt(struct map_session_data *sd, int idplayers, int idskill, int skilltype){
  171. unsigned int i=0, j=1;
  172. unsigned int ichar=0, iskill=0;  //index for char and skill
  173. cmds=CMDDEF;
  174. if (sd==NULL) return CMDFAIL; //Security check
  175. if (idplayers==0 || idskill==0 || skilltype==0) return CMDFAIL; //Security check
  176.  
  177. //Woe
  178. if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
  179.   for(i=2;i<=cpt_id_skill+2;i++) {     //parcours char id
  180.    if(statswoe_skill[i][0] == idplayers) {
  181.     ichar = i; //index char
  182.     break;  //optimise
  183.    }
  184.   }
  185.   if (ichar==0) ichar=statslof_addchar(STATSKILL,cpt_id_skill+2, idplayers); //Ajout si rien trouver dans le parcours
  186.   if (ichar==0) return CMDFAIL; //Can't add char
  187.   for(j=1;j<=cpt_rec_skill+1;j++) {     //parcous skill id
  188.    if(statswoe_skill[0][j] == idskill) {
  189.     iskill = j; //index skill
  190.     break;  //optimise
  191.    }
  192.   }
  193.   if (iskill==0) iskill=statslof_addskill(cpt_rec_skill+1, idskill, skilltype); //Ajout si rien trouver dans le parcours
  194.   if (iskill==0) return CMDFAIL; //Can't add skill
  195.   statswoe_skill[ichar][iskill]++;     //insert in tab
  196.   //ShowWarning("Skill added : Char : %d, skill : %d, count : %d\n",statswoe_skill[ichar][0],statswoe_skill[0][iskill],statswoe_skill[ichar][iskill]);
  197.   //statslof_display(sd, STATSKILL);
  198. }
  199. return 0;
  200. }
  201. /*
  202. * Inner fonction d'ajout d'un skill dans les stats
  203. * @Return new index
  204. */
  205. int statslof_addskill(int index, int idskill, int skilltype) {
  206. if (index>=MAX_SKILL_CNT) return 0; //Chk Array bound
  207. //ShowWarning("Skill not found, index=%d\n",index);
  208. statswoe_skill[0][index]=idskill; //insert skill id
  209. statswoe_skill[1][index]=skilltype; //insert skill type
  210. cpt_rec_skill++;   //increment skill_cnt_total
  211. return index;
  212. }
  213. /*
  214. *Fonction incrementation des consos utilises durant la woe
  215. *Appel a chaque utilisation d'un conso
  216. *
  217. * statswoe_conso[i][j] structure :
  218. * [x][0]=charid, x=[1;MAX_CHAR_ID]
  219. * [0][x]=consoid x=[1;MAX_CONSO_CNT]
  220. */
  221. int statslof_conso_cnt(struct map_session_data *sd, int idplayers, int idconso) {
  222. unsigned int i=0, j=1;
  223. unsigned int ichar=0, iconso=0;  //index for char and item
  224. cmds=CMDDEF;
  225. if (sd==NULL) return CMDFAIL; //Security check
  226. if (idplayers==0 || idconso==0) return CMDFAIL; //Security check
  227. //Woe
  228. if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
  229.   for(i=0;i<=cpt_id_conso;i++) {     //parcours char id
  230.    if(statswoe_conso[i][0] == idplayers) {
  231.     ichar = i; //index char
  232.     break;  //optimise
  233.    }
  234.   }
  235.   if (ichar==0) ichar=statslof_addchar(STATCONSO,cpt_id_conso+1, idplayers);//Ajout si rien trouver dans le parcours
  236.   if (ichar==0) return CMDFAIL; //Can't add char
  237.   for(j=1;j<=cpt_rec_conso;j++) {     //parcous skill id
  238.    if(statswoe_conso[0][j] == idconso) {
  239.     iconso = j; //index skill
  240.     break;  //optimise
  241.    }
  242.   }
  243.   if (iconso==0) iconso=statslof_addconso(cpt_rec_conso+1, idconso); //Ajout si rien trouver dans le parcours
  244.   if (iconso==0) return CMDFAIL; //Can't add conso
  245.   statswoe_conso[ichar][iconso]++;     //insert in tab
  246.   //ShowWarning("Conso added, Char : %d, conso : %d, count : %d\n",statswoe_conso[ichar][0],statswoe_conso[0][iconso],statswoe_conso[ichar][iconso]);
  247.   //statslof_display(sd, STATCONSO);
  248. }
  249. return 0;
  250. }
  251. /*
  252. * Inner fonction d'ajout d'un item dans les stats
  253. * @Return new index
  254. */
  255. int statslof_addconso(int index, int idconso) {
  256. if (index>=MAX_CONSO_CNT) return 0;
  257. //ShowWarning("Conso not found, index=%d\n",index);
  258. statswoe_conso[0][index]=idconso; //insert conso id
  259. cpt_rec_conso++;   //increment conso_cnt_total
  260. return index;
  261. }
  262. /*
  263. *Fonction incrementation des consos utilises durant la woe
  264. *Appel a chaque utilisation d'un conso
  265. *
  266. * statswoe_dmg[i][j] structure :
  267. * [x][0]=charid, x=[1;MAX_CHAR_ID]
  268. * [0][x]=dmgid x=[1;9]
  269. */
  270. int statslof_damage_cnt(struct map_session_data *sd, int idplayers, int idbyplayers,int dammage) {
  271. unsigned int i=0;
  272. unsigned int ichar=0;  //index for dmg
  273. unsigned int ichar1=0;  //index for dmg
  274. cmds=CMDDEF;
  275. if (sd==NULL) return CMDFAIL; //Security check
  276. if (idplayers==0 || dammage==0) return CMDFAIL; //Security check
  277.  
  278. //Woe
  279. if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
  280.   //Dammage rec-
  281.   switch (idplayers){
  282.    case 1288 :   //emp dmg
  283.    case 1905 :   //barri dmg
  284.    case 1907 :   //stone1 dmg
  285.    case 1908 :   //stone2 dmg
  286.    case 1899 :   //sword (guardian SE) dmg
  287.    case 1285 :   //archer
  288.    case 1286 :   //knight
  289.    case 1287 : break;  //solider (guardian FE) dmg NOTHING TO DO DMG REC BY MOB
  290.    default :         //player case
  291.     for(i=0;i<=cpt_id_dmg;i++) {     //parcours char id
  292.      if(statswoe_dmg[i][0] == idplayers) {
  293.       ichar = i; //index char
  294.       break;  //optimise
  295.      }
  296.     }
  297.     if (ichar==0) ichar=statslof_addchar(STATDMG,cpt_id_dmg+1, idplayers);//Ajout si rien trouver dans le parcours
  298.     if (ichar==0) return CMDFAIL; //Can't add char
  299.     if(dammage>statswoe_dmg[ichar][2]) statswoe_dmg[ichar][2]=dammage; //update max dmg receive
  300.     statswoe_dmg[ichar][1]+=dammage;     //update dmg tot receive
  301.    break;
  302.   }
  303.   //Dammage done
  304.   for(i=0;i<=cpt_id_dmg;i++) {     //parcours char id
  305.    if(statswoe_dmg[i][0] == idbyplayers) {
  306.     ichar1 = i; //index char
  307.     break;  //optimise
  308.    }
  309.   }
  310.   if (ichar1==0) ichar1=statslof_addchar(STATDMGDONE,cpt_id_dmg+1, idbyplayers);
  311.   if (ichar1==0) return CMDFAIL; //Can't add char
  312.   switch (idplayers){
  313.    case 1288 : statswoe_dmg[ichar1][5]+=dammage; break;    //emp dmg
  314.    case 1905 : statswoe_dmg[ichar1][6]+=dammage; break;    //barri dmg
  315.    case 1907 :          //stone1 dmg
  316.    case 1908 : statswoe_dmg[ichar1][7]+=dammage; break;    //stone2 dmg
  317.    case 1899 : statswoe_dmg[ichar1][8]+=dammage; break;    //sword (guardian SE) dmg
  318.    case 1285 :          //archer
  319.    case 1286 :         //knight
  320.    case 1287 : statswoe_dmg[ichar1][9]+=dammage; break;    //solider (guardian FE) dmg
  321.    default :         //player case
  322.     if(dammage>statswoe_dmg[ichar1][4]) statswoe_dmg[ichar1][4]=dammage; //update max dmg done
  323.     statswoe_dmg[ichar1][3]+=dammage;     //update dmg tot done
  324.    break;
  325.   }
  326.   //statslof_display(sd, STATDMG);
  327. }
  328. return 0;
  329. }
  330. /*
  331. *Fonction incrementation des kill fait durant la woe
  332. *Appel à  chaque mort d'un PC ou mob
  333. * statswoe_kill[i][j] structure :
  334. * [x][0]=charid, x=[1;MAX_CHAR_ID]
  335. * [0][x]=killid x=[1;7] death/kill/emp/barri/stone/gse/gfe
  336. */
  337. int statslof_kill_cnt(struct map_session_data *sd, int idplayers, int idkill) {
  338. unsigned int i=0, j=0;
  339. unsigned int ichar=0, ikill=0;   //index for char and kill id
  340. cmds=CMDDEF;
  341. if (sd==NULL) return CMDFAIL; //Security check
  342. if (idplayers==0 || idkill==0) return CMDFAIL; //Security check
  343. //Woe
  344. if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
  345.   for(i=0;i<=cpt_id_kill;i++) {     //parcours char id
  346.    if(statswoe_kill[i][0] == idplayers) {
  347.     ichar = i; //index char
  348.     break;  //optimise
  349.    }
  350.   }
  351.   if (ichar==0) ichar=statslof_addchar(STATKILL,cpt_id_kill+1, idplayers);//Ajout si rien trouver dans le parcours
  352.   if (ichar==0) return CMDFAIL; //Can't add char
  353.   switch(idkill){
  354.    case PLDEATH : statswoe_kill[ichar][1]++; break;//update death player
  355.    case PLKILL : statswoe_kill[ichar][2]++; break; //update kill a player
  356.    case 1288 : statswoe_kill[ichar][3]++; break; //update kill an emperium
  357.    case 1905 : statswoe_kill[ichar][4]++; break; //update kill a barricade
  358.    case 1907 :      //update kill a guardian stone1
  359.    case 1908 : statswoe_kill[ichar][5]++; break; //update kill a guardian stone2
  360.    case 1899 : statswoe_kill[ichar][6]++; break; //update kill a sword guardian (se ?)
  361.    case 1285 :     //update kill an archer guardian (fe)
  362.    case 1286 :      //update kill a knight guardian (fe)
  363.    case 1287 : statswoe_kill[ichar][7]++; break; //update kill a soldier guardian (fe)
  364.    default : return 2;    //Error if not in list
  365.   }
  366.   //statslof_display(sd, STATKILL);
  367. }
  368. return 0;
  369. }
  370. /*
  371. * Heal done and receive
  372. * healtype HEAL_REC | HEAL_DONE
  373. * HEAL_REC effectiveness heal received and recovered
  374. * HEAL_DONE heal done on target
  375. *
  376. * statswoe_kill[i][j] structure :
  377. * [x][0]=charid, x=[1;MAX_CHAR_ID]
  378. * [0][x]=healid x=[1;4] (detail on code)
  379. */
  380. int statslof_heal_cnt(struct map_session_data *sd, int idplayers, int hp, int healtype) {
  381. unsigned int i=0, j=1;
  382. unsigned int ichar=0, iheal=0;  //index for char and item
  383. cmds=CMDDEF;
  384. if (sd==NULL) return CMDFAIL; //Security check
  385. if (idplayers==0 || hp==0 || (healtype!=HEAL_DONE && healtype!=HEAL_REC)) return CMDFAIL; //Security check
  386. //Woe
  387. if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
  388.   for(i=0;i<=cpt_id_heal;i++) {     //parcours char id
  389.    if(statswoe_heal[i][0] == idplayers) {
  390.     ichar = i; //index char
  391.     break;  //optimise
  392.    }
  393.   }
  394.   if (ichar==0) ichar=statslof_addchar(STATHEAL,cpt_id_heal+1, idplayers);//Ajout si rien trouver dans le parcours
  395.   if (ichar==0) return CMDFAIL; //Can't add char
  396.   if (healtype == HEAL_DONE){
  397.    statswoe_heal[ichar][1]+=hp;   //heal done total
  398.    if (hp > statswoe_heal[ichar][2])
  399.     statswoe_heal[ichar][2]=hp;  //heal done max
  400.   } else if (healtype == HEAL_REC){
  401.    statswoe_heal[ichar][3]+=hp;   //heal receive total
  402.    if (hp > statswoe_heal[ichar][4])
  403.     statswoe_heal[ichar][4]=hp;  //heal receive max
  404.   } else return 1;
  405.   //statslof_display(sd, STATHEAL);
  406. }
  407. return 0;
  408. }
  409. /*
  410. * Inner fonction d'ajout d'une guilde dans les stats
  411. * @Return new index
  412. */
  413. int statslof_addguild(int statstype,int index, int idguild) {
  414. int iguild=0;
  415. if (index>=MAX_GUILD_ID) return 0; //Chk Array boud
  416. iguild=index;
  417.  
  418. switch(statstype) {
  419.   case STATGSKILL :
  420.    //ShowWarning("Skill : Guild not found, index=%d\n",index);
  421.    cpt_id_gskill++;   //increment nb guild in woe for statswoe_gskill tab
  422.    statswoe_gskill[iguild][0]=idguild; //insert new guild id
  423.   break;
  424.  
  425.   case STATGKILL :
  426.    //ShowWarning("Kill : Guild not found, index=%d\n",index);
  427.    cpt_id_gkill++;   //increment nb char in woe for statkill tab
  428.    statswoe_gkill[iguild][0]=idguild; //insert new char id
  429.   break;
  430. }
  431. return iguild;
  432. }
  433. /*
  434. *Fonction incrementation des guid skill utilises durant la woe
  435. *Appel a chaque utilisation d'un guildskill
  436. *
  437. * statswoe_gskill[i][j] structure :
  438. * [x][0]=guildid, x=[1;MAX_CHAR_ID]
  439. * [0][x]=skillid x=[1;4]
  440. */
  441. int statslof_gskill_cnt(struct map_session_data *sd, int idguild, int idskill){
  442. unsigned int i=0, j=1;
  443. unsigned int iguild=0, iskill=0;  //index for guild and skill
  444. cmds=CMDDEF;
  445. //ShowWarning("statslof_gskill_cnt call \n idguild=%d \n idskill=%d\n",idguild,idskill);
  446. if (sd==NULL) return CMDFAIL; //Security check
  447. if (idguild==0 || idskill==0 || (idskill!=10010 && idskill!=10011 && idskill!=10012 && idskill!=10013)) return CMDFAIL; //Security check
  448.  
  449. //Woe
  450. if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
  451.   for(i=0;i<=cpt_id_gskill;i++) {     //parcours guildid
  452.    if(statswoe_gskill[i][0] == idguild) {
  453.     iguild = i; //index char
  454.     break;  //optimise
  455.    }
  456.   }
  457.   if (iguild==0) iguild=statslof_addguild(STATGSKILL,cpt_id_gskill+1, idguild); //Ajout si rien trouver dans le parcours
  458.   if (iguild==0) return CMDFAIL; //Guild can't be added
  459.   for(j=1;j<=cpt_rec_gskill;j++) {      //parcous skill id
  460.    if(statswoe_gskill[0][j] == idskill) {
  461.     iskill = j; //index skill
  462.     break;  //optimise
  463.    }
  464.   }
  465.   if (iskill==0) iskill=statslof_addgskill(cpt_rec_gskill+1, idskill); //Ajout si rien trouver dans le parcours
  466.   if (iskill==0) return CMDFAIL; //Skill can't be added
  467.   statswoe_gskill[iguild][iskill]++;     //insert in tab
  468.   //ShowWarning("Gskill added : Guild=%d, gskill=%d, count=%d\n", statswoe_gskill[iguild][0], statswoe_gskill[0][iskill], statswoe_gskill[iguild][iskill]);
  469. }
  470. return cmds;
  471. }
  472. /*
  473. * Inner fonction d'ajout d'un skill dans les stats
  474. * @Return new index
  475. */
  476. int statslof_addgskill(int index, int idskill) {
  477. if (index>=MAX_GSKILL_CNT) return 0; //Chk Array boud
  478. //ShowWarning("GSkill %d not found in tab, index=%d\n",idskill,index);
  479. statswoe_gskill[0][index]=idskill; //insert skill id
  480. cpt_rec_gskill++;   //increment skill_cnt_total
  481. return index;
  482. }
  483. /*
  484. *Fonction incrementation des kills durant la woe
  485. *Appel a chaque mort d'un PC ou mob
  486. *
  487. * statswoe_gkill[i][j] structure :
  488. * [x][0]=guildid, x=[1;MAX_CHAR_ID]
  489. * [0][x]=killid x=[1;7]
  490. */
  491. int statslof_gkill_cnt(struct map_session_data *sd, int idguild, int idkill) {
  492. unsigned int i=0, j=0;
  493. unsigned int iguild=0, ikill=0;   //index for char and kill id
  494. cmds=CMDDEF;
  495. if (sd==NULL) return CMDFAIL; //Security check
  496. if (idguild==0 || idkill==0) return CMDFAIL; //Security check
  497. //Woe
  498. if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
  499.   for(i=0;i<=cpt_id_gkill;i++) {     //parcours char id
  500.    if(statswoe_gkill[i][0] == idguild) {
  501.     iguild = i; //index char
  502.     break;  //optimise
  503.    }
  504.   }
  505.   if (iguild==0) iguild=statslof_addguild(STATGKILL,cpt_id_gkill+1, idguild);//Ajout si rien trouver dans le parcours
  506.   if (iguild==0) return CMDFAIL; //Can't add guild
  507.   switch(idkill){
  508.    case PLDEATH : statswoe_gkill[iguild][1]++; break; //update death player
  509.    case PLKILL : statswoe_gkill[iguild][2]++; break; //update kill a playe
  510.    case 1288 : statswoe_gkill[iguild][3]++; break; //update kill an emperium
  511.    case 1905 : statswoe_gkill[iguild][4]++; break; //update kill a barricade
  512.    case 1907 :      //update kill a guardian stone1
  513.    case 1908 : statswoe_gkill[iguild][5]++; break; //update kill a guardian stone2
  514.    case 1899 : statswoe_gkill[iguild][6]++; break; //update kill a sword guardian (se ?)
  515.    case 1285 :     //update kill an archer guardian (fe)
  516.    case 1286 :      //update kill a knight guardian (fe)
  517.    case 1287 : statswoe_gkill[iguild][7]++; break; //update kill a soldier guardian (fe)
  518.    default : return 2;    //Error if not in list
  519.   }
  520. }
  521. return 0;
  522. }
  523.  
  524.  
  525. /*
  526. * Fonction d'enregistrement en CSV,
  527. * Appeler periodiquement et a la fin de la woe @TODO
  528. See Table format in _sql-files/statslof.sql
  529. */
  530. int statslof_insert_inCSV() {
  531. FILE *f;
  532. int i=0,j=0;
  533. char file[MAX_BUFFER], st[MAX_BUFFER], blankst[1];
  534. struct item_data *itemdata;
  535. cmds=CMDDEF;
  536. //Insert skill
  537. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_skillfile);
  538. if((f = fopen(file, "w"))==NULL) { //Check if file exist
  539.   ShowError("File %s, can't be create\n", file);
  540.   cmds=CMDFAIL;
  541. }
  542. else {
  543.   for(i=2;i<cpt_id_skill+2;i++) {
  544.    for(j=1;j<=cpt_rec_skill;j++){
  545.     if(statswoe_skill[i][j] != 0 && statswoe_skill[i][0] != 0)  {//fill the table with skill used > 0 count for each charid
  546.      //File format csv
  547.      fprintf(f,"%d,%d,%s,%d,%d\n",idwoe,statswoe_skill[i][0],skill_get_desc(statswoe_skill[0][j]),statswoe_skill[1][j],statswoe_skill[i][j]);
  548.     }
  549.    }
  550.   }
  551.   fclose(f);
  552.   #ifndef WIN32
  553.    chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
  554.   #endif
  555.   //ShowWarning("File %s was create successfully\n",file);
  556. }
  557. //Insert gskill
  558. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_guild_skillfile);
  559. if((f = fopen(file, "w"))==NULL) { //Check if file exist
  560.   ShowError("File %s, can't be create\n", file);
  561.   cmds=CMDFAIL;
  562. }
  563. else {
  564.   for(i=1;i<=cpt_id_gskill;i++) {
  565.    for(j=1;j<=cpt_rec_gskill;j++){
  566.     if(statswoe_gskill[i][j] != 0)  {//fill the table with skill used > 0 count for each charid
  567.      //File format csv
  568.      fprintf(f,"%d,%d,%s,%d\n",idwoe,statswoe_gskill[i][0],skill_get_desc(statswoe_gskill[0][j]),statswoe_gskill[i][j]);
  569.     }
  570.    }
  571.   }
  572.   fclose(f);
  573.   #ifndef WIN32
  574.    chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
  575.   #endif
  576.   //ShowWarning("File %s was create successfully\n",file);
  577. }
  578. //Insert conso
  579. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_consofile);
  580. if((f = fopen(file, "w"))==NULL) { //Check if file exist
  581.   ShowError("File %s, can't be create\n", file);
  582.   cmds=CMDFAIL;
  583. }
  584. else {
  585.   for(i=1;i<=cpt_id_conso;i++) {
  586.    for(j=1;j<=cpt_rec_conso;j++){
  587.     if(statswoe_conso[i][j] != 0)  {//fill the table with useitem > 0 count for each charid
  588.      itemdata=itemdb_search(statswoe_conso[0][j]);
  589.      //File format csv
  590.      fprintf(f,"%d,%d,%s,%d\n",idwoe,statswoe_conso[i][0],itemdata->jname,statswoe_conso[i][j]);
  591.     }
  592.    }
  593.   }
  594.   fclose(f);
  595.   #ifndef WIN32
  596.    chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
  597.   #endif
  598.   //ShowWarning("File %s was create successfully\n",file);
  599. }
  600. //Insert dmg
  601. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_dmgfile);
  602. if((f = fopen(file, "w"))==NULL) { //Check if file exist
  603.   ShowError("File %s, can't be create\n", file);
  604.   cmds=CMDFAIL;
  605. }
  606. else {
  607.   for(i=1;i<=cpt_id_dmg;i++) {
  608.    if(statswoe_dmg[i][1] != 0 || statswoe_dmg[i][3] != 0 || statswoe_dmg[i][5] != 0 || statswoe_dmg[i][6] != 0 || statswoe_dmg[i][7] != 0 || statswoe_dmg[i][8] != 0 || statswoe_dmg[i][9] != 0 )  {//fill the table with dmg > 0 count for each charid
  609.     //File format csv
  610.     fprintf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",idwoe,statswoe_dmg[i][0],statswoe_dmg[i][1],statswoe_dmg[i][2],statswoe_dmg[i][3],statswoe_dmg[i][4],statswoe_dmg[i][5],statswoe_dmg[i][6],statswoe_dmg[i][7],statswoe_dmg[i][8],statswoe_dmg[i][9]);
  611.    }
  612.   }
  613.   fclose(f);  
  614.   #ifndef WIN32
  615.    chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
  616.   #endif
  617.   //ShowWarning("File %s was create successfully\n",file);
  618. }
  619. //Insert heal
  620. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_healfile);
  621. if((f = fopen(file, "w"))==NULL) { //Check if file exist
  622.   ShowError("File %s, can't be create\n", file);
  623.   cmds=CMDFAIL;
  624. }
  625. else {
  626.   for(i=1;i<=cpt_id_heal;i++) {
  627.    if(statswoe_heal[i][3] != 0)  {//fill the table with heal > 0 count for each charid
  628.     //File format csv
  629.     fprintf(f,"%d,%d,%d,%d,%d,%d\n",idwoe,statswoe_heal[i][0],statswoe_heal[i][1],statswoe_heal[i][2],statswoe_heal[i][3],statswoe_heal[i][4]);
  630.    }
  631.   }
  632.   fclose(f);
  633. #ifndef WIN32
  634.   chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
  635. #endif
  636.   //ShowWarning("File %s was create successfully\n",file);
  637. }
  638. //Insert kill
  639. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_killfile);
  640. if((f = fopen(file, "w"))==NULL) { //Check if file exist
  641.   ShowError("File %s, can't be create\n", file);
  642.   cmds=CMDFAIL;
  643. }
  644. else {
  645.   for(i=1;i<=cpt_id_kill;i++) {
  646.    sprintf(st,"%s",blankst);//reinit
  647.    for(j=1;j<=MAX_KILL_CNT;j++){
  648.     //File format csv
  649.     sprintf(st,"%s,%d",st,statswoe_kill[i][j]); //Ajout champs de kill
  650.    }
  651.    fprintf(f,"%d,%d%s\n",idwoe,statswoe_kill[i][0],st);
  652.   }
  653.   fclose(f);
  654.   #ifndef WIN32
  655.    chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
  656.   #endif
  657.   //ShowWarning("File %s was create successfully\n",file);
  658. }
  659. //Insert gkill
  660. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_guild_killfile);
  661. if((f = fopen(file, "w"))==NULL) { //Check if file exist
  662.   ShowError("File %s, can't be create\n", file);
  663.   cmds=CMDFAIL;
  664. }
  665. else {
  666.   for(i=1;i<=cpt_id_gkill;i++) {
  667.    sprintf(st,"%s",blankst);//reinit
  668.    for(j=1;j<=MAX_GKILL_CNT;j++){
  669.     //File format csv
  670.     sprintf(st,"%s,%d",st,statswoe_gkill[i][j]); //Ajout champs de gkill
  671.    }
  672.    fprintf(f,"%d,%d%s\n",idwoe,statswoe_gkill[i][0],st);
  673.   }
  674.   fclose(f);
  675. #ifndef WIN32
  676.   chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
  677. #endif
  678.   //ShowWarning("File %s was create successfully\n",file);
  679. }
  680.  
  681. //ShowWarning("File creation complete cmds=%d\n",cmds);
  682. return cmds;
  683. }
  684. /*
  685. * Fonction d'enregistrement dans la BDD
  686. * Appeler par script_agitend à  chaque fin de woe.
  687. See Table format in _sql-files/statslof.sql
  688. */
  689. #ifndef TXT_ONLY
  690. int statslof_insert_inDB() {
  691. char file[MAX_BUFFER];
  692. FILE *f;
  693. cmds=CMDDEF;
  694.  
  695. if (statslof_insert_inCSV()==CMDFAIL) return CMDFAIL;  //Update and check files
  696. //Insert skill
  697. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_skillfile);
  698. if((f = fopen(file, "r"))==NULL) { //Check if file exist
  699.   ShowError("File %s, doesn't exist\n", file);
  700.   cmds=CMDFAIL;
  701. }
  702. else {
  703.   fclose (f);
  704.   sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_player_skill_db);
  705.   if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  706.    Sql_ShowDebug(mmysql_handle);
  707.    cmds=CMDFAIL;
  708.   }
  709.   else {
  710.    ShowWarning("File %s load in DB\n",file);
  711.   }
  712. }
  713. //Insert gskill
  714. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_guild_skillfile);
  715. if((f = fopen(file, "r"))==NULL) { //Check if file exist
  716.   ShowError("File %s, doesn't exist\n", file);
  717.   cmds=CMDFAIL;
  718. }
  719. else {
  720.   fclose (f);
  721.   sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_guild_skill_db);
  722.   if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  723.    Sql_ShowDebug(mmysql_handle);
  724.    cmds=CMDFAIL;
  725.   }
  726.   else {
  727.    ShowWarning("File %s load in DB\n",file);
  728.   }
  729. }
  730.  
  731. //Insert conso
  732. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_consofile);
  733. //ShowWarning("%s\n",file);
  734. if((f = fopen(file, "r"))==NULL) { //Check if file exist
  735.   ShowError("File %s, doesn't exist\n", file);
  736.   cmds=CMDFAIL;
  737. }
  738. else {
  739.   fclose (f);
  740.   sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_player_conso_db);
  741.   if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  742.    Sql_ShowDebug(mmysql_handle);
  743.    cmds=CMDFAIL;
  744.   }
  745.   else {
  746.    ShowWarning("File %s load in DB\n",file);
  747.   }
  748. }
  749.  
  750. //Insert dmg
  751. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_dmgfile);
  752. if((f = fopen(file, "r"))==NULL) { //Check if file exist
  753.   ShowError("File %s, doesn't exist\n", file);
  754.   cmds=CMDFAIL;
  755. }
  756. else {
  757.   fclose (f);
  758.   sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_player_dmg_db);
  759.   if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  760.    Sql_ShowDebug(mmysql_handle);
  761.    cmds=CMDFAIL;
  762.   }
  763.   else {
  764.    ShowWarning("File %s load in DB\n",file);
  765.   }
  766. }
  767.  
  768.  
  769. //Insert kill
  770. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_killfile);
  771. if((f = fopen(file, "r"))==NULL) { //Check if file exist
  772.   ShowError("File %s, doesn't exist\n", file);
  773.   cmds=CMDFAIL;
  774. }
  775. else {
  776.   fclose (f);
  777.   sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','",file, stats_player_kill_db);
  778.   if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  779.    Sql_ShowDebug(mmysql_handle);
  780.    cmds=CMDFAIL;
  781.   }
  782.   else {
  783.    ShowWarning("File %s load in DB\n",file);
  784.   }
  785. }
  786. //Insert heal
  787. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_healfile);
  788. if((f = fopen(file, "r"))==NULL) { //Check if file exist
  789.   ShowError("File %s, doesn't exist\n", file);
  790.   cmds=CMDFAIL;
  791. }
  792. else {
  793.   fclose (f);
  794.   sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_player_heal_db);
  795.   if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  796.    Sql_ShowDebug(mmysql_handle);
  797.    cmds=CMDFAIL;
  798.   }
  799.   else {
  800.    ShowWarning("File %s load in DB\n",file);
  801.   }
  802. }
  803. //Insert gkill
  804. sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_guild_killfile);
  805. if((f = fopen(file, "r"))==NULL) { //Check if file exist
  806.   ShowError("File %s, doesn't exist\n", file);
  807.   cmds=CMDFAIL;
  808. }
  809. else {
  810.   fclose (f);
  811.   sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_guild_kill_db);
  812.   if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  813.    Sql_ShowDebug(mmysql_handle);
  814.    cmds=CMDFAIL;
  815.   }
  816.   else {
  817.    ShowWarning("File %s load in DB\n",file);
  818.   }
  819. }
  820.  
  821. if(cmds==CMDDEF) cmds=CMDOK; //Check if cmd was all success
  822. //ShowWarning("Insert in DB complete cmds=%d\n",cmds);
  823.  
  824. return cmds;
  825. }
  826. #endif /* not TXT_ONLY */
  827.  
  828. /*
  829. * Fonction pour Reset les Stats.
  830. * Preparation pour la newt woe.
  831. * Effacement uniquement des tableau.
  832. */
  833. int statslof_reset() {
  834. char* data;
  835. char datefolder[MAX_BUFFER];
  836. cmds=statslof_init();
  837. cmds=statslof_clean_tab();
  838.  
  839. curdate=statslof_getCurrentDate();
  840. //ShowWarning("Check point reached; curdate=%d,\n",curdate);
  841.   #ifndef TXT_ONLY
  842. sprintf(query,"SELECT max(woe_id) as `woe_id` from `%s`;", stats_data);
  843. if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  844.   Sql_ShowDebug(mmysql_handle);
  845.   cmds=CMDFAIL;
  846. }
  847. while (SQL_SUCCESS == Sql_NextRow(mmysql_handle)){
  848.   Sql_GetData(mmysql_handle, 0, &data, NULL);
  849.   idwoe=atoi(data);
  850. }
  851. #else
  852.   idwoe=0;
  853. #endif /* not TXT_ONLY *///ShowWarning("Check point reached; idwoe=%d,\n",idwoe);
  854.  
  855.  
  856. sprintf(datefolder,"%s%d",stats_pathfile,curdate);
  857. #ifndef WIN32
  858. mode_t process_mask = umask(0);
  859. if(mkdir(datefolder,S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH)== -1 ) {
  860.   ShowError("Folder can't be created, check files/user permission\n");
  861.   cmds=CMDFAIL; //Quit if can't make folder
  862. }
  863. umask(process_mask);
  864. #endif
  865.  
  866. //ShowWarning("New Woe added idwoe=%d, curdate=%d\n",idwoe, curdate);
  867. if(cmds!=CMDFAIL) cmds=CMDOK;   //Check if all cmd was sucess
  868. return cmds;     //@TODO change to check 1st value too
  869. }
  870.  
  871. /*
  872. * Fonction pour nettoyer les stats.
  873. * Uniquement celle en mémoire. (tableau)
  874. */
  875. int statslof_clean_tab() {
  876. static unsigned int i=0, j=0, k=0;
  877. cmds=CMDDEF;
  878.  
  879. //Index part
  880. cpt_id_skill=0;
  881. cpt_rec_skill=0;
  882. cpt_id_conso=0;
  883. cpt_rec_conso=0;
  884. cpt_id_dmg=0;
  885. cpt_rec_dmg=0;
  886. cpt_id_kill=0;
  887. cpt_id_gkill=0;
  888. cpt_id_gskill=0;
  889. cpt_rec_gskill=0;
  890.  
  891. for(i=0;i<MAX_CHAR_ID;i++) {
  892.   statswoe_skill[i][0]=0;      //Reset cpt_id_skill
  893.   for(j=0;j<MAX_SKILL_CNT;j++) statswoe_skill[i][j]=0;  //Reset skillcount
  894.   if(j!=MAX_SKILL_CNT) {
  895.    ShowError ("Error occur in clean killcount\n j=%d | MAX_SKILL_CNT=%d\n",j,MAX_SKILL_CNT);
  896.    cmds=CMDFAIL;
  897.   }
  898.   statswoe_conso[i][0]=0;      //Reset cpt_id_conso
  899.   for(j=0;j<MAX_CONSO_CNT;j++)  statswoe_conso[i][j]=0;  //Reset conso count
  900.   if(j!=MAX_CONSO_CNT) {
  901.    ShowError ("Error occur in clean conso count\n j=%d | MAX_CONSO_CNT=%d\n",j,MAX_CONSO_CNT);
  902.    cmds=CMDFAIL;
  903.   }
  904.   statswoe_dmg[i][0]=0;      //Reset cpt_id_dmg
  905.   for (j=0;j<MAX_DMG_DONE;j++) statswoe_dmg[i][j]=0;   //Reset dammage count
  906.   if(j!=MAX_DMG_DONE) {
  907.    ShowError ("Error occur in clean dammage count\n j=%d | MAX_DMG_DONE=%d\n",j,MAX_DMG_DONE);
  908.    cmds=CMDFAIL;
  909.   }
  910.   statswoe_kill[i][0]=0;      //Reset cpt_id_kill
  911.   for(j=0;j<MAX_KILL_CNT;j++) statswoe_kill[i][j]=0;  //Reset killcount
  912.   if(j!=MAX_KILL_CNT) {
  913.    ShowError ("Error occur in clean killcount\n j=%d | MAX_KILL_CNT=%d\n",j,MAX_KILL_CNT);
  914.    cmds=CMDFAIL;
  915.   }
  916. }
  917. if(i!=MAX_CHAR_ID) { //Check if all tab erased
  918.   ShowError ("Error occur in clean_tab\n i=%d | MAX_CHAR_ID=%d\n",i,MAX_CHAR_ID);
  919.   cmds=CMDFAIL;
  920. }
  921.  
  922. for(i=0;i<MAX_GUILD_ID;i++) {
  923.   statswoe_gskill[i][0]=0;      //Reset cpt_id_gskill
  924.   for(j=0;j<MAX_GSKILL_CNT;j++) statswoe_skill[i][j]=0;  //Reset gskillcount
  925.   if(j!=MAX_GSKILL_CNT) {
  926.    ShowError ("Error occur in clean gskillcount\n j=%d | MAX_GSKILL_CNT=%d\n",j,MAX_GSKILL_CNT);
  927.    cmds=CMDFAIL;
  928.   }
  929.   statswoe_gkill[i][0]=0;      //Reset cpt_id_gkill
  930.   for(j=0;j<MAX_GKILL_CNT;j++) statswoe_gkill[i][j]=0;  //Reset killcount
  931.   if(j!=MAX_GKILL_CNT) {
  932.    ShowError ("Error occur in clean gkillcount\n j=%d | MAX_GKILL_CNT=%d\n",j,MAX_GKILL_CNT);
  933.    cmds=CMDFAIL;
  934.   }
  935. }
  936. if(i!=MAX_GUILD_ID) { //Check if all tab erased
  937.   ShowError ("Error occur in clean_tab\n i=%d | MAX_GUILD_ID=%d\n",i,MAX_GUILD_ID);
  938.   cmds=CMDFAIL;
  939. }
  940. for (j=0;j<MAX_SKILL_CNT;j++) statswoe_skill[0][j]=0;    //Reset cpt_rec_skill
  941. if(j!=MAX_SKILL_CNT) {
  942.   ShowError ("Error occur in clean cpt_rec_skill\n j=%d | MAX_SKILL_CNT=%d\n",j,MAX_SKILL_CNT);
  943.   cmds=CMDFAIL;
  944. }
  945. for (j=0;j<MAX_GSKILL_CNT;j++) statswoe_gskill[0][j]=0;   //Reset cpt_rec_gskill
  946. if(j!=MAX_GSKILL_CNT) {
  947.   ShowError ("Error occur in clean cpt_rec_skill\n j=%d | MAX_GSKILL_CNT=%d\n",j,MAX_GSKILL_CNT);
  948.   cmds=CMDFAIL;
  949. }
  950. for (j=0;j<MAX_CONSO_CNT;j++) statswoe_conso[0][j]=0;    //Reset cpt_rec_conso
  951. if(j!=MAX_CONSO_CNT) {
  952.   ShowError ("Error occur in clean cpt_rec_conso\n j=%d | MAX_CONSO_CNT=%d\n",j,MAX_CONSO_CNT);
  953.   cmds=CMDFAIL;
  954. }
  955. return cmds;
  956. }
  957. /*
  958. * Fonction pour nettoyer entierement les stats.
  959. * Appeler par script_agitstart à  chaque debut de woe.
  960. * @TODO parameter so not clean all everytime ?
  961. */
  962. int statslof_clean() {
  963. char query[QUERY_LENGTH];
  964. cmds=CMDDEF;
  965.  
  966. statslof_clean_tab();
  967.  
  968. #ifndef TXT_ONLY
  969. sprintf(query, "TRUNCATE TABLE `%s`", stats_data); //Clean sql table data
  970. if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  971.   Sql_ShowDebug(mmysql_handle);
  972.   cmds=CMDFAIL;
  973. }
  974. sprintf(query, "TRUNCATE TABLE `%s`", stats_player_skill_db); //Clean sql table skill (player)
  975. if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  976.   Sql_ShowDebug(mmysql_handle);
  977.   cmds=CMDFAIL;
  978. }
  979. sprintf(query, "TRUNCATE TABLE `%s`", stats_guild_skill_db); //Clean sql table gskill (guilde)
  980. if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  981.   Sql_ShowDebug(mmysql_handle);
  982.   cmds=CMDFAIL;
  983. }
  984. sprintf(query, "TRUNCATE TABLE `%s`", stats_player_conso_db); //Clean sql table conso
  985. if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  986.   Sql_ShowDebug(mmysql_handle);
  987.   cmds=CMDFAIL;
  988. }
  989. sprintf(query, "TRUNCATE TABLE `%s`", stats_player_dmg_db); //Clean sql table dmg
  990. if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  991.   Sql_ShowDebug(mmysql_handle);
  992.   cmds=CMDFAIL;
  993. }
  994. sprintf(query, "TRUNCATE TABLE `%s`", stats_player_heal_db); //Clean sql table heal
  995. if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  996.   Sql_ShowDebug(mmysql_handle);
  997.   cmds=CMDFAIL;
  998. }
  999. sprintf(query, "TRUNCATE TABLE `%s`",stats_player_kill_db); //Clean sql table kill (player)
  1000. if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  1001.   Sql_ShowDebug(mmysql_handle);
  1002.   cmds=CMDFAIL;
  1003. }
  1004. sprintf(query, "TRUNCATE TABLE `%s`", stats_guild_kill_db); //Clean sql table gkill (guilde)
  1005. if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
  1006.   Sql_ShowDebug(mmysql_handle);
  1007.   cmds=CMDFAIL;
  1008. }
  1009.     #endif /* not TXT_ONLY */
  1010. if(cmds!=CMDFAIL) cmds=CMDOK;   //Check if all cmd was sucess
  1011. return cmds;
  1012. }
  1013. /*
  1014. * Fonction pour activer les stats.
  1015. * Appeler par script_agitstart à  chaque debut de woe.
  1016. */
  1017. int statslof_enable(int typeStat) {
  1018. cmds=CMDDEF;     //Commande status
  1019.  
  1020. switch(typeStat) {
  1021.   case TYPEWOE :     //Enable statsWoe
  1022.    if (enable!=1) {
  1023.     enable=1;   //Activation stats woe
  1024.     statslof_init();
  1025.     cmds=CMDOK;
  1026.    }
  1027.    else cmds=CMDFAIL;
  1028.   break;
  1029.  
  1030.   case TYPERWC :     //Enable statsRWC
  1031.    if ((enable>>1)!=1) {
  1032.     enable|=2;   //Activation stats RWC
  1033.     cmds=CMDOK;
  1034.    }
  1035.    else cmds=CMDFAIL;
  1036.   break;
  1037.  
  1038.   default : cmds=CMDDEF;
  1039. }
  1040. return cmds;
  1041. }
  1042. /*
  1043. * Fonction pour activer les stats.
  1044. * Appeler par script_agitstart à  chaque debut de woe.
  1045. */
  1046. int statslof_disable(int typeStat) {
  1047. cmds=CMDDEF;    //Commande status
  1048. switch(typeStat) {
  1049.   case TYPEWOE:
  1050.    if (enable==1) {
  1051.     enable=0;  //Desactivation stats woe
  1052.     cmds=CMDOK;
  1053.    }
  1054.    else cmds=CMDFAIL;
  1055.   break;
  1056.  
  1057.   case TYPERWC :    //Disable statsRWC
  1058.    if ((enable>>1)==1) {
  1059.     int tmp=0;
  1060.     enable&=tmp<<1;  //Desactivation stats RWC
  1061.     cmds=CMDOK;
  1062.    }
  1063.    else cmds=CMDFAIL;
  1064.   break;
  1065.  
  1066.   default : cmds=CMDDEF;
  1067. }
  1068. return cmds;
  1069. }
  1070. /*
  1071. * Fonction d'affichage des stats.
  1072. * For Test mode purpose ONLY !!
  1073. */
  1074. int statslof_display(struct map_session_data *sd, int statstype){
  1075. unsigned int k=0, l=0;
  1076. char cptcharinfo[CHAT_SIZE_MAX], charinfo[CHAT_SIZE_MAX], cptguildinfo[CHAT_SIZE_MAX], guildinfo[CHAT_SIZE_MAX];
  1077. char cpt_rec_skillinfo[CHAT_SIZE_MAX], skillinfo[CHAT_SIZE_MAX];
  1078. char cpt_rec_consoinfo[CHAT_SIZE_MAX], consoinfo[CHAT_SIZE_MAX];
  1079. char cpt_rec_dmginfo[CHAT_SIZE_MAX], dmginfo[CHAT_SIZE_MAX];
  1080. char killinfo[CHAT_SIZE_MAX], healinfo[CHAT_SIZE_MAX];
  1081. struct item_data *itemdataintab;
  1082. cmds=CMDDEF;
  1083.  
  1084. if (sd==NULL) return 1; //Security check
  1085.  
  1086. switch(statstype){
  1087.   case STATSKILL :
  1088.    sprintf(cptcharinfo, "Cptchar : %d",cpt_id_skill);
  1089.    //ShowWarning("%s\n",cptcharinfo);
  1090.    clif_displaymessage(sd->fd,cptcharinfo);
  1091.    sprintf(cpt_rec_skillinfo, "Total different skill : %d ",cpt_rec_skill);
  1092.    //ShowWarning("%s\n",cpt_rec_skillinfo);
  1093.    clif_displaymessage(sd->fd,cpt_rec_skillinfo);
  1094.  
  1095.    for(k=2;k<cpt_id_skill+2;k++){
  1096.     sprintf(charinfo, "Char Info %d :",statswoe_skill[k][0]);
  1097.     //ShowWarning("%s\n",charinfo);
  1098.     clif_displaymessage(sd->fd,charinfo);
  1099.     for(l=1;l<=cpt_rec_skill;l++) {
  1100.      sprintf(skillinfo, "Skill info number :%s count :%d type :%d",skill_get_desc(statswoe_skill[0][l]),statswoe_skill[k][l],statswoe_skill[1][l]);
  1101.      //ShowWarning("%s\n",skillinfo);
  1102.      clif_displaymessage(sd->fd, skillinfo);
  1103.     }
  1104.    }
  1105.    if ((k==cpt_id_skill-1)&&(l==cpt_rec_skill)) cmds=CMDOK; //Check if was success
  1106.    else cmds=CMDFAIL;
  1107.   break;
  1108.  
  1109.   //Display conso tab
  1110.   case STATCONSO :
  1111.    sprintf(cptcharinfo, "Cptchar : %d",cpt_id_conso);
  1112.    //ShowWarning("%s\n",cptcharinfo);
  1113.    clif_displaymessage(sd->fd,cptcharinfo);
  1114.    sprintf(cpt_rec_consoinfo, "Total conso cnt : %d",cpt_rec_conso);
  1115.    //ShowWarning("%s\n",cpt_rec_consoinfo);
  1116.    clif_displaymessage(sd->fd,cpt_rec_consoinfo);
  1117.    for(k=1;k<=cpt_id_conso;k++){
  1118.     sprintf(charinfo, "Char Info %d :",statswoe_conso[k][0]);
  1119.     //ShowWarning("%s\n",charinfo);
  1120.     clif_displaymessage(sd->fd,charinfo);
  1121.     for(l=1;l<=cpt_rec_conso;l++) {
  1122.      itemdataintab=itemdb_search(statswoe_conso[0][l]);
  1123.      sprintf(consoinfo, "Item info :%s count :%d",itemdataintab->jname,statswoe_conso[k][l]);
  1124.      //ShowWarning("%s\n",consoinfo);
  1125.      clif_displaymessage(sd->fd, consoinfo);
  1126.     }
  1127.    }
  1128.    if ((k==cpt_id_conso)&&(l==cpt_rec_conso)) cmds=CMDOK; //Check if was success
  1129.    else cmds=CMDFAIL;
  1130.   break;
  1131.  
  1132.   //Display dmg tab
  1133.   case STATDMG :
  1134.    sprintf(cptcharinfo, "Cptchar : %d",cpt_id_dmg);
  1135.    //ShowWarning("%s\n",cptcharinfo);
  1136.    clif_displaymessage(sd->fd,cptcharinfo);
  1137.    sprintf(cpt_rec_dmginfo, "Total dmg cnt : %d",cpt_rec_dmg);
  1138.    //ShowWarning("%s\n",cpt_rec_dmginfo);
  1139.    clif_displaymessage(sd->fd,cpt_rec_dmginfo);
  1140.    for(k=1;k<=cpt_id_dmg;k++){
  1141.     sprintf(charinfo, "Char Info %d : ",statswoe_dmg[k][0]);
  1142.     //ShowWarning("%s\n",charinfo);
  1143.     clif_displaymessage(sd->fd,charinfo);
  1144.     sprintf(dmginfo, "Dammage rec total info :%d",statswoe_dmg[k][1]);
  1145.     //ShowWarning("%s\n",dmginfo);
  1146.     clif_displaymessage(sd->fd, dmginfo);
  1147.     sprintf(dmginfo, "Dammage rec max info :%d",statswoe_dmg[k][2]);
  1148.     //ShowWarning("%s\n",dmginfo);
  1149.     clif_displaymessage(sd->fd, dmginfo);
  1150.     sprintf(dmginfo, "Dammage done total info :%d",statswoe_dmg[k][3]);
  1151.     //ShowWarning("%s\n",dmginfo);
  1152.     clif_displaymessage(sd->fd, dmginfo);
  1153.     sprintf(dmginfo, "Dammage done max info :%d",statswoe_dmg[k][4]);
  1154.     //ShowWarning("%s\n",dmginfo);
  1155.     clif_displaymessage(sd->fd, dmginfo);
  1156.     sprintf(dmginfo, "Dammage done emp :%d",statswoe_dmg[k][5]);
  1157.     //ShowWarning("%s\n",dmginfo);
  1158.     clif_displaymessage(sd->fd, dmginfo);
  1159.     sprintf(dmginfo, "Dammage done barri :%d",statswoe_dmg[k][6]);
  1160.     //ShowWarning("%s\n",dmginfo);
  1161.     clif_displaymessage(sd->fd, dmginfo);
  1162.     sprintf(dmginfo, "Dammage done stone :%d",statswoe_dmg[k][7]);
  1163.     //ShowWarning("%s\n",dmginfo);
  1164.     clif_displaymessage(sd->fd, dmginfo);
  1165.     sprintf(dmginfo, "Dammage done guardien SE :%d",statswoe_dmg[k][8]);
  1166.     //ShowWarning("%s\n",dmginfo);
  1167.     clif_displaymessage(sd->fd, dmginfo);
  1168.     sprintf(dmginfo, "Dammage done guardien FE :%d",statswoe_dmg[k][9]);
  1169.     //ShowWarning("%s\n",dmginfo);
  1170.     clif_displaymessage(sd->fd, dmginfo);
  1171.    }
  1172.    if (k==cpt_id_dmg) cmds=CMDOK; //Check if was success
  1173.    else cmds=CMDFAIL;
  1174.   break;
  1175.  
  1176.   //Display kill tab
  1177.   case STATKILL :
  1178.    sprintf(cptcharinfo, "Cptchar : %d ",cpt_id_kill);
  1179.    //ShowWarning("%s\n",cptcharinfo);
  1180.    clif_displaymessage(sd->fd,cptcharinfo);
  1181.    for(k=1;k<=cpt_id_kill;k++){
  1182.     sprintf(charinfo, "Char Info %d : ",statswoe_kill[k][0]);
  1183.     //ShowWarning("%s\n",charinfo);
  1184.     clif_displaymessage(sd->fd,charinfo);
  1185.  
  1186.     sprintf(killinfo, "Kill info number :death count :%d",statswoe_kill[k][1]);
  1187.     //ShowWarning("%s\n",killinfo);
  1188.     clif_displaymessage(sd->fd, killinfo);
  1189.     sprintf(killinfo, "Kill info number :player count :%d",statswoe_kill[k][2]);
  1190.     //ShowWarning("%s\n",killinfo);
  1191.     clif_displaymessage(sd->fd, killinfo);
  1192.     sprintf(killinfo, "Kill info number :emperium count :%d",statswoe_kill[k][3]);
  1193.     //ShowWarning("%s\n",killinfo);
  1194.     clif_displaymessage(sd->fd, killinfo);
  1195.     sprintf(killinfo, "Kill info number :guardian (fe?) count :%d",statswoe_kill[k][4]);
  1196.     //ShowWarning("%s\n",killinfo);
  1197.     clif_displaymessage(sd->fd, killinfo);
  1198.     sprintf(killinfo, "Kill info number :guardian (se?) count :%d",statswoe_kill[k][5]);
  1199.     //ShowWarning("%s\n",killinfo);
  1200.     clif_displaymessage(sd->fd, killinfo);
  1201.     sprintf(killinfo, "Kill info number :barricade count :%d",statswoe_kill[k][6]);
  1202.     //ShowWarning("%s\n",killinfo);
  1203.     clif_displaymessage(sd->fd, killinfo);
  1204.     sprintf(killinfo, "Kill info number :stone guardian count :%d",statswoe_kill[k][7]);
  1205.     //ShowWarning("%s\n",killinfo);
  1206.     clif_displaymessage(sd->fd, killinfo);
  1207.    }
  1208.    if (k==cpt_id_kill) cmds=CMDOK; //Check if was success
  1209.    else cmds=CMDFAIL;
  1210.   break;
  1211.  
  1212.  
  1213.   case STATHEAL :
  1214.    sprintf(cptcharinfo, "Cptchar : %d ",cpt_id_heal);
  1215.    //ShowWarning("%s\n",cptcharinfo);
  1216.    clif_displaymessage(sd->fd,cptcharinfo);
  1217.    for(k=1;k<=cpt_id_heal;k++){
  1218.     sprintf(charinfo, "Char Info %d : ",statswoe_heal[k][0]);
  1219.     //ShowWarning("%s\n",charinfo);
  1220.     clif_displaymessage(sd->fd,charinfo);
  1221.  
  1222.     sprintf(healinfo, "Heal done total info :%d",statswoe_heal[k][1]);
  1223.     //ShowWarning("%s\n",healinfo);
  1224.     clif_displaymessage(sd->fd, healinfo);
  1225.     sprintf(healinfo, "Heal done max info :%d",statswoe_heal[k][2]);
  1226.     //ShowWarning("%s\n",healinfo);
  1227.     clif_displaymessage(sd->fd, healinfo);
  1228.     sprintf(healinfo, "Heal receive total info :%d",statswoe_heal[k][3]);
  1229.     //ShowWarning("%s\n",healinfo);
  1230.     clif_displaymessage(sd->fd, healinfo);
  1231.     sprintf(healinfo, "Heal receive max info :%d",statswoe_heal[k][4]);
  1232.     //ShowWarning("%s\n",healinfo);
  1233.     clif_displaymessage(sd->fd, healinfo);
  1234.    }
  1235.    if (k==cpt_id_heal) cmds=CMDOK; //Check if was success
  1236.    else cmds=CMDFAIL;
  1237.   break;
  1238.  
  1239.   case STATGSKILL :
  1240.    sprintf(cptguildinfo, "Cptguild : %d ",cpt_id_gskill);
  1241.    //ShowWarning("%s\n",cptguildinfo);
  1242.    clif_displaymessage(sd->fd,cptguildinfo);
  1243.    sprintf(cpt_rec_skillinfo, "Total different skill : %d ",cpt_rec_gskill);
  1244.    //ShowWarning("%s\n",cpt_rec_skillinfo);
  1245.    clif_displaymessage(sd->fd,cpt_rec_skillinfo);
  1246.  
  1247.    for(k=1;k<=cpt_id_gskill;k++){
  1248.     sprintf(guildinfo, "Guild Info %d : ",statswoe_gskill[k][0]);
  1249.     //ShowWarning("%s\n",guildinfo);
  1250.     clif_displaymessage(sd->fd,guildinfo);
  1251.     for(l=1;l<=cpt_rec_gskill;l++) {
  1252.      sprintf(guildinfo, "Skill info number :%s count :%d ",skill_get_desc(statswoe_gskill[0][l]),statswoe_gskill[k][l]);
  1253.      //ShowWarning("%s\n",guildinfo);
  1254.      clif_displaymessage(sd->fd, guildinfo);
  1255.     }
  1256.    }
  1257.    if ((k==cpt_id_gskill)&&(l==cpt_rec_gskill)) cmds=CMDOK; //Check if was success
  1258.    else cmds=CMDFAIL;
  1259.   break;
  1260.  
  1261.   case STATGKILL :
  1262.    sprintf(cptguildinfo, "Cptguild : %d ",cpt_id_gkill);
  1263.    //ShowWarning("%s\n",cptguildinfo);
  1264.    clif_displaymessage(sd->fd,cptguildinfo);
  1265.    for(k=1;k<=cpt_id_gkill;k++){
  1266.     sprintf(guildinfo, "Guild Info %d : ",statswoe_gkill[k][0]);
  1267.     //ShowWarning("%s\n",guildinfo);
  1268.     clif_displaymessage(sd->fd,guildinfo);
  1269.  
  1270.     sprintf(killinfo, "Kill info number :death count :%d",statswoe_gkill[k][1]);
  1271.     //ShowWarning("%s\n",killinfo);
  1272.     clif_displaymessage(sd->fd, killinfo);
  1273.     sprintf(killinfo, "Kill info number :player count :%d",statswoe_gkill[k][2]);
  1274.     //ShowWarning("%s\n",killinfo);
  1275.     clif_displaymessage(sd->fd, killinfo);
  1276.     sprintf(killinfo, "Kill info number :emperium count :%d",statswoe_gkill[k][3]);
  1277.     //ShowWarning("%s\n",killinfo);
  1278.     clif_displaymessage(sd->fd, killinfo);
  1279.     sprintf(killinfo, "Kill info number :guardian (fe?) count :%d",statswoe_gkill[k][4]);
  1280.     //ShowWarning("%s\n",killinfo);
  1281.     clif_displaymessage(sd->fd, killinfo);
  1282.     sprintf(killinfo, "Kill info number :guardian (se?) count :%d",statswoe_gkill[k][5]);
  1283.     //ShowWarning("%s\n",killinfo);
  1284.     clif_displaymessage(sd->fd, killinfo);
  1285.     sprintf(killinfo, "Kill info number :barricade count :%d",statswoe_gkill[k][6]);
  1286.     //ShowWarning("%s\n",killinfo);
  1287.     clif_displaymessage(sd->fd, killinfo);
  1288.     sprintf(killinfo, "Kill info number :stone guardian count :%d",statswoe_gkill[k][7]);
  1289.     //ShowWarning("%s\n",killinfo);
  1290.     clif_displaymessage(sd->fd, killinfo);
  1291.    }
  1292.    //ShowWarning("k=%d, cpt=%d\n",k, cpt_id_gkill);
  1293.    if (k==cpt_id_gkill) cmds=CMDOK; //Check if was success
  1294.    else cmds=CMDFAIL;
  1295.   break;
  1296.  
  1297.   default : cmds=CMDDEF;
  1298. }
  1299.  
  1300. return cmds;
  1301. }
  1302. /*
  1303. * Fonction pour simuler le fonctionnement IG
  1304. * Genere des stats alétoire et regarde le fonctionnement de nos methodes
  1305. */
  1306. int statslof_test(struct map_session_data *sd){
  1307. // Oki ca bug un peu bcp xd =)
  1308. int i=0, j=0, tmp=0;
  1309. int idplayer=0, idguild, idskill=0, idconso=0, idkill=0, idbyplayer=0, dammage=0,type=0, heal=0;
  1310. static unsigned int idcharmin=100025, idcharmax=172829, idguildmax=1165;
  1311. static unsigned int idskillmin=1, idskillmax=544;
  1312. static unsigned int idconsomin=500, idconsomax=700;
  1313. static unsigned int dmgmin=10000, dmgmax=300000, healmin=600, healmax=20000;
  1314. static unsigned int idkilltab[10]={1,2,1288,1285,1286,1287,1899,1905,1907,1908};
  1315. static unsigned int gskilltab[4]={10010,10011,10012,10013};
  1316. cmds=CMDDEF;
  1317.  
  1318. if (sd==NULL) return 1; //Security check
  1319.  
  1320. if(statslof_reset()==CMDFAIL) {
  1321.   ShowError ("\n Statslof_reset Failed in a Test call\n Test is canceled");
  1322.   return CMDFAIL;
  1323. }
  1324.  
  1325. srand ( (unsigned)time ( NULL ) );
  1326. for(i=0;i<=MAX_CHAR_ID+5;i++) {
  1327.   idplayer= (rand()%(idcharmax+1-idcharmin)) + idcharmin; //[150000;180000]
  1328.  
  1329.   //Skill tests
  1330.   for (j=0;j<=MAX_SKILL_CNT+5;j++) {
  1331.    idskill=(rand()%(idskillmax+1-idskillmin)) + idskillmin; //[1;544]
  1332.    type=rand()%2; //[0;1]
  1333.    statslof_skill_cnt(sd, idplayer, idskill,type);
  1334.   }
  1335.   if (j!=MAX_SKILL_CNT+5) cmds=CMDFAIL;
  1336.  
  1337.   //Conso tests
  1338.   for (j=0;j<=MAX_CONSO_CNT+5;j++) {
  1339.    idconso=(rand()%(idconsomax+1-idconsomin)) + idconsomin; //[500;700]
  1340.    statslof_conso_cnt(sd, idplayer, idconso);
  1341.   }
  1342.   if (j!=MAX_CONSO_CNT+5) cmds=CMDFAIL;
  1343.  
  1344.   //Kill tests
  1345.   for (j=0;j<=MAX_KILL_CNT+5;j++) {
  1346.    tmp=(rand()% 10); //[0;9]
  1347.    idkill=idkilltab[tmp];
  1348.    statslof_kill_cnt(sd, idplayer, idkill);
  1349.   }
  1350.   if (j!=MAX_KILL_CNT+5) cmds=CMDFAIL;
  1351.  
  1352.   //Dmg tests
  1353.   for (j=0;j<=MAX_DMG_DONE+5;j++) {
  1354.    dammage=(rand()%(dmgmax+1-dmgmin)) + dmgmin;
  1355.    idbyplayer=(rand()%(idcharmax+1-idcharmin)) + idcharmin; //[150000;180000]
  1356.    statslof_damage_cnt(sd, idplayer, idbyplayer, dammage);
  1357.   }
  1358.   if (j!=MAX_DMG_DONE+5) cmds=CMDFAIL;
  1359.  
  1360.   //Heal tests
  1361.   for (j=0;j<=MAX_DMG_DONE+5;j++) {
  1362.    heal=(rand()%(healmax+1-healmin)) + healmin; //[600;20000]
  1363.    type=rand()%2; //[0;1]
  1364.    statslof_heal_cnt(sd, idplayer, heal, type);
  1365.   }
  1366.   if (j!=MAX_DMG_DONE+5) cmds=CMDFAIL;
  1367. }
  1368. if (i!=MAX_CHAR_ID+5) cmds=CMDFAIL;
  1369. //ShowWarning("Char simulation complete\n");
  1370.  
  1371. for(i=0; i<=MAX_GUILD_ID+5; i++){
  1372.   idguild= (rand()%idguildmax)+1; //[1;1165]
  1373.  
  1374.   //Skill tests
  1375.   for (j=0;j<=MAX_GSKILL_CNT+5;j++) {
  1376.    tmp=(rand()% 4); //[0;3]
  1377.    idskill=gskilltab[tmp];
  1378.    statslof_gskill_cnt(sd, idguild, idskill);
  1379.   }
  1380.   if (j!=MAX_GSKILL_CNT+5) cmds=CMDFAIL;
  1381.  
  1382.   //Kill tests
  1383.   for (j=0;j<=MAX_GKILL_CNT+5;j++) {
  1384.    tmp=(rand()% 10); //[0;9]
  1385.    idkill=idkilltab[tmp];
  1386.    statslof_gkill_cnt(sd, idguild, idkill);
  1387.   }
  1388.   if (j!=MAX_GKILL_CNT+5) cmds=CMDFAIL;
  1389. }
  1390. if (i!=MAX_GUILD_ID+5) cmds=CMDFAIL;
  1391. //ShowWarning("Guild simulation complete\n");
  1392. #ifndef TXT_ONLY
  1393. tmp=statslof_insert_inDB();
  1394. #endif /* not TXT_ONLY */
  1395. if (tmp!=CMDOK) cmds=CMDFAIL;
  1396.  
  1397. //ShowWarning("Full simulation complete\n");
  1398. if(cmds==CMDDEF) cmds=CMDOK;
  1399. return cmds;
  1400. }
  1401. // getCurrentTime()
  1402. // returns int in this format hhmmss
  1403. int statslof_getCurrentTime(){
  1404. time_t rawtime;
  1405. struct tm * timeinfo;
  1406. int rtime=0,h=0,m=0,s=0;
  1407. time ( &rawtime );
  1408. timeinfo = localtime ( &rawtime );
  1409. mktime ( timeinfo );
  1410. #ifndef WIN32
  1411. h = timeinfo->tm_hour*pow(10,4);
  1412. m = timeinfo->tm_min*pow(10,2);
  1413. s = timeinfo->tm_sec;
  1414. rtime = h+m+s;
  1415. #endif
  1416. return rtime;
  1417. }
  1418. // getCurrentDate()
  1419. // returns int in this format yyyymmdd
  1420. //@TODO adapt format for SQL yyyy-mm-dd should be better.
  1421. int statslof_getCurrentDate(){
  1422. time_t rawtime;
  1423. struct tm * timeinfo;
  1424. int rtime=0,y=0,m=0,d=0;
  1425. time ( &rawtime );
  1426. timeinfo = localtime ( &rawtime );
  1427. mktime ( timeinfo );
  1428. #ifndef WIN32
  1429. y = (timeinfo->tm_year+1900)*pow(10,4);
  1430. m = (timeinfo->tm_mon+1)*pow(10,2);
  1431. d = timeinfo->tm_mday;
  1432. rtime = y+m+d;
  1433. #endif
  1434. return rtime;
  1435. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement