From 857b2e9a352ae8a4ce54213a03c9762d19e92987 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:52:33 +0200 Subject: [PATCH] spell replacement works --- client/ClientNetPackVisitors.h | 1 + client/NetPacksClient.cpp | 7 +++++++ client/windows/CCastleInterface.cpp | 28 +++++++++++++++++++++------- client/windows/CCastleInterface.h | 7 ++++--- server/CGameHandler.cpp | 12 ++++-------- server/CGameHandler.h | 1 - 6 files changed, 37 insertions(+), 19 deletions(-) diff --git a/client/ClientNetPackVisitors.h b/client/ClientNetPackVisitors.h index 82cb72d53..7b67d4b72 100644 --- a/client/ClientNetPackVisitors.h +++ b/client/ClientNetPackVisitors.h @@ -37,6 +37,7 @@ public: void visitHeroVisitCastle(HeroVisitCastle & pack) override; void visitSetMana(SetMana & pack) override; void visitSetMovePoints(SetMovePoints & pack) override; + void visitSetTownSpells(SetTownSpells & pack) override; void visitFoWChange(FoWChange & pack) override; void visitChangeStackCount(ChangeStackCount & pack) override; void visitSetStackType(SetStackType & pack) override; diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index cda16c4b3..e26516078 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -14,6 +14,7 @@ #include "CPlayerInterface.h" #include "CGameInfo.h" #include "windows/GUIClasses.h" +#include "windows/CCastleInterface.h" #include "mapView/mapHandler.h" #include "adventureMap/AdventureMapInterface.h" #include "adventureMap/CInGameConsole.h" @@ -172,6 +173,12 @@ void ApplyClientNetPackVisitor::visitSetMovePoints(SetMovePoints & pack) callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroMovePointsChanged, h); } +void ApplyClientNetPackVisitor::visitSetTownSpells(SetTownSpells & pack) +{ + for(const auto & win : GH.windows().findWindows()) + win->update(); +} + void ApplyClientNetPackVisitor::visitFoWChange(FoWChange & pack) { for(auto &i : cl.playerint) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 56211c500..7ee8dfeb1 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -1966,7 +1966,7 @@ void CFortScreen::RecruitArea::showPopupWindow(const Point & cursorPosition) } CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner, const ImagePath & imagename) - : CWindowObject(BORDERED, imagename), town(owner->town) + : CWindowObject(BORDERED, imagename), townId(owner->town->id) { OBJECT_CONSTRUCTION; @@ -1982,6 +1982,12 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner, const ImagePath & i exit = std::make_shared(Point(748, 556), AnimationPath::builtin("TPMAGE1.DEF"), CButton::tooltip(CGI->generaltexth->allTexts[593]), [&](){ close(); }, EShortcut::GLOBAL_RETURN); + update(); +} + +void CMageGuildScreen::update() +{ + OBJECT_CONSTRUCTION; static const std::vector > positions = { {Point(222,445), Point(312,445), Point(402,445), Point(520,445), Point(610,445), Point(700,445)}, @@ -1991,21 +1997,28 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner, const ImagePath & i {Point(491,325), Point(591,325)} }; - for(size_t i=0; itown->town->mageLevel; i++) + spells.clear(); + emptyScrolls.clear(); + + const CGTownInstance * town = LOCPLINT->cb->getTown(townId); + + for(size_t i=0; itown->mageLevel; i++) { - size_t spellCount = owner->town->spellsAtLevel((int)i+1,false); //spell at level with -1 hmmm? + size_t spellCount = town->spellsAtLevel((int)i+1,false); //spell at level with -1 hmmm? for(size_t j=0; jtown->mageGuildLevel() && owner->town->spells[i].size()>j) - spells.push_back(std::make_shared(positions[i][j], owner->town->spells[i][j].toSpell(), town)); + if(imageGuildLevel() && town->spells[i].size()>j) + spells.push_back(std::make_shared(positions[i][j], town->spells[i][j].toSpell(), townId)); else emptyScrolls.push_back(std::make_shared(AnimationPath::builtin("TPMAGES.DEF"), 1, 0, positions[i][j].x, positions[i][j].y)); } } + + redraw(); } -CMageGuildScreen::Scroll::Scroll(Point position, const CSpell *Spell, const CGTownInstance *town) - : spell(Spell), town(town) +CMageGuildScreen::Scroll::Scroll(Point position, const CSpell *Spell, ObjectInstanceID townId) + : spell(Spell), townId(townId) { OBJECT_CONSTRUCTION; @@ -2017,6 +2030,7 @@ CMageGuildScreen::Scroll::Scroll(Point position, const CSpell *Spell, const CGTo void CMageGuildScreen::Scroll::clickPressed(const Point & cursorPosition) { + const CGTownInstance * town = LOCPLINT->cb->getTown(townId); if(LOCPLINT->cb->getSettings().getBoolean(EGameSettings::TOWNS_SPELL_RESEARCH)) LOCPLINT->cb->spellResearch(town); else diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index 3091d48ab..a0d338555 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -379,10 +379,10 @@ class CMageGuildScreen : public CStatusbarWindow { const CSpell * spell; std::shared_ptr image; - const CGTownInstance *town; + ObjectInstanceID townId; public: - Scroll(Point position, const CSpell *Spell, const CGTownInstance *town); + Scroll(Point position, const CSpell *Spell, ObjectInstanceID townId); void clickPressed(const Point & cursorPosition) override; void showPopupWindow(const Point & cursorPosition) override; void hover(bool on) override; @@ -394,10 +394,11 @@ class CMageGuildScreen : public CStatusbarWindow std::shared_ptr resdatabar; - const CGTownInstance *town; + ObjectInstanceID townId; public: CMageGuildScreen(CCastleInterface * owner, const ImagePath & image); + void update(); }; /// The blacksmith window where you can buy available in town war machine diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index c14248b54..4c28225a9 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2248,21 +2248,17 @@ bool CGameHandler::spellResearch(ObjectInstanceID tid) return false; CGTownInstance *t = gs->getTown(tid); - auto spells = t->spells.at(1); + auto spells = t->spells.at(0); auto spell = SpellID(SpellID::FLY); spells.at(0) = spell; - setTownSpells(t, 1, spells); - spellResearchFinished(tid); - return true; -} + setTownSpells(t, 0, spells); -void CGameHandler::spellResearchFinished(ObjectInstanceID tid) -{ - const CGTownInstance * t = getTown(tid); if(t->visitingHero) giveSpells(t, t->visitingHero); if(t->garrisonHero) giveSpells(t, t->garrisonHero); + + return true; } bool CGameHandler::recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dstid, CreatureID crid, ui32 cram, si32 fromLvl, PlayerColor player) diff --git a/server/CGameHandler.h b/server/CGameHandler.h index b1540b636..e446aec7c 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -220,7 +220,6 @@ public: bool visitTownBuilding(ObjectInstanceID tid, BuildingID bid); bool razeStructure(ObjectInstanceID tid, BuildingID bid); bool spellResearch(ObjectInstanceID tid); - void spellResearchFinished(ObjectInstanceID tid); bool disbandCreature( ObjectInstanceID id, SlotID pos ); bool arrangeStacks( ObjectInstanceID id1, ObjectInstanceID id2, ui8 what, SlotID p1, SlotID p2, si32 val, PlayerColor player); bool bulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot);