Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using System.Collections;
- public enum AcidoBase { acido, basico };//para q possa ser acessado de fora da classe
- public class WarriorCard : MonoBehaviour
- {
- AudioController audio;
- public string elementType;
- public string elementName;
- private int wCardID;
- private Vector3 cardPosition;
- private Vector3 cardSpawnPosition;
- private Vector3 cardCombinerPosition;
- public Vector3 delta = Vector3.zero;
- public Vector3 lastPos = Vector3.zero;
- public float MoveSpeedFloat;
- private bool isInHand;
- private bool isDrag;
- private bool onResultPosition;
- private bool onCombinerPosition;
- private bool positionLock;
- public TextMesh MaxCon;
- public TextMesh ActualCon;
- public TextMesh SlashBar;
- public SpriteRenderer CardFrame;
- public SpriteRenderer ConBar;
- private Vector3 screenPoint;
- private Vector3 offset;
- public int nPoder;
- public int nConcentraçãoMaxima;
- public int nConcentração;
- public int nConcentraçãoInicial;
- public int idCarta;
- public AcidoBase acidoBase;
- public float doubleClickCheck = 0;
- public Transform ZoomArea;
- private ElementalCardPlace thisElementalCardPlace;
- private WarriorCardPlace thisWarriorCardPlace;
- private InventoryCardPlace thisInventoryCardPlace;
- private ConjurationCombiner combinerLink;
- private ConjurationTable tableLink;
- public int posicaoDeckBatalha;
- void Awake()
- {
- audio = GameObject.FindWithTag("AudioController").GetComponent<AudioController>();
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- combinerLink = GameObject.FindWithTag("TableMaster").GetComponent<ConjurationCombiner>();
- ZoomArea = GameObject.FindWithTag("ZoomArea").GetComponent<Transform>();
- }
- tableLink = GameObject.FindWithTag("TableMaster").GetComponent<ConjurationTable>();
- isInHand = false;
- MoveSpeedFloat = 10;
- }
- void Start()
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- cardPosition = cardSpawnPosition;
- DeactiveCardFrame();
- }
- HideCon();
- }
- void OnEnable()
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- ConjurationTableEvents.OnCombine += CombinationCheck;
- }
- }
- void Update()
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- if (positionLock)
- {
- transform.localPosition = cardPosition;
- }
- float ScaleSpeed = MoveSpeedFloat * Time.deltaTime;
- if (Input.GetKeyDown(KeyCode.Alpha1))
- {
- positionLock = false;
- }
- else if (Input.GetKeyDown(KeyCode.Alpha2))
- {
- positionLock = true;
- }
- if (Input.GetMouseButtonDown(0))
- {
- lastPos = Input.mousePosition;
- }
- else if (Input.GetMouseButton(0))
- {
- delta = Input.mousePosition - lastPos;
- lastPos = Input.mousePosition;
- float deltaExpandDistance = delta.magnitude;
- float deltaShrinkDistance = delta.magnitude;
- if (deltaExpandDistance >= 150 && positionLock == false)
- {
- isInHand = true;
- }
- }
- }
- }
- void ActiveCardFrame()
- {
- CardFrame.enabled = true;
- }
- void DeactiveCardFrame()
- {
- CardFrame.enabled = false;
- }
- void OnMouseDrag()
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- ActiveCardFrame();
- ShowCon();
- float ScaleSpeed = MoveSpeedFloat * Time.deltaTime;
- Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
- Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
- transform.position = curPosition;
- }
- }
- void OnMouseDown()
- {
- audio.MOVEWARRIOR();
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- ActiveCardFrame();
- ShowCon();
- isDrag = true;
- positionLock = false;
- screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
- offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
- }
- }
- void OnMouseUp()
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- DeactiveCardFrame();
- HideCon();
- isDrag = false;
- positionLock = true;
- if (positionLock)
- {
- float ScaleSpeed = MoveSpeedFloat * Time.deltaTime;
- iTween.ScaleTo(gameObject, iTween.Hash("x", 1.5f, "z", 1.6f, "delay", 0.1f, "time", ScaleSpeed));
- }
- //Descontinued
- /*
- if (onSpawnPosition)
- {
- CheckForInventory(tableLink.GetWarriorPlaces());
- onSpawnPosition = false;
- }
- else if (!onCombinerPosition && !onInventoryPosition)
- {
- CheckForInventory(tableLink.GetWarriorPlaces());
- onSpawnPosition = false;
- }
- */
- }
- }
- void OnMouseOver()
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- if (isDrag)
- {
- }
- else
- {
- positionLock = true;
- }
- }
- }
- public string GetElementType()
- {
- return elementType;
- }
- public void SetCardPosition(Vector3 position)
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- cardSpawnPosition = position;
- }
- }
- public void SetCardConcentration(int value)
- {
- nConcentração = value;
- }
- public void SetupCard(int pod, int con, Transform newWarriorCardPlace)
- {
- print("Carta que voltou da batalha. Card Position: " + cardPosition.x + "," + cardPosition.y + "," + cardPosition.z);
- SetNewPosition(newWarriorCardPlace);
- onCombinerPosition = false;
- nPoder = pod;
- nConcentração = con;
- onResultPosition = false;
- if(nConcentração > nConcentraçãoMaxima)
- {
- nConcentração = nConcentraçãoMaxima;
- }
- }
- void ShowCon()
- {
- ConBar.enabled = true;
- SlashBar.GetComponent<Renderer>().enabled = true;
- ActualCon.GetComponent<Renderer>().enabled = true;
- MaxCon.GetComponent<Renderer>().enabled = true;
- ActualCon.text = nConcentração.ToString();
- MaxCon.text = nConcentraçãoMaxima.ToString();
- }
- void HideCon()
- {
- ConBar.enabled = false;
- SlashBar.GetComponent<Renderer>().enabled = false;
- ActualCon.GetComponent<Renderer>().enabled = false;
- MaxCon.GetComponent<Renderer>().enabled = false;
- ActualCon.text = nConcentração.ToString();
- MaxCon.text = nConcentraçãoMaxima.ToString();
- }
- private void CombinationCheck()
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- if (positionLock && onCombinerPosition)
- {
- if (combinerLink.HasCombination())
- {
- ConjurationTableEvents.OnCombine -= CombinationCheck;
- //sucess
- thisElementalCardPlace.ResetElement();
- tableLink.MinusCards();
- Destroy(gameObject);
- }
- else
- {
- //Fail
- thisElementalCardPlace = null;
- onCombinerPosition = false;
- // CheckForInventory();
- }
- }
- }
- }
- public void CheckForInventory()
- {
- WarriorCardPlace[] inventoryPlaces = tableLink.GetWarriorPlaces();
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- for (int i = 0; i < inventoryPlaces.Length; i++)
- {
- if (inventoryPlaces[i].CanDropHere())
- {
- print("Check for inventory: " + inventoryPlaces[i].transform.position.x + "," + inventoryPlaces[i].transform.position.y + "," + inventoryPlaces[i].transform.position.z);
- SetNewPosition(inventoryPlaces[i].transform);
- transform.position = inventoryPlaces[i].transform.position;
- inventoryPlaces[i].ReceiveCard(gameObject);
- break;
- }
- }
- }
- }
- public int GetCardId()
- {
- return idCarta;
- }
- public int GetCardCon()
- {
- return nConcentração;
- }
- public int GetCardMaxCon()
- {
- return nConcentraçãoMaxima;
- }
- public int GetCardPod()
- {
- return nPoder;
- }
- public void SetNewPosition(Transform newPosition)
- {
- cardPosition = newPosition.position;
- }
- public void SetOnResultPosition()
- {
- onResultPosition = true;
- }
- void OnTriggerEnter(Collider other)
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- if (other.CompareTag("ElementalCardPlace"))
- {
- if (other.GetComponent<ElementalCardPlace>().CanDropHere(elementType))
- onCombinerPosition = true;
- thisElementalCardPlace = other.GetComponent<ElementalCardPlace>();
- other.GetComponent<ElementalCardPlace>().ReceiveAnElement(elementType);
- other.GetComponent<ElementalCardPlace>().AddCard();
- other.GetComponent<ElementalCardPlace>().AddWarriorCard(this.gameObject);
- cardCombinerPosition = other.GetComponent<ElementalCardPlace>().GetPosition();
- SetNewPosition(other.GetComponent<Transform>());
- }
- }
- if (other.CompareTag("InventoryCardPlace"))
- {
- thisInventoryCardPlace = other.GetComponent<InventoryCardPlace>();
- if (thisInventoryCardPlace.CanDropHere())
- {
- onCombinerPosition = false;
- thisInventoryCardPlace.ReceiveCard(gameObject);
- SetNewPosition(other.GetComponent<Transform>());
- }
- }
- if (other.CompareTag("WarriorCardPlace"))
- {
- if (other.GetComponent<WarriorCardPlace>().CanDropHere())
- {
- onCombinerPosition = false;
- thisWarriorCardPlace = other.GetComponent<WarriorCardPlace>();
- other.GetComponent<WarriorCardPlace>().ReceiveCard(gameObject);
- SetNewPosition(other.GetComponent<Transform>());
- }
- }
- if (other.CompareTag("ZoomArea"))
- {
- float ScaleSpeed = MoveSpeedFloat * Time.deltaTime;
- iTween.ScaleTo(gameObject, iTween.Hash("x", 7.5f, "z", 7.5f, "delay", 0.1f, "time", ScaleSpeed));
- }
- }
- void OnTriggerExit(Collider other)
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName != "levelBatalha")
- {
- if (other.CompareTag("ElementalCardPlace"))
- {
- if (other.GetComponent<ElementalCardPlace>().CanDropHere(elementType))
- {
- thisElementalCardPlace = null;
- onCombinerPosition = false;
- CheckForInventory();
- other.GetComponent<ElementalCardPlace>().RemoveAnElement();
- other.GetComponent<ElementalCardPlace>().RemoveWarriorCard(gameObject);
- other.GetComponent<ElementalCardPlace>().ResetElement();
- }
- else
- {
- onCombinerPosition = false;
- //Identificar o primeiro inventario disponivel
- CheckForInventory();
- }
- }
- if (other.CompareTag("InventoryCardPlace"))
- {
- thisInventoryCardPlace = other.GetComponent<InventoryCardPlace>();
- if (thisInventoryCardPlace.ReturnCard() == gameObject)
- {
- thisInventoryCardPlace.RemoveCard();
- CheckForInventory();
- }
- }
- if (other.CompareTag("WarriorCardPlace"))
- {
- other.GetComponent<WarriorCardPlace>().RemoveCard();
- }
- /*if (other.CompareTag("ZoomArea"))
- {
- float ScaleSpeed = MoveSpeedFloat * Time.deltaTime;
- iTween.ScaleTo(gameObject, iTween.Hash("x", 1.5f, "z", 1.6f, "delay", 0.1f, "time", ScaleSpeed));
- }*/
- }
- }
- }
Add Comment
Please, Sign In to add comment