Pack.cs 10 KB

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