Skip to content

Commit

Permalink
Merge pull request rtfmcorp#164 from rtfmcorp/dev
Browse files Browse the repository at this point in the history
Release v2.1.2
  • Loading branch information
acknowledge authored Aug 9, 2017
2 parents 710d075 + 5a3a779 commit 9f38294
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 137 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## [2.1.1] - 2017-17-23
## [2.1.2] - 2017-08-09
### Added
- Storage of the sectors ownership data in Redis

### Fixed
- Commanders defection when their base is taken
- Display of the incoming attacks in the admiralty
- Sectors ownership data in faction tactical registry
- Ending of recycling missions
- Conversion of the recycling places when there is no resources left

## [2.1.1] - 2017-07-23
### Added
- Spy and combat active report highlighting in the list
- Daily scheduling for notifications cleaning and inactive accounts management
Expand Down
7 changes: 7 additions & 0 deletions system/Classes/Daemon/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ public function treatCommand($data)
$data['data']['date']
);
break;
case 'cancel':
$this->realTimeActionScheduler->cancelFromProcess(
$data['data']['object_class'],
$data['data']['object_id'],
$data['data']['date']
);
break;
}
}

Expand Down
2 changes: 0 additions & 2 deletions system/Classes/Process/ProcessGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ProcessGateway
*/
public function writeTo(Process $process, $data)
{
\Asylamba\Classes\Daemon\Server::debug('Writing to Process : ' . json_encode($data));
fwrite($process->getOutput(), json_encode($data) . "\n");
}

Expand All @@ -23,7 +22,6 @@ public function writeTo(Process $process, $data)
*/
public function writeToMaster($data)
{
\Asylamba\Classes\Daemon\Server::debug('Writing to master: ' . json_encode($data));
fwrite(STDOUT, json_encode($data) . "\n");
}

Expand Down
24 changes: 24 additions & 0 deletions system/Classes/Scheduler/RealTimeActionScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,36 @@ public function reschedule($object, $date, $oldDate) {
*/
public function cancel($object, $date)
{
if (P_TYPE === 'worker') {
return $this->processGateway->writeToMaster([
'command' => 'cancel',
'data' => [
'object_class' => get_class($object),
'object_id' => $object->id,
'date' => $date
]
]);
}
unset($this->queue[$date][get_class($object) . '-' . $object->id]);

if (empty($this->queue[$date])) {
unset($this->queue[$date]);
}
}

/**
* @param string $class
* @param int $id
* @param string $date
*/
public function cancelFromProcess($class, $id, $date)
{
unset($this->queue[$date][$class . '-' . $id]);

if (empty($this->queue[$date])) {
unset($this->queue[$date]);
}
}

/**
* @return array
Expand Down
2 changes: 2 additions & 0 deletions system/Classes/Task/TechnicalTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class TechnicalTask extends Task
{
const DEFAULT_ESTIMATED_TIME = 10.00;

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 2 additions & 0 deletions system/Classes/Worker/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function init()
$this->container->get('process_manager')->launchProcesses();
$this->container->get('realtime_action_scheduler')->init();
$this->container->get('cyclic_action_scheduler')->init();
$this->container->get('gaia.sector_manager')->initOwnershipData();

$server = $this->container->get('server');
$server->createHttpServer();
$server->listen();
Expand Down
23 changes: 23 additions & 0 deletions system/Modules/Ares/Manager/CommanderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,29 @@ public function getIncomingAttacks($playerId)
return $this->entityManager->getRepository(Commander::class)->getIncomingAttacks($playerId);
}

/**
* @param int $playerId
* @return array
*/
public function getVisibleIncomingAttacks($playerId)
{
$attackingCommanders = $this->getIncomingAttacks($playerId) ;
$incomingCommanders = [] ;

foreach ($attackingCommanders as $commander) {
# va chercher les heures auxquelles il rentre dans les cercles d'espionnage
$startPlace = $this->placeManager->get($commander->getRBase());
$destinationPlace = $this->placeManager->get($commander->getRPlaceDestination());
$times = Game::getAntiSpyEntryTime($startPlace, $destinationPlace, $commander->getArrivalDate());

if (strtotime(Utils::now()) >= strtotime($times[0])) {
# ajout de l'événement
$incomingCommanders[] = $commander;
}
}
return $incomingCommanders;
}

/**
* @param int $playerId
* @return array
Expand Down
11 changes: 6 additions & 5 deletions system/Modules/Athena/Manager/OrbitalBaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public function changeOwnerById($id, $base, $newOwner, $baseCommanders) {
if (in_array($commander->statement, [Commander::INSCHOOL, Commander::ONSALE, Commander::RESERVE])) {
$commander->rPlayer = $newOwner;
} else if ($commander->statement == Commander::MOVING) {
$commander->statement = Commander::RETIRED;
$this->commanderManager->endTravel($commander, Commander::RETIRED);
$this->realtimeActionScheduler->cancel($commander, $commander->getArrivalDate());
} else {
$commander->statement = Commander::DEAD;
Expand Down Expand Up @@ -716,8 +716,7 @@ public function uRecycling($missionId) {
# if there is no more resource
if ($targetPlace->resources <= 0) {
# the place become an empty place
$targetPlace->resources = 0;
$targetPlace->typeOfPlace = Place::EMPTYZONE;
$this->placeManager->turnAsEmptyPlace($targetPlace);

# stop the mission
$mission->statement = RecyclingMission::ST_DELETED;
Expand Down Expand Up @@ -860,8 +859,10 @@ public function uRecycling($missionId) {

# update u
$mission->uRecycling = Utils::addSecondsToDate($mission->uRecycling, $mission->cycleTime);
// Schedule the next mission
$this->realtimeActionScheduler->schedule('athena.orbital_base_manager', 'uRecycling', $mission, $mission->uRecycling);
// Schedule the next mission if there is still resources
if ($mission->getStatement() !== RecyclingMission::ST_DELETED) {
$this->realtimeActionScheduler->schedule('athena.orbital_base_manager', 'uRecycling', $mission, $mission->uRecycling);
}
} else {
# the place become an empty place
$targetPlace->resources = 0;
Expand Down
41 changes: 3 additions & 38 deletions system/Modules/Gaia/EventListener/SectorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,29 @@ class SectorListener
protected $sectorManager;
/** @var SystemManager **/
protected $systemManager;
/** @var OrbitalBaseManager **/
protected $orbitalBaseManager;
/** @var PlayerManager **/
protected $playerManager;
/** @var EntityManager **/
protected $entityManager;
/** @var array **/
protected $scores;
/** @var int **/
protected $minimalScore;

/**
* @param SectorManager $sectorManager
* @param SystemManager $systemManager
* @param OrbitalBaseManager $orbitalBaseManager
* @param PlayerManager $playerManager
* @param EntityManager $entityManager
* @param RedisManager $redisManager
* @param array $scores
* @param int $minimalScore
*/
public function __construct(
SectorManager $sectorManager,
SystemManager $systemManager,
OrbitalBaseManager $orbitalBaseManager,
PlayerManager $playerManager,
EntityManager $entityManager,
$scores,
$minimalScore
)
{
$this->sectorManager = $sectorManager;
$this->systemManager = $systemManager;
$this->orbitalBaseManager = $orbitalBaseManager;
$this->playerManager = $playerManager;
$this->entityManager = $entityManager;
$this->scores = $scores;
$this->minimalScore = $minimalScore;
}

Expand All @@ -61,31 +48,9 @@ public function __construct(
public function onPlaceOwnerChange(PlaceOwnerChangeEvent $event)
{
$system = $this->systemManager->get($event->getPlace()->rSystem);
$systems = $this->systemManager->getSectorSystems($system->rSector);
$sector = $this->sectorManager->get($system->rSector);
$bases = $this->orbitalBaseManager->getSectorBases($system->rSector);
$scores = [];

foreach ($bases as $base)
{
$player = $this->playerManager->get($base->rPlayer);

$scores[$player->rColor] =
(!empty($scores[$player->rColor]))
? $scores[$player->rColor] + $this->scores[$base->typeOfBase]
: $this->scores[$base->typeOfBase]
;
}
// For each system, the owning faction gains two points
foreach ($systems as $system) {
if ($system->rColor === 0) {
continue;
}
$scores[$system->rColor] = (!empty($scores[$system->rColor])) ? $scores[$system->rColor] + 2 : 2;
}
$scores[0] = 0;
arsort($scores);
reset($scores);
$scores = $this->sectorManager->calculateOwnership($sector);

$newColor = key($scores);
$hasEnoughPoints = false;
foreach ($scores as $factionId => $score) {
Expand Down
9 changes: 9 additions & 0 deletions system/Modules/Gaia/Manager/PlaceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ public function updatePlayerPlaces() {
$this->entityManager->commit();
$this->entityManager->clear(Place::class);
}

/**
* @param Place $place
* @return bool
*/
public function turnAsEmptyPlace(Place $place)
{
return $this->entityManager->getRepository(Place::class)->turnAsEmptyPlace($place->getId());
}

public function turnAsSpawnPlace($placeId, $playerId)
{
Expand Down
97 changes: 96 additions & 1 deletion system/Modules/Gaia/Manager/SectorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,71 @@
namespace Asylamba\Modules\Gaia\Manager;

use Asylamba\Classes\Entity\EntityManager;
use Asylamba\Classes\Redis\RedisManager;
use Asylamba\Classes\Process\LoadBalancer;
use Asylamba\Classes\Task\TaskManager;

use Asylamba\Modules\Athena\Manager\OrbitalBaseManager;
use Asylamba\Modules\Zeus\Manager\PlayerManager;
use Asylamba\Modules\Gaia\Manager\SystemManager;

use Asylamba\Modules\Gaia\Model\Sector;

class SectorManager {
/** @var EntityManager **/
protected $entityManager;
/** @var RedisManager **/
protected $redisManager;
/** @var LoadBalancer **/
protected $loadBalancer;
/** @var TaskManager **/
protected $taskManager;
/** @var OrbitalBaseManager **/
protected $orbitalBaseManager;
/** @var PlayerManager **/
protected $playerManager;
/** @var SystemManager **/
protected $systemManager;
/** @var array **/
protected $scores = [];

/**
* @param EntityManager $entityManager
* @param RedisManager $redisManager
* @param LoadBalancer $loadBalancer
* @param TaskManager $taskManager
* @param OrbitalBaseManager $orbitalBaseManager
* @param PlayerManager $playerManager
* @param SystemManager $systemManager
* @param array $scores
*/
public function __construct(EntityManager $entityManager)
public function __construct(
EntityManager $entityManager,
RedisManager $redisManager,
LoadBalancer $loadBalancer,
TaskManager $taskManager,
OrbitalBaseManager $orbitalBaseManager,
PlayerManager $playerManager,
SystemManager $systemManager,
$scores
)
{
$this->entityManager = $entityManager;
$this->redisManager = $redisManager;
$this->loadBalancer = $loadBalancer;
$this->taskManager = $taskManager;
$this->orbitalBaseManager = $orbitalBaseManager;
$this->playerManager = $playerManager;
$this->systemManager = $systemManager;
$this->scores = $scores;
}

public function initOwnershipData()
{
$this->loadBalancer->affectTask(
$this->taskManager->createTechnicalTask('gaia.sector_manager', 'calculateAllOwnerships')
);
}

/**
* @param int $id
Expand Down Expand Up @@ -59,4 +110,48 @@ public function changeOwnership(Sector $sector)
{
$this->entityManager->getRepository(Sector::class)->changeOwnership($sector);
}

public function calculateAllOwnerships()
{
\Asylamba\Classes\Daemon\Server::debug('sectors');
foreach ($this->getAll() as $sector) {
$this->calculateOwnership($sector);
}
}

/**
* @param Sector $sector
* @return array
*/
public function calculateOwnership(Sector $sector)
{
$systems = $this->systemManager->getSectorSystems($sector->getId());
$bases = $this->orbitalBaseManager->getSectorBases($sector->getId());
$scores = [];

foreach ($bases as $base)
{
$player = $this->playerManager->get($base->rPlayer);

$scores[$player->rColor] =
(!empty($scores[$player->rColor]))
? $scores[$player->rColor] + $this->scores[$base->typeOfBase]
: $this->scores[$base->typeOfBase]
;
}
// For each system, the owning faction gains two points
foreach ($systems as $system) {
if ($system->rColor === 0) {
continue;
}
$scores[$system->rColor] = (!empty($scores[$system->rColor])) ? $scores[$system->rColor] + 2 : 2;
}
$scores[0] = 0;
arsort($scores);
reset($scores);

$this->redisManager->getConnection()->set('sector:' . $sector->getId(), serialize($scores));

return $scores;
}
}
Loading

0 comments on commit 9f38294

Please sign in to comment.