Skip to content
Permalink
Browse files

Fix /door test not outputting anything when used on a block that was …

…not affected by doors.

Also move some stuff out of ZoneCommands and into SpecialZone.Affect
  • Loading branch information...
UnknownShadow200 committed Jul 5, 2017
1 parent 1da2e1c commit cd295d9c7e61ba8a1ee281d8bd3e41583c1048ee
Showing with 62 additions and 78 deletions.
  1. +7 −74 fCraft/Commands/ZoneCommands.cs
  2. +55 −4 fCraft/Zone/SpecialZone.Affect.cs
@@ -23,22 +23,9 @@ static class ZoneCommands {
CommandManager.RegisterCommand( CdZoneRename );
CommandManager.RegisterCommand( CdZoneTest );
CommandManager.RegisterCommand( cdDoor );
openDoors = new List<Zone>();
}
static readonly TimeSpan DoorCloseTimer = TimeSpan.FromMilliseconds(1500);
const int maxDoorBlocks = 36; //change for max door area
public static List<Zone> openDoors;

struct DoorInfo {
public readonly Zone Zone;
public readonly Block[] Buffer;
public readonly Map WorldMap;
public DoorInfo(Zone zone, Block[] buffer, Map worldMap) {
Zone = zone;
Buffer = buffer;
WorldMap = worldMap;
}
}

#region ZoneAdd

static readonly CommandDescriptor CdZoneAdd = new CommandDescriptor {
@@ -1067,20 +1054,19 @@ static void Door(Player player, CommandReader cmd)
}

static void DoorTestCallback(Player player, Vector3I[] marks, object tag) {
bool doorPresent = false;
bool anyDoors = false;
foreach (Zone zone in player.World.map.Zones) {
if (zone.Name.StartsWith(SpecialZone.Door) && zone.Bounds.Contains(marks[0])) {
player.Message("{0} created by {1} on {2}", zone.Name, zone.CreatedBy, zone.CreatedDate);
doorPresent = false;
anyDoors = true;
}
}
if (doorPresent) {
player.Message("No zones affect this block.");
if (!anyDoors) {
player.Message("No doors affect this block.");
}
}

static void DoorAdd(Player player, Vector3I[] marks, object tag)
{
static void DoorAdd(Player player, Vector3I[] marks, object tag) {
int sx = Math.Min(marks[0].X, marks[1].X);
int ex = Math.Max(marks[0].X, marks[1].X);
int sy = Math.Min(marks[0].Y, marks[1].Y);
@@ -1089,8 +1075,7 @@ static void DoorAdd(Player player, Vector3I[] marks, object tag)
int eh = Math.Max(marks[0].Z, marks[1].Z);

int volume = (ex - sx + 1) * (ey - sy + 1) * (eh - sh + 1);
if (volume > maxDoorBlocks)
{
if (volume > maxDoorBlocks) {
player.Message("Doors are only allowed to be {0} blocks", maxDoorBlocks);
return;
}
@@ -1104,58 +1089,6 @@ static void DoorAdd(Player player, Vector3I[] marks, object tag)
door.Bounds.Dimensions.Z);
}

public static readonly object openDoorsLock = new object();

public static void openDoor(Zone zone, Player player)
{

int sx = zone.Bounds.XMin;
int ex = zone.Bounds.XMax;
int sy = zone.Bounds.YMin;
int ey = zone.Bounds.YMax;
int sz = zone.Bounds.ZMin;
int ez = zone.Bounds.ZMax;

Block[] buffer = new Block[zone.Bounds.Volume];

DoorInfo info = new DoorInfo(zone, buffer, player.WorldMap);
int counter = 0;
for (int x = sx; x <= ex; x++)
{
for (int y = sy; y <= ey; y++)
{
for (int z = sz; z <= ez; z++)
{
buffer[counter] = player.WorldMap.GetBlock(x, y, z);
info.WorldMap.QueueUpdate(new BlockUpdate(null, new Vector3I(x, y, z), Block.Air));
counter++;
}
}
}

//reclose door
Scheduler.NewTask(doorTimer_Elapsed).RunOnce(info, DoorCloseTimer);

}

static void doorTimer_Elapsed(SchedulerTask task)
{
DoorInfo info = (DoorInfo)task.UserState;
int counter = 0;
for (int x = info.Zone.Bounds.XMin; x <= info.Zone.Bounds.XMax; x++)
{
for (int y = info.Zone.Bounds.YMin; y <= info.Zone.Bounds.YMax; y++)
{
for (int z = info.Zone.Bounds.ZMin; z <= info.Zone.Bounds.ZMax; z++)
{
info.WorldMap.QueueUpdate(new BlockUpdate(null, new Vector3I(x, y, z), info.Buffer[counter]));
counter++;
}
}
}

lock (openDoorsLock) { openDoors.Remove(info.Zone); }
}
#endregion
}
}
@@ -1,11 +1,28 @@
// ProCraft Copyright 2014-2016 Joseph Beauvais <123DMWM@gmail.com>
using System;
using System.Collections.Generic;
using System.IO;
using JetBrains.Annotations;

namespace fCraft {
public static partial class SpecialZone {

static readonly object openDoorsLock = new object();
static readonly TimeSpan DoorCloseTimer = TimeSpan.FromMilliseconds(1500);
static List<Zone> openDoors = new List<Zone>();

struct DoorInfo {
public readonly Zone Zone;
public readonly Block[] Buffer;
public readonly Map WorldMap;
public DoorInfo(Zone zone, Block[] buffer, Map worldMap) {
Zone = zone;
Buffer = buffer;
WorldMap = worldMap;
}
}


internal static bool CheckAffectZone(Player p, Zone zone, Vector3I coord) {
if (zone.Name.CaselessStarts(Door)) {
p.RevertBlockNow(coord);
@@ -21,13 +38,47 @@ public static partial class SpecialZone {
}

static void HandleDoor(Player p, Zone zone) {
lock (ZoneCommands.openDoorsLock) {
if (!ZoneCommands.openDoors.Contains(zone)) {
ZoneCommands.openDoor(zone, p);
ZoneCommands.openDoors.Add(zone);
lock (openDoorsLock) {
if (!openDoors.Contains(zone)) {
OpenDoor(zone, p);
openDoors.Add(zone);
}
}
}

static void OpenDoor(Zone zone, Player player) {
Block[] buffer = new Block[zone.Bounds.Volume];
DoorInfo info = new DoorInfo(zone, buffer, player.WorldMap);
int i = 0;

for (int x = info.Zone.Bounds.XMin; x <= info.Zone.Bounds.XMax; x++)
for (int y = info.Zone.Bounds.YMin; y <= info.Zone.Bounds.YMax; y++)
for (int z = info.Zone.Bounds.ZMin; z <= info.Zone.Bounds.ZMax; z++)
{
buffer[i] = player.WorldMap.GetBlock(x, y, z);
info.WorldMap.QueueUpdate(new BlockUpdate(null, new Vector3I(x, y, z), Block.Air));
i++;
}

// reclose door
Scheduler.NewTask(DoorTimerElapsed).RunOnce(info, DoorCloseTimer);
}

static void DoorTimerElapsed(SchedulerTask task) {
DoorInfo info = (DoorInfo)task.UserState;
int i = 0;

for (int x = info.Zone.Bounds.XMin; x <= info.Zone.Bounds.XMax; x++)
for (int y = info.Zone.Bounds.YMin; y <= info.Zone.Bounds.YMax; y++)
for (int z = info.Zone.Bounds.ZMin; z <= info.Zone.Bounds.ZMax; z++)
{
info.WorldMap.QueueUpdate(new BlockUpdate(null, new Vector3I(x, y, z), info.Buffer[i]));
i++;
}

lock (openDoorsLock) { openDoors.Remove(info.Zone); }
}


static void HandleSign(Player p, Zone zone) {
p.LastSignClicked = zone.Name;

0 comments on commit cd295d9

Please sign in to comment.
You can’t perform that action at this time.