CardSProxy.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Collections.Generic;
  2. using ET;
  3. using GFGGame;
  4. namespace ET
  5. {
  6. public class NoticeGetNewCard : AMHandler<M2C_GetNewCard>
  7. {
  8. protected override async ETTask Run(Session session, M2C_GetNewCard message)
  9. {
  10. CardDataManager.Add(message.CardInfo);
  11. SkillDataManager.Instance.InitServerData(message.CardInfo.CardId, message.CardInfo.KsSkill, message.CardInfo.VsSkill);
  12. await ETTask.CompletedTask;
  13. }
  14. }
  15. }
  16. namespace GFGGame
  17. {
  18. public static class CardSProxy
  19. {
  20. public static async ETTask GetCardInfos()
  21. {
  22. M2C_GetCardInfos response = null;
  23. response = (M2C_GetCardInfos)await MessageHelper.SendToServer(new C2M_GetCardInfos() { });
  24. if (response != null)
  25. {
  26. if (response.Error == ErrorCode.ERR_Success)
  27. {
  28. for (int i = 0; i < response.CardInfos.Count; i++)
  29. {
  30. CardDataManager.Add(response.CardInfos[i]);
  31. SkillDataManager.Instance.InitServerData(response.CardInfos[i].CardId, response.CardInfos[i].KsSkill, response.CardInfos[i].VsSkill);
  32. }
  33. }
  34. }
  35. }
  36. public static async ETTask<bool> UpgradeCardLvl(int cardId, List<int> itemNums)
  37. {
  38. M2C_UpgradeCardLvl response = null;
  39. response = (M2C_UpgradeCardLvl)await MessageHelper.SendToServer(new C2M_UpgradeCardLvl() { CardId = cardId, ItemNums = itemNums });
  40. if (response != null)
  41. {
  42. if (response.Error == ErrorCode.ERR_Success)
  43. {
  44. CardData cardData = CardDataManager.GetCardDataById(response.CardId);
  45. cardData.lv = response.CardLvl;
  46. cardData.exp = response.CardExp;
  47. for (int i = 0; i < response.KsAttribute.Count; i++)
  48. {
  49. cardData.scores[response.KsAttribute[i]] = response.VsAttribute[i];
  50. }
  51. return true;
  52. }
  53. }
  54. return false;
  55. }
  56. public static async ETTask<bool> UpgradeCardStar(int cardId)
  57. {
  58. M2C_UpgradeCardStar response = null;
  59. response = (M2C_UpgradeCardStar)await MessageHelper.SendToServer(new C2M_UpgradeCardStar() { CardId = cardId });
  60. if (response != null)
  61. {
  62. if (response.Error == ErrorCode.ERR_Success)
  63. {
  64. CardData cardData = CardDataManager.GetCardDataById(response.CardId);
  65. cardData.star = response.CardStar;
  66. for (int i = 0; i < response.KsAttribute.Count; i++)
  67. {
  68. cardData.scores[response.KsAttribute[i]] = response.VsAttribute[i];
  69. }
  70. return true;
  71. }
  72. }
  73. return false;
  74. }
  75. //resIndex:0默认,1特殊
  76. public static async ETTask<bool> ChangeCardRes(int cardId, int resIndex)
  77. {
  78. M2C_ChangeCardRes response = null;
  79. response = (M2C_ChangeCardRes)await MessageHelper.SendToServer(new C2M_ChangeCardRes() { CardId = cardId, ResIndex = resIndex });
  80. if (response != null)
  81. {
  82. if (response.Error == ErrorCode.ERR_Success)
  83. {
  84. CardData cardData = CardDataManager.GetCardDataById(cardId);
  85. cardData.resIndex = resIndex;
  86. return true;
  87. }
  88. }
  89. return false;
  90. }
  91. public static async ETTask<bool> UpgradeCardSkill(int cardId, int skillId)
  92. {
  93. M2C_UpgradeCardSkill response = null;
  94. response = (M2C_UpgradeCardSkill)await MessageHelper.SendToServer(new C2M_UpgradeCardSkill() { CardId = cardId, SkillId = skillId });
  95. if (response != null)
  96. {
  97. if (response.Error == ErrorCode.ERR_Success)
  98. {
  99. SkillDataManager.Instance.UpdateSkill(response.CardId, response.SkillId, response.SkillLvl);
  100. EventAgent.DispatchEvent(ConstMessage.CARD_UP_SKILL);
  101. return true;
  102. }
  103. }
  104. return false;
  105. }
  106. }
  107. }