Beispiel #1
0
        int GetTravelTimeInSeconds()
        {
            // First Place resource should be main location of quest
            // This seems to hold true in all quests looked at in detail so far
            QuestResource[] placeResources = ParentQuest.GetAllResources(typeof(Place));
            if (placeResources == null || placeResources.Length == 0)
            {
                Debug.LogError("Clock wants a travel time but quest has no Place resources.");
                return(0);
            }

            // Get location from place resource
            DFLocation location;
            Place      place = (Place)placeResources[0];

            if (!DaggerfallUnity.Instance.ContentReader.GetLocation(place.SiteDetails.regionName, place.SiteDetails.locationName, out location))
            {
                Debug.LogErrorFormat("Could not find Quest Place {0}/{1}", place.SiteDetails.regionName, place.SiteDetails.locationName);
                return(0);
            }

            // Get end position in map pixel coordinates
            DFPosition endPos = MapsFile.WorldCoordToMapPixel(location.Exterior.RecordElement.Header.X, location.Exterior.RecordElement.Header.Y);

            // Create a path to location
            // Use the most cautious time possible allowing for player to camp out or stop at inns along the way
            TravelTimeCalculator travelTimeCalculator = new TravelTimeCalculator();

            travelTimeCalculator.GeneratePath(endPos);
            travelTimeCalculator.CalculateTravelTimeTotal(true, false, false, true, false);

            // Get travel time in total days across land and water
            // Allow for return trip travel time plus some fudge for side goals and quest process itself
            // How Daggerfall actually calcutes travel time is currently unknown
            // This should be fair and realistic in most circumstances while still creating time pressures
            // Modify "returnTripMultiplier" to make calcualted quest time harder/easier
            int travelTimeDaysLand  = 0;
            int travelTimeDaysWater = 0;
            int travelTimeDaysTotal = 0;

            if (travelTimeCalculator.TravelTimeTotalLand > 0)
            {
                travelTimeDaysLand = (int)((travelTimeCalculator.TravelTimeTotalLand / 60 / 24) + 0.5);
            }
            if (travelTimeCalculator.TravelTimeTotalWater > 0)
            {
                travelTimeDaysWater = (int)((travelTimeCalculator.TravelTimeTotalWater / 60 / 24) + 0.5);
            }
            travelTimeDaysTotal = (int)((travelTimeDaysLand + travelTimeDaysWater) * returnTripMultiplier);

            return(GetTimeInSeconds(travelTimeDaysTotal, 0, 0));
        }
        /// <summary>
        /// Gets travel time based on overworld map logic.
        /// </summary>
        /// <param name="place">Target place resource. If null will use first place defined in quest.</param>
        /// <param name="returnTrip">Use return trip multiplier.</param>
        /// <returns>Travel time in seconds.</returns>
        int GetTravelTimeInSeconds(Place place, bool returnTrip = true)
        {
            if (place == null)
            {
                // Get first place resource from quest
                QuestResource[] placeResources = ParentQuest.GetAllResources(typeof(Place));
                if (placeResources == null || placeResources.Length == 0)
                {
                    Debug.LogError("Clock wants a travel time but quest has no Place resources.");
                    return(0);
                }
                place = (Place)placeResources[0];
            }

            // Get target location from place resource
            DFLocation location;

            if (!DaggerfallUnity.Instance.ContentReader.GetLocation(place.SiteDetails.regionName, place.SiteDetails.locationName, out location))
            {
                Debug.LogErrorFormat("Could not find Quest Place {0}/{1}", place.SiteDetails.regionName, place.SiteDetails.locationName);
                return(0);
            }

            // Get end position in map pixel coordinates
            DFPosition endPos = MapsFile.WorldCoordToMapPixel(location.Exterior.RecordElement.Header.X, location.Exterior.RecordElement.Header.Y);

            // Create a path to location
            // Use the most cautious time possible allowing for player to camp out or stop at inns along the way
            TravelTimeCalculator travelTimeCalculator = new TravelTimeCalculator();
            int travelTimeMinutes = travelTimeCalculator.CalculateTravelTime(endPos, true, false, false, false, true);

            // Apply return trip multiplier
            if (returnTrip)
            {
                travelTimeMinutes = (int)(travelTimeMinutes * returnTripMultiplier);
            }

            // Always allow at least 1 day for travel time
            if (travelTimeMinutes < 1440)
            {
                travelTimeMinutes = 1440;
            }

            return(GetTimeInSeconds(0, 0, travelTimeMinutes));
        }
        /// <summary>
        /// Gets combined travel time to every place.
        /// This should ensure player has enough time to complete quest when several locations are involved.
        /// Only used when automatic time calculation is required.
        /// </summary>
        /// <param name="returnTrip">Use return trip multiplier. Only applied once for total, not for every place.</param>
        /// <returns>Combined travel time in seconds.</returns>
        int GetTravelTimeInSeconds(bool returnTrip = true)
        {
            int travelTimeMinutes = 0;

            QuestResource[] placeResources = ParentQuest.GetAllResources(typeof(Place));
            foreach (QuestResource place in placeResources)
            {
                travelTimeMinutes += GetTravelTimeInSeconds(place as Place, false);
            }

            // Apply return trip multiplier
            if (returnTrip)
            {
                travelTimeMinutes = (int)(travelTimeMinutes * returnTripMultiplier);
            }

            return(travelTimeMinutes);
        }