diff --git a/src/interaction.py b/src/interaction.py index e76098c8..fe5974d2 100644 --- a/src/interaction.py +++ b/src/interaction.py @@ -3213,6 +3213,9 @@ def __init__(self, default=None, targetParamName="selection"): self.escape = False + def rerender(self): + pass + def callIndirect(self, callback, extraParams=None): """ call a callback that is stored in a savable format @@ -6245,6 +6248,12 @@ def __init__(self, text="",targetParamName="keyPressed"): self.keyPressed = "" self.done = False self.targetParamName = targetParamName + self.counter = 0 + self.rerenderFunction = None + + def rerender(self): + if self.rerenderFunction: + main.set_text((urwid.AttrSpec("default", "default"), self.rerenderFunction())) def handleKey(self, key, noRender=False, character = None): """ @@ -7490,6 +7499,9 @@ def renderGameDisplay(renderChar=None): else: thisTerrain = char.terrain + submenue = char.macroState.get("submenue") + if submenue: + submenue.rerender() global lastTerrain if thisTerrain: @@ -7497,6 +7509,7 @@ def renderGameDisplay(renderChar=None): else: thisTerrain = lastTerrain + #bug: this fucks up performance def stringifyUrwid(inData): outData = "" for item in inData: diff --git a/src/itemFolder/automation/motionSensor.py b/src/itemFolder/automation/motionSensor.py index 18e471b7..32c11914 100644 --- a/src/itemFolder/automation/motionSensor.py +++ b/src/itemFolder/automation/motionSensor.py @@ -52,7 +52,7 @@ def trigger(self, character=None): character.addMessage("no items to trigger") return - items[0].remoteActivate() + items[0].remoteActivate(extraParams={"pos":character.getPosition()}) def getConfigurationOptions(self, character): """ diff --git a/src/itemFolder/automation/triggerPlate.py b/src/itemFolder/automation/triggerPlate.py index 2eac0884..5ae6cea2 100644 --- a/src/itemFolder/automation/triggerPlate.py +++ b/src/itemFolder/automation/triggerPlate.py @@ -34,7 +34,6 @@ def toggleActive(self,character): def doStepOnAction(self, character): if self.active: - character.addMessage("you step on a trigger plate") self.trigger(character) def render(self): @@ -58,6 +57,8 @@ def trigger(self, character, checkFaction=True): if checkFaction and self.faction == character.faction: return + character.addMessage("you step on a trigger plate") + if not self.target: return @@ -69,9 +70,10 @@ def trigger(self, character, checkFaction=True): return try: - items[0].remoteActivate() + items[0].remoteActivate except: - pass + return + items[0].remoteActivate(extraParams={"pos":self.getPosition()}) def getConfigurationOptions(self, character): """ @@ -102,7 +104,7 @@ def configureTarget(self,params): def configureTargetPosition(self,params): key = params.get("keyPressed") if key: - if key in ("enter","esc","lESC","rESC"): + if key in ("j","k","enter","esc","lESC","rESC"): return if key == "w": self.target = (self.target[0],self.target[1]-1,0) diff --git a/src/itemFolder/military/boltTower.py b/src/itemFolder/military/boltTower.py index d218cf7a..6bfd6690 100644 --- a/src/itemFolder/military/boltTower.py +++ b/src/itemFolder/military/boltTower.py @@ -18,18 +18,83 @@ def __init__(self): self.charges = 7 self.faction = None - def apply(self, character=None): + def apply(self, character): + self.showTargetingHud({"character":character}) + + def showTargetingHud(self,params): + character = params["character"] + + extraText = "\n" + key = params.get("keyPressed") + if key: + if key in ("enter","esc","lESC","rESC"): + return + if key == "w": + character.timeTaken += 1 + self.shoot({"character":character,"direction":(0,-1,0)}) + extraText = "you shoot\n" + if key == "a": + character.timeTaken += 1 + self.shoot({"character":character,"direction":(-1,0,0)}) + extraText = "you shoot\n" + if key == "s": + character.timeTaken += 1 + self.shoot({"character":character,"direction":(0,1,0)}) + extraText = "you shoot\n" + if key == "d": + character.timeTaken += 1 + self.shoot({"character":character,"direction":(1,0,0)}) + extraText = "you shoot\n" + if key == ".": + character.timeTaken += 1 + + def rerender(): + roomRender = self.container.render(advanceAnimations=False) + + for line in roomRender: + line.append("\n") + + return [roomRender,extraText,"\npress wasd to shoot \npress . to wait"] + + submenue = src.interaction.OneKeystrokeMenu(rerender()) + submenue.rerenderFunction = rerender + character.macroState["submenue"] = submenue + character.macroState["submenue"].followUp = {"container":self,"method":"showTargetingHud","params":params} + + def shoot(self, extraParams=None): + character = None + if extraParams: + character = extraParams.get("character") + if self.charges < 1: if character: character.addMessage("no charges") return - direction = (0,1,0) - if character: + direction = None + if extraParams: + direction = extraParams.get("direction") + + if not direction and character: characterPos = character.getPosition() ownPos = self.getPosition() direction = (ownPos[0]-characterPos[0],ownPos[1]-characterPos[1],ownPos[2]-characterPos[2]) + if not direction and extraParams: + targetPos = extraParams.get("pos") + if targetPos: + ownPos = self.getPosition() + direction = (ownPos[0]-targetPos[0],ownPos[1]-targetPos[1],ownPos[2]-targetPos[2]) + if abs(direction[0]) > 0 and direction[1] == 0: + direction = (-int(direction[0]/abs(direction[0])),0,0) + elif abs(direction[1]) > 0 and direction[0] == 0: + direction = (0,-int(direction[1]/abs(direction[1])),0) + else: + return + + if not direction: + 1/0 + currentPos = self.getPosition() while True: targets = self.container.getCharactersOnPosition(currentPos) @@ -41,7 +106,6 @@ def apply(self, character=None): break self.container.addAnimation(currentPos,"showchar",1,{"char":[(src.interaction.urwid.AttrSpec("#fff", "black"), "##")]}) - print(currentPos) currentPos = (currentPos[0]+direction[0],currentPos[1]+direction[1],currentPos[2]+direction[2]) @@ -54,29 +118,9 @@ def apply(self, character=None): if currentPos[0] <= 0: break return - 1/0 - - foundChars = [] - for checkChar in self.container.characters: - if checkChar.faction == self.faction: - continue - - foundChars.append(checkChar) - - self.container.addAnimation(self.getPosition(),"showchar",1,{"char":[(src.interaction.urwid.AttrSpec("#aaf", "black"), "%%")]}) - self.charges -= 1 - - if not foundChars: - if character: - character.addMessage("no valid targets found") - return - - while self.charges and foundChars: - target = foundChars.pop() - self.shock(target,character=character) - def remoteActivate(self): - self.apply() + def remoteActivate(self,extraParams=None): + self.shoot(extraParams=extraParams) def configure(self, character): """ diff --git a/src/itemFolder/military/poissonTower.py b/src/itemFolder/military/poissonTower.py index 5e8f3a5e..f10b89ec 100644 --- a/src/itemFolder/military/poissonTower.py +++ b/src/itemFolder/military/poissonTower.py @@ -31,7 +31,7 @@ def apply(self, character=None): target.hurt(70,reason="poission") self.destroy() - def remoteActivate(self): + def remoteActivate(self,extraParams=None): self.apply() def render(self): diff --git a/src/itemFolder/military/rodTower.py b/src/itemFolder/military/rodTower.py index 50c468e5..f984c222 100644 --- a/src/itemFolder/military/rodTower.py +++ b/src/itemFolder/military/rodTower.py @@ -41,7 +41,7 @@ def apply(self, character=None): for target in targets: target.hurt(20,reason="hit by rod") - def remoteActivate(self): + def remoteActivate(self,extraParams=None): self.apply() def render(self): diff --git a/src/itemFolder/military/shockTower.py b/src/itemFolder/military/shockTower.py index b083245e..f4329a37 100644 --- a/src/itemFolder/military/shockTower.py +++ b/src/itemFolder/military/shockTower.py @@ -16,48 +16,77 @@ def __init__(self): super().__init__(display="/\\") self.charges = 7 - self.faction = None - def apply(self, character=None): + def apply(self,character): + self.showTargetingHud({"character":character}) + + def showTargetingHud(self,params): + pos = params.get("pos") + if not pos: + pos = self.getPosition() + character = params["character"] + + cursorSymbol = "XX" + extraText = "\n" + key = params.get("keyPressed") + if key: + if key in ("enter","esc","lESC","rESC"): + return + if key == "w": + pos = (pos[0],pos[1]-1,0) + if key == "a": + pos = (pos[0]-1,pos[1],0) + if key == "s": + pos = (pos[0],pos[1]+1,0) + if key == "d": + pos = (pos[0]+1,pos[1],0) + if key == ".": + character.timeTaken += 1 + if key == "j": + character.timeTaken += 1 + extraText = "You trigger the shock tower\n" + self.shock(pos,character) + params["pos"] = pos + + def rerender(): + roomRender = self.container.render(advanceAnimations=False) + if not self.container.animations: + roomRender[pos[1]][pos[0]] = cursorSymbol + + for line in roomRender: + line.append("\n") + + return [roomRender,extraText,"\npress wasd to move cursor\npress j to shock coordinate\npress . to wait"] + + submenue = src.interaction.OneKeystrokeMenu(rerender()) + submenue.rerenderFunction = rerender + character.macroState["submenue"] = submenue + character.macroState["submenue"].followUp = {"container":self,"method":"showTargetingHud","params":params} + + def remoteActivate(self,extraParams=None): + if extraParams and extraParams.get("pos"): + pos = extraParams.get("pos") + self.shock(pos) + + def shock(self,targetPos,character=None): if self.charges < 1: if character: character.addMessage("no charges") return - foundChars = [] - for checkChar in self.container.characters: - if checkChar.faction == self.faction: - continue - - foundChars.append(checkChar) - - self.container.addAnimation(self.getPosition(),"showchar",1,{"char":[(src.interaction.urwid.AttrSpec("#aaf", "black"), "%%")]}) + character.addMessage(f"you shock the coordinate {targetPos}") self.charges -= 1 - - if not foundChars: - if character: - character.addMessage("no valid targets found") - return - - while self.charges and foundChars: - target = foundChars.pop() - self.shock(target,character=character) - - def remoteActivate(self): - self.apply() - - def shock(self,target,character=None): - if self.charges < 1: - return - damage = 50 - self.charges -= 1 - target.hurt(damage,reason="shocked") - self.container.addAnimation(target.getPosition(),"showchar",1,{"char":[(src.interaction.urwid.AttrSpec("#aaf", "black"), "%%")]}) - self.container.addAnimation(target.getPosition(),"smoke",damage,{}) + self.container.addAnimation(targetPos,"showchar",1,{"char":[(src.interaction.urwid.AttrSpec("#aaf", "black"), "%%")]}) - if character: - character.addMessage("the shock tower shocks an enemy") + targets = self.container.getCharactersOnPosition(targetPos) + if targets: + for target in targets: + target.hurt(damage,reason="shocked") + self.container.addAnimation(target.getPosition(),"smoke",10,{}) + + if character: + character.addMessage("an enemy is getting shocked") def configure(self, character): """ @@ -66,11 +95,6 @@ def configure(self, character): character: the character trying to use the item """ - if not self.faction == character.faction: - self.faction = character.faction - character.addMessage("you set the faction for the ShockTower") - return - compressorFound = None for item in character.inventory: if isinstance(item,src.items.itemMap["LightningRod"]): diff --git a/src/rooms.py b/src/rooms.py index ffcdc4f9..9e4b8f5c 100644 --- a/src/rooms.py +++ b/src/rooms.py @@ -874,7 +874,7 @@ def getItemByType(self,itemType,needsBolted=False): return item return None - def render(self): + def render(self,advanceAnimations=True): """ render the room @@ -1233,7 +1233,8 @@ def render(self): usedAnimationSlots.add(pos) if pos[0] == None: - self.animations.remove(animation) + if advanceAnimations: + self.animations.remove(animation) continue if animationType == "attack": @@ -1253,7 +1254,8 @@ def render(self): if duration > 10: animation[2] -= 10 else: - self.animations.remove(animation) + if advanceAnimations: + self.animations.remove(animation) elif animationType in ("hurt","shielded",): display = "++" if animationType == "hurt": @@ -1270,9 +1272,11 @@ def render(self): xDistance = random.randint(-distance,distance) offset = (xDistance,random.choice([distance-abs(xDistance),-(distance-abs(xDistance))])) newPos = (animation[0][0]+offset[0],animation[0][1]+offset[1],animation[0][2]) - self.addAnimation(newPos,"splatter",int(10*(duration/extraInfo["maxHealth"]))+1,{"mainChar":extraInfo["mainChar"]}) + if advanceAnimations: + self.addAnimation(newPos,"splatter",int(10*(duration/extraInfo["maxHealth"]))+1,{"mainChar":extraInfo["mainChar"]}) else: - self.animations.remove(animation) + if advanceAnimations: + self.animations.remove(animation) elif animationType in ("splatter",): if "display" not in extraInfo: letters = ["*","+",".",",","'","~"] @@ -1291,7 +1295,8 @@ def render(self): animation[2] -= 1 if duration < 1: - self.animations.remove(animation) + if advanceAnimations: + self.animations.remove(animation) elif animationType in ("scrapChange",): letters = ["*","+","#",";","%"] character = random.choice(letters)+random.choice(letters) @@ -1304,7 +1309,8 @@ def render(self): animation[2] -= 1 if duration < 1: - self.animations.remove(animation) + if advanceAnimations: + self.animations.remove(animation) elif animationType in ("explosion",): display = "##" display = (src.interaction.urwid.AttrSpec(["#fa0","#f00"][duration%2],["#f00","#fa0"][duration%2],),display) @@ -1314,7 +1320,8 @@ def render(self): animation[2] -= 1 if duration < 1: - self.animations.remove(animation) + if advanceAnimations: + self.animations.remove(animation) elif animationType in ("showchar",): display = extraInfo["char"] @@ -1327,7 +1334,8 @@ def render(self): animation[2] -= 1 if duration < 1: - self.animations.remove(animation) + if advanceAnimations: + self.animations.remove(animation) elif animationType in ("charsequence",): display = extraInfo["chars"][len(extraInfo["chars"])-1-duration] @@ -1336,7 +1344,8 @@ def render(self): animation[2] -= 1 if duration < 1: - self.animations.remove(animation) + if advanceAnimations: + self.animations.remove(animation) elif animationType in ("smoke",): display = (src.interaction.urwid.AttrSpec("#555", "black"), "##") @@ -1351,9 +1360,10 @@ def render(self): animation[2] -= 1 - self.animations.remove(animation) - if duration > 0: - self.addAnimation((animation[0][0]+direction[0],animation[0][1]+direction[1],animation[0][2]+direction[2],),animation[1],animation[2],extraInfo) + if advanceAnimations: + self.animations.remove(animation) + if duration > 0: + self.addAnimation((animation[0][0]+direction[0],animation[0][1]+direction[1],animation[0][2]+direction[2],),animation[1],animation[2],extraInfo) else: display = "??" chars[pos[1]][pos[0]] = display