Pack.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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 Config
  10. #region 配置
  11. public override string FullID
  12. {
  13. get
  14. {
  15. return PackFullIDPrefix + ID;
  16. }
  17. }
  18. public override string Name
  19. {
  20. get
  21. {
  22. return Language.GetStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.SkillName, FullID));
  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. button.interactable = true;
  56. SkillItem.SetActive(true);
  57. if (!string.IsNullOrEmpty(Label))
  58. {
  59. LanguageManager.Add(ButtonTitle, new MulLanStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.UI, Label)), "\n", Auxiliary.ImageParse(BuyCur), UseAmt.ToString("0"));
  60. }
  61. else
  62. {
  63. LanguageManager.Add(ButtonTitle, new MulLanStr(LanguageLabel.UI__Fe_BtnLab3), "\n", Auxiliary.ImageParse(BuyCur), UseAmt.ToString("0"));
  64. }
  65. }
  66. else if (itemStatus == SkillStatus.Lock)
  67. {
  68. button.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.StringToBool(attribute[17].Value, false);
  84. UseAmt = Auxiliary.StringToFloat(attribute[12].Value,0);
  85. ItemIndex = Auxiliary.StringToInt(attribute[3].Value,0);
  86. DiamondOnce = Auxiliary.StringToFloat(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 AnnulEffect()
  102. {
  103. Manager.SkillPlus -= Plus;
  104. Manager.SkillPerson -= Person;
  105. Manager.SkillPersonBuff -= PersonBuff;
  106. Manager.SkillCoinPerson -= CoinPerson;
  107. if (!SkillCD.Equal(0))
  108. {
  109. for (int j = 0; j < Manager.SkillList.Count; j++)
  110. {
  111. Manager.SkillList[j].Cool(-SkillCD, false, false);
  112. }
  113. }
  114. if (!SkillCdBuff.Equal(0))
  115. {
  116. for (int j = 0; j < Manager.SkillList.Count; j++)
  117. {
  118. Manager.SkillList[j].Cool(-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 Init(bool firstInit, float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  130. {
  131. if (!firstInit)
  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. GetBuff();
  140. }
  141. button.onClick.RemoveAllListeners();
  142. button.onClick.AddListener(OnClick);
  143. //if (!string.IsNullOrEmpty(Label))
  144. //{
  145. // ItemIcon1.SetActive(true);
  146. // ManaLan.Add(IconLab1, new LanStr("UI", Label));
  147. //}
  148. DescriptionText.text = GetDescription(0);
  149. LanguageManager.Add(TitleText, new MulLanStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.SkillName, FullID)));
  150. IAPManager.BuyProductCallbackDictionary.UniqueAdd(FullID, ()=>OnBuySucceed());
  151. ItemStatus = ItemStatus;
  152. SetActive();
  153. }
  154. public override void UpdateStatus()
  155. {
  156. if (!Manager.Inited)
  157. {
  158. return;
  159. }
  160. if (Lock && HttpManager.BuyPackLimitFlag && Level >= 1)
  161. {
  162. return;
  163. }
  164. DescriptionText.text = GetDescription(0);
  165. if (MaxUseLv == MinUseLv)
  166. {
  167. ItemStatus = SkillStatus.Buy;
  168. }
  169. else
  170. {
  171. if (Manager.GardenLevel > MaxUseLv || Manager.GardenLevel < MinUseLv)
  172. {
  173. ItemStatus = SkillStatus.Lock;
  174. }
  175. else
  176. {
  177. ItemStatus = SkillStatus.Buy;
  178. }
  179. }
  180. }
  181. protected void GetBuff()
  182. {
  183. Manager.SkillPlus += Plus;
  184. Manager.SkillPerson += Person;
  185. Manager.SkillPersonBuff += PersonBuff;
  186. Manager.SkillCoinPerson += CoinPerson;
  187. if (!SkillCD.Equal(0))
  188. {
  189. for (int i = 0; i < Manager.SkillList.Count; i++)
  190. {
  191. Manager.SkillList[i].Cool(SkillCD, false, false);
  192. }
  193. }
  194. if (!SkillCdBuff.Equal(0))
  195. {
  196. for (int i = 0; i < Manager.SkillList.Count; i++)
  197. {
  198. Manager.SkillList[i].Cool(SkillCdBuff, false, true);
  199. }
  200. }
  201. }
  202. public void SetActive()
  203. {
  204. bool active = !(Lock && HttpManager.BuyPackLimitFlag);
  205. if (active)
  206. {
  207. button.interactable = true;
  208. ItemStatus = ItemStatus;
  209. }
  210. else
  211. {
  212. if (Level > 0)
  213. {
  214. button.interactable = false;
  215. LanguageManager.Add(ButtonTitle, Language.GetStr(LanguageLabel.UI__Fe_BtnLab9));
  216. }
  217. }
  218. }
  219. protected void OnClick()
  220. {
  221. AudioManager.PlayClip(AudioLabel.ClickButton);
  222. ResourceManager.Get(CanvasLabel.Fe_Info).TweenForCG();
  223. ResourceManager.SetText(CanvasLabel.Fe_Tit, Name);
  224. ResourceManager.SetSprite(CanvasLabel.Fe_Icon, SkillIcon.sprite);
  225. if (ItemStatus == SkillStatus.Buy)
  226. {
  227. ResourceManager.SetText(CanvasLabel.Fe_Lab0, "");
  228. ResourceManager.SetText(CanvasLabel.Fe_Lab1, GetDescription(0));
  229. ResourceManager.SetText(CanvasLabel.Fe_BtnLab, string.Format("{0}({1}{2:0})", Language.GetStr(LanguageLabel.UI__Fe_BtnLab3), Auxiliary.ImageParse(BuyCur), UseAmt));
  230. ResourceManager.SetButtonEvent
  231. (
  232. CanvasLabel.Fe_Btn,
  233. () =>
  234. {
  235. OnBuy();
  236. ResourceManager.Get(CanvasLabel.Fe_Info).TweenBacCG();
  237. }
  238. );
  239. }
  240. }
  241. protected void OnBuy()
  242. {
  243. AudioManager.PlayClip(AudioLabel.ClickButton);
  244. Manager.Pay(FullID, UseAmt, BuyCur, ()=> OnBuySucceed(), StaticsManager.ItemID.购买礼包, StaticsManager.ConsumeModule.Charge);
  245. }
  246. public void OnBuySucceed(bool getGift = true)
  247. {
  248. int tempCoin = 0;
  249. int tempDiamond = (int) DiamondOnce;
  250. Manager.AddDiamond(DiamondOnce, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Charge);
  251. string tempFlower = "";
  252. if (!string.IsNullOrEmpty(Flower))
  253. {
  254. for (int i = 0; i < Flowers.Length; i++)
  255. {
  256. FlowerInfo flowerInfo = GardenManager.FlowerInfoDictionary[int.Parse(Flowers[i])];
  257. flowerInfo.Add();
  258. tempFlower += string.Format("{0}{1}{2} ", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.FlowerSprite, flowerInfo.Name);
  259. }
  260. }
  261. StringBuilder sb = new StringBuilder();
  262. if (!string.IsNullOrEmpty(CoinFml))
  263. {
  264. int coin = (int) Auxiliary.FmlParse(CoinFml, "l", Manager.GardenLevel.ToString(), "c", Manager.CoinPerson.ToString("0.000"));
  265. Manager.AddCoin(coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Shop);
  266. tempCoin += coin;
  267. }
  268. if (!tempCoin.Equal(0))
  269. {
  270. sb.AppendFormat("{0}{1}{2} ", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.CoinSprite, Auxiliary.ShrinkNumberStr(tempCoin));
  271. }
  272. if (!tempDiamond.Equal(0))
  273. {
  274. sb.AppendFormat("{0}{1}{2} ", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.DiamondSprite, Auxiliary.ShrinkNumberStr(tempDiamond));
  275. }
  276. if (!string.IsNullOrEmpty(tempFlower))
  277. {
  278. sb.Append(tempFlower);
  279. }
  280. string str = sb.ToString();
  281. if (!string.IsNullOrEmpty(str))
  282. {
  283. InfoBoxManager.GardenInfoBox.Display(str, 10f, Color.white, ResourceManager.LoadSprite("Atlas", Folder.Atlas));
  284. }
  285. Level++;
  286. AudioManager.PlayClip(AudioLabel.UseSkill);
  287. if (BuyCur == Current.Cash)
  288. {
  289. HttpManager.UploadConfig();
  290. }
  291. GetBuff();
  292. SetActive();
  293. if (getGift)
  294. {
  295. RechargeGiftManager.GetAllRechargeGiftAward(ID);
  296. }
  297. }
  298. protected int MinLevelParse(string str)
  299. {
  300. if (string.IsNullOrEmpty(str))
  301. {
  302. return 0;
  303. }
  304. else
  305. {
  306. return Auxiliary.StringToInt(str.Split(',')[0],0);
  307. }
  308. }
  309. protected int MaxLevelParse(string str)
  310. {
  311. if (string.IsNullOrEmpty(str))
  312. {
  313. return 0;
  314. }
  315. else
  316. {
  317. return Auxiliary.StringToInt(str.Split(',')[1],0);
  318. }
  319. }
  320. protected override string GetDescription(int offset)
  321. {
  322. string[] strings = Desc.Split(TransferLabel.OpenChar, TransferLabel.CloseChar);
  323. StringBuilder stringBuilder = new StringBuilder();
  324. for (int i = 0; i < strings.Length; i++)
  325. {
  326. if (strings[i].Contains(TransferLabel.Level))
  327. {
  328. }
  329. else if (strings[i].Contains(TransferLabel.Coin))
  330. {
  331. #region MyRegion
  332. if (!string.IsNullOrEmpty(CoinFml))
  333. {
  334. stringBuilder.Append(Auxiliary.FmlParse(CoinFml, "l", Manager.GardenLevel.ToString(), "c", Manager.CoinPerson.ToString("0.000")).ToString("0"));
  335. }
  336. #endregion
  337. }
  338. else if (strings[i].Contains(TransferLabel.Flower))
  339. {
  340. #region MyRegion
  341. if (!string.IsNullOrEmpty(Flower))
  342. {
  343. for (int j = 0; j < Flowers.Length; j++)
  344. {
  345. FlowerInfo flowerInfo = GardenManager.FlowerInfoDictionary[int.Parse(Flowers[j])];
  346. stringBuilder.Append(Language.GetStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.FlowerName, flowerInfo.FullID)));
  347. if (j != Flowers.Length - 1)
  348. {
  349. stringBuilder.Append(",");
  350. }
  351. }
  352. }
  353. #endregion
  354. }
  355. else if (strings[i].Contains(TransferLabel.Replace))
  356. {
  357. #region MyRegion
  358. //if (!string.IsNullOrEmpty(Flower))
  359. //{
  360. // for (int j = 0; j < Diamonds.Length; j++)
  361. // {
  362. // stringBuilder.Append(int.Parse(Diamonds[j]));
  363. // if (j != Diamonds.Length - 1)
  364. // {
  365. // stringBuilder.Append(",");
  366. // }
  367. // }
  368. //}
  369. #endregion
  370. }
  371. else if (strings[i].Contains(TransferLabel.Diamond))
  372. {
  373. #region MyRegion
  374. if (!DiamondOnce.Equal(0))
  375. {
  376. stringBuilder.Append(DiamondOnce.ToString("0"));
  377. }
  378. #endregion
  379. }
  380. else if (strings[i].Contains(TransferLabel.CoinPerson))
  381. {
  382. #region MyRegion
  383. if (!Plus.Equal(0))
  384. {
  385. stringBuilder.Append(string.Format("{0:0}%", Plus*100));
  386. }
  387. else if (!CoinPerson.Equal(0))
  388. {
  389. stringBuilder.Append(CoinPerson.ToString("0"));
  390. }
  391. #endregion
  392. }
  393. else
  394. {
  395. stringBuilder.Append(strings[i]);
  396. }
  397. }
  398. return stringBuilder.ToString();
  399. }
  400. }