Pack.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. public override string ID
  12. {
  13. get
  14. {
  15. return "Pack" + ID_;
  16. }
  17. }
  18. public override string Name
  19. {
  20. get
  21. {
  22. return Language.GetStr("SkillName", ID);
  23. }
  24. }
  25. protected int MinUseLv;
  26. protected int MaxUseLv;
  27. protected float Person;
  28. protected float SkillCD;
  29. protected float UseAmt;
  30. protected float CoinPerson;
  31. protected float DiamondOnce;
  32. protected string CoinFml;
  33. protected float Plus;
  34. protected float PersonBuff;
  35. protected float SkillCdBuff;
  36. protected string Label;
  37. protected string Anim;
  38. protected string Flower;
  39. protected Current BuyCur;
  40. #endregion
  41. public override int Level
  42. {
  43. get; set;
  44. }
  45. public SkillStatus ItemStatus
  46. {
  47. get { return ItemStatus_; }
  48. set
  49. {
  50. ItemStatus_ = value;
  51. if (ItemStatus_ == SkillStatus.Buy)
  52. {
  53. ItemBtn.interactable = true;
  54. SkillItem.SetActive(true);
  55. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab3"), "\n", ImageParse(BuyCur), UseAmt.ToString("0"));
  56. }
  57. else if (ItemStatus_ == SkillStatus.Lock)
  58. {
  59. ItemBtn.interactable = false;
  60. SkillItem.SetActive(false);
  61. }
  62. }
  63. }
  64. public SkillStatus ItemStatus_;
  65. #endregion
  66. public Pack(XmlAttributeCollection attribute)
  67. {
  68. #region 配置
  69. ID_ = int.Parse(attribute[0].Value);
  70. Icon_ = attribute[14].Value;
  71. Anim = attribute[15].Value;
  72. Label = attribute[16].Value;
  73. Flower = attribute[9].Value;
  74. CoinFml = attribute[7].Value;
  75. ItemIndex = Auxiliary.IntParse(attribute[3].Value,0);
  76. UseAmt = Auxiliary.FloatParse(attribute[12].Value,0);
  77. DiamondOnce = Auxiliary.FloatParse(attribute[8].Value,0);
  78. SkillTab = SkillClassParse(attribute[2].Value);
  79. BuyCur = CurrentParse(attribute[11].Value);
  80. MinUseLv = MinLevelParse(attribute[10].Value);
  81. MaxUseLv = MaxLevelParse(attribute[10].Value);
  82. ValueBuffParse(out Person, out PersonBuff, attribute[5].Value);
  83. ValueBuffParse(out SkillCD, out SkillCdBuff, attribute[6].Value);
  84. ValueBuffParse(out CoinPerson, out Plus, attribute[4].Value);
  85. #endregion
  86. SkillType = SkillType.Pack;
  87. }
  88. public override void Annul()
  89. {
  90. for (int i = 0; i < Level; i++)
  91. {
  92. ManaCenter.SkillPlus -= Plus;
  93. ManaCenter.SkillPerson -= Person;
  94. ManaCenter.SkillPersonBuff -= PersonBuff;
  95. ManaCenter.SkillCoinPerson -= CoinPerson;
  96. if (Math.Abs(SkillCD) > 0.0005f)
  97. {
  98. for (int j = 0; j < ManaCenter.SkillList.Count; j++)
  99. {
  100. ManaCenter.SkillList[j].ReceiveCool(-SkillCD, false, false);
  101. }
  102. }
  103. if (Math.Abs(SkillCdBuff) > 0.0005f)
  104. {
  105. for (int j = 0; j < ManaCenter.SkillList.Count; j++)
  106. {
  107. ManaCenter.SkillList[j].ReceiveCool(-SkillCdBuff, false, true);
  108. }
  109. }
  110. }
  111. }
  112. public override void Reactive()
  113. {
  114. for (int i = 0; i < Level; i++)
  115. {
  116. Annul();
  117. }
  118. }
  119. public override void RegistValue(float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  120. {
  121. Level = int.Parse(attribute[3].Value);
  122. for (int i = 0; i < Level; i++)
  123. {
  124. UseA();
  125. }
  126. ItemStatus_ = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  127. ItemBtn.onClick.RemoveAllListeners();
  128. ItemBtn.onClick.AddListener(OnClick);
  129. ItemLab.text = Description(0);
  130. ManaLan.Add(ItemTit, new LanStr("SkillName", ID));
  131. ItemStatus = ItemStatus;
  132. ManaIAP.ProductDic.UniqueAdd(ID, PurchaseResult);
  133. }
  134. public override void UpdateStatus()
  135. {
  136. if (!ManaCenter.Complete)
  137. {
  138. return;
  139. }
  140. ItemLab.text = Description(0);
  141. if (MaxUseLv == MinUseLv)
  142. {
  143. ItemStatus = SkillStatus.Buy;
  144. }
  145. else
  146. {
  147. if (ManaCenter.Level > MaxUseLv || ManaCenter.Level < MinUseLv)
  148. {
  149. ItemStatus = SkillStatus.Lock;
  150. }
  151. else
  152. {
  153. ItemStatus = SkillStatus.Buy;
  154. }
  155. }
  156. }
  157. protected void UseB()
  158. {
  159. if (!string.IsNullOrEmpty(CoinFml))
  160. {
  161. ManaCenter.Coin += Auxiliary.FmlParse(CoinFml, "l", ManaCenter.Level.ToString(), "c", ManaCenter.CoinPerson.ToString("0.000"));
  162. }
  163. ManaCenter.Diamond += DiamondOnce;
  164. }
  165. protected void UseA()
  166. {
  167. if (!string.IsNullOrEmpty(Flower))
  168. {
  169. string[] strings = Flower.Split(' ');
  170. for (int i = 0; i < strings.Length; i++)
  171. {
  172. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[int.Parse(strings[i])];
  173. if (flowerInfo.Unlock == false)
  174. {
  175. flowerInfo.Unlock = true;
  176. }
  177. }
  178. }
  179. ManaCenter.SkillPlus += Plus;
  180. ManaCenter.SkillPerson += Person;
  181. ManaCenter.SkillPersonBuff += PersonBuff;
  182. ManaCenter.SkillCoinPerson += CoinPerson;
  183. if (Math.Abs(SkillCD) > 0.0005f)
  184. {
  185. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  186. {
  187. ManaCenter.SkillList[i].ReceiveCool(SkillCD, false, false);
  188. }
  189. }
  190. if (Math.Abs(SkillCdBuff) > 0.0005f)
  191. {
  192. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  193. {
  194. ManaCenter.SkillList[i].ReceiveCool(SkillCdBuff, false, true);
  195. }
  196. }
  197. }
  198. protected void OnClick()
  199. {
  200. ManaAudio.PlayClip(Clip.BtnClip);
  201. ManaReso.Get("Fe_Info").TweenForCG();
  202. ManaReso.SetText("Fe_Tit", Name);
  203. ManaReso.SetSprite("Fe_Icon", ItemIcon.sprite);
  204. ManaReso.SetText("Fe_Lab0", "");
  205. if (ItemStatus == SkillStatus.Buy)
  206. {
  207. ManaReso.SetText("Fe_Lab1", Description(0));
  208. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), ImageParse(BuyCur), UseAmt));
  209. ManaReso.SetButtonEvent
  210. (
  211. "Fe_Btn",
  212. () =>
  213. {
  214. Purchase();
  215. ManaReso.Get("Fe_Info").TweenBacCG();
  216. }
  217. );
  218. }
  219. }
  220. protected void Purchase()
  221. {
  222. ManaAudio.PlayClip(Clip.BtnClip);
  223. ManaCenter.Pay(ID, UseAmt, Current.Cash, PurchaseResult);
  224. }
  225. protected void PurchaseResult()
  226. {
  227. UseA();
  228. UseB();
  229. StringBuilder sb = new StringBuilder();
  230. if (!string.IsNullOrEmpty(CoinFml))
  231. {
  232. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(金币)>", Auxiliary.FmlParse(CoinFml, "l", ManaCenter.Level.ToString(), "c", ManaCenter.CoinPerson.ToString("0.000")).ToString("0"));
  233. }
  234. if (!DiamondOnce.Equal(0))
  235. {
  236. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", DiamondOnce);
  237. }
  238. if (!string.IsNullOrEmpty(Flower))
  239. {
  240. string[] strings = Flower.Split(' ');
  241. for (int i = 0; i < strings.Length; i++)
  242. {
  243. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[int.Parse(strings[i])];
  244. if (flowerInfo.Unlock == false)
  245. {
  246. flowerInfo.Unlock = true;
  247. }
  248. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name);
  249. }
  250. }
  251. string str = sb.ToString();
  252. if (!string.IsNullOrEmpty(str))
  253. {
  254. ManaInfo.Show(str, 10f);
  255. }
  256. Level++;
  257. ManaAudio.PlayClip(Clip.SkillClip);
  258. if (BuyCur == Current.Cash)
  259. {
  260. ManaServer.Save();
  261. }
  262. }
  263. #region 解读器
  264. protected int MinLevelParse(string str)
  265. {
  266. if (string.IsNullOrEmpty(str))
  267. {
  268. return 0;
  269. }
  270. else
  271. {
  272. return Auxiliary.IntParse(str.Split(',')[0],0);
  273. }
  274. }
  275. protected int MaxLevelParse(string str)
  276. {
  277. if (string.IsNullOrEmpty(str))
  278. {
  279. return 0;
  280. }
  281. else
  282. {
  283. return Auxiliary.IntParse(str.Split(',')[1],0);
  284. }
  285. }
  286. protected override string Description(int offset)
  287. {
  288. string[] strings = Desc.Split('[', ']');
  289. StringBuilder stringBuilder = new StringBuilder();
  290. for (int i = 0; i < strings.Length; i++)
  291. {
  292. if (strings[i].Contains("lv"))
  293. {
  294. }
  295. else if (strings[i].Contains("&coin&"))
  296. {
  297. #region MyRegion
  298. if (!string.IsNullOrEmpty(CoinFml))
  299. {
  300. stringBuilder.Append(Auxiliary.FmlParse(CoinFml, "l", ManaCenter.Level.ToString(), "c", ManaCenter.CoinPerson.ToString("0.000")).ToString("0"));
  301. }
  302. #endregion
  303. }
  304. else if (strings[i].Contains("&flower&"))
  305. {
  306. #region MyRegion
  307. if (!string.IsNullOrEmpty(Flower))
  308. {
  309. string[] strings1 = Flower.Split(' ');
  310. for (int j = 0; j < strings1.Length; j++)
  311. {
  312. stringBuilder.Append(Language.GetStr("FlowerName", "Flower" + strings1[j]));
  313. if (j != strings1.Length - 1)
  314. {
  315. stringBuilder.Append(",");
  316. }
  317. }
  318. }
  319. #endregion
  320. }
  321. else if (strings[i].Contains("&diamond&"))
  322. {
  323. #region MyRegion
  324. if (Math.Abs(DiamondOnce) > 0.0005f)
  325. {
  326. stringBuilder.Append(DiamondOnce.ToString("0"));
  327. }
  328. #endregion
  329. }
  330. else if (strings[i].Contains("&coin_person&"))
  331. {
  332. #region MyRegion
  333. if (Math.Abs(Plus) > 0.0005f)
  334. {
  335. stringBuilder.Append(string.Format("{0:0}%", Plus*100));
  336. }
  337. else if (Math.Abs(CoinPerson) > 0.0005f)
  338. {
  339. stringBuilder.Append(CoinPerson.ToString("0"));
  340. }
  341. #endregion
  342. }
  343. else
  344. {
  345. stringBuilder.Append(strings[i]);
  346. }
  347. }
  348. return stringBuilder.ToString();
  349. }
  350. #endregion
  351. }