@Override public void run() { if (run) { // Chose if an AI player should place a bid or the level should change int nextBid = auction.getCurrentBid() + AuctionEngine.BID_DELTA; EBidLevel bidLevel = auction.getBidLevel(); List<IAIPlayer> biddingPlayers = new ArrayList<>(auction.getBiddingPlayers()); biddingPlayers.remove(auction.getBiddingPlayer()); boolean aiBid = rnd.nextInt(2) % 2 == 0 || bidLevel == EBidLevel.INITIAL; if (aiBid && !biddingPlayers.isEmpty()) { Collections.shuffle(biddingPlayers); IAIPlayer bidder = biddingPlayers.get(0); clientServerEventBus.post(new AuctionBid(bidder, nextBid, auction)); } else { EBidLevel nextLevel; switch (bidLevel) { case ONE: nextLevel = EBidLevel.TWO; break; case TWO: nextLevel = EBidLevel.DONE; break; default: throw new IllegalStateException("Levels "+EBidLevel.INITIAL+" and "+EBidLevel.DONE + " are not valid"); } clientServerEventBus.post(new AuctionBidLevel(bidLevel, nextLevel, auction.getBiddingPlayer(), auction)); } } }
private void addCurrentBidInformation(VBox box, IAuction nextAuction, int index) { if (nextAuction.getBiddingPlayer() == null) { // no bid String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.noBid", new Object[]{}, locale.getCurrentLocal()); DecoratedText dt = textFactory.createDecoratedText(template, new HashMap<>()); dt.setId("noBid"); box.getChildren().add(index, dt); } else { // current bid IPlayer bidder = nextAuction.getBiddingPlayer(); String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.currentBid", new Object[]{nextAuction.getCurrentBid(), bidder.getName(), bidder.getLastName()}, locale.getCurrentLocal()); DecoratedText dt = textFactory.createDecoratedText(template, new HashMap<>()); dt.setId("currentBid"); box.getChildren().add(index, dt); } box.getChildren().add(dialogHelper.createVerticalSpacer(20)); }
private String getBidLevelTemplate(IAuction auction) { switch (currentBidLevel.get()) { case INITIAL: return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.noBid", new Object[]{}, locale.getCurrentLocal()); case ONE: return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.first", new Object[]{}, locale.getCurrentLocal()); case TWO: return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.second", new Object[]{}, locale.getCurrentLocal()); case DONE: IPlayer newOwner = auction.getBiddingPlayer(); return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.sold", new Object[]{newOwner.getName(), newOwner.getLastName()}, locale.getCurrentLocal()); default: throw new IllegalStateException("Unhandled state: "+currentBidLevel.get()); } }
@Subscribe public void handleBid(AuctionBid bid) { Preconditions.checkArgument(!bid.getBidder().equals(bid.getAuction().getBiddingPlayer()), "The bidder has to change"); IAuction auction = bid.getAuction(); auction.getCurrentTask().cancel(); auction.setBidLevel(EBidLevel.INITIAL); auction.setBiddingPlayer(bid.getBidder()); auction.setCurrentBid(bid.getAmount()); clientServerEventBus.post(new AuctionBidLevel(auction.getBidLevel(), EBidLevel.INITIAL, bid.getBidder(), auction)); CancelableRunnable task = factory.createNextBidTask(auction); auction.setCurrentTask(task); timer.schedule(task, 30, TimeUnit.SECONDS); }
auctionBtn.setDisable(true); EBidLevel current = currentBidLevel.get(); EBidLevel next = nextAuction.getBiddingPlayer() == null ? EBidLevel.INITIAL : calculateNextBidLevel(current); clientEventBus.post(new AuctionBidLevel(current, next, city.getPlayer(), nextAuction)); } catch (RuntimeException e) {
if (change.getNewLevel() == EBidLevel.DONE) { IPlayer newOwner = auction.getBiddingPlayer(); int amount = auction.getCurrentBid(); if (auction.getOwner().isPresent() && auction.getOwner().get() instanceof IPlayer) {