Pack.cs 12 KB

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