ManaSign.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Xml;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using Random = UnityEngine.Random;
  9. public class Sign
  10. {
  11. #region 变量
  12. public int Coin
  13. {
  14. get
  15. {
  16. if (RoundBuff.Equal(-1))
  17. {
  18. return Coin_;
  19. }
  20. else
  21. {
  22. return (int)(Coin_*RoundBuff*ManaSign.SignRound);
  23. }
  24. }
  25. set { Coin_ = value; }
  26. }
  27. public int Diamond
  28. {
  29. get
  30. {
  31. if (RoundBuff.Equal(-1))
  32. {
  33. return Diamond_;
  34. }
  35. else
  36. {
  37. return (int)(Diamond_ * RoundBuff * ManaSign.SignRound);
  38. }
  39. }
  40. set { Diamond_ = value; }
  41. }
  42. public int Coin_;
  43. public int Diamond_;
  44. public float RoundBuff;
  45. public bool IsLottery;
  46. public Text Lab1;
  47. public Text Lab2;
  48. public Image Icon;
  49. public Image Mark;
  50. public Vector2 OriginSize;
  51. public List<int> FlowerList = new List<int>();
  52. #endregion
  53. public Sign(int index, Transform tra, XmlAttributeCollection attribute)
  54. {
  55. Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
  56. Auxiliary.CompileDic(tra, dic);
  57. Lab1 = dic["Lab1"].GetComponent<Text>();
  58. Lab2 = dic["Lab2"].GetComponent<Text>();
  59. Icon = dic["Icon1"].GetComponent<Image>();
  60. Mark = dic["Icon2"].GetComponent<Image>();
  61. OriginSize = Icon.rectTransform.sizeDelta;
  62. Lab2.text = index.ToString();
  63. Coin = Auxiliary.IntParse(attribute[4].Value, 0);
  64. IsLottery = Auxiliary.BoolParse(attribute[1].Value, false);
  65. Diamond = Auxiliary.IntParse(attribute[3].Value, 0);
  66. FlowerList = Auxiliary.IntListParse(',', attribute[2].Value, new List<int>());
  67. RoundBuff = Auxiliary.FloatParse(attribute[5].Value, -1);
  68. SetUI();
  69. }
  70. public void Get()
  71. {
  72. if (IsLottery)
  73. {
  74. Lottery.PlayAnimation();
  75. return;
  76. }
  77. ManaAudio.PlayClip(Clip.CurrentClip);
  78. Mark.SetActive(true);
  79. ResetSign();
  80. ManaReso.SetActive("Bb_Get", false);
  81. ManaReso.SetActive("Bb_Rotate", true);
  82. ManaReso.SetActive("Bb_Confirm", true);
  83. if (FlowerList.Valid())
  84. {
  85. for (int i = 0; i < FlowerList.Count; i++)
  86. {
  87. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerList[i]];
  88. if (flowerInfo.Unlock == false)
  89. {
  90. ManaReso.SetText("Bb_InfoLabA", flowerInfo.Name);
  91. ManaReso.SetActive("Bb_IconA", true);
  92. ManaReso.SetSprite("Bb_IconA0", flowerInfo.Icon);
  93. ManaReso.Get<Image>("Bb_IconA0").Resize(true, 0.65f, 0.65f);
  94. flowerInfo.Unlock = true;
  95. return;
  96. }
  97. }
  98. }
  99. if (Diamond > 0)
  100. {
  101. ManaReso.SetText("Bb_InfoLabB", Diamond.ToString());
  102. ManaReso.SetSprite("Bb_IconB", ManaReso.LoadSprite("钻石", Folder.UI));
  103. ManaReso.SetActive("Bb_IconB", true);
  104. ManaCenter.Diamond += Diamond;
  105. }
  106. else if (Coin > 0)
  107. {
  108. ManaReso.SetText("Bb_InfoLabB", Coin.ToString());
  109. ManaReso.SetSprite("Bb_IconB", ManaReso.LoadSprite("金币", Folder.UI));
  110. ManaReso.SetActive("Bb_IconB", true);
  111. ManaCenter.Coin += Coin;
  112. }
  113. else
  114. {
  115. throw new Exception();
  116. }
  117. }
  118. public void SetUI()
  119. {
  120. if (IsLottery)
  121. {
  122. Icon.sprite = ManaReso.LoadSprite("抽奖图标", Folder.UI);
  123. Icon.Resize(true, 0.3f, 0.3f);
  124. return;
  125. }
  126. if (FlowerList.Valid())
  127. {
  128. for (int i = 0; i < FlowerList.Count; i++)
  129. {
  130. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerList[i]];
  131. if (flowerInfo.Unlock == false)
  132. {
  133. Icon.sprite = flowerInfo.Icon;
  134. Icon.Resize(true, 0.15f, 0.15f);
  135. return;
  136. }
  137. }
  138. }
  139. if (Diamond > 0)
  140. {
  141. Icon.sprite = ManaReso.LoadSprite("钻石", Folder.UI);
  142. Icon.Resize(false, OriginSize);
  143. Lab1.text = Diamond.ToString();
  144. }
  145. else if (Coin > 0)
  146. {
  147. Icon.sprite = ManaReso.LoadSprite("金币", Folder.UI);
  148. Icon.Resize(false, OriginSize);
  149. Lab1.text = Coin.ToString();
  150. }
  151. }
  152. public static void ResetSign()
  153. {
  154. ManaSign.SignTime = ManaServer.Time;
  155. ManaSign.SignIndex++;
  156. if (ManaSign.SignIndex == 22)
  157. {
  158. ManaSign.SignIndex = 1;
  159. ManaSign.SignRound++;
  160. ManaReso.Get("B_SignIn").GetTweenCG().AddEventOnetime
  161. (
  162. EventType.BackwardFinish,
  163. () =>
  164. {
  165. foreach (var kv in ManaSign.SignDic)
  166. {
  167. kv.Value.SetUI();
  168. kv.Value.Mark.SetActive(false);
  169. }
  170. }
  171. );
  172. }
  173. }
  174. }
  175. public class Lottery
  176. {
  177. #region Var
  178. public int Type;
  179. public int Value;
  180. public Text Lab;
  181. public Transform BK;
  182. public Image Icon1;
  183. public Image Icon2;
  184. public Button Button;
  185. public static List<int> TypeList = new List<int>();
  186. public static List<int> ValueList = new List<int>();
  187. public static List<float> RateList = new List<float>();
  188. public static List<Vector3> PosList = new List<Vector3>();
  189. public static List<List<int>> LeftBorderDList = new List<List<int>>();
  190. public static List<List<int>> RightBorderDList = new List<List<int>>();
  191. #endregion
  192. public static void Configure(List<XmlAttributeCollection> attributeList)
  193. {
  194. PosList.Add(ManaReso.Get("Bc_LotteryItem1").position);
  195. PosList.Add(ManaReso.Get("Bc_LotteryItem2").position);
  196. PosList.Add(ManaReso.Get("Bc_LotteryItem3").position);
  197. for (int i = 0; i < attributeList.Count; i++)
  198. {
  199. RateList.Add((float) Auxiliary.FmlParse(attributeList[i][2].Value));
  200. TypeList.Add((int) Auxiliary.FmlParse(attributeList[i][1].Value));
  201. List<string> leftBorderStrList = Auxiliary.StringListParse(',', attributeList[i][3].Value, null);
  202. List<string> rightBorderStrList = Auxiliary.StringListParse(',', attributeList[i][4].Value, null);
  203. List<int> leftBorderList = new List<int>();
  204. List<int> rightBorderList = new List<int>();
  205. for (int j = 0; j < leftBorderStrList.Count; j++)
  206. {
  207. leftBorderList.Add((int)Auxiliary.FmlParse(leftBorderStrList[j]));
  208. rightBorderList.Add((int)Auxiliary.FmlParse(rightBorderStrList[j]));
  209. }
  210. LeftBorderDList.Add(leftBorderList);
  211. RightBorderDList.Add(rightBorderList);
  212. }
  213. }
  214. public static void CreateLottery(Transform lotteryItem)
  215. {
  216. Lottery lottery = new Lottery();
  217. #region 默认值
  218. lottery.Type = TypeList[0];
  219. lottery.Value = Random.Range(LeftBorderDList[0][0], RightBorderDList[0][0] + 1);
  220. #endregion
  221. float random = Random.Range(0f, 1f);
  222. for (int i = 0; i < RateList.Count; i++)
  223. {
  224. if (random <= RateList.MySum(f => f, i + 1))
  225. {
  226. lottery.Type = TypeList[i];
  227. if (lottery.Type == 3)
  228. {
  229. #region
  230. bool allUnlock = true;
  231. for (int j = 0; j < LeftBorderDList[i].Count; j++)
  232. {
  233. for (int k = LeftBorderDList[i][j]; k < RightBorderDList[i][j] + 1; k++)
  234. {
  235. if (!ManaGarden.FlowerInfoDic[k].Unlock && !ValueList.Contains(k))
  236. {
  237. allUnlock = false;
  238. goto exit;
  239. }
  240. }
  241. }
  242. exit :
  243. if (allUnlock)
  244. {
  245. int index = Random.Range(0, LeftBorderDList[i].Count);
  246. lottery.Value = Random.Range(LeftBorderDList[i][index], RightBorderDList[i][index] + 1);
  247. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[lottery.Value];
  248. lottery.Value = flowerInfo.UnlockAmt/5;
  249. if (flowerInfo.UnlockCur == Current.Coin)
  250. {
  251. lottery.Type = 1;
  252. }
  253. else if (flowerInfo.UnlockCur == Current.Diamond)
  254. {
  255. lottery.Type = 2;
  256. }
  257. }
  258. else
  259. {
  260. int anticrush = 0;
  261. do
  262. {
  263. if (anticrush++>10000)
  264. {
  265. throw new Exception();
  266. }
  267. int index = Random.Range(0, LeftBorderDList[i].Count);
  268. lottery.Value = Random.Range(LeftBorderDList[i][index], RightBorderDList[i][index] + 1);
  269. }
  270. while (ManaGarden.FlowerInfoDic[lottery.Value].Unlock || ValueList.Contains(lottery.Value));
  271. ValueList.Add(lottery.Value);
  272. }
  273. #endregion
  274. }
  275. else if (lottery.Type == 4)
  276. {
  277. #region
  278. bool allBought = true;
  279. for (int j = 0; j < LeftBorderDList[i].Count; j++)
  280. {
  281. for (int k = LeftBorderDList[i][j]; k < RightBorderDList[i][j] + 1; k++)
  282. {
  283. if (!ManaPlayer.CloseUnitDic[k].Bought && !ValueList.Contains(k))
  284. {
  285. allBought = false;
  286. goto exit;
  287. }
  288. }
  289. }
  290. exit :
  291. if (allBought)
  292. {
  293. int index = Random.Range(0, LeftBorderDList[i].Count);
  294. lottery.Value = Random.Range(LeftBorderDList[i][index], RightBorderDList[i][index] + 1);
  295. CloseUnit closeUnit = ManaPlayer.CloseUnitDic[lottery.Value];
  296. lottery.Value = (int) closeUnit.BuyAmt/5;
  297. if (closeUnit.BuyCurrent == Current.Coin)
  298. {
  299. lottery.Type = 1;
  300. }
  301. else if (closeUnit.BuyCurrent == Current.Diamond)
  302. {
  303. lottery.Type = 2;
  304. }
  305. }
  306. else
  307. {
  308. int anticrush = 0;
  309. do
  310. {
  311. if (anticrush++ > 10000)
  312. {
  313. throw new Exception();
  314. }
  315. int index = Random.Range(0, LeftBorderDList[i].Count);
  316. lottery.Value = Random.Range(LeftBorderDList[i][index], RightBorderDList[i][index] + 1);
  317. }
  318. while (ManaPlayer.CloseUnitDic[lottery.Value].Bought || ValueList.Contains(lottery.Value));
  319. ValueList.Add(lottery.Value);
  320. }
  321. #endregion
  322. }
  323. else
  324. {
  325. int index = Random.Range(0, LeftBorderDList[i].Count);
  326. lottery.Value = Random.Range(LeftBorderDList[i][index], RightBorderDList[i][index] + 1);
  327. }
  328. break;
  329. }
  330. }
  331. lottery.BK = lotteryItem.GetChild(0);
  332. lottery.Icon1 = lotteryItem.GetChild(1).GetChild(0).GetComponent<Image>();
  333. lottery.Icon2 = lotteryItem.GetChild(1).GetChild(1).GetComponent<Image>();
  334. lottery.Lab = lotteryItem.GetChild(1).GetChild(2).GetComponent<Text>();
  335. lottery.Button = lotteryItem.GetChild(1).GetChild(3).GetComponent<Button>();
  336. lottery.BK.SetActive(false);
  337. if (lottery.Type == 1)
  338. {
  339. lottery.Icon1.SetActive(false);
  340. lottery.Icon2.sprite = ManaReso.LoadSprite("金币", Folder.UI);
  341. lottery.Icon2.Resize(true, 1, 1);
  342. lottery.Icon2.transform.localPosition = new Vector3(0, 7.5f, 0);
  343. lottery.Lab.SetActive(true);
  344. lottery.Lab.text = lottery.Value.ToString();
  345. }
  346. else if (lottery.Type == 2)
  347. {
  348. lottery.Icon1.SetActive(false);
  349. lottery.Icon2.sprite = ManaReso.LoadSprite("钻石", Folder.UI);
  350. lottery.Icon2.Resize(true, 1, 1);
  351. lottery.Icon2.transform.localPosition = new Vector3(0, 7.5f, 0);
  352. lottery.Lab.SetActive(true);
  353. lottery.Lab.text = lottery.Value.ToString();
  354. }
  355. else if (lottery.Type == 3)
  356. {
  357. lottery.Icon1.SetActive(false);
  358. lottery.Icon2.sprite = ManaGarden.FlowerInfoDic[lottery.Value].Icon;
  359. lottery.Icon2.Resize(true, 0.25f, 0.25f);
  360. lottery.Icon2.transform.localPosition = new Vector3();
  361. lottery.Lab.SetActive(false);
  362. }
  363. else if (lottery.Type == 4)
  364. {
  365. CloseUnit closeUnit = ManaPlayer.CloseUnitDic[lottery.Value];
  366. float newSize = closeUnit.PixelSize / closeUnit.Sprites[0].rect.width;
  367. lottery.Icon2.sprite = closeUnit.Sprites[0];
  368. lottery.Icon2.Resize(true, newSize, newSize);
  369. lottery.Icon2.transform.localPosition = new Vector2(0, closeUnit.IconOffset);
  370. lottery.Lab.SetActive(false);
  371. if (closeUnit.Sprites.Length>1)
  372. {
  373. lottery.Icon1.SetActive(true);
  374. lottery.Icon1.sprite = closeUnit.Sprites[1];
  375. lottery.Icon1.Resize(true, newSize, newSize);
  376. lottery.Icon1.transform.localPosition = new Vector2(0, closeUnit.IconOffset) + closeUnit.IconOffset1*newSize;
  377. }
  378. else
  379. {
  380. lottery.Icon1.SetActive(false);
  381. }
  382. }
  383. lottery.Button.onClick = new Button.ButtonClickedEvent();
  384. lottery.Button.onClick.AddListener
  385. (
  386. () =>
  387. {
  388. ManaAudio.PlayClip(Clip.CurrentClip);
  389. ManaReso.Get<Button>("Bc_LotteryBack1").interactable = false;
  390. ManaReso.Get<Button>("Bc_LotteryBack2").interactable = false;
  391. ManaReso.Get<Button>("Bc_LotteryBack3").interactable = false;
  392. lotteryItem.TweenBacEuler();
  393. lottery.BK.SetActive(true);
  394. lottery.GetAward();
  395. Auxiliary.Instance.DelayCall
  396. (
  397. () =>
  398. {
  399. ManaReso.Get("Bc_Confirm").TweenForCG();
  400. ManaReso.Get("Bc_LotteryItem1").TweenBacEuler();
  401. ManaReso.Get("Bc_LotteryItem2").TweenBacEuler();
  402. ManaReso.Get("Bc_LotteryItem3").TweenBacEuler();
  403. },
  404. 1f
  405. );
  406. }
  407. );
  408. }
  409. public static void PlayAnimation()
  410. {
  411. ManaReso.Get("Bc_Lottery").TweenForCG();
  412. ManaReso.Get("Ba_Notice0").TweenBacCG();
  413. CreateLottery(ManaReso.Get("Bc_LotteryItem1"));
  414. CreateLottery(ManaReso.Get("Bc_LotteryItem2"));
  415. CreateLottery(ManaReso.Get("Bc_LotteryItem3"));
  416. Button button1 = ManaReso.Get<Button>("Bc_LotteryBack1");
  417. Button button2 = ManaReso.Get<Button>("Bc_LotteryBack2");
  418. Button button3 = ManaReso.Get<Button>("Bc_LotteryBack3");
  419. button1.interactable = false;
  420. button2.interactable = false;
  421. button3.interactable = false;
  422. Auxiliary.Instance.DelayCall
  423. (
  424. () =>
  425. {
  426. ManaReso.Get("Bc_LotteryItem1").Move2D(PosList[1], 0.25f, false, Curve.EaseOutQuad);
  427. ManaReso.Get("Bc_LotteryItem2").Move2D(PosList[1], 0.25f, false, Curve.EaseOutQuad);
  428. ManaReso.Get("Bc_LotteryItem3").Move2D(PosList[1], 0.25f, false, Curve.EaseOutQuad);
  429. },
  430. 1f
  431. );
  432. Auxiliary.Instance.DelayCall
  433. (
  434. () =>
  435. {
  436. ManaReso.Get("Bc_LotteryItem1").TweenForEuler();
  437. ManaReso.Get("Bc_LotteryItem2").TweenForEuler();
  438. ManaReso.Get("Bc_LotteryItem3").TweenForEuler();
  439. },
  440. 1.5f
  441. );
  442. Auxiliary.Instance.DelayCall
  443. (
  444. () =>
  445. {
  446. button1.interactable = true;
  447. button2.interactable = true;
  448. button3.interactable = true;
  449. List<Vector3> posList = PosList.Disturb();
  450. ManaReso.Get("Bc_LotteryItem1").Move2D(posList[0], 0.25f, false, Curve.EaseOutQuad);
  451. ManaReso.Get("Bc_LotteryItem2").Move2D(posList[1], 0.25f, false, Curve.EaseOutQuad);
  452. ManaReso.Get("Bc_LotteryItem3").Move2D(posList[2], 0.25f, false, Curve.EaseOutQuad);
  453. },
  454. 2f
  455. );
  456. Auxiliary.Instance.DelayCall
  457. (
  458. () =>
  459. {
  460. ManaReso.Get("Bc_Lab").TweenForCG();
  461. ManaReso.SetText("Bc_Lab", Language.GetStr("UI", "Bc_Lab"));
  462. },
  463. 2.5f
  464. );
  465. }
  466. public static void EndLottery()
  467. {
  468. ValueList = new List<int>();
  469. ManaReso.Get("Bc_Lab").TweenBacCG();
  470. ManaReso.Get("Bc_Confirm").TweenBacCG();
  471. ManaReso.Get("Ba_Notice0").TweenForCG();
  472. ManaReso.Get("B_SignIn").TweenBacCG();
  473. ManaReso.Get("Ba_Notice").TweenBacCG();
  474. ManaReso.Get("Bb_SignIn").TweenBacCG();
  475. ManaReso.Get("Bc_Lottery").TweenBacCG();
  476. ManaAudio.PlayClip(Clip.BtnClip);
  477. }
  478. public void GetAward()
  479. {
  480. Sign.ResetSign();
  481. BK.SetActive(true);
  482. if (Type == 1)
  483. {
  484. ManaCenter.Coin += Value;
  485. ManaReso.SetText("Bc_Lab", Language.GetStr("UI", "Bc_Lab1") + Language.GetStr("Common", "Coin") + Value);
  486. }
  487. else if (Type == 2)
  488. {
  489. ManaCenter.Diamond += Value;
  490. ManaReso.SetText("Bc_Lab", Language.GetStr("UI", "Bc_Lab1") + Language.GetStr("Common", "Diamond") + Value);
  491. }
  492. else if (Type == 3)
  493. {
  494. ManaGarden.FlowerInfoDic[Value].Unlock = true;
  495. ManaReso.SetText("Bc_Lab", Language.GetStr("UI", "Bc_Lab1") + ManaGarden.FlowerInfoDic[Value].Name);
  496. }
  497. else if (Type == 4)
  498. {
  499. ManaPlayer.CloseUnitDic[Value].Unlock();
  500. ManaPlayer.BoughtCloseList.UniqueAdd(Value);
  501. ManaReso.SetText("Bc_Lab", Language.GetStr("UI", "Bc_Lab1") + ManaPlayer.CloseUnitDic[Value].ArmatureName);
  502. }
  503. }
  504. }
  505. public class ManaSign : Regist
  506. {
  507. #region 变量
  508. public static int SignIndex;
  509. public static int SignRound;
  510. public static DateTime SignTime;
  511. public static Dictionary<int, Sign> SignDic = new Dictionary<int, Sign>();
  512. #endregion
  513. public static void Get()
  514. {
  515. SignDic[SignIndex].Get();
  516. ManaCenter.SignAmt++;
  517. }
  518. public override void RegistValueB()
  519. {
  520. SignTime = DateTime.Parse(ManaData.GetPlayerString("SignTime"));
  521. SignIndex = ManaData.GetPlayerInt("SignIndex");
  522. SignRound = ManaData.GetPlayerInt("SignRound");
  523. Transform par = ManaReso.Get("Bb_Grid");
  524. List<XmlAttributeCollection> attributeList = ManaData.GetSignConfig();
  525. for (int i = 0; i < attributeList.Count; i++)
  526. {
  527. Transform tra = ManaReso.Get("SignItem", Folder.UI, false, par, false, ObjType.SignItem);
  528. SignDic.Add(i + 1, new Sign(i + 1, tra, attributeList[i]));
  529. }
  530. for (int i = 1; i < SignIndex; i++)
  531. {
  532. SignDic[i].Mark.SetActive(true);
  533. }
  534. Lottery.Configure(ManaData.GetLotteryConfig());
  535. }
  536. }
  537. #region DebugList
  538. //签到的循环与存档
  539. #endregion