fix: check team when placing tower
This commit is contained in:
@@ -157,8 +157,8 @@ public:
|
|||||||
return m_TilePalette.at(index - 1);
|
return m_TilePalette.at(index - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CanPlaceLittleTower(const glm::vec2& worldPos) const;
|
bool CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID player) const;
|
||||||
bool CanPlaceBigTower(const glm::vec2& worldPos) const;
|
bool CanPlaceBigTower(const glm::vec2& worldPos, PlayerID player) const;
|
||||||
|
|
||||||
const std::unordered_map<ChunkCoord, ChunkPtr>& getChunks() const { return m_Chunks; }
|
const std::unordered_map<ChunkCoord, ChunkPtr>& getChunks() const { return m_Chunks; }
|
||||||
|
|
||||||
|
|||||||
@@ -394,14 +394,18 @@ const Color* World::getTileColor(TilePtr tile) const {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::CanPlaceLittleTower(const glm::vec2& worldPos) const {
|
bool World::CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID playerID) const {
|
||||||
TilePtr tile = getTile(worldPos.x, worldPos.y);
|
TilePtr tile = getTile(worldPos.x, worldPos.y);
|
||||||
|
const Player& player = m_Game->getPlayers()[playerID];
|
||||||
|
|
||||||
if (tile == nullptr) {
|
if (tile == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tile->getType() == game::TileType::Tower) {
|
if (tile->getType() == game::TileType::Tower) {
|
||||||
|
const TowerTile* towerTile = (const TowerTile*) tile.get();
|
||||||
|
if(towerTile->team_owner != player.getTeamColor())
|
||||||
|
return false;
|
||||||
for (int x = -1; x < 2; x++) {
|
for (int x = -1; x < 2; x++) {
|
||||||
for (int y = -1; y < 2; y++) {
|
for (int y = -1; y < 2; y++) {
|
||||||
game::TilePtr adjacentTile = getTile(worldPos.x + x, worldPos.y + y);
|
game::TilePtr adjacentTile = getTile(worldPos.x + x, worldPos.y + y);
|
||||||
@@ -416,14 +420,18 @@ bool World::CanPlaceLittleTower(const glm::vec2& worldPos) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::CanPlaceBigTower(const glm::vec2& worldPos) const {
|
bool World::CanPlaceBigTower(const glm::vec2& worldPos, PlayerID playerID) const {
|
||||||
TilePtr tile = getTile(worldPos.x, worldPos.y);
|
TilePtr tile = getTile(worldPos.x, worldPos.y);
|
||||||
|
const Player& player = m_Game->getPlayers()[playerID];
|
||||||
|
|
||||||
if (tile == nullptr) {
|
if (tile == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tile->getType() == game::TileType::Tower) {
|
if (tile->getType() == game::TileType::Tower) {
|
||||||
|
const TowerTile* towerTile = (const TowerTile*) tile.get();
|
||||||
|
if(towerTile->team_owner != player.getTeamColor())
|
||||||
|
return false;
|
||||||
for (int x = -2; x < 3; x++) {
|
for (int x = -2; x < 3; x++) {
|
||||||
for (int y = -2; y < 3; y++) {
|
for (int y = -2; y < 3; y++) {
|
||||||
game::TilePtr adjacentTile = getTile(worldPos.x + x, worldPos.y + y);
|
game::TilePtr adjacentTile = getTile(worldPos.x + x, worldPos.y + y);
|
||||||
|
|||||||
@@ -148,10 +148,10 @@ void ServerConnexion::HandlePacket(protocol::PlaceTowerPacket* packet) {
|
|||||||
const game::TowerInfo& towerInfo = game::getTowerInfo(towerType);
|
const game::TowerInfo& towerInfo = game::getTowerInfo(towerType);
|
||||||
game::World* world = m_Server->getGame().getWorld();
|
game::World* world = m_Server->getGame().getWorld();
|
||||||
if (towerInfo.isBigTower()) {
|
if (towerInfo.isBigTower()) {
|
||||||
if (!world->CanPlaceBigTower({ packet->getTowerX(), packet->getTowerY() }))
|
if (!world->CanPlaceBigTower({ packet->getTowerX(), packet->getTowerY() }, m_ID))
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (!world->CanPlaceLittleTower({ packet->getTowerX(), packet->getTowerY() }))
|
if (!world->CanPlaceLittleTower({ packet->getTowerX(), packet->getTowerY() }, m_ID))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ void WorldRenderer::changeZoom(float zoomStep) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldRenderer::click() {
|
void WorldRenderer::click() {
|
||||||
if (m_Client->getWorld().CanPlaceLittleTower(getClickWorldPos())) {
|
if (m_Client->getWorld().CanPlaceLittleTower(getClickWorldPos(), m_Client->getPlayer()->getID())) {
|
||||||
ImGui::OpenPopup("TowerPlace");
|
ImGui::OpenPopup("TowerPlace");
|
||||||
m_TowerPlacePopupOpened = true;
|
m_TowerPlacePopupOpened = true;
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ void WorldRenderer::renderPopups() const {
|
|||||||
for (int i = 0; i < (int)game::TowerType::TowerCount; i++) {
|
for (int i = 0; i < (int)game::TowerType::TowerCount; i++) {
|
||||||
game::TowerType towerType = game::TowerType(i);
|
game::TowerType towerType = game::TowerType(i);
|
||||||
const game::TowerInfo& towerInfo = game::getTowerInfo(towerType);
|
const game::TowerInfo& towerInfo = game::getTowerInfo(towerType);
|
||||||
if (!towerInfo.isBigTower() || (towerInfo.isBigTower() && m_Client->getWorld().CanPlaceBigTower(getClickWorldPos()))) {
|
if (!towerInfo.isBigTower() || (towerInfo.isBigTower() && m_Client->getWorld().CanPlaceBigTower(getClickWorldPos(), m_Client->getPlayer()->getID()))) {
|
||||||
if (ImGui::Button(game::getTowerInfo(towerType).getName().c_str())) {
|
if (ImGui::Button(game::getTowerInfo(towerType).getName().c_str())) {
|
||||||
m_Client->PlaceTower(towerType, getClickWorldPos());
|
m_Client->PlaceTower(towerType, getClickWorldPos());
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
|
|||||||
Reference in New Issue
Block a user