
ch.sahits.game.openpatrician.engine.event.task.RefitShipTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of OpenPatricianEngine Show documentation
Show all versions of OpenPatricianEngine Show documentation
Engine part driving the models and the game
package ch.sahits.game.openpatrician.engine.event.task;
import ch.sahits.game.openpatrician.annotation.ClassCategory;
import ch.sahits.game.openpatrician.annotation.EClassCategory;
import ch.sahits.game.openpatrician.annotation.Prototype;
import ch.sahits.game.openpatrician.client.ICityPlayerProxyJFX;
import ch.sahits.game.openpatrician.model.DisplayMessage;
import ch.sahits.game.openpatrician.model.event.TimedTask;
import ch.sahits.game.openpatrician.model.ship.EShipUpgrade;
import ch.sahits.game.openpatrician.model.ship.IShip;
import ch.sahits.game.openpatrician.model.ship.impl.Ship;
import ch.sahits.game.openpatrician.model.ship.impl.ShipWeaponsLocationFactory;
import ch.sahits.game.openpatrician.util.l10n.Locale;
import com.google.common.eventbus.AsyncEventBus;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.MessageSource;
/**
* @author Andi Hotz, (c) Sahits GmbH, 2014
* Created on Feb 23, 2014
*/
@Prototype
@ClassCategory(EClassCategory.DEPENDS_ON_SERIALIZED_BEAN)
class RefitShipTask extends TimedTask {
private final IShip ship;
private final EShipUpgrade level;
protected final ICityPlayerProxyJFX city;
@Autowired
@XStreamOmitField
private ShipWeaponsLocationFactory shipWeaponLocationFactory;
@Autowired
@Qualifier("clientEventBus")
@XStreamOmitField
private AsyncEventBus clientEventBus;
@Autowired
@XStreamOmitField
private Locale locale;
@Autowired
@XStreamOmitField
@Qualifier("messageSource")
private MessageSource messageSource;
public RefitShipTask(DateTime executionTime, IShip ship, EShipUpgrade upgrade, ICityPlayerProxyJFX city) {
super();
setExecutionTime(executionTime);
this.ship = ship;
level = upgrade;
this.city = city;
}
@Override
public void run() {
while (ship.getShipUpgradeLevel() != level) {
ship.upgrade();
((Ship)ship).setShipWeaponsLocation(shipWeaponLocationFactory.getShipWeaponsLocation(ship.getShipType(), level));
}
ship.setAvailable(true);
city.getPlayersShips().add(ship);
if (city.getPlayersShips().size() == 1) {
city.activateShip(ship);
}
int currentCapacity = ship.getCapacity();
DisplayMessage msg = new DisplayMessage(messageSource.getMessage("ch.sahits.game.openpatrician.engine.event.task.RefitShipTask.message", new Object[]{ship.getShipType(), level, currentCapacity}, locale.getCurrentLocal()));
clientEventBus.post(msg);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy