/** * Create the guild instance for the city. * @param city where to create a guild * @return new guild instance */ public IGuild createGuild(ICity city) { IGuild guild = (IGuild) context.getBean("guild", new Object[]{city}); guildList.add(guild); return guild; }
@Subscribe public void handleDailyUpdate(ClockTickDayChange event) { for (IGuild guild : guildList) { for (IAuction auction : guild.getAuctions()) { if (dateService.isToday(auction.getAuctionDate())) { handleAuction(auction, guild); guild.resetAuction(auction); } } } }
@Override public void run() { if (run) { if (auction instanceof IShipAuction) { if (auction.getOwner().isPresent()) { IShipAuction shipAuction = (IShipAuction) auction; clientServerEventBus.post(new ShipNotAuctioned(shipAuction.getAuctionedShip(), shipAuction.getOwner().get())); } } else { IBuildingAuction buildingAuction = (IBuildingAuction) auction; clientServerEventBus.post(new BuildingNotAuctioned(buildingAuction.getAuctionedBuilding(), buildingAuction.getOwner().get())); } } } };
@Subscribe public void handleBidLevelChange(AuctionBidLevel change) { IAuction auction = change.getAuction(); auction.setBidLevel(change.getNewLevel()); auction.setBiddingPlayer(change.getBidder()); if (change.getNewLevel() == EBidLevel.DONE) { IPlayer newOwner = auction.getBiddingPlayer(); int amount = auction.getCurrentBid(); if (auction.getOwner().isPresent() && auction.getOwner().get() instanceof IPlayer) { if (auction.getOwner().get() instanceof IHumanPlayer) { ((IPlayer) auction.getOwner().get()).getCompany().updateCash(amount); } else { ((IPlayer) auction.getOwner().get()).getCompany().updateCashDirectly(amount); clientServerEventBus.post(new ShipAuctionFinished(shipAuction.getAuctionedShip(), newOwner)); } else { IBuildingAuction buildingAuction = (IBuildingAuction) auction; clientServerEventBus.post(new BuildingAuctionFinished(buildingAuction.getAuctionedBuilding(), newOwner));
/** * {@inheritDoc} * Base requirements are: there has to be a guild, not yet a member and enough money to join. * @param player who should decide on joining * @param city where to join * @param vessel possible vessel in the city * @return */ @Override public boolean shouldJoin(IAIPlayer player, ICity city, Optional<INavigableVessel> vessel) { Optional<IGuild> maybeGuild = guildList.findGuild(city); if (maybeGuild.isPresent()) { IGuild guild = maybeGuild.get(); if (guild.getMembers().contains(player)) { return false; } else { ICompany company = player.getCompany(); int fee = guildService.getEntryFee(player); return fee * ENTRY_FEE_FACTOR < company.getCash() && additionalJoinRequirementsMet(player, city, vessel); } } return false; }
@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); }
public LocalDateTime cleanUpAuctionAndDetermineAuctionDate(LocalDateTime auctionDate, IGuild guild) { if (!guild.getAuctions().isEmpty()) { for (IAuction nextAuction : guild.getAuctions()) { if (dateService.isPast(nextAuction.getAuctionDate())) { nextAuction.setAuctionDate(date.getCurrentDate().plusDays(1)); } while (dateService.isSameDay(nextAuction.getAuctionDate(), auctionDate) ) { auctionDate = auctionDate.plusDays(1); } } } return auctionDate; } }
@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.GuildTradeAgreementDialog.title", new Object[]{}, locale.getCurrentLocal())); IMediterreanMap map = guildSettings.getMediterreanMap(); List<ITradeAgreement> agreements = map.getTradeAgreements(city.getPlayer()); VBox box = new VBox(10); for (ITradeAgreement agreement : agreements) { String cityName = agreement.getTradeLocation().getName(); String ware = modelTranslations.getLocalDisplayName((EWare) agreement.getWare()); int price = agreement.getWareAndAmount().getAVGPrice(); int amount = agreement.getWareAndAmount().getAmount(); String till = modelTranslations.toDisplayString(agreement.getValidTill()); String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.GuildTradeAgreementDialog.agreement", new Object[]{cityName, amount, ware, price, till}, locale.getCurrentLocal()); DecoratedText text = textFactory.createDecoratedText(template, new HashMap<>()); box.getChildren().add(text); } box.setLayoutX(2 * FRAME_BORDER); box.setLayoutY(CLOSE_BTN_Y_POS - 500); getContent().add(box); } }
private void addAuctionDescription(VBox box, IAuction nextAuction) { if (nextAuction instanceof IBuildingAuction) { IBuilding building = ((IBuildingAuction) nextAuction).getAuctionedBuilding(); IPlayer owner = nextAuction.getOwner().get(); String name = owner.getName()+" "+owner.getLastName(); String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.buildingAuction", new Object[]{modelTranslations.getLocalDisplayName(building), name}, locale.getCurrentLocal()); DecoratedText dt = textFactory.createDecoratedText(template, new HashMap<>()); dt.setId("buildingAuction"); box.getChildren().add(dt); } else { IShip ship = ((IShipAuction)nextAuction).getAuctionedShip(); String name = ship.getOwner().getName()+" "+ship.getOwner().getLastName(); String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.shipAuction", new Object[]{ship.getName(), name}, locale.getCurrentLocal()); DecoratedText dt = textFactory.createDecoratedText(template, new HashMap<>()); dt.setId("shipAuction"); box.getChildren().add(dt); } box.getChildren().add(dialogHelper.createVerticalSpacer(20)); }
@VisibleForTesting void pawnFromHumanDebitor(final IDebt debt, final ICity city) { // pawn a ship and auction it int sum = (int) (debt.getAmount() * debt.getInterest()); final IPlayer debitor = (IPlayer) debt.getDebitor(); IShip shipMatch = null; int maxDelta = Integer.MAX_VALUE; for (IShip ship : debitor.getFleet()) { int shipValue = ship.getValue(); if (Math.abs(shipValue - sum) < maxDelta) { maxDelta = Math.abs(shipValue - sum); shipMatch = ship; } } if (shipMatch != null) { LocalDateTime auctionDate = date.getCurrentDate().plusDays(10); // Add auction to guild IGuild guild = guildList.findGuild(city).get(); auctionDate = guildService.cleanUpAuctionAndDetermineAuctionDate(auctionDate, guild); IShipAuction auction = modelFactory.createShipAuction(auctionDate, shipMatch.getValue(), debitor, shipMatch); guild.getAuctions().add(auction); final LocalDateTime dateCollectMoney = auctionDate.plusDays(1); TimedTask collectMoney = taskFactory.getLoanerCollectMoneyAfterAuctionTask(debt, dateCollectMoney); taskList.add(collectMoney); } else { final LocalDateTime dateCollectMoney = date.getCurrentDate(); TimedTask collectMoney = taskFactory.getLoanerCollectMoneyTask(debt, debitor, dateCollectMoney); taskList.add(collectMoney); } }
private void handleAuction(IAuction auction, IGuild guild) { List<IAIPlayer> bidders = aiPlayers.findAIPlayersCurrentlyInCity(guild.getCity()); bidders.removeIf(player -> !guild.getMembers().contains(player)); auctionEngine.startAuction(auction, bidders); } }
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)); }
/** * Calculate the entry fee for the guild based on the company value. * @param player for whom to calculate the entry fee * @return entry fee for the player. */ public int getEntryFee(IPlayer player) { long companyValue = player.getCompany().getCompanyValue(); int min = guildSettings.getMinEntryFee(); int max = guildSettings.getMaxEntryFee(); int span = max - min; if (companyValue <= MIN_COMPANY_VALUE) { return min; } if (companyValue >= MAX_COMPANY_VALUE) { return max; } double factor = companyValue * 1.0 / MAX_COMPANY_VALUE; double fee = min + span * factor; return (int)Math.rint(fee); }
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()); } }
@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.GuildMediterraneanMapDialog.title", new Object[]{}, locale.getCurrentLocal())); IMediterreanMap map = guildSettings.getMediterreanMap(); Image image = imageUtilities.createMediterraneanMap(city.getPlayer(), map); ImageView imgView = new ImageView(image); imgView.setId("mediterraneanMap"); imgView.setFitWidth(WRAPPING_WIDTH); imgView.setPreserveRatio(true); VBox box = new VBox(imgView); box.setLayoutX(2 * FRAME_BORDER); box.setLayoutY(CLOSE_BTN_Y_POS - 500); getContent().add(box); } }
IPlayer player = proxy.getPlayer(); ICity city = proxy.getCity(); Optional<IGuild> guildOpt = guildList.findGuild(city); if (!guild.getMembers().contains(player)) { String s = messageSource.getMessage("ch.sahits.game.openpatrician.display.notice.NoticeBoardFactory.guild.join", new Object[]{}, locale.getCurrentLocal()); NoticeBoardMenuEntry entry = createNoticeBoardEntry(s, EDialogType.GUILD_JOIN); if (guild.getMembers().contains(player)) { String s = messageSource.getMessage("ch.sahits.game.openpatrician.display.notice.NoticeBoardFactory.guild.members", new Object[]{}, locale.getCurrentLocal()); NoticeBoardMenuEntry entry = createNoticeBoardEntry(s, EDialogType.GUILD_MEMBERS);
private EventHandler<MouseEvent> joinGuild(final IHumanPlayer player,final ICity city, final int fee) { return mouseEvent -> { try { ICompany company = player.getCompany(); company.updateCash(-fee); IGuild guild = guildList.findGuild(city).get(); guild.join(player); ViewChangeCityPlayerProxyJFX proxy = new ViewChangeCityPlayerProxyJFX(this.city, EViewChangeEvent.MAIN_VIEW_GUILD); clientEventBus.post(new NoticeBoardUpdate(proxy)); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to join the quild", e); } }; } }
private boolean isNextRankAchievable(IPlayer player){ ESocialRank rank = player.getRank(); if (rank==ESocialRank.PATRICIAN || rank==ESocialRank.MAYOR || rank==ESocialRank.ALDERMAN){ return false; } final ICompany company = player.getCompany(); ICity homeTown = player.getHometown(); long compValue = company.getCompanyValue(); ESocialRank nextRank = rank.getNextRank(); double remapedRep = repCalculator.remapReputation(homeTown, player); if (compValue>=nextRank.getCompanyValue() && remapedRep>=nextRank.getSocialRank()){ if (nextRank==ESocialRank.COUNCILMAN){ IGuild guild = guildList.findGuild(homeTown).get(); return guild.getMembers().contains(player); } return true; } return false; }
@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.GuildMembersDialog.title", new Object[]{}, locale.getCurrentLocal())); ICity city = this.city.getCity(); IGuild guild = guildList.findGuild(city).get(); if (guild.getMembers().isEmpty()) { String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.GuildMembersDialog.noMembers", new Object[]{city.getName()}, locale.getCurrentLocal()); DecoratedText text = textFactory.createDecoratedText(template, new HashMap<>()); text.setId("noMembers"); box = new VBox(text); box.setLayoutY(CLOSE_BTN_Y_POS - 500); getContent().addAll(box); } else { List<IPlayer> members = guild.getMembers(); List<IItemNavigatorLabelWrapper<IPlayer>> wrappedList = itemWrapperFactory.createNonLabeledListForPlayer(members); ItemNavigator<IPlayer> itemNavigator = new ItemNavigator<>(wrappedList); initializeContent(itemNavigator); if (members.size() > 1) { Group centerPane = dialogHelper.center(itemNavigator); box.getChildren().addAll(dialogHelper.createVerticalSpacer(50), centerPane); } } }