Jump to content

Mines Event


Recommended Posts

As title says, mines event generating box's each box has chance when u click on it if it's a coin u win if it's a torch u lose.

I didnt include the .mines command handler (aka chat handler) to the share most of u have ur own.

 

Requirements: Your own chat handler + menu handlers <-- i made a share for that.

If u use my menu handler add this to UsermenuHandler.java

else if(command.startsWith("_menuMinesSelect")){
			MinesEventHandler.getInstance().parseCmd(command, activeChar);
		}

Overview 1

Overview 2

Overview 3

Overview 4

 

MinesEventHandler.java

Mines.java

MinesEvent.java

MinesManager.java

minesMW.html

 

pastebin pass : maxcheaters

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

First of all an offtopic reply:

You did remind me the base version of my coupon manager 🤪

 

 

 

Now, lets focus on your idea.

 

Not bad at all, something new/fresh that in my pov, can be used and run with a simple npc that would ask for a price to play a new round. 

I'm also expecting a better reward when i got 2/3 or 3/3 success hits. The reward can simply be multiplied in that case (if the id,qnt have to be constants).

 

Now lets focus on your code.

You have to care about your bypasses. There are missing important checks for numerous suspicion actions.

The code inside of your if statement if(command.startsWith("_menuMinesSelect")){ ... } does not have any protection and it can be easily bypassed and request full rewards with a 50% chance at all. The reward action should be handled when the 'change icon' action take place. Atm, you have 2 different cases while the imporant one is located at the bypass that i mentioned. As it is now, it looks like that you can succeed the box without reward but also, the opossite.

 

You did care about the ConcurrentException inside of MinesManager but you didnt at the MinesEvent (which is created with an arraylist)

 

You have to debug your code for any possible mistake that you 'forgot' to fix up on the creation state. For example, something is wrong here:

 

case 0:
	Broadcast.announceToOnlinePlayers("[EVENT] ~ [Mines] Registrations closed.", true);

	if(MinesEvent.getInstance().getTotalPlayers() < 1) {
		Broadcast.announceToOnlinePlayers("[EVENT] ~ [Mines] Cancelled due to luck of participants.", true);
	}else {
		MinesEvent.getInstance().start();
	}
	setStarted(false);
	break;

 

You checking the total players count to decide if you have to start the event or abandon it but just after your decision, there is:

 

 setStarted(false);

 

Not a big deal at all but i think you got my point. I'm not seeing somewhere this boolean how and when is taking place but probably, is on the file you are not posting.

 

isStarted()

 

 

Generally, take care about naming policy (with proper lower/upper case and all), delete useless lines 

if(command.startsWith("_menuMinesSelect")){
            String selected = ""; // Where this variable is taking place?
            String cmdContent = st.nextToken(); // Where also this variable taking place?
            int position = Integer.valueOf(st.nextToken());
            int chance = Integer.valueOf(st.nextToken());
            Mines newMine =  MinesManager.getInstance().getMine(activeChar.getObjectId());
 
            if(chance > 50)
                newMine.soloRewards(activeChar);
 
            newMine.selectedBox(position);
            newMine.minesWindow(activeChar);

 

Read the java 8 features and get into stream . The addition of the Stream was one of the major features added to Java 8. Don't miss it.

 

For example, this code:

    public class MineBox{
        public int position;
        public int chance;
        public boolean selected;
        public String content;
    }
 
    public void feedList(){
        for(int i=0; i < 30; i++){
            MineBox bx = new MineBox();
            bx.position = i;
            bx.chance = Rnd.get(100);
            bx.selected = false;
            _boxs.add(bx);
        }
    }

 

Can be improved to this one:

 

public class MineBox
{
	public final int position;
	public final int chance = Rnd.get(100);
	public boolean selected = false;
	public String content;
	
	public MineBox(int pos) 
	{
		position = pos;
		_boxs.add(this);
	}
}

public final void feedList()
{
	IntStream.of(30).forEach(MineBox::new);
}

 

The only real problem impacting the stability is the ConcurrentException. Use ConcurrentHashMap.newKeySet() to handle it properly. All the other changes are about readability, performance and optimization.

 

I like you and i admire your effort. Keep sharing :yeih:

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

@melronThanks a lot for ur usefull tips ! I fixed most of the things u mentioned. I also added a win streak condition on soloRewards method it's up to u guys to add different rewards depending on the win streak 😄

 

About the setStarted,isStarted i use them on my chat handler to avoid ppl registering while event is running or not open for registrations.

 

Edit: Since i made a few changes for the multiplier, check the updated versions of Mines.java and MinesEvent.java:

Bonus Multiplier vid

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

 
Modification if you 
want to edit item by properties.
Config.java


+	public static int MINA_REWARD_ID;
+	public static int MINA_REWARD_COUNT;
	
+   MINA_REWARD_ID = players.parseIntIntList("MinaReward", "57");
+   MINA_REWARD_COUNT = players.getProperty("RewardCount", 500000);



+# Minas Event Custom reward
+MinaReward = 57
+RewardCount = 50000



net.sf.l2j.gameserver.util.Broadcast;
+ net.sf.l2j.Config;

     original 
	 
    //add the item to give for reward
    private final static int _rewardItemID = 0;
    //add the quantity of reward items
    private final static int _itemQuantity = 0;
	
	modificada 
	
    //add the item to give for reward
-	private final static int _rewardItemID = 0;
+   private final static int _rewardItemID = {Config.CHANGESEX_COIN_ID};
    //add the quantity of reward items
-   private final static int _itemQuantity = 0;
+   private final static int _itemQuantity = {Config.CHANGESEX_COIN_ID};

 

Edited by LucasDesigner
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.



×
×
  • Create New...