129 lines
4.5 KiB
Python
129 lines
4.5 KiB
Python
import logging
|
|
import inspect
|
|
|
|
class ActionBasics:
|
|
|
|
def __init__(self,world):
|
|
self.world = world
|
|
self.alleBootRaeume = [world.RAUM_BOOT, world.RAUM_BOOT2, world.RAUM_BOOT3]
|
|
|
|
def debug(self, method, text):
|
|
logging.debug(f'ActionBasics: {text}')
|
|
|
|
def ausDemInventar(self,item):
|
|
del self.world.inventar[item.id]
|
|
self.world.aktuellerRaum.items[item.id] = item
|
|
item.raumid = self.world.aktuellerRaum.id
|
|
|
|
def insInventar(self, item):
|
|
logging.debug(f'neu ins Inventar: {item.name}')
|
|
self.world.inventar[item.id] = item
|
|
|
|
def setFehler(self,text):
|
|
self.world.fehler =text
|
|
|
|
def clearFehler(self):
|
|
self.world.fehler = ''
|
|
|
|
def wechsleBoot(self,raum):
|
|
kabine = self.world.findItemById(self.world.ITEM_KABINE)
|
|
raumkabine = self.world.findRaumById(self.world.RAUM_KABINE)
|
|
beiboot = self.world.findItemById(self.world.ITEM_BEIBOOT)
|
|
|
|
if raum.id in self.alleBootRaeume:
|
|
raumkabine.ausgaenge[self.world.RAUF] = raum.id
|
|
self.moveItemVonRaumNachRaum(kabine,raum)
|
|
self.moveItemVonRaumNachRaum(beiboot,raum)
|
|
|
|
def wechsleRaum(self,raum):
|
|
logging.debug(f'wechsle in RaumId: {raum.id}')
|
|
if raum.id in self.alleBootRaeume:
|
|
logging.debug('wechsle nach anderen Bootraum')
|
|
self.wechsleBoot(raum)
|
|
elif raum.id == self.world.RAUM_BEIBOOT:
|
|
beiboot = self.world.findRaumById(self.world.RAUM_BEIBOOT)
|
|
logging.debug(f'Pfad: {self.world.weg}')
|
|
bootraum = self.world.findRaumById(self.world.weg[-1])
|
|
logging.debug(f'wechsle ins Beiboot bootraum.id= {bootraum.id}')
|
|
if(bootraum.id in self.alleBootRaeume):
|
|
beiboot.ausgaenge[self.world.RAUF] = bootraum.id
|
|
else:
|
|
beiboot.ausgaenge[self.world.RAUF] = '-1'
|
|
logging.debug(f'Ausgang RAUF im Beiboot ist {beiboot.ausgaenge[self.world.RAUF]}')
|
|
beiboot.ausgaenge[self.world.OST] = '-1'
|
|
if self.world.weg[-1] == self.world.RAUM_BOOT2:
|
|
beiboot.ausgaenge[self.world.OST] = self.world.RAUM_INSEL
|
|
|
|
|
|
self.world.weg.append(raum.id)
|
|
self.world.aktuellerRaum = raum
|
|
raum.entdeckt = True
|
|
|
|
def liegtItemInRaum(self,itemid, raum):
|
|
return itemid in raum.items
|
|
|
|
def macheItemSichtbar(self, item):
|
|
logging.debug(f'mache sichtbar {item.name} in Raum {item.raumid}')
|
|
item.sichtbar = True
|
|
|
|
def moveItemVonRaumNachInventar(self,item):
|
|
logging.debug(f'entferne aus aktuellen Raum {item.name}')
|
|
if item.id in self.world.aktuellerRaum.items:
|
|
del self.world.aktuellerRaum.items[item.id]
|
|
logging.debug(f'ins Inventar {item.name}')
|
|
self.insInventar(item)
|
|
|
|
def moveItemVonRaumNachRaum(self,item, raum):
|
|
if item.id in self.world.aktuellerRaum.items:
|
|
logging.debug(f'entferne {item.name} aus Raum {self.world.aktuellerRaum.id}')
|
|
del self.world.aktuellerRaum.items[item.id]
|
|
logging.debug(f'bewege {item.name} nach {raum.id}')
|
|
item.raumid = raum.id
|
|
raum.items[item.id] = item
|
|
|
|
|
|
def moveItemVonInventarNachRaum(self,item, nachRaumId):
|
|
del self.world.inventar[item.id]
|
|
logging.debug(f' Item {item.name} nach RaumId {nachRaumId}')
|
|
raum = self.world.findRaumById(nachRaumId)
|
|
logging.debug(f' Item {item.name} liegt jetzt in Raum {raum.name}')
|
|
logging.debug(f'{item.name} liegt im {raum.name}: {self.liegtItemInRaum(item.id, raum)}')
|
|
logging.debug(f'{item.name} liegt im {self.world.aktuellerRaum.name}: {self.liegtItemInRaum(item.id, self.world.aktuellerRaum)}')
|
|
raum.items[item.id] = item
|
|
item.raumid = nachRaumId
|
|
|
|
def isItemAndAktRaum(self,item, itemid, raumid):
|
|
isItem = self.isItem(item,itemid)
|
|
isRaum = self.isAktuellerRaum(raumid)
|
|
|
|
logging.debug(f'isItem={isItem}, isRaum={isRaum}')
|
|
return isItem and isRaum
|
|
|
|
def isItem(self, item, itemid):
|
|
return item.id == itemid
|
|
|
|
def macheWegFrei(self, richtung, raumid):
|
|
logging.debug(f'Richtung {richtung} führt jetzt zu RaumId {raumid}')
|
|
self.world.aktuellerRaum.ausgaenge[richtung] = raumid
|
|
|
|
def findItemInAktuellerRaumById(self, itemid):
|
|
for itemid in self.world.aktuellerRaum.items:
|
|
raum = self.world.aktuellerRaum
|
|
|
|
item = self.world.aktuellerRaum.items[itemid]
|
|
logging.debug(f'{itemid} -{item.id}')
|
|
if item.id == itemid:
|
|
return item
|
|
return None
|
|
|
|
def personVonRaumNachRaum(self, person, vonRaumId, nachRaumId):
|
|
vonRaum = self.world.findRaumById(vonRaumId)
|
|
nachRaum = self.world.findRaumById(nachRaumId)
|
|
|
|
del vonRaum.personen[person.id]
|
|
nachRaum.personen[person.id] = person
|
|
person.raumid = nachRaumId
|
|
|
|
|
|
|