Example #1
0
        public static void RevertNames()    //reverts names and vars for online players. offline players get reverted upon leaving the game
        {
            List <PlayerInfo> CTFPlayers = new List <PlayerInfo>(PlayerDB.PlayerInfoList.Where(r => (r.CTFBlueTeam || r.CTFRedTeam) && r.IsOnline).ToArray());

            for (int i = 0; i < CTFPlayers.Count(); i++)
            {
                string     p1 = CTFPlayers[i].Name.ToString();
                PlayerInfo pI = PlayerDB.FindPlayerInfoExact(p1);
                Player     p  = pI.PlayerObject;

                if (p != null)
                {
                    p.iName = null;
                    pI.tempDisplayedName = null;
                    pI.CTFBlueTeam       = false;
                    pI.CTFRedTeam        = false;
                    pI.isPlayingCTF      = false;
                    pI.placingBlueFlag   = false;
                    pI.placingRedFlag    = false;
                    pI.hasRedFlag        = false;
                    pI.hasBlueFlag       = false;
                    pI.CTFCaptures       = 0;
                    pI.CTFKills          = 0;
                    p.entityChanged      = true;

                    //reset all special messages
                    if (p.ClassiCube && Heartbeat.ClassiCube())
                    {
                        p.Send(PacketWriter.MakeSetBlockPermissions((byte)0, true, true));
                        p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f"));
                        p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f"));
                        p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&f"));
                    }

                    //undo gunmode (taken from GunHandler.cs)
                    p.GunMode = false;
                    try
                    {
                        foreach (Vector3I block in p.GunCache.Values)
                        {
                            p.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, p.WorldMap.GetBlock(block)));
                            Vector3I removed;
                            p.GunCache.TryRemove(block.ToString(), out removed);
                        }
                        if (p.bluePortal.Count > 0)
                        {
                            int j = 0;
                            foreach (Vector3I block in p.bluePortal)
                            {
                                if (p.WorldMap != null && p.World.IsLoaded)
                                {
                                    p.WorldMap.QueueUpdate(new BlockUpdate(null, block, p.blueOld[j]));
                                    j++;
                                }
                            }
                            p.blueOld.Clear();
                            p.bluePortal.Clear();
                        }
                        if (p.orangePortal.Count > 0)
                        {
                            int j = 0;
                            foreach (Vector3I block in p.orangePortal)
                            {
                                if (p.WorldMap != null && p.World.IsLoaded)
                                {
                                    p.WorldMap.QueueUpdate(new BlockUpdate(null, block, p.orangeOld[j]));
                                    j++;
                                }
                            }
                            p.orangeOld.Clear();
                            p.orangePortal.Clear();
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(LogType.SeriousError, "" + ex);
                    }
                    if (p.IsOnline)
                    {
                        p.Message("&aYour status has been reverted.");
                    }
                }
            }
        }
Example #2
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.ClassiCube && Heartbeat.ClassiCube())
                    {
                        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.");
                    }
                }
            }

            //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.");
                    }
                }
            }

            //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.");
            }

            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.");
            }

            //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.");
            }

            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.");
            }

            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.");
                    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.ClassiCube && Heartbeat.ClassiCube())
                        {
                            //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.ClassiCube && Heartbeat.ClassiCube())
                        {
                            //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!");
                        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!");
                        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}!", blueScore, redScore);
                Stop(null);
                return;
            }

            if (redScore == 5)
            {
                world_.Players.Message("&fThe red team has won {1} to {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}!", redScore, blueScore);
                    Stop(null);
                    return;
                }
                if (redScore < blueScore)
                {
                    world_.Players.Message("&fThe &1Blue&f Team won {0} to {1}!", blueScore, redScore);
                    Stop(null);
                    return;
                }
                if (redScore == blueScore)
                {
                    world_.Players.Message("&fThe teams tied {0} to {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.Count() >= 1)
                        {
                            world_.Players.Message("&1Blue Team &fhas forfeited the game. &cRed Team &fwins!");
                        }
                        Stop(null);
                        return;
                    }
                    if (redTeamCount == 0)
                    {
                        if (world_.Players.Count() >= 1)
                        {
                            world_.Players.Message("&cRed Team &fhas forfeited the game. &1Blue Team &fwins!");
                        }
                        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}.", redScore, blueScore);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft);
                }
                if (redScore < blueScore)
                {
                    world_.Players.Message("&fThe &1Blue Team&f is winning {0} to {1}.", blueScore, redScore);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft);
                }
                if (redScore == blueScore)
                {
                    world_.Players.Message("&fThe teams are tied at {0}!", blueScore);
                    world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft);
                }
                lastChecked = DateTime.Now;
            }
            if (timeLeft == 10)
            {
                world_.Players.Message("&WOnly 10 seconds left!");
            }
        }