瀏覽代碼

Use and check movement points in town portal.
* fixes mantiss 0002031

AlexVinS 10 年之前
父節點
當前提交
6c334174d9
共有 2 個文件被更改,包括 28 次插入5 次删除
  1. 12 4
      client/windows/CSpellWindow.cpp
  2. 16 1
      lib/spells/AdventureSpellMechanics.cpp

+ 12 - 4
client/windows/CSpellWindow.cpp

@@ -709,15 +709,23 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
 				std::vector <int> availableTowns;
 				std::vector <const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(false);
 
-				vstd::erase_if(Towns, [](const CGTownInstance * t)
+				vstd::erase_if(Towns, [this](const CGTownInstance * t)
 				{
-					const auto relations = LOCPLINT->cb->getPlayerRelations(t->tempOwner, LOCPLINT->playerID);	
+					const auto relations = owner->myInt->cb->getPlayerRelations(t->tempOwner, owner->myInt->playerID);	
 					return relations == PlayerRelations::ENEMIES; 				
 				});
-				
+
 				if (Towns.empty())
 				{
-					LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[124]);
+					owner->myInt->showInfoDialog(CGI->generaltexth->allTexts[124]);
+					return;
+				}
+
+				const int movementCost = (h->getSpellSchoolLevel(sp) >= 3) ? 200 : 300;
+
+				if(h->movement < movementCost)
+				{
+					owner->myInt->showInfoDialog(CGI->generaltexth->allTexts[125]);
 					return;
 				}
 

+ 16 - 1
lib/spells/AdventureSpellMechanics.cpp

@@ -238,7 +238,22 @@ bool TownPortalMechanics::applyAdventureEffects(const SpellCastEnvironment * env
 		}
 
 	}
-	env->moveHero(parameters.caster->id, town->visitablePos() + parameters.caster->getVisitableOffset() ,1);
+	
+	const int movementCost = (parameters.caster->getSpellSchoolLevel(owner) >= 3) ? 200 : 300;
+	
+	if(parameters.caster->movement < movementCost)
+	{
+		env->complain("This hero has not enough movement points!");
+		return false;		
+	}
+	
+	if(env->moveHero(parameters.caster->id, town->visitablePos() + parameters.caster->getVisitableOffset() ,1))
+	{
+		SetMovePoints smp;
+		smp.hid = parameters.caster->id;
+		smp.val = std::max<ui32>(0, parameters.caster->movement - movementCost);
+		env->sendAndApply(&smp);		
+	}
 	return true;
 }