From fec61e540e849136064e95af7f8cb92448e5717c Mon Sep 17 00:00:00 2001 From: Edward Jin <57547638+EddieJ03@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:08:10 -0700 Subject: [PATCH 01/11] some initial light cut code --- config.json | 2 +- include/server/game/servergamestate.hpp | 6 ++-- include/server/game/torchlight.hpp | 4 ++- src/client/client.cpp | 42 ++++++++++++++----------- src/server/game/servergamestate.cpp | 22 +++++++++++-- src/server/game/torchlight.cpp | 14 ++++++++- 6 files changed, 64 insertions(+), 26 deletions(-) diff --git a/config.json b/config.json index 89280081..2c644fdd 100644 --- a/config.json +++ b/config.json @@ -14,7 +14,7 @@ "lobby_name": "Hope you're doing well!1", "lobby_broadcast": true, "max_players": 1, - "disable_dm": true, + "disable_dm": false, "skip_intro": true }, "client": { diff --git a/include/server/game/servergamestate.hpp b/include/server/game/servergamestate.hpp index 08ed53da..a38e8d15 100644 --- a/include/server/game/servergamestate.hpp +++ b/include/server/game/servergamestate.hpp @@ -274,8 +274,6 @@ class ServerGameState { */ std::string to_string(); - Trap* createTrap(CellType type, glm::vec3 corner); - private: /** * list of entities to delete at the end of the tick @@ -357,6 +355,10 @@ class ServerGameState { */ Trap* currentGhostTrap; + std::optional dmCutLights; + + unsigned int lastLightCut; + /** /** * @brief helper function to spawn a wall at a specified cell diff --git a/include/server/game/torchlight.hpp b/include/server/game/torchlight.hpp index 6fc20ffb..c7983d73 100644 --- a/include/server/game/torchlight.hpp +++ b/include/server/game/torchlight.hpp @@ -53,7 +53,7 @@ class Torchlight : public Object { * animations * @parm current ServerGameState */ - void doTick(ServerGameState& state); + void doTick(ServerGameState& state, std::optional light_cut_pos); /** * @brief get current intensity of torch from 0-1 @@ -70,8 +70,10 @@ class Torchlight : public Object { // curr_step from 0-1 in flickering animation float curr_step; + // how much the intensity should change on every server tick float flickering_speed; + // if the flickering animation is inceasing in // intensity or decreasing bool inc_intensity; diff --git a/src/client/client.cpp b/src/client/client.cpp index 6ba42f5c..79ee451b 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1171,25 +1171,25 @@ void Client::lightingPass() { auto camPos = this->cam->getPos(); lighting_shader->setVec3("viewPos", camPos); - if (is_dm) { - auto ambient = glm::vec3(0.1, 0.1, 0.1); - auto diffuse = glm::vec3(0.1, 0.1, 0.1); - auto specular = glm::vec3(0.1, 0.1, 0.1); - std::array dirLights = { - DirLight{glm::vec3(1.0f, 0.0f, 0.0f), ambient, diffuse, specular}, - DirLight{glm::vec3(-1.0f, 1.0f, 0.0f), ambient, diffuse, specular}, - DirLight{glm::vec3(0.0f, 1.0f, 1.0f), ambient, diffuse, specular}, - DirLight{glm::vec3(0.0f, 1.0f, -1.0f), ambient, diffuse, specular}, - }; - - for (int i = 0; i < dirLights.size(); i++) { - std::string i_s = std::to_string(i); - lighting_shader->setVec3("dirLights[" + i_s + "].direction", dirLights[i].direction); - lighting_shader->setVec3("dirLights[" + i_s + "].ambient_color", ambient); - lighting_shader->setVec3("dirLights[" + i_s + "].diffuse_color", diffuse); - lighting_shader->setVec3("dirLights[" + i_s + "].specular_color", specular); - } - } + //if (is_dm) { + // auto ambient = glm::vec3(0.1, 0.1, 0.1); + // auto diffuse = glm::vec3(0.1, 0.1, 0.1); + // auto specular = glm::vec3(0.1, 0.1, 0.1); + // std::array dirLights = { + // DirLight{glm::vec3(1.0f, 0.0f, 0.0f), ambient, diffuse, specular}, + // DirLight{glm::vec3(-1.0f, 1.0f, 0.0f), ambient, diffuse, specular}, + // DirLight{glm::vec3(0.0f, 1.0f, 1.0f), ambient, diffuse, specular}, + // DirLight{glm::vec3(0.0f, 1.0f, -1.0f), ambient, diffuse, specular}, + // }; + + // for (int i = 0; i < dirLights.size(); i++) { + // std::string i_s = std::to_string(i); + // lighting_shader->setVec3("dirLights[" + i_s + "].direction", dirLights[i].direction); + // lighting_shader->setVec3("dirLights[" + i_s + "].ambient_color", ambient); + // lighting_shader->setVec3("dirLights[" + i_s + "].diffuse_color", diffuse); + // lighting_shader->setVec3("dirLights[" + i_s + "].specular_color", specular); + // } + //} for (int i = 0; i < closest_lights->size(); i++) { boost::optional& curr_source = closest_lights->at(i); @@ -1201,6 +1201,10 @@ void Client::lightingPass() { glm::vec3 pos = curr_source->physics.getCenterPosition(); lighting_shader->setFloat("pointLights[" + std::to_string(i) + "].intensity", properties.intensity); + + if (properties.intensity == 0.0f) + std::cout << "light intensity is 0: " << properties.intensity << std::endl; + lighting_shader->setVec3("pointLights[" + std::to_string(i) + "].position", pos); lighting_shader->setVec3("pointLights[" + std::to_string(i) + "].ambient_color", properties.ambient_color); diff --git a/src/server/game/servergamestate.cpp b/src/server/game/servergamestate.cpp index 731e4ae8..05bfa46c 100644 --- a/src/server/game/servergamestate.cpp +++ b/src/server/game/servergamestate.cpp @@ -65,6 +65,8 @@ ServerGameState::ServerGameState(GameConfig config) { this->spawner->spawnDummy(*this); this->spawner->spawnSmallDummy(*this); + this->dmCutLights = {}; + this->lastLightCut = 0; MazeGenerator generator(config); int attempts = 1; @@ -304,6 +306,7 @@ void ServerGameState::update(const EventList& events) { break; } + case EventType::SelectItem: { auto selectItemEvent = boost::get(event.data); @@ -355,6 +358,7 @@ void ServerGameState::update(const EventList& events) { } break; } + case EventType::UseItem: { auto useItemEvent = boost::get(event.data); @@ -375,6 +379,7 @@ void ServerGameState::update(const EventList& events) { } break; } + case EventType::DropItem: { auto dropItemEvent = boost::get(event.data); @@ -389,6 +394,7 @@ void ServerGameState::update(const EventList& events) { } break; } + case EventType::TrapPlacement: { DungeonMaster* dm = this->objects.getDM(); @@ -457,6 +463,9 @@ void ServerGameState::update(const EventList& events) { lightning->useLightning(dm, *this, corner); dm->useMana(); + + this->dmCutLights = corner; + this->lastLightCut = this->timestep; } break; @@ -780,6 +789,12 @@ void ServerGameState::update(const EventList& events) { if (this->objects.getDM() != nullptr) updateDungeonMasterParalysis(); + + // after some amount of timesteps NO CUT + //if (std::abs((int)(this->lastLightCut - this->timestep)) <= 50) { + // this->dmCutLights = {}; + //} + // Increment timestep this->timestep++; @@ -1185,11 +1200,14 @@ void ServerGameState::updateAttacks() { void ServerGameState::doTorchlightTicks() { auto torchlights = this->objects.getTorchlights(); + for (int t = 0; t < torchlights.size(); t++) { auto torchlight = torchlights.get(t); - if (torchlight == nullptr) continue; - torchlight->doTick(*this); + if (torchlight == nullptr) + continue; + + torchlight->doTick(*this, this->dmCutLights); } } diff --git a/src/server/game/torchlight.cpp b/src/server/game/torchlight.cpp index 0792dee5..4374090d 100644 --- a/src/server/game/torchlight.cpp +++ b/src/server/game/torchlight.cpp @@ -78,11 +78,23 @@ void Torchlight::init() { Torchlight::~Torchlight() {} -void Torchlight::doTick(ServerGameState& state) { +void Torchlight::doTick(ServerGameState& state, std::optional light_cut_pos) { if(!this->properties.flickering) { return; } + // cut this light if within position of light cut + if (light_cut_pos.has_value()) { + glm::vec3 pos = light_cut_pos.value(); + + // if within threshold, get out + if (glm::distance(pos, this->physics.shared.getCenterPosition()) <= 100.0f) { + this->curr_intensity = 0.0f; + std::cout << "A LIGHT CUT OUT!" << std::endl; + return; + } + } + // either increment or decrement intensity if (inc_intensity) { this->curr_step += this->flickering_speed; From 7f1a01a6fc9dbd9931d67f0edda956585a280df6 Mon Sep 17 00:00:00 2001 From: Anthony Tarbinian Date: Tue, 4 Jun 2024 22:14:14 -0700 Subject: [PATCH 02/11] add back intensity and ambient to dm lighting shader --- src/client/shaders/dm_deferred_lighting.frag | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/shaders/dm_deferred_lighting.frag b/src/client/shaders/dm_deferred_lighting.frag index 2d07e6fa..f7ea8e65 100644 --- a/src/client/shaders/dm_deferred_lighting.frag +++ b/src/client/shaders/dm_deferred_lighting.frag @@ -44,7 +44,7 @@ vec3 CalcPointLight(in PointLight light, in vec3 fragPos, in vec3 normal, in vec vec3 halfwayDir = normalize(lightDir + viewDir); float diff = max(dot(normal, lightDir), 0.0); - // vec3 ambient = light.ambient_color * mat_diffuse; + vec3 ambient = light.ambient_color * mat_diffuse; vec3 diffuse = light.diffuse_color * diff * mat_diffuse; float spec = pow(max(dot(normal, halfwayDir), 0.0), 16.0); vec3 specular = light.specular_color * spec * mat_shininess; @@ -53,10 +53,10 @@ vec3 CalcPointLight(in PointLight light, in vec3 fragPos, in vec3 normal, in vec float distance = length(light.position - fragPos); float attenuation = 1.0 / (1.0 + light.attn_linear * distance + light.attn_quadratic * (distance * distance)); - // ambient *= attenuation; + ambient *= attenuation; diffuse *= attenuation; specular *= attenuation; - return (diffuse + specular); + return (ambient + diffuse + specular) * light.intensity; } vec3 CalcDirLight(in DirLight light, in vec3 normal, in vec3 viewDir, From 40b5ff750a12957a62b71474bcdc9106e79cb8c9 Mon Sep 17 00:00:00 2001 From: Edward Jin <57547638+EddieJ03@users.noreply.github.com> Date: Tue, 4 Jun 2024 23:23:23 -0700 Subject: [PATCH 03/11] dm can now temporarily cut lights with lightning! --- include/server/game/constants.hpp | 4 +++- src/client/client.cpp | 3 --- src/server/game/servergamestate.cpp | 9 ++++----- src/server/game/torchlight.cpp | 3 +-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/server/game/constants.hpp b/include/server/game/constants.hpp index 2d7d78df..dd3377cc 100644 --- a/include/server/game/constants.hpp +++ b/include/server/game/constants.hpp @@ -102,4 +102,6 @@ #define TRAP_TIME 10 #define TRAP_COOL_DOWN 5 #define ITEM_SPAWN_PROB 0.1 -#define ITEM_SPAWN_BOUND 3 \ No newline at end of file +#define ITEM_SPAWN_BOUND 3 +#define LIGHT_CUT_TICKS 100 +#define LIGHT_CUT_RANGE 25.0 \ No newline at end of file diff --git a/src/client/client.cpp b/src/client/client.cpp index 79ee451b..f0902380 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1202,9 +1202,6 @@ void Client::lightingPass() { lighting_shader->setFloat("pointLights[" + std::to_string(i) + "].intensity", properties.intensity); - if (properties.intensity == 0.0f) - std::cout << "light intensity is 0: " << properties.intensity << std::endl; - lighting_shader->setVec3("pointLights[" + std::to_string(i) + "].position", pos); lighting_shader->setVec3("pointLights[" + std::to_string(i) + "].ambient_color", properties.ambient_color); diff --git a/src/server/game/servergamestate.cpp b/src/server/game/servergamestate.cpp index a2ad25e0..f0fc2264 100644 --- a/src/server/game/servergamestate.cpp +++ b/src/server/game/servergamestate.cpp @@ -788,12 +788,11 @@ void ServerGameState::update(const EventList& events) { // Only do this if the DM exists if (this->objects.getDM() != nullptr) updateDungeonMasterParalysis(); - - // after some amount of timesteps NO CUT - //if (std::abs((int)(this->lastLightCut - this->timestep)) <= 50) { - // this->dmCutLights = {}; - //} + // after some amount of timesteps uncut lights + if ((this->timestep - this->lastLightCut) >= LIGHT_CUT_TICKS && this->dmCutLights.has_value()) { + this->dmCutLights = {}; + } // Increment timestep this->timestep++; diff --git a/src/server/game/torchlight.cpp b/src/server/game/torchlight.cpp index 4374090d..14a9d909 100644 --- a/src/server/game/torchlight.cpp +++ b/src/server/game/torchlight.cpp @@ -88,9 +88,8 @@ void Torchlight::doTick(ServerGameState& state, std::optional light_c glm::vec3 pos = light_cut_pos.value(); // if within threshold, get out - if (glm::distance(pos, this->physics.shared.getCenterPosition()) <= 100.0f) { + if (glm::distance(pos, this->physics.shared.getCenterPosition()) <= LIGHT_CUT_RANGE) { this->curr_intensity = 0.0f; - std::cout << "A LIGHT CUT OUT!" << std::endl; return; } } From 06ea8587f94c458a24e30cad0213d8ae51792491 Mon Sep 17 00:00:00 2001 From: Edward Jin <57547638+EddieJ03@users.noreply.github.com> Date: Tue, 4 Jun 2024 23:53:53 -0700 Subject: [PATCH 04/11] added light cut action (need to test) --- include/server/game/constants.hpp | 1 + include/server/game/dungeonmaster.hpp | 2 +- include/server/game/servergamestate.hpp | 18 ++++++++++- include/server/game/torchlight.hpp | 2 +- include/shared/game/celltype.hpp | 1 + include/shared/game/sharedmodel.hpp | 3 +- src/client/client.cpp | 4 +++ src/client/gui/gui.cpp | 12 +++++++ src/server/game/dungeonmaster.cpp | 7 +++-- src/server/game/servergamestate.cpp | 42 ++++++++++++++++++------- src/server/game/torchlight.cpp | 16 ++++++++-- 11 files changed, 87 insertions(+), 21 deletions(-) diff --git a/include/server/game/constants.hpp b/include/server/game/constants.hpp index dd3377cc..17a2f3d7 100644 --- a/include/server/game/constants.hpp +++ b/include/server/game/constants.hpp @@ -72,6 +72,7 @@ #define DM_MANA_TOTAL 30 #define DM_MANA_REGEN 1 #define LIGHTNING_MANA 10 +#define LIGHT_CUT_MANA 5 /* Mirror Item */ // Mirror use duration in seconds diff --git a/include/server/game/dungeonmaster.hpp b/include/server/game/dungeonmaster.hpp index 87b85388..e46357a9 100644 --- a/include/server/game/dungeonmaster.hpp +++ b/include/server/game/dungeonmaster.hpp @@ -24,7 +24,7 @@ class DungeonMaster : public Creature { void setPlacedTraps(int placedTraps); // For lightning usage - void useMana(); + void useMana(int mana); void manaRegen(); /** diff --git a/include/server/game/servergamestate.hpp b/include/server/game/servergamestate.hpp index f7e760bc..22cd510e 100644 --- a/include/server/game/servergamestate.hpp +++ b/include/server/game/servergamestate.hpp @@ -355,10 +355,26 @@ class ServerGameState { */ Trap* currentGhostTrap; - std::optional dmCutLights; + /** + * @brief Field that stores the lightning pos for cutting lights + */ + std::optional dmLightningCutLights; + + /** + * @brief Field that stores the light cut action for cutting lights + */ + std::optional dmActionCutLights; + /** + * @brief last light cut for light cut action + */ unsigned int lastLightCut; + /** + * @brief last light cut for lightning action + */ + unsigned int lastLightningLightCut; + /** /** * @brief helper function to spawn a wall at a specified cell diff --git a/include/server/game/torchlight.hpp b/include/server/game/torchlight.hpp index c7983d73..fb1a7345 100644 --- a/include/server/game/torchlight.hpp +++ b/include/server/game/torchlight.hpp @@ -53,7 +53,7 @@ class Torchlight : public Object { * animations * @parm current ServerGameState */ - void doTick(ServerGameState& state, std::optional light_cut_pos); + void doTick(ServerGameState& state, std::optional lightning_light_cut_pos, std::optional action_light_cut_pos); /** * @brief get current intensity of torch from 0-1 diff --git a/include/shared/game/celltype.hpp b/include/shared/game/celltype.hpp index 6c71653b..42db2fb0 100644 --- a/include/shared/game/celltype.hpp +++ b/include/shared/game/celltype.hpp @@ -42,5 +42,6 @@ enum class CellType { Exit, Lightning, Mirror, + LightCut, Unknown }; \ No newline at end of file diff --git a/include/shared/game/sharedmodel.hpp b/include/shared/game/sharedmodel.hpp index 29248a9e..12a22362 100644 --- a/include/shared/game/sharedmodel.hpp +++ b/include/shared/game/sharedmodel.hpp @@ -36,5 +36,6 @@ enum class ModelType { FireballTrapDown, SunGod, ArrowTrap, - Mirror + Mirror, + LightCut }; \ No newline at end of file diff --git a/src/client/client.cpp b/src/client/client.cpp index f0902380..2797c839 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -366,7 +366,11 @@ void Client::sendTrapEvent(bool hover, bool place, ModelType trapType) { case ModelType::Lightning: this->session->sendEvent(Event(eid, EventType::TrapPlacement, TrapPlacementEvent(eid, this->world_pos, CellType::Lightning, hover, place))); break; + case ModelType::LightCut: + this->session->sendEvent(Event(eid, EventType::TrapPlacement, TrapPlacementEvent(eid, this->world_pos, CellType::LightCut, hover, place))); + break; } + } // Handle any updates diff --git a/src/client/gui/gui.cpp b/src/client/gui/gui.cpp index 5681a1fd..71774baa 100644 --- a/src/client/gui/gui.cpp +++ b/src/client/gui/gui.cpp @@ -1096,6 +1096,11 @@ void GUI::_sharedGameHUD() { break; } + case ModelType::LightCut: { + itemString = "Cut Lights (5)"; + + break; + } case ModelType::TeleporterTrap: { itemString = "Teleporter Trap"; @@ -1247,6 +1252,10 @@ void GUI::_sharedGameHUD() { case ModelType::Lightning: { itemString = "Lightning Bolt (10)"; + break; + }case ModelType::LightCut: { + itemString = "Cut Lights (5)"; + break; } case ModelType::TeleporterTrap: { @@ -1419,6 +1428,9 @@ void GUI::_sharedGameHUD() { case ModelType::Lightning: { itemflex->push(widget::StaticImg::make(glm::vec2(0.0f), images.getImg(img::ImgID::Lightning), 2)); break; + }case ModelType::LightCut: { + itemflex->push(widget::StaticImg::make(glm::vec2(0.0f), images.getImg(img::ImgID::Lightning), 2)); + break; } case ModelType::ArrowTrap: { itemflex->push(widget::StaticImg::make(glm::vec2(0.0f), images.getImg(img::ImgID::ArrowTrap), 2)); diff --git a/src/server/game/dungeonmaster.cpp b/src/server/game/dungeonmaster.cpp index 986af5f9..0cee222d 100644 --- a/src/server/game/dungeonmaster.cpp +++ b/src/server/game/dungeonmaster.cpp @@ -26,11 +26,12 @@ DungeonMaster::DungeonMaster(glm::vec3 corner, glm::vec3 facing) : // TODO: fill in rest of traps this->sharedTrapInventory.inventory[0] = ModelType::Lightning; - this->sharedTrapInventory.inventory[1] = ModelType::TeleporterTrap; + this->sharedTrapInventory.inventory[1] = ModelType::LightCut; this->sharedTrapInventory.inventory[2] = ModelType::ArrowTrap; this->sharedTrapInventory.inventory[3] = ModelType::SunGod; this->sharedTrapInventory.inventory[4] = ModelType::SpikeTrap; this->sharedTrapInventory.inventory[5] = ModelType::FloorSpikeFull; + this->sharedTrapInventory.inventory[6] = ModelType::TeleporterTrap; // DungeonMaster paralysis (relevant when the DM is paralyzed by a Player // reflecting a lightning bolt back at the DM using a Mirror) @@ -54,11 +55,11 @@ void DungeonMaster::setPlacedTraps(int traps) { this->placedTraps = traps; } -void DungeonMaster::useMana() { +void DungeonMaster::useMana(int mana) { if (this->dmInfo.mana_remaining == DM_MANA_TOTAL) { this->mana_used = std::chrono::system_clock::now(); } - this->dmInfo.mana_remaining -= LIGHTNING_MANA; + this->dmInfo.mana_remaining -= mana; } void DungeonMaster::manaRegen() { diff --git a/src/server/game/servergamestate.cpp b/src/server/game/servergamestate.cpp index f0fc2264..c5f2c234 100644 --- a/src/server/game/servergamestate.cpp +++ b/src/server/game/servergamestate.cpp @@ -65,7 +65,8 @@ ServerGameState::ServerGameState(GameConfig config) { this->spawner->spawnDummy(*this); this->spawner->spawnSmallDummy(*this); - this->dmCutLights = {}; + this->dmLightningCutLights = {}; + this->dmActionCutLights = {}; this->lastLightCut = 0; MazeGenerator generator(config); @@ -410,7 +411,8 @@ void ServerGameState::update(const EventList& events) { float cellWidth = currGrid.grid_cell_width; // If the DM is paralyzed, do nothing - if (dm->isParalyzed()) break; + if (dm->isParalyzed()) + break; glm::vec3 dir = glm::normalize(trapPlacementEvent.world_pos-dm->physics.shared.corner); @@ -433,9 +435,9 @@ void ServerGameState::update(const EventList& events) { if (trapPlacementEvent.hover) { // only hover for traps, not lightning - if (trapPlacementEvent.cell == CellType::Lightning) { + if (trapPlacementEvent.cell == CellType::Lightning || trapPlacementEvent.cell == CellType::LightCut) break; - } + Trap* trap = placeTrapInCell(cell, trapPlacementEvent.cell); @@ -462,10 +464,23 @@ void ServerGameState::update(const EventList& events) { ); lightning->useLightning(dm, *this, corner); - dm->useMana(); + dm->useMana(LIGHTNING_MANA); + + this->dmLightningCutLights = corner; + this->lastLightningLightCut = this->timestep; + } + + break; + } + + if (trapPlacementEvent.cell == CellType::LightCut) { + if (dm->dmInfo.mana_remaining >= LIGHT_CUT_MANA) { + this->dmActionCutLights = trapPlacementEvent.world_pos; - this->dmCutLights = corner; - this->lastLightCut = this->timestep; + // go back 150 ticks (light cut is longer) + this->lastLightCut = std::max(this->timestep, (unsigned int)150) - 150; + + dm->useMana(LIGHT_CUT_MANA); } break; @@ -790,10 +805,15 @@ void ServerGameState::update(const EventList& events) { updateDungeonMasterParalysis(); // after some amount of timesteps uncut lights - if ((this->timestep - this->lastLightCut) >= LIGHT_CUT_TICKS && this->dmCutLights.has_value()) { - this->dmCutLights = {}; + if ((this->timestep - this->lastLightningLightCut) >= LIGHT_CUT_TICKS && this->dmLightningCutLights.has_value()) { + this->dmLightningCutLights = {}; } - + + // after some amount of timesteps uncut lights + if ((this->timestep - this->lastLightCut) >= LIGHT_CUT_TICKS && this->dmActionCutLights.has_value()) { + this->dmActionCutLights = {}; + } + // Increment timestep this->timestep++; @@ -1204,7 +1224,7 @@ void ServerGameState::doTorchlightTicks() { if (torchlight == nullptr) continue; - torchlight->doTick(*this, this->dmCutLights); + torchlight->doTick(*this, this->dmLightningCutLights, this->dmActionCutLights); } } diff --git a/src/server/game/torchlight.cpp b/src/server/game/torchlight.cpp index 14a9d909..96308bc8 100644 --- a/src/server/game/torchlight.cpp +++ b/src/server/game/torchlight.cpp @@ -78,14 +78,24 @@ void Torchlight::init() { Torchlight::~Torchlight() {} -void Torchlight::doTick(ServerGameState& state, std::optional light_cut_pos) { +void Torchlight::doTick(ServerGameState& state, std::optional lightning_light_cut_pos, std::optional action_light_cut_pos) { if(!this->properties.flickering) { return; } // cut this light if within position of light cut - if (light_cut_pos.has_value()) { - glm::vec3 pos = light_cut_pos.value(); + if (lightning_light_cut_pos.has_value()) { + glm::vec3 pos = lightning_light_cut_pos.value(); + + // if within threshold, get out + if (glm::distance(pos, this->physics.shared.getCenterPosition()) <= LIGHT_CUT_RANGE) { + this->curr_intensity = 0.0f; + return; + } + } + + if (action_light_cut_pos.has_value()) { + glm::vec3 pos = action_light_cut_pos.value(); // if within threshold, get out if (glm::distance(pos, this->physics.shared.getCenterPosition()) <= LIGHT_CUT_RANGE) { From a6a5850d5b8ea2776868a77611a8323b1c4dcf77 Mon Sep 17 00:00:00 2001 From: Edward Jin <57547638+EddieJ03@users.noreply.github.com> Date: Wed, 5 Jun 2024 00:21:57 -0700 Subject: [PATCH 05/11] swapped ctrl and shift for DM + scaled sprint with height --- src/client/client.cpp | 20 +++++--------------- src/server/game/servergamestate.cpp | 4 +++- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 2797c839..80fbbb37 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1431,16 +1431,13 @@ void Client::keyCallback(GLFWwindow *window, int key, int scancode, int action, break; /* Send an event to start 'shift' movement (i.e. sprint) */ case GLFW_KEY_LEFT_SHIFT: - if (eid.has_value() && !this->session->getInfo().is_dungeon_master.value()) { + if (eid.has_value()) { this->session->sendEvent(Event(eid.value(), EventType::StartAction, StartActionEvent(eid.value(), glm::vec3(0.0f), ActionType::Sprint))); } - is_held_i = true; + break; case GLFW_KEY_LEFT_CONTROL: - if (this->session->getInfo().is_dungeon_master.has_value() && this->session->getInfo().is_dungeon_master.value()) { - this->session->sendEvent(Event(eid.value(), EventType::StartAction, StartActionEvent(eid.value(), glm::vec3(0.0f), ActionType::Sprint))); - } - + is_held_i = true; break; default: @@ -1484,10 +1481,9 @@ void Client::keyCallback(GLFWwindow *window, int key, int scancode, int action, break; case GLFW_KEY_LEFT_SHIFT: - if (eid.has_value() && !this->session->getInfo().is_dungeon_master.value()) { + if (eid.has_value()) { this->session->sendEvent(Event(eid.value(), EventType::StopAction, StopActionEvent(eid.value(), glm::vec3(0.0f), ActionType::Sprint))); } - is_held_i = false; break; case GLFW_KEY_O: // zoom out @@ -1497,16 +1493,10 @@ void Client::keyCallback(GLFWwindow *window, int key, int scancode, int action, } break; case GLFW_KEY_I: // zoom out - if (eid.has_value() && this->session->getInfo().is_dungeon_master.value()) { - //sendTrapEvent(true, false, (this->gameState.objects.at(eid.value()))->trapInventoryInfo->inventory[(this->gameState.objects.at(eid.value()))->trapInventoryInfo->selected-1]); - } is_held_i = false; break; case GLFW_KEY_LEFT_CONTROL: - if (this->session->getInfo().is_dungeon_master.has_value() && this->session->getInfo().is_dungeon_master.value()) { - this->session->sendEvent(Event(eid.value(), EventType::StopAction, StopActionEvent(eid.value(), glm::vec3(0.0f), ActionType::Sprint))); - } - + is_held_i = false; break; default: break; diff --git a/src/server/game/servergamestate.cpp b/src/server/game/servergamestate.cpp index c5f2c234..fda566a4 100644 --- a/src/server/game/servergamestate.cpp +++ b/src/server/game/servergamestate.cpp @@ -240,7 +240,9 @@ void ServerGameState::update(const EventList& events) { } case ActionType::Sprint: { if (obj->type == ObjectType::DungeonMaster) { - obj->physics.velocityMultiplier = glm::vec3(5.0f, 1.1f, 5.0f); + DungeonMaster* dm = this->objects.getDM(); + + obj->physics.velocityMultiplier = (dm->physics.shared.corner.y/5.0f) * glm::vec3(1.5f, 1.1f, 1.5f); } else { obj->physics.velocityMultiplier = glm::vec3(1.5f, 1.1f, 1.5f); From 162745e9eb9dd8b131bbdc9b6efd720b69ab13e7 Mon Sep 17 00:00:00 2001 From: Edward Jin <57547638+EddieJ03@users.noreply.github.com> Date: Wed, 5 Jun 2024 00:48:45 -0700 Subject: [PATCH 06/11] light cut icon in & minor fixes --- assets/imgs/lightcut.png | Bin 0 -> 639 bytes include/client/gui/img/img.hpp | 3 ++- include/server/game/constants.hpp | 3 ++- src/client/gui/gui.cpp | 2 +- src/client/gui/imgs/img.cpp | 1 + src/server/game/servergamestate.cpp | 5 ++--- 6 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 assets/imgs/lightcut.png diff --git a/assets/imgs/lightcut.png b/assets/imgs/lightcut.png new file mode 100644 index 0000000000000000000000000000000000000000..b332e7af802e868c4cadddbd363a28f1c635c259 GIT binary patch literal 639 zcmV-_0)YLAP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0p3YOK~z{r?Uqea z!axv(3D*!@Q0&5iJdCdNFdhh2Qk1253>|qx-q@K;PkJH&%i^nQlKFpm-9<9F@>i*v zYcI~Z<}OcFnYV1wyUHpcMTw~F%-@K}krJp18A}9-#Y~%Pi?KzdND2X8Rpk&(^CaZ< zRE6y7+Fws0X1iLo1el8$sX@Hdwfj6Y8SF0&ZM~!;EuH}6(@dQ+KF*Q8wRFcM1i;?K zX5;VWhTErAYr*n<9mcE=05Po^(L{jddR@hJ6GS}w-vGu-T~v!T1;lXEa8N=-bL$0I zM1a<$oFfuAv3NM9i7tUu>MS5NVS!Zy@F_Vs!Gk5c$D=S=D;A1U6C>RKal3@!LhgPX zp#Zi^-2j79!-Di_5XCyQMnJJ66cG+PIKwOJ19R}d;~Peb9g#wA=d|zX(}x#QQXle=xA%QV5c{l75R)TTCt^4s>vJ^|J`3Q87JP-{lOP^r%x5#U^L7q8 zj$8uizH0s0u1FE!B96o&fa(Ys!a8^e&5un%+Zf12Wcetc?mORk9>6I)0n91ZD zhsuO_Ro`iO00000NkvXXu0mjf2SmWF&jtbtx3A*X?aUycfFq-gh|G8vW(d)!QKLq6 Z=m(Hw;UHvyp>6;G002ovPDHLkV1i*G5@G-V literal 0 HcmV?d00001 diff --git a/include/client/gui/img/img.hpp b/include/client/gui/img/img.hpp index de6d6c47..056eeeaa 100644 --- a/include/client/gui/img/img.hpp +++ b/include/client/gui/img/img.hpp @@ -58,6 +58,7 @@ enum class ImgID { Sungod, Teleporter, Lightning, + LightCut, ArrowTrap, SpikeTrap, DMCD_10, DMCD_9, DMCD_8, DMCD_7, DMCD_6, DMCD_5, DMCD_4, DMCD_3, DMCD_2, DMCD_1, @@ -78,7 +79,7 @@ enum class ImgID { ImgID::Compass0, ImgID::Compass30, ImgID::Compass60, ImgID::Compass90, \ ImgID::Compass120, ImgID::Compass150, ImgID::Compass180, ImgID::Compass210, \ ImgID::Compass240, ImgID::Compass270, ImgID::Compass300, ImgID::Compass330, \ - ImgID::FloorSpikeTrap, ImgID::Sungod, ImgID::Teleporter, ImgID::Lightning, \ + ImgID::FloorSpikeTrap, ImgID::Sungod, ImgID::Teleporter, ImgID::Lightning, ImgID::LightCut, \ ImgID::ArrowTrap, ImgID::SpikeTrap, \ ImgID::DMTrapBG, ImgID::Needle, \ ImgID::EventBG, ImgID::DMEventBG, \ diff --git a/include/server/game/constants.hpp b/include/server/game/constants.hpp index 17a2f3d7..373b6408 100644 --- a/include/server/game/constants.hpp +++ b/include/server/game/constants.hpp @@ -104,5 +104,6 @@ #define TRAP_COOL_DOWN 5 #define ITEM_SPAWN_PROB 0.1 #define ITEM_SPAWN_BOUND 3 -#define LIGHT_CUT_TICKS 100 +#define LIGHTNING_LIGHT_CUT_TICKS 100 +#define LIGHT_CUT_TICKS 200 #define LIGHT_CUT_RANGE 25.0 \ No newline at end of file diff --git a/src/client/gui/gui.cpp b/src/client/gui/gui.cpp index 71774baa..d7d260ae 100644 --- a/src/client/gui/gui.cpp +++ b/src/client/gui/gui.cpp @@ -1429,7 +1429,7 @@ void GUI::_sharedGameHUD() { itemflex->push(widget::StaticImg::make(glm::vec2(0.0f), images.getImg(img::ImgID::Lightning), 2)); break; }case ModelType::LightCut: { - itemflex->push(widget::StaticImg::make(glm::vec2(0.0f), images.getImg(img::ImgID::Lightning), 2)); + itemflex->push(widget::StaticImg::make(glm::vec2(0.0f), images.getImg(img::ImgID::LightCut), 2)); break; } case ModelType::ArrowTrap: { diff --git a/src/client/gui/imgs/img.cpp b/src/client/gui/imgs/img.cpp index a4f30cf1..364103ae 100644 --- a/src/client/gui/imgs/img.cpp +++ b/src/client/gui/imgs/img.cpp @@ -79,6 +79,7 @@ std::string getImgFilepath(ImgID img) { case ImgID::Compass330: return (img_root / "compasses/compass_330.png").string(); case ImgID::Sungod: return (img_root / "sungod.png").string(); case ImgID::Lightning: return (img_root / "lightning.png").string(); + case ImgID::LightCut: return (img_root / "lightcut.png").string(); case ImgID::Teleporter: return (img_root / "teleporter.png").string(); case ImgID::FloorSpikeTrap: return (img_root / "floorspiketrap.png").string(); case ImgID::ArrowTrap: return (img_root / "arrowtrap.png").string(); diff --git a/src/server/game/servergamestate.cpp b/src/server/game/servergamestate.cpp index fda566a4..fb4374ad 100644 --- a/src/server/game/servergamestate.cpp +++ b/src/server/game/servergamestate.cpp @@ -439,7 +439,6 @@ void ServerGameState::update(const EventList& events) { // only hover for traps, not lightning if (trapPlacementEvent.cell == CellType::Lightning || trapPlacementEvent.cell == CellType::LightCut) break; - Trap* trap = placeTrapInCell(cell, trapPlacementEvent.cell); @@ -480,7 +479,7 @@ void ServerGameState::update(const EventList& events) { this->dmActionCutLights = trapPlacementEvent.world_pos; // go back 150 ticks (light cut is longer) - this->lastLightCut = std::max(this->timestep, (unsigned int)150) - 150; + this->lastLightCut = this->timestep; dm->useMana(LIGHT_CUT_MANA); } @@ -807,7 +806,7 @@ void ServerGameState::update(const EventList& events) { updateDungeonMasterParalysis(); // after some amount of timesteps uncut lights - if ((this->timestep - this->lastLightningLightCut) >= LIGHT_CUT_TICKS && this->dmLightningCutLights.has_value()) { + if ((this->timestep - this->lastLightningLightCut) >= LIGHTNING_LIGHT_CUT_TICKS && this->dmLightningCutLights.has_value()) { this->dmLightningCutLights = {}; } From 0162f10c47122a09e79a32c57031a1e09ccedce7 Mon Sep 17 00:00:00 2001 From: Tyler Lentz Date: Wed, 5 Jun 2024 01:43:46 -0700 Subject: [PATCH 07/11] fix directional light for DM being commented out --- src/client/client.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 80fbbb37..0d78b8e1 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1175,25 +1175,25 @@ void Client::lightingPass() { auto camPos = this->cam->getPos(); lighting_shader->setVec3("viewPos", camPos); - //if (is_dm) { - // auto ambient = glm::vec3(0.1, 0.1, 0.1); - // auto diffuse = glm::vec3(0.1, 0.1, 0.1); - // auto specular = glm::vec3(0.1, 0.1, 0.1); - // std::array dirLights = { - // DirLight{glm::vec3(1.0f, 0.0f, 0.0f), ambient, diffuse, specular}, - // DirLight{glm::vec3(-1.0f, 1.0f, 0.0f), ambient, diffuse, specular}, - // DirLight{glm::vec3(0.0f, 1.0f, 1.0f), ambient, diffuse, specular}, - // DirLight{glm::vec3(0.0f, 1.0f, -1.0f), ambient, diffuse, specular}, - // }; - - // for (int i = 0; i < dirLights.size(); i++) { - // std::string i_s = std::to_string(i); - // lighting_shader->setVec3("dirLights[" + i_s + "].direction", dirLights[i].direction); - // lighting_shader->setVec3("dirLights[" + i_s + "].ambient_color", ambient); - // lighting_shader->setVec3("dirLights[" + i_s + "].diffuse_color", diffuse); - // lighting_shader->setVec3("dirLights[" + i_s + "].specular_color", specular); - // } - //} + if (is_dm) { + auto ambient = glm::vec3(0.1, 0.1, 0.1); + auto diffuse = glm::vec3(0.1, 0.1, 0.1); + auto specular = glm::vec3(0.1, 0.1, 0.1); + std::array dirLights = { + DirLight{glm::vec3(1.0f, 0.0f, 0.0f), ambient, diffuse, specular}, + DirLight{glm::vec3(-1.0f, 1.0f, 0.0f), ambient, diffuse, specular}, + DirLight{glm::vec3(0.0f, 1.0f, 1.0f), ambient, diffuse, specular}, + DirLight{glm::vec3(0.0f, 1.0f, -1.0f), ambient, diffuse, specular}, + }; + + for (int i = 0; i < dirLights.size(); i++) { + std::string i_s = std::to_string(i); + lighting_shader->setVec3("dirLights[" + i_s + "].direction", dirLights[i].direction); + lighting_shader->setVec3("dirLights[" + i_s + "].ambient_color", ambient); + lighting_shader->setVec3("dirLights[" + i_s + "].diffuse_color", diffuse); + lighting_shader->setVec3("dirLights[" + i_s + "].specular_color", specular); + } + } for (int i = 0; i < closest_lights->size(); i++) { boost::optional& curr_source = closest_lights->at(i); From 5de27d57bf4cdb789fedabcb3ccd4e1c6a9b8a2c Mon Sep 17 00:00:00 2001 From: Edward Jin <57547638+EddieJ03@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:07:18 -0700 Subject: [PATCH 08/11] WARNING: broken commit --- include/server/game/dungeonmaster.hpp | 28 +++++++++++++++++++--- include/server/game/torchlight.hpp | 2 ++ include/server/game/trap.hpp | 34 +++++++++++++++++++++++++++ src/server/game/grid.cpp | 1 + src/server/game/torchlight.cpp | 4 ++-- 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/include/server/game/dungeonmaster.hpp b/include/server/game/dungeonmaster.hpp index e46357a9..dc2ef3a2 100644 --- a/include/server/game/dungeonmaster.hpp +++ b/include/server/game/dungeonmaster.hpp @@ -12,19 +12,32 @@ class DungeonMaster : public Creature { public: SharedTrapInventory sharedTrapInventory; SharedDMInfo dmInfo; - Weapon* lightning; DungeonMaster(glm::vec3 corner, glm::vec3 facing); ~DungeonMaster(); virtual SharedObject toShared() override; + /** + * @brief get the number of traps the DM currently has placed + */ int getPlacedTraps(); + /** + * @brief set the number of traps the DM currently has placed + * @param placedTraps the number of traps the DM has placed + */ void setPlacedTraps(int placedTraps); - // For lightning usage + /** + * @brief For lightning and light-cut usage + * @param mana the amount of mana the specific DM action takes + */ void useMana(int mana); + + /** + * @brief mana regeneration function + */ void manaRegen(); /** @@ -59,7 +72,12 @@ class DungeonMaster : public Creature { * the last time the DungeonMaster became paralyzed. */ std::chrono::time_point getParalysisStartTime() const; - + + /** + * @brief The DM's lightning weapon + */ + Weapon* lightning; + private: /** * @brief Duration, in seconds, of the Dungeon Master's current paralysis @@ -73,6 +91,10 @@ class DungeonMaster : public Creature { */ std::chrono::time_point paralysis_start_time; + /** + * @brief the number of traps the DM has placed + */ int placedTraps; + std::chrono::system_clock::time_point mana_used; }; \ No newline at end of file diff --git a/include/server/game/torchlight.hpp b/include/server/game/torchlight.hpp index 14d67429..3b9c4bb7 100644 --- a/include/server/game/torchlight.hpp +++ b/include/server/game/torchlight.hpp @@ -54,6 +54,8 @@ class Torchlight : public Object { * @brief runs on every server tick to update torchlight flickering * animations * @parm current ServerGameState + * @param the position the lightning hit (if exists) + * @param the position of the light cut action (if exists) */ void doTick(ServerGameState& state, std::optional lightning_light_cut_pos, std::optional action_light_cut_pos); diff --git a/include/server/game/trap.hpp b/include/server/game/trap.hpp index e49582ea..930aaaae 100644 --- a/include/server/game/trap.hpp +++ b/include/server/game/trap.hpp @@ -60,17 +60,51 @@ class Trap : public Object { SharedObject toShared() override; + /** + * Set the is_dm_trap field + * + * @param boolean for if this trap is a DM trap or not + */ void setIsDMTrap(bool is_dm_trap); + /** + * Set the SharedTrapInfo info dm_hover field + * + * @param boolean for if this trap is a a DM hover or not + */ void setIsDMTrapHover(bool is_dm_trap_hover); + /** + * Set the expiration of this trap + * + * @param expiration time + */ void setExpiration(std::chrono::time_point expiration); + /** + * Gets if this trap is a DM trap or not + * + * @returns True if the trap is a DM trap and false otherwise + */ bool getIsDMTrap(); + /** + * Gets the expiration time of this trap + * + * @returns the expiration time of this trap + */ std::chrono::time_point getExpiration(); + protected: + /** + * is this trap a DM trap? + */ bool is_dm_trap; + + /** + * the expiration time of this trap + */ std::chrono::time_point expiration; + SharedTrapInfo info; }; \ No newline at end of file diff --git a/src/server/game/grid.cpp b/src/server/game/grid.cpp index 20fcd872..4cd809bb 100644 --- a/src/server/game/grid.cpp +++ b/src/server/game/grid.cpp @@ -131,6 +131,7 @@ glm::ivec2 Grid::getGridCellFromPosition(glm::vec3 position) { std::vector Grid::getCellsFromPositionRange(glm::vec3 p1, glm::vec3 p2) { std::vector cellPositions; + // Get GridCell positions for p1 and p2 glm::ivec2 gridCellStart = Grid::getGridCellFromPosition(p1); glm::ivec2 gridCellEnd = Grid::getGridCellFromPosition(p2); diff --git a/src/server/game/torchlight.cpp b/src/server/game/torchlight.cpp index 183a4185..d1fbc50a 100644 --- a/src/server/game/torchlight.cpp +++ b/src/server/game/torchlight.cpp @@ -147,8 +147,8 @@ void Torchlight::doTick(ServerGameState& state, std::optional lightni if (action_light_cut_pos.has_value()) { glm::vec3 pos = action_light_cut_pos.value(); - // if within threshold, get out - if (glm::distance(pos, this->physics.shared.getCenterPosition()) <= LIGHT_CUT_RANGE) { + // if within threshold, black out (slightly expand the light cut action range) + if (glm::distance(pos, this->physics.shared.getCenterPosition()) <= (1.5 * LIGHT_CUT_RANGE)) { this->curr_intensity = 0.0f; return; } From 9c7c9133abb0cedfd66c1b311ac5a241f8eae3ae Mon Sep 17 00:00:00 2001 From: EddieJ03 Date: Wed, 5 Jun 2024 10:47:40 -0700 Subject: [PATCH 09/11] trap inventory size should be 7 NOT 6 --- include/server/game/constants.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/server/game/constants.hpp b/include/server/game/constants.hpp index 215dc288..e972f65b 100644 --- a/include/server/game/constants.hpp +++ b/include/server/game/constants.hpp @@ -92,7 +92,7 @@ /* DM Constants */ #define MAX_TRAPS 10 -#define TRAP_INVENTORY_SIZE 6 +#define TRAP_INVENTORY_SIZE 7 #define TRAP_TIME 10 #define TRAP_COOL_DOWN 5 #define ITEM_SPAWN_PROB 0.1 From e296a5631ef53ec8a3b707cea4a99da4ffd3f833 Mon Sep 17 00:00:00 2001 From: EddieJ03 Date: Wed, 5 Jun 2024 11:16:56 -0700 Subject: [PATCH 10/11] sccale DM velocity based on height WITHOUT sprinting (feels better) --- src/server/game/servergamestate.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/server/game/servergamestate.cpp b/src/server/game/servergamestate.cpp index c4cc1713..06adb61d 100644 --- a/src/server/game/servergamestate.cpp +++ b/src/server/game/servergamestate.cpp @@ -253,9 +253,12 @@ void ServerGameState::update(const EventList& events) { case ActionType::Zoom: { // only for DM DungeonMaster * dm = this->objects.getDM(); - if (dm != nullptr && (dm->physics.shared.corner.y + startAction.movement.y >= 10.0f) && (dm->physics.shared.corner.y + startAction.movement.y <= 100.0f)) + if (dm != nullptr && (dm->physics.shared.corner.y + startAction.movement.y >= 10.0f) && (dm->physics.shared.corner.y + startAction.movement.y <= 100.0f)) { dm->physics.shared.corner += startAction.movement; + obj->physics.velocityMultiplier = (dm->physics.shared.corner.y / 10.0f) * glm::vec3(1.5f, 1.1f, 1.5f); + } + break; } default: {} @@ -282,11 +285,18 @@ void ServerGameState::update(const EventList& events) { } case ActionType::Sprint: { obj->physics.velocityMultiplier = glm::vec3(1.0f, 1.0f, 1.0f); + + // if DM gotta re-adjust velocity to be based on height + if (obj->type == ObjectType::DungeonMaster) { + obj->physics.velocityMultiplier = (obj->physics.shared.corner.y / 10.0f) * glm::vec3(1.5f, 1.1f, 1.5f); + } + if (obj->physics.velocity.x != 0.0f && obj->physics.velocity.z != 0.0f) { obj->animState = AnimState::WalkAnim; } else { obj->animState = AnimState::IdleAnim; } + break; } default: { break; } @@ -1820,13 +1830,13 @@ Trap* ServerGameState::placeTrapInCell(GridCell* cell, CellType type) { } Direction dir; - if (cell->type == CellType::ArrowTrapDown) { + if (type == CellType::ArrowTrapDown) { dir = Direction::DOWN; } - else if (cell->type == CellType::ArrowTrapUp) { + else if (type == CellType::ArrowTrapUp) { dir = Direction::UP; } - else if (cell->type == CellType::ArrowTrapLeft) { + else if (type == CellType::ArrowTrapLeft) { dir = Direction::LEFT; } else { From 9c62f7824099b69168299a69bf18ff917fbbd8e9 Mon Sep 17 00:00:00 2001 From: Tyler Lentz Date: Wed, 5 Jun 2024 11:43:27 -0700 Subject: [PATCH 11/11] pass most of lint --- config.json | 4 +- include/client/animationmanager.hpp | 2 +- src/client/animationmanager.cpp | 2 + src/client/client.cpp | 10 -- src/server/game/mazegenerator.cpp | 2 - src/server/game/mirror.cpp | 2 +- src/server/game/objectmanager.cpp | 1 - src/server/game/servergamestate.cpp | 171 ++++++---------------------- 8 files changed, 40 insertions(+), 154 deletions(-) diff --git a/config.json b/config.json index e2f25ea7..fe052013 100644 --- a/config.json +++ b/config.json @@ -2,7 +2,7 @@ "game": { "maze": { "directory": "maps", - "procedural": false, + "procedural": true, "maze_file": "test/itemRoom.maze" } }, @@ -15,7 +15,7 @@ "lobby_broadcast": true, "max_players": 1, "disable_dm": false, - "skip_intro": true + "skip_intro": false }, "client": { "default_name": "Conan O'Brien", diff --git a/include/client/animationmanager.hpp b/include/client/animationmanager.hpp index 044cd352..44196a41 100644 --- a/include/client/animationmanager.hpp +++ b/include/client/animationmanager.hpp @@ -15,7 +15,7 @@ class AnimationManager { public: - AnimationManager(Animation* animation); + explicit AnimationManager(Animation* animation); void updateAnimation(float dt); diff --git a/src/client/animationmanager.cpp b/src/client/animationmanager.cpp index 8c5e2e81..834f66cb 100644 --- a/src/client/animationmanager.cpp +++ b/src/client/animationmanager.cpp @@ -5,6 +5,8 @@ AnimationManager::AnimationManager(Animation* animation) { m_currentTime = 0.0; m_currentAnimation = animation; + m_deltaTime = 0; // Tyler: is this still used? linter complaining about it not being initialized + m_finalBoneMatrices.reserve(100); for (int i = 0; i < 100; i++) diff --git a/src/client/client.cpp b/src/client/client.cpp index 0d78b8e1..f6289d69 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1572,16 +1572,6 @@ void Client::mouseCallback(GLFWwindow* window, double xposIn, double yposIn) { / mouse_xpos = new_mouse_xpos; mouse_ypos = new_mouse_ypos; - - if (this->gameState.phase == GamePhase::GAME && this->gui_state == GUIState::GAME_HUD) { - if (this->session->getInfo().is_dungeon_master.has_value() && - this->session->getInfo().is_dungeon_master.value()) { - auto eid = this->session->getInfo().client_eid; - auto obj = this->gameState.objects.at(eid.value()); - - //sendTrapEvent(true, false, obj->trapInventoryInfo->inventory[obj->trapInventoryInfo->selected - 1]); - } - } } void Client::setWorldPos() { diff --git a/src/server/game/mazegenerator.cpp b/src/server/game/mazegenerator.cpp index 07b90175..794fce7b 100644 --- a/src/server/game/mazegenerator.cpp +++ b/src/server/game/mazegenerator.cpp @@ -84,7 +84,6 @@ std::optional MazeGenerator::generate() { this->frontier.pop(); if (_num_rooms_placed == REQUIRED_NUM_ROOMS - 2) { - std::cout << "placing exit\n"; // optimize the placing of the exit and orb to make the exit as far away from the entrance as possible // essentially go through the frontier and throw out everything but the farthest away // from the spawn @@ -112,7 +111,6 @@ std::optional MazeGenerator::generate() { } if (_num_rooms_placed == REQUIRED_NUM_ROOMS - 1) { - std::cout << "placing orb\n"; // go through frontier, and get coord and required entry to be as far from exit_coord as possible int size = this->frontier.size(); int count = 0; diff --git a/src/server/game/mirror.cpp b/src/server/game/mirror.cpp index b0e3a2f4..5f880118 100644 --- a/src/server/game/mirror.cpp +++ b/src/server/game/mirror.cpp @@ -4,7 +4,7 @@ Mirror::Mirror(glm::vec3 corner, glm::vec3 dimensions) : Item(ObjectType::Mirror, false, corner, ModelType::Cube, dimensions) { this->modelType = ModelType::Mirror; - + this->used_player = nullptr; } void Mirror::useItem(Object* other, ServerGameState& state, int itemSelected) { diff --git a/src/server/game/objectmanager.cpp b/src/server/game/objectmanager.cpp index b1ac654c..e5eeb0f1 100644 --- a/src/server/game/objectmanager.cpp +++ b/src/server/game/objectmanager.cpp @@ -98,7 +98,6 @@ SpecificID ObjectManager::_createObject(Object* object, boost::optionaltypeID = this->players.push(dynamic_cast(object)); - std::cout << "INSERTING A PLAYER of TYPEID " << object->typeID << std::endl; break; case ObjectType::Python: case ObjectType::Minotaur: diff --git a/src/server/game/servergamestate.cpp b/src/server/game/servergamestate.cpp index 06adb61d..1b98e062 100644 --- a/src/server/game/servergamestate.cpp +++ b/src/server/game/servergamestate.cpp @@ -550,8 +550,8 @@ void ServerGameState::update(const EventList& events) { int randomC = randomInt(std::max(_cell->x - ITEM_SPAWN_BOUND, 0), std::min(this->grid.getColumns() - 1, _cell->x + ITEM_SPAWN_BOUND)); int randomR = randomInt(std::max(_cell->y - ITEM_SPAWN_BOUND, 0), std::min(this->grid.getRows() - 1, _cell->y + ITEM_SPAWN_BOUND)); - GridCell* cell = grid.getCell(randomC, randomR); - CellType celltype = cell->type; + GridCell* random_cell = grid.getCell(randomC, randomR); + CellType celltype = random_cell->type; int counter = 0; @@ -560,8 +560,8 @@ void ServerGameState::update(const EventList& events) { randomC = randomInt(std::max(_cell->x - ITEM_SPAWN_BOUND, 0), std::min(this->grid.getColumns() - 1, _cell->x + ITEM_SPAWN_BOUND)); randomR = randomInt(std::max(_cell->y - ITEM_SPAWN_BOUND, 0), std::min(this->grid.getRows() - 1, _cell->y + ITEM_SPAWN_BOUND)); - GridCell* cell = grid.getCell(randomC, randomR); - CellType celltype = cell->type; + random_cell = grid.getCell(randomC, randomR); + celltype = random_cell->type; counter += 1; @@ -585,9 +585,9 @@ void ServerGameState::update(const EventList& events) { glm::vec3 dimensions(1.0f); glm::vec3 corner( - cell->x * Grid::grid_cell_width + 1, + random_cell->x * Grid::grid_cell_width + 1, 0, - cell->y * Grid::grid_cell_width + 1 + random_cell->y * Grid::grid_cell_width + 1 ); int randomCellType = randomInt(1, 3); @@ -595,192 +595,89 @@ void ServerGameState::update(const EventList& events) { if (randomCellType == 1) { int r = randomInt(1, 3); if (r == 1) { - cell->type = CellType::HealthPotion; + random_cell->type = CellType::HealthPotion; } else if (r == 2) { - cell->type = CellType::InvisibilityPotion; + random_cell->type = CellType::InvisibilityPotion; } else { - cell->type = CellType::InvincibilityPotion; + random_cell->type = CellType::InvincibilityPotion; } } else if (randomCellType == 2) { int r = randomInt(1, 3); if (r == 1) { - cell->type = CellType::FireSpell; + random_cell->type = CellType::FireSpell; } else if (r == 2) { - cell->type = CellType::HealSpell; + random_cell->type = CellType::HealSpell; } else { - cell->type = CellType::TeleportSpell; + random_cell->type = CellType::TeleportSpell; } } else { int r = randomInt(1, 4); if (r == 1) { - cell->type = CellType::Dagger; + random_cell->type = CellType::Dagger; } else if (r == 2) { - cell->type = CellType::Sword; + random_cell->type = CellType::Sword; } else if (r == 3) { - cell->type = CellType::Mirror; + random_cell->type = CellType::Mirror; } else { - cell->type = CellType::Hammer; + random_cell->type = CellType::Hammer; } } - switch (cell->type) { - case CellType::Dagger: { - glm::vec3 dimensions(1.0f); - - glm::vec3 corner( - cell->x * Grid::grid_cell_width + 1, - 0, - cell->y * Grid::grid_cell_width + 1); - - Weapon* weapon = new Weapon(corner, dimensions, WeaponType::Dagger); - - this->objects.createObject(weapon); + Object* spawned_object = nullptr; - this->updated_entities.insert(weapon->globalID); + switch (random_cell->type) { + case CellType::Dagger: { + spawned_object= new Weapon(corner, dimensions, WeaponType::Dagger); break; } case CellType::Sword: { - glm::vec3 dimensions(1.0f); - - glm::vec3 corner( - cell->x * Grid::grid_cell_width + 1, - 0, - cell->y * Grid::grid_cell_width + 1); - - - Weapon* weapon = new Weapon(corner, dimensions, WeaponType::Sword); - - this->objects.createObject(weapon); - - this->updated_entities.insert(weapon->globalID); - + spawned_object = new Weapon(corner, dimensions, WeaponType::Sword); break; } case CellType::Hammer: { - glm::vec3 dimensions(1.0f); - - glm::vec3 corner( - cell->x * Grid::grid_cell_width + 1, - 0, - cell->y * Grid::grid_cell_width + 1); - - - Weapon* weapon = new Weapon(corner, dimensions, WeaponType::Hammer); - - this->objects.createObject(weapon); - - this->updated_entities.insert(weapon->globalID); - + spawned_object = new Weapon(corner, dimensions, WeaponType::Hammer); break; } case CellType::TeleportSpell: { - glm::vec3 dimensions(1.0f); - - glm::vec3 corner( - cell->x * Grid::grid_cell_width + 1, - 0, - cell->y * Grid::grid_cell_width + 1); - - Spell* spell = new Spell(corner, dimensions, SpellType::Teleport); - - this->objects.createObject(spell); - - this->updated_entities.insert(spell->globalID); - - + spawned_object = new Spell(corner, dimensions, SpellType::Teleport); break; } case CellType::FireSpell: { - glm::vec3 dimensions(1.0f); - - glm::vec3 corner( - cell->x * Grid::grid_cell_width + 1, - 0, - cell->y * Grid::grid_cell_width + 1); - - Spell* spell = new Spell(corner, dimensions, SpellType::Fireball); - - this->objects.createObject(spell); - - this->updated_entities.insert(spell->globalID); - - + spawned_object = new Spell(corner, dimensions, SpellType::Fireball); break; } case CellType::HealSpell: { - glm::vec3 dimensions(1.0f); - - glm::vec3 corner( - cell->x * Grid::grid_cell_width + 1, - 0, - cell->y * Grid::grid_cell_width + 1); - - - Spell* spell = new Spell(corner, dimensions, SpellType::HealOrb); - - this->objects.createObject(spell); - - this->updated_entities.insert(spell->globalID); - + spawned_object = new Spell(corner, dimensions, SpellType::HealOrb); break; } case CellType::HealthPotion: { - glm::vec3 dimensions(1.0f); - - glm::vec3 corner(cell->x * Grid::grid_cell_width + 1, - 0, - cell->y * Grid::grid_cell_width + 1); - - Potion* potion = new Potion(corner, dimensions, PotionType::Health); - - this->objects.createObject(potion); - - this->updated_entities.insert(potion->globalID); - + spawned_object = new Potion(corner, dimensions, PotionType::Health); break; } case CellType::InvisibilityPotion: { - glm::vec3 dimensions(1.0f); - - glm::vec3 corner(cell->x * Grid::grid_cell_width + 1, - 0, - cell->y * Grid::grid_cell_width + 1); - - - Potion* potion = new Potion(corner, dimensions, PotionType::Invisibility); - - this->objects.createObject(potion); - - this->updated_entities.insert(potion->globalID); - + spawned_object = new Potion(corner, dimensions, PotionType::Invisibility); break; } case CellType::InvincibilityPotion: { - glm::vec3 dimensions(1.0f); - - glm::vec3 corner(cell->x * Grid::grid_cell_width + 1, - 0, - cell->y * Grid::grid_cell_width + 1); - - Potion* potion = new Potion(corner, dimensions, PotionType::Invincibility); - - this->objects.createObject(potion); - - this->updated_entities.insert(potion->globalID); - + spawned_object = new Potion(corner, dimensions, PotionType::Invincibility); break; } default: - std::cout << "what item is this??" << std::endl; + std::cerr << "WARNING: unknown item spawned in DM care package code." << std::endl; + } + + if (spawned_object != nullptr) { + this->objects.createObject(spawned_object); + this->updated_entities.insert(spawned_object->globalID); } } }