public void RegisterQuest(CustomQuest quest) { if (QuestFrameworkMod.Instance.Status != State.LAUNCHING) { throw new InvalidOperationException($"Cannot register new quest when in state `{QuestFrameworkMod.Instance.Status}`."); } if (string.IsNullOrEmpty(quest.Name) || string.IsNullOrEmpty(quest.OwnedByModUid)) { throw new InvalidQuestException($"Quest name and category can't be empty or null!"); } if (quest.Name.Contains(' ') || quest.Name.Contains('@')) { throw new InvalidQuestException("Quest name contains illegal characters (spaces or these reserved characters: @)"); } if (this.Quests.Any(q => q.GetFullName() == quest.GetFullName())) { throw new InvalidQuestException($"Quest `{quest.GetFullName()}` is already registered!"); } quest.OnRegister(); this.Quests.Add(quest); this.monitor.Log($"Added quest `{quest.Name}` to quest manager"); }
public void ReintegrateQuests(Dictionary <string, int> oldIds) { if (!Context.IsMainPlayer) { throw new InvalidOperationException("Only main player can reintegrate quests."); } this.ResetIds(this.QuestManager.Quests); var newIds = this.AssignIds(QuestManager.ID_ROOT, this.QuestManager.Quests); this.questIdCache = newIds; if (oldIds == null || !Context.IsWorldReady) { return; } foreach (var farmhand in Game1.getAllFarmers()) { foreach (var oldIdName in oldIds) { int oldId = oldIdName.Value; string questKey = oldIdName.Key; CustomQuest managedQuest = this.QuestManager.Fetch(questKey); if (!farmhand.hasQuest(oldIdName.Value)) { continue; } if (managedQuest != null && newIds.TryGetValue(questKey, out int newId)) { Quest quest = farmhand.questLog.FirstOrDefault(q => q.id.Value == oldId); int questType = managedQuest.CustomTypeId; if (quest == null) { this.monitor.Log($"Quest `{managedQuest.GetFullName()}` is no longer in {farmhand.Name}'s questlog (player id: {farmhand.UniqueMultiplayerID}) - No fix needed."); continue; } quest.id.Value = newId; // quest.currentObjective = quest.id.Value.ToString(); quest.questType.Value = questType != -1 ? questType : managedQuest.BaseType.ToVanillaTypeId(); this.monitor.Log($"Fixed quest `{managedQuest.GetFullName()}` (#{oldId} -> #{newId}) in {farmhand.Name}'s questlog (player id: {farmhand.UniqueMultiplayerID})."); } else { farmhand.removeQuest(oldIdName.Value); this.monitor.Log($"Removed unknown quest `{questKey}` #{oldIdName.Value} from {farmhand.Name}'s questlog (player id: {farmhand.UniqueMultiplayerID})."); } } } }
private static QuestStatSummary GetQuestStats(CustomQuest managedQuest) { return(QuestFrameworkMod.Instance .StatsManager .GetStats(Game1.player.UniqueMultiplayerID) .GetQuestStatSummary(managedQuest.GetFullName())); }
public bool CheckCondition(string condition, string value, CustomQuest context) { bool isNot = false; string realConditionName = condition; if (condition == null || value == null) { return(true); } if (condition.StartsWith("not:")) { condition = condition.Substring(4); isNot = true; } if (this.Conditions.TryGetValue(condition, out var conditionFunc)) { bool result = false; foreach (string valuePart in value.Split('|')) { result |= conditionFunc(valuePart.Trim(), context); } if (this.monitor.IsVerbose) { this.monitor.Log( $"Checked condition `{realConditionName}` for `{value}` " + $"in quest context `{context.GetFullName()}` " + $"returns {(isNot ? !result : result)}"); } return(isNot ? !result : result); } this.monitor.Log( $"Checked unknown condition `{condition}` in quest context `{context.GetFullName()}`. Result for unknown conditions is always false.", LogLevel.Warn); return(false); }
public static bool IsNeverCompleted(this CustomQuest customQuest) { if (!Context.IsWorldReady) { return(false); } var stats = QuestFrameworkMod.Instance. StatsManager .GetStats(Game1.player.UniqueMultiplayerID); return(stats.GetQuestStatSummary(customQuest.GetFullName()).LastCompleted == null); }
private void OnQuestAccepted(object sender, QuestEventArgs e) { if (!e.IsManaged || this._npcQuestOffers.Value.Count == 0) { return; } CustomQuest quest = e.GetManagedQuest(); QuestOffer <NpcOfferAttributes> offer = this.QuestOffers.FirstOrDefault(o => o.QuestName == quest.GetFullName()); if (offer != null) { this.QuestOffers.Remove(offer); this.RefreshActiveIndicators(); } }