Making The Dungeon
Drop these three methods into your toolbox:
public static tk2dSpriteCollectionData ReplaceDungeonCollection(tk2dSpriteCollectionData sourceCollection, Texture2D spriteSheet = null, List<string> spriteList = null)
{
if (sourceCollection == null) { return null; }
tk2dSpriteCollectionData collectionData = UnityEngine.Object.Instantiate(sourceCollection);
tk2dSpriteDefinition[] spriteDefinietions = new tk2dSpriteDefinition[collectionData.spriteDefinitions.Length];
for (int i = 0; i < collectionData.spriteDefinitions.Length; i++) { spriteDefinietions[i] = collectionData.spriteDefinitions[i].Copy(); }
collectionData.spriteDefinitions = spriteDefinietions;
if (spriteSheet != null)
{
Material[] materials = sourceCollection.materials;
Material[] newMaterials = new Material[materials.Length];
if (materials != null)
{
for (int i = 0; i < materials.Length; i++)
{
newMaterials[i] = materials[i].Copy(spriteSheet);
}
collectionData.materials = newMaterials;
foreach (Material material2 in collectionData.materials)
{
foreach (tk2dSpriteDefinition spriteDefinition in collectionData.spriteDefinitions)
{
bool flag3 = material2 != null && spriteDefinition.material.name.Equals(material2.name);
if (flag3)
{
spriteDefinition.material = material2;
spriteDefinition.materialInst = new Material(material2);
}
}
}
}
}
else if (spriteList != null)
{
RuntimeAtlasPage runtimeAtlasPage = new RuntimeAtlasPage(0, 0, TextureFormat.RGBA32, 2);
for (int i = 0; i < spriteList.Count; i++)
{
Texture2D texture2D = ResourceExtractor.GetTextureFromResource(spriteList[i]);
if (!texture2D)
{
Debug.Log("[BuildDungeonCollection] Null Texture found at index: " + i);
goto IL_EXIT;
}
float X = (texture2D.width / 16f);
float Y = (texture2D.height / 16f);
// tk2dSpriteDefinition spriteData = collectionData.GetSpriteDefinition(i.ToString());
tk2dSpriteDefinition spriteData = collectionData.spriteDefinitions[i];
if (spriteData != null)
{
if (spriteData.boundsDataCenter != Vector3.zero)
{
try
{
// Debug.Log("[BuildDungeonCollection] Pack Existing Atlas Element at index: " + i);
RuntimeAtlasSegment runtimeAtlasSegment = runtimeAtlasPage.Pack(texture2D, false);
spriteData.materialInst.mainTexture = runtimeAtlasSegment.texture;
spriteData.uvs = runtimeAtlasSegment.uvs;
spriteData.extractRegion = true;
spriteData.position0 = Vector3.zero;
spriteData.position1 = new Vector3(X, 0, 0);
spriteData.position2 = new Vector3(0, Y, 0);
spriteData.position3 = new Vector3(X, Y, 0);
spriteData.boundsDataCenter = new Vector2((X / 2), (Y / 2));
spriteData.untrimmedBoundsDataCenter = spriteData.boundsDataCenter;
spriteData.boundsDataExtents = new Vector2(X, Y);
spriteData.untrimmedBoundsDataExtents = spriteData.boundsDataExtents;
}
catch (Exception)
{
Debug.Log("[BuildDungeonCollection] Exception caught at index: " + i);
}
}
else
{
// Debug.Log("Test 3. Replace Existing Atlas Element at index: " + i);
try
{
ETGMod.ReplaceTexture(spriteData, texture2D, true);
}
catch (Exception)
{
Debug.Log("[BuildDungeonCollection] Exception caught at index: " + i);
}
}
}
else
{
Debug.Log("[BuildDungeonCollection] SpriteData is null at index: " + i);
}
IL_EXIT:;
}
runtimeAtlasPage.Apply();
}
else
{
Debug.Log("[BuildDungeonCollection] SpriteList is null!");
}
return collectionData;
}
public static Material Copy(this Material orig, Texture2D textureOverride = null, Shader shaderOverride = null)
{
Material m_NewMaterial = new Material(orig.shader)
{
name = orig.name,
shaderKeywords = orig.shaderKeywords,
globalIlluminationFlags = orig.globalIlluminationFlags,
enableInstancing = orig.enableInstancing,
doubleSidedGI = orig.doubleSidedGI,
mainTextureOffset = orig.mainTextureOffset,
mainTextureScale = orig.mainTextureScale,
renderQueue = orig.renderQueue,
color = orig.color,
hideFlags = orig.hideFlags
};
if (textureOverride != null)
{
m_NewMaterial.mainTexture = textureOverride;
}
else
{
m_NewMaterial.mainTexture = orig.mainTexture;
}
if (shaderOverride != null)
{
m_NewMaterial.shader = shaderOverride;
}
else
{
m_NewMaterial.shader = orig.shader;
}
return m_NewMaterial;
}
public static tk2dSpriteDefinition Copy(this tk2dSpriteDefinition orig)
{
tk2dSpriteDefinition m_newSpriteCollection = new tk2dSpriteDefinition();
m_newSpriteCollection.boundsDataCenter = orig.boundsDataCenter;
m_newSpriteCollection.boundsDataExtents = orig.boundsDataExtents;
m_newSpriteCollection.colliderConvex = orig.colliderConvex;
m_newSpriteCollection.colliderSmoothSphereCollisions = orig.colliderSmoothSphereCollisions;
m_newSpriteCollection.colliderType = orig.colliderType;
m_newSpriteCollection.colliderVertices = orig.colliderVertices;
m_newSpriteCollection.collisionLayer = orig.collisionLayer;
m_newSpriteCollection.complexGeometry = orig.complexGeometry;
m_newSpriteCollection.extractRegion = orig.extractRegion;
m_newSpriteCollection.flipped = orig.flipped;
m_newSpriteCollection.indices = orig.indices;
if (orig.material != null) { m_newSpriteCollection.material = new Material(orig.material); }
m_newSpriteCollection.materialId = orig.materialId;
if (orig.materialInst != null) { m_newSpriteCollection.materialInst = new Material(orig.materialInst); }
m_newSpriteCollection.metadata = orig.metadata;
m_newSpriteCollection.name = orig.name;
m_newSpriteCollection.normals = orig.normals;
m_newSpriteCollection.physicsEngine = orig.physicsEngine;
m_newSpriteCollection.position0 = orig.position0;
m_newSpriteCollection.position1 = orig.position1;
m_newSpriteCollection.position2 = orig.position2;
m_newSpriteCollection.position3 = orig.position3;
m_newSpriteCollection.regionH = orig.regionH;
m_newSpriteCollection.regionW = orig.regionW;
m_newSpriteCollection.regionX = orig.regionX;
m_newSpriteCollection.regionY = orig.regionY;
m_newSpriteCollection.tangents = orig.tangents;
m_newSpriteCollection.texelSize = orig.texelSize;
m_newSpriteCollection.untrimmedBoundsDataCenter = orig.untrimmedBoundsDataCenter;
m_newSpriteCollection.untrimmedBoundsDataExtents = orig.untrimmedBoundsDataExtents;
m_newSpriteCollection.uvs = orig.uvs;
return m_newSpriteCollection;
}
Please read Tileset then return here.
Now we create a new file named FloorNameDungeon
Paste in:
public static GameLevelDefinition FloorNameDefinition;
public static GameObject GameManagerObject;
public static tk2dSpriteCollectionData gofuckyourself;
public static Dungeon GetOrLoadByNameHook(Func<string, Dungeon> orig, string name)
{
Dungeon dungeon = null;
string dungeonPrefabTemplate = "Base_ResourcefulRat";
if (name.ToLower() == "base_floorname")
{
dungeon = FloorNameGeon(GetOrLoadByName_Orig(dungeonPrefabTemplate));
}
if (dungeon)
{
DebugTime.RecordStartTime();
DebugTime.Log("AssetBundle.LoadAsset<Dungeon>({0})", new object[] { name });
return dungeon;
}
else
{
return orig(name);
}
}
public static Hook getOrLoadByName_Hook;
public static void InitCustomDungeon()
{
getOrLoadByName_Hook = new Hook(
typeof(DungeonDatabase).GetMethod("GetOrLoadByName", BindingFlags.Static | BindingFlags.Public),
typeof(FloorNameDungeon).GetMethod("GetOrLoadByNameHook", BindingFlags.Static | BindingFlags.Public)
);
AssetBundle braveResources = ResourceManager.LoadAssetBundle("brave_resources_001");
GameManagerObject = braveResources.LoadAsset<GameObject>("_GameManager");
FloorNameDefinition = new GameLevelDefinition()
{
dungeonSceneName = "tt_floorname", //this is the name we will use whenever we want to load our dungeons scene
dungeonPrefabPath = "Base_FloorName", //this is what we will use when we want to acess our dungeon prefab
priceMultiplier = 1.5f, //multiplies how much things cost in the shop
secretDoorHealthMultiplier = 1, //multiplies how much health secret room doors have, aka how many shots you will need to expose them
enemyHealthMultiplier = 2, //multiplies how much health enemies have
damageCap = 300, // damage cap for regular enemies
bossDpsCap = 78, // damage cap for bosses
flowEntries = new List<DungeonFlowLevelEntry>(0),
predefinedSeeds = new List<int>(0)
};
// sets the level definition of the GameLevelDefinition in GameManager.Instance.customFloors if it exists
foreach (GameLevelDefinition levelDefinition in GameManager.Instance.customFloors)
{
if (levelDefinition.dungeonSceneName == "tt_floorname") { FloorNameDefinition = levelDefinition; }
}
GameManager.Instance.customFloors.Add(FloorNameDefinition);
GameManagerObject.GetComponent<GameManager>().customFloors.Add(FloorNameDefinition);
}
public static Dungeon FloorNameGeon(Dungeon dungeon)
{
Dungeon MinesDungeonPrefab = GetOrLoadByName_Orig("Base_Mines");
Dungeon CatacombsPrefab = GetOrLoadByName_Orig("Base_Catacombs");
Dungeon RatDungeonPrefab = GetOrLoadByName_Orig("Base_ResourcefulRat");
DungeonMaterial FinalScenario_MainMaterial = UnityEngine.Object.Instantiate(RatDungeonPrefab.roomMaterialDefinitions[0]);
FinalScenario_MainMaterial.supportsPits = true;
FinalScenario_MainMaterial.doPitAO = false;
// FinalScenario_MainMaterial.pitsAreOneDeep = true;
FinalScenario_MainMaterial.useLighting = true;
// FinalScenario_MainMaterial.supportsLavaOrLavalikeSquares = true;
FinalScenario_MainMaterial.lightPrefabs.elements[0].rawGameObject = MinesDungeonPrefab.roomMaterialDefinitions[0].lightPrefabs.elements[0].rawGameObject;
FinalScenario_MainMaterial.roomFloorBorderGrid = RatDungeonPrefa .roomMaterialDefinitions[0].roomFloorBorderGrid;
FinalScenario_MainMaterial.pitLayoutGrid = RatDungeonPrefab.roomMaterialDefinitions[0].pitLayoutGrid;
FinalScenario_MainMaterial.pitBorderFlatGrid = RatDungeonPrefab.roomMaterialDefinitions[0].pitBorderFlatGrid;
DungeonTileStampData m_FloorNameStampData = ScriptableObject.CreateInstance<DungeonTileStampData>();
m_FloorNameStampData.name = "ENV_FloorName_STAMP_DATA";
m_FloorNameStampData.tileStampWeight = 0;
m_FloorNameStampData.spriteStampWeight = 0;
m_FloorNameStampData.objectStampWeight = 1;
m_FloorNameStampData.stamps = new TileStampData[0];
m_FloorNameStampData.spriteStamps = new SpriteStampData[0];
m_FloorNameStampData.objectStamps = RatDungeonPrefab.stampData.objectStamps;
m_FloorNameStampData.SymmetricFrameChance = 0.25f;
m_FloorNameStampData.SymmetricCompleteChance = 0.6f;
dungeon.gameObject.name = "Base_FloorName";
dungeon.contentSource = ContentSource.CONTENT_UPDATE_03;
dungeon.DungeonSeed = 0;
dungeon.DungeonFloorName = "Floor Name."; // what shows up At the top when floor is loaded
dungeon.DungeonShortName = "Floor Name."; // no clue lol, just make it the same
dungeon.DungeonFloorLevelTextOverride = "subtext..."; // what shows up below the floorname
dungeon.LevelOverrideType = GameManager.LevelOverrideState.NONE;
dungeon.debugSettings = new DebugDungeonSettings()
{
RAPID_DEBUG_DUNGEON_ITERATION_SEEKER = false,
RAPID_DEBUG_DUNGEON_ITERATION = false,
RAPID_DEBUG_DUNGEON_COUNT = 50,
GENERATION_VIEWER_MODE = false,
FULL_MINIMAP_VISIBILITY = false,
COOP_TEST = false,
DISABLE_ENEMIES = false,
DISABLE_LOOPS = false,
DISABLE_SECRET_ROOM_COVERS = false,
DISABLE_OUTLINES = false,
WALLS_ARE_PITS = false
};
dungeon.ForceRegenerationOfCharacters = false;
dungeon.ActuallyGenerateTilemap = true;
if (gofuckyourself == null)
{
gofuckyourself = RatDungeonPrefab.tileIndices.dungeonCollection;
}
dungeon.tileIndices = new TileIndices()
{
tilesetId = (GlobalDungeonData.ValidTilesets)CustomValidTilesets.FLOORNAMEGEON, //sets it to our floors CustomValidTileset
//since the tileset im using here is a copy of the Rat dungeon tileset, the first variable in ReplaceDungeonCollection is RatDungeonPrefab.tileIndices.dungeonCollection,
//otherwise we will use a different dungeon prefab
dungeonCollection = toolbox.ReplaceDungeonCollection(gofuckyourself, ModPrefabs.ENV_Tileset_FloorName),
dungeonCollectionSupportsDiagonalWalls = false,
aoTileIndices = RatDungeonPrefab.tileIndices.aoTileIndices,
placeBorders = true,
placePits = false,
chestHighWallIndices = new List<TileIndexVariant>() {
new TileIndexVariant() {
index = 41,
likelihood = 0.5f,
overrideLayerIndex = 0,
overrideIndex = 0
}
},
decalIndexGrid = null,
patternIndexGrid = RatDungeonPrefab.tileIndices.patternIndexGrid,
globalSecondBorderTiles = new List<int>(0),
edgeDecorationTiles = null
};
dungeon.tileIndices.dungeonCollection.name = "ENV_FloorName_Collection";
dungeon.roomMaterialDefinitions = new DungeonMaterial[] {
FinalScenario_MainMaterial,
FinalScenario_MainMaterial,
FinalScenario_MainMaterial,
FinalScenario_MainMaterial,
FinalScenario_MainMaterial,
FinalScenario_MainMaterial,
FinalScenario_MainMaterial
};
dungeon.dungeonWingDefinitions = new DungeonWingDefinition[0];
//This section can be used to take parts from other floors and use them as our own.
//we can make the running dust from one floor our own, the tables from another our own,
//we can use all of the stuff from the same floor, or if you want, you can make your own.
dungeon.pathGridDefinitions = new List<TileIndexGrid>() { MinesDungeonPrefab.pathGridDefinitions[0] };
dungeon.dungeonDustups = new DustUpVFX()
{
runDustup = MinesDungeonPrefab.dungeonDustups.runDustup,
waterDustup = MinesDungeonPrefab.dungeonDustups.waterDustup,
additionalWaterDustup = MinesDungeonPrefab.dungeonDustups.additionalWaterDustup,
rollNorthDustup = MinesDungeonPrefab.dungeonDustups.rollNorthDustup,
rollNorthEastDustup = MinesDungeonPrefab.dungeonDustups.rollNorthEastDustup,
rollEastDustup = MinesDungeonPrefab.dungeonDustups.rollEastDustup,
rollSouthEastDustup = MinesDungeonPrefab.dungeonDustups.rollSouthEastDustup,
rollSouthDustup = MinesDungeonPrefab.dungeonDustups.rollSouthDustup,
rollSouthWestDustup = MinesDungeonPrefab.dungeonDustups.rollSouthWestDustup,
rollWestDustup = MinesDungeonPrefab.dungeonDustups.rollWestDustup,
rollNorthWestDustup = MinesDungeonPrefab.dungeonDustups.rollNorthWestDustup,
rollLandDustup = MinesDungeonPrefab.dungeonDustups.rollLandDustup
};
dungeon.PatternSettings = new SemioticDungeonGenSettings()
{
flows = new List<DungeonFlow>() {
//this will contain our dungeon flows after we make them
},
mandatoryExtraRooms = new List<ExtraIncludedRoomData>(0),
optionalExtraRooms = new List<ExtraIncludedRoomData>(0),
MAX_GENERATION_ATTEMPTS = 250,
DEBUG_RENDER_CANVASES_SEPARATELY = false
};
dungeon.damageTypeEffectMatrix = MinesDungeonPrefab.damageTypeEffectMatrix;
dungeon.stampData = m_FloorNameStampData;
dungeon.UsesCustomFloorIdea = false;
dungeon.FloorIdea = new RobotDaveIdea()
{
ValidEasyEnemyPlaceables = new DungeonPlaceable[0],
ValidHardEnemyPlaceables = new DungeonPlaceable[0],
UseWallSawblades = false,
UseRollingLogsVertical = true,
UseRollingLogsHorizontal = true,
UseFloorPitTraps = false,
UseFloorFlameTraps = true,
UseFloorSpikeTraps = true,
UseFloorConveyorBelts = true,
UseCaveIns = true,
UseAlarmMushrooms = false,
UseChandeliers = true,
UseMineCarts = false,
CanIncludePits = false
};
//more variable we can copy from other floors, or make our own
dungeon.PlaceDoors = true;
dungeon.doorObjects = CatacombsPrefab.doorObjects;
dungeon.oneWayDoorObjects = MinesDungeonPrefab.oneWayDoorObjects;
dungeon.oneWayDoorPressurePlate = MinesDungeonPrefab.oneWayDoorPressurePlate;
dungeon.phantomBlockerDoorObjects = MinesDungeonPrefab.phantomBlockerDoorObjects;
dungeon.UsesWallWarpWingDoors = false;
dungeon.baseChestContents = CatacombsPrefab.baseChestContents;
dungeon.SecretRoomSimpleTriggersFacewall = new List<GameObject>() { CatacombsPrefab.SecretRoomSimpleTriggersFacewall[0] };
dungeon.SecretRoomSimpleTriggersSidewall = new List<GameObject>() { CatacombsPrefab.SecretRoomSimpleTriggersSidewall[0] };
dungeon.SecretRoomComplexTriggers = new List<ComplexSecretRoomTrigger>(0);
dungeon.SecretRoomDoorSparkVFX = CatacombsPrefab.SecretRoomDoorSparkVFX;
dungeon.SecretRoomHorizontalPoofVFX = CatacombsPrefab.SecretRoomHorizontalPoofVFX;
dungeon.SecretRoomVerticalPoofVFX = CatacombsPrefab.SecretRoomVerticalPoofVFX;
dungeon.sharedSettingsPrefab = CatacombsPrefab.sharedSettingsPrefab;
dungeon.NormalRatGUID = string.Empty;
dungeon.BossMasteryTokenItemId = CatacombsPrefab.BossMasteryTokenItemId;
dungeon.UsesOverrideTertiaryBossSets = false;
dungeon.OverrideTertiaryRewardSets = new List<TertiaryBossRewardSet>(0);
dungeon.defaultPlayerPrefab = MinesDungeonPrefab.defaultPlayerPrefab;
dungeon.StripPlayerOnArrival = false;
dungeon.SuppressEmergencyCrates = false;
dungeon.SetTutorialFlag = false;
dungeon.PlayerIsLight = true;
dungeon.PlayerLightColor = CatacombsPrefab.PlayerLightColor;
dungeon.PlayerLightIntensity = 4;
dungeon.PlayerLightRadius = 4;
dungeon.PrefabsToAutoSpawn = new GameObject[0];
//include this for custom floor audio
//dungeon.musicEventName = "play_sound";
CatacombsPrefab = null;
RatDungeonPrefab = null;
MinesDungeonPrefab = null;
return dungeon;
}
public static Dungeon GetOrLoadByName_Orig(string name)
{
AssetBundle assetBundle = ResourceManager.LoadAssetBundle("dungeons/" + name.ToLower());
DebugTime.RecordStartTime();
Dungeon component = assetBundle.LoadAsset<GameObject>(name).GetComponent<Dungeon>();
DebugTime.Log("AssetBundle.LoadAsset<Dungeon>({0})", new object[] { name });
return component;
}
READ THROUGH EVERYTHING AND CHANGE IT HOW YOU SEE FIT, FLOORS CAN HAVE A LOT OF VARIANCE.
Last updated