JSGCardDataBase.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using CommonAI.data;
  2. using CommonAI.Data;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using XmdsCommonSkill.Plugin.CardSkill;
  9. namespace XmdsCommonServer.Plugin.Base
  10. {
  11. public abstract class JSGCardDataBase : ICardData
  12. {
  13. public static readonly byte TRIGGER_NUM = 4;
  14. protected int mCards = 0;
  15. protected CardType[] mCardData = new CardType[(int)CardType.Max];
  16. public virtual void RefreshCardInfo(XmdsVirtual unit) { }
  17. public virtual void RefreshCardInfo(XmdsVirtual unit, byte[] cardData) { }
  18. public virtual void SendTriggerInfo(XmdsVirtual player, CardTriggerResult result, int skillId, byte[] cardData) { }
  19. public int GetCardNums()
  20. {
  21. return this.mCards;
  22. }
  23. public void ReSet(XmdsVirtual unit)
  24. {
  25. this.mCards = 0;
  26. for (int i = 0; i < (int)CardType.Max; i++)
  27. {
  28. mCardData[i] = CardType.Max;
  29. }
  30. if (unit != null)
  31. {
  32. this.RefreshCardInfo(unit);
  33. }
  34. }
  35. public CardTriggerResult AddCard(XmdsVirtual unit, GenCardData cardData)
  36. {
  37. if (mCards + cardData.nums >= TRIGGER_NUM)
  38. {
  39. CardTriggerResult result = new CardTriggerResult();
  40. byte[] cardNum = new byte[(int)CardType.Max];
  41. for (int i = 0; i < mCards; i++)
  42. {
  43. cardNum[(int)mCardData[i]]++;
  44. result.cardData[i] = (byte)mCardData[i];
  45. }
  46. cardNum[(int)cardData.type] = (byte)(cardNum[(int)cardData.type] + (TRIGGER_NUM - mCards));
  47. //1. 触发结果
  48. byte sameMax = 0, sameIndex = 0;
  49. for (byte i = 0; i < (byte)CardType.Max; i++)
  50. {
  51. if (cardNum[i] > sameMax)
  52. {
  53. sameMax = cardNum[i];
  54. sameIndex = i;
  55. }
  56. }
  57. //2. 保存触发记录
  58. for(int i = mCards; i < TRIGGER_NUM; i++)
  59. {
  60. result.cardData[i] = (byte)cardData.type;
  61. }
  62. //填充剩余卡牌
  63. mCards = Math.Min(TRIGGER_NUM - 1, mCards + cardData.nums - TRIGGER_NUM);
  64. for (int i = 0; i < mCards; i++)
  65. {
  66. mCardData[i] = cardData.type;
  67. }
  68. result.type = sameMax <= 1 ? CardType.Max : (CardType)(sameIndex);
  69. result.sameNums = cardNum[sameIndex];
  70. //刷一次之前的球信息
  71. this.RefreshCardInfo(unit, result.cardData);
  72. //刷当前的数据
  73. this.RefreshCardInfo(unit);
  74. return result;
  75. }
  76. else
  77. {
  78. for (int i = mCards; i < mCards + cardData.nums; i++)
  79. {
  80. mCardData[i] = cardData.type;
  81. }
  82. mCards = mCards + cardData.nums;
  83. this.RefreshCardInfo(unit);
  84. return null;
  85. }
  86. }
  87. public CardType GetCardData(int index)
  88. {
  89. if(index < 0 || index >= mCards)
  90. {
  91. return CardType.Max;
  92. }
  93. return this.mCardData[index];
  94. }
  95. }
  96. }