%%%-------------------------------------------------------------------
%%% @author : tyl
%%% @doc    时装工坊协议模块
%%% Module  : pp_workroom.erl
%%% Created : 2021-05-21
%%% @end
%%%-------------------------------------------------------------------
-module(pp_workroom).

-include("common.hrl").
-include("server.hrl").
-include("figure.hrl").
-include("def_module.hrl").
-include("predefine.hrl").
-include("errcode.hrl").


-export([handle/3]).

handle(Cmd, Status, Data) ->
	#player_status{figure = Figure} = Status,
	OpenLv = lib_module:get_open_lv(?MOD_WORKROOM),
	case Figure#figure.lv >= OpenLv of
		true ->
			do_handle(Cmd, Status, Data);
		false -> skip
	end.

%% 打造目标信息
do_handle(42101, Player, []) ->
	lib_workroom:forge_target_info(Player),
	{ok, Player};

%% 替换/删除打造目标
do_handle(42102, Player, [Type, GoodsList]) when Type == 0 orelse Type == 1 ->
	case Type of
		0 ->
			case GoodsList of
				[GoodsId] ->
					lib_workroom:change_forge_target(Player, GoodsId);
				_ ->
					lib_workroom:send_error(Player, ?ERRCODE(err421_forge_list_err)),
					{ok, Player}
			end;
		1 ->
			lib_workroom:delete_forge_target(Player, GoodsList)
	end;
do_handle(42102, Player, [Type, GoodsList]) when Type == 2 ->
	lib_workroom:replace_forge_target(Player, GoodsList);
do_handle(42102, Player, [_Type, _GoodsList]) ->
	{ok, Player};

%% 打造物品
do_handle(42103, Player, [GoodsId]) ->
	lib_workroom:forge_goods(Player, GoodsId);

%% 套装信息
do_handle(42104, Player, []) ->
	lib_workroom:suit_info(Player);

%% 激活套装
do_handle(42105, Player, [SuitId]) ->
	lib_workroom:active_suit(Player, SuitId);

%% 商城商品
do_handle(42106, Player, []) ->
	lib_workroom:shop_info(Player);

%% 购买商品
do_handle(42107, Player, [Pos]) ->
	lib_workroom:buy_good(Player, Pos);

%% 刷新商城
do_handle(42108, Player, []) ->
	lib_workroom:refresh_goods(Player);

do_handle(_Cmd, _PS, _Args) ->
	?ERR("Nomatch Cmd:~p Args:~p", [_Cmd, _Args]),
	{ok, _PS}.



