Pack.cs 10 KB

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