Example #1
0
            public override string Direction()
            {
                Place questLastPlaceReferenced = parent.LastPlaceReferenced;

                if (questLastPlaceReferenced.Scope == Place.Scopes.Remote)
                {
                    if (questLastPlaceReferenced == null)
                    {
                        QuestMachine.Log(parent, "Trying to get direction to quest location when no location has been referenced in the quest.");
                        return(TextManager.Instance.GetText("ConversationText", "resolvingError"));
                    }

                    return(GameManager.Instance.TalkManager.GetLocationCompassDirection(questLastPlaceReferenced));
                }
                else if (questLastPlaceReferenced.Scope == Place.Scopes.Local)
                {
                    if (questLastPlaceReferenced.SiteDetails.locationName == GameManager.Instance.PlayerGPS.CurrentLocation.Name)
                    {
                        return(GameManager.Instance.TalkManager.GetBuildingCompassDirection(questLastPlaceReferenced.SiteDetails.buildingKey));
                    }
                    else
                    {
                        string result = questLastPlaceReferenced.SiteDetails.locationName;
                        result += TextManager.Instance.GetText(TalkManager.TextDatabase, "comma");
                        result += GameManager.Instance.TalkManager.GetLocationCompassDirection(questLastPlaceReferenced);
                        return(result);
                    }
                }

                return(TextManager.Instance.GetText(TalkManager.TextDatabase, "resolvingError"));
            }
Example #2
0
        public override void Tick(Quest caller)
        {
            base.Tick(caller);

            // Auto-assign NPC to home Place if available and player enters
            // This only happens for very specific NPC types
            // Equivalent to calling "place anNPC at aPlace" from script
            // Will not be called again as assignment is permanent for duration of quest
            if (homePlaceSymbol != null && !assignedToHome)
            {
                Place home = ParentQuest.GetPlace(homePlaceSymbol);
                if (home == null)
                {
                    return;
                }

                if (home.IsPlayerHere())
                {
                    // Create SiteLink if not already present
                    if (!QuestMachine.HasSiteLink(ParentQuest, homePlaceSymbol))
                    {
                        QuestMachine.CreateSiteLink(ParentQuest, homePlaceSymbol);
                    }

                    // Hot-place NPC at this location
                    home.AssignQuestResource(Symbol);
                    assignedToHome = true;
                }
            }
        }
        public override IQuestAction CreateNew(string source, Quest parentQuest)
        {
            // Source must match pattern
            Match match = Test(source);

            if (!match.Success)
            {
                return(null);
            }

            // Factory new action
            CastSpellOnFoe action          = new CastSpellOnFoe(parentQuest);
            string         sourceSpellName = match.Groups["aSpell"].Value;

            action.spell.CustomKey = match.Groups["aCustomSpell"].Value;
            action.foeSymbol       = new Symbol(match.Groups["aFoe"].Value);

            // Get classic spell ID
            if (string.IsNullOrEmpty(action.spell.CustomKey))
            {
                Table spellsTable = QuestMachine.Instance.SpellsTable;
                if (spellsTable.HasValue(sourceSpellName))
                {
                    action.spell.ClassicID = int.Parse(spellsTable.GetValue("id", sourceSpellName));
                }
                else
                {
                    QuestMachine.LogFormat("CastSpellOnFoe could not resolve classic spell '{0}' in Quests-Spells data table", sourceSpellName);
                    SetComplete();
                }
            }

            return(action);
        }
        /// <summary>
        /// Check if player click has been triggered.
        /// </summary>
        public void SetPlayerClicked()
        {
            if (this is Person && ((this as Person).IsMuted || (this as Person).IsDestroyed))
            {
                QuestMachine.LogFormat("Ignoring click on muted or destroyed Person {0}.", Symbol.Original);
                return;
            }

            hasPlayerClicked = true;
        }
Example #5
0
        // Create by item class and subclass
        DaggerfallUnityItem CreateItem(int itemClass, int itemSubClass, int itemKey = -1)
        {
            // Validate
            if (itemClass == -1)
            {
                throw new Exception(string.Format("Tried to create Item with class {0}", itemClass));
            }

            DaggerfallUnityItem result;

            // Handle random magic items
            if (itemClass == (int)ItemGroups.MagicItems)
            {
                Entity.PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;
                result = ItemBuilder.CreateRegularMagicItem(itemSubClass, playerEntity.Level, playerEntity.Gender, playerEntity.Race);
            }
            // Handle books
            else if (itemClass == (int)ItemGroups.Books)
            {
                result = (itemKey != -1) ? ItemBuilder.CreateBook(itemKey) : ItemBuilder.CreateRandomBook();
            }
            // Handle potions
            else if (itemClass == (int)ItemGroups.UselessItems1 && itemSubClass == 1)
            {
                result = (itemKey != -1) ? ItemBuilder.CreatePotion(itemKey) : ItemBuilder.CreateRandomPotion();
            }
            else
            {
                // Handle random subclass
                if (itemSubClass == -1)
                {
                    Array enumArray = DaggerfallUnity.Instance.ItemHelper.GetEnumArray((ItemGroups)itemClass);
                    itemSubClass = UnityEngine.Random.Range(0, enumArray.Length);
                }

                // Create item
                result = new DaggerfallUnityItem((ItemGroups)itemClass, itemSubClass);
            }

            // Link item to quest
            result.LinkQuestItem(ParentQuest.UID, Symbol.Clone());

            string name = result.shortName.Replace("%it", result.ItemTemplate.name);

            QuestMachine.LogFormat(
                ParentQuest,
                "Generated \"{0}\" from Class {1} and Subclass {2} for item {3}",
                name,
                itemClass,
                itemSubClass,
                Symbol.Original
                );

            return(result);
        }
Example #6
0
        public static bool FindQuestMachine(out QuestMachine questMachineOut)
        {
            questMachineOut = GameObject.FindObjectOfType(typeof(QuestMachine)) as QuestMachine;
            if (questMachineOut == null)
            {
                DaggerfallUnity.LogMessage("Could not locate QuestMachine GameObject instance in scene!", true);
                return(false);
            }

            return(true);
        }
        public static bool FindQuestMachine(out QuestMachine questMachineOut)
        {
            questMachineOut = GameObject.FindObjectOfType(typeof(QuestMachine)) as QuestMachine;
            if (questMachineOut == null)
            {
                DaggerfallUnity.LogMessage("Could not locate QuestMachine GameObject instance in scene!", true);
                return false;
            }

            return true;
        }
Example #8
0
 void LogHomePlace(Place homePlace)
 {
     QuestMachine.LogFormat(
         ParentQuest,
         "Generated Home for Person {0} [{1}] at '{2}/{3}' in building '{4}'",
         Symbol.Original,
         DisplayName,
         HomeRegionName,
         HomeTownName,
         HomeBuildingName);
 }
 private void SetupSingleton()
 {
     if (instance == null)
         instance = this;
     else if (instance != this)
     {
         if (Application.isPlaying)
         {
             DaggerfallUnity.LogMessage("Multiple QuestMachine instances detected in scene!", true);
             Destroy(gameObject);
         }
     }
 }
Example #10
0
        public override IQuestAction CreateNew(string source, Quest parentQuest)
        {
            // Source must match pattern
            Match match = Test(source);

            if (!match.Success)
            {
                return(null);
            }

            // Factory new action
            CastSpellDo action          = new CastSpellDo(parentQuest);
            string      sourceSpellName = match.Groups["aSpell"].Value;

            action.taskSymbol = new Symbol(match.Groups["aTask"].Value);

            // Cache classic effects to match
            Table spellsTable = QuestMachine.Instance.SpellsTable;

            if (spellsTable.HasValue(sourceSpellName))
            {
                action.spellID = int.Parse(spellsTable.GetValue("id", sourceSpellName));
                SpellRecord.SpellRecordData spellRecord;
                if (GameManager.Instance.EntityEffectBroker.GetClassicSpellRecord(action.spellID, out spellRecord))
                {
                    action.classicEffects = spellRecord.effects;
                }
                else
                {
                    QuestMachine.LogFormat("CastSpellDo could not find spell matching spellID '{0}' from spell '{1}'", spellID, sourceSpellName);
                    SetComplete();
                }
            }
            else
            {
                QuestMachine.LogFormat("CastSpellDo could not resolve spell '{0}' in Quests-Spells data table", sourceSpellName);
                SetComplete();
            }

            return(action);
        }
Example #11
0
        /// <summary>
        /// Places NPC to home. This can happen automatically when player enters building or when
        /// quest script uses "create npc" action to automatically assign Person to home.
        /// </summary>
        public bool PlaceAtHome()
        {
            // Does not attempt to place a questor as they should be statically place or moved manually
            Place homePlace = ParentQuest.GetPlace(homePlaceSymbol);

            if (homePlace == null || isQuestor)
            {
                return(false);
            }

            // Create SiteLink if not already present
            if (!QuestMachine.HasSiteLink(ParentQuest, homePlaceSymbol))
            {
                QuestMachine.CreateSiteLink(ParentQuest, homePlaceSymbol);
            }

            // Assign to home place
            homePlace.AssignQuestResource(Symbol);
            SetAssignedPlaceSymbol(homePlace.Symbol);
            assignedToHome = true;

            return(true);
        }
Example #12
0
        /// <summary>
        /// Places NPC to home. This can happen automatically when player enters building or when
        /// quest script uses "create npc" action to automatically assign Person to home.
        /// </summary>
        public bool PlaceAtHome()
        {
            // Does not attempt to place a questor as they should be statically placed or moved manually
            // Individual NPCs are also excluded as they are either automatically at home or moved elsewhere by quest
            Place homePlace = ParentQuest.GetPlace(homePlaceSymbol);

            if (homePlace == null || isQuestor || isIndividualNPC)
            {
                return(false);
            }

            // Create SiteLink if not already present
            if (!QuestMachine.HasSiteLink(ParentQuest, homePlaceSymbol))
            {
                QuestMachine.CreateSiteLink(ParentQuest, homePlaceSymbol);
            }

            // Assign to home place
            homePlace.AssignQuestResource(Symbol);
            SetAssignedPlaceSymbol(homePlace.Symbol);
            assignedToHome = true;

            return(true);
        }
Example #13
0
        public override void Update(Task caller)
        {
            base.Update(caller);

            // Do nothing while player respawning
            if (GameManager.Instance.PlayerEnterExit.IsRespawning)
            {
                return;
            }

            // Handle resume on next tick of action after respawn process complete
            if (resumePending)
            {
                GameObject player = GameManager.Instance.PlayerObject;
                player.transform.position = resumePosition;
                resumePending             = false;
                SetComplete();
                return;
            }

            // Create SiteLink if not already present
            if (!QuestMachine.HasSiteLink(ParentQuest, targetPlace))
            {
                QuestMachine.CreateSiteLink(ParentQuest, targetPlace);
            }

            // Attempt to get Place resource
            Place place = ParentQuest.GetPlace(targetPlace);

            if (place == null)
            {
                return;
            }

            // Get selected spawn QuestMarker for this Place
            bool        usingMarker = false;
            QuestMarker marker      = new QuestMarker();

            if (targetMarker >= 0 && targetMarker < place.SiteDetails.questSpawnMarkers.Length)
            {
                marker      = place.SiteDetails.questSpawnMarkers[targetMarker];
                usingMarker = true;
            }

            // Attempt to get location data - using GetLocation(regionName, locationName) as it can support all locations
            DFLocation location;

            if (!DaggerfallUnity.Instance.ContentReader.GetLocation(place.SiteDetails.regionName, place.SiteDetails.locationName, out location))
            {
                return;
            }

            // Spawn inside dungeon at this world position
            DFPosition mapPixel = MapsFile.LongitudeLatitudeToMapPixel((int)location.MapTableData.Longitude, location.MapTableData.Latitude);
            DFPosition worldPos = MapsFile.MapPixelToWorldCoord(mapPixel.X, mapPixel.Y);

            GameManager.Instance.PlayerEnterExit.RespawnPlayer(
                worldPos.X,
                worldPos.Y,
                true,
                true);

            // Determine start position
            if (usingMarker)
            {
                // Use specified quest marker
                Vector3 dungeonBlockPosition = new Vector3(marker.dungeonX * RDBLayout.RDBSide, 0, marker.dungeonZ * RDBLayout.RDBSide);
                resumePosition = dungeonBlockPosition + marker.flatPosition;
            }
            else
            {
                // Use first quest marker
                marker = place.SiteDetails.questSpawnMarkers[0];
                Vector3 dungeonBlockPosition = new Vector3(marker.dungeonX * RDBLayout.RDBSide, 0, marker.dungeonZ * RDBLayout.RDBSide);
                resumePosition = dungeonBlockPosition + marker.flatPosition;
            }

            resumePending = true;
        }
 private void SetupSingleton()
 {
     if (instance == null)
         instance = this;
     else if (instance != this)
     {
         if (Application.isPlaying)
         {
             DaggerfallUnity.LogMessage("Multiple QuestMachine instances detected in scene!", true);
             Destroy(gameObject);
         }
     }
 }
Example #15
0
            public override string LocationDirection()
            {
                Vector2 positionPlayer;
                Vector2 positionLocation = Vector2.zero;

                Place questLastPlaceReferenced = parent.LastPlaceReferenced;

                if (questLastPlaceReferenced == null)
                {
                    QuestMachine.Log(parent, "Trying to get direction to quest location when no location has been referenced in the quest.");
                    return(TextManager.Instance.GetText("ConversationText", "resolvingError"));
                }

                DFPosition position  = new DFPosition();
                PlayerGPS  playerGPS = GameManager.Instance.PlayerGPS;

                if (playerGPS)
                {
                    position = playerGPS.CurrentMapPixel;
                }

                positionPlayer = new Vector2(position.X, position.Y);

                int region = DaggerfallUnity.Instance.ContentReader.MapFileReader.GetPoliticIndex(position.X, position.Y) - 128;

                if (region < 0 || region >= DaggerfallUnity.Instance.ContentReader.MapFileReader.RegionCount)
                {
                    region = -1;
                }

                DFRegion.RegionMapTable locationInfo = new DFRegion.RegionMapTable();

                DFRegion currentDFRegion = DaggerfallUnity.Instance.ContentReader.MapFileReader.GetRegion(region);

                string name = questLastPlaceReferenced.SiteDetails.locationName.ToLower();

                string[] locations = currentDFRegion.MapNames;
                for (int i = 0; i < locations.Length; i++)
                {
                    if (locations[i].ToLower() == name) // Valid location found with exact name
                    {
                        if (currentDFRegion.MapNameLookup.ContainsKey(locations[i]))
                        {
                            int index = currentDFRegion.MapNameLookup[locations[i]];
                            locationInfo     = currentDFRegion.MapTable[index];
                            position         = MapsFile.LongitudeLatitudeToMapPixel((int)locationInfo.Longitude, (int)locationInfo.Latitude);
                            positionLocation = new Vector2(position.X, position.Y);
                        }
                    }
                }

                if (positionLocation != Vector2.zero)
                {
                    Vector2 vecDirectionToTarget = positionLocation - positionPlayer;
                    vecDirectionToTarget.y = -vecDirectionToTarget.y; // invert y axis
                    return(GameManager.Instance.TalkManager.DirectionVector2DirectionHintString(vecDirectionToTarget));
                }
                else
                {
                    return("... never mind ...");
                }
            }