League boosters randomizing.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.gempukku.lotro.cards.packs;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DefaultSetRarity implements SetRarity {
|
||||
private List<String> _tengwarCards;
|
||||
private Map<String, List<String>> _rarityList;
|
||||
|
||||
public DefaultSetRarity(List<String> tengwarCards, Map<String, List<String>> rarityList) {
|
||||
_tengwarCards = tengwarCards;
|
||||
_rarityList = rarityList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getCardsOfRarity(String rarity) {
|
||||
return Collections.unmodifiableList(_rarityList.get(rarity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTengwarCards() {
|
||||
return Collections.unmodifiableList(_tengwarCards);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.gempukku.lotro.cards.packs;
|
||||
|
||||
import com.gempukku.lotro.common.CardType;
|
||||
import com.gempukku.lotro.common.Side;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprint;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class LeagueBoosterBox {
|
||||
private Random _random = new Random();
|
||||
private LotroCardBlueprintLibrary _library;
|
||||
|
||||
private List<String> _leagueRares;
|
||||
private List<String> _leagueSiteUncommons;
|
||||
private List<String> _leagueShadowUncommons;
|
||||
private List<String> _leagueFPUncommons;
|
||||
private List<String> _leagueShadowCommons;
|
||||
private List<String> _leagueFPCommons;
|
||||
|
||||
private List<String> _foilRares;
|
||||
private List<String> _foilUncommons;
|
||||
private List<String> _foilCommons;
|
||||
|
||||
public LeagueBoosterBox(LotroCardBlueprintLibrary library) {
|
||||
_library = library;
|
||||
}
|
||||
|
||||
public synchronized List<String> getBooster(String setNo) {
|
||||
if (!setNo.equals("1"))
|
||||
throw new IllegalArgumentException("Invalid setNo: "+setNo);
|
||||
initializeFotR();
|
||||
|
||||
boolean hasFoil = _random.nextInt(6) == 0;
|
||||
|
||||
List<String> result = new LinkedList<String>();
|
||||
// Maybe add foil
|
||||
if (hasFoil) {
|
||||
int type = _random.nextInt(11);
|
||||
if (type == 0)
|
||||
result.add(_foilRares.get(_random.nextInt(_foilRares.size()))+"*");
|
||||
else if (type < 4)
|
||||
result.add(_foilUncommons.get(_random.nextInt(_foilUncommons.size()))+"*");
|
||||
else
|
||||
result.add(_foilCommons.get(_random.nextInt(_foilCommons.size()))+"*");
|
||||
}
|
||||
|
||||
// Add rare
|
||||
result.add(_leagueRares.get(_random.nextInt(_leagueRares.size())));
|
||||
|
||||
// Add uncommon site
|
||||
result.add(_leagueSiteUncommons.get(_random.nextInt(_leagueSiteUncommons.size())));
|
||||
|
||||
result.add(_leagueShadowUncommons.get(_random.nextInt(_leagueShadowUncommons.size())));
|
||||
result.add(_leagueFPUncommons.get(_random.nextInt(_leagueFPUncommons.size())));
|
||||
|
||||
Collections.shuffle(_leagueShadowCommons);
|
||||
Collections.shuffle(_leagueFPCommons);
|
||||
|
||||
result.add(_leagueShadowCommons.get(0));
|
||||
result.add(_leagueFPCommons.get(0));
|
||||
|
||||
result.add(_leagueShadowCommons.get(1));
|
||||
result.add(_leagueFPCommons.get(1));
|
||||
|
||||
result.add(_leagueShadowCommons.get(2));
|
||||
result.add(_leagueFPCommons.get(2));
|
||||
|
||||
if (!hasFoil) {
|
||||
if (_random.nextBoolean())
|
||||
result.add(_leagueShadowCommons.get(3));
|
||||
else
|
||||
result.add(_leagueFPCommons.get(3));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void initializeFotR() {
|
||||
if (_foilRares == null) {
|
||||
SetRarity setRarity = new RarityReader().getSetRarity("1");
|
||||
|
||||
List<String> promos = replaceRarity("P", setRarity.getCardsOfRarity("P"));
|
||||
List<String> rares = replaceRarity("R", setRarity.getCardsOfRarity("R"));
|
||||
List<String> uncommons = replaceRarity("U", setRarity.getCardsOfRarity("U"));
|
||||
List<String> commons = replaceRarity("C", setRarity.getCardsOfRarity("C"));
|
||||
|
||||
_foilRares = new ArrayList<String>();
|
||||
_foilRares.addAll(rares);
|
||||
_foilRares.addAll(promos);
|
||||
|
||||
_foilUncommons = new ArrayList<String>();
|
||||
_foilUncommons.addAll(uncommons);
|
||||
|
||||
_foilCommons = new ArrayList<String>();
|
||||
_foilCommons.addAll(commons);
|
||||
|
||||
_leagueRares = new ArrayList<String>();
|
||||
_leagueRares.addAll(rares);
|
||||
|
||||
_leagueShadowUncommons = new ArrayList<String>();
|
||||
_leagueFPUncommons = new ArrayList<String>();
|
||||
_leagueSiteUncommons = new ArrayList<String>();
|
||||
|
||||
for (String uncommon : uncommons) {
|
||||
LotroCardBlueprint blueprint = _library.getLotroCardBlueprint(uncommon);
|
||||
if (blueprint.getSide() == Side.FREE_PEOPLE)
|
||||
_leagueFPUncommons.add(uncommon);
|
||||
else if (blueprint.getSide() == Side.SHADOW)
|
||||
_leagueShadowUncommons.add(uncommon);
|
||||
else
|
||||
_leagueSiteUncommons.add(uncommon);
|
||||
}
|
||||
|
||||
|
||||
_leagueShadowCommons = new ArrayList<String>();
|
||||
_leagueFPCommons = new ArrayList<String>();
|
||||
|
||||
for (String common : commons) {
|
||||
LotroCardBlueprint blueprint = _library.getLotroCardBlueprint(common);
|
||||
if (blueprint.getSide() == Side.FREE_PEOPLE)
|
||||
_leagueFPCommons.add(common);
|
||||
else if (blueprint.getSide() == Side.SHADOW)
|
||||
_leagueShadowCommons.add(common);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> replaceRarity(String rarity, List<String> values) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
for (String value : values)
|
||||
result.add(value.replace(rarity, "_"));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.gempukku.lotro.cards.packs;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RarityReader {
|
||||
public SetRarity getSetRarity(String setNo) {
|
||||
try {
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(RarityReader.class.getResourceAsStream("/set"+setNo+"-rarity.txt"), "UTF-8"));
|
||||
String line;
|
||||
List<String> tengwar = new LinkedList<String>();
|
||||
Map<String, List<String>> cardsByRarity = new HashMap<String, List<String>>();
|
||||
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
if (line.endsWith("T"))
|
||||
tengwar.add(line);
|
||||
else {
|
||||
if (!line.substring(0, setNo.length()).equals(setNo))
|
||||
throw new IllegalStateException("Seems the rarity is for some other set");
|
||||
String rarity = line.substring(setNo.length(), setNo.length()+1);
|
||||
List<String> cards = cardsByRarity.get(rarity);
|
||||
if (cards == null) {
|
||||
cards = new LinkedList<String>();
|
||||
cardsByRarity.put(rarity, cards);
|
||||
}
|
||||
cards.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
return new DefaultSetRarity(tengwar, cardsByRarity);
|
||||
} catch (IOException exp) {
|
||||
throw new RuntimeException("Problem loading rarity of set " + setNo, exp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.gempukku.lotro.cards.packs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SetRarity {
|
||||
public List<String> getCardsOfRarity(String rarity);
|
||||
public List<String> getTengwarCards();
|
||||
}
|
||||
380
gemp-lotr/gemp-lotr-cards/src/main/resources/set1-rarity.txt
Normal file
380
gemp-lotr/gemp-lotr-cards/src/main/resources/set1-rarity.txt
Normal file
@@ -0,0 +1,380 @@
|
||||
1R1
|
||||
1R1T
|
||||
1C2
|
||||
1C3
|
||||
1C4
|
||||
1C5
|
||||
1C6
|
||||
1C7
|
||||
1C8
|
||||
1C9
|
||||
1C10
|
||||
1C11
|
||||
1U12
|
||||
1R13
|
||||
1R13T
|
||||
1R14
|
||||
1R14T
|
||||
1R15
|
||||
1R16
|
||||
1U17
|
||||
1C18
|
||||
1C19
|
||||
1C20
|
||||
1C21
|
||||
1R22
|
||||
1R23
|
||||
1C24
|
||||
1C25
|
||||
1C26
|
||||
1U27
|
||||
1R28
|
||||
1U29
|
||||
1R30
|
||||
1R30T
|
||||
1U31
|
||||
1C32
|
||||
1R33
|
||||
1R34
|
||||
1R35
|
||||
1R36
|
||||
1C37
|
||||
1R38
|
||||
1C39
|
||||
1R40
|
||||
1C41
|
||||
1C42
|
||||
1C43
|
||||
1U44
|
||||
1R45
|
||||
1U46
|
||||
1R47
|
||||
1U48
|
||||
1R49
|
||||
1R50
|
||||
1R50T
|
||||
1U51
|
||||
1C52
|
||||
1C53
|
||||
1U54
|
||||
1R55
|
||||
1U56
|
||||
1U57
|
||||
1C58
|
||||
1C59
|
||||
1U60
|
||||
1C61
|
||||
1R62
|
||||
1U63
|
||||
1U64
|
||||
1U65
|
||||
1R66
|
||||
1C67
|
||||
1C68
|
||||
1R69
|
||||
1U70
|
||||
1R71
|
||||
1R72
|
||||
1R72T
|
||||
1U73
|
||||
1U74
|
||||
1R75
|
||||
1C76
|
||||
1U77
|
||||
1C78
|
||||
1R79
|
||||
1R80
|
||||
1R81
|
||||
1C82
|
||||
1R83
|
||||
1R83T
|
||||
1C84
|
||||
1C85
|
||||
1C86
|
||||
1R87
|
||||
1R88
|
||||
1R89
|
||||
1R89T
|
||||
1R90
|
||||
1U91
|
||||
1C92
|
||||
1R93
|
||||
1U94
|
||||
1R95
|
||||
1R96
|
||||
1R96T
|
||||
1U97
|
||||
1U98
|
||||
1R99
|
||||
1R100
|
||||
1C101
|
||||
1C102
|
||||
1C103
|
||||
1C104
|
||||
1U105
|
||||
1C106
|
||||
1C107
|
||||
1U108
|
||||
1U109
|
||||
1C110
|
||||
1R111
|
||||
1U112
|
||||
1U113
|
||||
1R114
|
||||
1R114T
|
||||
1R115
|
||||
1C116
|
||||
1C117
|
||||
1R118
|
||||
1C119
|
||||
1R120
|
||||
1C121
|
||||
1C122
|
||||
1R123
|
||||
1R124
|
||||
1R125
|
||||
1U126
|
||||
1R127
|
||||
1R127T
|
||||
1R128
|
||||
1R129
|
||||
1U130
|
||||
1R131
|
||||
1R132
|
||||
1C133
|
||||
1C134
|
||||
1U135
|
||||
1U136
|
||||
1R137
|
||||
1C138
|
||||
1R139
|
||||
1R140
|
||||
1C141
|
||||
1U142
|
||||
1R143
|
||||
1C144
|
||||
1C145
|
||||
1C146
|
||||
1R147
|
||||
1R148
|
||||
1C149
|
||||
1C150
|
||||
1C151
|
||||
1C152
|
||||
1U153
|
||||
1C154
|
||||
1R155
|
||||
1C156
|
||||
1C157
|
||||
1C158
|
||||
1U159
|
||||
1C160
|
||||
1U161
|
||||
1U162
|
||||
1R163
|
||||
1U164
|
||||
1R165
|
||||
1R165T
|
||||
1R166
|
||||
1R167
|
||||
1C168
|
||||
1R169
|
||||
1R170
|
||||
1C171
|
||||
1R172
|
||||
1R173
|
||||
1C174
|
||||
1R175
|
||||
1C176
|
||||
1C177
|
||||
1U178
|
||||
1C179
|
||||
1C180
|
||||
1U181
|
||||
1C182
|
||||
1R183
|
||||
1C184
|
||||
1C185
|
||||
1R186
|
||||
1C187
|
||||
1U188
|
||||
1R189
|
||||
1R190
|
||||
1C191
|
||||
1C192
|
||||
1C193
|
||||
1U194
|
||||
1R195
|
||||
1C196
|
||||
1C197
|
||||
1U198
|
||||
1R199
|
||||
1R200
|
||||
1C201
|
||||
1U202
|
||||
1U203
|
||||
1R204
|
||||
1R205
|
||||
1R206
|
||||
1U207
|
||||
1R208
|
||||
1U209
|
||||
1R210
|
||||
1U211
|
||||
1R212
|
||||
1U213
|
||||
1R214
|
||||
1U215
|
||||
1R216
|
||||
1R217
|
||||
1U218
|
||||
1U219
|
||||
1U220
|
||||
1R221
|
||||
1U222
|
||||
1U223
|
||||
1R224
|
||||
1U225
|
||||
1U226
|
||||
1U227
|
||||
1R228
|
||||
1R229
|
||||
1R230
|
||||
1U231
|
||||
1U231T
|
||||
1U232
|
||||
1U233
|
||||
1U234
|
||||
1U235
|
||||
1R236
|
||||
1R237
|
||||
1R237T
|
||||
1U238
|
||||
1U239
|
||||
1R240
|
||||
1U241
|
||||
1U242
|
||||
1R243
|
||||
1R244
|
||||
1R245
|
||||
1R246
|
||||
1R247
|
||||
1C248
|
||||
1U249
|
||||
1R250
|
||||
1U251
|
||||
1R252
|
||||
1R253
|
||||
1R254
|
||||
1C255
|
||||
1R256
|
||||
1R256T
|
||||
1U257
|
||||
1U258
|
||||
1R259
|
||||
1U260
|
||||
1C261
|
||||
1U262
|
||||
1R263
|
||||
1R264
|
||||
1R265
|
||||
1C266
|
||||
1U267
|
||||
1C268
|
||||
1C269
|
||||
1U270
|
||||
1C271
|
||||
1R272
|
||||
1C273
|
||||
1U274
|
||||
1U275
|
||||
1R276
|
||||
1C277
|
||||
1C278
|
||||
1R279
|
||||
1U280
|
||||
1C281
|
||||
1R282
|
||||
1C283
|
||||
1R284
|
||||
1U285
|
||||
1C286
|
||||
1C287
|
||||
1R288
|
||||
1R289
|
||||
1C290
|
||||
1R291
|
||||
1U292
|
||||
1U293
|
||||
1C294
|
||||
1C295
|
||||
1C296
|
||||
1C297
|
||||
1C298
|
||||
1C299
|
||||
1C300
|
||||
1U301
|
||||
1R302
|
||||
1C303
|
||||
1C304
|
||||
1C305
|
||||
1C306
|
||||
1R307
|
||||
1R308
|
||||
1U309
|
||||
1R310
|
||||
1C311
|
||||
1C312
|
||||
1R313
|
||||
1R314
|
||||
1C315
|
||||
1U316
|
||||
1C317
|
||||
1R318
|
||||
1U319
|
||||
1U320
|
||||
1U321
|
||||
1U322
|
||||
1U323
|
||||
1U324
|
||||
1U325
|
||||
1C326
|
||||
1U327
|
||||
1U328
|
||||
1U329
|
||||
1U330
|
||||
1C331
|
||||
1U332
|
||||
1U333
|
||||
1U334
|
||||
1U335
|
||||
1U336
|
||||
1C337
|
||||
1U338
|
||||
1U339
|
||||
1U340
|
||||
1U341
|
||||
1U342
|
||||
1U343
|
||||
1U344
|
||||
1U345
|
||||
1C346
|
||||
1U347
|
||||
1U348
|
||||
1C349
|
||||
1U350
|
||||
1C351
|
||||
1U352
|
||||
1U353
|
||||
1C354
|
||||
1U355
|
||||
1C356
|
||||
1U357
|
||||
1U358
|
||||
1U359
|
||||
1U360
|
||||
1U361
|
||||
1C362
|
||||
1U363
|
||||
1P364
|
||||
1P365
|
||||
Reference in New Issue
Block a user