Ejemplo n.º 1
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (GameManager.Instance.CurrentState == GameState.InTuto)
        {
            return;
        }

        if (eventData.pointerEnter == null && startParent.parent.GetComponent <InventoryOwner>() != null && startParent.parent.GetComponent <InventoryOwner>().Owner != null)
        {
            InventoryOwner inventaireDequi = startParent.parent.GetComponent <InventoryOwner>();

            // On ne peut drop que d'un keeper
            if (inventaireDequi.Owner.GetComponent <Behaviour.Keeper>() != null)
            {
                ItemContainer[] inventoryKeeperDequi = inventaireDequi.Owner.GetComponent <Behaviour.Inventory>().Items;


                InventoryManager.RemoveItem(inventoryKeeperDequi, eventData.pointerDrag.gameObject.GetComponent <ItemInstance>().ItemContainer);
                ItemContainer[] loot = new ItemContainer[1];
                loot[0] = eventData.pointerDrag.gameObject.GetComponent <ItemInstance>().ItemContainer;


                Tile t = inventaireDequi.Owner.GetComponent <PawnInstance>().CurrentTile;

                ItemManager.AddItemOnTheGround(t, inventaireDequi.Owner.transform, loot);

                Destroy(eventData.pointerDrag.gameObject);
            }
        }

        if (transform.parent == absoluteParent)
        {
            if (!GameManager.Instance.Ui.itemSplitter.activeSelf)
            {
                transform.position = startPosition;

                // force the item being drag to reset on his starting position
                transform.SetParent(startParent);
            }
        }

        if (GameManager.Instance.Ui.tooltipItem != null)
        {
            GameManager.Instance.Ui.tooltipItem.SetActive(false);
        }

        GetComponent <CanvasGroup>().blocksRaycasts = true;
    }
Ejemplo n.º 2
0
    public static void PostBattleCommonProcess()
    {
        for (int i = 0; i < currentBattleKeepers.Length; i++)
        {
            currentBattleKeepers[i].GetComponent <Fighter>().ResetValuesAfterBattle();
            if (GameManager.Instance.ArcherInstance != null && currentBattleKeepers[i].Data.Behaviours[(int)BehavioursEnum.Archer])
            {
                if (archerPreviousTile != null)
                {
                    GameManager.Instance.ArcherInstance.CurrentTile = archerPreviousTile;
                    currentBattleKeepers[i].CurrentTile             = archerPreviousTile;
                }
            }
            currentBattleKeepers[i].GetComponent <AnimatedPawn>().StartMoveFromBattlePositionAnimation();
        }

        if (isPrisonerOnTile)
        {
            GameManager.Instance.PrisonerInstance.GetComponent <AnimatedPawn>().StartMoveFromBattlePositionAnimation();
            GameManager.Instance.PrisonerInstance.GetComponent <Fighter>().ResetValuesAfterBattle();
        }

        for (int i = 0; i < currentBattleMonsters.Length; i++)
        {
            // TODO: test death cases
            if (currentBattleMonsters[i] != null)
            {
                if (currentBattleMonsters[i].GetComponent <Mortal>().CurrentHp > 0)
                {
                    currentBattleMonsters[i].GetComponent <AnimatedPawn>().StartMoveFromBattlePositionAnimation();
                    currentBattleMonsters[i].GetComponent <Fighter>().HasRecentlyBattled = true;
                    currentBattleMonsters[i].transform.GetChild(1).gameObject.SetActive(true);
                    GlowController.UnregisterObject(currentBattleMonsters[i].GetComponent <GlowObjectCmd>());
                    currentBattleMonsters[i].GetComponent <Fighter>().EffectiveBoeufs.Clear();
                    currentBattleMonsters[i].GetComponent <Fighter>().UpdateActiveBoeufs();
                    currentBattleMonsters[i].GetComponentInChildren <BuffFeedback>().ShowBuffs(false);
                    if (currentBattleMonsters[i].GetComponent <QuestDealerFeedbackUpdater>() != null)
                    {
                        currentBattleMonsters[i].GetComponent <QuestDealerFeedbackUpdater>().feedbackContainer.SetActive(true);
                    }
                }
                else
                {
                    GameObject.Destroy(currentBattleMonsters[i].gameObject, 0.5f);
                }
            }
        }

        GameManager.Instance.GetBattleUI.gameObject.SetActive(false);
        GameManager.Instance.ClearListKeeperSelected();
        for (int i = 0; i < currentBattleKeepers.Length; i++)
        {
            if (currentBattleKeepers[i].GetComponent <Mortal>().CurrentHp > 0)
            {
                GameManager.Instance.AddKeeperToSelectedList(currentBattleKeepers[i]);
                currentBattleKeepers[i].GetComponent <Keeper>().IsSelected = true;
                currentBattleKeepers[i].GetComponent <Fighter>().EffectiveBoeufs.Clear();
                currentBattleKeepers[i].GetComponent <Fighter>().UpdateActiveBoeufs();
                currentBattleKeepers[i].GetComponentInChildren <BuffFeedback>().ShowBuffs(false);
            }
        }

        if (isPrisonerOnTile)
        {
            GameManager.Instance.PrisonerInstance.GetComponent <Fighter>().EffectiveBoeufs.Clear();
            GameManager.Instance.PrisonerInstance.GetComponent <Fighter>().UpdateActiveBoeufs();
            GameManager.Instance.PrisonerInstance.GetComponentInChildren <BuffFeedback>().ShowBuffs(false);
        }

        ItemManager.AddItemOnTheGround(GameManager.Instance.ActiveTile, GameManager.Instance.ActiveTile.transform, currentBattleLoot.ToArray());

        ResetBattleHandler();
    }
Ejemplo n.º 3
0
        public void Die()
        {
            if (GetComponent <Keeper>() != null || GetComponent <Monster>() != null)
            {
                Keeper keeper = GetComponent <Keeper>();
                //Monster monster = GetComponent<Monster>();

                Debug.Log("Blaeuurgh... *dead*");
                PawnInstance pawnInstance = GetComponent <PawnInstance>();

                if (GameManager.Instance.Ui.tooltipAction != null)
                {
                    // TMP Remi
                    GameManager.Instance.Ui.GoActionPanelQ.transform.parent.SetParent(GameManager.Instance.Ui.transform);
                    GameManager.Instance.Ui.tooltipAction.SetActive(false);
                }


                // Remove reference from tiles
                if (keeper != null)
                {
                    if (TileManager.Instance.KeepersOnTile.ContainsKey(keeper.GetComponent <PawnInstance>().CurrentTile))
                    {
                        foreach (PawnInstance k in TileManager.Instance.KeepersOnTile[keeper.GetComponent <PawnInstance>().CurrentTile])
                        {
                            if (k.GetComponent <MentalHealthHandler>() != null)
                            {
                                k.GetComponent <MentalHealthHandler>().CurrentMentalHealth -= 30;
                            }
                        }
                    }

                    TileManager.Instance.RemoveKilledKeeper(pawnInstance);
                    GameManager.Instance.ClearListKeeperSelected();

                    keeper.IsSelected = false;
                    // Drop items
                    if (!GetComponent <Inventory>().IsEmpty())
                    {
                        ItemManager.AddItemOnTheGround(pawnInstance.CurrentTile, transform, GetComponent <Inventory>().Items);
                    }
                }
                else
                {
                    TileManager.Instance.RemoveDefeatedMonster(pawnInstance);
                }

                // Death operations
                // TODO @Rémi, il me faut de quoi mettre a jour le shortcut panel pour afficher l'icone de mort

                GlowController.UnregisterObject(GetComponent <GlowObjectCmd>());
                GetComponent <AnimatedPawn>().Anim.SetTrigger("triggerDeath");

                // Try to fix glow bug
                Destroy(GetComponent <GlowObjectCmd>());

                if (keeper != null)
                {
                    keeper.ShowSelectedPanelUI(false);
                    if (EventManager.OnKeeperDie != null)
                    {
                        EventManager.OnKeeperDie(GetComponent <Keeper>());
                    }

                    // Deactivate pawn
                    DeactivatePawn();
                }
                else
                {
                    if (GameManager.Instance.CurrentState != GameState.InBattle)
                    {
                        Destroy(gameObject, 0.1f);
                    }
                }
            }
            else if (GetComponent <Prisoner>() != null)
            {
                Debug.Log("Ashley is dead");
            }
            GameManager.Instance.CheckGameState();
        }
Ejemplo n.º 4
0
    void Update()
    {
        if (Input.GetKey(KeyCode.LeftControl) &&
            Input.GetKeyDown(KeyCode.RightControl))
        {
            isDebugModeActive = !isDebugModeActive;
            debugCanvas.SetActive(isDebugModeActive);
            Debug.Log("Debug mode now active.");
        }

        if (isDebugModeActive)
        {
            // Help window
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                debugCanvas.SetActive(!debugCanvas.activeInHierarchy);
            }

            // Unlimited action points
            if (Input.GetKeyDown(KeyCode.Alpha6))
            {
                if (GameManager.Instance.CurrentState == GameState.InBattle)
                {
                    for (int i = 0; i < BattleHandler.CurrentBattleKeepers.Length; i++)
                    {
                        BattleHandler.CurrentBattleKeepers[i].GetComponent <Fighter>().PhysicalSymbolStored  = 9;
                        BattleHandler.CurrentBattleKeepers[i].GetComponent <Fighter>().DefensiveSymbolStored = 9;
                        BattleHandler.CurrentBattleKeepers[i].GetComponent <Fighter>().MagicalSymbolStored   = 9;
                    }

                    if (BattleHandler.isPrisonerOnTile)
                    {
                        GameManager.Instance.PrisonerInstance.GetComponent <Fighter>().PhysicalSymbolStored  = 9;
                        GameManager.Instance.PrisonerInstance.GetComponent <Fighter>().DefensiveSymbolStored = 9;
                        GameManager.Instance.PrisonerInstance.GetComponent <Fighter>().MagicalSymbolStored   = 9;
                    }
                }
                else
                {
                    if (isUnlimitedActionPointsModeActive)
                    {
                        Debug.Log("Deactivate unlimited action points mode.");
                        foreach (PawnInstance pi in GameManager.Instance.AllKeepersList)
                        {
                            pi.GetComponent <Keeper>().MaxActionPoints = 3;
                            pi.GetComponent <Keeper>().ActionPoints    = 3;
                        }
                    }
                    else
                    {
                        Debug.Log("Activate unlimited action points mode.");
                        foreach (PawnInstance pi in GameManager.Instance.AllKeepersList)
                        {
                            pi.GetComponent <Keeper>().MaxActionPoints = 99;
                            pi.GetComponent <Keeper>().ActionPoints    = 99;
                        }
                    }
                    isUnlimitedActionPointsModeActive = !isUnlimitedActionPointsModeActive;
                }
            }

            // Discover all tiles
            if (Input.GetKeyDown(KeyCode.Alpha9))
            {
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    if (isMapUncovered)
                    {
                        if (oldTileStates != null && oldTileStates.Count > 0)
                        {
                            foreach (Tile tile in oldTileStates.Keys)
                            {
                                tile.State = oldTileStates[tile];
                            }
                        }
                    }
                    isMapUncovered = false;
                }
                else
                {
                    if (!isMapUncovered)
                    {
                        oldTileStates.Clear();
                        foreach (Tile tile in TileManager.Instance.Tiles.GetComponentsInChildren <Tile>())
                        {
                            oldTileStates.Add(tile, tile.State);
                            tile.State = TileState.Discovered;
                        }
                    }
                    isMapUncovered = true;
                }
            }

            // Decrease food Ashley
            if (Input.GetKey(KeyCode.CapsLock) && Input.GetKey(KeyCode.Alpha2))
            {
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    GameManager.Instance.PrisonerInstance.GetComponent <HungerHandler>().CurrentHunger++;
                }
                else
                {
                    GameManager.Instance.PrisonerInstance.GetComponent <HungerHandler>().CurrentHunger--;
                }
            }

            if (GameManager.Instance.ListOfSelectedKeepers == null || GameManager.Instance.ListOfSelectedKeepers.Count == 0)
            {
                return;
            }

            // Kill selected character
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                Debug.Log("Killed " + GameManager.Instance.GetFirstSelectedKeeper().Data.PawnName + " using debug tools.");
                GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Mortal>().CurrentHp = 0;
            }

            // Decrease food
            if (Input.GetKey(KeyCode.Alpha2) && !Input.GetKey(KeyCode.CapsLock))
            {
                if (GameManager.Instance.CurrentState == GameState.InBattle)
                {
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Fighter>().PhysicalSymbolStored++;
                    }
                    else
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Fighter>().PhysicalSymbolStored--;
                    }
                }
                else
                {
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <HungerHandler>().CurrentHunger++;
                    }
                    else
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <HungerHandler>().CurrentHunger--;
                    }
                }
            }

            // Decrease mental health
            if (Input.GetKey(KeyCode.Alpha3))
            {
                if (GameManager.Instance.CurrentState == GameState.InBattle)
                {
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Fighter>().DefensiveSymbolStored++;
                    }
                    else
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Fighter>().DefensiveSymbolStored--;
                    }
                }
                else
                {
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <MentalHealthHandler>().CurrentMentalHealth++;
                    }
                    else
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <MentalHealthHandler>().CurrentMentalHealth--;
                    }
                }
            }

            // Decrease HP
            if (Input.GetKey(KeyCode.Alpha4))
            {
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Mortal>().CurrentHp++;
                }
                else
                {
                    GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Mortal>().CurrentHp--;
                }
            }

            if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                if (GameManager.Instance.CurrentState == GameState.InBattle)
                {
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Fighter>().MagicalSymbolStored++;
                    }
                    else
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Fighter>().MagicalSymbolStored--;
                    }
                }
                else
                {
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Keeper>().ActionPoints++;
                    }
                    else
                    {
                        GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Keeper>().ActionPoints--;
                    }
                }
            }

            // Pop a monster
            if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                if (GameManager.Instance.CurrentState == GameState.InBattle)
                {
                    GameManager.Instance.GetBattleUI.GetComponent <UIBattleHandler>().EscapeBattle();
                }
                else
                {
                    Instantiate(monsterToPopPrefab,
                                GameManager.Instance.GetFirstSelectedKeeper().CurrentTile.transform.position,
                                Quaternion.identity, GameManager.Instance.GetFirstSelectedKeeper().CurrentTile.transform);
                }
            }

            // Pop an item on the ground
            if (Input.GetKeyDown(KeyCode.Alpha8))
            {
                ItemContainer[] itemToSpawn = new ItemContainer[1];
                itemToSpawn[0] = new ItemContainer(GameManager.Instance.ItemDataBase.ItemsList[Random.Range(0, GameManager.Instance.ItemDataBase.ItemsList.Count)], itemsToPopAmount);
                ItemManager.AddItemOnTheGround(GameManager.Instance.GetFirstSelectedKeeper().CurrentTile, GameManager.Instance.GetFirstSelectedKeeper().CurrentTile.transform, itemToSpawn);
            }

            // TP selected keeper
            if (Input.GetKey(KeyCode.T))
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    RaycastHit hitInfo;
                    if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo) == true)
                    {
                        if (hitInfo.transform.GetComponentInParent <Tile>() != null)
                        {
                            Tile         destinationTile = hitInfo.transform.GetComponentInParent <Tile>();
                            PawnInstance selectedKeeper  = GameManager.Instance.GetFirstSelectedKeeper();
                            TileManager.Instance.RemoveKeeperFromTile(selectedKeeper.CurrentTile, selectedKeeper);
                            TileManager.Instance.AddKeeperOnTile(destinationTile, selectedKeeper);

                            // Physical movement
                            selectedKeeper.GetComponent <AnimatedPawn>().StartBetweenTilesAnimation(destinationTile.transform.position);

                            //selectedKeeper.transform.position = destinationTile.transform.position;
                            GameObject currentCharacter;
                            Keeper     keeperComponent = selectedKeeper.GetComponent <Keeper>();
                            for (int i = 0; i < keeperComponent.GoListCharacterFollowing.Count; i++)
                            {
                                currentCharacter = keeperComponent.GoListCharacterFollowing[i];

                                if (currentCharacter.GetComponent <Escortable>() != null)
                                {
                                    currentCharacter.GetComponent <PawnInstance>().CurrentTile = destinationTile;
                                    currentCharacter.GetComponent <AnimatedPawn>().StartBetweenTilesAnimation(destinationTile.transform.position + Vector3.right * 0.2f);
                                }
                            }
                        }
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                GameManager.Instance.ResetGameData();
                GameManager.Instance.CurrentState = GameState.Normal;
                AudioManager.Instance.Fade(AudioManager.Instance.menuMusic);
                GameManager.Instance.Ui.GoActionPanelQ.transform.parent.SetParent(GameManager.Instance.Ui.transform);
                SceneManager.LoadScene(0);
            }
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Destroy monsters beaten in battle and remove them from dictionaries.
    /// </summary>
    /// <param name="tile">The tile concerned</param>
    public void RemoveDefeatedMonsters(Tile tile)
    {
        PawnInstance[] removeIndex           = new PawnInstance[monstersOnTile[tile].Count];
        short          nbrOfElementsToRemove = 0;

        List <ItemContainer> lootList            = new List <ItemContainer>();
        Transform            lastMonsterPosition = null;

        foreach (PawnInstance pi in monstersOnTile[tile])
        {
            if (pi.GetComponent <Behaviour.Mortal>().CurrentHp == 0)
            {
                lastMonsterPosition = pi.transform;
                if (pi.GetComponent <Behaviour.Mortal>().DeathParticles != null)
                {
                    ParticleSystem ps = Instantiate(pi.GetComponent <Behaviour.Mortal>().DeathParticles, pi.transform.parent);
                    ps.transform.position = pi.transform.position;
                    ps.Play();
                    Destroy(ps.gameObject, ps.main.duration);
                }

                pi.GetComponent <Behaviour.Inventory>().ComputeItems();
                lootList.AddRange(pi.GetComponent <Behaviour.Inventory>().Items);

                removeIndex[nbrOfElementsToRemove] = pi;
                nbrOfElementsToRemove++;
                if (EventManager.OnMonsterDie != null)
                {
                    EventManager.OnMonsterDie(pi.GetComponent <Behaviour.Monster>());
                }
            }
        }


        if (lootList.Count > 0)
        {
            ItemManager.AddItemOnTheGround(tile, lastMonsterPosition, lootList.ToArray());
        }

        int elementsRemoved = 0;

        for (int j = 0; j < monstersOnTile[tile].Count; j++)
        {
            for (int i = 0; i < removeIndex.Length; i++)
            {
                if (elementsRemoved == nbrOfElementsToRemove)
                {
                    break;
                }

                if (monstersOnTile[tile][j] == removeIndex[i])
                {
                    monstersOnTile[tile].RemoveAt(j);
                    elementsRemoved++;
                    break;
                }
            }
            if (elementsRemoved == nbrOfElementsToRemove)
            {
                break;
            }
        }

        for (int i = 0; i < nbrOfElementsToRemove; i++)
        {
            Destroy(removeIndex[i].gameObject, 0.1f);
        }

        if (monstersOnTile[tile].Count == 0)
        {
            monstersOnTile.Remove(tile);
        }
    }