psu_proto: Move npc_invite to events.

This commit is contained in:
Loïc Hoguin 2010-08-21 17:08:21 +02:00
parent 13ace4082f
commit dd6a44ef7f
3 changed files with 42 additions and 28 deletions

View File

@ -625,6 +625,29 @@ event({item_unequip, ItemID, TargetGID, TargetLID, A, B}) ->
send(<< 16#01050300:32, 0:64, GID:32/little-unsigned-integer, 0:64, 16#00011300:32, GID:32/little-unsigned-integer,
0:64, TargetGID:32/little-unsigned-integer, TargetLID:32/little-unsigned-integer, ItemID, 2, Category, A, B:32/little-unsigned-integer >>);
%% @todo Also happening a 1506 -> 1507? Only on first selection from menu.
%% @todo Also at the end send a 101a (NPC:16, PartyPos:16, ffffffff). Not sure about PartyPos.
event({npc_invite, NPCid}) ->
GID = get(gid),
{ok, User} = egs_user_model:read(GID),
%% Create NPC.
log("invited npcid ~b", [NPCid]),
TmpNPCUser = psu_npc:user_init(NPCid, ((User#egs_user_model.character)#characters.mainlevel)#level.number),
%% Create and join party.
%% @todo Check if party already exists.
{ok, PartyPid} = psu_party:start_link(GID),
{ok, PartyPos} = psu_party:join(PartyPid, npc, TmpNPCUser#egs_user_model.id),
NPCUser = TmpNPCUser#egs_user_model{lid=PartyPos, partypid=PartyPid},
egs_user_model:write(NPCUser),
egs_user_model:write(User#egs_user_model{partypid=PartyPid}),
%% Send stuff.
Character = NPCUser#egs_user_model.character,
SentNPCCharacter = Character#characters{gid=NPCid},
SentNPCUser = NPCUser#egs_user_model{id=NPCid, character=SentNPCCharacter},
%% @todo send_022c(0, 2),
send_1004(npc_invite, SentNPCUser, PartyPos),
send_101a(NPCid, PartyPos);
%% @todo If the player has a scape, use it! Otherwise red screen.
%% @todo Right now we force revive and don't update the player's HP.
event(player_death) ->
@ -752,33 +775,6 @@ handle(16#0404, Data) ->
log("unknown command 0404: eventid ~b blockid ~b value ~b", [EventID, BlockID, Value]),
send_1205(EventID, BlockID, Value);
%% @doc NPC invite.
%% @todo Also happening a 1506 -> 1507? Only on first selection from menu.
%% @todo Apparently Unknown is always ffffffff.
%% @todo Also at the end send a 101a (NPC:16, PartyPos:16, ffffffff). Not sure about PartyPos.
%% @todo Probably needs to make the NPC show up if he's invited while in-mission.
handle(16#0813, Data) ->
GID = get(gid),
{ok, User} = egs_user_model:read(GID),
%% Create NPC.
<< _Unknown:32, NPCid:32/little-unsigned-integer >> = Data,
log("invited npcid ~b", [NPCid]),
TmpNPCUser = psu_npc:user_init(NPCid, ((User#egs_user_model.character)#characters.mainlevel)#level.number),
%% Create and join party.
%% @todo Check if party already exists.
{ok, PartyPid} = psu_party:start_link(GID),
{ok, PartyPos} = psu_party:join(PartyPid, npc, TmpNPCUser#egs_user_model.id),
NPCUser = TmpNPCUser#egs_user_model{lid=PartyPos, partypid=PartyPid},
egs_user_model:write(NPCUser),
egs_user_model:write(User#egs_user_model{partypid=PartyPid}),
%% Send stuff.
Character = NPCUser#egs_user_model.character,
SentNPCCharacter = Character#characters{gid=NPCid},
SentNPCUser = NPCUser#egs_user_model{id=NPCid, character=SentNPCCharacter},
%% @todo send_022c(0, 2),
send_1004(npc_invite, SentNPCUser, PartyPos),
send_101a(NPCid, PartyPos);
%% @todo Used in the tutorial. Not sure what it does. Give an item (the PA) maybe?
handle(16#0a09, Data) ->
log("~p", [Data]),

View File

@ -34,4 +34,5 @@ user_init(NPCid, BaseLevel) ->
#psu_npc{race=Race, gender=Gender, class=Class, level=LevelDiff, appearance=Appearance} = Settings,
Character = #characters{gid=NPCGID, slot=0, type=npc, npcid=NPCid, name=UCS2Name, race=Race, gender=Gender, class=Class, appearance=Appearance,
mainlevel={level, BaseLevel + LevelDiff, 0}, blastbar=0, luck=2, money=0, playtime=0, stats={stats, 0, 0, 0, 0, 0, 0, 0}, se=[], currenthp=100, maxhp=100},
#egs_user_model{id=NPCGID, state=online, character=Character, areatype=lobby, area={psu_area, 0, 0, 0}, entryid=0, pos={pos, 0.0, 0.0, 0.0, 0.0}}.
#egs_user_model{id=NPCGID, state=online, character=Character, areatype=lobby, area={psu_area, 0, 0, 0}, entryid=0,
prev_area={psu_area, 0, 0, 0}, prev_entryid=0, pos={pos, 0.0, 0.0, 0.0, 0.0}}.

View File

@ -202,6 +202,23 @@ parse(Size, 16#0812, Channel, Data) ->
?ASSERT_EQ(VarI, 0),
counter_leave;
parse(Size, 16#0813, Channel, Data) ->
<< _LID: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, VarJ:32/little, NPCid:32/little >> = Data,
?ASSERT_EQ(Size, 52),
?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(VarJ, 16#ffffffff),
{npc_invite, NPCid};
parse(Size, 16#0b05, _Channel, _Data) ->
?ASSERT_EQ(Size, 8),
ignore;