diff options
author | Asheraf <acheraf1998@gmail.com> | 2018-09-21 13:20:29 +0100 |
---|---|---|
committer | Asheraf <acheraf1998@gmail.com> | 2018-09-23 03:17:25 +0100 |
commit | a2f18fad8e066fce131a9481bdf822d88eb91abf (patch) | |
tree | d1047031d99dc4b6ed45e13ec809160f4eec931a | |
parent | 41ca3c7cc304cac90ae4df32217bd3237e035773 (diff) | |
download | hercules-a2f18fad8e066fce131a9481bdf822d88eb91abf.tar.gz hercules-a2f18fad8e066fce131a9481bdf822d88eb91abf.tar.bz2 hercules-a2f18fad8e066fce131a9481bdf822d88eb91abf.tar.xz hercules-a2f18fad8e066fce131a9481bdf822d88eb91abf.zip |
Add support for item amount range in setquestinfo
-rw-r--r-- | doc/script_commands.txt | 2 | ||||
-rw-r--r-- | src/map/map.h | 8 | ||||
-rw-r--r-- | src/map/quest.c | 17 | ||||
-rw-r--r-- | src/map/script.c | 19 |
4 files changed, 30 insertions, 16 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 4c5dab969..343eb02cb 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -9414,7 +9414,7 @@ supported types: values QINFO_SEX: sex QINFO_BASE_LEVEL: min, max QINFO_JOB_LEVEL: min, max - QINFO_ITEM: item_id, amount // append to the items list on each use + QINFO_ITEM: item_id, min amount, max amount // append to the items list on each use QINFO_HOMUN_LEVEL: min QINFO_HOMUN_TYPE: homunculus_type (0 - regular, 1 - evolved, 2 - S) QINFO_QUEST: quest_id, state // append to the quests list on each use diff --git a/src/map/map.h b/src/map/map.h index cf3a4e57c..d50666d4b 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -789,6 +789,12 @@ struct questinfo_qreq { int state; }; +struct questinfo_itemreq { + int nameid; + int min; + int max; +}; + struct questinfo { struct npc_data *nd; unsigned short icon; @@ -805,7 +811,7 @@ struct questinfo { int min; int max; } job_level; - VECTOR_DECL(struct item) items; + VECTOR_DECL(struct questinfo_itemreq) items; struct s_homunculus homunculus; int homunculus_type; VECTOR_DECL(struct questinfo_qreq) quest_requirement; diff --git a/src/map/quest.c b/src/map/quest.c index 8cde4538e..02bf7638b 100644 --- a/src/map/quest.c +++ b/src/map/quest.c @@ -805,18 +805,17 @@ static bool quest_questinfo_validate_joblevel(struct map_session_data *sd, struc */ static bool quest_questinfo_validate_items(struct map_session_data *sd, struct questinfo *qi) { - int i, idx; - nullpo_retr(false, sd); nullpo_retr(false, qi); - - for (i = 0; i < VECTOR_LENGTH(qi->items); i++) { - struct item *item = &VECTOR_INDEX(qi->items, i); - idx = pc->search_inventory(sd, item->nameid); - if (idx == INDEX_NOT_FOUND) - return false; - if (sd->status.inventory[idx].amount < item->amount) + for (int i = 0; i < VECTOR_LENGTH(qi->items); i++) { + struct questinfo_itemreq *item = &VECTOR_INDEX(qi->items, i); + int count = 0; + for (int j = 0; j < MAX_INVENTORY; j++) { + if (sd->status.inventory[j].nameid == item->nameid) + count += sd->status.inventory[j].amount; + } + if (count < item->min || count > item->max) return false; } diff --git a/src/map/script.c b/src/map/script.c index 65ffc1a6d..31930c2dc 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -21114,17 +21114,26 @@ static BUILDIN(setquestinfo) } case QINFO_ITEM: { - struct item item = { 0 }; + struct questinfo_itemreq item = { 0 }; item.nameid = script_getnum(st, 3); - item.amount = script_getnum(st, 4); + item.min = script_hasdata(st, 4) ? script_getnum(st, 4) : 0; + item.max = script_hasdata(st, 5) ? script_getnum(st, 5) : 0; if (itemdb->exists(item.nameid) == NULL) { ShowWarning("buildin_setquestinfo: non existing item (%d) have been given.\n", item.nameid); return false; } - if (item.amount <= 0 || item.amount > MAX_AMOUNT) { - ShowWarning("buildin_setquestinfo: given amount (%d) must be bigger than 0 and smaller than %d.\n", item.amount, MAX_AMOUNT + 1); + if (item.min > item.max) { + ShowWarning("buildin_setquestinfo: minimal amount (%d) is bigger than the maximal amount (%d).\n", item.min, item.max); + return false; + } + if (item.min < 0 || item.min > MAX_AMOUNT) { + ShowWarning("buildin_setquestinfo: given amount (%d) must be bigger than or equal to 0 and smaller than %d.\n", item.min, MAX_AMOUNT + 1); + return false; + } + if (item.max < 0 || item.max > MAX_AMOUNT) { + ShowWarning("buildin_setquestinfo: given amount (%d) must be bigger than or equal to 0 and smaller than %d.\n", item.max, MAX_AMOUNT + 1); return false; } if (VECTOR_LENGTH(qi->items) == 0) @@ -25447,7 +25456,7 @@ static void script_parse_builtin(void) //Quest Log System [Inkfish] BUILDIN_DEF(questinfo, "i?"), - BUILDIN_DEF(setquestinfo, "i??"), + BUILDIN_DEF(setquestinfo, "i???"), BUILDIN_DEF(setquest, "i?"), BUILDIN_DEF(erasequest, "i?"), BUILDIN_DEF(completequest, "i?"), |