private static IEnumerator TestTreasureMapCoroutine(AdventureSaveData saveData, Heightmap.Biome biome, Player player, int count) { var biomes = new[] { Heightmap.Biome.Meadows, Heightmap.Biome.BlackForest, Heightmap.Biome.Swamp, Heightmap.Biome.Mountain, Heightmap.Biome.Plains }; saveData.DebugMode = true; var startInterval = saveData.TreasureMaps.Min(x => x.Interval) - 1; for (var i = 0; i < count; ++i) { saveData.IntervalOverride = startInterval - (i + 1); var selectedBiome = biome == Heightmap.Biome.None ? biomes[UnityEngine.Random.Range(0, biomes.Length)] : biome; yield return(AdventureDataManager.TreasureMaps.SpawnTreasureChest(selectedBiome, player, OnTreasureChestSpawnComplete)); } saveData.DebugMode = false; AdventureDataManager.CheatNumberOfBounties = -1; }
public static AdventureSaveData GetAdventureSaveData(this Player player) { var worldId = ZNet.m_world?.m_uid ?? 0; var adventureComponent = GetAdventureComponent(player); var saveData = adventureComponent.SaveData.AllSaveData.Find(x => (int)worldId == x.WorldID); if (saveData == null) { saveData = new AdventureSaveData() { WorldID = (int)worldId }; adventureComponent.SaveData.AllSaveData.Add(saveData); } return(saveData); }
private static Tuple <float, float> GetTreasureMapSpawnRadiusRange(Heightmap.Biome biome, AdventureSaveData saveData) { var biomeInfoConfig = GetBiomeInfoConfig(biome); var minRadius = biomeInfoConfig?.MinRadius ?? 0; var maxRadius = biomeInfoConfig?.MaxRadius ?? 6000; var numberOfBounties = AdventureDataManager.CheatNumberOfBounties >= 0 ? AdventureDataManager.CheatNumberOfBounties : saveData.NumberOfTreasureMapsOrBountiesStarted; var increments = numberOfBounties / AdventureDataManager.Config.TreasureMap.IncreaseRadiusCount; var min = Mathf.Min(AdventureDataManager.Config.TreasureMap.StartRadiusMin + increments * AdventureDataManager.Config.TreasureMap.RadiusInterval, minRadius); var max = Mathf.Min(AdventureDataManager.Config.TreasureMap.StartRadiusMax + increments * AdventureDataManager.Config.TreasureMap.RadiusInterval, maxRadius); return(new Tuple <float, float>(min, max)); }
protected static IEnumerator GetRandomPointInBiome(Heightmap.Biome biome, AdventureSaveData saveData, Action <bool, Vector3, Vector3> onComplete) { const int maxRangeIncreases = 10; const int maxPointsInRange = 15; MerchantPanel.ShowInputBlocker(true); var rangeTries = 0; var radiusRange = GetTreasureMapSpawnRadiusRange(biome, saveData); while (rangeTries < maxRangeIncreases) { rangeTries++; var tries = 0; while (tries < maxPointsInRange) { tries++; var randomPoint = UnityEngine.Random.insideUnitCircle; var mag = randomPoint.magnitude; var normalized = randomPoint.normalized; var actualMag = Mathf.Lerp(radiusRange.Item1, radiusRange.Item2, mag); randomPoint = normalized * actualMag; var spawnPoint = new Vector3(randomPoint.x, 0, randomPoint.y); var zoneId = ZoneSystem.instance.GetZone(spawnPoint); while (!ZoneSystem.instance.SpawnZone(zoneId, ZoneSystem.SpawnMode.Client, out _)) { EpicLoot.LogWarning($"Spawning Zone ({zoneId})..."); yield return(null); } ZoneSystem.instance.GetGroundData(ref spawnPoint, out var normal, out var foundBiome, out _, out _); var groundHeight = spawnPoint.y; EpicLoot.Log($"Checking biome at ({randomPoint}): {foundBiome} (try {tries})"); if (foundBiome != biome) { // Wrong biome continue; } var solidHeight = ZoneSystem.instance.GetSolidHeight(spawnPoint); var offsetFromGround = Math.Abs(solidHeight - groundHeight); if (offsetFromGround > 5) { // Don't place too high off the ground (on top of tree or something? EpicLoot.Log($"Spawn Point rejected: too high off of ground (groundHeight:{groundHeight}, solidHeight:{solidHeight})"); continue; } // But also don't place inside rocks spawnPoint.y = solidHeight; var placedNearPlayerBase = EffectArea.IsPointInsideArea(spawnPoint, EffectArea.Type.PlayerBase, AdventureDataManager.Config.TreasureMap.MinimapAreaRadius); if (placedNearPlayerBase) { // Don't place near player base EpicLoot.Log("Spawn Point rejected: too close to player base"); continue; } EpicLoot.Log($"Wards: {PrivateArea.m_allAreas.Count}"); var tooCloseToWard = PrivateArea.m_allAreas.Any(x => x.IsInside(spawnPoint, AdventureDataManager.Config.TreasureMap.MinimapAreaRadius)); if (tooCloseToWard) { EpicLoot.Log("Spawn Point rejected: too close to player ward"); continue; } var waterLevel = ZoneSystem.instance.m_waterLevel; if (waterLevel > groundHeight + 1.0f) { // Too deep, try again EpicLoot.Log($"Spawn Point rejected: too deep underwater (waterLevel:{waterLevel}, groundHeight:{groundHeight})"); continue; } EpicLoot.Log($"Success! (ground={groundHeight} water={waterLevel} placed={spawnPoint.y})"); onComplete?.Invoke(true, spawnPoint, normal); MerchantPanel.ShowInputBlocker(false); yield break; } radiusRange = new Tuple <float, float>(radiusRange.Item1 + 500, radiusRange.Item2 + 500); } onComplete?.Invoke(false, new Vector3(), new Vector3()); MerchantPanel.ShowInputBlocker(false); }
private void CreateTreasureChest(Heightmap.Biome biome, Player player, Vector3 spawnPoint, Vector3 normal, AdventureSaveData saveData, Action <bool, Vector3> callback) { const string treasureChestPrefabName = "piece_chest_wood"; var treasureChestPrefab = ZNetScene.instance.GetPrefab(treasureChestPrefabName); var treasureChestObject = Object.Instantiate(treasureChestPrefab, spawnPoint, Quaternion.FromToRotation(Vector3.up, normal)); var treasureChest = treasureChestObject.AddComponent <TreasureMapChest>(); treasureChest.Setup(player, biome, GetCurrentInterval()); var offset2 = UnityEngine.Random.insideUnitCircle * AdventureDataManager.Config.TreasureMap.MinimapAreaRadius; var offset = new Vector3(offset2.x, 0, offset2.y); saveData.PurchasedTreasureMap(GetCurrentInterval(), biome, spawnPoint, offset); player.SaveAdventureSaveData(); Minimap.instance.ShowPointOnMap(spawnPoint + offset); callback?.Invoke(true, spawnPoint); }