//dafault game turn behaviour public void MakeGameTurn() { //placeholder for battle ending if (PlayerList.Count == 0 || AIList.Count == 0) { gameOverTextGO.SetActive(true); return; } classTurnCounter++; if (classTurnCounter > turnList.Count) { classTurnCounter = 1; } currentTurnHero = turnList[classTurnCounter - 1]; CurrentTurnIndicator.SetActive(true); Vector3 indicatorSetter = currentTurnHero.gameObject.transform.position; CurrentTurnIndicator.transform.position = new Vector3(indicatorSetter.x, 2, indicatorSetter.z); if (currentTurnHero.mySlot.side == Affiliation.Enemy) { AIHandler.ChooseBehaviour(currentTurnHero, AIList, PlayerList, out targetsAmount); } }
private void EnemySpawnHandler() { if ((Time.time - timeSinceLastSpawn) >= spawnCheck && !(currEntities >= maxEntities)) { Vector3 spawnPoint = spawnPoints[Random.Range(0, spawnPoints.Count)].transform.position; EnemyData chosenData = enemyTypes[Random.Range(0, enemyTypes.Count)]; GameObject refr = Instantiate(enemyObject, spawnPoint, Quaternion.identity, entityParent.transform); AIHandler refrData = refr.GetComponent <AIHandler>(); refrData.sr.sprite = chosenData.enemySprite; refrData._type = chosenData.enemyType; refrData.target = _player.transform; refrData.maxHealth = chosenData.MaxHealth; refrData.moveSpeed = chosenData.MovementSpeed; refrData.minDistance = chosenData.MinFollowDistance; refrData.damageAmount = chosenData.Damage; refrData.damageTickRate = chosenData.DamageRate; refrData._dataContainer = chosenData; // refrData._wake = true; spawnCheck = Random.Range(minSpawnRate, maxSpawnRate); currEntities = Mathf.Clamp((currEntities + 1), 0, maxEntities); timeSinceLastSpawn = Time.time; } }
/// <summary> /// Create root Node /// </summary> /// <param name="player"></param> /// <param name="opponentPlayer"></param> public Node(Player player, Player opponentPlayer) { board = AIHandler.CloneBoard(_GameManager.board); this.player = AIHandler.ClonePlayer(player); this.opponentPlayer = AIHandler.ClonePlayer(opponentPlayer); captureBoxesPlayer = (player == _GameManager.players[0] ? AIHandler.CloneCaptureBoxesInitial(_GameManager.players[0].captureBench) : AIHandler.CloneCaptureBoxesInitial(_GameManager.players[1].captureBench)); captureBoxesOpponentPlayer = (opponentPlayer == _GameManager.players[0] ? AIHandler.CloneCaptureBoxesInitial(_GameManager.players[0].captureBench) : AIHandler.CloneCaptureBoxesInitial(_GameManager.players[1].captureBench)); isInitialPlayer = true; }
public override IEnumerator Enter() { yield return(base.Enter()); //Show the trump selector if the active player is a human player if (owner.Memory.GetData <Player>("Player" + owner.Memory.GetData <int>("ActivePlayer")).isHuman) { Card revealedCard = owner.Memory.GetData <Card>("RevealedCardFromKittie"); if (GameManager.AnimateGame) { //Ensure that other parts of the game are finished animating before we cary on while (revealedCard.animating) { yield return(null); } } //Show Trump Selector TrumpSelector tS = owner.Memory.GetData <TrumpSelector>("TrumpSelector"); tS.gameObject.SetActive(true); Dictionary <Card.Suit, UnityEngine.UI.Button> buttons = new Dictionary <Card.Suit, UnityEngine.UI.Button>(); buttons.Add(Card.Suit.Clubs, tS.clubs); buttons.Add(Card.Suit.Hearts, tS.hearts); buttons.Add(Card.Suit.Diamonds, tS.diamonds); buttons.Add(Card.Suit.Spades, tS.spades); //Hide the pass button if we are screwing the dealer if (GameManager.ScrewTheDealer && revealedCard.faceDown) { tS.aloneToggle.gameObject.SetActive(false); } else { tS.aloneToggle.gameObject.SetActive(true); } foreach (var suit in buttons.Keys) { if (revealedCard.faceDown) { //Only show the ones that do not match the turned down suit buttons[suit].interactable = (suit != revealedCard.suit); } else { //Set only the suit-button for the reveleaved card as showing buttons[suit].interactable = (suit == revealedCard.suit); } } } else { yield return(AIHandler.MakeTrumpOrderingDecision(owner.Memory.GetData <int>("ActivePlayer"), owner.Memory.GetData <PointSpread>("Player" + owner.Memory.GetData <int>("ActivePlayer") + "PointSpread"), owner)); } }
public void StartTurn() { for (int i = 0; i < Characters.Count; i++) { Characters[i].StartTurn(); } AIHandler.StartAIActions(); IsActive = true; Changed(); }
/// <summary> /// Create a children node, and apply the move given to get to the new state of the game /// </summary> /// <param name="parentNode">the parent node of this node</param> /// <param name="move">the move to get to the new state from parentNode</param> /// <param name="player">the current player in this node</param> /// <param name="opponentPlayer">the opponent player</param> /// <param name="makeTree"> will parent and children be insitialised</param> public Node(Node parentNode, Move move, Player player, Player opponentPlayer) { board = AIHandler.CloneBoard(parentNode.board); this.player = AIHandler.ClonePlayer(player); this.opponentPlayer = AIHandler.ClonePlayer(opponentPlayer); captureBoxesPlayer = AIHandler.CloneCaptureBoxesNode(parentNode.captureBoxesPlayer); captureBoxesOpponentPlayer = AIHandler.CloneCaptureBoxesNode(parentNode.captureBoxesOpponentPlayer); isInitialPlayer = parentNode.isInitialPlayer; Move m = AIHandler.CloneMove(move); m.play(this); _GameManager.AIupdateAllTokenMoves(this); isInitialPlayer = isInitialPlayer == true ? false : true; }
// Use this for initialization void Awake() { ui = GetComponent <UIHandler>(); animations = GetComponent <AnimationHandler>(); player = GameObject.Find("PlayerController").GetComponent <PlayerHandler>(); ai = GameObject.Find("AIController").GetComponent <PlayerHandler>(); aiHandler = GameObject.Find("AIController").GetComponent <AIHandler>(); player.isPlayer = true; ai.isPlayer = false; cardBack = Resources.Load <Sprite>("Images/card_back"); discardPilePosition = GameObject.Find("DiscardPile").transform.position; Initialize(); }
public GameManager(IGameCallback gameCallback) { this.gameCallback = gameCallback; // Load Creatures this.Friends = new List <FDCreature>(); this.Enemies = new List <FDCreature>(); this.Npcs = new List <FDCreature>(); this.Deads = new List <FDCreature>(); eventManager = new GameEventManager(this); dispatcher = new GameStateDispatcher(this); enemyAIHandler = new AIHandler(this, CreatureFaction.Enemy); npcAIHandler = new AIHandler(this, CreatureFaction.Npc); }
public void InformAIsSkillPicked() { if (singlePlayer) { for (int i = 0; i < numberOfPlayers; i++) { if (!players[i]) { continue; } if (myPlayerId != i) { AIHandler handler = players[i].GetComponent <AIHandler>(); if (handler.DontUpdateDest) { handler.DontUpdateDest = false; handler.SetRandomDestination(); } } } } }
void Start() { animatorAK47 = AK47.GetComponent <Animator>(); animatorRocketLauncher = RocketLauncher.GetComponent <Animator>(); animatorHands = Hands.GetComponent <Animator>(); animatorBoxGloves = BoxGloves.GetComponent <Animator>(); rb = GetComponent <Rigidbody>(); posY = transform.position.y; if (botPlayer) { navMeshAgent = GetComponent <NavMeshAgent>(); botAiHandler = GetComponent <AIHandler>(); navmeshSpeed = navMeshAgent.speed; navmeshASpeed = navMeshAgent.angularSpeed; } if (IsMyChar) { isMyChar = true; gm.gfButton.CharController = GetComponent <CharacterController>(); myPhotonView = GetComponent <PhotonView>(); } PhotonNetwork.AddCallbackTarget(this); }
void SpawnPlayers() { for (byte i = 0; i < numberOfPlayers; i++) { //Create instances players[i] = Instantiate(CharacterPrefab, PlayerSpawnPositions[i], Quaternion.Euler(PlayerSpawnRotations[i])).transform; players[i].GetComponent <CharacterController>().GM = GetComponent <GameManager>(); if (!singlePlayer) { int temp = MultiplayerManager.SetViewId(i, players[i]); if (temp != -1) { myPlayerId = temp; players[temp].GetComponent <CharacterController>().IsMyChar = true; CharCameraController.MyCharacterRb = players[i].GetComponent <Rigidbody>(); CharCameraController.MyCharacterTr = players[i].transform; CharCameraController.Cc = players[temp].GetComponent <CharacterController>(); } } if (myPlayerId != i && singlePlayer) { NavMeshAgent na = players[i].gameObject.AddComponent <NavMeshAgent>(); na.radius = 1.4f; na.height = 2.75f; na.agentTypeID = 0; na.obstacleAvoidanceType = ObstacleAvoidanceType.LowQualityObstacleAvoidance; na.speed = 8; na.angularSpeed = 400; na.autoBraking = false; na.acceleration = 100; AIHandler ah = players[i].gameObject.AddComponent <AIHandler>(); ah.DestMesh = spawnPosMesh; players[i].GetComponent <CharacterController>().BotPlayer = true; } else if (myPlayerId == i && singlePlayer) { players[i].GetComponent <CharacterController>().IsMyChar = true; CharCameraController.MyCharacterRb = players[i].GetComponent <Rigidbody>(); CharCameraController.MyCharacterTr = players[i].transform; CharCameraController.Cc = players[i].GetComponent <CharacterController>(); } // Assign materials MeshRenderer mr = players[i].Find("CharacterEquipments").Find("CharacterShape") .GetComponent <MeshRenderer>(); mr.sharedMaterials = new Material[] { BodyMaterials[i], EyeMaterials[i], MouthMaterials[i] }; // Paint color and box gloves color assignments switch (i) { case 0: players[i].GetComponent <CharacterController>().PaintColor = Color.red; players[i].GetComponent <CollisionPainter>().brush.Color = Color.red; players[i].Find("CharacterEquipments").Find("BoxGloves").Find("LeftBoxGlove").Find("Cube") .GetComponent <MeshRenderer>().material.color = Color.red; players[i].Find("CharacterEquipments").Find("BoxGloves").Find("RightBoxGlove").Find("Cube") .GetComponent <MeshRenderer>().material.color = Color.red; break; case 1: players[i].GetComponent <CharacterController>().PaintColor = Color.yellow; players[i].GetComponent <CollisionPainter>().brush.Color = Color.yellow; players[i].Find("CharacterEquipments").Find("BoxGloves").Find("LeftBoxGlove").Find("Cube") .GetComponent <MeshRenderer>().material.color = Color.yellow; players[i].Find("CharacterEquipments").Find("BoxGloves").Find("RightBoxGlove").Find("Cube") .GetComponent <MeshRenderer>().material.color = Color.yellow; break; case 2: players[i].GetComponent <CharacterController>().PaintColor = Color.green; players[i].GetComponent <CollisionPainter>().brush.Color = Color.green; players[i].Find("CharacterEquipments").Find("BoxGloves").Find("LeftBoxGlove").Find("Cube") .GetComponent <MeshRenderer>().material.color = Color.green; players[i].Find("CharacterEquipments").Find("BoxGloves").Find("RightBoxGlove").Find("Cube") .GetComponent <MeshRenderer>().material.color = Color.green; break; case 3: players[i].GetComponent <CharacterController>().PaintColor = Color.blue; players[i].GetComponent <CollisionPainter>().brush.Color = Color.blue; players[i].Find("CharacterEquipments").Find("BoxGloves").Find("LeftBoxGlove").Find("Cube") .GetComponent <MeshRenderer>().material.color = Color.blue; players[i].Find("CharacterEquipments").Find("BoxGloves").Find("RightBoxGlove").Find("Cube") .GetComponent <MeshRenderer>().material.color = Color.blue; break; } // Face expression textures assignment for (byte j = 0; j < 4; j++) { switch (i) { case 0: players[i].GetComponent <FaceExpressionHandler>().EyeExpressions[j] = EyeExpressionsRed[j]; break; case 1: players[i].GetComponent <FaceExpressionHandler>().EyeExpressions[j] = EyeExpressionsYellow[j]; break; case 2: players[i].GetComponent <FaceExpressionHandler>().EyeExpressions[j] = EyeExpressionsGreen[j]; break; case 3: players[i].GetComponent <FaceExpressionHandler>().EyeExpressions[j] = EyeExpressionsBlue[j]; break; } } for (byte j = 0; j < 3; j++) { switch (i) { case 0: players[i].GetComponent <FaceExpressionHandler>().MouthExpressions[j] = MouthExpressionsRed[j]; break; case 1: players[i].GetComponent <FaceExpressionHandler>().MouthExpressions[j] = MouthExpressionsYellow[j]; break; case 2: players[i].GetComponent <FaceExpressionHandler>().MouthExpressions[j] = MouthExpressionsGreen[j]; break; case 3: players[i].GetComponent <FaceExpressionHandler>().MouthExpressions[j] = MouthExpressionsBlue[j]; break; } } } for (byte i = 0; i < numberOfPlayers; i++) { int index = 0; Transform[] otherPlayers = new Transform[numberOfPlayers - 1]; for (byte j = 0; j < numberOfPlayers; j++) { if (i == j) { continue; } otherPlayers[index] = players[j].transform; index++; } players[i].GetComponent <CharacterController>().OtherPlayers = otherPlayers; } }
public override IEnumerator Enter() { yield return(base.Enter()); string activePlayerName = "Player" + owner.Memory.GetData <int>("ActivePlayer"); Player activePlayer = owner.Memory.GetData <Player>(activePlayerName); List <Card> plays = owner.Memory.GetData <List <Card> >("Plays"); //Check if the active player is playing this hand if (activePlayer.playingRound == false) { owner.Transition <Play>(); } //Check if we are done playing cards else if (plays.Count >= 4 || (owner.Memory.GetData <bool>("Alone") && plays.Count >= 3)) { //End the trick owner.Transition <EndTrick>(); } else { bool lockout = true; Card playedCard = null; //Wait for the active player to make a play System.Action <object, object> func = (object sender, object args) => { if (args == null) { return; } object[] trueArgs = (object[])args; GameObject zone = (GameObject)trueArgs[0]; playedCard = (Card)trueArgs[1]; if (zone.tag == "PlayZone" && activePlayer == playedCard.owner && AIHandler.isValidPlay(playedCard, activePlayer, owner)) { owner.Memory.GetData <List <Card> >("KnownCards").Add(playedCard); //Remove the card from the players hand. activePlayer.RemoveCard(playedCard); //Ensure card let go visuals are done now CardInteractionHandlers.CardMouseExit(this, playedCard); //Track the played card plays.Add(playedCard); owner.Memory.GetData <Dictionary <Card, int> >("PlaysMap").Add(playedCard, owner.Memory.GetData <int>("ActivePlayer")); //Move it to a resting position if (activePlayer.isHuman == false) { playedCard.StartCoroutine(GameManager.cardAnimator.FlyTo(Vector3.Lerp(Vector3.zero, activePlayer.gameObject.transform.position, 0.55f), playedCard, GameManager.AnimateGame, true)); } else { FMODUnity.RuntimeManager.PlayOneShot("event:/cardPlace" + Random.Range(1, 4), playedCard.transform.position); } //Flip the card up if it is face down if (playedCard.faceDown) { playedCard.StartCoroutine(GameManager.cardAnimator.Flip(playedCard, GameManager.AnimateGame)); } //Adjust the hand visuals playedCard.StartCoroutine(GameManager.cardAnimator.AdjustHand(activePlayerName, GameManager.AnimateGame, owner)); //Advance the coroutine lockout = false; } else { //Debug.Log("Invalid play, returning card"); playedCard.StartCoroutine(GameManager.cardAnimator.FlyTo(playedCard.goalPosition, playedCard, GameManager.AnimateGame)); } }; this.AddObserver(func, "CardPlayedInZone" + owner.UID); if (activePlayer.isHuman) { CardInteractionHandlers.CanPlayCard = true; } if (activePlayer.isHuman == false) { if (GameManager.AnimateGame) { yield return(new WaitForSeconds(0.25f)); } yield return(AIHandler.MakePlayDecision(owner.Memory.GetData <int>("ActivePlayer"), owner.Memory.GetData <PointSpread>("Player" + owner.Memory.GetData <int>("ActivePlayer") + "PointSpread"), owner)); } while (lockout) { yield return(null); } CardInteractionHandlers.CanPlayCard = false; this.RemoveObserver(func, "CardPlayedInZone" + owner.UID); owner.Transition <Play>(); } //Advance the active player owner.Memory.SetData("ActivePlayer", (owner.Memory.GetData <int>("ActivePlayer") == 3) ? 0 : owner.Memory.GetData <int>("ActivePlayer") + 1); }
public override IEnumerator Exit() { yield return(base.Exit()); //Hide the trump selector owner.Memory.GetData <TrumpSelector>("TrumpSelector").gameObject.SetActive(false); //If we are leaving the Trump round and have selected a trump, prepare regular play if (owner.Memory.HasKey <Card.Suit>("Trump")) { if (owner.Memory.GetData <Player>("Player" + owner.Memory.GetData <int>("ActivePlayer")).isHuman == false && GameManager.AnimateGame) { GameManager.AccessInstance().StartCoroutine(HandleAISpeach(GameManager.SpawnAIText(owner.Memory.GetData <int>("ActivePlayer"), 2, owner))); if (owner.Memory.GetData <bool>("Alone")) { GameManager.AccessInstance().StartCoroutine(HandleAISpeach(GameManager.SpawnAIText(owner.Memory.GetData <int>("ActivePlayer"), 3, owner))); } } //Organize AI and player's hands Player[] players = new Player[] { owner.Memory.GetData <Player>("Player0"), owner.Memory.GetData <Player>("Player1"), owner.Memory.GetData <Player>("Player2"), owner.Memory.GetData <Player>("Player3") }; System.Action OrganizeHands = () => { foreach (Player p in players) { if (p.isHuman) { Card.Suit trump = owner.Memory.GetData <Card.Suit>("Trump"); System.Func <Card, int> calcVal = (Card c) => { //Intial value is as printed on the card int val = (int)c.value; //Clump up same suits val += ((int)c.suit) * 30; //If on trump, add value if (c.suit == trump) { val += 500; } //Override on-color Jack if (c.suit == trump.SameColorSuit() && c.value == Card.Value.Jack) { val = 99995; } //Override on-trump Jack if (c.suit == trump && c.value == Card.Value.Jack) { val = 99999; } return(val); }; p.GetHand().Sort((Card x, Card y) => { if (calcVal(x) < calcVal(y)) { return(-1); } else { return(1); } }); p.GetHand().Reverse(); } else { System.Action <List <Card> > ShuffleTheList = (List <Card> shuffleList) => { int n = shuffleList.Count; while (n > 1) { n--; int k; //Shuffle, but don't let things stay in the same spot do { k = Random.Range(0, n + 1); } while (k == n); Card value = shuffleList[k]; shuffleList[k] = shuffleList[n]; shuffleList[n] = value; } }; ShuffleTheList(p.GetHand()); } //Animate the cards where they belong p.StartCoroutine(GameManager.cardAnimator.AdjustHand(p.gameObject.name, GameManager.AnimateGame, owner)); } }; //Create a stamp to track what trump is if (GameManager.AnimateGame) { owner.Memory.SetData <GameObject>("TrumpIndicator", GameManager.SpawnTrumpIndicator(owner.Memory.GetData <Card.Suit>("Trump"), owner.Memory.GetData <int>("ActivePlayer") % 2)); } Deck d = owner.Memory.GetData <Deck>("GameDeck"); //If the revealed card is still face up, have the dealer switch with it. if (owner.Memory.GetData <Card>("RevealedCardFromKittie").faceDown == false && //The following is some going alone logic. First check if someone went alone. //The specific case is when our partner calls a loner and we are the dealer so we need to skip doing the pickup //So we check for the specific case, and then compare it to false. //First we check for someone having gone alone. Then we check to make sure that was person was on our team, and then we check to see if it was not the dealer. (owner.Memory.GetData <bool>("Alone") && owner.Memory.GetData <int>("TrumpCaller") % 2 == owner.Memory.GetData <int>("Dealer") % 2 && owner.Memory.GetData <int>("TrumpCaller") != owner.Memory.GetData <int>("Dealer")) == false) { //Add the revealed card to the dealer's hand Card rCard = owner.Memory.GetData <Card>("RevealedCardFromKittie"); string dealerName = "Player" + owner.Memory.GetData <int>("Dealer"); Player dealer = owner.Memory.GetData <Player>(dealerName); dealer.AddCard(rCard); if (GameManager.AnimateGame) { yield return(GameManager.cardAnimator.Orient(rCard, dealerName, GameManager.AnimateGame, owner)); } //Hide the card if (GameManager.AnimateGame) { if (dealer.isHuman == false && GameManager.ShowAllCards == false) { yield return(GameManager.cardAnimator.Flip(rCard, GameManager.AnimateGame)); } } if (GameManager.AnimateGame) { yield return(GameManager.cardAnimator.AdjustHand(dealerName, GameManager.AnimateGame, owner)); } OrganizeHands(); //Wait for the cards to orient if (GameManager.AnimateGame) { foreach (Player player in players) { foreach (Card card in player.GetHand()) { while (card.animating) { yield return(null); } } } } //Add Listeners for Card interaction CardInteractionHandlers.EnableCardInteraction(this); if (dealer.isHuman) { CardInteractionHandlers.CanPlayCard = true; } bool lockout = true; System.Action <object, object> func = (object sender, object args) => { if (args == null) { return; } object[] trueArgs = (object[])args; GameObject zone = (GameObject)trueArgs[0]; Card card = (Card)trueArgs[1]; if (zone.tag == "PlayZone") { //Set the played card as the revealed card owner.Memory.SetData("RevealedCardFromKittie", card); //Remove the card from the dealers hand. dealer.RemoveCard(card); //Do exit visuals to signify the card has left hand control CardInteractionHandlers.CardMouseExit(this, card); //Adjust the hand visuals card.StartCoroutine(GameManager.cardAnimator.AdjustHand(dealerName, GameManager.AnimateGame, owner)); //Advance the coroutine lockout = false; } else { card.StartCoroutine(GameManager.cardAnimator.FlyTo(card.goalPosition, card, GameManager.AnimateGame)); } }; this.AddObserver(func, "CardPlayedInZone" + owner.UID); //Run the AI if (owner.Memory.GetData <Player>(dealerName).isHuman == false) { yield return(AIHandler.MakeTrumpDiscardDecision(owner.Memory.GetData <int>("Dealer"), owner.Memory.GetData <PointSpread>("Player" + owner.Memory.GetData <int>("ActivePlayer") + "PointSpread"), owner)); } if (GameManager.AnimateGame) { //Yield until the player plays one while (lockout) { yield return(null); } } //Remove listeners for card interaction CardInteractionHandlers.CanPlayCard = false; CardInteractionHandlers.DisableCardInteraction(this); this.RemoveObserver(func, "CardPlayedInZone" + owner.UID); } else { OrganizeHands(); //Wait for the cards to orient if (GameManager.AnimateGame) { foreach (Player player in players) { foreach (Card card in player.GetHand()) { while (card.animating) { yield return(null); } } } } } Card revealedCard = owner.Memory.GetData <Card>("RevealedCardFromKittie"); //Flip the card over if needed if (revealedCard.faceDown == false) { revealedCard.StartCoroutine(GameManager.cardAnimator.Flip(revealedCard, GameManager.AnimateGame)); } //Move card to the deck if (GameManager.AnimateGame) { yield return(GameManager.cardAnimator.FlyTo(d.basePosition, revealedCard, GameManager.AnimateGame)); } //Add revealed card back to deck d.Place(new Card[] { revealedCard }); //Slide the deck these cards offscreen foreach (Card card in d) { card.SetOrdering(-3); card.StartCoroutine(GameManager.cardAnimator.FlyTo(Vector3.LerpUnclamped(Vector3.zero, owner.Memory.GetData <Player>("Player" + owner.Memory.GetData <int>("Dealer")).gameObject.transform.position, 3.4f), card, GameManager.AnimateGame)); } //Reset active player to right of dealer owner.Memory.SetData("ActivePlayer", (owner.Memory.GetData <int>("Dealer") == 3) ? 0 : owner.Memory.GetData <int>("Dealer") + 1); //Game should be good to start, wait a moment before starting play if (GameManager.AnimateGame) { yield return(new WaitForSeconds(0.25f)); } //Enable regular card interaction CardInteractionHandlers.EnableCardInteraction(this); } else { if (owner.Memory.GetData <Player>("Player" + owner.Memory.GetData <int>("ActivePlayer")).isHuman == false && GameManager.AnimateGame) { GameManager.AccessInstance().StartCoroutine(HandleAISpeach(GameManager.SpawnAIText(owner.Memory.GetData <int>("ActivePlayer"), 1, owner))); if (GameManager.AnimateGame) { yield return(new WaitForSeconds(0.5f)); } } //Move on the active player owner.Memory.SetData("ActivePlayer", (owner.Memory.GetData <int>("ActivePlayer") == 3) ? 0 : owner.Memory.GetData <int>("ActivePlayer") + 1); } }
/// <summary> /// Met à jour les informations d'états et d'actions à partir du tableau courant. /// </summary> public void UpdateSensors(Board board, FOXCSOptions fo) { this.states.Clear(); this.actions.Clear(); this.board = AIHandler.CloneBoard(board); this.tokenOnBoard.Clear(); List <Token> tokenList = _GameManager.GetAllTokens(); if (_GameManager.toPromoteToken != null) { this.actions.Add(new Attribute("promote", new string[] { _GameManager.toPromoteToken.ToPrologCode(), FOXCS.ToPrologCode(true) }, fo.actionPredicateOptions["promote"])); this.actions.Add(new Attribute("promote", new string[] { _GameManager.toPromoteToken.ToPrologCode(), FOXCS.ToPrologCode(false) }, fo.actionPredicateOptions["promote"])); } foreach (Token tok in tokenList) { Attribute acc; if (!tok.isCaptured) { tokenOnBoard.Add(tok.ToPrologCode()); this.states.Add(new Attribute("onTile", new string[] { tok.ToPrologCode(), "c" + tok.box.getCoord().x.ToString(), "l" + tok.box.getCoord().y.ToString() }, fo.statePredicateOptions["onTile"])); List <Coordinates> tokLegalMoves = !tok.isPromoted ? tok.legalMoves(this.board) : tok.legalMovesPlus(this.board); List <Coordinates> tokPossibleMoves = !tok.isPromoted ? tok.possibleMoves(this.board) : tok.possibleMovesPlus(this.board); foreach (Coordinates cord in tokLegalMoves) { acc = new Attribute("legalMove", new string[] { tok.ToPrologCode(), "c" + cord.x.ToString(), "l" + cord.y.ToString() }, fo.statePredicateOptions["legalMove"]); if (!states.Contains(acc)) { this.states.Add(acc); } if (tok.owner.Equals(_GameManager.players[_GameManager.currentPlayerIndex]) && _GameManager.toPromoteToken == null) { acc = new Attribute("move", new string[] { tok.ToPrologCode(), "c" + cord.x.ToString(), "l" + cord.y.ToString() }, fo.actionPredicateOptions["move"]); if (!actions.Contains(acc)) { this.actions.Add(acc); } } } /* * tok.getTokensToEat(); * foreach (Coordinates cord in tok.possibleEats) * { * acc = new Attribute("inRange", new string[] { tok.ToPrologCode(), this.board.boxes[cord.getIndex()].getToken().ToPrologCode(), "c" + cord.x.ToString(), "l" + cord.y.ToString() }, fo.statePredicateOptions["inRange"]); * if (!states.Contains(acc)) * this.states.Add(acc); * } */ } else { foreach (Coordinates cord in tok.legalDrops(board)) { if (tok.owner.Equals(_GameManager.players[_GameManager.currentPlayerIndex]) && _GameManager.toPromoteToken == null) { acc = new Attribute("drop", new string[] { tok.ToPrologCode(), "c" + cord.x.ToString(), "l" + cord.y.ToString() }, fo.actionPredicateOptions["drop"]); if (!actions.Contains(acc)) { this.actions.Add(acc); } } acc = new Attribute("legalDrop", new string[] { tok.ToPrologCode(), "c" + cord.x.ToString(), "l" + cord.y.ToString() }, fo.statePredicateOptions["legalDrop"]); if (!states.Contains(acc)) { this.states.Add(acc); } } } } }
public override IEnumerator Enter() { yield return(base.Enter()); //Delay if (GameManager.AnimateGame) { yield return(new WaitForSeconds(1.0f)); } //Debug.Log("---End Trick"); //Determine Winner List <Card> originalPlays = owner.Memory.GetData <List <Card> >("Plays"); List <Card> plays = AIHandler.CloneListOfCards(originalPlays); foreach (Card card in plays) { while (card.animating) { yield return(null); } } Card.Suit trump = owner.Memory.GetData <Card.Suit>("Trump"); Card lead = plays[0]; plays.Sort((Card x, Card y) => { if (AIHandler.ScoreingValue(x, owner) < AIHandler.ScoreingValue(y, owner)) { return(-1); } else { return(1); } }); plays.Reverse(); //Debug.Log("Trump: " + trump + "\nLead:" + lead.suit); string winnerName = "Player" + owner.Memory.GetData <Dictionary <Card, int> >("PlaysMap")[plays[0]]; Player winningPlayer = owner.Memory.GetData <Player>(winnerName); int winnerPlayerNum = 0; switch (winnerName.ToLower()) { case "player0": winnerPlayerNum = 0; break; case "player1": winnerPlayerNum = 1; break; case "player2": winnerPlayerNum = 2; break; case "player3": winnerPlayerNum = 3; break; } //Set the active player to the winner owner.Memory.SetData("ActivePlayer", winnerPlayerNum); //Debug Log Trick { string t = "Trick Winner: Player" + winnerPlayerNum + " with " + plays[0] + "\nOP:"; for (int i = 0; i < originalPlays.Count; i++) { t += originalPlays[i].Shortname() + ","; } t += "\nP:"; for (int i = 0; i < plays.Count; i++) { t += plays[i].Shortname() + ","; } //Debug.Log(t); } //Award trick to the correct team owner.Memory.SetData(winnerName + "Tricks", owner.Memory.GetData <int>(winnerName + "Tricks") + 1); //Place Trump Indicators { List <GameObject> indicators = owner.Memory.GetData <List <GameObject> >(winnerName + "TrickIndicators"); if (GameManager.AnimateGame) { indicators.Add(GameManager.SpawnTrickIndicator(winnerPlayerNum % 2)); } float r = 1.15f; float size = 10.0f; float baseAngle = 0.0f; switch (winnerName.ToLower()) { case "player0": baseAngle = 270.0f; break; case "player1": baseAngle = 180.0f; break; case "player2": baseAngle = 90.0f; break; case "player3": baseAngle = 0.0f; break; } float range = size * (indicators.Count / 2.0f); float step = 1.0f / indicators.Count; //ret[i] = Vector3.Lerp(point + offset, point - offset, step * i) - (horizAxis * (cardWidth / 2.0f));// - ((amt % 2 != 0) ? : Vector3.zero); for (int i = 0; i < indicators.Count; i++) { float placeAngle = Mathf.Lerp(baseAngle + range, baseAngle - range, step * i) - (size / 2.0f); placeAngle *= Mathf.Deg2Rad; indicators[i].transform.position = new Vector3(r * Mathf.Cos(placeAngle), r * Mathf.Sin(placeAngle), 0.0f); } } //Animate Cards { foreach (Card card in plays) { card.SetOrdering(-3); //Flip down the played cards card.StartCoroutine(GameManager.cardAnimator.Flip(card, GameManager.AnimateGame)); //Orient towards winning player card.StartCoroutine(GameManager.cardAnimator.Orient(card, winnerName, GameManager.AnimateGame, owner)); //Have the cards fly past the winner's hand (from center) as if they are collecting the trick card.StartCoroutine(GameManager.cardAnimator.FlyTo(Vector3.LerpUnclamped(Vector3.zero, winningPlayer.gameObject.transform.position, 3.4f), card, GameManager.AnimateGame)); } foreach (Card card in plays) { while (card.animating) { yield return(null); } } } //Return the plays to the deck owner.Memory.GetData <Deck>("GameDeck").Place(plays.ToArray()); //Reset the plays list owner.Memory.SetData <List <Card> >("Plays", new List <Card>()); //Transition if (owner.Memory.GetData <int>("Player0Tricks") + owner.Memory.GetData <int>("Player1Tricks") + owner.Memory.GetData <int>("Player2Tricks") + owner.Memory.GetData <int>("Player3Tricks") >= 5) { //If we have played 5 tricks, go to end of hand owner.Transition <EndHand>(); } else { //Else play a new round owner.Transition <Play>(); } }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { CharacterController cc = other.GetComponent <CharacterController>(); switch (skillIndex) { case 0: if (cc.BotPlayer) { AIHandler handler = cc.GetComponent <AIHandler>(); handler.ClearGunDecisionFlags(); handler.AK47Taken = true; gm.CharCameraController.ArmedCharacters.Add(other.transform); } else { gm.CharCameraController.GunPicked = true; gm.gpUI.ChangeGunFistSprite(false); } cc.AK47Picked = true; cc.PickAK47(); break; case 1: if (cc.BotPlayer) { AIHandler handler = other.GetComponent <AIHandler>(); handler.ClearGunDecisionFlags(); handler.RocketTaken = true; gm.CharCameraController.ArmedCharacters.Add(other.transform); } else { gm.CharCameraController.GunPicked = true; gm.gpUI.ChangeGunFistSprite(false); } cc.RocketPicked = true; cc.PickRocketLauncher(); cc.faceExpHandler.ChangeFaceExpression(FaceExpressionHandler.FaceExpressions.ANGRY); cc.ReturnToSmile = false; break; case 2: cc.SpeedSkillPicked = true; cc.SetDoubleSpeed(); break; case 3: cc.GrowSkillPicked = true; cc.Grow(); break; case 4: cc.IncreaseHealth(25); break; case 5: cc.ActivateBombSkill(); if (!cc.BotPlayer) { gm.CharCameraController.ShakeCameraTrigger = true; } break; } if (skillIndex != 5) { Instantiate(PickableSkillEffect, transform.position + Vector3.up * 1f, PickableSkillEffect.transform.rotation); } else { Instantiate(BombSkillEffect, transform.position, BombSkillEffect.transform.rotation); } cc.PlaySkillSoundFX(skillIndex); gm.InformAIsSkillPicked(); gm.CharCameraController.SkillPositions.Remove(transform.position); Destroy(gameObject); } else if (other.CompareTag("Obstacle")) { other.transform.position += Vector3.right * 6; } }
IEnumerator HandleSkillSpawnProcess() { if (singlePlayer || PhotonNetwork.IsMasterClient) { while (true) { yield return(new WaitForSeconds(skillSpawnFrequence)); byte randomSkill = (byte)(Random.Range(0, 70) % 7); Vector3 skillPos = FindRandomPointInMesh(); if (PhotonNetwork.IsMasterClient) { object[] content = { randomSkill, skillPos }; RaiseEventOptions reo = new RaiseEventOptions() { Receivers = ReceiverGroup.Others }; SendOptions so = new SendOptions() { Reliability = true }; PhotonNetwork.RaiseEvent(2, content, reo, so); } if (randomSkill != 3) { PickableSkill ps = Instantiate(SkillPrefabs[randomSkill], skillPos, SkillPrefabs[randomSkill].transform.rotation) .GetComponent <PickableSkill>(); ps.GM = this; // inform all agents if (singlePlayer) { float[] playerDistacesToSkill = new float[numberOfPlayers]; for (int i = 0; i < numberOfPlayers; i++) { if (!players[i]) { playerDistacesToSkill[i] = float.PositiveInfinity; continue; } float distance = (players[i].transform.position - skillPos).sqrMagnitude; if (i != 0) { for (int j = 0; j < i; j++) { if (playerDistacesToSkill[j] + 9 < distance && !float.IsInfinity(playerDistacesToSkill[j])) { playerDistacesToSkill[i] = float.PositiveInfinity; break; } else { playerDistacesToSkill[i] = distance; } } } else { playerDistacesToSkill[i] = distance; } } for (int i = 0; i < numberOfPlayers; i++) { if (myPlayerId != i && !float.IsInfinity(playerDistacesToSkill[i])) { AIHandler handler = players[i].GetComponent <AIHandler>(); handler.DontUpdateDest = true; handler.SkillPosition = skillPos; handler.PickSkill = true; } } } CharCameraController.SkillPositions.Add(ps.transform.position); } else { Transform freezer = Instantiate(SkillPrefabs[randomSkill], skillPos, SkillPrefabs[randomSkill].transform.rotation) .GetComponent <Transform>(); FreezerSkill fs = freezer.Find("Freezer").GetComponent <FreezerSkill>(); fs.GM = GetComponent <GameManager>(); fs.SinglePlayer = singlePlayer; if (singlePlayer) { for (int i = 0; i < numberOfPlayers; i++) { if (!players[i]) { continue; } if (myPlayerId != i) { AIHandler handler = players[i].GetComponent <AIHandler>(); handler.FreezerSkillSpawned = true; handler.FreezerTr = freezer.Find("Freezer"); } } } CharCameraController.FreezerSpawned = true; CharCameraController.FreezerTr = freezer.Find("Freezer"); } } } }
private void Awake() { instance = this; }