109 lines
3.5 KiB
Python
109 lines
3.5 KiB
Python
import logging
|
|
import inspect
|
|
|
|
class ActionBasics:
|
|
|
|
def __init__(self,world):
|
|
self.world = world
|
|
|
|
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 wechsleRaum(self,raum):
|
|
logging.debug(f'wechsle in RaumId: {raum.id}')
|
|
if raum.id == self.world.RAUM_BOOT2:
|
|
logging.debug('wechsle nach Raum Boot2')
|
|
kabine = self.world.findItemById(self.world.ITEM_KABINE)
|
|
raumkabine = self.world.findRaumById(self.world.RAUM_KABINE)
|
|
boot2 = self.world.findRaumById(self.world.RAUM_BOOT2)
|
|
|
|
raumkabine.ausgaenge[self.world.RAUF] = boot2.id
|
|
self.moveItemVonRaumNachRaum(kabine,boot2)
|
|
|
|
self.world.weg.append(raum.name)
|
|
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
|
|
|
|
|
|
|