public void RestoreSaveData(QuestSaveData_v1 data) { // Restore base state uid = data.uid; questComplete = data.questComplete; questSuccess = data.questSuccess; questName = data.questName; displayName = data.displayName; factionId = data.factionId; questStartTime = data.questStartTime; questTombstoned = data.questTombstoned; questTombstoneTime = data.questTombstoneTime; smallerDungeonsState = data.smallerDungeonsState; compiledByVersion = data.compiledByVersion; // Restore active log messages activeLogMessages.Clear(); foreach (LogEntry logEntry in data.activeLogMessages) { activeLogMessages.Add(logEntry.stepID, logEntry); } // Restore messages messages.Clear(); foreach (Message.MessageSaveData_v1 messageData in data.messages) { Message message = new Message(this); message.RestoreSaveData(messageData); messages.Add(message.ID, message); } // Restore resources resources.Clear(); foreach (QuestResource.ResourceSaveData_v1 resourceData in data.resources) { // Construct deserialized QuestResource based on type System.Reflection.ConstructorInfo ctor = resourceData.type.GetConstructor(new Type[] { typeof(Quest) }); QuestResource resource = (QuestResource)ctor.Invoke(new object[] { this }); // Restore state resource.RestoreResourceSaveData(resourceData); resources.Add(resource.Symbol.Name, resource); } // Restore questors questors.Clear(); if (data.questors != null) { questors = data.questors; } // Restore tasks tasks.Clear(); foreach (Task.TaskSaveData_v1 taskData in data.tasks) { Task task = new Task(this); task.RestoreSaveData(taskData); tasks.Add(task.Symbol.Name, task); } }
/// <summary> /// Cache target quest and resource objects. /// If true then TargetQuest and TargetResource objects are cached and available. /// </summary> bool CacheTarget() { // Check already cached if (targetQuest != null && targetResource != null) { return(true); } // Must have a questUID and targetSymbol if (questUID == 0 || targetSymbol == null) { return(false); } // Get the quest this resource belongs to targetQuest = QuestMachine.Instance.GetActiveQuest(questUID); if (targetQuest == null) { return(false); } // Get the resource from quest targetResource = targetQuest.GetResource(targetSymbol); if (targetResource == null) { return(false); } return(true); }
/// <summary> /// Assign this behaviour a QuestResource object. /// </summary> public void AssignResource(QuestResource questResource) { if (questResource != null) { questUID = questResource.ParentQuest.UID; targetSymbol = questResource.Symbol; } }
/// <summary> /// Walks SiteLink > Quest > Place > QuestMarkers > Target to see if an individual NPC has been placed elsewhere. /// Used only to determine if an individual NPC should be disabled at home location by layout builders. /// Ignores non-individual NPCs. /// </summary> /// <param name="factionID">Faction ID of individual NPC.</param> /// <returns>True if individual has been placed elsewhere, otherwise false.</returns> public bool IsIndividualQuestNPCAtSiteLink(int factionID) { // Check this is a valid individual if (!IsIndividualNPC(factionID)) return false; // Iterate site links foreach (SiteLink link in siteLinks) { // Attempt to get Quest target Quest quest = GetQuest(link.questUID); if (quest == null) continue; // Attempt to get Place target Place place = quest.GetPlace(link.placeSymbol); if (place == null) continue; // Must have target resources SiteDetails siteDetails = place.SiteDetails; QuestMarker marker = siteDetails.questSpawnMarkers[siteDetails.selectedQuestItemMarker]; if (marker.targetResources == null) { Debug.Log("IsIndividualQuestNPCAtSiteLink() found a SiteLink with no targetResources assigned."); continue; } // Check spawn marker at this site for target NPC resource foreach(Symbol target in marker.targetResources) { // Get target resource QuestResource resource = quest.GetResource(target); if (resource == null) continue; // Must be a Person resource if (!(resource is Person)) continue; // Person must be an individual and not at home Person person = (Person)resource; if (!person.IsIndividualNPC || person.IsIndividualAtHome) continue; // Check if factionID match to placed NPC // This means we found an individual placed at site who is not supposed to be at their home location if (person.FactionData.id == factionID) return true; } } return false; }
public void AddResource(QuestResource resource) { if (resource.Symbol == null || string.IsNullOrEmpty(resource.Symbol.Name)) { throw new Exception("QuestResource must have a named symbol."); } if (resources.ContainsKey(resource.Symbol.Name)) { throw new Exception(string.Format("Duplicate QuestResource symbol name found: {0}", resource.Symbol)); } resources.Add(resource.Symbol.Name, resource); }
public void AddResource(QuestResource resource) { if (resource.Symbol == null || string.IsNullOrEmpty(resource.Symbol.Name)) { throw new Exception("QuestResource must have a named symbol."); } if (resources.ContainsKey(resource.Symbol.Name)) { throw new Exception(string.Format("Duplicate QuestResource symbol name found: {0}", resource.Symbol)); } resources.Add(resource.Symbol.Name, resource); // Track incoming Questor if resource is a Person with IsQuestor flag if (resource is Person && (resource as Person).IsQuestor) { AddQuestor(resource.Symbol); } }
/// <summary> /// Cache target quest and resource objects. /// If true then TargetQuest and TargetResource objects are cached and available. /// </summary> bool CacheTarget() { // Check already cached if (targetQuest != null && targetResource != null) { return(true); } // Must have a questUID and targetSymbol if (questUID == 0 || targetSymbol == null) { return(false); } // Get the quest this resource belongs to targetQuest = QuestMachine.Instance.GetQuest(questUID); if (targetQuest == null) { return(false); } // Get the resource from quest targetResource = targetQuest.GetResource(targetSymbol); if (targetResource == null) { return(false); } // Cache local EnemyEntity behaviour if resource is a Foe if (targetResource != null && targetResource is Foe) { enemyEntityBehaviour = gameObject.GetComponent <DaggerfallEntityBehaviour>(); } return(true); }
/// <summary> /// Schedule a quest resource to rearm player click immediately after task execution. /// </summary> /// <param name="resource"></param> public void ScheduleClickRearm(QuestResource resource) { pendingClickRearms.Add(resource); }
/// <summary> /// Assigns a quest resource to this Place site. /// Supports Persons, Foes, Items from within same quest as Place. /// Quest must have previously created SiteLink for layout builders to discover assigned resources. /// </summary> /// <param name="targetSymbol">Resource symbol of Person, Item, or Foe to assign.</param> public void AssignQuestResource(Symbol targetSymbol) { // Site must have at least one marker of each type if (!ValidateQuestMarkers(siteDetails.questSpawnMarkers, siteDetails.questItemMarkers)) { throw new Exception(string.Format("Tried to assign resource {0} to Place without at least 1x spawn and 1x item marker.", targetSymbol.Name)); } // Attempt to get resource from symbol QuestResource resource = ParentQuest.GetResource(targetSymbol); if (resource == null) { throw new Exception(string.Format("Could not locate quest resource with symbol {0}", targetSymbol.Name)); } // Must be a supported resource type MarkerTypes requiredMarkerType = MarkerTypes.None; if (resource is Person || resource is Foe) { requiredMarkerType = MarkerTypes.QuestSpawn; } else if (resource is Item) { requiredMarkerType = MarkerTypes.QuestItem; } else { throw new Exception(string.Format("Tried to assign incompatible resource symbol {0} to Place", targetSymbol.Name)); } // Assign target resource to marker selected for this quest if (requiredMarkerType == MarkerTypes.QuestSpawn) { AssignResourceToMarker(targetSymbol, ref siteDetails.questSpawnMarkers[siteDetails.selectedQuestSpawnMarker]); } else if (requiredMarkerType == MarkerTypes.QuestItem) { AssignResourceToMarker(targetSymbol, ref siteDetails.questItemMarkers[siteDetails.selectedQuestItemMarker]); } else { throw new Exception(string.Format("Tried to assign resource symbol _{0}_ to Place {1} but it has an unknown MarkerType {2}", targetSymbol.Name, Symbol.Name, requiredMarkerType.ToString())); } // Output debug information if (resource is Person) { if (siteDetails.siteType == SiteTypes.Building) { if (requiredMarkerType == MarkerTypes.QuestSpawn) { Debug.LogFormat("Assigned Person {0} to Building {1}", (resource as Person).DisplayName, SiteDetails.buildingName); } } else if (siteDetails.siteType == SiteTypes.Dungeon) { if (requiredMarkerType == MarkerTypes.QuestSpawn) { Debug.LogFormat("Assigned Person {0} to Dungeon {1}", (resource as Person).DisplayName, SiteDetails.locationName); } } } else if (resource is Foe) { if (siteDetails.siteType == SiteTypes.Building) { if (requiredMarkerType == MarkerTypes.QuestSpawn) { Debug.LogFormat("Assigned Foe _{0}_ to Building {1}", resource.Symbol.Name, SiteDetails.buildingName); } } else if (siteDetails.siteType == SiteTypes.Dungeon) { if (requiredMarkerType == MarkerTypes.QuestSpawn) { Debug.LogFormat("Assigned Foe _{0}_ to Dungeon {1}", resource.Symbol.Name, SiteDetails.locationName); } } } else if (resource is Item) { if (siteDetails.siteType == SiteTypes.Building) { if (requiredMarkerType == MarkerTypes.QuestItem) { Debug.LogFormat("Assigned Item _{0}_ to Building {1}", resource.Symbol.Name, SiteDetails.buildingName); } } else if (siteDetails.siteType == SiteTypes.Dungeon) { if (requiredMarkerType == MarkerTypes.QuestItem) { Debug.LogFormat("Assigned Item _{0}_ to Dungeon {1}", resource.Symbol.Name, SiteDetails.locationName); } } } }
public void RestoreSaveData(QuestSaveData_v1 data) { // Restore base state uid = data.uid; questComplete = data.questComplete; questSuccess = data.questSuccess; questName = data.questName; displayName = data.displayName; factionId = data.factionId; questStartTime = data.questStartTime; questTombstoned = data.questTombstoned; questTombstoneTime = data.questTombstoneTime; // Restore active log messages activeLogMessages.Clear(); foreach (LogEntry logEntry in data.activeLogMessages) { activeLogMessages.Add(logEntry.stepID, logEntry); } // Restore messages messages.Clear(); foreach (Message.MessageSaveData_v1 messageData in data.messages) { Message message = new Message(this); message.RestoreSaveData(messageData); messages.Add(message.ID, message); } // Restore resources resources.Clear(); foreach (QuestResource.ResourceSaveData_v1 resourceData in data.resources) { // Construct deserialized QuestResource based on type System.Reflection.ConstructorInfo ctor = resourceData.type.GetConstructor(new Type[] { typeof(Quest) }); QuestResource resource = (QuestResource)ctor.Invoke(new object[] { this }); // Restore state resource.RestoreResourceSaveData(resourceData); resources.Add(resource.Symbol.Name, resource); } // Restore questors questors.Clear(); if (data.questors != null) { questors = data.questors; } // Restore tasks tasks.Clear(); foreach (Task.TaskSaveData_v1 taskData in data.tasks) { Task task = new Task(this); task.RestoreSaveData(taskData); tasks.Add(task.Symbol.Name, task); } // May need to remap old marker system at end of load for each Place resource QuestResource[] foundPlaces = GetAllResources(typeof(Place)); if (foundPlaces != null && foundPlaces.Length > 0) { foreach (QuestResource place in foundPlaces) { (place as Place).ReassignSiteDetailsLegacyMarkers(); } } }