diff options
author | mekolat <mekolat@users.noreply.github.com> | 2015-05-07 20:42:47 -0400 |
---|---|---|
committer | mekolat <mekolat@users.noreply.github.com> | 2015-05-19 18:52:48 -0400 |
commit | 3474fe93eef3cde085b6a9ee8c7efd4a5e2cddea (patch) | |
tree | 9cb612e35201d2019bf140a470ca90087fa77c04 /src/map | |
parent | 6fd7eab6ba5d836c47847aca618ee02a50967072 (diff) | |
download | tmwa-3474fe93eef3cde085b6a9ee8c7efd4a5e2cddea.tar.gz tmwa-3474fe93eef3cde085b6a9ee8c7efd4a5e2cddea.tar.bz2 tmwa-3474fe93eef3cde085b6a9ee8c7efd4a5e2cddea.tar.xz tmwa-3474fe93eef3cde085b6a9ee8c7efd4a5e2cddea.zip |
add a builtin to change npc direction and make them sit
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.cpp | 27 | ||||
-rw-r--r-- | src/map/clif.cpp | 94 | ||||
-rw-r--r-- | src/map/clif.hpp | 5 | ||||
-rw-r--r-- | src/map/script-fun.cpp | 38 |
4 files changed, 126 insertions, 38 deletions
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index d587bde..63a1159 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -4157,30 +4157,6 @@ ATCE atcommand_npcmove(Session *, dumb_ptr<map_session_data>, } static -ATCE atcommand_npcsit(Session *, dumb_ptr<map_session_data> sd, - ZString message) -{ - NpcName character; - dumb_ptr<npc_data> nd = nullptr; - - if (!asplit(message, &character)) - return ATCE::USAGE; - - nd = npc_name2id(character); - if (nd == nullptr) - return ATCE::EXIST; - - if(nd->sit == DamageType::SIT) - nd->sit = DamageType::STAND; - else - nd->sit = DamageType::SIT; - - clif_sitnpc(sd, nd, true); - - return ATCE::OKAY; -} - -static ATCE atcommand_addwarp(Session *s, dumb_ptr<map_session_data> sd, ZString message) { @@ -5291,9 +5267,6 @@ Map<XString, AtCommandInfo> atcommand_info = {"npcmove"_s, {"<x> <y> <npc-name>"_s, 80, atcommand_npcmove, "Force an NPC to move on the map"_s}}, - {"npcsit"_s, {"<npc-name>"_s, - 80, atcommand_npcsit, - "Force an NPC to move on the map"_s}}, {"charpvp"_s, {"<charname> <channel>"_s, 40, atcommand_charpvp, "Set the pvp channel of another player"_s}}, diff --git a/src/map/clif.cpp b/src/map/clif.cpp index e48b2fd..5297084 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -131,6 +131,9 @@ static void clif_quitsave(Session *, dumb_ptr<map_session_data> sd); static +void clif_sitnpc_sub(Buffer& buf, dumb_ptr<npc_data> nd, DamageType dmg); + +static void clif_delete(Session *s) { assert (s != char_session); @@ -958,7 +961,11 @@ int clif_spawnnpc(dumb_ptr<npc_data> nd) clif_send(buf, nd, SendWho::AREA); if(nd->sit == DamageType::SIT) - clif_sitnpc(nullptr, nd, true); + { + Buffer buff; + clif_sitnpc_sub(buff, nd, nd->sit); + clif_send(buff, nd, SendWho::AREA); + } return 0; } @@ -2364,7 +2371,11 @@ void clif_getareachar_npc(dumb_ptr<map_session_data> sd, dumb_ptr<npc_data> nd) send_buffer(sd->sess, buf); if(nd->sit == DamageType::SIT) - clif_sitnpc(sd, nd, false); + { + Buffer buff; + clif_sitnpc_sub(buff, nd, nd->sit); + send_buffer(sd->sess, buff); + } } /*========================================== @@ -3181,20 +3192,83 @@ void clif_sitting(Session *, dumb_ptr<map_session_data> sd) clif_send(buf, sd, SendWho::AREA); } -void clif_sitnpc(dumb_ptr<map_session_data> sd, dumb_ptr<npc_data> nd, bool area) +static +void clif_sitnpc_sub(Buffer& buf, dumb_ptr<npc_data> nd, DamageType dmg) { nullpo_retv(nd); - nullpo_retv(sd); Packet_Fixed<0x008a> fixed_8a; fixed_8a.src_id = nd->bl_id; - fixed_8a.damage_type = nd->sit; - Buffer buf = create_fpacket<0x008a, 29>(fixed_8a); + fixed_8a.damage_type = dmg; + buf = create_fpacket<0x008a, 29>(fixed_8a); +} - if(area) - clif_send(buf, nd, SendWho::AREA); - else if(sd) - clif_send(buf, sd, SendWho::SELF); +void clif_sitnpc_towards(dumb_ptr<map_session_data> sd, dumb_ptr<npc_data> nd, DamageType dmg) +{ + nullpo_retv(nd); + nullpo_retv(sd); + + if(!sd) + return; + + Buffer buf; + clif_sitnpc_sub(buf, nd, dmg); + clif_send(buf, sd, SendWho::SELF); +} + +void clif_sitnpc(dumb_ptr<npc_data> nd, DamageType dmg) +{ + nullpo_retv(nd); + + Buffer buf; + clif_sitnpc_sub(buf, nd, dmg); + clif_send(buf, nd, SendWho::AREA); +} + +static +void clif_setnpcdirection_sub(Buffer& buf, dumb_ptr<npc_data> nd, DIR direction) +{ + nullpo_retv(nd); + short dir = 1 | 0; + + switch (direction) + { + case DIR::S: dir = 1 | 0; break; // down + case DIR::SW: dir = 1 | 2; break; + case DIR::W: dir = 0 | 2; break; // left + case DIR::NW: dir = 4 | 2; break; + case DIR::N: dir = 4 | 0; break; // up + case DIR::NE: dir = 4 | 8; break; + case DIR::E: dir = 0 | 8; break; // right + case DIR::SE: dir = 1 | 8; break; + } + + Packet_Fixed<0x009c> fixed_9c; + fixed_9c.block_id = nd->bl_id; + fixed_9c.client_dir = dir; + buf = create_fpacket<0x009c, 9>(fixed_9c); +} + +void clif_setnpcdirection_towards(dumb_ptr<map_session_data> sd, dumb_ptr<npc_data> nd, DIR direction) +{ + nullpo_retv(nd); + nullpo_retv(sd); + + if(!sd) + return; + + Buffer buf; + clif_setnpcdirection_sub(buf, nd, direction); + clif_send(buf, sd, SendWho::SELF); +} + +void clif_setnpcdirection(dumb_ptr<npc_data> nd, DIR direction) +{ + nullpo_retv(nd); + + Buffer buf; + clif_setnpcdirection_sub(buf, nd, direction); + clif_send(buf, nd, SendWho::AREA); } /*========================================== diff --git a/src/map/clif.hpp b/src/map/clif.hpp index 862aed9..3cc308c 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -98,7 +98,10 @@ int clif_useitemack(dumb_ptr<map_session_data>, IOff0, int, int); // self void clif_emotion(dumb_ptr<block_list> bl, int type); void clif_emotion_towards(dumb_ptr<block_list> bl, dumb_ptr<block_list> target, int type); void clif_sitting(Session *, dumb_ptr<map_session_data> sd); -void clif_sitnpc(dumb_ptr<map_session_data> sd, dumb_ptr<npc_data> nd, bool area); +void clif_sitnpc(dumb_ptr<npc_data> nd, DamageType dmg); +void clif_sitnpc_towards(dumb_ptr<map_session_data> sd, dumb_ptr<npc_data> nd, DamageType dmg); +void clif_setnpcdirection(dumb_ptr<npc_data> nd, DIR direction); +void clif_setnpcdirection_towards(dumb_ptr<map_session_data> sd, dumb_ptr<npc_data> nd, DIR direction); // trade void clif_traderequest(dumb_ptr<map_session_data> sd, CharName name); diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 9020203..7617e0d 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -1631,6 +1631,43 @@ void builtin_setnpctimer(ScriptState *st) npc_settimerevent_tick(nd, tick); } +static +void builtin_setnpcdirection(ScriptState *st) +{ + dumb_ptr<npc_data> nd_; + DIR dir = static_cast<DIR>(conv_num(st, &AARG(0))); + bool save = bool(conv_num(st, &AARG(2))); + DamageType action; + + if (HARG(3)) + nd_ = npc_name2id(stringish<NpcName>(ZString(conv_str(st, &AARG(3))))); + else + nd_ = map_id_is_npc(st->oid); + + if (bool(conv_num(st, &AARG(1)))) + action = DamageType::SIT; + else + action = DamageType::STAND; + + if (save) + { + nd_->dir = dir; + nd_->sit = action; + } + + if (st->rid) + { + dumb_ptr<map_session_data> sd = script_rid2sd(st); + clif_sitnpc_towards(sd, nd_, action); + clif_setnpcdirection_towards(sd, nd_, dir); + } + else + { + clif_sitnpc(nd_, action); + clif_setnpcdirection(nd_, dir); + } +} + /*========================================== * 天の声アナウンス *------------------------------------------ @@ -3062,6 +3099,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(stopnpctimer, "?"_s, '\0'), BUILTIN(getnpctimer, "i?"_s, 'i'), BUILTIN(setnpctimer, "i?"_s, '\0'), + BUILTIN(setnpcdirection, "iii?"_s, '\0'), BUILTIN(announce, "si"_s, '\0'), BUILTIN(mapannounce, "Msi"_s, '\0'), BUILTIN(getusers, "i"_s, 'i'), |