/********************************
 *
 * 作者:吴隆健
 * 创建时间: 2019/7/3 14:08:57
 *
 ********************************/

using System;
using System.Text;
using Server.Core;

namespace GameData
{
    /// <summary>
    /// 
    /// </summary>
    public class PlayerDataChange : Reference
    {
        /// <summary>
        /// 玩家的userid;
        /// </summary>
        public int userid;

        /// <summary>
        /// 游戏币变化值
        /// </summary>
        public long moneyChange;

        /// <summary>
        /// 经验变化值
        /// </summary>
        public int expChange;

        /// <summary>
        /// 金币变化值
        /// </summary>
        public int goldChange;

        /// <summary>
        /// 房卡变化值
        /// </summary>
        public int fangkaChange;

        /// <summary>
        /// 奖券变化值
        /// </summary>
        public int couponChange;

        /// <summary>
        /// 比赛卷变化 ,用于新的大厅界面的充值钻石（钻石）
        /// </summary>
        public int MatchRollChange;

        /// <summary>
        /// 钱备份
        /// </summary>
        public long MoneyBak;

        /// <summary>
        /// 是否已更改
        /// </summary>
        public bool IsChanged => MatchRollChange != 0 || expChange != 0 ||
                                 moneyChange != 0 || goldChange != 0 ||
                                 fangkaChange != 0 || couponChange != 0;
        
        /// <summary>
        /// 获取相反值
        /// </summary>
        /// <returns></returns>
        public PlayerDataChange GetOppositeValue(bool fromPool)
        {
            PlayerDataChange pdc = null;
            if (fromPool)
            {
                pdc = PlayerDataChange.Create(this.userid);
            }
            else
            {
                pdc = new PlayerDataChange();
                pdc.userid = this.userid;
            }

            pdc.userid = this.userid;
            pdc.expChange = -this.expChange;
            pdc.moneyChange = -this.moneyChange;
            pdc.goldChange = -this.goldChange;
            pdc.fangkaChange = -this.fangkaChange;
            pdc.couponChange = -this.couponChange;
            pdc.MatchRollChange = -this.MatchRollChange;
            return pdc;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("userid:" + userid);
            sb.AppendLine("moneyChange:" + moneyChange);
            sb.AppendLine("MoneyBak:" + MoneyBak);
            sb.AppendLine("goldChange:" + goldChange);
            sb.AppendLine("fangkaChange:" + fangkaChange);
            sb.AppendLine("couponChange:" + couponChange);
            sb.AppendLine("MatchRollChange:" + MatchRollChange);
            return sb.ToString();
        }

        /// <summary>
        /// 
        /// </summary>
        public PlayerDataChange()
        {
        }

        public static PlayerDataChange Create(int userid)
        {
            PlayerDataChange self = ReferencePool.Fetch<PlayerDataChange>();
            self.userid = userid;
            self.moneyChange = 0;
            self.expChange = 0;
            self.goldChange = 0;
            self.fangkaChange = 0;
            self.couponChange = 0;
            self.MatchRollChange = 0;
            self.MoneyBak = 0;
            return self;
        }

        public override void Dispose()
        {
            ReferencePool.Recycle(this);
        }
    }
}