Jump to content

Recommended Posts

Posted (edited)

Long time since i shared something. I made this code in 10 minute. It's a Procedural PvP reward system which you can extend

and add anything you like. Basically each time a player get a PvP, system check if he can get any reward (Item, Color, Skill) and reward him.

 

It has protection to avoid duplicated rewards in case he reduce his PvP and repeat the procedure. 

 

Index: java/kara/PvPData.java
===================================================================
--- java/kara/PvPData.java	(revision 0)
+++ java/kara/PvPData.java	(revision 0)
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2004-2018 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package kara;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import com.l2jserver.Config;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.model.variables.PlayerVariables;
+import com.l2jserver.util.data.xml.IXmlReader;
+
+import kara.model.PEvent;
+import kara.model.events.PvPColor;
+import kara.model.events.PvPReward;
+import kara.model.events.PvPSkill;
+
+/**
+ * @author Kara`
+ */
+public class PvPData implements IXmlReader
+{
+	final Map<Integer, List<PEvent>> HOLDER = new HashMap<>();
+	
+	public PvPData()
+	{
+		load();
+	}
+	
+	@Override
+	public void load()
+	{
+		HOLDER.clear();
+		parseDatapackFile(Config.DATAPACK_ROOT + "data/pvpData.xml");
+		LOGGER.info("[" + PvPData.class.getName() + "] Loaded " + HOLDER.size() + " holders.");
+	}
+	
+	@Override
+	public void parseDocument(Document doc)
+	{
+		for (Node d = doc.getFirstChild(); d != null; d = d.getNextSibling())
+		{
+			if (d.getNodeName().equals("list"))
+			{
+				for (Node holder = d.getFirstChild(); holder != null; holder = holder.getNextSibling())
+				{
+					if (holder.getNodeName().equals("holder"))
+					{
+						List<PEvent> list = new ArrayList<>();
+						
+						for (Node pevent = holder.getFirstChild(); pevent != null; pevent = pevent.getNextSibling())
+						{
+							NamedNodeMap attr = pevent.getAttributes();
+							
+							try
+							{
+								if (pevent.getNodeName().equals("color"))
+								{
+									list.add(new PvPColor(Integer.parseInt(attr.getNamedItem("r").getNodeValue()), Integer.parseInt(attr.getNamedItem("g").getNodeValue()), Integer.parseInt(attr.getNamedItem("b").getNodeValue())));
+								}
+								if (pevent.getNodeName().equals("item"))
+								{
+									list.add(new PvPReward(Integer.parseInt(attr.getNamedItem("id").getNodeValue()), Integer.parseInt(attr.getNamedItem("count").getNodeValue())));
+								}
+								if (pevent.getNodeName().equals("skill"))
+								{
+									list.add(new PvPSkill(Integer.parseInt(attr.getNamedItem("id").getNodeValue()), Integer.parseInt(attr.getNamedItem("level").getNodeValue())));
+								}
+							}
+							catch (Exception e)
+							{
+								e.printStackTrace();
+								continue;
+							}
+						}
+						
+						HOLDER.put(Integer.parseInt(holder.getAttributes().getNamedItem("require").getNodeValue()), list);
+					}
+				}
+			}
+		}
+	}
+	
+	/**
+	 * Check if player has any given rewards. <br>
+	 * Info: if player decreased pvp somehow he <b> wont </b> receive.
+	 * @param player
+	 */
+	public void executeEvent(L2PcInstance player)
+	{
+		PlayerVariables variables = player.getVariables();
+		
+		if (variables.getInt("lastPvP", 0) >= player.getPvpKills())
+		{
+			return;
+		}
+		
+		List<PEvent> list = HOLDER.get(player.getPvpKills());
+		
+		if (list == null)
+		{
+			return;
+		}
+		
+		variables.set("lastPvP", player.getPvpKills());
+		
+		list.forEach(s -> s.getEffect(player));
+	}
+	
+	public static PvPData getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
+	private static class SingletonHolder
+	{
+		protected static final PvPData _instance = new PvPData();
+	}
+}
\ No newline at end of file
Index: java/kara/model/PEvent.java
===================================================================
--- java/kara/model/PEvent.java	(revision 0)
+++ java/kara/model/PEvent.java	(revision 0)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2004-2018 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package kara.model;
+
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author Kara`
+ */
+public abstract class PEvent
+{
+	protected Object[] values;
+	
+	public abstract void getEffect(L2PcInstance player);
+}
Index: java/kara/model/events/PvPColor.java
===================================================================
--- java/kara/model/events/PvPColor.java	(revision 0)
+++ java/kara/model/events/PvPColor.java	(revision 0)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2004-2018 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package kara.model.events;
+
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+import kara.model.PEvent;
+
+/**
+ * @author Kara`
+ */
+public class PvPColor extends PEvent
+{
+	public PvPColor(int r, int g, int b)
+	{
+		values = new Object[3] { r, g, b };
+	}
+	
+	@Override
+	public void getEffect(L2PcInstance player)
+	{
+		player.getAppearance().setNameColor((int) values[0], (int) values[1], (int) values[2]);
+		player.broadcastUserInfo();
+	}
+}
Index: java/kara/model/events/PvPReward.java
===================================================================
--- java/kara/model/events/PvPReward.java	(revision 0)
+++ java/kara/model/events/PvPReward.java	(revision 0)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2004-2018 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package kara.model.events;
+
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+import kara.model.PEvent;
+
+/**
+ * @author Kara`
+ */
+public class PvPReward extends PEvent
+{
+	public PvPReward(int id, int count)
+	{
+		values = new Object[2]{ id, count };
+	}
+	
+	@Override
+	public void getEffect(L2PcInstance player)
+	{
+		player.addItem("Reward", (int) values[0], (int) values[1], player, true);
+	}
+}
Index: java/kara/model/events/PvPSkill.java
===================================================================
--- java/kara/model/events/PvPSkill.java	(revision 0)
+++ java/kara/model/events/PvPSkill.java	(revision 0)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2004-2018 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package kara.model.events;
+
+import com.l2jserver.gameserver.datatables.SkillData;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.model.skills.Skill;
+
+import kara.model.PEvent;
+
+/**
+ * @author Kara`
+ */
+public class PvPSkill extends PEvent
+{
+	public PvPSkill(int id, int level)
+	{
+		values = new Object[2] { id, level };
+	}
+
+	@Override
+	public void getEffect(L2PcInstance player)
+	{
+		Skill skill = SkillData.getInstance().getSkill((int) values[0], (int) values[1]);
+		
+		if (skill == null)
+		{
+			return;
+		}
+		
+		player.addSkill(skill);
+	}
+}

 

Xml: 

 

<!-- TODO : That minions need to be moved in spawn system when is done! -->
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xsd/pvpData.xsd">
	
	<!-- Created by Kara` -->
	
	<holder require="10">
		<color r="80" g="212" b="168" />
		<item id="57" count="100000000" />
		<skill id="6393" level="1" />
	</holder>
	
	<holder require="30">
		<color r="120" g="120" b="168" />
		<item id="6393" count="100" />
		<skill id="6393" level="1" />
	</holder>
	
</list>

 

How to use it? It's pretty simple:

 

  • In GameServer.java somewhere add the following line:
Quote

PvPData.getInstance();

 

  • To use it just go in the L2PcInstance.java and find the method that increasePvpKills and somewhere inside add the
Quote

PvPData.getInstance().executeEvent(this);

 

Hope you like it.

PS. Coded for L2J-H5

Edited by Kara`
Posted (edited)
8 minutes ago, ToNoobForscool said:

Author Kara should be all... the rest code is kara.this Kara.that Kara Kara.kara.kara.java 

You're right, i forgot to name the class itself KaraData. Thanks a lot !

 

Maybe im foolish, maybe im blind, thinking i can see though this and see whats behind.

Got no way to prove it so maybe im blind. But i'm only kara after all, i'm kara after all, don't put the

blame on me. Take a look in my code, what do you see,,, in what you believe??

Edited by Kara`
Posted (edited)
6 minutes ago, Elfocrash said:

Nice one but I have a question.

 

I won't comment on the whole structure but I'm really curious about this one:

 


values = new Object[]
{
	2
};

Is this supposed to be an array one dimensional array with a length of 2?

 

Typo. Changed to 

values = new Object[2];

 

I also had declared duplicated new Item i changed that too. Also the idea was to call it though enum and reflect it to avoid copy paste line getAttr() blabla but i'ts fine this way.

Edited by Kara`
Posted (edited)
10 minutes ago, Elfocrash said:

You can also shorthand it like this:

 


values = new Object[]{ id, level };

There are multiple ways to clean up the code.

 

I know trust me, you can use a interface and not extend, and about creating object you can use a reflection though a enum as i said like that:

 

/**
 * @author Kara`
 */
public enum GhostType
{
	CAPTURE_THE_FLAG(1, CTF.class);
	
	final int _id;
	final Class<? extends AbstractGhost> _type;
	
	GhostType(int id, Class<? extends AbstractGhost> type)
	{
		_id = id;
		_type = type;
	}
	
	public int getId()
	{
		return _id;
	}
	
	public Class<? extends AbstractGhost> getType()
	{
		return _type;
	}
}

Multiple ways to shorten it but still it's a nice system compared to:

 

Quote

if (player.getPvpKills() <30) { player.addItem(....   player.addSkill( ...

else if (player.getPvpKills() < 60 { ...

 

In my next share you will realise that i love organized and shrinked java code.

 

@Elfocrash PS i chaged the array as you mentioned:

 

values = new Object[3] { r, g, b };

 

Edited by Kara`
Posted
1 minute ago, Pamela32 said:

by the way , share section its alive ... thanks god :P

After i finish few clients and 1 event engine which i want sell for few bucks since there is no active event engine in the community now other than some buggy phoenix and erlandys that no develop anymore i'll share some more code. For now i focus on my clients.

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.




  • Posts

    • Hello, I'm working with custom Icons and noticed that you can use 64x64 icons and the client will handle them without problems in the Inventory and when you Drag them, they look HD so it's really cool, the problem starts when you move them to the shortcut bar, when they're placed there instead of rescaling the icon it just show the upper left corner (so it's 32x32 but showing only the part that fits in that space). I tried checking interface.u but can't find the line where the size for the icons in the shortcut bar are handled.   When in Inventory the item shows in a 32x32 size, if I use a 64x64 icon it re-scales so the icon looks great When dragging the item the image becomes 64x64 which looks pretty big, but it works good When placing the item in the shortcut bar only the top left of the icon is visible   Is there a way I can adjust the shortcut bar so that it re-scales the icon?
    • If you want to edit a large amount of entries in the L2 File-edit I recommend using excel, since both work with columns you can copy the entire file or just a few lines and paste it in excel and it will copy without problems, after you're done with editing you just select the cells and paste them in the .dat file making sure you're formatting correctly. I'm currently doing a massive edit on all gear and that's how i'm handling the .dat work
    • the logic is the "stacking" that is a filter if you use it then the item cannot co-exist (stack)
    • [Exclusive L2Gold Weekend Server] Available ONLY on Saturdays & Sundays – nowhere else, no other time ! Custom Armors (Dynasty, Apella) Custom Weapons (L2Gold Weapons) Custom Jewelry (L2Gold Jewelry) Custom Teleport System Custom AIO Buffer Custom Zones & NPCs Custom Raidboss … and much more waiting for you every weekend! This is not just another private server – it’s a limited-time battleground. When the weekend comes, everyone gathers in one place for the ultimate L2 experience. 👉 Online: Saturday–Sunday only 👉 Contact / Info: [https://www.facebook.com/profile.php?id=61578869175323]
    • ⏳ The price drops like sand slipping down in an hourglass.   📉 USA numbers are already at the lowest 💸 🌍 Next in line: Europe, Asia, and dozens of other countries.     All next week we’ll be actively working on lowering prices. The process has already started  soon costs will be much cheaper. 🔥 Get ready: the price drop will affect every country!   Website link — https://vibe-sms.net/ Our Telegram channel — https://t.me/vibe_sms
  • Topics

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