Jump to content

Idle Auto Farm


Recommended Posts

Idle Auto Farm aka giving rewards to AFK players. I also added an option for premium in case u want to give bonus to premium players. I dont suggest u to use the current threadpool timers it was just for tests. Ideally u have to set it to minutes.

 

IdleFarmer.java

IdleFarmManager.java

pastebin pass : maxcheaters

 

Video

Video 2

It's up to u on how to trigger it for the player

 

  //To start the idle farm
  IdleFarmManager.getInstance().addIdleFarmer(activeChar);
  //To stop the idle farm
  IdleFarmManager.getInstance().removeIdleFarmer(activeChar);

 

GameServer.java
+StringUtil.printSection("Idle Engine");
+IdleFarmManager.getInstance().start();  

 

Player.java
+IdleFarmManager.getInstance().removeIdleFarmer(this);
			
World.getInstance().removePlayer(this); // force remove in case of crash during teleport

 

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

Thanks for your share!

The main concept for idle farm is the exp,sp. Rewards can be added also by some specific conditions, but in anycase it should't be as a main reward (in my pov).

 

About the code structure, it would be easier/correct to use an interface to build your xp/sp/rewards with their name as a tag. Your _itemsList array should be refactored and also your thought about IdleItem class (by naming view policy, im expecting data of an item (id,count) with the name IdleItem), it could be an intintholder instead.

You can completely remove the class Engine and instead, implement the Runnable class at your IdleFarmManager . It would generate the overriden method 'run'.

 

A security thing now, you are correctly checking for join conditions in order to add someone to your idle farm list, but you are not checking anything up on the reward state. Considering the fact that this feature could be used for low rate servers too, they can easily cheat even if the 1st join condition have the peace zone check.. There are numerous of things that players can think about to 'hack' it. They have recall skills, gotolove or 1000 other things that you can't imagine right now. Also, another benefit that you would get by checking some conditions up on the reward state is that some rewards may need some extra conditions to be applied. For example, you can add an +1 A grade enchant to rhand only if the player is 80 level, have A grade weapon equipped with enchant level < 3 and 0 EAW items found on inventory/warehouse. (Just an example). In that case, you need a different check conditions for that.

 

My personal opinion for this code is to create an interface 

package net.sf.l2j.gameserver.custom.idlefarm.rewards;

import java.time.temporal.ValueRange;

import net.sf.l2j.gameserver.enums.ZoneId;
import net.sf.l2j.gameserver.model.actor.Player;
import net.sf.l2j.gameserver.model.holder.IntIntHolder;

/**
 * @author Melron
 */
public interface IIdleFarmReward
{
	public boolean meetTheConditions(Player player);
	public int getChance();
	public IntIntHolder[] getItemRewards();
	public int getExp(int playerLevel);
	public int getSp(int playerLevel);
	
	default boolean levelIsBetween(Player player, int min, int max)
	{
		return ValueRange.of(min, max).isValidValue(player.getStatus().getLevel());
	}
	
	default boolean isInTown(Player player)
	{
		return player.isInsideZone(ZoneId.PEACE);
	}
}

 

 

and then start creating your classes by giving the correct name. Example, NewbiesReward/AdvancedReward. etc. An example for NewbiesReward :

package net.sf.l2j.gameserver.custom.idlefarm.rewards.type;

import net.sf.l2j.commons.random.Rnd;

import net.sf.l2j.gameserver.custom.idlefarm.rewards.IIdleFarmReward;
import net.sf.l2j.gameserver.model.actor.Player;
import net.sf.l2j.gameserver.model.holder.IntIntHolder;

/**
 * @author Melron
 */
public class NewbiesReward implements IIdleFarmReward
{
	private static final int MIN_LEVEL = 45;
	private static final int MAX_LEVEL = 67;
	private static final IntIntHolder[] ITEM_REWARDS = new IntIntHolder[]
	{
		new IntIntHolder(57, 5_000_000),
		new IntIntHolder(57, 2_000_000),
	};
	
	@Override
	public boolean meetTheConditions(Player player)
	{
		return isInTown(player) && levelIsBetween(player, MIN_LEVEL, MAX_LEVEL);
	}
	
	@Override
	public int getChance()
	{
		return 70;
	}
	
	@Override
	public IntIntHolder[] getItemRewards()
	{
		return ITEM_REWARDS;
	}
	
	@Override
	public int getExp(int playerLevel)
	{
		final int baseValue = playerLevel * 1_000_000;
		return Rnd.get(baseValue, baseValue * 2);
	}
	
	@Override
	public int getSp(int playerLevel)
	{
		final int baseValue = playerLevel * 500_000;
		return Rnd.get(baseValue, baseValue * 2);
	}
}

 

for Advanced: 

 

package net.sf.l2j.gameserver.custom.idlefarm.rewards.type;

import net.sf.l2j.commons.random.Rnd;

import net.sf.l2j.gameserver.custom.idlefarm.rewards.IIdleFarmReward;
import net.sf.l2j.gameserver.model.actor.Player;
import net.sf.l2j.gameserver.model.holder.IntIntHolder;

/**
 * @author Melron
 */
public class AdvancedReward implements IIdleFarmReward
{
	private static final int MIN_LEVEL = 76;
	private static final int MAX_LEVEL = 80;
	private static final IntIntHolder[] REWARDS = new IntIntHolder[]
	{
		new IntIntHolder(961, 1), // EWS
		new IntIntHolder(1540, 100), // QHP
	};
	
	@Override
	public boolean meetTheConditions(Player player)
	{
		return isInTown(player) && levelIsBetween(player, MIN_LEVEL, MAX_LEVEL);
	}
	
	@Override
	public int getChance()
	{
		return 2;
	}
	
	@Override
	public IntIntHolder[] getItemRewards()
	{
		return REWARDS;
	}
	
	@Override
	public int getExp(int playerLevel)
	{
		final int baseValue = playerLevel * 5_000_000;
		return Rnd.get(baseValue, baseValue * 2);
	}
	
	@Override
	public int getSp(int playerLevel)
	{
		final int baseValue = playerLevel * 2_500_000;
		return Rnd.get(baseValue, baseValue * 2);
	}
}

 

 

You can specify whatever you need on the classes and play with meetConditions method to allow the player to get some rewards. (The exp,sp calcs are random).

 

If you want 1 condition to be checked after and a chance check and assuming you have set all your rewards on a Set or something simillar,

for (IIdleFarmReward reward : REWARDS)
{
	if (reward.meetTheConditions(player))
	{
		player.getStatus().addExp(reward.getExp(player.getStatus().getLevel()));
		player.getStatus().addSp(reward.getSp(player.getStatus().getLevel()));
		
		for (IntIntHolder rewardHolder : reward.getItemRewards())
			if (Rnd.get(100) <= reward.getChance())
				player.addItem("Idle Farm", rewardHolder.getId(), rewardHolder.getValue(), null, true);
	}
}

 

But i insist that if you edit a bit my way, you can achieve some cool things for them 🙂

  • Thanks 1
Link to comment
Share on other sites

6 hours ago, melron said:

The main concept for idle farm is the exp,sp. Rewards can be added also by some specific conditions, but in anycase it should't be as a main reward (in my pov).

Hey Melron , how are u ?
Thanks again for ur useful tips as always. Well obviously it's up to ur taste if u want to optimize it or add extra features to it. I dont think that it's mendatory to add xp/sp especially for low rate servers (i dont think ppl will like it). As u said it's ur pov.

 

6 hours ago, melron said:

Your _itemsList array should be refactored and also your thought about IdleItem class (by naming view policy, im expecting data of an item (id,count) with the name IdleItem), it could be an intintholder instead.

Yeap you are right it's an old bad habit of mine working on to fix it, itemList is array not a List ( i rly need to fix this bad habit).

intintHolder for ur case is right since u work with 2 int's.

 

6 hours ago, melron said:

You can completely remove the class Engine and instead, implement the Runnable class at your IdleFarmManager . It would generate the overriden method 'run'.

Yes i know, i made it this way inorder to make it more flexible let's say for example if u want to make this auto farm thing 2-3 times a month obviously u can do it while the class implements Runnable but i wanted to avoid using interrupts. As it's u can start / close it if u dont want to make it run everytime server starts.

//start idle Engine 
IdleFarmManager.getInstance().start();
//stop idle Engine 
IdleFarmManager.getInstance().stop();

 

 

6 hours ago, melron said:

A security thing now, you are correctly checking for join conditions in order to add someone to your idle farm list, but you are not checking anything up on the reward state. Considering the fact that this feature could be used for low rate servers too, they can easily cheat even if the 1st join condition have the peace zone check.. There are numerous of things that players can think about to 'hack' it. They have recall skills, gotolove or 1000 other things that you can't imagine right now. Also, another benefit that you would get by checking some conditions up on the reward state is that some rewards may need some extra conditions to be applied.

I might be wrong for this one but we make the same checks beside the fact u use interface to achieve it. Or u do sth else that u dont show on the code's.

//Melrons example
@Override
public boolean meetTheConditions(Player player)
{
  return isInTown(player) && levelIsBetween(player, MIN_LEVEL, MAX_LEVEL);
}

//LordPanic example
if(getPlayer().getLevel() >= item._plrLvlMin && getPlayer().getLevel() <= item._plrLvlMax && item._chance > Rnd.get(100))

More security conditions needs to be implemented thats for sure.

 

Still i rly appreciate ur help and if im wrong feel free to point it.

 

P.s i prefer the way i create the IdleItems it might not be readable to the eye but everything is there.

Edited by LordPanic
Link to comment
Share on other sites

30 minutes ago, LordPanic said:

Hey Melron , how are u ?
Thanks again for ur useful tips as always. Well obviously it's up to ur taste if u want to optimize it or add extra features to it. I dont think that it's mendatory to add xp/sp especially for low rate servers (i dont think ppl will like it). As u said it's ur pov.

Im just 'hearing' the phrase "farm" and im expecting exp,sp and some rewards 😛

 

30 minutes ago, LordPanic said:

I might be wrong for this one but we make the same checks beside the fact u use interface to achieve it. Or u do sth else that u dont show on the code's.

//Melrons example
@Override
public boolean meetTheConditions(Player player)
{
  return isInTown(player) && levelIsBetween(player, MIN_LEVEL, MAX_LEVEL);
}

//LordPanic example
if(getPlayer().getLevel() >= item._plrLvlMin && getPlayer().getLevel() <= item._plrLvlMax && item._chance > Rnd.get(100))

More security conditions needs to be implemented thats for sure.

 

Still i rly appreciate ur help and if im wrong feel free to point it.

 

P.s i prefer the way i create the IdleItems it might not be readable to the eye but everything is there.

 

Well, my purpose wasn't to 'change' your check. Its indeed the same result but im using meetTheConditions at every time i need to reward someone and also im using the method for every reward. Check my code again. As i said with an example, you can add multiple checks and conditions for 1 item reward. As it is now, except that there isn't any check on the reward state, but lets say we add it. It should use the 'same' check for all your rewards. With custom classes, you have the ability to create the necessary check for any item

 

 

Edited by melron
Link to comment
Share on other sites

31 minutes ago, melron said:

Well, my purpose wasn't to 'change' your check. Its indeed the same result but im using meetTheConditions at every time i need to reward someone and also im using the method for every reward. Check my code again. As i said with an example, you can add multiple checks and conditions for 1 item reward. As it is now, except that there isn't any check on the reward state, but lets say we add it. It should use the 'same' check for all your rewards. With custom classes, you have the ability to create the necessary check for any item

Noted, it's not that i didnt understand it, it's simply due to the fact when i create a mod (out of interest) after that i simply lose interest and just leave it as it is (except serious issues).

 

If u are ok with it , send me ur discord it would be better to communicate from there. It's always good to hear a second opinion before every mod share i make or maybe a few tips.

Link to comment
Share on other sites

21 minutes ago, LordPanic said:

Noted, it's not that i didnt understand it, it's simply due to the fact when i create a mod (out of interest) after that i simply lose interest and just leave it as it is (except serious issues).

Mods are mods. You share them and then the receiver can change anything. I'm just pointing out some things not for the mod itself, but for a general purpose.

 

22 minutes ago, LordPanic said:

If u are ok with it , send me ur discord it would be better to communicate from there. It's always good to hear a second opinion before every mod share i make or maybe a few tips.

Not a problem at all, melron#5110

Link to comment
Share on other sites

  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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