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); } }
public void blockUpdate(int index, Block type) { short x = 0; short y = 0; short z = 0; if (Math.Abs(marks[1].X - marks[0].X) > Math.Abs(marks[1].Y - marks[0].Y)) { if (marks[0].X < marks[1].X) { x = (short)(PixelPos.X + (index / 8)); y = (short)PixelPos.Y; z = (short)(PixelPos.Z + (index % 8)); } else { x = (short)(PixelPos.X - (index / 8)); y = (short)PixelPos.Y; z = (short)(PixelPos.Z + (index % 8)); } } else if (Math.Abs(marks[1].X - marks[0].X) < Math.Abs(marks[1].Y - marks[0].Y)) { if (marks[0].Y < marks[1].Y) { x = (short)PixelPos.X; y = (short)(PixelPos.Y + (index / 8)); z = (short)(PixelPos.Z + (index % 8)); } else { x = (short)PixelPos.X; y = (short)(PixelPos.Y - (index / 8)); z = (short)(PixelPos.Z + (index % 8)); } } else { return; } if (type != Block.Air) //exclude air / gaps in the cuboid { Player.RaisePlayerPlacedBlockEvent(player, world.Map, new Vector3I(x, y, z - 1), world.Map.GetBlock(x, y, z - 1), type, BlockChangeContext.Drawn); world.Map.QueueUpdate(new BlockUpdate(null, x, y, (short)(z - 1), type)); blockCount++; } }
private static void DrawOneBlock(Player player, Map map, Block drawBlock, Vector3I coord, BlockChangeContext context, ref int blocks, ref int blocksDenied, fCraft.Drawing.UndoState undoState) { if (map == null) { return; } if (player == null) { throw new ArgumentNullException("player"); } if (!map.InBounds(coord)) { return; } Block block = map.GetBlock(coord); if (block == drawBlock) { return; } if (player.CanPlace(map, coord, drawBlock, context) != CanPlaceResult.Allowed) { blocksDenied++; return; } map.QueueUpdate(new BlockUpdate(null, coord, drawBlock)); Player.RaisePlayerPlacedBlockEvent(player, map, coord, block, drawBlock, context); if (!undoState.IsTooLargeToUndo) { if (!undoState.Add(coord, block)) { player.Message("NOTE: This draw command is too massive to undo."); player.LastDrawOp = null; } } blocks++; }
public static void PlayerClickedDoor(object sender, PlayerClickedEventArgs e) { //after 10s, revert effects of /DoorCheck if ((DateTime.Now - e.Player.Info.doorCheckTime).TotalSeconds > 10 && e.Player.Info.doorCheckTime != DateTime.MaxValue) { e.Player.Info.doorCheckTime = DateTime.MaxValue; e.Player.Info.isDoorChecking = false; } Zone[] allowed, denied; if (e.Player.WorldMap.Zones.CheckDetailed(e.Coords, e.Player, out allowed, out denied)) { foreach (Zone zone in allowed) { if (zone.Name.StartsWith("Door_")) { Player.RaisePlayerPlacedBlockEvent(e.Player, e.Player.WorldMap, e.Coords, e.Block, e.Block, BlockChangeContext.Manual); //if player is checking a door, print the door info instead of opening it if (e.Player.Info.isDoorChecking) { e.Player.Message(zone.Name); e.Player.Message("Created by {0} on {1}", zone.CreatedBy, zone.CreatedDate); return; } lock (openDoorsLock) { if (!openDoors.Contains(zone)) { openDoor(zone, e.Player); openDoors.Add(zone); } } } } } }
private static void PlaceHandler(Player player, CommandReader cmd) { bool isConsole = (player == Player.Console); if (isConsole && cmd.Count < 6) { player.Message("When used by console /Place requires a world name."); player.Message("/Place [x] [y] [z] [block] [world]"); return; } Block block = Block.Stone; if (!isConsole && player.LastUsedBlockType != Block.None) block = player.LastUsedBlockType; Vector3I coords; int x, y, z; if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) { if (cmd.HasNext) { string last = cmd.Next(); if (!Map.GetBlockByName(last, false, out block)) { player.Message("\"{0}\" is not a valid block type", last); return; } } coords = new Vector3I(x, y, z); } else if (isConsole) { player.Message("Invalid coordinates!"); return; } else { cmd.Rewind(); if (cmd.HasNext) { string last = cmd.Next(); if (!Map.GetBlockByName(last, false, out block)) { player.Message("\"{0}\" is not a valid block type", last); return; } } coords = new Vector3I(player.Position.X / 32, player.Position.Y / 32, (player.Position.Z - 64) / 32); } World world; if (player == Player.Console) { string worldName = cmd.Next(); if (string.IsNullOrEmpty(worldName)) { player.Message("Console must specify a world!"); } world = WorldManager.FindWorldOrPrintMatches(player, worldName); if (world == null) return; } else { world = player.World; } bool unLoad = false; if (!world.IsLoaded) { world.LoadMap(); unLoad = true; } coords.X = Math.Min(world.map.Width - 1, Math.Max(0, coords.X)); coords.Y = Math.Min(world.map.Length - 1, Math.Max(0, coords.Y)); coords.Z = Math.Min(world.map.Height - 1, Math.Max(0, coords.Z)); if (player == Player.Console) { BlockUpdate blockUpdate = new BlockUpdate(player, coords, block); player.Info.ProcessBlockPlaced((byte)block); world.map.QueueUpdate(blockUpdate); player.RaisePlayerPlacedBlockEvent(player, world.map, coords, block, world.map.GetBlock(coords), BlockChangeContext.Manual, true); } else { player.SendNow(Packet.MakeSetBlock(coords, block, player)); player.PlaceBlockWithEvents(coords, ClickAction.Build, block); } if (!isConsole) player.Message("{0} placed at {1}", block.ToString(), coords.ToString()); if (unLoad) { world.UnloadMap(true); } }