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;
- protected InstanceUnit mOwner;
- public PlayerCacheBase(InstanceUnit unit, IntIntIntData refreshRule)
- {
- this.mRefreshRule = refreshRule;
-
- }
- 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)
- {
-
- this.NotifyPlayer();
- return true;
- }
-
- public virtual bool UseTalentValue(int value)
- {
-
- this.NotifyPlayer();
- return 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;
-
- }
- int passTimes = (int)((CommonLang.CUtils.S_LOCAL_TIMESTAMPMS - this.mTalnetUpdateTime) / this.mRefreshRule.value2);
- if (passTimes > 0)
- {
-
-
- this.mTalentValue = Math.Max(0, this.mTalentValue - passTimes * this.mRefreshRule.value3);
- this.mTalnetUpdateTime = CommonLang.CUtils.S_LOCAL_TIMESTAMPMS;
- if (notify)
- {
- this.NotifyPlayer();
- }
-
-
-
-
- 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;
- }
- }
- }
|