Skip to content

Commit

Permalink
many tweaks for the towers
Browse files Browse the repository at this point in the history
  • Loading branch information
Marx Mustermann committed Jun 13, 2024
1 parent ebcb398 commit 4b0b4ac
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 84 deletions.
13 changes: 13 additions & 0 deletions src/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -7490,13 +7499,17 @@ def renderGameDisplay(renderChar=None):
else:
thisTerrain = char.terrain

submenue = char.macroState.get("submenue")
if submenue:
submenue.rerender()

global lastTerrain
if thisTerrain:
lastTerrain = thisTerrain
else:
thisTerrain = lastTerrain

#bug: this fucks up performance
def stringifyUrwid(inData):
outData = ""
for item in inData:
Expand Down
2 changes: 1 addition & 1 deletion src/itemFolder/automation/motionSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
10 changes: 6 additions & 4 deletions src/itemFolder/automation/triggerPlate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand All @@ -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):
"""
Expand Down Expand Up @@ -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)
Expand Down
96 changes: 70 additions & 26 deletions src/itemFolder/military/boltTower.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])

Expand All @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/itemFolder/military/poissonTower.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/itemFolder/military/rodTower.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
100 changes: 62 additions & 38 deletions src/itemFolder/military/shockTower.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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"]):
Expand Down
Loading

0 comments on commit 4b0b4ac

Please sign in to comment.