diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-09-28 22:36:21 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-10-02 21:41:55 +0300 |
commit | 0528b1a5f0b3012c2ff91d364c73e9cb4513fd38 (patch) | |
tree | 064e7c3696b27f3ceb9690aef458b0f61834b53f /src | |
parent | 16b4e9a8a2ee0eae30d18bdf30ed0a24d85200bb (diff) | |
download | hercules-0528b1a5f0b3012c2ff91d364c73e9cb4513fd38.tar.gz hercules-0528b1a5f0b3012c2ff91d364c73e9cb4513fd38.tar.bz2 hercules-0528b1a5f0b3012c2ff91d364c73e9cb4513fd38.tar.xz hercules-0528b1a5f0b3012c2ff91d364c73e9cb4513fd38.zip |
Fix getting achievement reward packets order.
Also split achievement reward function to parts.
Diffstat (limited to 'src')
-rw-r--r-- | src/map/achievement.c | 66 | ||||
-rw-r--r-- | src/map/achievement.h | 4 | ||||
-rw-r--r-- | src/map/pc.c | 2 | ||||
-rw-r--r-- | src/map/pc.h | 2 |
4 files changed, 47 insertions, 27 deletions
diff --git a/src/map/achievement.c b/src/map/achievement.c index 2450cfb49..68fc8a983 100644 --- a/src/map/achievement.c +++ b/src/map/achievement.c @@ -1016,45 +1016,56 @@ static bool achievement_check_title(struct map_session_data *sd, int title_id) { return false; } -/** - * Achievement rewards are given to player - * @param sd session data - * @param ad achievement data - */ -static void achievement_get_rewards(struct map_session_data *sd, const struct achievement_data *ad) +static void achievement_get_rewards_buffs(struct map_session_data *sd, const struct achievement_data *ad) { - int i = 0; - struct achievement *ach = NULL; - nullpo_retv(sd); nullpo_retv(ad); - if ((ach = achievement->ensure(sd, ad)) == NULL) - return; - - /* Buff */ if (ad->rewards.bonus != NULL) script->run(ad->rewards.bonus, 0, sd->bl.id, 0); +} - /* Give Items */ - for (i = 0; i < VECTOR_LENGTH(ad->rewards.item); i++) { - struct item it = { 0 }; - int total = 0; +// TODO: kro send items by rodex +static void achievement_get_rewards_items(struct map_session_data *sd, const struct achievement_data *ad) +{ + nullpo_retv(sd); + nullpo_retv(ad); - it.nameid = VECTOR_INDEX(ad->rewards.item, i).id; - total = VECTOR_INDEX(ad->rewards.item, i).amount; + struct item it = { 0 }; + it.identify = 1; - it.identify = 1; + for (int i = 0; i < VECTOR_LENGTH(ad->rewards.item); i++) { + it.nameid = VECTOR_INDEX(ad->rewards.item, i).id; + int total = VECTOR_INDEX(ad->rewards.item, i).amount; //Check if it's stackable. if (!itemdb->isstackable(it.nameid)) { - int j = 0; - for (j = 0; j < total; ++j) - pc->additem(sd, &it, (it.amount = 1), LOG_TYPE_SCRIPT); + it.amount = 1; + for (int j = 0; j < total; ++j) + pc->additem(sd, &it, 1, LOG_TYPE_SCRIPT); } else { - pc->additem(sd, &it, (it.amount = total), LOG_TYPE_SCRIPT); + it.amount = total; + pc->additem(sd, &it, total, LOG_TYPE_SCRIPT); } } +} + +/** + * Achievement rewards are given to player + * @param sd session data + * @param ad achievement data + */ +static bool achievement_get_rewards(struct map_session_data *sd, const struct achievement_data *ad) +{ + nullpo_retr(false, sd); + nullpo_retr(false, ad); + + struct achievement *ach = achievement->ensure(sd, ad); + if (ach == NULL) + return false; + + /* Buff */ + achievement->get_rewards_buffs(sd, ad); ach->rewarded_at = time(NULL); @@ -1066,6 +1077,11 @@ static void achievement_get_rewards(struct map_session_data *sd, const struct ac clif->achievement_send_update(sd->fd, sd, ad); // send update. clif->achievement_reward_ack(sd->fd, sd, ad); } + + /* Give Items */ + achievement->get_rewards_items(sd, ad); + + return true; } /** @@ -1978,4 +1994,6 @@ void achievement_defaults(void) achievement->init_titles = achievement_init_titles; achievement->check_title = achievement_check_title; achievement->get_rewards = achievement_get_rewards; + achievement->get_rewards_buffs = achievement_get_rewards_buffs; + achievement->get_rewards_items = achievement_get_rewards_items; } diff --git a/src/map/achievement.h b/src/map/achievement.h index beba120a2..de5eaa060 100644 --- a/src/map/achievement.h +++ b/src/map/achievement.h @@ -277,7 +277,9 @@ struct achievement_interface { /* */ void (*init_titles) (struct map_session_data *sd); bool (*check_title) (struct map_session_data *sd, int title_id); - void (*get_rewards) (struct map_session_data *sd, const struct achievement_data *ad); + bool (*get_rewards) (struct map_session_data *sd, const struct achievement_data *ad); + void (*get_rewards_buffs) (struct map_session_data *sd, const struct achievement_data *ad); + void (*get_rewards_items) (struct map_session_data *sd, const struct achievement_data *ad); }; #ifdef HERCULES_CORE diff --git a/src/map/pc.c b/src/map/pc.c index 961dda9f5..c64c79db2 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -4689,7 +4689,7 @@ static int pc_search_inventory(struct map_session_data *sd, int item_id) * 6 = ? * 7 = stack limitation *------------------------------------------*/ -static int pc_additem(struct map_session_data *sd, struct item *item_data, int amount, e_log_pick_type log_type) +static int pc_additem(struct map_session_data *sd, const struct item *item_data, int amount, e_log_pick_type log_type) { struct item_data *data; int i; diff --git a/src/map/pc.h b/src/map/pc.h index 17a9b8200..4ee5f560b 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -937,7 +937,7 @@ END_ZEROED_BLOCK; /* End */ int (*inventoryblank) (struct map_session_data *sd); int (*search_inventory) (struct map_session_data *sd,int item_id); int (*payzeny) (struct map_session_data *sd,int zeny, enum e_log_pick_type type, struct map_session_data *tsd); - int (*additem) (struct map_session_data *sd,struct item *item_data,int amount,e_log_pick_type log_type); + int (*additem) (struct map_session_data *sd, const struct item *item_data, int amount, e_log_pick_type log_type); int (*getzeny) (struct map_session_data *sd,int zeny, enum e_log_pick_type type, struct map_session_data *tsd); int (*delitem) (struct map_session_data *sd,int n,int amount,int type, short reason, e_log_pick_type log_type); |