PlayerCacheBase.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using CommonAI.data;
  2. using CommonAI.Zone;
  3. using CommonAI.Zone.Instance;
  4. using CommonLang.Log;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using XmdsCommonServer.XLS.Data;
  11. namespace XmdsCommonSkill.Plugin.Skills
  12. {
  13. public abstract class PlayerCacheBase : IPlayerCache
  14. {
  15. protected static Logger log = LoggerFactory.GetDefLogger();
  16. public static readonly int UPDATE_INTERVAL = 1000;
  17. private bool mIsValid = true; // 是否有效
  18. protected int mTalentValue; // 天赋怒气,剑气
  19. protected long mTalnetUpdateTime; // 天赋最后更新时间
  20. protected long mReduceTalnetTime; // 最后一次脱战时间
  21. protected IntIntIntData mRefreshRule; // 刷新规则,脱战valu1毫秒后,每隔value2毫秒,减少value3:
  22. protected InstanceUnit mOwner;
  23. public PlayerCacheBase(InstanceUnit unit, IntIntIntData refreshRule)
  24. {
  25. this.mRefreshRule = refreshRule;
  26. //this.ReInit(unit);
  27. }
  28. public virtual void ReInit(InstanceUnit unit)
  29. {
  30. this.MarkValid(true);
  31. this.mOwner = unit;
  32. this.mTalnetUpdateTime = 0;
  33. this.Refresh(false);
  34. this.NotifyPlayer();
  35. }
  36. // 获得天赋值
  37. public virtual bool AddTalentValue(int value)
  38. {
  39. //System.Console.WriteLine("++获得天赋值了:" + value + ", 总值:" + this.mTalentValue);
  40. this.NotifyPlayer();
  41. return true;
  42. }
  43. // 使用天赋(怒气/剑气)
  44. public virtual bool UseTalentValue(int value)
  45. {
  46. //System.Console.WriteLine("--消耗天赋值了:" + value + ", 总值:" + this.mTalentValue);
  47. this.NotifyPlayer();
  48. return true;
  49. }
  50. //天赋信息有变更,返回true
  51. public virtual bool Refresh(bool notify = true)
  52. {
  53. //有天赋值才处理刷新
  54. if (mTalentValue <= 0 || !this.IsValid())
  55. {
  56. return false;
  57. }
  58. if(this.mOwner.Virtual.GetBattleStatus() > CommonAI.Data.BattleStatus.ReadyBattle)
  59. {
  60. this.mReduceTalnetTime = 0;
  61. this.mTalnetUpdateTime = 0;
  62. return false;
  63. }
  64. else if(this.mReduceTalnetTime == 0)
  65. {
  66. this.mReduceTalnetTime = CommonLang.CUtils.localTimeMS + mRefreshRule.value1;
  67. }
  68. // 脱战时间不够,不降低怒气
  69. if(CommonLang.CUtils.localTimeMS < this.mReduceTalnetTime)
  70. {
  71. return false;
  72. }
  73. else if(this.mTalnetUpdateTime == 0)
  74. {
  75. this.mTalnetUpdateTime = CommonLang.CUtils.S_LOCAL_TIMESTAMPMS;
  76. //System.Console.WriteLine("怒气开始降低了1:" + CommonLang.TimeUtil.GetTimestampMS());
  77. }
  78. int passTimes = (int)((CommonLang.CUtils.S_LOCAL_TIMESTAMPMS - this.mTalnetUpdateTime) / this.mRefreshRule.value2);
  79. if (passTimes > 0)
  80. {
  81. //System.Console.WriteLine("怒气开始降低了2:" + CommonLang.TimeUtil.GetTimestampMS() + ", " + passTimes);
  82. //System.Console.WriteLine("怒气开始降低了3:" + this.mTalentValue + " -> " + Math.Max(0, this.mTalentValue - passTimes * this.mRefreshRule.value3));
  83. this.mTalentValue = Math.Max(0, this.mTalentValue - passTimes * this.mRefreshRule.value3);
  84. this.mTalnetUpdateTime = CommonLang.CUtils.S_LOCAL_TIMESTAMPMS;
  85. if (notify)
  86. {
  87. this.NotifyPlayer();
  88. }
  89. //if(passTimes > 5)
  90. //{
  91. // System.Console.WriteLine("怒气开始降低了4:" + passTimes + ", 间隔: " + this.mRefreshRule.value2);
  92. //}
  93. return true;
  94. }
  95. return false;
  96. }
  97. //通知玩家信息变更
  98. public virtual void NotifyPlayer()
  99. {
  100. RefreshTalnetInfo refreshInfo = new RefreshTalnetInfo((short)this.GetTalentValue());
  101. mOwner.Virtual.SendMsgToPlayer(refreshInfo);
  102. }
  103. public virtual void MarkValid(bool isValid)
  104. {
  105. this.mIsValid = isValid;
  106. }
  107. public bool IsValid() { return this.mIsValid; }
  108. public int GetTalentValue() { return this.mTalentValue; }
  109. public virtual byte GetTalentLv() { return 0; }
  110. }
  111. public class IntIntIntData
  112. {
  113. public int value1;
  114. public int value2;
  115. public int value3;
  116. public IntIntIntData() { }
  117. public IntIntIntData(int value1, int value2, int value3)
  118. {
  119. this.value1 = value1;
  120. this.value2 = value2;
  121. this.value3 = value3;
  122. }
  123. }
  124. }