%%% -------------------------------------------------------
%%% @author ming_up@foxmail.com
%%% @since  2018-04-09
%%% @deprecated （语言/地区）版本管理配置
%%%
%%% @doc    游戏版本区分管理
%%% @author huangyongxing@yeah.net
%%% 由编译时提供宏定义CP_VER，决定编译版本
%%% 便于不同版本可以存在参数或功能上的小差异
%%% @end
%%% -------------------------------------------------------
-module(data_vsn).
-include("predefine.hrl").
-include("common.hrl").
-export([
    is_cn/0                             %% 是否简体版本
    ,is_tw/0                            %% 是否繁体版本
    ,is_en/0                            %% 是否英文版本
    ,is_kr/0                            %% 是否韩文版本
    ,is_jp/0                            %% 是否日文版本
]).
-export([
    is_chat_monitor/0                   %% 是否启动聊天监控
    ,top_pk_first_season_open_date/0    %% 巅峰竞技第一个赛季开启日期{Y,M,D}
    ,get_imgreg_url_and_key/0           %% 获取头像日志接口的URL以及KEY
]).

-export([
        get_game_vsn/0
        ,get_issuer_vsn/0

        ,get_name_width/0
        ,get_guild_name_width/0
        ,get_mate_declaration_width/0

        ,calc_recharge_recency/1
        ,calc_recharge_frequency/1
        ,calc_recharge_monetary/1
        ,calc_recharge_top/1
        ,calc_name_group/0
        ,calc_name_group/1
    ]).
-include("game_vsn.hrl").

is_cn() -> get_game_vsn() == ?VER_MAIN.   %% 简体版
is_tw() -> get_game_vsn() == ?VER_TW.   %% 繁体版
is_en() -> get_game_vsn() == ?VER_EN.   %% 英文版
is_kr() -> get_game_vsn() == ?VER_KR.   %% 韩文版
is_jp() -> get_game_vsn() == ?VER_JP.   %% 日文版

%% 是否启动聊天监控
is_chat_monitor() ->
    case ?GAME_VER of
        ?VER_MAIN -> true;
        _         -> false
    end.

%% 巅峰竞技第一个赛季开启日期{Y,M,D}
%% 注: 巅峰竞技不再强调具体是第几赛季了
%%     以下日期固定{2018, 7, 9}
top_pk_first_season_open_date() ->
    case ?GAME_VER of
        ?VER_MAIN -> {2018, 7, 9};
        _         -> {2018, 7, 9}
    end.

%% 获取头像日志接口的URL以及KEY
%% 注：礼包卡及服务端web错误日志使用本接口
%% @return {URL, KEY}
get_imgreg_url_and_key() ->
    TICKET = config:get_ticket(),
    case {TICKET == ?INTERNAL_TICKET, ?GAME_VER} of
        %% 内网环境
        {true, _} ->
            {
                "http://register-mrzj.sydevlop.cn/api/api.php?",
                "FiN7AkwMBANvERe41rX8B1E32OTwdxCa"
            };
        %% 外网环境
        _ ->
            {
                "http://admin.userpic.suyougame.com/api/api.php?",
                "FiN7AkwMBANvERe41rX8B1E32OTwdxCa"
            }
    end.

%% 获取当前版本的版本编号
%% 说明：CP_VER同时用于定义game_version和issuer_version，
%%      定义时注意两边兼容
get_game_vsn() ->
    case ?CP_VER of
        "TW"    -> ?VER_TW;
        "EN"    -> ?VER_EN;
        "KR"    -> ?VER_KR;
        "JP"    -> ?VER_JP;
        "TH"    -> ?VER_TH;
        "VN"    -> ?VER_VN;
        "ML"    -> ?VER_MAIN;
        "MAIN"  -> ?VER_MAIN;
        "TEST"  -> ?VER_TEST;
        _       -> ?VER_MAIN
    end.

%% 获取当前运营版本
get_issuer_vsn() ->
    case ?CP_VER of
        "ML"    -> ?VER_ISSUER_ML;
        _       ->
            Plat = config:get_platform(),
            case Plat of
                "kw" ->
                    %% 暂时将6kw发行的也记为漫灵版，如果其他地方有差异需求，再分离
                    ?VER_ISSUER_ML;
                _    ->
                    ?VER_ISSUER_OTHER
            end
    end.

%% 各版本角色名宽度
%% （1个汉字占2个宽度，英文字母及数字占1个宽度）
get_name_width()->
    case get_game_vsn() of
        ?VER_TH     -> {2, 32};
        ?VER_VN     -> {3, 41};
        ?VER_EN     -> {3, 16};
        ?VER_KR     -> {2, 12};
        %% 其他版本默认使用国内版本限制（1-6个汉字宽度）
        _           -> {2, 12}
    end.

%% 帮派名称长度
get_guild_name_width()->
    case get_game_vsn() of
        ?VER_TH -> 41;
        _       -> 12
    end.

%% 羁绊交友大厅宣言最大长度
get_mate_declaration_width() ->
    100.
%%%-------------------------------------------------------------------
%%% @doc 根据语言版本计算充值评级
%%%-------------------------------------------------------------------
%% 计算充值间隔评级
calc_recharge_recency(RecencyValue) ->
    calc_recharge_recency(RecencyValue, get_game_vsn()).
calc_recharge_recency(RecencyValue, _GameVer) ->
    if
        RecencyValue >= 1  andalso RecencyValue =< 3  -> 5;
        RecencyValue >= 4  andalso RecencyValue =< 7  -> 4;
        RecencyValue >= 8  andalso RecencyValue =< 14 -> 3;
        RecencyValue >= 15 andalso RecencyValue =< 21 -> 2;
        RecencyValue >= 22 andalso RecencyValue =< 29 -> 1;
        true -> 0
    end.

%% 计算充值频率评级
calc_recharge_frequency(FrequencyValue) ->
    calc_recharge_frequency(FrequencyValue, get_game_vsn()).
calc_recharge_frequency(FrequencyValue, _GameVer) ->
    if
        FrequencyValue >= 0  andalso FrequencyValue =< 3  -> 0;
        FrequencyValue >= 4  andalso FrequencyValue =< 9  -> 1;
        FrequencyValue >= 10 andalso FrequencyValue =< 15 -> 2;
        FrequencyValue >= 16 andalso FrequencyValue =< 20 -> 3;
        FrequencyValue >= 21 andalso FrequencyValue =< 29 -> 4;
        true -> 5
    end.

%% 计算历史总充值评级
calc_recharge_monetary(MonetaryValue) ->
    calc_recharge_monetary(MonetaryValue, get_game_vsn()).
calc_recharge_monetary(MonetaryValue, _GameVer) ->
    if
        MonetaryValue >= 0     andalso MonetaryValue =< 6    -> 0;
        MonetaryValue >= 7     andalso MonetaryValue =< 100  -> 1;
        MonetaryValue >= 101   andalso MonetaryValue =< 500  -> 2;
        MonetaryValue >= 501   andalso MonetaryValue =< 2000 -> 3;
        MonetaryValue >= 20001 andalso MonetaryValue =< 9999 -> 4;
        true -> 5
    end.

%% 计算最高额充值评级
calc_recharge_top(TopValue) ->
    calc_recharge_top(TopValue, get_game_vsn()).
calc_recharge_top(TopValue, _GameVer) ->
    if
        TopValue >= 0   andalso TopValue =< 6   -> 0;
        TopValue >= 7   andalso TopValue =< 30  -> 1;
        TopValue >= 31  andalso TopValue =< 128 -> 2;
        TopValue >= 129 andalso TopValue =< 198 -> 3;
        TopValue >= 199 andalso TopValue =< 328 -> 4;
        true -> 5
    end.

%% 根据版本获得姓名库组别
calc_name_group() ->
    calc_name_group(get_game_vsn()).

calc_name_group(?VER_MAIN) ->
    case urand:list_rand(data_role_name:get_all_group()) of
        Group when is_integer(Group) -> Group;
        _   -> 1
    end;
calc_name_group(_) ->
    1.
