void ReloadCurrentRegion() { regionData = dfUnity.ContentReader.MapFileReader.GetRegion(regionNames[selectedRegion]); lastSelectedRegion = selectedRegion; }
/// <summary> /// Add random enemies from encounter tables based on dungeon type, monster power, and seed. /// </summary> /// <param name="go">GameObject to add monsters to.</param> /// <param name="editorObjects">Editor objects containing flats.</param> /// <param name="dungeonType">Dungeon type selects the encounter table.</param> /// <param name="monsterPower">Value between 0-1 for lowest monster power to highest.</param> /// <param name="monsterVariance">Adjust final index +/- this value in encounter table.</param> /// <param name="seed">Random seed for encounters.</param> /// <param name="serialize">Allow for serialization when available.</param> public static void AddRandomEnemies( GameObject go, DFBlock.RdbObject[] editorObjects, DFRegion.DungeonTypes dungeonType, float monsterPower, ref DFBlock blockData, int monsterVariance = 4, int seed = 0, bool serialize = true) { const int randomMonsterFlatIndex = 15; DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) return; // Must have import enabled and prefab set if (!dfUnity.Option_ImportEnemyPrefabs || dfUnity.Option_EnemyPrefab == null) return; // Editor objects array must be populated if (editorObjects == null || editorObjects.Length == 0) return; // Add parent node GameObject randomEnemiesNode = new GameObject("Random Enemies"); randomEnemiesNode.transform.parent = go.transform; // Seed random generator UnityEngine.Random.seed = seed; // Iterate editor flats for enemies for (int i = 0; i < editorObjects.Length; i++) { // Add random enemy objects if (editorObjects[i].Resources.FlatResource.TextureRecord == randomMonsterFlatIndex) AddRandomRDBEnemy(editorObjects[i], dungeonType, monsterPower, monsterVariance, randomEnemiesNode.transform, ref blockData, serialize); } }
private static void AddRandomRDBEnemy( DFBlock.RdbObject obj, DFRegion.DungeonTypes dungeonType, float monsterPower, int monsterVariance, Transform parent, ref DFBlock blockData, bool serialize) { // Must have a dungeon type if (dungeonType == DFRegion.DungeonTypes.NoDungeon) return; // Get dungeon type index int dungeonIndex = (int)dungeonType >> 8; if (dungeonIndex < RandomEncounters.EncounterTables.Length) { // Get encounter table RandomEncounterTable table = RandomEncounters.EncounterTables[dungeonIndex]; // Get base monster index into table int baseMonsterIndex = (int)((float)table.Enemies.Length * monsterPower); // Set min index int minMonsterIndex = baseMonsterIndex - monsterVariance; if (minMonsterIndex < 0) minMonsterIndex = 0; // Set max index int maxMonsterIndex = baseMonsterIndex + monsterVariance; if (maxMonsterIndex >= table.Enemies.Length) maxMonsterIndex = table.Enemies.Length; // Get random monster from table MobileTypes type = table.Enemies[UnityEngine.Random.Range(minMonsterIndex, maxMonsterIndex)]; // Create unique LoadID for save sytem long loadID = 0; if (serialize) loadID = (blockData.Index << 24) + obj.This; // Add enemy AddEnemy(obj, type, parent, loadID); } else { DaggerfallUnity.LogMessage(string.Format("RDBLayout: Dungeon type {0} is out of range or unknown.", dungeonType), true); } }
/// <summary> /// Layout a complete RDB block game object. /// </summary> /// <param name="blockName">Name of block to create.</param> /// <param name="textureTable">Optional texture table for dungeon.</param> /// <param name="allowExitDoors">Add exit doors to block (for start blocks).</param> /// <param name="dungeonType">Dungeon type for random encounters.</param> /// <param name="seed">Seed for random encounters.</param> /// <param name="cloneFrom">Clone and build on a prefab object template.</param> public static GameObject CreateRDBBlockGameObject( string blockName, int[] textureTable = null, bool allowExitDoors = true, DFRegion.DungeonTypes dungeonType = DFRegion.DungeonTypes.HumanStronghold, float monsterPower = 0.5f, int monsterVariance = 4, int seed = 0, DaggerfallRDBBlock cloneFrom = null) { // Get DaggerfallUnity DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) return null; Dictionary<int, RDBLayout.ActionLink> actionLinkDict = new Dictionary<int, RDBLayout.ActionLink>(); // Create base object DFBlock blockData; GameObject go = RDBLayout.CreateBaseGameObject(blockName, actionLinkDict, out blockData, textureTable, allowExitDoors, cloneFrom); // Add action doors RDBLayout.AddActionDoors(go, actionLinkDict, ref blockData, textureTable); // Add lights RDBLayout.AddLights(go, ref blockData); // Add flats DFBlock.RdbObject[] editorObjects; GameObject[] startMarkers; GameObject[] enterMarkers; RDBLayout.AddFlats(go, actionLinkDict, ref blockData, out editorObjects, out startMarkers, out enterMarkers); // Set start and enter markers DaggerfallRDBBlock dfBlock = go.GetComponent<DaggerfallRDBBlock>(); if (dfBlock != null) dfBlock.SetMarkers(startMarkers, enterMarkers); // Add treasure RDBLayout.AddTreasure(go, editorObjects, ref blockData); // Add enemies RDBLayout.AddFixedEnemies(go, editorObjects, ref blockData); RDBLayout.AddRandomEnemies(go, editorObjects, dungeonType, monsterPower, ref blockData, monsterVariance, seed); // Link action nodes RDBLayout.LinkActionNodes(actionLinkDict); return go; }
private void UpdateWorldInfo(int x, int y) { // Requires MAPS.BSA connection if (dfUnity.ContentReader.MapFileReader == null) return; // Get climate and politic data currentClimateIndex = dfUnity.ContentReader.MapFileReader.GetClimateIndex(x, y); currentPoliticIndex = dfUnity.ContentReader.MapFileReader.GetPoliticIndex(x, y); climateSettings = MapsFile.GetWorldClimateSettings(currentClimateIndex); if (currentPoliticIndex > 128) regionName = dfUnity.ContentReader.MapFileReader.GetRegionName(currentPoliticIndex - 128); else if (currentPoliticIndex == 64) regionName = "Ocean"; else regionName = "Unknown"; // Get region data currentRegion = dfUnity.ContentReader.MapFileReader.GetRegion(CurrentRegionIndex); // Get location data ContentReader.MapSummary mapSummary; if (dfUnity.ContentReader.HasLocation(x, y, out mapSummary)) { currentLocation = dfUnity.ContentReader.MapFileReader.GetLocation(mapSummary.RegionIndex, mapSummary.MapIndex); hasCurrentLocation = true; CalculateWorldLocationRect(); } else { currentLocation = new DFLocation(); hasCurrentLocation = false; ClearWorldLocationRect(); } // Get location type if (hasCurrentLocation) { if (currentRegion.MapTable == null) { DaggerfallUnity.LogMessage(string.Format("PlayerGPS: Location {0} in region{1} has a null MapTable.", currentLocation.Name, currentLocation.RegionName)); } else { currentLocationType = currentRegion.MapTable[mapSummary.MapIndex].LocationType; } } }
private static void AddEnemy( DFBlock.RdbObject obj, MobileTypes type, Transform parent = null, DFRegion.DungeonTypes dungeonType = DFRegion.DungeonTypes.HumanStronghold) { // Get default reaction MobileReactions reaction = MobileReactions.Hostile; if (obj.Resources.FlatResource.FlatData.Reaction == (int)DFBlock.EnemyReactionTypes.Passive) reaction = MobileReactions.Passive; // Just setup demo enemies at this time string name = string.Format("DaggerfallEnemy [{0}]", type.ToString()); Vector3 position = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale; GameObject go = GameObjectHelper.InstantiatePrefab(DaggerfallUnity.Instance.Option_EnemyPrefab.gameObject, name, parent, position); SetupDemoEnemy setupEnemy = go.GetComponent<SetupDemoEnemy>(); if (setupEnemy != null) { // Configure enemy setupEnemy.ApplyEnemySettings(type, reaction); // Align non-flying units with ground DaggerfallMobileUnit mobileUnit = setupEnemy.GetMobileBillboardChild(); if (mobileUnit.Summary.Enemy.Behaviour != MobileBehaviour.Flying) GameObjectHelper.AlignControllerToGround(go.GetComponent<CharacterController>()); } }
/// <summary> /// Opens the region panel to the specified region. /// </summary> void OpenRegionPanel(int region) { string[] mapNames = GetRegionMapNames(region); if (mapNames == null || mapNames.Length == 0) return; mapIndex = 0; selectedRegion = region; selectedRegionMapNames = mapNames; StopRegionIdentify(); SetupArrowButtons(); regionTextureOverlayPanel.Enabled = true; SetRegionTexture(); regionTextureOverlayPanel.BackgroundTexture = regionTexture; //enable find button findButton.Enabled = true; currentDFRegion = DaggerfallUnity.ContentReader.MapFileReader.GetRegion(region); UpdateLocationCluster(); }
//returns index to locationPixelColor array or -1 if invalid or filtered int GetPixelColorIndex(DFRegion.LocationTypes locationType) { int index = -1; switch (locationType) { case DFRegion.LocationTypes.DungeonLabyrinth: index = 0; break; case DFRegion.LocationTypes.DungeonKeep: index = 1; break; case DFRegion.LocationTypes.DungeonRuin: index = 2; break; case DFRegion.LocationTypes.GraveyardCommon: index = 3; break; case DFRegion.LocationTypes.GraveyardForgotten: index = 3; break; case DFRegion.LocationTypes.HomeFarms: index = 4; break; case DFRegion.LocationTypes.HomeWealthy: index = 5; break; case DFRegion.LocationTypes.HomePoor: index = 6; break; case DFRegion.LocationTypes.HomeYourShips: break; case DFRegion.LocationTypes.ReligionTemple: index = 7; break; case DFRegion.LocationTypes.ReligionCult: index = 8; break; case DFRegion.LocationTypes.ReligionCoven: index = 9; break; case DFRegion.LocationTypes.Tavern: index = 10; break; case DFRegion.LocationTypes.TownCity: index = 11; break; case DFRegion.LocationTypes.TownHamlet: index = 12; break; case DFRegion.LocationTypes.TownVillage: index = 13; break; default: break; } if (index < 0) return index; else if (index < 4 && filterDungeons) index = -1; else if (index > 3 && index < 7 && filterHomes) index = -1; else if (index > 6 && index < 10 && filterTemples) index = -1; else if (index > 9 && index < 14 && filterTowns) index = -1; return index; }