Browse Source

Save & restore mana

nordsoft 2 years ago
parent
commit
e85593dbb3
4 changed files with 23 additions and 6 deletions
  1. 1 1
      client/CPlayerInterface.cpp
  2. 0 3
      lib/NetPacksLib.cpp
  3. 21 2
      server/CGameHandler.cpp
  4. 1 0
      server/CQuery.h

+ 1 - 1
client/CPlayerInterface.cpp

@@ -911,7 +911,7 @@ void CPlayerInterface::battleEnd(const BattleResult *br, QueryID queryID)
 		{
 			bool replay = allowBattleReplay && !settings["adventure"]["alwaysSkipCombat"].Bool(); //do not allow manual replay
 			allowBattleReplay = false;
-			auto wnd = std::make_shared<CBattleResultWindow>(*br, *this, replay);
+			auto wnd = std::make_shared<BattleResultWindow>(*br, *this, replay);
 			wnd->resultCallback = [=](ui32 selection)
 			{
 				cb->selectionMade(selection, queryID);

+ 0 - 3
lib/NetPacksLib.cpp

@@ -2221,9 +2221,6 @@ void BattleResultAccepted::applyGs(CGameState * gs) const
 		CBonusSystemNode::treeHasChanged();
 	}
 
-	army1->battle = nullptr;
-	army2->battle = nullptr;
-	
 	gs->curB.dellNull();
 }
 

+ 21 - 2
server/CGameHandler.cpp

@@ -634,7 +634,7 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance * heroAttacker, con
 
 	//Check how many battle queries were created (number of players blocked by battle)
 	const int queriedPlayers = battleQuery ? (int)boost::count(queries.allQueries(), battleQuery) : 0;
-	finishingBattle = make_unique<FinishingBattleHelper>(battleQuery, queriedPlayers);
+	finishingBattle = std::make_unique<FinishingBattleHelper>(battleQuery, queriedPlayers);
 	
 	auto battleDialogQuery = std::make_shared<CBattleDialogQuery>(this, gs->curB);
 	battleResult.data->queryID = battleDialogQuery->queryID;
@@ -2667,13 +2667,32 @@ void CGameHandler::startBattlePrimary(const CArmedInstance *army1, const CArmedI
 	auto battleQuery = std::dynamic_pointer_cast<CBattleQuery>(queries.topQuery(gs->curB->sides[0].color));
 	if(battleQuery)
 	{
+		for(int i : {0, 1})
+		{
+			if(heroes[i])
+			{
+				SetMana restoreInitialMana;
+				restoreInitialMana.val = battleQuery->initialHeroMana[i];
+				restoreInitialMana.hid = heroes[i]->id;
+				sendAndApply(&restoreInitialMana);
+			}
+		}
+		
 		battleQuery->bi = gs->curB;
 		battleQuery->result = boost::none;
 		battleQuery->belligerents[0] = gs->curB->sides[0].armyObject;
 		battleQuery->belligerents[1] = gs->curB->sides[1].armyObject;
 	}
 
-	queries.addQuery(std::make_shared<CBattleQuery>(this, gs->curB));
+	battleQuery = std::make_shared<CBattleQuery>(this, gs->curB);
+	for(int i : {0, 1})
+	{
+		if(heroes[i])
+		{
+			battleQuery->initialHeroMana[i] = heroes[i]->mana;
+		}
+	}
+	queries.addQuery(battleQuery);
 
 	this->battleThread = std::make_unique<boost::thread>(boost::thread(&CGameHandler::runBattle, this));
 }

+ 1 - 0
server/CQuery.h

@@ -97,6 +97,7 @@ class CBattleQuery : public CGhQuery
 {
 public:
 	std::array<const CArmedInstance *,2> belligerents;
+	std::array<int, 2> initialHeroMana;
 
 	const BattleInfo *bi;
 	boost::optional<BattleResult> result;