Beispiel #1
0
    public bool MoveToTarget(ActionType type, CaseBehavior target)
    {
        List <CaseBehavior> path = pathfinder.GetActionPath(type, target);

        if (path.Count > 0)
        {
            gManager.onlineGameInterface.RecordMove(type, this, target);

            CharacterBehaviorIHM characterIHM = GetComponent <CharacterBehaviorIHM>();
            if (!characterIHM.gliding)
            {
                characterIHM.gliding = true;
                characterIHM.moveTargets.Clear();
                foreach (CaseBehavior cell in path)
                {
                    characterIHM.moveTargets.Add(cell.cibleAssociated);
                    cell.cibleAssociated.GetComponent <SpriteRenderer>().color = Color.green;
                    if (cell.affiliationJoueur != null && cell.affiliationJoueur != affiliationJoueur)
                    {
                        break;
                    }
                }
                characterIHM.glideToNextPosition();
            }
            return(true);
        }

        return(false);
    }
Beispiel #2
0
        private void ExecuteActionHeal(ActionHeal action)
        {
            if (gManager.onlineGameInterface.WaitingForExpectedState())
            {
                gManager.onlineGameInterface.ForceEndReplayAction(); return;
            }

            CharacterBehaviorIHM character = GetTokenByNameAndPlayerId(action.tokenName, action.playerId).GetComponent <CharacterBehaviorIHM>();
            CharacterBehaviorIHM target    = GetTokenById(action.targetId).GetComponent <CharacterBehaviorIHM>();

            if (action.tokenName == "Troll")
            {
                Debug.Assert(character == target);
                Debug.Assert(character is CB_TrollIHM);
                character.characterSelection();
                character.GetComponent <CB_TrollIHM>().regenerate();
                gManager.onlineGameInterface.ForceEndReplayAction();
            }
            else if (action.tokenName == "Cleric")
            {
                Debug.Assert(character == target);
                Debug.Assert(character is CB_ClercIHM);
                character.characterSelection();
                character.GetComponent <CB_ClercIHM>().healCharacter();
                // TODO: the target seems not to be actually applied
                // EndReplay is done by the clerc
            }
            else
            {
                Debug.Assert(false, "Unexpected character type");
                gManager.onlineGameInterface.ForceEndReplayAction();
            }
        }
Beispiel #3
0
        private void ExecuteActionDoor(ActionDoor action)
        {
            if (gManager.onlineGameInterface.WaitingForExpectedState())
            {
                gManager.onlineGameInterface.ForceEndReplayAction(); return;
            }

            CaseBehavior actionCharacterCell = gManager.getCase(action.y1, action.x1).GetComponent <CaseBehavior>();

            CharacterBehavior c = actionCharacterCell.getNonWoundedCharacter();

            Debug.Assert(c != null);
            CharacterBehaviorIHM character = c.GetComponent <CharacterBehaviorIHM>();

            character.characterSelection();
            if (action.action == ActionType.DESTROYDOOR)
            {
                Debug.Assert(character is CB_GuerrierIHM);
                character.GetComponent <CB_GuerrierIHM>().briserHerse();
            }
            else
            {
                Debug.Assert(character is CB_VoleuseIHM);
                character.GetComponent <CB_VoleuseIHM>().changerEtatHerse();
            }
            gManager.onlineGameInterface.ForceEndReplayAction();
        }
Beispiel #4
0
        private void ExecuteActionRoomRotated(ActionRoomRotated action)
        {
            if (gManager.onlineGameInterface.WaitingForExpectedState())
            {
                gManager.onlineGameInterface.ForceEndReplayAction(); return;
            }

            TileBehaviorIHM      tile  = GetTileOfIndex(action.tileIndex).GetComponent <TileBehaviorIHM>();
            CharacterBehaviorIHM chara = GetTokenByNameAndPlayerId(action.tokenName, action.playerId).GetComponent <CharacterBehaviorIHM>();

            chara.characterSelection();
            tile.inverseRotationDirection = (tile.associatedTile.clockwiseRotation != action.clockwise);
            tile.enableTileRotation(); // enable rotation, apply the rotation and than disable rotation
            // EndReplayAction is called at the end of the rotation.
        }
Beispiel #5
0
        private void ExecuteActionCombatStart(ActionCombatStart action)
        {
            if (gManager.onlineGameInterface.WaitingForExpectedState())
            {
                gManager.onlineGameInterface.ForceEndReplayAction(); return;
            }

            Debug.Assert(action.attackers.Count > 0);
            Debug.Assert(action.defenders.Count > 0);
            CharacterBehaviorIHM character = GetTokenByNameAndPlayerId(action.attackers[0], action.playerId).GetComponent <CharacterBehaviorIHM>();
            string opponentId           = gManager.onlineGameInterface.playerId(1 - gManager.onlineGameInterface.playerIndex(action.playerId));
            CharacterBehaviorIHM target = GetTokenByNameAndPlayerId(action.defenders[0], opponentId).GetComponent <CharacterBehaviorIHM>();

            character.characterSelection();
            gManager.combatManager.combat(target.gameObject);
            gManager.onlineGameInterface.ForceEndReplayAction();
        }
Beispiel #6
0
        private void ExecuteActionMove(ActionMove action)
        {
            if (gManager.onlineGameInterface.WaitingForExpectedState())
            {
                gManager.onlineGameInterface.ForceEndReplayAction(); return;
            }

            CharacterBehavior    chara    = GetTokenByNameAndPlayerId(action.tokenName, action.playerId).GetComponent <CharacterBehavior>();
            CharacterBehaviorIHM charaIHM = chara.GetComponent <CharacterBehaviorIHM>();

            if (!chara.selected)
            {
                charaIHM.characterSelection();
            }

            // synchronize carried token
            if (gManager.onlineGameInterface.IsCarrier(action.tokenId))
            {
                int   carriedId    = gManager.onlineGameInterface.GetCarriedToken(action.tokenId);
                Token carriedToken = GetTokenById(carriedId);
                if (chara.tokenTranporte != null && chara.tokenTranporte.GetComponent <Token>() == carriedToken)
                {
                    charaIHM.deposerToken();
                }

                if (chara.tokenTranporte == null)
                {
                    charaIHM.ramasserToken(carriedToken.gameObject);
                }
            }
            else
            {
                if (chara.tokenTranporte != null)
                {
                    charaIHM.deposerToken();
                }
            }

            CaseBehavior target = gManager.getCase(action.y, action.x).GetComponent <CaseBehavior>();

            target.cibleAssociated.GetComponent <CibleDeplacementIHM>().moveSelectedTokenToTarget();

            // jump will automatically call end movement
            // for simple walk, end movement is called when leaving movingCharacterContinue state.
        }
Beispiel #7
0
        private void ExecuteActionRemove(ActionRemove action)
        {
            if (gManager.onlineGameInterface.WaitingForExpectedState())
            {
                gManager.onlineGameInterface.ForceEndReplayAction(); return;
            }

            if (action.score > 0) // get out
            {
                Debug.Assert(false, "Not implemented yet");
                //GameObject character = ...
                //moveCharacter(character.GetComponent<CharacterBehavior>());
                //endCharacterMovement(character.GetComponent<TokenIHM>());
                gManager.onlineGameInterface.ForceEndReplayAction();
            }
            else // use potion, fireballwand
            {
                Debug.Assert(action.removeTokenIds.Count == 1); // 1 item is consummed
                Token token = GetTokenById(action.removeTokenIds[0]);
                if (token is Item_PotionDeVitesse)
                {
                    CharacterBehaviorIHM character = GetTokenByNameAndPlayerId(action.tokenName, action.playerId).GetComponent <CharacterBehaviorIHM>();
                    character.characterSelection();
                    token.GetComponent <Item_PotionDeVitesse_IHM>().speedPotion();
                    gManager.onlineGameInterface.ForceEndReplayAction();
                }
                else if (token is Item_BatonDeBouleDeFeu)
                {
                    Multi.Logger.Instance.Log("LOG", "Skip removal of fireball");
                    gManager.onlineGameInterface.ForceEndReplayAction();
                }
                else
                {
                    Debug.Assert(false, "Unexpected token");
                }
            }
        }
Beispiel #8
0
    void checkAndExecuteExchange()
    {
        gManager.cameraMovementLocked = false;
        bool       spotFound = false;
        GameObject newPoint  = originalPoint;

        foreach (GameObject spot in gManager.exchangePoints)
        {
            if (isInteractableSpot(spot) && spot != originalPoint && Vector3.Distance(transform.position, spot.transform.position) < SNAP_DISTANCE)
            {
                newPoint  = spot;
                spotFound = true;
                break;
            }
        }
        // Si le token n'est pas dirigé vers un emplacement différent, on le remet à son emplacement de départ
        if (!spotFound)
        {
            Debug.LogWarning("Not found");
            transform.position = originalPoint.transform.position;
        }
        // Sinon, on le déplace vers son nouvel emplacement
        else
        {
            CharacterBehaviorIHM charaIHM = gManager.actionCharacter.GetComponent <CharacterBehaviorIHM>();
            //if (!gManager.tokensInteractedWith.Contains(token)) gManager.tokensInteractedWith.Add(token);

            // Si un autre token se trouve déjà à cet endroit, échanger sa place avec celui-ci
            if (newPoint.GetComponent <ExchangePointUI>().isHoldingToken())
            {
                Debug.Log("Echange");
                TokenExchangeUI otherToken = newPoint.GetComponent <ExchangePointUI>().occupyingToken.GetComponent <TokenExchangeUI>();
                otherToken.originalPoint      = originalPoint;
                otherToken.transform.position = originalPoint.transform.position;
                originalPoint.GetComponent <ExchangePointUI>().occupyingToken = otherToken.gameObject;
                //if (!gManager.tokensInteractedWith.Contains(otherToken.token)) gManager.tokensInteractedWith.Add(otherToken.token);

                // Le token est déplacé vers l'emplacement de token transporté
                if (newPoint.GetComponent <ExchangePointUI>().isCarriedTokenSpot())
                {
                    charaIHM.deposerToken();
                    if (token.GetComponent <Token>().tokenHolder != null)
                    {
                        CharacterBehavior characterHoldingThisToken = token.GetComponent <Token>().tokenHolder;
                        characterHoldingThisToken.GetComponent <CharacterBehaviorIHM>().deposerToken();
                        characterHoldingThisToken.GetComponent <CharacterBehaviorIHM>().ramasserToken(otherToken.token);
                    }
                    else
                    {
                        checkIfHoldingToken(token);
                        otherToken.token.GetComponent <Token>().caseActuelle = currentCase.gameObject;
                    }
                    // Jouer le son de l'objet qui est ramassé
                    GameManager.gManager.playSound(token.GetComponent <TokenIHM>().tokenGetSound);
                    charaIHM.ramasserToken(token);
                }
                // Le token est déplacé vers l'emplacement de sol
                else if (originalPoint.GetComponent <ExchangePointUI>().isCarriedTokenSpot())
                {
                    // Jouer le son de l'objet qui est déposé
                    GameManager.gManager.playSound(token.GetComponent <TokenIHM>().tokenDropSound);
                    charaIHM.deposerToken();
                    if (otherToken.token.GetComponent <Token>().tokenHolder != null)
                    {
                        CharacterBehavior characterHoldingOtherToken = otherToken.token.GetComponent <Token>().tokenHolder;
                        characterHoldingOtherToken.GetComponent <CharacterBehaviorIHM>().deposerToken();
                        characterHoldingOtherToken.GetComponent <CharacterBehaviorIHM>().ramasserToken(token);
                    }
                    else
                    {
                        checkIfHoldingToken(otherToken.token);
                        token.GetComponent <Token>().caseActuelle = currentCase.gameObject;
                    }
                    charaIHM.ramasserToken(otherToken.token);
                }
            }
            // Sinon
            else
            {
                Debug.Log("Transfert");
                // Déposer le token au sol et si un autre personnage est présent, lui associer
                if (originalPoint.GetComponent <ExchangePointUI>().isCarriedTokenSpot())
                {
                    // find if another character can hold the dropped item
                    CharacterBehavior receiverCharacter = currentCase.getOtherMainCharacter(token.GetComponent <Token>().tokenHolder);
                    // Jouer le son de l'objet qui est déposé
                    GameManager.gManager.playSound(token.GetComponent <TokenIHM>().tokenDropSound);
                    charaIHM.deposerToken();
                    //Debug.Log(receiverCharacter);
                    if (receiverCharacter != null)
                    {
                        receiverCharacter.GetComponent <CharacterBehaviorIHM>().ramasserToken(token);
                    }
                    token.GetComponent <Token>().caseActuelle = currentCase.gameObject;
                }
                // Récupérer le token
                else if (newPoint.GetComponent <ExchangePointUI>().isCarriedTokenSpot())
                {
                    // Si le token était déjà tenu par un autre personnage, les dissocier
                    if (token.GetComponent <Token>().tokenHolder != null)
                    {
                        token.GetComponent <Token>().tokenHolder.GetComponent <CharacterBehaviorIHM>().deposerToken();
                    }
                    // Sinon, si le token à ramasser est un personnage qui porte un objet, déposer son objet
                    else
                    {
                        checkIfHoldingToken(token);
                    }
                    // Jouer le son de l'objet qui est ramassé
                    GameManager.gManager.playSound(token.GetComponent <TokenIHM>().tokenGetSound);
                    charaIHM.ramasserToken(token);
                }
                else
                {
                    Debug.LogError("TokenExchangeUI, checkAndExecuteExchange: Token non affilié");
                }
                originalPoint.GetComponent <ExchangePointUI>().occupyingToken = null;
            }
            originalPoint      = newPoint;
            transform.position = newPoint.transform.position;
            newPoint.GetComponent <ExchangePointUI>().occupyingToken = gameObject;

            // Recalculer le déplacement du personnage
            gManager.actionCharacter.GetComponent <CharacterBehaviorIHM>().recomputePossibleActionsIHM(false, false);
        }
    }