diff --git a/SampSharpGameMode1/Civilisation/PathExtractor.cs b/SampSharpGameMode1/Civilisation/PathExtractor.cs index 97cd69a..eaa872c 100644 --- a/SampSharpGameMode1/Civilisation/PathExtractor.cs +++ b/SampSharpGameMode1/Civilisation/PathExtractor.cs @@ -193,7 +193,7 @@ public enum NodeType : byte public static void Load() { - string heightmapFile = Directory.GetCurrentDirectory() + "\\scriptfiles\\SAfull.hmap"; + string heightmapFile = Directory.GetCurrentDirectory() + "/scriptfiles/SAfull.hmap"; using (FileStream fs = File.Open(heightmapFile, FileMode.Open, FileAccess.Read)) { long fsLen = fs.Length; @@ -220,7 +220,7 @@ public static void Extract(string path, int index) { try { - string filename = path + "\\NODES" + index + ".DAT"; + string filename = path + "/NODES" + index + ".DAT"; Random rdm = new Random(); using (FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read)) { diff --git a/SampSharpGameMode1/Civilisation/RecordCreator.cs b/SampSharpGameMode1/Civilisation/RecordCreator.cs index fc99722..8d6f55c 100644 --- a/SampSharpGameMode1/Civilisation/RecordCreator.cs +++ b/SampSharpGameMode1/Civilisation/RecordCreator.cs @@ -73,7 +73,7 @@ public void AddVehicleBlock(VehicleBlock vehicleBlock) /// File name with .rec extension public void Save(string filename) { - using (FileStream fs = File.Open(Directory.GetCurrentDirectory() + "\\npcmodes\\recordings\\" + filename, FileMode.Create, FileAccess.Write)) + using (FileStream fs = File.Open(Directory.GetCurrentDirectory() + "/npcmodes/recordings/" + filename, FileMode.Create, FileAccess.Write)) { byte[] buffer; diff --git a/SampSharpGameMode1/Commands/CommonCommands.cs b/SampSharpGameMode1/Commands/CommonCommands.cs index ba652b0..5d0f3b8 100644 --- a/SampSharpGameMode1/Commands/CommonCommands.cs +++ b/SampSharpGameMode1/Commands/CommonCommands.cs @@ -13,24 +13,31 @@ namespace SampSharpGameMode1.Commands { class CommonCommands { + [Command("help")] + private static void HelpCommand(Player player) + { + player.SendClientMessage(ColorPalette.Primary.Main + "This is a SA-MP where you can create your own maps, races and derbies !"); + player.SendClientMessage($"Type {ColorPalette.Secondary.Main}/event-infos{Color.White} to get more information about how to create a map, a race, or a derby."); + player.SendClientMessage($"Teleport yourself where you want with {ColorPalette.Secondary.Main}/tlps"); + player.SendClientMessage($"This server is still in beta, type {ColorPalette.Secondary.Main}/beta{Color.White} to see what is coming soon !"); + } [Command("beta")] private static void BetaCommand(Player player) { player.SendClientMessage(ColorPalette.Primary.Main + "These features are still in development and will be ready to test soon:"); - player.SendClientMessage(ColorPalette.Secondary.Main + " - Map creator (in progress)"); - player.SendClientMessage(ColorPalette.Secondary.Main + " - Derby creator and Derby events (need to implement Map creator first)"); - player.SendClientMessage(ColorPalette.Secondary.Main + " - AI / NPC to play with"); - player.SendClientMessage(ColorPalette.Secondary.Main + " - More event types"); + player.SendClientMessage(" - AI / NPC to play with"); + player.SendClientMessage(" - More event types"); } [Command("event-infos")] private static void EventInfosCommand(Player player) { player.SendClientMessage(ColorPalette.Primary.Main + "On this server you can create your own races and derbies, so please read the following instructions:"); - player.SendClientMessage(ColorPalette.Secondary.Main + " - Use /race to see race creator commands, and /derby for derby creator commands"); - player.SendClientMessage(ColorPalette.Secondary.Main + " - Make sure you use a keyboard with numpad (controllers are not supported yet)"); - player.SendClientMessage(ColorPalette.Secondary.Main + " - You can only edit your own event"); - player.SendClientMessage(ColorPalette.Secondary.Main + " - If you want to add a map to your event, create the map first with /map commands, then load it into your event"); - player.SendClientMessage(ColorPalette.Secondary.Main + " - Once your event is playable, everybody can load it and join it"); + player.SendClientMessage($" - Use {ColorPalette.Secondary.Main}/race{Color.White} to see race creator commands, and {ColorPalette.Secondary.Main}/derby{Color.White} for derby creator commands"); + player.SendClientMessage($" - Make sure you use a keyboard with numpad (controllers are not supported yet)"); + player.SendClientMessage($" - You can only edit your own event"); + player.SendClientMessage($" - If you want to add a map to your event, create the map first with {ColorPalette.Secondary.Main}/map{Color.White} commands, then load it into your event"); + player.SendClientMessage($" - Don't forget to save your creations with {ColorPalette.Secondary.Main}/race save{Color.White}, {ColorPalette.Secondary.Main}/derby save{Color.White} or {ColorPalette.Secondary.Main}/map save{Color.White}"); + player.SendClientMessage($" - Once your event is playable, everybody can load it and join it"); } [Command("s")] @@ -44,8 +51,11 @@ private static void RCommand(Player player) { if (player.LastSavedPosition.Position != Vector3.Zero) { - player.Teleport(player.LastSavedPosition.Position + Vector3.UnitZ); - player.Angle = player.LastSavedPosition.Rotation; + if (!player.IsInEvent) + { + player.Teleport(player.LastSavedPosition.Position + Vector3.UnitZ); + player.Angle = player.LastSavedPosition.Rotation; + } } else player.SendClientMessage(ColorPalette.Error.Main + "Set the position with /s first"); diff --git a/SampSharpGameMode1/Commands/DerbyCommands.cs b/SampSharpGameMode1/Commands/DerbyCommands.cs index a2a7c6b..b926c26 100644 --- a/SampSharpGameMode1/Commands/DerbyCommands.cs +++ b/SampSharpGameMode1/Commands/DerbyCommands.cs @@ -12,6 +12,61 @@ namespace SampSharpGameMode1.Commands { class DerbyCommands { + + /* Display a list of all the player's races */ + [Command("myderbies")] + private static void MyDerbiesCommand(Player player) + { + List races = Derby.GetPlayerDerbyList(player); + if (races.Count == 0) + player.SendClientMessage("You don't have any derbies"); + else + { + ListDialog list = new ListDialog(player.Name + "'s derbies", "Options", "Close"); + list.AddItems(races); + list.Response += (object sender, DialogResponseEventArgs e) => + { + if (e.DialogButton == DialogButton.Left) + { + ListDialog actionList = new ListDialog("Action", "Select", "Cancel"); + actionList.AddItem("Infos ..."); + actionList.AddItem("Edit"); + actionList.AddItem("Delete"); + actionList.Response += (object sender, DialogResponseEventArgs ev) => + { + if (ev.DialogButton == DialogButton.Left) + { + try + { + int raceid = Convert.ToInt32(races[e.ListItem].Substring(0, races[e.ListItem].IndexOf('_'))); + switch (ev.ListItem) + { + case 0: // Infos + DerbyCommandsClass.GetInfo(player, raceid); + break; + case 1: // Edit + DerbyCommandsClass.LoadDerbyCreator(player, raceid); + break; + case 2: // Delete + player.SendClientMessage(Color.Red + "This function is not developped yet"); + break; + } + } + catch (Exception ex) + { + MySQLConnector.Instance().CloseReader(); + Logger.WriteLineAndClose("DerbyCommands.cs - DerbyCommands.MyDerbiesCommand:E: Exception raised: " + ex.Message); + player.SendClientMessage(Color.Red + "An error occured"); + } + } + }; + actionList.Show(player); + } + }; + list.Show(player); + } + } + [Command("derby")] private static void DerbyCommandUsage(Player player) { @@ -36,7 +91,7 @@ private static void CreateDerby(Player player) } [Command("loadc")] - private static void LoadDerbyCreator(Player player, int id) + public static void LoadDerbyCreator(Player player, int id) { if (player.pEvent != null) return; @@ -142,7 +197,7 @@ private static void EditPickup(Player player, int objectid) [Command("find")] private static void FindDerby(Player player, string name) { - Dictionary result = DerbyCreator.Find(name); + Dictionary result = Derby.Find(name); if (result.Count == 0) player.SendClientMessage("No derby found !"); else @@ -155,9 +210,9 @@ private static void FindDerby(Player player, string name) } [Command("info")] - private static void GetInfo(Player player, int id) + public static void GetInfo(Player player, int id) { - Dictionary result = DerbyCreator.GetInfo(id); + Dictionary result = Derby.GetInfo(id); if (result.Count == 0) player.SendClientMessage("No derby found !"); else @@ -166,7 +221,7 @@ private static void GetInfo(Player player, int id) string str = ""; foreach (KeyValuePair kvp in result) { - str = new Color(50, 50, 255) + kvp.Key + ": " + new Color(255, 255, 255) + kvp.Value; + str = Display.ColorPalette.Primary.Main + kvp.Key + ": " + new Color(255, 255, 255) + kvp.Value; if (str.Length >= 64) { infoList.AddItem(str.Substring(0, 63)); diff --git a/SampSharpGameMode1/Commands/MappingCommands.cs b/SampSharpGameMode1/Commands/MappingCommands.cs index 1badac4..590d610 100644 --- a/SampSharpGameMode1/Commands/MappingCommands.cs +++ b/SampSharpGameMode1/Commands/MappingCommands.cs @@ -12,12 +12,66 @@ namespace SampSharpGameMode1.Commands { class MappingCommands { + + /* Display a list of all the player's maps */ + [Command("mymaps")] + private static void MyMapsCommands(Player player) + { + List maps = Map.GetPlayerMapList(player); + if (maps.Count == 0) + player.SendClientMessage("You don't have any maps"); + else + { + ListDialog list = new ListDialog(player.Name + "'s maps", "Options", "Close"); + list.AddItems(maps); + list.Response += (object sender, DialogResponseEventArgs e) => + { + if (e.DialogButton == DialogButton.Left) + { + ListDialog actionList = new ListDialog("Action", "Select", "Cancel"); + actionList.AddItem("Infos ..."); + actionList.AddItem("Edit"); + actionList.AddItem("Delete"); + actionList.Response += (object sender, DialogResponseEventArgs ev) => + { + if (ev.DialogButton == DialogButton.Left) + { + try + { + int mapid = Convert.ToInt32(maps[e.ListItem].Substring(0, maps[e.ListItem].IndexOf('_'))); + switch (ev.ListItem) + { + case 0: // Infos + MappingCommandClass.GetInfo(player, mapid); + break; + case 1: // Edit + MappingCommandClass.LoadCommand(player, mapid); + break; + case 2: // Delete + player.SendClientMessage(Color.Red + "This function is not developped yet"); + break; + } + } + catch (Exception ex) + { + MySQLConnector.Instance().CloseReader(); + Logger.WriteLineAndClose("MappingCommands.cs - MappingCommands.MyMapsCommands:E: Exception raised: " + ex.Message); + player.SendClientMessage(Color.Red + "An error occured"); + } + } + }; + actionList.Show(player); + } + }; + list.Show(player); + } + } [Command("mapping", Shortcut = "map")] private static void MappingCommand(Player player) { player.SendClientMessage($"Usage: {ColorPalette.Secondary.Main}/mapping [action]"); player.SendClientMessage($"Global Actions: {ColorPalette.Secondary.Main}help, create, loadc, exit"); - player.SendClientMessage($"On map editing Actions: {ColorPalette.Secondary.Main}help, save, exit, list, addo, delo, replace, marker, dist, edit"); + player.SendClientMessage($"On map editing Actions: {ColorPalette.Secondary.Main}help, save, exit, info, addo, delo, replace, marker, dist, edit"); } [CommandGroup("mapping", "map")] class MappingCommandClass @@ -29,15 +83,15 @@ private static void HelpCommand(Player player) $"{ColorPalette.Primary.Main}/mapping create {ColorPalette.Primary.Darken}Create a new map" + "\n" + $"{ColorPalette.Primary.Main}/mapping loadc [id] {ColorPalette.Primary.Darken}Load a map" + "\n" + $"{ColorPalette.Primary.Main}/mapping save {ColorPalette.Primary.Darken}Save the map" + "\n" + - $"{ColorPalette.Primary.Main}/mapping exit {ColorPalette.Primary.Darken}Close the editor without saving the map" + "\n" + - $"{ColorPalette.Primary.Main}/mapping list {ColorPalette.Primary.Darken}List all your races" + "\n" + + $"{ColorPalette.Primary.Main}/mapping exit {ColorPalette.Primary.Darken}Close the editor (save your map first !)" + "\n" + + $"{ColorPalette.Primary.Main}/mapping info [id] {ColorPalette.Primary.Darken}Display the info of a map" + "\n" + $"{ColorPalette.Primary.Main}/mapping addo [modelid] {ColorPalette.Primary.Darken}Add an object with specified modelid" + "\n" + $"{ColorPalette.Primary.Main}/mapping delo [objectid] {ColorPalette.Primary.Darken}Delete the object" + "\n" + $"{ColorPalette.Primary.Main}/mapping replace [objectid] [modelid] {ColorPalette.Primary.Darken}Replace the object by the s modelid" + "\n" + + $"{ColorPalette.Primary.Main}/mapping dupl [objectid] {ColorPalette.Primary.Darken}Duplicate the object" + "\n" + $"{ColorPalette.Primary.Main}/mapping marker [1-2] {ColorPalette.Primary.Darken}Edit the marker position to get distance" + "\n" + $"{ColorPalette.Primary.Main}/mapping dist {ColorPalette.Primary.Darken}Displays the distance between the markers" + "\n" + - $"{ColorPalette.Primary.Main}/mapping edit [objectid] {ColorPalette.Primary.Darken}Edit position/rotation of object" + "\n" + - $"{ColorPalette.Primary.Main}/mapping exit {ColorPalette.Primary.Darken}Close the editor" + $"{ColorPalette.Primary.Main}/mapping edit [objectid] {ColorPalette.Primary.Darken}Edit position/rotation of object"; ; MessageDialog dialog = new MessageDialog("Command list", list, "Close"); dialog.Show(player); @@ -51,7 +105,7 @@ private static void CreateCommand(Player player) player.mapCreator.CreateMap(); } [Command("loadc")] - private static void LoadCommand(Player player, int id) + public static void LoadCommand(Player player, int id) { if (player.pEvent != null) return; @@ -189,6 +243,14 @@ private static void ReplaceCommand(Player player, int objectid, int modelid) else player.SendClientMessage(Color.Red, $"Map creator is not initialized, create or load a map first"); } + [Command("dupl")] + private static void DuplicateCommand(Player player, int objectid) + { + if (!(player.mapCreator is null)) + player.mapCreator.DuplicateObject(objectid); + else + player.SendClientMessage(Color.Red, $"Map creator is not initialized, create or load a map first"); + } [Command("marker")] private static void MarkerCommand(Player player, int marker) { @@ -213,6 +275,31 @@ private static void EditCommand(Player player, int objectid) else player.SendClientMessage(Color.Red, $"Map creator is not initialized, create or load a map first"); } + + [Command("info")] + public static void GetInfo(Player player, int id) + { + Dictionary result = Map.GetInfo(id); + if (result.Count == 0) + player.SendClientMessage("No map found !"); + else + { + var infoList = new ListDialog("Map info", "Ok", ""); + string str = ""; + foreach (KeyValuePair kvp in result) + { + str = Display.ColorPalette.Primary.Main + kvp.Key + ": " + new Color(255, 255, 255) + kvp.Value; + if (str.Length >= 64) + { + infoList.AddItem(str.Substring(0, 63)); + infoList.AddItem(str.Substring(63)); + } + else + infoList.AddItem(str); + } + infoList.Show(player); + } + } } } } diff --git a/SampSharpGameMode1/Commands/RaceCommands.cs b/SampSharpGameMode1/Commands/RaceCommands.cs index 156478a..7f9ea3d 100644 --- a/SampSharpGameMode1/Commands/RaceCommands.cs +++ b/SampSharpGameMode1/Commands/RaceCommands.cs @@ -27,7 +27,7 @@ private static void RespawnCommand(Player player) [Command("myraces")] private static void MyRacesCommand(Player player) { - List races = RaceCreator.GetPlayerRaceList(player); + List races = Race.GetPlayerRaceList(player); if (races.Count == 0) player.SendClientMessage("You don't have any races"); else @@ -64,6 +64,7 @@ private static void MyRacesCommand(Player player) } catch (Exception ex) { + MySQLConnector.Instance().CloseReader(); Logger.WriteLineAndClose("RaceCommands.cs - RaceCommands.MyRacesCommand:E: Exception raised: " + ex.Message); player.SendClientMessage(Color.Red + "An error occured"); } @@ -229,7 +230,7 @@ private static void AddSG(Player player) [Command("find")] private static void FindRace(Player player, string name) { - Dictionary result = RaceCreator.Find(name); + Dictionary result = Race.Find(name); if (result.Count == 0) player.SendClientMessage("No race found !"); else @@ -244,7 +245,7 @@ private static void FindRace(Player player, string name) [Command("info")] public static void GetInfo(Player player, int id) { - Dictionary result = RaceCreator.GetInfo(id); + Dictionary result = Race.GetInfo(id); if (result.Count == 0) player.SendClientMessage("No race found !"); else @@ -253,7 +254,7 @@ public static void GetInfo(Player player, int id) string str = ""; foreach (KeyValuePair kvp in result) { - str = new Color(50, 50, 255) + kvp.Key + ": " + new Color(255, 255, 255) + kvp.Value; + str = Display.ColorPalette.Primary.Main + kvp.Key + ": " + new Color(255, 255, 255) + kvp.Value; if (str.Length >= 64) { infoList.AddItem(str.Substring(0, 63)); diff --git a/SampSharpGameMode1/Commands/TeleportCommands.cs b/SampSharpGameMode1/Commands/TeleportCommands.cs new file mode 100644 index 0000000..eb096d3 --- /dev/null +++ b/SampSharpGameMode1/Commands/TeleportCommands.cs @@ -0,0 +1,145 @@ +using SampSharp.GameMode; +using SampSharp.GameMode.Definitions; +using SampSharp.GameMode.Display; +using SampSharp.GameMode.SAMP; +using SampSharp.GameMode.SAMP.Commands; +using SampSharp.GameMode.World; +using SampSharpGameMode1.Display; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SampSharpGameMode1.Commands +{ + class MapHUD : HUD + { + protected MySQLConnector mySQLConnector = MySQLConnector.Instance(); + private Dictionary teleportations = new Dictionary(); + Player player; + public MapHUD(Player player) : base(player, "mapteleport.json") + { + this.player = player as Player; + if (mySQLConnector != null) + { + float scaleX = 6000 / layer.GetTextdrawSize("mapbox").X; + float scaleY = 6000 / layer.GetTextdrawSize("mapbox").Y; + + Dictionary param = new Dictionary(); + mySQLConnector.OpenReader("SELECT * FROM teleportations WHERE 1=1", param); + Dictionary row = mySQLConnector.GetNextRow(); + int tlpID; + string tlpName; + Vector3 tlpPosition; + Vector2 tlpDisplayedPosition; + teleportations.Clear(); + while (row.Count > 0) + { + tlpID = Convert.ToInt32(row["teleport_id"]); + tlpName = row["teleport_name"]; + tlpPosition = new Vector3( + (float)Convert.ToDouble(row["teleport_pos_x"]), + (float)Convert.ToDouble(row["teleport_pos_y"]), + (float)Convert.ToDouble(row["teleport_pos_z"]) + ); + teleportations[tlpID] = new Vector3R(tlpPosition, (float)Convert.ToDouble(row["teleport_angle"])); + tlpDisplayedPosition = new Vector2( + (tlpPosition.X + 3000) / scaleX + layer.GetTextdrawPosition("mapbox").X, + ((tlpPosition.Y * -1) + 3000) / scaleY + layer.GetTextdrawPosition("mapbox").Y + ); + layer.CreateBackground(player, "tlps_" + tlpID, tlpDisplayedPosition, new Vector2(5, 5), ColorPalette.Secondary.Main.GetColor()); + layer.SetTextdrawText("tlps_" + tlpID, "LD_POOL:nib"); + layer.UpdateTextdraw("tlps_" + tlpID); + layer.SetClickable("tlps_" + tlpID); + + Color color = ColorPalette.Primary.Main.GetColor(); + color = new Color(color.R, color.G, color.B, 0.8f); + layer.CreateTextdraw(player, "info_" + tlpID, TextdrawLayer.TextdrawType.Box); + layer.SetTextdrawText("info_" + tlpID, $"{tlpName}"); + layer.SetTextdrawSize("info_" + tlpID, 5, 50); + layer.SetTextdrawColor("info_" + tlpID, ColorPalette.Secondary.Main.GetColor()); + layer.SetTextdrawBoxColor("info_" + tlpID, new Color(100, 100, 100, 0.8f)); + layer.SetTextdrawPosition("info_" + tlpID, layer.GetTextdrawPosition("tlps_" + tlpID) + new Vector2(0, 8)); + layer.SetTextdrawLetterSize("info_" + tlpID, 0.15f, 0.6f); + layer.SetTextdrawFont("info_" + tlpID, 1); + layer.SetTextdrawAlignment("info_" + tlpID, 2); + layer.SetClickable("info_" + tlpID); + + row = mySQLConnector.GetNextRow(); + } + mySQLConnector.CloseReader(); + layer.UnselectAllTextdraw(); + + layer.TextdrawClicked += OnTextdrawClicked; + } + else + { + Logger.WriteLineAndClose("TeleportCommands.cs - MapHUD._:E: MySQL not started"); + } + } + + private void OnTextdrawClicked(object sender, TextdrawLayer.TextdrawEventArgs e) + { + if(Int32.TryParse(e.TextdrawName.Substring(5), out int tlpID)) + { + player.Teleport(teleportations[tlpID].Position); + player.Angle = teleportations[tlpID].Rotation; + player.CancelSelectTextDraw(); + } + } + + public void ForceHide() + { + //layer.Hide("mapbox"); + } + } + class TeleportCommands + { + [Command("tlps")] + private static void TlpsCommand(BasePlayer player) + { + MapHUD mapHUD = new MapHUD(player as Player); + mapHUD.Show(); + mapHUD.ForceHide(); + player.SelectTextDraw(ColorPalette.Primary.Main.GetColor()); + player.CancelClickTextDraw += (sender, e) => + { + if(mapHUD != null) + { + mapHUD.Hide(); + mapHUD = null; + } + }; + } + + [CommandGroup("tlps")] + class TlpsCommandGroup + { + [Command("add", PermissionChecker = typeof(AdminPermissionChecker))] + private static void AddCommand(BasePlayer player) + { + InputDialog dialog = new InputDialog("Creating Teleport point", "Type the name of the teleport point", false, "Save", "Cancel"); + dialog.Response += (sender, e) => + { + if(e.DialogButton == DialogButton.Left) + { + MySQLConnector mySQLConnector = MySQLConnector.Instance(); + Dictionary param = new Dictionary(); + param.Add("@name", e.InputText); + param.Add("@pos_x", e.Player.Position.X); + param.Add("@pos_y", e.Player.Position.Y); + param.Add("@pos_z", e.Player.Position.Z); + param.Add("@angle", e.Player.Angle); + param.Add("@zone", Zone.GetZoneName(e.Player.Position)); + mySQLConnector.Execute("INSERT INTO teleportations (teleport_name, teleport_pos_x, teleport_pos_y, teleport_pos_z, teleport_angle, teleport_zone) VALUES" + + "(@name, @pos_x, @pos_y, @pos_z, @angle, @zone)", param); + if (mySQLConnector.RowsAffected > 0) + { + player.SendClientMessage($"{ColorPalette.Primary.Main}The teleport point {ColorPalette.Secondary.Main}\"{e.InputText}\"{ColorPalette.Primary.Main} has been created"); + } + } + }; + dialog.Show(player); + } + } + } +} diff --git a/SampSharpGameMode1/Display/ColorPalette.cs b/SampSharpGameMode1/Display/ColorPalette.cs index 6aac65d..d043edf 100644 --- a/SampSharpGameMode1/Display/ColorPalette.cs +++ b/SampSharpGameMode1/Display/ColorPalette.cs @@ -15,6 +15,11 @@ public SAMPColor(SampSharp.GameMode.SAMP.Color clr) { this.color = Color.FromArgb(clr.A, clr.R, clr.G, clr.B); } + public SampSharp.GameMode.SAMP.Color GetColor() + { + return new SampSharp.GameMode.SAMP.Color(color.R, color.G, color.B, color.A); + + } public override string ToString() { return "{" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2") + "}"; diff --git a/SampSharpGameMode1/Display/HUD.cs b/SampSharpGameMode1/Display/HUD.cs index 7612110..0282eb9 100644 --- a/SampSharpGameMode1/Display/HUD.cs +++ b/SampSharpGameMode1/Display/HUD.cs @@ -21,7 +21,7 @@ public class HUD public HUD(Player player, string jsonFilename) { layer = new TextdrawLayer(); - string filename = Directory.GetCurrentDirectory() + "\\scriptfiles\\" + jsonFilename; + string filename = Directory.GetCurrentDirectory() + "/scriptfiles/" + jsonFilename; string jsonData = ""; if (File.Exists(filename)) { diff --git a/SampSharpGameMode1/Display/TextdrawCreator.cs b/SampSharpGameMode1/Display/TextdrawCreator.cs index a33fac5..b242e8a 100644 --- a/SampSharpGameMode1/Display/TextdrawCreator.cs +++ b/SampSharpGameMode1/Display/TextdrawCreator.cs @@ -25,7 +25,7 @@ public TextdrawHUD(Player player) { isSwitched = false; layer = new TextdrawLayer(); - string filename = Directory.GetCurrentDirectory() + "\\scriptfiles\\tdcreator.json"; + string filename = Directory.GetCurrentDirectory() + "/scriptfiles/tdcreator.json"; string jsonData = ""; if (File.Exists(filename)) { @@ -433,7 +433,7 @@ private void ShowTextdrawDialog() string[] posStr = input.Split(";"); if(double.TryParse(posStr[0], out double posX) && double.TryParse(posStr[1], out double posY)) { - layers[layerIndex].SetTextdrawPos(editingTDName, new Vector2(posX, posY)); + layers[layerIndex].SetTextdrawPosition(editingTDName, new Vector2(posX, posY)); UpdateRuler(); } else player.SendClientMessage(Color.Red, "Format error"); @@ -473,7 +473,7 @@ public void Update() } public void Load(string name) { - string filename = Directory.GetCurrentDirectory() + "\\scriptfiles\\" + name + ".json"; + string filename = Directory.GetCurrentDirectory() + "/scriptfiles/" + name + ".json"; string jsonData = ""; if (File.Exists(filename)) { @@ -566,7 +566,7 @@ public void Save(string name) output = JsonConvert.SerializeObject(listOfTextdraw, Formatting.Indented); player.SendClientMessage(output); - string filename = Directory.GetCurrentDirectory() + "\\scriptfiles\\" + name + ".json"; + string filename = Directory.GetCurrentDirectory() + "/scriptfiles/" + name + ".json"; try { diff --git a/SampSharpGameMode1/Display/TextdrawLayer.cs b/SampSharpGameMode1/Display/TextdrawLayer.cs index 6b7d174..eb13edb 100644 --- a/SampSharpGameMode1/Display/TextdrawLayer.cs +++ b/SampSharpGameMode1/Display/TextdrawLayer.cs @@ -9,6 +9,11 @@ namespace SampSharpGameMode1.Display { public class TextdrawLayer { + public class TextdrawEventArgs : EventArgs + { + public string TextdrawName { get; set; } + } + private Color editingColor = new Color(180, 50, 50); Dictionary textdrawList = new Dictionary(); @@ -20,6 +25,13 @@ public class TextdrawLayer public enum TextdrawType { Background, Box, Text }; public enum EditingMode { Unselected, Position, WidthHeight }; + + public event EventHandler TextdrawClicked; + protected virtual void OnTextdrawClicked(TextdrawEventArgs e) + { + TextdrawClicked?.Invoke(this, e); + } + public Dictionary GetTextdrawList() { return textdrawList; @@ -39,13 +51,14 @@ public Textdraw CreateBackground(BasePlayer owner, string name, Vector2 position textdrawList[name].type = "background"; textdrawList[name].ForeColor = color; + textdrawType[name] = TextdrawType.Background; textdrawEditMode[name] = EditingMode.Position; textdrawOrder.Add(name); textdrawList[name].Show(); return textdrawList[name]; } - public Textdraw CreateTextdraw(BasePlayer owner, string name, TextdrawType type) + public Textdraw CreateTextdraw(BasePlayer owner, string name, TextdrawType type, string text = "") { textdrawList.Add(name, new Textdraw(owner, name)); textdrawList[name].Position = new Vector2(320.0f, 240.0f); @@ -61,7 +74,7 @@ public Textdraw CreateTextdraw(BasePlayer owner, string name, TextdrawType type) } else if (type == TextdrawType.Text) { - textdrawList[name].text = name; + textdrawList[name].text = text; textdrawList[name].type = "text"; textdrawType[name] = TextdrawType.Text; } @@ -105,16 +118,11 @@ public void Destroy() td.Value.AutoDestroy = true; this.HideAll(); } - - public Boolean SetTextdrawPosition(string name, Vector2 position) + public Vector2 GetTextdrawSize(string name) { - if (!textdrawList.ContainsKey(name)) + if (!textdrawType.ContainsKey(name)) throw new TextdrawNameNotFoundException(name); - float newPosX, newPosY; - newPosX = (position.X >= 0) ? position.X : textdrawList[name].Position.X; - newPosY = (position.Y >= 0) ? position.Y : textdrawList[name].Position.Y; - textdrawList[name].Position = new Vector2(newPosX, newPosY); - return true; + return new Vector2(textdrawList[name].Width, textdrawList[name].Height); } public Boolean SetTextdrawSize(string name, float width, float height) { @@ -154,11 +162,15 @@ public Vector2 GetTextdrawPosition(string name) throw new TextdrawNameNotFoundException(name); return textdrawList[name].Position; } - public void SetTextdrawPos(string name, Vector2 pos) + public Boolean SetTextdrawPosition(string name, Vector2 position) { if (!textdrawList.ContainsKey(name)) throw new TextdrawNameNotFoundException(name); - textdrawList[name].Position = pos; + float newPosX, newPosY; + newPosX = (position.X >= 0) ? position.X : textdrawList[name].Position.X; + newPosY = (position.Y >= 0) ? position.Y : textdrawList[name].Position.Y; + textdrawList[name].Position = new Vector2(newPosX, newPosY); + return true; } public void SetTextdrawType(string name, TextdrawType type) @@ -284,14 +296,14 @@ public void UpdateTextdraw(string name) textdrawList[name].Show(); } - public void SetOnClickCallback(string name, Action callback) + public void SetClickable(string name) { textdrawList[name].Selectable = true; textdrawList[name].Click += (object sender, SampSharp.GameMode.Events.ClickPlayerTextDrawEventArgs e) => { - callback(); + OnTextdrawClicked(new TextdrawEventArgs { TextdrawName = name }); }; - } + } public bool SelectTextdraw(string name) { diff --git a/SampSharpGameMode1/Events/Derbys/Derby.cs b/SampSharpGameMode1/Events/Derbys/Derby.cs index f1870f3..9dcbaad 100644 --- a/SampSharpGameMode1/Events/Derbys/Derby.cs +++ b/SampSharpGameMode1/Events/Derbys/Derby.cs @@ -38,6 +38,7 @@ public class Derby : EventSource public bool IsLoaded { get; private set; } public bool IsCreatorMode { get; set; } public string Creator { get; set; } + public float MinimumHeight { get; set; } // Launcher only @@ -71,6 +72,14 @@ protected virtual void OnFinished(DerbyFinishedEventArgs e) #endregion #region PlayerEvents + private void OnPlayerUpdate(object sender, PlayerUpdateEventArgs e) + { + if(((BasePlayer)sender).Position.Z < this.MinimumHeight) + { + OnPlayerFinished((Player)sender, "Fall from the map"); + ((Player)sender).Update -= OnPlayerUpdate; + } + } public void OnPlayerDisconnect(object sender, DisconnectEventArgs e) { OnPlayerFinished((Player)sender, "Disconnected"); @@ -125,6 +134,7 @@ public void Load(int id, int virtualworld = -1) { this.StartingVehicle = null; } + this.MinimumHeight = (float)Convert.ToDouble(row["derby_minheight"]); } else { @@ -236,6 +246,7 @@ public void Prepare(List slots) slot.Player.VirtualWorld = virtualWorld; + slot.Player.Update += OnPlayerUpdate; slot.Player.ExitVehicle += OnPlayerExitVehicle; slot.Player.KeyStateChanged += OnPlayerKeyStateChanged; slot.Player.Disconnected += OnPlayerDisconnect; @@ -434,6 +445,7 @@ public void Eject(Player player) } player.DisableCheckpoint(); player.DisableRaceCheckpoint(); + player.Update -= OnPlayerUpdate; player.ExitVehicle -= OnPlayerExitVehicle; player.KeyStateChanged -= OnPlayerKeyStateChanged; player.Disconnected -= OnPlayerDisconnect; @@ -469,5 +481,79 @@ public bool IsPlayerSpectating(Player player) { return this.spectatingPlayers.Contains(player); } + + public static List GetPlayerDerbyList(Player player) + { + MySQLConnector mySQLConnector = MySQLConnector.Instance(); + mySQLConnector = MySQLConnector.Instance(); + Dictionary param = new Dictionary + { + { "@name", player.Name } + }; + mySQLConnector.OpenReader("SELECT derby_id, derby_name FROM derbys WHERE derby_creator = @name", param); + List result = new List(); + Dictionary row = mySQLConnector.GetNextRow(); + while (row.Count > 0) + { + result.Add(row["derby_id"] + "_" + Display.ColorPalette.Primary.Main + row["derby_name"]); + row = mySQLConnector.GetNextRow(); + } + mySQLConnector.CloseReader(); + + return result; + } + + public static Dictionary Find(string str) + { + MySQLConnector mySQLConnector = MySQLConnector.Instance(); + mySQLConnector = MySQLConnector.Instance(); + Dictionary param = new Dictionary + { + { "@name", str } + }; + mySQLConnector.OpenReader("SELECT derby_id, derby_name FROM derbys WHERE derby_name LIKE @name", param); + Dictionary results = mySQLConnector.GetNextRow(); + mySQLConnector.CloseReader(); + return results; + } + public static Dictionary GetInfo(int id) + { + // id, name, creator, number of spawn points, number of pickups, number of map objects + Dictionary results = new Dictionary(); + Dictionary row; + bool exists = false; + + MySQLConnector mySQLConnector = MySQLConnector.Instance(); + Dictionary param = new Dictionary + { + { "@id", id } + }; + + mySQLConnector.OpenReader("SELECT derby_id, derby_name, derby_creator, map_name FROM derbys LEFT JOIN maps ON (derby_name = map_id) WHERE derby_id = @id", param); + + row = mySQLConnector.GetNextRow(); + if (row.Count > 0) exists = true; + foreach (KeyValuePair kvp in row) + results.Add(MySQLConnector.Field.GetFieldName(kvp.Key), kvp.Value); + + mySQLConnector.CloseReader(); + + if (exists) + { + mySQLConnector.OpenReader("SELECT COUNT(*) as nbr " + + "FROM derby_spawn WHERE derby_id = @id", param); + row = mySQLConnector.GetNextRow(); + results.Add("Spawn points", row["nbr"]); + mySQLConnector.CloseReader(); + + mySQLConnector.OpenReader("SELECT COUNT(*) as nbr " + + "FROM derby_pickups WHERE derby_id = @id", param); + row = mySQLConnector.GetNextRow(); + results.Add("Pickups", row["nbr"]); + mySQLConnector.CloseReader(); + } + + return results; + } } } diff --git a/SampSharpGameMode1/Events/Derbys/DerbyCreator.cs b/SampSharpGameMode1/Events/Derbys/DerbyCreator.cs index 05a13d4..ab97fe1 100644 --- a/SampSharpGameMode1/Events/Derbys/DerbyCreator.cs +++ b/SampSharpGameMode1/Events/Derbys/DerbyCreator.cs @@ -293,9 +293,11 @@ public Boolean Save() { { "@name", editingDerby.Name }, { "@mapid", editingDerby.MapId == -1 ? null : editingDerby.MapId.ToString() }, + { "@vehicleid", editingDerby.StartingVehicle }, + { "@minheight", editingDerby.MinimumHeight }, { "@id", editingDerby.Id } }; - mySQLConnector.Execute("UPDATE derbys SET derby_name=@name, derby_map=@mapid WHERE derby_id=@id", param); + mySQLConnector.Execute("UPDATE derbys SET derby_name=@name, derby_map=@mapid, derby_startvehicle=@vehicleid, derby_minheight=@minheight WHERE derby_id=@id", param); isNew = false; return (mySQLConnector.RowsAffected > 0); } @@ -310,11 +312,12 @@ public Boolean Save() { { "@derby_name", name }, { "@derby_creator", player.Name }, - { "@derby_startvehicle", editingDerby.StartingVehicle } + { "@derby_startvehicle", editingDerby.StartingVehicle }, + { "@derby_minheight", editingDerby.MinimumHeight }, }; editingDerby.Id = (int)mySQLConnector.Execute("INSERT INTO derbys " + - "(derby_name, derby_creator, derby_startvehicle) VALUES" + - "(@derby_name, @derby_creator, @derby_startvehicle)", param); + "(derby_name, derby_creator, derby_startvehicle, derby_minheight) VALUES" + + "(@derby_name, @derby_creator, @derby_startvehicle, @derby_minheight)", param); if (mySQLConnector.RowsAffected > 0) { editingDerby.Name = name; @@ -407,6 +410,7 @@ private void ShowDerbyDialog() derbyDialog.AddItem("Edit derby name"); derbyDialog.AddItem("Start Spawn creator"); derbyDialog.AddItem("Load a map ..."); + derbyDialog.AddItem("Set minimum height"); derbyDialog.Show(player); derbyDialog.Response += DerbyDialog_Response; @@ -493,8 +497,8 @@ private void DerbyDialog_Response(object sender, DialogResponseEventArgs e) hud.SetEditingMode(editingMode); } break; - } - case 3: + } + case 3: // Load a map { InputDialog findMapDialog = new InputDialog("Find a map", "Type the name of the map you want to load, or empty for full list", false, "Search", "Cancel"); findMapDialog.Show(player); @@ -512,13 +516,32 @@ private void DerbyDialog_Response(object sender, DialogResponseEventArgs e) }; break; } + case 4: // Set minimum height + { + MessageDialog minHeightDialog = new MessageDialog("Setting minimum height", "This setting is used to determinate when player fall from the map. Place yourself on the lowest part of your derby, when you are ready press \"SET\"", "SET", "Cancel"); + minHeightDialog.Response += (sender, eventArgs) => + { + if (eventArgs.DialogButton == DialogButton.Left) + { + editingDerby.MinimumHeight = player.Position.Z - 10.0f; + player.Notificate("Minimum height set"); + } + else + { + player.Notificate("Cancelled"); + ShowDerbyDialog(); + } + }; + minHeightDialog.Show(player); + break; + } } } } } private void ShowLoadMapDialog(string text) { - Dictionary maps = Map.FindAll(text); + Dictionary maps = Map.FindAll(text, player); if (maps.Count == 0) { player.Notificate("No results"); @@ -632,64 +655,5 @@ private void moverObject_Edited(object sender, EditPlayerObjectEventArgs e) if(e.EditObjectResponse == EditObjectResponse.Final || e.EditObjectResponse == EditObjectResponse.Cancel) lastPickedUpPickup = null; } - - public static Dictionary Find(string str) - { - MySQLConnector mySQLConnector = MySQLConnector.Instance(); - mySQLConnector = MySQLConnector.Instance(); - Dictionary param = new Dictionary - { - { "@name", str } - }; - mySQLConnector.OpenReader("SELECT derby_id, derby_name FROM derbys WHERE derby_name LIKE @name", param); - Dictionary results = mySQLConnector.GetNextRow(); - mySQLConnector.CloseReader(); - return results; - } - public static Dictionary GetInfo(int id) - { - // id, name, creator, type, number of spawn points, number of pickups, number of map objects - Dictionary results = new Dictionary(); - Dictionary row; - bool exists = false; - - MySQLConnector mySQLConnector = MySQLConnector.Instance(); - Dictionary param = new Dictionary - { - { "@id", id } - }; - - mySQLConnector.OpenReader("SELECT derby_id, derby_name, derby_creator FROM derbys WHERE derby_id = @id", param); - - row = mySQLConnector.GetNextRow(); - if (row.Count > 0) exists = true; - foreach (KeyValuePair kvp in row) - results.Add(MySQLConnector.Field.GetFieldName(kvp.Key), kvp.Value); - - mySQLConnector.CloseReader(); - - if(exists) - { - mySQLConnector.OpenReader("SELECT COUNT(*) as nbr " + - "FROM derby_spawn WHERE derby_id = @id", param); - row = mySQLConnector.GetNextRow(); - results.Add("Spawn points", row["nbr"]); - mySQLConnector.CloseReader(); - - mySQLConnector.OpenReader("SELECT COUNT(*) as nbr " + - "FROM derby_pickups WHERE derby_id = @id", param); - row = mySQLConnector.GetNextRow(); - results.Add("Pickups", row["nbr"]); - mySQLConnector.CloseReader(); - - mySQLConnector.OpenReader("SELECT COUNT(*) as nbr " + - "FROM derby_mapobjects WHERE derby_id = @id", param); - row = mySQLConnector.GetNextRow(); - results.Add("Map objects", row["nbr"]); - mySQLConnector.CloseReader(); - } - - return results; - } } } diff --git a/SampSharpGameMode1/Events/Derbys/DerbyPickupRandomEvent.cs b/SampSharpGameMode1/Events/Derbys/DerbyPickupRandomEvent.cs index a214c56..86f6a23 100644 --- a/SampSharpGameMode1/Events/Derbys/DerbyPickupRandomEvent.cs +++ b/SampSharpGameMode1/Events/Derbys/DerbyPickupRandomEvent.cs @@ -3,7 +3,7 @@ using SampSharp.GameMode.World; using SampSharp.Streamer.World; using System; -using System.Collections.Generic; +using System.Linq; using System.Threading; namespace SampSharpGameMode1.Events.Derbys @@ -130,17 +130,26 @@ private void OnPlayerKeyStateChanged(Object sender, KeyStateChangedEventArgs eve SampSharp.GameMode.SAMP.Timer.RunOnce(8000, () => { explosionOffset = new Vector3(rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), 0.0); - BasePlayer.CreateExplosionForAll(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f); + foreach (BasePlayer p in BasePlayer.GetAll().Where(p => p.VirtualWorld == this.Player.VirtualWorld)) + { + p.CreateExplosion(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f); + } }); SampSharp.GameMode.SAMP.Timer.RunOnce(8100, () => { explosionOffset = new Vector3(rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), 0.0); - BasePlayer.CreateExplosionForAll(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f); + foreach (BasePlayer p in BasePlayer.GetAll().Where(p => p.VirtualWorld == this.Player.VirtualWorld)) + { + p.CreateExplosion(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f); + } }); SampSharp.GameMode.SAMP.Timer.RunOnce(8200, () => { explosionOffset = new Vector3(rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), 0.0); - BasePlayer.CreateExplosionForAll(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f); + foreach (BasePlayer p in BasePlayer.GetAll().Where(p => p.VirtualWorld == this.Player.VirtualWorld)) + { + p.CreateExplosion(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f); + } }); SampSharp.GameMode.SAMP.Timer.RunOnce(10000, () => { diff --git a/SampSharpGameMode1/Events/Races/Race.cs b/SampSharpGameMode1/Events/Races/Race.cs index 1c93659..46d8f40 100644 --- a/SampSharpGameMode1/Events/Races/Race.cs +++ b/SampSharpGameMode1/Events/Races/Race.cs @@ -653,6 +653,11 @@ private void UpdatePlayerCheckpoint(Player player) if (cp == this.checkpoints[this.checkpoints.Count - 1]) // If it's the last checkpoint { player.SetRaceCheckpoint(cp.Type + 1, cp.Position, Vector3.Zero, cp.Size); + foreach (Player p in spectatingPlayers) + { + if (players[playersData[p].spectatePlayerIndex] == player) + p.SetRaceCheckpoint(cp.Type + 1, cp.Position, Vector3.Zero, cp.Size); + } } else { @@ -660,6 +665,11 @@ private void UpdatePlayerCheckpoint(Player player) { Checkpoint nextcp = this.checkpoints[cp.Idx + 1]; player.SetRaceCheckpoint(cp.Type, cp.Position, nextcp.Position, cp.Size); + foreach(Player p in spectatingPlayers) + { + if(players[playersData[p].spectatePlayerIndex] == player) + p.SetRaceCheckpoint(cp.Type, cp.Position, nextcp.Position, cp.Size); + } } catch (KeyNotFoundException e) { @@ -885,5 +895,96 @@ public bool IsPlayerSpectating(Player player) { return this.spectatingPlayers.Contains(player); } + + + public static List GetPlayerRaceList(Player player) + { + MySQLConnector mySQLConnector = MySQLConnector.Instance(); + mySQLConnector = MySQLConnector.Instance(); + Dictionary param = new Dictionary + { + { "@name", player.Name } + }; + mySQLConnector.OpenReader("SELECT race_id, race_name FROM races WHERE race_creator = @name", param); + List result = new List(); + Dictionary row = mySQLConnector.GetNextRow(); + while (row.Count > 0) + { + result.Add(row["race_id"] + "_" + Display.ColorPalette.Primary.Main + row["race_name"]); + row = mySQLConnector.GetNextRow(); + } + mySQLConnector.CloseReader(); + + return result; + } + + public static Dictionary Find(string str) + { + MySQLConnector mySQLConnector = MySQLConnector.Instance(); + mySQLConnector = MySQLConnector.Instance(); + Dictionary param = new Dictionary + { + { "@name", str } + }; + mySQLConnector.OpenReader("SELECT race_id, race_name FROM races WHERE race_name LIKE @name", param); + Dictionary results = mySQLConnector.GetNextRow(); + mySQLConnector.CloseReader(); + return results; + } + + public static Dictionary GetInfo(int id) + { + // id, name, creator, number of checkpoints, zone, number of spawnpoints + Dictionary results = new Dictionary(); + Dictionary row; + + MySQLConnector mySQLConnector = MySQLConnector.Instance(); + Dictionary param = new Dictionary + { + { "@id", id } + }; + + mySQLConnector.OpenReader("SELECT race_id, race_name, race_creator, map_name FROM races LEFT JOIN maps ON (race_map = map_id) WHERE race_id = @id", param); + + row = mySQLConnector.GetNextRow(); + foreach (KeyValuePair kvp in row) + results.Add(MySQLConnector.Field.GetFieldName(kvp.Key), kvp.Value); + + mySQLConnector.CloseReader(); + + mySQLConnector.OpenReader("SELECT checkpoint_id, checkpoint_number, checkpoint_pos_x, checkpoint_pos_y, checkpoint_pos_z " + + "FROM race_checkpoints WHERE race_id = @id", param); + int nbrOfCheckpoints = 0; + row = mySQLConnector.GetNextRow(); + Vector3 firstCheckpointPos = new Vector3(); + while (row.Count > 0) + { + nbrOfCheckpoints++; + if (row["checkpoint_number"] == "0") + { + firstCheckpointPos = new Vector3( + (float)Convert.ToDouble(row["checkpoint_pos_x"]), + (float)Convert.ToDouble(row["checkpoint_pos_y"]), + (float)Convert.ToDouble(row["checkpoint_pos_z"]) + ); + } + row = mySQLConnector.GetNextRow(); + } + results.Add("Number of checkpoints", nbrOfCheckpoints.ToString()); + mySQLConnector.CloseReader(); + + string zoneStr = Zone.GetZoneName(firstCheckpointPos); + results.Add("Zone", zoneStr); + + mySQLConnector.OpenReader("SELECT COUNT(spawn_index) as nbr " + + "FROM race_spawn WHERE race_id = @id", param); + row = mySQLConnector.GetNextRow(); + if (row.Count == 0) + results.Add("Number of spawn points", Color.Red + "No spawn point"); + else + results.Add("Number of spawn points", row["nbr"]); + mySQLConnector.CloseReader(); + return results; + } } } diff --git a/SampSharpGameMode1/Events/Races/RaceCreator.cs b/SampSharpGameMode1/Events/Races/RaceCreator.cs index e2edec1..7a19307 100644 --- a/SampSharpGameMode1/Events/Races/RaceCreator.cs +++ b/SampSharpGameMode1/Events/Races/RaceCreator.cs @@ -29,7 +29,6 @@ public HUD(Player player) : base(player, "racecreator.json") layer.SetTextdrawText("totalcp", "Total CP: 0"); layer.SetTextdrawText("editingmode", "Mode: None"); layer.UnselectAllTextdraw(); - layer.SetOnClickCallback("editingmode", OnEditingModeClick); } public void Destroy() { @@ -56,10 +55,6 @@ public void SetEditingMode(EditingMode editingMode) layer.SetTextdrawText("editingmode", editingMode.ToString()); this.SetSelectedIdx(selectedIdx, editingMode); } - private void OnEditingModeClick() - { - Player.SendClientMessageToAll("EditingMode textdraw clicked !"); - } } enum EditingMode { Checkpoints, SpawnPos } @@ -316,9 +311,10 @@ public Boolean Save() { { "@name", editingRace.Name }, { "@mapid", editingRace.MapId == -1 ? null : editingRace.MapId.ToString() }, + { "@vehicleid", editingRace.StartingVehicle }, { "@id", editingRace.Id } }; - mySQLConnector.Execute("UPDATE races SET race_name=@name, race_map=@mapid WHERE race_id=@id", param); + mySQLConnector.Execute("UPDATE races SET race_name=@name, race_map=@mapid, race_startvehicle=@vehicleid WHERE race_id=@id", param); isNew = false; return (mySQLConnector.RowsAffected > 0); } @@ -657,7 +653,7 @@ private void RaceDialog_Response(object sender, SampSharp.GameMode.Events.Dialog private void ShowLoadMapDialog(string text) { - Dictionary maps = Map.FindAll(text); + Dictionary maps = Map.FindAll(text, player); if (maps.Count == 0) { player.Notificate("No results"); @@ -1000,98 +996,5 @@ private void moverObject_Edited(object sender, SampSharp.GameMode.Events.EditPla player.cameraController.Enabled = true; } } - - public static List GetPlayerRaceList(Player player) - { - - MySQLConnector mySQLConnector = MySQLConnector.Instance(); - mySQLConnector = MySQLConnector.Instance(); - Dictionary param = new Dictionary - { - { "@name", player.Name } - }; - mySQLConnector.OpenReader("SELECT race_id, race_name FROM races WHERE race_creator = @name", param); - List result = new List(); - Dictionary row = mySQLConnector.GetNextRow(); - while(row.Count > 0) - { - result.Add(row["race_id"] + "_" + Display.ColorPalette.Primary.Main + row["race_name"]); - row = mySQLConnector.GetNextRow(); - } - mySQLConnector.CloseReader(); - - return result; - } - - public static Dictionary Find(string str) - { - MySQLConnector mySQLConnector = MySQLConnector.Instance(); - mySQLConnector = MySQLConnector.Instance(); - Dictionary param = new Dictionary - { - { "@name", str } - }; - mySQLConnector.OpenReader("SELECT race_id, race_name FROM races WHERE race_name LIKE @name", param); - Dictionary results = mySQLConnector.GetNextRow(); - mySQLConnector.CloseReader(); - return results; - } - - public static Dictionary GetInfo(int id) - { - // id, name, creator, type, number of checkpoints, zone, number of spawnpoints - Dictionary results = new Dictionary(); - Dictionary row; - - MySQLConnector mySQLConnector = MySQLConnector.Instance(); - Dictionary param = new Dictionary - { - { "@id", id } - }; - - mySQLConnector.OpenReader("SELECT race_id, race_name, race_creator FROM races WHERE race_id = @id", param); - - row = mySQLConnector.GetNextRow(); - foreach (KeyValuePair kvp in row) - results.Add(MySQLConnector.Field.GetFieldName(kvp.Key), kvp.Value); - - mySQLConnector.CloseReader(); - - mySQLConnector.OpenReader("SELECT checkpoint_id, checkpoint_number, checkpoint_pos_x, checkpoint_pos_y, checkpoint_pos_z " + - "FROM race_checkpoints WHERE race_id = @id", param); - int nbrOfCheckpoints = 0; - row = mySQLConnector.GetNextRow(); - Vector3 firstCheckpointPos = new Vector3(); - while(row.Count > 0) - { - nbrOfCheckpoints++; - if(row["checkpoint_number"] == "0") - { - firstCheckpointPos = new Vector3( - (float)Convert.ToDouble(row["checkpoint_pos_x"]), - (float)Convert.ToDouble(row["checkpoint_pos_y"]), - (float)Convert.ToDouble(row["checkpoint_pos_z"]) - ); - } - row = mySQLConnector.GetNextRow(); - } - results.Add("Number of checkpoints", nbrOfCheckpoints.ToString()); - mySQLConnector.CloseReader(); - - // On récupère la zone du premier checkpoint - Zone zone = new Zone(); - string zoneStr = zone.GetZoneName(firstCheckpointPos); - results.Add("Zone", zoneStr); - - mySQLConnector.OpenReader("SELECT COUNT(spawn_index) as nbr " + - "FROM race_spawn WHERE race_id = @id", param); - row = mySQLConnector.GetNextRow(); - if (row.Count == 0) - results.Add("Number of spawn points", Color.Red + "No spawn point"); - else - results.Add("Number of spawn points", row["nbr"]); - mySQLConnector.CloseReader(); - return results; - } } } diff --git a/SampSharpGameMode1/GameMode.cs b/SampSharpGameMode1/GameMode.cs index aa612af..b09735f 100644 --- a/SampSharpGameMode1/GameMode.cs +++ b/SampSharpGameMode1/GameMode.cs @@ -35,9 +35,19 @@ protected override void OnInitialized(EventArgs e) #endif Console.WriteLine("----------------------------------\n"); - //this.AddPlayerClass(1, 1, new Vector3(1431.6393, 1519.5398, 10.5988), 0.0f); // airlv + SetGameModeText("Free/Race/Derby"); + + this.AddPlayerClass(1, 0, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); this.AddPlayerClass(1, 1, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); - //this.AddPlayerClass(1, 1, new Vector3(-2699.6025,2381.6885,66.8945), 0.0f); + this.AddPlayerClass(1, 2, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); + this.AddPlayerClass(1, 7, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); + this.AddPlayerClass(1, 8, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); + this.AddPlayerClass(1, 12, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); + this.AddPlayerClass(1, 13, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); + this.AddPlayerClass(1, 17, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); + this.AddPlayerClass(1, 19, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); + this.AddPlayerClass(1, 21, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); + this.AddPlayerClass(1, 15, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f); Logger.Init(); @@ -67,7 +77,7 @@ protected override void OnInitialized(EventArgs e) //Civilisation.PathExtractor.Extract("E:\\Jeux\\GTA San Andreas\\data\\Paths", 54); for (int i = 0; i < 64; i++) { - Civilisation.PathExtractor.Extract(ConfigurationManager.AppSettings["gta_basefolder"] + "\\data\\Paths", i); + Civilisation.PathExtractor.Extract(ConfigurationManager.AppSettings["gta_basefolder"] + "/data/Paths", i); } sw.Stop(); Logger.WriteLineAndClose($"GameMode.cs - GameMode.OnInitialized:I: PathExtractor.Extract => {sw.ElapsedMilliseconds} ms"); diff --git a/SampSharpGameMode1/Logger.cs b/SampSharpGameMode1/Logger.cs index e3f0a6c..1ce9996 100644 --- a/SampSharpGameMode1/Logger.cs +++ b/SampSharpGameMode1/Logger.cs @@ -8,8 +8,7 @@ namespace SampSharpGameMode1 { class Logger { - private static string filename = Directory.GetCurrentDirectory() + "\\scriptfiles\\gamemode.log"; - //private static string filename = BaseMode.Instance.Client.ServerPath + "..\\..\\scriptfiles\\gamemode.log"; + private static string filename = Directory.GetCurrentDirectory() + "/scriptfiles/gamemode.log"; FileStream fileStream = null; @@ -48,16 +47,27 @@ public static void Init() { try { + filename = Path.GetFullPath(filename); FileStream fs = File.Open(filename, FileMode.Create, FileAccess.Write); fs.Close(); - Logger.WriteLineAndClose("Logger.cs - Logger.Init:I: Logger initialized at " + DateTime.Now.ToString(), false); - Console.WriteLine("Logger.cs - Logger.Init:I: Logger initialized"); + if(File.Exists(filename)) + { + Logger.WriteLineAndClose("Logger.cs - Logger.Init:I: Logger initialized at " + DateTime.Now.ToString(), false); + Console.WriteLine("Logger.cs - Logger.Init:I: Logger initialized in " + filename); + } + else + Console.WriteLine("Logger.cs - Logger.Init:E: Error during Logger init, file could not be created"); } catch (IOException e) { Console.WriteLine("Logger.cs - Logger.Init:E: Cannot delete logger file: "); Console.WriteLine(e.Message); } + catch (UnauthorizedAccessException e) + { + Console.WriteLine("Logger.cs - Logger.Init:E: Cannot delete logger file: "); + Console.WriteLine(e.Message); + } } public static void WriteAndClose(string text, bool writeToConsole = true) { diff --git a/SampSharpGameMode1/Map.cs b/SampSharpGameMode1/Map.cs index 8136b6b..d7f9d20 100644 --- a/SampSharpGameMode1/Map.cs +++ b/SampSharpGameMode1/Map.cs @@ -127,16 +127,17 @@ public static List GetAllLoadedMaps() return pool; } - public static Dictionary FindAll(string str) + public static Dictionary FindAll(string str, Player owner) { Dictionary results = new Dictionary(); MySQLConnector mySQLConnector = MySQLConnector.Instance(); Dictionary param = new Dictionary { - { "@name", str } + { "@name", str }, + { "@playerid", owner.DbId } }; - mySQLConnector.OpenReader("SELECT map_id, map_name FROM maps WHERE map_name LIKE @name", param); + mySQLConnector.OpenReader("SELECT map_id, map_name FROM maps WHERE map_name LIKE @name AND map_creator = @playerid", param); Dictionary row = mySQLConnector.GetNextRow(); while(row.Count > 0) @@ -147,5 +148,92 @@ public static Dictionary FindAll(string str) mySQLConnector.CloseReader(); return results; } + public static List GetPlayerMapList(Player player) + { + MySQLConnector mySQLConnector = MySQLConnector.Instance(); + mySQLConnector = MySQLConnector.Instance(); + Dictionary param = new Dictionary + { + { "@playerid", player.DbId } + }; + mySQLConnector.OpenReader("SELECT map_id, map_name FROM maps WHERE map_creator = @playerid", param); + List result = new List(); + Dictionary row = mySQLConnector.GetNextRow(); + while (row.Count > 0) + { + result.Add(row["map_id"] + "_" + Display.ColorPalette.Primary.Main + row["map_name"]); + row = mySQLConnector.GetNextRow(); + } + mySQLConnector.CloseReader(); + + return result; + } + public static Dictionary GetInfo(int id) + { + // id, name, creator, zone, number of objects, creation date, last update date + Dictionary results = new Dictionary(); + Dictionary row; + + MySQLConnector mySQLConnector = MySQLConnector.Instance(); + Dictionary param = new Dictionary + { + { "@id", id } + }; + + mySQLConnector.OpenReader("SELECT map_id, map_name, map_creator, map_creationdate, map_lasteditdate FROM maps WHERE map_id = @id", param); + + row = mySQLConnector.GetNextRow(); + foreach (KeyValuePair kvp in row) + results.Add(MySQLConnector.Field.GetFieldName(kvp.Key), kvp.Value); + + mySQLConnector.CloseReader(); + + mySQLConnector.OpenReader("SELECT obj_id, obj_pos_x, obj_pos_y, obj_pos_z " + + "FROM mapobjects WHERE map_id = @id", param); + int nbrOfObjects = 0; + row = mySQLConnector.GetNextRow(); + Vector3 firstObjectPos = Vector3.Zero; + while (row.Count > 0) + { + nbrOfObjects++; + if (firstObjectPos == Vector3.Zero) + { + firstObjectPos = new Vector3( + (float)Convert.ToDouble(row["obj_pos_x"]), + (float)Convert.ToDouble(row["obj_pos_y"]), + (float)Convert.ToDouble(row["obj_pos_z"]) + ); + } + row = mySQLConnector.GetNextRow(); + } + results.Add("Number of objects", nbrOfObjects.ToString()); + mySQLConnector.CloseReader(); + + string zoneStr = Zone.GetZoneName(firstObjectPos); + results.Add("Zone", zoneStr); + + List usedBy = new List(); + + mySQLConnector.OpenReader("SELECT race_id, race_name FROM races WHERE race_map = @id", param); + row = mySQLConnector.GetNextRow(); + while (row.Count > 0) + { + usedBy.Add($"[Race] {row["race_id"]}_{row["race_name"]}"); + row = mySQLConnector.GetNextRow(); + } + mySQLConnector.CloseReader(); + mySQLConnector.OpenReader("SELECT derby_id, derby_name FROM derbys WHERE derby_map = @id", param); + row = mySQLConnector.GetNextRow(); + while (row.Count > 0) + { + usedBy.Add($"[Derby] {row["derby_id"]}_{row["derby_name"]}"); + row = mySQLConnector.GetNextRow(); + } + mySQLConnector.CloseReader(); + + results.Add("Used in", $"{usedBy.Count} events"); + usedBy.ForEach(evt => results.Add("", evt)); + return results; + } } } diff --git a/SampSharpGameMode1/MapCreator.cs b/SampSharpGameMode1/MapCreator.cs index ed68e0b..e832efa 100644 --- a/SampSharpGameMode1/MapCreator.cs +++ b/SampSharpGameMode1/MapCreator.cs @@ -16,12 +16,26 @@ namespace SampSharpGameMode1 public class MapCreator { const int MAX_OBJECTS_PER_MAP = 1000; + enum Axis + { + X, Y, Z + }; public Map editingMap = null; private bool isNew; public bool IsNew { get { return isNew; } private set { isNew = value; } } + private bool magnet; // If true, the edited object will try to stick to other objects + public bool Magnet { + get { return magnet; } + set { + magnet = value; + hud.SetText("magnet", "Magnet: " + (value ? "On" : "Off")); + hud.SetColor("magnet", value ? Color.Green : Color.White); + } + } + private Player player; private HUD hud; @@ -97,9 +111,9 @@ private void SetPlayerInEditor() hud = new HUD(player, "mapcreator.json"); hud.SetText("mapname", editingMap.Name); hud.SetText("totalobj", "Total: " + editingMap.Objects.Count.ToString() + " objects"); + Magnet = true; player.SendClientMessage("Here are the controls:"); - player.SendClientMessage(" submission key (2/é): Open menu"); - player.SendClientMessage(" Y/N: Unfreeze/Freeze"); + player.SendClientMessage(" Y/N: Unfreeze/Freeze (usefull in Jetpack !)"); } private void Player_Disconnected(object sender, DisconnectEventArgs e) @@ -212,12 +226,25 @@ public void Unload() { player.VirtualWorld = 0; player.CancelEdit(); + player.Disconnected -= Player_Disconnected; player.KeyStateChanged -= Player_KeyStateChanged; } } - public void AddObject(int modelid, Vector3? position = null, Vector3? rotation = null) + /// + /// Creates a new object and returns its ID + /// + /// Model ID of the object to create + /// Position of the new object + /// Rotation of the new object + /// Returns the object ID, -1 if the object is not created + public int AddObject(int modelid, Vector3? position = null, Vector3? rotation = null) { + if(editingMap.Objects.Count >= MAX_OBJECTS_PER_MAP) + { + player.SendClientMessage(Color.Red, "You reached the max number of objects per map"); + return -1; + } MapObject mapObject = new MapObject( -1, modelid, @@ -226,18 +253,84 @@ public void AddObject(int modelid, Vector3? position = null, Vector3? rotation = player.VirtualWorld ); mapObject.Edit(player); + Axis editedAxis = Axis.X; + Vector3 lastObjectPos = mapObject.Position; // Used to detect which axis is being modified + Vector3 lastObjectRot = mapObject.Rotation; // Used to detect which axis is being modified mapObject.Edited += (object sender, SampSharp.Streamer.Events.PlayerEditEventArgs e) => { - mapObject.Position = e.Position; - mapObject.Rotation = e.Rotation; + Vector3 newPosition = e.Position; + Vector3 newRotation = e.Rotation; + if(magnet) + { + if (newPosition.X != lastObjectPos.X) + editedAxis = Axis.X; + if (newPosition.Y != lastObjectPos.Y) + editedAxis = Axis.Y; + if (newPosition.Z != lastObjectPos.Z) + editedAxis = Axis.Z; + + if (newRotation.X != lastObjectRot.X) + editedAxis = Axis.X; + if (newRotation.Y != lastObjectRot.Y) + editedAxis = Axis.Y; + if (newRotation.Z != lastObjectRot.Z) + editedAxis = Axis.Z; + + MapObject nearestObject = null; + float nearestObjectDistance = 99999.0f; + foreach (MapObject obj in editingMap.Objects) + { + if (Vector3.Distance(obj.Position, e.Position) < 50.0 && obj.Id != mapObject.Id) + { + if (nearestObject == null || Vector3.Distance(obj.Position, e.Position) < nearestObjectDistance) + { + nearestObject = obj; + nearestObjectDistance = Vector3.Distance(obj.Position, e.Position); + } + } + } + if(nearestObjectDistance < 3.0f) + { + Console.WriteLine("Nearest object detected: " + nearestObject.Id + " " + nearestObjectDistance); + Console.WriteLine("edited axis: " + editedAxis.ToString()); + if (Math.Abs(nearestObject.Position.X - mapObject.Position.X) < 3.0f && editedAxis == Axis.X) + newPosition = new Vector3(nearestObject.Position.X, newPosition.Y, newPosition.Z); + if (Math.Abs(nearestObject.Position.Y - mapObject.Position.Y) < 3.0f && editedAxis == Axis.Y) + newPosition = new Vector3(newPosition.X, nearestObject.Position.Y, newPosition.Z); + if (Math.Abs(nearestObject.Position.Z - mapObject.Position.Z) < 3.0f && editedAxis == Axis.Z) + newPosition = new Vector3(newPosition.X, newPosition.Y, nearestObject.Position.Z); + + + if (Math.Abs(nearestObject.Rotation.X - mapObject.Rotation.X) < 3.0f && editedAxis == Axis.X) + newRotation = new Vector3(nearestObject.Rotation.X, newRotation.Y, newRotation.Z); + if (Math.Abs(nearestObject.Rotation.Y - mapObject.Rotation.Y) < 3.0f && editedAxis == Axis.Y) + newRotation = new Vector3(newRotation.X, nearestObject.Rotation.Y, newRotation.Z); + if (Math.Abs(nearestObject.Rotation.Z - mapObject.Rotation.Z) < 3.0f && editedAxis == Axis.Z) + newRotation = new Vector3(newRotation.X, newRotation.Y, nearestObject.Rotation.Z); + } + } + mapObject.Position = newPosition; + mapObject.Rotation = newRotation; textLabels[mapObject.Id].Position = e.Position; + if (e.Response == SampSharp.GameMode.Definitions.EditObjectResponse.Final || e.Response == SampSharp.GameMode.Definitions.EditObjectResponse.Cancel) + textLabels[mapObject.Id].Text = $"Object #{mapObject.Id}"; + else if(e.Response == SampSharp.GameMode.Definitions.EditObjectResponse.Update) + textLabels[mapObject.Id].Text = $"Object #{mapObject.Id}\nPos: {mapObject.Position.ToString()}\nRot: {mapObject.Rotation.ToString()}"; + + lastObjectPos = newPosition; + lastObjectRot = newRotation; }; editingMap.Objects.Add(mapObject); textLabels.Add(mapObject.Id, new DynamicTextLabel($"Object #{mapObject.Id}", Color.White, mapObject.Position, 100.0f, null, null, false)); player.SendClientMessage($"Object #{mapObject.Id} created with model {modelid}"); hud.SetText("totalobj", "Total: " + editingMap.Objects.Count.ToString() + " objects"); + return mapObject.Id; } + /// + /// Deletes an object + /// + /// Object ID of the object to delete public void DelObject(int objectid) { if (editingMap.Objects.Find(obj => obj.Id == objectid) is MapObject obj) @@ -252,6 +345,12 @@ public void DelObject(int objectid) else player.SendClientMessage("Unknown object id"); } + + /// + /// Replaces the model ID of an object + /// + /// Object ID to replace + /// Model ID to replace with public void ReplaceObject(int objectid, int modelid) { if (editingMap.Objects.Find(obj => obj.Id == objectid) is MapObject obj) @@ -266,6 +365,26 @@ public void ReplaceObject(int objectid, int modelid) else player.SendClientMessage("Unknown object id"); } + + /// + /// Duplicates an object + /// + /// Object ID to duplicate + public void DuplicateObject(int objectid) + { + if (editingMap.Objects.Find(obj => obj.Id == objectid) is MapObject obj) + { + AddObject(obj.ModelId, obj.Position, obj.Rotation); + hud.SetText("totalobj", "Total: " + editingMap.Objects.Count.ToString() + " objects"); + } + else + player.SendClientMessage("Unknown object id"); + } + + /// + /// Open the in-game position editor for an object + /// + /// Object ID to edit public void EditObject(int objectid) { if(editingMap.Objects.Find(obj => obj.Id == objectid) is MapObject obj) diff --git a/SampSharpGameMode1/MySQLConnector.cs b/SampSharpGameMode1/MySQLConnector.cs index 98ae396..326bc4e 100644 --- a/SampSharpGameMode1/MySQLConnector.cs +++ b/SampSharpGameMode1/MySQLConnector.cs @@ -202,11 +202,16 @@ public class Field {"race_id", "Race ID"}, {"race_name", "Race Name"}, {"race_creator", "Race Creator"}, - {"race_type", "Race Type"}, /* Derby */ {"derby_id", "Derby ID"}, {"derby_name", "Derby Name"}, {"derby_creator", "Derby Creator"}, + /* Map */ + {"map_id", "Map ID"}, + {"map_name", "Map Name"}, + {"map_creator", "Map Creator"}, + {"map_creationdate", "Map Creation date"}, + {"map_lasteditdate", "Map Last edit date"}, }; public static string GetFieldName(string name) diff --git a/SampSharpGameMode1/NPC.cs b/SampSharpGameMode1/NPC.cs index 6357cc5..288c8bd 100644 --- a/SampSharpGameMode1/NPC.cs +++ b/SampSharpGameMode1/NPC.cs @@ -153,7 +153,7 @@ public void Create() try { - string filename = SampSharp.GameMode.BaseMode.Instance.Client.ServerPath + "\\npcmodes\\recordings\\npctest.rec"; + string filename = SampSharp.GameMode.BaseMode.Instance.Client.ServerPath + "/npcmodes/recordings/npctest.rec"; using (FileStream fs = File.Open(filename, FileMode.OpenOrCreate, FileAccess.Write)) { foreach (byte headerbyte in header) diff --git a/SampSharpGameMode1/Physics/CollisionManager.cs b/SampSharpGameMode1/Physics/CollisionManager.cs index d907f8e..98b8c35 100644 --- a/SampSharpGameMode1/Physics/CollisionManager.cs +++ b/SampSharpGameMode1/Physics/CollisionManager.cs @@ -3,8 +3,7 @@ using SampSharp.Streamer; using SampSharp.Streamer.World; using System; -using System.Collections.Generic; -using System.Text; +using System.Linq; using System.Threading; namespace SampSharpGameMode1.Physics @@ -36,7 +35,10 @@ public static void ExplodeOnCollision(DynamicObject obj, Vector3 dest, BasePlaye } if(collisionTarget.distance < 10.0 || collisionWithVehicle) { - BasePlayer.CreateExplosionForAll(objPos, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f); + foreach(BasePlayer p in BasePlayer.GetAll().Where(p => p.VirtualWorld == sender.VirtualWorld)) + { + p.CreateExplosion(obj.Position, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f); + } obj.Dispose(); } Thread.Sleep(500); diff --git a/SampSharpGameMode1/Player.cs b/SampSharpGameMode1/Player.cs index d7ffa28..743be85 100644 --- a/SampSharpGameMode1/Player.cs +++ b/SampSharpGameMode1/Player.cs @@ -87,6 +87,9 @@ public override void OnConnected(EventArgs e) if(!this.IsNPC) { +#if DEBUG + this.Notificate("DEBUG"); +#endif isAuthenticated = false; Adminlevel = 0; @@ -243,7 +246,7 @@ public override void OnKeyStateChanged(KeyStateChangedEventArgs e) } } } - #endregion +#endregion public void Notificate(string message, int style = 3) { diff --git a/SampSharpGameMode1/Zone.cs b/SampSharpGameMode1/Zone.cs index 85cf9a8..c0f43ba 100644 --- a/SampSharpGameMode1/Zone.cs +++ b/SampSharpGameMode1/Zone.cs @@ -7,7 +7,7 @@ namespace SampSharpGameMode1 { class Zone { - class Limit + public class Limit { public float Xmin; public float Ymin; @@ -25,7 +25,7 @@ public Limit(double Xmin, double Ymin, double Zmin, double Xmax, double Ymax, do this.Zmax = (float)Zmax; } } - Dictionary SAMPZone = new Dictionary(); + protected static Dictionary SAMPZone = new Dictionary(); public Zone() { SAMPZone = new Dictionary(); @@ -399,7 +399,7 @@ public Zone() SAMPZone.Add("Whetstone", new Limit(-2997.40, -2892.90, -242.90, -1213.90, -1115.50, 900.00)); } - public string GetZoneName(Vector3 pos) + public static string GetZoneName(Vector3 pos) { string result = ""; foreach(KeyValuePair kvp in SAMPZone) diff --git a/db/sampserver_structure.sql b/db/sampserver_structure.sql index 97efa11..650f8cf 100644 --- a/db/sampserver_structure.sql +++ b/db/sampserver_structure.sql @@ -33,7 +33,7 @@ CREATE TABLE `derby_pickups` ( PRIMARY KEY (`pickup_id`), KEY `derby_pickups_FK` (`derby_id`), CONSTRAINT `derby_pickups_FK` FOREIGN KEY (`derby_id`) REFERENCES `derbys` (`derby_id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -53,7 +53,7 @@ CREATE TABLE `derby_spawn` ( PRIMARY KEY (`spawn_id`), KEY `derby_spawnpos_FK` (`derby_id`), CONSTRAINT `derby_spawnpos_FK` FOREIGN KEY (`derby_id`) REFERENCES `derbys` (`derby_id`) -) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -69,10 +69,11 @@ CREATE TABLE `derbys` ( `derby_creator` varchar(50) NOT NULL, `derby_startvehicle` int(11) NOT NULL DEFAULT 509, `derby_map` int(11) DEFAULT NULL, + `derby_minheight` float NOT NULL DEFAULT 0, PRIMARY KEY (`derby_id`), KEY `derbys_FK` (`derby_map`), CONSTRAINT `derbys_FK` FOREIGN KEY (`derby_map`) REFERENCES `maps` (`map_id`) ON DELETE SET NULL -) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -95,7 +96,7 @@ CREATE TABLE `mapobjects` ( PRIMARY KEY (`obj_id`), KEY `mapobjects_FK` (`map_id`), CONSTRAINT `mapobjects_FK` FOREIGN KEY (`map_id`) REFERENCES `maps` (`map_id`) -) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=115 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -112,7 +113,7 @@ CREATE TABLE `maps` ( `map_creationdate` datetime DEFAULT NULL, `map_lasteditdate` datetime DEFAULT NULL, PRIMARY KEY (`map_id`) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -156,7 +157,7 @@ CREATE TABLE `race_checkpoints` ( PRIMARY KEY (`checkpoint_id`), KEY `race_checkpoints_FK` (`race_id`), CONSTRAINT `race_checkpoints_FK` FOREIGN KEY (`race_id`) REFERENCES `races` (`race_id`) -) ENGINE=InnoDB AUTO_INCREMENT=768 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1005 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -176,7 +177,7 @@ CREATE TABLE `race_records` ( KEY `race_records_FK_1` (`player_id`), CONSTRAINT `race_records_FK` FOREIGN KEY (`race_id`) REFERENCES `races` (`race_id`), CONSTRAINT `race_records_FK_1` FOREIGN KEY (`player_id`) REFERENCES `users` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=68 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=93 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -197,7 +198,7 @@ CREATE TABLE `race_spawn` ( PRIMARY KEY (`spawn_id`), KEY `race_spawnpos_FK` (`race_id`), CONSTRAINT `race_spawnpos_FK` FOREIGN KEY (`race_id`) REFERENCES `races` (`race_id`) -) ENGINE=InnoDB AUTO_INCREMENT=482 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +) ENGINE=InnoDB AUTO_INCREMENT=628 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -218,7 +219,26 @@ CREATE TABLE `races` ( PRIMARY KEY (`race_id`), KEY `races_FK` (`race_map`), CONSTRAINT `races_FK` FOREIGN KEY (`race_map`) REFERENCES `maps` (`map_id`) ON DELETE SET NULL -) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `teleportations` +-- + +DROP TABLE IF EXISTS `teleportations`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `teleportations` ( + `teleport_id` int(11) NOT NULL AUTO_INCREMENT, + `teleport_name` varchar(100) NOT NULL, + `teleport_pos_x` float NOT NULL, + `teleport_pos_y` float NOT NULL, + `teleport_pos_z` float NOT NULL, + `teleport_angle` float NOT NULL, + `teleport_zone` varchar(100) DEFAULT NULL, + PRIMARY KEY (`teleport_id`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -250,4 +270,4 @@ CREATE TABLE `users` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-06-28 4:05:30 +-- Dump completed on 2022-07-17 17:48:04