Beispiel #1
0
func CreateArea(name string, zone types.Zone) (types.Area, error) {
	if GetAreaByName(name) != nil {
		return nil, errors.New("An area with that name already exists")
	}

	return db.NewArea(name, zone.GetId()), nil
}
Beispiel #2
0
func CreateRoom(zone types.Zone, location types.Coordinate) (types.Room, error) {
	existingRoom := GetRoomByLocation(location, zone.GetId())
	if existingRoom != nil {
		return nil, errors.New("A room already exists at that location")
	}

	return db.NewRoom(zone.GetId(), location), nil
}
Beispiel #3
0
func ZoneCorners(zone types.Zone) (types.Coordinate, types.Coordinate) {
	var top int
	var bottom int
	var left int
	var right int
	var high int
	var low int

	rooms := GetRoomsInZone(zone.GetId())

	for _, room := range rooms {
		top = room.GetLocation().Y
		bottom = room.GetLocation().Y
		left = room.GetLocation().X
		right = room.GetLocation().X
		high = room.GetLocation().Z
		low = room.GetLocation().Z
		break
	}

	for _, room := range rooms {
		if room.GetLocation().Z < high {
			high = room.GetLocation().Z
		}

		if room.GetLocation().Z > low {
			low = room.GetLocation().Z
		}

		if room.GetLocation().Y < top {
			top = room.GetLocation().Y
		}

		if room.GetLocation().Y > bottom {
			bottom = room.GetLocation().Y
		}

		if room.GetLocation().X < left {
			left = room.GetLocation().X
		}

		if room.GetLocation().X > right {
			right = room.GetLocation().X
		}
	}

	return types.Coordinate{X: left, Y: top, Z: high},
		types.Coordinate{X: right, Y: bottom, Z: low}
}