feat: implement comprehensive combat system with plugin architecture
- Complete combat system with instant, turn-based, and tactical combat - Plugin-based architecture with CombatPluginManager for extensibility - Real-time combat events via WebSocket - Fleet vs fleet and fleet vs colony combat support - Comprehensive combat statistics and history tracking - Admin panel for combat management and configuration - Database migrations for combat tables and fleet system - Complete test suite for combat functionality - Combat middleware for validation and logging - Service locator pattern for dependency management Combat system features: • Multiple combat resolution types with plugin support • Real-time combat events and spectator support • Detailed combat logs and casualty calculations • Experience gain and veterancy system for ships • Fleet positioning and tactical formations • Combat configurations and modifiers • Queue system for battle processing • Comprehensive admin controls and monitoring 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
1a60cf55a3
commit
8d9ef427be
37 changed files with 13302 additions and 26 deletions
243
src/controllers/player/resource.controller.js
Normal file
243
src/controllers/player/resource.controller.js
Normal file
|
|
@ -0,0 +1,243 @@
|
|||
/**
|
||||
* Resource Controller
|
||||
* Handles resource-related API endpoints for players
|
||||
*/
|
||||
|
||||
const ResourceService = require('../../services/resource/ResourceService');
|
||||
const { asyncHandler } = require('../../middleware/error.middleware');
|
||||
const logger = require('../../utils/logger');
|
||||
const serviceLocator = require('../../services/ServiceLocator');
|
||||
|
||||
// Create resource service with WebSocket integration
|
||||
function getResourceService() {
|
||||
const gameEventService = serviceLocator.get('gameEventService');
|
||||
return new ResourceService(gameEventService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get player's current resources
|
||||
* GET /api/player/resources
|
||||
*/
|
||||
const getPlayerResources = asyncHandler(async (req, res) => {
|
||||
const correlationId = req.correlationId;
|
||||
const playerId = req.user.playerId;
|
||||
|
||||
logger.info('Player resources request received', {
|
||||
correlationId,
|
||||
playerId
|
||||
});
|
||||
|
||||
const resourceService = getResourceService();
|
||||
const resources = await resourceService.getPlayerResources(playerId, correlationId);
|
||||
|
||||
logger.info('Player resources retrieved', {
|
||||
correlationId,
|
||||
playerId,
|
||||
resourceCount: resources.length
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'Resources retrieved successfully',
|
||||
data: {
|
||||
resources
|
||||
},
|
||||
correlationId
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Get player's resource summary (simplified view)
|
||||
* GET /api/player/resources/summary
|
||||
*/
|
||||
const getPlayerResourceSummary = asyncHandler(async (req, res) => {
|
||||
const correlationId = req.correlationId;
|
||||
const playerId = req.user.playerId;
|
||||
|
||||
logger.info('Player resource summary request received', {
|
||||
correlationId,
|
||||
playerId
|
||||
});
|
||||
|
||||
const resourceService = getResourceService();
|
||||
const summary = await resourceService.getPlayerResourceSummary(playerId, correlationId);
|
||||
|
||||
logger.info('Player resource summary retrieved', {
|
||||
correlationId,
|
||||
playerId,
|
||||
resourceTypes: Object.keys(summary)
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'Resource summary retrieved successfully',
|
||||
data: {
|
||||
resources: summary
|
||||
},
|
||||
correlationId
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Get player's resource production rates
|
||||
* GET /api/player/resources/production
|
||||
*/
|
||||
const getResourceProduction = asyncHandler(async (req, res) => {
|
||||
const correlationId = req.correlationId;
|
||||
const playerId = req.user.playerId;
|
||||
|
||||
logger.info('Resource production request received', {
|
||||
correlationId,
|
||||
playerId
|
||||
});
|
||||
|
||||
const resourceService = getResourceService();
|
||||
const production = await resourceService.calculatePlayerResourceProduction(playerId, correlationId);
|
||||
|
||||
logger.info('Resource production calculated', {
|
||||
correlationId,
|
||||
playerId,
|
||||
productionData: production
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'Resource production retrieved successfully',
|
||||
data: {
|
||||
production
|
||||
},
|
||||
correlationId
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Add resources to player (for testing/admin purposes)
|
||||
* POST /api/player/resources/add
|
||||
*/
|
||||
const addResources = asyncHandler(async (req, res) => {
|
||||
const correlationId = req.correlationId;
|
||||
const playerId = req.user.playerId;
|
||||
const { resources } = req.body;
|
||||
|
||||
// Only allow in development environment
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
logger.warn('Resource addition attempted in production', {
|
||||
correlationId,
|
||||
playerId
|
||||
});
|
||||
|
||||
return res.status(403).json({
|
||||
success: false,
|
||||
message: 'Resource addition not allowed in production',
|
||||
correlationId
|
||||
});
|
||||
}
|
||||
|
||||
logger.info('Resource addition request received', {
|
||||
correlationId,
|
||||
playerId,
|
||||
resources
|
||||
});
|
||||
|
||||
const resourceService = getResourceService();
|
||||
const updatedResources = await resourceService.addPlayerResources(
|
||||
playerId,
|
||||
resources,
|
||||
correlationId
|
||||
);
|
||||
|
||||
logger.info('Resources added successfully', {
|
||||
correlationId,
|
||||
playerId,
|
||||
updatedResources
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'Resources added successfully',
|
||||
data: {
|
||||
updatedResources
|
||||
},
|
||||
correlationId
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Transfer resources between colonies
|
||||
* POST /api/player/resources/transfer
|
||||
*/
|
||||
const transferResources = asyncHandler(async (req, res) => {
|
||||
const correlationId = req.correlationId;
|
||||
const playerId = req.user.playerId;
|
||||
const { fromColonyId, toColonyId, resources } = req.body;
|
||||
|
||||
logger.info('Resource transfer request received', {
|
||||
correlationId,
|
||||
playerId,
|
||||
fromColonyId,
|
||||
toColonyId,
|
||||
resources
|
||||
});
|
||||
|
||||
const resourceService = getResourceService();
|
||||
const result = await resourceService.transferResourcesBetweenColonies(
|
||||
fromColonyId,
|
||||
toColonyId,
|
||||
resources,
|
||||
playerId,
|
||||
correlationId
|
||||
);
|
||||
|
||||
logger.info('Resources transferred successfully', {
|
||||
correlationId,
|
||||
playerId,
|
||||
fromColonyId,
|
||||
toColonyId,
|
||||
transferResult: result
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'Resources transferred successfully',
|
||||
data: result,
|
||||
correlationId
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Get all available resource types
|
||||
* GET /api/player/resources/types
|
||||
*/
|
||||
const getResourceTypes = asyncHandler(async (req, res) => {
|
||||
const correlationId = req.correlationId;
|
||||
|
||||
logger.info('Resource types request received', {
|
||||
correlationId
|
||||
});
|
||||
|
||||
const resourceService = getResourceService();
|
||||
const resourceTypes = await resourceService.getResourceTypes(correlationId);
|
||||
|
||||
logger.info('Resource types retrieved', {
|
||||
correlationId,
|
||||
count: resourceTypes.length
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'Resource types retrieved successfully',
|
||||
data: {
|
||||
resourceTypes
|
||||
},
|
||||
correlationId
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
getPlayerResources,
|
||||
getPlayerResourceSummary,
|
||||
getResourceProduction,
|
||||
addResources,
|
||||
transferResources,
|
||||
getResourceTypes
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue