Ejemplo n.º 1
0
    private void CheckStates()
    {
        DivineDebug.Log("State checked in this state: " + _curState);

        if (_curState == BattleLogicStates.WaitForPartiesReadyToStartFight)
        {
            _curState = BattleLogicStates.PartiesReadyToStartFight;

            WaitToStartBattle();
        }
        else if (_curState == BattleLogicStates.TurnLoop_DoingFightActions)
        {
            CheckFightActionList();
        }
        else if (_curState == BattleLogicStates.TryToEndBattle)
        {
            TryToEndBattle();
        }
        else if (_curState == BattleLogicStates.TurnLoop_Start)
        {
            StartWaitingForActionReceive();
        }
        else if (_curState == BattleLogicStates.TurnLoop_TryToFinishTurn && _currentSelectedCharacter == null)
        {
            FinishTurn();
        }
        else if (_curState == BattleLogicStates.WaitForPrefight && _battleEndCame)
        {
            OnBattleFinished();
        }
    }
Ejemplo n.º 2
0
    private bool RunNextAction_IfWeHaveAny()
    {
        if (_actionData.Count == 0)
        {
            DivineDebug.Log("No action data to run.");

            return(false);
        }

        _numOfKilledCharacterInThisAct = 0;
        _apGeneratedInThisTurn         = false;

        _curState = BattleLogicStates.TurnLoop_DoingFightActions;

        DivineDebug.Log("Run action number " + _indexOfCurrentAction + " .");

        ActionData ad = _actionData[0];

        if ((ad as FightActionData) != null)
        {
            Character.Deleg_SpellCasted onCharacterCastSpell = OnCharacterCastSpell;
            ad.RunAction(onCharacterCastSpell);
        }
        else if ((ad as SecretActionData) != null)
        {
            ad.RunAction(null);
        }

        _actionData.Remove(ad);
        _indexOfCurrentAction++;

        return(true);
    }
Ejemplo n.º 3
0
    private void TryToFinishTurn()
    {
        DivineDebug.Log("Trying To Finish Turn");

        _curState = BattleLogicStates.TurnLoop_TryToFinishTurn;

        SelectACharacter(_currentSelectedCharacter, null, null, null, null, false);
    }
Ejemplo n.º 4
0
    private void OnSecretCastSuccessful(int enabledSecret)
    {
        DivineDebug.Log("Secret Cast Successful with this ID: " + enabledSecret);

        _curState = BattleLogicStates.TurnLoop_CastingSecret;

        bool isForMe    = _currentSelectedCharacter.side == PartySide.Player;
        int  partyIndex = isForMe ? 0 : 1;

        _newBattleUI.ShowSecretCastUI(_parties[partyIndex].secrets[enabledSecret], isForMe, OnSecretCastAnimComplete);
    }
Ejemplo n.º 5
0
    public void FakeServer_StartNextTurn(List <int> eligibleSpells)
    {
        DivineDebug.Log("Next Turn Started.");

        _curState             = BattleLogicStates.TurnLoop_Start;
        _indexOfCurrentAction = 0;
        _actionData           = new List <ActionData>();

        StartTimer();

        SelectNextCharacter(eligibleSpells);
    }
Ejemplo n.º 6
0
    private void TryToStartNextTurn()
    {
        if (_isFirstTurn)
        {
            _isFirstTurn = false;
            _newBattleUI.FirstTurnStarted();
        }

        _curState = BattleLogicStates.WaitForPrefight;

        _actionData = new List <ActionData>();

        BattleDataProvider.instance.Event_BattleTurnTick += OnFirstTimeTickCome;
    }
 //Handle Events
 private void OnReadyCome(BattleLogic battleLogic, BattleLogicStates curState)
 {
     if (_currentState == States.WaitToStartFight)
     {
         StartNextTurn(FindNextTurnCharacterID(), true);
     }
     else if (_currentState == States.TurnLoop_WaitTillNextCharSelected)
     {
         WaitForMove();
     }
     else if (_currentState == States.TurnLoop_WaitToMoveCompleted)
     {
         FinishThisTurn();
     }
 }
Ejemplo n.º 8
0
    private void StartNextTurn(long nextCharacterID, List <int> eligibleSpells, List <CoolDownData> cooldownSpells, List <int> eligibleSecrets, List <CoolDownData> cooldownSecrets)
    {
        DivineDebug.Log("Next Turn Started.");

        if (_actionData == null)
        {
            _actionData = new List <ActionData>();
        }
        _curState              = BattleLogicStates.TurnLoop_Start;
        _indexOfCurrentAction  = 0;
        _waitingToStartNewTurn = false;

        StartTimer();

        SelectACharacter(GetCharacterWithID(nextCharacterID), eligibleSpells, cooldownSpells, eligibleSecrets, cooldownSecrets, true);
    }
Ejemplo n.º 9
0
    private void StartWaitingForActionReceive()
    {
        _curState = BattleLogicStates.TurnLoop_WaitForAction;

        if (_actionData != null && _actionData.Count > 0)
        {
            StartFightActions();
        }

        if (_battleInfo.isBot && _currentSelectedCharacter.side == PartySide.Enemy)
        {
            _botLogic.RunLogic(_currentSelectedCharacter, _parties, Net_SendAction);
        }

        //<Test>
        if (FakeServer.instance.isFake)
        {
            Net_ImReady();
        }
        //</Test>
    }
Ejemplo n.º 10
0
    public void FakeServer_StartNextTurn(long nextCharacterID, List <int> eligibleSpells, int actionPoint)
    {
        DivineDebug.Log("Next Turn Started.");

        for (int i = 0; i < _parties.Length; i++)
        {
            if (_parties[i].side == PartySide.Player)
            {
                _parties[i].SetActionPoint(_parties[i].actionPoint + actionPoint, true);
            }
        }

        _curState             = BattleLogicStates.TurnLoop_Start;
        _indexOfCurrentAction = 0;
        _actionData           = new List <ActionData>();

        StartTimer();

        List <int> eligibleSecrets = new List <int>()
        {
        };
        List <CoolDownData> cooldownSecrets = new List <CoolDownData>(2)
        {
            new CoolDownData(0, 0), new CoolDownData(1, 0)
        };

        List <CoolDownData> cooldownSpells = new List <CoolDownData>(eligibleSpells.Count);

        foreach (var item in eligibleSpells)
        {
            cooldownSpells.Add(new CoolDownData(item, 2));
        }

        SelectACharacter(GetCharacterWithID(nextCharacterID), eligibleSpells, new List <CoolDownData>()
        {
        }, eligibleSecrets, new List <CoolDownData>()
        {
        }, true);
    }
Ejemplo n.º 11
0
    private void FinishTurn()
    {
        _curState = BattleLogicStates.TurnLoop_TurnFinished;

        _currentSelectedCharacter = null;

        _indexOfCurrentAction = 0;
        _actionData           = null;

        if (_waitingToStartNewTurn) //For prefight actions, need to say ready to server too
        {
            TryToStartNextTurn();
            return;
        }

        if (_battleEndCame)
        {
            OnBattleFinished();
        }
        else
        {
            Net_ImReady();
        }
    }
Ejemplo n.º 12
0
    private void StartParties()
    {
        DivineDebug.Log("Starting Parties.");

        for (int i = 0; i < _parties.Length; i++)
        {
            if (i == 0)
            {
                _parties[i].StartParty(_battleScene.startingPointsForLeftSide, _battleScene.formationPointsForLeftSide);
            }
            else
            {
                _parties[i].StartParty(_battleScene.startingPointsForRightSide, _battleScene.formationPointsForRightSide);
            }

            _parties[i].Event_PartyReady            += OnPartyReady;
            _parties[i].Event_CharacterDied         += OnCharacterDied;
            _parties[i].Event_ChakraAppeared        += OnChakraAppeared;
            _parties[i].Event_CharacterClicked      += OnCharacterClicked;
            _parties[i].Event_CharacterRecieveSpell += OnCharacterReceiveSpell;
        }

        _curState = BattleLogicStates.WaitForPartiesReadyToStartFight;
    }
Ejemplo n.º 13
0
    //Private Methods
    private void Init(BattleInfo battleInfo)
    {
        if (Application.isMobilePlatform)
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        DivineDebug.Log("Initing battle Logic.");

        _curState    = BattleLogicStates.Start;
        _battleInfo  = battleInfo;
        _battleScene = BattleSceneManager.instance.SelectBattleScene(_battleInfo.battleSceneType);
        _newBattleUI = NewUIGroup.CreateGroup(NewUIGroup.NAME__BATTLEUI, NewUIGroup.PrefabProviderType.Battle) as BattleUI;

        _generatedApOnDeath     = AppManager.instance.config.apDeath;
        _generatedApDamageTaken = AppManager.instance.config.apTakenDamage;

        _isFirstTurn   = true;
        _battleEndCame = false;

        _firstPing         = true;
        _pingProblem       = AppManager.instance.config.pingProblemNumber;
        _timeOutTime       = _pingProblem * 5;
        _clientCurrentTime = Time.time;

        _currentselectedCharacters = new List <Character>();

        MakeParties(_battleInfo.partyInfoes);
        StartParties();

        List <Character> orderArray = new List <Character>(_battleInfo.charactersTurnOrder_id.Length);

        foreach (var item in _battleInfo.charactersTurnOrder_id)
        {
            var characterOrder = _parties[0].FindCharacter(item);

            if (characterOrder != null)
            {
                orderArray.Add(characterOrder);
            }
            else
            {
                orderArray.Add(_parties[1].FindCharacter(item));
            }
        }

        _newBattleUI.Init(_parties[0].Name, _parties[1].Name,
                          _battleInfo.turnTime,
                          battleInfo.partyInfoes[0].availableSecrets,
                          OnSpellSelectedByCurrentChar,
                          OnSecretSelected,
                          orderArray);

        _newBattleUI.InitScore(0, 0);

        BattleDataProvider.instance.SetBattleLogic(this);

        BattleDataProvider.instance.Event_BattleFinish   += OnBattleFinishedComeFromServer;
        BattleDataProvider.instance.Event_BattleTurnData += OnTurnChanged;
        BattleDataProvider.instance.Event_ActionReceived += OnActionReceived;
        BattleDataProvider.instance.Event_BattlePingTick += OnPinging;
        //BattleDataProvider.instance.Event_Secret += OnSecretCastSuccessful;

        if (!TutorialManager.instance.IsInBattleTutorial())
        {
            TimeManager.instance.Event_OneSecTick += OnSecTick;
        }

        _battleSpellDataProvider = BattleSpellDataProvider.instance;

        GameAnalytics.NewProgressionEvent(GAProgressionStatus.Start, _parties[0].hero.moniker.ToString());

        if (_battleInfo.isBot)
        {
            _botLogic = new BotLogic(orderArray, battleInfo.botPower);
        }

        //Test
        FakeServer.instance.Event_ActionAnalyzed += OnActionReceived;
        FakeServer.instance.Event_BattleFinished += OnBattleFinishedComeFromServer;
    }
Ejemplo n.º 14
0
    private void OnBattleFinished()
    {
        _curState = BattleLogicStates.TryToEndBattle;

        CheckStates();
    }