public static Rect GetLocationRect(ContentReader.MapSummary mapSummary)
        {
            DFLocation targetLocation;

            if (!DaggerfallUnity.Instance.ContentReader.GetLocation(
                    mapSummary.RegionIndex, mapSummary.MapIndex, out targetLocation))
            {
                throw new ArgumentException("TediousTravel destination not found!");
            }
            return(DaggerfallLocation.GetLocationRect(targetLocation));
        }
        static Rect GetLocationRect(DFLocation currentLocation)
        {
            var locationRect = DaggerfallLocation.GetLocationRect(currentLocation);

            var min = WorldCoordToTerrainPosition(locationRect.min);
            var max = WorldCoordToTerrainPosition(locationRect.max);

            return(new Rect()
            {
                xMin = min.x,
                yMin = min.y,
                xMax = max.x,
                yMax = max.y
            });
        }
Beispiel #3
0
        private void Start()
        {
            // Cache references
            playerGPS      = GameManager.Instance.PlayerGPS;
            dfLocation     = GetComponent <DaggerfallLocation>();
            cityNavigation = GetComponent <CityNavigation>();

            // Get dominant race in locations climate zone
            populationRace = playerGPS.ClimateSettings.People;

            // Calculate maximum population
            int totalBlocks      = dfLocation.Summary.BlockWidth * dfLocation.Summary.BlockHeight;
            int populationBlocks = Mathf.Clamp(totalBlocks / 16, 1, 4);

            maxPopulation = populationBlocks * populationIndexPer16Blocks;
        }
        void Start()
        {
            Material shopMaterial       = new Material(Minimap.buildingMarkerMaterial);
            Material blacksmithMaterial = new Material(Minimap.buildingMarkerMaterial);
            Material housesMaterial     = new Material(Minimap.buildingMarkerMaterial);
            Material tavernsMaterial    = new Material(Minimap.buildingMarkerMaterial);
            Material utilitiesMaterial  = new Material(Minimap.buildingMarkerMaterial);
            Material governmentMaterial = new Material(Minimap.buildingMarkerMaterial);
            Material noMaterial         = new Material(Minimap.buildingMarkerMaterial);

            buildingMaterialDict = new Dictionary <Minimap.MarkerGroups, Material>()
            {
                { Minimap.MarkerGroups.Shops, shopMaterial },
                { Minimap.MarkerGroups.Blacksmiths, blacksmithMaterial },
                { Minimap.MarkerGroups.Houses, housesMaterial },
                { Minimap.MarkerGroups.Taverns, tavernsMaterial },
                { Minimap.MarkerGroups.Utilities, utilitiesMaterial },
                { Minimap.MarkerGroups.Government, governmentMaterial },
                { Minimap.MarkerGroups.None, noMaterial }
            };

            Material shopIconMaterial       = new Material(Minimap.iconMarkerMaterial);
            Material blacksmithIconMaterial = new Material(Minimap.iconMarkerMaterial);
            Material housesIconMaterial     = new Material(Minimap.iconMarkerMaterial);
            Material tavernsIconMaterial    = new Material(Minimap.iconMarkerMaterial);
            Material utilitiesIconMaterial  = new Material(Minimap.iconMarkerMaterial);
            Material governmentIconMaterial = new Material(Minimap.iconMarkerMaterial);
            Material noIconMaterial         = new Material(Minimap.iconMarkerMaterial);

            iconMaterialDict = new Dictionary <Minimap.MarkerGroups, Material>()
            {
                { Minimap.MarkerGroups.Shops, shopIconMaterial },
                { Minimap.MarkerGroups.Blacksmiths, blacksmithIconMaterial },
                { Minimap.MarkerGroups.Houses, housesIconMaterial },
                { Minimap.MarkerGroups.Taverns, tavernsIconMaterial },
                { Minimap.MarkerGroups.Utilities, utilitiesIconMaterial },
                { Minimap.MarkerGroups.Government, governmentIconMaterial },
                { Minimap.MarkerGroups.None, noIconMaterial }
            };

            currentCity     = GameManager.Instance.StreamingWorld.CurrentPlayerLocationObject;
            currentLocation = "Starting Game";
        }
Beispiel #5
0
        public static GameObject CreateDaggerfallLocationGameObject(string multiName, Transform parent)
        {
            // Get city
            DFLocation location;

            if (!FindMultiNameLocation(multiName, out location))
            {
                return(null);
            }

            GameObject go = new GameObject(string.Format("DaggerfallLocation [Region={0}, Name={1}]", location.RegionName, location.Name));

            if (parent)
            {
                go.transform.parent = parent;
            }
            DaggerfallLocation c = go.AddComponent <DaggerfallLocation>() as DaggerfallLocation;

            c.SetLocation(location);

            return(go);
        }
 // Place foe somewhere near player when outside a location navgrid is available
 // Navgrid placement helps foe avoid getting tangled in geometry like buildings
 void PlaceFoeExteriorLocation(GameObject[] gameObjects, DaggerfallLocation locationParent)
 {
     PlaceFoeFreely(gameObjects, locationParent.transform);
 }
        private void Update()
        {
            // Do nothing if game paused
            if (GameManager.IsGamePaused)
            {
                return;
            }

            // Do nothing if paralyzed
            if (entityBehaviour.Entity.IsParalyzed)
            {
                mobileBillboard.IsIdle = false;
                return;
            }

            // Must have a navgrid assigned
            if (!cityNavigation)
            {
                // Try to get navgrid from current player location
                // This is for mobiles dropped directly into world from editor
                // May be removed once fully runtime as intended
                if (!triedPlayerLocation)
                {
                    DaggerfallLocation playerLocation = GameManager.Instance.StreamingWorld.CurrentPlayerLocationObject;
                    if (playerLocation)
                    {
                        cityNavigation   = playerLocation.GetComponent <CityNavigation>();
                        transform.parent = playerLocation.transform;
                        ChangeState(MobileStates.SeekingTile);
                    }
                    triedPlayerLocation = true;
                }

                return;
            }

            // Go idle if near player
            distanceToPlayer = GameManager.Instance.PlayerMotor.DistanceToPlayer(transform.position);
            bool playerStandingStill = GameManager.Instance.PlayerMotor.IsStandingStill;

            if (!playerStandingStill && mobileBillboard.IsIdle)
            {
                // Switch animation state back to moving
                mobileBillboard.IsIdle = false;
                currentMobileState     = MobileStates.MovingForward;
            }
            else if (playerStandingStill && !mobileBillboard.IsIdle && distanceToPlayer < idleDistance)
            {
                // Switch animation state to idle
                mobileBillboard.IsIdle = true;
                currentMobileState     = MobileStates.Idle;
            }

            // Update based on current state
            switch (currentMobileState)
            {
            case MobileStates.SeekingTile:
                SeekingTile();
                break;

            case MobileStates.MovingForward:
                MovingForward();
                break;

            case MobileStates.Idle:
                // Do nothing for now
                break;
            }
        }
Beispiel #8
0
 private void Start()
 {
     dfLocation = GetComponent <DaggerfallLocation>();
 }
Beispiel #9
0
        private void Update()
        {
            // Do nothing if game paused
            if (GameManager.IsGamePaused)
            {
                return;
            }

            // Do nothing if paralyzed
            if (entityBehaviour.Entity.IsParalyzed)
            {
                mobileBillboard.IsIdle = false;
                return;
            }

            // Must have a navgrid assigned
            if (!cityNavigation)
            {
                // Try to get navgrid from current player location
                // This is for mobiles dropped directly into world from editor
                // May be removed once fully runtime as intended
                if (!triedPlayerLocation)
                {
                    DaggerfallLocation playerLocation = GameManager.Instance.StreamingWorld.CurrentPlayerLocationObject;
                    if (playerLocation)
                    {
                        cityNavigation   = playerLocation.GetComponent <CityNavigation>();
                        transform.parent = playerLocation.transform;
                        ChangeState(MobileStates.SeekingTile);
                    }
                    triedPlayerLocation = true;
                }

                return;
            }

            // Go idle if near player
            distanceToPlayer = GameManager.Instance.PlayerMotor.DistanceToPlayer(transform.position);
            bool withinIdleDistance  = (distanceToPlayer < idleDistance);
            bool playerStandingStill = GameManager.Instance.PlayerMotor.IsStandingStill;
            bool sheathed            = GameManager.Instance.WeaponManager.Sheathed;
            bool invisible           = GameManager.Instance.PlayerEntity.IsInvisible;
            bool inBeastForm         = GameManager.Instance.PlayerEntity.IsInBeastForm;

            bool wantsToStop = playerStandingStill && withinIdleDistance && sheathed && !invisible && !inBeastForm;

            // greatly reduce # of calls to AreEnemiesNearby() by short-circuit evaluation
            if (wantsToStop && !GameManager.Instance.AreEnemiesNearby())
            {
                wantsToStop = true;
            }
            else
            {
                wantsToStop = false;
            }

            if (!wantsToStop && mobileBillboard.IsIdle)
            {
                // Switch animation state back to moving
                mobileBillboard.IsIdle = false;
                currentMobileState     = MobileStates.MovingForward;
            }
            else if (wantsToStop && !mobileBillboard.IsIdle)
            {
                // Switch animation state to idle
                mobileBillboard.IsIdle = true;
                currentMobileState     = MobileStates.Idle;
            }

            // Update based on current state
            switch (currentMobileState)
            {
            case MobileStates.SeekingTile:
                SeekingTile();
                break;

            case MobileStates.MovingForward:
                MovingForward();
                break;

            case MobileStates.Idle:
                // Do nothing for now
                break;
            }
        }
Beispiel #10
0
        /// <summary>
        /// Rebuild door marker positions for active quest sites in current player location only.
        /// Quite inefficient but this class is only intended for early quest testing.
        /// This method should only be run when player enters/exits a location rect or when a new quest begins.
        /// </summary>
        void RefreshSiteTargets()
        {
            // Clear existing sites
            ClearSiteTargets();

            // Get player's location component in scene
            DaggerfallLocation dfLocation = GameManager.Instance.StreamingWorld.CurrentPlayerLocationObject;

            if (!dfLocation)
            {
                return;
            }

            // Get all active quest sites
            SiteDetails[] allSites = QuestMachine.Instance.GetAllActiveQuestSites();
            if (allSites == null || allSites.Length == 0)
            {
                return;
            }

            // Get all door collections in this location
            DaggerfallStaticDoors[] allDoors = dfLocation.gameObject.GetComponentsInChildren <DaggerfallStaticDoors>();
            if (allDoors == null || allDoors.Length == 0)
            {
                return;
            }

            // Enumerate sites and look for entrance doors
            int foundTotal = 0;

            foreach (SiteDetails site in allSites)
            {
                // Only interested in buildings within player's current location
                if (site.siteType != SiteTypes.Building || site.mapId != dfLocation.Summary.MapID)
                {
                    continue;
                }

                // Get site layout coords
                int siteLayoutX, siteLayoutY, siteRecordIndex;
                BuildingDirectory.ReverseBuildingKey(site.buildingKey, out siteLayoutX, out siteLayoutY, out siteRecordIndex);

                // Build a list of all doors matching site building index
                foreach (DaggerfallStaticDoors dfStaticDoors in allDoors)
                {
                    foreach (StaticDoor door in dfStaticDoors.Doors)
                    {
                        // Get building layout coords from door
                        int doorLayoutX, doorLayoutY, doorRecordIndex;
                        BuildingDirectory.ReverseBuildingKey(door.buildingKey, out doorLayoutX, out doorLayoutY, out doorRecordIndex);

                        // Reject door collections belonging to a different block than site
                        if (doorLayoutX != siteLayoutX || doorLayoutY != siteLayoutY)
                        {
                            break;
                        }

                        // Match building keys
                        if (door.buildingKey == site.buildingKey)
                        {
                            foundTotal++;
                            Vector3 position = door.buildingMatrix.MultiplyPoint3x4(door.centre) + dfStaticDoors.transform.position + worldCompensation;

                            SiteTarget target = new SiteTarget();
                            target.doorPosition = position;
                            target.markerLabel  = new TextLabel();
                            target.targetName   = site.buildingName;
                            Components.Add(target.markerLabel);
                            siteTargets.Add(target);
                        }
                    }
                }
            }

            // Output how many doors were found in thise location and get out if zero
            //Debug.LogFormat("Found {0} doors matching an active quest site in location {1}/{2}.", foundTotal, dfLocation.Summary.RegionName, dfLocation.Summary.LocationName);
            if (foundTotal == 0)
            {
                ClearSiteTargets();
                return;
            }

            // Update SiteLink count
            lastSiteLinkCount = QuestMachine.Instance.SiteLinkCount;

            worldCompensation = Vector3.zero;
        }