From c4cb95e5b73211c1b286e9216e2e2374cc1e2ba2 Mon Sep 17 00:00:00 2001 From: Lako Date: Fri, 9 Jun 2023 22:10:25 -0400 Subject: [PATCH] Code revert and isolating game over code --- A1Emu/A1.Objects/FKGamePlayer.cs | 16 +++++ A1Emu/A1.Servers/A1_TCP.cs | 106 +++++++------------------------ 2 files changed, 40 insertions(+), 82 deletions(-) create mode 100644 A1Emu/A1.Objects/FKGamePlayer.cs diff --git a/A1Emu/A1.Objects/FKGamePlayer.cs b/A1Emu/A1.Objects/FKGamePlayer.cs new file mode 100644 index 0000000..fc95b1f --- /dev/null +++ b/A1Emu/A1.Objects/FKGamePlayer.cs @@ -0,0 +1,16 @@ +namespace A1Emu.A1.Objects +{ + public class FKGamePlayer + { + //Used in all/most games. + public int score = 0; + public int round = 0; + + //Plugin 3 + public int health = 200; + public int lives = 3; + + //Plugin 5 + public bool isKicker = false; + } +} diff --git a/A1Emu/A1.Servers/A1_TCP.cs b/A1Emu/A1.Servers/A1_TCP.cs index a485d89..b0766d7 100644 --- a/A1Emu/A1.Servers/A1_TCP.cs +++ b/A1Emu/A1.Servers/A1_TCP.cs @@ -1473,6 +1473,25 @@ namespace A1Emu.A1.Servers // -------------------------------------------------------------------------- \\ // Multiplayer (Generic) \\ // -------------------------------------------------------------------------- \\ + void SendGameOver(XmlWriter writer) + { + writer.WriteStartElement("go"); + //The result attribute seems to determine the coin distribution. + if (mpPlayer.score > mpRival.score) + { + writer.WriteAttributeString("r", "6"); + } + else if (mpPlayer.score < mpRival.score) + { + writer.WriteAttributeString("r", "7"); + } + else + { + writer.WriteAttributeString("r", "8"); + } + + writer.WriteEndElement(); + } async Task JoinGame(string pr, string c, string plugin) { @@ -2037,23 +2056,7 @@ namespace A1Emu.A1.Servers } } con.Close(); - - writer.WriteStartElement("go"); - //The result attribute seems to determine the coin distribution. - if (mpPlayer.score > mpRival.score) - { - writer.WriteAttributeString("r", "6"); - } - else if (mpPlayer.score < mpRival.score) - { - writer.WriteAttributeString("r", "7"); - } - else - { - writer.WriteAttributeString("r", "8"); - } - - writer.WriteEndElement(); + SendGameOver(writer); } } @@ -2132,23 +2135,7 @@ namespace A1Emu.A1.Servers } } con.Close(); - - writer.WriteStartElement("go"); - //The result attribute seems to determine the coin distribution. - if (mpPlayer.score > mpRival.score) - { - writer.WriteAttributeString("r", "6"); - } - else if (mpPlayer.score < mpRival.score) - { - writer.WriteAttributeString("r", "7"); - } - else - { - writer.WriteAttributeString("r", "8"); - } - - writer.WriteEndElement(); + SendGameOver(writer); } } @@ -2448,22 +2435,7 @@ namespace A1Emu.A1.Servers writer.WriteAttributeString("s", mpPlayer.score.ToString()); writer.WriteEndElement(); - writer.WriteStartElement("go"); - //The result attribute seems to determine the coin distribution. - if (mpPlayer.score < mpRival.score) - { - writer.WriteAttributeString("r", "6"); - } - else if (mpPlayer.score > mpRival.score) - { - writer.WriteAttributeString("r", "7"); - } - else - { - writer.WriteAttributeString("r", "8"); - } - - writer.WriteEndElement(); + SendGameOver(writer); } } @@ -2501,22 +2473,7 @@ namespace A1Emu.A1.Servers writer.WriteAttributeString("s", mpRival.score.ToString()); writer.WriteEndElement(); - writer.WriteStartElement("go"); - //The result attribute seems to determine the coin distribution. - if (mpPlayer.score > mpRival.score) - { - writer.WriteAttributeString("r", "6"); - } - else if (mpPlayer.score < mpRival.score) - { - writer.WriteAttributeString("r", "7"); - } - else - { - writer.WriteAttributeString("r", "8"); - } - - writer.WriteEndElement(); + SendGameOver(writer); } writer.WriteEndElement(); @@ -2736,22 +2693,7 @@ namespace A1Emu.A1.Servers //SCRATCH - s="1", leads to game over, but it still adds points to the player...? if (s.Equals("1")) { - writer.WriteStartElement("go"); - //The result attribute seems to determine the coin distribution. - if (mpPlayer.score < mpRival.score) - { - writer.WriteAttributeString("r", "6"); - } - else if (mpPlayer.score > mpRival.score) - { - writer.WriteAttributeString("r", "7"); - } - else - { - writer.WriteAttributeString("r", "8"); - } - - writer.WriteEndElement(); + SendGameOver(writer); } writer.WriteStartElement("nt");