Results 1 to 8 of 8
  1. #1
    ZeusAlmighty's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Posts
    689
    Reputation
    27
    Thanks
    2,198
    My Mood
    Buzzed

    Post [SD] My Horde Minigame

    So I have been asked quite a few times to release this minigame or to help people to add it in. So here it is.

    Before any of you asks why there is a database hook for something as simple as old dyes:
    The database hook is there in case of any sort of restart/crash etc in which case simply reverting the dyes to the old colours would not be possible. The database hook ensures that the dyes are changed back no matter what in most cases, unless the database doesnt have them saved as the crash happens while joining or something very unlucky.

    The basis of the minigame:


    VIDEO BY Meapy. Thanks bruh.

    There are two teams, red and blue.
    You have to kill as many monsters as you can within the time/kill them all. Team with most kills wins the round.
    First to 3 round wins wins the game, and the winning team all receive Fame as a reward.

    The minigame has AFK detection etc to stop AFKers and disadvantages.

    So without further adue, heres the messy minigame code:


    SERVER SIDE

     

    TerrainTile.cs

    Inside "public enum TileRegion : byte"
    Add this:

     
    Code:
            DungArea_1,
            DungArea_2,
            DungArea_3,
            DungArea_4


    Database.cs

    Add this:

     
    Code:
            public void SaveOldTextures(Account acc, Char chr, int oldTex1, int oldTex2)
            {
                using (var cmd = CreateQuery())
                {
                    cmd.CommandText = @"UPDATE characters SET 
                    oldTex1=@oldTex1,
                    oldTex2=@oldTex2
                    WHERE accId=@accId AND charId=@charId;";
                    cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                    cmd.Parameters.AddWithValue("@charId", chr.CharacterId);
    
                    cmd.Parameters.AddWithValue("@oldTex1", oldTex1);
                    cmd.Parameters.AddWithValue("@oldTex2", oldTex2);
                    cmd.ExecuteNonQuery();
                }
                return;
            }
    
            public List<int> GetOldTextures(Account acc, Char chr)
            {
                var ret = new List<int>();
                using (var cmd = CreateQuery())
                {
                    cmd.CommandText = "SELECT oldTex1, oldTex2 FROM characters WHERE accId=@accId AND charId=@charId;";
                    cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                    cmd.Parameters.AddWithValue("@charId", chr.CharacterId);
                    using (MySqlDataReader rdr = cmd.ExecuteReader())
                        if (rdr.HasRows)
                            while (rdr.Read())
                            {
                                ret.Add(rdr.GetInt32("oldTex1"));
                                ret.Add(rdr.GetInt32("oldTex2"));
                            }
                }
                return ret;
            }


    Make a new file where your worlds are stored, e.g. for me its : wServer/Realm/Worlds/Dungeons

    Call it Horde.cs
    Inside put:

     
    Code:
    using System.Collections.Generic;
    using wServer.networking.svrPackets;
    using wServer.realm.entities;
    using wServer.realm.terrain;
    using System.Linq;
    using System;
    using System.Threading.Tasks;
    using System.Diagnostics;
    
    namespace wServer.realm.worlds
    {
        public class Horde : World
        {
            public int blueScore = 0;
            public int redScore = 0;
            public int Time = 60;
            public int BlueWins;
            public int RedWins;
            public List<string> blueNames = new List<string>();
            public List<string> redNames = new List<string>();
            public List<string> dyeList = new List<string>();
            public bool started = false;
            public bool spawned = false;
            public bool ready = false;
            public bool spawn = false;
            public bool finished = false;
            public bool complete = false;
            public bool counting = false;
            public bool rewarding = false;
            public int round = 0;
            public List<string> roundDamageDone = new List<string>();
    
            private readonly string[] FirstEnemies =
            {
                "Lizard God", "Minotaur", "Ogre King", "Undead Dwarf God", "Flayer God",
            };
    
            private readonly string[] SecondEnemies =
            {
                "White Demon", "Sprite God", "Medusa", "Ent God", "Beholder", "Flying Brain", "Slime God", "Ghost God", "Djinn"
            };
    
            private readonly string[] ThirdEnemies =
            {
                "Limon the Sprite God", "Archdemon Malphas", "Septavius the Ghost God"
            };
    
    
            public bool hasEntitiesRemaining;
    
            public Horde()
            {
                Id = HORDE_ID;
                Name = "Horde";
                Background = 0;
                Difficulty = 5;
                AllowTeleport = true;
                SetMusic("JumpIntoBattle");
                RayDungeon = true;
            }
    
            protected override void Init()
            {
                LoadMap("wServer.realm.worlds.dungeons.Horde.jm", MapType.Json);
            }
    
            public override void Tick(RealmTime time)
            {
                base.Tick(time);
    
                if (this == null) return;
                if (Players.Count <= 0 && started) //if 0 players and the matchs started, will remove world
                {
                    Manager.RemoveWorld(this);
                    return;
                }
    
                CheckInSafeZone();
    
                if (round == 5 || RedWins == 3 || BlueWins == 3)
                    complete = true;
    
                if (complete && !rewarding)
                {
                    if (this == null) return;
                    if (Players.Count <= 0) return;
                    var fameBase = 500;
                    rewarding = true;
                    foreach (var i in Players.Values)
                    {
                        i.Client.SendPacket(new HordeDataPacket()
                        {
                            BlueScore = blueScore,
                            RedScore = redScore,
                            Time = 60
                        });
    
                        var def = new List<IntPoint>();
                        for (var x = 0; x < Map.Width; x++)
                            for (var y = 0; y < Map.Height; y++)
                                if (Map[x, y].Region == TileRegion.DungArea_3)
                                    def.Add(new IntPoint(x, y));
    
                        var tile = def[new Random().Next(0, def.Count)];
    
                        i.Owner.BroadcastPacket(new GotoPacket
                        {
                            ObjectId = i.Id,
                            Position = new Position
                            {
                                X = tile.X,
                                Y = tile.Y
                            }
                        }, null);
                    }
                    if (BlueWins > RedWins)
                    {
                        foreach (var i in Players.Values)
                        {
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo("Blue team wins the Game!");
                            i.SendInfo("Score:");
                            i.SendInfo("Blue    :    Red");
                            i.SendInfo(BlueWins + "       :      " + RedWins);
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo("The winners all recieve 500 fame!");
    
                            if (blueNames.Contains(i.Name))
                            {
                                i.Manager.Data.AddDatabaseOperation(db =>
                                {
                                    var donorRank = i.Client.Account.DonatorRank;
                                    var playerFame = fameBase * (donorRank == 6 ? 5 : (donorRank == 5 ? 3 : (1 + 0.25 * donorRank)));
                                    i.CurrentFame = i.Client.Account.Stats.Fame = db.UpdateFame(i.Client.Account, (int)playerFame);
                                });
                            }
                            Task.Factory.StartNew(() =>
                            {
                                while (!worldTimer(5000)) { }
    
                                if (this == null) return;
                                if (Players.Count <= 0) return;
                                if (i == null) return;
                                i.Client.Reconnect(new ReconnectPacket
                                {
                                    Host = "",
                                    Port = 2050,
                                    GameId = NEXUS_ID,
                                    Name = "Nexus",
                                    Key = Empty<byte>.Array,
                                });
                            });
                        }
                    }
                    else
                    {
                        foreach (var i in Players.Values)
                        {
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo("Red team wins the Game!");
                            i.SendInfo("Score:");
                            i.SendInfo("Blue    :    Red");
                            i.SendInfo(BlueWins + "       :      " + RedWins);
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo("The winners all recieve 500 fame!");
    
                            if (redNames.Contains(i.Name))
                            {
                                i.Manager.Data.AddDatabaseOperation(db =>
                                {
                                    var donorRank = i.Client.Account.DonatorRank;
                                    var playerFame = fameBase * (donorRank == 6 ? 5 : (donorRank == 5 ? 3 : (1 + 0.25 * donorRank)));
                                    i.CurrentFame = i.Client.Account.Stats.Fame = db.UpdateFame(i.Client.Account, (int)playerFame);
                                });
                            }
                            Task.Factory.StartNew(() =>
                            {
                                while (!worldTimer(5000)) { }
    
                                if (this == null) return;
                                if (Players.Count <= 0) return;
                                if (i == null) return;
                                i.Client.Reconnect(new ReconnectPacket
                                {
                                    Host = "",
                                    Port = 2050,
                                    GameId = NEXUS_ID,
                                    Name = "Nexus",
                                    Key = Empty<byte>.Array,
                                });
                            });
                        }
                    }
                }
    
                if ((Enemies.Count == 0 && spawned) || (Time == 0 && spawned))
                {
                    if (this == null) return;
                    if (Players.Count <= 0) return;
                    spawned = false;
                    round++;
    
                    var listToKick = new List<Player>();
    
                    var def = new List<IntPoint>();
                    for (var x = 0; x < Map.Width; x++)
                        for (var y = 0; y < Map.Height; y++)
                            if (Map[x, y].Region == TileRegion.DungArea_3)
                                def.Add(new IntPoint(x, y));
    
                    var tile = def[new Random().Next(0, def.Count)];
    
                    foreach (var i in Players.Values)
                    {
                        var dmgExsts = false;
                        for (var j = 0; j < roundDamageDone.Count; j++)
                        {
                            if (roundDamageDone[j].Split(':')[0] == i.Name)
                            {
                                if (roundDamageDone[j].Split(':')[1] == "1")
                                    dmgExsts = true;
                                roundDamageDone[j] = $"{i.Name}:0";
                            }
                        }
                        if (!dmgExsts && (Map[(int)i.X, (int)i.Y].Region != TileRegion.Spawn && Map[(int)i.X, (int)i.Y].Region != TileRegion.DungArea_3))
                            listToKick.Add(i);
    
                        i.Client.SendPacket(new HordeDataPacket()
                        {
                            BlueScore = 0,
                            RedScore = 0,
                            Time = 60
                        });
    
                        i.Owner.BroadcastPacket(new GotoPacket
                        {
                            ObjectId = i.Id,
                            Position = new Position
                            {
                                X = tile.X,
                                Y = tile.Y
                            }
                        }, null);
                    }
    
                    if (blueScore > redScore)
                    {
                        BlueWins++;
                        foreach (var i in Players.Values)
                        {
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo("Blue team wins that round!");
                            i.SendInfo("Current Score:");
                            i.SendInfo("Blue    :    Red");
                            i.SendInfo(BlueWins + "       :      " + RedWins);
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo("Next round in 5 seconds!");
                        }
                    }
                    else
                    {
                        RedWins++;
                        foreach (var i in Players.Values)
                        {
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo("Red team wins that round!");
                            i.SendInfo("Current Score:");
                            i.SendInfo("Blue    :    Red");
                            i.SendInfo(BlueWins + "       :      " + RedWins);
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo("Next round in 5 seconds!");
                        }
                    }
                    //Timers.Add(new WorldTimer(2500, (world, t) =>
                    Task.Factory.StartNew(() =>
                    {
                        while (!worldTimer(2500)) { }
    
                        if (this == null) return;
                        if (Players.Count <= 0) return;
                        foreach (var i in Players.Values)
                        {
                            if (i == null) return;
    
                            if (listToKick.Contains(i))
                            {
                                foreach (var j in Players.Values)
                                {
                                    if (j != i)
                                    {
                                        j.SendInfo($"{i.Name} has been kicked from Horde due to insufficient damage!");
                                    }
                                }
                                i.GoToNexus();
                            }
    
                            if (i.Boost == null) i.CalculateBoost();
                            i.HP = i.Stats[0] + i.Boost[0];
                            i.MP = i.Stats[1] + i.Boost[1];
                            i.Client.SendPacket(new HordeDataPacket()
                            {
                                BlueScore = 0,
                                RedScore = 0,
                                Time = 60
                            });
                        }
                    });
    
                    //Timers.Add(new WorldTimer(5000, (world, t) =>
                    Task.Factory.StartNew(() =>
                    {
                        while (!worldTimer(5000)) { }
    
                        if (this == null) return;
                        if (Players.Count <= 0) return;
                        ready = true;
                        blueScore = 0;
                        redScore = 0;
                        Time = 60;
                    });
                }
    
                if (spawned && !counting)
                {
                    if (this == null) return;
                    if (Players.Count <= 0) return;
                    counting = true;
                    //Timers.Add(new WorldTimer(1000, (world, t) =>
                    Task.Factory.StartNew(() =>
                    {
                        while (!worldTimer(1000)) { }
    
                        if (this == null) return;
                        if (Players.Count <= 0) return;
                        Time--;
                        counting = false;
                        foreach (var i in Players.Values)
                        {
                            if (i == null) return;
                            i.Client.SendPacket(new HordeDataPacket()
                            {
                                BlueScore = blueScore,
                                RedScore = redScore,
                                Time = Time
                            });
                        }
                    });
                }
    
    
                if (!started && Players.Count > 1) //when 2 players join, game will be started
                {
                    started = true;
                    if (this == null) return;
                    if (Players.Count <= 0) return;
                    //Timers.Add(new WorldTimer(15000, (world, t) =>
                    Task.Factory.StartNew(() =>
                    {
                        while (!worldTimer(15000)) { }
    
                        if (this == null) return;
                        if (Players.Count <= 0) return;
                        foreach (var i in Players.Values)
                        {
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo("Welcome to the Horde!");
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo("Aim : To get more kills than the other team.");
                            i.SendInfo("Last person to hit the mob before death gets the kill.");
                            i.SendInfo("Idlers will be kicked!");
                            i.SendInfo("Each Round lasts 60 seconds.");
                            i.SendInfo("This round will start in 10 seconds, good luck!");
                        }
                        ready = true;
                    });
                }
                if (ready)
                {
                    if (this == null) return;
                    if (Players.Count <= 0) return;
                    ready = false;
                    //Timers.Add(new WorldTimer(10000, (world, t) =>
                    Task.Factory.StartNew(() =>
                    {
                        while (!worldTimer(10000)) { }
    
                        if (this == null) return;
                        if (Players.Count <= 0) return;
                        foreach (var i in Players.Values)
                        {
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            i.SendInfo($"Round {round + 1} begins.");
                            i.SendInfo("~~~~~~~~~~~~~~~~~~~~~");
                            if (blueNames.Contains(i.Name))
                            {
                                var def = new List<IntPoint>();
                                for (var x = 0; x < Map.Width; x++)
                                    for (var y = 0; y < Map.Height; y++)
                                        if (Map[x, y].Region == TileRegion.DungArea_1)
                                            def.Add(new IntPoint(x, y));
    
                                var tile = def[new Random().Next(0, def.Count)];
    
                                i.Owner.BroadcastPacket(new GotoPacket
                                {
                                    ObjectId = i.Id,
                                    Position = new Position
                                    {
                                        X = tile.X,
                                        Y = tile.Y
                                    }
                                }, null);
                            } else if (redNames.Contains(i.Name))
                            {
                                var def = new List<IntPoint>();
                                for (var x = 0; x < Map.Width; x++)
                                    for (var y = 0; y < Map.Height; y++)
                                        if (Map[x, y].Region == TileRegion.DungArea_2)
                                            def.Add(new IntPoint(x, y));
    
                                var tile = def[new Random().Next(0, def.Count)];
    
                                i.Owner.BroadcastPacket(new GotoPacket
                                {
                                    ObjectId = i.Id,
                                    Position = new Position
                                    {
                                        X = tile.X,
                                        Y = tile.Y
                                    }
                                }, null);
                            }
                        }
                        spawn = true;
                    });
                }
                if (spawn)
                {
                    if (this == null) return;
                    if (Players.Count <= 0) return;
                    spawn = false;
                    //Timers.Add(new WorldTimer(2000, (world, t) =>
                    Task.Factory.StartNew(() =>
                    {
                        while (!worldTimer(2000)) { }
    
                        if (this == null) return;
                        if (Players.Count <= 0) return;
                        startSpawn();
                    });
                }
            }
    
            private void CheckInSafeZone()
            {
                foreach (var i in Enemies.Values)
                {
                    var xloc = (int)i.X;
                    var yloc = (int)i.Y;
                    if (Map[xloc, yloc].Region != TileRegion.DungArea_4)
                    {
                        i.Move(i.SpawnPoint.X, i.SpawnPoint.Y);
                    }
                }
            }
    
            private void startSpawn()
            {
                var enems = new List<string>();
                var r = new Random();
    
                if (round == 0)
                {
                    for (int i = 0; i < r.Next(15) + 10; i++)
                    {
                        enems.Add(FirstEnemies[r.Next(0, FirstEnemies.Length)]);
                    }
    
                    for (int i = 0; i < r.Next(4); i++)
                    {
                        enems.Add(SecondEnemies[r.Next(0, SecondEnemies.Length)]);
                    }
                }
    
                if (round == 1)
                {
                    for (int i = 0; i < r.Next(15) + 5; i++)
                    {
                        enems.Add(FirstEnemies[r.Next(0, FirstEnemies.Length)]);
                    }
    
                    for (int i = 0; i < r.Next(10) + 5; i++)
                    {
                        enems.Add(SecondEnemies[r.Next(0, SecondEnemies.Length)]);
                    }
                }
    
                if (round == 2)
                {
                    for (int i = 0; i < r.Next(15) + 5; i++)
                    {
                        enems.Add(FirstEnemies[r.Next(0, FirstEnemies.Length)]);
                    }
    
                    for (int i = 0; i < r.Next(15) + 15; i++)
                    {
                        enems.Add(SecondEnemies[r.Next(0, SecondEnemies.Length)]);
                    }
                }
    
                if (round == 3)
                {
                    for (int i = 0; i < r.Next(15) + 15; i++)
                    {
                        enems.Add(FirstEnemies[r.Next(0, FirstEnemies.Length)]);
                    }
    
                    for (int i = 0; i < r.Next(15) + 20; i++)
                    {
                        enems.Add(SecondEnemies[r.Next(0, SecondEnemies.Length)]);
                    }
                }
    
                if (round == 4)
                {
                    for (int i = 0; i < r.Next(5) + 25; i++)
                    {
                        enems.Add(SecondEnemies[r.Next(0, SecondEnemies.Length)]);
                    }
    
                    for (int i = 0; i < r.Next(5) + 5; i++)
                    {
                        enems.Add(ThirdEnemies[r.Next(0, ThirdEnemies.Length)]);
                    }
                }
    
    
                for (var i = 0; i < enems.Count; i++)
                {
                    if (this == null) break;
                    if (Players.Count <= 0) break;
                    var def = new List<IntPoint>();
                    for (var x = 0; x < Map.Width; x++)
                        for (var y = 0; y < Map.Height; y++)
                            if (Map[x, y].Region == TileRegion.DungArea_4)
                                def.Add(new IntPoint(x, y));
    
                    var tile = def[r.Next(0, def.Count)];
    
                    var id = Manager.GameData.IdToObjectType[enems[i]];
                    var enemy = Entity.Resolve(Manager, id);
                    enemy.Move(tile.X, tile.Y);
    
                    EnterWorld(enemy);
                }
                spawned = true;
            }
    
            public override int EnterWorld(Entity entity)
            {
                base.EnterWorld(entity);
                if (entity is Player && entity.Owner is Horde)
                {
                    var i = (entity as Player);
                    var exstsDmg = false;
                    for (var j = 0; j < roundDamageDone.Count; j++)
                    {
                        if (roundDamageDone[j].Split(':')[0] == i.Name)
                        {
                            exstsDmg = true;
                        }
                    }
                    if (!exstsDmg)
                        roundDamageDone.Add($"{i.Name}:0");
                    if (!blueNames.Contains(i.Client.Account.Name) && !redNames.Contains(i.Client.Account.Name))
                    {
                        var blueCount = blueNames.Count;
                        var redCount = redNames.Count;
                        if (blueCount > redCount)
                        {
                            redNames.Add(i.Name);
                            var oldTex1 = i.Texture1;
                            var oldTex2 = i.Texture2;
                            i.Manager.Data.AddDatabaseOperation(db =>
                            {
                                db.SaveOldTextures(i.Client.Account, i.Client.Character, oldTex1, oldTex2);
                            });
                            //dyeList.Add($"{i.Name}:{i.Texture1}:{i.Texture2}");
                            i.Texture1 = 0x01FF0000;
                            i.Texture2 = 0x01FF0000;
                            foreach (var k in Players.Values)
                            {
                                if (k == null) break;
                                k.SendInfo(i.Name + " has joined the Red Team");
                            }
                        } else if (redCount > blueCount)
                        {
                            blueNames.Add(i.Name);
                            var oldTex1 = i.Texture1;
                            var oldTex2 = i.Texture2;
                            i.Manager.Data.AddDatabaseOperation(db =>
                            {
                                db.SaveOldTextures(i.Client.Account, i.Client.Character, oldTex1, oldTex2);
                            });
                            //dyeList.Add($"{i.Name}:{i.Texture1}:{i.Texture2}");
                            i.Texture1 = 0x010000FF;
                            i.Texture2 = 0x010000FF;
                            foreach (var k in Players.Values)
                            {
                                if (k == null) break;
                                k.SendInfo(i.Name + " has joined the Blue Team");
                            }
                        } else
                        {
                            var rand = new Random();
                            if (rand.Next(100) >= 50)
                            {
                                redNames.Add(i.Name);
                                var oldTex1 = i.Texture1;
                                var oldTex2 = i.Texture2;
                                i.Manager.Data.AddDatabaseOperation(db =>
                                {
                                    db.SaveOldTextures(i.Client.Account, i.Client.Character, oldTex1, oldTex2);
                                });
                                //dyeList.Add($"{i.Name}:{i.Texture1}:{i.Texture2}");
                                i.Texture1 = 0x01FF0000;
                                i.Texture2 = 0x01FF0000;
                                foreach (var k in Players.Values)
                                {
                                    if (k == null) break;
                                    k.SendInfo(i.Name + " has joined the Red Team");
                                }
                            }
                            else
                            {
                                blueNames.Add(i.Name);
                                var oldTex1 = i.Texture1;
                                var oldTex2 = i.Texture2;
                                i.Manager.Data.AddDatabaseOperation(db =>
                                {
                                    db.SaveOldTextures(i.Client.Account, i.Client.Character, oldTex1, oldTex2);
                                });
                                //dyeList.Add(i.Name + ":" + i.Texture1 + ":" + i.Texture2);
                                i.Texture1 = 0x010000FF;
                                i.Texture2 = 0x010000FF;
                                foreach (var k in Players.Values)
                                {
                                    if (k == null) break;
                                    k.SendInfo(i.Name + " has joined the Blue Team");
                                }
                            }
                        }
                    }
                }
                return entity.Id;
            }
    
            private bool worldTimer(int time)
            {
                var timer = new Stopwatch();
                timer.Start();
    
                var timeElapsed = false;
                while (!timeElapsed)
                    if (timer.ElapsedMilliseconds > time)
                    {
                        timer.Stop();
                        timeElapsed = true;
                    }
                return true;
            }
    
            public override void LeaveWorld(Entity entity)
            {
                if (entity is Enemy && entity.Owner is Horde)
                {
                    var enemy = (entity as Enemy);
                    if (enemy.DamageCounter.LastHitter == null) return;
                    if (enemy.DamageCounter == null) return;
                    if (blueNames.Contains(enemy.DamageCounter.LastHitter  .Name))
                    {
                        if (ThirdEnemies.Contains(enemy.Name))
                            blueScore += 5;
                        else if (SecondEnemies.Contains(enemy.Name))
                            blueScore += 3;
                        else
                            blueScore++;
                    }
                    else if (redNames.Contains(enemy.DamageCounter.LastHitter.  Name))
                    {
                        if (ThirdEnemies.Contains(enemy.Name))
                            redScore += 5;
                        else if (SecondEnemies.Contains(enemy.Name))
                            redScore += 3;
                        else
                            redScore++;
                    }
                    foreach (var i in Players.Values) {
                        i.Client.SendPacket(new HordeDataPacket()
                        {
                            BlueScore = blueScore,
                            RedScore = redScore,
                            Time = Time
                        });
                        var doneDamage = false;
                        foreach (var j in enemy.DamageCounter.GetPlayerData())
                        {
                            if (j.Item1.Name == i.Name)
                                doneDamage = true;
                        }
                        if (doneDamage)
                        {
                            for (var h = 0; h < roundDamageDone.Count; h++)
                            {
                                var hSplit = roundDamageDone[h].Split(':');
                                if (hSplit[0] == i.Name && hSplit[1] != "1")
                                {
                                    roundDamageDone[h] = $"{i.Name}:1";
                                }
                            }
                        }
                    }
                }
                if (entity is Player && entity.Owner is Horde)
                {
                    var i = (entity as Player);
                    if (blueNames.Contains(i.Client.Account.Name))
                    {
                        blueNames.Remove(i.Client.Account.Name);
                        foreach (var k in Players.Values)
                        {
                            if (k == null) break;
                            k.SendInfo(i.Name + " has left the Blue Team");
                        }
                    }
                    if (redNames.Contains(i.Client.Account.Name))
                    {
                        redNames.Remove(i.Client.Account.Name);
                        foreach (var k in Players.Values)
                        {
                            if (k == null) break;
                            k.SendInfo(i.Name + " has left the Red Team");
                        }
                    }
                    //i.Manager.Data.DoActionAsync(db =>
                    //{
                    //    var textures = db.GetOldTextures(i.Client.Account, i.Client.Character);
                    //    if (textures[0] != -1)
                    //        i.Texture1 = textures[0];
                    //    if (textures[1] != -1)
                    //        i.Texture2 = textures[1];
                    //    i.SaveToCharacter();
                    //});
                    //i.UpdateCount++;
                }
                base.LeaveWorld(entity);
            }
        }
    }



    The map file is attached. I use JM maps so if you dont have JM compatible, you may need to add it or convert the world to WMap.


    UsePortalPacketHandler.cs

    Add this inside the switch "switch (entity.ObjectType)":

     
    Code:
                            case 0x2008:
                                //horde
                                break;


    Also add this above "if (player.Manager.PlayerWorldMapping.ContainsKey(pla yer.AccountId))" :

     
    Code:
                var hordeExists = false;
                if (entity.ObjectType == 0x2008)
                {
                    foreach (var i in player.Manager.Worlds.Values)
                        if (i is Horde)
                        {
                            hordeExists = true;
                            if (i.Players.Count > 15 || (i as Horde)****und > 3)
                            {
                                world = player.Manager.AddWorld(new Horde());
                            }
                            else
                            {
                                world = i;
                            }
                        }
                    if (!hordeExists)
                    {
                        world = player.Manager.AddWorld(new Horde());
                    }
                }


    PacketIds.cs

    Add this packet id:

     

    HordeData = 101


    Locate where your svrPackets are stored. e.g. mine is wServer/Networking/svrPackets

    Create a new file called HordeDataPacket.cs

    Inside it put:

     
    Code:
    namespace wServer.networking.svrPackets
    {
        public class HordeDataPacket : ServerPacket
        {
            public int BlueScore { get; set; }
            public int RedScore { get; set; }
            public int Time { get; set; }
    
            public override PacketID ID
            {
                get { return PacketID.HordeData; }
            }
    
            public override Packet CreateInstance()
            {
                return new HordeDataPacket();
            }
    
            protected override void Read(NReader rdr)
            {
            }
    
            protected override void Write(NWriter wtr)
            {
                wtr.Write(BlueScore);
                wtr.Write(RedScore);
                wtr.Write(Time);
            }
        }
    }


    Player.cs

    Find "public void Death" and put:

     
    Code:
                    case "Horde":
                        HP = Stats[0] + Stats[0];
                        MP = Stats[1] + Stats[1];
                        client.Reconnect(new ReconnectPacket
                        {
                            Host = "",
                            Port = 2050,
                            GameId = World.NEXUS_ID,
                            Name = "Nexus",
                            Key = Empty<byte>.Array,
                        });
                        return;


    Player.UseItem.cs

    Find "case ActivateEffects.Dye:"
    And replace with:

     
    Code:
                        case ActivateEffects.Dye:
                            if (!(Owner is Horde))
                            {
                                if (item.Texture1 != 0)
                                {
                                    Texture1 = item.Texture1;
                                }
                                if (item.Texture2 != 0)
                                {
                                    Texture2 = item.Texture2;
                                }
                                SaveToCharacter();
                            }
                            break;


    World.cs

    At the top where the "public const int blahblah = -2" are, add this:

     

    public const int HORDE_ID = -12;


    And then find "public virtual int EnterWorld" and where it says "if (entity is Player)", at the end put:

     
    Code:
                    if ((i.Owner is Horde))
                        i.Client.SendPacket(new GlobalNotificationPacket()
                        {
                            Text = "{\"type\": \"horde\", \"title\": \"horde\", \"text\": \"horde\"}"
                        });
                    else
                    {
                        i.Manager.Data.AddDatabaseOperation(db =>
                        {
                            var textures = db.GetOldTextures(i.Client.Account, i.Client.Character);
                            if (textures[0] != -1)
                            {
                                i.Texture1 = textures[0];
                                db.SaveOldTextures(i.Client.Account, i.Client.Character, -1, textures[1]);
                                i.SaveToCharacter();
                            }
                            if (textures[1] != -1)
                            {
                                i.Texture2 = textures[1];
                                db.SaveOldTextures(i.Client.Account, i.Client.Character, textures[0], -1);
                                i.SaveToCharacter();
                            }
                        });
                    }


    addition.xml (or wherever your additional objects are stored)

    Add this:

     
    Code:
        
        <Object type="0x2008" id="Horde Portal" ext="true">
          <DisplayId>Horde</DisplayId>
          <Class>Portal</Class>
          <IntergamePortal />
          <DungeonName>Horde</DungeonName>
          <Texture>
            <File>YOURFILE</File>
            <Index>YOURINDEX</Index>
          </Texture>
        </Object>


    And replace YOURFILE and YOURINDEX with the texture you would like the portal to be.



    CLIENT SIDE

     

    GameSprite.as

    Find "public function GameSprite" and above "addEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);" add:

     

    this.horde_ = new HordeUI(this);
    this.horde_.visible = false;
    addChild(this.horde_);[/CODE]]



    Then under "public function GameSprite" add :

     
    Code:
        public var horde_:HordeUI;


    Go to "src\_011" and create a file called HordeData.as
    Inside it put:

     
    Code:
    // Decompiled by AS3 Sorcerer 1.99
    // https://www.as3sorcerer.com/
    
    //_011._iD_
    
    package _011 {
    import flash.util*****ataInput;
    
    public class HordeData extends _01Q_ {
    
        public function HordeData(_arg1:uint) {
            super(_arg1);
        }
        public var redScore:int;
        public var blueScore:int;
        public var time:int;
    
        override public function parseFromInput(_arg1:IDataInput):void {
            this.blueScore = _arg1.readInt();
            this.redScore = _arg1.readInt()
            this.time = _arg1.readInt();
        }
    
        override public function toString():String {
            return (formatToString("HORDEDATA", "blueScore", "redScore", "time"));
        }
    
    }
    }//package _011


    Go to "src\com\company\assemblegameclient\ui" and create a file called HordeUI.as
    Inside put:

     
    Code:
    package com.company.assembleegameclient.ui {
    import _0D_d.Frame;
    import _0D_d.TextInput;
    
    import com.company.assembleegameclient.game.GameSprite;
    import com.company****tmg.graphics.DeleteXGraphic;
    import com.company.ui.SimpleText;
    import com.company.util.GraphicHelper;
    
    import flash.display.CapsStyle;
    
    import flash.display.GraphicsPath;
    
    import flash.display.GraphicsSolidFill;
    import flash.display.GraphicsStroke;
    import flash.display.IGraphicsData;
    import flash.display.JointStyle;
    import flash.display.LineScaleMode;
    
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.geom.Rectangle;
    import flash.ui.Mouse;
    
    public class HordeUI extends Sprite{
    
        private var width_:int = 128;
        private var height_:int = 48;
    
        private var outlineFill_:GraphicsSolidFill;
        private var lineStyle_:GraphicsStroke;
        private var backgroundFill_:GraphicsSolidFill;
        private var path_:GraphicsPath;
        private var graphicsData_:Vector.<IGraphicsData>;
        private var gs_:GameSprite;
        private var hordeBox1:HordeBox;
        private var hordeBox2:HordeBox;
        private var scoreSeperator:SimpleText;
        private var hordeTime:HordeTime;
    
        public function HordeUI(_arg1:GameSprite){
            this.gs_ = _arg1;
    
            this.hordeTime = new HordeTime();
            this.hordeTime.x = (this.x + 64) - 22;
            this.hordeTime.y = 46;
            this.addChild(this.hordeTime);
    
            this.backgroundFill_ = new GraphicsSolidFill(0x333333, 1);
            this.outlineFill_ = new GraphicsSolidFill(0xFFFFFF, 1);
            this.lineStyle_ = new GraphicsStroke(1, false, LineScaleMode.NORMAL, CapsStyle.NONE, JointStyle****UND, 3, this.outlineFill_);
            this.path_ = new GraphicsPath(new Vector.<int>(), new Vector.<Number>());
            this.graphicsData_ = new <IGraphicsData>[this.lineStyle_, this.backgroundFill_, this.path_, GraphicHelper.END_FILL, GraphicHelper._H_B_];
            this.x = (600 / 2) - (width_ / 2);
    
            this.hordeBox1 = new HordeBox(0x0000FF);
            this.hordeBox1.x = 13;
            this.hordeBox1.y = 9;
            this.addChild(hordeBox1);
    
            this.scoreSeperator = new SimpleText(54, 0xFFFFFF, false, 0, 0, "Myriad Pro");
            this.scoreSeperator.x = 56;
            this.scoreSeperator.y = -16;
            this.scoreSeperator.text = ":";
            this.scoreSeperator.updateMetrics();
            this.addChild(this.scoreSeperator);
    
            this.hordeBox2 = new HordeBox(0xFF0000);
            this.hordeBox2.x = 71;
            this.hordeBox2.y = 9;
            this.addChild(hordeBox2);
    
            draw()
        }
    
        public function draw():void{
            GraphicHelper._0L_6(this.path_);
            GraphicHelper.drawUI(0, 0, this.width_, this.height_ , 4, [1, 1, 1, 1], this.path_);
            graphics.drawGraphicsData(this.graphicsData_);
        }
    
        public function updateValues(_args1:int, _args2:int){
            this.hordeBox1.updateValue(_args1);
            this.hordeBox2.updateValue(_args2);
        }
    
        public function updateTime(_args1:int){
            this.hordeTime.updateValue(_args1);
        }
    
        public function getTime(){
            return Number(this.hordeTime.getValue());
        }
    }
    }
    
    import com.company.ui.SimpleText;
    import com.company.util.GraphicHelper;
    
    import flash.display.CapsStyle;
    
    import flash.display.GraphicsPath;
    
    import flash.display.GraphicsSolidFill;
    import flash.display.GraphicsStroke;
    import flash.display.IGraphicsData;
    import flash.display.JointStyle;
    import flash.display.LineScaleMode;
    
    import flash.display.Sprite;
    import flash.filters.DropShadowFilter;
    import flash.text.TextFormat;
    
    class HordeBox extends Sprite {
    
        private var outlineFill_:GraphicsSolidFill;
        private var lineStyle_:GraphicsStroke;
        private var backgroundFill_:GraphicsSolidFill;
        private var path_:GraphicsPath;
        private var graphicsData_:Vector.<IGraphicsData>;
    
        private var width_:int = 44;
        private var height_:int = 30;
    
        private var scoreText:SimpleText;
    
        public function HordeBox(_args1:uint) {
    
            this.backgroundFill_ = new GraphicsSolidFill(0x545454, 1);
            this.outlineFill_ = new GraphicsSolidFill(0xFFFFFF, 1);
            this.lineStyle_ = new GraphicsStroke(1, false, LineScaleMode.NORMAL, CapsStyle.NONE, JointStyle****UND, 3, this.outlineFill_);
            this.path_ = new GraphicsPath(new Vector.<int>(), new Vector.<Number>());
            this.graphicsData_ = new <IGraphicsData>[this.lineStyle_, this.backgroundFill_, this.path_, GraphicHelper.END_FILL, GraphicHelper._H_B_];
    
            this.scoreText = new SimpleText(28, _args1, false, 0, 0, "Myriad Pro");
            this.scoreText.y = -6;
            this.scoreText.x = 4;
            this.scoreText.text = "0";
            this.scoreText.updateMetrics();
            this.scoreText.filters = [new DropShadowFilter(0, 0, 0)];
            this.addChild(this.scoreText);
            draw();
        }
    
        public function draw():void {
            GraphicHelper._0L_6(this.path_);
            GraphicHelper.drawUI(0, 0, this.width_, this.height_ , 4, [1, 1, 1, 1], this.path_);
            graphics.drawGraphicsData(this.graphicsData_);
        }
    
        public function updateValue(_args1:int){
            this.scoreText.text = _args1.toString();
            this.scoreText.updateMetrics();
        }
    
    }
    
    import com.company.ui.SimpleText;
    import com.company.util.GraphicHelper;
    
    import flash.display.CapsStyle;
    
    import flash.display.GraphicsPath;
    
    import flash.display.GraphicsSolidFill;
    import flash.display.GraphicsStroke;
    import flash.display.IGraphicsData;
    import flash.display.JointStyle;
    import flash.display.LineScaleMode;
    
    import flash.display.Sprite;
    import flash.filters.DropShadowFilter;
    import flash.text.TextFormat;
    
    class HordeTime extends Sprite {
    
        private var outlineFill_:GraphicsSolidFill;
        private var lineStyle_:GraphicsStroke;
        private var backgroundFill_:GraphicsSolidFill;
        private var path_:GraphicsPath;
        private var graphicsData_:Vector.<IGraphicsData>;
    
        private var width_:int = 44;
        private var height_:int = 30;
    
        private var scoreText:SimpleText;
    
        public function HordeTime() {
    
            this.backgroundFill_ = new GraphicsSolidFill(0x333333, 1);
            this.outlineFill_ = new GraphicsSolidFill(0xFFFFFF, 1);
            this.lineStyle_ = new GraphicsStroke(1, false, LineScaleMode.NORMAL, CapsStyle.NONE, JointStyle****UND, 3, this.outlineFill_);
            this.path_ = new GraphicsPath(new Vector.<int>(), new Vector.<Number>());
            this.graphicsData_ = new <IGraphicsData>[this.lineStyle_, this.backgroundFill_, this.path_, GraphicHelper.END_FILL, GraphicHelper._H_B_];
    
            this.scoreText = new SimpleText(28, 0xB3B3B3, false, 0, 0, "Myriad Pro");
            this.scoreText.y = -6;
            this.scoreText.x = 6;
            this.scoreText.text = "60";
            this.scoreText.updateMetrics();
            this.scoreText.filters = [new DropShadowFilter(0, 0, 0)];
            this.addChild(this.scoreText);
            draw();
        }
    
        public function draw():void {
            GraphicHelper._0L_6(this.path_);
            GraphicHelper.drawUI(0, 0, this.width_, this.height_ , 4, [1, 1, 1, 1], this.path_);
            graphics.drawGraphicsData(this.graphicsData_);
        }
    
        public function updateValue(_args1:int){
            this.scoreText.text = _args1.toString();
            this.scoreText.updateMetrics();
        }
    
        public function getValue(){
            return this.scoreText.text;
        }
    }


    _1f.as

    Inside put:

     
    Code:
        public static const HORDEDATA:int = 101;


    Also put:

     
    Code:
            this._08._g9(HORDEDATA, HordeData, this.hordeDataHandle);


    And find "private function globalNotif_(_arg1:GlobalNotification):void {" and put :

     
    Code:
                case "horde":
                    this.gs_.horde_.visible = true;
                    return;


    Also add this:

     
    Code:
        private function hordeDataHandle(_arg1:HordeData):void {
            var _local1:HordeData = _arg1;
            this.gs_.horde_.updateTime(_local1.time);
            this.gs_.horde_.updateValues(_local1.blueScore, _local1.redScore)
        }


    _G_z.dat

    Add:

     
    Code:
       <Region type="0x26" id="Dungeon Area 1">
          <Color>0xFF3333</Color>
       </Region>
       <Region type="0x27" id="Dungeon Area 2">
          <Color>0xFF3333</Color>
       </Region>
       <Region type="0x28" id="Dungeon Area 3">
          <Color>0xFF3333</Color>
       </Region>
       <Region type="0x29" id="Dungeon Area 4">
          <Color>0xFF3333</Color>
       </Region>




    DATABASE SIDE

     

    Inside your database, you will need to add two collums to the character field.

    Like so:

     
    https://i.gyazo.com/0069c3a1cdbda26c9b7d87f1cf9918be.png




    And now your done!

    PS: The names of things may be different for you as my source is quite different than normal SD, so you may need to figure out what the name is in normal SD. If you need any help feel free to add me on Skype, I will try to help if I am not busy. Other than that, drop a thanks if you like it.

    Credits: Me

    Scans:
     
    https://www.virustotal.com/en/file/3a0ac525e5c6cf68cf7f29954fc846b8b886a94576467569ab 9af2839c2df439/analysis/1491481149/

    https://virusscan.jotti.org/en-US/fi...job/tcp2m39qb1
    <b>Downloadable Files</b> Downloadable Files
    Last edited by ZeusAlmighty; 04-06-2017 at 06:30 AM.

  2. The Following 3 Users Say Thank You to ZeusAlmighty For This Useful Post:

    9Gold (04-06-2017),LiveDEMI (04-19-2017),Orbit (04-06-2017)

  3. #2
    9Gold's Avatar
    Join Date
    Nov 2016
    Gender
    male
    Location
    New World
    Posts
    539
    Reputation
    32
    Thanks
    2,931
    My Mood
    Angelic
    Cool mini-game, now good luck responding to over 50 people that have errors implementing it
    ==================================================

    Links > Rules | How to MPGH | Report a Scammer | Market Place Rules

     
    MPGH History

    MPGH Member - 11-20-2016
    News Force (WTF) - 06-06-2017 - 07-23-17 [Resign]

    Return to MPGH - 10-14-2017

  4. #3
    ZeusAlmighty's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Posts
    689
    Reputation
    27
    Thanks
    2,198
    My Mood
    Buzzed
    Quote Originally Posted by 9Gold View Post
    Cool mini-game, now good luck responding to over 50 people that have errors implementing it
    Meh its cool, we were all in that position at one point. As long as they try to learn instead of just asking me to straight up fix it for them.

  5. The Following User Says Thank You to ZeusAlmighty For This Useful Post:

    9Gold (04-06-2017)

  6. #4
    Demon's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Location
    Lost
    Posts
    1,095
    Reputation
    86
    Thanks
    316
    My Mood
    Angelic
    Longest piece of code in the world: Hordes.cs
    Nice

  7. #5
    ZeusAlmighty's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Posts
    689
    Reputation
    27
    Thanks
    2,198
    My Mood
    Buzzed
    Quote Originally Posted by DemonLives View Post
    Longest piece of code in the world: Hordes.cs
    Yep, its handled less efficiently than it could be but it does the job and works.

  8. #6
    059's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    California
    Posts
    3,312
    Reputation
    700
    Thanks
    92,771
    Approved the map file. Nice tutorial man
    My Vouches
    Having an issue with RotMG? Check for the solution here.


    Need Realm items? Come to RealmStock!

    Accepting PayPal - Bitcoin - Giftcards
    Selling ST Sets, Class Top Sets, Life Pots, and much more!


    Find it here: MPGH Sales Thread

  9. The Following User Says Thank You to 059 For This Useful Post:

    ZeusAlmighty (04-07-2017)

  10. #7
    ZeusAlmighty's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Posts
    689
    Reputation
    27
    Thanks
    2,198
    My Mood
    Buzzed
    Quote Originally Posted by 059 View Post
    Approved the map file. Nice tutorial man
    Thanks matey

  11. #8
    ZeusAlmighty's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Posts
    689
    Reputation
    27
    Thanks
    2,198
    My Mood
    Buzzed
    NOTE: Just had a skype message about the database:

    The databasing in SD is different, you must use what databasing you have available.

Similar Threads

  1. Multiple HORDE 85's AND EVERY BATTLE.NET game on the account
    By Nekrage in forum Selling Accounts/Keys/Items
    Replies: 48
    Last Post: 04-23-2011, 10:24 PM
  2. From the power of the horde <3
    By Avagen in forum Member Introduction & Return
    Replies: 24
    Last Post: 12-02-2010, 06:04 PM
  3. [Info] Orcish Horde ! Recruiting
    By bloodbanger in forum CrossFire Clan Recruitment & Advertising
    Replies: 1
    Last Post: 08-18-2010, 08:45 AM
  4. CF Minigame! Post your score!
    By sup12sup in forum CrossFire Discussions
    Replies: 12
    Last Post: 08-05-2010, 10:16 PM
  5. Hosting MW2 Minigame Match
    By iZ3RO in forum Call of Duty Modern Warfare 2 Discussions
    Replies: 4
    Last Post: 06-08-2010, 01:56 AM