psu_proto: Move npc_shop_enter and npc_shop_leave to events.

This commit is contained in:
Loïc Hoguin 2010-08-22 20:33:16 +02:00
parent 851db3f046
commit 468549fddf
2 changed files with 56 additions and 10 deletions

View File

@ -701,6 +701,20 @@ event({npc_invite, NPCid}) ->
send_1004(npc_invite, SentNPCUser, PartyPos), send_1004(npc_invite, SentNPCUser, PartyPos),
send_101a(NPCid, PartyPos); send_101a(NPCid, PartyPos);
%% @todo Currently send the normal items shop for all shops, differentiate.
event({npc_shop_enter, ShopID}) ->
log("npc shop enter ~p", [ShopID]),
GID = get(gid),
{ok, File} = file:read_file("p/itemshop.bin"),
send(<< 16#010a0300:32, 0:64, GID:32/little-unsigned-integer, 0:64, 16#00011300:32,
GID:32/little-unsigned-integer, 0:64, GID:32/little-unsigned-integer, 0:32, File/binary >>);
event({npc_shop_leave, ShopID}) ->
log("npc shop leave ~p", [ShopID]),
GID = get(gid),
send(<< 16#010a0300:32, 0:64, GID:32/little-unsigned-integer, 0:64, 16#00011300:32,
GID:32/little-unsigned-integer, 0:64, GID:32/little-unsigned-integer, 0:32 >>);
%% @todo First 1a02 value should be non-0. %% @todo First 1a02 value should be non-0.
%% @todo Could the 2nd 1a02 parameter simply be the shop type or something? %% @todo Could the 2nd 1a02 parameter simply be the shop type or something?
%% @todo Although the values replied should be right, they seem mostly ignored by the client. %% @todo Although the values replied should be right, they seem mostly ignored by the client.
@ -782,16 +796,6 @@ event({unicube_select, Selection, EntryID}) ->
handle(16#0102, _) -> handle(16#0102, _) ->
ignore; ignore;
%% @doc Shop listing request. Currently return the normal item shop for everything.
%% @todo Return the other shops appropriately.
handle(16#010a, Data) ->
<< _:64, A:16/little, B:8, C:8, D:16/little, E:16/little >> = Data,
log("shop listing request (~b,~b,~b,~b,~b)", [A, B, C, D, E]),
GID = get(gid),
{ok, File} = file:read_file("p/itemshop.bin"),
send(<< 16#010a0300:32, 0:64, GID:32/little-unsigned-integer, 0:64, 16#00011300:32,
GID:32/little-unsigned-integer, 0:64, GID:32/little-unsigned-integer, 0:32, File/binary >>);
%% @doc Shortcut changes handler. Do nothing. %% @doc Shortcut changes handler. Do nothing.
%% @todo Save it. %% @todo Save it.
handle(16#0302, _) -> handle(16#0302, _) ->

View File

@ -89,6 +89,48 @@ parse(Size, 16#0105, Channel, Data) ->
{Event, ItemID, TargetGID, TargetLID, VarH, VarI} {Event, ItemID, TargetGID, TargetLID, VarH, VarI}
end; end;
parse(Size, 16#010a, Channel, Data) ->
<< HeaderLID:16/little, VarA:16/little, VarB:32/little, VarC:32/little, VarD:32/little, VarE:32/little, VarF:32/little, VarG:32/little, VarH:32/little, VarI:32/little,
_GID:32/little, BodyLID:32/little, EventID:16/little, VarJ:8, VarK:8, Param:16/bits, VarL:16 >> = Data,
?ASSERT_EQ(Size, 60),
?ASSERT_EQ(Channel, 2),
?ASSERT_EQ(VarA, 0),
?ASSERT_EQ(VarB, 0),
?ASSERT_EQ(VarC, 0),
?ASSERT_EQ(VarD, 0),
?ASSERT_EQ(VarE, 0),
?ASSERT_EQ(VarF, 0),
?ASSERT_EQ(VarG, 0),
?ASSERT_EQ(VarH, 0),
?ASSERT_EQ(VarI, 0),
?ASSERT_EQ(HeaderLID, BodyLID),
case EventID of
1 ->
<< ShopID:16/little >> = Param,
?ASSERT_EQ(VarJ, 0),
?ASSERT_EQ(VarK, 0),
?ASSERT_EQ(VarL, 0),
{npc_shop_enter, ShopID};
2 ->
<< _ShopItemIndex:16/little >> = Param,
?ASSERT_EQ(VarJ, VarK),
?ASSERT_EQ(VarL, 0),
ignore; %% @todo {npc_shop_buy, ShopItemIndex};
3 ->
<< _InventoryItemIndex:8, _Unknown:8 >> = Param,
?ASSERT_EQ(VarK, 0),
?ASSERT_EQ(VarL, 0),
ignore; %% @todo {npc_shop_sell, InventoryItemIndex};
4 -> ?ASSERT(), ignore;
5 ->
<< ShopID:16/little >> = Param,
?ASSERT_EQ(VarJ, 0),
?ASSERT_EQ(VarK, 0),
?ASSERT_EQ(VarL, 0),
{npc_shop_leave, ShopID};
6 -> ?ASSERT(), ignore
end;
parse(Size, 16#0110, Channel, Data) -> parse(Size, 16#0110, Channel, Data) ->
<< _LID:16/little, VarA:16/little, VarB:32/little, HeaderGID:32/little, VarC:32/little, VarD:32/little, VarE:32/little, << _LID:16/little, VarA:16/little, VarB:32/little, HeaderGID:32/little, VarC:32/little, VarD:32/little, VarE:32/little,
VarF:32/little, VarG:32/little, VarH:32/little, BodyGID:32/little, _PartyPosOrLID:32/little, EventID:32/little, Param:32/little >> = Data, VarF:32/little, VarG:32/little, VarH:32/little, BodyGID:32/little, _PartyPosOrLID:32/little, EventID:32/little, Param:32/little >> = Data,