Pack.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. protected int MinUseLv;
  12. protected int MaxUseLv;
  13. protected float Person;
  14. protected float SkillCD;
  15. protected float UseAmt;
  16. protected float CoinOnce;
  17. protected float CoinPerson;
  18. protected float DiamondOnce;
  19. protected float Plus;
  20. protected float PersonBuff;
  21. protected float SkillCdBuff;
  22. protected string Label;
  23. protected string Anim;
  24. protected string Flower;
  25. protected Current BuyCur;
  26. #endregion
  27. public SkillStatus _ItemStatus;
  28. public SkillStatus ItemStatus
  29. {
  30. get { return _ItemStatus; }
  31. set
  32. {
  33. _ItemStatus = value;
  34. if (_ItemStatus == SkillStatus.Buy)
  35. {
  36. ItemBtn.interactable = true;
  37. ManaText.Add(ItemBtnLab, ImageParse(BuyCur), UseAmt.ToString("0"), "\n", new LanStr("UI", "Fe_BtnLab3"));
  38. }
  39. else if (_ItemStatus == SkillStatus.Lock)
  40. {
  41. ItemBtn.interactable = false;
  42. ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab5"), "\n", new LanStr("UI", "Fe_BtnLab4"), MinUseLv.ToString(), "-", MaxUseLv.ToString());
  43. }
  44. else
  45. {
  46. throw new Exception(_ItemStatus.ToString());
  47. }
  48. }
  49. }
  50. #endregion
  51. public Pack(XmlAttributeCollection attribute)
  52. {
  53. #region 配置
  54. ID = int.Parse(attribute[0].Value);
  55. Icon = attribute[14].Value;
  56. Anim = attribute[15].Value;
  57. Label = attribute[16].Value;
  58. _Name = "Pack" + ID;
  59. Flower = attribute[9].Value;
  60. ClassID = IntParse(attribute[3].Value);
  61. UseAmt = FloatParse(attribute[12].Value);
  62. CoinOnce = FloatParse(attribute[7].Value);
  63. DiamondOnce = FloatParse(attribute[8].Value);
  64. SkillTab = SkillClassParse(attribute[2].Value);
  65. BuyCur = CurrentParse(attribute[11].Value);
  66. MinUseLv = MinLevelParse(attribute[10].Value);
  67. MaxUseLv = MaxLevelParse(attribute[10].Value);
  68. ValueBuffParse(out Person, out PersonBuff, attribute[5].Value);
  69. ValueBuffParse(out SkillCD, out SkillCdBuff, attribute[6].Value);
  70. ValueBuffParse(out CoinPerson, out Plus, attribute[4].Value);
  71. #endregion
  72. SkillType = SkillType.Pack;
  73. }
  74. public override void RegistValue(float elapse, List<List<SkillRoot>> ffList, XmlAttributeCollection attribute)
  75. {
  76. Level = int.Parse(attribute[3].Value);
  77. _ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  78. ManaText.Add(ItemTit, new LanStr("SkillName", _Name));
  79. ItemLab.text = Description(0);
  80. ItemBtn.onClick.AddListener(OnClick);
  81. for (int i = 0; i < Level; i++)
  82. {
  83. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁 等级 : {1}", Name, Level));
  84. UseConti();
  85. }
  86. }
  87. public override void UpdateStatus()
  88. {
  89. if (MaxUseLv == MinUseLv)
  90. {
  91. ItemStatus = SkillStatus.Buy;
  92. }
  93. else
  94. {
  95. if (ManaData.Level > MaxUseLv || ManaData.Level < MinUseLv)
  96. {
  97. ItemStatus = SkillStatus.Lock;
  98. }
  99. else
  100. {
  101. ItemStatus = SkillStatus.Buy;
  102. }
  103. }
  104. }
  105. protected void OnClick()
  106. {
  107. if (ManaData.Connect == false)
  108. {
  109. ManaReso.Get("Fg_Reconnect").TweenForCG();
  110. return;
  111. }
  112. ManaReso.Get("Fe_Info").TweenForCG();
  113. ManaReso.SetText("Fe_Tit", Name);
  114. ManaReso.SetSprite("Fe_Icon", ItemIcon.sprite);
  115. ManaReso.SetText("Fe_Lab0", "");
  116. if (ItemStatus == SkillStatus.Buy)
  117. {
  118. ManaReso.SetText("Fe_Lab1", Description(0));
  119. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), ImageParse(BuyCur), UseAmt));
  120. ManaReso.SetButtonEvent
  121. (
  122. "Fe_Btn",
  123. () =>
  124. {
  125. Buy();
  126. ManaReso.Get("Fe_Info").TweenBacCG();
  127. }
  128. );
  129. }
  130. else
  131. {
  132. throw new Exception();
  133. }
  134. }
  135. protected virtual void Buy()
  136. {
  137. if (ManaData.Pay(UseAmt, BuyCur))
  138. {
  139. ManaData.Skill++;
  140. #region 调试输出
  141. StringBuilder strb = new StringBuilder();
  142. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  143. if (Math.Abs(Plus) > 0.0005f)
  144. {
  145. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", Plus * 100);
  146. }
  147. if (Math.Abs(Person) > 0.0005f)
  148. {
  149. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", Person);
  150. }
  151. if (Math.Abs(PersonBuff) > 0.0005f)
  152. {
  153. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", PersonBuff * 100);
  154. }
  155. if (Math.Abs(CoinPerson) > 0.0005f)
  156. {
  157. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", CoinPerson);
  158. }
  159. if (Math.Abs(SkillCD) > 0.0005f)
  160. {
  161. strb.AppendFormat(" 减少冷却上限<color=red>{0}</color>", SkillCD);
  162. }
  163. if (Math.Abs(SkillCdBuff) > 0.0005f)
  164. {
  165. strb.AppendFormat(" 减少冷却上限<color=red>{0}%</color>", SkillCdBuff * 100);
  166. }
  167. if (Math.Abs(CoinOnce) > 0.0005f)
  168. {
  169. strb.AppendFormat(" 获得金币<color=red>{0}</color>", CoinOnce);
  170. }
  171. if (Math.Abs(DiamondOnce) > 0.0005f)
  172. {
  173. strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
  174. }
  175. if (!string.IsNullOrEmpty(Flower))
  176. {
  177. string[] strings = Flower.Split(' ');
  178. for (int i = 0; i < strings.Length; i++)
  179. {
  180. strb.AppendFormat(" 获得<color=red>{0}</color>", ManaGarden.FlowerInfoList[int.Parse(strings[i])].Name);
  181. }
  182. }
  183. strb.Append(" <color=red>永久有效</color>");
  184. ManaDebug.Log(strb.ToString());
  185. #endregion
  186. UseConti();
  187. UseImmed();
  188. Level++;
  189. }
  190. }
  191. protected void UseConti()
  192. {
  193. if (!string.IsNullOrEmpty(Flower))
  194. {
  195. string[] strings = Flower.Split(' ');
  196. for (int i = 0; i < strings.Length; i++)
  197. {
  198. FlowerInfo flowerInfo = ManaGarden.FlowerInfoList[int.Parse(strings[i])];
  199. if (flowerInfo.Unlock == false)
  200. {
  201. flowerInfo.Unlock = true;
  202. }
  203. }
  204. }
  205. ManaData.SkillPlus += Plus;
  206. ManaData.SkillPerson += Person;
  207. ManaData.SkillPersonBuff += PersonBuff;
  208. ManaData.SkillCoinPerson += CoinPerson;
  209. if (Math.Abs(SkillCD) > 0.0005f)
  210. {
  211. for (int i = 0; i < ManaData.SkillList.Count; i++)
  212. {
  213. ManaData.SkillList[i].ReceiveCool(SkillCD, false, false);
  214. }
  215. }
  216. if (Math.Abs(SkillCdBuff) > 0.0005f)
  217. {
  218. for (int i = 0; i < ManaData.SkillList.Count; i++)
  219. {
  220. ManaData.SkillList[i].ReceiveCool(SkillCdBuff, false, true);
  221. }
  222. }
  223. }
  224. protected void UseImmed()
  225. {
  226. ManaData.Coin += CoinOnce;
  227. ManaData.Diamond += DiamondOnce;
  228. }
  229. #region 解读器
  230. protected int MinLevelParse(string str)
  231. {
  232. if (string.IsNullOrEmpty(str))
  233. {
  234. return 0;
  235. }
  236. else
  237. {
  238. return IntParse(str.Split(',')[0]);
  239. }
  240. }
  241. protected int MaxLevelParse(string str)
  242. {
  243. if (string.IsNullOrEmpty(str))
  244. {
  245. return 0;
  246. }
  247. else
  248. {
  249. return IntParse(str.Split(',')[1]);
  250. }
  251. }
  252. protected override string Description(int offset)
  253. {
  254. string[] strings = Desc.Split('[', ']');
  255. StringBuilder stringBuilder = new StringBuilder();
  256. for (int i = 0; i < strings.Length; i++)
  257. {
  258. if (strings[i].Contains("lv"))
  259. {
  260. }
  261. else if (strings[i].Contains("&coin&"))
  262. {
  263. #region MyRegion
  264. if (Math.Abs(CoinOnce) > 0.0005f)
  265. {
  266. stringBuilder.Append(CoinOnce.ToString("0"));
  267. }
  268. #endregion
  269. }
  270. else if (strings[i].Contains("&flower&"))
  271. {
  272. #region MyRegion
  273. if (!string.IsNullOrEmpty(Flower))
  274. {
  275. string[] strings1 = Flower.Split(' ');
  276. for (int j = 0; j < strings1.Length; j++)
  277. {
  278. stringBuilder.Append(Language.GetStr("FlowerName", "Flower" + strings1[j]));
  279. if (j != strings1.Length - 1)
  280. {
  281. stringBuilder.Append(",");
  282. }
  283. }
  284. }
  285. #endregion
  286. }
  287. else if (strings[i].Contains("&diamond&"))
  288. {
  289. #region MyRegion
  290. if (Math.Abs(DiamondOnce) > 0.0005f)
  291. {
  292. stringBuilder.Append(DiamondOnce.ToString("0"));
  293. }
  294. #endregion
  295. }
  296. else if (strings[i].Contains("&coin_person&"))
  297. {
  298. #region MyRegion
  299. if (Math.Abs(Plus) > 0.0005f)
  300. {
  301. stringBuilder.Append(string.Format("{0:0}%", Plus*100));
  302. }
  303. else if (Math.Abs(CoinPerson) > 0.0005f)
  304. {
  305. stringBuilder.Append(CoinPerson.ToString("0.0"));
  306. }
  307. #endregion
  308. }
  309. else
  310. {
  311. stringBuilder.Append(strings[i]);
  312. }
  313. }
  314. return stringBuilder.ToString();
  315. }
  316. #endregion
  317. }