diff --git a/p/packet0a06.bin b/p/packet0a06.bin deleted file mode 100644 index 49cda14..0000000 Binary files a/p/packet0a06.bin and /dev/null differ diff --git a/src/egs_game.erl b/src/egs_game.erl index b4fb092..b40b208 100644 --- a/src/egs_game.erl +++ b/src/egs_game.erl @@ -283,7 +283,7 @@ event({counter_enter, CounterID, FromZoneID, FromMapID, FromEntryID}, State=#sta psu_game:send_1207(), psu_game:send_1212(), psu_proto:send_0201(User#egs_user_model{lid=0}, State2), - psu_game:send_0a06(), + psu_proto:send_0a06(User, State2), case User#egs_user_model.partypid of undefined -> ignore; _ -> psu_game:send_022c(0, 16#12) diff --git a/src/egs_user_model.erl b/src/egs_user_model.erl index 77ebe86..feaa199 100644 --- a/src/egs_user_model.erl +++ b/src/egs_user_model.erl @@ -194,7 +194,7 @@ handle_call({item_add, GID, ItemID, Variables}, _From, State) -> Character2 = Character#characters{inventory=Inventory2}, mnesia:transaction(fun() -> mnesia:write(User#egs_user_model{character=Character2}) end), if New =:= false -> {reply, 16#ffffffff, State}; - true -> {reply, 1000 + mnesia:dirty_update_counter(counters, items, 1), State} + true -> {reply, length(Inventory2), State} end; handle_call({shop_get, GID}, _From, State) -> diff --git a/src/psu/psu_game.erl b/src/psu/psu_game.erl index b37fbe2..f31a39d 100644 --- a/src/psu/psu_game.erl +++ b/src/psu/psu_game.erl @@ -204,7 +204,7 @@ area_load(AreaType, IsStart, SetID, OldUser, User, QuestFile, ZoneFile, AreaName end, psu_proto:send_0201(User#egs_user_model{lid=0}, State2), if ZoneChange =:= true -> - send_0a06(); + psu_proto:send_0a06(User, State2); true -> ignore end, send_0233(SpawnList), @@ -386,29 +386,22 @@ send_0a04(NPCGID) -> {ok, Bin} = file:read_file("p/packet0a04.bin"), send(<< 16#0a040300:32, 0:32, 16#00001d00:32, NPCGID:32/little-unsigned-integer, 0:64, 16#00011300:32, GID:32/little-unsigned-integer, 0:64, Bin/binary >>). -%% @todo Inventory related. Figure out everything in this packet and handle it correctly. -%% @todo It sends 60 values so it's probably some kind of options for all 60 items in the inventory? -send_0a06() -> - {ok, << _:32, A:96/bits, _:32, B:96/bits, _:32, C:1440/bits, _:32, D/bits >>} = file:read_file("p/packet0a06.bin"), - GID = get(gid), - send(<< A/binary, GID:32/little-unsigned-integer, B/binary, GID:32/little-unsigned-integer, C/binary, GID:32/little-unsigned-integer, D/binary >>). - %% @todo Handle more than just goggles. send_0a0a(Inventory) -> {ok, << _:68608/bits, Rest/bits >>} = file:read_file("p/packet0a0a.bin"), GID = get(gid), NbItems = length(Inventory), - ItemVariables = build_0a0a_item_variables(Inventory, []), + ItemVariables = build_0a0a_item_variables(Inventory, 1, []), ItemConstants = build_0a0a_item_constants(Inventory, []), send(<< 16#0a0a0300:32, 16#ffff:16, 0:144, 16#00011300:32, GID:32/little, 0:64, NbItems:8, 0:8, 6:8, 0:72, 0:192, 0:2304, ItemVariables/binary, ItemConstants/binary, 0:13824, Rest/binary >>). -%% @todo That ItemUUID have to be handled properly. -build_0a0a_item_variables([], Acc) -> +build_0a0a_item_variables([], _N, Acc) -> + io:format("~p~n", [_N]), Bin = iolist_to_binary(lists:reverse(Acc)), Padding = 17280 - 8 * byte_size(Bin), << Bin/binary, 0:Padding >>; -build_0a0a_item_variables([{ItemID, Variables}|Tail], Acc) -> - build_0a0a_item_variables(Tail, [build_item_variables(ItemID, 0, Variables)|Acc]). +build_0a0a_item_variables([{ItemID, Variables}|Tail], N, Acc) -> + build_0a0a_item_variables(Tail, N + 1, [build_item_variables(ItemID, N, Variables)|Acc]). build_item_variables(ItemID, ItemUUID, #psu_clothing_item_variables{color=ColorNb}) -> #psu_item{rarity=Rarity, data=#psu_clothing_item{colors=ColorsBin}} = proplists:get_value(ItemID, ?ITEMS), diff --git a/src/psu/psu_proto.erl b/src/psu/psu_proto.erl index 3986861..8dee263 100644 --- a/src/psu/psu_proto.erl +++ b/src/psu/psu_proto.erl @@ -1330,8 +1330,19 @@ send_0236(#state{socket=Socket, gid=DestGID}) -> packet_send(Socket, << 16#02360300:32, 0:160, 16#00011300:32, DestGID:32/little, 0:64 >>). %% @todo Inventory related. Doesn't seem to do anything. -send_0a05(#state{socket=Socket, gid=DestGID, lid=DestLID}) -> - packet_send(Socket, << 16#0a050300:32, DestLID:16/little, 0:144, 16#00011300:32, DestGID:32/little, 0:64 >>). +%% @todo Handle the LID properly. +send_0a05(#state{socket=Socket, gid=DestGID}) -> + packet_send(Socket, << 16#0a050300:32, 0:160, 16#00011300:32, DestGID:32/little, 0:64 >>). + +%% @doc Send the list of ItemUUID for the items in the inventory. +%% @todo Handle the LID properly. +send_0a06(CharUser, #state{socket=Socket, gid=DestGID}) -> + Len = length((CharUser#egs_user_model.character)#characters.inventory), + UUIDs = lists:seq(1, Len), + Bin = iolist_to_binary([ << N:32/little >> || N <- UUIDs]), + Blanks = lists:seq(1, 60 - Len), + Bin2 = iolist_to_binary([ << 16#ffffffff:32 >> || _N <- Blanks]), + packet_send(Socket, << 16#0a060300:32, 0:64, DestGID:32/little, 0:64, 16#00011300:32, DestGID:32/little, 0:64, Bin/binary, Bin2/binary >>). %% @doc Send an item's description. send_0a11(ItemID, ItemDesc, #state{socket=Socket, gid=DestGID, lid=DestLID}) ->