mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-23 00:28:08 +02:00
suggested changes
This commit is contained in:
@ -142,7 +142,7 @@
|
|||||||
"removeOnDepletion" : {
|
"removeOnDepletion" : {
|
||||||
"type" : "boolean",
|
"type" : "boolean",
|
||||||
},
|
},
|
||||||
"val" : {
|
"startingCharges" : {
|
||||||
"type" : "number",
|
"type" : "number",
|
||||||
"description" : "Default starting charge amount"
|
"description" : "Default starting charge amount"
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ In order to make functional artifact you also need:
|
|||||||
// Optional, by default is false. Remove when fully discharged
|
// Optional, by default is false. Remove when fully discharged
|
||||||
"removeOnDepletion" : true,
|
"removeOnDepletion" : true,
|
||||||
// Optional, by default is 0. Default starting charge amount.
|
// Optional, by default is 0. Default starting charge amount.
|
||||||
"val" : 2,
|
"startingCharges" : 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -226,9 +226,9 @@ std::shared_ptr<CArtifact> CArtHandler::loadFromJson(const std::string & scope,
|
|||||||
art->setCondition(stringToDischargeCond(node["charged"]["usageType"].String()));
|
art->setCondition(stringToDischargeCond(node["charged"]["usageType"].String()));
|
||||||
if(!node["charged"]["removeOnDepletion"].isNull())
|
if(!node["charged"]["removeOnDepletion"].isNull())
|
||||||
art->setRemoveOnDepletion(node["charged"]["removeOnDepletion"].Bool());
|
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)
|
if(charges < 0)
|
||||||
logMod->warn("Warning! Charged artifact %s number of charges cannot be less than zero %d!", art->getNameTranslated(), charges);
|
logMod->warn("Warning! Charged artifact %s number of charges cannot be less than zero %d!", art->getNameTranslated(), charges);
|
||||||
else
|
else
|
||||||
@ -335,7 +335,7 @@ DischargeArtifactCondition CArtHandler::stringToDischargeCond(const std::string
|
|||||||
{
|
{
|
||||||
{"SPELLCAST", DischargeArtifactCondition::SPELLCAST},
|
{"SPELLCAST", DischargeArtifactCondition::SPELLCAST},
|
||||||
{"BATTLE", DischargeArtifactCondition::BATTLE},
|
{"BATTLE", DischargeArtifactCondition::BATTLE},
|
||||||
{"BUILDING", DischargeArtifactCondition::BUILDING},
|
//{"BUILDING", DischargeArtifactCondition::BUILDING},
|
||||||
};
|
};
|
||||||
return growingConditionsMap.at(cond);
|
return growingConditionsMap.at(cond);
|
||||||
}
|
}
|
||||||
|
@ -247,14 +247,15 @@ bool CArtifact::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, b
|
|||||||
}
|
}
|
||||||
|
|
||||||
CChargedArtifact::CChargedArtifact()
|
CChargedArtifact::CChargedArtifact()
|
||||||
: removeOnDepletion(false)
|
: condition(DischargeArtifactCondition::NONE)
|
||||||
|
, removeOnDepletion(false)
|
||||||
, defaultStartCharges(0)
|
, defaultStartCharges(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CChargedArtifact::isCharged() const
|
bool CChargedArtifact::isCharged() const
|
||||||
{
|
{
|
||||||
return condition.has_value();
|
return condition != DischargeArtifactCondition::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CChargedArtifact::setCondition(const DischargeArtifactCondition & dischargeCondition)
|
void CChargedArtifact::setCondition(const DischargeArtifactCondition & dischargeCondition)
|
||||||
@ -277,7 +278,7 @@ uint16_t CChargedArtifact::getDefaultStartCharges() const
|
|||||||
return defaultStartCharges;
|
return defaultStartCharges;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<DischargeArtifactCondition> CChargedArtifact::getDischargeCondition() const
|
DischargeArtifactCondition CChargedArtifact::getDischargeCondition() const
|
||||||
{
|
{
|
||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "StdInc.h"
|
|
||||||
|
|
||||||
#include "ArtBearer.h"
|
#include "ArtBearer.h"
|
||||||
#include "EArtifactClass.h"
|
#include "EArtifactClass.h"
|
||||||
|
|
||||||
@ -69,7 +67,7 @@ public:
|
|||||||
|
|
||||||
class DLL_LINKAGE CChargedArtifact
|
class DLL_LINKAGE CChargedArtifact
|
||||||
{
|
{
|
||||||
std::optional<DischargeArtifactCondition> condition;
|
DischargeArtifactCondition condition;
|
||||||
bool removeOnDepletion;
|
bool removeOnDepletion;
|
||||||
uint16_t defaultStartCharges;
|
uint16_t defaultStartCharges;
|
||||||
|
|
||||||
@ -83,7 +81,7 @@ public:
|
|||||||
void setRemoveOnDepletion(const bool remove);
|
void setRemoveOnDepletion(const bool remove);
|
||||||
void setDefaultStartCharges(const uint16_t charges);
|
void setDefaultStartCharges(const uint16_t charges);
|
||||||
uint16_t getDefaultStartCharges() const;
|
uint16_t getDefaultStartCharges() const;
|
||||||
std::optional<DischargeArtifactCondition> getDischargeCondition() const;
|
DischargeArtifactCondition getDischargeCondition() const;
|
||||||
bool getRemoveOnDepletion() const;
|
bool getRemoveOnDepletion() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -79,11 +79,12 @@ struct MoveArtifactInfo
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class DischargeArtifactCondition
|
enum class DischargeArtifactCondition : int8_t
|
||||||
{
|
{
|
||||||
|
NONE,
|
||||||
SPELLCAST,
|
SPELLCAST,
|
||||||
BATTLE,
|
BATTLE,
|
||||||
BUILDING // not implemented
|
//BUILDING // not implemented
|
||||||
};
|
};
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -3933,7 +3933,7 @@ void CGameHandler::castSpell(const spells::Caster * caster, SpellID spellID, con
|
|||||||
s->adventureCast(spellEnv, p);
|
s->adventureCast(spellEnv, p);
|
||||||
|
|
||||||
if(const auto hero = caster->getHeroCaster())
|
if(const auto hero = caster->getHeroCaster())
|
||||||
verifyChargedArtifactUsed(hero->id, spellID);
|
useChargedArtifactUsed(hero->id, spellID);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGameHandler::swapStacks(const StackLocation & sl1, const StackLocation & sl2)
|
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);
|
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()));
|
const auto artInst = slotInfo.getArt();
|
||||||
|
const auto artType = artInst->getType();
|
||||||
if(vstd::contains(hero->getSpellsInSpellbook(), spellID))
|
if(artType->getDischargeCondition() == DischargeArtifactCondition::SPELLCAST)
|
||||||
return;
|
|
||||||
|
|
||||||
std::vector<std::pair<ArtifactPosition, ArtifactInstanceID>> chargedArts;
|
|
||||||
for(const auto & [slot, slotInfo] : hero->artifactsWorn)
|
|
||||||
{
|
{
|
||||||
const auto artInst = slotInfo.getArt();
|
chargedArts.emplace_back(slot, artInst->getId());
|
||||||
const auto artType = artInst->getType();
|
}
|
||||||
if(artType->getDischargeCondition() == DischargeArtifactCondition::SPELLCAST)
|
else
|
||||||
{
|
{
|
||||||
chargedArts.emplace_back(slot, artInst->getId());
|
if(const auto bonuses = artInst->getBonusesOfType(BonusType::SPELL, spellID); !bonuses->empty())
|
||||||
}
|
return;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ public:
|
|||||||
void changeFogOfWar(const std::unordered_set<int3> &tiles, PlayerColor player,ETileVisibility mode) override;
|
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 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
|
/// Returns hero that is currently visiting this object, or nullptr if no visit is active
|
||||||
const CGHeroInstance * getVisitingHero(const CGObjectInstance *obj);
|
const CGHeroInstance * getVisitingHero(const CGObjectInstance *obj);
|
||||||
|
@ -124,7 +124,7 @@ bool BattleActionProcessor::doHeroSpellAction(const CBattleInfoCallback & battle
|
|||||||
}
|
}
|
||||||
|
|
||||||
parameters.cast(gameHandler->spellEnv, ba.getTarget(&battle));
|
parameters.cast(gameHandler->spellEnv, ba.getTarget(&battle));
|
||||||
gameHandler->verifyChargedArtifactUsed(h->id, ba.spell);
|
gameHandler->useChargedArtifactUsed(h->id, ba.spell);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -508,7 +508,7 @@ void BattleResultProcessor::battleFinalize(const BattleID & battleID, const Batt
|
|||||||
{
|
{
|
||||||
auto artInst = slotInfo.getArt();
|
auto artInst = slotInfo.getArt();
|
||||||
assert(artInst);
|
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);
|
auto & discharging = resultsApplied.dischargingArtifacts.emplace_back(artInst->getId(), 1);
|
||||||
discharging.artLoc.emplace(id, creature, slot);
|
discharging.artLoc.emplace(id, creature, slot);
|
||||||
|
Reference in New Issue
Block a user