summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-04-22 01:42:02 +0200
committerHaru <haru@dotalux.com>2016-04-22 11:24:44 +0200
commit5ec67b19fdb3387aea790f8d8a40071087b93443 (patch)
treebdfc974562d770849f2d147d585ee5ed3356e6ef /src/map
parente35bdc6974663ad11317892ba757dcb35b34be6d (diff)
downloadhercules-5ec67b19fdb3387aea790f8d8a40071087b93443.tar.gz
hercules-5ec67b19fdb3387aea790f8d8a40071087b93443.tar.bz2
hercules-5ec67b19fdb3387aea790f8d8a40071087b93443.tar.xz
hercules-5ec67b19fdb3387aea790f8d8a40071087b93443.zip
Fixed an issue that could prevent a mvp reward to be ignored
- During the randomization of the list, an entry could be overwritten under certain (rare) conditions. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/mob.c92
1 files changed, 47 insertions, 45 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index c765e7d63..6a2fc8304 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -2556,60 +2556,62 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) {
pc->gainexp(mvp_sd, &md->bl, mexp,0, false);
log_mvp[1] = mexp;
- if( !(map->list[m].flag.nomvploot || type&1) ) {
+ if (!(map->list[m].flag.nomvploot || type&1)) {
/* pose them randomly in the list -- so on 100% drop servers it wont always drop the same item */
- int mdrop_id[MAX_MVP_DROP];
- int mdrop_p[MAX_MVP_DROP];
- struct item item;
-
- memset(&mdrop_id,0,MAX_MVP_DROP*sizeof(int));
-
- for(i = 0; i < MAX_MVP_DROP; i++) {
- while( 1 ) {
- int va = rnd()%MAX_MVP_DROP;
- if( !mdrop_id[va] || !md->db->mvpitem[i].nameid ) {
- mdrop_id[va] = md->db->mvpitem[i].nameid;
- mdrop_p[va] = md->db->mvpitem[i].p;
- break;
- }
- }
+ struct {
+ int nameid;
+ int p;
+ } mdrop[MAX_MVP_DROP] = { { 0 } };
+
+ for (i = 0; i < MAX_MVP_DROP; i++) {
+ int rpos;
+ if (md->db->mvpitem[i].nameid == 0)
+ continue;
+ do {
+ rpos = rnd()%MAX_MVP_DROP;
+ } while (mdrop[rpos].nameid != 0);
+
+ mdrop[rpos].nameid = md->db->mvpitem[i].nameid;
+ mdrop[rpos].p = md->db->mvpitem[i].p;
}
- for(i = 0; i < MAX_MVP_DROP; i++) {
- struct item_data *data;
- if(mdrop_id[i] <= 0)
+ for (i = 0; i < MAX_MVP_DROP; i++) {
+ struct item_data *data = NULL;
+ int rate = 0;
+
+ if (mdrop[i].nameid <= 0)
continue;
- if(! (data = itemdb->exists(mdrop_id[i])) )
+ if ((data = itemdb->exists(mdrop[i].nameid)) == NULL)
continue;
- temp = mdrop_p[i];
- if(temp <= 0 && !battle_config.drop_rate0item)
- temp = 1;
- if(temp <= rnd()%10000+1) //if ==0, then it doesn't drop
- continue;
+ rate = mdrop[i].p;
+ if (rate <= 0 && !battle_config.drop_rate0item)
+ rate = 1;
+ if (rate > rnd()%10000) {
+ struct item item = { 0 };
+
+ item.nameid = mdrop[i].nameid;
+ item.identify = itemdb->isidentified2(data);
+ clif->mvp_item(mvp_sd, item.nameid);
+ log_mvp[0] = item.nameid;
+
+ //A Rare MVP Drop Global Announce by Lupus
+ if (rate <= battle_config.rare_drop_announce) {
+ char message[128];
+ sprintf(message, msg_txt(541), mvp_sd->status.name, md->name, data->jname, rate/100.);
+ //MSG: "'%s' won %s's %s (chance: %0.02f%%)"
+ intif->broadcast(message, strlen(message)+1, BC_DEFAULT);
+ }
- memset(&item,0,sizeof(item));
- item.nameid=mdrop_id[i];
- item.identify= itemdb->isidentified2(data);
- clif->mvp_item(mvp_sd,item.nameid);
- log_mvp[0] = item.nameid;
-
- //A Rare MVP Drop Global Announce by Lupus
- if(temp<=battle_config.rare_drop_announce) {
- char message[128];
- sprintf (message, msg_txt(541), mvp_sd->status.name, md->name, data->jname, temp/100.);
- //MSG: "'%s' won %s's %s (chance: %0.02f%%)"
- intif->broadcast(message, strlen(message)+1, BC_DEFAULT);
- }
+ if((temp = pc->additem(mvp_sd,&item,1,LOG_TYPE_PICKDROP_PLAYER)) != 0) {
+ clif->additem(mvp_sd,0,0,temp);
+ map->addflooritem(&md->bl, &item, 1, mvp_sd->bl.m, mvp_sd->bl.x, mvp_sd->bl.y, mvp_sd->status.char_id, (second_sd?second_sd->status.char_id : 0), (third_sd ? third_sd->status.char_id : 0), 1);
+ }
- if((temp = pc->additem(mvp_sd,&item,1,LOG_TYPE_PICKDROP_PLAYER)) != 0) {
- clif->additem(mvp_sd,0,0,temp);
- map->addflooritem(&md->bl, &item, 1, mvp_sd->bl.m, mvp_sd->bl.x, mvp_sd->bl.y, mvp_sd->status.char_id, (second_sd?second_sd->status.char_id : 0), (third_sd ? third_sd->status.char_id : 0), 1);
+ //Logs items, MVP prizes [Lupus]
+ logs->pick_mob(md, LOG_TYPE_MVP, -1, &item, data);
+ break;
}
-
- //Logs items, MVP prizes [Lupus]
- logs->pick_mob(md, LOG_TYPE_MVP, -1, &item, data);
- break;
}
}