Pack.cs 10 KB

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