mirror of
https://github.com/magefree/mage.git
synced 2026-01-22 19:29:59 -08:00
refactor : removed all instances of new Random() and replaced with RandomUtil for a ThreadLocal randomizer
This commit is contained in:
parent
f2cc8d4571
commit
e2a479255a
51 changed files with 173 additions and 133 deletions
|
|
@ -38,6 +38,7 @@ import mage.cards.repository.CardInfo;
|
|||
import mage.cards.repository.CardRepository;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.SetType;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -73,7 +74,7 @@ public class ShadowsOverInnistrad extends ExpansionSet {
|
|||
public void addDoubleFace(List<Card> booster) {
|
||||
for (int i = 0; i < numBoosterDoubleFaced; i++) {
|
||||
List<CardInfo> doubleFacedCards;
|
||||
if (rnd.nextInt(15) < 10) {
|
||||
if (RandomUtil.nextInt(15) < 10) {
|
||||
doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.COMMON);
|
||||
} else {
|
||||
doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.UNCOMMON);
|
||||
|
|
@ -99,14 +100,14 @@ public class ShadowsOverInnistrad extends ExpansionSet {
|
|||
@Override
|
||||
public int getNumberOfSpecialCommons() {
|
||||
// Then about an eighth of the packs will have a second double-faced card, which will be a rare or mythic rare.
|
||||
return rnd.nextInt(8) == 0 ? 1 : 0;
|
||||
return RandomUtil.nextInt(8) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSpecialCommon(List<Card> booster, int number) {
|
||||
// number is here always 1
|
||||
List<CardInfo> doubleFacedCards;
|
||||
if (rnd.nextInt(8) > 0) {
|
||||
if (RandomUtil.nextInt(8) > 0) {
|
||||
doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.RARE);
|
||||
} else {
|
||||
doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.MYTHIC);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ import mage.players.Player;
|
|||
import mage.players.PlayerList;
|
||||
import mage.target.Target;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -76,7 +77,6 @@ public class WhimsOfTheFates extends CardImpl {
|
|||
|
||||
class WhimsOfTheFateEffect extends OneShotEffect {
|
||||
|
||||
protected static Random rnd = new Random();
|
||||
|
||||
public WhimsOfTheFateEffect() {
|
||||
super(Outcome.Detriment);
|
||||
|
|
@ -173,7 +173,7 @@ class WhimsOfTheFateEffect extends OneShotEffect {
|
|||
Player player = game.getPlayer(playerPiles.getKey());
|
||||
if (player != null) {
|
||||
// decide which pile to sacrifice
|
||||
int sacrificePile = rnd.nextInt(3) + 1; // random number from 1 - 3
|
||||
int sacrificePile = RandomUtil.nextInt(3) + 1; // random number from 1 - 3
|
||||
game.informPlayers(new StringBuilder(player.getLogName()).append(" sacrifices pile number ").append(sacrificePile).toString());
|
||||
for (UUID permanentId : playerPiles.getValue().get(sacrificePile)) {
|
||||
Permanent permanent = game.getPermanent(permanentId);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -98,10 +99,9 @@ class RuhanOfTheFomoriEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
Random random = new Random();
|
||||
List<UUID> opponents = new ArrayList<>();
|
||||
opponents.addAll(game.getOpponents(controller.getId()));
|
||||
Player opponent = game.getPlayer(opponents.get(random.nextInt(opponents.size())));
|
||||
Player opponent = game.getPlayer(opponents.get(RandomUtil.nextInt(opponents.size())));
|
||||
if (opponent != null) {
|
||||
ContinuousEffect effect = new AttacksIfAbleTargetPlayerSourceEffect();
|
||||
effect.setTargetPointer(new FixedTarget(opponent.getId()));
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -102,10 +103,9 @@ class RavingDeadEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
Random random = new Random();
|
||||
List<UUID> opponents = new ArrayList<>();
|
||||
opponents.addAll(game.getOpponents(controller.getId()));
|
||||
Player opponent = game.getPlayer(opponents.get(random.nextInt(opponents.size())));
|
||||
Player opponent = game.getPlayer(opponents.get(RandomUtil.nextInt(opponents.size())));
|
||||
if (opponent != null) {
|
||||
ContinuousEffect effect = new AttacksIfAbleTargetPlayerSourceEffect();
|
||||
effect.setTargetPointer(new FixedTarget(opponent.getId()));
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import mage.cards.CardImpl;
|
|||
import mage.filter.common.FilterCreatureCard;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -98,8 +99,7 @@ class HauntedFengrafEffect extends OneShotEffect {
|
|||
if (player != null) {
|
||||
Card[] cards = player.getGraveyard().getCards(new FilterCreatureCard(), game).toArray(new Card[0]);
|
||||
if (cards.length > 0) {
|
||||
Random rnd = new Random();
|
||||
Card card = cards[rnd.nextInt(cards.length)];
|
||||
Card card = cards[RandomUtil.nextInt(cards.length)];
|
||||
card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
|
||||
game.informPlayers(card.getName() + " returned to the hand of " + player.getLogName());
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@
|
|||
*/
|
||||
package mage.sets.eldritchmoon;
|
||||
|
||||
import mage.sets.EldritchMoon;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import mage.filter.predicate.mageobject.CardTypePredicate;
|
|||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.players.Player;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -114,8 +115,7 @@ class CharmbreakerDevilsEffect extends OneShotEffect {
|
|||
new CardTypePredicate(CardType.SORCERY)));
|
||||
Card[] cards = player.getGraveyard().getCards(filter, game).toArray(new Card[0]);
|
||||
if (cards.length > 0) {
|
||||
Random rnd = new Random();
|
||||
Card card = cards[rnd.nextInt(cards.length)];
|
||||
Card card = cards[RandomUtil.nextInt(cards.length)];
|
||||
card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
|
||||
game.informPlayers(new StringBuilder("Charmbreaker Devils: ").append(card.getName()).append(" returned to the hand of ").append(player.getLogName()).toString());
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import mage.filter.FilterCard;
|
|||
import mage.filter.predicate.mageobject.SubtypePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -96,8 +97,7 @@ class GhoulraiserEffect extends OneShotEffect {
|
|||
filter.add(new SubtypePredicate("Zombie"));
|
||||
Card[] cards = player.getGraveyard().getCards(filter, game).toArray(new Card[0]);
|
||||
if (cards.length > 0) {
|
||||
Random rnd = new Random();
|
||||
Card card = cards[rnd.nextInt(cards.length)];
|
||||
Card card = cards[RandomUtil.nextInt(cards.length)];
|
||||
card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
|
||||
game.informPlayers(card.getName() + "returned to the hand of" + player.getLogName());
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import mage.cards.CardImpl;
|
|||
import mage.filter.common.FilterCreatureCard;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -116,7 +117,7 @@ class MoldgrafMonstrosityEffect extends OneShotEffect {
|
|||
return null;
|
||||
}
|
||||
int i = 0;
|
||||
int pick = new Random().nextInt(cards.size());
|
||||
int pick = RandomUtil.nextInt(cards.size());
|
||||
for (Card card : cards) {
|
||||
if (i == pick) {
|
||||
return card;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import mage.cards.CardImpl;
|
|||
import mage.filter.common.FilterCreatureCard;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -101,8 +102,7 @@ class WoodlandSleuthEffect extends OneShotEffect {
|
|||
if (player != null) {
|
||||
Card[] cards = player.getGraveyard().getCards(new FilterCreatureCard(), game).toArray(new Card[0]);
|
||||
if (cards.length > 0) {
|
||||
Random rnd = new Random();
|
||||
Card card = cards[rnd.nextInt(cards.length)];
|
||||
Card card = cards[RandomUtil.nextInt(cards.length)];
|
||||
card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
|
||||
game.informPlayers(card.getName() + " returned to the hand of " + player.getLogName());
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ import mage.filter.predicate.permanent.ControllerPredicate;
|
|||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -115,8 +116,7 @@ class CapriciousEfreetEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
if (!targetPermanents.isEmpty()) {
|
||||
Random random = new Random();
|
||||
permanent = targetPermanents.get(random.nextInt(targetPermanents.size()));
|
||||
permanent = targetPermanents.get(RandomUtil.nextInt(targetPermanents.size()));
|
||||
permanent.destroy(source.getSourceId(), game, false);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.players.PlayerList;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -81,11 +82,10 @@ class ScrambleverseEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Random random = new Random();
|
||||
PlayerList players = game.getState().getPlayersInRange(source.getControllerId(), game);
|
||||
int count = players.size();
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) {
|
||||
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, players.get(random.nextInt(count)));
|
||||
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, players.get(RandomUtil.nextInt(count)));
|
||||
effect.setTargetPointer(new FixedTarget(permanent.getId()));
|
||||
game.addEffect(effect, source);
|
||||
permanent.untap(game);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import mage.constants.Zone;
|
|||
import mage.game.Game;
|
||||
import mage.game.permanent.token.Token;
|
||||
import mage.players.Player;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -106,7 +107,7 @@ class ElementalToken extends Token {
|
|||
public ElementalToken() {
|
||||
super("Elemental", "1/1 red Elemental creature");
|
||||
this.setOriginalExpansionSetCode("M14");
|
||||
this.setTokenType(new Random().nextInt(2) + 1);
|
||||
this.setTokenType(RandomUtil.nextInt(2) + 1);
|
||||
cardType.add(CardType.CREATURE);
|
||||
color.setRed(true);
|
||||
subtype.add("Elemental");
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import mage.constants.Zone;
|
|||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.players.Player;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -83,7 +84,7 @@ class KrarksThumbEffect extends ReplacementEffectImpl {
|
|||
Player player = game.getPlayer(event.getPlayerId());
|
||||
if (player != null) {
|
||||
// because second flip is ignored it may not be done by the player method
|
||||
boolean secondCoinFlip = new Random().nextBoolean();
|
||||
boolean secondCoinFlip = RandomUtil.nextBoolean();
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers("[Flip a coin] " + player.getLogName() + (secondCoinFlip ? " won (head)." : " lost (tail)."));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import mage.filter.FilterCard;
|
|||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -93,8 +94,7 @@ class SurrealMemoirEffect extends OneShotEffect {
|
|||
filter.add(new CardTypePredicate(CardType.INSTANT));
|
||||
Card[] cards = player.getGraveyard().getCards(filter, game).toArray(new Card[0]);
|
||||
if (cards.length > 0) {
|
||||
Random rnd = new Random();
|
||||
Card card = cards[rnd.nextInt(cards.length)];
|
||||
Card card = cards[RandomUtil.nextInt(cards.length)];
|
||||
card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
|
||||
game.informPlayers(card.getName() + "returned to the hand of" + player.getLogName());
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import mage.game.events.GameEvent.EventType;
|
|||
import mage.game.stack.StackObject;
|
||||
import mage.target.Target;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -154,7 +155,7 @@ class GripOfChaosEffect extends OneShotEffect {
|
|||
Set<UUID> possibleTargets = target.possibleTargets(source.getSourceId(), source.getControllerId(), game);
|
||||
if (possibleTargets.size() > 0) {
|
||||
int i = 0;
|
||||
int rnd = new Random().nextInt(possibleTargets.size());
|
||||
int rnd = RandomUtil.nextInt(possibleTargets.size());
|
||||
Iterator<UUID> it = possibleTargets.iterator();
|
||||
while (i < rnd) {
|
||||
it.next();
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.target.Target;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -98,8 +99,8 @@ class WildSwingEffect extends OneShotEffect {
|
|||
if (!source.getTargets().isEmpty() && sourceObject != null) {
|
||||
Target target = source.getTargets().get(0);
|
||||
if (target != null && !target.getTargets().isEmpty()) {
|
||||
Random rnd = new Random();
|
||||
Permanent targetPermanent = game.getPermanent(target.getTargets().get(rnd.nextInt(target.getTargets().size())));
|
||||
|
||||
Permanent targetPermanent = game.getPermanent(target.getTargets().get(RandomUtil.nextInt(target.getTargets().size())));
|
||||
if (targetPermanent != null) {
|
||||
game.informPlayers(sourceObject.getLogName() + ": The randomly chosen target to destroy is " + targetPermanent.getLogName());
|
||||
targetPermanent.destroy(source.getSourceId(), game, false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue