InstanceZonesController.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using ET;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. //所有副本关卡通用类
  11. public class InstanceZonesController
  12. {
  13. public delegate void OnFinishStoryLevelCall(int levelCfgId, bool firstPass, bool success);
  14. private static OnFinishStoryLevelCall _onFinishStoryLevelCall;
  15. public static void ShowLevelView(int levelCfgId, OnFinishStoryLevelCall onFinishStoryLevelCall, int needitemId = 0, int needItemCount = 0)
  16. {
  17. _onFinishStoryLevelCall = onFinishStoryLevelCall;
  18. InstanceZonesDataManager.currentLevelCfgId = levelCfgId;
  19. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  20. if (levelCfg.fightID.Length > 0)
  21. {
  22. StoryFightCfg storyFightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  23. if (storyFightCfg == null)
  24. {
  25. Debug.LogError(string.Format("战斗id:{0} 无配置", levelCfg.fightID));
  26. return;
  27. }
  28. ViewManager.Show<StoryLevelInfoView>(new object[] { levelCfgId, needitemId, needItemCount });
  29. }
  30. else if (!string.IsNullOrEmpty(levelCfg.storyStartID))
  31. {
  32. List<StoryDialogCfg> storyDialogCfg = StoryDialogCfgArray.Instance.GetCfgsByid(levelCfg.storyStartID);
  33. if (storyDialogCfg.Count <= 0)
  34. {
  35. Debug.LogError(string.Format("剧情id:{0} 无配置", levelCfg.storyStartID));
  36. return;
  37. }
  38. object[] gobackparams;
  39. if (levelCfg.type == ConstInstanceZonesType.Studio && levelCfg.subType == ConstInstanceZonesSubType.Hard3)
  40. {
  41. object param = ViewManager.GetUIView(nameof(StudioFilingView)).viewData;
  42. gobackparams = new object[] { typeof(StudioFilingView).FullName, param };
  43. }
  44. else
  45. {
  46. gobackparams = new object[] { typeof(StoryChapterView).FullName, MainStoryDataManager.currentChapterCfgId };
  47. }
  48. //, new object[] { typeof(StoryChapterView).FullName, MainStoryDataManager.currentChapterCfgId }
  49. bool skipable = MainStoryDataManager.CheckCurrentLevelPass();
  50. ViewManager.Show<StoryDialogView>(new object[] { levelCfg.storyStartID, skipable, new OnCompleteStoryDialogCall(OnCompleteChapterStoryDialog),null,false }, gobackparams, true);
  51. }
  52. }
  53. public static async ETTask CheckStoryFightResult()
  54. {
  55. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  56. //if (storyLevelCfg.type == ConstInstanceZonesType.Studio && storyLevelCfg.subType == ConstInstanceZonesSubType.Hard3)
  57. //{
  58. // float addition = StudioDataManager.Instance.GetAddition();
  59. // addition = addition / 10000 * FightDataManager.Instance.totalScore;
  60. // FightDataManager.Instance.totalScore += (int)Math.Round(addition);
  61. //}
  62. var score = FightDataManager.Instance.totalScore;
  63. //客户端先做判断,成功和失败处理不同
  64. var success = InstanceZonesDataManager.GetFightResult(score, out var npcScore);
  65. if (success)
  66. {
  67. await InstanceZonesSProxy.FinishStoryFightLevel(InstanceZonesDataManager.currentLevelCfgId, score, npcScore, InstanceZonesDataManager.usedRecommend);
  68. }
  69. else
  70. {
  71. ViewManager.Show<StroyFightResultView>(new StoryFightResultData
  72. {
  73. Result = false,
  74. Score = score,
  75. FirstPass = false,
  76. Star = 0
  77. }, null, true);
  78. //失败仅判断并更新最高分
  79. if (score > InstanceZonesDataManager.GetScoreHighest(InstanceZonesDataManager.currentCardId))
  80. {
  81. InstanceZonesSProxy.StoryFightLevelFail(InstanceZonesDataManager.currentLevelCfgId, score).Coroutine();
  82. }
  83. }
  84. }
  85. public static void OnCompleteChapterStoryDialog(bool isSkip, object param)
  86. {
  87. //if (!MainStoryDataManager.CheckCurrentLevelPass() && isSkip)
  88. //{
  89. // InstanceZonesSProxy.FinishStoryDialogLevel(InstanceZonesDataManager.currentLevelCfgId).Coroutine();
  90. //}
  91. //else
  92. //{
  93. // OnFinishStoryLevel(InstanceZonesDataManager.currentLevelCfgId, false, false);
  94. //}
  95. }
  96. public static void OnFinishStoryLevel(int levelCfgId, bool firstPass, bool success)
  97. {
  98. _onFinishStoryLevelCall?.Invoke(levelCfgId, firstPass, success);
  99. }
  100. }
  101. }