InstanceZonesController.cs 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. //, new object[] { typeof(StoryChapterView).FullName, MainStoryDataManager.currentChapterCfgId }
  39. bool skipable = MainStoryDataManager.CheckCurrentLevelPass();
  40. ViewManager.Show<StoryDialogView>(new object[] { levelCfg.storyStartID, skipable, new OnCompleteStoryDialogCall(OnCompleteChapterStoryDialog),null,false }, true);
  41. }
  42. }
  43. public static async ETTask CheckStoryFightResult()
  44. {
  45. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  46. //if (storyLevelCfg.type == ConstInstanceZonesType.Studio && storyLevelCfg.subType == ConstInstanceZonesSubType.Hard3)
  47. //{
  48. // float addition = StudioDataManager.Instance.GetAddition();
  49. // addition = addition / 10000 * FightDataManager.Instance.totalScore;
  50. // FightDataManager.Instance.totalScore += (int)Math.Round(addition);
  51. //}
  52. var score = FightDataManager.Instance.totalScore;
  53. //客户端先做判断,成功和失败处理不同
  54. var success = InstanceZonesDataManager.GetFightResult(score, out var npcScore);
  55. if (success)
  56. {
  57. await InstanceZonesSProxy.FinishStoryFightLevel(InstanceZonesDataManager.currentLevelCfgId, score, npcScore, InstanceZonesDataManager.usedRecommend);
  58. }
  59. else
  60. {
  61. ViewManager.Show<StroyFightResultView>(new StoryFightResultData
  62. {
  63. Result = false,
  64. Score = score,
  65. FirstPass = false,
  66. Star = 0
  67. }, true);
  68. //失败仅判断并更新最高分
  69. if (score > InstanceZonesDataManager.GetScoreHighest(InstanceZonesDataManager.currentCardId))
  70. {
  71. InstanceZonesSProxy.StoryFightLevelFail(InstanceZonesDataManager.currentLevelCfgId, score).Coroutine();
  72. }
  73. }
  74. }
  75. public static void OnCompleteChapterStoryDialog(bool isSkip, object param)
  76. {
  77. if (!MainStoryDataManager.CheckCurrentLevelPass() && isSkip)
  78. {
  79. InstanceZonesSProxy.FinishStoryDialogLevel(InstanceZonesDataManager.currentLevelCfgId).Coroutine();
  80. }
  81. else
  82. {
  83. OnFinishStoryLevel(InstanceZonesDataManager.currentLevelCfgId, false, false);
  84. }
  85. }
  86. public static void OnFinishStoryLevel(int levelCfgId, bool firstPass, bool success)
  87. {
  88. _onFinishStoryLevelCall?.Invoke(levelCfgId, firstPass, success);
  89. }
  90. }
  91. }