Pack.cs 12 KB

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