Пример #1
0
        /// <summary>
        /// Helper to get location rect in world coordinates.
        /// </summary>
        /// <param name="location">Target location.</param>
        /// <returns>Location rect in world space. xMin,yMin is SW corner. xMax,yMax is NE corner.</returns>
        public static Rect GetLocationRect(DFLocation location)
        {
            // This finds the absolute SW origin of map pixel in world coords
            DFPosition mapPixel    = MapsFile.LongitudeLatitudeToMapPixel(location.MapTableData.Longitude, location.MapTableData.Latitude);
            DFPosition worldOrigin = MapsFile.MapPixelToWorldCoord(mapPixel.X, mapPixel.Y);

            // Find tile offset point using same logic as terrain helper
            DFPosition tileOrigin = TerrainHelper.GetLocationTerrainTileOrigin(location);

            // Adjust world origin by tileorigin*2 in world units
            worldOrigin.X += (tileOrigin.X * 2) * MapsFile.WorldMapTileDim;
            worldOrigin.Y += (tileOrigin.Y * 2) * MapsFile.WorldMapTileDim;

            // Get width and height of location in world units
            int width  = location.Exterior.ExteriorData.Width * MapsFile.WorldMapRMBDim;
            int height = location.Exterior.ExteriorData.Height * MapsFile.WorldMapRMBDim;

            // Create location rect in world coordinates
            Rect locationRect = new Rect()
            {
                xMin = worldOrigin.X,
                xMax = worldOrigin.X + width,
                yMin = worldOrigin.Y,
                yMax = worldOrigin.Y + height,
            };

            return(locationRect);
        }
Пример #2
0
        // Teleport player to any location by name
        IEnumerator TeleportLocation(string regionName, string locationName)
        {
            if (!CanTeleport())
            {
                yield break;
            }

            DFLocation location = dfUnity.ContentReader.MapFileReader.GetLocation(regionName, locationName);

            if (!location.Loaded)
            {
                yield break;
            }

            //if (titleScreen)
            //    titleScreen.ShowTitle = true;
            yield return(new WaitForEndOfFrame());

            // Check inside range
            DFPosition mapPos = MapsFile.LongitudeLatitudeToMapPixel((int)location.MapTableData.Longitude, (int)location.MapTableData.Latitude);

            if (mapPos.X >= TerrainHelper.minMapPixelX || mapPos.X < TerrainHelper.maxMapPixelX ||
                mapPos.Y >= TerrainHelper.minMapPixelY || mapPos.Y < TerrainHelper.maxMapPixelY)
            {
                streamingWorld.TeleportToCoordinates(mapPos.X, mapPos.Y, StreamingWorld.RepositionMethods.RandomStartMarker);
            }
        }
Пример #3
0
        public void SetLocation(DFLocation location, bool performLayout = true)
        {
            if (!ReadyCheck())
            {
                return;
            }

            // Validate
            if (this.isSet)
            {
                throw new Exception("This location has already been set.");
            }
            if (!location.Loaded)
            {
                throw new Exception("DFLocation not loaded.");
            }

            // Set summary
            summary           = new LocationSummary();
            summary.MapID     = location.MapTableData.MapId;
            summary.Longitude = (int)location.MapTableData.Longitude;
            summary.Latitude  = (int)location.MapTableData.Latitude;
            DFPosition mapPixel   = MapsFile.LongitudeLatitudeToMapPixel(summary.Longitude, summary.Latitude);
            DFPosition worldCoord = MapsFile.MapPixelToWorldCoord(mapPixel.X, mapPixel.Y);

            summary.MapPixelX      = mapPixel.X;
            summary.MapPixelY      = mapPixel.Y;
            summary.WorldCoordX    = worldCoord.X;
            summary.WorldCoordZ    = worldCoord.Y;
            summary.RegionName     = location.RegionName;
            summary.LocationName   = location.Name;
            summary.WorldClimate   = (MapsFile.Climates)location.Climate.WorldClimate;
            summary.LocationType   = location.MapTableData.LocationType;
            summary.DungeonType    = location.MapTableData.DungeonType;
            summary.HasDungeon     = location.HasDungeon;
            summary.Climate        = ClimateSwaps.FromAPIClimateBase(location.Climate.ClimateType);
            summary.Nature         = ClimateSwaps.FromAPITextureSet(location.Climate.NatureSet);
            summary.SkyBase        = location.Climate.SkyBase;
            summary.BlockWidth     = location.Exterior.ExteriorData.Width;
            summary.BlockHeight    = location.Exterior.ExteriorData.Height;
            summary.LegacyLocation = location;

            // Assign starting climate
            CurrentSeason    = ClimateSeason.Summer;
            CurrentClimate   = summary.Climate;
            CurrentNatureSet = summary.Nature;

            // Perform layout
            if (performLayout)
            {
                LayoutLocation(ref location);
                ApplyClimateSettings();
            }

            // Set location rect
            SetLocationRect();

            // Seal location
            isSet = true;
        }
Пример #4
0
            public static string Execute(params string[] args)
            {
                if (args == null || args.Count() < 1)
                {
                    return(string.Format("Invalid paramaters; \n {0}", usage));
                }

                DaggerfallConnect.DFLocation loc;

                string name = args[0];

                for (int i = 1; i < args.Count(); i++)
                {
                    name += " " + args[i];
                }


                if (DaggerfallWorkshop.Utility.GameObjectHelper.FindMultiNameLocation(name, out loc))
                {
                    DaggerfallConnect.Utility.DFPosition pos = MapsFile.LongitudeLatitudeToMapPixel((int)loc.MapTableData.Longitude, (int)loc.MapTableData.Latitude);
                    return(string.Format("{0} found; Pixel Coordinates: \nx: {1} y: {2}", name, pos.X, pos.Y));
                }
                else
                {
                    return("Invalid location.  Check spelling?");
                }
            }
Пример #5
0
            public override string LocationDirection()
            {
                Vector2 positionPlayer;
                Vector2 positionLocation = Vector2.zero;

                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 = this.parent.LastPlaceReferenced.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 ...");
                }
            }
        private void DeployFullBlownVampirism()
        {
            const int deathIsNotEternalTextID = 401;

            // Cancel rest window if sleeping
            if (DaggerfallUI.Instance.UserInterfaceManager.TopWindow is DaggerfallRestWindow)
            {
                (DaggerfallUI.Instance.UserInterfaceManager.TopWindow as DaggerfallRestWindow).CloseWindow();
            }

            // Halt random enemy spawns for next playerEntity update so player isn't bombarded by spawned enemies after transform time
            GameManager.Instance.PlayerEntity.PreventEnemySpawns = true;

            // Reset legal reputation for all regions and strip player of guild memberships
            ResetLegalRepAndGuildMembership();

            // Raise game time to an evening two weeks later
            float raiseTime = (2 * DaggerfallDateTime.SecondsPerWeek) + (DaggerfallDateTime.DuskHour + 1 - DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.Hour) * 3600;

            DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.RaiseTime(raiseTime);

            // Transfer player to a random cemetery
            // Always using a small cemetery, nothing spoils that first vampire moment like being lost the guts of a massive dungeon
            // Intentionally not spawning enemies, for this time the PLAYER is the monster lurking inside the crypt
            DFLocation location = GetRandomCemetery();
            DFPosition mapPixel = MapsFile.LongitudeLatitudeToMapPixel(location.MapTableData.Longitude, location.MapTableData.Latitude);
            DFPosition worldPos = MapsFile.MapPixelToWorldCoord(mapPixel.X, mapPixel.Y);

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

            // Assign vampire spells to spellbook
            GameManager.Instance.PlayerEntity.AssignPlayerVampireSpells(InfectionVampireClan);

            // Fade in from black
            DaggerfallUI.Instance.FadeBehaviour.FadeHUDFromBlack(1.0f);

            // Start permanent vampirism effect stage two
            EntityEffectBundle bundle = GameManager.Instance.PlayerEffectManager.CreateVampirismCurse();

            GameManager.Instance.PlayerEffectManager.AssignBundle(bundle, AssignBundleFlags.BypassSavingThrows);

            // Display popup
            DaggerfallMessageBox mb = DaggerfallUI.MessageBox(deathIsNotEternalTextID);

            mb.Show();

            // Terminate custom disease lifecycle
            EndDisease();
        }
        // Teleports player to a random location in a random region
        IEnumerator TeleportRandomLocation()
        {
            if (!CanTeleport())
            {
                yield break;
            }

            // Find a random location
            UnityEngine.Random.seed = UnityEngine.Time.renderedFrameCount;
            DFPosition mapPos = new DFPosition();
            bool       found  = false;

            while (!found)
            {
                // Get random region
                int      regionIndex = UnityEngine.Random.Range(0, dfUnity.ContentReader.MapFileReader.RegionCount);
                DFRegion region      = dfUnity.ContentReader.MapFileReader.GetRegion(regionIndex);
                if (region.LocationCount == 0)
                {
                    continue;
                }

                // Get random location
                int        locationIndex = UnityEngine.Random.Range(0, region.MapTable.Length);
                DFLocation location      = dfUnity.ContentReader.MapFileReader.GetLocation(regionIndex, locationIndex);
                if (!location.Loaded)
                {
                    continue;
                }

                // Check inside range
                mapPos = MapsFile.LongitudeLatitudeToMapPixel((int)location.MapTableData.Longitude, (int)location.MapTableData.Latitude);
                if ((mapPos.X >= TerrainHelper.minMapPixelX + 2 && mapPos.X < TerrainHelper.maxMapPixelX - 2) &&
                    (mapPos.Y >= TerrainHelper.minMapPixelY + 2 && mapPos.Y < TerrainHelper.maxMapPixelY - 2))
                {
                    found = true;
                }
            }

            // Teleport
            if (titleScreen)
            {
                titleScreen.ShowTitle = true;
            }
            yield return(new WaitForEndOfFrame());

            streamingWorld.TeleportToCoordinates(mapPos.X, mapPos.Y);
        }
Пример #8
0
        public void __EditorFindLocation()
        {
            DFLocation location;

            if (!GameObjectHelper.FindMultiNameLocation(EditorFindLocationString, out location))
            {
                DaggerfallUnity.LogMessage(string.Format("Could not find location [Region={0}, Name={1}]", location.RegionName, location.Name), true);
                return;
            }

            int        longitude = (int)location.MapTableData.Longitude;
            int        latitude  = (int)location.MapTableData.Latitude;
            DFPosition pos       = MapsFile.LongitudeLatitudeToMapPixel(longitude, latitude);

            MapPixelX = pos.X;
            MapPixelY = pos.Y;
        }
Пример #9
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;
        }
Пример #10
0
        bool parseCommand(string[] args)
        {
            bool   handled = false;
            Logger l       = Logger.GetInstance();

            switch (args[0])
            {
            case (SPAWN_ENEMY_CMD):
                if (args.Length == 2)
                {
                    int mobileType = System.Convert.ToInt32(args[1]);
                    if (mobileType > -1 && mobileType < 147)
                    {
                        l.log("Spawning enemy of type " + (MobileTypes)mobileType + ".\n");
                        GameObject.FindGameObjectWithTag("EnemySpawner").SendMessage("SpawnEnemy", mobileType);
                        handled = true;
                    }
                }
                break;

            case (TRAVEL_CMD):
                if (args.Length >= 2)
                {
                    DFLocation location;
                    string     nameWithPossibleSpaces = string.Join(" ", args);
                    nameWithPossibleSpaces = nameWithPossibleSpaces.Substring(TRAVEL_CMD.Length + 1);
                    if (!GameObjectHelper.FindMultiNameLocation(nameWithPossibleSpaces, out location))
                    {
                        l.log("Unable to find location " + nameWithPossibleSpaces + ".\n");
                    }
                    else
                    {
                        l.log("Found location in " + location.RegionName + "!\n");
                        DFPosition mapPos = MapsFile.LongitudeLatitudeToMapPixel((int)location.MapTableData.Longitude, (int)location.MapTableData.Latitude);
                        if (mapPos.X >= TerrainHelper.minMapPixelX || mapPos.X < TerrainHelper.maxMapPixelX ||
                            mapPos.Y >= TerrainHelper.minMapPixelY || mapPos.Y < TerrainHelper.maxMapPixelY)
                        {
                            streamingWorldOwner.TeleportToCoordinates(mapPos.X, mapPos.Y);
                        }
                        else
                        {
                            l.log("Requested location is out of bounds!\n");
                        }
                    }
                }
                break;

            case (SNOW_COMMAND):
                if (weatherManager.IsSnowing)
                {
                    weatherManager.StopSnowing();
                }
                else
                {
                    weatherManager.StartSnowing();
                }
                break;

            case (XML_DEBUG):
                QuestManager.Instance.doDebugQuest();
                break;

            case (QUEST_DEBUG):
                l.log("Dumping all quests:");
                QuestManager.Instance.dumpAllQuests();
                break;

            case (TIME_DEBUG):
                l.log("The time is: " + dfUnity.WorldTime.Now.LongDateTimeString());
                ulong timeInSeconds = dfUnity.WorldTime.Now.ToSeconds();
                l.log("The time in seconds is: " + timeInSeconds.ToString());
                timeInSeconds -= 60 * 60 * 24;
                l.log("Setting the time 1 day in the past: " + timeInSeconds.ToString());
                dfUnity.WorldTime.Now.FromSeconds(timeInSeconds);
                l.log("The time is now: " + dfUnity.WorldTime.Now.LongDateTimeString());
                l.log("The time in seconds is now: " + dfUnity.WorldTime.Now.ToSeconds().ToString());

                break;

            case (DISPLAY_SCROLL):
                if (args.Length == 2)
                {
                    scrollManager.displayScroll(args[1]);
                }
                break;

            default:
                break;
            }


            return(handled);
        }