Example #1
0
 def enterMakeBlankHouse(self):
     self.house = DistributedHouseAI(self.mgr.air)
     self.house.setHousePos(self.houseIndex)
     self.house.setColor(self.houseIndex)
     self.house.generateWithRequired(self.estate.zoneId)
     self.estate.houses[self.houseIndex] = self.house
     self.demand('Off')
 def enterMakeBlankHouse(self):
     self.house = DistributedHouseAI(self.mgr.air)
     self.house.setHousePos(self.houseIndex)
     self.house.setColor(self.houseIndex)
     self.house.generateWithRequired(self.estate.zoneId)
     self.estate.houses[self.houseIndex] = self.house
     self.demand("Off")
Example #3
0
class LoadHouseFSM(FSM):
    notify = DirectNotifyGlobal.directNotify.newCategory('LoadHouseFSM')

    def __init__(self, mgr, estate, houseIndex, toon, callback):
        FSM.__init__(self, 'LoadHouseFSM')
        self.mgr = mgr
        self.estate = estate
        self.houseIndex = houseIndex
        self.toon = toon
        self.callback = callback

        self.done = False

    def start(self):
        # We have a few different cases here:
        if self.toon is None:
            # Case #1: There isn't a Toon in that estate slot. Make a blank house.

            # Because this state completes so fast, we'll use taskMgr to delay
            # it until the next iteration. This solves re-entrancy problems.
            taskMgr.doMethodLater(0.0, self.demand,
                                  'makeBlankHouse-%s' % id(self),
                                  extraArgs=['MakeBlankHouse'])
            return

        self.houseId = self.toon.get('setHouseId', [0])[0]
        if self.houseId  == 0:
            # Case #2: There is a Toon, but no setHouseId. Gotta make one.
            self.demand('CreateHouse')
        else:
            # Case #3: Toon with a setHouseId. Load it.
            self.demand('LoadHouse')

    def enterMakeBlankHouse(self):
        self.house = DistributedHouseAI(self.mgr.air)
        self.house.setHousePos(self.houseIndex)
        self.house.setColor(self.houseIndex)
        self.house.generateWithRequired(self.estate.zoneId)
        self.estate.houses[self.houseIndex] = self.house
        self.demand('Off')

    def enterCreateHouse(self):
        style = ToonDNA.ToonDNA()
        style.makeFromNetString(self.toon['setDNAString'][0])
        
        self.mgr.air.dbInterface.createObject(
            self.mgr.air.dbId,
            self.mgr.air.dclassesByName['DistributedHouseAI'],
            {
                'setName' : [self.toon['setName'][0]],
                'setAvatarId' : [self.toon['ID']],
                'setGender': [0 if style.getGender() == 'm' else 1]
            },
            self.__handleCreate)

    def __handleCreate(self, doId):
        if self.state != 'CreateHouse':
            return

        # Update the avatar's houseId:
        av = self.mgr.air.doId2do.get(self.toon['ID'])
        if av:
            av.b_setHouseId(doId)
        else:
            self.mgr.air.dbInterface.updateObject(
                self.mgr.air.dbId,
                self.toon['ID'],
                self.mgr.air.dclassesByName['DistributedToonAI'],
                {'setHouseId': [doId]})

        self.houseId = doId
        self.demand('LoadHouse')

    def enterLoadHouse(self):
        # Activate the house:
        self.mgr.air.sendActivate(self.houseId, self.mgr.air.districtId, self.estate.zoneId,
                                  self.mgr.air.dclassesByName['DistributedHouseAI'],
                                  {'setHousePos': [self.houseIndex],
                                   'setColor': [self.houseIndex],
                                   'setName': [self.toon['setName'][0]],
                                   'setAvatarId': [self.toon['ID']]})

        # Now we wait for the house to show up... We do this by hanging a messenger
        # hook which the DistributedHouseAI throws once it spawns.
        self.acceptOnce('generate-%d' % self.houseId, self.__gotHouse)

    def __gotHouse(self, house):
        self.house = house
        house.initializeInterior()

        self.estate.houses[self.houseIndex] = self.house

        self.demand('Off')

    def exitLoadHouse(self):
        self.ignore('generate-%d' % self.houseId)

    def enterOff(self):
        self.done = True
        self.callback(self.house)
class LoadHouseFSM(FSM):
    notify = DirectNotifyGlobal.directNotify.newCategory("LoadHouseFSM")

    def __init__(self, mgr, estate, houseIndex, toon, callback):
        FSM.__init__(self, "LoadHouseFSM")
        self.mgr = mgr
        self.estate = estate
        self.houseIndex = houseIndex
        self.toon = toon
        self.callback = callback

        self.done = False

    def start(self):
        # We have a few different cases here:
        if self.toon is None:
            # Case #1: There isn't a Toon in that estate slot. Make a blank house.

            # Because this state completes so fast, we'll use taskMgr to delay
            # it until the next iteration. This solves re-entrancy problems.
            taskMgr.doMethodLater(0.0, self.demand, "makeBlankHouse-%s" % id(self), extraArgs=["MakeBlankHouse"])
            return

        self.houseId = self.toon.get("setHouseId", [0])[0]
        if self.houseId == 0:
            # Case #2: There is a Toon, but no setHouseId. Gotta make one.
            self.demand("CreateHouse")
        else:
            # Case #3: Toon with a setHouseId. Load it.
            self.demand("LoadHouse")

    def enterMakeBlankHouse(self):
        self.house = DistributedHouseAI(self.mgr.air)
        self.house.setHousePos(self.houseIndex)
        self.house.setColor(self.houseIndex)
        self.house.generateWithRequired(self.estate.zoneId)
        self.estate.houses[self.houseIndex] = self.house
        self.demand("Off")

    def enterCreateHouse(self):
        style = ToonDNA.ToonDNA()
        style.makeFromNetString(self.toon["setDNAString"][0])

        self.mgr.air.dbInterface.createObject(
            self.mgr.air.dbId,
            self.mgr.air.dclassesByName["DistributedHouseAI"],
            {
                "setName": [self.toon["setName"][0]],
                "setAvatarId": [self.toon["ID"]],
                "setGender": [0 if style.getGender() == "m" else 1],
            },
            self.__handleCreate,
        )

    def __handleCreate(self, doId):
        if self.state != "CreateHouse":
            return

        # Update the avatar's houseId:
        av = self.mgr.air.doId2do.get(self.toon["ID"])
        if av:
            av.b_setHouseId(doId)
        else:
            self.mgr.air.dbInterface.updateObject(
                self.mgr.air.dbId,
                self.toon["ID"],
                self.mgr.air.dclassesByName["DistributedToonAI"],
                {"setHouseId": [doId]},
            )

        self.houseId = doId
        self.demand("LoadHouse")

    def enterLoadHouse(self):
        # Activate the house:
        self.mgr.air.sendActivate(
            self.houseId,
            self.mgr.air.districtId,
            self.estate.zoneId,
            self.mgr.air.dclassesByName["DistributedHouseAI"],
            {
                "setHousePos": [self.houseIndex],
                "setColor": [self.houseIndex],
                "setName": [self.toon["setName"][0]],
                "setAvatarId": [self.toon["ID"]],
            },
        )

        # Now we wait for the house to show up... We do this by hanging a messenger
        # hook which the DistributedHouseAI throws once it spawns.
        self.acceptOnce("generate-%d" % self.houseId, self.__gotHouse)

    def __gotHouse(self, house):
        self.house = house
        house.initializeInterior()

        self.estate.houses[self.houseIndex] = self.house

        self.demand("Off")

    def exitLoadHouse(self):
        self.ignore("generate-%d" % self.houseId)

    def enterOff(self):
        self.done = True
        self.callback(self.house)