Roxaq

ConjurationTable

Nov 10th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.02 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.SceneManagement;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7.  
  8.  
  9. public class ConjurationTable : MonoBehaviour
  10. {
  11.  
  12. AudioController audio;
  13.  
  14. public GameObject[] ElementalCardDeck;
  15. public GameObject[] BattleCardsDeck;
  16. private GameObject[] ElementalRepositionCardsDeck = new GameObject[6];
  17. public GameObject[] SpecialCardDeck;
  18. public GameObject[] GameCardDeck;
  19.  
  20. GameObject ChatWindow;
  21. Animator FadeConjur;
  22. GameObject FadeConjurOBJ;
  23.  
  24. public bool CanLoadScene;
  25. public Transform[] WarriorPosition;
  26.  
  27. public List<GameObject> repositionCards = new List<GameObject>();
  28.  
  29. private GameObject[] cardsElemental = new GameObject[24];
  30.  
  31. private Vector3[] elementalCardPositions = new Vector3[24];
  32. private Vector3[] repositionCardsPositions = new Vector3[6];
  33. public Transform[] specialCardsPositions;
  34. public Transform resultCardposition;
  35. public GameObject[] inventoryCards = new GameObject[5];
  36. private int[] transformRandomPosition = new int[24];
  37. public GameObject cardHolder;
  38.  
  39. public WarriorCardPlace[] warriorCardPlaces;
  40.  
  41. public int[] respawnCardsIds;
  42. public int CardIdTest;
  43. public int cardsToRespawn;
  44. private int specialCardsID;
  45.  
  46. //Variaveis do tempo de conjuração
  47. public float _ConjurationTimer;
  48.  
  49. //Variaveis para limitação de cartas conjuradas
  50. private int CardNumber;
  51. private int _InventoryCardNumber;
  52. private int _MaxInventoryCardNumber;
  53. public bool _CanConjurate;
  54. public bool debugMode;
  55.  
  56. //Variaveis de inventarios
  57. private int _ConjurationDeckIndex;
  58. private int _BattleDeckIndex;
  59.  
  60. //Interface
  61. public Text _textConjurationTimer;
  62.  
  63. public ConjurationData _DATAHOLDER;
  64. public ConcentrationEnhancer concentrationLink;
  65. public ConjurationCombiner conjurationLink;
  66. private MAINDATABATTLE mDATA;
  67.  
  68. // Use this for initialization///////////////////////////////////////////////////////////////
  69. //mudei o nome dessa funcao ela era o teu Start, agora ela é chamada quando eu sei que os dois jogadores estao na mesma sala
  70. /// <summary>
  71. ///
  72.  
  73. void Awake()
  74. {
  75. audio = GameObject.FindWithTag("AudioController").GetComponent<AudioController>();
  76. concentrationLink = GameObject.Find("TableObject").GetComponent<ConcentrationEnhancer>();
  77. conjurationLink = GameObject.FindWithTag("TableMaster").GetComponent<ConjurationCombiner>();
  78. try
  79. {
  80. _DATAHOLDER = GameObject.Find("DataHolder").GetComponent<ConjurationData>();
  81. }
  82. catch (Exception e)
  83. {
  84. debugMode = true;
  85. print("nao existe data");
  86. }
  87. }
  88.  
  89. public void Start()
  90. {
  91. audio.CONJURTABLE();
  92. ChatWindow = GameObject.FindWithTag("CanvasChat");
  93. cardHolder = new GameObject("Card Holder");
  94. specialCardsID = PlayerPrefs.GetInt("SETSELECTED");
  95. FadeConjurOBJ = GameObject.FindWithTag("FadeConjur");
  96. FadeConjurOBJ.SetActive(true);
  97. FadeConjur = GameObject.FindWithTag("FadeConjur").GetComponent<Animator>();
  98. FadeConjur.enabled = true;
  99. FadeConjur.Play("FadeConjur_back");
  100.  
  101. if (debugMode)
  102. {
  103. _ConjurationTimer = 200;
  104. CardNumber = 0;
  105. }
  106. else {
  107. _DATAHOLDER.ResetCardNumber();
  108. _ConjurationTimer = _DATAHOLDER.GetConjurationTime();
  109. _MaxInventoryCardNumber = _DATAHOLDER.GetMaxCards();
  110. }
  111.  
  112. if (!debugMode)
  113. {
  114. if (CheckBattleCardsReturn())
  115. {
  116. print("Retorno de cartas");
  117. //Retorna as cartas de combate que permaneceram na lista na mesa de batalha
  118. GetBattleCards();
  119. }
  120. }
  121.  
  122. //Função para recuperar o valor do timer no matchmaking;
  123.  
  124. _CanConjurate = true;
  125.  
  126. SpawnElementalCardsRepository();
  127. RandomPositionGenerator();
  128. GeneratePositions();
  129. CardGenerator();
  130. PlaceCards();
  131. PlaceSpecialCards();
  132. }
  133.  
  134. //------------------------
  135. //Controladores (limits)
  136.  
  137. void Update()
  138. {
  139. TimerController();
  140. DeckController();
  141. }
  142.  
  143. void TimerController()
  144. {
  145. if (_ConjurationTimer > 0)
  146. {
  147. _textConjurationTimer.text = ("" + (int)_ConjurationTimer);
  148. _ConjurationTimer -= Time.deltaTime;
  149. }
  150. else
  151. {
  152. BattleScene();
  153. }
  154. }
  155.  
  156. void DeckController()
  157. {
  158. if(CardNumber > 7)
  159. {
  160. _CanConjurate = false;
  161. }
  162. }
  163.  
  164. //Controladores (limits)
  165. //------------------------
  166. //Transformers
  167.  
  168. void RandomPositionGenerator()
  169. {
  170.  
  171. for (int i = 0; i < transformRandomPosition.Length; i++)
  172. {
  173. transformRandomPosition[i] = i;
  174. }
  175.  
  176. transformRandomPosition = KnuthShuffle(transformRandomPosition);
  177. }
  178.  
  179. void GeneratePositions()
  180. {
  181. for (int i = 0; i < elementalCardPositions.Length; i++)
  182. {
  183. if (i < 6)
  184. {
  185. elementalCardPositions[i] = new Vector3((i - 1) * 16, 0, 95);
  186. }
  187. else if (i < 12)
  188. {
  189.  
  190. elementalCardPositions[i] = new Vector3((i - 7) * 16, 0, 73);
  191.  
  192. }
  193. else if (i < 18)
  194. {
  195. elementalCardPositions[i] = new Vector3((i - 13) * 16, 0, 29);
  196.  
  197. }
  198. else
  199. {
  200. elementalCardPositions[i] = new Vector3((i - 19) * 16, 0, 51);
  201.  
  202. }
  203. }
  204. }
  205.  
  206. public WarriorCardPlace[] GetWarriorPlaces()
  207. {
  208. return warriorCardPlaces;
  209. }
  210.  
  211. public GameObject GetRepositionCard(int index)
  212. {
  213. return repositionCards[index];
  214. }
  215.  
  216. //Transformers
  217. //------------------------
  218. //Card Generators (main)
  219.  
  220. void SpawnElementalCardsRepository()
  221. {
  222. for (int i = 0; i < 24; i++)
  223. {
  224. repositionCards.Add(ElementalCardDeck[UnityEngine.Random.Range(0, ElementalCardDeck.Length)]);
  225. }
  226.  
  227. }
  228.  
  229. public void RespawnElementalCards(int cardId)
  230. {
  231. GameObject specificCard = Instantiate(repositionCards[0], elementalCardPositions[transformRandomPosition[cardId]], Quaternion.identity) as GameObject;
  232. specificCard.transform.parent = cardHolder.transform;
  233. specificCard.GetComponent<ElementalCard>().SetCardPosition(elementalCardPositions[transformRandomPosition[cardId]]);
  234. specificCard.GetComponent<ElementalCard>().SetCardId(cardId);
  235. repositionCards.RemoveAt(0);
  236. repositionCards.Add(ElementalCardDeck[UnityEngine.Random.Range(0, ElementalCardDeck.Length)]);
  237. }
  238.  
  239. void PlaceSpecialCards()
  240. {
  241. switch (specialCardsID)
  242. {
  243.  
  244. //H2O - F
  245. case 1001:
  246. Instantiate(SpecialCardDeck[0], specialCardsPositions[0].position, Quaternion.identity);
  247. Instantiate(SpecialCardDeck[1], specialCardsPositions[1].position, Quaternion.identity);
  248. break;
  249.  
  250. //H2O - H2O
  251. case 1002:
  252. Instantiate(SpecialCardDeck[0], specialCardsPositions[0].position, Quaternion.identity);
  253. Instantiate(SpecialCardDeck[0], specialCardsPositions[1].position, Quaternion.identity);
  254. break;
  255.  
  256. //H2O - N
  257. case 1003:
  258. Instantiate(SpecialCardDeck[0], specialCardsPositions[0].position, Quaternion.identity);
  259. Instantiate(SpecialCardDeck[2], specialCardsPositions[1].position, Quaternion.identity);
  260. break;
  261.  
  262. //H2O - Cianeto
  263. case 1004:
  264. Instantiate(SpecialCardDeck[0], specialCardsPositions[0].position, Quaternion.identity);
  265. GameObject bonusWarriorCard4 = Instantiate(SpecialCardDeck[3], specialCardsPositions[1].position, Quaternion.identity) as GameObject;
  266. bonusWarriorCard4.GetComponent<WarriorCard>().SetCardPosition(specialCardsPositions[1].position);
  267. break;
  268.  
  269. //Acetico - H2O
  270. case 1005:
  271. GameObject bonusWarriorCard5 = Instantiate(SpecialCardDeck[4], specialCardsPositions[0].position, Quaternion.identity) as GameObject;
  272. Instantiate(SpecialCardDeck[0], specialCardsPositions[1].position, Quaternion.identity);
  273. bonusWarriorCard5.GetComponent<WarriorCard>().SetCardPosition(specialCardsPositions[0].position);
  274. break;
  275.  
  276. //Sulfato - H2O
  277. case 1006:
  278. GameObject bonusWarriorCard6 = Instantiate(SpecialCardDeck[5], specialCardsPositions[0].position, Quaternion.identity) as GameObject;
  279. Instantiate(SpecialCardDeck[0], specialCardsPositions[1].position, Quaternion.identity);
  280. bonusWarriorCard6.GetComponent<WarriorCard>().SetCardPosition(specialCardsPositions[0].position);
  281. break;
  282. default:
  283. print("Player não escolheu cartas especiais");
  284. Instantiate(SpecialCardDeck[0], specialCardsPositions[0].position, Quaternion.identity);
  285. Instantiate(SpecialCardDeck[0], specialCardsPositions[1].position, Quaternion.identity);
  286. break;
  287. }
  288.  
  289. }
  290.  
  291. void CardGenerator()
  292. {
  293.  
  294. for (int i = 0; i < cardsElemental.Length; i++)
  295. {
  296.  
  297. if (i < 3)
  298. {
  299.  
  300. cardsElemental[i] = ElementalCardDeck[0];
  301.  
  302. }
  303. else if (i < 8 && i > 2)
  304. {
  305.  
  306. cardsElemental[i] = ElementalCardDeck[1];
  307.  
  308. }
  309. else if (i < 12 && i > 7)
  310. {
  311.  
  312. cardsElemental[i] = ElementalCardDeck[2];
  313.  
  314. }
  315. else
  316. {
  317. int p = UnityEngine.Random.Range(0, 110);
  318. if (p < 20)
  319. {
  320. //O
  321. cardsElemental[i] = ElementalCardDeck[0];
  322. }
  323. else if (p > 19 && p < 41)
  324. {
  325.  
  326. //H
  327. cardsElemental[i] = ElementalCardDeck[1];
  328.  
  329. }
  330. else if (p > 40 && p < 62)
  331. {
  332.  
  333. //C
  334. cardsElemental[i] = ElementalCardDeck[2];
  335.  
  336. }
  337. else if (p > 61 && p < 80)
  338. {
  339.  
  340. //N
  341. cardsElemental[i] = ElementalCardDeck[3];
  342.  
  343. }
  344. else if (p > 79 && p < 89)
  345. {
  346.  
  347. //S
  348. cardsElemental[i] = ElementalCardDeck[4];
  349.  
  350. }
  351. else if (p > 88 && p < 95)
  352. {
  353.  
  354. //P
  355. cardsElemental[i] = ElementalCardDeck[5];
  356.  
  357. }
  358. else if (p > 94 && p < 101)
  359. {
  360.  
  361. //F
  362. cardsElemental[i] = ElementalCardDeck[6];
  363.  
  364. }
  365. else if (p > 100 && p < 106)
  366. {
  367. //Na
  368. cardsElemental[i] = ElementalCardDeck[7];
  369. }
  370. else if (p > 105 && p < 111)
  371. {
  372. //Cl
  373. cardsElemental[i] = ElementalCardDeck[8];
  374. }
  375. }
  376. }
  377. }
  378.  
  379. void PlaceCards()
  380. {
  381.  
  382. for (int i = 0; i < cardsElemental.Length; i++)
  383. {
  384. GameObject nextCard = Instantiate(cardsElemental[i], elementalCardPositions[transformRandomPosition[i]], Quaternion.identity) as GameObject;
  385. nextCard.GetComponent<ElementalCard>().SetCardPosition(elementalCardPositions[transformRandomPosition[i]]);
  386. nextCard.GetComponent<ElementalCard>().SetCardId(i);
  387. nextCard.transform.parent = cardHolder.transform;
  388. }
  389. cardHolder.transform.position = new Vector3(-11.2f, 0, -44);
  390. }
  391.  
  392. //Card Generators (main)
  393. //------------------------
  394. //Card Generators (player)
  395.  
  396. void GetBattleCards()
  397. {
  398. //Função usada quando o jogo voltar da mesa de batalha
  399. for (int i = 0; i < 5; i++)
  400. {
  401. print("Cartas a voltar");
  402. if (_DATAHOLDER.GetWarriorCard(i) != null)
  403. {
  404. print("Carta " + i + "contem dados");
  405. GetBattleCard(conjurationLink.CheckWarriorCard(_DATAHOLDER.GetWarriorCard(i).GetCardID().ToString()), _DATAHOLDER.GetWarriorCard(i).GetCardPOD(), _DATAHOLDER.GetWarriorCard(i).GetCardCON(), i);
  406. }
  407. }
  408. }
  409.  
  410. public void GenerateBattleCards(int cardId)
  411. {
  412. CardNumber++;
  413. //mDATA.TakeCardNumber();
  414. GameObject resultCard = Instantiate(BattleCardsDeck[cardId - 1], resultCardposition.position, Quaternion.identity) as GameObject;
  415. resultCard.GetComponent<WarriorCard>().SetCardPosition(resultCardposition.position);
  416. resultCard.GetComponent<WarriorCard>().SetOnResultPosition();
  417.  
  418. if (concentrationLink.GetWarriorComb())
  419. {
  420. resultCard.GetComponent<WarriorCard>().SetCardConcentration(concentrationLink.GetTotalCon());
  421. }
  422. concentrationLink.ResetList();
  423. }
  424.  
  425. public void GetBattleCard(int cardId, int pod, int con, int index)
  426. {
  427. CardNumber++;
  428. GameObject battleCard = Instantiate(BattleCardsDeck[cardId - 1], WarriorPosition[index].position, Quaternion.identity) as GameObject;
  429. battleCard.GetComponent<WarriorCard>().SetupCard(pod, con, WarriorPosition[index]);
  430. battleCard.GetComponent<WarriorCard>().SetCardPosition(WarriorPosition[index].position);
  431. battleCard.GetComponent<WarriorCard>().CheckForInventory();
  432. battleCard.GetComponent<WarriorCard>().SetNewPosition(WarriorPosition[index]);
  433. }
  434.  
  435. //Card Generators (player)
  436. //------------------------
  437. //Controladores (bool)
  438.  
  439. public bool CheckBattleCardsReturn()
  440. {
  441. return _DATAHOLDER.GetHasGoneToBattle();
  442. }
  443.  
  444. public bool GetCanConjurate()
  445. {
  446. return _CanConjurate;
  447. }
  448.  
  449. //Controladores (bool)
  450. //------------------------
  451. //Controladores (int)
  452.  
  453. public void AddRespawnCardCounter()
  454. {
  455. cardsToRespawn++;
  456. }
  457.  
  458. public void MinusRespawnCardCounter()
  459. {
  460. cardsToRespawn--;
  461. }
  462.  
  463. public void MinusCards()
  464. {
  465. CardNumber--;
  466. }
  467.  
  468. public void AddInventoryCard()
  469. {
  470. _InventoryCardNumber++;
  471. }
  472.  
  473. public void RemoveInventoryCard()
  474. {
  475. _InventoryCardNumber--;
  476. }
  477.  
  478. //Controladores (int)
  479. //------------------------
  480. //Controladores (Scenes)
  481.  
  482. IEnumerator BattleSceneCheck()
  483. {
  484. int IsReady = 1;
  485. MultiplayerController.Instance.SendMyUpdateReadyConjuration(IsReady);
  486. while (!CanLoadScene)
  487. {
  488. yield return null;
  489. }
  490. CanLoadScene = true;
  491. StartCoroutine(ConjurWaitFade());
  492. }
  493.  
  494. IEnumerator ConjurWaitFade()
  495. {
  496. yield return new WaitForSeconds(1);
  497. SceneManager.LoadScene(8);
  498. GameObject audio = GameObject.FindWithTag("AudioController");
  499. DontDestroyOnLoad(audio);
  500. GameObject mData = GameObject.FindWithTag("MAINDATA");
  501. DontDestroyOnLoad(mData);
  502.  
  503. }
  504.  
  505. public void LostConnOp()
  506. {
  507. MultiplayerController.Instance.LeaveRoom();
  508. FadeConjur.Play("FadeConjur");
  509. StartCoroutine(LostConn());
  510. }
  511.  
  512. IEnumerator LostConn()
  513. {
  514. yield return new WaitForSeconds(1);
  515. SceneManager.LoadScene("levelDuelarConexao");
  516. GameObject audio = GameObject.FindWithTag("AudioController");
  517. DontDestroyOnLoad(audio);
  518. GameObject data = GameObject.FindWithTag("MAINDATA");
  519. Destroy(data);
  520. }
  521.  
  522. public void BattleScene()
  523. {
  524. FadeConjur.enabled = true;
  525. FadeConjur.Play("FadeConjurW");
  526. StartCoroutine(BattleSceneCheck());
  527. }
  528.  
  529. public void BattleSceneReceiveCheck(int EnemyReady)
  530. {
  531. if (EnemyReady == 1)
  532. {
  533. CanLoadScene = true;
  534. }
  535. if (EnemyReady == 0)
  536. {
  537. CanLoadScene = false;
  538. }
  539. }
  540.  
  541. //Controladores (Scenes)
  542. //------------------------
  543. //Aux
  544.  
  545. int[] KnuthShuffle(int[] array)
  546. {
  547.  
  548. for (int i = 0; i < array.Length; i++)
  549. {
  550. int j = UnityEngine.Random.Range(i, array.Length); // Don't select from the entire array on subsequent loops
  551. int temp = array[i]; array[i] = array[j]; array[j] = temp;
  552. }
  553.  
  554. return array;
  555. }
  556.  
  557. public bool CanDeployBattleCard()
  558. {
  559. if(_InventoryCardNumber >= _MaxInventoryCardNumber)
  560. {
  561. return false;
  562. }
  563. else
  564. {
  565. return true;
  566. }
  567. }
  568.  
  569. //Aux
  570. }
Add Comment
Please, Sign In to add comment