Jump to content

Procedural PvP Reward System [By cute Kara]


Kara

Recommended Posts

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`
Link to comment
Share on other sites

17 minutes ago, Kara` said:

Why that :3 ?

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

  • Sad 2
Link to comment
Share on other sites

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`
Link to comment
Share on other sites

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`
Link to comment
Share on other sites

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`
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

    • /data/attachments/4/4519-0e10f165cf34562cd44d346d47967752.jpg Dear friends! September 27 we start Event for Olympiad games on Open Beta server Start Olympiad games in 19:00 (UTC +3) September 27 Fights will be till 23:40, then we get Heroes (after 00:00) All who get Hero status, will receive 500 ToDs. Best 5 Hero, who will get the most PTS, will get 800 ToDs instead of 500. ToDs you will get on your Master Account balance No class vs class fights Enchant Level Restrictions: S gr +6, A gr + 7, C/B gr + 16. On Olympiad, all items that higher than restriction level will be removed, and you won't be able to use them or wear them Talent Tree avaible only Tier 1 (same like will be on 1st Oly cycle on Live server) Skill enchant lvl: 15 max for 2nd profession, 7 for 3rd profession - its global rules for all Beta Good luck to Everyone!  
    • I'm currently working on an advanced auto-farm compatible with older chronicles (C4, IL, HF, etc) and older L2J-Mobius builds. https://imgur.com/a/LJS2OMC
    • GamezAION 4.8 High Quality Relaunch Coming Friday 4th October 2024   All Latest Retail Skin Appearances Unique RvR Battlegrounds (Guardian) (Battle of Gods) Added New PvPvE Map with Seasonal Ranking System Active Anticheat System & Shugo Console Support   Download links available on website   https://gamezaion.com Join the Action!
    • 🌟 Step Into Lin2Age C4 – Your Nostalgic Journey Awaits! 🌟 Get ready for an unforgettable adventure filled with fierce battles ⚔️, mighty clans 👑, and epic quests 🌍! Lin2Age is a custom Lineage 2 server designed to bring you the ultimate classic experience, enriched with modern features. Whether you're a battle-hardened veteran or a fresh-faced newcomer, there's a place for everyone in our world! 🛡️✨   🔥 Why Lin2Age is Your Best Choice 🔥 ✅ Dynamic Events & Rewards: Enjoy thrilling features like TVT, Magic Roulette, Daily Rewards, measures to enhance your gameplay. ✅ Advanced Security Features: Enjoy robust protections with Anti-Bot measures, Password Lock, and Raid Boss Information to keep your adventures safe and secure. ✅ Balanced Gameplay for All: Dive into a harmonious blend of PvP, PvE, and crafting! Lin2Age combines the finest elements from Scions of Destiny MasterWork and Interlude, ensuring an immersive experience for every playstyle! 🛡️⚔️ ✅ Epic Gear & AIO Buffer: Equip Legendary Armor and powerful jewels! Our All-In-One Buffer is at your service, empowering you to dominate the battlefield! 💎💪 ✅ Unique Custom Features: Embark on exclusive quests 📜 and take on formidable raid bosses 🐉! Lin2Age is filled with thrilling content that keeps your adventures lively and exciting. 🎯🎮 ✅ Thriving Community: Join a vibrant community where teamwork and friendship thrive! Whether leading a clan or joining one, support is always at your fingertips! 🤝👑 ✅ Regular Updates & Events: Experience continuous excitement! With frequent updates, fresh custom content, and epic events, Lin2Age is always evolving, thanks to your invaluable feedback! 🔄🏆 ✅ Smooth, Lag-Free Experience: Enjoy uninterrupted gameplay on our top-tier servers—say goodbye to lag! 🚀⚡   💎 Fair Play Above All 💎 At Lin2Age, we champion a balanced and equitable gaming experience. Our No Pay-to-Win policy ensures that success comes from skill, strategy, and teamwork, not your wallet! 💪 Everything you need to thrive can be earned through quests, crafting, and epic battles! 🏆🎮   🔑 Key Features You’ll Love 🔑 🔹 Rates: EXP x45, SP x45, ADENA x300—meticulously balanced for your enjoyment! 🔹 Custom Classes & Skills: Discover unique classes and skills that make PvP combat dynamic! ⚔️ 🔹 Epic Raid Bosses: Challenge yourself against custom bosses for legendary loot! 💀🏹 🔹 Clan Wars & Sieges: Test your strength in exhilarating clan wars and castle sieges! 🏰⚔️ 🔹 Dedicated Support Team: Our active Game Masters are committed to ensuring fairness and smooth gameplay! 👥🛡️ ⚔️ Join the Lin2Age Beta Test – Adventurers Needed! 🛡️ Are you ready to experience the glory of Lineage 2, reimagined for a new generation? 🌍 Become part of our exclusive beta test and help shape the future of Lin2Age! 🚀✨ Start your epic journey today. Welcome to Lin2Age C4! 💬 Connect with Us on Discord Join our community, stay updated, and take part in the latest events! Discord: https://discord.gg/qKJnQ7Kp5X Youtube: https://www.youtube.com/watch?v=nnO-J_uAqvg https://prnt.sc/b3tRHlxT6YS7
  • Topics

×
×
  • Create New...