diff --git a/src/main/java/client/Character.java b/src/main/java/client/Character.java index 406491f367..070c55ad5a 100644 --- a/src/main/java/client/Character.java +++ b/src/main/java/client/Character.java @@ -69,7 +69,7 @@ import server.life.Monster; import server.life.PlayerNPC; import server.maps.*; import server.maps.MiniGame.MiniGameResult; -import server.minigame.MapleRockPaperScissor; +import server.minigame.RockPaperScissor; import server.partyquest.AriantColiseum; import server.partyquest.MonsterCarnival; import server.partyquest.MonsterCarnivalParty; @@ -159,7 +159,7 @@ public class Character extends AbstractCharacterObject { private Job job = Job.BEGINNER; private Messenger messenger = null; private MiniGame miniGame; - private MapleRockPaperScissor rps; + private RockPaperScissor rps; private Mount maplemount; private Party party; private final Pet[] pets = new Pet[3]; @@ -5496,7 +5496,7 @@ public class Character extends AbstractCharacterObject { return playerShop; } - public MapleRockPaperScissor getRPS() { // thanks inhyuk for suggesting RPS addition + public RockPaperScissor getRPS() { // thanks inhyuk for suggesting RPS addition return rps; } @@ -9218,12 +9218,12 @@ public class Character extends AbstractCharacterObject { this.name = name; } - public void setRPS(MapleRockPaperScissor rps) { + public void setRPS(RockPaperScissor rps) { this.rps = rps; } public void closeRPS() { - MapleRockPaperScissor rps = this.rps; + RockPaperScissor rps = this.rps; if (rps != null) { rps.dispose(client); setRPS(null); diff --git a/src/main/java/net/server/channel/handlers/RPSActionHandler.java b/src/main/java/net/server/channel/handlers/RPSActionHandler.java index 79b9ad2b00..0916f648af 100644 --- a/src/main/java/net/server/channel/handlers/RPSActionHandler.java +++ b/src/main/java/net/server/channel/handlers/RPSActionHandler.java @@ -4,7 +4,7 @@ import client.Character; import client.Client; import net.AbstractPacketHandler; import net.packet.InPacket; -import server.minigame.MapleRockPaperScissor; +import server.minigame.RockPaperScissor; import tools.PacketCreator; /** @@ -17,7 +17,7 @@ public final class RPSActionHandler extends AbstractPacketHandler { @Override public final void handlePacket(InPacket p, Client c){ Character chr = c.getPlayer(); - MapleRockPaperScissor rps = chr.getRPS(); + RockPaperScissor rps = chr.getRPS(); if (c.tryacquireClient()) { try { @@ -35,7 +35,7 @@ public final class RPSActionHandler extends AbstractPacketHandler { rps.reward(c); } if(chr.getMeso() >= 1000){ - chr.setRPS(new MapleRockPaperScissor(c, mode)); + chr.setRPS(new RockPaperScissor(c, mode)); }else{ c.sendPacket(PacketCreator.rpsMesoError(-1)); } diff --git a/src/main/java/server/minigame/MapleRockPaperScissor.java b/src/main/java/server/minigame/MapleRockPaperScissor.java deleted file mode 100644 index fb4c476a66..0000000000 --- a/src/main/java/server/minigame/MapleRockPaperScissor.java +++ /dev/null @@ -1,84 +0,0 @@ -package server.minigame; - -import client.Client; -import client.inventory.Item; -import client.inventory.manipulator.InventoryManipulator; -import tools.PacketCreator; -import tools.Randomizer; - -/** - * @Author Arnah - * @Website http://Vertisy.ca/ - * @since Aug 15, 2016 - */ -public class MapleRockPaperScissor{ - - private int round = 0; - private boolean ableAnswer = true; - private boolean win = false; - - public MapleRockPaperScissor(final Client c, final byte mode){ - c.sendPacket(PacketCreator.rpsMode((byte) (9 + mode))); - if(mode == 0){ - c.getPlayer().gainMeso(-1000, true, true, true); - } - } - - public final boolean answer(final Client c, final int answer){ - if(ableAnswer && !win && answer >= 0 && answer <= 2){ - final int response = Randomizer.nextInt(3); - if(response == answer){ - c.sendPacket(PacketCreator.rpsSelection((byte) response, (byte) round)); - // dont do anything. they can still answer once a draw - }else if((answer == 0 && response == 2) || (answer == 1 && response == 0) || (answer == 2 && response == 1)){ // they win - c.sendPacket(PacketCreator.rpsSelection((byte) response, (byte) (round + 1))); - ableAnswer = false; - win = true; - }else{ // they lose - c.sendPacket(PacketCreator.rpsSelection((byte) response, (byte) -1)); - ableAnswer = false; - } - return true; - } - reward(c); - return false; - } - - public final boolean timeOut(final Client c){ - if(ableAnswer && !win){ - ableAnswer = false; - c.sendPacket(PacketCreator.rpsMode((byte) 0x0A)); - return true; - } - reward(c); - return false; - } - - public final boolean nextRound(final Client c){ - if(win){ - round++; - if(round < 10){ - win = false; - ableAnswer = true; - c.sendPacket(PacketCreator.rpsMode((byte) 0x0C)); - return true; - } else { - round = 10; - } - } - reward(c); - return false; - } - - public final void reward(final Client c){ - if(win){ - InventoryManipulator.addFromDrop(c, new Item(4031332 + round, (short) 0, (short) 1), true); - } - c.getPlayer().setRPS(null); - } - - public final void dispose(final Client c){ - reward(c); - c.sendPacket(PacketCreator.rpsMode((byte) 0x0D)); - } -} diff --git a/src/main/java/server/minigame/RockPaperScissor.java b/src/main/java/server/minigame/RockPaperScissor.java new file mode 100644 index 0000000000..81595874d1 --- /dev/null +++ b/src/main/java/server/minigame/RockPaperScissor.java @@ -0,0 +1,83 @@ +package server.minigame; + +import client.Client; +import client.inventory.Item; +import client.inventory.manipulator.InventoryManipulator; +import tools.PacketCreator; +import tools.Randomizer; + +/** + * @Author Arnah + * @Website http://Vertisy.ca/ + * @since Aug 15, 2016 + */ +public class RockPaperScissor { + private int round = 0; + private boolean ableAnswer = true; + private boolean win = false; + + public RockPaperScissor(final Client c, final byte mode) { + c.sendPacket(PacketCreator.rpsMode((byte) (9 + mode))); + if (mode == 0) { + c.getPlayer().gainMeso(-1000, true, true, true); + } + } + + public final boolean answer(final Client c, final int answer) { + if (ableAnswer && !win && answer >= 0 && answer <= 2) { + final int response = Randomizer.nextInt(3); + if (response == answer) { + c.sendPacket(PacketCreator.rpsSelection((byte) response, (byte) round)); + // dont do anything. they can still answer once a draw + } else if ((answer == 0 && response == 2) || (answer == 1 && response == 0) || (answer == 2 && response == 1)) { // they win + c.sendPacket(PacketCreator.rpsSelection((byte) response, (byte) (round + 1))); + ableAnswer = false; + win = true; + } else { // they lose + c.sendPacket(PacketCreator.rpsSelection((byte) response, (byte) -1)); + ableAnswer = false; + } + return true; + } + reward(c); + return false; + } + + public final boolean timeOut(final Client c) { + if (ableAnswer && !win) { + ableAnswer = false; + c.sendPacket(PacketCreator.rpsMode((byte) 0x0A)); + return true; + } + reward(c); + return false; + } + + public final boolean nextRound(final Client c) { + if (win) { + round++; + if (round < 10) { + win = false; + ableAnswer = true; + c.sendPacket(PacketCreator.rpsMode((byte) 0x0C)); + return true; + } else { + round = 10; + } + } + reward(c); + return false; + } + + public final void reward(final Client c) { + if (win) { + InventoryManipulator.addFromDrop(c, new Item(4031332 + round, (short) 0, (short) 1), true); + } + c.getPlayer().setRPS(null); + } + + public final void dispose(final Client c) { + reward(c); + c.sendPacket(PacketCreator.rpsMode((byte) 0x0D)); + } +}