// Update is called once per frame void Update() { if (Time.time > lastPlayed + playInterval) { lastPlayed = Time.time; int handIndex = Random.Range(0, enemyHand.hand.Count - 1); Debug.Log(handIndex); Card wantPlay = enemyHand.hand[handIndex]; if (wantPlay.type == Card.cardType.creature) { int col = Random.Range(0, 5); if (board.isPlayableAtPosition(wantPlay, 0, col)) { board.addCardToBoard(enemyHand.removeCard(wantPlay), 0, col, enemyHand.dir); GameObject ind = Instantiate(enemyIndprfb); ind.transform.position = wantPlay.transform.position - wantPlay.transform.forward * .05f; ind.transform.rotation = wantPlay.transform.rotation; ind.transform.parent = wantPlay.transform; } } if (wantPlay.type == Card.cardType.targetCreature) { List <Card> freindly = new List <Card>(); List <Card> hostile = new List <Card>(); foreach (BoardPosition pos in board.boardPositions) { if (pos.unitCard != null && pos.unitCard.dir == enemyHand.dir) { freindly.Add(pos.unitCard); } else if (pos.unitCard != null && pos.unitCard.dir != enemyHand.dir) { hostile.Add(pos.unitCard); } } int dmg = wantPlay.GetComponent <targetActionLightning>().damage; if (dmg > 0 && hostile.Count > 0) { hostile[Random.Range(0, hostile.Count - 1)].playCardToThis(enemyHand.removeCard(wantPlay)); } else if (freindly.Count > 0 && dmg <= 0) { freindly[Random.Range(0, freindly.Count - 1)].playCardToThis(enemyHand.removeCard(wantPlay)); } } if (wantPlay.type == Card.cardType.targetBoard) { foreach (BoardPosition pos in enemyHand.board.boardPositions) { if (pos.unitCard != null && pos.unitCard.type == Card.cardType.creature) { Debug.Log("attempt"); wantPlay.GetComponent <targetAction>().actOnTarget(pos.unitCard); } } enemyHand.removeCard(wantPlay); } } }
// Update is called once per frame void Update() { hideHandPos = defaultHandPos + hideHandOffset; Ray mouseRay = cam.ScreenPointToRay(Input.mousePosition); RaycastHit interfaceHit = new RaycastHit(); Physics.Raycast(mouseRay, out interfaceHit); if (Input.GetMouseButtonDown(1)) { selectify = null; } if (selectify != null) { selectShow.SetActive(true); selectShow.transform.position = selectify.transform.position; selectShow.transform.rotation = selectify.transform.rotation; selectShow.transform.position -= selectify.transform.forward * .005f; actionLine.positionCount = 0; hand.transform.position = hand.transform.position * (1 - Time.deltaTime) + hideHandPos * Time.deltaTime; } else { hand.transform.position = hand.transform.position * (1 - Time.deltaTime) + defaultHandPos * Time.deltaTime; targetBoard.SetActive(false); } if (interfaceHit.collider) { Debug.DrawLine(new Vector3(0, 0, 0), interfaceHit.transform.position); Card rayCard = interfaceHit.collider.GetComponent <Card>(); BoardPosition bordComp = interfaceHit.collider.GetComponent <BoardPosition>(); if (selectify != null && selectify.type == Card.cardType.targetBoard && rayCard == null) { targetBoard.SetActive(true); } else { targetBoard.SetActive(false); } if (Input.GetMouseButtonDown(0) && rayCard != null) { if (rayCard.state == Card.cardState.onboard && selectify != null) { if (rayCard.isValidTarget(selectify)) { hand.removeCard(selectify); rayCard.playCardToThis(selectify); selectify = null; } } if (hand.hand.Contains(rayCard)) { selectify = rayCard; } } else if (Input.GetMouseButtonDown(0) && bordComp != null && selectify != null) { if (bordComp.isPlayableHere(selectify)) { hand.removeCard(selectify); if (selectify.type == Card.cardType.targetBoard) { bool applyOnce = false; foreach (BoardPosition pos in hand.board.boardPositions) { if (pos.unitCard != null && pos.unitCard.type == Card.cardType.creature) { Debug.Log("attempt"); selectify.GetComponent <targetAction>().actOnTarget(pos.unitCard); applyOnce = true; } } /*for (int col = 0; col <= 4; col++) * { * for(int row = 0; row <= 7; row++) * { * Debug.Log("pos" + row + ":" + col); * BoardPosition applypos = hand.board.getBoardPosition(row, col); * if (applypos.unitCard != null && applypos.unitCard.type == Card.cardType.creature) * { * Debug.Log("attempt"); * selectify.GetComponent<targetAction>().actOnTarget(applypos.unitCard); * applyOnce = true; * } * } * }*/ selectify.transform.parent = null; selectify.transform.position = new Vector3(0, 2, 0); if (!applyOnce) { Destroy(selectify); } } else { hand.board.addCardToBoard(selectify, bordComp.row, bordComp.col, hand.dir); } selectify = null; } } if ((selectify != null && (selectify.type != Card.cardType.targetBoard)) && ((bordComp != null && bordComp.isPlayableHere(selectify)) || (rayCard != null && rayCard.isValidTarget(selectify)))) { if (selectify.type == Card.cardType.targetCol) { if (bordComp != null) { targetCol.SetActive(true); targetCol.transform.position = bordComp.transform.position - new Vector3(0, 0, bordComp.transform.position.z); } } else if (selectify.type == Card.cardType.targetRow) { if (bordComp != null) { targetRow.SetActive(true); targetRow.transform.position = bordComp.transform.position - new Vector3(bordComp.transform.position.x, 0, 0); } } else { GameObject targ = bordComp != null ? bordComp.gameObject : rayCard.gameObject; targetShow.SetActive(true); targetShow.transform.position = targ.transform.position + targ.transform.forward * .05f; if (bordComp != null) { targetShow.transform.rotation = new Quaternion(1, 0, 0, 1); } else { targetShow.transform.rotation = targ.transform.rotation; } } } else { targetShow.SetActive(false); } if (selectify != null && ( bordComp != null && bordComp.isPlayableHere(selectify) || rayCard != null && rayCard.isValidTarget(selectify) )) { actionLine.positionCount = 20; Debug.DrawLine(selectify.transform.position, interfaceHit.transform.position); for (int i = 0; i < actionLine.positionCount; i++) { float percentLine = i / (actionLine.positionCount - 1f); float leanBias = selectify.transform.position.x > 0 ? Mathf.Sin(percentLine * Mathf.PI) : -Mathf.Sin(percentLine * Mathf.PI); Vector3 hoverHeight = new Vector3(leanBias * 2, Mathf.Sin(percentLine * Mathf.PI) * 4, 0); actionLine.SetPosition(i, selectify.transform.position * (1 - percentLine) + hoverHeight + interfaceHit.transform.position * percentLine); } if (rayCard != null) { targetShow.SetActive(true); targetShow.transform.position = interfaceHit.transform.position - interfaceHit.transform.forward * .05f; } else if (bordComp != null && selectify.type != Card.cardType.targetBoard) { targetShow.SetActive(true); targetShow.transform.position = interfaceHit.transform.position + interfaceHit.transform.forward * .05f; } } else if (selectify == null) { selectShow.SetActive(false); } } else { targetShow.SetActive(false); targetBoard.SetActive(false); } }