Pack.cs 13 KB

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