예제 #1
0
	def getChance(self, scroll, item):
		if item.getEnchantLevel() < self.getSafeEnchantLevel(item):
			return 100
		if self.isCustomChance and scroll.getItemId() in self.custom_chance.keys():
			return self.custom_chance[scroll.getItemId()]
		tscroll = EnchantItemTable.getInstance().getEnchantScroll(scroll)
		if tscroll:
			return max(tscroll.getChance(item, None), 0)
		return 0
예제 #2
0
	def process_enchant(self, event, npc, player):
		itemoid, scrolloid = event
		itemoid, scrolloid = int(itemoid), int(scrolloid)
		inv = player.getInventory()
		item = inv.getItemByObjectId(itemoid)
		scroll = inv.getItemByObjectId(scrolloid)
		if item == None or scroll == None: return
		escroll = EnchantItemTable.getInstance().getEnchantScroll(scroll)
		if escroll == None: return
		dscroll = inv.destroyItem(self.qn, scrolloid, 1, player, item)
		if not dscroll: return
		if not item.getOwnerId() == player.getObjectId(): return
		if not item.isEnchantable(): return
		chance = self.getChance(scroll, item)
		if Rnd.get(100) < chance:
			item.setEnchantLevel(item.getEnchantLevel() + 1)
			item.updateDatabase()
			player.sendPacket(EnchantResult(0, 0, 0))
			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_SUCCESSFULY_ENCHANTED_A_S2_S3);
			sm.addCharName(player)
			sm.addNumber(item.getEnchantLevel())
			sm.addItemName(item)
			if item.getEnchantLevel() in self.enchant_lv_notify:
				player.broadcastPacket(sm)
				if self.canFireWorks:
					skill = SkillTable.FrequentSkill.FIREWORK.getSkill()
					if skill:
						player.broadcastPacket(MagicSkillUse(player, player, skill.getId(), skill.getLevel(), skill.getHitTime(), skill.getReuseDelay()))
			else:
				player.sendPacket(sm)
			if self.isEnchantToSafe:
				if item.getEnchantLevel() < self.getSafeEnchantLevel(item):
					self.process_enchant(event, npc, player)
					# self.startQuestTimer(" ".join(["enchant"] + event), 250, npc, player, False)
		else:
			if escroll.isSafe():
				player.sendPacket(SystemMessage.sendString("強化失敗 物品強化值不變"))
				# player.sendPacket(SystemMessageId.SAFE_ENCHANT_FAILED)
				player.sendPacket(EnchantResult(5, 0, 0))
			else:
				if item.isEquipped():
					if item.getEnchantLevel() > 0:
						sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED)
						sm.addNumber(item.getEnchantLevel())
						sm.addItemName(item)
						player.sendPacket(sm)
					else:
						sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED)
						sm.addItemName(item)
						player.sendPacket(sm)
					unequiped = inv.unEquipItemInSlotAndRecord(item.getLocationSlot())
					iu = InventoryUpdate()
					for itm in unequiped:
						iu.addModifiedItem(itm)
					player.sendPacket(iu)
					player.broadcastUserInfo()
				if escroll.isBlessed():
					player.sendPacket(SystemMessageId.BLESSED_ENCHANT_FAILED)
					if self.canEnchantZero:
						item.setEnchantLevel(0)
					item.updateDatabase()
					player.sendPacket(EnchantResult(3, 0, 0))
				else:
					if self.canDestory:
						crystalId = item.getItem().getCrystalItemId()
						count = item.getCrystalCount() - ((item.getItem().getCrystalCount() + 1) / 2)
						if count < 1:
							count = 1
						destroyItem = inv.destroyItem(self.qn, item, player, None)
						if not destroyItem:
							Util.handleIllegalPlayerAction(player, "Unable to delete item on enchant failure from player " + player.getName() + ", possible cheater !", Config.DEFAULT_PUNISH);
							player.sendPacket(EnchantResult(2, 0, 0))
						crystals = None
						if crystalId:
							crystals = inv.addItem(self.qn, crystalId, count, player, destroyItem)
							sm = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S)
							sm.addItemName(crystals)
							sm.addItemNumber(count)
							player.sendPacket(sm)
						iu = InventoryUpdate()
						if destroyItem.getCount():
							iu.addModifiedItem(destroyItem)
						else:
							iu.addRemovedItem(destroyItem)
						if crystalId and crystals:
							iu.addItem(crystals)
						player.sendPacket(iu)
						L2World.getInstance().removeObject(destroyItem)
						if crystalId:
							player.sendPacket(EnchantResult(1, crystalId, count))
						else:
							player.sendPacket(EnchantResult(4, 0, 0))
					elif self.canEnchantZero:
						player.sendPacket(SystemMessage.sendString("強化失敗 物品強化值變為0"))
						item.setEnchantLevel(0)
						item.updateDatabase()
						player.sendPacket(EnchantResult(3, 0, 0))
					else:
						player.sendPacket(SystemMessage.sendString("強化失敗 物品強化值不變"))
						# player.sendPacket(SystemMessageId.SAFE_ENCHANT_FAILED)
						player.sendPacket(EnchantResult(5, 0, 0))
		su = StatusUpdate(player)
		su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad())
		player.sendPacket(su)
		
		player.sendPacket(ItemList(player, False));
		player.broadcastUserInfo()
		player.setActiveEnchantItem(None)
예제 #3
0
	def list_item(self, event, npc, player):
		def isValid(item):
			renPart = [L2Item.SLOT_NECK, L2Item.SLOT_R_EAR, L2Item.SLOT_L_EAR, L2Item.SLOT_LR_EAR, L2Item.SLOT_R_FINGER, L2Item.SLOT_L_FINGER, L2Item.SLOT_LR_FINGER]
			if not item.isEnchantable(): return False
			if not item.isEquipable(): return False
			ct = item.getItem().getCrystalType()
			for e in event:
				if e == "+wp" and not item.isWeapon(): return False
				if e == "+am" and not item.isArmor(): return False
				if e == "+ren":
					bp = item.getItem().getBodyPart()
					if not bp in renPart: return False
				if e == "-ren":
					bp = item.getItem().getBodyPart()
					if bp in renPart: return False
				if e == "+gn" and not ct == L2Item.CRYSTAL_NONE: return False
				if e == "+gd" and not ct == L2Item.CRYSTAL_D: return False
				if e == "+gc" and not ct == L2Item.CRYSTAL_C: return False
				if e == "+gb" and not ct == L2Item.CRYSTAL_B: return False
				if e == "+ga" and not ct == L2Item.CRYSTAL_A: return False
				if e == "+gs" and not ct in [L2Item.CRYSTAL_S,L2Item.CRYSTAL_S80,L2Item.CRYSTAL_S84]: return False
				if e == "+gr" and not ct in [L2Item.CRYSTAL_R,L2Item.CRYSTAL_R95,L2Item.CRYSTAL_R99]: return False
				if not e[0] in ["+", "-"] and not e in self.itemNameTable.getName(item.getItemId()): return False
			if item.isWeapon() and item.getEnchantLevel() >= self.maxWpEnchantLevel: return False
			if item.isArmor():
				if item.getItem().getBodyPart() in renPart:
					if item.getEnchantLevel() >= self.maxRenEnchantLevel: return False
				else:
					if item.getEnchantLevel() >= self.maxAmEnchantLevel: return False
			return True
			
		list_command = " ".join(["list"] + event)
		e_scroll = self.getEnchantScroll(player)
		r = ""
		for item in [x for x in player.getInventory().getItems() if isValid(x)]:
			eit = EnchantItemTable.getInstance()
			r3 = ""
			for e in [x for x in e_scroll]:
				tscroll = eit.getEnchantScroll(e)
				if tscroll == None or not tscroll.isValid(item, None): continue
				tempChance = self.getChance(e, item)
				if tempChance < 1: continue
				desc = "%d%%<BR1>(%d)" % (tempChance, e.getCount())
				r3 += "<td><img src=%(icon)s width=32 height=32><a action=\"bypass -h Quest %(qn)s enchant %(item)d %(scroll)d%(sepa)s%(list_command)s\">%(desc)s</a></td>" % {"qn":self.qn, "icon":e.getItem().getIcon(), "item":item.getObjectId(), "scroll":e.getObjectId(), "sepa":self.command_split_char, "desc":desc, "list_command":list_command}
			if len(r3) < 1:
				continue
			r2 = ""
			r2 += "<tr>"
			r2 += "<td height=34><img src=%(icon)s width=32 height=32></td>" % {"icon":item.getItem().getIcon()}
			enchance_string = ""
			enchantLevel = item.getEnchantLevel()
			if enchantLevel:
				enchance_string = "<font color=b09b79>+" + str(enchantLevel) + " </font>"
			addname = self.itemNameTable.getAddName(item.getItemId())
			if len(addname):
				addname = " <font color=ffd969>" + addname + " </font>"
			r2 += "<td>%(enchance)s%(name)s<br1>%(addname)s</td>" % {"name":self.itemNameTable.getName(item.getItemId()), "enchance":enchance_string, "addname":addname}
			r2 += r3
			r2 += "</tr>"
			r += r2
		if r == "":
			return self.htm_header + "沒有對應強化卷軸之物品" + self.htm_footer
		r = "<table>" + r + "</table>"
		if len(r) > 17249: #大約數
			r = "可強化列表過長 請減少身上可強化物品後再使用"
		return self.htm_header + r + self.htm_footer