Guest User

pc_out_of_pvp(sd) by pan

a guest
Feb 6th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 9.22 KB | None | 0 0
  1. diff --git a/src/map/atcommand.c b/src/map/atcommand.c
  2. index 6177fad..42f5e10 100644
  3. --- a/src/map/atcommand.c
  4. +++ b/src/map/atcommand.c
  5. @@ -868,13 +868,16 @@ static inline const char* atcommand_help_string(AtCommandInfo *info) {
  6.         else
  7.             status->set_viewdata(&sd->bl, sd->status.class_);
  8.         clif->message(fd, msg_txt(10)); // Invisible: Off
  9. +
  10. +       if( !pc_out_of_pvp(sd) )
  11. +       {
  12. +           // increment the number of pvp players on the map
  13. +           map->list[sd->bl.m].users_pvp++;
  14.        
  15. -       // increment the number of pvp players on the map
  16. -       map->list[sd->bl.m].users_pvp++;
  17. -      
  18. -       if( map->list[sd->bl.m].flag.pvp && !map->list[sd->bl.m].flag.pvp_nocalcrank ) {
  19. -           // register the player for ranking calculations
  20. -           sd->pvp_timer = timer->add( timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0 );
  21. +           if( map->list[sd->bl.m].flag.pvp && !map->list[sd->bl.m].flag.pvp_nocalcrank ) {
  22. +               // register the player for ranking calculations
  23. +               sd->pvp_timer = timer->add( timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0 );
  24. +           }
  25.         }
  26.         //bugreport:2266
  27.         map->foreachinmovearea(clif->insight, &sd->bl, AREA_SIZE, sd->bl.x, sd->bl.y, BL_ALL, &sd->bl);
  28. @@ -882,14 +885,17 @@ static inline const char* atcommand_help_string(AtCommandInfo *info) {
  29.         sd->sc.option |= OPTION_INVISIBLE;
  30.         sd->vd.class_ = INVISIBLE_CLASS;
  31.         clif->message(fd, msg_txt(11)); // Invisible: On
  32. +
  33. +       if( !pc_out_of_pvp(sd) )
  34. +       {
  35. +           // decrement the number of pvp players on the map
  36. +           map->list[sd->bl.m].users_pvp--;
  37.        
  38. -       // decrement the number of pvp players on the map
  39. -       map->list[sd->bl.m].users_pvp--;
  40. -      
  41. -       if( map->list[sd->bl.m].flag.pvp && !map->list[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER ) {
  42. -           // unregister the player for ranking
  43. -           timer->delete( sd->pvp_timer, pc->calc_pvprank_timer );
  44. -           sd->pvp_timer = INVALID_TIMER;
  45. +           if( map->list[sd->bl.m].flag.pvp && !map->list[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER ) {
  46. +               // unregister the player for ranking
  47. +               timer->delete( sd->pvp_timer, pc->calc_pvprank_timer );
  48. +               sd->pvp_timer = INVALID_TIMER;
  49. +           }
  50.         }
  51.     }
  52.     clif->changeoption(&sd->bl);
  53. @@ -1477,9 +1483,12 @@ int atcommand_pvpoff_sub(struct block_list *bl,va_list ap)
  54.  {
  55.     TBL_PC* sd = (TBL_PC*)bl;
  56.     clif->pvpset(sd, 0, 0, 2);
  57. -   if (sd->pvp_timer != INVALID_TIMER) {
  58. -       timer->delete(sd->pvp_timer, pc->calc_pvprank_timer);
  59. -       sd->pvp_timer = INVALID_TIMER;
  60. +   if( !pc_out_of_pvp(sd) )
  61. +   {
  62. +       if (sd->pvp_timer != INVALID_TIMER) {
  63. +           timer->delete(sd->pvp_timer, pc->calc_pvprank_timer);
  64. +           sd->pvp_timer = INVALID_TIMER;
  65. +       }
  66.     }
  67.     return 0;
  68.  }
  69. @@ -1510,6 +1519,10 @@ int atcommand_pvpoff_sub(struct block_list *bl,va_list ap)
  70.  int atcommand_pvpon_sub(struct block_list *bl,va_list ap)
  71.  {
  72.     TBL_PC* sd = (TBL_PC*)bl;
  73. +
  74. +   if( pc_out_of_pvp(sd) )
  75. +       return 0;
  76. +
  77.     if (sd->pvp_timer == INVALID_TIMER) {
  78.         sd->pvp_timer = timer->add(timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0);
  79.         sd->pvp_rank = 0;
  80.  
  81. diff --git a/src/map/clif.c b/src/map/clif.c
  82. index 1e1a98e..b6b15a0 100644
  83. --- a/src/map/clif.c
  84. +++ b/src/map/clif.c
  85. @@ -5785,6 +5785,9 @@ void clif_map_type(struct map_session_data* sd, enum map_type type) {
  86.  /// 019a <id>.L <ranking>.L <total>.L
  87.  void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  88.  {
  89. +   if( pc_out_of_pvp(sd) )
  90. +       return;
  91. +
  92.     if(type == 2) {
  93.         int fd = sd->fd;
  94.         WFIFOHEAD(fd,packet_len(0x19a));
  95. @@ -9306,7 +9309,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
  96.         sd->state.hpmeter_visible = 1;
  97.     }
  98.    
  99. -   if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  100. +   if( !(sd->sc.option&OPTION_INVISIBLE) && !pc_out_of_pvp(sd) ) { // increment the number of pvp players on the map
  101.         map->list[sd->bl.m].users_pvp++;
  102.     }
  103.    
  104. @@ -9327,7 +9330,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
  105.  
  106.     if( sd->bg_id ) clif->bg_hp(sd); // BattleGround System
  107.    
  108. -   if(map->list[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  109. +   if(map->list[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE) && !pc_out_of_pvp(sd)) {
  110.         if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  111.             if (!map->list[sd->bl.m].flag.pvp_nocalcrank)
  112.                 sd->pvp_timer = timer->add(timer->gettick()+200, pc->calc_pvprank_timer, sd->bl.id, 0);
  113.  
  114. @@ -1323,7 +1359,7 @@ int pc_reg_received(struct map_session_data *sd)
  115.         clif->pLoadEndAck(sd->fd, sd);
  116.     }
  117.  
  118. -   if( sd->sc.option & OPTION_INVISIBLE ) {
  119. +   if( sd->sc.option & OPTION_INVISIBLE && !pc_out_of_pvp(sd) ) {
  120.         sd->vd.class_ = INVISIBLE_CLASS;
  121.         clif->message(sd->fd, msg_txt(11)); // Invisible: On
  122.         // decrement the number of pvp players on the map
  123. @@ -9070,7 +9106,8 @@ int pc_calc_pvprank_sub(struct block_list *bl,va_list ap)
  124.     sd1=(struct map_session_data *)bl;
  125.     sd2=va_arg(ap,struct map_session_data *);
  126.  
  127. -   if( sd1->sc.option&OPTION_INVISIBLE || sd2->sc.option&OPTION_INVISIBLE )
  128. +   if( sd1->sc.option&OPTION_INVISIBLE || sd2->sc.option&OPTION_INVISIBLE
  129. +       || pc_out_of_pvp(sd1) || pc_out_of_pvp(sd2) )
  130.     {// cannot register pvp rank for hidden GMs
  131.         return 0;
  132.     }
  133. @@ -9105,7 +9142,7 @@ int pc_calc_pvprank_timer(int tid, int64 tick, int id, intptr_t data) {
  134.         return 0;
  135.     sd->pvp_timer = INVALID_TIMER;
  136.  
  137. -   if( sd->sc.option&OPTION_INVISIBLE )
  138. +   if( sd->sc.option&OPTION_INVISIBLE || pc_out_of_pvp(sd) )
  139.     {// do not calculate the pvp rank for a hidden GM
  140.         return 0;
  141.     }
  142. diff --git a/src/map/pc.h b/src/map/pc.h
  143. index 30a24c0..2ae2e5d 100644
  144. --- a/src/map/pc.h
  145. +++ b/src/map/pc.h
  146. @@ -698,6 +698,7 @@ enum equip_pos {
  147.  #define pc_has_permission(sd,permission) ( ((sd)->extra_temp_permissions&(permission)) != 0 || ((sd)->group->e_permissions&(permission)) != 0 )
  148.  #define pc_can_give_items(sd) ( pc_has_permission((sd),PC_PERM_TRADE) )
  149.  #define pc_can_give_bound_items(sd) ( pc_has_permission((sd),PC_PERM_TRADE_BOUND) )
  150. +#define pc_out_of_pvp(sd) ( pc_has_permission((sd), PC_OUT_PVP) )
  151.  
  152.  struct skill_tree_entry {
  153.     short id;
  154. diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c
  155. index 906462c..2dd4419 100644
  156. --- a/src/map/pc_groups.c
  157. +++ b/src/map/pc_groups.c
  158. @@ -418,6 +418,7 @@ void do_init_pc_groups(void) {
  159.         { "disable_commands_when_dead", PC_PERM_DISABLE_CMD_DEAD },
  160.         { "hchsys_admin", PC_PERM_HCHSYS_ADMIN },
  161.         { "can_trade_bound", PC_PERM_TRADE_BOUND },
  162. +       { "disable_pvp_rank", PC_OUT_PVP },
  163.     };
  164.     unsigned char i, len = ARRAYLENGTH(pc_g_defaults);
  165.    
  166. diff --git a/src/map/pc_groups.h b/src/map/pc_groups.h
  167. index 5c03f99..d76738e 100644
  168. --- a/src/map/pc_groups.h
  169. +++ b/src/map/pc_groups.h
  170. @@ -31,6 +31,7 @@ enum e_pc_permission {
  171.     PC_PERM_DISABLE_CMD_DEAD    = 0x100000,
  172.     PC_PERM_HCHSYS_ADMIN        = 0x200000,
  173.     PC_PERM_TRADE_BOUND         = 0x400000,
  174. +   PC_OUT_PVP                  = 0x800000,
  175.  };
  176.  
  177.  // Cached config settings for quick lookup
  178. diff --git a/src/map/script.c b/src/map/script.c
  179. index 21d55ca..829671d 100644
  180. --- a/src/map/script.c
  181. +++ b/src/map/script.c
  182. @@ -10746,7 +10746,7 @@ void script_detach_rid(struct script_state* st) {
  183.  /* pvp timer handling */
  184.  int script_mapflag_pvp_sub(struct block_list *bl,va_list ap) {
  185.     TBL_PC* sd = (TBL_PC*)bl;
  186. -   if (sd->pvp_timer == INVALID_TIMER) {
  187. +   if (sd->pvp_timer == INVALID_TIMER && !pc_out_of_pvp(sd)) {
  188.         sd->pvp_timer = timer->add(timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0);
  189.         sd->pvp_rank = 0;
  190.         sd->pvp_lastusers = 0;
  191. @@ -10977,7 +10977,7 @@ int script_mapflag_pvp_sub(struct block_list *bl,va_list ap) {
  192.     iter = mapit_getallusers();
  193.     for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) )
  194.     {
  195. -       if( sd->bl.m != m || sd->pvp_timer != INVALID_TIMER )
  196. +       if( sd->bl.m != m || sd->pvp_timer != INVALID_TIMER || pc_out_of_pvp(sd) )
  197.             continue; // not applicable
  198.  
  199.         sd->pvp_timer = timer->add(timer->gettick()+200,pc->calc_pvprank_timer,sd->bl.id,0);
  200. @@ -10996,7 +10996,7 @@ int buildin_pvpoff_sub(struct block_list *bl,va_list ap)
  201.  {
  202.     TBL_PC* sd = (TBL_PC*)bl;
  203.     clif->pvpset(sd, 0, 0, 2);
  204. -   if (sd->pvp_timer != INVALID_TIMER) {
  205. +   if (sd->pvp_timer != INVALID_TIMER && !pc_out_of_pvp(sd)) {
  206.         timer->delete(sd->pvp_timer, pc->calc_pvprank_timer);
  207.         sd->pvp_timer = INVALID_TIMER;
  208.     }
  209. diff --git a/src/map/unit.c b/src/map/unit.c
  210. index 320649a..ba7766b 100644
  211. --- a/src/map/unit.c
  212. +++ b/src/map/unit.c
  213. @@ -2158,7 +2158,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i
  214.             sd->npc_shopid = 0;
  215.             sd->adopt_invite = 0;
  216.  
  217. -           if(sd->pvp_timer != INVALID_TIMER) {
  218. +           if(sd->pvp_timer != INVALID_TIMER && !pc_out_of_pvp(sd)) {
  219.                 timer->delete(sd->pvp_timer,pc->calc_pvprank_timer);
  220.                 sd->pvp_timer = INVALID_TIMER;
  221.                 sd->pvp_rank = 0;
  222. @@ -2192,7 +2192,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i
  223.                     sd->debug_file, sd->debug_line, sd->debug_func, file, line, func);
  224.             } else if (--map->list[bl->m].users == 0 && battle_config.dynamic_mobs) //[Skotlex]
  225.                 map->removemobs(bl->m);
  226. -           if( !(sd->sc.option&OPTION_INVISIBLE) ) {
  227. +           if( !(sd->sc.option&OPTION_INVISIBLE) || !pc_out_of_pvp(sd) ) {
  228.                 // decrement the number of active pvp players on the map
  229.                 --map->list[bl->m].users_pvp;
  230.             }
Advertisement
Add Comment
Please, Sign In to add comment