예제 #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 and itemType != listType:
                        raise 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)
                        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

                        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
    def locatableItem(self, status, item):
        modification = False
        itemFields = InvItem(item[0])
        itemLocation = itemFields.getLocation()
        origStatus = status
        if status == self.STATUS_ITEM_MODIFIED or status == self.STATUS_ITEM_MODIFIED_OVERFLOW:
            if itemFields[self.ITEM_CAT_IDX] == 0:
                status = self.STATUS_ITEM_REMOVED
            elif not self._locatableItems.has_key(itemLocation):
                status = self.STATUS_ITEM_ADDED

        if status == self.STATUS_ITEM_ADDED:
            self._locatableItems[itemLocation] = itemFields
            modification = True
        elif status == self.STATUS_ITEM_REMOVED:
            if self._locatableItems.has_key(itemLocation):
                del self._locatableItems[itemLocation]

            modification = True
        elif status == self.STATUS_ITEM_MODIFIED or status == self.STATUS_ITEM_MODIFIED_OVERFLOW:
            self._locatableItems.pop(itemLocation, None)
            self._locatableItems[itemLocation] = itemFields
            modification = True

        if modification:
            self.notify.debug('sending inventoryLocation message for %s' %
                              itemLocation)
            messenger.send(getLocationChangeMsg(self.doId), [itemLocation])
            if origStatus == self.STATUS_ITEM_MODIFIED_OVERFLOW:
                messenger.send(getOverflowChangeMsg(self.doId), [itemLocation])

            if itemFields.getCat():
                messenger.send(
                    getCategoryChangeMsg(self.doId, itemFields.getCat()),
                    [itemFields.getType()])
                messenger.send(
                    getCategoryQuantChangeMsg(self.doId, itemFields.getCat()),
                    [itemFields.getCount()])

            messenger.send(getAnyChangeMsg(self.doId))
예제 #3
0
 def locatableItem(self, status, item):
     modification = False
     itemFields = InvItem(item[0])
     itemLocation = itemFields.getLocation()
     origStatus = status
     if status == self.STATUS_ITEM_MODIFIED or status == self.STATUS_ITEM_MODIFIED_OVERFLOW:
         if itemFields[self.ITEM_CAT_IDX] == 0:
             status = self.STATUS_ITEM_REMOVED
         elif not self._locatableItems.has_key(itemLocation):
             status = self.STATUS_ITEM_ADDED
         
     
     if status == self.STATUS_ITEM_ADDED:
         self._locatableItems[itemLocation] = itemFields
         modification = True
     elif status == self.STATUS_ITEM_REMOVED:
         if self._locatableItems.has_key(itemLocation):
             del self._locatableItems[itemLocation]
         
         modification = True
     elif status == self.STATUS_ITEM_MODIFIED or status == self.STATUS_ITEM_MODIFIED_OVERFLOW:
         self._locatableItems.pop(itemLocation, None)
         self._locatableItems[itemLocation] = itemFields
         modification = True
     
     if modification:
         self.notify.debug('sending inventoryLocation message for %s' % itemLocation)
         messenger.send(getLocationChangeMsg(self.doId), [
             itemLocation])
         if origStatus == self.STATUS_ITEM_MODIFIED_OVERFLOW:
             messenger.send(getOverflowChangeMsg(self.doId), [
                 itemLocation])
         
         if itemFields.getCat():
             messenger.send(getCategoryChangeMsg(self.doId, itemFields.getCat()), [
                 itemFields.getType()])
             messenger.send(getCategoryQuantChangeMsg(self.doId, itemFields.getCat()), [
                 itemFields.getCount()])
         
         messenger.send(getAnyChangeMsg(self.doId))
        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