diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index b62ee25d2..692b19b46 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -59,6 +59,10 @@ "vcmi.spellBook.search" : "search...", + "vcmi.spellResearch.canNotAfford" : "You can't afford to research a spell.", + "vcmi.spellResearch.comeAgain" : "Research has already been done today. Come back tomorrow.", + "vcmi.spellResearch.pay" : "Would you like to research a new spell and replace this?", + "vcmi.mainMenu.serverConnecting" : "Connecting...", "vcmi.mainMenu.serverAddressEnter" : "Enter address:", "vcmi.mainMenu.serverConnectionFailed" : "Failed to connect", diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index efe786220..6ef4f4353 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -58,6 +58,10 @@ "vcmi.spellBook.search" : "suchen...", + "vcmi.spellResearch.canNotAfford" : "Ihr könnt es Euch nicht leisten, einen Zauberspruch zu erforschen.", + "vcmi.spellResearch.comeAgain" : "Die Forschung wurde heute bereits abgeschlossen. Kommt morgen wieder.", + "vcmi.spellResearch.pay" : "Möchtet Ihr einen neuen Zauberspruch erforschen und diesen ersetzen?", + "vcmi.mainMenu.serverConnecting" : "Verbinde...", "vcmi.mainMenu.serverAddressEnter" : "Addresse eingeben:", "vcmi.mainMenu.serverConnectionFailed" : "Verbindung fehlgeschlagen", diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 457871a3a..045e4fb3a 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -2032,7 +2032,37 @@ 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, spell->id); + { + int daysSinceLastResearch = LOCPLINT->cb->getDate(Date::DAY) - town->lastSpellResearchDay; + if(!daysSinceLastResearch) + { + LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.spellResearch.comeAgain")); + return; + } + + int level = -1; + for(int i = 0; i < town->spells.size(); i++) + if(vstd::find_pos(town->spells[i], spell->id) != -1) + level = i; + + TResources cost; + cost[EGameResID::GOLD] = 1000; + cost[EGameResID::MERCURY] = (level + 1) * 2; + cost[EGameResID::SULFUR] = (level + 1) * 2; + cost[EGameResID::CRYSTAL] = (level + 1) * 2; + cost[EGameResID::GEMS] = (level + 1) * 2; + + std::vector> resComps; + for(TResources::nziterator i(cost); i.valid(); i++) + { + resComps.push_back(std::make_shared(ComponentType::RESOURCE, i->resType, i->resVal)); + } + + if(LOCPLINT->cb->getResourceAmount().canAfford(cost)) + LOCPLINT->showYesNoDialog(CGI->generaltexth->translate("vcmi.spellResearch.pay"), [this, town](){ LOCPLINT->cb->spellResearch(town, spell->id); }, nullptr, resComps); + else + LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.spellResearch.canNotAfford"), resComps); + } else LOCPLINT->showInfoDialog(spell->getDescriptionTranslated(0), std::make_shared(ComponentType::SPELL, spell->id)); } diff --git a/config/gameConfig.json b/config/gameConfig.json index 9e4e5a4a3..3f439f223 100644 --- a/config/gameConfig.json +++ b/config/gameConfig.json @@ -313,7 +313,7 @@ // Chances for a town with default buildings to receive corresponding dwelling level built in start "startingDwellingChances": [100, 50], // Enable spell research in mage guild - "spellResearch": true + "spellResearch": false }, "combat": diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index fed910807..31bd4e2de 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -915,7 +915,7 @@ void CGameState::initTowns() vti->spells[s->getLevel()-1].push_back(s->id); vti->possibleSpells -= s->id; } - vti->possibleSpells.clear(); //SR + vti->possibleSpells.clear(); } } diff --git a/lib/networkPacks/NetPacksLib.cpp b/lib/networkPacks/NetPacksLib.cpp index a2cb60448..89207fa1c 100644 --- a/lib/networkPacks/NetPacksLib.cpp +++ b/lib/networkPacks/NetPacksLib.cpp @@ -944,6 +944,7 @@ void SetTownSpells::applyGs(CGameState *gs) CGTownInstance *town = gs->getTown(tid); town->spells[level] = spells; + town->lastSpellResearchDay = gs->getDate(Date::DAY); } void SetMana::applyGs(CGameState *gs) diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index fb9625012..6620f0c74 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2273,8 +2273,6 @@ bool CGameHandler::spellResearch(ObjectInstanceID tid, SpellID spellAtSlot) giveResources(t->getOwner(), -cost); - t->lastSpellResearchDay = gs->getDate(Date::DAY); - auto spells = t->spells.at(level); std::swap(spells.at(t->spellsAtLevel(level, false)), spells.at(vstd::find_pos(spells, spellAtSlot)));