123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using CommonAI.data;
- using CommonAI.Zone;
- using CommonAI.Zone.Instance;
- using CommonLang.Log;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XmdsCommonServer.XLS.Data;
- namespace XmdsCommonSkill.Plugin.Skills
- {
- public abstract class PlayerCacheBase : IPlayerCache
- {
- protected static Logger log = LoggerFactory.GetDefLogger();
- public static readonly int UPDATE_INTERVAL = 1000;
- private bool mIsValid = true; // 是否有效
- protected int mTalentValue; // 天赋怒气,剑气
- protected long mTalnetUpdateTime; // 天赋最后更新时间
- protected long mReduceTalnetTime; // 最后一次脱战时间
- protected IntIntIntData mRefreshRule; // 刷新规则,脱战valu1毫秒后,每隔value2毫秒,减少value3:
- protected InstanceUnit mOwner;
- public PlayerCacheBase(InstanceUnit unit, IntIntIntData refreshRule)
- {
- this.mRefreshRule = refreshRule;
- //this.ReInit(unit);
- }
- public virtual void ReInit(InstanceUnit unit)
- {
- this.MarkValid(true);
- this.mOwner = unit;
- this.mTalnetUpdateTime = 0;
- this.Refresh(false);
- this.NotifyPlayer();
- }
- // 获得天赋值
- public virtual bool AddTalentValue(int value)
- {
- //System.Console.WriteLine("++获得天赋值了:" + value + ", 总值:" + this.mTalentValue);
- this.NotifyPlayer();
- return true;
- }
- // 使用天赋(怒气/剑气)
- public virtual bool UseTalentValue(int value)
- {
- //System.Console.WriteLine("--消耗天赋值了:" + value + ", 总值:" + this.mTalentValue);
- this.NotifyPlayer();
- return true;
- }
- //天赋信息有变更,返回true
- public virtual bool Refresh(bool notify = true)
- {
- //有天赋值才处理刷新
- if (mTalentValue <= 0 || !this.IsValid())
- {
- return false;
- }
- if(this.mOwner.Virtual.GetBattleStatus() > CommonAI.Data.BattleStatus.ReadyBattle)
- {
- this.mReduceTalnetTime = 0;
- this.mTalnetUpdateTime = 0;
- return false;
- }
- else if(this.mReduceTalnetTime == 0)
- {
- this.mReduceTalnetTime = CommonLang.CUtils.localTimeMS + mRefreshRule.value1;
- }
- // 脱战时间不够,不降低怒气
- if(CommonLang.CUtils.localTimeMS < this.mReduceTalnetTime)
- {
- return false;
- }
- else if(this.mTalnetUpdateTime == 0)
- {
- this.mTalnetUpdateTime = CommonLang.CUtils.S_LOCAL_TIMESTAMPMS;
- //System.Console.WriteLine("怒气开始降低了1:" + CommonLang.TimeUtil.GetTimestampMS());
- }
- int passTimes = (int)((CommonLang.CUtils.S_LOCAL_TIMESTAMPMS - this.mTalnetUpdateTime) / this.mRefreshRule.value2);
- if (passTimes > 0)
- {
- //System.Console.WriteLine("怒气开始降低了2:" + CommonLang.TimeUtil.GetTimestampMS() + ", " + passTimes);
- //System.Console.WriteLine("怒气开始降低了3:" + this.mTalentValue + " -> " + Math.Max(0, this.mTalentValue - passTimes * this.mRefreshRule.value3));
- this.mTalentValue = Math.Max(0, this.mTalentValue - passTimes * this.mRefreshRule.value3);
- this.mTalnetUpdateTime = CommonLang.CUtils.S_LOCAL_TIMESTAMPMS;
- if (notify)
- {
- this.NotifyPlayer();
- }
- //if(passTimes > 5)
- //{
- // System.Console.WriteLine("怒气开始降低了4:" + passTimes + ", 间隔: " + this.mRefreshRule.value2);
- //}
- return true;
- }
- return false;
- }
- //通知玩家信息变更
- public virtual void NotifyPlayer()
- {
- RefreshTalnetInfo refreshInfo = new RefreshTalnetInfo((short)this.GetTalentValue());
- mOwner.Virtual.SendMsgToPlayer(refreshInfo);
- }
- public virtual void MarkValid(bool isValid)
- {
- this.mIsValid = isValid;
- }
- public bool IsValid() { return this.mIsValid; }
- public int GetTalentValue() { return this.mTalentValue; }
- public virtual byte GetTalentLv() { return 0; }
- }
- public class IntIntIntData
- {
- public int value1;
- public int value2;
- public int value3;
- public IntIntIntData() { }
- public IntIntIntData(int value1, int value2, int value3)
- {
- this.value1 = value1;
- this.value2 = value2;
- this.value3 = value3;
- }
- }
- }
|