Pack.cs 9.4 KB

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