Example #1
0
 public void placeTokenOnCell(CaseBehavior cell)
 {
     tokenPlace   = true;
     caseActuelle = cell.gameObject;
     cibleToken   = null;
     ciblesTokens.Clear();
 }
Example #2
0
        private void _SwitchTargetToTarget(Token token1, Token token2)
        {
            Debug.Assert(token1.cibleToken != null);
            Debug.Assert(token2.cibleToken != null);
            PlacementTokens cible1 = token1.cibleToken;
            PlacementTokens cible2 = token2.cibleToken;

            token1.placeToken(cible2);
            token2.placeToken(cible1);
        }
Example #3
0
        public void RecordPlacementOnRoomDiscovered(Token token, PlacementTokens target)
        {
            if (!doRecordInteractions(activePlayerIndex))
            {
                Logger.Instance.Log("LOG", "Skip RecordPlacementOnRoomDiscovered"); return;
            }

            gameData.RecordPlacementOnRoomDiscovered(activePlayerIndex, token.getOwnerIndex(), token.getTokenName(),
                                                     target.caseActuelle.column, target.caseActuelle.row);
        }
Example #4
0
        public void RecordPlacement(Token token, PlacementTokens target)
        {
            if (!doRecordInteractions(activePlayerIndex))
            {
                Logger.Instance.Log("LOG", "Skip RecordPlacement"); return;
            }

            gameData.RecordPlacement(activePlayerIndex, token.getOwnerIndex(), token.getTokenName(),
                                     target.transform.parent.GetComponent <HiddenTileBehavior>().tileAssociated.GetComponent <TileBehavior>().index);
        }
Example #5
0
 private PlacementTokens FindRevealedTileTarget(CaseBehavior cell)
 {
     foreach (GameObject cible in GameObject.FindGameObjectsWithTag("TileRevealedTarget"))
     {
         PlacementTokens target = cible.GetComponent <PlacementTokens>();
         if (target.caseActuelle == cell)
         {
             return(target);
         }
     }
     return(null);
 }
Example #6
0
        private void _SwitchTargetToCell(Token token1, Token token2)
        {
            Debug.Assert(token1.cibleToken != null);
            Debug.Assert(token2.caseActuelle != null);
            PlacementTokens cible1 = token1.cibleToken;
            CaseBehavior    cell2  = token2.caseActuelle.GetComponent <CaseBehavior>();

            token2.tokenPlace   = false;
            token2.caseActuelle = null;

            token1.placeTokenOnCell(cell2);
            token2.placeToken(cible1);
        }
Example #7
0
    private PlacementTokens findFreePlacementTargetOnHiddenTile(int indexTile)
    {
        Transform associatedTile = getHiddenTile(indexTile).transform;

        for (int j = 0; j < associatedTile.childCount; j++)
        {
            if (associatedTile.GetChild(j).name != "Highlight")
            {
                PlacementTokens cible = associatedTile.GetChild(j).GetComponent <PlacementTokens>();
                if (cible.tokenAssociated == null)
                {
                    return(cible);
                }
            }
        }
        return(null);
    }
Example #8
0
 // Place le token sur une case donnée
 public void placeToken(PlacementTokens cible)
 {
     // On lie le token et l'emplacement
     cible.tokenAssociated = gameObject;
     cibleToken            = cible;
     // Si placement de départ sur les salles, on valide automatiquement le placement et on change de joueur
     if (gManager.gameMacroState == GameProgression.TokenPlacement)
     {
         Debug.Assert(cible.transform.parent != null);
         gManager.onlineGameInterface.RecordPlacement(this, cible);
         cible.locked = true;
         if (gManager.isActivePlayer(affiliationJoueur))
         {
             gManager.SendMessage("oneTokenPlaced");
         }
     }
 }
Example #9
0
    private void SetTokenPosition(Token token, int row, int column, string carrierName, int carrierOwnerIndex, int indexRoomAssociated)
    {
        if (token.isRemovedFromGame())
        {
            token.GetComponent <TokenIHM>().hideToken();
            // since it is hidden, no need to set a position
            //token.caseActuelle = GameManager.gManager.getCase(row, column);
            //newPosition = token.caseActuelle.transform.position;
        }
        else if (carrierName != null) // carried token
        {
            // do nothing: carried tokens will be placed later
        }
        else if (token.tokenPlace) // token placed on board
        {
            token.caseActuelle = GameManager.gManager.getCase(row, column);
            token.setPosition(token.caseActuelle.transform.position);
        }
        else if (indexRoomAssociated != GameDataItem.NO_REFERENCE) // placed on room
        {
            PlacementTokens cible = findFreePlacementTargetOnHiddenTile(indexRoomAssociated);
            Debug.Assert(cible != null, "No Free Placement Target found on associated tile " + indexRoomAssociated);
            token.cibleToken      = cible;
            cible.tokenAssociated = token.gameObject;
            cible.locked          = true;
            token.setPosition(token.cibleToken.transform.position);

            // Si un joueur vient d'ouvrir une salle et que le pion est en attente d'y etre place
            if (indexRoomAssociated == managerData.roomBeingOpenedIndex)
            {
                token.ciblesTokens.Clear();
                token.ciblesTokens.AddRange(GameObject.FindGameObjectsWithTag("TileRevealedTarget"));
                HiddenTileBehaviorIHM hiddenTile = getHiddenTile(managerData.roomBeingOpenedIndex);
                token.setPosition(hiddenTile.getWaitingToBePlacedTokenPosition(token.cibleToken.transform.position));
            }
        }
        else // not placed
        {
            Debug.Assert(!token.tokenPlace, "there should be nothing to do, since game is in initial state");
        }
    }
Example #10
0
    private void removeTargetOfTokensToBePlacedOnDiscoveredRoom()
    {
        HiddenTileBehaviorIHM hiddenTile = getHiddenTile(managerData.roomBeingOpenedIndex);

        if (hiddenTile != null)
        {
            Transform associatedTile = hiddenTile.transform;
            for (int j = 0; j < associatedTile.childCount; j++)
            {
                if (associatedTile.GetChild(j).name != "Highlight")
                {
                    PlacementTokens cible = associatedTile.GetChild(j).GetComponent <PlacementTokens>();
                    if (cible.tokenAssociated != null)
                    {
                        cible.tokenAssociated.GetComponent <Token>().cibleToken = null;
                        cible.tokenAssociated = null;
                        cible.locked          = false;
                    }
                }
            }
        }
    }
Example #11
0
        private void ExecuteActionTokensUpdate(ActionTokensUpdate action)
        {
            foreach (var token in action.tokens)
            {
                if (!token.isHidden)
                {
                    gManager.onlineGameInterface.RegisterToken(token.playerId, token.token, token.id); // all ids update must be done first !!!
                }
            }
            if (gManager.onlineGameInterface.WaitingForExpectedState())
            {
                if (gManager.onlineGameInterface.GetCurrentOnlineState() == "discoverRoomPlaceToken")
                {
                    // if this assert is trigged we will need to add a
                    // hack for very special case, depending of weither bga send grouped updates or not for placed tokens.
                    Debug.Assert(action.tokens.Count <= 1, "discoverRoomPlaceToken's TokensUpdate has been grouped by bga !");
                }
                gManager.onlineGameInterface.ForceEndReplayAction();
                return;
            }

            bool discoveredRoomPlacementComplete = true;
            bool cancelCurrentMove = false;
            int placementIndex     = 0;
            foreach (var token in action.tokens)
            {
                Multi.Logger.Instance.Log("DETAIL", token.ToString());
                switch (action.destinationType)
                {
                case ActionTokensUpdate.Destination.STARTING_LINE:     // PLACEMENT1
                {
                    Debug.Assert(!token.onRoom);
                    if (isOnlinePlayer(token.playerId))
                    {
                        TokenIHM tokenIHM = GetRandomFreeCharacter(token.playerId).GetComponent <TokenIHM>();
                        tokenIHM.displayToken();         // Fix display bug
                        tokenIHM.placeTokenOnCell(gManager.getCase(token.y, token.x).GetComponent <CaseBehavior>());
                    }
                    else
                    {
                        Multi.Logger.Instance.Log("DETAIL", "Placement of hideen token on cell " + token.y + "," + token.x + " confirmed by bga");
                    }
                    break;
                }

                case ActionTokensUpdate.Destination.ROOM:     // PLACEMENT2
                {
                    Debug.Assert(token.onRoom);
                    HiddenTileBehavior tileBack = GetTileBack(token.room);
                    TokenIHM           tokenIHM = GetRandomFreeToken(token.playerId).GetComponent <TokenIHM>();
                    if (!tileBack.placeTokenOnAvailableSpot(tokenIHM))
                    {
                        Multi.Logger.Instance.Log("ERROR", "ActionPlayer: No spot found on tile index " + tileBack.tileAssociated.GetComponent <TileBehavior>().index);
                    }
                    break;
                }

                case ActionTokensUpdate.Destination.REVEAL:     // REVEAL STARTING CHARACTERS
                {
                    Debug.Assert(!token.onRoom && !token.isHidden);
                    Token tokenToPlace = GetTokenByNameAndPlayerId(token.token, token.playerId);
                    Debug.Assert(tokenToPlace != null);
                    Token tokenFound = GetTokenAtPosition(token.x, token.y);
                    Debug.Assert(tokenFound != null);
                    SwitchTokenPositions(tokenToPlace, tokenFound);
                    break;
                }

                case ActionTokensUpdate.Destination.TO_PLACE:     // ROOM DISCOVERED
                {
                    Debug.Assert(tileToDiscover != null);
                    PlacementTokens targetPlacement = tileToDiscover.getPlacementSpot(placementIndex);
                    ++placementIndex;
                    Debug.Assert(targetPlacement != null);
                    Token tokenFound   = targetPlacement.tokenAssociated.GetComponent <Token>();
                    Token tokenToPlace = GetTokenByNameAndPlayerId(token.token, token.playerId);
                    SwitchTokenPositions(tokenToPlace, tokenFound);
                    break;
                }

                case ActionTokensUpdate.Destination.BOARD:     // MISC
                {
                    if (gManager.onlineGameInterface.GetCurrentOnlineState() == "discoverRoomPlaceToken")
                    {
                        Debug.Assert(!token.isCarried);
                        Debug.Assert(!token.isHidden);
                        if (token.onRoom)
                        {
                            discoveredRoomPlacementComplete = false;
                        }
                        else
                        {
                            PlacementTokens target = FindRevealedTileTarget(gManager.getCase(token.y, token.x).GetComponent <CaseBehavior>());
                            Debug.Assert(target != null && target.tokenAssociated == null && !target.locked);
                            TokenIHM tokenIHM = GetTokenByNameAndPlayerId(token.token, token.playerId).GetComponent <TokenIHM>();
                            tokenIHM.placeToken(target.gameObject);
                        }
                    }
                    else if (gManager.onlineGameInterface.GetCurrentOnlineState() == "movingCharacterContinue")
                    {
                        if (GetTokenByNameAndPlayerId(token.token, token.playerId).gameObject == gManager.actionCharacter)
                        {
                            // update on the selected character means a move cancel, therefore: cancel move :)
                            cancelCurrentMove = true;
                        }
                    }
                    else
                    {
                        Multi.Logger.Instance.Log("LOG", "TokensUpdate: simple update has no effect");
                    }
                    break;
                }
                }
            }

            if (!discoveredRoomPlacementComplete)
            {
                Multi.Logger.Instance.Log("LOG", "TokensUpdate: discoveredRoom placement incomplete");
            }

            foreach (var token in action.tokens)
            {
                if (token.isCarried)
                {
                    gManager.onlineGameInterface.SetCarriedToken(token.holdingCharacterId, token.id);
                }
                else
                {
                    gManager.onlineGameInterface.SetDropped(token.id);
                }
            }

            if (action.destinationType == ActionTokensUpdate.Destination.TO_PLACE) // ROOM DISCOVERED
            {
                if (gManager.actionCharacter == null)
                {
                    gManager.actionCharacter = SelectACharacterToOpenRoom(tileToDiscover).gameObject;
                }
                if (!gManager.actionCharacter.GetComponent <CharacterBehavior>().selected)
                {
                    gManager.actionCharacter.GetComponent <CharacterBehavior>().selectionPersonnage();
                }
                tileToDiscover.openRoom();
                // TODO: wait for end of animation ?
                gManager.progression.BlockInteractionsUntilBgaAnswer(false); // allow player to interact again once room discovered
            }

            if (cancelCurrentMove)
            {
                gManager.actionCharacter.GetComponent <CharacterBehaviorIHM>().cancelMovement();
            }

            gManager.onlineGameInterface.ForceEndReplayAction();
        }