HISP/Horse Isle Server/Horse Isle Server/Gamedata.cs
SilicaAndPina 30c0be0020 update
2020-10-01 12:21:14 +13:00

98 lines
4.1 KiB
C#

using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Horse_Isle_Server
{
class Gamedata
{
public static void ReadGamedata()
{
if(!File.Exists(ConfigReader.GameDataFile))
{
Logger.ErrorPrint("Game Data JSON File: " + ConfigReader.GameDataFile + " Does not exist!");
return;
}
string jsonData = File.ReadAllText(ConfigReader.GameDataFile);
dynamic gameData = JsonConvert.DeserializeObject(jsonData);
// Register Towns
int totalTowns = gameData.places.towns.Count;
for (int i = 0; i < totalTowns; i++)
{
World.Town town = new World.Town();
town.StartX = gameData.places.towns[i].start_x;
town.StartY = gameData.places.towns[i].start_y;
town.EndX = gameData.places.towns[i].end_x;
town.EndY = gameData.places.towns[i].end_y;
town.Name = gameData.places.towns[i].name;
Logger.DebugPrint("Registered Town: " + town.Name + " X " + town.StartX + "-" + town.EndX + " Y " + town.StartY + "-" + town.EndY);
World.Towns.Add(town);
}
// Register Areas
int totalAreas = gameData.places.towns.Count;
for (int i = 0; i < totalAreas; i++)
{
World.Area area = new World.Area();
area.StartX = gameData.places.areas[i].start_x;
area.StartY = gameData.places.areas[i].start_y;
area.EndX = gameData.places.areas[i].end_x;
area.EndY = gameData.places.areas[i].end_y;
area.Name = gameData.places.areas[i].name;
Logger.DebugPrint("Registered Area: " + area.Name + " X " + area.StartX + "-" + area.EndX + " Y " + area.StartY + "-" + area.EndY);
World.Areas.Add(area);
}
// Register Isles
int totalIsles = gameData.places.isles.Count;
for(int i = 0; i < totalIsles; i++)
{
World.Isle isle = new World.Isle();
isle.StartX = gameData.places.isles[i].start_x;
isle.StartY = gameData.places.isles[i].start_y;
isle.EndX = gameData.places.isles[i].end_x;
isle.EndY = gameData.places.isles[i].end_y;
isle.Tileset = gameData.places.isles[i].tileset;
isle.Name = gameData.places.isles[i].name;
Logger.DebugPrint("Registered Isle: " + isle.Name + " X " + isle.StartX + "-" + isle.EndX + " Y " + isle.StartY + "-" + isle.EndY + " tileset: " + isle.Tileset);
World.Isles.Add(isle);
}
Messages.NewUserMessage = gameData.new_user.starting_message;
Map.NewUserStartX = gameData.new_user.starting_x;
Map.NewUserStartY = gameData.new_user.starting_y;
Messages.LoginFormat = gameData.messages.login_format;
Messages.MotdFormat = gameData.messages.motd_format;
Messages.ProfileSavedMessage = gameData.messages.profile_save;
Messages.IsleFormat = gameData.messages.meta.isle_format;
Messages.TownFormat = gameData.messages.meta.town_format;
Messages.AreaFormat = gameData.messages.meta.area_format;
Messages.LocationFormat = gameData.messages.meta.location_format;
Messages.Sepeerator = gameData.messages.meta.seperator;
Messages.TileFormat = gameData.messages.meta.tile_format;
Messages.NothingMessage = gameData.messages.meta.nothing_message;
Map.OverlayTileDepth = gameData.tile_paramaters.overlay_tiles.tile_depth.ToObject<int[]>();
Map.OverlayTilesetPassibility = gameData.tile_paramaters.overlay_tiles.passibility.ToObject<bool[][]>();
Map.TerrainTilePassibility = gameData.tile_paramaters.terrain_tiles.passibility.ToObject<bool[]>();
}
}
}