Roxaq

WarriorCard

Nov 10th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.80 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. using System.Collections;
  4.  
  5. public enum AcidoBase { acido, basico };//para q possa ser acessado de fora da classe
  6.  
  7. public class WarriorCard : MonoBehaviour
  8. {
  9.  
  10. AudioController audio;
  11.  
  12. public string elementType;
  13. public string elementName;
  14. private int wCardID;
  15.  
  16. private Vector3 cardPosition;
  17. private Vector3 cardSpawnPosition;
  18. private Vector3 cardCombinerPosition;
  19. public Vector3 delta = Vector3.zero;
  20. public Vector3 lastPos = Vector3.zero;
  21.  
  22. public float MoveSpeedFloat;
  23.  
  24. private bool isInHand;
  25. private bool isDrag;
  26. private bool onResultPosition;
  27. private bool onCombinerPosition;
  28. private bool positionLock;
  29.  
  30. public TextMesh MaxCon;
  31. public TextMesh ActualCon;
  32. public TextMesh SlashBar;
  33.  
  34. public SpriteRenderer CardFrame;
  35. public SpriteRenderer ConBar;
  36.  
  37. private Vector3 screenPoint;
  38. private Vector3 offset;
  39.  
  40. public int nPoder;
  41. public int nConcentraçãoMaxima;
  42. public int nConcentração;
  43. public int nConcentraçãoInicial;
  44. public int idCarta;
  45.  
  46. public AcidoBase acidoBase;
  47.  
  48. public float doubleClickCheck = 0;
  49.  
  50. public Transform ZoomArea;
  51.  
  52. private ElementalCardPlace thisElementalCardPlace;
  53. private WarriorCardPlace thisWarriorCardPlace;
  54. private InventoryCardPlace thisInventoryCardPlace;
  55.  
  56. private ConjurationCombiner combinerLink;
  57. private ConjurationTable tableLink;
  58.  
  59. public int posicaoDeckBatalha;
  60.  
  61. void Awake()
  62. {
  63. audio = GameObject.FindWithTag("AudioController").GetComponent<AudioController>();
  64. string sceneName = SceneManager.GetActiveScene().name;
  65. if (sceneName != "levelBatalha")
  66. {
  67. combinerLink = GameObject.FindWithTag("TableMaster").GetComponent<ConjurationCombiner>();
  68.  
  69. ZoomArea = GameObject.FindWithTag("ZoomArea").GetComponent<Transform>();
  70. }
  71. tableLink = GameObject.FindWithTag("TableMaster").GetComponent<ConjurationTable>();
  72. isInHand = false;
  73. MoveSpeedFloat = 10;
  74. }
  75.  
  76. void Start()
  77. {
  78. string sceneName = SceneManager.GetActiveScene().name;
  79. if (sceneName != "levelBatalha")
  80. {
  81. cardPosition = cardSpawnPosition;
  82. DeactiveCardFrame();
  83. }
  84. HideCon();
  85. }
  86.  
  87. void OnEnable()
  88. {
  89. string sceneName = SceneManager.GetActiveScene().name;
  90. if (sceneName != "levelBatalha")
  91. {
  92. ConjurationTableEvents.OnCombine += CombinationCheck;
  93. }
  94. }
  95.  
  96. void Update()
  97. {
  98. string sceneName = SceneManager.GetActiveScene().name;
  99. if (sceneName != "levelBatalha")
  100. {
  101. if (positionLock)
  102. {
  103. transform.localPosition = cardPosition;
  104. }
  105.  
  106. float ScaleSpeed = MoveSpeedFloat * Time.deltaTime;
  107.  
  108. if (Input.GetKeyDown(KeyCode.Alpha1))
  109. {
  110. positionLock = false;
  111. }
  112. else if (Input.GetKeyDown(KeyCode.Alpha2))
  113. {
  114. positionLock = true;
  115. }
  116.  
  117. if (Input.GetMouseButtonDown(0))
  118. {
  119.  
  120. lastPos = Input.mousePosition;
  121.  
  122. }
  123. else if (Input.GetMouseButton(0))
  124. {
  125.  
  126. delta = Input.mousePosition - lastPos;
  127. lastPos = Input.mousePosition;
  128.  
  129. float deltaExpandDistance = delta.magnitude;
  130. float deltaShrinkDistance = delta.magnitude;
  131.  
  132. if (deltaExpandDistance >= 150 && positionLock == false)
  133. {
  134. isInHand = true;
  135. }
  136. }
  137. }
  138. }
  139.  
  140. void ActiveCardFrame()
  141. {
  142. CardFrame.enabled = true;
  143. }
  144.  
  145. void DeactiveCardFrame()
  146. {
  147. CardFrame.enabled = false;
  148. }
  149.  
  150. void OnMouseDrag()
  151. {
  152. string sceneName = SceneManager.GetActiveScene().name;
  153. if (sceneName != "levelBatalha")
  154. {
  155. ActiveCardFrame();
  156. ShowCon();
  157. float ScaleSpeed = MoveSpeedFloat * Time.deltaTime;
  158. Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
  159. Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
  160. transform.position = curPosition;
  161. }
  162. }
  163.  
  164. void OnMouseDown()
  165. {
  166. audio.MOVEWARRIOR();
  167. string sceneName = SceneManager.GetActiveScene().name;
  168. if (sceneName != "levelBatalha")
  169. {
  170. ActiveCardFrame();
  171. ShowCon();
  172. isDrag = true;
  173. positionLock = false;
  174. screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
  175. offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
  176. }
  177. }
  178.  
  179. void OnMouseUp()
  180. {
  181.  
  182. string sceneName = SceneManager.GetActiveScene().name;
  183. if (sceneName != "levelBatalha")
  184. {
  185. DeactiveCardFrame();
  186. HideCon();
  187. isDrag = false;
  188. positionLock = true;
  189. if (positionLock)
  190. {
  191. float ScaleSpeed = MoveSpeedFloat * Time.deltaTime;
  192. iTween.ScaleTo(gameObject, iTween.Hash("x", 1.5f, "z", 1.6f, "delay", 0.1f, "time", ScaleSpeed));
  193. }
  194.  
  195. //Descontinued
  196. /*
  197. if (onSpawnPosition)
  198. {
  199. CheckForInventory(tableLink.GetWarriorPlaces());
  200. onSpawnPosition = false;
  201. }
  202. else if (!onCombinerPosition && !onInventoryPosition)
  203. {
  204. CheckForInventory(tableLink.GetWarriorPlaces());
  205. onSpawnPosition = false;
  206. }
  207. */
  208. }
  209. }
  210.  
  211. void OnMouseOver()
  212. {
  213. string sceneName = SceneManager.GetActiveScene().name;
  214. if (sceneName != "levelBatalha")
  215. {
  216. if (isDrag)
  217. {
  218.  
  219. }
  220. else
  221. {
  222. positionLock = true;
  223. }
  224. }
  225.  
  226. }
  227.  
  228. public string GetElementType()
  229. {
  230. return elementType;
  231. }
  232.  
  233. public void SetCardPosition(Vector3 position)
  234. {
  235. string sceneName = SceneManager.GetActiveScene().name;
  236. if (sceneName != "levelBatalha")
  237. {
  238. cardSpawnPosition = position;
  239. }
  240. }
  241.  
  242. public void SetCardConcentration(int value)
  243. {
  244. nConcentração = value;
  245. }
  246.  
  247. public void SetupCard(int pod, int con, Transform newWarriorCardPlace)
  248. {
  249. print("Carta que voltou da batalha. Card Position: " + cardPosition.x + "," + cardPosition.y + "," + cardPosition.z);
  250. SetNewPosition(newWarriorCardPlace);
  251. onCombinerPosition = false;
  252. nPoder = pod;
  253. nConcentração = con;
  254. onResultPosition = false;
  255. if(nConcentração > nConcentraçãoMaxima)
  256. {
  257. nConcentração = nConcentraçãoMaxima;
  258. }
  259. }
  260.  
  261. void ShowCon()
  262. {
  263. ConBar.enabled = true;
  264. SlashBar.GetComponent<Renderer>().enabled = true;
  265. ActualCon.GetComponent<Renderer>().enabled = true;
  266. MaxCon.GetComponent<Renderer>().enabled = true;
  267. ActualCon.text = nConcentração.ToString();
  268. MaxCon.text = nConcentraçãoMaxima.ToString();
  269. }
  270.  
  271. void HideCon()
  272. {
  273. ConBar.enabled = false;
  274. SlashBar.GetComponent<Renderer>().enabled = false;
  275. ActualCon.GetComponent<Renderer>().enabled = false;
  276. MaxCon.GetComponent<Renderer>().enabled = false;
  277. ActualCon.text = nConcentração.ToString();
  278. MaxCon.text = nConcentraçãoMaxima.ToString();
  279. }
  280.  
  281. private void CombinationCheck()
  282. {
  283. string sceneName = SceneManager.GetActiveScene().name;
  284. if (sceneName != "levelBatalha")
  285. {
  286. if (positionLock && onCombinerPosition)
  287. {
  288. if (combinerLink.HasCombination())
  289. {
  290. ConjurationTableEvents.OnCombine -= CombinationCheck;
  291. //sucess
  292. thisElementalCardPlace.ResetElement();
  293. tableLink.MinusCards();
  294. Destroy(gameObject);
  295. }
  296. else
  297. {
  298. //Fail
  299. thisElementalCardPlace = null;
  300. onCombinerPosition = false;
  301. // CheckForInventory();
  302. }
  303. }
  304.  
  305. }
  306. }
  307.  
  308. public void CheckForInventory()
  309. {
  310. WarriorCardPlace[] inventoryPlaces = tableLink.GetWarriorPlaces();
  311.  
  312. string sceneName = SceneManager.GetActiveScene().name;
  313. if (sceneName != "levelBatalha")
  314. {
  315. for (int i = 0; i < inventoryPlaces.Length; i++)
  316. {
  317. if (inventoryPlaces[i].CanDropHere())
  318. {
  319. print("Check for inventory: " + inventoryPlaces[i].transform.position.x + "," + inventoryPlaces[i].transform.position.y + "," + inventoryPlaces[i].transform.position.z);
  320. SetNewPosition(inventoryPlaces[i].transform);
  321. transform.position = inventoryPlaces[i].transform.position;
  322. inventoryPlaces[i].ReceiveCard(gameObject);
  323. break;
  324. }
  325. }
  326. }
  327. }
  328.  
  329. public int GetCardId()
  330. {
  331. return idCarta;
  332. }
  333.  
  334. public int GetCardCon()
  335. {
  336.  
  337. return nConcentração;
  338. }
  339.  
  340. public int GetCardMaxCon()
  341. {
  342. return nConcentraçãoMaxima;
  343. }
  344.  
  345. public int GetCardPod()
  346. {
  347. return nPoder;
  348. }
  349.  
  350. public void SetNewPosition(Transform newPosition)
  351. {
  352. cardPosition = newPosition.position;
  353. }
  354.  
  355. public void SetOnResultPosition()
  356. {
  357. onResultPosition = true;
  358. }
  359.  
  360. void OnTriggerEnter(Collider other)
  361. {
  362. string sceneName = SceneManager.GetActiveScene().name;
  363. if (sceneName != "levelBatalha")
  364. {
  365. if (other.CompareTag("ElementalCardPlace"))
  366. {
  367. if (other.GetComponent<ElementalCardPlace>().CanDropHere(elementType))
  368.  
  369. onCombinerPosition = true;
  370. thisElementalCardPlace = other.GetComponent<ElementalCardPlace>();
  371. other.GetComponent<ElementalCardPlace>().ReceiveAnElement(elementType);
  372. other.GetComponent<ElementalCardPlace>().AddCard();
  373. other.GetComponent<ElementalCardPlace>().AddWarriorCard(this.gameObject);
  374. cardCombinerPosition = other.GetComponent<ElementalCardPlace>().GetPosition();
  375. SetNewPosition(other.GetComponent<Transform>());
  376. }
  377. }
  378.  
  379. if (other.CompareTag("InventoryCardPlace"))
  380. {
  381.  
  382. thisInventoryCardPlace = other.GetComponent<InventoryCardPlace>();
  383. if (thisInventoryCardPlace.CanDropHere())
  384. {
  385. onCombinerPosition = false;
  386. thisInventoryCardPlace.ReceiveCard(gameObject);
  387. SetNewPosition(other.GetComponent<Transform>());
  388. }
  389.  
  390. }
  391.  
  392. if (other.CompareTag("WarriorCardPlace"))
  393. {
  394. if (other.GetComponent<WarriorCardPlace>().CanDropHere())
  395. {
  396. onCombinerPosition = false;
  397. thisWarriorCardPlace = other.GetComponent<WarriorCardPlace>();
  398. other.GetComponent<WarriorCardPlace>().ReceiveCard(gameObject);
  399. SetNewPosition(other.GetComponent<Transform>());
  400. }
  401. }
  402.  
  403. if (other.CompareTag("ZoomArea"))
  404. {
  405. float ScaleSpeed = MoveSpeedFloat * Time.deltaTime;
  406. iTween.ScaleTo(gameObject, iTween.Hash("x", 7.5f, "z", 7.5f, "delay", 0.1f, "time", ScaleSpeed));
  407. }
  408. }
  409.  
  410.  
  411. void OnTriggerExit(Collider other)
  412. {
  413. string sceneName = SceneManager.GetActiveScene().name;
  414. if (sceneName != "levelBatalha")
  415. {
  416. if (other.CompareTag("ElementalCardPlace"))
  417. {
  418. if (other.GetComponent<ElementalCardPlace>().CanDropHere(elementType))
  419. {
  420. thisElementalCardPlace = null;
  421. onCombinerPosition = false;
  422. CheckForInventory();
  423. other.GetComponent<ElementalCardPlace>().RemoveAnElement();
  424. other.GetComponent<ElementalCardPlace>().RemoveWarriorCard(gameObject);
  425. other.GetComponent<ElementalCardPlace>().ResetElement();
  426. }
  427. else
  428. {
  429. onCombinerPosition = false;
  430. //Identificar o primeiro inventario disponivel
  431. CheckForInventory();
  432. }
  433. }
  434.  
  435. if (other.CompareTag("InventoryCardPlace"))
  436. {
  437.  
  438. thisInventoryCardPlace = other.GetComponent<InventoryCardPlace>();
  439. if (thisInventoryCardPlace.ReturnCard() == gameObject)
  440. {
  441. thisInventoryCardPlace.RemoveCard();
  442. CheckForInventory();
  443. }
  444. }
  445.  
  446.  
  447. if (other.CompareTag("WarriorCardPlace"))
  448. {
  449. other.GetComponent<WarriorCardPlace>().RemoveCard();
  450. }
  451.  
  452. /*if (other.CompareTag("ZoomArea"))
  453. {
  454. float ScaleSpeed = MoveSpeedFloat * Time.deltaTime;
  455. iTween.ScaleTo(gameObject, iTween.Hash("x", 1.5f, "z", 1.6f, "delay", 0.1f, "time", ScaleSpeed));
  456. }*/
  457. }
  458. }
  459.  
  460. }
Add Comment
Please, Sign In to add comment