GIGA REFACTOR

This commit is contained in:
2022-03-02 18:51:42 +01:00
parent 553b2f6aad
commit 6df59b1487
92 changed files with 1807 additions and 1785 deletions

View File

@@ -18,58 +18,58 @@ WorldClient::WorldClient(ClientGame* game) : game::World(game), protocol::Packet
}
void WorldClient::HandlePacket(const protocol::WorldBeginDataPacket* packet) {
loadMap(packet);
if (m_Game->getGameState() == game::GameState::Game) {
const game::Color& backgroundColor = getBackgroundColor();
m_Game->getRenderer()->setBackgroundColor({ static_cast<float>(backgroundColor.r / 255.0f), static_cast<float>(backgroundColor.g / 255.0f),
LoadMap(packet);
if (m_Game->GetGameState() == game::GameState::Game) {
const game::Color& backgroundColor = GetBackgroundColor();
m_Game->GetRenderer()->SetBackgroundColor({ static_cast<float>(backgroundColor.r / 255.0f), static_cast<float>(backgroundColor.g / 255.0f),
static_cast<float>(backgroundColor.b / 255.0f) });
}
}
void WorldClient::HandlePacket(const protocol::WorldDataPacket* packet) {
loadMap(packet);
LoadMap(packet);
}
void WorldClient::HandlePacket(const protocol::SpawnMobPacket* packet) {
spawnMobAt(packet->getMobID(), packet->getMobType(), packet->getMobLevel(), packet->getSender(),
packet->getMobX(), packet->getMobY(), packet->getMobDirection());
SpawnMobAt(packet->GetMobID(), packet->GetMobType(), packet->GetMobLevel(), packet->GetSender(),
packet->GetMobX(), packet->GetMobY(), packet->GetMobDirection());
}
void WorldClient::HandlePacket(const protocol::UpgradeTowerPacket* packet) {
game::TowerPtr tower = getTowerById(packet->getTowerID());
game::TowerPtr tower = GetTowerById(packet->GetTowerID());
if (tower == nullptr) return; // this should not happen but who knows ?
tower->upgrade(packet->getTowerLevel().getLevel(), packet->getTowerLevel().getPath());
tower->Upgrade(packet->GetTowerLevel().GetLevel(), packet->GetTowerLevel().GetPath());
}
void WorldClient::HandlePacket(const protocol::WorldAddTowerPacket* packet) {
game::TowerPtr newTower = placeTowerAt(packet->getTowerID(), packet->getTowerType(), packet->getTowerX(), packet->getTowerY(), packet->getBuilder());
game::TowerPtr newTower = PlaceTowerAt(packet->GetTowerID(), packet->GetTowerType(), packet->GetTowerX(), packet->GetTowerY(), packet->GetBuilder());
getWorldNotifier().notifyListeners(&WorldListener::OnTowerAdd, newTower);
GetWorldNotifier().NotifyListeners(&WorldListener::OnTowerAdd, newTower);
}
void WorldClient::HandlePacket(const protocol::RemoveTowerPacket* packet) {
game::TowerPtr tower = removeTower(packet->getTowerID());
game::TowerPtr tower = RemoveTower(packet->GetTowerID());
if (tower != nullptr) {
getWorldNotifier().notifyListeners(&WorldListener::OnTowerRemove, tower);
GetWorldNotifier().NotifyListeners(&WorldListener::OnTowerRemove, tower);
}
}
void WorldClient::HandlePacket(const protocol::UpdateMobStatesPacket* packet) {
for (auto mobState : packet->getMobStates()) {
game::MobID mobId = mobState.getMobId();
auto it = std::find_if(getMobList().begin(), getMobList().end(), [mobId](game::MobPtr mob) { return mob->getMobID() == mobId; });
if (it != getMobList().end()) {
for (auto mobState : packet->GetMobStates()) {
game::MobID mobId = mobState.GetMobId();
auto it = std::find_if(GetMobList().begin(), GetMobList().end(), [mobId](game::MobPtr mob) { return mob->GetMobID() == mobId; });
if (it != GetMobList().end()) {
game::MobPtr& mob = *it;
mob->setCenter(mobState.getMobPosition());
mob->setDirection(mobState.getMobDirection());
mob->setHealth(mobState.getMobLife());
mob->SetCenter(mobState.GetMobPosition());
mob->SetDirection(mobState.GetMobDirection());
mob->SetHealth(mobState.GetMobLife());
}
}
}
void WorldClient::HandlePacket(const protocol::UpdateCastleLifePacket* packet) {
getTeam(packet->getTeamColor()).getCastle().setLife(packet->getCastleLife());
GetTeam(packet->GetTeamColor()).GetCastle().SetLife(packet->GetCastleLife());
}
} // namespace client