Jump to content

[Share] H5 Npc Enchant Manager V2 /*java*/


HappyLDE

Recommended Posts

dude

imports... -.-'

I know that, but others don't as you see.. :P You ask them to show the error, given line where is error and they don't get it and they give you random shit.. It's really frustrating sometimes.. :D

Link to comment
Share on other sites

this code is hardcode.

 

the html is better to define them as such and not within the code.

 

execution times is better to write this as follows

        String html = "<html>"+                        "<title>L2Mondial Enchanter</title>"+
                        "<body>"+
                            "<center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>"+
                            "<font color=\"FF9900\">" + title + "</font></center><br>"+
                            content +
                            "<br><br>"+
                            "<center><a action=\"bypass -h Quest Enchant " + enchantType + "\">Go Back</a></center>"+
                        "</body>"+
                        "</html>";


        return html;
 
TextBuilder _td = new TextBuilder();
_td.append("<html>");
        _td.append("<title>L2Mondial Enchanter</title>");
        _td.append("<body>");
        _td.append("<center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>");
        _td.append("<font color=\"FF9900\">" + title + "</font></center><br>" + content + "<br><br>");
        _td.append("<center><a action=\"bypass -h Quest Enchant " + enchantType + "\">Go Back</a></center>");
        _td.append("</body>");
        _td.append("</html>");


        return _td.toString();
Link to comment
Share on other sites

 

    int npcId = 9994;
 
    // Item required to enchant armor +1
    int itemRequiredArmor = 6393;
    int itemRequiredArmorCount = 50;
 
    // Item required to enchant jewels +1
    int itemRequiredJewels = 6393;
    int itemRequiredJewelsCount = 50;
 
    // Item required to enchant weapon +1
    int itemRequiredWeapon = 6393;
    int itemRequiredWeaponCount = 150;
 
    // Item required to enchant belt/shirt +1
    int itemRequiredBeltShirt = 6393;
    int itemRequiredBeltShirtCount = 100;
 
all should be private final static
 
Overall a cool code, but imo its very poor

 

 

Disagree, the variables in this class are only being accessed by it's own class/itself. It is not being called by any other outside class or instance.

 

Why would you want to make all the variables global? This will keep them in memory even when this instance/class is unloaded/not in use.

 

Having them as non static, dynamic, will only access them and keep them in memory while the instance of that class is still being used/in memory.

 

You should only use static methods/variables etc when you need to access them from other classes/instances, and dont need to initiate a new instance of the class holding the needed variables/methods. Hope I explained it well, try the example program and you should see.

 

They Should be -> private final int

 

Example:

void main(){
{
dynamic int a = 1;
static int b = 1;
}
// a deleted from memory but b still is there
cout << b;
cout << a; // error occured because a deleted
} 
Edited by MlDNlGHT
Link to comment
Share on other sites

 

Disagree, the variables in this class are only being accessed by it's own class/itself. It is not being called by any other outside class or instance.

 

Why would you want to make all the variables global? This will keep them in memory even when this instance/class is unloaded/not in use.

 

Having them as non static, dynamic, will only access them and keep them in memory while the instance of that class is still being used/in memory.

 

You should only use static methods/variables etc when you need to access them from other classes/instances, and dont need to initiate a new instance of the class holding the needed variables/methods. Hope I explained it well, try the example program and you should see.

 

They Should be -> private final int

 

Example:

void main(){
{
dynamic int a = 1;
static int b = 1;
}
// a deleted from memory but b still is there
cout << b;
cout << a; // error occured because a deleted
} 

 

Good explanation and i thank you for taking the time!

Link to comment
Share on other sites

 

Disagree, the variables in this class are only being accessed by it's own class/itself. It is not being called by any other outside class or instance.

 

Why would you want to make all the variables global? This will keep them in memory even when this instance/class is unloaded/not in use.

 

Having them as non static, dynamic, will only access them and keep them in memory while the instance of that class is still being used/in memory.

 

You should only use static methods/variables etc when you need to access them from other classes/instances, and dont need to initiate a new instance of the class holding the needed variables/methods. Hope I explained it well, try the example program and you should see.

 

They Should be -> private final int

 

Example:

void main(){
{
dynamic int a = 1;
static int b = 1;
}
// a deleted from memory but b still is there
cout << b;
cout << a; // error occured because a deleted
} 

 

 

it should be static since the variable belongs to the class and not neceserly to the object, just like config variables... Static variables have better perfomance than non-static, for example they are faster.

I find no reason for them to be nonstatic since I see no OOP here

 

However I will neither argue with you, your argument is valid, since the "perfomance" while alocating memory is nowaday useless due to the modern JVMs

Edited by xdem
Link to comment
Share on other sites

Error. Help. http://postimg.org/image/r28k0kbw1/ For all items he say is no't encantable!!!

Here is the code what i make for freya. Some help plz thx

 

package custom.Enchant;
 
import java.util.logging.Logger;
 
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.itemcontainer.Inventory;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.olympiad.OlympiadManager;
import com.l2jserver.gameserver.model.quest.Quest;
import com.l2jserver.gameserver.model.quest.QuestState;
import com.l2jserver.gameserver.network.serverpackets.CharInfo;
import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
import com.l2jserver.gameserver.network.serverpackets.UserInfo;
 
public class Enchant extends Quest
{
    public static final Logger _log = Logger.getLogger(Enchant.class.getName());
 
    private final static int npcId = 9994;
 
    // Item required to enchant armor +1
    private final static int itemRequiredArmor = 6393;
    private final static int itemRequiredArmorCount = 50;
 
    // Item required to enchant jewels +1
    private final static int itemRequiredJewels = 6393;
    private final static int itemRequiredJewelsCount = 50;
 
    // Item required to enchant weapon +1
    private final static int itemRequiredWeapon = 6393;
    private final static int itemRequiredWeaponCount = 150;
 
    // Item required to enchant belt/shirt +1
    private final static int itemRequiredBeltShirt = 6393;
    private final static int itemRequiredBeltShirtCount = 100;
 
    public Enchant(int questId, String name, String descr)
    {
        super(questId, name, descr);
       
        addStartNpc(npcId);
        addFirstTalkId(npcId);
        addTalkId(npcId);
    }
    
    public static void main(String[] args)
    {
        new Enchant(-1, Enchant.class.getSimpleName(), "custom");
    }
    
    public String onFirstTalk(L2Npc npc, L2PcInstance player)
    {
        String enchantType = "Enchant.htm";
 
        if (player.getQuestState(getName()) == null)
        {
            newQuestState(player);
        }
        else if (player.isInCombat())
        {
            return drawHtml("You are in combat", "Don't fight if you want to talk with me!", enchantType);
        }
        else if (player.getPvpFlag() == 1)
        {
            return drawHtml("You are flagged", "Don't fight if you want to talk with me!", enchantType);
        }
        else if (player.getKarma() != 0)
        {
            return drawHtml("You are in chaotic state", "Don't fight if you want to talk with me!", enchantType);
        }
        else if (OlympiadManager.getInstance().isRegistered(player))
        {
            return drawHtml("You are registered for Olympiad", "You can't use my services<br1>while playing the Olympiad.", enchantType);
        }
 
        return "Enchant.htm";
    }
 
    public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
    {
        String htmlText = event;
 
        String enchantType = "Enchant.htm";
 
        int armorType = -1;
 
        // Armor parts
        if (event.equals("enchantHelmet"))
        {
            armorType = Inventory.PAPERDOLL_HEAD;
            enchantType = "EnchantArmor.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        else if (event.equals("enchantChest"))
        {
            armorType = Inventory.PAPERDOLL_CHEST;
            enchantType = "EnchantArmor.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        else if (event.equals("enchantLeggings"))
        {
            armorType = Inventory.PAPERDOLL_LEGS;
            enchantType = "EnchantArmor.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        else if (event.equals("enchantGloves"))
        {
            armorType = Inventory.PAPERDOLL_GLOVES;
            enchantType = "EnchantArmor.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        else if (event.equals("enchantBoots"))
        {
            armorType = Inventory.PAPERDOLL_FEET;
            enchantType = "EnchantArmor.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        else if (event.equals("enchantShieldOrSigil"))
        {
            armorType = Inventory.PAPERDOLL_LHAND;
            enchantType = "EnchantArmor.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredArmor, itemRequiredArmorCount);
        }
        // Jewels
        else if (event.equals("enchantUpperEarring"))
        {
            armorType = Inventory.PAPERDOLL_LEAR;
            enchantType = "EnchantJewels.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredJewels, itemRequiredJewelsCount);
        }
        else if (event.equals("enchantLowerEarring"))
        {
            armorType = Inventory.PAPERDOLL_REAR;
            enchantType = "EnchantJewels.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredJewels, itemRequiredJewelsCount);
        }
        else if (event.equals("enchantNecklace"))
        {
            armorType = Inventory.PAPERDOLL_NECK;
            enchantType = "EnchantJewels.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredJewels, itemRequiredJewelsCount);
        }
        else if (event.equals("enchantUpperRing"))
        {
            armorType = Inventory.PAPERDOLL_LFINGER;
            enchantType = "EnchantJewels.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredJewels, itemRequiredJewelsCount);
        }
        else if (event.equals("enchantLowerRing"))
        {
            armorType = Inventory.PAPERDOLL_RFINGER;
            enchantType = "EnchantJewels.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredJewels, itemRequiredJewelsCount);
        }
        // Belt/Shirt
        else if (event.equals("enchantBelt"))
        {
            armorType = Inventory.PAPERDOLL_BELT;
            enchantType = "EnchantBeltShirt.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredBeltShirt, itemRequiredBeltShirtCount);
        }
        else if (event.equals("enchantShirt"))
        {
            armorType = Inventory.PAPERDOLL_UNDER;
            enchantType = "EnchantBeltShirt.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredBeltShirt, itemRequiredBeltShirtCount);
        }
        // Weapon
        else if (event.equals("enchantWeapon"))
        {
            armorType = Inventory.PAPERDOLL_RHAND;
            enchantType = "EnchantWeapon.htm";
            
            htmlText = enchant(enchantType, player, armorType, itemRequiredWeapon, itemRequiredWeaponCount);
        }
 
        return htmlText;
    }
 
    private String enchant(String enchantType, L2PcInstance player, int armorType, int itemRequired, int itemRequiredCount)
    {
        QuestState st = player.getQuestState(getName());
 
        int currentEnchant = 0;
        int newEnchantLevel = 0;
 
        if (st.getQuestItemsCount(itemRequired) >= itemRequiredCount)
        {
            try
            {
                L2ItemInstance item = getItemToEnchant(player, armorType);
 
                if (item != null)
                {
                    if ( item.isCommonItem() && item.isEquipable() && !item.isConsumable() && !item.isCommonItem() && !item.isOlyRestrictedItem() && !item.isShadowItem() && !item.isQuestItem() )
                    {
                        currentEnchant = item.getEnchantLevel();
 
                        if ( currentEnchant < 20 )
                        {
                            newEnchantLevel = setEnchant(player, item, currentEnchant+1, armorType);
 
                            if ( newEnchantLevel > 0 )
                            {
                                st.takeItems(itemRequired, itemRequiredCount);
                                player.sendMessage("You successfully enchanted your " + item.getItem().getName() +" from +" + currentEnchant + " to +" + newEnchantLevel + "!");
 
                                String htmlContent = "<center>You successfully enchanted your:<br>"+
                                                        "<font color=\"FF7200\">" + item.getItem().getName() + "</font><br>"+
                                                        "From: <font color=\"AEFF00\">+" + currentEnchant + "</font> to <font color=\"AEFF00\">+" + newEnchantLevel + "</font>"+
                                                    "</center>";
 
                                return drawHtml("Congratulations!", htmlContent, enchantType);
                            }
                        }
                        else
                        {
                            player.sendMessage("Your " + item.getItem().getName() + " is already +20!");
                            return drawHtml("It's already +20", "<center>Your <font color=\"FF7200\">" + item.getItem().getName() +"</font> is already +20!</center>", enchantType);
                        }
                    }
                    else
                    {
                        player.sendMessage("Your " + item.getItem().getName() + " is not enchantable!");
                        return drawHtml("Not enchantable item!", "<center>Your <font color=\"FF7200\">" + item.getItem().getName() +"</font> is not enchantable!</center>", enchantType);
                    }
                }
            }
            catch (StringIndexOutOfBoundsException e)
            {
                player.sendMessage("Something went wrong. Are equiped with the item?");
                return drawHtml("Error Enchant", "<center>Something went wrong.<br>Are equiped with the item?</center>", enchantType);
            }
            catch (NumberFormatException e)
            {
                player.sendMessage("Something went wrong. Are equiped with the item?");
                return drawHtml("Error Enchant", "<center>Something went wrong.<br>Are equiped with the item?</center>", enchantType);
            }
 
 
            player.sendMessage("Something went wrong. Are equiped with the item?");
            return drawHtml("Error Enchant", "<center>Something went wrong.<br>Are equiped with the item?</center>", enchantType);
        }
        else
        {
            String content = "<center>"+
                                "Not enough <font color=\"FF7200\">Event - Glitering Medals</font>!<br>";
 
                    if ( st.getQuestItemsCount(itemRequired) > 0 )
                    {
                        content += "You have " + st.getQuestItemsCount(itemRequired) + " Glittering Medals,<br1>"+
                                    "Need " + (itemRequiredCount - st.getQuestItemsCount(itemRequired)) + " more.";
                    }
                    else
                    {
                        content += "You need <font color=\"FF7200\">" + itemRequiredCount + " Event - Glitering Medals</font>!";
                    }
 
                    content += "</center>";
 
            return drawHtml("Not Enough Items", content, enchantType);
        }
    }
 
    private L2ItemInstance getItemToEnchant(L2PcInstance player, int armorType)
    {
        L2ItemInstance itemInstance = null;
        L2ItemInstance parmorInstance = player.getInventory().getPaperdollItem(armorType);
 
        if ((parmorInstance != null) && (parmorInstance.getLocationSlot() == armorType))
        {
            itemInstance = parmorInstance;
 
            if (itemInstance != null)
            {
                return itemInstance;
            }
        }
 
        return null;
    }
 
    private int setEnchant(L2PcInstance player, L2ItemInstance item, int newEnchantLevel, int armorType)
    {
        if (item != null)
        {
            // set enchant value
            player.getInventory().unEquipItemInSlot(armorType);
            item.setEnchantLevel(newEnchantLevel);
            player.getInventory().equipItem(item);
            
            // send packets
            InventoryUpdate iu = new InventoryUpdate();
            iu.addModifiedItem(item);
            player.sendPacket(iu);
            player.broadcastPacket(new CharInfo(player));
            player.sendPacket(new UserInfo(player));
            player.broadcastPacket(new ExBrExtraUserInfo(player));
 
            return newEnchantLevel;
        }
 
        return -1;
    }
 
    public String drawHtml(String title, String content, String enchantType)
    {
        String html = "<html>"+
                        "<title>L2Mondial Enchanter</title>"+
                        "<body>"+
                            "<center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>"+
                            "<font color=\"FF9900\">" + title + "</font></center><br>"+
                            content +
                            "<br><br>"+
                            "<center><a action=\"bypass -h Quest Enchant " + enchantType + "\">Go Back</a></center>"+
                        "</body>"+
                        "</html>";
 
        return html;
    }
}
Link to comment
Share on other sites


-- if ( item.isCommonItem() && item.isEquipable() && !item.isConsumable() && !item.isCommonItem() && !item.isOlyRestrictedItem() && !item.isShadowItem() && !item.isQuestItem() )

++ if ( item.isEquipable() && !item.isConsumable() && !item.isCommonItem() && !item.isOlyRestrictedItem() && !item.isShadowItem() && !item.isQuestItem() )

 

Edited by HappyLDE
Link to comment
Share on other sites

  • 2 weeks later...

it should be static since the variable belongs to the class and not neceserly to the object, just like config variables... Static variables have better perfomance than non-static, for example they are faster.

I find no reason for them to be nonstatic since I see no OOP here

 

However I will neither argue with you, your argument is valid, since the "perfomance" while alocating memory is nowaday useless due to the modern JVMs

 

It doesn't make 1 ioata of a difference if they belong to the class or the object, in the same class. All the objects in that class are in that class. It would make a difference if the objects are in a different class.

 

As for faster processing , I would sacrafic a few ms loading/processing time for less total memory usage of the entire application.  I don't believe the "change off" is worth it.

 

Guess it's all about one's coding style..

Edited by MlDNlGHT
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

Hello,

I tried using your updated enchant manager npc (V2) in my H5 server but keep getting this L2ItemInstance error. I haven't changed any of your code.

 

post-135436-0-69473800-1388430360_thumb.png

 

I haven't got much experience with this and am still trying to learn, any help would be appreciated :D

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.



×
×
  • Create New...