def selectRecipe(self, recipe): if self.gameFSM.state != 'RecipeSelect': return itemId = PotionGlobals.potionBuffIdToInventoryTypeId(recipe.potionID) inv = localAvatar.getInventory() if not inv: return quantity = inv.getItemQuantity(InventoryType.ItemTypeConsumable, itemId) limit = inv.getItemLimit(InventoryType.ItemTypeConsumable, itemId) if quantity >= limit: self.cleanUpConfirm() self.confirm = PiratesConfirm.PiratesConfirm( PLocalizer.PotionGui['MaxedOutTitle'], PLocalizer.PotionGui['MaxedOutText'], self.onSelectConfirmed) self.confirm.setPos(0.35, 0, -0.17) self.confirm.bOk['command'] = self.onSelectConfirmed self.confirm.bOk['extraArgs'] = [recipe] self.confirm.bNo['command'] = self.onSelectDeclined self.closeCurrentDialog = self.cleanUpConfirm self.gameBoard.disableInputEvents() self.disableButtons() else: self.gameFSM.request('StartGame', recipe)
def selectRecipe(self, recipe): if self.gameFSM.state != 'RecipeSelect': return None itemId = PotionGlobals.potionBuffIdToInventoryTypeId(recipe.potionID) inv = localAvatar.getInventory() if not inv: return None quantity = inv.getItemQuantity(InventoryType.ItemTypeConsumable, itemId) limit = inv.getItemLimit(InventoryType.ItemTypeConsumable, itemId) if quantity >= limit: self.cleanUpConfirm() self.confirm = PiratesConfirm.PiratesConfirm(PLocalizer.PotionGui['MaxedOutTitle'], PLocalizer.PotionGui['MaxedOutText'], self.onSelectConfirmed) self.confirm.setPos(0.34999999999999998, 0, -0.17000000000000001) self.confirm.bOk['command'] = self.onSelectConfirmed self.confirm.bOk['extraArgs'] = [ recipe] self.confirm.bNo['command'] = self.onSelectDeclined self.closeCurrentDialog = self.cleanUpConfirm self.gameBoard.disableInputEvents() self.disableButtons() else: self.gameFSM.request('StartGame', recipe)
def show(self): if self.potionName is not None: self.potionName.removeNode() if self.potionDesc is not None: self.potionDesc.removeNode() if self.potionXp is not None: self.potionXp.removeNode() if self.potionImg is not None: self.potionImg.removeNode() self.potionName = DirectLabel(parent = self, relief = None, text = self.potionGame.currentRecipe.name, text_scale = PiratesGuiGlobals.TextScaleTitleMed, text_align = TextNode.ACenter, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_wordwrap = 17, pos = (0.75, 0, 0.65000000000000002), textMayChange = 0) self.potionDesc = DirectLabel(parent = self, relief = None, text = self.potionGame.currentRecipe.desc, text_scale = PiratesGuiGlobals.TextScaleExtraLarge, text_align = TextNode.ACenter, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_wordwrap = 34, pos = (0.75, 0, 0.22), textMayChange = 0) xpAmt = PotionGlobals.getPotionBuffXP(self.potionGame.currentRecipe.potionID) xpAmt = int(math.ceil(float(xpAmt) / 2.0)) xpBonus = self.potionGame.dist.getXpBonus() labelTxt = '+ ' + str(xpAmt) + ' ' + PLocalizer.PotionGui['XPLabel'] if xpBonus: xpAmt = xpAmt + xpBonus labelTxt = PLocalizer.PotionGui['XPLabelBonus'] % (str(xpAmt), str(xpBonus)) self.potionXp = DirectLabel(parent = self, relief = None, text = labelTxt, text_scale = PiratesGuiGlobals.TextScaleTitleSmall, text_align = TextNode.ACenter, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_wordwrap = 17, pos = (0.75, 0, 0.28999999999999998), textMayChange = 0) asset = ItemGlobals.getIcon(PotionGlobals.potionBuffIdToInventoryTypeId(self.potionGame.currentRecipe.potionID)) skillIcons = loader.loadModel('models/textureCards/skillIcons') geom = skillIcons.find('**/%s' % asset) if geom.isEmpty(): geom = skillIcons.find('**/base') geom_scale = 0.23999999999999999 self.potionImg = DirectFrame(parent = self, geom = geom, geom_scale = geom_scale, pos = (0.75, 0, 0.5), image = None, relief = None) self.unstash() self.potionGame.closeCurrentDialog = self.cleanUp self.potionGame.disableButtons() skillIcons.removeNode()
def show(self): if self.potionName is not None: self.potionName.removeNode() if self.potionDesc is not None: self.potionDesc.removeNode() if self.potionXp is not None: self.potionXp.removeNode() if self.potionImg is not None: self.potionImg.removeNode() self.potionName = DirectLabel( parent=self, relief=None, text=self.potionGame.currentRecipe.name, text_scale=PiratesGuiGlobals.TextScaleTitleMed, text_align=TextNode.ACenter, text_fg=PiratesGuiGlobals.TextFG2, text_shadow=PiratesGuiGlobals.TextShadow, text_wordwrap=17, pos=(0.75, 0, 0.65000000000000002), textMayChange=0) self.potionDesc = DirectLabel( parent=self, relief=None, text=self.potionGame.currentRecipe.desc, text_scale=PiratesGuiGlobals.TextScaleExtraLarge, text_align=TextNode.ACenter, text_fg=PiratesGuiGlobals.TextFG2, text_shadow=PiratesGuiGlobals.TextShadow, text_wordwrap=34, pos=(0.75, 0, 0.22), textMayChange=0) xpAmt = PotionGlobals.getPotionBuffXP( self.potionGame.currentRecipe.potionID) xpAmt = int(math.ceil(float(xpAmt) / 2.0)) xpBonus = self.potionGame.dist.getXpBonus() labelTxt = '+ ' + str(xpAmt) + ' ' + PLocalizer.PotionGui['XPLabel'] if xpBonus: xpAmt = xpAmt + xpBonus labelTxt = PLocalizer.PotionGui['XPLabelBonus'] % (str(xpAmt), str(xpBonus)) self.potionXp = DirectLabel( parent=self, relief=None, text=labelTxt, text_scale=PiratesGuiGlobals.TextScaleTitleSmall, text_align=TextNode.ACenter, text_fg=PiratesGuiGlobals.TextFG2, text_shadow=PiratesGuiGlobals.TextShadow, text_wordwrap=17, pos=(0.75, 0, 0.28999999999999998), textMayChange=0) asset = ItemGlobals.getIcon( PotionGlobals.potionBuffIdToInventoryTypeId( self.potionGame.currentRecipe.potionID)) skillIcons = loader.loadModel('models/textureCards/skillIcons') geom = skillIcons.find('**/%s' % asset) if geom.isEmpty(): geom = skillIcons.find('**/base') geom_scale = 0.23999999999999999 self.potionImg = DirectFrame(parent=self, geom=geom, geom_scale=geom_scale, pos=(0.75, 0, 0.5), image=None, relief=None) self.unstash() self.potionGame.closeCurrentDialog = self.cleanUp self.potionGame.disableButtons() skillIcons.removeNode()
def completeRecipe(self, recipeId, clearNewFlag): if not self.__verifySender(): return if self.__workingRecipe == -1: if not PotionRecipeData.getPotionData(recipeId): self.notify.warning( 'Received complete Recipe for an invalid recipe %d!' % recipeId) self.air.logPotentialHacker( message='Received complete Recipe for an invalid recipe.', targetAvId=self.avatar.doId, recipeId=recipeId) return self.__workingRecipe = recipeId # Is this still the same recipe? elif self.__workingRecipe != recipeId: self.notify.warning( 'Attempted to complete recipe that has not been started!') self.air.logPotentialHacker( message= 'Attempted to complete recipe that has not been started!', targetAvId=self.avatar.doId, recipeId=recipeId) return self.__numIngredients += 1 if self.__numIngredients >= PotionRecipeData.getNumIngredients( recipeId): # Perform disabled potion sanity check if PotionRecipeData.getDisabled(recipeId): self.notify.warning( '%d completed a disabled potion recipe! (%d)' % (self.avatar.doId, recipeId)) self.air.logPotentialHacker( message='Attempted to complete a disabled recipe!', targetAvId=self.avatar.doId, recipeId=recipeId) self.reset() return self.notify.debug('%s completed recipe %d!' % (self.avatar.doId, recipeId)) inventory = self.air.inventoryManager.getInventory( self.avatar.doId) success = True if not inventory: self.notify.warning('Failed to get inventory for avatar %d!' % avatar.doId) # Log failure for Game Masters self.air.writeServerEvent( 'recipe-error', message='Failed to give player potion game rewards.', targetAvId=self.avatar.doId, recipeId=recipeId, rep=rep, potionId=potionId) self.reset() return potionRep = inventory.getPotionsRep() or 1 # Perform potion level sanity check requiredLevel = PotionRecipeData.getPotionData(recipeId)['level'] if potionRep < requiredLevel: self.notify.warning( '%d completed a potion they are not a high enough level for! (%d); Requires %s. Has %s' % (self.avatar.doId, recipeId, requiredLevel, potionRep)) self.air.logPotentialHacker( message= 'Attempted to complete a potion they are not a high enough level for!', targetAvId=self.avatar.doId, recipeId=recipeId, level=potionRep, required=requiredLevel) self.reset() return # Set have made flag if clearNewFlag: madeType = PotionGlobals.getPotionHaveMadeFlag(recipeId) madeCounter = inventory.getStack( madeType)[1] if inventory.getStack(madeType) != None else 0 madeCounter += 1 inventory.b_setStack(madeType, madeCounter) # Aware XP rep = PotionGlobals.getPotionBuffXP(recipeId) potionId = PotionGlobals.potionBuffIdToInventoryTypeId(recipeId) inventory.setPotionsRep(potionRep + rep) #TODO give out potion self.notify.warning( 'TODO: Implement potion rewards; PotionId: %d!' % potionId) self.reset()