コード例 #1
0
        public override void Stop()
        {
            Program.MainForm.LogDebug("Stopping." + Environment.StackTrace);
            End?.Stop();
            End = null;

            List <Character> Winners;
            List <Character> Losers;

            if (SnowballMap.GetWinner() == SnowballEventState.MAPLE_WIN)
            {
                Winners = MapleTeam.ToList();
                Losers  = StoryTeam.ToList();
            }
            else
            {
                Winners = StoryTeam.ToList();
                Losers  = MapleTeam.ToList();
            }

            _log.Info("Total players: " + (Winners.Count + Losers.Count));
            _log.Info("Winners: " + string.Join(", ", Winners.Select(x => x.Name)));
            _log.Info("Losers: " + string.Join(", ", Losers.Select(x => x.Name)));

            Winners.ForEach(c =>
            {
                MapPacket.MapEffect(c, 4, "Coconut/Victory", true);
                MapPacket.MapEffect(c, 3, "event/coconut/victory", true);
            });
            Losers.ForEach(c =>
            {
                MapPacket.MapEffect(c, 4, "Coconut/Failed", true);
                MapPacket.MapEffect(c, 3, "event/coconut/lose", true);
            });

            RepeatingAction.Start("snowball warper", e =>
            {
                Winners.ForEach(c => c.ChangeMap(WinMapId));
                Losers.ForEach(c => c.ChangeMap(LoseMapId));
                SnowballMap.TimerEndTime = MasterThread.CurrentTime;
                MapleTeam.Clear();
                StoryTeam.Clear();
                SnowballMap.Reset();
                base.Stop();
            }, 10 * 1000, 0);
        }
コード例 #2
0
ファイル: mapgenerator.cs プロジェクト: RavenB/gridsearch
        static void WritePacketClass(TextWriter writer, MapPacket packet)
        {
            string sanitizedName;

            //writer.WriteLine("    /// <summary>" + packet.Name + " packet</summary>");
            writer.WriteLine("    /// <exclude/>");
            writer.WriteLine("    public class " + packet.Name + "Packet : Packet" + Environment.NewLine + "    {");

            // Write out each block class
            foreach (MapBlock block in packet.Blocks)
            {
                WriteBlockClass(writer, block, packet);
            }

            // Header member
            writer.WriteLine("        private Header header;");
            //writer.WriteLine("        /// <summary>The header for this packet</summary>");
            writer.WriteLine("        public override Header Header { get { return header; } set { header = value; } }");

            // PacketType member
            //writer.WriteLine("        /// <summary>Will return PacketType." + packet.Name+ "</summary>");
            writer.WriteLine("        public override PacketType Type { get { return PacketType." + 
                packet.Name + "; } }");

            // Block members
            foreach (MapBlock block in packet.Blocks)
            {
                // TODO: More thorough name blacklisting
                if (block.Name == "Header") { sanitizedName = "_" + block.Name; }
                else { sanitizedName = block.Name; }

                //writer.WriteLine("        /// <summary>" + block.Name + " block</summary>");
                writer.WriteLine("        public " + block.Name + "Block" +
                    ((block.Count != 1) ? "[]" : "") + " " + sanitizedName + ";");
            }

            writer.WriteLine("");

            // Default constructor
            //writer.WriteLine("        /// <summary>Default constructor</summary>");
            writer.WriteLine("        public " + packet.Name + "Packet()" + Environment.NewLine + "        {");
            writer.WriteLine("            Header = new " + packet.Frequency.ToString() + "Header();");
            writer.WriteLine("            Header.ID = " + packet.ID + ";");
            writer.WriteLine("            Header.Reliable = true;"); // Turn the reliable flag on by default
            if (packet.Encoded) { writer.WriteLine("            Header.Zerocoded = true;"); }
            foreach (MapBlock block in packet.Blocks)
            {
                if (block.Name == "Header") { sanitizedName = "_" + block.Name; }
                else { sanitizedName = block.Name; }

                if (block.Count == 1)
                {
                    // Single count block
                    writer.WriteLine("            " + sanitizedName + " = new " + block.Name + "Block();");
                }
                else if (block.Count == -1)
                {
                    // Variable count block
                    writer.WriteLine("            " + sanitizedName + " = new " + block.Name + "Block[0];");
                }
                else
                {
                    // Multiple count block
                    writer.WriteLine("            " + sanitizedName + " = new " + block.Name + 
                        "Block[" + block.Count + "];");
                }
            }
            writer.WriteLine("        }" + Environment.NewLine);

            // Constructor that takes a byte array and beginning position only (no prebuilt header)
            bool seenVariable = false;
            //writer.WriteLine("        /// <summary>Constructor that takes a byte array and beginning position (no prebuilt header)</summary>");
            writer.WriteLine("        public " + packet.Name + "Packet(byte[] bytes, ref int i)" + Environment.NewLine + "        {");
            writer.WriteLine("            int packetEnd = bytes.Length - 1;");
            writer.WriteLine("            Header = new " + packet.Frequency.ToString() + 
                "Header(bytes, ref i, ref packetEnd);");
            foreach (MapBlock block in packet.Blocks)
            {
                if (block.Name == "Header") { sanitizedName = "_" + block.Name; }
                else { sanitizedName = block.Name; }

                if (block.Count == 1)
                {
                    // Single count block
                    writer.WriteLine("            " + sanitizedName + " = new " + block.Name + "Block(bytes, ref i);");
                }
                else if (block.Count == -1)
                {
                    // Variable count block
                    if (!seenVariable)
                    {
                        writer.WriteLine("            int count = (int)bytes[i++];");
                        seenVariable = true;
                    }
                    else
                    {
                        writer.WriteLine("            count = (int)bytes[i++];");
                    }
                    writer.WriteLine("            " + sanitizedName + " = new " + block.Name + "Block[count];");
                    writer.WriteLine("            for (int j = 0; j < count; j++)");
                    writer.WriteLine("            { " + sanitizedName + "[j] = new " +
                        block.Name + "Block(bytes, ref i); }");
                }
                else
                {
                    // Multiple count block
                    writer.WriteLine("            " + sanitizedName + " = new " + block.Name + 
                        "Block[" + block.Count + "];");
                    writer.WriteLine("            for (int j = 0; j < " + block.Count + "; j++)");
                    writer.WriteLine("            { " + sanitizedName + "[j] = new " + 
                        block.Name + "Block(bytes, ref i); }");
                }
            }
            writer.WriteLine("        }" + Environment.NewLine);

            seenVariable = false;

            // Constructor that takes a byte array and a prebuilt header
            //writer.WriteLine("        /// <summary>Constructor that takes a byte array and a prebuilt header</summary>");
            writer.WriteLine("        public " + packet.Name + 
                "Packet(Header head, byte[] bytes, ref int i)" + Environment.NewLine + "        {");
            writer.WriteLine("            Header = head;");
            foreach (MapBlock block in packet.Blocks)
            {
                if (block.Name == "Header") { sanitizedName = "_" + block.Name; }
                else { sanitizedName = block.Name; }

                if (block.Count == 1)
                {
                    // Single count block
                    writer.WriteLine("            " + sanitizedName + " = new " + block.Name + "Block(bytes, ref i);");
                }
                else if (block.Count == -1)
                {
                    // Variable count block
                    if (!seenVariable)
                    {
                        writer.WriteLine("            int count = (int)bytes[i++];");
                        seenVariable = true;
                    }
                    else
                    {
                        writer.WriteLine("            count = (int)bytes[i++];");
                    }
                    writer.WriteLine("            " + sanitizedName + " = new " + block.Name + "Block[count];");
                    writer.WriteLine("            for (int j = 0; j < count; j++)");
                    writer.WriteLine("            { " + sanitizedName + "[j] = new " +
                        block.Name + "Block(bytes, ref i); }");
                }
                else
                {
                    // Multiple count block
                    writer.WriteLine("            " + sanitizedName + " = new " + block.Name +
                        "Block[" + block.Count + "];");
                    writer.WriteLine("            for (int j = 0; j < " + block.Count + "; j++)");
                    writer.WriteLine("            { " + sanitizedName + "[j] = new " +
                        block.Name + "Block(bytes, ref i); }");
                }
            }
            writer.WriteLine("        }" + Environment.NewLine);

            // ToBytes() function
            //writer.WriteLine("        /// <summary>Serialize this packet to a byte array</summary><returns>A byte array containing the serialized packet</returns>");
            writer.WriteLine("        public override byte[] ToBytes()" + Environment.NewLine + "        {");

            writer.Write("            int length = ");
            if (packet.Frequency == PacketFrequency.Low) { writer.WriteLine("10;"); }
            else if (packet.Frequency == PacketFrequency.Medium) { writer.WriteLine("8;"); }
            else { writer.WriteLine("7;"); }

            foreach (MapBlock block in packet.Blocks)
            {
                if (block.Name == "Header") { sanitizedName = "_" + block.Name; }
                else { sanitizedName = block.Name; }

                if (block.Count == 1)
                {
                    // Single count block
                    writer.Write("            length += " + sanitizedName + ".Length;");
                }
            }
            writer.WriteLine(";");

            foreach (MapBlock block in packet.Blocks)
            {
                if (block.Name == "Header") { sanitizedName = "_" + block.Name; }
                else { sanitizedName = block.Name; }

                if (block.Count == -1)
                {
                    writer.WriteLine("            length++;");
                    writer.WriteLine("            for (int j = 0; j < " + sanitizedName +
                        ".Length; j++) { length += " + sanitizedName + "[j].Length; }");
                }
                else if (block.Count > 1)
                {
                    writer.WriteLine("            for (int j = 0; j < " + block.Count +
                        "; j++) { length += " + sanitizedName + "[j].Length; }");
                }
            }

            writer.WriteLine("            if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; }");
            writer.WriteLine("            byte[] bytes = new byte[length];");
            writer.WriteLine("            int i = 0;");
            writer.WriteLine("            header.ToBytes(bytes, ref i);");
            foreach (MapBlock block in packet.Blocks)
            {
                if (block.Name == "Header") { sanitizedName = "_" + block.Name; }
                else { sanitizedName = block.Name; }

                if (block.Count == -1)
                {
                    // Variable count block
                    writer.WriteLine("            bytes[i++] = (byte)" + sanitizedName + ".Length;");
                    writer.WriteLine("            for (int j = 0; j < " + sanitizedName +
                        ".Length; j++) { " + sanitizedName + "[j].ToBytes(bytes, ref i); }");
                }
                else if (block.Count == 1)
                {
                    writer.WriteLine("            " + sanitizedName + ".ToBytes(bytes, ref i);");
                }
                else
                {
                    // Multiple count block
                    writer.WriteLine("            for (int j = 0; j < " + block.Count +
                        "; j++) { " + sanitizedName + "[j].ToBytes(bytes, ref i); }");
                }
            }

            writer.WriteLine("            if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); }");
            writer.WriteLine("            return bytes;" + Environment.NewLine + "        }" + Environment.NewLine);

            // ToString() function
            //writer.WriteLine("        /// <summary>Serialize this packet to a string</summary><returns>A string containing the serialized packet</returns>");
            writer.WriteLine("        public override string ToString()" + Environment.NewLine + "        {");
            writer.WriteLine("            string output = \"--- " + packet.Name + " ---\" + Environment.NewLine;");

            foreach (MapBlock block in packet.Blocks)
            {
                if (block.Name == "Header") { sanitizedName = "_" + block.Name; }
                else { sanitizedName = block.Name; }

                if (block.Count == -1)
                {
                    // Variable count block
                    writer.WriteLine("            for (int j = 0; j < " + 
                        sanitizedName + ".Length; j++)" + Environment.NewLine + "            {");
                    writer.WriteLine("                output += " + sanitizedName + 
                        "[j].ToString() + Environment.NewLine;" + Environment.NewLine + "            }");
                }
                else if (block.Count == 1)
                {
                    writer.WriteLine("                output += " + sanitizedName + ".ToString() + Environment.NewLine;");
                }
                else
                {
                    // Multiple count block
                    writer.WriteLine("            for (int j = 0; j < " + 
                        block.Count + "; j++)" + Environment.NewLine + "            {");
                    writer.WriteLine("                output += " + sanitizedName + 
                        "[j].ToString() + Environment.NewLine;" + Environment.NewLine + "            }");
                }
            }

            writer.WriteLine("            return output;" + Environment.NewLine + "        }" + Environment.NewLine);

            // Closing function bracket
            writer.WriteLine("    }" + Environment.NewLine);
        }
コード例 #3
0
ファイル: mapgenerator.cs プロジェクト: RavenB/gridsearch
        static void WriteBlockClass(TextWriter writer, MapBlock block, MapPacket packet)
        {
            bool variableFields = false;
            bool floatFields = false;

            //writer.WriteLine("        /// <summary>" + block.Name + " block</summary>");
            writer.WriteLine("        /// <exclude/>");
            writer.WriteLine("        [XmlType(\"" + packet.Name.ToLower() + "_" + block.Name.ToLower() + "\")]");
            writer.WriteLine("        public class " + block.Name + "Block" + Environment.NewLine + "        {");

            foreach (MapField field in block.Fields)
            {
                WriteFieldMember(writer, field);

                if (field.Type == FieldType.Variable) { variableFields = true; }
                if (field.Type == FieldType.F32 || field.Type == FieldType.F64) { floatFields = true; }
            }

            // Length property
            writer.WriteLine("");
            //writer.WriteLine("            /// <summary>Length of this block serialized in bytes</summary>");
            writer.WriteLine("            [XmlIgnore]" + Environment.NewLine +
                             "            public int Length" + Environment.NewLine +
                             "            {" + Environment.NewLine + 
                             "                get" + Environment.NewLine +
                             "                {");
            int length = 0;

            // Figure out the length of this block
            foreach (MapField field in block.Fields)
            {
                length += GetFieldLength(writer, field);
            }

            if (!variableFields)
            {
                writer.WriteLine("                    return " + length + ";");
            }
            else
            {
                writer.WriteLine("                    int length = " + length + ";");

                foreach (MapField field in block.Fields)
                {
                    if (field.Type == FieldType.Variable)
                    {
                        writer.WriteLine("                    if (" + field.Name +
                            " != null) { length += " + field.Count + " + " + field.Name + ".Length; }");
                    }
                }

                writer.WriteLine("                    return length;");
            }

            writer.WriteLine("                }" + Environment.NewLine + "            }" + Environment.NewLine);

            // Default constructor
            //writer.WriteLine("            /// <summary>Default constructor</summary>");
            writer.WriteLine("            public " + block.Name + "Block() { }");

            // Constructor for building the class from bytes
            //writer.WriteLine("            /// <summary>Constructor for building the block from a byte array</summary>");
            writer.WriteLine("            public " + block.Name + "Block(byte[] bytes, ref int i)" + Environment.NewLine + 
                "            {");

            // Declare a length variable if we need it for variable fields in this constructor
            if (variableFields) { writer.WriteLine("                int length;"); }

            // Start of the try catch block
            writer.WriteLine("                try" + Environment.NewLine + "                {");

            foreach (MapField field in block.Fields)
            {
                WriteFieldFromBytes(writer, field);
            }

            writer.WriteLine("                }" + Environment.NewLine + 
                "                catch (Exception)" + Environment.NewLine +
                "                {" + Environment.NewLine + 
                "                    throw new MalformedDataException();" + Environment.NewLine +
                "                }" + Environment.NewLine + "            }" + Environment.NewLine);

            // ToBytes() function
            //writer.WriteLine("            /// <summary>Serialize this block to a byte array</summary>");
            writer.WriteLine("            public void ToBytes(byte[] bytes, ref int i)" + Environment.NewLine + 
                "            {");

            // Declare a byte[] variable if we need it for floating point field conversions
            if (floatFields) { writer.WriteLine("                byte[] ba;"); }

            foreach (MapField field in block.Fields)
            {
                WriteFieldToBytes(writer, field);
            }

            writer.WriteLine("            }" + Environment.NewLine);

            // ToString() function
            writer.WriteLine("            public override string ToString()" + Environment.NewLine + "            {");
            writer.WriteLine("                StringBuilder output = new StringBuilder();");
            writer.WriteLine("                output.AppendLine(\"-- " + block.Name + " --\");");

            for (int i = 0; i < block.Fields.Count; i++)
            {
                MapField field = block.Fields[i];

                if (field.Type == FieldType.Variable || field.Type == FieldType.Fixed)
                {
                    writer.WriteLine("                Helpers.FieldToString(output, " + field.Name + ", \"" + field.Name + "\");");
                    if (i != block.Fields.Count - 1) writer.WriteLine("                output.Append(Environment.NewLine);");
                }
                else
                {
                    if (i != block.Fields.Count - 1) writer.WriteLine("                output.AppendLine(String.Format(\"" + field.Name + ": {0}\", " + field.Name + "));");
                    else writer.WriteLine("                output.Append(String.Format(\"" + field.Name + ": {0}\", " + field.Name + "));");
                }
            }

            writer.WriteLine("                return output.ToString();" + Environment.NewLine + "            }");
            writer.WriteLine("        }" + Environment.NewLine);
        }