diff options
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/map/clif.c | 60 | ||||
-rw-r--r-- | src/map/clif.h | 10 | ||||
-rw-r--r-- | src/map/init.c | 68 | ||||
-rw-r--r-- | src/map/quest.c | 81 | ||||
-rw-r--r-- | src/map/quest.h | 9 | ||||
-rw-r--r-- | src/map/script.c | 7 |
7 files changed, 207 insertions, 34 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index c739693..e3cc46f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,9 @@ LOGIN_SRC = login/config.c \ common/interfaces.c \ common/interfaces.h -MAP_SRC = map/dummy.c \ +MAP_SRC = map/clif.c \ + map/clif.h \ + map/dummy.c \ map/dummy.h \ map/init.c \ map/npc.c \ @@ -23,6 +25,8 @@ MAP_SRC = map/dummy.c \ map/parse.h \ map/pc.c \ map/pc.h \ + map/quest.c \ + map/quest.h \ map/script.c \ map/script.h \ map/scriptdefines.h \ diff --git a/src/map/clif.c b/src/map/clif.c new file mode 100644 index 0000000..ed83b52 --- /dev/null +++ b/src/map/clif.c @@ -0,0 +1,60 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "../../../common/HPMi.h" +#include "../../../common/malloc.h" +#include "../../../common/mmo.h" +#include "../../../common/socket.h" +#include "../../../common/strlib.h" +#include "../../../map/pc.h" +#include "../../../map/quest.h" + +#include "map/clif.h" + +void eclif_quest_send_list(struct map_session_data *sd) +{ + hookStop(); + int fd = sd->fd; + int i; + int info_len = 15; + int len = sd->avail_quests * info_len + 8; + WFIFOHEAD(fd,len); + WFIFOW(fd, 0) = 0x97a; + WFIFOW(fd, 2) = len; + WFIFOL(fd, 4) = sd->avail_quests; + + for (i = 0; i < sd->avail_quests; i++ ) + { + struct quest_db *qi = quest->db(sd->quest_log[i].quest_id); + WFIFOL(fd, i * info_len + 8) = sd->quest_log[i].quest_id; + WFIFOB(fd, i * info_len + 12) = sd->quest_log[i].count[0]; // was state + WFIFOL(fd, i * info_len + 13) = sd->quest_log[i].time - qi->time; + WFIFOL(fd, i * info_len + 17) = sd->quest_log[i].time; + WFIFOW(fd, i * info_len + 21) = 0; + } + + WFIFOSET(fd, len); +} + +void eclif_quest_add(struct map_session_data *sd, struct quest *qd) +{ + hookStop(); + int fd = sd->fd; + int i; + struct mob_db *monster; + struct quest_db *qi = quest->db(qd->quest_id); + + WFIFOHEAD(fd, packet_len(0x2b3)); + WFIFOW(fd, 0) = 0x2b3; + WFIFOL(fd, 2) = qd->quest_id; + WFIFOB(fd, 6) = qd->count[0]; // was state; + WFIFOB(fd, 7) = qd->time - qi->time; + WFIFOL(fd, 11) = qd->time; + WFIFOW(fd, 15) = 0; + + WFIFOSET(fd, 107); +} diff --git a/src/map/clif.h b/src/map/clif.h new file mode 100644 index 0000000..6f11c5d --- /dev/null +++ b/src/map/clif.h @@ -0,0 +1,10 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_CLIF +#define EVOL_MAP_CLIF + +void eclif_quest_send_list(struct map_session_data *sd); +void eclif_quest_add(struct map_session_data *sd, struct quest *qd); + +#endif // EVOL_MAP_CLIF diff --git a/src/map/init.c b/src/map/init.c index dbce79c..b87c62d 100644 --- a/src/map/init.c +++ b/src/map/init.c @@ -34,11 +34,13 @@ #include "../../../map/quest.h" #include "common/interfaces.h" +#include "map/clif.h" #include "map/dummy.h" #include "map/npc.h" #include "map/parse.h" #include "map/script.h" #include "map/pc.h" +#include "map/quest.h" #include "../../../common/HPMDataCheck.h" /* should always be the last file included! (if you don't make it last, it'll intentionally break compile time) */ @@ -54,6 +56,40 @@ HPExport struct hplugin_info pinfo = HPExport void plugin_init (void) { +// HPM_map_add_group_permission = GET_SYMBOL("addGroupPermission"); + + addScriptCommand("setcamnpc", "*", setCamNpc); + addScriptCommand("restorecam", "", restoreCam); + addScriptCommand("npctalk3", "s", npcTalk3); + addScriptCommand("closedialog", "", closeDialog); + addScriptCommand("shop", "s", shop); + addScriptCommand("getitemlink", "s", getItemLink); + addScriptCommand("l", "s*", l); + addScriptCommandDeprecated("getlang", "", getLang); + addScriptCommandDeprecated("setlang", "i", setLang); + addScriptCommand("requestlang", "v", requestLang); + addScriptCommand("getq", "i", getq); + addScriptCommand("setq", "ii", setq); + addScriptCommand("getnpcdir", "*", dummyInt); + addScriptCommand("setnpcdir", "*", dummy); + addScriptCommand("rif", "is*", dummyStr); + addScriptCommand("countitemcolor", "*", dummyInt); + addScriptCommandDeprecated("getclientversion", "", getClientVersion); + // must be replaced to misceffect + addScriptCommand("misceffect2", "i*", dummy); + + addPacket(0x7530, 22, map_parse_version, hpClif_Parse); + addHookPre("pc->readparam", epc_readparam_pre); + addHookPre("pc->setregistry", epc_setregistry); + addHookPre("npc->checknear", enpc_checknear); + addHookPre("clif->quest_send_list", eclif_quest_send_list); + addHookPre("clif->quest_add", eclif_quest_add); + + langScriptId = script->add_str("Lang"); +} + +HPExport void server_preinit (void) +{ interfaces_init_common(); atcommand = GET_SYMBOL("atcommand"); @@ -97,38 +133,8 @@ HPExport void plugin_init (void) libpcre = GET_SYMBOL("libpcre"); mapit = GET_SYMBOL("mapit"); mapindex = GET_SYMBOL("mapindex"); -// HPM_map_add_group_permission = GET_SYMBOL("addGroupPermission"); - addScriptCommand("setcamnpc", "*", setCamNpc); - addScriptCommand("restorecam", "", restoreCam); - addScriptCommand("npctalk3", "s", npcTalk3); - addScriptCommand("closedialog", "", closeDialog); - addScriptCommand("shop", "s", shop); - addScriptCommand("getitemlink", "s", getItemLink); - addScriptCommand("l", "s*", l); - addScriptCommandDeprecated("getlang", "", getLang); - addScriptCommandDeprecated("setlang", "i", setLang); - addScriptCommand("requestlang", "v", requestLang); - addScriptCommand("getq", "i", getq); - addScriptCommand("setq", "ii", setq); - addScriptCommand("getnpcdir", "*", dummyInt); - addScriptCommand("setnpcdir", "*", dummy); - addScriptCommand("rif", "is*", dummyStr); - addScriptCommand("countitemcolor", "*", dummyInt); - addScriptCommandDeprecated("getclientversion", "", getClientVersion); - // must be replaced to misceffect - addScriptCommand("misceffect2", "i*", dummy); - - addPacket(0x7530, 22, map_parse_version, hpClif_Parse); - addHookPre("pc->readparam", epc_readparam_pre); - addHookPre("pc->setregistry", epc_setregistry); - addHookPre("npc->checknear", enpc_checknear); - - langScriptId = script->add_str("Lang"); -} - -HPExport void server_preinit (void) -{ + addHookPre("quest->read_db", equest_read_db); } HPExport void server_online (void) diff --git a/src/map/quest.c b/src/map/quest.c new file mode 100644 index 0000000..de77bcc --- /dev/null +++ b/src/map/quest.c @@ -0,0 +1,81 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "../../../common/HPMi.h" +#include "../../../common/malloc.h" +#include "../../../common/mmo.h" +#include "../../../common/socket.h" +#include "../../../common/strlib.h" +#include "../../../map/quest.h" + +#include "map/quest.h" + +int equest_read_db(void) +{ + hookStop(); + FILE *fp; + char line[1024]; + int i, count = 0; + char *str[20], *p, *np; + struct quest_db entry; + + sprintf(line, "%s/quest_db.txt", map->db_path); + if ((fp=fopen(line,"r"))==NULL) { + ShowError("can't read %s\n", line); + return -1; + } + + while (fgets(line, sizeof(line), fp)) { + if (line[0]=='/' && line[1]=='/') + continue; + memset(str,0,sizeof(str)); + + for (i = 0, p = line; i < 8; i++) { + if (( np = strchr(p,',') ) != NULL) { + str[i] = p; + *np = 0; + p = np + 1; + } else if (str[0] == NULL) { + break; + } else { + ShowError("quest_read_db: insufficient columns in line %s\n", line); + continue; + } + } + if (str[0] == NULL) + continue; + + memset(&entry, 0, sizeof(entry)); + + entry.id = atoi(str[0]); + + if (entry.id < 0 || entry.id >= MAX_QUEST_DB) { + ShowError("quest_read_db: Invalid quest ID '%d' in line '%s' (min: 0, max: %d.)\n", entry.id, line, MAX_QUEST_DB); + continue; + } + + entry.time = atoi(str[1]); + +// for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) { + for (i = 0; i < 1; i++) { +// entry.mob[i] = atoi(str[2*i+2]); + entry.mob[i] = 1; + entry.count[i] = atoi(str[2*i+3]); + } + + entry.num_objectives = i; + + if (quest->db_data[entry.id] == NULL) + quest->db_data[entry.id] = aMalloc(sizeof(struct quest_db)); + + memcpy(quest->db_data[entry.id], &entry, sizeof(struct quest_db)); + count++; + } + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, "quest_db.txt"); + return 0; +} diff --git a/src/map/quest.h b/src/map/quest.h new file mode 100644 index 0000000..07b5db7 --- /dev/null +++ b/src/map/quest.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_QUEST +#define EVOL_MAP_QUEST + +int equest_read_db(void); + +#endif // EVOL_MAP_QUEST diff --git a/src/map/script.c b/src/map/script.c index 80e43c2..932a3f0 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -10,6 +10,7 @@ #include "../../../common/mmo.h" #include "../../../common/socket.h" #include "../../../common/strlib.h" +#include "../../../map/chrif.h" #include "../../../map/clif.h" #include "../../../map/npc.h" #include "../../../map/pc.h" @@ -269,7 +270,10 @@ BUILDIN(setq) sd->quest_log[i].count[0] = quest_value; sd->save_quest = true; - clif->quest_update_objective(sd, &sd->quest_log[i]); + if (map->save_settings & 64) + chrif->save(sd,0); + + eclif_quest_add(sd, &sd->quest_log[i]); return true; } @@ -287,7 +291,6 @@ BUILDIN(getq) ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id); if (i == sd->num_quests) { - ShowError("Quest with id=%d not found\n", quest_id); script_pushint(st, 0); return false; } |