Jump to content

L2Jacis Casino Manager


Recommended Posts

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

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

Link to comment
Share on other sites

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

make an update on code jajaja

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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