Skip to content

Commit

Permalink
Updated to v1.2.7
Browse files Browse the repository at this point in the history
Fixed creature Idle action error
  • Loading branch information
max-su-2019 committed Jan 1, 2024
1 parent 5892559 commit e07167d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include(GNUInstallDirs)
# info
project(
SCAR
VERSION 1.2.6
VERSION 1.2.7
LANGUAGES CXX
)

Expand Down
47 changes: 45 additions & 2 deletions src/SCARActionData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "DataHandler.h"
#include "Function.h"

#undef GetObject

namespace SCAR
{
void from_json(const json& j, SCARActionData& a_data)
Expand Down Expand Up @@ -105,6 +107,36 @@ namespace SCAR
return itr != actionMap.end() ? itr->second : DefaultObject::kActionRightAttack;
}

bool SCARActionData::PerformSpecialIdle(RE::Actor* a_attacker, RE::Actor* a_target, RE::BGSAction* a_action, RE::TESIdleForm* a_Idle)
{
if (!a_attacker || !a_target || !a_attacker->GetActorRuntimeData().currentProcess)
return false;

if (!a_Idle->CheckConditions(a_attacker, a_target, false)) {
return false;
}

auto actionData = RE::TESActionData::Create();
if (!actionData) {
return false;
}

actionData->source.reset(a_attacker);
actionData->target.reset(a_target);
actionData->animObjIdle = a_Idle;
actionData->animEvent = a_Idle->animEventName;
actionData->action = a_action;

a_attacker->SetGraphVariableInt("SCAR_AttackVariants", variantID);
auto result = actionData->Process();

actionData->~TESActionData();
RE::free(actionData);
actionData = nullptr;

return result;
}

bool SCARActionData::PerformSCARAction(RE::Actor* a_attacker, RE::Actor* a_target, RE::CombatBehaviorContextMelee* a_context, RE::hkbClipGenerator* a_clip)
{
if (!a_attacker || !a_target || !a_attacker->GetActorRuntimeData().currentProcess)
Expand Down Expand Up @@ -133,8 +165,19 @@ namespace SCAR
return false;
}

a_attacker->SetGraphVariableInt("SCAR_AttackVariants", variantID);
auto result = a_attacker->GetActorRuntimeData().currentProcess->SetupSpecialIdle(a_attacker, GetActionObject(), IdleAnimation, true, true, a_target);
auto defaultObjMgr = RE::BGSDefaultObjectManager::GetSingleton();
if (!defaultObjMgr)
return false;

auto actionObj = GetActionObject();
auto actionForm = defaultObjMgr->GetObject(actionObj);
auto action = actionForm ? actionForm->As<RE::BGSAction>() : nullptr;
if (!action) {
ERROR("Not Vaild Action Type Get: \"{}\"!", actionType);
return false;
}

auto result = PerformSpecialIdle(a_attacker, a_target, action, IdleAnimation);
if (result) {
DEBUG("Perform SCAR Action! Name : {}, Distance: {}-{}, Angle: {}-{}, Chance: {}, Type: {}, Weight {}",
IdleAnimationEditorID, minDistance, maxDistance, startAngle, endAngle, chance, actionType, weight);
Expand Down
2 changes: 2 additions & 0 deletions src/SCARActionData.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace SCAR

private:
const DefaultObject GetActionObject() const;
bool PerformSpecialIdle(RE::Actor* a_attacker, RE::Actor* a_target, RE::BGSAction* a_action, RE::TESIdleForm* a_Idle);

_NODISCARD const float GetStartRadian() const { return startAngle / 180.f * std::numbers::pi; };
_NODISCARD const float GetEndRadian() const { return endAngle / 180.f * std::numbers::pi; };

Expand Down

0 comments on commit e07167d

Please sign in to comment.