summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2018-09-23 16:07:59 +0200
committerGitHub <noreply@github.com>2018-09-23 16:07:59 +0200
commitd45933be8820b19e36994548f4f4a37f1b327c27 (patch)
tree16aa704ce150326debef195de1e8b7e1b91ae451 /src
parent09188644db5b359234499bc3d9c608710b168130 (diff)
parenta2f18fad8e066fce131a9481bdf822d88eb91abf (diff)
downloadhercules-d45933be8820b19e36994548f4f4a37f1b327c27.tar.gz
hercules-d45933be8820b19e36994548f4f4a37f1b327c27.tar.bz2
hercules-d45933be8820b19e36994548f4f4a37f1b327c27.tar.xz
hercules-d45933be8820b19e36994548f4f4a37f1b327c27.zip
Merge pull request #2218 from Asheraf/questinfo_fix
Fix wrong validation for quests in setquestinfo
Diffstat (limited to 'src')
-rw-r--r--src/map/map.h8
-rw-r--r--src/map/quest.c26
-rw-r--r--src/map/script.c19
3 files changed, 37 insertions, 16 deletions
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 ab0b06974..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;
}
@@ -887,7 +886,14 @@ static bool quest_questinfo_validate_quests(struct map_session_data *sd, struct
for (i = 0; i < VECTOR_LENGTH(qi->quest_requirement); i++) {
struct questinfo_qreq *quest_requirement = &VECTOR_INDEX(qi->quest_requirement, i);
- if (quest->check(sd, quest_requirement->id, HAVEQUEST) != quest_requirement->state)
+ int quest_progress = quest->check(sd, quest_requirement->id, HAVEQUEST);
+ if (quest_progress == -1)
+ quest_progress = 0;
+ else if (quest_progress == 0 || quest_progress == 1)
+ quest_progress = 1;
+ else
+ quest_progress = 2;
+ if (quest_progress != quest_requirement->state)
return false;
}
diff --git a/src/map/script.c b/src/map/script.c
index 2182b942c..f1bb63aa3 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?"),