def addGift(self, doId, newGift, replyToChannelId): # print("addGift") """ Appends an existing gift list with the parameter newGift doId is the DO that you want to append newGift onto newGift the gift blob you want to add """ # this is where the message gets sent back to, in this case it is the calling AI # replyToChannel = self.air.getSenderReturnChannel() # check to see if the gift is in our cache dictionary giftBlob = self.avatarIdToGifts.getData(doId) giftItem = CatalogItemList.CatalogItemList(newGift, store = CatalogItem.Customization | CatalogItem.DeliveryDate) self.air.writeServerEvent("Adding Server Gift", doId, "receiver %s gift %s" % (doId, giftItem[0].getName())) if giftBlob == None: # if not in our cache myAddGift=AddGift(self, replyToChannelId, doId, newGift) else: # else it's in our cache giftList = CatalogItemList.CatalogItemList(giftBlob, store = CatalogItem.Customization | CatalogItem.DeliveryDate) giftItem = CatalogItemList.CatalogItemList(newGift, store = CatalogItem.Customization | CatalogItem.DeliveryDate) if giftItem[0].giftCode != ToontownGlobals.GIFT_RAT: giftList.append(giftItem[0]) giftBlob = giftList.getBlob(CatalogItem.Customization | CatalogItem.DeliveryDate) else: giftBlob = AccumRATBeans(giftItem[0], giftBlob) self.writeGift(doId, giftBlob, replyToChannelId)
def finish(self): #print "AddGiftRequestFR FINISH" """ gift = self.distObj.avatarIdToGifts.get(self.avatarId) if gift == None: gift=self.neededObjects.get("setGiftSchedule")[0] gift.append(self.newGift) self.distObj.writeGift(self.avatarId, gift, self.replyToChannelId) AsyncRequest.finish(self) """ giftBlob = self.distObj.avatarIdToGifts.getData(self.avatarId) if giftBlob == None: giftBlob = self.neededObjects.get("setGiftSchedule")[0] giftItem = CatalogItemList.CatalogItemList( self.newGift, store=CatalogItem.Customization | CatalogItem.DeliveryDate) giftList = CatalogItemList.CatalogItemList( giftBlob, store=CatalogItem.Customization | CatalogItem.DeliveryDate) giftList.append(giftItem[0]) giftBlob = giftList.getBlob(CatalogItem.Customization | CatalogItem.DeliveryDate) self.distObj.writeGiftFR(self.avatarId, giftBlob, self.replyToChannelId, self.senderId, self.context, self.retcode) AsyncRequest.finish(self)
def nukeAllAwards(self, toon): """Try to remove all awards.""" if len(toon.onAwardOrder) == 0 and len(toon.awardMailboxContents) == 0: result = (False, "no awards to remove") else: import pdb pdb.set_trace() numInMailbox = len(toon.awardMailboxContents) numInQueue = len(toon.onAwardOrder) toon.awardMailboxContents = CatalogItemList.CatalogItemList( store=CatalogItem.Customization) toon.onAwardOrder = CatalogItemList.CatalogItemList( store=CatalogItem.Customization | CatalogItem.DeliveryDate) newBlob = toon.onAwardOrder.getBlob(store=CatalogItem.Customization | CatalogItem.DeliveryDate) self.air.sendUpdateToDoId("DistributedToon", "setAwardSchedule", toon.doId, [newBlob]) newAwardBlob = toon.awardMailboxContents.getBlob( store=CatalogItem.Customization) self.air.sendUpdateToDoId("DistributedToon", "setAwardMailboxContents", toon.doId, [newAwardBlob]) result = (True, "awards nuked, in mailbox=%d, in queue=%d" % (numInMailbox, numInQueue)) return result
def finish(self): #print "AddGiftRequestFR FINISH" """ gift = self.distObj.avatarIdToGifts.get(self.avatarId) if gift == None: gift=self.neededObjects.get("setGiftSchedule")[0] gift.append(self.newGift) self.distObj.writeGift(self.avatarId, gift, self.replyToChannelId) AsyncRequest.finish(self) """ giftBlob = self.distObj.avatarIdToGifts.getData(self.avatarId) if giftBlob == None: giftBlob = self.neededObjects.get("setGiftSchedule")[0] giftItem = CatalogItemList.CatalogItemList( self.newGift, store=CatalogItem.Customization | CatalogItem.DeliveryDate) giftList = CatalogItemList.CatalogItemList( giftBlob, store=CatalogItem.Customization | CatalogItem.DeliveryDate) if giftItem[0].giftCode != ToontownGlobals.GIFT_RAT: #print("Gift Item not RAT") giftList.append(giftItem[0]) giftBlob = giftList.getBlob(CatalogItem.Customization | CatalogItem.DeliveryDate) else: #print("Gift Item is RAT") giftBlob = AccumRATBeans(giftItem[0], giftBlob) self.distObj.writeGift(self.avatarId, giftBlob, self.replyToChannelId) giftList.append(giftItem[0]) giftBlob = giftList.getBlob(CatalogItem.Customization | CatalogItem.DeliveryDate) self.distObj.writeGift(self.avatarId, giftBlob, self.replyToChannelId) AsyncRequest.finish(self)
def processAvatar(self, av, db): self.printSometimes(av) #print "Processing Avatar: %d, %s" % (av.doId, av.name) convertWallpaperItems(av.monthlyCatalog, fCatalog = 1) convertWallpaperItems(av.weeklyCatalog, fCatalog = 1) convertWallpaperItems(av.backCatalog, fCatalog = 1) convertWallpaperItems(av.onOrder) convertWallpaperItems(av.mailboxContents) # Remove Duplicates for backCatalog list oldBackCatalog = av.backCatalog av.backCatalog = CatalogItemList.CatalogItemList() for item in oldBackCatalog: if item not in av.backCatalog: av.backCatalog.append(item) # Make sure stuff in current weekly catalog hasn't already been offered oldWeeklyCatalog = av.weeklyCatalog av.weeklyCatalog = CatalogItemList.CatalogItemList() for item in oldWeeklyCatalog: if ((item not in av.backCatalog) and (item not in av.weeklyCatalog)): av.weeklyCatalog.append(item) db2 = DatabaseObject.DatabaseObject(self.air, av.doId) db2.storeObject(av, ['setCatalog', 'setMailboxContents', 'setDeliverySchedule']) return
def generateWeeklyCatalog(self, avatar, week, monthlyCatalog): weeklyCatalog = CatalogItemList.CatalogItemList() self.notify.debug('Generating catalog for %s for week %s.' % (avatar.doId, week)) if week >= 1 and week <= len(WeeklySchedule): saleItem = 0 schedule = WeeklySchedule[week - 1] if isinstance(schedule, Sale): schedule = schedule.args saleItem = 1 for item in schedule: weeklyCatalog += self.__selectItem(avatar, item, monthlyCatalog, saleItem=saleItem) if nextAvailableCloset not in schedule: weeklyCatalog += self.__selectItem(avatar, nextAvailableCloset, monthlyCatalog, saleItem=0) if nextAvailableBank not in schedule: weeklyCatalog += self.__selectItem(avatar, nextAvailableBank, monthlyCatalog, saleItem=0) weeklyCatalog += self.__selectItem(avatar, get50ItemTrunk, monthlyCatalog, saleItem=0) if time.time() < 1096617600.0: def hasPetTrick(catalog): for item in catalog: if isinstance(item, CatalogPetTrickItem): return 1 return 0 if not hasPetTrick(weeklyCatalog) and not hasPetTrick(avatar.weeklyCatalog) and not hasPetTrick(avatar.backCatalog): self.notify.debug('Artificially adding pet trick to catalog') weeklyCatalog += self.__selectItem(avatar, 5000, monthlyCatalog, saleItem=saleItem) self.notify.debug('Generated catalog: %s' % weeklyCatalog) return weeklyCatalog
def finish(self): #print("PurchaseGiftRequest FINISH") sAv = self.neededObjects[self.senderId] rAv = self.neededObjects[self.receiverId] self.item = CatalogItem.getItem(self.itemBlob, store = CatalogItem.Customization) retcode = None #put neat stuff here #----------------------------------------------------------------------------- retcode = self.checkGift(retcode) retcode = self.checkCatalog(retcode) #retcode = self.checkMoney(retcode) retcode = self.checkGender(retcode) retcode = self.checkPurchaseLimit(retcode) retcode = self.checkMailbox(retcode) if (retcode != None): self.distObj.sendUpdateToChannel(self.replyToChannelId, "receiveRejectPurchaseGift", [self.senderId, self.context, retcode, self.cost]) else: now = (int)(time.time() / 60 + 0.5) deliveryTime = self.item.getDeliveryTime() / self.distObj.timeScale if deliveryTime < 2: deliveryTime = 2 self.item.deliveryDate = int(now + deliveryTime) #self.item.giftTag = self.senderId itemList = CatalogItemList.CatalogItemList([self.item]) itemBlob = itemList.getBlob(store = CatalogItem.Customization | CatalogItem.DeliveryDate) retcode = ToontownGlobals.P_ItemOnOrder self.distObj.addGiftFR(self.receiverId, itemBlob, self.senderId, self.context, retcode, self.replyToChannelId) #----------------------------------------------------------------------------- AsyncRequest.finish(self)
def setInteriorItems(self, items): # This should only be called once, to fill the data from the # database. Subsequently, we should modify the list directly, # so we don't break the connection between items on the list # and manifested DistributedFurnitureItems. self.interiorItems = CatalogItemList.CatalogItemList( items, store=CatalogItem.Location | CatalogItem.Customization)
def setAwardMailboxContents(self, awardMailboxContents): self.notify.debug("Setting awardMailboxContents to %s." % (awardMailboxContents)) self.awardMailboxContents = CatalogItemList.CatalogItemList( awardMailboxContents, store=CatalogItem.Customization) self.notify.debug("awardMailboxContents is %s." % (self.awardMailboxContents))
def setWindows(self, items): self.windows = CatalogItemList.CatalogItemList( items, store=CatalogItem.Customization | CatalogItem.WindowPlacement) print['setWindows', self.windows] if self.interior: self.__setupWindows()
def AccumRATBeans(newGift, GiftListBlob): giftList = CatalogItemList.CatalogItemList(GiftListBlob, store=CatalogItem.Customization | CatalogItem.DeliveryDate) if newGift.giftCode == ToontownGlobals.GIFT_RAT: numBeans = newGift.beanAmount found = 0 for index in range(len(giftList)): if (giftList[index].giftCode == ToontownGlobals.GIFT_RAT and found == 0): found = 1 giftList[ index].beanAmount = numBeans + giftList[index].beanAmount #print giftList[index].beanAmount if found: #print("RAT already on list") giftList.markDirty() else: #print("RAT is not on the list") giftList.append(newGift) newBlobList = giftList.getBlob(CatalogItem.Customization | CatalogItem.DeliveryDate) return newBlobList
def deliverGifts(self, avId, time): """ a request to have a toon's gifts delivered to their mailbox this simply removes old gifts based on the time parameter """ #retreive the onGiftDelivery field #remove the old gifts from the onGiftDelivery field replyToChannelId = self.air.getSenderReturnChannel() giftListBlob = self.avatarIdToGifts.getData(avId) if giftListBlob == None: # if not in our cache myAddGiftRequest = DeliverGiftRequest(self, replyToChannelId, avId, time) else: giftList = CatalogItemList.CatalogItemList( giftListBlob, store=CatalogItem.Customization | CatalogItem.DeliveryDate) delivered, remaining = giftList.extractDeliveryItems(time) giftBlob = remaining.getBlob(CatalogItem.Customization | CatalogItem.DeliveryDate) self.writeGiftField(avId, giftBlob, replyToChannelId) self.sendUpdateToChannel(replyToChannelId, "receiveAcceptDeliverGifts", [avId, "deliverGifts activated"])
def finish(self): giftListBlob=self.neededObjects.get("setGiftSchedule")[0] giftList = CatalogItemList.CatalogItemList(giftListBlob, store = CatalogItem.Customization | CatalogItem.DeliveryDate) delivered, remaining = giftList.extractDeliveryItems(self.time) giftBlob = remaining.getBlob(CatalogItem.Customization | CatalogItem.DeliveryDate) self.distObj.writeGiftField(self.avatarId, giftBlob, self.replyToChannelId) AsyncRequest.finish(self)
def __gotHouse(self, db, retcode): assert (self.notify.debug( "__gotHouse(%s, %s): %s" % (list(db.values.keys()), retcode, self.doId))) if retcode != 0: self.notify.warning("House %s for avatar %s does not exist!" % (self.av.houseId, self.av.doId)) self.sendCatalog(0) return atticItems = [] atticWallpaper = [] atticWindows = [] interiorItems = [] dg = db.values.get('setAtticItems') if dg: di = PyDatagramIterator(dg) blob = di.getString() atticItems = CatalogItemList.CatalogItemList( blob, store=CatalogItem.Customization) dg = db.values.get('setAtticWallpaper') if dg: di = PyDatagramIterator(dg) blob = di.getString() atticWallpaper = CatalogItemList.CatalogItemList( blob, store=CatalogItem.Customization) dg = db.values.get('setAtticWindows') if dg: di = PyDatagramIterator(dg) blob = di.getString() atticWindows = CatalogItemList.CatalogItemList( blob, store=CatalogItem.Customization) dg = db.values.get('setInteriorItems') if dg: di = PyDatagramIterator(dg) blob = di.getString() interiorItems = CatalogItemList.CatalogItemList( blob, store=CatalogItem.Location | CatalogItem.Customization) # Finally we're ready to tell the user what he needs to know. numAtticItems = len(atticItems) + len(atticWallpaper) + len( atticWindows) numHouseItems = numAtticItems + len(interiorItems) self.sendCatalog(numHouseItems)
def __init__(self, air, doId, estateId, zoneId, posIndex): DistributedObjectAI.DistributedObjectAI.__init__(self, air) self.doId = doId self.estateId = estateId self.zoneId = zoneId # self.garden = None self.cannon = None self.housePosInd = posIndex # these members are stored in the db and initialized in the # initFromServerResponse function (called by the estateAI). # These are the default values until they are initialized by # the database. (It is more convenient here not to depend on # initial value settings in the dc file.) self.houseType = HouseGlobals.HOUSE_DEFAULT self.gardenPosInd = 0 self.ownerId = 0 self.name = "" self.colorIndex = posIndex self.atticItems = CatalogItemList.CatalogItemList() self.interiorItems = CatalogItemList.CatalogItemList() self.atticWallpaper = CatalogItemList.CatalogItemList() self.interiorWallpaper = CatalogItemList.CatalogItemList() self.atticWindows = CatalogItemList.CatalogItemList() self.interiorWindows = CatalogItemList.CatalogItemList() self.deletedItems = CatalogItemList.CatalogItemList() self.cannonEnabled = 0 # initialize the stuff that doesn't need a response from the database self.interior = None self.interiorManager = None self.mailbox = None
def giveRecruitAToonPayment(self, receiverId, amount = 1): # print("Adding Bean Item") replyToChannel = self.air.getSenderReturnChannel() testItem = CatalogBeanItem.CatalogBeanItem(amount) testItem.giftTag = 0 testItem.giftCode = ToontownGlobals.GIFT_RAT itemBlob = testItem.getBlob(store = CatalogItem.Customization) testBlob = CatalogItemList.CatalogItemList(itemBlob, store = CatalogItem.Customization) #import pdb; pdb.set_trace() myGiveItem = GiveItem(self, replyToChannel, receiverId, itemBlob)
def __gotOwnerAv(self, db, retcode): assert (self.notify.debug( "__gotOwnerAv(%s, %s): %s" % (list(db.values.keys()), retcode, self.doId))) if retcode != 0: self.notify.warning("Avatar %s for house %s does not exist!" % (self.ownerId, self.doId)) return # The avatar still exists, so check its properties. onOrder = None mailboxContents = None awardMailboxContents = None dg = db.values.get('setDeliverySchedule') if dg: di = PyDatagramIterator(dg) blob = di.getString() onOrder = CatalogItemList.CatalogItemList( blob, store=CatalogItem.Customization | CatalogItem.DeliveryDate) dg = db.values.get('setMailboxContents') if dg: di = PyDatagramIterator(dg) blob = di.getString() mailboxContents = CatalogItemList.CatalogItemList( blob, store=CatalogItem.Customization) dg = db.values.get('setMaxHp') if dg: di = PyDatagramIterator(dg) hp = di.getUint16() dg = db.values.get('setAwardMailboxContents') if dg: di = PyDatagramIterator(dg) blob = di.getString() awardMailboxContents = CatalogItemList.CatalogItemList( blob, store=CatalogItem.Customization) #self.b_setCannonEnabled(1) self.__checkMailbox(onOrder, mailboxContents, 0, awardMailboxContents)
def removeOldItem(self, flag): # Called when we are about to add a new bank or closet to the # attic, this searches for and removes the previous bank or # closet. It actually removes any items found whose # item.getFlags() member matches the bits in flag. self.notify.info("Removing old item matching %x from house %s" % (flag, self.doId)) newAtticItems = CatalogItemList.CatalogItemList( [], store=CatalogItem.Customization) for item in self.atticItems: if (item.getFlags() & flag) == 0: # This item doesn't match; preserve it. newAtticItems.append(item) else: self.notify.info("removing %s from attic" % (item)) newInteriorItems = CatalogItemList.CatalogItemList( [], store=CatalogItem.Location | CatalogItem.Customization) for item in self.interiorItems: if (item.getFlags() & flag) == 0: # This item doesn't match; preserve it. newInteriorItems.append(item) else: self.notify.info("removing %s from interior" % (item)) self.b_setAtticItems(newAtticItems) self.b_setInteriorItems(newInteriorItems) if self.interiorManager: self.interiorManager.d_setAtticItems(self.atticItems) # Also remove any corresponding dfitems from the interior. newDfitems = [] for dfitem in self.interiorManager.dfitems: if (dfitem.item.getFlags() & flag) == 0: # This item doesn't match; preserve it. newDfitems.append(dfitem) else: # This item does match, remove it. dfitem.requestDelete() self.interiorManager.dfitems = newDfitems
def generateMonthlyCatalog(self, avatar, weekStart): dayNumber = int(weekStart / 1440) itemLists = self.__getMonthlyItemLists(dayNumber, weekStart) monthlyCatalog = CatalogItemList.CatalogItemList() for list in itemLists: saleItem = 0 if isinstance(list, Sale): list = list.args saleItem = 1 for item in list: monthlyCatalog += self.__selectItem(avatar, item, [], saleItem=saleItem) return monthlyCatalog
def setDeletedItems(self, items): self.deletedItems = CatalogItemList.CatalogItemList( items, store=CatalogItem.Customization | CatalogItem.DeliveryDate) if self.air.doLiveUpdates: deleted = self.reconsiderDeletedItems() # If we removed any deleted items, immediately send the new # list back to the database. if deleted: self.d_setDeletedItems(self.deletedItems) if self.interiorManager: self.interiorManager.d_setDeletedItems(self.deletedItems)
def testWallpaperCombo(self, wallpaperType, wallpaperColorIndex, borderIndex, borderColorIndex, mouldingType, mouldingColorIndex, flooringType, flooringColorIndex, wainscotingType, wainscotingColorIndex): wallpaperItem = CatalogWallpaperItem.CatalogWallpaperItem(wallpaperType, wallpaperColorIndex, borderIndex, borderColorIndex) mouldingItem = CatalogMouldingItem.CatalogMouldingItem(mouldingType, mouldingColorIndex) flooringItem = CatalogFlooringItem.CatalogFlooringItem(flooringType, flooringColorIndex) wainscotingItem = CatalogWainscotingItem.CatalogWainscotingItem(wainscotingType, wainscotingColorIndex) self.wallpaper = CatalogItemList.CatalogItemList([wallpaperItem, mouldingItem, flooringItem, wainscotingItem, wallpaperItem, mouldingItem, flooringItem, wainscotingItem], store=CatalogItem.Customization) if self.interior: self.__colorWalls()
def __init__(self, air): DistributedObjectUD.__init__(self, air) self.dna = ToonDNA.ToonDNA() self.clothesTopsList = [] self.clothesBottomsList = [] self.emoteAccess = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] self.fishingRod = 0 if simbase.wantPets: self.petTrickPhrases = [] if simbase.wantBingo: self.bingoCheat = False self.customMessages = [] self.mailboxContents = CatalogItemList.CatalogItemList(store = CatalogItem.Customization)
def finish(self): #print("AddItem FINISH") rAv = self.neededObjects[self.receiverId] self.item = CatalogItem.getItem(self.itemBlob, store = CatalogItem.Customization) now = (int)(time.time() / 60 + 0.5) deliveryTime = self.item.getDeliveryTime() / self.distObj.timeScale #if deliveryTime < 2: # deliveryTime = 2 deliveryTime = 2 self.item.deliveryDate = int(now + deliveryTime) itemList = CatalogItemList.CatalogItemList([self.item]) itemBlob = itemList.getBlob(store = CatalogItem.Customization | CatalogItem.DeliveryDate) retcode = ToontownGlobals.P_ItemOnOrder self.distObj.addGift(self.receiverId, itemBlob, self.replyToChannelId) #----------------------------------------------------------------------------- AsyncRequest.finish(self)
def generateBackCatalog(self, avatar, week, previousWeek, weeklyCatalog): backCatalog = CatalogItemList.CatalogItemList() lastBackCatalog = avatar.backCatalog[:] thisWeek = min(len(WeeklySchedule), week - 1) lastWeek = min(len(WeeklySchedule), previousWeek) for week in xrange(thisWeek, lastWeek, -1): self.notify.debug('Adding items from week %s to back catalog' % week) schedule = WeeklySchedule[week - 1] if not isinstance(schedule, Sale): for item in schedule: for item in self.__selectItem(avatar, item, weeklyCatalog + backCatalog): item.putInBackCatalog(backCatalog, lastBackCatalog) if previousWeek < week: self.notify.debug('Adding current items from week %s to back catalog' % previousWeek) for item in avatar.weeklyCatalog: item.putInBackCatalog(backCatalog, lastBackCatalog) backCatalog += lastBackCatalog for item in weeklyCatalog: while item in backCatalog: backCatalog.remove(item) return backCatalog
def setDeletedItems(self, items): self.deletedItems = CatalogItemList.CatalogItemList(items, store=CatalogItem.Customization)
def setAtticWindows(self, items): self.atticWindows = CatalogItemList.CatalogItemList(items, store=CatalogItem.Customization)
def setAtticWallpaper(self, items): self.atticWallpaper = CatalogItemList.CatalogItemList(items, store=CatalogItem.Customization)
def setAwardMailboxContents(self, awardMailboxContents): self.awardMailboxContents = CatalogItemList.CatalogItemList( awardMailboxContents.decode('base64'), store=CatalogItem.Customization)
def setAwardSchedule(self, onOrder): self.onAwardOrder = CatalogItemList.CatalogItemList( onOrder.decode('base64'), store=CatalogItem.Customization | CatalogItem.DeliveryDate)
def setWallpaper(self, items): self.wallpaper = CatalogItemList.CatalogItemList(items, store=CatalogItem.Customization) if self.interior: self.__colorWalls()