示例#1
0
    void OnCommandsDepleted(BattleQueue queue)
    {
        LogEx.Log <BattleStateExecute>("#--- End Turn " + (Coordinator.TurnCount) + " ---#");

        queue.Emptied -= OnCommandsDepleted;
        End();
    }
示例#2
0
    public void RemoveEffect(FieldEffectType fieldEffectType)
    {
        // TODO.
        LogEx.Log <FieldSide>("Removed effect: " + fieldEffectType);

        _fieldEffects[fieldEffectType].Reset();
    }
示例#3
0
    public void RegisterCharacter(Character character)
    {
        if (!_activeCharacters.Contains(character))
        {
            LogEx.Log <BattleSystem>("Registered character: '{0}'", character.name);

            _activeCharacters.Add(character);

            character.BattleEntities.ForEach(x => x.Initialize(this));

            // Assign character into player slot.
            //character.Owner.FieldSide.Register(character);

            if (CharacterAddedToSlot != null)
            {
                CharacterAddedToSlot.Invoke(character);
            }

            if (PostCharacterAddedToSlot != null)
            {
                PostCharacterAddedToSlot.Invoke(character);
            }
        }
        else
        {
            LogEx.LogError <BattleSystem>("Cannot register character '{0}' as they are already registered.", character.name);
        }
    }
示例#4
0
    void RegisterAction(BaseAction action, BattleQueueType type)
    {
        if (_logRegistrations)
        {
            LogEx.Log <BattleQueue>("Registered action: {0} of type '{1}'", action.GetType().Name, type.ToString());
        }

        switch (type)
        {
        case BattleQueueType.GenericUpdate:
            _genericUpdates.Queue.Enqueue(action);
            break;

        case BattleQueueType.PlayerCommand:
            _playerCommands.Queue.Enqueue(action);
            break;

        case BattleQueueType.StatusUpdate:
            _statusUpdates.Queue.Enqueue(action);
            break;

        case BattleQueueType.Weather:
            _weatherUpdates.Queue.Clear();
            _weatherUpdates.Queue.Enqueue(action);
            break;
        }
    }
示例#5
0
    void OnStateEnd(BattleState endingState)
    {
        switch (endingState.ID)
        {
        case BattleStateID.Start: SetState(BattleStateID.WaitingForInput); break;

        case BattleStateID.WaitingForInput: SetState(BattleStateID.Executing); break;

        case BattleStateID.Executing:
            // TODO: Evaluate win condition.
            bool gameOver = false;

            if (gameOver)
            {
                LogEx.Log <BattleCoordinator>("Game Over!");
            }
            else
            {
                SetState(BattleStateID.PostTurn);
            }
            break;

        case BattleStateID.PostTurn: SetState(BattleStateID.PostTurnExecute); break;

        case BattleStateID.PostTurnExecute: SetState(BattleStateID.WaitingForInput); break;
        }
    }
示例#6
0
    public void RegisterPlayer(Player player, int fieldSideID)
    {
        if (!_players.Contains(player))
        {
            LogEx.Log <BattleSystem>("Registered player: '{0}'", player.name);

            _players.Add(player);

            fieldSideID = Mathf.Clamp(fieldSideID, 0, _fieldSides.Count - 1);

            player.AssignFieldSide(_fieldSides[fieldSideID]);

            // TEMP!!!
            //RegisterCharacter(player.ActiveCharacter);

            // TEMP!!!
            //player.ActiveCharacter.BattleEntities.ForEach(x => x.Initialize(this));

            if (PlayerAdded != null)
            {
                PlayerAdded.Invoke(player);
            }
        }
        else
        {
            LogEx.LogError <BattleSystem>("Cannot register player '{0}' as they are already registered.", player.name);
        }
    }
    protected override void OnApplyEffect(Character target)
    {
        LogEx.Log <FieldEffectSpikes>("Applying spikes. Multiplier {0}", Level);

        var damage = _parameters.PercentageDamagePerLevel[Level];

        target.Health.ChangeHealth(null, -damage);
    }
示例#8
0
 void OnEnterWeather(BattleSystem battleSystem)
 {
     if (battleSystem.Weather.Current != null)
     {
         LogEx.Log <BattleQueue>("Found a weather effect.");
         RegisterWeather(battleSystem.Weather.Current);
     }
 }
示例#9
0
 public void Assign(Character character)
 {
     LogEx.Log <FieldSlot>("Assigned character '{0}'", character.name);
     Character          = character;
     Character.Fainted += OnCharacterFainted;
     Character.AssignSlot(this);
     CharacterAdded.InvokeSafe(Character);
 }
示例#10
0
 void OnHealthChanged(HealthChangeEvent obj)
 {
     if (obj.NewValue <= 0)
     {
         LogEx.Log <Character>("{0} fainted...", name);
         ActiveState = ActiveState.Fainted;
         Fainted.InvokeSafe(this);
     }
 }
示例#11
0
    void OnPlayerReadyStateChanged(Player player)
    {
        LogEx.Log <BattleCoordinator>("{0} ready state changed to: {1}", player.name, player.IsReady);

        if (Coordinator.System.Players.TrueForAll(x => x.IsReady))
        {
            End();
        }
    }
示例#12
0
    public void RemoveAllEffects()
    {
        // TODO.
        LogEx.Log <FieldSide>("Removed all effects.");

        foreach (var fieldEffect in _fieldEffects)
        {
            fieldEffect.Value.Reset();
        }
    }
示例#13
0
    public void IncreaseEffect()
    {
        Active = true;

        if (CanApply)
        {
            Level++;
            LogEx.Log <FieldEffectSpikes>("Increased effect multiplier to {0}", Level);
        }
    }
示例#14
0
    public override void OnStart()
    {
        Coordinator.System.Players.ForEach(x => x.ReadyStateChanged += OnPlayerReadyStateChanged);

        LogEx.Log <BattleCoordinator>("Waiting for {0} players.", Coordinator.System.Players.Count);

        if (Coordinator.AutoReadyPlayers)
        {
            Coordinator.System.Players.ForEach(x => x.Attack());
        }
    }
示例#15
0
    public override void OnStart()
    {
        base.OnStart();

        Coordinator.AddTurn();

        LogEx.Log <BattleStateExecute>("#--- Begin Turn " + (Coordinator.TurnCount) + " ---#");

        Coordinator.Queue.Emptied += OnCommandsDepleted;

        OnContinue();
    }
示例#16
0
    void RegisterAction(BaseAction action, BattleQueueType type)
    {
        if (_logRegistrations)
        {
            LogEx.Log <BattleQueue>("Registered action: {0} of type '{1}'", action.GetType().Name, type.ToString());
        }

        if (ActionRegistered != null)
        {
            ActionRegistered.Invoke(action, type);
        }
    }
示例#17
0
    protected override void OnExecute(BattleSystem battleSystem)
    {
        _executionsTotal++;

        TriggerCompletion();

        if (Expired)
        {
            LogEx.Log <Lifetime>(name + "'s life expired.");
            battleSystem.Log(ExpiryMessage);
        }
    }
示例#18
0
    public virtual void Execute(BattleSystem battleSystem)
    {
        Executed = true;

        if (Log)
        {
            LogEx.Log <BaseAction>(name + " executed.");
        }

        _battleSystem = battleSystem;

        OnExecute(battleSystem);
    }
示例#19
0
    public void Log(string message, params object[] args)
    {
        if (!string.IsNullOrEmpty(message))
        {
            RegisterAction(() => LogEx.Log <BattleSystem>("Battle Log: " + message), "BattleLog");

            RegisterAction(() =>
            {
                LogEx.Log <BattleSystem>("Battle Log: " + message);
                LogPosted.InvokeSafe(message);
            }, "BattleLog");
        }
    }
示例#20
0
    public void RelayToReference(BattleSystem battleSystem)
    {
        if (Log)
        {
            LogEx.Log <TriggerOnDestroy>("Relaying...");
        }

        foreach (var action in Reference.GetComponents <TargetedAction>())
        {
            action.SetSource(Source);
            action.SetReciever(Reciever);
            battleSystem.RegisterAction(action);
        }
    }
示例#21
0
    public void Set(Weather weather)
    {
        LogEx.Log <BattleWeather>("Weather is now: " + weather.ToString());

        switch (weather)
        {
        case Weather.None: Clear(); break;

        case Weather.Sandstorm: Create(Sandstorm); break;
        }

        if (Changed != null)
        {
            Changed.Invoke(this);
        }
    }
示例#22
0
    public void AddEffect(FieldEffectType fieldEffectType)
    {
        if (_fieldEffects.ContainsKey(fieldEffectType))
        {
            var fieldEffect = _fieldEffects[fieldEffectType];

            if (fieldEffect.CanApply)
            {
                LogEx.Log <FieldSide>("Added effect: " + fieldEffectType);
                _fieldEffects[fieldEffectType].IncreaseEffect();
            }
            else
            {
                LogEx.Log <FieldSide>("Field effect of type '{0}' cannot be applied.", fieldEffectType);
            }
        }
    }
示例#23
0
    BaseAction Dequeue(ExecutionType executionType)
    {
        GenerateQueue(executionType);

        if (_genericUpdates.Queue.Count != 0)
        {
            return(_genericUpdates.Queue.Dequeue());
        }

        if (_linearQueues.Count == 0)
        {
            return(null);
        }
        else
        {
            if (_linearQueues.Peek().Queue.Count != 0)
            {
                return(_linearQueues.Peek().Queue.Dequeue());
            }
            else
            {
                // Find the next non-empty queue.
                BattleQueueWrapper next = null;

                while (next == null || next.Queue.Count == 0 && _linearQueues.Count != 0)
                {
                    next = _linearQueues.Dequeue();

                    // Activate the next queue.
                    if (next.OnActivation != null)
                    {
                        next.OnActivation(_battleSystem);
                    }
                }

                if (next != null)
                {
                    LogEx.Log <BattleQueue>("Moving to next non-empty queue: " + next.Type);
                }

                return(next != null && next.Queue.Count != 0 ? next.Queue.Dequeue() : null);
            }
        }
    }
示例#24
0
    void OnPlayerReplacementCharacterSelected(ReplaceCommand replaceCommand)
    {
        Coordinator.System.RegisterPlayerCommand(replaceCommand);

        if (_replacingPlayers.Contains(replaceCommand.Player))
        {
            _replacingPlayers.Remove(replaceCommand.Player);
        }
        else
        {
            LogEx.LogError <BattleStatePostTurn>("Player {0} cannot be removed as they were never registered.", replaceCommand.Player.name);
        }

        if (_replacingPlayers.Count == 0)
        {
            LogEx.Log <BattleStatePostTurn>("All players have chosen their replacements. Executing...");
            End();
        }
    }
示例#25
0
    void SetState(BattleStateID stateID)
    {
        switch (stateID)
        {
        case BattleStateID.Start: _state = _stateStart; break;

        case BattleStateID.WaitingForInput: _state = _stateInput; break;

        case BattleStateID.Executing: _state = _stateExecute; break;

        case BattleStateID.PostTurn: _state = _statePostTurn; break;

        case BattleStateID.PostTurnExecute: _state = _statePostTurnExecute; break;
        }

        LogEx.Log <BattleCoordinator>("State is now: " + _state.ID);

        _state.Start(this);
    }
示例#26
0
    public override void OnStart()
    {
        base.OnStart();

        // Get all players whose character has fainted.
        _replacingPlayers = new List <Player>();
        _replacingPlayers.AddRange(Coordinator.System.Players
                                   .Where(x => x.ActiveCharacter.ActiveState == ActiveState.Fainted)
                                   .ToList());

        if (_replacingPlayers.Count != 0)
        {
            LogEx.Log <BattleStatePostTurn>("Waiting for {0} players to choose a replacement...", _replacingPlayers.Count);
            _replacingPlayers.ForEach(x => x.ReplacementCharacterSelected += OnPlayerReplacementCharacterSelected);
        }
        else
        {
            End();
        }
    }
示例#27
0
    public void Execute(ExecutionType executionType)
    {
        var next = Dequeue(executionType);

        if (next != null)
        {
            next.Completed += OnActionExecutionComplete;
            next.Execute(_battleSystem);
        }
        else
        {
            LogEx.Log <BattleSystem>("No more battle actions left to execute.");

            // TODO: Move Turn Count somewhere else.
            //TurnCount++;

            Reset();

            Emptied.InvokeSafe(this);
        }
    }
示例#28
0
    public void UnregisterPlayer(Player player)
    {
        if (_players.Contains(player))
        {
            LogEx.Log <BattleSystem>("Unregistered player: '{0}'", player.name);

            _players.Remove(player);

            // TEMP!!!
            UnregisterCharacter(player.ActiveCharacter);

            if (PlayerRemoved != null)
            {
                PlayerRemoved.Invoke(player);
            }
        }
        else
        {
            LogEx.LogError <BattleSystem>("Cannot unregister player '{0}' as they were never registered.", player.name);
        }
    }
示例#29
0
        private void _HandleDispatcherException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            var log = LogEx.Log(this);

            log.Error(e.Exception, "Unhandled dispatcher exception");

            FirstChanceDispatcherException?.Invoke(this, e);

            if (e.Handled)
            {
                log.Information("Exception handled by first chance handler");
                return;
            }

            if (MainWindow is MetroWindow window)
            {
                window.ShowModalMessageExternal(
                    "Error", $"{e.Exception.Message}\r\n\r\n{e.Exception}");
            }

            e.Handled = true;
            Shutdown(e.Exception.GetHashCode());
        }
示例#30
0
    public void UnregisterCharacter(Character character)
    {
        if (_activeCharacters.Contains(character))
        {
            LogEx.Log <BattleSystem>("Unregistered character: '{0}'", character.name);

            _activeCharacters.Remove(character);

            if (CharacterRemovedFromSlot != null)
            {
                CharacterRemovedFromSlot.Invoke(character);
            }

            if (PostCharacterRemovedFromSlot != null)
            {
                PostCharacterRemovedFromSlot.Invoke(character);
            }
        }
        else
        {
            LogEx.LogError <BattleSystem>("Cannot unregister character '{0}' as they were never registered.", character.name);
        }
    }