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

    • Thank you for your reply. I have removed it from the L2Server.exe file, but the L2Server still crashes. It doesn't crash if I don't start l2npc, otherwise it will crash within a few days at the latest.
    • Welcome to my store :  https://topestore.mysellix.io/fr/ 2015-2022 Aged Discord Account 2015 Discord Account : 50.99 $ 2016 Discord Account : 10$ 2017 Discord Account :3.99 $ 2018 Discord Account : 3.50$ 2019 Discord Account : 2.70 $ 2020 Discord Account :1.50$ 2021 Discord Account :0.99$ 2022 Discord Account :0.70$ Warranty :Lifetime Payment Methods : Crypto/ PayPal Contact Me On Discord Or Telegram Discord : @ultrasstore11 Telegram : https://t.me/ultrastore1 Welcome to my store :  https://topestore.mysellix.io/fr/ 2015-2022 Aged Discord Account 2015 Discord Account : 50.99 $ 2016 Discord Account : 10$ 2017 Discord Account :3.99 $ 2018 Discord Account : 3.50$ 2019 Discord Account : 2.70 $ 2020 Discord Account :1.50$ 2021 Discord Account :0.99$ 2022 Discord Account :0.70$ Warranty :Lifetime Payment Methods : Crypto/ PayPal Contact Me On Discord Or Telegram Discord : @ultrasstore11
    • L2 ArenaWar: Low Rate PvP Server with Free Buffs & Autofarm [PVP]⚔️ [Free]🆓 Classic Interlude with  3x XP rates! Free starter pack(no grade) to kickstart your adventure! Autofarm for convenient grinding! Free buffs to keep you fighting fit! (2 job buffs) No experience loss on death! (Except with Karma) Clear Karma system to keep things fair! ⚖️ Active community of 800-1k players! Join our Discord to learn more! >> Discord <<     Server website: https://l2arenawar.com/en/    
    • This is dedication! 2 years working on a problem. Congratulations!
    • You indeed have to save player position over Enterworld to properly clean it up later (if you don't, even trying to delete packet content would eventually keep it up), that's what we do with debug packet (which is a reusable Map of ExServerPrimitive packets) on aCis.   It doesn't solve the FPS stuttering - more you draw/delete lines, more your client becomes laggy. It's like if client wasn't deleting drawn points/lines properly, but instead simply hide them and redrawn content above.   If you got a solution, I would happy to integrate it.   You should check aCis#Player _debug packet integration, it allows very big amount of lines/points to be drawn, it is also reusable.   https://gitlab.com/Tryskell/acis_public/-/blob/master/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java?ref_type=heads https://gitlab.com/Tryskell/acis_public/-/blob/master/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java?ref_type=heads  
  • Topics

×
×
  • Create New...