In-game resources views
* Added session records to carry resource information over to the clients * Added SQL support code for the various views * Added interface and implementation of the resource information access component * Hooked resources information queries into both the empire and planet management component * Added resources display to planet and overview pages
This commit is contained in:
parent
56eddcc4f0
commit
597429fadf
45 changed files with 3211 additions and 52 deletions
legacyworlds-server-beans-resources/src/main
java/com/deepclone/lw/beans/game/resources
AbstractResourceMapper.javaEmpireResourceMapper.javaPlanetResourceMapper.javaResourcesInformationDAOBean.java
resources/configuration/game
|
@ -0,0 +1,61 @@
|
|||
package com.deepclone.lw.beans.game.resources;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.deepclone.lw.cmd.player.gdata.AbstractResourceRecord;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Base class for resource information row mappers
|
||||
*
|
||||
* <p>
|
||||
* This class can be used to map resource information rows (for either planets or empires). It
|
||||
* provides a method which maps the resource information's descriptive fields, and implements
|
||||
* Spring's {@link RowMapper} for the correct type.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
* @param <RTYPE>
|
||||
* a resource information record based on {@link AbstractResourceRecord}.
|
||||
*/
|
||||
abstract class AbstractResourceMapper< RTYPE extends AbstractResourceRecord >
|
||||
implements RowMapper< RTYPE >
|
||||
{
|
||||
|
||||
/**
|
||||
* Extract a resource information row's descriptive fields
|
||||
*
|
||||
* <p>
|
||||
* This method will extract the descriptive fields from a resource information row and store
|
||||
* them in a resource information instance. It extracts:
|
||||
* <ul>
|
||||
* <li>the resource's text identifier,
|
||||
* <li>the resource's internationalised name,
|
||||
* <li>the resource's internationalised description,
|
||||
* <li>the resource's internationalised category name, if there is one.
|
||||
* </ul>
|
||||
*
|
||||
* @param resource
|
||||
* the resource information record
|
||||
* @param rs
|
||||
* the result set with the correct row selected
|
||||
*
|
||||
* @throws SQLException
|
||||
* if a SQLException is encountered getting column values
|
||||
*/
|
||||
protected final void getResourceDescription( RTYPE resource , ResultSet rs )
|
||||
throws SQLException
|
||||
{
|
||||
resource.setIdentifier( rs.getString( "resource_identifier" ) );
|
||||
resource.setTitle( rs.getString( "resource_name" ) );
|
||||
resource.setDescription( rs.getString( "resource_description" ) );
|
||||
resource.setCategory( rs.getString( "resource_category" ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.deepclone.lw.beans.game.resources;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.deepclone.lw.cmd.player.gdata.empire.EmpireResourceRecord;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Row mapper for empire resources
|
||||
*
|
||||
* <p>
|
||||
* This class is responsible for converting empire resource information rows into instances of the
|
||||
* corresponding class, {@link EmpireResourceRecord}.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
class EmpireResourceMapper
|
||||
extends AbstractResourceMapper< EmpireResourceRecord >
|
||||
{
|
||||
|
||||
/**
|
||||
* Map a row from <code>emp.resources_view</code>
|
||||
*
|
||||
* <p>
|
||||
* This method extracts the resource's description and the fields specific to empire resource
|
||||
* information from the row, returning the information as an {@link EmpireResourceRecord}
|
||||
* instance.
|
||||
*/
|
||||
@Override
|
||||
public EmpireResourceRecord mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
EmpireResourceRecord resource = new EmpireResourceRecord( );
|
||||
this.getResourceDescription( resource , rs );
|
||||
this.getEmpireFields( resource , rs );
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read empire-specific resource information from a row
|
||||
*
|
||||
* <p>
|
||||
* This method extracts the stockpiled quantity as well as income and upkeep from the row. If a
|
||||
* mining setting is set, it extracts it as well.
|
||||
*
|
||||
* @param resource
|
||||
* the empire resource record
|
||||
* @param rs
|
||||
* the result set with the correct row selected
|
||||
*
|
||||
* @throws SQLException
|
||||
* if a SQLException is encountered getting column values
|
||||
*/
|
||||
private void getEmpireFields( EmpireResourceRecord resource , ResultSet rs )
|
||||
throws SQLException
|
||||
{
|
||||
resource.setStockpiled( rs.getLong( "empres_possessed" ) );
|
||||
resource.setPlanetUpkeep( rs.getLong( "planets_upkeep" ) );
|
||||
resource.setIncome( rs.getLong( "planets_income" ) );
|
||||
resource.setFleetUpkeep( rs.getLong( "fleets_upkeep" ) );
|
||||
|
||||
int miningPriority = rs.getInt( "empmset_weight" );
|
||||
if ( !rs.wasNull( ) ) {
|
||||
resource.setMiningPriority( miningPriority );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
package com.deepclone.lw.beans.game.resources;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.deepclone.lw.cmd.player.gdata.planets.PlanetResourceRecord;
|
||||
import com.deepclone.lw.cmd.player.gdata.planets.ResourceProviderRecord;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Row mapper for planet resources
|
||||
*
|
||||
* <p>
|
||||
* This class maps rows obtained from the planet resources information stored procedure into
|
||||
* instances of {@link PlanetResourceRecord} which can be sent to a client.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
class PlanetResourceMapper
|
||||
extends AbstractResourceMapper< PlanetResourceRecord >
|
||||
{
|
||||
|
||||
/**
|
||||
* Map a row from <code>emp.get_planet_resources( )</code>
|
||||
*
|
||||
* <p>
|
||||
* This method extracts fields that are always present, generating the
|
||||
* {@link PlanetResourceRecord} instance and setting it accordingly, then reads resource
|
||||
* provider columns and adds a {@link ResourceProviderRecord} instance to the record if
|
||||
* necessary.
|
||||
*/
|
||||
@Override
|
||||
public PlanetResourceRecord mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
PlanetResourceRecord resource = getResourceFields( rs );
|
||||
getResourceProvider( rs , resource );
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Map common fields into a {@link PlanetResourceRecord} instance
|
||||
*
|
||||
* <p>
|
||||
* This method creates the instance then reads descriptive fields, then extracts the income,
|
||||
* upkeep and investment fields.
|
||||
*
|
||||
* @param rs
|
||||
* the JDBC result set that contains the row being extracted
|
||||
*
|
||||
* @return the new {@link PlanetResourceRecord} instance with its common fields set
|
||||
*
|
||||
* @throws SQLException
|
||||
* if a SQLException is encountered getting column values
|
||||
*/
|
||||
private PlanetResourceRecord getResourceFields( ResultSet rs )
|
||||
throws SQLException
|
||||
{
|
||||
PlanetResourceRecord resource = new PlanetResourceRecord( );
|
||||
this.getResourceDescription( resource , rs );
|
||||
resource.setIncome( rs.getLong( "pres_income" ) );
|
||||
resource.setUpkeep( rs.getLong( "pres_upkeep" ) );
|
||||
resource.setInvested( rs.getLong( "pres_invested" ) );
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Map resource provider fields if they are present.
|
||||
*
|
||||
* <p>
|
||||
* Check if the record includes resource provider information. If it does, extract the fields'
|
||||
* values into a {@link ResourceProviderRecord} instance and add it to the
|
||||
* {@link PlanetResourceRecord}.
|
||||
*
|
||||
* @param rs
|
||||
* the JDBC result set that contains the row being extracted
|
||||
* @param resource
|
||||
* the {@link PlanetResourceRecord} instance to add information to
|
||||
*
|
||||
* @throws SQLException
|
||||
* if a SQLException is encountered getting column values
|
||||
*/
|
||||
private void getResourceProvider( ResultSet rs , PlanetResourceRecord resource )
|
||||
throws SQLException
|
||||
{
|
||||
long capacity = rs.getLong( "resprov_capacity" );
|
||||
if ( rs.wasNull( ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceProviderRecord provider = new ResourceProviderRecord( );
|
||||
|
||||
provider.setCapacity( capacity );
|
||||
provider.setQuantity( rs.getLong( "resprov_quantity" ) );
|
||||
provider.setDifficulty( rs.getInt( "resprov_difficulty" ) );
|
||||
provider.setPriority( rs.getInt( "mset_weight" ) );
|
||||
|
||||
resource.setResourceProvider( provider );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package com.deepclone.lw.beans.game.resources;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import com.deepclone.lw.cmd.player.gdata.empire.EmpireResourceRecord;
|
||||
import com.deepclone.lw.cmd.player.gdata.planets.PlanetResourceRecord;
|
||||
import com.deepclone.lw.interfaces.game.resources.ResourcesInformationDAO;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Resource information access component
|
||||
*
|
||||
* <p>
|
||||
* This component's goal is to read information about resources from the database and return the
|
||||
* records in some usable format.
|
||||
*
|
||||
* <p>
|
||||
* It does not contain any method that actually change the database.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
class ResourcesInformationDAOBean
|
||||
implements ResourcesInformationDAO
|
||||
{
|
||||
|
||||
/** SQL query that fetches a planet's resources information */
|
||||
private static final String Q_PLANET_RESOURCES = "SELECT * FROM emp.get_planet_resources( ? )";
|
||||
|
||||
/** SQL query that fetches an empire's resources information */
|
||||
private static final String Q_EMPIRE_RESOURCES = "SELECT * FROM emp.resources_view WHERE empire_id = ?";
|
||||
|
||||
/** Row mapper for planet resources */
|
||||
private final PlanetResourceMapper mPlanetResource;
|
||||
|
||||
/** Row mapper for empire resources */
|
||||
private final EmpireResourceMapper mEmpireResource;
|
||||
|
||||
/** Spring JDBC interface */
|
||||
private JdbcTemplate dTemplate;
|
||||
|
||||
|
||||
/** Initialise the necessary row mappers */
|
||||
public ResourcesInformationDAOBean( )
|
||||
{
|
||||
this.mPlanetResource = new PlanetResourceMapper( );
|
||||
this.mEmpireResource = new EmpireResourceMapper( );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that sets the data source
|
||||
*
|
||||
* @param dataSource
|
||||
* the data source
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the planet resources information query and extract the data
|
||||
*
|
||||
* <p>
|
||||
* This implementation simply executes a query using the <code>emp.get_planet_resources()</code>
|
||||
* stored procedure and maps the resulting rows into a list of {@link PlanetResourceRecord}
|
||||
* instances.
|
||||
*/
|
||||
@Override
|
||||
public List< PlanetResourceRecord > getPlanetInformation( int planet )
|
||||
{
|
||||
return this.dTemplate.query( Q_PLANET_RESOURCES , this.mPlanetResource , planet );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the empire resources information query and extract the data
|
||||
*
|
||||
* <p>
|
||||
* This implementation executes a query on <code>emp.resources_view</code> for a specific
|
||||
* empire, and maps the resulting rows into a list of {@link EmpireResourceRecord} instances.
|
||||
*/
|
||||
@Override
|
||||
public List< EmpireResourceRecord > getEmpireInformation( int empire )
|
||||
{
|
||||
return this.dTemplate.query( Q_EMPIRE_RESOURCES , this.mEmpireResource , empire );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||
|
||||
<bean id="resourcesInformationDAO" class="com.deepclone.lw.beans.game.resources.ResourcesInformationDAOBean" />
|
||||
|
||||
</beans>
|
Reference in a new issue