Pack.cs 9.5 KB

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