Exemplo n.º 1
0
    public IEnumerator EnterCityEditMode(MapCity mapCity)
    {
        //Debug.Log("EnterCityEditMode");
        mapCity.DimmLabel();
        // Block mouse input
        // InputBlocker inputBlocker = transform.root.Find("MiscUI/InputBlocker").GetComponent<InputBlocker>();
        InputBlocker.SetActive(true);
        // Wait for all animations to finish
        // this depends on the labelDimTimeout parameter in MapObject, we add additional 0.1f just in case
        yield return(new WaitForSeconds(mapCity.GetComponent <MapObject>().LabelDimTimeout + 0.1f));

        // Unblock mouse input
        InputBlocker.SetActive(false);
        // map manager change to browse mode back
        // . - this is done by OnDisable() automatically in MapManager
        //MapManager mapManager = transform.parent.GetComponent<MapManager>();
        //mapManager.SetMode(MapManager.Mode.Browse);
        // Deactivate map manager with map
        MapManager.Instance.gameObject.SetActive(false);
        // Deactivate this map menu
        gameObject.SetActive(keepEnabledAfterStart);
        // Note: everything below related to mapManager or mapScreen will not be processed, because map manager is disabled
        // Activate city view = go to city edit mode
        transform.root.GetComponentInChildren <UIManager>().GetComponentInChildren <EditPartyScreen>(true).SetEditPartyScreenActive(mapCity.LCity);
    }
Exemplo n.º 2
0
    public IEnumerator EnterHeroEditMode(MapHero mapHero)
    {
        Debug.Log("Enter hero edit mode.");
        mapHero.DimmLabel();
        // Trigger on mapobject exit to Hide label(s - + hide hero's lable, if it is in city)
        // verify if MapObject's labe is still active and mouse over it
        if (mapHero.GetComponent <MapObject>().Label.GetComponent <Text>().raycastTarget&& mapHero.GetComponent <MapObject>().Label.IsMouseOver)
        {
            // disable it
            mapHero.GetComponent <MapObject>().OnPointerExit(null);
        }
        // Block mouse input
        // InputBlocker inputBlocker = transform.root.Find("MiscUI/InputBlocker").GetComponent<InputBlocker>();
        InputBlocker.SetActive(true);
        // Wait for all animations to finish
        // this depends on the labelDimTimeout parameter in MapObject, we add additional 0.1f just in case
        yield return(new WaitForSeconds(mapHero.GetComponent <MapObject>().LabelDimTimeout + 0.1f));

        // Unblock mouse input
        InputBlocker.SetActive(false);
        // Deactivate map manager with map
        MapManager.Instance.gameObject.SetActive(false);
        // Deactivate this map menu
        gameObject.SetActive(false);
        // Note: everything below related to mapManager or mapScreen will not be processed, because map manager is disabled
        // Activate hero edit menu
        transform.root.GetComponentInChildren <UIManager>().GetComponentInChildren <EditPartyScreen>(true).SetEditPartyScreenActive(mapHero.LHeroParty);
    }
Exemplo n.º 3
0
    void LoadGameData()
    {
        // open file stream for read
        Debug.Log("Loading game data from " + fullFilePath + " file");
        FileStream file = File.OpenRead(fullFilePath);
        // Create binary formater
        BinaryFormatter binaryFormatter = new BinaryFormatter();
        // Deserialize game data
        GameData gameData = (GameData)binaryFormatter.Deserialize(file);

        // Close file
        file.Close();
        // Activate Loading screen
        loadingScreen.SetActive(true, loadGameConfig.loadingGameTextString);
        // Block mouse input
        InputBlocker.SetActive(true);
        // We use coroutine to make sure that all objects are removed before new objects are created and to show some animation
        // remove current world
        ChapterManager.Instance.CoroutineQueue.Run(RemoveCurrentWorld());
        // load chapter world from template
        ChapterManager.Instance.CoroutineQueue.Run(LoadChapterWorldFromTemplate(gameData));
        // remove old data
        ChapterManager.Instance.CoroutineQueue.Run(CleanNewWorldBeforeLoad());
        // create new objects from saved data
        ChapterManager.Instance.CoroutineQueue.Run(CreateGameObjects(gameData));
        // activate screens
        ChapterManager.Instance.CoroutineQueue.Run(ActivateScreens());
    }
Exemplo n.º 4
0
    IEnumerator ActivateScreens()
    {
        yield return(null);

        Debug.Log("Activate Screens");
        // Activate map screen
        // MapManager should be already active
        // MapManager.Instance.gameObject.SetActive(true);
        UIRoot.Instance.GetComponentInChildren <MapMenuManager>(true).gameObject.SetActive(true);
        // UnFreeze map (during Animation internal updates are not done)
        MapManager.Instance.SetMode(MapManager.Mode.Browse);
        // Activate main menu panel, so it is visible next time main menu is activated
        transform.parent.Find("MainMenuPanel").gameObject.SetActive(true);
        // Deactivate main menu
        transform.root.Find("MainMenu").gameObject.SetActive(false);
        // trigger main menu changes related to running game state
        menuButton.OnGameStartMenuChanges();
        // execute pre-turn actions for MapMenu
        MapMenuManager.Instance.ExecutePreTurnActions(TurnsManager.Instance.GetActivePlayer());
        // execute pre-turn actions for MapManager
        MapManager.Instance.ExecutePreTurnActions();
        // Deactivate this screen
        gameObject.SetActive(false);
        // Bring loading screen to front
        loadingScreen.transform.SetAsLastSibling();
        // Wait a bit
        yield return(new WaitForSeconds(loadGameConfig.loadingScreenExplicitDelaySeconds));

        // Unblock mouse input
        InputBlocker.SetActive(false);
        // Deactivate Loading screen
        loadingScreen.SetActive(false);
    }
 public void HireFirstHero()
 {
     // activate Starting Game loading screen
     loadingScreen.SetActive(true, startGameConfig.startingGameTextString);
     // Bring loading screen to front
     loadingScreen.transform.SetAsLastSibling();
     // Block mouse input
     InputBlocker.SetActive(true);
     // Start to load a game
     StartCoroutine(StartGame());
 }
Exemplo n.º 6
0
    IEnumerator ReturnToTheMapScreenWithAnimation()
    {
        // Block mouse input
        // InputBlocker inputBlocker = transform.root.Find("MiscUI/InputBlocker").GetComponent<InputBlocker>();
        InputBlocker.SetActive(true);
        // Wait for all animations to finish
        yield return(new WaitForSeconds(0.51f));

        // Unblock mouse input
        InputBlocker.SetActive(false);
        // Deactivate this screen
        gameObject.SetActive(false);
        // activate map screen
        MapManager.Instance.gameObject.SetActive(true);
        MapMenuManager.Instance.gameObject.SetActive(true);
    }
Exemplo n.º 7
0
    public IEnumerator Act()
    {
        // Block mouse input
        // InputBlocker inputBlocker = transform.root.Find("MiscUI/InputBlocker").GetComponent<InputBlocker>();
        InputBlocker.SetActive(true);
        // Wait for animation
        yield return(new WaitForSeconds(0.25f));

        // Get all possible moves
        List <BattleMove> battleMoves = GetAllMoves();

        // Display all moves
        foreach (BattleMove battleMove in battleMoves)
        {
            if (battleMove.TargetUnitSlot != null)
            {
                Debug.Log("Move: " + battleMove.Action.ToString() + " " + battleMove.TargetUnitSlot.GetUnit().UnitName);
            }
            else
            {
                Debug.Log("Move: " + battleMove.Action.ToString());
            }
        }
        // Find best move
        BattleMove bestMove = GetBestMove(battleMoves);

        if (bestMove.TargetUnitSlot != null)
        {
            Debug.Log("Best move: " + bestMove.Action.ToString() + " " + bestMove.TargetUnitSlot.GetUnit().UnitName);
        }
        else
        {
            Debug.Log("Best move: " + bestMove.Action.ToString());
        }
        // Execute best move
        ExecuteMove(bestMove);
        // Wait for animation
        yield return(new WaitForSeconds(0.25f));

        // Unblock mouse input
        InputBlocker.SetActive(false);
    }
Exemplo n.º 8
0
    IEnumerator EndChapter()
    {
        // Activate Loading screen
        UIRoot.Instance.GetComponentInChildren <EndingGameScreen>(true).SetActive(true);
        // Set waiting cursor
        CursorController.Instance.SetBlockInputCursor();
        // Activate input blocker
        InputBlocker.SetActive(true);
        // Remove world map
        World.Instance.RemoveCurrentChapter();
        // Deactivate loading screen after clean
        yield return(new WaitForSeconds(endGameScreenWaitingTimeSeconds));

        // Deactivate Loading screen
        UIRoot.Instance.GetComponentInChildren <EndingGameScreen>(true).SetActive(false);
        // Set normal cursor
        CursorController.Instance.SetNormalCursor();
        // Disable input blocker
        InputBlocker.SetActive(false);
    }
    IEnumerator StartGame()
    {
        // skip all actions until next frame
        yield return(null);

        // enable main menu panel (it was disabled by ChooseChapter)
        MainMenuManager.Instance.MainMenuPanel.SetActive(true);
        // Disable Choose Chapter menu
        MainMenuManager.Instance.ChooseChapter.gameObject.SetActive(false);
        // Load currently set active chapter
        ChapterManager.Instance.LoadChapter(ChapterManager.Instance.ActiveChapter.ChapterData.chapterName);
        // change player name to the name which is set by the user
        TurnsManager.Instance.GetActivePlayer().PlayerData.givenName = GetPlayerName();
        // get selected faction
        Faction selectedFaction = factionSelectionGroup.GetSelectedFaction();

        // Activate and reset turns manager, set chosen faction as active player
        TurnsManager.Instance.Reset(selectedFaction);
        // Activate main menu in game mode
        MainMenuManager.Instance.MainMenuInGameModeSetActive(true);
        // Activate world map
        ChapterManager.Instance.ActiveChapter.GetComponentInChildren <MapManager>(true).gameObject.SetActive(true);
        // Set chosen Unique ability for chosen player
        // TurnsManager.Instance.GetActivePlayer().PlayerData.playerUniqueAbilityData.uniqueAbilityConfig = Array.Find(ConfigManager.Instance.UniqueAbilityConfigsMap, element => element.playerUniqueAbility == playerUniqueAbility).uniqueAbilityConfig;
        // Array.Find(ConfigManager.Instance.UniqueAbilityConfigs, element => element.playerUniqueAbility == playerUniqueAbility);
        TurnsManager.Instance.GetActivePlayer().PlayerData.playerUniqueAbilityData.playerUniqueAbility = uniqueAbilitiesToggleGroup.GetSelectedToggle().GetComponent <UniqueAbilitySelector>().UniqueAbilityConfig.playerUniqueAbility;
        // GetSelectedUnitType and Get Chosen race starting city and hire first hero
        transform.root.GetComponentInChildren <UIManager>().GetComponentInChildren <EditPartyScreen>(true).HireUnit(null, GetSelectedUnitType(), false, ObjectsManager.Instance.GetStartingCityByFaction(selectedFaction));
        // Wait a bit
        yield return(new WaitForSeconds(startGameConfig.startingScreenExplicitDelaySeconds));

        // Unblock mouse input
        InputBlocker.SetActive(false);
        // Deactivate Loading screen
        loadingScreen.SetActive(false);
        // Activate Prolog
        prolog.SetActive(true, ChapterManager.Instance.ActiveChapter.ChapterData);
        // [Should be last] Deactivate (this) Choose your first hero menu
        SetActive(false);
    }
Exemplo n.º 10
0
 // context is destination unit slot
 public void OnUnitSlotLeftClickEvent(System.Object context)
 {
     // verify if context is correct
     if (context is UnitSlot)
     {
         // init unit slot from context
         UnitSlot unitSlot = (UnitSlot)context;
         // Verify if battle has not ended
         if (!BattleHasEnded)
         {
             //Debug.Log("UnitSlot ActOnClick in Battle screen");
             // act based on the previously set by SetOnClickAction by PartyPanel conditions
             if (unitSlot.IsAllowedToApplyPowerToThisUnit)
             {
                 // it is allowed to apply powers to the unit in this cell
                 // Block mouse input
                 InputBlocker.SetActive(true);
                 // Trigger Event
                 // Listeners: All active PartyPanelCell(s)
                 battleApplyActiveUnitAbilityEvent.Raise(unitSlot);
                 // tmp:
                 //unitSlot.GetComponentInParent<PartyPanel>().ApplyPowersToUnit(unitSlot.GetComponentInChildren<PartyUnitUI>());
                 // set unit has moved flag
                 ActiveUnitUI.LPartyUnit.HasMoved = true;
                 // activate next unit
                 ActivateNextUnit();
             }
             else
             {
                 // it is not allowed to use powers on this cell
                 // display error message
                 NotificationPopUp.Instance().DisplayMessage(unitSlot.ErrorMessage);
             }
         }
     }
 }
Exemplo n.º 11
0
    IEnumerator ActivateUnit()
    {
        //Debug.Log("ActivateUnit");
        // Wait while all previously triggered actions are complete
        //while (queueIsActive)
        //{
        //    Debug.Log("Queue is active");
        //    yield return new WaitForSeconds(1f);
        //}
        //// Set Queue is active flag
        //queueIsActive = true;
        UnitStatus unitStatus = ActiveUnitUI.LPartyUnit.UnitStatus;

        switch (unitStatus)
        {
        case UnitStatus.Active:
            // Activate highlights of which cells can or cannot be targeted
            // Trigger event for all required listeners
            CoroutineQueueManager.Run(TriggerNewUnitHasBeenActivatedEvent());
            // SetHighlight();
            // verify if active unit's party panel is AI controlled => faction not equal to player's faction
            if (ActiveUnitUI.GetUnitPartyPanel().IsAIControlled)
            {
                // give control to battle AI
                CoroutineQueueManager.Run(battleAI.Act());
            }
            else
            {
                // wait for user to act
            }
            // canActivate = true;
            break;

        case UnitStatus.Escaping:
            // If there were debuffs applied and unit has survived,
            // then unit may escape now
            // Escape unit
            CoroutineQueueManager.Run(EscapeUnit());
            break;

        case UnitStatus.Dead:
            // This unit can't act any more
            // This can happen here due to applied debuffs
            // Skip post-move actions and Activate next unit
            // canActivate = ActivateNextUnit();
            ActivateNextUnit();
            break;

        case UnitStatus.Waiting:
        case UnitStatus.Escaped:
            Debug.LogError("This status [" + unitStatus.ToString() + "] should not be here.");
            break;

        default:
            Debug.LogError("Unknown unit status " + unitStatus.ToString());
            break;
        }
        // Unblock mouse input
        // InputBlocker inputBlocker = transform.root.Find("MiscUI/InputBlocker").GetComponent<InputBlocker>();
        InputBlocker.SetActive(false);
        Debug.Log("Unit has been activated");
        yield return(null);
    }
Exemplo n.º 12
0
 IEnumerator EndBattle()
 {
     Debug.Log("EndBattle");
     // set battle has ended
     BattleHasEnded = true;
     battleHasEnded.Raise();
     // Remove highlight from active unit
     ActiveUnitUI.HighlightActiveUnitInBattle(false);
     //// Set exit button variable
     //BattleExit exitButton = GetBattleExitButton();
     //// Activate exit battle button;
     //exitButton.gameObject.SetActive(true);
     // Deactivate all other battle buttons;
     // SetBattleControlsActive(false);
     // Check who win battle
     if (!playerPartyPanel.CanFight())
     {
         Debug.Log("Player cannot fight anymore");
         // player cannot fight anymore
         // verify if player has flee from battle
         if (playerPartyPanel.HasEscapedBattle())
         {
             Debug.Log("Player has escaped battle");
             // On exit: move it 2 tiles away from other party
             exitOption = ExitOption.FleePlayer;
         }
         else
         {
             Debug.Log("Player lost battle and was destroyed");
             // verify if battle was with city Garnizon:
             // .. this is not needed here because city garnizon cannot initiate fight
             // On exit: destroy player party
             exitOption = ExitOption.DestroyPlayer;
         }
         // Show how much experience was earned by enemy party
         enemyPartyPanel.GrantAndShowExperienceGained(playerPartyPanel);
     }
     else
     {
         Debug.Log("Enemy cannot fight anymore");
         // verify if enemy has flee from battle
         if (enemyPartyPanel.HasEscapedBattle())
         {
             Debug.Log("Enemy has escaped battle");
             // On exit: move it 2 tiles away from other party
             exitOption = ExitOption.FleeEnemy;
         }
         else
         {
             Debug.Log("Enemy lost battle and was destroyed");
             // verify if battle was with city Garnizon:
             if (enemyPartyPanel.GetHeroParty().PartyMode == PartyMode.Garnizon)
             {
                 // On exit: enter city
                 Debug.Log("Enter city on exit");
                 exitOption = ExitOption.EnterCity;
             }
             else if (enemyPartyPanel.GetHeroParty().PartyMode == PartyMode.Party)
             {
                 // On exit: destroy enemy party
                 exitOption = ExitOption.DestroyEnemy;
             }
             else
             {
                 Debug.LogError("Unknown party mode " + enemyPartyPanel.GetHeroParty().PartyMode.ToString());
             }
         }
         // Show how much experience was earned by player party
         playerPartyPanel.GrantAndShowExperienceGained(enemyPartyPanel);
     }
     // Remove all buffs and debuffs
     enemyPartyPanel.RemoveAllBuffsAndDebuffs();
     playerPartyPanel.RemoveAllBuffsAndDebuffs();
     // unblock input
     InputBlocker.SetActive(false);
     yield return(null);
 }