Ejemplo n.º 1
0
        def check1(tradeItems, limitChanges, stacks, locatable, accumulators,
                   doIds, giving):
            listType = type([])
            possibleTypes = (type(1), type(1L), listType)
            for i in tradeItems:
                for v in i:
                    itemType = type(v)
                    if itemType not in possibleTypes:
                        raise AITradeException, 'element is the wrong type'
                    if v > 4294967295L:
                        raise itemType != listType and AITradeException, 'element is larger than unsigned long'
                else:
                    t = i[TypeIndex]
                    if InventoryId.isLimitChange(t):
                        a = limitChanges.setdefault(t, [t, 0])
                        a[1] += i[QuantityIndex]
                        if a[1] > 65535L:
                            raise AITradeException, 'element is larger than unsigned short'
                    elif InventoryId.isStackable(t):
                        a = stacks.setdefault(t, [t, 0])
                        a[1] += i[QuantityIndex]
                        if a[1] > 65535L:
                            raise AITradeException, 'element is larger than unsigned short'
                    elif isLocatable(t):
                        inv = simbase.air.doId2do.get(self.inventoryId)
                        theInvItem = inv and InvItem(i)
                        theInvItemType = theInvItem.getType()
                        if giving:
                            equippableInfo = inv.getItemRequirements(
                                theInvItemType, self.giving)
                            if equippableInfo == None or filter(
                                    lambda x: equippableInfo[x][1] == False,
                                    equippableInfo):
                                if theInvItemType and theInvItemType not in self.unequippables:
                                    self.unequippables.append(theInvItemType)
                            if isStackableType(theInvItem.getCat()):
                                for currLocatable in locatable:
                                    prevInvItem = InvItem(currLocatable)
                                    if prevInvItem.compare(theInvItem,
                                                           excludeLoc=True):
                                        adjustedInvItem = prevInvItem.adjustCount(
                                            theInvItem.getCount())
                                        locatable.remove(currLocatable)
                                        i = list(adjustedInvItem)
                                        break

                        else:
                            raise AITradeException, 'inventory not present'
                        locatable.append(i)
                    elif InventoryId.isAccumulator(t):
                        a = accumulators.setdefault(t, [t, 0])
                        a[1] += i[QuantityIndex]
                        if a[1] > 4294967295L:
                            raise AITradeException, 'element is larger than unsigned long'
                    elif InventoryId.isDoId(t):
                        doIds[i[DoIdIndex]] = i

            return
Ejemplo n.º 2
0
    def _sortOffer(self, offer):
        categoryLimitChanges = []
        stackLimitChanges = []
        setAccumulators = []
        stackables = []
        locatable = []
        accumulators = []
        doIds = []
        for i in offer:
            a = i[0]
            if InventoryId.isLimitChange(a):
                changing = InventoryId.getChangeCategoryOrType(a)
                if InventoryId.isCategory(changing):
                    categoryLimitChanges.append(i)
                elif InventoryId.isStackable(changing):
                    stackLimitChanges.append(i)
                elif InventoryId.isAccumulator(changing):
                    setAccumulators.append(i)
                else:
                    print '=============EXCEPTION1 RAISED: %s' % a
                    raise Exception, 'undefined trade category'
            elif InventoryId.isStackable(a):
                stackables.append(i)
            elif isLocatable(a):
                locatable.append(i)
            elif InventoryId.isAccumulator(a):
                accumulators.append(i)
            elif InventoryId.isCategory(a):
                doIds.append(i)
            else:
                print '=============EXCEPTION2 RAISED: %s' % a
                raise Exception, 'undefined trade type'

        offer = categoryLimitChanges + stackLimitChanges + setAccumulators + stackables + locatable + accumulators + doIds
        def isNotFreelyGivable(stacks):
            for (stackType, quantity) in stacks.items():
                if not InventoryId.isFreeGiveStackType(stackType):
                    return True
                    continue

            return False
        def isNotFreelyGivable(stacks):
            for (stackType, quantity) in stacks.items():
                if not InventoryId.isFreeGiveStackType(stackType):
                    return True
                    continue

            return False
Ejemplo n.º 5
0
 def makeButton(self, parent, pos, cellSizeX, cellSizeZ):
     if InventoryId.isStackable(self.uid):
         data = [
          self.uid, 1]
     else:
         data = [
          InventoryId.getCategory(self.uid), self.uid]
     simpleItemGui = SimpleItemGUI([self.uid, 1], parent=parent, pos=pos)
     self.itemName = simpleItemGui.nameTag['text']
     self.shortDesc = self.itemName
     self.longDesc = self.itemName
     simpleItemGui.destroy()
     geomParams = InventoryItemGui.getGeomParams(self.uid)
     button = DirectButton(parent=parent, relief=None, rolloverSound=None, text='', text_scale=0.05, textMayChange=1, geom=geomParams['geom'], geom_pos=(0,
                                                                                                                                                         0,
                                                                                                                                                         0), geom_scale=geomParams['geom_scale'], pos=pos, extraArgs=[self])
     return button
Ejemplo n.º 6
0
 def makeButton(self, parent, pos, cellSizeX, cellSizeZ):
     if InventoryId.isStackable(self.uid):
         data = [
             self.uid,
             1]
     else:
         data = [
             InventoryId.getCategory(self.uid),
             self.uid]
     simpleItemGui = SimpleItemGUI([
         self.uid,
         1], parent = parent, pos = pos)
     self.itemName = simpleItemGui.nameTag['text']
     self.shortDesc = self.itemName
     self.longDesc = self.itemName
     simpleItemGui.destroy()
     geomParams = InventoryItemGui.getGeomParams(self.uid)
     button = DirectButton(parent = parent, relief = None, rolloverSound = None, text = '', text_scale = 0.050000000000000003, textMayChange = 1, geom = geomParams['geom'], geom_pos = (0, 0, 0), geom_scale = geomParams['geom_scale'], pos = pos, extraArgs = [
         self])
     return button
Ejemplo n.º 7
0
    def computeCategoryCounts(self):
        counts = {}
        for category in self.doIds.values():
            counts[category] = counts.get(category, 0) + 1

        for stackType in self.stacks.keys():
            category = InventoryId.getCategory(stackType)
            if category:
                counts[category] = counts.get(category, 0) + 1

        self.categoryCounts = counts
Ejemplo n.º 8
0
    def setStacks(self, stackTypesAndQuantities):
        old = self.stacks
        self.stacks = dict(stackTypesAndQuantities)
        stacksInCategory = {}
        for t, q in stackTypesAndQuantities:
            if old.get(t, 0) != q:
                messenger.send(InventoryGlobals.getCategoryQuantChangeMsg(self.doId, t), [q])
            categoryId = InventoryId.getCategory(t)
            categoryList = stacksInCategory.setdefault(categoryId, {})
            categoryList[t] = self.stacks[t]

        self.stacksInCategory = stacksInCategory
    def computeCategoryCounts(self):
        counts = { }
        for category in self.doIds.values():
            counts[category] = counts.get(category, 0) + 1

        for stackType in self.stacks.keys():
            category = InventoryId.getCategory(stackType)
            if category:
                counts[category] = counts.get(category, 0) + 1
                continue

        self.categoryCounts = counts
    def _sortOffer(self, offer):
        categoryLimitChanges = []
        stackLimitChanges = []
        setAccumulators = []
        stackables = []
        locatable = []
        accumulators = []
        doIds = []
        for i in offer:
            a = i[0]
            if InventoryId.isLimitChange(a):
                changing = InventoryId.getChangeCategoryOrType(a)
                if InventoryId.isCategory(changing):
                    categoryLimitChanges.append(i)
                elif InventoryId.isStackable(changing):
                    stackLimitChanges.append(i)
                elif InventoryId.isAccumulator(changing):
                    setAccumulators.append(i)
                else:
                    print "=============EXCEPTION1 RAISED: %s" % a
                    raise Exception, "undefined trade category"
            InventoryId.isCategory(changing)
            if InventoryId.isStackable(a):
                stackables.append(i)
                continue
            if isLocatable(a):
                locatable.append(i)
                continue
            if InventoryId.isAccumulator(a):
                accumulators.append(i)
                continue
            if InventoryId.isCategory(a):
                doIds.append(i)
                continue
            print "=============EXCEPTION2 RAISED: %s" % a
            raise Exception, "undefined trade type"

        offer = (
            categoryLimitChanges + stackLimitChanges + setAccumulators + stackables + locatable + accumulators + doIds
        )
    def setStacks(self, stackTypesAndQuantities):
        old = self.stacks
        self.stacks = dict(stackTypesAndQuantities)
        stacksInCategory = { }
        for (t, q) in stackTypesAndQuantities:
            if old.get(t, 0) != q:
                messenger.send(InventoryGlobals.getCategoryQuantChangeMsg(self.doId, t), [
                    q])

            categoryId = InventoryId.getCategory(t)
            categoryList = stacksInCategory.setdefault(categoryId, { })
            categoryList[t] = self.stacks[t]

        self.stacksInCategory = stacksInCategory
 def stack(self, stackType, quantity):
     self.stacks[stackType] = quantity
     categoryId = InventoryId.getCategory(stackType)
     category = self.stacksInCategory.setdefault(categoryId, { })
     if quantity:
         category[stackType] = quantity
     else:
         category.pop(stackType, None)
     messenger.send(InventoryGlobals.getCategoryQuantChangeMsg(self.doId, stackType), [
         quantity])
     messenger.send(InventoryGlobals.getAnyChangeMsg(self.doId))
     if stackType == InventoryType.Vitae_Level and stackType == InventoryType.Vitae_Cost or stackType == InventoryType.Vitae_Left:
         localAvatar.guiMgr.gameGui.updateVitae(self.getStackQuantity(InventoryType.Vitae_Level), self.getStackQuantity(InventoryType.Vitae_Cost), self.getStackQuantity(InventoryType.Vitae_Left))
     
     if self.ownerId == localAvatar.getDoId():
         localAvatar.gotSpecialReward(stackType)
Ejemplo n.º 13
0
 def stack(self, stackType, quantity):
     self.stacks[stackType] = quantity
     categoryId = InventoryId.getCategory(stackType)
     category = self.stacksInCategory.setdefault(categoryId, { })
     if quantity:
         category[stackType] = quantity
     else:
         category.pop(stackType, None)
     messenger.send(InventoryGlobals.getCategoryQuantChangeMsg(self.doId, stackType), [
         quantity])
     messenger.send(InventoryGlobals.getAnyChangeMsg(self.doId))
     if stackType == InventoryType.Vitae_Level and stackType == InventoryType.Vitae_Cost or stackType == InventoryType.Vitae_Left:
         localAvatar.guiMgr.gameGui.updateVitae(self.getStackQuantity(InventoryType.Vitae_Level), self.getStackQuantity(InventoryType.Vitae_Cost), self.getStackQuantity(InventoryType.Vitae_Left))
     
     if self.ownerId == localAvatar.getDoId():
         localAvatar.gotSpecialReward(stackType)
Ejemplo n.º 14
0
 def giveStackableMinLimit(self, stackType, minLimit):
     limitMinimum = InventoryId.getLimitMinChange(stackType)
     self.giving.append([limitMinimum, minLimit])
Ejemplo n.º 15
0
 def giveStackableTypeLimit(self, stackType, addToLimit):
     limitChange = InventoryId.getLimitChange(stackType)
     self.giving.append([limitChange, addToLimit])
Ejemplo n.º 16
0
 def giveCategoryLimit(self, category, addToLimit):
     limitChange = InventoryId.getLimitChange(category)
     self.giving.append([limitChange, addToLimit])
 def setAccumulator(self, accumulatorType, quantity):
     setAccumulator = InventoryId.getLimitChange(accumulatorType)
     self.giving.append((setAccumulator, quantity))
Ejemplo n.º 18
0
        def isNotFreelyRemovable(stacks):
            for stackType, quantity in stacks.items():
                if not InventoryId.isFreeTakeStackType(stackType):
                    return True

            return False
Ejemplo n.º 19
0
 def takeStackMax(self, stackType):
     percentChange = InventoryId.getStackPercentChange(stackType)
     self.taking.append([percentChange, 100])
 def takeStackMax(self, stackType):
     percentChange = InventoryId.getStackPercentChange(stackType)
     self.taking.append([percentChange, 100])
        def check1(tradeItems, limitChanges, stacks, locatable, accumulators, doIds, giving):
            listType = type([])
            possibleTypes = (type(1), type(0x1L), listType)
            for i in tradeItems:
                for v in i:
                    itemType = type(v)
                    if itemType not in possibleTypes:
                        raise AITradeException, "element is the wrong type"

                    if v > 0xFFFFFFFFL and itemType != listType:
                        raise AITradeException, "element is larger than unsigned long"
                        continue
                else:
                    t = i[TypeIndex]
                    if InventoryId.isLimitChange(t):
                        a = limitChanges.setdefault(t, [t, 0])
                        a[1] += i[QuantityIndex]
                        if a[1] > 0xFFFFL:
                            raise AITradeException, "element is larger than unsigned short"

                    if InventoryId.isStackable(t):
                        a = stacks.setdefault(t, [t, 0])
                        a[1] += i[QuantityIndex]
                        if a[1] > 0xFFFFL:
                            raise AITradeException, "element is larger than unsigned short"

                    a[1] > 0xFFFFL
                    if isLocatable(t):
                        inv = simbase.air.doId2do.get(self.inventoryId)
                        if inv:
                            theInvItem = InvItem(i)
                            theInvItemType = theInvItem.getType()
                            if giving:
                                equippableInfo = inv.getItemRequirements(theInvItemType, self.giving)
                                if (
                                    (
                                        equippableInfo == None
                                        or filter(lambda x: equippableInfo[x][1] == False, equippableInfo)
                                    )
                                    and theInvItemType
                                    and theInvItemType not in self.unequippables
                                ):
                                    self.unequippables.append(theInvItemType)

                            if isStackableType(theInvItem.getCat()):
                                for currLocatable in locatable:
                                    prevInvItem = InvItem(currLocatable)
                                    if prevInvItem.compare(theInvItem, excludeLoc=True):
                                        adjustedInvItem = prevInvItem.adjustCount(theInvItem.getCount())
                                        locatable.remove(currLocatable)
                                        i = list(adjustedInvItem)
                                        break
                                        continue

                        else:
                            raise AITradeException, "inventory not present"
                        locatable.append(i)
                        continue
                    if InventoryId.isAccumulator(t):
                        a = accumulators.setdefault(t, [t, 0])
                        a[1] += i[QuantityIndex]
                        if a[1] > 0xFFFFFFFFL:
                            raise AITradeException, "element is larger than unsigned long"

                    a[1] > 0xFFFFFFFFL
                    if InventoryId.isDoId(t):
                        doIds[i[DoIdIndex]] = i
                        continue
Ejemplo n.º 22
0
 def checkStackable(self):
     return InventoryId.isStackable(self.uid)
 def giveCategoryLimit(self, category, addToLimit):
     limitChange = InventoryId.getLimitChange(category)
     self.giving.append([limitChange, addToLimit])
 def giveStackableTypeLimit(self, stackType, addToLimit):
     limitChange = InventoryId.getLimitChange(stackType)
     self.giving.append([limitChange, addToLimit])
 def giveStackableMinLimit(self, stackType, minLimit):
     limitMinimum = InventoryId.getLimitMinChange(stackType)
     self.giving.append([limitMinimum, minLimit])
Ejemplo n.º 26
0
 def checkStackable(self):
     return InventoryId.isStackable(self.uid)
Ejemplo n.º 27
0
 def setAccumulator(self, accumulatorType, quantity):
     setAccumulator = InventoryId.getLimitChange(accumulatorType)
     self.giving.append((setAccumulator, quantity))