%% ---------------------------------------------------------------------------
%% @doc lib_guild.erl

%% @author  hjh
%% @email  hejiahua@163.com
%% @since  2016-12-15
%% @deprecated 玩家进程
%% ---------------------------------------------------------------------------
-module(lib_guild).
-export([]).

-compile(export_all).

-include("server.hrl").
-include("figure.hrl").
-include("guild.hrl").
-include("sql_guild.hrl").
-include("errcode.hrl").
-include("common.hrl").
-include("scene.hrl").
-include("def_daily.hrl").
-include("def_module.hrl").
-include("def_event.hrl").
-include("role.hrl").
-include("goods.hrl").
-include("def_fun.hrl").
-include("predefine.hrl").
-include("daily.hrl").

%% 获取公会status
load_status_guild(RoleId, Now, _LastLogoutTime) ->
    %获取公会相关信息
    MemberSql = io_lib:format(?sql_guild_member_select_login, [RoleId]),
    case db:get_row(MemberSql) of
        [GuildId, Position, CreateTime] ->
            GuildSql = io_lib:format(?sql_guild_select_login, [GuildId]),
            case db:get_row(GuildSql) of
                [GuildName, GuildLv,Flag,Badges0] ->
                    Badges = lib_guild_mod:make_badge(util:bitstring_to_term(Badges0),Now,[]);
                [] ->
                    GuildName = <<>>, GuildLv = 0,Flag=0,Badges = []
            end,
            % 第一职位
            case db_position_name_select_by_position(GuildId, Position) of
                [] ->
                    case data_guild:get_guild_pos(Position) of
                        [] -> UnkPositionName = "";
                        #base_guild_pos{name = UnkPositionName} -> ok
                    end;
                [UnkPositionName] ->
                    ok
            end,
            PositionName = util:make_sure_binary(UnkPositionName);
        [] ->
            GuildId = 0, Position = 0, CreateTime = 0,Badges=[],
            PositionName = <<>>, GuildName = <<>>, GuildLv = 0,Flag=0
    end,
    %%上次离开公会时间
    case db:get_row(io_lib:format(?sql_guild_select_player_guild, [RoleId])) of
        [LeaveTime, RedPacket,GoldRedPacket,_SupportId,_IsSupportAsker,GuildReputation] ->
            skip;
        _ ->
            Sql = io_lib:format(?sql_insert_null_player_guild,[RoleId]),
            db:execute(Sql),
            LeaveTime = 0,
            RedPacket = 0,
            GoldRedPacket = 0,
            GuildReputation = 0
    end,
    Orders = lib_guild_order_mod:load_guild_orders(RoleId),
    count_guild_attr(#status_guild{
            id = GuildId
            , flag = Flag
            , name = GuildName
            , lv = GuildLv
            , position = Position
            , position_name = PositionName
            , create_time = CreateTime
            , leave_time = LeaveTime
            , red_packet = RedPacket
            , red_gold_packet = GoldRedPacket
            , support_id = 0
            , is_support_asker = 0
            , guild_reputation = GuildReputation
            , badges = Badges
            , orders = Orders
        }).

%%计算公会属性 (目前只有公会技能)
count_guild_attr(StatusGuild)->
    % #status_guild{skill_list=SkillList, building_lv_map = BuildLvMap} = StatusGuild,
    % SkillBuildLv = maps:get(?BUILDING_TYPE_SKILL, BuildLvMap, 0),
    % Ratio = data_guild:get_skill_lv_ratio(SkillBuildLv),
    % SkillAttr = count_guild_skill_attr(SkillList, Ratio, []),
    % StatusGuild#status_guild{attr=SkillAttr}.
    StatusGuild.

%%计算公会技能属性
% count_guild_skill_attr([], 0, AttrList) -> AttrList;
% count_guild_skill_attr([], Ratio, AttrList) ->
%     lib_player_attr:set_attr_by_ratio(AttrList, (Ratio + 100) * 100);
% count_guild_skill_attr([{SkillId,SkillLv}|T], Ratio, AttrList) ->
%     case data_guild:get_skill(SkillId,SkillLv) of
%         #base_skill{attr=Attr} ->
%             NewAttrList = lib_player_attr:add_attr(list,[AttrList,Attr]),
%             count_guild_skill_attr(T, Ratio, NewAttrList);
%         _ -> count_guild_skill_attr(T, Ratio, AttrList)
%     end.

%% 创建公会
create_guild(Player, CfgId, GuildName, Flag) ->
    case check_create_guild(Player, CfgId, GuildName, Flag) of
        {false, ErrorCode} ->
            NewPlayer2 = Player;
        {true, Cost} ->
            case lib_goods_api:cost_objects_with_auto_buy(Player, Cost, create_guild, "") of
                {false, ErrorCode, _} ->
                    NewPlayer2 = Player;
                {true, NewPlayer, _} ->
                    case do_create_guild(NewPlayer, GuildName,Flag,CfgId) of
                        {false, ErrorCode} ->
                            NewPlayer2 = NewPlayer;
                        {ok, NewPlayer2} ->
                            ErrorCode = ?SUCCESS
                    end
            end
    end,
    case ErrorCode == ?SUCCESS of
        true ->
            #player_status{id=RoleID,figure = #figure{name = Name, lv = RoleLv, guild_id = GuildId, vip = Vip}} = NewPlayer2,
            lib_chat:send_TV({all}, ?MOD_GUILD, 7, [Name,RoleID,GuildName,GuildId]),
            send_info(NewPlayer2),
            {ok, BinData} = pt_400:write(40004, [ErrorCode]),
            lib_server_send:send_to_sid(Player#player_status.sid, BinData),
            %% 日志
            case data_guild:get_guild_create(CfgId) of
                #base_guild_create{cost = CreateCost,guild_lv=CreateLv} ->
                    skip;
                _ ->
                    CreateCost = [],CreateLv=0
            end,
            lib_log_api:log_guild(GuildId, GuildName, Flag, CreateLv, RoleID, RoleLv, Name, Vip, ?CREATE_GUILD, CreateCost);
        false ->
            send_error_code(Player#player_status.sid, ErrorCode)
    end,
    {ok, NewPlayer2}.

%% 检查创建公会
check_create_guild(Status, OpTy, GuildName,Flag) ->
    #player_status{guild = StatusGuild} = Status,
    #status_guild{id = GuildId} = StatusGuild,
    % 放一些基础的判断,特别是call进程的,防止一开始就call数据.fun()性能较差
    {NMin,NMax} = data_guild:get(guild_name_len),
    %% 前5创建的社团半价
    %% (理论上会存在同时两个玩家创建社团获取到相同数据，因为获取之后数值之后
    %% 还要组织数据再同步创建社团；但这种情况比较小，暂时先不考虑)
    GuildNum = lib_guild_mod:get_history_guild_num(),
    {DiscountNum, Discount} = data_guild:get(create_guild_discount),
    IsDiscount  = GuildNum < DiscountNum,
    CheckList = [
        % 校验字符串
        {fun() -> GuildName =/= "" end, ?ERRCODE(err400_guild_name_null)},
        {fun() -> util:check_length(GuildName, NMin, NMax) == true end, ?ERRCODE(err400_guild_name_len)},
        {fun() -> lib_word:check_keyword(GuildName) == false end, ?ERRCODE(err400_guild_name_sensitive)},
        % 是否没有拥有公会
        {fun() -> GuildId == 0 end, ?ERRCODE(err400_on_guild_not_to_create)},
        %旗帜校验
        {fun()-> check_flag(Flag) end,?ERRCODE(err400_guild_flag_used)},
        % 是否有足够的消耗
        fun() ->
                Result = case data_guild:get_guild_create(OpTy) of
                    #base_guild_create{cost = TCost} ->
                        TCost1 =
                        case TCost of
                            [{_, _, _}|_] when IsDiscount == true ->
                                [{TGoodsType, TGoodsId, round(TNum * Discount)}||{TGoodsType, TGoodsId, TNum}<-TCost];
                            _ -> TCost
                        end,
                        lib_goods_api:check_object_list(Status, TCost1);
                    _ -> {false, ?ERRCODE(err400_create_guild_cfg)}
                end,
                Result
        end,
        % 判断条件
        fun() ->
                Result = case data_guild:get_guild_create(OpTy) of
                    #base_guild_create{condition = []} -> true;
                    #base_guild_create{condition = Condition} ->
                        Fun = fun(Con) -> check_create_condition(Status, Con) == true end,
                        case lists:any(Fun, Condition) of
                            true -> true;
                            false -> {false, ?ERRCODE(err400_condition_not_enough)}
                        end;
                    _ -> {false, ?ERRCODE(err400_create_guild_cfg)}
                end,
                Result
        end,
        % 活动中
        fun() -> lib_mutex_check:check_create_guild(Status) end,
        % 是否没有同名
        {fun() ->
                    NewGuildName = string:to_upper(util:make_sure_list(GuildName)),
                    GuildUpperMap = mod_guild:search_guild_by_name_upper(NewGuildName),
                    is_map(GuildUpperMap) andalso GuildUpperMap == #{}
            end, ?ERRCODE(err400_guild_name_same_not_to_create)}
        % % 是否重复旗帜
        % {fun() ->
        %     IsUsed = mod_guild:search_guild_flag(Flag),
        %     IsUsed == true end, ?ERRCODE(err400_guild_flag_used)}
    ],
    case util:check_list(CheckList) of
        {false, ErrorCode} -> {false, ErrorCode};
        true ->
            case data_guild:get_guild_create(OpTy) of
                #base_guild_create{cost = Cost} ->
                    Cost1 =
                    case Cost of
                        [{_, _, _}|_] when IsDiscount == true ->
                            [{GoodsType, GoodsId, round(Num * Discount)}||{GoodsType, GoodsId, Num}<-Cost];
                        _ -> Cost
                    end,
                    {true, Cost1};
                _ -> {false, ?ERRCODE(err400_create_guild_cfg)}
            end
    end.

check_create_condition(Player, {vip, NeedVip}) ->
    #player_status{figure = #figure{vip = RoleVip}} = Player,
    case RoleVip >= NeedVip of
        true -> true;
        false -> {false, ?ERRCODE(err450_vip_limit)}
    end;
check_create_condition(Player, {lv, NeedLv}) ->
    #player_status{figure = #figure{lv = Lv}} = Player,
    case Lv >= NeedLv of
        true -> true;
        false -> {false, ?ERRCODE(err400_not_enough_lv_to_create_guild)}
    end;
check_create_condition(_Player, _) ->
    {false, ?ERRCODE(err400_create_guild_cfg)}.

%% 创建公会
do_create_guild(Player, GuildName,Flag,CfgId) ->
    #player_status{
        id = RoleId, figure = Figure, hightest_combat_power = HCombatPower, combat_power = CombatPower, last_login_time = LastLoginTime,
        last_logout_time = LastLogoutTime, guild = GuildStatus} = Player,
    #figure{name = Name} = Figure,
    % 默认等级
    % GuildLv = data_guild_m:get_config(guild_default_lv),
    GuildLv = case data_guild:get_guild_create(CfgId) of
        #base_guild_create{guild_lv = Lv} -> Lv;
        _ -> 1
    end,
    Time = utime:unixtime(),
    GuildNameBin = util:make_sure_binary(GuildName),
    Announce = data_guild:get(default_announce),
    WeekStart = utime:logic_week_start(),
    Guild = #guild{
        name = GuildNameBin
        , name_upper = string:to_upper(util:make_sure_list(GuildName))
        , announce = util:make_sure_binary(Announce)
        , lv = GuildLv
        , flag = Flag
        , chief_id = RoleId
        , chief_name = Name
        , member_num = 0
        , create_time = Time
        , disband_warnning_time = 0
        , week_labor_refresh = WeekStart
        , approve_type = ?APPROVE_TYPE_AUTO
        , last_renew   = WeekStart+86400*7
    },
    Position = ?POS_CHIEF,
    GuildMember = #guild_member{
        id = RoleId
        , figure = Figure
        , guild_name = GuildNameBin
        , position = Position
        , online_flag = 1
        , last_login_time = LastLoginTime
        , last_logout_time = ?IF(LastLogoutTime == 0, LastLoginTime, LastLogoutTime)
        , combat_power = CombatPower
        , h_combat_power = max(HCombatPower, CombatPower)
        , create_time = Time
    },
    case mod_guild:create_guild(Guild, GuildMember) of
        {false, ErrorCode} -> {false, ErrorCode};
        {ok, NewGuild} ->
            % lib_mail_api:send_sys_mail([RoleId], ?MOD_GUILD, utext:get(173), utext:get(174), []),
            {ok, Player1} = lib_player_event:dispatch(Player, ?EVENT_CREATE_GUILD),
            #guild{id = GuildId} = NewGuild,
            NewGuildStatus = GuildStatus#status_guild{
                id = GuildId, name = GuildNameBin, lv = GuildLv, position = Position, flag = Flag
            },
            NewFigure = Figure#figure{
                guild_id = GuildId,
                guild_name = GuildNameBin,
                position = Position},
            NewPlayer = Player1#player_status{guild = NewGuildStatus, figure = NewFigure},
            lib_mail_api:send_sys_mail([RoleId], ?MOD_GUILD, utext:get(4000006), utext:get(4000007, [GuildLv,GuildNameBin]), []),
            {ok, NewPlayer}
    end.

check_rename_guild_pass(#player_status{sid = Sid, guild = #status_guild{id = GuildId}} = Player, Cost, GuildId, OpTy, GuildName, Flag) ->
    IsCanRename = lib_mutex_check:check_rename(Player),
    if
        IsCanRename =/= true ->
            {_, ErrCode} = IsCanRename,
            send_error_code(Sid, ErrCode);
        Cost =:= [] ->
            mod_guild:rename_guild(GuildId, Player#player_status.id, [GuildName,Flag, Cost]),
            {ok, Player};
        true ->
            case lib_goods_api:cost_object_list_with_check(Player, Cost, guild_rename, GuildName) of
                {true, CostPlayer,_} ->
                    mod_guild:rename_guild(GuildId, Player#player_status.id, [OpTy,GuildName,Flag,Cost]),
                    {ok, CostPlayer};
                {false, ErrorCode, _} ->
                    send_error_code(Player#player_status.sid, ErrorCode)
            end
    end;

check_rename_guild_pass(_PS, _Cost, _GuildId, _OpTy, _GuildName,_Flag) -> skip.

update_guild_name(Player, GuildId, Flag, GuildName) ->
    case Player#player_status.guild of
        #status_guild{id = GuildId, position = Position, position_name = PositionName} = StatusGuild ->
            Figure = Player#player_status.figure,
            mod_scene_agent:update(Player, [{guild, {GuildId, GuildName, Position, PositionName}}]),
            % 同步场景
            {ok, BinData} = pt_400:write(40017, [Player#player_status.id, GuildId, GuildName, Position, PositionName]),
            lib_server_send:send_to_area_scene(Player#player_status.scene, Player#player_status.scene_pool_id,
                Player#player_status.copy_id, Player#player_status.x, Player#player_status.y, BinData),
            lib_role:update_role_show(Player#player_status.id, [{guild_name, GuildName}]),
            mod_chat_agent:update(Player#player_status.id, [{guild_name, GuildName}]),
            {ok, Player#player_status{guild = StatusGuild#status_guild{name = GuildName,flag=Flag}, figure = Figure#figure{guild_name = GuildName,flag=Flag}}};
        _ ->
            skip
    end.

%%徽章更新
update_guild_badge(Status, GuildId, Badges) ->
    case Status#player_status.guild of
        #status_guild{id = GuildId} = StatusGuild ->
            NStatus0 = Status#player_status{guild = StatusGuild#status_guild{badges=Badges}},
            NStatus  = lib_guild_badge:update_status_guild(Status,NStatus0),
            mod_scene_agent:update(NStatus,[{badge,Badges}]),
            {ok, NStatus};
        _ ->
            ok
    end.

rename_guild_fail(Player, Cost, ErrorCode) ->
    % Msg
    % = case data_errorcode_msg:get(ErrorCode) of
    %     #errorcode_msg{about = About} ->
    %         About;
    %     _ ->
    %         util:term_to_string(ErrorCode)
    % end,
    if
        Cost =:= [] ->
            NewPlayer = Player;
        true ->
            ?ERR("rename_guild_fail ~p, ~p~n",[Player#player_status.id, Cost]),
            NewPlayer = Player
            % Produce = #produce{type = guild_rename_fail, reward = Cost, remark= Msg},
            % NewPlayer = lib_goods_api:send_reward(Player, Produce)
    end,
    send_error_code(Player#player_status.sid, ErrorCode),
    {ok, NewPlayer}.

%% 发送公会信息
send_info(Player) ->
    #player_status{sid = Sid, guild = Guild} = Player,
    #status_guild{
        id = GuildId, name = GuildName, lv = GuildLv, position = Position, position_name = PositionName
    } = Guild,
    {ok, BinData} = pt_400:write(40015, [GuildId, GuildName, GuildLv, Position, PositionName]),
    lib_server_send:send_to_sid(Sid, BinData),
    ok.

%% 更新和发送公会信息
update_and_send_guild_info(Player, AttrList) ->
    {ok, NewPlayer} = update_status_guild(Player, AttrList),
    {ok, NewPlayer2} = update_other_by_status_guild_change(NewPlayer, AttrList),
    NewPlayer3 = lib_guild_badge:update_status_guild(Player,NewPlayer2),
    send_to_area_scene(Player, NewPlayer3),
    send_info(NewPlayer3),
    {ok, NewPlayer3}.

send_to_area_scene(OldPlayer, Player) ->
    #player_status{
        guild = #status_guild{
            id = OldGuildId
            , name = OldGuildName
            , position = OldPosition
            , position_name = OldPositionName
        }
    } = OldPlayer,
    #player_status{
        guild = #status_guild{
            id = GuildId
            , name = GuildName
            , position = Position
            , position_name = PositionName}
    } = Player,
    Old = [OldGuildId, OldGuildName, OldPosition, OldPositionName],
    New = [GuildId, GuildName, Position, PositionName],
    case Old =/= New of
        true ->
            mod_scene_agent:update(Player, [{guild, {GuildId, GuildName, Position, PositionName}}]),
            % 同步场景
            {ok, BinData} = pt_400:write(40017, [Player#player_status.id, GuildId, GuildName, Position, PositionName]),
            lib_server_send:send_to_area_scene(Player#player_status.scene, Player#player_status.scene_pool_id,
                Player#player_status.copy_id, Player#player_status.x, Player#player_status.y, BinData);
        false ->
            skip
    end.

%% 零点刷新玩家商店购买记录和红包金额
daily_clear(?TWELVE) -> ok;
daily_clear(?FOUR)->
    db:execute(<<"TRUNCATE TABLE guild_order">>),
    OnlineList = ets:tab2list(?ETS_ONLINE),
    spawn(fun()-> daily_clear(OnlineList) end);
daily_clear(OnlineList)when is_list(OnlineList) ->
    Sql = io_lib:format(?sql_guild_update_all_midnight, [0,0]),
    db:execute(Sql),
    KeyValList = [{red_packet,0}, {red_gold_packet,0}],
    [lib_player:apply_cast(PlayerId, ?APPLY_CAST_STATUS, ?MODULE, update_status_guild, [KeyValList])||#ets_online{id = PlayerId}<-OnlineList];
daily_clear(_) -> ok.

%% ----------------------------------------------------
%% 函数
%% ----------------------------------------------------

update_status_guild(Player, []) -> {ok, Player};
update_status_guild(Player, [T|L]) ->
    #player_status{guild = StatusGuild} = Player,
    case T of
        {guild_id, GuildId} -> NewStatusGuild = StatusGuild#status_guild{id = GuildId};
        {guild_name, GuildName} -> NewStatusGuild = StatusGuild#status_guild{name = GuildName};
        {guild_lv, GuildLv} -> NewStatusGuild = StatusGuild#status_guild{lv = GuildLv};
        {position, Position} -> NewStatusGuild = StatusGuild#status_guild{position = Position};
        {position_name, PositionName} -> NewStatusGuild = StatusGuild#status_guild{position_name = PositionName};
        {create_time, CreateTime} -> NewStatusGuild = StatusGuild#status_guild{create_time = CreateTime};
        {leave_time, LeaveTime} -> NewStatusGuild = StatusGuild#status_guild{leave_time = LeaveTime};
        {red_packet, Num} -> NewStatusGuild = StatusGuild#status_guild{red_packet = Num};
        {red_gold_packet, Num} -> NewStatusGuild = StatusGuild#status_guild{red_gold_packet = Num};
        {badge,Badges} -> NewStatusGuild = StatusGuild#status_guild{badges=Badges};
        {flag,Flag} -> NewStatusGuild = StatusGuild#status_guild{flag=Flag};
        _ ->
            NewStatusGuild = StatusGuild
    end,
    NewPlayer = Player#player_status{guild = NewStatusGuild},
    update_status_guild(NewPlayer, L).

%% 根据StatusGuild来更新玩家其他数据
update_other_by_status_guild_change(Player, []) -> {ok, Player};
update_other_by_status_guild_change(Player, [T|L]) ->
    #player_status{figure = Figure} = Player,
    case T of
        {guild_id, GuildId} ->
            NewPlayer = Player#player_status{ figure = Figure#figure{guild_id = GuildId} };
        {guild_name, GuildName} ->
            NewPlayer = Player#player_status{ figure = Figure#figure{guild_name = GuildName} };
        {position, Position} ->
            NewPlayer = Player#player_status{ figure = Figure#figure{position = Position} };
        {position_name, PositionName} ->
            NewPlayer = Player#player_status{ figure = Figure#figure{position_name = PositionName} };
        {flag, Flag} ->
            NewPlayer = Player#player_status{ figure = Figure#figure{flag = Flag} };
        _ ->
            % ?ERR("ignore attr:~p~n", [T]),
            NewPlayer  = Player
    end,
    update_other_by_status_guild_change(NewPlayer, L).

%% 发送公会职位权限列表给玩家
%% 需在公会进程调用
send_permission_list_to_role(RoleId, GuildId, Position) ->
    PermissionList = lib_guild_mod:get_position_permission_list(GuildId, Position),
    {ok, BinData} = pt_400:write(40021, [PermissionList]),
    lib_server_send:send_to_uid(RoleId, BinData).
%% 发送错误码
send_error_code(Sid, ErrorCode) ->
    {ok, BinData} = pt_400:write(40000, [ErrorCode]),
    lib_server_send:send_to_sid(Sid, BinData).

%% 是否公会场景
is_guild_scene(Scene) ->
    case data_scene:get(Scene) of
        #ets_scene{type = ?SCENE_TYPE_GUILD} -> true;
        _ -> false
    end.

%% 构造RoleMap
% 玩家在线
make_role_map(Player) when is_record(Player, player_status) ->
    #player_status{figure = Figure, hightest_combat_power = HCombatPower, combat_power = CombatPower, last_login_time = LastLoginTime, last_logout_time = LastLogoutTime} = Player,
    NewLastLogoutTime = ?IF(LastLogoutTime == 0, LastLoginTime, LastLogoutTime),
    #{figure=>Figure, combat_power=>CombatPower, hcombat_power=>HCombatPower, last_login_time=>LastLoginTime, online_flag=>?ONLINE_ON, last_logout_time=>NewLastLogoutTime};
make_role_map(RoleShow) ->
    #ets_role_show{figure = Figure, h_combat_power = HCombatPower, combat_power = CombatPower, online_flag = OnlineFlag, last_login_time = LastLoginTime, last_logout_time = LastLogoutTime} = RoleShow,
    LastCombatPower = ?IF(CombatPower > 0, CombatPower, HCombatPower),
    NewLastLogoutTime = ?IF(OnlineFlag == ?ONLINE_ON andalso LastLogoutTime ==0, LastLoginTime, LastLogoutTime),
    #{figure=>Figure, combat_power=>LastCombatPower, hcombat_power=>HCombatPower, last_login_time=>LastLoginTime, online_flag=>OnlineFlag, last_logout_time=>NewLastLogoutTime}.

%% ----------------------------------------------------
%% 数据库操作
%% ----------------------------------------------------

db_position_name_select_by_position(GuildId, Position) ->
    Sql = io_lib:format(?sql_position_name_select_by_position, [GuildId, Position]),
    db:get_row(Sql).

%% ----------------------------------------------------
%% gm操作
%% ----------------------------------------------------
gm_update_guild_time(RoleId, Time) ->
    GuildMember = lib_guild_data:get_guild_member_by_role_id(RoleId),
    case is_record(GuildMember, guild_member) of
        true ->
            NewGuildMember = GuildMember#guild_member{create_time = Time},
            Sql = io_lib:format(<<"update guild_member set create_time = ~p where id = ~p">>, [Time, RoleId]),
            db:execute(Sql),
            lib_guild_data:update_guild_member(NewGuildMember),
            lib_player:apply_cast(RoleId, ?APPLY_CAST_STATUS, ?MODULE, gm_update_ps_guild_time, [Time]),
            ok;
        false -> ok
    end.

gm_update_ps_guild_time(PS, Time) ->
    #player_status{guild = StatusGuild} = PS,
    NewStatusGuild = StatusGuild#status_guild{create_time = Time},
    PS#player_status{guild = NewStatusGuild}.


check_flag(Flag)->
    Style = Flag div 10000,
    Color = Flag rem 10000,
    case 0<Style andalso Style=<12 of
        true->
            0<Color andalso Color=<8;
        _->
            false
    end.

