Pack.cs 10 KB

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