diff options
author | Inkfish <Inkfish@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2009-07-28 04:04:50 +0000 |
---|---|---|
committer | Inkfish <Inkfish@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2009-07-28 04:04:50 +0000 |
commit | 5129aec41d33947923a91604647a5936e49ae009 (patch) | |
tree | 1b10aa011002f1b475ace9a9136673377e13e285 /src/map | |
parent | a269c22b8d92b56a6b09bc2fa8375d1803cab909 (diff) | |
download | hercules-5129aec41d33947923a91604647a5936e49ae009.tar.gz hercules-5129aec41d33947923a91604647a5936e49ae009.tar.bz2 hercules-5129aec41d33947923a91604647a5936e49ae009.tar.xz hercules-5129aec41d33947923a91604647a5936e49ae009.zip |
* Some more updates to Quest Log
- Implemented a new saving mechanism. Now they can be saved every 'autosave_time' in case the char-server is not online when you get a quest.
- Improved 'changequest' code.
- Increase MAX_QUEST_DB to 1200.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13973 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/chrif.c | 2 | ||||
-rw-r--r-- | src/map/intif.c | 80 | ||||
-rw-r--r-- | src/map/intif.h | 4 | ||||
-rw-r--r-- | src/map/mob.c | 6 | ||||
-rw-r--r-- | src/map/quest.c | 205 | ||||
-rw-r--r-- | src/map/quest.h | 12 | ||||
-rw-r--r-- | src/map/script.c | 11 |
7 files changed, 135 insertions, 185 deletions
diff --git a/src/map/chrif.c b/src/map/chrif.c index 63aa5dac0..c725ff30a 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -289,7 +289,7 @@ int chrif_save(struct map_session_data *sd, int flag) if( sd->md && mercenary_get_lifetime(sd->md) > 0 ) mercenary_save(sd->md); if( sd->num_quests ) - quest_save(sd); + intif_quest_save(sd); return 0; } diff --git a/src/map/intif.c b/src/map/intif.c index 06f93f52e..d3a46001f 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -38,7 +38,7 @@ static const int packet_len_table[]={ 10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830 9, 9,-1,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840 -1,-1, 7, 7, 7,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus] - -1,11,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish] + -1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish] -1, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3870 Mercenaries [Zephyrus] 11,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3880 -1,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator] @@ -1364,66 +1364,48 @@ int intif_parse_questlog(int fd) return 0; } -int intif_parse_questDelete(int fd) +int intif_parse_questsave(int fd) { - quest_delete_ack(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10)); - return 0; -} + TBL_PC * sd = map_charid2sd(RFIFOL(fd, 4)); + int i,j; + int count = (RFIFOW(fd, 2) - 8) / 4; -int intif_quest_delete(int char_id, int quest_id) -{ - if(CheckForCharServer()) - return 0; - - WFIFOHEAD(inter_fd, 10); - WFIFOW(inter_fd,0) = 0x3062; - WFIFOL(inter_fd,2) = char_id; - WFIFOL(inter_fd,6) = quest_id; - WFIFOSET(inter_fd, 10); + if( !sd ) + return -1; - return 0; -} + for( i = 0; i < count; i++ ) + { + int qid = RFIFOL(fd, 4*i+8); + + ARR_FIND(0, sd->avail_quests, j, sd->quest_log[j].quest_id == qid); + if(j == sd->avail_quests) //shouldn't happen + { + ShowError("intif_parse_questsave: Quest %d not found in your quest log!\n", qid); + continue; + } + //This packet can't go before 'close' and 'next'. That's weird and why I send it here. [Inkfish] + clif_send_quest_info(sd, &sd->quest_log[j]); + } -int intif_parse_questAdd(int fd) -{ - quest_add_ack(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10)); return 0; } -int intif_quest_add(int char_id, struct quest * qd) +int intif_quest_save(TBL_PC *sd) { + int len; if(CheckForCharServer()) return 0; - WFIFOHEAD(inter_fd, sizeof(struct quest) + 8); - WFIFOW(inter_fd,0) = 0x3061; - WFIFOW(inter_fd,2) = sizeof(struct quest) + 8; - WFIFOL(inter_fd,4) = char_id; - memcpy(WFIFOP(inter_fd,8), qd, sizeof(struct quest)); - WFIFOSET(inter_fd, WFIFOW(inter_fd,2)); - - return 0; -} - -int intif_quest_save(int char_id, struct quest * qd) -{ - if(CheckForCharServer()) - return 0; - - WFIFOHEAD(inter_fd, sizeof(struct quest) + 8); - WFIFOW(inter_fd,0) = 0x3063; - WFIFOW(inter_fd,2) = sizeof(struct quest) + 8; - WFIFOL(inter_fd,4) = char_id; - memcpy(WFIFOP(inter_fd,8), qd, sizeof(struct quest)); - WFIFOSET(inter_fd, WFIFOW(inter_fd,2)); + len = sizeof(struct quest)*sd->num_quests + 8; - return 0; -} + WFIFOHEAD(inter_fd, len); + WFIFOW(inter_fd,0) = 0x3061; + WFIFOW(inter_fd,2) = len; + WFIFOL(inter_fd,4) = sd->status.char_id; + memcpy(WFIFOP(inter_fd,8), &sd->quest_log, sizeof(struct quest)*sd->num_quests); + WFIFOSET(inter_fd, len); -int intif_parse_questSave(int fd) -{ - quest_save_ack(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10)); return 0; } @@ -2062,9 +2044,7 @@ int intif_parse(int fd) //Quest system case 0x3860: intif_parse_questlog(fd); break; - case 0x3861: intif_parse_questAdd(fd); break; - case 0x3862: intif_parse_questDelete(fd); break; - case 0x3863: intif_parse_questSave(fd); break; + case 0x3861: intif_parse_questsave(fd); break; #ifndef TXT_ONLY // Mail System diff --git a/src/map/intif.h b/src/map/intif.h index 51389bd5b..25bda1765 100644 --- a/src/map/intif.h +++ b/src/map/intif.h @@ -75,9 +75,7 @@ int intif_homunculus_requestdelete(int homun_id); /******QUEST SYTEM*******/ int intif_request_questlog(struct map_session_data * sd); -int intif_quest_delete(int char_id, int quest_id); -int intif_quest_add(int char_id, struct quest * qd); -int intif_quest_save(int char_id, struct quest * qd); +int intif_quest_save(struct map_session_data * sd); // MERCENARY SYSTEM int intif_mercenary_create(struct s_mercenary *merc); diff --git a/src/map/mob.c b/src/map/mob.c index abcb9f469..c6020e05c 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -34,7 +34,6 @@ #include "date.h" #include "quest.h" - #include <stdio.h> #include <stdlib.h> #include <stdarg.h> @@ -1993,9 +1992,10 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) clif_mission_info(sd, temp, 0); } pc_setglobalreg(sd,"TK_MISSION_COUNT", sd->mission_count); + + if( sd->avail_quests ) + quest_update_objective(sd, md->class_); } - if( sd->avail_quests ) - quest_update_objective(sd, md->class_); } // filter out entries not eligible for exp distribution diff --git a/src/map/quest.c b/src/map/quest.c index 360cebd29..6c4ef7b14 100644 --- a/src/map/quest.c +++ b/src/map/quest.c @@ -12,7 +12,6 @@ #include "../common/utils.h" #include "map.h" -#include "chrif.h" #include "pc.h" #include "npc.h" #include "itemdb.h" @@ -26,6 +25,7 @@ #include "clif.h" #include "quest.h" #include "intif.h" +#include "chrif.h" #include <stdio.h> #include <stdlib.h> @@ -45,7 +45,7 @@ struct s_quest_db quest_db[MAX_QUEST_DB]; //Send quest info on login int quest_pc_login(TBL_PC * sd) { - if(sd->num_quests == 0) + if(sd->avail_quests == 0) return 1; clif_send_questlog(sd); @@ -59,7 +59,13 @@ int quest_add(TBL_PC * sd, int quest_id) int i, j, count; - if( quest_check_quest(sd, quest_id, HAVEQUEST) >= 0 ) + if( sd->num_quests >= MAX_QUEST_DB ) + { + ShowError("quest_add: your quest log is full.(max quests: %d)\n", MAX_QUEST_DB); + return 1; + } + + if( quest_check(sd, quest_id, HAVEQUEST) >= 0 ) { ShowError("quest_add: you already have quest %d.\n",quest_id); return -1; @@ -71,14 +77,9 @@ int quest_add(TBL_PC * sd, int quest_id) return -1; } - if( sd->num_quests >= MAX_QUEST_DB ) - { - ShowError("quest_add: your quest log is full.(max quests: %d)\n", MAX_QUEST_DB); - return 1; - } - i = sd->avail_quests; memmove(&sd->quest_log[i+1], &sd->quest_log[i], sizeof(struct quest)*(sd->num_quests-sd->avail_quests)); + memset(&sd->quest_log[i], 0, sizeof(struct quest)); sd->quest_log[i].quest_id = quest_db[j].id; if( quest_db[j].time ) @@ -91,82 +92,99 @@ int quest_add(TBL_PC * sd, int quest_id) sd->num_quests++; sd->avail_quests++; - //Notify inter server - intif_quest_add(sd->status.char_id, &sd->quest_log[i]); + if( save_settings&64 ) + chrif_save(sd,0); + else + intif_quest_save(sd); return 0; } -int quest_add_ack(int char_id, int quest_id, int success) +int quest_change(TBL_PC * sd, int qid1, int qid2) { - int i; - TBL_PC * sd = map_charid2sd(char_id); - ///Player no longer on map - if(!sd) - return -1; - - ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id); - if( i == sd->avail_quests ) - return -1; //Shouldn't happen! + int i, j, count; - if( success ) - clif_send_quest_info(sd, &sd->quest_log[i]); //Notify client - else + if( sd->num_quests >= MAX_QUEST_DB ) { - sd->avail_quests--; - if( sd->num_quests < MAX_QUEST_DB && sd->quest_log[i+1].quest_id ) - memmove(&sd->quest_log[i], &sd->quest_log[i+1], sizeof(struct quest)*(sd->num_quests-i)); - memset(&sd->quest_log[--sd->num_quests], 0, sizeof(struct quest)); - ShowError("Quest %d for character %d could not be added!\n", quest_id, char_id); + ShowError("quest_change: your quest log is full.(max quests: %d)\n", MAX_QUEST_DB); return 1; } - return 0; -} + if( quest_check(sd, qid2, HAVEQUEST) >= 0 ) + { + ShowError("quest_change: you already have quest %d.\n",qid2); + return -1; + } -int quest_delete(TBL_PC * sd, int quest_id) -{ - //Search for quest - if( quest_check_quest(sd, quest_id, HAVEQUEST) < 0 ) //Quest not found + if( quest_check(sd, qid1, HAVEQUEST) < 0 ) { - ShowError("quest_delete: quest %d not found in your quest log.\n",quest_id); + ShowError("quest_change: you don't have quest %d.\n",qid1); return -1; } - intif_quest_delete(sd->status.char_id, quest_id); + if( (j = quest_search_db(qid2)) < 0 ) + { + ShowError("quest_change: quest %d not found in DB.\n",qid2); + return -1; + } + + ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == qid1); + if(i == sd->avail_quests) + { + ShowError("quest_change: Quest %d not found in your quest log!\n", qid1); + return -1; + } + + // Complete quest + sd->quest_log[i].state = Q_COMPLETE; + memcpy(&sd->quest_log[sd->num_quests], &sd->quest_log[i],sizeof(struct quest)); + clif_send_quest_delete(sd, qid1); + + // Add new quest + memset(&sd->quest_log[i], 0, sizeof(struct quest)); + sd->quest_log[i].quest_id = quest_db[j].id; + if( quest_db[j].time ) + sd->quest_log[i].time = (unsigned int)(time(NULL) + quest_db[j].time); + sd->quest_log[i].state = Q_ACTIVE; + for( count = 0; count < MAX_QUEST_OBJECTIVES && quest_db[j].mob[count]; count++ ) + sd->quest_log[i].mob[count] = quest_db[j].mob[count]; + sd->quest_log[i].num_objectives = count; + + sd->num_quests++; + + if( save_settings&64 ) + chrif_save(sd,0); + else + intif_quest_save(sd); return 0; } -int quest_delete_ack(int char_id, int quest_id, int success) +int quest_delete(TBL_PC * sd, int quest_id) { int i; - TBL_PC * sd = map_charid2sd(char_id); - - ///Player no longer on map - if(!sd) - return -1; //Search for quest ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id); - if(i == sd->num_quests) //Shouldn't happen! - return -1; - - if(success) + if(i == sd->num_quests) { - if( sd->quest_log[i].state != Q_COMPLETE ) - sd->avail_quests--; - if( sd->num_quests < MAX_QUEST_DB && sd->quest_log[i+1].quest_id ) - memmove(&sd->quest_log[i], &sd->quest_log[i+1], sizeof(struct quest)*(sd->num_quests-i)); - memset(&sd->quest_log[--sd->num_quests], 0, sizeof(struct quest)); - clif_send_quest_delete(sd, quest_id); + ShowError("quest_delete: quest %d not found in your quest log.\n",quest_id); + return -1; } + + if( sd->quest_log[i].state != Q_COMPLETE ) + sd->avail_quests--; + if( sd->num_quests-- < MAX_QUEST_DB && sd->quest_log[i+1].quest_id ) + memmove(&sd->quest_log[i], &sd->quest_log[i+1], sizeof(struct quest)*(sd->num_quests-i)); + memset(&sd->quest_log[sd->num_quests], 0, sizeof(struct quest)); + + clif_send_quest_delete(sd, quest_id); + + if( save_settings&64 ) + chrif_save(sd,0); else - { - ShowError("Quest %d for character %d could not be deleted!\n", quest_id, char_id); - return 1; - } + intif_quest_save(sd); return 0; } @@ -184,87 +202,54 @@ void quest_update_objective(TBL_PC * sd, int mob) if( sd->quest_log[i].mob[j] == mob ) { sd->quest_log[i].count[j]++; - sd->quest_log[i].save_quest = true; - //clif_send_quest_info(sd, &sd->quest_log[i]); //TODO: Figure out the real packet [Inkfish] + + // Should figure out the real packet. + clif_send_quest_delete(sd, sd->quest_log[i].quest_id); + clif_send_quest_info(sd, &sd->quest_log[i]); //break; } } } -int quest_update_status(TBL_PC * sd, int quest_id, int status) +int quest_update_status(TBL_PC * sd, int quest_id, quest_state status) { int i; - //Search for quest - ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id); // Only status of active and inactive quests can't be updated and completed quests can't [Inkfish] - if(i == sd->avail_quests) //Quest not found + //Only status of active and inactive quests can be updated. Completed quests can't (for now). [Inkfish] + ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id); + if(i == sd->avail_quests) { - ShowError("Quest %d not found in your quest log!\n", quest_id); + ShowError("quest_update_status: Quest %d not found in your quest log!\n", quest_id); return -1; } - sd->quest_log[i].state = (quest_state)status; - if( status != Q_COMPLETE ) + sd->quest_log[i].state = status; + + if( status < Q_COMPLETE ) { clif_send_quest_status(sd, quest_id, (bool)status); - sd->quest_log[i].save_quest = true; + return 0; } - else + + if( i != (--sd->avail_quests) ) { struct quest tmp_quest; - - clif_send_quest_delete(sd, quest_id); - sd->avail_quests--; - memcpy(&tmp_quest, &sd->quest_log[i],sizeof(struct quest)); memcpy(&sd->quest_log[i], &sd->quest_log[sd->avail_quests],sizeof(struct quest)); memcpy(&sd->quest_log[sd->avail_quests], &tmp_quest,sizeof(struct quest)); - - sd->quest_log[sd->avail_quests].save_quest = true; } - return 0; -} - -int quest_save(TBL_PC * sd) -{ - int i; - - for( i = 0; i < sd->num_quests; i++ ) - if( sd->quest_log[i].save_quest ) - intif_quest_save(sd->status.char_id, &sd->quest_log[i]); - - return 0; -} - -int quest_save_ack(int char_id, int quest_id, int success) -{ + clif_send_quest_delete(sd, quest_id); - int i; - TBL_PC * sd = map_charid2sd(char_id); - - ///Player no longer on map - if(!sd) - return -1; - - //Search for quest - ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id); - if(i == sd->num_quests) //Quest not found - return -1; - - if(success) - sd->quest_log[i].save_quest = false; + if( save_settings&64 ) + chrif_save(sd,0); else - { - ShowError("Quest %d for character %d could not be saved!\n", quest_id, char_id); - return 1; - } + intif_quest_save(sd); return 0; - } -int quest_check_quest(TBL_PC * sd, int quest_id, quest_check_type type) +int quest_check(TBL_PC * sd, int quest_id, quest_check_type type) { int i; diff --git a/src/map/quest.h b/src/map/quest.h index ff351796c..39e1f3461 100644 --- a/src/map/quest.h +++ b/src/map/quest.h @@ -9,17 +9,11 @@ typedef enum quest_check_type { HAVEQUEST, PLAYTIME, HUNTING } quest_check_type; int quest_pc_login(TBL_PC * sd); int quest_add(TBL_PC * sd, int quest_id); -int quest_add_ack(int char_id, int quest_id, int success); - int quest_delete(TBL_PC * sd, int quest_id); -int quest_delete_ack(int char_id, int quest_id, int success); - +int quest_change(TBL_PC * sd, int qid1, int qid2); void quest_update_objective(TBL_PC * sd, int mob); -int quest_update_status(TBL_PC * sd, int quest_id, int status); -int quest_save(TBL_PC * sd); -int quest_save_ack(int char_id, int quest_id, int success); - -int quest_check_quest(TBL_PC * sd, int quest_id, quest_check_type type); +int quest_update_status(TBL_PC * sd, int quest_id, quest_state status); +int quest_check(TBL_PC * sd, int quest_id, quest_check_type type); int quest_search_db(int quest_id); diff --git a/src/map/script.c b/src/map/script.c index a2a60c13d..184e9121c 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -13447,21 +13447,14 @@ BUILDIN_FUNC(completequest) TBL_PC * sd = script_rid2sd(st); quest_update_status(sd, script_getnum(st, 2), Q_COMPLETE); - intif_quest_save(sd->status.char_id, &sd->quest_log[sd->avail_quests]); return 0; } BUILDIN_FUNC(changequest) { TBL_PC * sd = script_rid2sd(st); - int q1 = script_getnum(st, 2), q2 = script_getnum(st, 3); - - if( quest_check_quest(sd, q1, HAVEQUEST) == Q_ACTIVE && !quest_add(sd, q2) ) - { - quest_update_status(sd, q1, Q_COMPLETE); - intif_quest_save(sd->status.char_id, &sd->quest_log[sd->avail_quests]); - } + quest_change(sd, script_getnum(st, 2),script_getnum(st, 3)); return 0; } @@ -13473,7 +13466,7 @@ BUILDIN_FUNC(checkquest) if( script_hasdata(st, 3) ) type = (quest_check_type)script_getnum(st, 3); - script_pushint(st, quest_check_quest(sd, script_getnum(st, 2), type)); + script_pushint(st, quest_check(sd, script_getnum(st, 2), type)); return 0; } |