Skip to content

Commit

Permalink
Fix crash on object hit effect.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neloreck committed Jun 20, 2023
1 parent 38f041d commit 270f847
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 54 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ Optimizations, quality and logics updates are welcome.

- [NodeJS](https://nodejs.org/en/) 14 or later
- [Stalker-COP](https://store.steampowered.com/app/41700/STALKER_Call_of_Pripyat/) game
- `cli/config.json` file should be edited to match your system paths

## 💿 Start development

- DOWNLOAD [the game](https://store.steampowered.com/app/41700/STALKER_Call_of_Pripyat/)
- RUN `git clone https://github.com/xray-forge/stalker-xrf-template.git` - clone repository
- RUN `cd stalker-xrf-template` - cd to project folder
- EDIT `cli/config.json` - correct paths to match your local system (game path, logs path, resources path)
- RUN `npm install` - install all the dependencies
- RUN `npm run setup` - set up the project, install submodules
- RUN `npm run cli link` - link gamedata to the game folder
Expand Down
90 changes: 38 additions & 52 deletions src/engine/scripts/declarations/effects/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ISchemeCombatState } from "@/engine/core/schemes/combat";
import { ISchemeCombatIgnoreState } from "@/engine/core/schemes/combat_ignore";
import { ISchemeMobCombatState } from "@/engine/core/schemes/mob_combat";
import { initTarget } from "@/engine/core/schemes/remark/actions";
import { abort, assertDefined } from "@/engine/core/utils/assertion";
import { abort, assert, assertDefined } from "@/engine/core/utils/assertion";
import { extern } from "@/engine/core/utils/binding";
import { pickSectionFromCondList } from "@/engine/core/utils/ini/config";
import { parseConditionsList } from "@/engine/core/utils/ini/parse";
Expand Down Expand Up @@ -119,71 +119,57 @@ extern(
);

/**
* todo;
* Hit target from name of actor.
* Usually used to become enemies based on hit.
*/
extern("xr_effects.hit_npc_from_actor", (actor: ClientObject, npc: ClientObject, p: [Optional<TStringId>]): void => {
const h: hit = new hit();
let storyObject: Optional<ClientObject> = null;

h.draftsman = actor;
h.type = hit.wound;

if (p[0]) {
storyObject = getObjectByStoryId(p[0]);
extern(
"xr_effects.hit_npc_from_actor",
(actor: ClientObject, object: ClientObject, [storyId]: [Optional<TStringId>] = [null]): void => {
const hitObject: Hit = new hit();
const target: ClientObject = storyId ? (getObjectByStoryId(storyId) as ClientObject) : object;

if (storyObject) {
h.direction = actor.position().sub(storyObject.position());
}
hitObject.direction = actor.position().sub(target.position());
hitObject.draftsman = actor;
hitObject.type = hit.wound;
hitObject.power = 0.001;
hitObject.impulse = 0.001;
hitObject.bone("bip01_spine");

if (!storyObject) {
h.direction = actor.position().sub(npc.position());
}
} else {
h.direction = actor.position().sub(npc.position());
storyObject = npc;
target.hit(hitObject);
}

h.bone("bip01_spine");
h.power = 0.001;
h.impulse = 0.001;

storyObject!.hit(h);
});
);

/**
* todo;
* Make objects enemies.
* Hit object or second parameter story ID from name of first story ID parameter.
*/
extern("xr_effects.make_enemy", (actor: ClientObject, npc: ClientObject, p: [string, string]) => {
if (p === null) {
abort("Invalid parameter in function 'hit_npc_from_npc'!!!!");
}
extern(
"xr_effects.make_enemy",
(actor: ClientObject, object: ClientObject, parameters: [TStringId, Optional<TStringId>]): void => {
assert(parameters, "Invalid parameter in function 'hit_npc_from_npc'.");

const h: Hit = new hit();
let objectToHit: ClientObject = npc;
const [from, to] = parameters;

h.draftsman = getObjectByStoryId(p[0]);
const target: ClientObject = to ? (getObjectByStoryId(to) as ClientObject) : object;
const hitObject: Hit = new hit();

if (p[1] !== null) {
objectToHit = getObjectByStoryId(p[1])!;
}
hitObject.draftsman = getObjectByStoryId(from);

h.type = hit.wound;
h.direction = h.draftsman!.position().sub(objectToHit.position());
h.bone("bip01_spine");
h.power = 0.03;
h.impulse = 0.03;
objectToHit.hit(h);
});
hitObject.type = hit.wound;
hitObject.direction = hitObject.draftsman!.position().sub(target.position());
hitObject.bone("bip01_spine");
hitObject.power = 0.03;
hitObject.impulse = 0.03;

target.hit(hitObject);
}
);

/**
* todo;
* Set sniper fire mode for an object.
*/
extern("xr_effects.sniper_fire_mode", (actor: ClientObject, npc: ClientObject, p: [string]): void => {
if (p[0] === TRUE) {
npc.sniper_fire_mode(true);
} else {
npc.sniper_fire_mode(false);
}
extern("xr_effects.sniper_fire_mode", (actor: ClientObject, object: ClientObject, parameters: [string]): void => {
object.sniper_fire_mode(parameters[0] === TRUE);
});

/**
Expand Down

0 comments on commit 270f847

Please sign in to comment.