Beispiel #1
0
        public QuestActionStructure(QuestAction current, ILoggable updateLogs)
        {
            hasActionOnComplete = new Dictionary <QuestAction, bool>();
            hasActionOnFail     = new Dictionary <QuestAction, bool>();
            currentAction       = current;
            _actionChanged      = new BehaviorSubject <QuestAction>(current);
            ActionChanged().Subscribe((action) =>
            {
                #region Structure Logs
                currentAction = action;
                action.SetActive();

                JournalLog currentLog = updateLogs.AddDiscreteLogWrapper(action.TaskName(), action.TaskDescription(), action.StartProgress(), action.Target());
                action.UpdateScore().Subscribe((score) =>
                {
                    if (!currentLog.HasBeenCompleted())
                    {
                        currentLog.UpdateCurrentProgress(score > currentLog.Range ? currentLog.Range : score);
                    }
                });
                action.logUpdated.Subscribe((log) =>
                {
                    updateLogs.AddLogWrapper(log);
                });
                #endregion
                #region Structure Completion status
                action.OnComplete().Subscribe((x) =>
                {
                    if (x)
                    {
                        if (!hasActionOnComplete.ContainsKey(action))
                        {
                            completeSubject.OnNext(true);
                        }
                    }
                });

                action.OnFail().Subscribe((x) =>
                {
                    if (x)
                    {
                        if (!hasActionOnFail.ContainsKey(action))
                        {
                            failSubject.OnNext(true);
                        }
                    }
                });
                #endregion
            });
        }