1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

suggested changes

This commit is contained in:
SoundSSGood
2025-05-17 19:01:04 +02:00
parent 051381d4db
commit e85b1d4c1c
10 changed files with 42 additions and 43 deletions

View File

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

View File

@ -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,
}
}
```

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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

View File

@ -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))
const auto hero = getHero(heroObjectID);
assert(hero);
assert(hero->canCastThisSpell(spellID.toSpell()));
if(vstd::contains(hero->getSpellsInSpellbook(), spellID))
return;
std::vector<std::pair<ArtifactPosition, ArtifactInstanceID>> chargedArts;
for(const auto & [slot, slotInfo] : hero->artifactsWorn)
{
assert(hero->canCastThisSpell(spellID.toSpell()));
if(vstd::contains(hero->getSpellsInSpellbook(), spellID))
return;
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);
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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);