Pack.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. using UnityEngine;
  2. using System;
  3. using System.Xml;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. public class Pack : SkillRoot
  8. {
  9. #region 变量
  10. #region 配置
  11. protected int MinUseLv;
  12. protected int MaxUseLv;
  13. protected float Person;
  14. protected float SkillCD;
  15. protected float UseAmt;
  16. protected float CoinOnce;
  17. protected float CoinPerson;
  18. protected float DiamondOnce;
  19. protected float Plus;
  20. protected float PersonBuff;
  21. protected float SkillCdBuff;
  22. protected string Label;
  23. protected string Anim;
  24. protected string Flower;
  25. protected Current BuyCur;
  26. #endregion
  27. public SkillStatus _ItemStatus;
  28. public SkillStatus ItemStatus
  29. {
  30. get { return _ItemStatus; }
  31. set
  32. {
  33. _ItemStatus = value;
  34. if (_ItemStatus == SkillStatus.Buy)
  35. {
  36. ItemBtn.interactable = true;
  37. ManaText.Add(ItemBtnLab, ImageParse(BuyCur), UseAmt.ToString("0"), "\n", new LanStr("UI", "Fe_BtnLab3"));
  38. }
  39. else if (_ItemStatus == SkillStatus.Lock)
  40. {
  41. ItemBtn.interactable = false;
  42. ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab5"), "\n", new LanStr("UI", "Fe_BtnLab4"), MinUseLv.ToString(), "-", MaxUseLv.ToString());
  43. }
  44. else
  45. {
  46. throw new Exception(_ItemStatus.ToString());
  47. }
  48. }
  49. }
  50. #endregion
  51. public Pack(XmlAttributeCollection attributes)
  52. {
  53. #region 配置
  54. ID = int.Parse(attributes[0].Value);
  55. Icon = attributes[14].Value;
  56. Anim = attributes[15].Value;
  57. Label = attributes[16].Value;
  58. _Name = "Pack" + ID;
  59. Flower = attributes[9].Value;
  60. ClassID = IntParse(attributes[3].Value);
  61. UseAmt = FloatParse(attributes[12].Value);
  62. CoinOnce = FloatParse(attributes[7].Value);
  63. DiamondOnce = FloatParse(attributes[8].Value);
  64. SkillTab = SkillClassParse(attributes[2].Value);
  65. BuyCur = CurrentParse(attributes[11].Value);
  66. MinUseLv = MinLevelParse(attributes[10].Value);
  67. MaxUseLv = MaxLevelParse(attributes[10].Value);
  68. ValueBuffParse(out Person, out PersonBuff, attributes[5].Value);
  69. ValueBuffParse(out SkillCD, out SkillCdBuff, attributes[6].Value);
  70. ValueBuffParse(out CoinPerson, out Plus, attributes[4].Value);
  71. #endregion
  72. SkillType = SkillType.Pack;
  73. }
  74. public override void RegistValue(float elapse, List<List<SkillRoot>> ffList)
  75. {
  76. ManaText.Add(ItemTit, new LanStr("SkillName", _Name));
  77. ItemLab.text = Description(0);
  78. ItemBtn.onClick.AddListener(OnClick);
  79. for (int i = 0; i < Level; i++)
  80. {
  81. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁 等级 : {1}", Name, Level));
  82. UseConti();
  83. }
  84. }
  85. public override void UpdateStatus()
  86. {
  87. if (MaxUseLv == MinUseLv)
  88. {
  89. ItemStatus = SkillStatus.Buy;
  90. }
  91. else
  92. {
  93. if (ManaData.Level > MaxUseLv || ManaData.Level < MinUseLv)
  94. {
  95. ItemStatus = SkillStatus.Lock;
  96. }
  97. else
  98. {
  99. ItemStatus = SkillStatus.Buy;
  100. }
  101. }
  102. }
  103. protected void OnClick()
  104. {
  105. if (ManaData.Connect == false)
  106. {
  107. ManaReso.Get("Fg_Reconnect").TweenForCG();
  108. return;
  109. }
  110. ManaReso.Get("Fe_Info").TweenForCG();
  111. ManaReso.SetText("Fe_Tit", Name);
  112. ManaReso.SetText("Fe_Lab0", "");
  113. if (ItemStatus == SkillStatus.Buy)
  114. {
  115. ManaReso.SetText("Fe_Lab1", Description(0));
  116. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), ImageParse(BuyCur), UseAmt));
  117. ManaReso.SetButtonEvent
  118. (
  119. "Fe_Btn",
  120. () =>
  121. {
  122. Buy();
  123. ManaReso.Get("Fe_Info").TweenBacCG();
  124. }
  125. );
  126. }
  127. else
  128. {
  129. throw new Exception();
  130. }
  131. }
  132. protected virtual void Buy()
  133. {
  134. if (ManaData.Pay(UseAmt, BuyCur))
  135. {
  136. #region 调试输出
  137. StringBuilder strb = new StringBuilder();
  138. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  139. if (Math.Abs(Plus) > 0.0005f)
  140. {
  141. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", Plus * 100);
  142. }
  143. if (Math.Abs(Person) > 0.0005f)
  144. {
  145. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", Person);
  146. }
  147. if (Math.Abs(PersonBuff) > 0.0005f)
  148. {
  149. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", PersonBuff * 100);
  150. }
  151. if (Math.Abs(CoinPerson) > 0.0005f)
  152. {
  153. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", CoinPerson);
  154. }
  155. if (Math.Abs(SkillCD) > 0.0005f)
  156. {
  157. strb.AppendFormat(" 减少冷却上限<color=red>{0}</color>", SkillCD);
  158. }
  159. if (Math.Abs(SkillCdBuff) > 0.0005f)
  160. {
  161. strb.AppendFormat(" 减少冷却上限<color=red>{0}%</color>", SkillCdBuff * 100);
  162. }
  163. if (Math.Abs(CoinOnce) > 0.0005f)
  164. {
  165. strb.AppendFormat(" 获得金币<color=red>{0}</color>", CoinOnce);
  166. }
  167. if (Math.Abs(DiamondOnce) > 0.0005f)
  168. {
  169. strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
  170. }
  171. if (!string.IsNullOrEmpty(Flower))
  172. {
  173. string[] strings = Flower.Split(' ');
  174. for (int i = 0; i < strings.Length; i++)
  175. {
  176. strb.AppendFormat(" 获得<color=red>{0}</color>", ManaGarden.FlowerInfoList[int.Parse(strings[i])].Name);
  177. }
  178. }
  179. strb.Append(" <color=red>永久有效</color>");
  180. ManaDebug.Log(strb.ToString());
  181. #endregion
  182. UseConti();
  183. UseImmed();
  184. Level++;
  185. }
  186. }
  187. protected void UseConti()
  188. {
  189. if (!string.IsNullOrEmpty(Flower))
  190. {
  191. string[] strings = Flower.Split(' ');
  192. for (int i = 0; i < strings.Length; i++)
  193. {
  194. FlowerInfo flowerInfo = ManaGarden.FlowerInfoList[int.Parse(strings[i])];
  195. if (flowerInfo.Unlock == false)
  196. {
  197. flowerInfo.Unlock = true;
  198. }
  199. }
  200. }
  201. ManaData.SkillPlus += Plus;
  202. ManaData.SkillPerson += Person;
  203. ManaData.SkillPersonBuff += PersonBuff;
  204. ManaData.SkillCoinPerson += CoinPerson;
  205. if (Math.Abs(SkillCD) > 0.0005f)
  206. {
  207. for (int i = 0; i < ManaData.SkillList.Count; i++)
  208. {
  209. ManaData.SkillList[i].ReceiveCool(SkillCD, false, false);
  210. }
  211. }
  212. if (Math.Abs(SkillCdBuff) > 0.0005f)
  213. {
  214. for (int i = 0; i < ManaData.SkillList.Count; i++)
  215. {
  216. ManaData.SkillList[i].ReceiveCool(SkillCdBuff, false, true);
  217. }
  218. }
  219. }
  220. protected void UseImmed()
  221. {
  222. ManaData.Coin += CoinOnce;
  223. ManaData.Diamond += DiamondOnce;
  224. }
  225. #region 解读器
  226. protected int MinLevelParse(string str)
  227. {
  228. if (string.IsNullOrEmpty(str))
  229. {
  230. return 0;
  231. }
  232. else
  233. {
  234. return IntParse(str.Split(',')[0]);
  235. }
  236. }
  237. protected int MaxLevelParse(string str)
  238. {
  239. if (string.IsNullOrEmpty(str))
  240. {
  241. return 0;
  242. }
  243. else
  244. {
  245. return IntParse(str.Split(',')[1]);
  246. }
  247. }
  248. protected override string Description(int offset)
  249. {
  250. string[] strings = Desc.Split('[', ']');
  251. StringBuilder stringBuilder = new StringBuilder();
  252. for (int i = 0; i < strings.Length; i++)
  253. {
  254. if (strings[i].Contains("lv"))
  255. {
  256. }
  257. else if (strings[i].Contains("&coin&"))
  258. {
  259. #region MyRegion
  260. if (Math.Abs(CoinOnce) > 0.0005f)
  261. {
  262. stringBuilder.Append(CoinOnce.ToString("0"));
  263. }
  264. #endregion
  265. }
  266. else if (strings[i].Contains("&flower&"))
  267. {
  268. #region MyRegion
  269. if (!string.IsNullOrEmpty(Flower))
  270. {
  271. string[] strings1 = Flower.Split(' ');
  272. for (int j = 0; j < strings1.Length; j++)
  273. {
  274. stringBuilder.Append(Language.GetStr("FlowerName", "Flower" + strings1[j]));
  275. if (j != strings1.Length - 1)
  276. {
  277. stringBuilder.Append(",");
  278. }
  279. }
  280. }
  281. #endregion
  282. }
  283. else if (strings[i].Contains("&diamond&"))
  284. {
  285. #region MyRegion
  286. if (Math.Abs(DiamondOnce) > 0.0005f)
  287. {
  288. stringBuilder.Append(DiamondOnce.ToString("0"));
  289. }
  290. #endregion
  291. }
  292. else if (strings[i].Contains("&coin_person&"))
  293. {
  294. #region MyRegion
  295. if (Math.Abs(Plus) > 0.0005f)
  296. {
  297. stringBuilder.Append(string.Format("{0:0}%", Plus*100));
  298. }
  299. else if (Math.Abs(CoinPerson) > 0.0005f)
  300. {
  301. stringBuilder.Append(CoinPerson.ToString("0.0"));
  302. }
  303. #endregion
  304. }
  305. else
  306. {
  307. stringBuilder.Append(strings[i]);
  308. }
  309. }
  310. return stringBuilder.ToString();
  311. }
  312. #endregion
  313. }