Пример #1
0
        void BuildScenarioState(ScenarioState scenarioState)
        {
            scenarioState.ScenarioID = (int)_data.Entry.Id;
            ScenarioStepRecord step = GetStep();

            if (step != null)
            {
                scenarioState.CurrentStep = (int)step.Id;
            }
            scenarioState.CriteriaProgress = GetCriteriasProgress();
            scenarioState.BonusObjectives  = GetBonusObjectivesData();
            // Don't know exactly what this is for, but seems to contain list of scenario steps that we're either on or that are completed
            foreach (var state in _stepStates)
            {
                if (state.Key.IsBonusObjective())
                {
                    continue;
                }

                switch (state.Value)
                {
                case ScenarioStepState.InProgress:
                case ScenarioStepState.Done:
                    break;

                case ScenarioStepState.NotStarted:
                default:
                    continue;
                }

                scenarioState.PickedSteps.Add(state.Key.Id);
            }
            scenarioState.ScenarioComplete = IsComplete();
        }
Пример #2
0
        public override bool CanCompleteCriteriaTree(CriteriaTree tree)
        {
            ScenarioStepRecord step = tree.ScenarioStep;

            if (step == null)
            {
                return(false);
            }

            if (step.ScenarioID != _data.Entry.Id)
            {
                return(false);
            }

            if (step.IsBonusObjective())
            {
                return(!IsComplete());
            }

            if (step != GetStep())
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
        public override bool CanUpdateCriteriaTree(Criteria criteria, CriteriaTree tree, Player referencePlayer)
        {
            ScenarioStepRecord step = tree.ScenarioStep;

            if (step == null)
            {
                return(false);
            }

            if (step.ScenarioID != _data.Entry.Id)
            {
                return(false);
            }

            ScenarioStepRecord currentStep = GetStep();

            if (currentStep == null)
            {
                return(false);
            }

            if (step.IsBonusObjective())
            {
                return(true);
            }

            return(currentStep == step);
        }
Пример #4
0
        ScenarioStepState GetStepState(ScenarioStepRecord step)
        {
            if (!_stepStates.ContainsKey(step))
            {
                return(ScenarioStepState.Invalid);
            }

            return(_stepStates[step]);
        }
Пример #5
0
        void SetStep(ScenarioStepRecord step)
        {
            _currentstep = step;
            if (step != null)
            {
                SetStepState(step, ScenarioStepState.InProgress);
            }

            ScenarioState scenarioState = new ScenarioState();

            BuildScenarioState(scenarioState);
            SendPacket(scenarioState);
        }
Пример #6
0
        public virtual void CompleteStep(ScenarioStepRecord step)
        {
            Quest quest = Global.ObjectMgr.GetQuestTemplate(step.RewardQuestID);

            if (quest != null)
            {
                foreach (ObjectGuid guid in _players)
                {
                    Player player = Global.ObjAccessor.FindPlayer(guid);
                    if (player)
                    {
                        player.RewardQuest(quest, 0, null, false);
                    }
                }
            }

            if (step.IsBonusObjective())
            {
                return;
            }

            ScenarioStepRecord newStep = null;

            foreach (var _step in _data.Steps.Values)
            {
                if (_step.IsBonusObjective())
                {
                    continue;
                }

                if (GetStepState(_step) == ScenarioStepState.Done)
                {
                    continue;
                }

                if (newStep == null || _step.OrderIndex < newStep.OrderIndex)
                {
                    newStep = _step;
                }
            }

            SetStep(newStep);
            if (IsComplete())
            {
                CompleteScenario();
            }
            else
            {
                Log.outError(LogFilter.Scenario, "Scenario.CompleteStep: Scenario (id: {0}, step: {1}) was completed, but could not determine new step, or validate scenario completion.", step.ScenarioID, step.Id);
            }
        }
Пример #7
0
        ScenarioStepRecord GetFirstStep()
        {
            // Do it like this because we don't know what order they're in inside the container.
            ScenarioStepRecord firstStep = null;

            foreach (var scenarioStep in _data.Steps.Values)
            {
                if (scenarioStep.IsBonusObjective())
                {
                    continue;
                }

                if (firstStep == null || scenarioStep.OrderIndex < firstStep.OrderIndex)
                {
                    firstStep = scenarioStep;
                }
            }

            return(firstStep);
        }
Пример #8
0
        public override void CompletedCriteriaTree(CriteriaTree tree, Player referencePlayer)
        {
            ScenarioStepRecord step = tree.ScenarioStep;

            if (step == null)
            {
                return;
            }

            if (!step.IsBonusObjective() && step != GetStep())
            {
                return;
            }

            if (GetStepState(step) == ScenarioStepState.Done)
            {
                return;
            }

            SetStepState(step, ScenarioStepState.Done);
            CompleteStep(step);
        }
Пример #9
0
        public Scenario(ScenarioData scenarioData)
        {
            _data        = scenarioData;
            _currentstep = null;

            //ASSERT(_data);

            foreach (var step in _data.Steps)
            {
                SetStepState(step.Value, ScenarioStepState.NotStarted);
            }

            ScenarioStepRecord firstStep = GetFirstStep();

            if (firstStep != null)
            {
                SetStep(firstStep);
            }
            else
            {
                Log.outError(LogFilter.Scenario, "Scenario.Scenario: Could not launch Scenario (id: {0}), found no valid scenario step", _data.Entry.Id);
            }
        }
Пример #10
0
 public void SetStepState(ScenarioStepRecord step, ScenarioStepState state)
 {
     _stepStates[step] = state;
 }
Пример #11
0
        void LoadInstanceData(uint instanceId)
        {
            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_SCENARIO_INSTANCE_CRITERIA_FOR_INSTANCE);

            stmt.AddValue(0, instanceId);

            SQLResult result = DB.Characters.Query(stmt);

            if (!result.IsEmpty())
            {
                SQLTransaction trans = new SQLTransaction();
                long           now   = Time.UnixTime;

                List <CriteriaTree> criteriaTrees = new List <CriteriaTree>();
                do
                {
                    uint  id      = result.Read <uint>(0);
                    ulong counter = result.Read <ulong>(1);
                    long  date    = result.Read <uint>(2);

                    Criteria criteria = Global.CriteriaMgr.GetCriteria(id);
                    if (criteria == null)
                    {
                        // Removing non-existing criteria data for all instances
                        Log.outError(LogFilter.Scenario, "Removing scenario criteria {0} data from the table `instance_scenario_progress`.", id);

                        stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_SCENARIO_INSTANCE_CRITERIA);
                        stmt.AddValue(0, instanceId);
                        stmt.AddValue(1, id);
                        trans.Append(stmt);
                        continue;
                    }

                    if (criteria.Entry.StartTimer != 0 && (date + criteria.Entry.StartTimer) < now)
                    {
                        continue;
                    }

                    switch (criteria.Entry.Type)
                    {
                    // Blizzard appears to only stores creatures killed progress for unknown reasons. Either technical shortcoming or intentional
                    case CriteriaTypes.KillCreature:
                        break;

                    default:
                        continue;
                    }

                    SetCriteriaProgress(criteria, counter, null, ProgressType.Set);

                    List <CriteriaTree> trees = Global.CriteriaMgr.GetCriteriaTreesByCriteria(criteria.Id);
                    if (trees != null)
                    {
                        foreach (CriteriaTree tree in trees)
                        {
                            criteriaTrees.Add(tree);
                        }
                    }
                }while (result.NextRow());

                DB.Characters.CommitTransaction(trans);

                foreach (CriteriaTree tree in criteriaTrees)
                {
                    ScenarioStepRecord step = tree.ScenarioStep;
                    if (step == null)
                    {
                        continue;
                    }

                    if (IsCompletedCriteriaTree(tree))
                    {
                        SetStepState(step, ScenarioStepState.Done);
                    }
                }
            }
        }