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 everyone! I am wanting to save the files (Ini. - Data - ) of the EP5 Client: Salvation... But they generate the error "corrupt files"... I tried several versions of L2FileEditor without good results. I need help! Thank you!
    • Opening December 6th at 19:00 (GMT +3)! Open Beta Test from November 30th!   https://l2soe.com/   🌟 Introducing L2 Saga of Eternia: A Revolution in Lineage 2 High Five! 🌟   Dear Lineage 2 enthusiasts, Prepare to witness the future of private servers! L2 Saga of Eternia is not just another High Five project—it’s a game-changing experience designed to compete with the giants of the Lineage 2 private server scene. Built for the community, by the community, we’re here to raise the bar in quality, innovation, and longevity. What Sets Us Apart? 💎 No Wipes, Ever Say goodbye to the fear of losing your progress. Our server is built to last and will never close. Stability and consistency are our promises to you. ⚔️ Weekly New Content Our dedicated development team ensures fresh challenges, events, and updates every week. From custom quests to exclusive features, there will always be something exciting to explore. 💰 No Pay-to-Win Skill and strategy matter most here. Enjoy a balanced gameplay environment where your achievements come from effort, not your wallet. 🌍 A Massive Community With 2000+ players expected, join a vibrant and active community of like-minded adventurers ready to conquer the world of Aden. 🏆 Fair and Competitive Gameplay Our systems are designed to promote healthy competition while avoiding abusive mechanics and exploits. 🔧 Professional Development From advanced bug fixes to carefully curated content, we pride ourselves on smooth performance, no lag, and unparalleled server quality. Key Features Chronicle: High Five with unique interface Rate: Dynamic x10 rates Class Balance: Carefully fine-tuned for a fair experience PvP Focused: PvP Ranking & aura display effect for 3 Top PvPers every week Custom Events: Seasonal and permanent events to keep you engaged Additional Features:   Custom Endgame Content: Introduce unique dungeons, raids, or zones unavailable in other servers. Player-Driven Economy: Implement a strong market system and avoid overinflated drops or rewards. Epic Siege Battles: Announce special large-scale sieges and PvP events. Incentives for Streamers and Clans: Attract influencers and big clans to boost server publicity. Roadmap Transparency: Share a public roadmap of planned updates to build trust and excitemen   Here you can read all the features: https://l2soe.com/features   Video preview: Join the Revolution! This is your chance to be part of something legendary. L2 Saga of Eternia is not just a server; it’s a movement to redefine what Lineage 2 can be. Whether you’re a seasoned veteran or a newcomer to the world of Aden, we invite you to experience Lineage 2 at its finest.   Official Launch Date: December 6th 2024 Website: https://l2soe.com/ Facebook: https://www.facebook.com/l2soe Discord: https://discord.com/invite/l2eternia   Let’s build the ultimate Lineage 2 experience together. See you in-game! 🎮
    • That's like a tutorial on how to run l2 on MacOS Xd but good job for the investigation. 
    • small update: dc robe set sold   wts adena 1kk = 1.5$ 
    • DISCORD : utchiha_market telegram : https://t.me/utchiha_market SELLIX STORE : https://utchihamkt.mysellix.io/ Join our server for more products : https://discord.gg/hood-services https://campsite.bio/utchihaamkt
  • Topics

×
×
  • Create New...