Beispiel #1
0
        public bool TryGetCharTask(uint charIdx, TaskKind kind, int taskId, out GameTask task)
        {
            //var charTasksNode = (XmlElement)CharNode(charIdx).SelectSingleNode("Tasks");
            var charTasksNode = CharTasksNode(charIdx);
            var taskNodeName  = GameTask.GenXmlNodeName(kind, taskId);
            var taskNode      = (XmlElement)charTasksNode.SelectSingleNode(taskNodeName);

            if (taskNode != null)
            {
                try {
                    task = GameTask.FromXmlElement(taskNode);
                    return(true);
                } catch (Exception) { }
            }

            task = new GameTask();
            return(false);
        }
Beispiel #2
0
        public void SaveCharTask(GameTask task)
        {
            //var charTasksNode = (XmlElement)CharNode(task.CharIdx).SelectSingleNode("Tasks");
            var charTasksNode = CharTasksNode(task.CharIdx);
            var taskNodeName  = task.XmlNodeName;

            var taskNode = (XmlElement)charTasksNode.SelectSingleNode(taskNodeName);

            if (taskNode == null)
            {
                task.AppendXmlElement(charTasksNode);
            }
            else
            {
                task.SetXmlAttribs(taskNode);
            }

            SaveFile();
        }
Beispiel #3
0
        public GameTask Add(GameTask gameTask)
        {
            bool taskMatureTimeUnique = false;
            uint attempts             = 0;

            while (taskMatureTimeUnique == false)
            {
                ArgumentException aex = new ArgumentException();

                if (this.Queue.ContainsKey(gameTask.MatureTime.Ticks))
                {
                    taskMatureTimeUnique = false;
                }
                else
                {
                    taskMatureTimeUnique = true;

                    try {
                        Queue.Add(gameTask.MatureTime.Ticks, gameTask);
                    } catch (ArgumentException aexNew) {
                        MessageBox.Show("Failed to add task with key: '" + gameTask.MatureTime.Ticks + "'.");
                        aex = aexNew;
                    }
                }

                if (taskMatureTimeUnique == false)
                {
                    gameTask = gameTask.AddTicks(1);
                }

                attempts += 1;

                if (attempts > 500)
                {
                    MessageBox.Show("GameTaskQueue::Add(): Error adding task: " + aex.ToString());
                }
            }

            return(gameTask);
        }
Beispiel #4
0
        // Populates queue taking in to account last invoke times.
        public void Populate(Interactor intr, int charsMax, bool resetDay)
        {
            var now = DateTime.Now;

            for (uint charIdx = 0; charIdx < charsMax; charIdx++)
            {
                // ################################### INVOCATION #####################################
                int invokesToday = intr.AccountStates.GetCharStateOr(charIdx, "invokesToday", 0);

                DateTime invokesCompletedOn = intr.AccountStates.GetCharStateOr(charIdx,
                                                                                "invokesCompleteFor", Global.Default.SomeOldDate);

                // Clear any stale invoke count:
                if (invokesCompletedOn < TodaysGameDate.AddDays(-1))
                {
                    invokesToday = 0;
                }

                DateTime mostRecentInvoke = intr.AccountStates.GetCharStateOr(charIdx, "mostRecentInvocationTime",
                                                                              now.AddHours(-24));

                var invTaskMatureTime = CalculateTaskMatureTime(mostRecentInvoke, charIdx,
                                                                TaskKind.Invocation, invokesToday, 0.0f);

                if (invokesToday >= 6)
                {
                    if (invokesCompletedOn < TodaysGameDate)                       // START FRESH DAY
                    {
                        intr.AccountStates.SaveCharState(0, charIdx, "invokesToday");
                        invokesToday      = 0;
                        invTaskMatureTime = now;
                    }
                    else                         // DONE FOR THE DAY
                    {
                        invTaskMatureTime = NextThreeAmPst;
                    }
                }

                if (resetDay)
                {
                    intr.AccountStates.SaveCharState(0, charIdx, "invokesToday");
                    intr.AccountStates.SaveCharState(TodaysGameDate.AddDays(-1), charIdx,
                                                     "mostRecentInvocationTime");
                    invokesToday      = 0;
                    invTaskMatureTime = now;
                }

                intr.Log(LogEntryType.Debug, "Adding invocation task to queue for character [{0}], matures: {1}.",
                         charIdx, invTaskMatureTime);

                var invTask = new GameTask(mostRecentInvoke, invTaskMatureTime, charIdx, TaskKind.Invocation, invokesToday, 0.0f);
                intr.AccountStates.SaveCharTask(invTask);
                this.Add(invTask);


                // ################################## PROFESSIONS #####################################
                // ################ Prune Stale Profession Tasks ################
                //for (var p = 0; p < ProfessionTasksRef.ProfessionTaskNames.Length; p++) {
                //	var settingKey = "MostRecentProfTime_" + p;
                //	var oldTaskThreshold = now.AddDays(-2);

                //	//DateTime profTaskMatureTime;

                //	//if (DateTime.TryParse(intr.AccountStates.GetCharStateOr(charIdx,
                //	//			charSettingSection, ""), out profTaskMatureTime)) {
                //	//	intr.Log("Found " + settingKey + " for " + charSettingSection + " in ini file: " +
                //	//		profTaskMatureTime.ToString() + ".", LogEntryType.Debug);

                //	//	//// [TODO]: Is this necessary?:
                //	//	//if (profTaskMatureTime < oldTaskThreshold) {
                //	//	//	intr.Log("Removing " + settingKey + " for " + charSettingSection + " from ini file.", LogEntryType.Debug);
                //	//	//	intr.GameAccount.RemoveSetting(settingKey, charSettingSection);
                //	//	//}
                //	//}
                //	DateTime profTaskMatureTime = intr.AccountStates.GetCharStateOr(charIdx,
                //		settingKey, Global.Default.SomeOldDate);
                //}

                // ################ Add Tasks to Queue ################
                int tasksQueued = 0;

                for (var taskId = 0; taskId < ProfessionTasksRef.ProfessionTaskNames.Length; taskId++)
                {
                    GameTask profTask;

                    // Attempt to load from new task persistence system:
                    if (!intr.AccountStates.TryGetCharTask(charIdx, TaskKind.Profession, taskId, out profTask))
                    {
                        // Use old school system:
                        var      mostRecentTaskTime = intr.AccountStates.GetCharStateOr(charIdx, "MostRecentProfTime_" + taskId, Global.Default.SomeOldDate);
                        DateTime profTaskMatureTime = CalculateTaskMatureTime(mostRecentTaskTime, charIdx, TaskKind.Profession, taskId, 0.0f);
                        profTask = new GameTask(mostRecentTaskTime, profTaskMatureTime, charIdx, TaskKind.Profession, taskId, 0.0f);
                    }

                    intr.Log(LogEntryType.Info, "Adding profession task to queue for character [" + charIdx
                             + "], matures: " + profTask.MatureTime.ToString() + ", taskId: " + taskId.ToString() + ".");
                    this.Add(profTask);
                    tasksQueued += 1;
                }

                intr.Log(LogEntryType.Info, "[" + tasksQueued.ToString() + "] profession tasks queued for character [" + charIdx + "].");
            }
        }