AddPhysicsTask() private method

private AddPhysicsTask ( PhysicsTask task, int Delay ) : void
task PhysicsTask
Delay int
return void
Example #1
0
 public static void blockSquash(object sender, PlayerPlacingBlockEventArgs e)
 {
     try {
         Player player = e.Player;
         World  world  = player.World;
         if (null == world)
         {
             return;
         }
         lock (world.SyncRoot) {
             if (null != world.Map && world.IsLoaded && world.plantPhysics)
             {
                 if (e.NewBlock == Block.Plant)
                 {
                     world.AddPhysicsTask(new PlantTask(world, ( short )e.Coords.X, ( short )e.Coords.Y, ( short )e.Coords.Z), PlantTask.GetRandomDelay());
                 }
                 Vector3I z = new Vector3I(e.Coords.X, e.Coords.Y, e.Coords.Z - 1);
                 if (world.Map.GetBlock(z) == Block.Grass && e.NewBlock != Block.Air)
                 {
                     world.Map.QueueUpdate(new BlockUpdate(null, z, Block.Dirt));
                 }
                 else if (Physics.CanSquash(world.Map.GetBlock(z)) && e.NewBlock != Block.Air)
                 {
                     e.Result = CanPlaceResult.Revert;
                     Player.RaisePlayerPlacedBlockEvent(player, world.Map, z, world.Map.GetBlock(z), e.NewBlock, BlockChangeContext.Physics);
                     world.Map.QueueUpdate(new BlockUpdate(null, z, e.NewBlock));
                 }
             }
         }
     } catch (Exception ex) {
         Logger.Log(LogType.SeriousError, "BlockSquash" + ex);
     }
 }
Example #2
0
 public void HitPlayer(World world, Vector3I pos, Player hitted, Player by, ref int restDistance, IList <BlockUpdate> updates)
 {
     hitted.Kill(world, String.Format("{0}&S was torn to pieces by {1}", hitted.ClassyName, hitted.ClassyName == by.ClassyName ? "theirself" : by.ClassyName));
     updates.Add(new BlockUpdate(null, pos, Block.TNT));
     world.AddPhysicsTask(new TNTTask(world, pos, by, false, true), 0);
     restDistance = 0;
 }
Example #3
0
 public static void ClickedGlass(object sender, PlayerClickingEventArgs e)
 {
     if (e.Player.GunMode && !e.Player.Info.IsHidden && !e.Player.Info.IsFrozen)
     {
         World world = e.Player.World;
         Map   map   = e.Player.World.Map;
         if (e.Player.GunCache.Values.Contains(e.Coords))
         {
             if (world.gunPhysics)
             {
                 e.Player.Send(PacketWriter.MakeSetBlock(e.Coords.X, e.Coords.Y, e.Coords.Z, Block.Glass));
                 if (e.Block == Block.TNT && world.tntPhysics)
                 {
                     if (e.Player.CanFireTNT())
                     {
                         double   ksi = 2.0 * Math.PI * (-e.Player.Position.L) / 256.0;
                         double   r   = Math.Cos(ksi);
                         double   phi = 2.0 * Math.PI * (e.Player.Position.R - 64) / 256.0;
                         Vector3F dir = new Vector3F((float)(r * Math.Cos(phi)), (float)(r * Math.Sin(phi)),
                                                     (float)(Math.Sin(ksi)));
                         world.AddPhysicsTask(
                             new Particle(world, e.Coords, dir, e.Player, Block.TNT, _tntBulletBehavior), 0);
                     }
                 }
                 else
                 {
                     Block block = e.Block;
                     if (block == Block.BlueWool)
                     {
                         block = Block.Water;
                     }
                     if (block == Block.OrangeWool)
                     {
                         block = Block.Lava;
                     }
                     double   ksi = 2.0 * Math.PI * (-e.Player.Position.L) / 256.0;
                     double   r   = Math.Cos(ksi);
                     double   phi = 2.0 * Math.PI * (e.Player.Position.R - 64) / 256.0;
                     Vector3F dir = new Vector3F((float)(r * Math.Cos(phi)), (float)(r * Math.Sin(phi)),
                                                 (float)(Math.Sin(ksi)));
                     world.AddPhysicsTask(new Particle(world, e.Coords, dir, e.Player, block, _bulletBehavior), 0);
                 }
             }
         }
     }
 }
Example #4
0
 public bool VisitBlock(World world, Vector3I pos, Block block, Player owner, ref int restDistance, IList <BlockUpdate> updates, Block sending)
 {
     if (Block.Air != block && Block.Water != block)            //explode it
     {
         updates.Add(new BlockUpdate(null, pos, Block.TNT));
         world.AddPhysicsTask(new TNTTask(world, pos, owner, false, true), 0);
         restDistance = 0;
         return(false);
     }
     return(true);
 }
Example #5
0
 public void ClickedFootball(object sender, PlayerClickedEventArgs e)
 {
     //replace e.coords with player.Pos.toblock()(moving event)
     if (e.Coords == _world.footballPos)
     {
         double   ksi = 2.0 * Math.PI * (-e.Player.Position.L) / 256.0;
         double   r   = Math.Cos(ksi);
         double   phi = 2.0 * Math.PI * (e.Player.Position.R - 64) / 256.0;
         Vector3F dir = new Vector3F((float)(r * Math.Cos(phi)), (float)(r * Math.Sin(phi)), (float)(Math.Sin(ksi)));
         _world.AddPhysicsTask(new Particle(_world, e.Coords, dir, e.Player, Block.White, _footballBehavior), 0);
     }
 }
Example #6
0
 //true if not stopped
 public bool VisitBlock(World world, Vector3I pos, Block block, Player owner, ref int restDistance, IList <BlockUpdate> updates, Block sending)
 {
     if (Block.TNT == block)             //explode it
     {
         world.AddPhysicsTask(new TNTTask(world, pos, owner, false, true), _r.Next(150, 300));
     }
     if (Block.Air != block && Block.Water != block && Block.Lava != block)
     {
         if (owner.CanPlace(world.Map, pos, Block.Wood, BlockChangeContext.Manual) == CanPlaceResult.Allowed)
         {
             updates.Add(new BlockUpdate(null, pos, Block.Air));
         }
     }
     return(true);
 }
Example #7
0
        internal static void SpellHandler(Player player, Command cmd)
        {
            World    world = player.World;
            Vector3I pos1  = player.Position.ToBlockCoords();
            Random   _r    = new Random();
            int      n     = _r.Next(8, 12);

            for (int i = 0; i < n; ++i)
            {
                double phi = -_r.NextDouble() + -player.Position.L * 2 * Math.PI;
                double ksi = -_r.NextDouble() + player.Position.R * Math.PI - Math.PI / 2.0;

                Vector3F direction = (new Vector3F(( float )(Math.Cos(phi) * Math.Cos(ksi)), ( float )(Math.Sin(phi) * Math.Cos(ksi)), ( float )Math.Sin(ksi))).Normalize();
                world.AddPhysicsTask(new Particle(world, (pos1 + 2 * direction).Round(), direction, player, Block.Obsidian, particleBehavior), 0);
            }
        }
Example #8
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);
                            }
                        }
                    }
                }
            }
        }
Example #9
0
 public bool VisitBlock(World world, Vector3I pos, Block block, Player owner, ref int restDistance, IList<BlockUpdate> updates, Block sending)
 {
     if (Block.Air != block && Block.Water != block) //explode it
     {
         updates.Add(new BlockUpdate(null, pos, Block.TNT));
         world.AddPhysicsTask(new TNTTask(world, pos, owner, false, true), 0);
         restDistance = 0;
         return false;
     }
     return true;
 }
Example #10
0
 public void HitPlayer(World world, Vector3I pos, Player hitted, Player by, ref int restDistance, IList<BlockUpdate> updates)
 {
     hitted.Kill(world, String.Format("{0}&S was torn to pieces by {1}", hitted.ClassyName, hitted.ClassyName == by.ClassyName ? "theirself" : by.ClassyName));
     updates.Add(new BlockUpdate(null, pos, Block.TNT));
     world.AddPhysicsTask(new TNTTask(world, pos, by, false, true), 0);
     restDistance = 0;
 }
Example #11
0
 //true if not stopped
 public bool VisitBlock(World world, Vector3I pos, Block block, Player owner, ref int restDistance, IList<BlockUpdate> updates, Block sending)
 {
     if (Block.TNT == block) //explode it
     {
         world.AddPhysicsTask(new TNTTask(world, pos, owner, false, true), _r.Next(150, 300));
     }
     if (Block.Air != block && Block.Water != block && Block.Lava != block)
         updates.Add(new BlockUpdate(null, pos, Block.Air));
     return true;
 }
Example #12
0
        public static void PlayerPlacingPhysics(object sender, PlayerPlacingBlockEventArgs e)
        {
            World world = e.Player.World;

            if (e.Result != CanPlaceResult.Allowed)
            {
                return;
            }
            if (e.NewBlock == Block.Gold)
            {
                if (e.Context == BlockChangeContext.Manual)
                {
                    if (e.Player.fireworkMode && world.fireworkPhysics)
                    {
                        if (world.FireworkCount > 10)
                        {
                            e.Result = CanPlaceResult.Revert;
                            e.Player.Message("&WThere are too many active fireworks on this world");
                            return;
                        }
                        else
                        {
                            world.FireworkCount++;
                            world.AddPhysicsTask(new Firework(world, e.Coords), 300);
                        }
                    }
                }
            }
            if (e.NewBlock == Block.TNT)
            {
                if (world.tntPhysics)
                {
                    if (e.Context == BlockChangeContext.Manual)
                    {
                        lock (world.SyncRoot) {
                            world.AddPhysicsTask(new TNTTask(world, e.Coords, e.Player, false, true), 3000);
                            return;
                        }
                    }
                }
            }
            if (e.NewBlock == Block.Sand || e.NewBlock == Block.Gravel)
            {
                if (e.Context == BlockChangeContext.Manual)
                {
                    if (world.sandPhysics)
                    {
                        lock (world.SyncRoot) {
                            world.AddPhysicsTask(new SandTask(world, e.Coords, e.NewBlock), 150);
                            return;
                        }
                    }
                }
            }
            if (Physics.CanFloat(e.NewBlock))
            {
                if (world.waterPhysics)
                {
                    if (e.Context == BlockChangeContext.Manual)
                    {
                        world.AddPhysicsTask(new BlockFloat(world, e.Coords, e.NewBlock), 200);
                        return;
                    }
                }
            }
            if (!Physics.CanFloat(e.NewBlock) &&
                e.NewBlock != Block.Air &&
                e.NewBlock != Block.Water &&
                e.NewBlock != Block.Lava &&
                e.NewBlock != Block.BrownMushroom &&
                e.NewBlock != Block.RedFlower &&
                e.NewBlock != Block.RedMushroom &&
                e.NewBlock != Block.YellowFlower &&
                e.NewBlock != Block.Plant)
            {
                if (e.Context == BlockChangeContext.Manual)
                {
                    if (world.waterPhysics)
                    {
                        world.AddPhysicsTask(new BlockSink(world, e.Coords, e.NewBlock), 200);
                        return;
                    }
                }
            }
        }
Example #13
0
 //true if not stopped
 public bool VisitBlock(World world, Vector3I pos, Block block, Player owner, ref int restDistance, IList<BlockUpdate> updates, Block sending)
 {
     if (Block.TNT == block) //explode it
     {
         world.AddPhysicsTask(new TNTTask(world, pos, owner, false, true), _r.Next(150, 300));
     }
     if (Block.Air != block && Block.Water != block && Block.Lava != block)
         if (owner.CanPlace(world.Map, pos, Block.Wood, BlockChangeContext.Manual) == CanPlaceResult.Allowed)
         updates.Add(new BlockUpdate(null, pos, Block.Air));
     return true;
 }