Inheritance: PlayerEventArgs
Ejemplo n.º 1
0
        public static void DummyFollowing(object sender, Events.PlayerMovingEventArgs e)
        {
            if (e.Player.World.Map.Dummys.Count() > 0)
            {
                foreach (Player d in e.Player.World.Map.Dummys)
                {
                    if (d.Info.IsFollowing)
                    {
                        if (d.Info.ID.ToString() == e.Player.Info.followingID)
                        {
                            Vector3I oldPos = new Vector3I(e.OldPosition.X, e.OldPosition.Y, e.OldPosition.Z);
                            Vector3I newPos = new Vector3I(e.NewPosition.X, e.NewPosition.Y, e.NewPosition.Z);
                            Packet   packet = PacketWriter.MakeMoveRotate(d.Info.ID, new Position
                            {
                                X = (short)(newPos.X - oldPos.X),
                                Y = (short)(newPos.Y - oldPos.Y),
                                Z = (short)(newPos.Z - oldPos.Z),
                                R = (byte)Math.Abs(e.Player.Position.R),
                                L = (byte)Math.Abs(e.Player.Position.L)
                            });;

                            e.Player.World.Players.Send(packet);
                            d.Info.DummyPos = d.Position;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        // Checks if the seeker tagged a player, after they broke the block form
        public static void PlayerMovingHandler(object sender, Events.PlayerMovingEventArgs e)
        {
            if (e.Player.IsPropHuntSeeker)
            {
                var oldPos = new Vector3I(e.OldPosition.X / 32, e.OldPosition.Y / 32, e.OldPosition.Z / 32);
                // Get the position of the player
                var newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, e.NewPosition.Z / 32);

                if (oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z)
                // Check if the positions are not the same (player moved)
                {
                    foreach (Player p in PropHuntPlayers.ToList())
                    {
                        Vector3I pos = p.Position.ToBlockCoords(); // Converts to block coords
                        if (e.NewPosition.DistanceSquaredTo(pos.ToPlayerCoords()) <= 48 * 48 && p != e.Player && !p.IsSolidBlock)
                        {
                            if (!p.IsPropHuntSeeker && !p.IsSolidBlock)
                            {
                                MakeSeeker(p);
                                Server.Message(p, "&W{0} was tagged!", p.ClassyName);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void DummyTurn(object sender, Events.PlayerMovingEventArgs e)
        {
            foreach (Player d in e.Player.World.Map.Dummys)
            {
                foreach (Player P in e.Player.World.Players)
                {
                    if (d.Info.Static)
                    {
                        Packet packet = PacketWriter.MakeMoveRotate(d.Info.ID, new Position
                        {
                            X = d.Position.X,
                            Y = d.Position.Y,
                            Z = d.Position.Z,
                            R = (byte)Math.Abs(P.Position.L * 2),
                            L = (byte)Math.Abs(P.Position.L * 2)
                        });;

                        P.Send(packet);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        //check if player tagged another player
        public static void PlayerMoved(object poo, fCraft.Events.PlayerMovingEventArgs e)
        {
            if (e.Player.Info.isInfected)
            {
                Vector3I oldPos = new Vector3I(e.OldPosition.X / 32, e.OldPosition.Y / 32, e.OldPosition.Z / 32);   //get positions as block coords
                Vector3I newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, e.NewPosition.Z / 32);

                if (oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z) //check if player has moved at least one block
                {
                    foreach (Player p in world_.Players)
                    {
                        Vector3I pos = p.Position.ToBlockCoords();                                             //convert to block coords

                        if (e.NewPosition.DistanceSquaredTo(pos.ToPlayerCoords()) <= 42 * 42 && p != e.Player) //Get blocks on and around player, ignore instances when the target = player
                        {
                            if (!p.Info.isInfected)
                            {
                                Infect(p, e.Player);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void movePortal(object sender, PlayerMovingEventArgs e)
        {
            try
            {
                if (e.Player.LastUsedPortal != null && (DateTime.Now - e.Player.LastUsedPortal).TotalSeconds < 4)
                {
                    return;
                }
                Vector3I newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, (e.NewPosition.Z / 32));
                foreach (Player p in e.Player.World.Players)
                {
                    foreach (Vector3I block in p.bluePortal)
                    {
                        if (newPos == block)
                        {
                            if (p.World.Map.GetBlock(block) == Block.Water)
                            {
                                if (p.orangePortal.Count > 0)
                                {
                                    e.Player.TeleportTo(new Position
                                    {
                                        X = (short)(((p.orangePortal[0].X) + 0.5) * 32),
                                        Y = (short)(((p.orangePortal[0].Y) + 0.5) * 32),
                                        Z = (short)(((p.orangePortal[0].Z) + 1.59375) * 32),
                                        R = (byte)(p.blueOut - 128),
                                        L = e.Player.Position.L
                                    });
                                }
                                e.Player.LastUsedPortal = DateTime.Now;
                            }
                        }
                    }

                    foreach (Vector3I block in p.orangePortal)
                    {
                        if (newPos == block)
                        {
                            if (p.World.Map.GetBlock(block) == Block.Lava)
                            {
                                if (p.bluePortal.Count > 0)
                                {
                                    e.Player.TeleportTo(new Position
                                    {
                                        X = (short)(((p.bluePortal[0].X + 0.5)) * 32),
                                        Y = (short)(((p.bluePortal[0].Y + 0.5)) * 32),
                                        Z = (short)(((p.bluePortal[0].Z) + 1.59375) * 32), //fixed point 1.59375 lol.
                                        R = (byte)(p.orangeOut - 128),
                                        L = e.Player.Position.L
                                    });
                                }
                                e.Player.LastUsedPortal = DateTime.Now;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.SeriousError, "MovePortal: " + ex);
            }
        }
Ejemplo n.º 6
0
 static bool RaisePlayerMovingEvent( [NotNull] Player player, Position newPos ) {
     if( player == null ) throw new ArgumentNullException( "player" );
     var h = Moving;
     if( h == null ) return false;
     var e = new PlayerMovingEventArgs( player, newPos );
     h( null, e );
     return e.Cancel;
 }
Ejemplo n.º 7
0
        private static void PlayerMoving( object sender, PlayerMovingEventArgs e )
        {
            if ( _world != null && e.Player.World == _world ) {
                if ( _world.gameMode == GameMode.MineField && !Failed.Contains( e.Player ) ) {
                    if ( e.NewPosition != null ) {
                        Vector3I oldPos = new Vector3I( e.OldPosition.X / 32, e.OldPosition.Y / 32, e.OldPosition.Z / 32 );
                        Vector3I newPos = new Vector3I( e.NewPosition.X / 32, e.NewPosition.Y / 32, e.NewPosition.Z / 32 );

                        if ( oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z ) {
                            if ( !_map.InBounds( newPos ) ) {
                                e.Player.TeleportTo( _map.Spawn );
                                newPos = ( Vector3I )_map.Spawn;
                            }
                            // Check if the player jumped, flew, whatevers
                            if ( newPos.Z > _ground + 2 ) {
                                e.Player.TeleportTo( e.OldPosition );
                                newPos = oldPos;
                            }
                            foreach ( Vector3I pos in Mines.Values ) {
                                if ( newPos == new Vector3I( pos.X, pos.Y, pos.Z + 2 ) ||
                                    newPos == new Vector3I( pos.X, pos.Y, pos.Z + 1 ) ||
                                    newPos == new Vector3I( pos.X, pos.Y, pos.Z ) ) {
                                    _world.Map.QueueUpdate( new BlockUpdate( null, pos, Block.TNT ) );
                                    _world.AddPhysicsTask( new TNTTask( _world, pos, null, true, false ), 0 );
                                    Vector3I removed;
                                    Mines.TryRemove( pos.ToString(), out removed );
                                }
                            }
                            if ( _map.GetBlock( newPos.X, newPos.Y, newPos.Z - 2 ) == Block.Green
                                && !_stopped ) {
                                _stopped = true;
                                Stop( e.Player, true );
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static void PlayerMoving(object poo, fCraft.Events.PlayerMovingEventArgs e)
        {
            if (!started)
            {
                return;
            }
            //If the player has the red flag (player is no the blue team)
            if (e.Player.Info.hasRedFlag)
            {
                Vector3I oldPos = e.OldPosition.ToBlockCoords(); //get positions as block coords
                Vector3I newPos = e.NewPosition.ToBlockCoords();

                if (oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z) //check if player has moved at least one block
                {
                    //If the player is near enough to the blue spawn
                    if (e.NewPosition.DistanceSquaredTo(world_.blueCTFSpawn.ToPlayerCoords()) <= 42 * 42)
                    {
                        blueScore++;
                        world_.Players.Message("&f{0} has capped the &cred &fflag. The score is now &cRed&f: {1} and &1Blue&f: {2}.", e.Player.Name, redScore, blueScore);
                        e.Player.Info.hasRedFlag = false;
                        redFlagHolder            = null;
                        e.Player.Info.CTFCaptures++;

                        //Replace red block as flag
                        BlockUpdate blockUpdate = new BlockUpdate(null, world_.redFlag, Block.Red);
                        foreach (Player p in world_.Players)
                        {
                            p.World.Map.QueueUpdate(blockUpdate);

                            //set game score
                            if (p.ClassiCube && Heartbeat.ClassiCube())
                            {
                                p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: " + redScore + ",&1 Blue&f: " + blueScore));
                                p.Send(PacketWriter.MakeSpecialMessage((byte)100, e.Player.Name + " has successfully capped the &cred &fflag"));
                            }
                        }
                        world_.redFlagTaken = false;
                        announced           = DateTime.Now;
                        return;
                    }
                }
            }
            //If the player has the blue flag (player must be on red team)
            else if (e.Player.Info.hasBlueFlag)
            {
                Vector3I oldPos = e.OldPosition.ToBlockCoords(); //get positions as block coords
                Vector3I newPos = e.NewPosition.ToBlockCoords();

                if (oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z) //check if player has moved at least one block
                {
                    //If the player is near enough to the red spawn
                    if (e.NewPosition.DistanceSquaredTo(world_.redCTFSpawn.ToPlayerCoords()) <= 42 * 42)
                    {
                        redScore++;
                        world_.Players.Message("&f{0} has capped the &1blue &fflag. The score is now &cRed&f: {1} and &1Blue&f: {2}.", e.Player.Name, redScore, blueScore);
                        e.Player.Info.hasBlueFlag = false;
                        blueFlagHolder            = null;
                        e.Player.Info.CTFCaptures++;

                        //Replace blue block as flag
                        BlockUpdate blockUpdate = new BlockUpdate(null, world_.blueFlag, Block.Blue);
                        foreach (Player p in world_.Players)
                        {
                            p.World.Map.QueueUpdate(blockUpdate);

                            //set game scorecboard
                            if (p.ClassiCube && Heartbeat.ClassiCube())
                            {
                                p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: " + redScore + ",&1 Blue&f: " + blueScore));
                                p.Send(PacketWriter.MakeSpecialMessage((byte)100, e.Player.Name + " has successfully capped the &cred &fflag"));
                            }
                        }
                        world_.blueFlagTaken = false;
                        announced            = DateTime.Now;
                        return;
                    }
                }
            }

            //backstabbing, player with a flag cannot backstab an enemy player
            else
            {
                if (e.Player.Info.stabDisarmed)
                {
                    return;
                }

                Vector3I oldPos = e.OldPosition.ToBlockCoords(); //get positions as block coords
                Vector3I newPos = e.NewPosition.ToBlockCoords();

                if (oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z) //check if player has moved at least one block
                {
                    //loop through each player, detect if current player is "touching" another player
                    foreach (Player p in world_.Players)
                    {
                        Vector3I pos = p.Position.ToBlockCoords(); //convert to block coords

                        //determine if player is "touching" another player
                        if (e.NewPosition.DistanceSquaredTo(pos.ToPlayerCoords()) <= 42 * 42 && p != e.Player)
                        {
                            if ((p.Info.CTFBlueTeam && e.Player.Info.CTFBlueTeam) || (p.Info.CTFRedTeam && e.Player.Info.CTFRedTeam))
                            {
                                //friendly fire, do not stab
                                return;
                            }

                            //create just under a 180 degree semicircle in the direction the target player is facing (90 degrees = 64 pos.R bytes)
                            short lowerLimit = (short)(p.Position.R - 63);
                            short upperLimit = (short)(p.Position.R + 63);

                            //if lower limit is -45 degrees for example, convert to 256 + (-32) = 201 bytes (-45 degrees translates to -32 bytes)
                            if (lowerLimit < 0)
                            {
                                lowerLimit = (short)(256 + lowerLimit);
                            }

                            //if upper limit is 450 degrees for example, convert to 320 - 256 = 54 bytes (450 degrees translates to 320 bytes, 360 degrees translates to 256 bytes)
                            if (upperLimit > 256)
                            {
                                upperLimit = (short)(upperLimit - 256);
                            }

                            //Logger.LogToConsole(upperLimit.ToString() + " " + lowerLimit.ToString() + " " + e.Player.Position.R.ToString() + " " + p.Position.R);

                            bool kill = false;

                            //if target's line of sight contains 0
                            if (p.Position.R > 192 && p.Position.R < 64)
                            {
                                if (Enumerable.Range(lowerLimit, 255).Contains(e.Player.Position.R) || Enumerable.Range(0, upperLimit).Contains(e.Player.Position.R))
                                {
                                    kill = true;
                                }
                            }
                            else
                            {
                                if (Enumerable.Range(lowerLimit, upperLimit).Contains(e.Player.Position.R))
                                {
                                    kill = true;
                                }
                            }

                            if (e.Player.Info.stabAnywhere)
                            {
                                kill = true;
                            }

                            if (kill)
                            {
                                p.KillCTF(world_, String.Format("&f{0}&S was backstabbed by &f{1}", p.Name, e.Player.Name));
                                e.Player.Info.CTFKills++;
                                PowerUp(e.Player);

                                if (p.Info.hasRedFlag)
                                {
                                    world_.Players.Message("The red flag has been returned.");
                                    p.Info.hasRedFlag = false;
                                    redFlagHolder     = null;

                                    //Put flag back
                                    BlockUpdate blockUpdate = new BlockUpdate(null, world_.redFlag, Block.Red);
                                    foreach (Player pl in world_.Players)
                                    {
                                        pl.World.Map.QueueUpdate(blockUpdate);
                                    }
                                    world_.redFlagTaken = false;
                                }

                                if (p.Info.hasBlueFlag)
                                {
                                    world_.Players.Message("The blue flag has been returned.");
                                    p.Info.hasBlueFlag = false;
                                    blueFlagHolder     = null;

                                    //Put flag back
                                    BlockUpdate blockUpdate = new BlockUpdate(null, world_.blueFlag, Block.Blue);
                                    foreach (Player pl in world_.Players)
                                    {
                                        pl.World.Map.QueueUpdate(blockUpdate);
                                    }
                                    world_.blueFlagTaken = false;
                                }
                            }
                            //target player can see player, do not stab
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
 internal static bool RaisePlayerMovingEvent( Player player, Position newPos ) {
     var h = PlayerMoving;
     if( h == null ) return false;
     var e = new PlayerMovingEventArgs( player, newPos );
     h( null, e );
     return e.Cancel;
 }
Ejemplo n.º 10
0
 static bool RaisePlayerMovingEvent( [NotNull] Player player, Position newPos ) {
     if( player == null ) throw new ArgumentNullException( "player" );
     var e = new PlayerMovingEventArgs( player, newPos );
     MovingEvent.Raise( e );
     return !e.Cancel;
 }