From db20d783fe41bb9b44b92461f9843a31146a5ce7 Mon Sep 17 00:00:00 2001 From: mekolat Date: Thu, 21 May 2015 19:17:03 -0400 Subject: npc actions --- src/map/clif.cpp | 18 ++++++++++++++++++ src/map/clif.hpp | 1 + src/map/script-fun.cpp | 25 +++++++++++++++++++++++++ tools/protocol.py | 2 +- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index d8e0b7e..73315d8 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -800,6 +800,24 @@ void clif_mob0078(dumb_ptr md, Buffer& buf) buf = create_fpacket<0x0078, 54>(fixed_78); } +void clif_npc_action(dumb_ptr sd, BlockId npcid, + short command, int id, short x, short y) +{ + nullpo_retv(sd); + if(sd->client_version < 2) + return; + + Packet_Fixed<0x0212> fixed_212; + fixed_212.npc_id = npcid; + fixed_212.command = command; + fixed_212.id = id; + fixed_212.x = x; + fixed_212.y = y; + + Buffer buf = create_fpacket<0x0212, 16>(fixed_212); + send_buffer(sd->sess, buf); +} + /*========================================== * MOB表示2 *------------------------------------------ diff --git a/src/map/clif.hpp b/src/map/clif.hpp index 8332fb9..99d4a2c 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -106,6 +106,7 @@ void clif_setnpcdirection(dumb_ptr nd, DIR direction); void clif_setnpcdirection_towards(dumb_ptr sd, dumb_ptr nd, DIR direction); void clif_npc_send_title(Session *s, BlockId npcid, XString msg); void clif_change_music(dumb_ptr sd, XString music); +void clif_npc_action(dumb_ptr, BlockId, short, int, short, short); // trade void clif_traderequest(dumb_ptr sd, CharName name); diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 520936b..0d19770 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -1614,6 +1614,30 @@ void builtin_setnpctimer(ScriptState *st) npc_settimerevent_tick(nd, tick); } +static +void builtin_npcaction(ScriptState *st) +{ + dumb_ptr sd = script_rid2sd(st); + short command = conv_num(st, &AARG(0)); + int id = 0; + short x = HARG(2) ? conv_num(st, &AARG(2)) : 0; + short y = HARG(3) ? conv_num(st, &AARG(3)) : 0; + + if(HARG(1)) + { + if(command == 2) + { + dumb_ptr nd_; + nd_ = npc_name2id(stringish(ZString(conv_str(st, &AARG(1))))); + id = unwrap(nd_->bl_id); + } + else + id = conv_num(st, &AARG(1)); + } + + clif_npc_action(sd, st->oid, command, id, x, y); +} + static void builtin_setnpcdirection(ScriptState *st) { @@ -3103,6 +3127,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(getnpctimer, "i?"_s, 'i'), BUILTIN(setnpctimer, "i?"_s, '\0'), BUILTIN(setnpcdirection, "iii?"_s, '\0'), + BUILTIN(npcaction, "i???"_s, '\0'), BUILTIN(announce, "si"_s, '\0'), BUILTIN(mapannounce, "Msi"_s, '\0'), BUILTIN(getusers, "i"_s, 'i'), diff --git a/tools/protocol.py b/tools/protocol.py index e3353de..23a0719 100755 --- a/tools/protocol.py +++ b/tools/protocol.py @@ -4631,7 +4631,7 @@ def build_context(): at(0, u16, 'packet id'), at(2, block_id, 'npc id'), at(6, u16, 'command'), - at(8, block_id, 'id'), + at(8, u32, 'id'), at(12, u16, 'x'), at(14, u16, 'y'), ], -- cgit v1.2.3-70-g09d2 From ef9eb6bde90ec1d9d175b6481935cb3bd67d6c6c Mon Sep 17 00:00:00 2001 From: mekolat Date: Sat, 23 May 2015 10:17:10 -0400 Subject: add clif_message_towards --- src/map/clif.cpp | 31 +++++++++++++++++++++++++------ src/map/clif.hpp | 1 + src/map/script-fun.cpp | 23 +++++++++++++++++------ 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 73315d8..db5ecd2 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -3809,19 +3809,16 @@ RecvResult clif_parse_GlobalMessage(Session *s, dumb_ptr sd) return rv; } -void clif_message(dumb_ptr bl, XString msg) +static +void clif_message_sub(Buffer& buf, dumb_ptr bl, XString msg) { size_t msg_len = msg.size() + 1; if (msg_len + 16 > 512) return; - nullpo_retv(bl); - Packet_Head<0x008d> head_8d; head_8d.block_id = bl->bl_id; - Buffer buf = create_vpacket<0x008d, 8, 1>(head_8d, msg); - - clif_send(buf, bl, SendWho::AREA, MIN_CLIENT_VERSION); + buf = create_vpacket<0x008d, 8, 1>(head_8d, msg); } void clif_npc_send_title(Session *s, BlockId npcid, XString msg) @@ -3854,6 +3851,28 @@ void clif_change_music(dumb_ptr sd, XString music) send_buffer(sd->sess, buf); } +void clif_message_towards(dumb_ptr sd, dumb_ptr bl, XString msg) +{ + nullpo_retv(bl); + nullpo_retv(sd); + + if(!sd) + return; + + Buffer buf; + clif_message_sub(buf, bl, msg); + clif_send(buf, sd, SendWho::SELF, MIN_CLIENT_VERSION); +} + +void clif_message(dumb_ptr bl, XString msg) +{ + nullpo_retv(bl); + + Buffer buf; + clif_message_sub(buf, bl, msg); + clif_send(buf, bl, SendWho::AREA, MIN_CLIENT_VERSION); +} + /*========================================== * *------------------------------------------ diff --git a/src/map/clif.hpp b/src/map/clif.hpp index 99d4a2c..cd499de 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -179,6 +179,7 @@ void clif_resurrection(dumb_ptr bl, int type); int clif_specialeffect(dumb_ptr bl, int type, int flag); // special effects [Valaris] void clif_message(dumb_ptr bl, XString msg); // messages (from mobs/npcs) [Valaris] +void clif_message_towards(dumb_ptr sd, dumb_ptr bl, XString msg); int clif_GM_kick(dumb_ptr sd, dumb_ptr tsd, int type); diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 0d19770..2b72fc4 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2713,13 +2713,24 @@ void builtin_music(ScriptState *st) static void builtin_npctalk(ScriptState *st) { - dumb_ptr nd = map_id_is_npc(st->oid); - RString str = conv_str(st, &AARG(0)); + dumb_ptr nd; + RString str = conv_str(st, &AARG(1)); - if (nd) - { - clif_message(nd, str); + dumb_ptr nd_ = npc_name2id(stringish(ZString(conv_str(st, &AARG(0))))); + assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT); + nd = nd_->is_script(); + + + if(HARG(2)){ + CharName player = stringish(ZString(conv_str(st, &AARG(2)))); + dumb_ptr pl_sd = map_nick2sd(player); + if (pl_sd == nullptr) + return; + clif_message_towards(pl_sd, nd, str); } + + else + clif_message(nd, str); } /*========================================== @@ -3174,7 +3185,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(npcwarp, "xys"_s, '\0'), BUILTIN(npcareawarp, "xyxyis"_s, '\0'), BUILTIN(message, "Ps"_s, '\0'), - BUILTIN(npctalk, "s"_s, '\0'), + BUILTIN(npctalk, "ss?"_s, '\0'), BUILTIN(title, "s"_s, '\0'), BUILTIN(music, "s"_s, '\0'), BUILTIN(getlook, "i"_s, 'i'), -- cgit v1.2.3-70-g09d2 From 08809eeb1db043ac72ca8a64f74e9f5ed6a54631 Mon Sep 17 00:00:00 2001 From: mekolat Date: Fri, 22 May 2015 13:09:14 -0400 Subject: add map mask support --- src/map/clif.cpp | 16 ++++++++++++++++ src/map/clif.hpp | 1 + src/map/map.hpp | 1 + src/map/mapflag.cpp | 2 +- src/map/mapflag.hpp | 2 +- src/map/mapflag.py | 2 +- src/map/npc-parse.cpp | 15 ++++++++++++++- src/map/pc.cpp | 3 +++ src/map/script-fun.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tools/protocol.py | 15 ++++++++++++++- 10 files changed, 98 insertions(+), 5 deletions(-) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index db5ecd2..35cc463 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -1155,6 +1155,9 @@ void clif_changemap(dumb_ptr sd, MapName mapname, int x, int y fixed_91.x = x; fixed_91.y = y; send_fpacket<0x0091, 22>(s, fixed_91); + + if(sd->bl_m->mask > 0) + clif_send_mask(sd, sd->bl_m->mask); } /*========================================== @@ -3873,6 +3876,19 @@ void clif_message(dumb_ptr bl, XString msg) clif_send(buf, bl, SendWho::AREA, MIN_CLIENT_VERSION); } +void clif_send_mask(dumb_ptr sd, int map_mask) +{ + nullpo_retv(sd); + if(sd->client_version < 2) + return; + + Packet_Fixed<0x0226> fixed_226; + fixed_226.mask = map_mask; + + Buffer buf = create_fpacket<0x0226, 10>(fixed_226); + send_buffer(sd->sess, buf); +} + /*========================================== * *------------------------------------------ diff --git a/src/map/clif.hpp b/src/map/clif.hpp index cd499de..28f58a9 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -107,6 +107,7 @@ void clif_setnpcdirection_towards(dumb_ptr sd, dumb_ptr sd, XString music); void clif_npc_action(dumb_ptr, BlockId, short, int, short, short); +void clif_send_mask(dumb_ptr, int); // trade void clif_traderequest(dumb_ptr sd, CharName name); diff --git a/src/map/map.hpp b/src/map/map.hpp index 2b638d4..aea35b7 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -505,6 +505,7 @@ struct map_local : map_abstract MapFlags flag; Point save; Point resave; + int mask; Array, MAX_NPC_PER_MAP> npc; }; diff --git a/src/map/mapflag.cpp b/src/map/mapflag.cpp index 9f3c9ab..22c4878 100644 --- a/src/map/mapflag.cpp +++ b/src/map/mapflag.cpp @@ -71,7 +71,7 @@ bool impl_extract(XString str, MapFlag *mf) {"nowarp"_s, MapFlag::NOWARP}, {"nowarpto"_s, MapFlag::NOWARPTO}, {"nopvp"_s, MapFlag::NOPVP}, - //{"noicewall"_s, MapFlag::NOICEWALL}, + {"mask"_s, MapFlag::MASK}, {"snow"_s, MapFlag::SNOW}, {"fog"_s, MapFlag::FOG}, {"sakura"_s, MapFlag::SAKURA}, diff --git a/src/map/mapflag.hpp b/src/map/mapflag.hpp index 3538c56..9223d70 100644 --- a/src/map/mapflag.hpp +++ b/src/map/mapflag.hpp @@ -54,7 +54,7 @@ enum class MapFlag NOWARP = 1 << 13, NOWARPTO = 1 << 26, NOPVP = 1 << 14, - //NOICEWALL = 1 << 15, + MASK = 1 << 15, SNOW = 1 << 16, FOG = 1 << 17, SAKURA = 1 << 18, diff --git a/src/map/mapflag.py b/src/map/mapflag.py index b0a2f24..728aa81 100644 --- a/src/map/mapflag.py +++ b/src/map/mapflag.py @@ -40,7 +40,7 @@ class MapFlags(object): ('NOWARP', 13), ('NOWARPTO', 26), ('NOPVP', 14), - #('NOICEWALL', 15), + ('MASK', 15), ('SNOW', 16), ('FOG', 17), ('SAKURA', 18), diff --git a/src/map/npc-parse.cpp b/src/map/npc-parse.cpp index 0a0d682..9ee84d2 100644 --- a/src/map/npc-parse.cpp +++ b/src/map/npc-parse.cpp @@ -354,7 +354,7 @@ bool npc_load_mapflag(ast::npc::MapFlag& mapflag) } MapName savemap; - int savex, savey; + int savex, savey, mask; if (mf == MapFlag::NOSAVE) { @@ -392,6 +392,19 @@ bool npc_load_mapflag(ast::npc::MapFlag& mapflag) return false; } } + else if (mf == MapFlag::MASK) + { + if (mapflag.vec_extra.data.size() == 1 + && extract(mapflag.vec_extra.data[0].data, &mask)) + { + m->mask = mask; + } + else + { + mapflag.vec_extra.span.error("Unable to extract map mask"_s); + return false; + } + } else { if (mapflag.vec_extra.data.size()) diff --git a/src/map/pc.cpp b/src/map/pc.cpp index ca636b4..96233e1 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -796,6 +796,9 @@ int pc_authok(AccountId id, int login_id2, pc_calcstatus(sd, 1); + if(sd->bl_m->mask > 0) + clif_send_mask(sd, sd->bl_m->mask); + // Init Quest Log clif_sendallquest(sd); return 0; diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 2b72fc4..2822550 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2704,6 +2704,50 @@ void builtin_music(ScriptState *st) clif_change_music(sd, msg); } +static +void builtin_mapmask(ScriptState *st) +{ + dumb_ptr nd; + dumb_ptr sd; + int map_mask = conv_num(st, &AARG(0)); + + if(st->oid) + nd = map_id_is_npc(st->oid); + if(st->rid) + sd = script_rid2sd(st); + + if(HARG(1) && sd != nullptr) + sd->bl_m->mask = map_mask; + else if(HARG(1) && nd) + nd->bl_m->mask = map_mask; + + if (sd == nullptr) + return; + clif_send_mask(sd, map_mask); +} + +static +void builtin_getmask(ScriptState *st) +{ + dumb_ptr nd; + dumb_ptr sd; + int map_mask; + + if(st->oid) + nd = map_id_is_npc(st->oid); + if(st->rid) + sd = script_rid2sd(st); + + if(sd != nullptr) + map_mask = sd->bl_m->mask; + else if(nd) + map_mask = nd->bl_m->mask; + else + map_mask = -1; + + push_int(st->stack, map_mask); +} + /*========================================== * npctalk (sends message to surrounding * area) [Valaris] @@ -3188,6 +3232,8 @@ BuiltinFunction builtin_functions[] = BUILTIN(npctalk, "ss?"_s, '\0'), BUILTIN(title, "s"_s, '\0'), BUILTIN(music, "s"_s, '\0'), + BUILTIN(mapmask, "i?"_s, '\0'), + BUILTIN(getmask, ""_s, 'i'), BUILTIN(getlook, "i"_s, 'i'), BUILTIN(getsavepoint, "i"_s, '.'), BUILTIN(areatimer, "MxyxytE"_s, '\0'), diff --git a/tools/protocol.py b/tools/protocol.py index 23a0719..f7be6e5 100755 --- a/tools/protocol.py +++ b/tools/protocol.py @@ -4703,7 +4703,20 @@ def build_context(): Send mob walkpath data to client ''', ) - # 0x0226 define='SMSG_MAP_MASK', + map_user.s(0x0226, 'send map mask', + define='SMSG_MAP_MASK', + fixed=[ + at(0, u16, 'packet id'), + at(2, u32, 'mask'), + at(6, u32, 'unused'), + ], + fixed_size=10, + pre=[NOTHING], + post=[PRETTY], + desc=''' + Set map mask + ''', + ) map_user.s(0x0227, 'change map music', define='SMSG_MAP_MUSIC', head=[ -- cgit v1.2.3-70-g09d2