예제 #1
0
        public override void Update(Task caller)
        {
            base.Update(caller);

            // Attempt to get Item resource
            Item item = ParentQuest.GetItem(itemSymbol);

            if (item == null)
            {
                SetComplete();
                throw new Exception(string.Format("Could not find Item resource symbol {0}", itemSymbol));
            }

            // Attempt to get target resource
            QuestResource target = ParentQuest.GetResource(targetSymbol);

            if (target == null)
            {
                SetComplete();
                throw new Exception(string.Format("Could not find target resource symbol {0}", targetSymbol));
            }

            // Target must exist in the world
            if (!target.QuestResourceBehaviour)
            {
                return;
            }

            // Must have an Entity to receive item
            DaggerfallEntityBehaviour entityBehaviour = target.QuestResourceBehaviour.GetComponent <DaggerfallEntityBehaviour>();

            if (!entityBehaviour)
            {
                SetComplete();
                throw new Exception(string.Format("GiveItem target {0} is not an Entity with DaggerfallEntityBehaviour", targetSymbol));
            }

            // Assign item for player to find
            //  * Some quests assign item to Foe at create time, others on injured event
            //  * It's possible for target enemy to be one-shot or to be killed by other means (such as "killall")
            //  * This assignment will direct quest loot item either to live enemy or corpse loot container
            if (entityBehaviour.CorpseLootContainer)
            {
                // If enemy is already dead then place item in corpse loot container
                entityBehaviour.CorpseLootContainer.Items.AddItem(item.DaggerfallUnityItem);
            }
            else
            {
                // Otherwise add quest Item to Entity item collection
                // It will be transferred to corpse marker loot container when dropped
                entityBehaviour.Entity.Items.AddItem(item.DaggerfallUnityItem);
            }

            SetComplete();
        }
예제 #2
0
        public override void Update(Task caller)
        {
            base.Update(caller);

            // Attempt to get Item resource
            Item item = ParentQuest.GetItem(itemSymbol);

            if (item == null)
            {
                SetComplete();
                throw new Exception(string.Format("Could not find Item resource symbol {0}", itemSymbol));
            }

            // Attempt to get target resource
            QuestResource target = ParentQuest.GetResource(targetSymbol);

            if (target == null)
            {
                SetComplete();
                throw new Exception(string.Format("Could not find target resource symbol {0}", targetSymbol));
            }

            // Add item to Foe resource or generic entity
            // In practice GiveItem will always be to a Foe resource - NPCs are handled by "get item"
            // Keeping generic GiveItem behaviour as entity catch-all and reference
            if (target is Foe)
            {
                // Add to Foe item queue
                (target as Foe).QueueItem(item.DaggerfallUnityItem);

                // Dequeue items on entity immediately if target already exists in the world
                // Will also handle placing items to dead enemy loot container
                if (target.QuestResourceBehaviour)
                {
                    DaggerfallEntityBehaviour entityBehaviour = target.QuestResourceBehaviour.GetComponent <DaggerfallEntityBehaviour>();
                    if (entityBehaviour)
                    {
                        target.QuestResourceBehaviour.AddItemQueue(target as Foe, entityBehaviour);
                    }
                }
            }
            else
            {
                // Target must exist in the world
                if (!target.QuestResourceBehaviour)
                {
                    return;
                }

                // Must have an Entity to receive item
                DaggerfallEntityBehaviour entityBehaviour = target.QuestResourceBehaviour.GetComponent <DaggerfallEntityBehaviour>();
                if (!entityBehaviour)
                {
                    SetComplete();
                    throw new Exception(string.Format("GiveItem target {0} is not an Entity with DaggerfallEntityBehaviour", targetSymbol));
                }

                // Assign item for player to find
                //  * Some quests assign item to Foe at create time, others on injured event
                //  * It's possible for target enemy to be one-shot or to be killed by other means (such as "killall")
                //  * This assignment will direct quest loot item either to live enemy or corpse loot container
                if (entityBehaviour.CorpseLootContainer)
                {
                    // If enemy is already dead then place item in corpse loot container
                    entityBehaviour.CorpseLootContainer.Items.AddItem(item.DaggerfallUnityItem);
                }
                else
                {
                    // Otherwise add quest Item to Entity item collection
                    // It will be transferred to corpse marker loot container when dropped
                    entityBehaviour.Entity.Items.AddItem(item.DaggerfallUnityItem);
                }
            }

            // Remove item from player inventory if they are holding it
            if (GameManager.Instance.PlayerEntity.Items.Contains(item.DaggerfallUnityItem))
            {
                GameManager.Instance.PlayerEntity.Items.RemoveItem(item.DaggerfallUnityItem);
            }

            SetComplete();
        }
예제 #3
0
        /// <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);
                    }
                }
            }
        }