mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
CScrollArtifactInstance
This commit is contained in:
@@ -169,16 +169,12 @@ std::string CComponent::getDescription()
|
||||
case artifact:
|
||||
{
|
||||
auto artID = ArtifactID(subtype);
|
||||
std::unique_ptr<CArtifactInstance> art;
|
||||
if (artID != ArtifactID::SPELL_SCROLL)
|
||||
auto description = VLC->arth->objects[artID]->getDescriptionTranslated();
|
||||
if(artID == ArtifactID::SPELL_SCROLL)
|
||||
{
|
||||
art.reset(ArtifactUtils::createNewArtifactInstance(artID));
|
||||
ArtifactUtils::insertScrrollSpellName(description, SpellID(val));
|
||||
}
|
||||
else
|
||||
{
|
||||
art.reset(ArtifactUtils::createScroll(SpellID(val)));
|
||||
}
|
||||
return art->getDescription();
|
||||
return description;
|
||||
}
|
||||
case experience: return CGI->generaltexth->allTexts[241];
|
||||
case spell: return (*CGI->spellh)[subtype]->getDescriptionTranslated(val);
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "CArtHandler.h"
|
||||
#include "GameSettings.h"
|
||||
#include "spells/CSpellHandler.h"
|
||||
|
||||
#include "mapping/CMap.h"
|
||||
#include "mapObjects/CGHeroInstance.h"
|
||||
@@ -218,4 +219,18 @@ DLL_LINKAGE CArtifactInstance * ArtifactUtils::createArtifact(CMap * map, const
|
||||
return art;
|
||||
}
|
||||
|
||||
DLL_LINKAGE void ArtifactUtils::insertScrrollSpellName(std::string & description, SpellID & sid)
|
||||
{
|
||||
// We expect scroll description to be like this: This scroll contains the [spell name] spell which is added
|
||||
// into spell book for as long as hero carries the scroll. So we want to replace text in [...] with a spell name.
|
||||
// However other language versions don't have name placeholder at all, so we have to be careful
|
||||
auto nameStart = description.find_first_of('[');
|
||||
auto nameEnd = description.find_first_of(']', nameStart);
|
||||
if(sid.getNum() >= 0)
|
||||
{
|
||||
if(nameStart != std::string::npos && nameEnd != std::string::npos)
|
||||
description = description.replace(nameStart, nameEnd - nameStart + 1, sid.toSpell(VLC->spells())->getNameTranslated());
|
||||
}
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@@ -41,6 +41,7 @@ namespace ArtifactUtils
|
||||
DLL_LINKAGE CArtifactInstance * createNewArtifactInstance(CArtifact * art);
|
||||
DLL_LINKAGE CArtifactInstance * createNewArtifactInstance(const ArtifactID & aid);
|
||||
DLL_LINKAGE CArtifactInstance * createArtifact(CMap * map, const ArtifactID & aid, int spellID = -1);
|
||||
DLL_LINKAGE void insertScrrollSpellName(std::string & description, SpellID & sid);
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@@ -820,19 +820,7 @@ std::string CArtifactInstance::getDescription() const
|
||||
{
|
||||
std::string text = artType->getDescriptionTranslated();
|
||||
if(artType->getId() == ArtifactID::SPELL_SCROLL)
|
||||
{
|
||||
// we expect scroll description to be like this: This scroll contains the [spell name] spell which is added into your spell book for as long as you carry the scroll.
|
||||
// so we want to replace text in [...] with a spell name
|
||||
// however other language versions don't have name placeholder at all, so we have to be careful
|
||||
SpellID spellID = getScrollSpellID();
|
||||
size_t nameStart = text.find_first_of('[');
|
||||
size_t nameEnd = text.find_first_of(']', nameStart);
|
||||
if(spellID.getNum() >= 0)
|
||||
{
|
||||
if(nameStart != std::string::npos && nameEnd != std::string::npos)
|
||||
text = text.replace(nameStart, nameEnd - nameStart + 1, spellID.toSpell(VLC->spells())->getNameTranslated());
|
||||
}
|
||||
}
|
||||
ArtifactUtils::insertScrrollSpellName(text, getScrollSpellID());
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -879,17 +867,6 @@ void CArtifactInstance::deserializationFix()
|
||||
attachTo(*part.art);
|
||||
}
|
||||
|
||||
SpellID CArtifactInstance::getScrollSpellID() const
|
||||
{
|
||||
const auto b = getBonusLocalFirst(Selector::type()(BonusType::SPELL));
|
||||
if(!b)
|
||||
{
|
||||
logMod->warn("Warning: %s doesn't bear any spell!", nodeName());
|
||||
return SpellID::NONE;
|
||||
}
|
||||
return SpellID(b->subtype);
|
||||
}
|
||||
|
||||
bool CArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
|
||||
{
|
||||
if(supposedPart == this)
|
||||
@@ -916,6 +893,18 @@ void CCombinedArtifactInstance::addArtInstAsPart(CArtifactInstance * art, const
|
||||
artInst->attachTo(*art);
|
||||
}
|
||||
|
||||
SpellID CScrollArtifactInstance::getScrollSpellID() const
|
||||
{
|
||||
auto artInst = static_cast<const CArtifactInstance*>(this);
|
||||
const auto bonus = artInst->getBonusLocalFirst(Selector::type()(BonusType::SPELL));
|
||||
if (!bonus)
|
||||
{
|
||||
logMod->warn("Warning: %s doesn't bear any spell!", artInst->nodeName());
|
||||
return SpellID::NONE;
|
||||
}
|
||||
return SpellID(bonus->subtype);
|
||||
}
|
||||
|
||||
CArtifactSet::~CArtifactSet() = default;
|
||||
|
||||
const CArtifactInstance * CArtifactSet::getArt(const ArtifactPosition & pos, bool excludeLocked) const
|
||||
|
@@ -137,7 +137,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class CCombinedArtifactInstance
|
||||
class DLL_LINKAGE CCombinedArtifactInstance
|
||||
{
|
||||
protected:
|
||||
CCombinedArtifactInstance() = default;
|
||||
@@ -158,7 +158,16 @@ public:
|
||||
void addArtInstAsPart(CArtifactInstance * art, const ArtifactPosition & slot);
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CArtifactInstance : public CBonusSystemNode, public CCombinedArtifactInstance
|
||||
class DLL_LINKAGE CScrollArtifactInstance
|
||||
{
|
||||
protected:
|
||||
CScrollArtifactInstance() = default;
|
||||
public:
|
||||
SpellID getScrollSpellID() const;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CArtifactInstance
|
||||
: public CBonusSystemNode, public CCombinedArtifactInstance, public CScrollArtifactInstance
|
||||
{
|
||||
protected:
|
||||
void init();
|
||||
@@ -174,7 +183,6 @@ public:
|
||||
void setType(CArtifact * art);
|
||||
|
||||
std::string getDescription() const;
|
||||
SpellID getScrollSpellID() const; //to be used with scrolls (and similar arts), -1 if none
|
||||
|
||||
ArtifactID getTypeId() const;
|
||||
bool canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved = false) const;
|
||||
|
Reference in New Issue
Block a user