Skip to content

Commit

Permalink
HPM: Npc.c Interface
Browse files Browse the repository at this point in the history
Fully Interfaced.
Special Thanks to Haruna

Signed-off-by: shennetsind <ind@henn.et>
  • Loading branch information
shennetsind committed Sep 16, 2013
1 parent 5d33b1c commit 95e13fe
Show file tree
Hide file tree
Showing 20 changed files with 650 additions and 534 deletions.
40 changes: 20 additions & 20 deletions src/map/atcommand.c
Expand Up @@ -3749,7 +3749,7 @@ ACMD(reloadscript)
flush_fifos();
iMap->reloadnpc(true); // reload config files seeking for npcs
script->reload();
npc_reload();
npc->reload();

clif->message(fd, msg_txt(100)); // Scripts have been reloaded.

Expand Down Expand Up @@ -4237,7 +4237,7 @@ ACMD(tonpc)
return false;
}

if ((nd = npc_name2id(npcname)) != NULL) {
if ((nd = npc->name2id(npcname)) != NULL) {
if (pc->setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == 0)
clif->message(fd, msg_txt(0)); // Warped.
else
Expand Down Expand Up @@ -4265,8 +4265,8 @@ ACMD(shownpc)
return false;
}

if (npc_name2id(NPCname) != NULL) {
npc_enable(NPCname, 1);
if (npc->name2id(NPCname) != NULL) {
npc->enable(NPCname, 1);
clif->message(fd, msg_txt(110)); // Npc Enabled.
} else {
clif->message(fd, msg_txt(111)); // This NPC doesn't exist.
Expand All @@ -4291,12 +4291,12 @@ ACMD(hidenpc)
return false;
}

if (npc_name2id(NPCname) == NULL) {
if (npc->name2id(NPCname) == NULL) {
clif->message(fd, msg_txt(111)); // This NPC doesn't exist.
return false;
}

npc_enable(NPCname, 0);
npc->enable(NPCname, 0);
clif->message(fd, msg_txt(112)); // Npc Disabled.
return true;
}
Expand All @@ -4318,9 +4318,9 @@ ACMD(loadnpc)
fclose(fp);

// add to list of script sources and run it
npc_addsrcfile(message);
npc_parsesrcfile(message,true);
npc_read_event_script();
npc->addsrcfile(message);
npc->parsesrcfile(message,true);
npc->read_event_script();

clif->message(fd, msg_txt(262));

Expand All @@ -4340,14 +4340,14 @@ ACMD(unloadnpc)
return false;
}

if ((nd = npc_name2id(NPCname)) == NULL) {
if ((nd = npc->name2id(NPCname)) == NULL) {
clif->message(fd, msg_txt(111)); // This NPC doesn't exist.
return false;
}

npc_unload_duplicates(nd);
npc_unload(nd,true);
npc_read_event_script();
npc->unload_duplicates(nd);
npc->unload(nd,true);
npc->read_event_script();
clif->message(fd, msg_txt(112)); // Npc Disabled.
return true;
}
Expand Down Expand Up @@ -4749,7 +4749,7 @@ ACMD(disguise)
} else { //Acquired a Name
if ((id = mob->db_searchname(message)) == 0)
{
struct npc_data* nd = npc_name2id(message);
struct npc_data* nd = npc->name2id(message);
if (nd != NULL)
id = nd->class_;
}
Expand Down Expand Up @@ -4828,7 +4828,7 @@ ACMD(disguiseguild)
id = 0;
} else {
if( (id = mob->db_searchname(monster)) == 0 ) {
struct npc_data* nd = npc_name2id(monster);
struct npc_data* nd = npc->name2id(monster);
if( nd != NULL )
id = nd->class_;
}
Expand Down Expand Up @@ -5116,7 +5116,7 @@ ACMD(npcmove)
return false;
}

if ((nd = npc_name2id(atcmd_player_name)) == NULL)
if ((nd = npc->name2id(atcmd_player_name)) == NULL)
{
clif->message(fd, msg_txt(111)); // This NPC doesn't exist.
return false;
Expand Down Expand Up @@ -5165,7 +5165,7 @@ ACMD(addwarp)
return false;
}

nd = npc_add_warp(warpname, sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y);
nd = npc->add_warp(warpname, sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y);
if( nd == NULL )
return false;

Expand Down Expand Up @@ -6194,7 +6194,7 @@ ACMD(npctalk)
}
}

if (!(nd = npc_name2id(name))) {
if (!(nd = npc->name2id(name))) {
clif->message(fd, msg_txt(111)); // This NPC doesn't exist
return false;
}
Expand Down Expand Up @@ -8759,7 +8759,7 @@ ACMD(unloadnpcfile) {
return false;
}

if( npc_unloadfile(message) )
if( npc->unloadfile(message) )
clif->message(fd, msg_txt(1386)); // File unloaded. Be aware that mapflags and monsters spawned directly are not removed.
else {
clif->message(fd, msg_txt(1387)); // File not found.
Expand Down Expand Up @@ -10018,7 +10018,7 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message
if( binding->log ) /* log only if this command should be logged [Ind/Hercules] */
logs->atcommand(sd, atcmd_msg);

npc_do_atcmd_event((invokeFlag ? sd : ssd), command, params, binding->npc_event);
npc->do_atcmd_event((invokeFlag ? sd : ssd), command, params, binding->npc_event);
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/map/battleground.c
Expand Up @@ -149,7 +149,7 @@ int bg_team_leave(struct map_session_data *sd, int flag)
}

if( bg_data->logout_event[0] && flag )
npc_event(sd, bg_data->logout_event, 0);
npc->event(sd, bg_data->logout_event, 0);

if( sd->bg_queue.arena ) {
bg->queue_pc_cleanup(sd);
Expand Down Expand Up @@ -534,7 +534,7 @@ void bg_begin(struct bg_arena *arena) {
arena->ongoing = true;
mapreg_setreg(script->add_str("$@bg_queue_id"),arena->queue_id);/* TODO: make this a arena-independant var? or just .@? */
mapreg_setregstr(script->add_str("$@bg_delay_var$"),bg->gdelay_var);
npc_event_do(arena->npc_event);
npc->event_do(arena->npc_event);
/* we split evenly? */
/* but if a party of say 10 joins, it cant be split evenly unless by luck there are 10 soloers in the queue besides them */
/* not sure how to split T_T needs more info */
Expand Down
2 changes: 1 addition & 1 deletion src/map/chat.c
Expand Up @@ -388,7 +388,7 @@ int chat_triggerevent(struct chat_data *cd)
nullpo_ret(cd);

if( cd->users >= cd->trigger && cd->npc_event[0] )
npc_event_do(cd->npc_event);
npc->event_do(cd->npc_event);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/map/chrif.c
Expand Up @@ -463,10 +463,10 @@ int chrif_connectack(int fd) {

chrif_sendmap(fd);

ShowStatus("Event '"CL_WHITE"OnInterIfInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc_event_doall("OnInterIfInit"));
ShowStatus("Event '"CL_WHITE"OnInterIfInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc->event_doall("OnInterIfInit"));
if( !char_init_done ) {
char_init_done = true;
ShowStatus("Event '"CL_WHITE"OnInterIfInitOnce"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc_event_doall("OnInterIfInitOnce"));
ShowStatus("Event '"CL_WHITE"OnInterIfInitOnce"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc->event_doall("OnInterIfInitOnce"));
guild->castle_map_init();
}

Expand Down
54 changes: 27 additions & 27 deletions src/map/clif.c
Expand Up @@ -1928,7 +1928,7 @@ void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
int slen = strlen(mes) + 9;
struct block_list *bl = NULL;

if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = iMap->id2bl(npcid)) && (bl->m!=sd->bl.m ||
if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = iMap->id2bl(npcid)) && (bl->m!=sd->bl.m ||
bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
clif->sendfakenpc(sd, npcid);
Expand Down Expand Up @@ -1960,7 +1960,7 @@ void clif_scriptinput(struct map_session_data *sd, int npcid)

nullpo_retv(sd);

if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = iMap->id2bl(npcid)) && (bl->m!=sd->bl.m ||
if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = iMap->id2bl(npcid)) && (bl->m!=sd->bl.m ||
bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
clif->sendfakenpc(sd, npcid);
Expand Down Expand Up @@ -1991,7 +1991,7 @@ void clif_scriptinputstr(struct map_session_data *sd, int npcid)

nullpo_retv(sd);

if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = iMap->id2bl(npcid)) && (bl->m!=sd->bl.m ||
if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = iMap->id2bl(npcid)) && (bl->m!=sd->bl.m ||
bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
clif->sendfakenpc(sd, npcid);
Expand Down Expand Up @@ -9531,7 +9531,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
iMap->map_foreachpc(clif->friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);

//Login Event
npc_script_event(sd, NPCE_LOGIN);
npc->script_event(sd, NPCE_LOGIN);
} else {
//For some reason the client "loses" these on warp/map-change.
clif->updatestatus(sd,SP_STR);
Expand All @@ -9547,7 +9547,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
sd->npc_menu = 0;

if(sd->npc_id)
npc_event_dequeue(sd);
npc->event_dequeue(sd);

if( sd->guild && ( battle_config.guild_notice_changemap == 2 || ( battle_config.guild_notice_changemap == 1 && sd->state.changemap ) ) )
clif->guild_notice(sd,sd->guild);
Expand Down Expand Up @@ -9611,7 +9611,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
}

if(map[sd->bl.m].flag.loadevent) // Lance
npc_script_event(sd, NPCE_LOADMAP);
npc->script_event(sd, NPCE_LOADMAP);

if (pc->checkskill(sd, SG_DEVIL) && !pc->nextjobexp(sd)) //blindness [Komurka]
clif->sc_end(&sd->bl, sd->bl.id, SELF, SI_DEVIL1);
Expand All @@ -9623,7 +9623,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {

// For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
if (iMap->getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
npc->touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
else
sd->areanpc_id = 0;

Expand Down Expand Up @@ -9750,7 +9750,7 @@ void clif_parse_progressbar(int fd, struct map_session_data * sd)
sd->st->state = END;

sd->state.workinprogress = sd->progressbar.npc_id = sd->progressbar.timeout = 0;
npc_scriptcont(sd, npc_id, false);
npc->scriptcont(sd, npc_id, false);
}


Expand Down Expand Up @@ -10401,8 +10401,8 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
//-------------------------------------------------------//
if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4)) {
char* str = target+4; //Skip the NPC: string part.
struct npc_data* npc;
if ((npc = npc_name2id(str))) {
struct npc_data *nd;
if ((nd = npc->name2id(str))) {
char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
char *split;
char output[256];
Expand All @@ -10429,8 +10429,8 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
script->set_var(sd,output,(char *) split_data[i]);
}

sprintf(output, "%s::OnWhisperGlobal", npc->exname);
npc_event(sd,output,0); // Calls the NPC label
sprintf(output, "%s::OnWhisperGlobal", nd->exname);
npc->event(sd,output,0); // Calls the NPC label

return;
}
Expand Down Expand Up @@ -10837,7 +10837,7 @@ void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
break;
}
if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
npc_click(sd,(TBL_NPC*)bl);
npc->click(sd,(TBL_NPC*)bl);
break;
}
}
Expand All @@ -10852,7 +10852,7 @@ void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
{
if (sd->state.trading)
return;
npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
npc->buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
}


Expand Down Expand Up @@ -10884,7 +10884,7 @@ void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
if( sd->state.trading || !sd->npc_shopid )
result = 1;
else
result = npc_buylist(sd,n,item_list);
result = npc->buylist(sd,n,item_list);

sd->npc_shopid = 0; //Clear shop data.

Expand Down Expand Up @@ -10920,7 +10920,7 @@ void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
if (sd->state.trading || !sd->npc_shopid)
fail = 1;
else
fail = npc_selllist(sd,n,item_list);
fail = npc->selllist(sd,n,item_list);

sd->npc_shopid = 0; //Clear shop data.

Expand Down Expand Up @@ -10949,7 +10949,7 @@ void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
clif->skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
return;
}
if( npc_isnear(&sd->bl) ) {
if( npc->isnear(&sd->bl) ) {
// uncomment for more verbose message.
//char output[150];
//sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
Expand Down Expand Up @@ -11695,15 +11695,15 @@ void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
}

sd->npc_menu = select;
npc_scriptcont(sd,npc_id, false);
npc->scriptcont(sd,npc_id, false);
}


/// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
/// 00b9 <npc id>.L
void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
{
npc_scriptcont(sd,RFIFOL(fd,2), false);
npc->scriptcont(sd,RFIFOL(fd,2), false);
}


Expand All @@ -11715,7 +11715,7 @@ void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
int amount = (int)RFIFOL(fd,6);

sd->npc_amount = amount;
npc_scriptcont(sd, npcid, false);
npc->scriptcont(sd, npcid, false);
}


Expand All @@ -11731,7 +11731,7 @@ void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
return; // invalid input

safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
npc_scriptcont(sd, npcid, false);
npc->scriptcont(sd, npcid, false);
}


Expand All @@ -11741,7 +11741,7 @@ void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
{
if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
return;
npc_scriptcont(sd, RFIFOL(fd,2), true);
npc->scriptcont(sd, RFIFOL(fd,2), true);
}


Expand Down Expand Up @@ -13275,9 +13275,9 @@ void clif_parse_GMKick(int fd, struct map_session_data *sd)
clif->GM_kickack(sd, 0);
return;
}
npc_unload_duplicates(nd);
npc_unload(nd,true);
npc_read_event_script();
npc->unload_duplicates(nd);
npc->unload(nd,true);
npc->read_event_script();
}
break;

Expand Down Expand Up @@ -15293,7 +15293,7 @@ void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
short amount = RFIFOW(fd,4);
int points = RFIFOL(fd,6);

fail = npc_cashshop_buy(sd, nameid, amount, points);
fail = npc->cashshop_buy(sd, nameid, amount, points);
#else
int len = RFIFOW(fd,2);
int points = RFIFOL(fd,4);
Expand All @@ -15305,7 +15305,7 @@ void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * 4);
return;
}
fail = npc_cashshop_buylist(sd,points,count,item_list);
fail = npc->cashshop_buylist(sd,points,count,item_list);
#endif
}

Expand Down

0 comments on commit 95e13fe

Please sign in to comment.