def buyConsItem(self, tocharacterId, consID, itemCount, itemId, price, buyType): '''购买寄卖物品 @param tocharacterId: int 角色的id @param consID: int 物品寄卖的ID @param itemId: int 物品的id @param price: int 物品的价格 @param itemCount: int 物品的数量 @param buyType: int 购买类型 1 金币 2钻 ''' characterId = self._owner.baseInfo.id package = self._owner.pack._package.getWholePagePack() position = package.findSparePositionForItem() if position == -1: return {'result': False, 'message': Lg().g(16)} if buyType == 1: the_coin = self._owner.finance.getCoin() - price to_coin = int(math.ceil(price * (1 - 0.1))) else: the_coin = self._owner.finance.getGold() - price to_coin = price if the_coin < 0: return {'result': False, 'message': Lg().g(190)} item = Item(id=itemId) item.pack.setStack(itemCount) item.InsertItemIntoDB(characterId=characterId) newitemId = item.baseInfo.getId() result = dbaccess.dbbuyConsItem(characterId, tocharacterId, consID, newitemId, the_coin, to_coin, position, buyType) if not result: return {'result': True, 'message': Lg().g(470)} item = Item(id=newitemId) item.pack.setStack(itemCount) item.InsertItemIntoDB(characterId=characterId) package.putItemByPosition(position, item) if buyType == 1: self._owner.finance.setCoin(the_coin) else: self._owner.finance.setGold(the_coin) return {'result': True, 'message': Lg().g(193)}
def getNewItemInPackage(self, itemTemplateId): '''获取新的物品''' item = Item(itemTemplateId=itemTemplateId) item.InsertItemIntoDB(characterId=self._owner.baseInfo.id) self.putNewItemInPackage(item)