PlayerCacheBase.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 void AddTalentValue(int value)
  38. {
  39. //System.Console.WriteLine("++获得天赋值了:" + value + ", 总值:" + this.mTalentValue);
  40. this.NotifyPlayer();
  41. }
  42. // 使用天赋(怒气/剑气)
  43. public virtual void UseTalentValue(int value)
  44. {
  45. //System.Console.WriteLine("--消耗天赋值了:" + value + ", 总值:" + this.mTalentValue);
  46. this.NotifyPlayer();
  47. }
  48. //天赋信息有变更,返回true
  49. public virtual bool Refresh(bool notify = true)
  50. {
  51. //有天赋值才处理刷新
  52. if (mTalentValue <= 0 || !this.IsValid())
  53. {
  54. return false;
  55. }
  56. if(this.mOwner.Virtual.GetBattleStatus() > CommonAI.Data.BattleStatus.ReadyBattle)
  57. {
  58. this.mReduceTalnetTime = 0;
  59. this.mTalnetUpdateTime = 0;
  60. return false;
  61. }
  62. else if(this.mReduceTalnetTime == 0)
  63. {
  64. this.mReduceTalnetTime = CommonLang.CUtils.localTimeMS + mRefreshRule.value1;
  65. }
  66. // 脱战时间不够,不降低怒气
  67. if(CommonLang.CUtils.localTimeMS < this.mReduceTalnetTime)
  68. {
  69. return false;
  70. }
  71. else if(this.mTalnetUpdateTime == 0)
  72. {
  73. this.mTalnetUpdateTime = CommonLang.CUtils.S_LOCAL_TIMESTAMPMS;
  74. //System.Console.WriteLine("怒气开始降低了1:" + CommonLang.TimeUtil.GetTimestampMS());
  75. }
  76. int passTimes = (int)((CommonLang.CUtils.S_LOCAL_TIMESTAMPMS - this.mTalnetUpdateTime) / this.mRefreshRule.value2);
  77. if (passTimes > 0)
  78. {
  79. //System.Console.WriteLine("怒气开始降低了2:" + CommonLang.TimeUtil.GetTimestampMS() + ", " + passTimes);
  80. //System.Console.WriteLine("怒气开始降低了3:" + this.mTalentValue + " -> " + Math.Max(0, this.mTalentValue - passTimes * this.mRefreshRule.value3));
  81. this.mTalentValue = Math.Max(0, this.mTalentValue - passTimes * this.mRefreshRule.value3);
  82. this.mTalnetUpdateTime = CommonLang.CUtils.S_LOCAL_TIMESTAMPMS;
  83. if (notify)
  84. {
  85. this.NotifyPlayer();
  86. }
  87. if(passTimes > 5)
  88. {
  89. System.Console.WriteLine("怒气开始降低了4:" + passTimes + ", 间隔: " + this.mRefreshRule.value2);
  90. }
  91. return true;
  92. }
  93. return false;
  94. }
  95. //通知玩家信息变更
  96. public virtual void NotifyPlayer()
  97. {
  98. RefreshTalnetInfo refreshInfo = new RefreshTalnetInfo((short)this.GetTalentValue());
  99. mOwner.Virtual.SendMsgToPlayer(refreshInfo);
  100. }
  101. public virtual void MarkValid(bool isValid)
  102. {
  103. this.mIsValid = isValid;
  104. }
  105. public bool IsValid() { return this.mIsValid; }
  106. public int GetTalentValue() { return this.mTalentValue; }
  107. public virtual byte GetTalentLv() { return 0; }
  108. }
  109. public class IntIntIntData
  110. {
  111. public int value1;
  112. public int value2;
  113. public int value3;
  114. public IntIntIntData() { }
  115. public IntIntIntData(int value1, int value2, int value3)
  116. {
  117. this.value1 = value1;
  118. this.value2 = value2;
  119. this.value3 = value3;
  120. }
  121. }
  122. }