private void setActiveFriends() { deleteAllActiveFriendChildren(); activeFriendsHolder.GetComponent <RectTransform>().sizeDelta = new Vector2((float)275 * activeFriendsIDS.Count, 100); for (int i = 0; i < activeFriendsIDS.Count; i++) { GameObject tempObj = Instantiate(activeFriendsObject); tempObj.transform.SetParent(activeFriendsHolder.transform, false); activePlayer fp = tempObj.GetComponent <activePlayer>(); GSData tempData = activeFriends.GetGSData(activeFriendsIDS.ElementAt(i)); fp.setActivePlayerDetails((string)tempData.GetString("displayName"), (int)tempData.GetInt("level"), profImages[(int)tempData.GetInt("profNum")], activeFriendsIDS.ElementAt(i)); } }
public GameState(ListBox.ObjectCollection pLib, ListBox.ObjectCollection pHand, ListBox.ObjectCollection pField, ListBox.ObjectCollection pGrave, ListBox.ObjectCollection pExile, ListBox.ObjectCollection EField, ListBox.ObjectCollection EGrave, ListBox.ObjectCollection EExile, ListBox.ObjectCollection Atk, ListBox.ObjectCollection Def, int pHealth, int eHealth, phase curPhase, activePlayer player, int[] manaAvail, bool PlayedMana) { playerHealth = pHealth; enemyHealth = eHealth; currentPhase = curPhase; active = player; target = null; score = 0; manaForTurn = PlayedMana; mana = manaAvail; foreach (Card c in pHand) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addUsList(newC); newC.deepCopy(c); PlayerHand.Add(newC); } foreach (Card c in pField) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addUsList(newC); newC.deepCopy(c); PlayerField.Add(newC); } foreach (Card c in pGrave) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addUsList(newC); newC.deepCopy(c); PlayerGraveyard.Add(newC); } foreach (Card c in pExile) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addUsList(newC); newC.deepCopy(c); PlayerExile.Add(newC); } foreach (Card c in EField) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addEnemyList(newC); newC.deepCopy(c); EnemyField.Add(newC); } foreach (Card c in EGrave) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addEnemyList(newC); newC.deepCopy(c); EnemyGraveyard.Add(newC); } foreach (Card c in EExile) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addEnemyList(newC); newC.deepCopy(c); EnemyExile.Add(newC); } if (active == activePlayer.Us) { foreach (Card c in Atk) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addUsList(newC); newC.deepCopy(c); Attacking.Add(newC); } foreach (Card c in Def) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addEnemyList(newC); newC.deepCopy(c); Defending.Add(newC); } } else { foreach (Card c in Atk) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addEnemyList(newC); newC.deepCopy(c); Attacking.Add(newC); } foreach (Card c in Def) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addUsList(newC); newC.deepCopy(c); Defending.Add(newC); } } }
// Update is called once per frame void Update() { cardSel = Input.GetAxis("Horizontal"); var f = 0.0f; debugTextMiddle.text = " Turn: " + whoPlays + " Phase: " + curPhase; if (c1M != null) { debugText2.text = "LIFE = " + p1Life + " \nMonster = " + c1M.CardName + "\n HP: " + c1M.Health + " ATK: " + c1M.Attack; if (c1M.Health <= 0) { Destroy(p1MonsterObj.GetComponent <Transform>()); Destroy(p1MonsterObj); activeCards.Remove(c1M); c1M = null; p1Life--; debugText2.text = "LIFE = " + p1Life + " \nMonster = N/A"; } } if (c2M != null) { debugText1.text = "LIFE = " + p2Life + " \nMonster = " + c2M.CardName + "\n HP: " + c2M.Health + " ATK: " + c2M.Attack; if (c2M.Health <= 0) { Destroy(p2MonsterObj.GetComponent <Transform>()); Destroy(p2MonsterObj); activeCards.Remove(c2M); c2M = null; p2Life--; debugText1.text = "LIFE = " + p2Life + " \nMonster = N/A"; } } if (phaseCD != 0.0f) //PHASE COOLDOWN SCRIPT. { // so it doesn't change rapidly phaseCD -= Time.deltaTime; if (phaseCD <= 0.0) { phaseCD = 0.0f; paused = false; } } //PLAYER if (whoPlays == activePlayer.Player) { if (curPhase == Phase.Draw) { if (!paused) { pHand.Add(pDeck[0]); var temp = pHand[pHand.Count - 1]; pDeck.Remove(temp); checkEffects(Phase.Draw); curPhase = Phase.Placement; phaseCD = phaseCDmax; selection = 0; GameObject cardObject = new GameObject(); displayHand.Add(Instantiate(cardObject, battleCanvas.transform)); cardImage = displayHand[displayHand.Count - 1].AddComponent <Image>(); cardImage.sprite = pHand[displayHand.Count - 1].cardArt; displayHand[displayHand.Count - 1].SetActive(true); Destroy(cardObject); foreach (GameObject cimage in displayHand) { cimage.transform.position = new Vector3(minHandX + (maxHandX / (displayHand.Count) * f), f, 0.0f); f += 1.0f; // } displayHand[selection].transform.position = new Vector3(displayHand[selection].transform.position.x, 70.0f, displayHand[selection].transform.position.z); } } else if (curPhase == Phase.Placement) { //move if (cardSel != 0 && cardSelCD == 0.0f) //move { displayHand[selection].transform.position = new Vector3(displayHand[selection].transform.position.x, 0.0f, displayHand[selection].transform.position.z); if (cardSel < 0) { if (selection == 0) { selection = displayHand.Count - 1; } else { selection--; } } else if (cardSel > 0) { if (selection == displayHand.Count - 1) { selection = 0; } else { selection++; } } displayHand[selection].transform.position = new Vector3(displayHand[selection].transform.position.x, 70.0f, displayHand[selection].transform.position.z); cardSelCD = 0.4f; } if (Input.GetButtonDown("Fire1")) { if (pHand[selection].type == CardType.Monster) { if (c1M == null) //if player doesnt alraedy have a monster out { //in future it will prompt but for now itll auto play CardClass clone = Instantiate(pHand[selection]) as CardClass; c1M = clone; activeCards.Add(clone); Destroy(displayHand[selection]); displayHand.RemoveAt(selection); pHand.RemoveAt(selection); checkEffects(Phase.Placement); p1MonsterObj = Instantiate(c1M.cardModel); p1MonsterObj.transform.position = p1M.transform.position; //reset positions. foreach (GameObject cimage in displayHand) { cimage.transform.position = new Vector3(minHandX + (maxHandX / (displayHand.Count) * f), 0.0f, 0.0f); f += 1.0f; // } selection = 0; } else { Debug.Log("There is already a monster on the field."); } } else if (pHand[selection].type == CardType.Action) { foreach (EffectClass efs in pHand[selection].effects) { //normally i would have to check if the card CAN before its used, //and the player wouldnt be able to use the card if they couldnt //however with this current code, the Action item is used regardless of whether it //functions or not. //It also assumes that its being used on the player's active monster if (c1M != null) { efs.EffectedCard = setTargetCard(efs); efs.doEffect(); Destroy(displayHand[selection]); displayHand.RemoveAt(selection); pHand.RemoveAt(selection); foreach (GameObject cimage in displayHand) { cimage.transform.position = new Vector3(minHandX + (maxHandX / (displayHand.Count) * f), 0.0f, 0.0f); f += 1.0f; // } selection = 0; } else { //normally this would mean dont let it activate. } } //activate the card. } else if (pHand[selection].type == CardType.Item) { //prompt for setting the card } } //cooldown if (cardSelCD != 0.0f) //SWITCHING COOLDOWN SCRIPT. { // so it doesn't change rapidly cardSelCD -= Time.deltaTime; if (cardSelCD <= 0.0) { cardSelCD = 0.0f; } } if (Input.GetButtonDown("Next")) { if (phaseCD <= 0.0f) { curPhase = Phase.Battle; phaseCD = phaseCDmax; } else { Debug.Log("ERROR: Wait a bit to go to the next phase!"); } } } else if (curPhase == Phase.Battle) { foreach (GameObject cimage in displayHand) { cimage.transform.position = new Vector3(minHandX + (maxHandX / (displayHand.Count) * f), 0.0f, 0.0f); f += 1.0f; // } if (Input.GetButtonDown("Fire1")) { //attack also choose left from right? //worry abt that later if (c2M != null && c1M != null) { c2M.Health -= c1M.Attack; checkEffects(Phase.Battle); curPhase = Phase.End; } else { //attacking cannot happen } } else if (Input.GetButtonDown("Next")) { if (phaseCD <= 0.0f) { curPhase = Phase.End; phaseCD = phaseCDmax; paused = true; } else { Debug.Log("ERROR: Wait a bit to go to the next phase!"); } } } else if (curPhase == Phase.End) { if (!paused) { checkEffects(Phase.End); whoPlays = activePlayer.Enemy; curPhase = Phase.Draw; paused = true; phaseCD = phaseCDmax; } } } //ENEMY else if (whoPlays == activePlayer.Enemy) { if (curPhase == Phase.Draw) { if (!paused) { eHand.Add(eDeck[0]); var temp = eHand[0]; eDeck.Remove(temp); checkEffects(Phase.Draw); curPhase = Phase.Placement; selection = 0; phaseCD = phaseCDmax; paused = true; } } else if (curPhase == Phase.Placement) { if (!paused) { if (c2M == null) { var a = 0; var found = false; foreach (CardClass card in eHand) { if (card.type == CardType.Monster) { selection = a; found = true; } a++; } if (!found) { phaseCD = phaseCDmax; paused = true; curPhase = Phase.End; } else if (found) { CardClass clone = Instantiate(eHand[selection]) as CardClass; c2M = clone; activeCards.Add(clone); //Destroy(displayHand[selection]); // displayHand.RemoveAt(selection); eHand.RemoveAt(selection); checkEffects(Phase.Placement); p2MonsterObj = Instantiate(c2M.cardModel); p2MonsterObj.transform.position = p2M.transform.position; phaseCD = phaseCDmax; paused = true; curPhase = Phase.Battle; } } else if (c2M != null) { foreach (CardClass card in eHand) //use every action that it can use { foreach (EffectClass efs in card.effects) { if (card.type == CardType.Action) { efs.EffectedCard = setEnemyTargetCard(efs); efs.doEffect(); } else { //normally this would mean dont let it activate. } } //activate the card. } } phaseCD = phaseCDmax; paused = true; curPhase = Phase.Battle; } } else if (curPhase == Phase.Battle) { if (!paused) { if (true) //if AI has decided to go { //attack also choose left from right? //worry abt that later if (c2M != null && c1M != null) { c1M.Health -= c2M.Attack; checkEffects(Phase.Battle); curPhase = Phase.End; } else { phaseCD = phaseCDmax; paused = true; curPhase = Phase.End; //attacking cannot happen } } else { //if ai doesnt wanna go curPhase = Phase.End; } } } else if (curPhase == Phase.End) { if (!paused) { checkEffects(Phase.End); whoPlays = activePlayer.Player; curPhase = Phase.Draw; phaseCD = phaseCDmax; paused = true; } } } }
public GameState(GameState gs, Card effTarget) { this.playerHealth = gs.playerHealth; this.enemyHealth = gs.enemyHealth; this.currentPhase = gs.currentPhase; this.target = effTarget; this.active = gs.active; this.mana = gs.mana; this.manaForTurn = gs.manaForTurn; foreach (Card c in gs.PlayerHand) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addUsList(newC); newC.deepCopy(c); this.PlayerHand.Add(newC); } foreach (Card c in gs.PlayerField) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addUsList(newC); newC.deepCopy(c); this.PlayerField.Add(newC); } foreach (Card c in gs.PlayerGraveyard) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addUsList(newC); newC.deepCopy(c); this.PlayerGraveyard.Add(newC); } foreach (Card c in gs.PlayerExile) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addUsList(newC); newC.deepCopy(c); this.PlayerExile.Add(newC); } foreach (Card c in gs.EnemyField) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addEnemyList(newC); newC.deepCopy(c); this.EnemyField.Add(newC); } foreach (Card c in gs.EnemyGraveyard) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addEnemyList(newC); newC.deepCopy(c); this.EnemyGraveyard.Add(newC); } foreach (Card c in gs.EnemyExile) { Card newC = (Card)Activator.CreateInstance(c.GetType()); addEnemyList(newC); newC.deepCopy(c); this.EnemyExile.Add(newC); } foreach (Card c in gs.Attacking) {//add check for phase so we know who is attacking Card newC = (Card)Activator.CreateInstance(c.GetType()); newC.deepCopy(c); this.Attacking.Add(newC); } foreach (Card c in gs.Defending) {//add check for phase so we know who is defending Card newC = (Card)Activator.CreateInstance(c.GetType()); newC.deepCopy(c); this.Defending.Add(newC); } }