Use smart ArbUt pointers for returning scripts.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
cd50b2c2e8
commit
0117cb9d64
|
@ -367,8 +367,8 @@ void TurnHandler::ExecuteItemChoice(const ArbUt::BorrowedPtr<ItemTurnChoice>& ch
|
|||
if (!battle.HasValue()) {
|
||||
return;
|
||||
}
|
||||
auto* script = battle.GetValue()->GetLibrary()->GetScriptResolver()->LoadItemScript(choice->GetItem());
|
||||
if (script == nullptr) {
|
||||
auto script = battle.GetValue()->GetLibrary()->GetScriptResolver()->LoadItemScript(choice->GetItem());
|
||||
if (!script.HasValue()) {
|
||||
return;
|
||||
}
|
||||
const auto& targetIndex = choice->GetTarget();
|
||||
|
@ -376,17 +376,17 @@ void TurnHandler::ExecuteItemChoice(const ArbUt::BorrowedPtr<ItemTurnChoice>& ch
|
|||
if (targetIndex.has_value()) {
|
||||
target = battle.GetValue()->GetCreature(targetIndex.value());
|
||||
}
|
||||
auto isCreatureUseItem = script->IsCreatureUseItem();
|
||||
auto isCreatureUseItem = script.GetValue()->IsCreatureUseItem();
|
||||
if (isCreatureUseItem && !target.HasValue()) {
|
||||
target = choice->GetUser();
|
||||
}
|
||||
|
||||
if (isCreatureUseItem) {
|
||||
if (!script->IsUseValidForCreature(target.GetValue())) {
|
||||
if (!script.GetValue()->IsUseValidForCreature(target.GetValue())) {
|
||||
return;
|
||||
}
|
||||
script->OnCreatureUse(target.GetValue(), true);
|
||||
script.GetValue()->OnCreatureUse(target.GetValue(), true);
|
||||
} else {
|
||||
script->OnUse(battle.GetValue());
|
||||
script.GetValue()->OnUse(battle.GetValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -365,7 +365,11 @@ namespace CreatureLib::Battling {
|
|||
return false;
|
||||
}
|
||||
|
||||
auto* script = _library->GetScriptResolver()->LoadItemScript(_heldItem.GetValue());
|
||||
auto scriptOpt = _library->GetScriptResolver()->LoadItemScript(_heldItem.GetValue());
|
||||
if (!scriptOpt.HasValue()) {
|
||||
return false;
|
||||
}
|
||||
auto script = scriptOpt.GetValue();
|
||||
auto isCreatureUseItem = script->IsCreatureUseItem();
|
||||
if (isCreatureUseItem) {
|
||||
if (!script->IsUseValidForCreature(this)) {
|
||||
|
|
|
@ -18,13 +18,13 @@ namespace CreatureLib::Battling {
|
|||
virtual ~ScriptResolver() = default;
|
||||
|
||||
virtual void Initialize([[maybe_unused]] BattleLibrary* non_null library){};
|
||||
virtual BattleScript* nullable LoadScript([[maybe_unused]] const ArbUt::OptionalBorrowedPtr<void>& owner,
|
||||
[[maybe_unused]] ScriptCategory category,
|
||||
[[maybe_unused]] const ArbUt::StringView& scriptName) {
|
||||
virtual ArbUt::OptionalUniquePtr<BattleScript>
|
||||
LoadScript([[maybe_unused]] const ArbUt::OptionalBorrowedPtr<void>& owner,
|
||||
[[maybe_unused]] ScriptCategory category, [[maybe_unused]] const ArbUt::StringView& scriptName) {
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
virtual ItemUseScript* nullable
|
||||
virtual ArbUt::OptionalUniquePtr<ItemUseScript>
|
||||
LoadItemScript([[maybe_unused]] const CreatureLib::Library::Item* non_null item) {
|
||||
return nullptr;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue