def updateBalance(self, extraArgs=None): self.balance = 0 for item in self.purchaseInventory: self.balance += EconomyGlobals.getItemCost(item[0]) if self.balance > 0: self.balanceTitle['text'] = PLocalizer.Cost self.balanceValue['text'] = str(abs(self.balance)) elif self.balance < 0: self.balanceTitle['text'] = PLocalizer.Gain self.balanceValue['text'] = str(abs(self.balance)) else: self.balanceTitle['text'] = PLocalizer.Cost self.balanceValue['text'] = str(abs(self.balance)) inventory = base.localAvatar.getInventory() if inventory: if inventory.getGoldInPocket() < self.balance: self.commitButton[ 'frameColor'] = PiratesGuiGlobals.ButtonColor3 elif len( inventory.getShipDoIdList()) >= inventory.getCategoryLimit( InventoryCategory.SHIPS): self.commitButton[ 'frameColor'] = PiratesGuiGlobals.ButtonColor3 else: self.commitButton[ 'frameColor'] = PiratesGuiGlobals.ButtonColor4
def createGui(self): item, quantity = self.data name = PLocalizer.InventoryTypeNames[item] self.price = EconomyGlobals.getItemCost(item) repId = InventoryType.SailingRep itemTypeName = PLocalizer.InventoryTypeNames.get(repId) self.itemType = itemTypeName if self.sell: self.price /= 2 card = loader.loadModel('models/textureCards/shipCatalog') renderName = self.shipImageDict.get(item, 'Catalog_War_Brig') myTexCard = card.find('**/%s*' % renderName) myTex = myTexCard.findAllTextures()[0] card.removeNode() del card self.minLvl = EconomyGlobals.getItemMinLevel(item) self.miscText = None self.picture = DirectFrame(parent=self, relief=None, state=DGG.DISABLED, image=myTex, image_scale=(0.07, 1.0, 0.06)) self.picture.setPos(0.1, 0, 0.08) self.picture.setTransparency(1) self.nameTag = DirectLabel(parent=self, state=DGG.DISABLED, relief=None, text=name, text_scale=PiratesGuiGlobals.TextScaleMed * PLocalizer.getHeadingScale(2), text_align=TextNode.ALeft, text_fg=PiratesGuiGlobals.TextFG1, text_shadow=PiratesGuiGlobals.TextShadow, textMayChange=0) self.nameTag.setPos(0.2, 0, 0.1) self.costText = DirectLabel(parent=self, relief=None, state=DGG.DISABLED, geom=self.coinImage, geom_scale=0.12, geom_pos=Vec3(-0.01, 0, 0.01), text=str(self.price), text_scale=PiratesGuiGlobals.TextScaleSmall, text_align=TextNode.ARight, text_fg=PiratesGuiGlobals.TextFG2, text_shadow=PiratesGuiGlobals.TextShadow, text_wordwrap=11, text_pos=(-0.03, 0, 0), text_font=PiratesGlobals.getInterfaceFont()) self.costText.setPos(0.48, 0, 0.04) return
def __init__(self, uid): SimpleItem.__init__(self, uid) self.itemClass = EconomyGlobals.getItemCategory(uid) self.itemType = EconomyGlobals.getItemType(uid) self.cost = EconomyGlobals.getItemCost(uid) if not self.cost: self.cost = ItemGlobals.getGoldCost(uid)
def confirmOverhaulShip(self, shipId=None): if not shipId: return None shipOV = self.cr.getOwnerView(shipId) if not shipOV: return None if shipOV.state != 'Off': base.localAvatar.guiMgr.createWarning( PLocalizer.ShipNotInBottleWarning, PiratesGuiGlobals.TextFG6) return None shipClass = shipOV.getShipClass() cost = EconomyGlobals.getItemCost( shipClass) * EconomyGlobals.OVERHAUL_COST_PERCENTAGE if self.confirmDialog: self.confirmDialog.destroy() self.confirmDialog = None self.confirmDialog = PDialog.PDialog( text=PLocalizer.OverhaulConfirmDialog % {'gold': cost}, style=OTPDialog.YesNo, command=self.sendRequestOverhaulShip, extraArgs=[shipId])
def loadData(self): itemId = self.data[0] (item, quantity) = self.data self.quantity = quantity itemType = EconomyGlobals.getItemType(itemId) if itemType <= ItemType.WAND: itemTypeName = PLocalizer.getItemSubtypeName(ItemGlobals.getSubtype(itemId)) else: itemTypeName = PLocalizer.InventoryItemClassNames.get(itemType) if itemType <= ItemType.WAND or itemType == ItemType.POTION: name = PLocalizer.getItemName(itemId) self.price = ItemGlobals.getGoldCost(itemId) else: name = PLocalizer.InventoryTypeNames.get(item) self.price = EconomyGlobals.getItemCost(item) if self.sell: self.price /= 2 if self.buy: if itemType > ItemType.WAND and itemType != ItemType.POTION: self.quantity = EconomyGlobals.getItemQuantity(itemId) self.price *= self.quantity self.price = int(self.price) self.name = PLocalizer.makeHeadingString(name, 2) self.itemType = itemTypeName if itemType != ItemType.FISHING_LURE: if itemType != ItemType.POTION: self.minLvl = ItemGlobals.getWeaponRequirement(itemId) else: self.minLvl = 0 else: self.minLvl = EconomyGlobals.getItemMinLevel(self.data[0])
def loadData(self): itemId = self.data[0] item, quantity = self.data self.quantity = quantity itemType = EconomyGlobals.getItemType(itemId) if itemType <= ItemType.WAND: itemTypeName = PLocalizer.getItemSubtypeName( ItemGlobals.getSubtype(itemId)) else: itemTypeName = PLocalizer.InventoryItemClassNames.get(itemType) if itemType <= ItemType.WAND or itemType == ItemType.POTION: name = PLocalizer.getItemName(itemId) self.price = ItemGlobals.getGoldCost(itemId) else: name = PLocalizer.InventoryTypeNames.get(item) self.price = EconomyGlobals.getItemCost(item) if self.sell: self.price /= 2 if self.buy: if itemType > ItemType.WAND and itemType != ItemType.POTION: self.quantity = EconomyGlobals.getItemQuantity(itemId) self.price *= self.quantity self.price = int(self.price) self.name = PLocalizer.makeHeadingString(name, 2) self.itemType = itemTypeName if itemType != ItemType.FISHING_LURE: if itemType != ItemType.POTION: self.minLvl = ItemGlobals.getWeaponRequirement(itemId) else: self.minLvl = 0 else: self.minLvl = EconomyGlobals.getItemMinLevel(self.data[0])
def sendRequestSellShip(self, shipId, choice): shipOV = self.cr.getOwnerView(shipId) if not shipOV: if self.pickShipGUI: self.pickShipGUI.hide() return None modelType = ShipGlobals.getModelClass(shipOV.shipClass) cost = EconomyGlobals.getItemCost(modelType) / 2 if choice == 1: inventory = base.localAvatar.getInventory() if inventory: if cost > 0 and inventory.getGoldInPocket() + cost > InventoryGlobals.GOLD_CAP: r = Functor(self.sendRequestSellShipGoldOverflow, shipId) if self.confirmDialog: self.confirmDialog.destroy() self.confirmDialog = None self.confirmDialog = PDialog.PDialog(text = PLocalizer.ExcessGoldLost, style = OTPDialog.YesNo, command = r) return None self.sendUpdate('requestSellShip', [ shipId]) if self.pickShipGUI: self.pickShipGUI.hide() self.finishShopping()
def createGui(self): (item, quantity) = self.data name = PLocalizer.InventoryTypeNames[item] self.price = EconomyGlobals.getItemCost(item) repId = InventoryType.SailingRep itemTypeName = PLocalizer.InventoryTypeNames.get(repId) self.itemType = itemTypeName if self.sell: self.price /= 2 card = loader.loadModel("models/textureCards/shipCatalog") renderName = self.shipImageDict.get(item, "Catalog_War_Brig") myTexCard = card.find("**/%s*" % renderName) myTex = myTexCard.findAllTextures()[0] card.removeNode() del card self.minLvl = EconomyGlobals.getItemMinLevel(item) self.miscText = None self.picture = DirectFrame( parent=self, relief=None, state=DGG.DISABLED, image=myTex, image_scale=(0.070000000000000007, 1.0, 0.059999999999999998), ) self.picture.setPos(0.10000000000000001, 0, 0.080000000000000002) self.picture.setTransparency(1) self.nameTag = DirectLabel( parent=self, state=DGG.DISABLED, relief=None, text=name, text_scale=PiratesGuiGlobals.TextScaleMed * PLocalizer.getHeadingScale(2), text_align=TextNode.ALeft, text_fg=PiratesGuiGlobals.TextFG1, text_shadow=PiratesGuiGlobals.TextShadow, textMayChange=0, ) self.nameTag.setPos(0.20000000000000001, 0, 0.10000000000000001) self.costText = DirectLabel( parent=self, relief=None, state=DGG.DISABLED, geom=self.coinImage, geom_scale=0.12, geom_pos=Vec3(-0.01, 0, 0.01), text=str(self.price), text_scale=PiratesGuiGlobals.TextScaleSmall, text_align=TextNode.ARight, text_fg=PiratesGuiGlobals.TextFG2, text_shadow=PiratesGuiGlobals.TextShadow, text_wordwrap=11, text_pos=(-0.029999999999999999, 0, 0), text_font=PiratesGlobals.getInterfaceFont(), ) self.costText.setPos(0.47999999999999998, 0, 0.040000000000000001)
def requestMakeShipSale(self, buying, selling, names): avatar = self.air.doId2do.get(self.air.getAvatarIdFromSender()) if not avatar: return inventory = self.air.inventoryManager.getInventory(avatar.doId) if not inventory: self.notify.warning('Failed to get inventory for avatar %d!' % avatar.doId) self.sendUpdateToAvatarId(avatar.doId, 'makeSaleResponse', [RejectCode.TIMEOUT]) return if len(buying) == 0: self.notify.warning( 'Failed to process ship sale; Received an empty list!') self.sendUpdateToAvatarId(avatar.doId, 'makeSaleResponse', [RejectCode.TIMEOUT]) return itemData = buying[0] shipId = itemData[0] requiredGold = EconomyGlobals.getItemCost(shipId) if requiredGold > inventory.getGoldInPocket(): self.air.logPotentialHacker( message='Attempted to make sale without sufficent gold', pirateGold=inventory.getGoldInPocket(), requiredGold=requiredGold) self.sendUpdateToAvatarId(avatar.doId, 'makeSaleResponse', [0]) return resultCode = 0 #TODO check if there is an open slot openSlot = False if not openSlot: resultCode = RejectCode.OVERFLOW if resultCode == 0: self.air.writeServerEvent('shop-transaction', transactionType='ship', shipId=shipId, name=names) inventory.setGoldInPocket(inventory.getGoldInPocket() - requiredGold) #TODO issue ship self.sendUpdateToAvatarId(avatar.doId, 'makeSaleResponse', [resultCode])
def sendRequestOverhaulShip(self, choice, extraArgs): if self.pickShipGUI: self.pickShipGUI.hide() shipId = extraArgs[0] shipOV = self.cr.getOwnerView(shipId) if not shipOV: return shipClass = shipOV.getShipClass() cost = EconomyGlobals.getItemCost(shipClass) * EconomyGlobals.OVERHAUL_COST_PERCENTAGE if choice == 1: inventory = base.localAvatar.getInventory() if inventory: if inventory.getGoldInPocket() < cost: base.localAvatar.guiMgr.createWarning(PLocalizer.NotEnoughMoneyWarning, PiratesGuiGlobals.TextFG6) return self.sendUpdate('requestPurchaseOverhaul', [shipId]) self.finishShopping()
def confirmSellShip(self, shipId=None): if not shipId: return shipOV = self.cr.getOwnerView(shipId) if not shipOV: return if shipOV.state != 'Off': base.localAvatar.guiMgr.createWarning(PLocalizer.ShipNotInBottleWarning, PiratesGuiGlobals.TextFG6) return modelType = ShipGlobals.getModelClass(shipOV.shipClass) cost = EconomyGlobals.getItemCost(modelType) / 2 r = Functor(self.doubleConfirmSellShip, shipId) if self.confirmDialog: self.confirmDialog.destroy() self.confirmDialog = None self.confirmDialog = PDialog.PDialog(text=PLocalizer.SellShipConfirmDialog % {'gold': cost}, style=OTPDialog.YesNo, command=r) return
def confirmOverhaulShip(self, shipId = None): if not shipId: return None shipOV = self.cr.getOwnerView(shipId) if not shipOV: return None if shipOV.state != 'Off': base.localAvatar.guiMgr.createWarning(PLocalizer.ShipNotInBottleWarning, PiratesGuiGlobals.TextFG6) return None shipClass = shipOV.getShipClass() cost = EconomyGlobals.getItemCost(shipClass) * EconomyGlobals.OVERHAUL_COST_PERCENTAGE if self.confirmDialog: self.confirmDialog.destroy() self.confirmDialog = None self.confirmDialog = PDialog.PDialog(text = PLocalizer.OverhaulConfirmDialog % { 'gold': cost }, style = OTPDialog.YesNo, command = self.sendRequestOverhaulShip, extraArgs = [ shipId])
def confirmSellShip(self, shipId = None): if not shipId: return None shipOV = self.cr.getOwnerView(shipId) if not shipOV: return None if shipOV.state != 'Off': base.localAvatar.guiMgr.createWarning(PLocalizer.ShipNotInBottleWarning, PiratesGuiGlobals.TextFG6) return None modelType = ShipGlobals.getModelClass(shipOV.shipClass) cost = EconomyGlobals.getItemCost(modelType) / 2 r = Functor(self.doubleConfirmSellShip, shipId) if self.confirmDialog: self.confirmDialog.destroy() self.confirmDialog = None self.confirmDialog = PDialog.PDialog(text = PLocalizer.SellShipConfirmDialog % { 'gold': cost }, style = OTPDialog.YesNo, command = r)
def updateBalance(self, extraArgs = None): self.balance = 0 for item in self.purchaseInventory: self.balance += EconomyGlobals.getItemCost(item[0]) if self.balance > 0: self.balanceTitle['text'] = PLocalizer.Cost self.balanceValue['text'] = str(abs(self.balance)) elif self.balance < 0: self.balanceTitle['text'] = PLocalizer.Gain self.balanceValue['text'] = str(abs(self.balance)) else: self.balanceTitle['text'] = PLocalizer.Cost self.balanceValue['text'] = str(abs(self.balance)) inventory = base.localAvatar.getInventory() if inventory: if inventory.getGoldInPocket() < self.balance: self.commitButton['frameColor'] = PiratesGuiGlobals.ButtonColor3 elif len(inventory.getShipDoIdList()) >= inventory.getCategoryLimit(InventoryCategory.SHIPS): self.commitButton['frameColor'] = PiratesGuiGlobals.ButtonColor3 else: self.commitButton['frameColor'] = PiratesGuiGlobals.ButtonColor4
def sendRequestOverhaulShip(self, choice, extraArgs): if self.pickShipGUI: self.pickShipGUI.hide() shipId = extraArgs[0] shipOV = self.cr.getOwnerView(shipId) if not shipOV: return None shipClass = shipOV.getShipClass() cost = EconomyGlobals.getItemCost(shipClass) * EconomyGlobals.OVERHAUL_COST_PERCENTAGE if choice == 1: inventory = base.localAvatar.getInventory() if inventory: if inventory.getGoldInPocket() < cost: base.localAvatar.guiMgr.createWarning(PLocalizer.NotEnoughMoneyWarning, PiratesGuiGlobals.TextFG6) return None self.sendUpdate('requestPurchaseOverhaul', [ shipId]) self.finishShopping()
def createGui(self): (item, quantity) = self.data name = PLocalizer.InventoryTypeNames[item] self.price = EconomyGlobals.getItemCost(item) repId = InventoryType.SailingRep itemTypeName = PLocalizer.InventoryTypeNames.get(repId) self.itemType = itemTypeName if self.sell: self.price /= 2 card = loader.loadModel('models/textureCards/shipRenders') if item in [ ItemId.INTERCEPTOR_L1, ItemId.INTERCEPTOR_L2, ItemId.INTERCEPTOR_L3]: myTexCard = card.find('**/Interceptor_Render*') elif item in [ ItemId.MERCHANT_L1, ItemId.MERCHANT_L2, ItemId.MERCHANT_L3]: myTexCard = card.find('**/Merchant_Render*') elif item in [ ItemId.WARSHIP_L1, ItemId.WARSHIP_L2, ItemId.WARSHIP_L3]: myTexCard = card.find('**/Warship_Render*') else: myTexCard = card.find('**/Warship_Render*') myTex = myTexCard.findAllTextures()[0] card.removeNode() del card self.minLvl = EconomyGlobals.getItemMinLevel(item) self.miscText = None self.picture = DirectFrame(parent = self, relief = None, state = DGG.DISABLED, image = myTex, image_scale = 0.059999999999999998, pos = (0.085000000000000006, 0, 0.074999999999999997)) self.picture.setTransparency(1) self.nameTag = DirectLabel(parent = self, state = DGG.DISABLED, relief = None, text = name, text_scale = PiratesGuiGlobals.TextScaleMed * PLocalizer.getHeadingScale(2), text_align = TextNode.ALeft, text_fg = PiratesGuiGlobals.TextFG1, text_shadow = PiratesGuiGlobals.TextShadow, pos = (0.16, 0, 0.105), textMayChange = 0) self.costText = DirectLabel(parent = self, relief = None, state = DGG.DISABLED, geom = self.coinImage, geom_scale = 0.12, geom_pos = Vec3(-0.01, 0, 0.01), text = str(self.price), text_scale = PiratesGuiGlobals.TextScaleSmall, text_align = TextNode.ARight, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_wordwrap = 11, text_pos = (-0.029999999999999999, 0, 0), pos = (self.width - 0.035000000000000003, 0, 0.105), text_font = PiratesGlobals.getInterfaceFont())
def requestMakeSale(self, buying, selling): avatar = self.air.doId2do.get(self.air.getAvatarIdFromSender()) if not avatar: return inventory = self.air.inventoryManager.getInventory(avatar.doId) if not inventory: self.notify.warning('Failed to get inventory for avatar %d!' % avatar.doId) self.sendUpdateToAvatarId(avatar.doId, 'makeSaleResponse', [RejectCode.TIMEOUT]) return buying = self.__reverseSwitchStatement(buying) selling = self.__reverseSwitchStatement(selling) for buy in buying: item = buy[0] quantity = buy[1] cost = EconomyGlobals.getItemCost(item) if not cost: self.notify.warning('Unable to locate price for item: %s!' % item) self.sendUpdateToAvatarId(avatar.doId, 'makeSaleResponse', [RejectCode.TIMEOUT]) if not inventory.getGoldInPocket() >= cost: self.air.logPotentialHacker( message='Attempted to make sale without sufficent gold', pirateGold=inventory.getGoldInPocket(), requiredGold=cost) self.sendUpdateToAvatarId(avatar.doId, 'makeSaleResponse', [0]) return itemType = InventoryId.LOCATABLE resultCode = 0 if not UberDogGlobals.isLocatable(item): itemType == InventoryId.STACK if itemType == InventoryId.LOCATABLE: self.notify.warning( 'Attempted to make purchase for unsupported item type: LOCATABLE' ) self.sendUpdateToAvatarId(avatar.doId, 'makeSaleResponse', [RejectCode.TIMEOUT]) return elif itemType == InventoryId.STACK: pass if resultCode == 0: self.air.writeServerEvent('shop-transaction', transactionType='generic', buying=buying, selling=selling) inventory.setGoldInPocket(inventory.getGoldInPocket() - cost) self.sendUpdateToAvatarId(avatar.doId, 'makeSaleResponse', [resultCode]) for sell in selling: pass #TODO
def createGui(self): (item, quantity) = self.data name = PLocalizer.InventoryTypeNames[item] self.price = EconomyGlobals.getItemCost(item) repId = InventoryType.SailingRep itemTypeName = PLocalizer.InventoryTypeNames.get(repId) self.itemType = itemTypeName if self.sell: self.price /= 2 card = loader.loadModel('models/textureCards/shipRenders') if item in [ ItemId.INTERCEPTOR_L1, ItemId.INTERCEPTOR_L2, ItemId.INTERCEPTOR_L3 ]: myTexCard = card.find('**/Interceptor_Render*') elif item in [ ItemId.MERCHANT_L1, ItemId.MERCHANT_L2, ItemId.MERCHANT_L3 ]: myTexCard = card.find('**/Merchant_Render*') elif item in [ItemId.WARSHIP_L1, ItemId.WARSHIP_L2, ItemId.WARSHIP_L3]: myTexCard = card.find('**/Warship_Render*') else: myTexCard = card.find('**/Warship_Render*') myTex = myTexCard.findAllTextures()[0] card.removeNode() del card self.minLvl = EconomyGlobals.getItemMinLevel(item) self.miscText = None self.picture = DirectFrame(parent=self, relief=None, state=DGG.DISABLED, image=myTex, image_scale=0.059999999999999998, pos=(0.085000000000000006, 0, 0.074999999999999997)) self.picture.setTransparency(1) self.nameTag = DirectLabel(parent=self, state=DGG.DISABLED, relief=None, text=name, text_scale=PiratesGuiGlobals.TextScaleMed * PLocalizer.getHeadingScale(2), text_align=TextNode.ALeft, text_fg=PiratesGuiGlobals.TextFG1, text_shadow=PiratesGuiGlobals.TextShadow, pos=(0.16, 0, 0.105), textMayChange=0) self.costText = DirectLabel( parent=self, relief=None, state=DGG.DISABLED, geom=self.coinImage, geom_scale=0.12, geom_pos=Vec3(-0.01, 0, 0.01), text=str(self.price), text_scale=PiratesGuiGlobals.TextScaleSmall, text_align=TextNode.ARight, text_fg=PiratesGuiGlobals.TextFG2, text_shadow=PiratesGuiGlobals.TextShadow, text_wordwrap=11, text_pos=(-0.029999999999999999, 0, 0), pos=(self.width - 0.035000000000000003, 0, 0.105), text_font=PiratesGlobals.getInterfaceFont())