Jump to content

Color Name - Title & Skill system with xml


Recommended Posts

Color name - title system + Skill Reward coded on 374 acis . cheers

 

package net.sf.l2j.gameserver.datatables;

import net.sf.l2j.gameserver.templates.L2Pvp;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import net.sf.l2j.gameserver.model.holder.IntIntHolder;
import net.sf.l2j.gameserver.templates.StatsSet;
import net.sf.l2j.gameserver.xmlfactory.XMLDocumentFactory;
import org.w3c.dom.*;

public class PvpTable
{

    public PvpTable()
    {
    }
    
    public static void load()
    {
        try
        {
            File f = new File("./data/xml/pvp.xml");
            Document doc = XMLDocumentFactory.getInstance().loadDocument(f);
            Node n = doc.getFirstChild();
            for(Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
                if(d.getNodeName().equalsIgnoreCase("template"))
                {
                    NamedNodeMap attrs = d.getAttributes();
                    int pvpAmount = Integer.valueOf(attrs.getNamedItem("pvp_amount").getNodeValue()).intValue();
                    int nameColor = Integer.decode((new StringBuilder()).append("0x").append(attrs.getNamedItem("name_color").getNodeValue()).toString()).intValue();
                    int titleColor = Integer.decode((new StringBuilder()).append("0x").append(attrs.getNamedItem("title_color").getNodeValue()).toString()).intValue();
                    String learnSkill = attrs.getNamedItem("learn_skill").getNodeValue().trim();
                    StatsSet set = new StatsSet();
                    set.set("pvp_amount", pvpAmount);
                    set.set("name_color", nameColor);
                    set.set("title_color", titleColor);
                    L2Pvp template = new L2Pvp(set);
                    if(learnSkill != null)
                    {
                        String property[] = learnSkill.split(";");
                        String as[] = property;
                        int i = as.length;
                        for(int j = 0; j < i; j++)
                        {
                            String data = as[j];
                            String holder[] = data.split(",");
                            template.addLearnSkill(new IntIntHolder(Integer.parseInt(holder[0]), Integer.parseInt(holder[1])));
                        }

                    }
                    _templates.add(template);
                }

        }
        catch(Exception e)
        {
            _log.severe((new StringBuilder()).append("Exception: PvpTable load: ").append(e).toString());
        }
        _log.info((new StringBuilder()).append("PvpTable: Loaded ").append(_templates.size()).append(" template(s).").toString());
    }

    public static List<L2Pvp> getTemplate()
    {
        return _templates;
    }

    private static final Logger _log = Logger.getLogger(PvpTable.class.getName());
    private static final List<L2Pvp> _templates = new ArrayList<>();

}

 

 

 

package net.sf.l2j.gameserver.templates;

import java.util.ArrayList;
import java.util.List;
import net.sf.l2j.gameserver.model.holder.IntIntHolder;
import net.sf.l2j.gameserver.templates.StatsSet;

public class L2Pvp
{

    public L2Pvp(StatsSet set)
    {
        _pvpAmount = set.getInteger("pvp_amount");
        _nameColor = set.getInteger("name_color");
        _titleColor = set.getInteger("title_color");
    }

    public int getPvpAmount()
    {
        return _pvpAmount;
    }

    public int getNameColor()
    {
        return _nameColor;
    }

    public int getTitleColor()
    {
        return _titleColor;
    }

    public List<IntIntHolder> getLearnSkills()
    {
        return _learnSkill;
    }

    public void addLearnSkill(IntIntHolder holder)
    {
        _learnSkill.add(holder);
    }

    private final int _pvpAmount;
    private final int _nameColor;
    private final int _titleColor;
    private final List<IntIntHolder> _learnSkill = new ArrayList<>();
}

 

Open : Gameserver.java
add somewhere this PvpTable.load();

Open : Player.java
add somewhere this

    public static void updatePvp(Player player)
    {
        for(Iterator<L2Pvp> iterator = PvpTable.getTemplate().iterator(); iterator.hasNext();)
        {
            L2Pvp template = iterator.next();
            if(template.getPvpAmount() <= player.getPvpKills())
            {
                player.getAppearance().setNameColor(template.getNameColor());
                player.getAppearance().setTitleColor(template.getTitleColor());
                Iterator<IntIntHolder> iterator1 = template.getLearnSkills().iterator();
                while(iterator1.hasNext()) 
                {
                    IntIntHolder holder = iterator1.next();
                    net.sf.l2j.gameserver.model.L2Skill skill = SkillTable.getInstance().getInfo(holder.getId(), holder.getValue());
                    if(skill != null)
                        player.addSkill(skill, false);
                }
            }
        }

        player.broadcastUserInfo();
    }

find in Player.java
below this line setPvpKills(getPvpKills() + 1);  add ->  updatePvp(this);

find  : public boolean setActiveClass(int classIndex)
under this line  restoreSkills(); add - > updatePvp(this);

find : public void onPlayerEnter() add somewhere under : updatePvp(this);

XML

loc : data/xml/pvp.xml

<?xml version='1.0' encoding='utf-8'?>
<list>
	<!-- <template pvp_amount="100" name_color="FFAA00" title_color="FFFF77" learn_skill="0,0;" /> -->
		<template pvp_amount="5" name_color="FFAA00" title_color="FFFF77" learn_skill="0,0;" />
</list>

 

Edited by Kishin
  • Thanks 1
Link to comment
Share on other sites

  • 4 months later...
  • 2 months later...

Wouldn't it be better to have a simple config location, where you would specify the different pvp's and pk's as follows?:

ExampleSystemPvPs = 300,00ff00;

300 is the amount of pvp's you need and then the colour in Hexa. This is what I've personally done to make it easier, rather than reading an XML code.

Link to comment
Share on other sites

On 1/14/2020 at 1:47 AM, xFranky said:

Wouldn't it be better to have a simple config location, where you would specify the different pvp's and pk's as follows?:

ExampleSystemPvPs = 300,00ff00;

300 is the amount of pvp's you need and then the colour in Hexa. This is what I've personally done to make it easier, rather than reading an XML code.

why running the code all over than have it catched? though this one not just rewards color name or title but skill reward aswell , also its more readable than 123,ff0000;1234,ff01234

you can add and do w/e you want with the templates ->

<list>
       <template pvp_amount="50" name_color="FFAA00" title_color="FFFF00" learn_skill="0,0;" />
       <template pvp_amount="100" name_color="FF0000" title_color="FFAA00" learn_skill="2106,1;" />
       <template pvp_amount="150" name_color="FF0000" title_color="FFFFAA" learn_skill="0,0;" />
</list>

 

Edited by Kishin
Link to comment
Share on other sites

11 hours ago, Kishin said:

why running the code all over than have it catched? though this one not just rewards color name or title but skill reward aswell , also its more readable than 123,ff0000;1234,ff01234

you can add and do w/e you want with the templates ->


<list>
       <template pvp_amount="50" name_color="FFAA00" title_color="FFFF77" learn_skill="0,0;" />
       <template pvp_amount="100" name_color="FF0000" title_color="FFAA00" learn_skill="2106,1;" />
       <template pvp_amount="100" name_color="FF00AA" title_color="FFAAAA" learn_skill="2107,1;" />
</list>

 

In my opinion, it takes extra time to read an extra XML file, rather than a config file that is read already, and adds extra space to the memory just to hold the data of the XML. Also, you could have separated the pvp kills with the name colours, and the PK kills with the title colours, and have your extra Skills. I do not believe that anyone would create a server for extra kills, just to make their character stronger and increase their penetration. You have to create extra skills for the characters, which requires l2 client knowledge in order to get this right. Finally, I believe that this could have happened a lot quicker and easier, with less lines of code, rather than doing it with the way you attempted. 

 

What I suggested is just an opinion and is not meant to judge you, or you as a programmer or your work. I believe you have done a great job bringing this code for the community and I hope I see more shares from you like this one. I will be releasing my personal version of this system, so you are welcome to judge me and suggest your own opinion.

Link to comment
Share on other sites

  • 1 year later...

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
Reply to this topic...

×   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...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock