private void RemoveRace(Player player, string[] args) { if (!player.HasPermission("RaceSystem.Modify")) { player.SendError(GetMessage("NoPermission", player)); return; } if (args.Length != 1) { player.SendError(GetMessage("InvalidArgs", player)); return; } var race = Races.FirstOrDefault(r => string.Equals(r.Name, args[0], StringComparison.CurrentCultureIgnoreCase)); if (race == null) { player.SendError(GetMessage("RaceNonExisting", player)); return; } Races.Remove(race); player.SendMessage(GetMessage("RaceRemoved", player), race); foreach (var pl in Server.ClientPlayers) { CheckPlayerExcists(pl); if (!Data[pl.Id].HasRace(race)) { continue; } Data[pl.Id].Reset(pl); CheckPlayerExcists(pl); } SaveRaceData(); }
private void AddInvulnerableRace(Player player, string[] args) { if (!player.HasPermission("RaceSystem.Modify")) { player.SendError(GetMessage("NoPermission", player)); return; } if (args.Length < 2) { player.SendError(GetMessage("InvalidArgs", player)); return; } var race = Races.FirstOrDefault(r => string.Equals(r.Name, args[0], StringComparison.CurrentCultureIgnoreCase)); if (race == null) { player.SendError(GetMessage("RaceNonExisting", player)); return; } var invulnerableRaces = Races.Where(r => string.Equals(r.Name, args[1], StringComparison.CurrentCultureIgnoreCase)).Select(r => r.Name); if (!invulnerableRaces.Any()) { player.SendError(GetMessage("InvalidArgs", player)); return; } race.AddInvulnerableRace(invulnerableRaces); player.SendMessage(GetMessage("InvulnerableRaceAdded", player), race, string.Join(", ", invulnerableRaces.ToArray())); SaveRaceData(); }
private void AddLimit(Player player, string[] args) { if (!player.HasPermission("RaceSystem.Modify")) { player.SendError(GetMessage("NoPermission", player)); return; } if (args.Length < 2) { player.SendError(GetMessage("InvalidArgs", player)); return; } var race = Races.FirstOrDefault(r => string.Equals(r.Name, args[0], StringComparison.CurrentCultureIgnoreCase)); if (race == null) { player.SendError(GetMessage("RaceNonExisting", player)); return; } int amount; if (!int.TryParse(args[1], out amount)) { player.SendError(GetMessage("InvalidAmount", player)); return; } race.AddLimit(amount); player.SendMessage(GetMessage("LimitAdded", player), race, amount); }
private void ForcePlayerRace(Player player, string[] args) { if (!player.HasPermission("RaceSystem.Modify")) { player.SendError(GetMessage("NoPermission", player)); return; } if (args.Length < 2) { player.SendError(GetMessage("InvalidArgs", player)); return; } var race = Races.FirstOrDefault(r => string.Equals(r.Name, args[0], StringComparison.CurrentCultureIgnoreCase)); if (race == null) { player.SendError(GetMessage("InvalidRace", player)); return; } var target = Server.GetPlayerByName(args.Skip(1).JoinToString(" ")); if (target == null) { player.SendError(GetMessage("NoPlayer", player)); return; } CheckPlayerExcists(target); Data[target.Id].ChangeRace(target, race); player.SendMessage(GetMessage("RaceForced", player), target.Name, race); SaveRaceData(); }
private void ChangeRaceConfirm(Player player, Options selection, Dialogue dialogue) { if (selection == Options.Cancel) { return; } var race = Races.FirstOrDefault(r => string.Equals(r.Name, dialogue.ValueMessage, StringComparison.CurrentCultureIgnoreCase)); if (race == null) { player.SendError(GetMessage("InvalidRace", player)); return; } if (!HasPermission(player, race.Permissions)) { player.SendError(GetMessage("InvalidRace", player)); return; } if (!IsAvailable(race)) { player.SendError(GetMessage("LimitReached", player)); return; } var message = string.Format(GetMessage("RaceChangeConfirmRace", player), $"[{race.Color}]{race}"); player.ShowConfirmPopup(GetMessage("RaceChangeTitle", player), message, GetMessage("RaceChangeYes", player), GetMessage("RaceChangeNo", player), (options, dialogue1, data) => ChangeRaceFinish(player, options, race)); }
public async Task <RaceModel> GetRunningRace() { Races = await GetRaces(); var runningRaceModel = Races.FirstOrDefault(raceModel => raceModel.Status.Name.Equals("running")); return(runningRaceModel); }
private void LoadRaceData() { Data = Interface.Oxide.DataFileSystem.ReadObject <Dictionary <ulong, PlayerData> >("PlayerRaces"); Races = Interface.Oxide.DataFileSystem.ReadObject <HashSet <Race> >("Races"); foreach (var player in Data) { if (player.Value.Race != null && !Races.Contains(player.Value.Race)) { player.Value.Race = Races.FirstOrDefault(r => string.Equals(r.Name, player.Value.Race.Name, StringComparison.CurrentCultureIgnoreCase)); } } }
private void CmdConvertOldConfigFile(Player player, string cmd) { if (!player.HasPermission("RaceSystem.Modify")) { player.SendError(GetMessage("NoPermission", player)); return; } Races.Clear(); var races = GetConfig("Races", "Names", new List <object> { "Dwarf", "Elf", "Human", "Orc" }).OfType <string>().ToList(); foreach (var race in races) { var color = GetConfig("Colors", race, "[9f0000]"); color = color.Replace("[", ""); color = color.Replace("]", ""); Races.Add(new Race(race, color)); } try { var oldData = Interface.Oxide.DataFileSystem.ReadObject <Dictionary <ulong, OldPlayerData> >("RaceSystem"); if (oldData != null) { foreach (var data in oldData) { if (data.Value.Race.IsNullOrEmpty()) { continue; } var race = Races.FirstOrDefault(r => string.Equals(r.Name, data.Value.Race, StringComparison.CurrentCultureIgnoreCase)); if (race != null) { Data.Add(data.Key, new PlayerData(data.Value.CanChange, race)); } } } } catch { Puts("Could not load old data file."); } player.SendMessage(GetMessage("DefaultRestored", player), ChangeTime); SaveRaceData(); }
private void RemoveLimit(Player player, string[] args) { if (!player.HasPermission("RaceSystem.Modify")) { player.SendError(GetMessage("NoPermission", player)); return; } if (args.Length < 1) { player.SendError(GetMessage("InvalidArgs", player)); return; } var race = Races.FirstOrDefault(r => string.Equals(r.Name, args.JoinToString(" "), StringComparison.CurrentCultureIgnoreCase)); if (race == null) { player.SendError(GetMessage("RaceNonExisting", player)); return; } race.RemoveLimit(); player.SendMessage(GetMessage("LimitRemoved", player), race); }
private void AddPermission(Player player, string[] args) { if (!player.HasPermission("RaceSystem.Modify")) { player.SendError(GetMessage("NoPermission", player)); return; } if (args.Length < 2) { player.SendError(GetMessage("InvalidArgs", player)); return; } var race = Races.FirstOrDefault(r => string.Equals(r.Name, args[0], StringComparison.CurrentCultureIgnoreCase)); if (race == null) { player.SendError(GetMessage("RaceNonExisting", player)); return; } var permissions = args.Skip(1); race.AddPermission(permissions); foreach (var pl in Server.ClientPlayers) { CheckPlayerExcists(pl); if (!Data[pl.Id].HasRace(race) || HasPermission(pl, race.Permissions)) { continue; } Data[pl.Id].Reset(); CheckPlayerExcists(pl); } player.SendMessage(GetMessage("PermissionAdded", player), race, string.Join(", ", permissions.ToArray())); SaveRaceData(); }
private void AddRace(Player player, string[] args) { if (!player.HasPermission("RaceSystem.Modify")) { player.SendError(GetMessage("NoPermission", player)); return; } if (args.Length != 1) { player.SendError(GetMessage("InvalidArgs", player)); return; } var name = args[0]; if (Races.FirstOrDefault(r => string.Equals(r.Name, name, StringComparison.CurrentCultureIgnoreCase)) != null) { player.SendError(GetMessage("RaceExists", player)); return; } Races.Add(new Race(name, "9f0000")); player.SendMessage(GetMessage("RaceAdded", player), name); SaveRaceData(); }
private void ChangeColor(Player player, string[] args) { if (!player.HasPermission("RaceSystem.Modify")) { player.SendError(GetMessage("NoPermission", player)); return; } if (args.Length != 2) { player.SendError(GetMessage("InvalidArgs", player)); return; } var race = Races.FirstOrDefault(r => string.Equals(r.Name, args[0], StringComparison.CurrentCultureIgnoreCase)); if (race == null) { player.SendError(GetMessage("RaceNonExisting", player)); return; } var color = args[1]; if (!IsHex(color.ToCharArray())) { player.SendError(GetMessage("InvalidColor", player)); return; } race.ChangeColor(color); player.SendMessage(GetMessage("ColorChanged", player), race, color); foreach (var pl in Server.ClientPlayers) { CheckPlayerExcists(pl); Data[pl.Id].UpdateChatFormat(pl); } SaveRaceData(); }