Ejemplo n.º 1
0
        /// <summary>
        /// Gets the next map in the cycle
        /// </summary>
        /// <param name="addHistory">If the map is to be added to the history list</param>
        /// <returns></returns>
        public string NextMap(bool addHistory)
        {
            string map = null;

            if (Mode != MapMode.Cycle)
            {
                throw new InvalidOperationException("NextMap is only used for cycle mode.");
            }

            //Retrieve the most recent map in history.
            var lastMap = History.LastOrDefault();

            //Ensure that history actually contains maps.
            if (lastMap != null)
            {
                bool isNext = false;
                for (int i = 0; i < Maps.Count; i++)
                {
                    var mapName = Maps.ElementAt(i);
                    if (isNext)
                    {
                        map    = mapName;
                        isNext = false;
                        break;
                    }
                    if (mapName == lastMap)
                    {
                        isNext = true;
                    }
                }

                if (isNext)
                {
                    //As there was no selected map (last element was reached)
                    //Use the first map in the cycle
                    map = Maps.FirstOrDefault();
                }
            }
            else
            {
                //Initialize history with the first map.
                map = Maps.FirstOrDefault();
            }

            if (map != null && addHistory)
            {
                AddToHistory(map);
            }
            return(map);
        }
Ejemplo n.º 2
0
        private async Task SaveFile()
        {
            DataLoaded = false;
            StatusText = "Saving...";
            ///* Might need something like this to prevent bad data.
            for (int m = 0; m < Maps.Count(); m++)
            {
                for (int i = 0; i < Maps.ElementAt(m).MapBlockValues.Count(); i++)
                {
                    if (Maps.ElementAt(m).MapBlockValues[i] >= BlockSets.ElementAt((int)Maps.ElementAt(m).TileSetID).Tiles.Count())
                    {
                        Maps.ElementAt(m).MapBlockValues[i] = 0;
                    }
                }
            }
            //*/
            await Task.Run(() => romConverter.SaveROMDataToFile(romFile, Moves, Pokemons, TypeStrengths, AllTMs, EncounterZones, Trainers, Shops, Items, Maps, PokeTypes));

            DataLoaded = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Start or continue a running game process
        /// </summary>
        public static async Task ContinueGame()
        {
            try
            {
                if (!isBuilding)
                {
                    isBuilding    = true;
                    isGameAborted = new CancellationTokenSource();

                    if (Tick != null)
                    {
                        Tick.Stop();
                    }
                    if (Eliminator != null)
                    {
                        Eliminator.Stop();
                    }
                    if (TimeLimit != null)
                    {
                        TimeLimit.Stop();
                    }

                    await HideMapVoters();
                    await ClearGameArea();

                    await Task.Delay(6000, isGameAborted.Token);

                    int maxVotes = 0;
                    var chose    = new List <MapInfo>();
                    foreach (MapVote mv in MapVoteSigns)
                    {
                        if (maxVotes < mv.Voters.Count)
                        {
                            maxVotes = mv.Voters.Count;
                            chose.Clear();
                            chose.Add(Maps.FirstOrDefault(map => map.Id == mv.MapId));
                        }
                        else if (maxVotes == mv.Voters.Count)
                        {
                            chose.Add(Maps.FirstOrDefault(map => map.Id == mv.MapId));
                        }
                    }

                    MapInfo newMap = Maps.ElementAt(0);
                    if (chose.Count == 1)
                    {
                        newMap = chose.ElementAt(0);
                    }
                    else if (chose.Count > 1)
                    {
                        newMap = chose.ElementAt(new Random().Next(0, chose.Count));
                    }

                    await PlaceSign(TopLeftShiftCoord.X + 16, TopLeftShiftCoord.Y + 22, 58, $"You'll be playing now:\n{newMap.Title}\nBy {newMap.Creator}\n[Difficulty: {newMap.Difficulty}]", 1);
                    await BuildMap(newMap, isGameAborted.Token);
                    await CreateExit();

                    {
                        Formatter[] format =
                        {
                            new Formatter(newMap.Title,         Color.Cyan),
                            new Formatter(newMap.Id.ToString(), Color.Gray),
                            new Formatter(newMap.Creator,       Color.Cyan),
                        };

                        Console.WriteLineFormatted("  Map {0} ({1}) By {2}", Color.Silver, format);
                    }


                    if (PlayersSafe.Count < 2)
                    {
                        round = 1;

                        PlayersInGame = new List <Player>();
                        PlayersSafe   = new Dictionary <Player, TimeSpan>();

                        foreach (Player p in Players)
                        {
                            if (!p.Afk)
                            {
                                await SayCommand($"reset {p.Name}");
                                await SayCommand($"tp {p.Name} {TopLeftShiftCoord.X + 16} {TopLeftShiftCoord.Y + 22}");

                                PlayersInGame.Add(p);
                            }
                        }

                        if (PlayersInGame.Count < 4)
                        {
                            isTrainMode = true;
                            await Say($"Not enough players! Traning mode is enabled! Statistics will not be updated!");
                        }
                        else
                        {
                            isTrainMode = !isSavingData; // If you are saving data (true) then training mode is not (false), then data is saved!
                            if (isTrainMode)
                            {
                                await Say($"This bot does not save players statistics.");
                            }
                        }

                        foreach (Player p in Players)
                        {
                            if (!isTrainMode)
                            {
                                Profiles[p.Name].Plays++;
                            }
                        }

                        Console.Write("* ", Color.Silver);
                        Console.Write("NEW GAME! ");
                        Console.WriteLine($"{Players.Count} in world, {PlayersInGame.Count} joined", Color.DarkGray);
                    }
                    else
                    {
                        round++;

                        int playersBefore = PlayersInGame.Count;
                        PlayersInGame = new List <Player>();

                        foreach (KeyValuePair <Player, TimeSpan> p in PlayersSafe)
                        {
                            PlayersInGame.Add(p.Key);
                        }

                        PlayersSafe = new Dictionary <Player, TimeSpan>();

                        Formatter[] format =
                        {
                            new Formatter("Round",                             Color.White),
                            new Formatter(round,                               Color.Gold),
                            new Formatter(PlayersInGame.Count,                 Color.Green),
                            new Formatter(playersBefore - PlayersInGame.Count, Color.Green),
                        };

                        Console.WriteLineFormatted("    {0} {1}! {2} joined the round, {3} eliminated", Color.Silver, format);
                    }

                    TimeLimit          = new System.Timers.Timer(150 * 1000);
                    TimeLimit.Elapsed += async(object s, ElapsedEventArgs e) =>
                    {
                        await Say($"Time's over!");
                        await ContinueGame();
                    };

                    int k = Math.Max(35 - round * 5, 10);
                    Eliminator          = new System.Timers.Timer(k * 1000);
                    Eliminator.Elapsed += async(object s, ElapsedEventArgs e) =>
                    {
                        if (PlayersSafe.Count == 1)
                        {
                            await Say($"{PlayersSafe.ElementAt(0).Key.Name.ToUpper()} won!");

                            if (!isTrainMode)
                            {
                                Profiles[PlayersSafe.ElementAt(0).Key.Name].Wins++;
                            }
                        }
                        else
                        {
                            await Say($"Time's over!");
                        }
                        await ContinueGame();
                    };

                    await Task.Delay(5000, isGameAborted.Token);
                    await MakeGravity();
                    await OpenEntrance();

                    await Task.Delay(500, isGameAborted.Token);
                    await ReleasePlayers();

                    startTime = DateTime.Now;
                    TimeLimit.Start();

                    await Task.Delay(2000, isGameAborted.Token);
                    await CreateSafeArea();

                    foreach (Player p in Players)
                    {
                        p.Vote = -1;
                    }
                    await RegenerateMapVoters();

                    Tick.Start();
                    isBuilding = false;
                }
            }
            catch (TaskCanceledException)
            {
                await ResetGame();
            }
        }