Pack.cs 12 KB

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