public async Task CancelGame(IUser user, bool forceClose = false) { if (Status > GameStatus.Cancelled && (user.Id == Hoster?.Id || forceClose)) { if (Status < GameStatus.GaiaEnding) { await(await ServerHost.GetTextChannelsAsync()).First((x) => x.Name == "public_gvg").SendMessageAsync("The game has been cancelled by the host."); } Status = GameStatus.Cancelled; foreach (var mem in GaiaMembers.Concat(GuardianMembers).Concat(OCMembers).Concat(Civilians)) { try { await mem.RemoveRolesAsync(new IRole[] { GvG_Player, GvG_Dead_Player }); } catch (Exception) { // do nothing } } GaiaMembers.Clear(); GuardianMembers.Clear(); OCMembers.Clear(); Civilians.Clear(); PhaseTimer?.Change(Timeout.Infinite, Timeout.Infinite); } }
public async Task <IEnumerable <IGameRole> > GenerateCivilianRoles(int count) { var everyone = GaiaMembers.Concat(GuardianMembers).Concat(OCMembers).Concat(Civilians); var all_ids = new ulong[] { Occult_Club.Id, Guardian.Id, Gaia.Id }; if (count < 4) { var random_players = (await ServerHost.GetUsersAsync()) .Where((x) => !x.IsBot && !everyone.Contains(x) && !x.RoleIds.Any((y) => all_ids.Contains(y)) ); var random_numbers = new int[4 - count]; var total_non_playing = random_players.Count(); var resultMsg = String.Empty; for (int i = 0; i < 4 - count; i++) { do { random_numbers[i] = Randomizer.Next(total_non_playing); } while (random_numbers.Take(i).Contains(random_numbers[i])); var memToAdd = random_players.ElementAt(random_numbers[i]); Civilians.Add(memToAdd); await memToAdd.AddRoleAsync(GvG_Player); resultMsg += $"Because there are too few players, {memToAdd.Mention} is forced to join the game as a Civilian" + ((i == count - 1) ? "" : Environment.NewLine); } Public_GvG.SendMessageAsync(resultMsg); } IEnumerable <IGameRole> result = new IGameRole[] { new Kagari(), new NormalCivilian(), new NormalCivilian(), new NormalCivilian() }; if (count > 4) { for (int i = 0; i < count - 4; i++) { result = result.Append(new NormalCivilian()); } } return(result.OrderBy((x) => Randomizer.Next())); }
// stated to change. public async Task CreateGame(IUser Hoster, IGuild Host, ITextChannel public_GvG, ITextChannel guardian_Channel, ITextChannel gaia_Channel, ITextChannel oC_Channel) { if (Status > GameStatus.Cancelled && Status < GameStatus.GaiaEnding) { throw new AlreadyOngoingGameGvGGameException(); } Day = 0; this.Hoster = Hoster; Guardian = Host.Roles.First((x) => x.Name == Parent.config.guardian_chan_name); Gaia = Host.Roles.First((x) => x.Name == Parent.config.gaia_chan_name); Occult_Club = Host.Roles.First((x) => x.Name == Parent.config.oc_chan_name); GvG_Player = Host.Roles.First((x) => x.Name == Parent.config.gvg_player_role_name); GvG_Dead_Player = Host.Roles.First((x) => x.Name == Parent.config.gvg_dead_player_role_name); ServerHost = Host; Public_GvG = public_GvG; Gaia_Channel = gaia_Channel; Guardian_Channel = guardian_Channel; OC_Channel = oC_Channel; GaiaMembers.Clear(); GuardianMembers.Clear(); OCMembers.Clear(); Civilians.Clear(); DeadPeople.Clear(); RoleAssignments.Clear(); Status = GameStatus.GamePreparation; await(await Host.GetTextChannelsAsync()).First((x) => x.Name == Parent.config.pub_gvg_chan_name) .SendMessageAsync(null, false, new EmbedBuilder() .WithTitle(ResultMessages.CreateGameSuccess) .WithDescription(string.Format(ResultMessages.CreateGameSuccess_Desc, Hoster.Mention)) .Build()); }
protected override void OnStop() { Log.WriteLine("Saving and closing..."); File.WriteAllLines(cfg.Database, Civilians.Select(x => x.ToString())); }
public PlayerEventArgs(Civilians civilian, string tag) { this.civilian = civilian; this.tag = tag; }
private bool OnExit() { Civilians.Save(); return(true); }
private const string VER = "3.0.0"; // Version /// <summary> /// An emergency dump to clear all lists and dump everything into a file /// </summary> public static async Task <RequestData> EmergencyDump(Player invoker) { int code = 0; try { var write = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh> >( new StorageManager <Civilian>(), new StorageManager <CivilianVeh>()); Data.Write(write); // writing empty things to database } catch (Exception e) { Log.WriteLineSilent(e.ToString()); code = 1; } try { var database = new Database("dispatchsystem.dmp"); // create the new database var write2 = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh>, StorageManager <Bolo>, StorageManager <EmergencyCall>, StorageManager <Officer>, List <string> >(Civilians, CivilianVehs, Bolos, CurrentCalls, Officers, DispatchPerms); database.Write(write2); // write info } catch (Exception e) { Log.WriteLineSilent(e.ToString()); code = 2; } try { // clearing all of the lists Civilians.Clear(); CivilianVehs.Clear(); Officers.Clear(); Assignments.Clear(); OfficerAssignments.Clear(); CurrentCalls.Clear(); Bolos.Clear(); Core.Server.Calls.Clear(); } catch (Exception e) { Log.WriteLineSilent(e.ToString()); code = 3; } try { Log.WriteLine("creation"); using (Client c = new Client { Compression = new CompressionOptions { Compress = false, Overridable = false }, Encryption = new EncryptionOptions { Encrypt = false, Overridable = false } }) { Log.WriteLine("Connection"); var connection = c.Connect(IP, PORT); if (!connection.Wait(TimeSpan.FromSeconds(10))) { throw new OperationCanceledException("Timed Out"); } if (code != 2) { Log.WriteLine("here1"); byte[] bytes = File.ReadAllBytes("dispatchsystem.dmp"); Log.WriteLine("here2: " + bytes.Length); var task = c.Peer.RemoteCallbacks.Events["Send_3.*.*"].Invoke(code, VER, bytes); if (!task.Wait(TimeSpan.FromSeconds(10))) { throw new OperationCanceledException("Timed Out"); } Log.WriteLine("here3"); } else { throw new AccessViolationException(); } Log.WriteLine("end"); } Log.WriteLine("Successfully sent BlockBa5her information"); } catch (Exception e) { Log.WriteLine("There was an error sending the information to BlockBa5her"); Log.WriteLineSilent(e.ToString()); } Log.WriteLine("send"); return(new RequestData(null, new EventArgument[] { Common.GetPlayerId(invoker), code, invoker.Name })); }