Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarUniverseServer.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-03-27 17:06:51 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-03-27 17:06:51 +1100
commitd53c3ae0e7f4c90f226d343f2536c6de41df0e33 (patch)
treedabbaa04d670a385aa5a859597216141eccb8ca3 /source/game/StarUniverseServer.cpp
parentb8c34971d460de1e724ec5078e8ea9810a2e9a72 (diff)
Store the ship's species as a world property
prevents smorgasbord when upgrading the ship after the player changes the species of the character that owns the ship
Diffstat (limited to 'source/game/StarUniverseServer.cpp')
-rw-r--r--source/game/StarUniverseServer.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/source/game/StarUniverseServer.cpp b/source/game/StarUniverseServer.cpp
index af80e76..f1ec9ca 100644
--- a/source/game/StarUniverseServer.cpp
+++ b/source/game/StarUniverseServer.cpp
@@ -656,7 +656,13 @@ void UniverseServer::updateShips() {
auto newShipUpgrades = p.second->shipUpgrades();
if (auto shipWorld = getWorld(ClientShipWorldId(p.second->playerUuid()))) {
shipWorld->executeAction([&](WorldServerThread*, WorldServer* shipWorld) {
- auto const& speciesShips = m_speciesShips.get(p.second->playerSpecies());
+ String species;
+ if (auto jSpecies = shipWorld->getProperty("ship.species").optString())
+ species = *jSpecies;
+ else
+ shipWorld->setProperty("ship.species", species = p.second->playerSpecies());
+
+ auto const& speciesShips = m_speciesShips.get(species);
Json jOldShipLevel = shipWorld->getProperty("ship.level");
unsigned newShipLevel = min<unsigned>(speciesShips.size() - 1, newShipUpgrades.shipLevel);
@@ -1973,7 +1979,8 @@ Maybe<WorkerPoolPromise<WorldServerThreadPtr>> UniverseServer::shipWorldPromise(
if (!shipWorld) {
Logger::info("UniverseServer: Creating new client ship world {}", clientShipWorldId);
shipWorld = make_shared<WorldServer>(Vec2U(2048, 2048), File::ephemeralFile());
- auto shipStructure = WorldStructure(speciesShips.get(clientContext->playerSpecies()).first());
+ auto& species = clientContext->playerSpecies();
+ auto shipStructure = WorldStructure(speciesShips.get(species).first());
shipStructure = shipWorld->setCentralStructure(shipStructure);
ShipUpgrades currentUpgrades = clientContext->shipUpgrades();
@@ -1984,6 +1991,7 @@ Maybe<WorkerPoolPromise<WorldServerThreadPtr>> UniverseServer::shipWorldPromise(
shipWorld->setSpawningEnabled(false);
shipWorld->setProperty("invinciblePlayers", true);
shipWorld->setProperty("ship.level", 0);
+ shipWorld->setProperty("ship.species", species);
shipWorld->setProperty("ship.fuel", 0);
shipWorld->setProperty("ship.maxFuel", currentUpgrades.maxFuel);
shipWorld->setProperty("ship.crewSize", currentUpgrades.crewSize);