%%%--------------------------------------
%%% @Module  : lib_flower
%%% @Author  : zengzy
%%% @Created : 2017-06-30
%%% @Description:  花语和鲜花
%%%--------------------------------------
-module(lib_flower_api).

-include("server.hrl").
-include("flower.hrl").

-export([
    add_fame/2
    ,add_charm/2
    ]).

%%增加名誉
add_fame(Player, Num) ->
    #player_status{id = RoleId, flower = RoleFlowerData} = Player,
    #flower{fame = Fame} = RoleFlowerData,
    NewFame = Fame + Num,
    db:execute(io_lib:format(?sql_update_fame, [NewFame, RoleId])),
    Player#player_status{flower = RoleFlowerData#flower{fame = NewFame}}.

%%增加魅力值
add_charm(Player, Num) ->
    #player_status{id = RoleId, flower = RoleFlowerData} = Player,
    #flower{flower_num = FlowerNum, charm = Charm, fame = Fame, week_charm = WeekCharm, update_time = UpdateTime} = RoleFlowerData,
    NewCharm = Charm + Num,
    {NewWeekCharm, NewUpdateTime} = lib_flower:update_week_charm(WeekCharm, utime:unixtime(), UpdateTime, Num),
    db:execute(?sql_replace_flower, [RoleId, FlowerNum, NewCharm, Fame, NewWeekCharm, NewUpdateTime]),
    Player#player_status{flower = RoleFlowerData#flower{charm = NewCharm, week_charm = NewWeekCharm, update_time = NewUpdateTime}}.