public void selectEnemyCard(ECardMonster ec) { Card sCard = selectedCards [0] as Card; if (sCard.canTarget(ec)) { sCard.assignTarget(ec); } deselectCard(sCard); }
/// <summary> /// Plays an enemy card of the specified unique ID in the specified slot. /// </summary> /// <param name="uid">The unique ID of the card to be played.</param> /// <param name="slotID">The slot to play the card in.</param> public void playEnemyCard(int uid, int slotID) { foreach (Slot slot in GameObject.FindObjectsOfType <Slot>()) { if (slot.SlotID == slotID + 12) { Card c = getCard <Card>(uid); switch (c.CardI.Type) { case (CardInfo.CardType.Monster): ECardMonster ecm = c as ECardMonster; if (ecm.CardI.AssoCardInfo.ContainsKey(CardRelation.RPAIR)) { Transform pairDropSlot = this.transform.parent.FindChild(string.Format("enemyMonster{0}", slotID + 1)); // foreach (SlotMonster sm in this.transform.parent.GetComponentsInChildren<SlotMonster>()) { // if (sm.gameObject.name.Equals(string.Format("playerMonster{0}", SlotID + dir))) // pairDropSlot = sm; // } if (pairDropSlot == null) { break; } Slot pdsm = pairDropSlot.GetComponent <Slot> (); if (pdsm == null) { break; } // SlotMonster pairDropSlot = null; // foreach (SlotMonster sm in slot.transform.parent.GetComponentsInChildren<SlotMonster>()) { // if (sm.gameObject.name.Equals(string.Format("enemyMonster{0}", slotID + 1))) // pairDropSlot = sm; // } // if (pairDropSlot == null) // break; ECardMonster ecmPair = pdsm.GetComponentInChildren <ECardMonster>(); GameObject o = GameObject.Instantiate(eMultiCardPrefab); CardMultiPart mpc = o.GetComponent <CardMultiPart>(); mpc.changeCard((c.CardI as MonsterInfo) + (ecmPair.CardI as MonsterInfo)); mpc.createUID(uid); mpc.GetComponent <SpriteRenderer> ().sortingOrder = pdsm.GetComponent <SpriteRenderer> ().sortingOrder + 1; mpc.State = Card.States.INPLAY; mpc.changeReturnParent(pdsm.transform); mpc.returnToParent(); GameObject.Destroy(c.gameObject); GameObject.Destroy(ecmPair.gameObject); } break; } if (c != null) { c.GetComponent <SpriteRenderer> ().sortingOrder = slot.GetComponent <SpriteRenderer> ().sortingOrder + 1; c.State = Card.States.INPLAY; c.changeReturnParent(slot.transform); c.returnToParent(); } } } }
public override void OnEvent(EventData photonEvent) { base.OnEvent(photonEvent); object content; switch (photonEvent.Code) { case (byte)EvDealCard: content = photonEvent.Parameters[ParameterCode.CustomEventContent]; Hashtable cardInfo = content as Hashtable; if (cardInfo != null) { int uid = (int)cardInfo[(byte)1]; CardInfo c = CardPool.Cards[(int)cardInfo[(byte)2] - 1]; clientGame.dealCardToEnemy(uid, c); Debug.Log(string.Format("The enemy was dealt a card with UID: {0} and name: {1}.", uid, c.Name)); } break; case (byte)EvCreateDeck: content = photonEvent.Parameters[ParameterCode.CustomEventContent]; Hashtable deckSent = content as Hashtable; if (deckSent != null) { enemyDeck = new Deck((int[])deckSent[(byte)1]); Debug.Log("The other player has created a deck."); } break; case (byte)EvStageChanged: content = photonEvent.Parameters[ParameterCode.CustomEventContent]; Hashtable stageInfo = content as Hashtable; if (stageInfo != null) { GameStage stageTemp = (GameStage)Enum.ToObject(typeof(GameStage), (int)stageInfo[(byte)1]); if (stageTemp != GameStage.SETUP) //If the next stage is SETUP, start the game. The stage changes in startGame(). { if (clientPlayer.isReady()) //Both players are ready at this point so change stages. This should always be true or we have problems. { if (stage == GameStage.SETUP && !isTurn) //Set initial monster to defend if the client isn't going first. { clientGame.setRemainingMonstersToDefend(); } stage = nextStage; if (stage == GameStage.BATTLE) { startBattleStage(); } if (stage == GameStage.PREP) { startPrepStage(); } else { oppReady = false; } if (stage == GameStage.WAITING) //If the next stage is WAITING, keep the client in the ready state. { advanceStage(); } else { clientPlayer.changeStatus(false); } } else { oppReady = true; } } else { startGame(); } Debug.Log(string.Format("Other player ready. Game entering {0} stage.", stage)); } break; case (byte)EvGraveCard: //Probably gonna see a lot of these... //Implement unique card ID // // content = photonEvent.Parameters[ParameterCode.CustomEventContent]; Hashtable graveInfo = content as Hashtable; if (graveInfo != null) { int uid = (int)graveInfo[(byte)1]; clientGame.removeCard(uid); Debug.Log(string.Format("Removing card with ID {0}", uid)); } break; // // //end case (byte)EvPlayCard: //omg why am i doing this before i fixed the cards // // content = photonEvent.Parameters[ParameterCode.CustomEventContent]; Hashtable playInfo = content as Hashtable; if (playInfo != null) { int uid = (int)playInfo[(byte)1]; int slotid = (int)playInfo[(byte)2]; clientGame.playEnemyCard(uid, slotid); Debug.Log(string.Format("Playing card with ID {0} in slot {1}", uid, slotid)); } break; // //end case (byte)EvDefenseToggle: //thought this one would be fine but no. //ill go fix the cards after the event section. // // content = photonEvent.Parameters[ParameterCode.CustomEventContent]; Hashtable defInfo = content as Hashtable; if (defInfo != null) { int uid = (int)defInfo[(byte)1]; bool state = (bool)defInfo[(byte)2]; ECardMonster c = clientGame.getCard <ECardMonster>(uid); c.setDefending(state); Debug.Log(string.Format("Card with UID: {0} is {1}", uid, (state ? "now defending." : "no longer defending."))); } break; case (byte)EvAttack: content = photonEvent.Parameters[ParameterCode.CustomEventContent]; Hashtable attackInfo = content as Hashtable; if (attackInfo != null) { int auid = (int)attackInfo[(byte)1]; int tuid = (int)attackInfo[(byte)2]; bool defend = (bool)attackInfo[(byte)3]; ActionQueue.calcAttack(clientGame.getCard <Card>(auid), clientGame.getCard <Card>(tuid), defend); Debug.Log(string.Format("{0} attacked {1} who {2} defending.", auid, tuid, defend ? "is" : "is not")); } break; // case (byte)EvExecuteAction: // // //gg // //gfg // // // // // content = photonEvent.Parameters[ParameterCode.CustomEventContent]; // Hashtable actionInfo = content as Hashtable; // if (actionInfo != null) // { // Actions a = (Actions)Enum.ToObject(typeof(Actions), (int)actionInfo[(byte)1]); // int actionCardID = (int)actionInfo[(byte)2]; // int targetCardID = (int)actionInfo[(byte)3]; // // GameAction action = new GameAction(a, clientGame.getCard(CardPool.Cards[actionCardID-1], CardInfo.CardType.MONSTER, true), clientGame.getCard(CardPool.Cards[targetCardID-1])); // action.executeAction(); // // Debug.Log(string.Format("Card with ID {0} is performing action: {1} on card with ID {2}", actionCardID, a, targetCardID)); // } // break; // //end case EventCode.PropertiesChanged: if (clientPlayer != null && enemyPlayer != null) { turnNumber = (float)this.CurrentRoom.CustomProperties["t#"]; isTurn = ((int)this.CurrentRoom.CustomProperties["tp"] == this.LocalPlayer.ID); Debug.Log(string.Format("Other player updated room properties. Turn #: {0}, Client's Turn: {1}", turnNumber, isTurn)); } break; } }