Example #1
0
	def initializeTraps(self):
		#TODO: Remove treasure / traps / stairs when reloading.
		if self.isStairRoom:
			pos = self.getRandomPosition()
			coords = posToCoords(pos)
			if GetTerrain(self.floor).getAtCoord(coords) != 1 and coords not in GetTerrain(self.floor).traps:
				directions = []
				if self.floor > 1:
					directions += [Traps.Directions.UP]
				if self.floor < NUMFLOORS:
					directions += [Traps.Directions.DOWN]
				if directions:
					direction = random.choice(directions)
					self.traps += [Traps.createTrap(coords, PTRS["TRAPTYPES"].STAIRS, self.floor, [direction])]
				
		if random.random() <= TREASURECHANCE:
			pos = self.getRandomPosition()
			self.traps += [Traps.createTrap(posToCoords(pos), PTRS["TRAPTYPES"].TREASURE, self.floor, ["-d", self, "-t", random.randint(0, 2)])]
			
		if random.random() <= TRAPCHANCE:
			for i in range(random.randint(5, 10)):
				toDo = 1
				if random.random() <= 0.2:
					toDo = 2
				pos = self.getRandomPosition()
				for x in range(toDo):
					for y in range(toDo):
						coords = posToCoords(pos)
						coords = (coords[0] + x, coords[1] + y)
						if GetTerrain(self.floor).getAtCoord(coords) != 1 and coords not in GetTerrain(self.floor).traps:
							self.traps += [Traps.createTrap(coords, PTRS["TRAPTYPES"].FLOORSPIKETRAP, self.floor, ["-d", self, "-t", random.randint(0, 2)])]
Example #2
0
	def addShrine(self, TPtr, room, boxSize, square, godInfo):
		coordTarg = dungeonGridToCoords([square[0], square[1]])
		if godInfo["god"] == "Nature":
			coordTarg = [coordTarg[0] - 1, coordTarg[1] - 2]
			for x in range(3):
				for y in range(4):
					cPos = (coordTarg[0] + x, coordTarg[1] + y)
					solid = False
					if y >= 2:
						solid = True
					layer = 2
					if y >= 3:
						layer = 0
					room.decorObjects += [Traps.Shrine(cPos, room.floor, 0 + x, 0 + y, layer, solid)]
			for x in range(1, (boxSize[0] + 1)):
				for y in range(1, (boxSize[1] + 1)):
					cPos = (square[0] * (boxSize[0] + 1) + x, square[1] * (boxSize[1] + 1) + y)
					if TPtr.getAtCoord(cPos) not in [1]:
						TPtr.setTile(cPos, ["0", 3, 0])
			for x in range(2, (boxSize[0])):
				for y in range(2, (boxSize[1])):
					cPos = (square[0] * (boxSize[0] + 1) + x, square[1] * (boxSize[1] + 1) + y)
					if TPtr.getAtCoord(cPos) not in [1]:
						TPtr.setTile(cPos, ["0", 5, 0])
		elif godInfo["god"] == "Water":
			coordTarg = [coordTarg[0], coordTarg[1] - 1]
			for x in range(1):
				for y in range(2):
					cPos = (coordTarg[0] + x, coordTarg[1] + y)
					solid = False
					if y >= 1:
						solid = True
					layer = 2
					if y >= 1:
						layer = 0
					room.decorObjects += [Traps.Shrine(cPos, room.floor, 3 + x, 0 + y, layer, solid)]
			for x in range(-2, 3):
				for y in range(-2, 4):
					cPos = (coordTarg[0] + x, coordTarg[1] + y)
					if TPtr.getAtCoord(cPos) not in [1]:
						TPtr.setTile(cPos, ["1", 2, 0])
		elif godInfo["god"] == "Death":
			coordTarg = [coordTarg[0], coordTarg[1]]
			for p in [[-1, -1], [-2, -1], [-1, -2],   [1, -1], [1, -2], [2, -1],    [1, 1], [1, 2], [2, 1],    [-1, 1], [-1, 2], [-2, 1]]:
				cPos = (coordTarg[0] + p[0], coordTarg[1] + p[1])
				solid = True
				layer = 0
				room.decorObjects += [Traps.Shrine(cPos, room.floor, 0, 4, layer, solid)]
				TPtr.setTile(cPos, ["2", 0, 0])
Example #3
0
	def addOtherDecor(self, TPtr, room, boxSize):
		for square in room.spawnableTiles:
			numToSpawn = random.randint(1, 4)
			for off in [[-1, 0], [1, 0], [0, 1], [0, -1]]:
				if self.climateGrid.getTile([square[0] + off[0], square[1] + off[1]]) != self.climateGrid.getTile(square):
					numToSpawn = 0
			for i in range(numToSpawn):
				coord = square[0] * (boxSize[0] + 1) + random.randint(1, boxSize[0]), square[1] * (boxSize[1] + 1) + random.randint(1, boxSize[1])
				if TPtr.getAtCoord(coord) == 0:
					tileset = int(TPtr.getAtCoord(coord, 0))
					if tileset == 0:
						type = random.randint(0, 9)
						if type == 9:
							#coord = (square[0] * (boxSize[0] + 1) + random.randint(1, boxSize[0]), square[1] * (boxSize[1] + 1) + random.randint(1, boxSize[1] - 1))
							foundOne = False
							for t in room.decorObjects:
								if (t.source[0] == coord[0] and (t.source[1] != coord[1] or t.source[1] != coord[1] + 1)):
									foundOne = True
							if not foundOne:
								for x in range(1):
									for y in range(2):
										layer = 2
										solid = (y == 0)
										room.decorObjects += [Traps.Decoration((coord[0] + x, coord[1] - y), room.floor, 9, 1 - y, layer, solid)]
						else:
							room.decorObjects = room.decorObjects + [Traps.Decoration(coord, room.floor, type, 0, 0, False)]
					elif tileset == 1:
						type = random.randint(0, 4)
						room.decorObjects = room.decorObjects + [Traps.Decoration(coord, room.floor, type, 1, 0, False)]
					elif tileset == 2:
						type = random.randint(0, 7)
						if type in [6, 7]:
							#coord = (square[0] * (boxSize[0] + 1) + random.randint(1, boxSize[0]), square[1] * (boxSize[1] + 1) + random.randint(1, boxSize[1] - 1))
							foundOne = False
							for t in room.decorObjects:
								if (t.source[0] == coord[0] and (t.source[1] != coord[1] or t.source[1] != coord[1] + 1)):
									foundOne = True
							if not foundOne:
								for x in range(1):
									for y in range(2):
										layer = 2
										solid = (y == 0)
										room.decorObjects += [Traps.Decoration((coord[0] + x, coord[1] - y), room.floor, type, 3 - y, layer, solid)]
						else:
							room.decorObjects = room.decorObjects + [Traps.Decoration(coord, room.floor, type, 2, 0, False)]
Example #4
0
	def changeTrapType(self, pos, trapType, remove):
		coords = (int(pos[0]), int(pos[1]))
		newTrap = None
		if coords in self.traps and self.traps[coords].TrapId == trapType:
			del self.traps[coords]
		else:
			if coords in self.traps:
				del self.traps[coords]
			if not remove:
				newTrap = Traps.createTrap(coords, trapType, [])
		if newTrap:
			self.traps[coords] = newTrap
Example #5
0
	def addStairs(self, TPtr, room, boxSize):
		for square in room.spawnableTiles:
			if self.getMajorNodeType((square[0], square[1])) == "stairs":
				stairInfo = getMajorNode(self, square)
				self.traps += [Traps.createTrap(stairInfo["coord"], PTRS["TRAPTYPES"].STAIRS, self.floor, [stairInfo["direction"]])]
Example #6
0
	def addTrapAtCoords(self, coords, trapType, floor, args=[]):
		coords = (int(coords[0]), int(coords[1]))
		newTrap = Traps.createTrap(coords, floor, trapType, args)
		self.traps[coords] = newTrap
		return newTrap