@Subscribe public void handleShipNotAuction(ShipNotAuctioned event) { IShipOwner owner = event.getShip().getOwner(); if (owner instanceof IHumanPlayer) { // Post targeted message IShip ship = event.getShip(); ((IHumanPlayer) owner).addShip(ship); Optional<ICity> city = shipService.findCity(ship); DisplayMessage msg = new DisplayMessage("ch.sahits.game.openpatrician.engine.player.HumanPlayerEngine.shipNotAuctioned", ship.getName(), city.get().getName()); TargetedEvent targetMsg = new TargetedEvent((IHumanPlayer) event.getNewOwner(), msg); clientServerEventBus.post(targetMsg); } } @Subscribe
ShipFactory shipFactory = context.getBean(ShipFactory.class); IShip ship = shipFactory.createCrayer("Cheat ship name", EShipUpgrade.LEVEL1, 350); player.addShip(ship); player.addSelectableVessel(ship); ship.setOwner(player);
private IHumanPlayer startupGameEnvironment(NewGame newGameDTO) { date.setStartYear(newGameDTO.getStartYear()); GameFactory gameFactory = serverContext.getBean(GameFactory.class); CityFactory cityFactory = serverContext.getBean(CityFactory.class); ShipFactory shipFactory = serverContext.getBean(ShipFactory.class); gameFactory.createMap(newGameDTO.getMapName()); LocationTracker locationTracker = serverContext.getBean(LocationTracker.class); serverContext.getBean(StartNewGameBean.class); IGame game = gameFactory.createGame(newGameDTO.getObjective(), newGameDTO.getDifficulty(), newGameDTO.getSpeed(), newGameDTO.isSingleplayer()); ICity homeCity = cityFactory.createCityByName(newGameDTO.getHometown()); IHumanPlayer player = gameFactory.createPlayer(newGameDTO.getFirstName(), newGameDTO.getLastName(), homeCity, newGameDTO.isMale(), newGameDTO.getDifficulty().getStartingCapital(), EPlayerColor.BLUE); IShip ship = shipFactory.createCrayer(shipNameLoader.getRandomName(), EShipUpgrade.LEVEL1, 350); ship.setOwner(player); player.addShip(ship); player.addSelectableVessel(ship); ship.setLocation(homeCity.getCoordinates()); locationTracker.add(ship); // Start the game server.startGame(game, 1); server.startStandaloneGame(player); serverContext.getBean("startNewGameHandler"); // Force creation of this lazy bean return player; }