Skip to content

Commit

Permalink
Fixes to item drops
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustav Simonsson committed Jul 8, 2012
1 parent 73ccd60 commit 7166c0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
22 changes: 12 additions & 10 deletions apps/browserquest_srv/src/browserquest_srv_item.erl
Expand Up @@ -11,7 +11,7 @@

-include("../include/browserquest.hrl").
%% API
-export([create/2, start_link/2]).
-export([create/4, start_link/4]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
Expand All @@ -21,27 +21,29 @@

-define(SERVER, ?MODULE).

-record(state, {id}).
-record(state, {id, zone}).

%%%===================================================================
%%% API
%%%===================================================================
create(ItemType, Args) ->
start_link(ItemType, Args).
start_link(ItemType, Args) ->
gen_server:start_link(?MODULE, [ItemType, Args], []).
create(Zone, Item, Id, SpawnInfo) ->
start_link(Zone, Item, Id, SpawnInfo).
start_link(Zone, Item, Id, SpawnInfo) ->
gen_server:start_link(?MODULE, [Zone, Item, Id, SpawnInfo], []).

pickup(ItemPid, PlayerState) ->
gen_server:call(ItemPid, {pickup, PlayerState}).

%%%===================================================================
%%% gen_server callbacks
%%%===================================================================
init([ItemType, Args]) ->
browserquest_srv_entity_handler:register(Args),
{ok, #state{id = ItemType}}.
init([Zone, Item, Id, SpawnInfo]) ->
browserquest_srv_entity_handler:register(Zone, Item, Id, SpawnInfo),
{ok, #state{id = Item, zone = Zone}}.

handle_call({pickup, PlayerState}, _From, State = #state{id = Id}) ->
handle_call({pickup, PlayerState}, _From,
State = #state{id = Id, zone = Zone}) ->
browserquest_srv_entity_handler:unregister(Zone),
{stop, normal, new_player_state(Id, PlayerState), State};
handle_call(Request, From, State) ->
browserquest_srv_util:unexpected_call(?MODULE, Request, From, State),
Expand Down
5 changes: 2 additions & 3 deletions apps/browserquest_srv/src/browserquest_srv_mob.erl
Expand Up @@ -87,7 +87,6 @@ handle_call({get_armor}, _From, State = #state{id = Id, armor = Armor}) ->

handle_call(Request, From, State) ->
browserquest_srv_util:unexpected_call(?MODULE, Request, From, State),
Reply = ok,
{reply, ok, State}.

handle_cast({tick}, State = #state{hate = _Hate, hitpoints = HP}) ->
Expand Down Expand Up @@ -151,9 +150,9 @@ drop_item(Item, X, Y) ->
%% Items start with 9
Id = browserquest_srv_entity_handler:generate_id("9"),
Zone = browserquest_srv_entity_handler:make_zone(X,Y),
Args = [Zone, Item, Id, [?SPAWN, Id, Item, X, Y]],
SpawnInfo = [?SPAWN, Id, Item, X, Y],
%% Remove apply, spawn item gen_server, call register from it
Fun = fun() -> browserquest_srv_item:create(Item, Args) end,
Fun = fun() -> browserquest_srv_item:create(Zone, Item, Id, SpawnInfo) end,
spawn(Fun),
ok.

Expand Down

0 comments on commit 7166c0e

Please sign in to comment.