Pack.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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.SetText("Fe_Lab0", "");
  115. if (ItemStatus == SkillStatus.Buy)
  116. {
  117. ManaReso.SetText("Fe_Lab1", Description(0));
  118. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), ImageParse(BuyCur), UseAmt));
  119. ManaReso.SetButtonEvent
  120. (
  121. "Fe_Btn",
  122. () =>
  123. {
  124. Buy();
  125. ManaReso.Get("Fe_Info").TweenBacCG();
  126. }
  127. );
  128. }
  129. else
  130. {
  131. throw new Exception();
  132. }
  133. }
  134. protected virtual void Buy()
  135. {
  136. if (ManaData.Pay(UseAmt, BuyCur))
  137. {
  138. ManaData.Skill++;
  139. #region 调试输出
  140. StringBuilder strb = new StringBuilder();
  141. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  142. if (Math.Abs(Plus) > 0.0005f)
  143. {
  144. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", Plus * 100);
  145. }
  146. if (Math.Abs(Person) > 0.0005f)
  147. {
  148. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", Person);
  149. }
  150. if (Math.Abs(PersonBuff) > 0.0005f)
  151. {
  152. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", PersonBuff * 100);
  153. }
  154. if (Math.Abs(CoinPerson) > 0.0005f)
  155. {
  156. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", CoinPerson);
  157. }
  158. if (Math.Abs(SkillCD) > 0.0005f)
  159. {
  160. strb.AppendFormat(" 减少冷却上限<color=red>{0}</color>", SkillCD);
  161. }
  162. if (Math.Abs(SkillCdBuff) > 0.0005f)
  163. {
  164. strb.AppendFormat(" 减少冷却上限<color=red>{0}%</color>", SkillCdBuff * 100);
  165. }
  166. if (Math.Abs(CoinOnce) > 0.0005f)
  167. {
  168. strb.AppendFormat(" 获得金币<color=red>{0}</color>", CoinOnce);
  169. }
  170. if (Math.Abs(DiamondOnce) > 0.0005f)
  171. {
  172. strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
  173. }
  174. if (!string.IsNullOrEmpty(Flower))
  175. {
  176. string[] strings = Flower.Split(' ');
  177. for (int i = 0; i < strings.Length; i++)
  178. {
  179. strb.AppendFormat(" 获得<color=red>{0}</color>", ManaGarden.FlowerInfoList[int.Parse(strings[i])].Name);
  180. }
  181. }
  182. strb.Append(" <color=red>永久有效</color>");
  183. ManaDebug.Log(strb.ToString());
  184. #endregion
  185. UseConti();
  186. UseImmed();
  187. Level++;
  188. }
  189. }
  190. protected void UseConti()
  191. {
  192. if (!string.IsNullOrEmpty(Flower))
  193. {
  194. string[] strings = Flower.Split(' ');
  195. for (int i = 0; i < strings.Length; i++)
  196. {
  197. FlowerInfo flowerInfo = ManaGarden.FlowerInfoList[int.Parse(strings[i])];
  198. if (flowerInfo.Unlock == false)
  199. {
  200. flowerInfo.Unlock = true;
  201. }
  202. }
  203. }
  204. ManaData.SkillPlus += Plus;
  205. ManaData.SkillPerson += Person;
  206. ManaData.SkillPersonBuff += PersonBuff;
  207. ManaData.SkillCoinPerson += CoinPerson;
  208. if (Math.Abs(SkillCD) > 0.0005f)
  209. {
  210. for (int i = 0; i < ManaData.SkillList.Count; i++)
  211. {
  212. ManaData.SkillList[i].ReceiveCool(SkillCD, false, false);
  213. }
  214. }
  215. if (Math.Abs(SkillCdBuff) > 0.0005f)
  216. {
  217. for (int i = 0; i < ManaData.SkillList.Count; i++)
  218. {
  219. ManaData.SkillList[i].ReceiveCool(SkillCdBuff, false, true);
  220. }
  221. }
  222. }
  223. protected void UseImmed()
  224. {
  225. ManaData.Coin += CoinOnce;
  226. ManaData.Diamond += DiamondOnce;
  227. }
  228. #region 解读器
  229. protected int MinLevelParse(string str)
  230. {
  231. if (string.IsNullOrEmpty(str))
  232. {
  233. return 0;
  234. }
  235. else
  236. {
  237. return IntParse(str.Split(',')[0]);
  238. }
  239. }
  240. protected int MaxLevelParse(string str)
  241. {
  242. if (string.IsNullOrEmpty(str))
  243. {
  244. return 0;
  245. }
  246. else
  247. {
  248. return IntParse(str.Split(',')[1]);
  249. }
  250. }
  251. protected override string Description(int offset)
  252. {
  253. string[] strings = Desc.Split('[', ']');
  254. StringBuilder stringBuilder = new StringBuilder();
  255. for (int i = 0; i < strings.Length; i++)
  256. {
  257. if (strings[i].Contains("lv"))
  258. {
  259. }
  260. else if (strings[i].Contains("&coin&"))
  261. {
  262. #region MyRegion
  263. if (Math.Abs(CoinOnce) > 0.0005f)
  264. {
  265. stringBuilder.Append(CoinOnce.ToString("0"));
  266. }
  267. #endregion
  268. }
  269. else if (strings[i].Contains("&flower&"))
  270. {
  271. #region MyRegion
  272. if (!string.IsNullOrEmpty(Flower))
  273. {
  274. string[] strings1 = Flower.Split(' ');
  275. for (int j = 0; j < strings1.Length; j++)
  276. {
  277. stringBuilder.Append(Language.GetStr("FlowerName", "Flower" + strings1[j]));
  278. if (j != strings1.Length - 1)
  279. {
  280. stringBuilder.Append(",");
  281. }
  282. }
  283. }
  284. #endregion
  285. }
  286. else if (strings[i].Contains("&diamond&"))
  287. {
  288. #region MyRegion
  289. if (Math.Abs(DiamondOnce) > 0.0005f)
  290. {
  291. stringBuilder.Append(DiamondOnce.ToString("0"));
  292. }
  293. #endregion
  294. }
  295. else if (strings[i].Contains("&coin_person&"))
  296. {
  297. #region MyRegion
  298. if (Math.Abs(Plus) > 0.0005f)
  299. {
  300. stringBuilder.Append(string.Format("{0:0}%", Plus*100));
  301. }
  302. else if (Math.Abs(CoinPerson) > 0.0005f)
  303. {
  304. stringBuilder.Append(CoinPerson.ToString("0.0"));
  305. }
  306. #endregion
  307. }
  308. else
  309. {
  310. stringBuilder.Append(strings[i]);
  311. }
  312. }
  313. return stringBuilder.ToString();
  314. }
  315. #endregion
  316. }