Finished most of the quest log code, still bits here and there but it's usable now.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@12558 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
Kevin 2008-04-11 07:12:45 +00:00
parent 12aff369d9
commit ffa3b60fc0
6 changed files with 104 additions and 16 deletions

View File

@ -3,6 +3,9 @@ Date Added
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2008/04/11
* Finished most of the quest log code, still bits here and there
- but it's ready for testing. (r12558) [Kevin]
2008/04/10
* More quest log code. [Kevin]
* Client not marked online until map receives auth request from the client

View File

@ -59,6 +59,7 @@ char hotkey_db[256] = "hotkey";
char quest_db[256] = "quest";
char quest_obj_db[256] = "quest_objective";
//#undef TXT_SQL_CONVERT
#ifndef TXT_SQL_CONVERT
static DBMap* char_db_; // int char_id -> struct mmo_charstatus*
@ -679,6 +680,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
StringBuf_Init(&buf2);
StringBuf_Clear(&buf);
StringBuf_Clear(&buf2);
diff = 0;
StringBuf_Printf(&buf, "REPLACE INTO `%s` (`char_id`, `quest_id`, `state`) VALUES ", quest_db);
for(i=0; i<MAX_QUEST; i++)
{
@ -691,7 +693,8 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
diff = 1;
StringBuf_Printf(&buf2, "REPLACE INTO `%s` (`quest_id`, `num`, `name`, `count`) VALUES ", quest_obj_db);
for(j=0; j<MAX_QUEST_OBJECTIVES; j++)
count = 0;
for(j=0; j<p->quest_log[i].num_objectives; j++)
{
if(p->quest_log[i].objectives[j].name)
@ -705,7 +708,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
}
}
if(diff) {
if(count) {
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf2)) )
Sql_ShowDebug(sql_handle);
}
@ -716,7 +719,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
else
strcat(save_status, " hotkeys");
strcat(save_status, " quests");
}
StringBuf_Destroy(&buf2);
@ -1206,15 +1209,15 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
//`quest_objectives`
if( SQL_ERROR == SqlStmt_Prepare(stmt2, "SELECT q.`count`, q.`name` FROM `%s` q", quest_obj_db)
|| SQL_ERROR == SqlStmt_BindParam(stmt2, 0, SQLDT_INT, &char_id, 0)
|| SQL_ERROR == SqlStmt_BindParam(stmt2, 0, SQLDT_INT, &tmp_quest.quest_id, 0)
|| SQL_ERROR == SqlStmt_Execute(stmt2)
|| SQL_ERROR == SqlStmt_BindColumn(stmt2, 0, SQLDT_INT, &tmp_quest_obj.count, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt2, 1, SQLDT_STRING, &tmp_quest_obj.name, 0, NULL, NULL) )
|| SQL_ERROR == SqlStmt_BindColumn(stmt2, 1, SQLDT_STRING, &tmp_quest_obj.name, NAME_LENGTH, NULL, NULL) )
SqlStmt_ShowDebug(stmt2);
for( j = 0; j < MAX_QUEST_OBJECTIVES && SQL_SUCCESS == SqlStmt_NextRow(stmt2); ++j )
memcpy(&p->quest_log[i].objectives[j], &tmp_quest_obj, sizeof(tmp_quest_obj));
p->quest_log[i].num_objectives = j+1;
p->quest_log[i].num_objectives = j;
}
p->num_quests = i;
strcat(t_msg, " quests");

View File

@ -127,11 +127,11 @@ enum item_types {
//Questlog system [Kevin]
typedef enum quest_state { Q_NONE, Q_ACTIVE, Q_INACTIVE } quest_state;
typedef enum quest_state { Q_INACTIVE, Q_ACTIVE } quest_state;
struct quest_objective {
char * name;
char name[NAME_LENGTH];
int count;
};

View File

@ -44,11 +44,6 @@ int quest_pc_login(TBL_PC * sd)
return 0;
}
struct quest * quest_make(int id, time_t time, int num_objs, struct quest_objective ** qo_arr)
{
return NULL;
}
int quest_add(TBL_PC * sd, struct quest * qd)
{
@ -101,7 +96,7 @@ int quest_delete(TBL_PC * sd, int quest_id)
}
int quest_update_objective(TBL_PC * sd, int quest_id, int objective_num, struct quest_objective qod)
int quest_update_objective(TBL_PC * sd, int quest_id, int objective_num, const char * name, int count)
{
int i;
@ -113,8 +108,8 @@ int quest_update_objective(TBL_PC * sd, int quest_id, int objective_num, struct
if(i != MAX_QUEST)
return -1;
memcpy(sd->quest_log[i].objectives[objective_num].name, qod.name, NAME_LENGTH);
sd->quest_log[i].objectives[objective_num].count = qod.count;
memcpy(&sd->quest_log[i].objectives[objective_num].name, name, NAME_LENGTH);
sd->quest_log[i].objectives[objective_num].count = count;
//Notify client
clif_send_quest_info(sd, &sd->quest_log[i]);
@ -123,6 +118,12 @@ int quest_update_objective(TBL_PC * sd, int quest_id, int objective_num, struct
}
int quest_update_status(TBL_PC * sd, int quest_id, bool status)
{
return 0;
}
int quest_load_info(TBL_PC * sd, struct mmo_charstatus * st)
{
sd->num_quests = st->num_quests;

View File

@ -7,5 +7,9 @@
int quest_pc_login(TBL_PC * sd);
int quest_load_info(TBL_PC * sd, struct mmo_charstatus * st);
int quest_make_savedata(TBL_PC * sd);
int quest_add(TBL_PC * sd, struct quest * qd);
int quest_delete(TBL_PC * sd, int quest_id);
int quest_update_objective(TBL_PC * sd, int quest_id, int objective_num, const char * name, int count);
int quest_update_status(TBL_PC * sd, int quest_id, bool status);
#endif

View File

@ -43,6 +43,7 @@
#include "pet.h"
#include "mail.h"
#include "script.h"
#include "quest.h"
#include <stdio.h>
#include <stdlib.h>
@ -13044,6 +13045,78 @@ BUILDIN_FUNC(setcell)
return 0;
}
/******************
Questlog script commands
*******************/
BUILDIN_FUNC(getquest)
{
TBL_PC * sd = script_rid2sd(st);
struct quest qd;
int i, count = 0;
char * temp;
memset(&qd, 0, sizeof(struct quest));
qd.quest_id = script_getnum(st, 2);
qd.time = script_getnum(st, 3);
qd.state = Q_ACTIVE;
for(i=0; i<(script_lastdata(st)-3) && (i/2) < MAX_QUEST_OBJECTIVES; i+=2)
{
temp = (char*)script_getstr(st, i+4);
memcpy(&qd.objectives[i/2].name, temp, NAME_LENGTH);
temp = NULL;
qd.objectives[i/2].count = script_getnum(st, i+5);
count++;
}
qd.num_objectives = count;
quest_add(sd, &qd);
return 0;
}
BUILDIN_FUNC(deletequest)
{
TBL_PC * sd = script_rid2sd(st);
int qid = script_getnum(st, 2);
quest_delete(sd, qid);
return 0;
}
BUILDIN_FUNC(setquestobjective)
{
TBL_PC * sd = script_rid2sd(st);
int qid = script_getnum(st, 2);
int num = script_getnum(st, 3);
const char * str = script_getstr(st, 4);
int count = script_getnum(st, 5);
quest_update_objective(sd, qid, num, str, count);
return 0;
}
BUILDIN_FUNC(setqueststatus)
{
TBL_PC * sd = script_rid2sd(st);
int qid = script_getnum(st, 2);
bool active = script_getnum(st, 3)?true:false;
quest_update_status(sd, qid, active);
return 0;
}
// declarations that were supposed to be exported from npc_chat.c
#ifdef PCRE_SUPPORT
@ -13388,5 +13461,9 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(openauction,""),
BUILDIN_DEF(checkcell,"siii"),
BUILDIN_DEF(setcell,"siiiiii"),
BUILDIN_DEF(getquest, "ii*"),
BUILDIN_DEF(deletequest, "i"),
BUILDIN_DEF(setquestobjective, "iisi"),
BUILDIN_DEF(setqueststatus, "ii"),
{NULL,NULL,NULL},
};