Pack.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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 UseB()
  163. {
  164. if (!string.IsNullOrEmpty(CoinFml))
  165. {
  166. double coin = Auxiliary.FmlParse(CoinFml, "l", ManaCenter.Level.ToString(), "c", ManaCenter.CoinPerson.ToString("0.000"));
  167. ManaCenter.AddCoin(coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Shop);
  168. }
  169. ManaCenter.AddDiamond(DiamondOnce, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Charge);
  170. }
  171. protected void UseA()
  172. {
  173. ManaCenter.SkillPlus += Plus;
  174. ManaCenter.SkillPerson += Person;
  175. ManaCenter.SkillPersonBuff += PersonBuff;
  176. ManaCenter.SkillCoinPerson += CoinPerson;
  177. if (!SkillCD.Equal(0))
  178. {
  179. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  180. {
  181. ManaCenter.SkillList[i].ReceiveCool(SkillCD, false, false);
  182. }
  183. }
  184. if (!SkillCdBuff.Equal(0))
  185. {
  186. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  187. {
  188. ManaCenter.SkillList[i].ReceiveCool(SkillCdBuff, false, true);
  189. }
  190. }
  191. }
  192. protected void OnClick()
  193. {
  194. ManaAudio.PlayClip(Clip.BtnClip);
  195. ManaReso.Get("Fe_Info").TweenForCG();
  196. ManaReso.SetText("Fe_Tit", Name);
  197. ManaReso.SetSprite("Fe_Icon", ItemIcon.sprite);
  198. if (ItemStatus == SkillStatus.Buy)
  199. {
  200. ManaReso.SetText("Fe_Lab0", "");
  201. ManaReso.SetText("Fe_Lab1", GetDescription(0));
  202. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), Auxiliary.ImageParse(BuyCur), UseAmt));
  203. ManaReso.SetButtonEvent
  204. (
  205. "Fe_Btn",
  206. () =>
  207. {
  208. Purchase();
  209. ManaReso.Get("Fe_Info").TweenBacCG();
  210. }
  211. );
  212. }
  213. }
  214. protected void Purchase()
  215. {
  216. ManaAudio.PlayClip(Clip.BtnClip);
  217. ManaCenter.Pay(ID, UseAmt, BuyCur, PurchaseResult, StaticsManager.ItemID.购买礼包, StaticsManager.ConsumeModule.Charge);
  218. }
  219. protected void PurchaseResult()
  220. {
  221. int tempCoin = 0;
  222. int tempDiamond = (int) DiamondOnce;
  223. string tempFlower = "";
  224. if (!string.IsNullOrEmpty(Flower))
  225. {
  226. for (int i = 0; i < Flowers.Length; i++)
  227. {
  228. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[int.Parse(Flowers[i])];
  229. if (flowerInfo.Unlock == false)
  230. {
  231. flowerInfo.Unlock = true;
  232. tempFlower += string.Format("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name);
  233. }
  234. else
  235. {
  236. if (flowerInfo.UnlockCur == Current.Coin)
  237. {
  238. tempCoin = flowerInfo.UnlockAmt/5;
  239. ManaCenter.AddCoin(flowerInfo.UnlockAmt / 5, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Charge);
  240. }
  241. else if (flowerInfo.UnlockCur == Current.Diamond)
  242. {
  243. tempDiamond += flowerInfo.UnlockAmt/5;
  244. ManaCenter.AddDiamond(flowerInfo.UnlockAmt/5, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Charge);
  245. }
  246. }
  247. }
  248. }
  249. StringBuilder sb = new StringBuilder();
  250. if (!string.IsNullOrEmpty(CoinFml))
  251. {
  252. int coin = (int) Auxiliary.FmlParse(CoinFml, "l", ManaCenter.Level.ToString(), "c", ManaCenter.CoinPerson.ToString("0.000"));
  253. ManaCenter.AddCoin(coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Charge);
  254. tempCoin += coin;
  255. }
  256. if (!tempCoin.Equal(0))
  257. {
  258. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(金币)>", tempCoin);
  259. }
  260. if (!tempDiamond.Equal(0))
  261. {
  262. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", tempDiamond);
  263. }
  264. if (!string.IsNullOrEmpty(tempFlower))
  265. {
  266. sb.Append(tempFlower);
  267. }
  268. string str = sb.ToString();
  269. if (!string.IsNullOrEmpty(str))
  270. {
  271. ManaInfo.Show(str, 10f);
  272. }
  273. Level++;
  274. ManaAudio.PlayClip(Clip.SkillClip);
  275. if (BuyCur == Current.Cash)
  276. {
  277. ManaServer.Save();
  278. }
  279. UseA();
  280. UseB();
  281. }
  282. #region 解读器
  283. protected int MinLevelParse(string str)
  284. {
  285. if (string.IsNullOrEmpty(str))
  286. {
  287. return 0;
  288. }
  289. else
  290. {
  291. return Auxiliary.IntParse(str.Split(',')[0],0);
  292. }
  293. }
  294. protected int MaxLevelParse(string str)
  295. {
  296. if (string.IsNullOrEmpty(str))
  297. {
  298. return 0;
  299. }
  300. else
  301. {
  302. return Auxiliary.IntParse(str.Split(',')[1],0);
  303. }
  304. }
  305. protected override string GetDescription(int offset)
  306. {
  307. string[] strings = Desc.Split('[', ']');
  308. StringBuilder stringBuilder = new StringBuilder();
  309. for (int i = 0; i < strings.Length; i++)
  310. {
  311. if (strings[i].Contains("lv"))
  312. {
  313. }
  314. else if (strings[i].Contains("&coin&"))
  315. {
  316. #region MyRegion
  317. if (!string.IsNullOrEmpty(CoinFml))
  318. {
  319. stringBuilder.Append(Auxiliary.FmlParse(CoinFml, "l", ManaCenter.Level.ToString(), "c", ManaCenter.CoinPerson.ToString("0.000")).ToString("0"));
  320. }
  321. #endregion
  322. }
  323. else if (strings[i].Contains("&flower&"))
  324. {
  325. #region MyRegion
  326. if (!string.IsNullOrEmpty(Flower))
  327. {
  328. for (int j = 0; j < Flowers.Length; j++)
  329. {
  330. stringBuilder.Append(Language.GetStr("FlowerName", "Flower" + Flowers[j]));
  331. if (j != Flowers.Length - 1)
  332. {
  333. stringBuilder.Append(",");
  334. }
  335. }
  336. }
  337. #endregion
  338. }
  339. else if (strings[i].Contains("&replace&"))
  340. {
  341. #region MyRegion
  342. //if (!string.IsNullOrEmpty(Flower))
  343. //{
  344. // for (int j = 0; j < Diamonds.Length; j++)
  345. // {
  346. // stringBuilder.Append(int.Parse(Diamonds[j]));
  347. // if (j != Diamonds.Length - 1)
  348. // {
  349. // stringBuilder.Append(",");
  350. // }
  351. // }
  352. //}
  353. #endregion
  354. }
  355. else if (strings[i].Contains("&diamond&"))
  356. {
  357. #region MyRegion
  358. if (!DiamondOnce.Equal(0))
  359. {
  360. stringBuilder.Append(DiamondOnce.ToString("0"));
  361. }
  362. #endregion
  363. }
  364. else if (strings[i].Contains("&coin_person&"))
  365. {
  366. #region MyRegion
  367. if (!Plus.Equal(0))
  368. {
  369. stringBuilder.Append(string.Format("{0:0}%", Plus*100));
  370. }
  371. else if (!CoinPerson.Equal(0))
  372. {
  373. stringBuilder.Append(CoinPerson.ToString("0"));
  374. }
  375. #endregion
  376. }
  377. else
  378. {
  379. stringBuilder.Append(strings[i]);
  380. }
  381. }
  382. return stringBuilder.ToString();
  383. }
  384. #endregion
  385. }