RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.content.gambling.impl.FlowerPoker Class Reference
Inheritance diagram for com.runehive.content.gambling.impl.FlowerPoker:
Collaboration diagram for com.runehive.content.gambling.impl.FlowerPoker:

Classes

enum  Ranking

Public Member Functions

 FlowerPoker (Player host, Player opponent)
void gamble ()
String toString ()
Public Member Functions inherited from com.runehive.content.gambling.Gamble
 Gamble (Player host, Player opponent)
Player getHost ()
Player getOpponent ()

Private Member Functions

void plant (Task gambleTask)

Static Private Member Functions

static Map< Integer, Integer > getPairs (ArrayList< Flowers > list)
static Ranking getRank (Player player)

Additional Inherited Members

Public Attributes inherited from com.runehive.content.gambling.Gamble
int hostScore
 Score betwen the players inside the 'gamble'.
int opponentScore

Detailed Description

Definition at line 20 of file FlowerPoker.java.

Constructor & Destructor Documentation

◆ FlowerPoker()

com.runehive.content.gambling.impl.FlowerPoker.FlowerPoker ( Player host,
Player opponent )

Definition at line 22 of file FlowerPoker.java.

22 {
23 super(host, opponent);
24 }

References com.runehive.content.gambling.Gamble.host, and com.runehive.content.gambling.Gamble.opponent.

Member Function Documentation

◆ gamble()

void com.runehive.content.gambling.impl.FlowerPoker.gamble ( )

Reimplemented from com.runehive.content.gambling.Gamble.

Definition at line 32 of file FlowerPoker.java.

32 {
33 getHost().getGambling().getFlowers().clear();
34 getOpponent().getGambling().getFlowers().clear();
35
36 getHost().getGambling().getGameFlowers().clear();
37 getOpponent().getGambling().getGameFlowers().clear();
38
39 for (int i = 0; i < 5; i++) {
40 Flowers hostFlower = Flowers.values()[Utility.random(Flowers.values().length - 1)];
41 Flowers opponentFlower = Flowers.values()[Utility.random(Flowers.values().length - 1)];
42
43 while (hostFlower == Flowers.BLACK || hostFlower == Flowers.WHITE) {
44 hostFlower = Flowers.values()[Utility.random(Flowers.values().length - 1)];
45 }
46
47 while (opponentFlower == Flowers.BLACK || hostFlower == Flowers.WHITE) {
48 opponentFlower = Flowers.values()[Utility.random(Flowers.values().length - 1)];
49 }
50
51 getHost().getGambling().getFlowers().add(hostFlower);
52 getOpponent().getGambling().getFlowers().add(opponentFlower);
53 }
54 final Ranking hostResult = getRank(getHost());
55 final Ranking opponentResult = getRank(getOpponent());
56
57 System.out.println("Looking for place to play");
58 boolean[] canPlay = { false, false };
59 Position positionOne, positionTwo;
60 do {
61 int maxX = GAMBLING_ZONE.getMaximumX() - GAMBLING_ZONE.getMinimumX();
62 int maxY = GAMBLING_ZONE.getMaximumY() - GAMBLING_ZONE.getMinimumY();
63 System.out.println("maxX: " + maxX + ", " + maxY);
64 positionOne = new Position(GAMBLING_ZONE.getMinimumX() + Utility.random(maxX), GAMBLING_ZONE.getMinimumY() + Utility.random(maxY));
65 positionTwo = positionOne.create(positionOne.getX() + 1, positionOne.getY());
66 canPlay[0] = getHost().getGambling().canPlayFlowerPokerAtPositon(getHost(), positionTwo);
67 canPlay[1] = getHost().getGambling().canPlayFlowerPokerAtPositon(getHost(), positionOne);
68
69 System.out.println(canPlay[0] + " - " + canPlay[1]);
70 } while(canPlay[0] == false || canPlay[1] == false);
71
72 System.out.println("Found a place to play");
73
74 Position finalPositionOne = positionOne;
75 Position finalPositionTwo = positionTwo;
76 World.schedule(new Task(1) {
77 int time = 0;
78
79 @Override
80 protected void execute() {
81 if(getHost().getGambling().getStage() != GambleStage.IN_PROGRESS) {
82 cancel();
83 return;
84 }
85 switch (time) {
86 case 0:
87 getHost().move(finalPositionOne);
88 getOpponent().move(finalPositionTwo);
89 break;
90 case 1:
91 plant(this);
92 break;
93 case 29:
94 getHost().speak("I got " + hostResult.name().toLowerCase().replaceAll("_", " "));
95 getOpponent().speak("I got " + opponentResult.name().toLowerCase().replaceAll("_", " "));
96 break;
97 case 30:
98 getHost().getGambling().finish(getHost(), getOpponent(), hostResult.ordinal(), opponentResult.ordinal());
99 cancel();
100 break;
101 }
102 time++;
103 }
104 });
105 }

References com.runehive.content.gambling.Flowers.BLACK, com.runehive.content.gambling.GambleManager.canPlayFlowerPokerAtPositon(), com.runehive.game.world.position.Position.create(), com.runehive.content.gambling.GambleManager.finish(), com.runehive.content.gambling.GambleManager.getFlowers(), com.runehive.game.world.entity.mob.player.Player.getGambling(), com.runehive.content.gambling.GambleManager.getGameFlowers(), com.runehive.content.gambling.Gamble.getHost(), com.runehive.content.gambling.Gamble.getOpponent(), getRank(), com.runehive.game.world.position.Position.getX(), com.runehive.game.world.position.Position.getY(), com.runehive.content.gambling.GambleStage.IN_PROGRESS, com.runehive.game.world.entity.mob.Mob.move(), plant(), com.runehive.util.Utility.random(), com.runehive.game.world.World.schedule(), com.runehive.game.world.entity.mob.Mob.speak(), and com.runehive.content.gambling.Flowers.WHITE.

Here is the call graph for this function:

◆ getPairs()

Map< Integer, Integer > com.runehive.content.gambling.impl.FlowerPoker.getPairs ( ArrayList< Flowers > list)
staticprivate

Definition at line 227 of file FlowerPoker.java.

227 {
228 Map<Integer, Integer> finalPairs = new HashMap<Integer, Integer>();
229 int[] pairs = new int[14];
230 for (Flowers flower : list) {
231 pairs[flower.ordinal()]++;
232 }
233 int slot = 0;
234 for (int i = 0; i < pairs.length; i++) {
235 if (pairs[i] >= 2) {
236 finalPairs.put(slot, pairs[i]);
237 slot++;
238 }
239 }
240 return finalPairs;
241 }

Referenced by getRank().

Here is the caller graph for this function:

◆ getRank()

Ranking com.runehive.content.gambling.impl.FlowerPoker.getRank ( Player player)
staticprivate

Definition at line 188 of file FlowerPoker.java.

188 {
189 ArrayList<Flowers> flowers = new ArrayList<Flowers>();
190 flowers.addAll(player.getGambling().getFlowers());
191 Collections.sort(flowers);
192 Map<Integer, Integer> pairs = getPairs(flowers);
193 for (int i = 0; i < pairs.size(); i++) {
194 if (pairs.get(i) == null) {
195 continue;
196 }
197 if (pairs.get(i).intValue() == 5) {
198 return Ranking.ROYAL_KIND;
199 }
200 }
201 if (pairs.size() == 2) {
202 if ((pairs.get(0).intValue() == 3 && pairs.get(1).intValue() == 2) || (pairs.get(1).intValue() == 3 && pairs.get(0).intValue() == 2)) {
203 return Ranking.FULL_HOUSE;
204 }
205 }
206 int totalPairs = 0;
207 for (int i = 0; i < pairs.size(); i++) {
208 if (pairs.get(i) == null) {
209 continue;
210 }
211 if (pairs.get(i).intValue() == 3) {
212 return Ranking.THREE_OF_KIND;
213 }
214 if (pairs.get(i).intValue() == 2) {
215 totalPairs++;
216 }
217 }
218 if (totalPairs == 2) {
219 return Ranking.TWO_PAIR;
220 }
221 if (totalPairs == 1) {
222 return Ranking.PAIR;
223 }
224 return Ranking.NOTHING;
225 }

References com.runehive.content.gambling.impl.FlowerPoker.Ranking.FULL_HOUSE, com.runehive.content.gambling.GambleManager.getFlowers(), com.runehive.game.world.entity.mob.player.Player.getGambling(), getPairs(), com.runehive.content.gambling.impl.FlowerPoker.Ranking.NOTHING, com.runehive.content.gambling.impl.FlowerPoker.Ranking.PAIR, com.runehive.content.gambling.impl.FlowerPoker.Ranking.ROYAL_KIND, com.runehive.content.gambling.impl.FlowerPoker.Ranking.THREE_OF_KIND, and com.runehive.content.gambling.impl.FlowerPoker.Ranking.TWO_PAIR.

Referenced by gamble().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plant()

void com.runehive.content.gambling.impl.FlowerPoker.plant ( Task gambleTask)
private

Definition at line 107 of file FlowerPoker.java.

107 {
108 World.schedule(new Task(1) {
109 int time = 0;
110 int type = 0;
111 Flowers hostFlower = getHost().getGambling().getFlowers().get(type);
112 Flowers opponentFlower = getOpponent().getGambling().getFlowers().get(type);
113
114 Player[] players = new Player[] { getHost(), getOpponent() };
115
116 @Override
117 protected void execute() {
118 if(getHost().getGambling().getStage() != GambleStage.IN_PROGRESS) {
119 cancel();
120 return;
121 }
122
123 switch (time) {
124 case 1:
125 for(Player player : players)
126 player.animate(827);
127 break;
128 case 2:
129 hostFlower = getHost().getGambling().getFlowers().get(type);
130 opponentFlower = getOpponent().getGambling().getFlowers().get(type);
131
132 if (hostFlower == null || opponentFlower == null) {
133 cancel();
134 break;
135 }
136
137 for(Player player : players) {
138 Flowers flowers = player.equals(getHost()) ? hostFlower : opponentFlower;
139
140 final CustomGameObject gameFlower = new CustomGameObject(flowers.getId(), player.getPosition().copy());
141 gameFlower.register();
142 player.getGambling().getGameFlowers().add(gameFlower);
143
144 player.movement.walkTo(player.getPosition().south());
145 }
146
147 break;
148 case 3:
149 for(Player player : players) {
150 Flowers flowers = player.equals(getHost()) ? hostFlower : opponentFlower;
151 player.speak("I planted a " + Utility.formatText(flowers.name().toLowerCase()) + " flower.");
152 }
153 break;
154 case 4:
155
156 if(hostFlower.name().equalsIgnoreCase("WHITE") || hostFlower.name().equalsIgnoreCase("BLACK") ||
157 opponentFlower.name().equalsIgnoreCase("WHITE") || opponentFlower.name().equalsIgnoreCase("BLACK")) {
158 getHost().getGambling().finish(getHost(), getOpponent(), 0, 0);
159 gambleTask.cancel();
160 cancel();
161 break;
162 }
163
164 if (type == 4) {
165 cancel();
166 break;
167 }
168
169 time = 0;
170 type++;
171 break;
172 }
173 time++;
174 }
175 });
176 }

References com.runehive.game.task.Task.cancel(), com.runehive.content.gambling.GambleManager.finish(), com.runehive.util.Utility.formatText(), com.runehive.content.gambling.GambleManager.getFlowers(), com.runehive.game.world.entity.mob.player.Player.getGambling(), com.runehive.content.gambling.Gamble.getHost(), com.runehive.content.gambling.Flowers.getId(), com.runehive.content.gambling.Gamble.getOpponent(), com.runehive.content.gambling.GambleStage.IN_PROGRESS, com.runehive.game.world.object.CustomGameObject.register(), and com.runehive.game.world.World.schedule().

Referenced by gamble().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

String com.runehive.content.gambling.impl.FlowerPoker.toString ( )

Definition at line 27 of file FlowerPoker.java.

27 {
28 return "Flower Poker";
29 }

The documentation for this class was generated from the following file: