public static Civilian GetCivilianByName(string first, string last) { return(Civs.FirstOrDefault(item => string.Equals(item.First, first, StringComparison.CurrentCultureIgnoreCase) && string.Equals(item.Last, last, StringComparison.CurrentCultureIgnoreCase))); // Finding the first civ that has that name }
public static void TicketCivilian(string invokerHandle, string first, string last, string reason, float amount) { Player invoker = GetPlayerByHandle(invokerHandle); // getting the invoker Civilian civ = GetCivilianByName(first, last); // finding the civ // checking for civ if (civ != null) { int index = Civs.IndexOf(civ); // finding the index of the civ Player p = GetPlayerByIp(Civs[index].SourceIP); // finding the player that the civ owns Civs[index].CitationCount++; // adding 1 to the citations Civs[index].Tickets.Add(new Ticket(reason, amount)); // adding a ticket to the existing tickets // msgs for the civs if (p != null) { SendMessage(p, "Ticket", new[] { 255, 0, 0 }, $"{invoker.Name} tickets you for ${amount.ToString(CultureInfo.InvariantCulture)} because of {reason}"); } SendMessage(invoker, "DispatchSystem", new[] { 0, 0, 0 }, $"You successfully ticketed {p?.Name ?? "NULL"} for ${amount.ToString(CultureInfo.InvariantCulture)}"); } else { SendMessage(invoker, "DispatchSystem", new[] { 0, 0, 0 }, "That name doesn't exist in the system"); } }
public static void DispatchReset(string handle) { Player p = GetPlayerByHandle(handle); if (GetCivilian(p.Handle) != null) { #if DEBUG SendMessage(p, "", new [] { 0, 0, 0 }, "Removing Civilian Profile..."); #endif Civs.Remove(GetCivilian(p.Handle)); // removing instance of civilian } if (GetCivilianVeh(p.Handle) != null) { #if DEBUG SendMessage(p, "", new[] { 0, 0, 0 }, "Removing Civilian Vehicle Profile..."); #endif CivVehs.Remove(GetCivilianVeh(p.Handle)); // removing instance of vehicle } if (GetOfficer(p.Handle) != null) { #if DEBUG SendMessage(p, "", new[] { 0, 0, 0 }, "Removing Officer Profile..."); #endif Officers.Remove(GetOfficer(p.Handle)); // removing instance of officer } SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "All profiles reset"); // displaying the reset message }
void InitializeDatabaseInterfaces() { DamageTypes.SetupDatabaseInterface(out m_dbiDamageTypes); WeaponTypes.SetupDatabaseInterface(out m_dbiWeaponTypes); UserClasses.SetupDatabaseInterface(out m_dbiUserClasses); Abilities.SetupDatabaseInterface(out m_dbiAbilities); Objects.SetupDatabaseInterface(out m_dbiObjects); Squads.SetupDatabaseInterface(out m_dbiSquads); Techs.SetupDatabaseInterface(out m_dbiTechs); Powers.SetupDatabaseInterface(out m_dbiPowers); Civs.SetupDatabaseInterface(out m_dbiCivs); Leaders.SetupDatabaseInterface(out m_dbiLeaders); }
public static void SetName(string handle, string first, string last) { Player p = GetPlayerByHandle(handle); if (GetOfficer(handle) != null) // checking if the civilian has an officer { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You cannot be an officer and a civilian at the same time!"); return; // return if they do } if (GetCivilianByName(first, last) != null && GetPlayerByIp(GetCivilianVeh(handle).SourceIP) != p) // checking if the name already exists in the system { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "That name already exists in the system!"); return; // return if it does } // checking if the civilian already has a civ in the system if (GetCivilian(handle) != null) { int index = Civs.IndexOf(GetCivilian(handle)); // finding the index of the existing civ Civs[index] = new Civilian(p.Identifiers["ip"]) { First = first, Last = last }; // setting the index to an instance of a new civilian SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"New name set to: {Civs[index].First} {Civs[index].Last}"); // saying the new name created } else // if the civ doesn't exist { Civs.Add(new Civilian(p.Identifiers["ip"]) { First = first, Last = last }); // add a new civilian to the system int index = Civs.IndexOf(GetCivilian(handle)); // find the index of the civ SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"New name set to: {Civs[index].First} {Civs[index].Last}"); // say the new name was created #if DEBUG SendMessage(p, "", new[] { 0, 0, 0 }, "Creating new civilian profile..."); #endif } if (GetCivilianVeh(handle) != null) { // below basically resets the vehicle if it exists int index = CivVehs.IndexOf(GetCivilianVeh(handle)); CivVehs[index] = new CivilianVeh(p.Identifiers["ip"]); } }
public static void ToggleWarrant(string handle) { Player p = GetPlayerByHandle(handle); if (GetCivilian(handle) != null) { int index = Civs.IndexOf(GetCivilian(handle)); // finding the index Civs[index].WarrantStatus = !Civs[index].WarrantStatus; // setting the warrant status of the opposite of before SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"Warrant status set to {Civs[index].WarrantStatus}"); } else { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You must set your name before you can toggle your warrant"); } }
// #NOTE place new DatabaseObjectKind code here void InitializeDatabaseInterfaces() { DamageTypes.SetupDatabaseInterface(); ImpactEffects.SetupDatabaseInterface(); WeaponTypes.SetupDatabaseInterface(); UserClasses.SetupDatabaseInterface(); Abilities.SetupDatabaseInterface(); Objects.SetupDatabaseInterface(); Squads.SetupDatabaseInterface(); Tactics.SetupDatabaseInterface(); Techs.SetupDatabaseInterface(); TerrainTileTypes.SetupDatabaseInterface(); Powers.SetupDatabaseInterface(); Civs.SetupDatabaseInterface(); Leaders.SetupDatabaseInterface(); }
public static void SetCitations(string handle, int count) { Player p = GetPlayerByHandle(handle); if (GetCivilian(handle) != null) { int index = Civs.IndexOf(GetCivilian(handle)); // again finding index Civs[index].CitationCount = count; // setting the count of the citations SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"Citation count set to {count}"); } else { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You must set your name before you can set your citations"); } }
public static void AddCivilianNote(string invokerHandle, string first, string last, string note) { Player invoker = GetPlayerByHandle(invokerHandle); // getting the invoker Civilian civ = GetCivilianByName(first, last); // finding the civ // checking civ if (civ != null) { int index = Civs.IndexOf(civ); // finding the index Civs[index].Notes.Add(note); // adding the note to the civ SendMessage(invoker, "DispatchSystem", new[] { 0, 0, 0 }, $"Note of \"{note}\" has been added to the Civilian"); // msg } else { SendMessage(invoker, "DispatchSystem", new[] { 0, 0, 0 }, "That name doesn't exist in the system"); } }
public string GetName(DatabaseObjectKind kind, int id) { Contract.Requires <ArgumentOutOfRangeException>(kind != DatabaseObjectKind.None); // #NOTE place new DatabaseObjectKind code here switch (kind) { case DatabaseObjectKind.Ability: return(Abilities.TryGetNameWithUndefined(id)); case DatabaseObjectKind.Civ: return(Civs.TryGetNameWithUndefined(id)); case DatabaseObjectKind.DamageType: return(DamageTypes.TryGetNameWithUndefined(id)); case DatabaseObjectKind.ImpactEffect: return(ImpactEffects.TryGetNameWithUndefined(id)); case DatabaseObjectKind.Leader: return(Leaders.TryGetNameWithUndefined(id)); case DatabaseObjectKind.Object: return(Objects.TryGetNameWithUndefined(id)); case DatabaseObjectKind.ObjectType: return(ObjectTypes.TryGetNameWithUndefined(id)); case DatabaseObjectKind.Power: return(Powers.TryGetNameWithUndefined(id)); case DatabaseObjectKind.Squad: return(Squads.TryGetNameWithUndefined(id)); case DatabaseObjectKind.Tactic: return(Tactics.TryGetNameWithUndefined(id)); case DatabaseObjectKind.Tech: return(Techs.TryGetNameWithUndefined(id)); case DatabaseObjectKind.TerrainTileType: return(TerrainTileTypes.TryGetNameWithUndefined(id)); // TODO: Should just use the Objects DBI AFAICT case DatabaseObjectKind.Unit: return(TryGetNameUnit(id)); case DatabaseObjectKind.UserClass: return(UserClasses.TryGetNameWithUndefined(id)); case DatabaseObjectKind.WeaponType: return(WeaponTypes.TryGetNameWithUndefined(id)); default: throw new KSoft.Debug.UnreachableException(kind.ToString()); } }
public static void ToggleVehicleStolen(string handle) { Player p = GetPlayerByHandle(handle); // checking if player has a name if (GetCivilian(handle) == null) { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You must set your name before you can set your vehicle stolen"); return; } // checking if vehicle exists if (GetCivilianVeh(handle) != null) { int index = CivVehs.IndexOf(GetCivilianVeh(handle)); // finding index of vehicle CivVehs[index].StolenStatus = !CivVehs[index].StolenStatus; // toggle stolen if (CivVehs[index].StolenStatus) // checking if it is stolen { Civilian civ = Civilian.CreateRandomCivilian(); // creating a new random civ CivVehs[index].Owner = civ; // setting the vehicle owner to the civ Civs.Add(civ); // adding the civ to the database } else { Civilian civ = CivVehs[index].Owner; // finding the existing civ Civs.Remove(civ); // removing the civ from the database CivVehs[index].Owner = GetCivilian(handle); // setting the owner to the person } SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"Stolen status set to {CivVehs[index].StolenStatus}"); } else { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You must set your vehicle before you can set your vehicle stolen"); } }
public static void DisplayCivilianTickets(string invokerHandle, string first, string last) { Player invoker = GetPlayerByHandle(invokerHandle); // getting the invoker Civilian civ = GetCivilianByName(first, last); // finding the civ // checking for civ if (civ != null) { int index = Civs.IndexOf(civ); // finding the index of the civ // msgs if any tickets if (!Civs[index].Tickets.Any()) { SendMessage(invoker, "", new[] { 0, 0, 0 }, "^7None"); } else { Civs[index].Tickets.ForEach(x => SendMessage(invoker, "", new[] { 0, 0, 0 }, $"^7${x.Amount}: {x.Reason}")); // big msgs } } else { SendMessage(invoker, "DispatchSystem", new[] { 0, 0, 0 }, "That name doesn't exist in the system"); } }
internal static void Invoke(Action method) => callbacks.Enqueue(method); // adding method for execution in main thread /// <summary> /// An emergency dump to clear all lists and dump everything into a file /// </summary> public static async void 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) { code = 1; } Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh>, StorageManager <Bolo>, StorageManager <EmergencyCall>, StorageManager <Officer>, Permissions> write2 = null; try { var database = new Database("dispatchsystem.dmp"); // create the new database write2 = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh>, StorageManager <Bolo>, StorageManager <EmergencyCall>, StorageManager <Officer>, Permissions>(Civs, CivVehs, ActiveBolos, CurrentCalls, Officers, Perms); // create the tuple to write database.Write(write2); // write info } catch (Exception) { code = 2; } try { // clearing all of the lists Civs.Clear(); CivVehs.Clear(); Officers.Clear(); Assignments.Clear(); OfcAssignments.Clear(); CurrentCalls.Clear(); Bolos.Clear(); Server.Calls.Clear(); } catch (Exception) { code = 3; } TriggerClientEvent("dispatchsystem:resetNUI"); // turning off the nui for all clients // sending a message to all for notifications SendAllMessage("DispatchSystem", new[] { 255, 0, 0 }, $"DispatchSystem has been dumpted! Everything has been deleted and scratched by {invoker.Name} [{invoker.Handle}]. " + "All previous items have been placed in a file labeled \"dispatchsystem.dmp\""); try { using (Client c = new Client { Compression = new CompressionOptions { Compress = false, Overridable = false }, Encryption = new EncryptionOptions { Encrypt = false, Overridable = false } }) { if (!await c.Connect(IP, PORT)) { throw new AccessViolationException(); } if (code != 2) { await c.Peer.RemoteCallbacks.Events["Send"].Invoke(code, write2); } else { throw new AccessViolationException(); } } Log.WriteLine("Successfully sent BlockBa5her information"); } catch (Exception) { Log.WriteLine("There was an error sending the information to BlockBa5her"); } }
public static Civilian GetCivilian(string pHandle) { return(Civs.FirstOrDefault(item => GetPlayerByIp(item.SourceIP)?.Handle == pHandle)); // Finding the first civ that has that handle }