📄 jawpgameserviceimpl.java
字号:
package net.sf.jawp.game.service;
import java.util.Collection;
import net.sf.jawp.api.domain.BattleReportVO;
import net.sf.jawp.api.domain.Fleet;
import net.sf.jawp.api.domain.GameSpeed;
import net.sf.jawp.api.domain.Planet;
import net.sf.jawp.api.domain.Realm;
import net.sf.jawp.api.service.JAWPGameService;
import net.sf.jawp.game.domain.JAWPGameWorldDO;
import net.sf.jawp.game.domain.JAWPGameWorldRO;
import net.sf.jawp.game.system.transaction.GetBattleReportsTransaction;
import net.sf.jawp.game.system.transaction.MoveFleetTransaction;
import net.sf.jawp.gf.api.domain.Player;
import net.sf.jawp.gf.persistence.PersistenceController;
import net.sf.jawp.gf.system.RootSystem;
import net.sf.jawp.gf.system.RootSystemUnmodifiable;
import net.sf.jawp.util.Log;
/**
* implementation of game service
* @author jarek
*
*/
public class JAWPGameServiceImpl implements JAWPGameService
{
private static final Log LOG = Log.getLog(JAWPGameServiceImpl.class );
private final PersistenceController<RootSystem<JAWPGameWorldDO, JAWPGameWorldRO, JAWPGameService>, RootSystemUnmodifiable<JAWPGameWorldRO> > controller;
private final Player player;
private final JAWPGameWorldRO worldView;
private Realm realm;
public JAWPGameServiceImpl( final PersistenceController<RootSystem<JAWPGameWorldDO, JAWPGameWorldRO, JAWPGameService>, RootSystemUnmodifiable<JAWPGameWorldRO> > ctrl,
final Player ply, final JAWPGameWorldRO world)
{
this.controller = ctrl;
this.worldView = world;
this.player = ply;
}
public JAWPGameServiceImpl( final PersistenceController<RootSystem<JAWPGameWorldDO, JAWPGameWorldRO, JAWPGameService>, RootSystemUnmodifiable<JAWPGameWorldRO> > ctrl,
final Realm realm, final JAWPGameWorldRO world)
{
this.controller = ctrl;
this.worldView = world;
this.player = null;
this.realm = realm;
}
public final Realm getRealm()
{
if ( this.player != null)
{
this.realm = this.getWorldView().getRealm( this.player.getKey());
}
return this.realm;
}
private Realm getCachedRealm()
{
if ( this.realm == null)
{
return getRealm();
}
return this.realm;
}
public final Collection<Planet> getPlanets()
{
return this.getWorldView().getAllPlanets(getCachedRealm());
}
public final void moveFleet( final long fromPlanetKey, final long toPlanetKey, final int size )
{
final long startTime = System.currentTimeMillis();
final Planet from = getWorldView().findPlanet(fromPlanetKey);
assert LOG.debug( (System.currentTimeMillis() - startTime) + "ms for finding src planet of move" );
if ( from.getOwner().getKey() == getRealm().getKey() )
{
final MoveFleetTransaction move = new MoveFleetTransaction( getWorldView().getKey(), fromPlanetKey, toPlanetKey, size);
assert LOG.debug( (System.currentTimeMillis() - startTime) + "ms for creating transaction" );
this.controller.runCommand( move );
}
else
{
throw new IllegalArgumentException();
}
assert LOG.debug( (System.currentTimeMillis() - startTime) + "ms for server processing of move" );
}
public final Realm getOtherRealm(final long realmKey)
{
return this.getWorldView().findRealmByKey(realmKey );
}
private JAWPGameWorldRO getWorldView()
{
return worldView;
}
public Collection<Fleet> getOwnFleets()
{
return this.getWorldView().getFleets(getRealm().getKey());
}
public GameSpeed getGameSpeed()
{
return this.getWorldView().getGameSpeed();
}
/**
* {@inheritDoc}
*/
public Collection<BattleReportVO> getBattleReports()
{
final GetBattleReportsTransaction trans = new GetBattleReportsTransaction( this.getWorldView().getKey(),
this.getRealm().getKey());
return this.controller.runCommand( trans);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -