Skip to content

Commit

Permalink
feat: add setCollision method for ObjectReference collision manag…
Browse files Browse the repository at this point in the history
…ement (#2333)
  • Loading branch information
Pospelove authored Feb 14, 2025
1 parent 7c38988 commit f1e7f9f
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/release/dev/sp-set-collision.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a `setCollision` method to enable or disable an `ObjectReference`'s collision, serving as a binding for a method from CommonLibSSE.
4 changes: 2 additions & 2 deletions overlay_ports/commonlibae/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO powerof3/CommonLibSSE
REF 20276e9c1f6104c07747d0eddf6d290485ff6e5f
SHA512 be201095e0065cbac884f465a73c5331e1e1a97e5442b4768b73c57cb9b5bac3f47a4b81730963ec2239ba45c619cbcb1ef685b534c85fd67db9801edbc2c834
REF e3626d228d60b92a82410accd475bffdd7245653
SHA512 349036dd83e7886b57e3b59f2810f0fc87d5ca9a2f8580597b6a20c8a046afb806cd7d394c57cff8c2106eaa46af44ee8a3cd0a74791d93a5e41072a09866386
HEAD_REF dev
PATCHES
patches/01-objectrefr-make_moverefr_public.patch
Expand Down
8 changes: 4 additions & 4 deletions overlay_ports/commonlibse/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO Ryan-rsm-McKenzie/CommonLibSSE
REF 20276e9c1f6104c07747d0eddf6d290485ff6e5f
SHA512 be201095e0065cbac884f465a73c5331e1e1a97e5442b4768b73c57cb9b5bac3f47a4b81730963ec2239ba45c619cbcb1ef685b534c85fd67db9801edbc2c834
HEAD_REF master
REPO powerof3/CommonLibSSE
REF e3626d228d60b92a82410accd475bffdd7245653
SHA512 349036dd83e7886b57e3b59f2810f0fc87d5ca9a2f8580597b6a20c8a046afb806cd7d394c57cff8c2106eaa46af44ee8a3cd0a74791d93a5e41072a09866386
HEAD_REF dev
PATCHES
patches/01-objectrefr-make_moverefr_public.patch
patches/02-variable-make_members_public.patch
Expand Down
63 changes: 57 additions & 6 deletions skymp5-client/src/sync/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import {
Game,
storage,
// @ts-expect-error (TODO: Remove in 2.10.0)
castSpellImmediate,
// @ts-expect-error (TODO: Remove in 2.10.0)
SpellType,
// @ts-expect-error (TODO: Remove in 2.10.0)
interruptCast
setCollision
} from "skyrimPlatform";
import { Movement } from "./movement";
import { applyWeapDrawn } from "./movementApply";
Expand All @@ -36,6 +32,52 @@ const allowedIdles = new Array<[number, string]>();
const refsWithDefaultAnimsDisabled = new Set<number>();
const allowedAnims = new Set<string>();

const actorSitAnimsLowerCase = [
"IdleStoolEnterPlayer",
"IdleStoolEnter",
"IdleStoolEnterInstant",
"IdleChairRightEnter",
"IdleChairLeftEnter",
"IdleChairFrontEnter",
"IdleJarlChairEnter",
"IdleJarlChairEnterInstant",
"IdleSnowElfPrinceChairDialogue",
"IdleSnowElfPrinceChairEnter",
"IdleSnowElfPrinceChairEnterInstant",
"IdleChairCHILDEnterInstant",
"IdleChairCHILDFrontEnter",
"IdleChairCHILDLeftEnter",
"IdleChairCHILDRightEnter",
"IdleChairEnterInstant",
].map(x => x.toLowerCase());

const actorGetUpAnimsLowerCase = [
"IdleStoolBackExit",
"IdleChairRightExit",
"IdleChairRightQuickExit",
"IdleChairLeftExit",
"IdleChairLeftQuickExit",
"IdleChairFrontExit",
"IdleChairFrontQuickExit",
"IdleChairCHILDFrontExit",
"IdleChairCHILDLeftExit",
"IdleChairCHILDRightExit",
].map(x => x.toLocaleLowerCase());

// unclassified:

// IdleChairEnterInstant
// IdleChairEnterStart
// IdleChairEnterStop
// IdleChairEnterToSit
// IdleChairExitStart
// IdleChairExitToStand
// IdleChairSitting
// IdleLeftChairEnterStart
// ChairIdle
// IdleRightChairEnterStart
// IdleLeftChairEnterStart

const isIdle = (animEventName: string) => {
return (
animEventName === "MotionDrivenIdle" ||
Expand Down Expand Up @@ -83,8 +125,10 @@ export const applyAnimation = (
return;
}

const animEventNameLowerCase = anim.animEventName.toLowerCase();

if (refsWithDefaultAnimsDisabled.has(refr.getFormID())) {
if (anim.animEventName.toLowerCase().includes("attack")) {
if (animEventNameLowerCase.includes("attack")) {
allowedAnims.add(refr.getFormID() + ":" + anim.animEventName);
}
}
Expand All @@ -99,6 +143,13 @@ export const applyAnimation = (
});
}

if (actorSitAnimsLowerCase.find((x) => x === animEventNameLowerCase) !== undefined) {
setCollision(refr.getFormID(), false);
}

if (actorGetUpAnimsLowerCase.find((x) => x === animEventNameLowerCase) !== undefined) {
setCollision(refr.getFormID(), true);
}
};

export const setDefaultAnimsDisabled = (
Expand Down
3 changes: 2 additions & 1 deletion skymp5-client/src/sync/movementApply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ const translateTo = (refr: ObjectReference, m: Movement) => {
m.runMode !== "Standing" ||
m.isInJumpState ||
ObjectReferenceEx.getDistanceNoZ(refrRealPos, gTempTargetPos) > 8 ||
angleDiff > 80
angleDiff > 80 ||
Actor.from(refr)?.getSitState() === 3
) {
const actor = Actor.from(refr);
if (actor && actor.getActorValue("Variable10") < -999) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1612,3 +1612,5 @@ export declare function castSpellImmediate(actorCasterFormId: number, castingSou
export declare function interruptCast(actorCasterFormId: number, castingSource: SpellType, animationVariables: ActorAnimationVariables): void;
export declare function getAnimationVariablesFromActor(actorFormId: number): ActorAnimationVariables;
export declare function applyAnimationVariablesToActor(actorFormId: number, animationVariables: ActorAnimationVariables): boolean;

export declare function setCollision(refrFormId: number, collision: boolean): void;
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,8 @@ export declare function interruptCast(actorCasterFormId: number, castingSource:
export declare function getAnimationVariablesFromActor(actorFormId: number): ActorAnimationVariables;
export declare function applyAnimationVariablesToActor(actorFormId: number, animationVariables: ActorAnimationVariables): boolean;

export declare function setCollision(refrFormId: number, collision: boolean): void;

// Based on Form.pex
export declare class Form extends PapyrusObject {
static from(papyrusObject: PapyrusObject | null): Form | null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "ObjectReferenceApi.h"

#include "NullPointerException.h"

RE::TESObjectREFR* GetArgObjectReference(const JsValue& arg)
{
auto formId = static_cast<uint32_t>(static_cast<double>(arg));
auto refr = RE::TESForm::LookupByID<RE::TESObjectREFR>(formId);

if (!refr) {
throw NullPointerException("refr");
}

return refr;
}

JsValue ObjectReferenceApi::SetCollision(const JsFunctionArguments& args)
{
auto refr = GetArgObjectReference(args[1]);
refr->SetCollision(static_cast<bool>(args[2]));
return JsValue::Undefined();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace ObjectReferenceApi {

JsValue SetCollision(const JsFunctionArguments& args);

inline void Register(JsValue& exports)
{
exports.SetProperty("setCollision", JsValue::Function(SetCollision));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "LoadGameApi.h"
#include "MagicApi.h"
#include "MpClientPluginApi.h"
#include "ObjectReferenceApi.h"
#include "SkyrimPlatformProxy.h"
#include "TextApi.h"
#include "ThreadPoolWrapper.h"
Expand Down Expand Up @@ -263,6 +264,7 @@ class CommonExecutionListener : public TickListener
InventoryApi::Register(e);
MagicApi::Register(e);
ConstEnumApi::Register(e, engine);
ObjectReferenceApi::Register(e);
CallNativeApi::Register(
e, [this] { return nativeCallRequirements; });
e.SetProperty("settings", getSettings, nullptr);
Expand Down

0 comments on commit f1e7f9f

Please sign in to comment.