DivineSenceInfoPanel.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Bag;
  8. using UnityEngine;
  9. using Utility;
  10. namespace Fort23.Mono
  11. {
  12. [UIBinding(prefab = "DivineSenceInfoPanel")]
  13. public partial class DivineSenceInfoPanel : UIPanel
  14. {
  15. private Action<int, List<ItemInfo>> callback;
  16. private int useCount = 0;
  17. List<ItemInfo> useItems = new List<ItemInfo>();
  18. List<DivineSenceInfoBtnWidget> _divineSenceInfoBtnWidgets = new List<DivineSenceInfoBtnWidget>();
  19. private int maxCount;
  20. private DivineSenseConfig divineSenseConfig;
  21. private void Init()
  22. {
  23. isAddStack = true;
  24. }
  25. public override CTask GetFocus()
  26. {
  27. AppBarPanel.OpenPanel(this);
  28. return base.GetFocus();
  29. }
  30. protected override void AddEvent()
  31. {
  32. }
  33. protected override void DelEvent()
  34. {
  35. }
  36. public override void AddButtonEvent()
  37. {
  38. Btn_Ok.onClick.AddListener(() =>
  39. {
  40. useItems.Clear();
  41. foreach (var senceInfoBtnWidget in _divineSenceInfoBtnWidgets)
  42. {
  43. if (senceInfoBtnWidget.type == 2 && senceInfoBtnWidget.ItemInfo != null)
  44. {
  45. useItems.Add(senceInfoBtnWidget.ItemInfo);
  46. }
  47. }
  48. callback?.Invoke(useCount, useItems);
  49. UIManager.Instance.HideUIUIPanel(this);
  50. });
  51. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  52. Slider_Count.onValueChanged.AddListener((c) => { Slider_Count_OnValueChanged(c); });
  53. Btn_Tip.onClick.AddListener(() => { DivineSenceLevelPreviewPanel.OpenPanel(); });
  54. Btn_Event.onClick.AddListener(() => { DivineSenceEventPreviewPanel.OpenPanel(); });
  55. }
  56. private void Slider_Count_OnValueChanged(float value)
  57. {
  58. useCount = (int)value;
  59. Text_Count.text = $"神识探索:{value}次";
  60. // Text_shenshishangxian.text = $"({EventSystemManager.Instance.GetShenShiCount()}<color=green>+{value}</color>/{maxCount})";
  61. Text_shenshishangxian.text = $"({EventSystemManager.Instance.GetShenShiCount() + value }/{maxCount})";
  62. foreach (var senceInfoBtnWidget in _divineSenceInfoBtnWidgets)
  63. {
  64. senceInfoBtnWidget.UpdateItermCount(useCount);
  65. }
  66. }
  67. public async void CustomInit(Action<int, List<ItemInfo>> callback)
  68. {
  69. _divineSenceInfoBtnWidgets.Clear();
  70. divineSenseConfig = ConfigComponent.Instance.Get<DivineSenseConfig>(AccountFileInfo.Instance.playerData.divineSenseLevel);
  71. HeroPowerUpConfig heroPowerUpConfig = PlayerManager.Instance.myHero.powerUpConfig;
  72. Text_Level.text = $"神识等级:{AccountFileInfo.Instance.playerData.divineSenseLevel}级";
  73. Text_Exp.text = $"{AccountFileInfo.Instance.playerData.divineSenseexp}/{divineSenseConfig.exp}";
  74. Slider_Exp.maxValue = divineSenseConfig.exp;
  75. Slider_Exp.value = AccountFileInfo.Instance.playerData.divineSenseexp;
  76. int count = (int)(AccountFileInfo.Instance.playerData.divineSensePoint / PlayerManager.Instance.gameConstantConfig.DetectEventCount);
  77. maxCount = heroPowerUpConfig.ShenshiMax / PlayerManager.Instance.gameConstantConfig.DetectEventCount;
  78. maxCount = maxCount > 10 ? 10 : maxCount;
  79. count = count + EventSystemManager.Instance.GetShenShiCount() > maxCount ? maxCount - EventSystemManager.Instance.GetShenShiCount() : count;
  80. if (count == 1)
  81. {
  82. Slider_Count.minValue = 0;
  83. Slider_Count.maxValue = count;
  84. Slider_Count.value = count;
  85. Slider_Count.interactable = false;
  86. }
  87. else
  88. {
  89. Slider_Count.minValue = 1;
  90. Slider_Count.maxValue = count;
  91. Slider_Count.value = count;
  92. Slider_Count.interactable = true;
  93. }
  94. Slider_Count_OnValueChanged(count);
  95. List<float> probabilities = UtilTools.CalculateProbabilities(divineSenseConfig.QualityBonusChance.ToList());
  96. for (var i = 0; i < Text_qs.Count; i++)
  97. {
  98. Text_qs[i].text = $"{probabilities[i] * 100:F2}%";
  99. }
  100. DivineSenceInfoBtnWidget divineSenceInfoBtnWidget = await UIManager.Instance.CreateGComponentForObject<DivineSenceInfoBtnWidget>(DivineSenceInfoBtnWidgetGam0, null);
  101. divineSenceInfoBtnWidget.CustomInit(-1, 1);
  102. divineSenceInfoBtnWidget.OnClick = OnClick;
  103. _divineSenceInfoBtnWidgets.Add(divineSenceInfoBtnWidget);
  104. divineSenceInfoBtnWidget = await UIManager.Instance.CreateGComponentForObject<DivineSenceInfoBtnWidget>(DivineSenceInfoBtnWidgetGam1, null);
  105. divineSenceInfoBtnWidget.CustomInit(-1, 2);
  106. divineSenceInfoBtnWidget.OnClick = OnClick;
  107. _divineSenceInfoBtnWidgets.Add(divineSenceInfoBtnWidget);
  108. // divineSenceInfoBtnWidget = await UIManager.Instance.CreateGComponentForObject<DivineSenceInfoBtnWidget>(DivineSenceInfoBtnWidgetGam2, null);
  109. // divineSenceInfoBtnWidget.CustomInit(-1, 2);
  110. // divineSenceInfoBtnWidget.OnClick = OnClick;
  111. // _divineSenceInfoBtnWidgets.Add(divineSenceInfoBtnWidget);
  112. this.callback = callback;
  113. }
  114. private void OnClick(ItemWidgetBasic obj)
  115. {
  116. DivineSenceInfoBtnWidget divineSenceInfoBtnWidget = obj as DivineSenceInfoBtnWidget;
  117. if (divineSenceInfoBtnWidget.type == 1)
  118. return;
  119. List<int> selectType = new List<int>();
  120. foreach (var senceInfoBtnWidget in _divineSenceInfoBtnWidgets)
  121. {
  122. if (senceInfoBtnWidget != divineSenceInfoBtnWidget && senceInfoBtnWidget.type != 1 && senceInfoBtnWidget.ItemInfo != null)
  123. {
  124. selectType.Add(senceInfoBtnWidget.ItemInfo.config.associateID);
  125. }
  126. }
  127. DivineSenceItemPanel.OpenPanel(divineSenceInfoBtnWidget.ItemInfo, selectType, (id) =>
  128. {
  129. divineSenceInfoBtnWidget.CustomInit(id, divineSenceInfoBtnWidget.type);
  130. UpdateBl();
  131. },
  132. () =>
  133. {
  134. divineSenceInfoBtnWidget.CustomInit(-1, divineSenceInfoBtnWidget.type);
  135. UpdateBl();
  136. });
  137. }
  138. public void UpdateBl()
  139. {
  140. Map<int, int> probabilitiesMap = new Map<int, int>();
  141. foreach (var senceInfoBtnWidget in _divineSenceInfoBtnWidgets)
  142. {
  143. if (senceInfoBtnWidget.type == 2 && senceInfoBtnWidget.ItemInfo != null && senceInfoBtnWidget.ItemInfo.config.associateID == 6)
  144. {
  145. if (!probabilitiesMap.ContainsKey(senceInfoBtnWidget.ItemInfo.config.associateVlaue[0]))
  146. {
  147. probabilitiesMap.Add(senceInfoBtnWidget.ItemInfo.config.associateVlaue[0], senceInfoBtnWidget.ItemInfo.config.associateVlaue[1]);
  148. }
  149. else
  150. {
  151. probabilitiesMap[senceInfoBtnWidget.ItemInfo.config.associateVlaue[0]] += senceInfoBtnWidget.ItemInfo.config.associateVlaue[1];
  152. }
  153. }
  154. senceInfoBtnWidget.UpdateItermCount(useCount);
  155. }
  156. var QualityBonusChance = divineSenseConfig.QualityBonusChance.ToList();
  157. foreach (var keyValuePair in probabilitiesMap)
  158. {
  159. QualityBonusChance[keyValuePair.Key - 1] *= keyValuePair.Value + 0.01f;
  160. }
  161. List<float> probabilities = UtilTools.CalculateProbabilities(QualityBonusChance);
  162. for (var i = 0; i < Text_qs.Count; i++)
  163. {
  164. Text_qs[i].text = $"{probabilities[i] * 100:F2}%";
  165. }
  166. }
  167. public async static CTask OpenPanel(Action<int, List<ItemInfo>> callback)
  168. {
  169. DivineSenceInfoPanel divineSenceInfoPanel = await UIManager.Instance.LoadAndOpenPanel<DivineSenceInfoPanel>(null, UILayer.Middle);
  170. divineSenceInfoPanel.CustomInit(callback);
  171. }
  172. }
  173. }