Advertisement
Lucasdesigner

Mines.java

Oct 16th, 2021
1,205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.42 KB | None | 0 0
  1. package net.sf.l2j.gameserver.custom.events.mines;
  2.  
  3. import net.sf.l2j.commons.lang.StringUtil;
  4. import net.sf.l2j.commons.random.Rnd;
  5. import net.sf.l2j.gameserver.model.actor.instance.Player;
  6. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.List;
  10.  
  11.  
  12. public class Mines extends MinesEvent {
  13.     private int _selected = -1;
  14.     private final List<MineBox> _boxs = new ArrayList<>();
  15.     private int _lives = 3;
  16.  
  17.     public Mines() {
  18.         feedList();
  19.     }
  20.  
  21.     public void minesWindow(Player player) {
  22.         final StringBuilder sb = new StringBuilder();
  23.         if(_lives != 0) {
  24.             selectedBox(getSelected());
  25.             StringUtil.append(sb, "<br>Lives");
  26.             StringUtil.append(sb, "<br1><table width=96><tr>");
  27.             for (int sI = 0; sI < _lives; sI++)
  28.                 StringUtil.append(sb, "<td><button action=\"bypass \" width=32 height=32 back=\"icon.etc_dice_a_i00\" fore=\"icon.etc_dice_a_i00\"></td>");
  29.  
  30.             StringUtil.append(sb, "</tr></table>");
  31.  
  32.             StringUtil.append(sb, "<br><table width=260>");
  33.             int i = 0;
  34.             for (MineBox bx : _boxs) {
  35.                 final boolean isNextLine = i % 6 == 0;
  36.                 if (isNextLine)
  37.                     sb.append("<tr>");
  38.                 StringUtil.append(sb, "" + displayIcons(bx.position, bx.chance, bx.selected, bx.content));
  39.                 if (isNextLine)
  40.                     sb.append("</tr>");
  41.                 i++;
  42.             }
  43.             StringUtil.append(sb, "</table>");
  44.         }else
  45.             StringUtil.append(sb, "<br>You Lost");
  46.  
  47.         NpcHtmlMessage html = new NpcHtmlMessage(0);
  48.         html.setFile("data/html/mods/Events/mines/minesMW.htm");
  49.         html.replace("%mines%", sb.toString());
  50.         player.sendPacket(html);
  51.     }
  52.  
  53.     public String displayIcons(int chanceNum,int position,boolean selected, String content){
  54.         String tempHolder = "";
  55.  
  56.         if(selected)
  57.             tempHolder = content;
  58.         else
  59.             tempHolder = "<td><button action=\"bypass  _menuMinesSelect " + chanceNum + " "+ position + "\" width=32 height=32 back=\"icon.etc_box_of_adventure_1_i00\" fore=\"icon.etc_box_of_adventure_1_i00\"></td>";
  60.  
  61.         return tempHolder;
  62.     }
  63.  
  64.     public void selectedBox(int pos){
  65.         for(MineBox bx : _boxs){
  66.             if(bx.position == pos){
  67.                 bx.selected = true;
  68.                 if(bx.chance < 50) {
  69.                     bx.content = "<td><button action=\"bypass \" width=32 height=32 back=\"icon.etc_torch_on_i00\" fore=\"icon.etc_torch_on_i00\"></td>";
  70.                     _lives--;
  71.                 }else
  72.                 bx.content = "<td><button action=\"bypass \" width=32 height=32 back=\"icon.etc_pig_adena_i00\" fore=\"icon.etc_pig_adena_i00\"></td>";
  73.             }
  74.         }
  75.     }
  76.  
  77.     public class MineBox{
  78.         public int position;
  79.         public int chance;
  80.         public boolean selected;
  81.         public String content;
  82.     }
  83.  
  84.     public void feedList(){
  85.         for(int i=0; i < 30; i++){
  86.             MineBox bx = new MineBox();
  87.             bx.position = i;
  88.             bx.chance = Rnd.get(100);
  89.             bx.selected = false;
  90.             _boxs.add(bx);
  91.         }
  92.     }
  93.  
  94.     public void setSelected(int position){
  95.         _selected = position;
  96.     }
  97.  
  98.     public int getSelected()
  99.     {
  100.        return _selected;
  101.     }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement