コード例 #1
0
        public static void LoadConfig(string path)
        {
            players = new Dictionary <string, PlayerConfig>();

            var data = JObject.Parse(File.ReadAllText(path));

            // Read the player configuration
            var playerConfigurations = data.SelectToken("players");

            foreach (var player in playerConfigurations)
            {
                var playerConfig = new PlayerConfig(player);
                players.Add(string.Format("player{0}", players.Count + 1), playerConfig);
            }

            // Read the game configuration
            var game = data.SelectToken("game");

            gameConfig = new GameConfig(game);

            // Read spawns info
            contentManager = new ContentManager();
            var mapPath = contentManager.GetMapDataPath(gameConfig.map);
            var mapData = JObject.Parse(File.ReadAllText(mapPath));
            var spawns  = mapData.SelectToken("spawns");

            mapSpawns = new MapSpawns();
            foreach (JProperty teamSpawn in spawns)
            {
                var team = teamSpawn.Name;
                var spawnsByPlayerCount = (JArray)teamSpawn.Value;
                for (var i = 0; i < spawnsByPlayerCount.Count; i++)
                {
                    var playerSpawns = new PlayerSpawns((JArray)spawnsByPlayerCount[i]);
                    mapSpawns.SetSpawns(team, playerSpawns, i);
                }
            }
        }
コード例 #2
0
ファイル: Config.cs プロジェクト: horato/IntWarsSharp
        public static void LoadConfig()
        {
            players = new Dictionary<string, PlayerConfig>();
            var script = new LuaScript();

            script.loadScript(System.IO.Path.Combine(Program.ExecutingDirectory, "lua", "config.lua"));

            var playerList = script.getTableDictionary("players");

            for (int i = 1; i < 12; i++)
            {
                var playerIndex = "player" + i;
                if (!playerList.ContainsKey(playerIndex))
                    continue;
                var player = playerList[playerIndex] as LuaTable;
                if (player == null)
                    continue;

                var config = new PlayerConfig();

                foreach (var p in script.getTableDictionary(player))
                {
                    switch (p.Key.ToString().ToLower())
                    {
                        case "rank":
                            config.rank = p.Value.ToString();
                            break;
                        case "name":
                            config.name = p.Value.ToString();
                            break;
                        case "champion":
                            config.champion = p.Value.ToString();
                            break;
                        case "team":
                            config.team = p.Value.ToString();
                            break;
                        case "skin":
                            config.skin = short.Parse(p.Value.ToString());
                            break;
                        case "summoner1":
                            config.summoner1 = p.Value.ToString();
                            break;
                        case "summoner2":
                            config.summoner2 = p.Value.ToString();
                            break;
                        case "ribbon":
                            config.ribbon = short.Parse(p.Value.ToString());
                            break;
                        case "icon":
                            config.icon = int.Parse(p.Value.ToString());
                            break;
                        default:
                            Logger.LogCoreInfo("Unknown player config " + p.Key.ToString());
                            break;
                    }
                }
                players.Add(playerIndex, config);
            }

            gameConfig = new GameConfig();
            var game = script.getTableDictionary("game");
            foreach (var g in game)
            {
                switch (g.Key.ToString().ToLower())
                {
                    case "map":
                        gameConfig.map = g.Value.ToString();
                        break;
                    default:
                        Logger.LogCoreInfo("Unknown game config " + g.Key.ToString());
                        break;
                }
            }

            mapSpawns = new MapSpawns();
            script.loadScript(System.IO.Path.Combine(Program.ExecutingDirectory, "lua", "maps", "map" + gameConfig.map + ".lua"));
            var teams = script.getTableDictionary("spawnpoints");
            foreach (var team in teams)
            {
                var teamColor = team.Key.ToString().ToLower();
                var numOfPlayers = team.Value as LuaTable;
                if (numOfPlayers == null)
                    continue;

                foreach (var num in script.getTableDictionary(numOfPlayers))
                {
                    var number = int.Parse(num.Key.ToString());
                    var spawns = num.Value as LuaTable;
                    if (spawns == null)
                        continue;
                    var playerSpawns = new PlayerSpawns();

                    foreach (var spawn in script.getTableDictionary(spawns))
                    {
                        var spawnName = spawn.Key;
                        var spawnPoint = int.Parse(spawn.Value.ToString());
                        switch (spawnName.ToString().ToLower())
                        {
                            case "player1x":
                                playerSpawns.player1X = spawnPoint;
                                break;
                            case "player1y":
                                playerSpawns.player1Y = spawnPoint;
                                break;
                            case "player2x":
                                playerSpawns.player2X = spawnPoint;
                                break;
                            case "player2y":
                                playerSpawns.player2Y = spawnPoint;
                                break;
                            case "player3x":
                                playerSpawns.player3X = spawnPoint;
                                break;
                            case "player3y":
                                playerSpawns.player3Y = spawnPoint;
                                break;
                            case "player4x":
                                playerSpawns.player4X = spawnPoint;
                                break;
                            case "player4y":
                                playerSpawns.player4Y = spawnPoint;
                                break;
                            case "player5x":
                                playerSpawns.player5X = spawnPoint;
                                break;
                            case "player5y":
                                playerSpawns.player5Y = spawnPoint;
                                break;
                            case "player6x":
                                playerSpawns.player6X = spawnPoint;
                                break;
                            case "player6y":
                                playerSpawns.player6Y = spawnPoint;
                                break;
                        }
                    }

                    switch (teamColor)
                    {
                        case "blue":
                            mapSpawns.blue.Add(number, playerSpawns);
                            break;
                        case "purple":
                            mapSpawns.purple.Add(number, playerSpawns);
                            break;
                    }
                }
            }
        }
コード例 #3
0
ファイル: Config.cs プロジェクト: NitroXenon/IntWarsSharp
        public static void LoadConfig()
        {
            players = new Dictionary <string, PlayerConfig>();
            var script = new LuaScript();

            script.loadScript(System.IO.Path.Combine(Program.ExecutingDirectory, "lua", "config.lua"));

            var playerList = script.getTableDictionary("players");

            for (int i = 1; i < 12; i++)
            {
                var playerIndex = "player" + i;
                if (!playerList.ContainsKey(playerIndex))
                {
                    continue;
                }
                var player = playerList[playerIndex] as LuaTable;
                if (player == null)
                {
                    continue;
                }

                var config = new PlayerConfig();

                foreach (var p in script.getTableDictionary(player))
                {
                    switch (p.Key.ToString().ToLower())
                    {
                    case "rank":
                        config.rank = p.Value.ToString();
                        break;

                    case "name":
                        config.name = p.Value.ToString();
                        break;

                    case "champion":
                        config.champion = p.Value.ToString();
                        break;

                    case "team":
                        config.team = p.Value.ToString();
                        break;

                    case "skin":
                        config.skin = short.Parse(p.Value.ToString());
                        break;

                    case "summoner1":
                        config.summoner1 = p.Value.ToString();
                        break;

                    case "summoner2":
                        config.summoner2 = p.Value.ToString();
                        break;

                    case "ribbon":
                        config.ribbon = short.Parse(p.Value.ToString());
                        break;

                    case "icon":
                        config.icon = int.Parse(p.Value.ToString());
                        break;

                    default:
                        Logger.LogCoreInfo("Unknown player config " + p.Key.ToString());
                        break;
                    }
                }
                players.Add(playerIndex, config);
            }

            gameConfig = new GameConfig();
            var game = script.getTableDictionary("game");

            foreach (var g in game)
            {
                switch (g.Key.ToString().ToLower())
                {
                case "map":
                    gameConfig.map = g.Value.ToString();
                    break;

                default:
                    Logger.LogCoreInfo("Unknown game config " + g.Key.ToString());
                    break;
                }
            }

            mapSpawns = new MapSpawns();
            script.loadScript(System.IO.Path.Combine(Program.ExecutingDirectory, "lua", "maps", "map" + gameConfig.map + ".lua"));
            var teams = script.getTableDictionary("spawnpoints");

            foreach (var team in teams)
            {
                var teamColor    = team.Key.ToString().ToLower();
                var numOfPlayers = team.Value as LuaTable;
                if (numOfPlayers == null)
                {
                    continue;
                }

                foreach (var num in script.getTableDictionary(numOfPlayers))
                {
                    var number = int.Parse(num.Key.ToString());
                    var spawns = num.Value as LuaTable;
                    if (spawns == null)
                    {
                        continue;
                    }
                    var playerSpawns = new PlayerSpawns();

                    foreach (var spawn in script.getTableDictionary(spawns))
                    {
                        var spawnName  = spawn.Key;
                        var spawnPoint = int.Parse(spawn.Value.ToString());
                        switch (spawnName.ToString().ToLower())
                        {
                        case "player1x":
                            playerSpawns.player1X = spawnPoint;
                            break;

                        case "player1y":
                            playerSpawns.player1Y = spawnPoint;
                            break;

                        case "player2x":
                            playerSpawns.player2X = spawnPoint;
                            break;

                        case "player2y":
                            playerSpawns.player2Y = spawnPoint;
                            break;

                        case "player3x":
                            playerSpawns.player3X = spawnPoint;
                            break;

                        case "player3y":
                            playerSpawns.player3Y = spawnPoint;
                            break;

                        case "player4x":
                            playerSpawns.player4X = spawnPoint;
                            break;

                        case "player4y":
                            playerSpawns.player4Y = spawnPoint;
                            break;

                        case "player5x":
                            playerSpawns.player5X = spawnPoint;
                            break;

                        case "player5y":
                            playerSpawns.player5Y = spawnPoint;
                            break;

                        case "player6x":
                            playerSpawns.player6X = spawnPoint;
                            break;

                        case "player6y":
                            playerSpawns.player6Y = spawnPoint;
                            break;
                        }
                    }

                    switch (teamColor)
                    {
                    case "blue":
                        mapSpawns.blue.Add(number, playerSpawns);
                        break;

                    case "purple":
                        mapSpawns.purple.Add(number, playerSpawns);
                        break;
                    }
                }
            }
        }