%% ---------------------------------------------------------
%% Author:  xyj
%% Email:   156702030@qq.com
%% Created: 2011-12-29
%% Description: 仓库物品操作
%% --------------------------------------------------------
-module(lib_storage_util).
-compile(export_all).
-include("common.hrl").
-include("goods.hrl").
-include("def_goods.hrl").
-include("sql_goods.hrl").
-include("figure.hrl").
-include("server.hrl").
-include("sell.hrl").
-include("errcode.hrl").
-include("def_fun.hrl").

%% 检查某个物品存入
check_movein_pos(_PlayerStatus, GoodsStatus, GoodsInfo, ToPos) ->
    case data_goods_type:get(GoodsInfo#goods.goods_id) of
        %% 物品类型不存在
        [] ->
            {fail, ?ERRCODE(err150_no_goods_type)};
        _GoodsTypeInfo ->
            FreeNum = lib_goods_util:get_null_cell_num(GoodsStatus, ToPos),
            if
            %% 背包
                ToPos == ?GOODS_LOC_BAG andalso FreeNum =< 0 ->
                    {fail, ?ERRCODE(err150_no_cell)};
            %% 仓库
                ToPos == ?GOODS_LOC_STORAGE andalso FreeNum =< 0 ->
                    {fail, ?ERRCODE(err150_storage_no_cell)};
                true ->
                    {ok, GoodsInfo}
            end
    end.

%% 仓库扩展
extend_storage(PlayerStatus, CellNum) ->
    NewCellNum = PlayerStatus#player_status.storage_num + CellNum,
    Sql = io_lib:format(?SQL_PLAYER_UPDATE_STORAGE_NUM, [NewCellNum, PlayerStatus#player_status.id]),
    goods_transaction:add_sql(Sql),
    PlayerStatus#player_status{storage_num = NewCellNum}.


