public static void OnAssemblyLoaded(string path) { MOD_FOLDER = Path.GetDirectoryName(path) + "/"; GAME_ROOT = path.Substring(0, path.IndexOf("gamedata")).Replace("\\", "/") + "/"; GAMEDATA_FOLDER = path.Substring(0, path.IndexOf("gamedata") + "gamedata".Length).Replace("\\", "/") + "/"; GAME_SAVES = GAMEDATA_FOLDER + "savegames/"; MOD_MESH_PATH = MOD_FOLDER + "gamedata/meshes/"; MOD_ICON_PATH = MOD_FOLDER + "gamedata/textures/icons/"; MOD_CUSTOM_TEXTURE_PATH = MOD_FOLDER + "gamedata/textures/custom/"; DecorLogger.LogToFile("Mod Instalation Directory: " + MOD_FOLDER); DecorLogger.LogToFile("Mod Mesh Directory: " + MOD_MESH_PATH); DecorLogger.LogToFile("Mod Icon Directory: " + MOD_ICON_PATH); DecorLogger.LogToFile("Game Root Directory: " + GAME_ROOT); DecorLogger.LogToFile("Game Gamedata Directory: " + GAMEDATA_FOLDER); DecorLogger.LogToFile("Game Savegame Directory: " + GAME_SAVES); BASE_FILE = MOD_FOLDER + BASE_FILE_NAME; EXAMPLE_FILE = MOD_FOLDER + EXAMPLE_FILE_NAME; if (!File.Exists(BASE_FILE)) { File.Copy(EXAMPLE_FILE, BASE_FILE); } //DecorLogger.LogToFile("Types in TypeList" + TypeList); }
public static void AfterWorldLoad() { if (NewWorld) { DecorConfigFileTrue = false; if (!Directory.Exists(GAME_SAVEFILE)) { return; } if (!File.Exists(NEW_FILE)) { DecorLogger.LogToFile("Decor Config file not found for save game " + ServerManager.WorldName + " named " + FILE_NAME); if (File.Exists(EXAMPLE_FILE)) { DecorLogger.LogToFile("Example Decor File Found"); File.Copy(EXAMPLE_FILE, NEW_FILE); DecorLogger.LogToFile("Example File Coppied to savegame"); ServerLog.LogAsyncMessage(new LogMessage("<color = blue>Restart server/game for decor mod to be functional</color>", LogType.Log)); NewDecorConfigFileTrue = true; } else { DecorLogger.LogToFile("Example Decor File not found can not copy file"); DecorConfigFileTrue = false; return; } } DecorLogger.LogToFile("Decor Config file found for save game " + ServerManager.WorldName + " named " + FILE_NAME); var fileContents = File.ReadAllText(NEW_FILE); DecorTypes = JsonConvert.DeserializeObject <Dictionary <string, List <DecorType> > >(fileContents); foreach (string type in TypeList) { if (!DecorTypes.ContainsKey(type)) { DecorTypes.Add(type, null); } } fileContents = JsonConvert.SerializeObject(DecorTypes); File.WriteAllText(NEW_FILE, fileContents); using (StreamWriter outputFile = new StreamWriter(Path.Combine(GenerateTypeConfig.GAME_SAVEFILE, "TypeList.txt"))) { outputFile.WriteLine(""); } } DecorLogger.LogToFile("TypeList.txt Contents: " + File.ReadAllText(GenerateTypeConfig.GAME_SAVEFILE + "TypeList.txt")); }
public static void AddTextureMappingEntries() { string[] files = Directory.GetFiles(GenerateTypeConfig.MOD_CUSTOM_TEXTURE_PATH); foreach (string file in files) { if (file.EndsWith(GenerateTypeConfig.ICONTYPE)) { TextureList.Add(file); var texture = file.Replace(GenerateTypeConfig.ICONTYPE, ""); texture = texture.Replace(GenerateTypeConfig.MOD_CUSTOM_TEXTURE_PATH, ""); DecorLogger.LogToFile("Adding Texture: \"" + texture + "\" to TextureList"); } } foreach (string texture in TextureList) { var newTexture = new TextureBase(); newTexture.name = "Nach0Decor." + texture; } }
public static void generateTypes(string name, List <Colliders.Boxes> colliders) { using (StreamWriter outputFile = new StreamWriter(System.IO.Path.Combine(GenerateTypeConfig.GAME_SAVEFILE, "TypeList.txt"), true)) { outputFile.WriteLine(name + " types:"); } DecorLogger.LogToFile("Begining " + name + " generation"); List <string> typesAdded = new List <string>(); List <string> categories = new List <string>(categoryBase.categories); categories.Add(name); if (name != "Slab") { JSONNode list = new JSONNode(NodeType.Array); var Typesbase = new DecorTypeSpecs(); Typesbase.baseType.colliders.boxes = colliders; Typesbase.baseType.mesh = GenerateTypeConfig.MOD_MESH_PATH + name + GenerateTypeConfig.MESHTYPE; if (!File.Exists(GenerateTypeConfig.MOD_ICON_PATH + name + GenerateTypeConfig.ICONTYPE)) { Typesbase.baseType.icon = GenerateTypeConfig.MOD_ICON_PATH + "_NoIcon" + GenerateTypeConfig.ICONTYPE; } else { Typesbase.baseType.icon = GenerateTypeConfig.MOD_ICON_PATH + name + GenerateTypeConfig.ICONTYPE; } if (GenerateTypeConfig.DecorTypes.TryGetValue("_ALL", out List <DecorType> allBlockTypes)) { foreach (var currentType in allBlockTypes) { var typeName = GenerateTypeConfig.TYPEPREFIX + name + "." + currentType.name; if (!typesAdded.Contains(typeName)) { DecorLogger.LogToFile("Generating type \"" + typeName + "\" with \"name\": \"" + currentType.name + "\" \"type\": \"" + currentType.type + "\" \"texture\": \"" + currentType.texture + "\""); Typesbase.typeName = typeName; Typesbase.baseType.categories = new List <string>(categories); Typesbase.baseType.categories.Add(currentType.texture); Typesbase.baseType.sideall = currentType.texture; list.AddToArray(Typesbase.JsonSerialize()); typesAdded.Add(typeName); DecorLogger.LogToFile("JSON - " + Typesbase.JsonSerialize().ToString()); using (StreamWriter outputFile = new StreamWriter(System.IO.Path.Combine(GenerateTypeConfig.GAME_SAVEFILE, "TypeList.txt"), true)) { outputFile.WriteLine("Type \"" + typeName + "\" has texture \"" + currentType.texture + "\""); } } else { DecorLogger.LogToFile("Type with \"name\": \"" + currentType.name + "\" already exists for \"" + name + "\" check decor file for duplicates, type skipped"); } } } if (GenerateTypeConfig.DecorTypes.TryGetValue(name, out List <DecorType> blockTypes)) { foreach (var currentType in blockTypes) { var typeName = GenerateTypeConfig.TYPEPREFIX + name + "." + currentType.name; if (!typesAdded.Contains(typeName)) { DecorLogger.LogToFile("Generating type \"" + typeName + "\" with \"name\": \"" + currentType.name + "\" \"type\": \"" + currentType.type + "\" \"texture\": \"" + currentType.texture + "\""); Typesbase.typeName = typeName; Typesbase.baseType.categories = categories; Typesbase.baseType.categories.Add(currentType.texture); Typesbase.baseType.sideall = currentType.texture; list.AddToArray(Typesbase.JsonSerialize()); typesAdded.Add(typeName); DecorLogger.LogToFile("JSON - " + Typesbase.JsonSerialize().ToString()); using (StreamWriter outputFile = new StreamWriter(System.IO.Path.Combine(GenerateTypeConfig.GAME_SAVEFILE, "TypeList.txt"), true)) { outputFile.WriteLine("Type \"" + typeName + "\" has texture \"" + currentType.texture + "\""); } } else { DecorLogger.LogToFile("Type with \"name\": \"" + currentType.name + "\" already exists for \"" + name + "\" check decor file for duplicates, type skipped"); } } } ItemTypesServer.BlockRotator.Patches.AddPatch(new ItemTypesServer.BlockRotator.BlockGeneratePatch(GenerateTypeConfig.MOD_FOLDER, -99999, list)); } else { var TypeParent = new DecorTypeBase(); TypeParent.icon = GenerateTypeConfig.MOD_ICON_PATH + name + GenerateTypeConfig.ICONTYPE; var TypeUp = new DecorTypeBase(); TypeUp.mesh = GenerateTypeConfig.MOD_MESH_PATH + name + ".up" + GenerateTypeConfig.MESHTYPE; TypeUp.colliders.boxes = typeColliders.Colliders_Dict[name + "Up"]; var TypeDown = new DecorTypeBase(); TypeUp.mesh = GenerateTypeConfig.MOD_MESH_PATH + name + ".down" + GenerateTypeConfig.MESHTYPE; TypeUp.colliders.boxes = typeColliders.Colliders_Dict[name + "Down"]; if (GenerateTypeConfig.DecorTypes.TryGetValue("_ALL", out List <DecorType> allBlockTypes)) { foreach (var currentType in allBlockTypes) { var typeName = GenerateTypeConfig.TYPEPREFIX + name + "." + currentType.name; var typeDownName = typeName + ".down"; var typeUpName = typeName + ".up"; if (!typesAdded.Contains(typeName)) { DecorLogger.LogToFile("Generating type \"" + typeName + "\" with \"name\": \"" + currentType.name + "\" \"type\": \"" + currentType.type + "\" \"texture\": \"" + currentType.texture + "\""); TypeParent.name = typeName; TypeParent.categories = new List <string>(categories); TypeParent.categories.Add(currentType.texture); TypeParent.sideall = currentType.texture; TypeParent.rotatablexn = typeUpName; TypeParent.rotatablexp = typeUpName; TypeParent.rotatablezn = typeDownName; TypeParent.rotatablezp = typeDownName; TypeUp.name = typeUpName; TypeDown.name = typeDownName; typesAdded.Add(typeName); DecorLogger.LogToFile("JSON - " + TypeParent.JsonSerialize().ToString()); using (StreamWriter outputFile = new StreamWriter(System.IO.Path.Combine(GenerateTypeConfig.GAME_SAVEFILE, "TypeList.txt"), true)) { outputFile.WriteLine("Type \"" + typeName + "\" has texture \"" + currentType.texture + "\""); } } else { DecorLogger.LogToFile("Type with \"name\": \"" + currentType.name + "\" already exists for \"" + name + "\" check decor file for duplicates, type skipped"); } } } } using (StreamWriter outputFile = new StreamWriter(System.IO.Path.Combine(GenerateTypeConfig.GAME_SAVEFILE, "TypeList.txt"), true)) { outputFile.WriteLine(""); } }
public static void generateRecipes(string name) { DecorLogger.LogToFile("Begining " + name + " recipe generation"); List <string> recipesAdded = new List <string>(); if (GenerateTypeConfig.DecorTypes.TryGetValue("_ALL", out List <DecorType> allBlockTypes)) { foreach (var currentType in allBlockTypes) { var typeName = GenerateTypeConfig.TYPEPREFIX + name + "." + currentType.name; var typeNameRecipe = typeName + ".Recipe"; if (!recipesAdded.Contains(typeNameRecipe)) { DecorLogger.LogToFile("Generating recipe " + typeNameRecipe); var recipe = new TypeRecipeBase(); recipe.name = typeNameRecipe; recipe.requires.Add(new RecipeItem(currentType.type)); recipe.results.Add(new RecipeResult(typeName)); var requirements = new List <InventoryItem>(); var results = new List <RecipeResult>(); recipe.JsonSerialize(); DecorLogger.LogToFile("JSON - " + recipe.JsonSerialize().ToString()); foreach (var ri in recipe.requires) { if (ItemTypes.IndexLookup.TryGetIndex(ri.type, out var itemIndex)) { requirements.Add(new InventoryItem(itemIndex, ri.amount)); } else { DecorLogger.LogToFile("\"" + typeNameRecipe + "\" bad requirement \"" + ri.type + "\""); } } foreach (var ri in recipe.results) { results.Add(ri); } var newRecipe = new Recipe(recipe.name, requirements, results, recipe.defaultLimit, 0, (int)recipe.defaultPriority); ServerManager.RecipeStorage.AddLimitTypeRecipe(recipe.Job, newRecipe); } } } if (GenerateTypeConfig.DecorTypes.TryGetValue(name, out List <DecorType> blockTypes)) { foreach (var currentType in blockTypes) { var typeName = GenerateTypeConfig.TYPEPREFIX + name + "." + currentType.name; var typeNameRecipe = typeName + ".Recipe"; if (!recipesAdded.Contains(typeNameRecipe)) { DecorLogger.LogToFile("Generating recipe " + typeNameRecipe); var recipe = new TypeRecipeBase(); recipe.name = typeNameRecipe; recipe.requires.Add(new RecipeItem(currentType.type)); recipe.results.Add(new RecipeResult(typeName)); var requirements = new List <InventoryItem>(); var results = new List <RecipeResult>(); recipe.JsonSerialize(); DecorLogger.LogToFile("JSON - " + recipe.JsonSerialize().ToString()); foreach (var ri in recipe.requires) { if (ItemTypes.IndexLookup.TryGetIndex(ri.type, out var itemIndex)) { requirements.Add(new InventoryItem(itemIndex, ri.amount)); } else { DecorLogger.LogToFile("\"" + typeNameRecipe + "\" bad requirement \"" + ri.type + "\""); } } foreach (var ri in recipe.results) { results.Add(ri); } var newRecipe = new Recipe(recipe.name, requirements, results, recipe.defaultLimit, 0, (int)recipe.defaultPriority); ServerManager.RecipeStorage.AddLimitTypeRecipe(recipe.Job, newRecipe); } } } }
public bool TryDoCommand(Players.Player player, string chat, List <string> splits) { //ServerLog.LogAsyncMessage(new LogMessage("Command Imput: " + chat, LogType.Log)); if (player == null) { return(false); } if (chat.StartsWith("/decoradd")) { DecorLogger.LogToFile("Command Attempt: " + chat + " by player: " + player.ID); if (PermissionsManager.CheckAndWarnPermission(player, "NACH0.Decor.Add") || ServerManager.HostingSettings.NetworkType == Shared.Options.EServerNetworkType.Singleplayer) { DecorLogger.LogToFile("Command Attempt: " + chat); var inventorySlot1 = player.Inventory.Items[0]; var typeName = ItemTypes.GetType(inventorySlot1.Type).Name; var typeCategories = ItemTypes.GetType(inventorySlot1.Type).Categories; var typeIsPlaceable = ItemTypes.GetType(inventorySlot1.Type).IsPlaceable; var typeSideAll = ItemTypes.GetType(inventorySlot1.Type).SideAll; var typeAmounnt = inventorySlot1.Amount; if (typeAmounnt != 0 && typeCategories != null && typeSideAll != null && typeIsPlaceable) { DecorLogger.LogToFile("Type in inventory Slot 1: " + typeName); Chat.Send(player, "<color=blue>Type in inventory Slot 1: " + typeName + "</color>"); var requestedDecorType = chat.Replace("/decoradd2", ""); requestedDecorType = requestedDecorType.Replace("/decoradd", ""); requestedDecorType = requestedDecorType.Replace(" ", ""); var decorType = ""; if (requestedDecorType != "") { DecorLogger.LogToFile("Requested Decor Type: " + requestedDecorType); foreach (string type in GenerateTypeConfig.TypeList) { if (requestedDecorType == type) { DecorLogger.LogToFile("Requested Decor Type is same as Decor Type: " + type); decorType = type; } } if (decorType == "") { //ServerLog.LogAsyncMessage(new LogMessage("Type " + requestedDecorType + " does not exist, defaulting to _ALL", LogType.Log)); DecorLogger.LogToFile("Type " + requestedDecorType + " does not exist, stopping command"); Chat.Send(player, "<color=blue>Type " + requestedDecorType + " does not exist, stopping command</color>"); return(false); } } else { decorType = "_ALL"; } //ServerLog.LogAsyncMessage(new LogMessage("typetoadd = " + typeToAddTo, LogType.Log)); if (GenerateTypeConfig.DecorTypes.TryGetValue(decorType, out List <DecorType> blockTypes)) { foreach (var currentType in blockTypes) { if (currentType.texture == typeSideAll) { DecorLogger.LogToFile("There is already a registered type in " + decorType + " that has the texture: " + currentType.texture); Chat.Send(player, "<color=blue>There is already a registered type in " + decorType + " that has the texture: " + currentType.texture + "</color>"); return(false); } if (currentType.name == typeName) { DecorLogger.LogToFile("There is already a registered type in " + decorType + " that has the name: " + currentType.name); Chat.Send(player, "<color=blue>There is already a registered type in " + decorType + " that has the name: " + currentType.name + "</color>"); return(false); } } DecorType newDecorTypeProperties = new DecorType(); newDecorTypeProperties.name = typeName; newDecorTypeProperties.type = typeName; newDecorTypeProperties.texture = typeSideAll; newDecorTypeProperties.name = newDecorTypeProperties.name.Replace("NACH0.Types.", ""); newDecorTypeProperties.name = newDecorTypeProperties.name.Replace("Pandaros.Settlers.AutoLoad.", ""); newDecorTypeProperties.name = newDecorTypeProperties.name.Replace("Pandaros.Settlers.", ""); newDecorTypeProperties.name = newDecorTypeProperties.name.Replace("Ulfric.ColonyAddOns.Blocks.", ""); GenerateTypeConfig.DecorTypes[decorType].Add(newDecorTypeProperties); var jsonWithAddedType = JsonConvert.SerializeObject(GenerateTypeConfig.DecorTypes, Formatting.Indented); File.WriteAllText(GenerateTypeConfig.NEW_FILE, jsonWithAddedType); DecorLogger.LogToFile("Added " + newDecorTypeProperties.type + " to " + decorType); Chat.Send(player, "<color=blue>" + "Added " + newDecorTypeProperties.type + " to " + decorType + "</color>"); Chat.Send(player, "<color=blue>World/Server needs to be restarted to see new type, world is still playable and more can be added before restarting</color>"); return(true); //ServerLog.LogAsyncMessage(new LogMessage("Texture and name do not exist, able to add new type", LogType.Log)); } } else { if (typeAmounnt == 0) { Chat.Send(player, "<color=blue>Slot 1 is empty</color>"); } else { if (typeCategories == null) { Chat.Send(player, "<color=blue>Type in slot one had no categories (its a non obtainable type)</color>"); } if (!typeIsPlaceable) { Chat.Send(player, "<color=blue>Type in slot one is a item not a block</color>"); } if (typeSideAll == null) { Chat.Send(player, "<color=blue>Type in slot one does not have a sideall texture</color>"); } } } } else { Chat.Send(player, "<color=blue>You do not have required permissions</color>"); } } return(false); }
public static void AfterSelectedWorld() { DecorLogger.LogToFile("MOD VERSION = " + MOD_VERSION); string[] files = Directory.GetFiles(MOD_MESH_PATH); //DecorLogger.LogToFile("Files in Mod Mesh Directory" + files); foreach (string file in files) { if (file.EndsWith(MESHTYPE)) { var type = file.Replace(MESHTYPE, ""); type = type.Replace(MOD_MESH_PATH, ""); TypeList.Add(type); DecorLogger.LogToFile("Adding Type: \"" + type + "\" to typeList"); } } GAME_SAVEFILE = GAME_SAVES + ServerManager.WorldName + "/"; NEW_FILE = GAME_SAVEFILE + FILE_NAME; DecorLogger.LogToFile("Game SaveFile Directory: " + GAME_SAVEFILE); if (!Directory.Exists(GAME_SAVEFILE)) { Directory.CreateDirectory(GAME_SAVEFILE); //NewWorld = true; //return; } if (!File.Exists(NEW_FILE)) { DecorLogger.LogToFile("Decor Config file not found for save game " + ServerManager.WorldName + " named " + FILE_NAME); if (File.Exists(BASE_FILE)) { DecorLogger.LogToFile("Example Decor File Found"); File.Copy(BASE_FILE, NEW_FILE); DecorLogger.LogToFile("Example File Coppied to savegame"); //ServerLog.LogAsyncMessage(new LogMessage("<color = blue>Restart server/game for decor mod to be functional</color>", LogType.Log)); NewDecorConfigFileTrue = true; DecorConfigFileTrue = true; } else { DecorLogger.LogToFile("Example Decor File not found can not copy file"); DecorConfigFileTrue = false; return; } } DecorConfigFileTrue = true; DecorLogger.LogToFile("Decor Config file found for save game " + ServerManager.WorldName + " named " + FILE_NAME); var fileContents = File.ReadAllText(NEW_FILE); DecorLogger.LogToFile("DecorTypes.json Contents: " + fileContents); DecorTypes = JsonConvert.DeserializeObject <Dictionary <string, List <DecorType> > >(fileContents); using (StreamWriter outputFile = new StreamWriter(Path.Combine(GenerateTypeConfig.GAME_SAVEFILE, "TypeList.txt"))) { outputFile.WriteLine(""); } /*SETTINGS_FILE = GAME_SAVEFILE + "DecorSettings.json"; * if (!File.Exists(SETTINGS_FILE)) * { * if (ServerManager.HostingSettings.NetworkType == Shared.Options.EServerNetworkType.Singleplayer) * { * DecorSettings["Singleplayer"] = true; * } * else * { * DecorSettings["Singleplayer"] = false; * } * var settingsJSON = JsonConvert.SerializeObject(DecorSettings, Formatting.Indented); * File.WriteAllText(SETTINGS_FILE, settingsJSON); * } * else * { * var settingsFileContents = File.ReadAllText(SETTINGS_FILE); * DecorSettings = JsonConvert.DeserializeObject<Dictionary<string, bool>>(settingsFileContents); * }*/ }