Jump to content

Recommended Posts

Posted (edited)

567136f854304129a821319417203fff.png

package com.l2jfresh.gameserver.model.actor.instance;

import java.util.StringTokenizer;
import java.util.NoSuchElementException;

import com.l2jfresh.gameserver.Announcements;
import com.l2jfresh.gameserver.model.actor.L2Npc;
import com.l2jfresh.gameserver.model.actor.template.NpcTemplate;
import com.l2jfresh.gameserver.network.clientpackets.Say2;
import com.l2jfresh.gameserver.network.serverpackets.Dice;
import com.l2jfresh.gameserver.network.serverpackets.ExShowScreenMessage;
import com.l2jfresh.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfresh.gameserver.network.serverpackets.NpcSay;
import com.l2jfresh.gameserver.util.Broadcast;
import com.l2jfresh.util.Rnd;



public class L2CasinoInstance extends L2Npc
{
	//Item Id
    public static int _itemId;
	private String itemname= "None";
    //Ammount Item
    public static int jackpot;
    public static int jackpot2;
    public L2CasinoInstance(int objectId, NpcTemplate template)
    {
        super(objectId, template);
    }
    
	@Override
	public boolean isAttackable()
	{
		return false;
	}
    @Override
    public void onBypassFeedback(L2PcInstance player, String command)
    {
      int ammount = 0;
      if (command.startsWith("play1"))
      {
        StringTokenizer st = new StringTokenizer(command);
        st.nextToken();
        try
        {
          String type = st.nextToken();

          if(type.startsWith("VoteStone"))
          {
        	  _itemId = 9595;
          }
          else if(type.startsWith("FarmCoin"))
          {
        	  _itemId = 9696;
          }
          ammount = Integer.parseInt(st.nextToken());
        }
        catch (NoSuchElementException nse)
        {
        }
        if (ammount >0)
        {
            Dice(player, this, ammount);
        }
        else return;
      }
    }
    
    @Override
    public void showChatWindow(L2PcInstance player)
    {
        NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
        msg.setHtml(casinoWindow(player));
        msg.replace("%objectId%", String.valueOf(this.getObjectId()));
        player.sendPacket(msg);
    }

    private static String casinoWindow(L2PcInstance player)
    {
    	StringBuilder tb = new StringBuilder();
        tb.append("<html><title>L2Ultimate Casino</title><body>");
        tb.append("<center><img src=\"L2Ultimate.logo\" width=\"300\" height=\"100\"/><br>");
        tb.append("<font color=\"3b8d8d\">Casino Manager</font><br>");
        tb.append("<img src=\"L2UI.SquareGray\" width=\"200\" height=\"1\"><br>");
        tb.append("<table width=290>");
        tb.append("<tr>");
        tb.append("<td align=\"center\"><font color=\"FFCC33\">Hello Sir, i Am Here for Your bets.<font></td></tr>");        
        tb.append("<tr><td align=\"center\"><font color=\"FFCC33\">You got need to Roll Number: 6-6 or 6-5 or 5-5 or 3-3</font></td></tr>");
        tb.append("<tr><td align=\"center\"><font color=\"LEVEL\">But if you are Lucky and you will win the Jackpot ,</font></td></tr>");
        tb.append("<tr><td align=\"center\"><font color=\"FF0000\">Jackpot of Vote Stone: "+jackpot+"</font></td></tr>");	
        tb.append("<tr><td align=\"center\"><font color=\"FF0000\">Jackpot of Farm Coin: "+jackpot2+"</font></td></tr>"); 
        tb.append("<tr></tr>");
        tb.append("</table>");
        tb.append("<center><img src=\"L2UI.SquareGray\" width=\"280\" height=\"1\"><br>");
        tb.append("<table width=290>");
        tb.append("<tr>");
        tb.append("<td align=\"center\"><font color=\"0F92FF\">Select a Currency To Bet:</font></td>");
        tb.append("<td><combobox width=120 height=21 var=\"cb\"list=VoteStone;FarmCoin></td>");
        tb.append("</tr>");
        tb.append("<tr></tr>");
        tb.append("<tr></tr>");
        tb.append("<tr>");
        tb.append("<td align=center><font color=\"0F92FF\">Type an Amount:</font></td>");
        tb.append("<td><edit var=\"qbox\" width=120 height=15></td>");
        tb.append("</table><br>");
        tb.append("<center><img src=\"L2UI.SquareGray\" width=\"280\" height=\"1\"></center><br><br>");
        tb.append("<center><button value=\"Try Your Luck!\" action=\"bypass -h npc_%objectId%_play1 $cb $qbox\" width=134 height=21 back=\"L2UI_ch3.BigButton3_over\" fore=\"L2UI_ch3.BigButton3\"></center>");
        tb.append("</body></html>");
        return tb.toString();
    }
    
    public void Dice(L2PcInstance activeChar,L2Npc npc,int _ammount)
    {
		if(activeChar.getInventory().getInventoryItemCount(_itemId, 0) >= _ammount)
		{
				int number = rollDice();
				int number2 = rollDice2();
				if(number == 6 && number2 == 6 || number == 6 && number2 == 5 || number == 5 && number2 == 5 || number == 3 && number2 == 3)
				{
			        ExShowScreenMessage screen = new ExShowScreenMessage("Congratulations "+activeChar.getName()+" won You got "+number+"-"+number2+" Good!", 6000);
			        String name = activeChar.getName();
			        activeChar.sendPacket(new NpcSay(npc.getObjectId(), Say2.TELL, npc.getNpcId(), "Congratulations "+name+" won You got "+number+"-"+number2+" Good!"));
			        activeChar.sendPacket(screen);
					activeChar.addItem("Consume", _itemId, _ammount, activeChar,true);
					/*if(_itemId == 9595)
					{
				   	  jackpot += _ammount;
					}
					else if(_itemId == 9696)
					{
					  jackpot2 += _ammount;
					}*/
					showChatWindow(activeChar);
					switch(_itemId)
					{
					    case 9595:
						itemname = "Vote Stone";
						break;
					    case 9696:
						itemname = "Look Coin";
						break;
					}
					
					switch(Rnd.get(1,20))
					{
					    case 1:
						break;
					    case 2:
						break;
					    case 3:
						break;
					    case 4:
						break;
					    case 5:
						    if(_itemId == 9595)
						    {
						     activeChar.addItem("Consume", _itemId, jackpot, activeChar,true);
						     activeChar.broadcastUserInfo();
						     Announcements.gameAnnounceToAll("Congratulations "+ activeChar.getName() +" he won "+ jackpot +" Jackpot of "+ itemname +"!");
						     jackpot = 0;
						    }
						    else if(_itemId == 9696)
						    {
						    activeChar.addItem("Consume", _itemId, jackpot2, activeChar,true);
						    activeChar.broadcastUserInfo();
						    Announcements.gameAnnounceToAll("Congratulations "+ activeChar.getName() +" he won "+ jackpot2 +" Jackpot of "+ itemname +"!");
						    jackpot2 = 0;
						    }
						break;
					    case 6:
						break;
					    case 7:
						break;
					    case 8:
						break;
					    case 9:
						break;
					    case 10:
						break;
					    case 11:
					    if(_itemId == 9595)
					    {
					     activeChar.addItem("Consume", _itemId, jackpot, activeChar,true);
					     activeChar.broadcastUserInfo();
					     Announcements.gameAnnounceToAll("Congratulations "+ activeChar.getName() +" he won "+ jackpot +" Jackpot of "+ itemname +"!");
					     jackpot = 0;
					    }
					    else if(_itemId == 9696)
					    {
					    activeChar.addItem("Consume", _itemId, jackpot2, activeChar,true);
					    activeChar.broadcastUserInfo();
					    Announcements.gameAnnounceToAll("Congratulations "+ activeChar.getName() +" he won "+ jackpot2 +" Jackpot of "+ itemname +"!");
					    jackpot2 = 0;
					    }
						break;
					    case 12:
						break;
					    case 13:
						break;
					    case 14:
						break;
					    case 16:
						break;
					    case 17:
						break;
					    case 18:
						break;
					    case 19:
						break;
					    case 20:
						break;
					}
					activeChar.broadcastUserInfo();
				}
				else
				{
			        ExShowScreenMessage screen = new ExShowScreenMessage(""+activeChar.getName()+" Ïops lost again play can be lucky!", 6000);
			        String name = activeChar.getName();
			        activeChar.sendPacket(new NpcSay(npc.getObjectId(),Say2.TELL, npc.getNpcId(), name+" Ïops lost again Play can be Lucky!"));
			        activeChar.sendPacket(screen);
					activeChar.destroyItemByItemId("Consume", _itemId, _ammount, activeChar, true);
					if(_itemId == 9595)
					{
				   	  jackpot += _ammount;
					}
					else if(_itemId == 9696)
					{
					   jackpot2 += _ammount;
					}
					activeChar.broadcastUserInfo();
					showChatWindow(activeChar);
				}
				Broadcast.toSelfAndKnownPlayers(npc, new Dice(npc.getObjectId(), 4625, number, npc.getX() - 30, npc.getY() - 30, npc.getZ()));
				Broadcast.toSelfAndKnownPlayers(npc, new Dice(npc.getObjectId(), 4626, number2, npc.getX() - 22, npc.getY() - 22, npc.getZ()));
			}
			else
			{
				switch(_itemId)
				{
				    case 9595:
					itemname = "Vote Stone";
					break;
				    case 9696:
					itemname = "Look Coin";
					break;
				}
				activeChar.sendMessage("You do not have enough "+itemname+".");
			}
	}
    
	public static int rollDice2()
	{
		return Rnd.get(1, 7);
	}
	
	public static int rollDice()
	{
		return Rnd.get(1, 7);
	}
	
}

code by fofas :)

Edited by Crazyboy*
Posted

lmao, what a bad code.. What's the point of this "dice"? As I see it's normal bet "double or nothing", so I don't relly get it. You only need one Rnd.get(.

Posted

You don't have to add all Cases that are not used in switch lel just the 2 that are used and the default:  that will happen in case none of them is.. 

Devorakoc the dev guy aka MrPRO* BFF

Posted

lmao, what a bad code.. What's the point of this "dice"? As I see it's normal bet "double or nothing", so I don't relly get it. You only need one Rnd.get(.

Shut the fuck up kid, we all know you're jealous of his skills and u can't remake this code.. stop being kid

Posted

Shut the fuck up kid, we all know you're jealous of his skills and u can't remake this code.. stop being kid

:( :( :(

 

You hurt my feelings. But still, its "one code line".

Posted (edited)

You probably can cut the code from 60 to 80% :

  • a chance of 50% (according your HTM) doesn't need 5 different dice rolls, it's a simple Rnd.nextBoolean()
  • HTM content = static HTM to avoid hardcoded HTMs.
  • The bypass can be directly the itemId to avoid string checks.
  • The whole switch is pointless. I don't want to imagine if you were using a Rnd.get(1000)... You would wrote 998 empty cases ? If you don't want a 50% win case, simply write Rnd.get(1000) or 10000 and test 0 and 1 as results. No need your whole fat ugly switch.
  • You lose all jackpot data on server restart. Use GobalVariables (or ServerMemo) to store it.
  • jackpot and jackpot2 is a stupid concept, imagine you want to add or remove currencies. You're fucked up. And static the itemId is also wrong, if 2 players are using 2 different currencies in same time, one of the player can end with the other currency when the other player flipped it.

I don't recommend to use it, being aCis or not.

Edited by Tryskell
Posted

Wow you really have to try very hard to suck at coding such a basic concept.

 

I remember a time where you were coding almost as bad as the OP (your old balancer stats, just to give an exemple of extremely redundant code style). I say that, I say nothing.

 

;D

Posted

I remember a time where you were coding almost as bad as the OP (your old balancer stats, just to give an exemple of extremely redundant code style). I say that, I say nothing.

 

;D

We all begin from something don't we ? :D

Posted (edited)

We all begin from something don't we ? :D

 

So you should be the best to know it's not nice to bash people, while you can explain where are the flaws and how to improve the code. In both case you say the code got issues, but one way is negative while the second is more positive.

 

That was the morale lesson of the day, cya tomorrow for new lessons ! :D

Edited by Tryskell

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Posts

    • You should buy it then I’ll make a discount  
    • Hi everyone,   In 2014, I completely stepped away from developing L2 servers and doing L2J-related work. Since then, I’ve only opened this server about once a year and helped a few servers and individuals for free. I haven’t taken on any paid L2J work since then.   LINEAGE2.GOLD is a project that has reached about Season 6. The first season launched at the end of 2020 and was a fully rebuilt Gold-style server on the Classic client (protocol 110). It featured many custom systems and enhancements. After several seasons, I decided to abandon the Mobius-based project and move to Lucera, as my goal was to get as close as possible to Interlude PTS behavior while still staying on the L2J platform.   The current project was once again completely rebuilt, this time on the Essence client (protocol 306), and is based on Lucera. Because of that, acquiring a license from Deazer is required.   My Lucera extender includes, but is not limited to: Formulas.java Basic anti-bot detection, which proved quite effective, we caught most Adrenaline users using relatively simple server-side logic, logged them, and took staff action. Simple admin account lookup commands based on IP, HWID, and similar identifiers. In-game Captcha via https://lineage2.gold/code, protected by Cloudflare, including admin commands for blacklisting based on aggression levels and whitelisting. Additional admin tools such as Auto-Play status checks, Enchanted Hero Weapon live sync, force add/remove clans from castle sieges, item listeners for live item monitoring, and more. A fully rewritten Auto-Play system with support for ExAutoPlaySetting, while still using the Auto-Play UI wheel, featuring: Debuff Efficiency Party Leader Assist Respectful Hunting Healer AI Target Mode Range Mode Summoner buff support Dwarf mechanics Reworked EffectDispelEffects to restore buffs after Cancellation. Raid Bomb item support. Reworked CronZoneSwitcher. Prime Time Raid Respawn Service. Community Board features such as Top rankings and RB/Epic status. Custom systems for Noblesse, Subclasses, support-class rewards, and much more.   Depending on the deal, the project can include: The lineage2.gold domain The website built on the Laravel PHP framework The server’s Discord Client Interface source Server files and extender source The server database (excluding private data such as emails and passwords)   I’m primarily looking for a serious team to continue the project, as it would be a shame to see this work abandoned. This is not cheap. You can DM me with offers. If you’re wondering why I’m doing this: I’ve felt a clear lack of appreciation from the L2 community, and I’m not interested in doing charity work for people who don’t deserve it. I’m simply not someone who tolerates BS. Server Info: https://lineage2.gold/info Server for test: https://lineage2.gold/download Over 110 videos YouTube playlist: https://www.youtube.com/watch?v=HO7BZaxUv2U&list=PLD9WZ0Nj-zstZaYeWxAxTKbX7ia2M_DUu&index=113
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock