예제 #1
0
    // Ready the game state for battle scene
    IEnumerator ConfigureBattle()
    {
        int currentStep = 0;
        int stepCount   = 3;

        EventMessenger.NotifyEvent(LoadingEvents.LOADING_STARTED);

        CreateEnemyHeroes();
        yield return(null);

        EventMessenger.NotifyEvent <int, int>(LoadingEvents.LOADING_PROGRESS, currentStep++, stepCount);

        fightSettings.UpdateSettings(true, true, false, m_SelectedHeroes.ToArray(), m_EnemyHeroes.ToArray());

        EventMessenger.NotifyEvent(SaveEvents.SAVE_GAME_STATE);
        yield return(null);

        EventMessenger.NotifyEvent <int, int>(LoadingEvents.LOADING_PROGRESS, currentStep++, stepCount);

        m_BattleScene.PrepareBattleScene(fightSettings);
        yield return(null);

        EventMessenger.NotifyEvent <int, int>(LoadingEvents.LOADING_PROGRESS, currentStep++, stepCount);
        EventMessenger.NotifyEvent(LoadingEvents.LOADING_FINISHED);
    }
예제 #2
0
    void LoadMenu()
    {
        SetupUIForMenu();

        EventMessenger.NotifyEvent <int, int>(LoadingEvents.LOADING_PROGRESS, 1, 1);
        EventMessenger.NotifyEvent(LoadingEvents.LOADING_FINISHED);
    }
예제 #3
0
    void AttackCompleted()
    {
        IsAttackInProgress = false;

        CurrentFightSettings.isPlayerTurn = !CurrentFightSettings.isPlayerTurn;
        IsPlayerTurn = CurrentFightSettings.isPlayerTurn;

        // Save Game State

        if (m_AlivePlayerHeroCount == 0)
        {
            EventMessenger.NotifyEvent(FightEvents.ALL_ALLY_DEAD);
        }
        else if (m_AliveEnemyHeroCount == 0)
        {
            EventMessenger.NotifyEvent(FightEvents.ALL_ENEMY_DEAD);
        }

        CurrentFightSettings.selectedAllyHeroIndex = -1;
        CurrentFightSettings.selectedEnemyIndex    = -1;

        EventMessenger.NotifyEvent(SaveEvents.SAVE_GAME_STATE);

        if (m_AliveEnemyHeroCount != 0 &&
            m_AlivePlayerHeroCount != 0)
        {
            UpdateTurnText();
        }

        if (!IsPlayerTurn)
        {
            EnemyPlay();
        }
    }
예제 #4
0
    void DamageDoneOnHero(BattleHero hero, int damage)
    {
        AttackEffect attackEffect = m_AttackEffecPool.GetItem();

        attackEffect.transform.position = hero.transform.position;
        attackEffect.RegulateSize(hero.GetComponent <RectTransform>());
        attackEffect.gameObject.SetActive(true);

        StringBuilder builder = new StringBuilder(AttributeChange.HEALTH_DECREASE_TEXT);

        builder.Replace("{DECREASE}", damage.ToString());

        AttributeChange attributeChange = AttribueChangeEffectPool.GetItem();

        attributeChange.PrepareForActivation(hero.transform, false, builder.ToString());
        attributeChange.gameObject.SetActive(true);

        if (!hero.IsEnemy)
        {
            CurrentFightSettings.selectedAllyHeroIndex = FindHeroIndex(m_PlayerHeroes, hero);
        }

        EventMessenger.NotifyEvent(SaveEvents.SAVE_GAME_STATE);

        bool isDead = hero.TakeDamage(damage);
    }
예제 #5
0
    void IPointerUpHandler.OnPointerUp(PointerEventData eventData)
    {
        if (m_Hero == null)
        {
            return;
        }

        EventMessenger.NotifyEvent <Action>(SelectionEvents.HERO_FRAME_CLICKED_UP, MakeSelection);
    }
예제 #6
0
    void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
    {
        if (m_Hero == null)
        {
            return;
        }

        EventMessenger.NotifyEvent <HeroBase>(SelectionEvents.HERO_FRAME_CLICKED_DOWN, this);
    }
예제 #7
0
    public void AddNewHero()
    {
        if (m_OwnedHeroes.Count < 10)
        {
            m_OwnedHeroes.Add(HeroFactory.GetNewAllyHero());
            EventMessenger.NotifyEvent(SaveEvents.SAVE_GAME_STATE);
        }


        EventMessenger.NotifyEvent(HeroEvents.HERO_ADDED);
    }
예제 #8
0
    IEnumerator StartUp()
    {
        yield return(new WaitForSeconds(0.1f));

        EventMessenger.NotifyEvent(LoadingEvents.LOADING_STARTED);

        WaitForSeconds waitForSeconds = new WaitForSeconds(0.1f);

        // Initialize everything but DataManager
        for (int i = 0; i < managers.Count - 1; ++i)
        {
            StartCoroutine(managers[i].Init());
        }

        int readyCount = 0;

        while (readyCount < managers.Count - 1)
        {
            int currentReadyCount = 0;

            foreach (IGameManager gameManager in managers)
            {
                if (gameManager.IsReady())
                {
                    ++currentReadyCount;
                }
            }

            if (currentReadyCount > readyCount)
            {
                EventMessenger.NotifyEvent(LoadingEvents.LOADING_PROGRESS, currentReadyCount, managers.Count);

                readyCount = currentReadyCount;
            }

            yield return(waitForSeconds);
        }

        // Initialize DataManager last since it will set other managers up
        IGameManager dataMan = managers[managers.Count - 1];

        StartCoroutine(dataMan.Init());
        while (!dataMan.IsReady())
        {
            yield return(waitForSeconds);
        }

        EventMessenger.NotifyEvent(LoadingEvents.LOADING_PROGRESS, 1, 1);

        EventMessenger.NotifyEvent(LoadingEvents.LOADING_FINISHED);
    }
예제 #9
0
    public bool TakeDamage(int damage)
    {
        int currentHealth = m_Hero.Health;

        currentHealth = Mathf.Max(currentHealth - damage, 0);

        m_HealthBar.SetFillAmount((float)currentHealth / m_Hero.MaxHealth);

        m_Hero.UpdateHealth(currentHealth);

        if (!IsAlive)
        {
            m_HeroImage.color = m_DeadColor;
            EventMessenger.NotifyEvent <BattleHero>(FightEvents.HERO_DIED, this);
        }

        return(!IsAlive);
    }
예제 #10
0
    protected override void MakeSelection()
    {
        if (isSelected)
        {
            m_HeroFrame.color = m_DefaultFrameColor;
            EventMessenger.NotifyEvent <HeroData>(SelectionEvents.HERO_FRAME_DESELECTED, m_Hero);
        }
        else if (Managers.MissionManager.CanSelectHero)
        {
            m_HeroFrame.color = m_SelectedFrameColor;
            EventMessenger.NotifyEvent <HeroData>(SelectionEvents.HERO_FRAME_SELECTED, m_Hero);
        }
        else
        {
            return;
        }

        isSelected = !isSelected;
    }
예제 #11
0
    public void PerformAttack()
    {
        m_AttackBeginPosition = transform.position;
        SetEndPosition();

        EventMessenger.NotifyEvent(FightEvents.ATTACK_SIGNAL_GIVEN);

        if (selectedTargetIndex == -1)
        {
            target = m_TargetPicker(!m_Hero.IsEnemy);
        }
        else
        {
            target = FindObjectOfType <BattleScene>().GetBattleHeroOnIndex(selectedTargetIndex); // This will be called only once on first attack upon loading
        }
        if (target == null)
        {
            return;
        }

        StartCoroutine(AttackRoutine());
    }
예제 #12
0
    private void Start()
    {
        Debug.Assert(m_PlayerHeroes.Length >= MissionManager.PLAYER_SIDE_COUNT &&
                     m_EnemyHeroes.Length >= MissionManager.ENEMY_SIDE_COUNT);

        m_BackButton = transform.Find("MainMenuButton").gameObject;
        m_BackButton.GetComponent <Button>().onClick.AddListener(() => EventMessenger.NotifyEvent(SceneEvents.REWARDING_COMPLETE));

        m_AttackEffecPool        = new GameObjectPool <AttackEffect>(3, m_AttackEffects, m_AttackEffectPrefab);
        AttribueChangeEffectPool = new GameObjectPool <AttributeChange>(4, m_AttributeChangeEffects, m_AttribueChangeEffectPrefab);

        m_AttackEffecPool.DeactivateAll();
        AttribueChangeEffectPool.DeactivateAll();

        EventMessenger.AddListener(FightEvents.ATTACK_SIGNAL_GIVEN, AttackSignalGiven);
        EventMessenger.AddListener(FightEvents.ATTACK_COMPLETED, AttackCompleted);
        EventMessenger.AddListener <BattleHero, int>(FightEvents.DAMAGE_DONE, DamageDoneOnHero);
        EventMessenger.AddListener <BattleHero>(FightEvents.HERO_DIED, OnHeroDied);
        EventMessenger.AddListener(FightEvents.ALL_ALLY_DEAD, OnDefeat);
        EventMessenger.AddListener(FightEvents.ALL_ENEMY_DEAD, OnVictory);

        EventMessenger.AddListener(SaveEvents.LOADING_SAVE_COMPLETED, LoadBattleSceneSettings);
    }
예제 #13
0
    void EnemyPlay()
    {
        if (m_PlayerHeroes.Length <= 0)
        {
            return;
        }

        BattleHero enemy = null;

        if (CurrentFightSettings.selectedEnemyIndex == -1)
        {
            enemy = GetAliveHero(m_EnemyHeroes);
        }
        else
        {
            enemy = FindBattleHeroOnIndex(m_EnemyHeroes, CurrentFightSettings.selectedEnemyIndex);
        }

        CurrentFightSettings.selectedEnemyIndex = FindHeroIndex(m_EnemyHeroes, enemy);

        EventMessenger.NotifyEvent(SaveEvents.SAVE_GAME_STATE);

        enemy?.PerformAttack();
    }
예제 #14
0
    void LoadMenu()
    {
        int stepCount   = 3;
        int currentStep = 0;

        EventMessenger.NotifyEvent(LoadingEvents.LOADING_STARTED);

        m_SelectedHeroes.Clear();
        m_EnemyHeroes.Clear();

        fightSettings.Reset();

        if (++fightSettings.consectuiveFightCount == REWARD_MATCH_COUNT)
        {
            fightSettings.consectuiveFightCount = 0;
            Managers.HeroManager.AddNewHero();
        }

        EventMessenger.NotifyEvent <int, int>(LoadingEvents.LOADING_PROGRESS, ++currentStep, stepCount);

        EventMessenger.NotifyEvent(SaveEvents.SAVE_GAME_STATE);

        EventMessenger.NotifyEvent <int, int>(LoadingEvents.LOADING_PROGRESS, ++currentStep, stepCount);
    }
    public void LoadGameData()
    {
        // Load Data From File and
        // Update Managers

        if (!File.Exists(m_FilePath))
        {
            ((IGameManager)Managers.HeroManager).UpdateData(null);
            ((IGameManager)Managers.MissionManager).UpdateData(null);
            return;
        }

        Dictionary <string, object> gameState;
        FileStream      file      = File.Open(m_FilePath, FileMode.Open);
        BinaryFormatter formatter = new BinaryFormatter();

        gameState = formatter.Deserialize(file) as Dictionary <string, object>;
        file.Close();

        ((IGameManager)Managers.HeroManager).UpdateData(gameState["HeroState"]);
        ((IGameManager)Managers.MissionManager).UpdateData(gameState["MissionState"]);

        EventMessenger.NotifyEvent(SaveEvents.LOADING_SAVE_COMPLETED);
    }
예제 #16
0
 public void ResetGame() =>
 EventMessenger.NotifyEvent(SaveEvents.GAME_RESET);
예제 #17
0
 void DoingDamage() =>
 EventMessenger.NotifyEvent <BattleHero, int>(FightEvents.DAMAGE_DONE, target, m_Hero.AttackDamage);
예제 #18
0
    public void SignalBattle()
    {
        EventMessenger.NotifyEvent(SceneEvents.BATTLE_START_SIGNAL);

        SetupUIForFight();
    }
예제 #19
0
 void AttackEnded()
 {
     target = null;
     selectedTargetIndex = -1;
     EventMessenger.NotifyEvent(FightEvents.ATTACK_COMPLETED);
 }