diff --git a/ProjectEarthServerAPI/Util/AdventureUtils.cs b/ProjectEarthServerAPI/Util/AdventureUtils.cs index 827970c..1c1f377 100644 --- a/ProjectEarthServerAPI/Util/AdventureUtils.cs +++ b/ProjectEarthServerAPI/Util/AdventureUtils.cs @@ -106,14 +106,22 @@ public static AdventureRequestResult RedeemCrystal(string playerId, PlayerAdvent return Encounters; } - public static LocationResponse.ActiveLocation CreateEncounterLocation(double randomLatitude, double randomLongitude, DateTime expirationTime) + public static LocationResponse.ActiveLocation GenerateEncounterLocation(double randomLatitude, double randomLongitude, DateTime expirationTime) + { + + AdventureUtils adventureUtils = new AdventureUtils(); + + return adventureUtils.CreateEncounterLocation(randomLatitude, randomLongitude, expirationTime); + } + + public LocationResponse.ActiveLocation CreateEncounterLocation(double randomLatitude, double randomLongitude, DateTime expirationTime) { Encounters.RemoveAll(match => match.expirationTime < DateTime.UtcNow); string selectedAdventureIcon = AdventureIcons[random.Next(0, AdventureIcons.Length)]; Guid selectedAdventureId = Guid.NewGuid(); // Generate a new unique ID for the encounter - var newEncounterLocation = new LocationResponse.ActiveLocation + LocationResponse.ActiveLocation newEncounterLocation = new LocationResponse.ActiveLocation { coordinate = new Coordinate { latitude = randomLatitude, longitude = randomLongitude }, encounterMetadata = new EncounterMetadata @@ -140,9 +148,17 @@ public static LocationResponse.ActiveLocation CreateEncounterLocation(double ran Encounters.Add(newEncounterLocation); + StoreEncounter(newEncounterLocation); + return newEncounterLocation; } + private void StoreEncounter(LocationResponse.ActiveLocation newEncounterLocation) + { + var storage = new LocationResponse.ActiveLocationStorage { location = newEncounterLocation }; + StateSingleton.Instance.activeTappables.Add(newEncounterLocation.id, storage); + // Log.Debug($"Active tappables count: {StateSingleton.Instance.activeTappables.Count}"); + } } } diff --git a/ProjectEarthServerAPI/Util/ConfigGenerator.cs b/ProjectEarthServerAPI/Util/ConfigGenerator.cs index 3e44cb6..81d0210 100644 --- a/ProjectEarthServerAPI/Util/ConfigGenerator.cs +++ b/ProjectEarthServerAPI/Util/ConfigGenerator.cs @@ -33,7 +33,7 @@ public void GenerateConfigFile(string configFilePath) { "tappableExpirationTime", 10 }, // Minutes { "biomeGeneration", true }, // Custom Generation. Needs Tile Server!! { "publicAdventureSpawnPercentage", 5 }, // Percentage of Adventure Spawn rate - { "publicAdventuresLimit", 2 }, // Public Adventures Limit + { "publicAdventuresLimit", 5 }, // Public Adventures Limit { "webPanel", true }, { "webPanelPassword", "password" }, { "maxTappablesPerTile", 20 }, diff --git a/ProjectEarthServerAPI/Util/TappableUpdates.cs b/ProjectEarthServerAPI/Util/TappableUpdates.cs index 92ccfa5..0200e1f 100644 --- a/ProjectEarthServerAPI/Util/TappableUpdates.cs +++ b/ProjectEarthServerAPI/Util/TappableUpdates.cs @@ -24,7 +24,7 @@ public static void RemoveExpiredTappables() StateSingleton.Instance.activeTappables.Remove(tappableId); } - Log.Debug($"Removed {tappablesToRemove.Count} expired tappables."); + // Log.Debug($"Removed {tappablesToRemove.Count} expired tappables."); } public static LocationResponse.Root GetActiveLocations(double lat, double lon, int radius = 1) @@ -37,7 +37,11 @@ public static LocationResponse.Root GetActiveLocations(double lat, double lon, i .Select(kvp => kvp.Value.location) .ToList(); - var globalEncounters = AdventureUtils.GetEncountersForLocation(lat, lon); + var globalEncounters = StateSingleton.Instance.activeTappables + .Where(kvp => kvp.Value.location.type == "Encounter") + .Select(kvp => kvp.Value.location) + .ToList(); + globalTappables.AddRange(globalEncounters); return new LocationResponse.Root @@ -54,6 +58,7 @@ public static LocationResponse.Root GetActiveLocations(double lat, double lon, i } else { + AdventureUtils.GetEncountersForLocation(lat, lon); radius = StateSingleton.Instance.config.tappableSpawnRadius; string tileId = Tile.GetTileForCoordinates(lat, lon); string[] parts = tileId.Split('_'); @@ -69,17 +74,18 @@ public static LocationResponse.Root GetActiveLocations(double lat, double lon, i var maxCoordinates = new Coordinate { latitude = maxTileCoordinates[1][0], longitude = maxTileCoordinates[1][1] }; var tappables = StateSingleton.Instance.activeTappables - .Where(pred => - pred.Value.location.coordinate.latitude >= minCoordinates.latitude && - pred.Value.location.coordinate.latitude <= maxCoordinates.latitude && - pred.Value.location.coordinate.longitude >= minCoordinates.longitude && - pred.Value.location.coordinate.longitude <= maxCoordinates.longitude) - .Select(pred => pred.Value.location) - .ToList(); + .Where(pred => pred.Value.location.type == "Tappable") + .Select(pred => pred.Value.location) + .ToList(); + + var encounters = StateSingleton.Instance.activeTappables + .Where(pred => pred.Value.location.type == "Encounter") + .Select(pred => pred.Value.location) + .ToList(); - // TAPPABLE GENERATION - if (StateSingleton.Instance.config.maxTappableSpawnAmount > tappables.Count) + // TAPPABLE GENERATION + if (StateSingleton.Instance.config.maxTappableSpawnAmount > tappables.Count) { // For each tile for (int latLoop = tileIdLat - radius; latLoop <= tileIdLat + radius; latLoop++) @@ -129,32 +135,30 @@ public static LocationResponse.Root GetActiveLocations(double lat, double lon, i } } - // Encounters/Adventures - var encountersInCurrentTile = AdventureUtils.GetEncountersForLocation(lat, lon) - .Where(kvp => kvp.tileId == currentTileId) - .Select(pred => pred) - .ToList(); - - tappables.AddRange(encountersInCurrentTile); - - double randomLatitude = minCoordinates.latitude + (random.NextDouble() * (maxCoordinates.latitude - minCoordinates.latitude)); - double randomLongitude = minCoordinates.longitude + (random.NextDouble() * (maxCoordinates.longitude - minCoordinates.longitude)); - - var encounterCount = AdventureUtils.GetEncountersForLocation(lat, lon).Count - 1; - var existingLocationsCount = AdventureUtils.ReadEncounterLocations().Count; - - if (random.Next(1, 101) <= StateSingleton.Instance.config.publicAdventureSpawnPercentage) - { - if (StateSingleton.Instance.config.publicAdventuresLimit > encounterCount + existingLocationsCount) - { - DateTime expirationTime = DateTime.UtcNow.AddMinutes(30); - var newAdventures = AdventureUtils.CreateEncounterLocation(randomLatitude, randomLongitude, expirationTime); - if (newAdventures != null) - { - tappables.Add(newAdventures); - } - } - } + // Encounters/Adventures + if (StateSingleton.Instance.config.publicAdventuresLimit > encounters.Count) + { + var encountersInCurrentTile = StateSingleton.Instance.activeTappables + .Where(kvp => kvp.Value.location.tileId == currentTileId && kvp.Value.location.type == "Encounter") + .Select(kvp => kvp.Value.location) + .ToList(); + + tappables.AddRange(encountersInCurrentTile); + + if (random.Next(1, 101) <= StateSingleton.Instance.config.publicAdventureSpawnPercentage) + { + double randomLatitude = minCoordinates.latitude + (random.NextDouble() * (maxCoordinates.latitude - minCoordinates.latitude)); + double randomLongitude = minCoordinates.longitude + (random.NextDouble() * (maxCoordinates.longitude - minCoordinates.longitude)); + + DateTime expirationTime = DateTime.UtcNow.AddMinutes(30); + + var newAdventures = AdventureUtils.GenerateEncounterLocation(randomLatitude, randomLongitude, expirationTime); + if (newAdventures != null) + { + tappables.Add(newAdventures); + } + } + } } } } diff --git a/ProjectEarthServerAPI/Views/Panel/index.cshtml b/ProjectEarthServerAPI/Views/Panel/index.cshtml index 9105a0f..4fc7c8d 100644 --- a/ProjectEarthServerAPI/Views/Panel/index.cshtml +++ b/ProjectEarthServerAPI/Views/Panel/index.cshtml @@ -47,6 +47,9 @@
  • Live Tappable Count: @ViewBag.TappableCount
  • +
  • + Live Adventures Count: @ViewBag.AdventuresCount +
  • Biome Generation: @ViewBag.BiomeGeneration
  • diff --git a/ProjectEarthServerAPI/WebControllers/panel.cs b/ProjectEarthServerAPI/WebControllers/panel.cs index abc8f60..dfa1772 100644 --- a/ProjectEarthServerAPI/WebControllers/panel.cs +++ b/ProjectEarthServerAPI/WebControllers/panel.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Http; using ProjectEarthServerAPI.Util; using Serilog; +using System.Linq; namespace ProjectEarthServerAPI.Views { @@ -48,6 +49,11 @@ public IActionResult Index() ViewBag.SpawnRadius = StateSingleton.Instance.config.tappableSpawnRadius; ViewBag.TappableExpirationTime = StateSingleton.Instance.config.tappableExpirationTime; ViewBag.AdventuresCountJson = AdventureUtils.ReadEncounterLocations().Count; + var adventures = StateSingleton.Instance.activeTappables + .Where(pred => pred.Value.location.type == "Encounter") + .Select(pred => pred.Value.location) + .ToList(); + ViewBag.AdventuresCount = adventures.Count; ViewBag.PublicAdventuresLimit = StateSingleton.Instance.config.publicAdventuresLimit; ViewBag.AdventureSpawnPercentage = StateSingleton.Instance.config.publicAdventureSpawnPercentage; ViewBag.MaxTappablesPerTile = StateSingleton.Instance.config.maxTappablesPerTile;