Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quest Misc DB #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions db/import-tmpl/quest_misc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Quest DB misc information
//
// Structure:
// quest_id,flags,range
//
// quest_id:
// See available quest at db/[pre-]re/quest_db.txt
//
// flags:
// The value is bitmask of
// 1 : Sets the quest state to Q_COMPLETE if all objectives are completed
// 2 : Does not give quest drop if objectives are completed
// 4 : Gives quest drop only for the killer
// 8 : Makes the killer as center for distance checking
//
// range:
// The max distance area for party members get objective counter from the center.
// If 0 or no value defined, default range is AREA_SIZE.
18 changes: 18 additions & 0 deletions db/pre-re/quest_misc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Quest DB misc information
//
// Structure:
// quest_id,flags,range
//
// quest_id:
// See available quest at db/[pre-]re/quest_db.txt
//
// flags:
// The value is bitmask of
// 1 : Sets the quest state to Q_COMPLETE if all objectives are completed
// 2 : Does not give quest drop if objectives are completed
// 4 : Gives quest drop only for the killer
// 8 : Makes the killer as center for distance checking
//
// range:
// The max distance area for party members get objective counter from the center.
// If 0 or no value defined, default range is AREA_SIZE.
18 changes: 18 additions & 0 deletions db/re/quest_misc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Quest DB misc information
//
// Structure:
// quest_id,flags,range
//
// quest_id:
// See available quest at db/[pre-]re/quest_db.txt
//
// flags:
// The value is bitmask of
// 1 : Sets the quest state to Q_COMPLETE if all objectives are completed
// 2 : Does not give quest drop if objectives are completed
// 4 : Gives quest drop only for the killer
// 8 : Makes the killer as center for distance checking
//
// range:
// The max distance area for party members get objective counter from the center.
// If 0 or no value defined, default range is AREA_SIZE.
4 changes: 2 additions & 2 deletions src/map/mob.c
Original file line number Diff line number Diff line change
Expand Up @@ -2885,9 +2885,9 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
}

if( sd->status.party_id )
map_foreachinrange(quest_update_objective_sub,&md->bl,AREA_SIZE,BL_PC,sd->status.party_id,md->mob_id);
map_foreachinmap(quest_update_objective_sub,md->bl.m,BL_PC,sd,md);
else if( sd->avail_quests )
quest_update_objective(sd, md->mob_id);
quest_update_objective(sd, md, sd);

if( sd->md && src && src->type == BL_MER && mob_db(md->mob_id)->lv > sd->status.base_level/2 )
mercenary_kills(sd->md);
Expand Down
104 changes: 93 additions & 11 deletions src/map/quest.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,21 @@ int quest_delete(TBL_PC *sd, int quest_id)
*/
int quest_update_objective_sub(struct block_list *bl, va_list ap)
{
struct map_session_data *sd;
int mob_id, party_id;
struct map_session_data *sd = NULL, *killer = NULL;
struct mob_data *md = NULL;

nullpo_ret(bl);
nullpo_ret(sd = (struct map_session_data *)bl);

party_id = va_arg(ap,int);
mob_id = va_arg(ap,int);
killer = va_arg(ap,struct map_session_data *);
md = va_arg(ap,struct mob_data *);

if( !sd->avail_quests )
return 0;
if( sd->status.party_id != party_id )
if( sd->status.party_id != killer->status.party_id )
return 0;

quest_update_objective(sd, mob_id);
quest_update_objective(sd, md, killer);

return 1;
}
Expand All @@ -237,33 +237,66 @@ int quest_update_objective_sub(struct block_list *bl, va_list ap)
* @param sd : Character's data
* @param mob_id : Monster ID
*/
void quest_update_objective(TBL_PC *sd, int mob_id)
void quest_update_objective(TBL_PC *sd, struct mob_data *md, struct map_session_data *killer)
{
int i, j;

nullpo_retv(sd);
nullpo_retv(md);

for( i = 0; i < sd->avail_quests; i++ ) {
struct quest_db *qi = NULL;
int dist = 0;
bool objective_updated = false;

if( sd->quest_log[i].state == Q_COMPLETE ) // Skip complete quests
continue;

qi = quest_search(sd->quest_log[i].quest_id);
qi = (struct quest_db *)idb_get(questdb, sd->quest_log[i].quest_id);

if (!qi)
continue;

// Distance checking
if (sd != killer && !(dist = check_distance_bl(&sd->bl, (qi->flag.killer_as_center) ? &killer->bl : &md->bl, qi->range)))
continue;

for( j = 0; j < qi->objectives_count; j++ ) {
if( qi->objectives[j].mob == mob_id && sd->quest_log[i].count[j] < qi->objectives[j].count ) {
if( qi->objectives[j].mob == md->mob_id && sd->quest_log[i].count[j] < qi->objectives[j].count) {
sd->quest_log[i].count[j]++;
sd->save_quest = true;
clif_quest_update_objective(sd, &sd->quest_log[i], mob_id);
clif_quest_update_objective(sd, &sd->quest_log[i], md->mob_id);
objective_updated = true;
}
}

// Checking for autocomplete
if (qi->flag.autocomplete) {
uint8 completes = 0;

for( j = 0; j < qi->objectives_count; j++ ) {
if( sd->quest_log[i].count[j] >= qi->objectives[j].count)
++completes;
}

if (completes == qi->objectives_count) {
quest_update_status(sd, qi->id, Q_COMPLETE);
pc_show_questinfo(sd);
}
}

// Item drop skipping
if ((!objective_updated && qi->flag.nomore_drop) || // Objectives are complete
(qi->flag.drop_killer_only && sd != killer)) // Only for killer
continue;

// process quest-granted extra drop bonuses
for (j = 0; j < qi->dropitem_count; j++) {
struct quest_dropitem *dropitem = &qi->dropitem[j];
struct item item;
int temp;

if (dropitem->mob_id != 0 && dropitem->mob_id != mob_id)
if (dropitem->mob_id != 0 && dropitem->mob_id != md->mob_id)
continue;
// TODO: Should this be affected by server rates?
if (dropitem->rate < 10000 && rnd()%10000 >= dropitem->rate)
Expand Down Expand Up @@ -496,6 +529,7 @@ void quest_read_txtdb(void)

if (!quest->id) {
quest->id = quest_id;
quest->range = AREA_SIZE;
idb_put(questdb, quest->id, quest);
}
count++;
Expand All @@ -506,12 +540,60 @@ void quest_read_txtdb(void)
}
}

static bool questdb_read_miscdb(char* str[], int columns, int current) {
int quest_id = strtoul(str[0], NULL, 0);
int flag = strtoul(str[1], NULL, 0);
unsigned short range = (unsigned short)strtoul(str[2], NULL, 0);
struct quest_db *quest = (struct quest_db *)idb_get(questdb, quest_id);

if (!quest) {
ShowError("questdb_read_miscdb: Invalid quest with ID '%s'.\n", str[0]);
return false;
}

quest->flag.autocomplete = (flag&1)?1:0;
quest->flag.nomore_drop = (flag&2)?1:0;
quest->flag.drop_killer_only = (flag&4)?1:0;
quest->flag.killer_as_center = (flag&8)?1:0;
if (range)
quest->range = range;

return true;
}

/**
* Loads Quest DB
*/
static void quest_read_db(void)
{
int i;
const char* dbsubpath[] = {
"",
"/"DBIMPORT,
};

quest_read_txtdb();

for(i=0; i<ARRAYLENGTH(dbsubpath); i++){
uint8 n1 = (uint8)(strlen(db_path)+strlen(dbsubpath[i])+1);
uint8 n2 = (uint8)(strlen(db_path)+strlen(DBPATH)+strlen(dbsubpath[i])+1);
char* dbsubpath1 = (char*)aMalloc(n1+1);
char* dbsubpath2 = (char*)aMalloc(n2+1);


if(i==0) {
safesnprintf(dbsubpath1,n1,"%s%s",db_path,dbsubpath[i]);
safesnprintf(dbsubpath2,n2,"%s/%s%s",db_path,DBPATH,dbsubpath[i]);
}
else {
safesnprintf(dbsubpath1,n1,"%s%s",db_path,dbsubpath[i]);
safesnprintf(dbsubpath2,n1,"%s%s",db_path,dbsubpath[i]);
}

sv_readdb(dbsubpath2, "quest_misc.txt", ',', 3, 3, -1, &questdb_read_miscdb, i);
aFree(dbsubpath1);
aFree(dbsubpath2);
}
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/map/quest.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ struct quest_db {
struct quest_objective *objectives;
uint8 dropitem_count;
struct quest_dropitem *dropitem;
unsigned short range; ///< Add custom range for party member get monster's kill counter [Cydh]
struct {
unsigned autocomplete : 1; ///< Makes quest with kill mission set to complete state automatically [Cydh]
unsigned nomore_drop : 1; ///< Makes quest doesn't give drop item if the objective is complete [Cydh]
unsigned drop_killer_only : 1; ///< Only drop the item only for the killer [Cydh]
unsigned killer_as_center: 1; ///< Makes killer as center for distance checking, instead using killed mob [Cydh]
} flag;
StringBuf name;
};

Expand All @@ -45,7 +52,7 @@ int quest_add(TBL_PC * sd, int quest_id);
int quest_delete(TBL_PC * sd, int quest_id);
int quest_change(TBL_PC * sd, int qid1, int qid2);
int quest_update_objective_sub(struct block_list *bl, va_list ap);
void quest_update_objective(TBL_PC * sd, int mob_id);
void quest_update_objective(TBL_PC * sd, struct mob_data *md, struct map_session_data *killer);
int quest_update_status(TBL_PC * sd, int quest_id, enum quest_state status);
int quest_check(TBL_PC * sd, int quest_id, enum quest_check_type type);

Expand Down
1 change: 1 addition & 0 deletions vcproj-10/map-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
<Copy SourceFiles="..\db\import-tmpl\pet_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\pet_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\produce_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\produce_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\quest_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\quest_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\quest_misc.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\quest_misc.txt')" />
<Copy SourceFiles="..\db\import-tmpl\refine_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\refine_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\size_fix.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\size_fix.txt')" />
<Copy SourceFiles="..\db\import-tmpl\skill_cast_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\skill_cast_db.txt')" />
Expand Down
1 change: 1 addition & 0 deletions vcproj-12/map-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
<Copy SourceFiles="..\db\import-tmpl\pet_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\pet_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\produce_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\produce_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\quest_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\quest_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\quest_misc.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\quest_misc.txt')" />
<Copy SourceFiles="..\db\import-tmpl\refine_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\refine_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\size_fix.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\size_fix.txt')" />
<Copy SourceFiles="..\db\import-tmpl\skill_cast_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\skill_cast_db.txt')" />
Expand Down
1 change: 1 addition & 0 deletions vcproj-13/map-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
<Copy SourceFiles="..\db\import-tmpl\pet_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\pet_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\produce_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\produce_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\quest_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\quest_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\quest_misc.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\quest_misc.txt')" />
<Copy SourceFiles="..\db\import-tmpl\refine_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\refine_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\size_fix.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\size_fix.txt')" />
<Copy SourceFiles="..\db\import-tmpl\skill_cast_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\skill_cast_db.txt')" />
Expand Down
1 change: 1 addition & 0 deletions vcproj-14/map-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@
<Copy SourceFiles="..\db\import-tmpl\pet_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\pet_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\produce_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\produce_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\quest_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\quest_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\quest_misc.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\quest_misc.txt')" />
<Copy SourceFiles="..\db\import-tmpl\refine_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\refine_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\size_fix.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\size_fix.txt')" />
<Copy SourceFiles="..\db\import-tmpl\skill_cast_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\skill_cast_db.txt')" />
Expand Down
1 change: 1 addition & 0 deletions vcproj-15/map-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@
<Copy SourceFiles="..\db\import-tmpl\pet_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\pet_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\produce_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\produce_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\quest_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\quest_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\quest_misc.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\quest_misc.txt')" />
<Copy SourceFiles="..\db\import-tmpl\refine_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\refine_db.txt')" />
<Copy SourceFiles="..\db\import-tmpl\size_fix.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\size_fix.txt')" />
<Copy SourceFiles="..\db\import-tmpl\skill_cast_db.txt" DestinationFolder="..\db\import\" ContinueOnError="true" Condition="!Exists('..\db\import\skill_cast_db.txt')" />
Expand Down