Jump to content
  • 0

Question

Posted

Hello, everyone. I’m currently restoring the old enchantment system of aCis, but I have a question: some items in my inventory are not updating when I use enchantment as an administrator. This issue occurs only with earrings and rings; after enchanting, the values don’t update automatically only when I open and close the inventory. Does anyone know how I can fix this?

I use aCis 409 free version

 

package net.sf.l2j.gameserver.handler.admincommandhandlers;

import net.sf.l2j.gameserver.data.SkillTable;
import net.sf.l2j.gameserver.data.xml.ArmorSetData;
import net.sf.l2j.gameserver.enums.Paperdoll;
import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
import net.sf.l2j.gameserver.model.WorldObject;
import net.sf.l2j.gameserver.model.actor.Player;
import net.sf.l2j.gameserver.model.item.ArmorSet;
import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
import net.sf.l2j.gameserver.model.item.kind.Armor;
import net.sf.l2j.gameserver.model.item.kind.Item;
import net.sf.l2j.gameserver.model.item.kind.Weapon;
import net.sf.l2j.gameserver.network.serverpackets.SkillList;
import net.sf.l2j.gameserver.skills.L2Skill;

public class AdminEnchant implements IAdminCommandHandler
{
	private static final String[] ADMIN_COMMANDS =
	{
		"admin_seteh", // 6
		"admin_setec", // 10
		"admin_seteg", // 9
		"admin_setel", // 11
		"admin_seteb", // 12
		"admin_setew", // 7
		"admin_setes", // 8
		"admin_setle", // 1
		"admin_setre", // 2
		"admin_setlf", // 4
		"admin_setrf", // 5
		"admin_seten", // 3
		"admin_setun", // 0
		"admin_setba", // 13
		"admin_enchant"
	};
	
	@Override
	public void useAdminCommand(String command, Player player)
	{
		if (command.equals("admin_enchant"))
			showMainPage(player);
		else
		{
			int armorType = -1;
			
			if (command.startsWith("admin_seteh"))
				armorType = Item.SLOT_HEAD;
			else if (command.startsWith("admin_setec"))
				armorType = Item.SLOT_CHEST;
			else if (command.startsWith("admin_seteg"))
				armorType = Item.SLOT_GLOVES;
			else if (command.startsWith("admin_seteb"))
				armorType = Item.SLOT_FEET;
			else if (command.startsWith("admin_setel"))
				armorType = Item.SLOT_LEGS;
			else if (command.startsWith("admin_setew"))
				armorType = Item.SLOT_R_HAND;
			else if (command.startsWith("admin_setes"))
				armorType = Item.SLOT_L_HAND;
			else if (command.startsWith("admin_setle"))
				armorType = Item.SLOT_L_EAR;
			else if (command.startsWith("admin_setre"))
				armorType = Item.SLOT_R_EAR;
			else if (command.startsWith("admin_setlf"))
				armorType = Item.SLOT_L_FINGER;
			else if (command.startsWith("admin_setrf"))
				armorType = Item.SLOT_R_FINGER;
			else if (command.startsWith("admin_seten"))
				armorType = Item.SLOT_NECK;
			else if (command.startsWith("admin_setun"))
				armorType = Item.SLOT_UNDERWEAR;
			else if (command.startsWith("admin_setba"))
				armorType = Item.SLOT_BACK;
			
			if (armorType != -1)
			{
				try
				{
					int ench = Integer.parseInt(command.substring(12));
					
					// check value
					if (ench < 0 || ench > 65535)
						player.sendMessage("You must set the enchant level to be between 0-65535.");
					else
						setEnchant(player, ench, armorType);
				}
				catch (Exception e)
				{
					player.sendMessage("Please specify a new enchant value.");
				}
			}
			
			// show the enchant menu after an action
			showMainPage(player);
		}
		
		return;
	}
	
	/**
	 * @param activeChar
	 * @param enchant
	 * @param armorType
	 */
	private static void setEnchant(Player activeChar, int enchant, int armorType)
	{
		WorldObject target = activeChar.getTarget();
		if (!(target instanceof Player))
			target = activeChar;
		
		final Player player = (Player) target;
		
		final ItemInstance item = player.getInventory().getItemFrom(armorType);
		if (item == null)
		{
			player.sendMessage(player.getName() + " doesn't wear any item in " + armorType + " slot.");
			return;
		}
		
		final Item it = item.getItem();
		final int oldEnchant = item.getEnchantLevel();
		
		// Do nothing if both values are the same.
		if (oldEnchant == enchant)
		{
			player.sendMessage(player.getName() + "'s " + it.getName() + " enchant is already set to " + enchant + ".");
			return;
		}
		
		item.setEnchantLevel(enchant, player);
		
		// If item is equipped, verify the skill obtention/drop (+4 duals, +6 armorset).
		if (item.isEquipped())
		{
			final int currentEnchant = item.getEnchantLevel();
			
			// Skill bestowed by +4 duals.
			if (it instanceof Weapon)
			{
				// Old enchant was >= 4 and new is lower : we drop the skill.
				if (oldEnchant >= 4 && currentEnchant < 4)
				{
					final L2Skill enchant4Skill = ((Weapon) it).getEnchant4Skill();
					if (enchant4Skill != null)
					{
						player.removeSkill(enchant4Skill.getId(), false);
						player.sendPacket(new SkillList(player));
					}
				}
				// Old enchant was < 4 and new is 4 or more : we add the skill.
				else if (oldEnchant < 4 && currentEnchant >= 4)
				{
					final L2Skill enchant4Skill = ((Weapon) it).getEnchant4Skill();
					if (enchant4Skill != null)
					{
						player.addSkill(enchant4Skill, false);
						player.sendPacket(new SkillList(player));
					}
				}
			}
			// Add skill bestowed by +6 armorset.
			else if (it instanceof Armor)
			{
				// Old enchant was >= 6 and new is lower : we drop the skill.
				if (oldEnchant >= 6 && currentEnchant < 6)
				{
					// Check if player is wearing a chest item.
					final int itemId = player.getInventory().getItemIdFrom(Paperdoll.CHEST);
					if (itemId > 0)
					{
						final ArmorSet armorSet = ArmorSetData.getInstance().getSet(itemId);
						if (armorSet != null)
						{
							final int skillId = armorSet.getEnchant6skillId();
							if (skillId > 0)
							{
								player.removeSkill(skillId, false);
								player.sendPacket(new SkillList(player));
							}
						}
					}
				}
				// Old enchant was < 6 and new is 6 or more : we add the skill.
				else if (oldEnchant < 6 && currentEnchant >= 6)
				{
					// Check if player is wearing a chest item.
					final int itemId = player.getInventory().getItemIdFrom(Paperdoll.CHEST);
					if (itemId > 0)
					{
						final ArmorSet armorSet = ArmorSetData.getInstance().getSet(itemId);
						if (armorSet != null && armorSet.isEnchanted6(player)) // has all parts of set enchanted to 6 or more
						{
							final int skillId = armorSet.getEnchant6skillId();
							if (skillId > 0)
							{
								final L2Skill skill = SkillTable.getInstance().getInfo(skillId, 1);
								if (skill != null)
								{
									player.addSkill(skill, false);
									player.sendPacket(new SkillList(player));
								}
							}
						}
					}
				}
			}
		}
		
		player.broadcastUserInfo();	
		player.sendMessage(player.getName() + "'s " + it.getName() + " enchant was modified from " + oldEnchant + " to " + enchant + ".");
	}
	
	
	private void showMainPage(Player activeChar)
	{
		sendFile(activeChar, "enchant.htm");
	}
	
	@Override
	public String[] getAdminCommandList()
	{
		return ADMIN_COMMANDS;
	}
}

 

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...