Pack.cs 13 KB

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