void ShuffleCards(CombatantBehavior combatant, Transform combatantTransform) { bool keepGoing = true; while (keepGoing) { if (combatant.GetNextOpenSlot() < handAmount && combatant.GetNextOpenSlot() != -1) { int openSlot = combatant.GetNextOpenSlot(); //Probably not good to try/catch this. try { CardBehavior card = cardScripts[combatant.GetCardInSlot(openSlot + 1)]; card.MoveSlot(openSlot, combatantTransform.GetChild(openSlot)); combatant.SetOccupiedSlot(openSlot + 1, false, -1); combatant.SetOccupiedSlot(card.GetSlot(), true, card.GetSessionId()); } catch { keepGoing = false; } } else { keepGoing = false; } } }
void KillCombatant(CombatantBehavior combatant) { int index = combatant.GetSessionId(); combatantScripts[index].Die(); activeCombatants[index] = null; combatantScripts[index] = null; combatant = null; selectedCombatant = null; }
void EndTurn() { sideTurn++; if (sideTurn > sidesAmount - 1) { sideTurn = 0; } turnCount++; for (int k = 0; k < amtCombatants; k++) { if (activeCombatants[k] != null) { FillHand(activeCombatants[k]); combatantScripts[k].ResetAp(sideTurn); //Fill combatant AP to max AP if it is the beginning of their turn. } } //Change Turn Text if (sideTurn == 0) { turnText0.text = "Turn"; turnText1.text = ""; } else { turnText0.text = ""; turnText1.text = "Turn"; } //Deselect Cards and Combatants if (selectedCard != null) { selectedCard.Reset(); selectedCard = null; } if (selectedCombatant != null) { selectedCombatant.Select(false); selectedCombatant = null; } //Tell AI it's their turn. if (AI_Enabled) { if (sideTurn == enemyScript.GetSide()) { enemyScript.IsTurn(true); } } }
void DrawCard(CombatantBehavior combatant) { //In cardbehavior int slot = combatant.GetNextOpenSlot(); if (slot != -1) { combatant.SetOccupiedSlot(slot, true, SpawnCardRandomDeck(combatant.transform.GetChild(slot), slot, combatant.GetSessionId(), combatant.GetDeckLength())); //combatant.SetOccupiedSlot(slot, true, SpawnCardRandomDeck(combatant.transform.GetChild(slot), slot, combatant.GetId(), combatant.GetDeckLength())); //combatant.SetOccupiedSlot(slot, true, SpawnCardFullDeck(combatant.transform.GetChild(slot), slot, combatant.GetId())); } }
void Hover(Vector3 mposition) { RaycastHit hit; Ray ray = camera.ScreenPointToRay(mposition); if (Physics.Raycast(ray, out hit)) { Transform objectHit = hit.transform; if (objectHit.tag == "Card") { if (highlightedCard != null) { highlightedCard.Highlight(false); } highlightedCard = objectHit.gameObject.GetComponent <CardBehavior>(); highlightedCard.Highlight(true); } else if (objectHit.tag == "Button") { highlightedButton = objectHit.gameObject.GetComponent <ButtonBehavior>(); highlightedButton.Highlight(true); } else if (objectHit.tag == "Combatant") { highlightedCombatant = objectHit.gameObject.GetComponent <CombatantBehavior>(); highlightedCombatant.Highlight(true); } else { if (highlightedCard != null) { highlightedCard.Highlight(false); highlightedCard = null; } if (highlightedButton != null) { highlightedButton.Highlight(false); highlightedButton = null; } if (highlightedCombatant != null) { highlightedCombatant.Highlight(false); highlightedCombatant = null; } } } }
/* * //PlayCard With Button * void PlayCard() * { * if (selectedCard != null && selectedCombatant != null) * { * //Attack Card * if (selectedCard.GetEffect() == 0 && selectedCombatant.side != sideTurn) //make side a getter. * { * if (selectedCombatant.Damage(selectedCard.GetDamageVal()) <= 0) //Call HPAdjust, do damage, if it brings the combatant's HP zero, kill it. * { * selectedCombatant.Die(); * selectedCombatant = null; * } * selectedCard.Die(); * selectedCard = null; * EndTurn(); * } * //Healer Card * else if (selectedCard.GetEffect() == 1) * { * Debug.Log("Healing Card. Not yet implemented."); * EndTurn(); * } * else * { * Debug.Log("Card Has No Effect"); * } * //EndTurn(); * } * } */ //PlayCard With PlayArea void PlayCard() { if (playAreaCard != null && selectedCombatant != null) { //Attack Card if (playAreaCard.GetEffect() == 0 && selectedCombatant.side != sideTurn) //make side a getter. { CombatantBehavior owningCombatant = combatantScripts[playAreaCard.GetCombatant()]; if (owningCombatant.EvalCardCost(playAreaCard.GetApCost())) //Evaluate if we have enough AP to use card then remove action points based on card AP cost. { if (selectedCombatant.Damage(playAreaCard.GetDamageVal()) <= 0) //Call HPAdjust, do damage, if it brings the combatant's HP zero, kill it. { KillCombatant(selectedCombatant); } //owningCombatant.SubtractAp(playAreaCard.GetApCost()); //Remove action points based on card AP cost. owningCombatant.SetOccupiedSlot(playAreaCard.GetSlot(), false, -1); //Set slot's occupied slot to empty. ShuffleCards(owningCombatant, activeCombatants[playAreaCard.GetCombatant()].transform); activeCards[playAreaCard.GetSessionId()] = null; cardScripts[playAreaCard.GetSessionId()] = null; playAreaCard.Die(); playAreaCard = null; //EndTurn(); } //Healer Card else if (playAreaCard.GetEffect() == 1) { Debug.Log("Healing Card. Not yet implemented."); EndTurn(); } else { Debug.Log("Card Has No Effect"); } //EndTurn(); } } }
public void AIUse(int combatant) { selectedCombatant = combatantScripts[combatant]; PlayCard(); }
void Click(Vector3 mposition) { RaycastHit hit; Ray ray = camera.ScreenPointToRay(mposition); if (Physics.Raycast(ray, out hit)) { Transform objectHit = hit.transform; if (objectHit.tag == "Card") { updateMousePos = true; if (selectedCard != null) { selectedCard.Select(false); } selectedCard = objectHit.gameObject.GetComponent <CardBehavior>(); selectedCard.Select(true); oldCardPosition = selectedCard.transform.localPosition; } else if (objectHit.tag == "Button") { selectedButton = objectHit.gameObject.GetComponent <ButtonBehavior>(); selectedButton.Select(true); } else if (objectHit.tag == "Combatant") { if (selectedCombatant != null) { selectedCombatant.Select(false); } selectedCombatant = objectHit.gameObject.GetComponent <CombatantBehavior>(); selectedCombatant.Select(true); if (playAreaCard != null) { PlayCard(); } } else if (objectHit.tag == "PlayArea") { if (playAreaCard != null) { playAreaCard.Reset(); playAreaCard = null; } } else { if (selectedCard != null) { selectedCard.Select(false); selectedCard = null; } if (selectedCombatant != null) { selectedCombatant.Select(false); selectedCombatant = null; } } } }
public void AttachBehavior(CombatantBehavior behavior) { behavior.Combatant = this; CombatantBehaviors.Add(behavior); }