소스 검색

suggested changes

SoundSSGood 5 달 전
부모
커밋
e85b1d4c1c

+ 1 - 1
config/schemas/artifact.json

@@ -142,7 +142,7 @@
 				"removeOnDepletion" : {
 					"type" : "boolean",
 				},
-				"val" : {
+				"startingCharges" : {
 					"type" : "number",
 					"description" : "Default starting charge amount"
 				}

+ 1 - 1
docs/modders/Entities_Format/Artifact_Format.md

@@ -98,7 +98,7 @@ In order to make functional artifact you also need:
     // Optional, by default is false. Remove when fully discharged
     "removeOnDepletion" : true,
     // Optional, by default is 0. Default starting charge amount.
-    "val" : 2,
+    "startingCharges" : 2,
 	}
 }
 ```

+ 3 - 3
lib/entities/artifact/CArtHandler.cpp

@@ -226,9 +226,9 @@ std::shared_ptr<CArtifact> CArtHandler::loadFromJson(const std::string & scope,
 		art->setCondition(stringToDischargeCond(node["charged"]["usageType"].String()));
 		if(!node["charged"]["removeOnDepletion"].isNull())
 			art->setRemoveOnDepletion(node["charged"]["removeOnDepletion"].Bool());
-		if(!node["charged"]["val"].isNull())
+		if(!node["charged"]["startingCharges"].isNull())
 		{
-			const auto charges = node["charged"]["val"].Integer();
+			const auto charges = node["charged"]["startingCharges"].Integer();
 			if(charges < 0)
 				logMod->warn("Warning! Charged artifact %s number of charges cannot be less than zero %d!", art->getNameTranslated(), charges);
 			else
@@ -335,7 +335,7 @@ DischargeArtifactCondition CArtHandler::stringToDischargeCond(const std::string
 	{
 		{"SPELLCAST", DischargeArtifactCondition::SPELLCAST},
 		{"BATTLE", DischargeArtifactCondition::BATTLE},
-		{"BUILDING", DischargeArtifactCondition::BUILDING},
+		//{"BUILDING", DischargeArtifactCondition::BUILDING},
 	};
 	return growingConditionsMap.at(cond);
 }

+ 4 - 3
lib/entities/artifact/CArtifact.cpp

@@ -247,14 +247,15 @@ bool CArtifact::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, b
 }
 
 CChargedArtifact::CChargedArtifact()
-	: removeOnDepletion(false)
+	: condition(DischargeArtifactCondition::NONE)
+	,	removeOnDepletion(false)
 	, defaultStartCharges(0)
 {
 }
 
 bool CChargedArtifact::isCharged() const
 {
-	return condition.has_value();
+	return condition != DischargeArtifactCondition::NONE;
 }
 
 void CChargedArtifact::setCondition(const DischargeArtifactCondition & dischargeCondition)
@@ -277,7 +278,7 @@ uint16_t CChargedArtifact::getDefaultStartCharges() const
 	return defaultStartCharges;
 }
 
-std::optional<DischargeArtifactCondition> CChargedArtifact::getDischargeCondition() const
+DischargeArtifactCondition CChargedArtifact::getDischargeCondition() const
 {
 	return condition;
 }

+ 2 - 4
lib/entities/artifact/CArtifact.h

@@ -9,8 +9,6 @@
  */
 #pragma once
 
-#include "StdInc.h"
-
 #include "ArtBearer.h"
 #include "EArtifactClass.h"
 
@@ -69,7 +67,7 @@ public:
 
 class DLL_LINKAGE CChargedArtifact
 {
-	std::optional<DischargeArtifactCondition> condition;
+	DischargeArtifactCondition condition;
 	bool removeOnDepletion;
 	uint16_t defaultStartCharges;
 
@@ -83,7 +81,7 @@ public:
 	void setRemoveOnDepletion(const bool remove);
 	void setDefaultStartCharges(const uint16_t charges);
 	uint16_t getDefaultStartCharges() const;
-	std::optional<DischargeArtifactCondition> getDischargeCondition() const;
+	DischargeArtifactCondition getDischargeCondition() const;
 	bool getRemoveOnDepletion() const;
 };
 

+ 3 - 2
lib/networkPacks/ArtifactLocation.h

@@ -79,11 +79,12 @@ struct MoveArtifactInfo
 	}
 };
 
-enum class DischargeArtifactCondition
+enum class DischargeArtifactCondition : int8_t
 {
+	NONE,
 	SPELLCAST,
 	BATTLE,
-	BUILDING	// not implemented
+	//BUILDING	// not implemented
 };
 
 VCMI_LIB_NAMESPACE_END

+ 24 - 25
server/CGameHandler.cpp

@@ -3933,7 +3933,7 @@ void CGameHandler::castSpell(const spells::Caster * caster, SpellID spellID, con
 	s->adventureCast(spellEnv, p);
 
 	if(const auto hero = caster->getHeroCaster())
-		verifyChargedArtifactUsed(hero->id, spellID);
+		useChargedArtifactUsed(hero->id, spellID);
 }
 
 bool CGameHandler::swapStacks(const StackLocation & sl1, const StackLocation & sl2)
@@ -4341,34 +4341,33 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
 	battles->startBattle(army1, army2);
 }
 
-void CGameHandler::verifyChargedArtifactUsed(const ObjectInstanceID & heroObjectID, const SpellID & spellID)
+void CGameHandler::useChargedArtifactUsed(const ObjectInstanceID & heroObjectID, const SpellID & spellID)
 {
-	if(const auto hero = getHero(heroObjectID))
-	{
-		assert(hero->canCastThisSpell(spellID.toSpell()));
+	const auto hero = getHero(heroObjectID);
+	assert(hero);
+	assert(hero->canCastThisSpell(spellID.toSpell()));
 
-		if(vstd::contains(hero->getSpellsInSpellbook(), spellID))
-			return;
+	if(vstd::contains(hero->getSpellsInSpellbook(), spellID))
+		return;
 
-		std::vector<std::pair<ArtifactPosition, ArtifactInstanceID>> chargedArts;
-		for(const auto & [slot, slotInfo] : hero->artifactsWorn)
+	std::vector<std::pair<ArtifactPosition, ArtifactInstanceID>> chargedArts;
+	for(const auto & [slot, slotInfo] : hero->artifactsWorn)
+	{
+		const auto artInst = slotInfo.getArt();
+		const auto artType = artInst->getType();
+		if(artType->getDischargeCondition() == DischargeArtifactCondition::SPELLCAST)
 		{
-			const auto artInst = slotInfo.getArt();
-			const auto artType = artInst->getType();
-			if(artType->getDischargeCondition() == DischargeArtifactCondition::SPELLCAST)
-			{
-				chargedArts.emplace_back(slot, artInst->getId());
-			}
-			else
-			{
-				if(const auto bonuses = artInst->getBonusesOfType(BonusType::SPELL, spellID); !bonuses->empty())
-					return;
-			}
+			chargedArts.emplace_back(slot, artInst->getId());
+		}
+		else
+		{
+			if(const auto bonuses = artInst->getBonusesOfType(BonusType::SPELL, spellID); !bonuses->empty())
+				return;
 		}
-
-		assert(!chargedArts.empty());
-		DischargeArtifact msg(chargedArts.front().second, 1);
-		msg.artLoc.emplace(hero->id, chargedArts.front().first);
-		sendAndApply(msg);
 	}
+
+	assert(!chargedArts.empty());
+	DischargeArtifact msg(chargedArts.front().second, 1);
+	msg.artLoc.emplace(hero->id, chargedArts.front().first);
+	sendAndApply(msg);
 }

+ 1 - 1
server/CGameHandler.h

@@ -169,7 +169,7 @@ public:
 	void changeFogOfWar(const std::unordered_set<int3> &tiles, PlayerColor player,ETileVisibility mode) override;
 	
 	void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override;
-	void verifyChargedArtifactUsed(const ObjectInstanceID & heroObjectID, const SpellID & spellID);
+	void useChargedArtifactUsed(const ObjectInstanceID & heroObjectID, const SpellID & spellID);
 
 	/// Returns hero that is currently visiting this object, or nullptr if no visit is active
 	const CGHeroInstance * getVisitingHero(const CGObjectInstance *obj);

+ 1 - 1
server/battles/BattleActionProcessor.cpp

@@ -124,7 +124,7 @@ bool BattleActionProcessor::doHeroSpellAction(const CBattleInfoCallback & battle
 	}
 
 	parameters.cast(gameHandler->spellEnv, ba.getTarget(&battle));
-	gameHandler->verifyChargedArtifactUsed(h->id, ba.spell);
+	gameHandler->useChargedArtifactUsed(h->id, ba.spell);
 
 	return true;
 }

+ 1 - 1
server/battles/BattleResultProcessor.cpp

@@ -508,7 +508,7 @@ void BattleResultProcessor::battleFinalize(const BattleID & battleID, const Batt
 		{
 			auto artInst = slotInfo.getArt();
 			assert(artInst);
-			if(const auto condition = artInst->getType()->getDischargeCondition(); condition && condition.value() == DischargeArtifactCondition::BATTLE)
+			if(const auto condition = artInst->getType()->getDischargeCondition(); condition == DischargeArtifactCondition::BATTLE)
 			{
 				auto & discharging = resultsApplied.dischargingArtifacts.emplace_back(artInst->getId(), 1);
 				discharging.artLoc.emplace(id, creature, slot);