Esempio n. 1
0
        public static void Interval(SchedulerTask task)
        {
            //check to stop Interval
            if (world_ == null)
            {
                task.Stop();
                return;
            }
            if (world_.gameMode != GameMode.FFA) //bug checking
            {
                task.Stop();
                world_ = null;
                return;
            }

            //remove announcement after 5 seconds
            if ((DateTime.Now - announced).TotalSeconds >= 5)
            {
                foreach (Player p in world_.Players)
                {
                    if (p.usesCPE)
                    {
                        p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f"));//super hacky way to remove announcement, simply send a color code and call it a day
                    }
                }
            }

            if (!started)                       //first time running the interval
            {
                if (world_.Players.Count() < 2) //in case players leave the world or disconnect during the start delay
                {
                    world_.Players.Message("&WFFA&s requires at least 2 people to play.", 0);
                    task.Stop();
                    return;
                }
                if (startTime != null && (DateTime.Now - startTime).TotalSeconds > timeDelay)
                {
                    foreach (Player p in world_.Players)
                    {
                        int x  = rand.Next(2, world_.Map.Width);
                        int y  = rand.Next(2, world_.Map.Length);
                        int z1 = 0;
                        for (int z = world_.Map.Height - 1; z > 0; z--)
                        {
                            if (world_.Map.GetBlock(x, y, z) != Block.Air)
                            {
                                z1 = z + 3;
                                break;
                            }
                        }
                        p.TeleportTo(new Position(x, y, z1 + 2).ToVector3I().ToPlayerCoords()); //teleport players to a random position
                        InitializePlayer(p);
                        if (!p.GunMode)
                        {
                            p.GunMode = true; //turns on gunMode automatically if not already on
                            GunGlassTimer timer = new GunGlassTimer(p);
                            timer.Start();
                        }

                        if (p.Info.IsHidden) //unhides players automatically if hidden (cannot shoot guns while hidden)
                        {
                            p.Info.IsHidden = false;
                            Player.RaisePlayerHideChangedEvent(p);
                        }

                        //send an announcement
                        p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&cLet the Games Begin!"));

                        //set player health
                        p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]"));

                        //set leader
                        p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&eCurrent Leader&f: None"));
                    }
                    started = true;   //the game has officially started
                    if (!world_.gunPhysics)
                    {
                        world_.EnableGunPhysics(Player.Console, true); //enables gun physics if they are not already on
                    }
                    lastChecked = DateTime.Now;                        //used for intervals
                    announced   = DateTime.Now;                        //set when the announcement was launched
                    return;
                }
            }

            //check if one of the players has won
            foreach (Player p in world_.Players)
            {
                if (started && startTime != null && (DateTime.Now - startTime).TotalSeconds >= timeDelay && p.Info.gameKillsFFA >= scoreLimit)
                {
                    Stop(p);
                    return;
                }
            }

            //check if time is up
            if (started && startTime != null && (DateTime.Now - startTime).TotalSeconds >= (totalTime))
            {
                Player winner = GetScoreList()[0];
                if (world_.Players.Count() < 2)
                {
                    Stop(winner);
                    return;
                }
                Stop(winner);
                return;
            }

            if (started && (DateTime.Now - lastChecked).TotalSeconds > 10) //check if players left the world, forfeits if no players of that team left
            {
                if (world_.Players.Count() < 2)
                {
                    Player[] players = world_.Players;
                    Stop(players[0]);
                    return;
                }
            }
            timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).ToSeconds()));
            //Keep the players updated about the score
            if (lastChecked != null && (DateTime.Now - lastChecked).TotalSeconds > 29.9 && timeLeft <= timeLimit)
            {
                Player leader      = GetScoreList()[0]; //leader is the top of the score list
                Player secondPlace = GetScoreList()[1]; //second place is - well, second place XD
                if (isOn() && leader.Info.gameKillsFFA != secondPlace.Info.gameKillsFFA)
                {
                    world_.Players.Message("{0}&f is winning &c{1} &fto &c{2}", 0, leader.ClassyName, leader.Info.gameKillsFFA, secondPlace.Info.gameKillsFFA);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", 0, timeLeft);
                }
                if (leader.Info.gameKillsFFA == secondPlace.Info.gameKillsFFA)
                {
                    world_.Players.Message("{1}&f and {2}&f are tied at &c{0}!", 0, leader.Info.gameKillsFFA, leader.ClassyName, secondPlace.ClassyName);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", 0, timeLeft);
                }
                lastChecked = DateTime.Now;
            }
            if (timeLeft < 10.1)
            {
                world_.Players.Message("&WOnly 10 seconds left!", 0);
            }
        }
Esempio n. 2
0
        public static void Interval(SchedulerTask task)
        {
            //check to stop Interval
            if (world_ == null)
            {
                task.Stop();
                return;
            }
            if (world_.gameMode != GameMode.TeamDeathMatch)
            {
                task.Stop();
                world_ = null;
                return;
            }

            //remove announcement after 5 seconds
            if ((DateTime.Now - announced).TotalSeconds >= 5)
            {
                foreach (Player p in world_.Players)
                {
                    if (p.usesCPE)
                    {
                        p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f"));//super hacky way to remove announcement, simply send a color code and call it a day
                    }
                }
            }

            if (!started)
            {
                if (world_.Players.Count() < 2) //in case players leave the world or disconnect during the start delay
                {
                    world_.Players.Message("&WTeam DeathMatch&s requires at least 2 people to play.", MessageType.Chat);
                    return;
                }
                if (startTime != null && (DateTime.Now - startTime).TotalSeconds > timeDelay)
                {
                    foreach (Player p in world_.Players)
                    {
                        if (!manualTeams)
                        {
                            AssignTeams(p); //assigns teams (who knew?)
                        }
                        if (p.Info.isOnRedTeam)
                        {
                            p.TeleportTo(TeamDeathMatch.redSpawn);
                        }                                                                  //teleport players to the team spawn
                        if (p.Info.isOnBlueTeam)
                        {
                            p.TeleportTo(TeamDeathMatch.blueSpawn);
                        }

                        if (!p.GunMode)
                        {
                            p.GunMode = true; //turns on gunMode automatically if not already on
                            GunGlassTimer timer = new GunGlassTimer(p);
                            timer.Start();
                        }

                        if (p.Info.IsHidden) //unhides players automatically if hidden (cannot shoot guns while hidden)
                        {
                            p.Info.IsHidden = false;
                            Player.RaisePlayerHideChangedEvent(p);
                        }

                        //send an announcement
                        p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&cLet the Games Begin!"));

                        if (p.usesCPE)
                        {
                            //set player's health
                            p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]"));

                            //set game score
                            p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: 0,&1 Blue&f: 0"));
                        }
                    }
                    started = true;   //the game has officially started
                    isOn    = true;
                    if (!world_.gunPhysics)
                    {
                        world_.EnableGunPhysics(Player.Console, true); //enables gun physics if they are not already on
                    }
                    lastChecked = DateTime.Now;                        //used for intervals
                    announced   = DateTime.Now;                        //set when the announcement was launched
                    return;
                }
            }

            //check if one of the teams have won
            if (redScore >= scoreLimit || blueScore >= scoreLimit)
            {
                Stop(null);
                return;
            }
            if (blueScore == scoreLimit && redScore == scoreLimit) //if they somehow manage to tie which I am pretty sure is impossible
            {
                world_.Players.Message("The teams tied at {0}!", MessageType.Announcement, redScore);
                Stop(null);
                return;
            }

            //check if time is up
            if (started && startTime != null && (DateTime.Now - startTime).TotalSeconds >= (totalTime))
            {
                if (redScore != blueScore)
                {
                    Stop(null);
                    return;
                }
                if (redScore == blueScore)
                {
                    world_.Players.Message("&fThe teams tied {0} to {1}!", MessageType.Announcement, blueScore, redScore);
                    Stop(null);
                    return;
                }
                if (world_.Players.Count() <= 1)
                {
                    Stop(null);
                    return;
                }
            }

            if (started && (DateTime.Now - lastChecked).TotalSeconds > 10) //check if players left the world, forfeits if no players of that team left
            {
                int redCount  = world_.Players.Where(p => p.Info.isOnRedTeam).ToArray().Count();
                int blueCount = world_.Players.Where(p => p.Info.isOnBlueTeam).ToArray().Count();
                if (blueCount < 1 || redCount < 1)
                {
                    if (blueTeamCount == 0)
                    {
                        if (world_.Players.Any())
                        {
                            world_.Players.Message("&1Blue Team &fhas forfeited the game. &cRed Team &fwins!", MessageType.Announcement);
                        }
                        Stop(null);
                        return;
                    }
                    if (redTeamCount == 0)
                    {
                        if (world_.Players.Any())
                        {
                            world_.Players.Message("&cRed Team &fhas forfeited the game. &1Blue Team &fwins!", MessageType.Announcement);
                        }
                        Stop(null);
                        return;
                    }
                    else
                    {
                        Stop(null);
                        return;
                    }
                }
            }
            timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).TotalSeconds));
            //Keep the players updated about the score
            if ((DateTime.Now - lastChecked).TotalSeconds > 29.8 && timeLeft <= timeLimit)
            {
                if (redScore > blueScore)
                {
                    world_.Players.Message("&fThe &cRed Team&f is winning {0} to {1}.", MessageType.Announcement, redScore, blueScore);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", MessageType.Announcement, timeLeft);
                }
                if (redScore < blueScore)
                {
                    world_.Players.Message("&fThe &1Blue Team&f is winning {0} to {1}.", MessageType.Announcement, blueScore, redScore);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", MessageType.Announcement, timeLeft);
                }
                if (redScore == blueScore)
                {
                    world_.Players.Message("&fThe teams are tied at {0}!", MessageType.Announcement, blueScore);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", MessageType.Announcement, timeLeft);
                }
                lastChecked = DateTime.Now;
            }
            if (timeLeft == 10)
            {
                world_.Players.Message("&WOnly 10 seconds left!", MessageType.Announcement);
            }
        }
Esempio n. 3
0
        public static void Interval(SchedulerTask task)
        {
            //check to stop Interval
            if (world_ == null)
            {
                task.Stop();
                return;
            }
            if (world_.gameMode != GameMode.CaptureTheFlag)
            {
                task.Stop();
                world_ = null;
                return;
            }

            //remove announcements after 5 seconds
            if (announced != DateTime.MaxValue && (DateTime.Now - announced).TotalSeconds >= 5)
            {
                foreach (Player p in world_.Players)
                {
                    if (p.usesCPE)
                    {
                        p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f"));//super hacky way to remove announcements, simply send a color code and call it a day
                    }
                }
                announced = DateTime.MaxValue;
            }

            //remove dodge after 1m
            foreach (Player p in world_.Players)
            {
                if (p.Info.canDodge)
                {
                    if (p.Info.dodgeTime != DateTime.MaxValue && (DateTime.Now - p.Info.dodgeTime).TotalSeconds >= 60)
                    {
                        p.Info.canDodge  = false;
                        p.Info.dodgeTime = DateTime.MaxValue;

                        world_.Players.Message(p.Name + " is no longer able to dodge.", 0);
                    }
                }
            }

            //remove strengthen after 1m
            foreach (Player p in world_.Players)
            {
                if (p.Info.strengthened)
                {
                    if (p.Info.strengthTime != DateTime.MaxValue && (DateTime.Now - p.Info.strengthTime).TotalSeconds >= 60)
                    {
                        p.Info.strengthened = false;
                        p.Info.strengthTime = DateTime.MaxValue;

                        world_.Players.Message(p.Name + " is no longer dealing 2x damage.", 0);
                    }
                }
            }

            //remove Blades of Fury after 1m
            if ((BlueBOFdebuff != DateTime.MaxValue && (DateTime.Now - BlueBOFdebuff).TotalSeconds >= 60))
            {
                foreach (Player p in world_.Players)
                {
                    if (p.Info.CTFBlueTeam)
                    {
                        p.Info.stabDisarmed = false;
                    }
                    else
                    {
                        p.Info.stabAnywhere = false;
                    }
                }
                BlueBOFdebuff = DateTime.MaxValue;

                world_.Players.Message("Blades of Fury has ended.", 0);
            }

            if ((RedBOFdebuff != DateTime.MaxValue && (DateTime.Now - RedBOFdebuff).TotalSeconds >= 60))
            {
                foreach (Player p in world_.Players)
                {
                    if (p.Info.CTFRedTeam)
                    {
                        p.Info.stabDisarmed = false;
                    }
                    else
                    {
                        p.Info.stabAnywhere = false;
                    }
                }
                RedBOFdebuff = DateTime.MaxValue;

                world_.Players.Message("Blades of Fury has ended.", 0);
            }

            //remove disarm after 30s
            if ((RedDisarmed != DateTime.MaxValue && (DateTime.Now - RedDisarmed).TotalSeconds >= 30))
            {
                foreach (Player p in world_.Players)
                {
                    if (p.Info.CTFRedTeam)
                    {
                        p.GunMode          = true;
                        p.Info.gunDisarmed = false;
                    }
                }
                RedDisarmed = DateTime.MaxValue;

                world_.Players.Message("The Disarm Spell has ended.", 0);
            }

            if ((BlueDisarmed != DateTime.MaxValue && (DateTime.Now - BlueDisarmed).TotalSeconds >= 30))
            {
                foreach (Player p in world_.Players)
                {
                    if (p.Info.CTFBlueTeam)
                    {
                        p.GunMode          = true;
                        p.Info.gunDisarmed = false;
                    }
                }
                BlueDisarmed = DateTime.MaxValue;

                world_.Players.Message("The Disarm Spell has ended.", 0);
            }

            if (!started)
            {
                //create a player moving event
                Player.Moving += PlayerMoving;

                if (world_.Players.Count() < 2) //in case players leave the world or disconnect during the start delay
                {
                    world_.Players.Message("&WCTF&s requires at least 2 people to play.", 0);
                    return;
                }

                //once timedelay is up, we start
                if (startTime != null && (DateTime.Now - startTime).TotalSeconds > timeDelay)
                {
                    if (!world_.gunPhysics)
                    {
                        world_.EnableGunPhysics(Player.Console, true); //enables gun physics if they are not already on
                    }
                    foreach (Player p in world_.Players)
                    {
                        if (p.usesCPE)
                        {
                            //loop through each block ID
                            for (int i = 1; i < 65; i++)
                            {
                                //allow player to break glass block in order to shoot gun, disallow all other blocks except flags
                                if (i.Equals(20))
                                {
                                    p.Send(PacketWriter.MakeSetBlockPermissions((byte)20, false, true));
                                }
                                else if (i.Equals(21))
                                {
                                    p.Send(PacketWriter.MakeSetBlockPermissions((byte)21, false, true));
                                }
                                else if (i.Equals(29))
                                {
                                    p.Send(PacketWriter.MakeSetBlockPermissions((byte)29, false, true));
                                }
                                else
                                {
                                    p.Send(PacketWriter.MakeSetBlockPermissions((byte)i, false, false));
                                }
                            }
                        }

                        AssignTeams(p);

                        if (p.Info.IsHidden) //unhides players automatically if hidden (cannot shoot guns while hidden)
                        {
                            p.Info.IsHidden = false;
                            Player.RaisePlayerHideChangedEvent(p);
                        }

                        if (p.Info.CTFRedTeam)
                        {
                            p.TeleportTo(world_.redCTFSpawn.ToPlayerCoords());
                        }

                        if (p.Info.CTFBlueTeam)
                        {
                            p.TeleportTo(world_.blueCTFSpawn.ToPlayerCoords());
                        }

                        p.GunMode = true;
                        GunGlassTimer timer = new GunGlassTimer(p);
                        timer.Start();

                        //send an announcement (Will be sent as a normal message to non classicube players)
                        p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&cLet the Games Begin!"));

                        if (p.usesCPE)
                        {
                            //set player health
                            p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]"));

                            //set game score
                            p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: 0,&1 Blue&f: 0"));
                        }
                    }

                    //check that the flags haven't been misplaced during startup
                    if (world_.Map.GetBlock(world_.redFlag) != Block.Red)
                    {
                        world_.Map.QueueUpdate(new BlockUpdate(null, world_.redFlag, Block.Red));
                    }

                    if (world_.Map.GetBlock(world_.blueFlag) != Block.Blue)
                    {
                        world_.Map.QueueUpdate(new BlockUpdate(null, world_.blueFlag, Block.Blue));
                    }

                    started     = true;         //the game has officially started
                    isOn        = true;
                    lastChecked = DateTime.Now; //used for intervals
                    announced   = DateTime.Now;
                    return;
                }
            }

            //update blue team and red team counts
            redTeamCount =
                (
                    from red in world_.Players
                    where red.Info.CTFRedTeam
                    select red
                ).Count();

            blueTeamCount =
                (
                    from blue in world_.Players
                    where blue.Info.CTFBlueTeam
                    select blue
                ).Count();



            //Announce flag holder
            if (String.IsNullOrEmpty(redFlagHolder))
            {
                foreach (Player p in world_.Players)
                {
                    if (p.Info.hasRedFlag && redFlagHolder == null)
                    {
                        world_.Players.Message(p.Name + " has stolen the Red flag!", 0);
                        redFlagHolder = p.Name;
                    }
                }
            }

            //update flagholder
            else
            {
                redFlagHolder = null;
                foreach (Player p in world_.Players)
                {
                    if (p.Info.hasRedFlag)
                    {
                        redFlagHolder = p.Name;
                    }
                }
            }

            if (String.IsNullOrEmpty(blueFlagHolder))
            {
                foreach (Player p in world_.Players)
                {
                    if (p.Info.hasBlueFlag && blueFlagHolder == null)
                    {
                        world_.Players.Message(p.Name + " has stolen the Blue flag!", 0);
                        blueFlagHolder = p.Name;
                    }
                }
            }

            //update flagholder
            else
            {
                blueFlagHolder = null;
                foreach (Player p in world_.Players)
                {
                    if (p.Info.hasBlueFlag)
                    {
                        blueFlagHolder = p.Name;
                    }
                }
            }

            //Check victory conditions
            if (blueScore == 5)
            {
                world_.Players.Message("&fThe blue team has won {0} to {1}!", 0, blueScore, redScore);
                Stop(null);
                return;
            }

            if (redScore == 5)
            {
                world_.Players.Message("&fThe red team has won {1} to {0}!", 0, blueScore, redScore);
                Stop(null);
                return;
            }

            //if time is up
            if (started && startTime != null && (DateTime.Now - startTime).TotalSeconds >= (totalTime))
            {
                if (redScore > blueScore)
                {
                    world_.Players.Message("&fThe &cRed&f Team won {0} to {1}!", 0, redScore, blueScore);
                    Stop(null);
                    return;
                }
                if (redScore < blueScore)
                {
                    world_.Players.Message("&fThe &1Blue&f Team won {0} to {1}!", 0, blueScore, redScore);
                    Stop(null);
                    return;
                }
                if (redScore == blueScore)
                {
                    world_.Players.Message("&fThe teams tied {0} to {0}!", 0, blueScore);
                    Stop(null);
                    return;
                }
                if (world_.Players.Count() <= 1)
                {
                    Stop(null);
                    return;
                }
            }

            //Check for forfeits
            if (started && (DateTime.Now - lastChecked).TotalSeconds > 10)
            {
                if (blueTeamCount < 1 || redTeamCount < 1)
                {
                    if (blueTeamCount == 0)
                    {
                        if (world_.Players.Any())
                        {
                            world_.Players.Message("&1Blue Team &fhas forfeited the game. &cRed Team &fwins!", 0);
                        }
                        Stop(null);
                        return;
                    }
                    if (redTeamCount == 0)
                    {
                        if (world_.Players.Any())
                        {
                            world_.Players.Message("&cRed Team &fhas forfeited the game. &1Blue Team &fwins!", 0);
                        }
                        Stop(null);
                        return;
                    }
                    //lol, everyone left
                    else
                    {
                        Stop(null);
                        return;
                    }
                }
            }

            timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).TotalSeconds));
            //Keep the players updated about the score
            if (lastChecked != null && (DateTime.Now - lastChecked).TotalSeconds > 29.8 && timeLeft <= timeLimit)
            {
                if (redScore > blueScore)
                {
                    world_.Players.Message("&fThe &cRed Team&f is winning {0} to {1}.", 0, redScore, blueScore);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", 0, timeLeft);
                }
                if (redScore < blueScore)
                {
                    world_.Players.Message("&fThe &1Blue Team&f is winning {0} to {1}.", 0, blueScore, redScore);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", 0, timeLeft);
                }
                if (redScore == blueScore)
                {
                    world_.Players.Message("&fThe teams are tied at {0}!", 0, blueScore);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", 0, timeLeft);
                }
                lastChecked = DateTime.Now;
            }
            if (timeLeft == 10)
            {
                world_.Players.Message("&WOnly 10 seconds left!", 0);
            }
        }