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)])]
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
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"]])]
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