Advertisement
dreamunreal

Advanced common drop system

Dec 26th, 2011
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.96 KB | None | 0 0
  1. Index: conf/battle/drops.conf
  2. ===================================================================
  3. --- conf/battle/drops.conf  (版本 15049)
  4. +++ conf/battle/drops.conf  (工作副本)
  5. @@ -146,3 +146,10 @@
  6.  // 333 = show announces for 3.33% or lower drop chance items
  7.  // 10000 = show announces for all items
  8.  rare_drop_announce: 0
  9. +
  10. +// enable common drop advanced
  11. +// if switch on that common drop suport format must be
  12. +// mobid,itemid,droprate
  13. +// but switch off that common drop suport format can be
  14. +// anything,itemid,droprate
  15. +common_drop.adv_flag: 1
  16. Index: db/item_droprate.txt
  17. ===================================================================
  18. --- db/item_droprate.txt    (版本 0)
  19. +++ db/item_droprate.txt    (版本 0)
  20. @@ -0,0 +1,11 @@
  21. +// Advanced common drop data base
  22. +// common drop type 1: Advanced mode. -> conf/drop.conf -> common_drop.adv_flag: 1
  23. +// e.g 1: set knight of abyss's knight of abyss card's drop rate to 100%
  24. +// 1219,4120,10000
  25. +// e.g 2: set moonlight_flower's elunium's drop rate to 0.01%
  26. +// 1150,985,1
  27. +//
  28. +// common drop type 2: Ind's mode. -> conf/drop.conf -> common_drop.adv_flag: 0
  29. +// e.g : set any monster's elunium's drop rate to 100%
  30. +// X,985,10000
  31. +// X can be any number
  32. \ No newline at end of file
  33. Index: src/map/battle.c
  34. ===================================================================
  35. --- src/map/battle.c    (版本 15049)
  36. +++ src/map/battle.c    (工作副本)
  37. @@ -4023,6 +4023,7 @@
  38.     { "bg_magic_attack_damage_rate",        &battle_config.bg_magic_damage_rate,            60,     0,      INT_MAX,        },
  39.     { "bg_misc_attack_damage_rate",         &battle_config.bg_misc_damage_rate,             60,     0,      INT_MAX,        },
  40.     { "bg_flee_penalty",                    &battle_config.bg_flee_penalty,                 20,     0,      INT_MAX,        },
  41. +   { "common_drop.adv_flag",               &battle_config.common_drop_flag,                 1,     0,      1,              },
  42.  };
  43.  
  44.  
  45. Index: src/map/battle.h
  46. ===================================================================
  47. --- src/map/battle.h    (版本 15049)
  48. +++ src/map/battle.h    (工作副本)
  49. @@ -497,6 +497,7 @@
  50.     int bg_magic_damage_rate;
  51.     int bg_misc_damage_rate;
  52.     int bg_flee_penalty;
  53. +   int common_drop_flag;
  54.  } battle_config;
  55.  
  56.  void do_init_battle(void);
  57. Index: src/map/mob.c
  58. ===================================================================
  59. --- src/map/mob.c   (版本 15049)
  60. +++ src/map/mob.c   (工作副本)
  61. @@ -66,6 +66,10 @@
  62.  static struct eri *item_drop_ers; //For loot drops delay structures.
  63.  static struct eri *item_drop_list_ers;
  64.  
  65. +// common drop type 1 advanced mode and type 2 Ind mode. by [dreamunreal]
  66. +int common_drop1[MAX_MOB_DB][0x8000];
  67. +int common_drop2[0x8000];
  68. +
  69.  static struct {
  70.     int qty;
  71.     int class_[350];
  72. @@ -3610,6 +3614,14 @@
  73.             break;
  74.         }
  75.         db->dropitem[i].p = mob_drop_adjust(rate, rate_adjust, ratemin, ratemax);
  76. +
  77. +       // set type 1 or type 2 drop rate. by [dreamunreal]
  78. +       if(battle_config.common_drop_flag)
  79. +           if(common_drop1[class_][db->dropitem[i].nameid])
  80. +               db->dropitem[i].p = common_drop1[class_][db->dropitem[i].nameid];
  81. +       else
  82. +           if(common_drop2[db->dropitem[i].nameid])
  83. +               db->dropitem[i].p = common_drop2[db->dropitem[i].nameid];
  84.        
  85.         //calculate and store Max available drop chance of the item
  86.         if( db->dropitem[i].p && (class_ < 1324 || class_ > 1363) && (class_ < 1938 || class_ > 1946) )
  87. @@ -4272,8 +4284,71 @@
  88.     return true;
  89.  }
  90.  
  91. +// set common droprate. by [dreamunreal]
  92. +static bool common_parse_drop(char** str) {
  93. +   int ratio = atoi(str[2]);
  94. +   if( mobdb_checkid(atoi(str[0])) == 0 && battle_config.common_drop_flag)
  95. +       return false; // mobid is dummy ? if type 2 is selected. that mobid check will be skip.
  96. +   if( itemdb_exists(atoi(str[1])) == NULL )
  97. +       return false; // requet unexists item
  98. +   if( ratio < 1 )
  99. +       ratio = 1; // low than 0.01% default to 0.01%
  100. +   if( ratio > 10000 ) {
  101. +       ratio = 10000; // high than 100% default to 100%
  102. +       ShowWarning("[Common Drop] ItemID: %d droprate high than 100%%,default to 100%%.\n",atoi(str[1]));
  103. +   }
  104. +   if(battle_config.common_drop_flag)
  105. +       common_drop1[atoi(str[0])][atoi(str[1])] = ratio;
  106. +   else
  107. +       common_drop2[atoi(str[1])] = ratio;
  108. +   return true;
  109. +}
  110. +// item_droprate.txt loaded. by [dreamunreal]
  111. +void mob_common_droprate(void) {
  112. +       uint32 lines = 0, count = 0;
  113. +       char line[1024], path[256], filename[20] = "item_droprate.txt";
  114. +       FILE* fp;
  115. +       sprintf(path, "%s/%s", db_path,filename);
  116. +       fp = fopen(path, "r");
  117. +       if(fp == NULL) {
  118. +           ShowWarning("[Common Drop] Faild to open file '%s'.\n",path);
  119. +           return;
  120. +       }
  121. +
  122. +       // process rows one by one
  123. +       while(fgets(line, sizeof(line), fp))
  124. +       {
  125. +           char *str[3], *p, *np;
  126. +           int i;
  127. +          
  128. +           lines++;
  129. +           if(line[0] == '/' && line[1] == '/')
  130. +               continue;
  131. +           for(i = 0, p = line; i < 3; i++)
  132. +           {
  133. +               str[i] = p;
  134. +               if((np = strchr(p, ',')) != NULL) {
  135. +                   *np = '\0'; p = np + 1;
  136. +               }
  137. +           }
  138. +           if(i < 3) {
  139. +               ShowWarning("[Common Drop] MobID: %d,ItemID: %d, Droprate: %d skip.\n", atoi(str[0]),atoi(str[1]),atoi(str[2]));
  140. +               continue;
  141. +           }
  142. +          
  143. +           if (!common_parse_drop(str))
  144. +               continue;  
  145. +           count++;
  146. +       }
  147. +       fclose(fp);
  148. +       ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count,path);
  149. +   return;
  150. +}
  151. +
  152.  static void mob_load(void)
  153.  {
  154. +   // load common drop function. by [dreamunreal]
  155. +   mob_common_droprate();
  156.  #ifndef TXT_ONLY
  157.     if(db_use_sqldbs)
  158.         mob_read_sqldb();
  159. @@ -4290,8 +4365,22 @@
  160.  
  161.  void mob_reload(void)
  162.  {
  163. -   int i;
  164. +   int i,j;
  165.  
  166. +   // clean common drop when reload mob_db. by [dreamunral]
  167. +   if(battle_config.common_drop_flag) // here is type 1
  168. +   {
  169. +       for(i = 0; i < MAX_MOB_DB; i++)
  170. +           for(j = 0; j < 0x8000; j++)
  171. +               if(common_drop1[i][j])
  172. +                   common_drop1[i][j] = 0;
  173. +   }
  174. +   else // here is type 2
  175. +   {
  176. +       for(i = 0; i < 0x8000; i++)
  177. +           if(common_drop2[i]) common_drop2[i] = 0;
  178. +   }
  179. +
  180.     //Mob skills need to be cleared before re-reading them. [Skotlex]
  181.     for (i = 0; i < MAX_MOB_DB; i++)
  182.         if (mob_db_data[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement