Skip to content

Commit

Permalink
Add separate utils to generate default for meeting scheme. Separate a…
Browse files Browse the repository at this point in the history
…buse/clear abuse/hit actor utils to use in effects/animations freely. Tests for new object utils. Enum for active item slot.
  • Loading branch information
Neloreck committed Aug 20, 2023
1 parent 27073d2 commit b251ac6
Show file tree
Hide file tree
Showing 24 changed files with 613 additions and 330 deletions.
37 changes: 19 additions & 18 deletions src/engine/core/managers/interface/ActorInputManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,31 @@ import { SchemeNoWeapon } from "@/engine/core/schemes/sr_no_weapon";
import { readTimeFromPacket, writeTimeToPacket } from "@/engine/core/utils/game/game_time";
import { LuaLogger } from "@/engine/core/utils/logging";
import { misc } from "@/engine/lib/constants/items/misc";
import { ClientObject, GameHud, NetPacket, NetProcessor, Optional, TDuration, Time, TIndex } from "@/engine/lib/types";
import {
ClientObject,
EActiveItemSlot,
GameHud,
NetPacket,
NetProcessor,
Optional,
TDuration,
Time,
TIndex,
} from "@/engine/lib/types";

const logger: LuaLogger = new LuaLogger($filename);

/**
* Manager to handle actor input.
*/
export class ActorInputManager extends AbstractCoreManager {
/**
* Item slot `none`.
*/
public static readonly NONE_ITEM_SLOT: TIndex = 0;
/**
* Item slot applied by default when game is started.
*/
public static readonly DEFAULT_ACTIVE_ITEM_SLOT: TIndex = 3;

public isWeaponHidden: boolean = false;
public isWeaponHiddenInDialog: boolean = false;
public isActorNightVisionEnabled: boolean = false;
public isActorTorchEnabled: boolean = false;

public activeItemSlot: TIndex = ActorInputManager.DEFAULT_ACTIVE_ITEM_SLOT;
public memoizedItemSlot: TIndex = ActorInputManager.NONE_ITEM_SLOT;
public activeItemSlot: EActiveItemSlot = EActiveItemSlot.PRIMARY;
public memoizedItemSlot: EActiveItemSlot = EActiveItemSlot.NONE;

public disableInputAt: Optional<Time> = null;
public disableInputDuration: Optional<TDuration> = null;
Expand Down Expand Up @@ -148,9 +149,9 @@ export class ActorInputManager extends AbstractCoreManager {
if (resetSlot) {
const slot: TIndex = actor.active_slot();

if (slot !== ActorInputManager.NONE_ITEM_SLOT) {
if (slot !== EActiveItemSlot.NONE) {
this.memoizedItemSlot = slot;
actor.activate_slot(ActorInputManager.NONE_ITEM_SLOT);
actor.activate_slot(EActiveItemSlot.NONE);
}
}

Expand All @@ -174,14 +175,14 @@ export class ActorInputManager extends AbstractCoreManager {

if (restore) {
if (
this.memoizedItemSlot !== ActorInputManager.NONE_ITEM_SLOT &&
this.memoizedItemSlot !== EActiveItemSlot.NONE &&
registry.actor.item_in_slot(this.memoizedItemSlot) !== null
) {
registry.actor.activate_slot(this.memoizedItemSlot);
}
}

this.memoizedItemSlot = ActorInputManager.NONE_ITEM_SLOT;
this.memoizedItemSlot = EActiveItemSlot.NONE;

level.show_weapon(true);
level.enable_input();
Expand All @@ -205,9 +206,9 @@ export class ActorInputManager extends AbstractCoreManager {

const slot: TIndex = actor.active_slot();

if (slot !== ActorInputManager.NONE_ITEM_SLOT) {
if (slot !== EActiveItemSlot.NONE) {
this.memoizedItemSlot = slot;
actor.activate_slot(ActorInputManager.NONE_ITEM_SLOT);
actor.activate_slot(EActiveItemSlot.NONE);
}

level.disable_input();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/managers/interface/MapDisplayManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
import { SmartTerrain, Squad } from "@/engine/core/objects";
import { parseConditionsList, pickSectionFromCondList, readIniString, TConditionList } from "@/engine/core/utils/ini";
import { LuaLogger } from "@/engine/core/utils/logging";
import { isSquadMonsterCommunity } from "@/engine/core/utils/object";
import { getAnomalyArtefacts } from "@/engine/core/utils/object/object_anomaly";
import { hasAlifeInfo } from "@/engine/core/utils/object/object_info_portion";
import { isSquadMonsterCommunity } from "@/engine/core/utils/object/object_section";
import {
ERelation,
getSquadMembersRelationToActor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import { GlobalSoundManager } from "@/engine/core/managers/sounds/GlobalSoundMan
import { Stalker } from "@/engine/core/objects";
import { abort, assert } from "@/engine/core/utils/assertion";
import { LuaLogger } from "@/engine/core/utils/logging";
import { isObjectWounded } from "@/engine/core/utils/object";
import { getInventoryNameForItemSection } from "@/engine/core/utils/object/object_spawn";
import { isObjectWounded } from "@/engine/core/utils/object/object_state";
import { captions, TCaption } from "@/engine/lib/constants/captions/captions";
import { scriptSounds } from "@/engine/lib/constants/sound/script_sounds";
import { textures, TTexture } from "@/engine/lib/constants/textures";
Expand Down
33 changes: 17 additions & 16 deletions src/engine/core/objects/animation/animations/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { finishHelpWounded } from "@/engine/core/schemes/help_wounded/utils";
import { createSequence } from "@/engine/core/utils/animation";
import { getExtern } from "@/engine/core/utils/binding";
import { startPlayingGuitar, startPlayingHarmonica } from "@/engine/core/utils/camp";
import { clearObjectAbuse, objectPunchActor } from "@/engine/core/utils/object";
import { AnyCallablesModule, ClientObject, TName } from "@/engine/lib/types";

/**
Expand Down Expand Up @@ -399,54 +400,54 @@ export const baseAnimations: LuaTable<TName, IAnimationDescriptor> = $fromObject
into: createSequence(
[
"norm_facer_0_0",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").actor_punch(...args) },
{ f: (object: ClientObject) => objectPunchActor(object) },
"norm_facer_0_1",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").clearAbuse(...args) },
{ f: (object: ClientObject) => clearObjectAbuse(object) },
],
[
"norm_facer_1_0",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").actor_punch(...args) },
{ f: (object: ClientObject) => objectPunchActor(object) },
"norm_facer_1_1",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").clearAbuse(...args) },
{ f: (object: ClientObject) => clearObjectAbuse(object) },
],
[
"norm_facer_2_0",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").actor_punch(...args) },
{ f: (object: ClientObject) => objectPunchActor(object) },
"norm_facer_2_1",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").clearAbuse(...args) },
{ f: (object: ClientObject) => clearObjectAbuse(object) },
],
[
"norm_facer_3_0",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").actor_punch(...args) },
{ f: (object: ClientObject) => objectPunchActor(object) },
"norm_facer_3_1",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").clearAbuse(...args) },
{ f: (object: ClientObject) => clearObjectAbuse(object) },
],
[
"norm_facer_4_0",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").actor_punch(...args) },
{ f: (object: ClientObject) => objectPunchActor(object) },
"norm_facer_4_1",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").clearAbuse(...args) },
{ f: (object: ClientObject) => clearObjectAbuse(object) },
],
null,
null,
null,
[
"norm_facer_8_0",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").actor_punch(...args) },
{ f: (object: ClientObject) => objectPunchActor(object) },
"norm_facer_8_1",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").clearAbuse(...args) },
{ f: (object: ClientObject) => clearObjectAbuse(object) },
],
[
"norm_facer_9_0",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").actor_punch(...args) },
{ f: (object: ClientObject) => objectPunchActor(object) },
"norm_facer_9_1",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").clearAbuse(...args) },
{ f: (object: ClientObject) => clearObjectAbuse(object) },
],
[
"norm_facer_10_0",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").actor_punch(...args) },
{ f: (object: ClientObject) => objectPunchActor(object) },
"norm_facer_10_1",
{ f: (...args: Array<any>) => getExtern<AnyCallablesModule>("xr_effects").clearAbuse(...args) },
{ f: (object: ClientObject) => clearObjectAbuse(object) },
]
),
out: null,
Expand Down
44 changes: 0 additions & 44 deletions src/engine/core/schemes/abuse/SchemeAbuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,48 +73,4 @@ export class SchemeAbuse extends AbstractScheme {
state: IRegistryObjectState,
section: TSection
): void {}

/**
* Increment abuse for object.
*/
public static addAbuse(object: ClientObject, value: TCount): void {
const abuseState: Optional<ISchemeAbuseState> = registry.objects.get(object.id())[
SchemeAbuse.SCHEME_SECTION
] as ISchemeAbuseState;

abuseState?.abuseManager.addAbuse(value);
}

/**
* Clear abuse state for object.
*/
public static clearAbuse(object: ClientObject): void {
const state: Optional<ISchemeAbuseState> = registry.objects.get(object.id())[
SchemeAbuse.SCHEME_SECTION
] as ISchemeAbuseState;

state?.abuseManager.clearAbuse();
}

/**
* Disable abuse for object.
*/
public static disableAbuse(object: ClientObject): void {
const state: Optional<ISchemeAbuseState> = registry.objects.get(object.id())[
SchemeAbuse.SCHEME_SECTION
] as ISchemeAbuseState;

state?.abuseManager.disableAbuse();
}

/**
* Enable abuse for object.
*/
public static enableAbuse(object: ClientObject): void {
const state: Optional<ISchemeAbuseState> = registry.objects.get(object.id())[
SchemeAbuse.SCHEME_SECTION
] as ISchemeAbuseState;

state?.abuseManager.enableAbuse();
}
}
52 changes: 31 additions & 21 deletions src/engine/core/schemes/meet/ISchemeMeetState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,41 @@ import type { MeetManager } from "@/engine/core/schemes/meet/MeetManager";
import type { TConditionList } from "@/engine/core/utils/ini/ini_types";
import type { Optional, TDistance, TSection } from "@/engine/lib/types";

/**
* Approximate meet distance to simplify logical checks.
*/
export enum EMeetDistance {
CLOSE = 1,
FAR = 2,
}

/**
* Scheme state representing `meet` configuration for specific object.
*/
export interface ISchemeMeetState extends IBaseSchemeState {
meetManager: MeetManager;
snd_on_use: TConditionList;
use: TConditionList;
meet_dialog: TConditionList;
abuse: TConditionList;
trade_enable: TConditionList;
allow_break: TConditionList;
meet_on_talking: TConditionList;
use_text: TConditionList;
close_distance: TConditionList;
close_anim: TConditionList;
close_snd_distance: TConditionList;
close_snd_hello: TConditionList;
close_snd_bye: TConditionList;
close_victim: TConditionList;
far_distance: TConditionList;
far_anim: TConditionList;
far_snd_distance: TConditionList;
far_snd: TConditionList;
far_victim: TConditionList;
meetSection: Optional<TSection>;
reset_distance: TDistance;
meet_only_at_path: boolean;
abuse: TConditionList;
use: TConditionList;
useText: TConditionList;
useSound: TConditionList;
meetDialog: TConditionList;
isMeetOnlyAtPathEnabled: boolean;
isTradeEnabled: TConditionList;
isBreakAllowed: TConditionList;
isMeetOnTalking: TConditionList;
// Distance to reset state.
resetDistance: TDistance;
// Distance considered close for meeting.
closeDistance: TConditionList;
closeAnimation: TConditionList;
closeSoundDistance: TConditionList;
closeSoundHello: TConditionList;
closeSoundBye: TConditionList;
closeVictim: TConditionList;
farDistance: TConditionList;
farAnimation: TConditionList;
farSoundDistance: TConditionList;
farSound: TConditionList;
farVictim: TConditionList;
}
Loading

0 comments on commit b251ac6

Please sign in to comment.