Pack.cs 14 KB

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