psu_game: Load the players already in the zone on zone change.
This commit is contained in:
parent
50c2a2615f
commit
ad7071a61b
@ -63,7 +63,10 @@ select({neighbors, User}) ->
|
||||
X#?TABLE.instancepid =:= User#?TABLE.instancepid,
|
||||
X#?TABLE.area =:= User#?TABLE.area
|
||||
])),
|
||||
{ok, List}.
|
||||
{ok, List};
|
||||
select(UsersGID) ->
|
||||
L = [read(GID) || GID <- UsersGID],
|
||||
[User || {ok, User} <- L].
|
||||
|
||||
%% @spec write(User) -> ok
|
||||
write(User) ->
|
||||
|
@ -20,7 +20,7 @@
|
||||
-module(egs_zones).
|
||||
-behaviour(gen_server).
|
||||
|
||||
-export([start_link/4, stop/1, setid/1, enter/2, leave/2]). %% API.
|
||||
-export([start_link/4, stop/1, setid/1, enter/2, leave/2, get_all_players/2]). %% API.
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). %% gen_server.
|
||||
|
||||
-record(state, {
|
||||
@ -51,6 +51,9 @@ enter(Pid, GID) ->
|
||||
leave(Pid, GID) ->
|
||||
gen_server:cast(Pid, {leave, GID}).
|
||||
|
||||
get_all_players(Pid, ExcludeGID) ->
|
||||
gen_server:call(Pid, {get_all_players, ExcludeGID}).
|
||||
|
||||
%% gen_server.
|
||||
|
||||
init([UniID, QuestID, ZoneID, ZoneData]) ->
|
||||
@ -71,6 +74,9 @@ handle_call({enter, GID}, _From, State) ->
|
||||
egs_users:broadcast_spawn(GID, PlayersGID),
|
||||
{reply, LID, State#state{players=[{GID, LID}|Players], freelids=FreeLIDs}};
|
||||
|
||||
handle_call({get_all_players, ExcludeGID}, _From, State) ->
|
||||
{reply, lists:delete(ExcludeGID, players_gid(State#state.players)), State};
|
||||
|
||||
handle_call(stop, _From, State) ->
|
||||
{stop, normal, stopped, State};
|
||||
|
||||
|
@ -88,10 +88,16 @@ area_load(QuestID, ZoneID, MapID, EntryID, State) ->
|
||||
%% Load the player.
|
||||
psu_proto:send_0201(User3#users{lid=0}, State2),
|
||||
if ZoneChange ->
|
||||
psu_proto:send_0a06(User3, State2);
|
||||
psu_proto:send_0a06(User3, State2),
|
||||
%% Load the other players in the zone.
|
||||
OtherPlayersGID = egs_zones:get_all_players(User3#users.zonepid, User3#users.gid),
|
||||
if OtherPlayersGID =:= [] -> ignore;
|
||||
true ->
|
||||
OtherPlayers = egs_users:select(OtherPlayersGID),
|
||||
psu_proto:send_0233(OtherPlayers, State)
|
||||
end;
|
||||
true -> ignore
|
||||
end,
|
||||
%% @todo Send the spawn list.
|
||||
%% End of loading.
|
||||
State3 = State2#state{areanb=State2#state.areanb + 1},
|
||||
psu_proto:send_0208(State3),
|
||||
|
Loading…
Reference in New Issue
Block a user