Skip to content

Commit

Permalink
fix(skymp5-client): add some client qol tweaks (#1744)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored Nov 18, 2023
1 parent 4aec267 commit b50d8a3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
22 changes: 18 additions & 4 deletions skymp5-client/src/services/services/deathService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class DeathService extends ClientListener {
this.hookDisableBlockedAnims();
}

public isBusy() {
return this.playerDead || this.busyForOtherReasonsCounter > 0;
}

private onceUpdate() {
const player = this.sp.Game.getPlayer();
player?.startDeferredKill();
Expand Down Expand Up @@ -79,6 +83,9 @@ export class DeathService extends ClientListener {

private killActor = (actor: Actor, killer: Actor | null = null): void => {
if (this.isPlayer(actor) === true) {
this.playerDead = true;
this.busyForOtherReasonsCounter++;
this.sp.Utility.wait(7.5).then(() => this.busyForOtherReasonsCounter--);
this.allowedPlayerAnimations = [];
actor.setDontMove(true);
this.killWithPush(actor);
Expand All @@ -87,22 +94,25 @@ export class DeathService extends ClientListener {
actor.kill(killer);
}
};

private resurrectActor = (actor: Actor): void => {
if (this.isPlayer(actor) === true) {
this.playerDead = false;
this.busyForOtherReasonsCounter++;
this.sp.Utility.wait(7.5).then(() => this.busyForOtherReasonsCounter--);
this.allowedPlayerAnimations = null;
actor.setDontMove(false);
this.ressurectWithPushKill(actor);
} else {
throw new RespawnNeededError("needs to be respawned");
}
};

private killWithPush = (actor: Actor): void => {
this.allowedPlayerAnimations?.push(AnimationEventName.Ragdoll);
actor.pushActorAway(actor, 0);
};

private ressurectWithPushKill = (act: Actor): void => {
const formId = act.getFormID();
const ragdollService = this.controller.lookupListener(RagdollService);
Expand All @@ -114,7 +124,7 @@ export class DeathService extends ClientListener {
this.sp.Game.getPlayer()!.setAnimationVariableInt("iGetUpType", 1);
this.sp.Debug.sendAnimationEvent(actor, AnimationEventName.GetUpBegin);
});
};
};

private isPlayer = (actor: Actor): boolean => {
return actor.getFormID() === this.playerActorId;
Expand All @@ -124,4 +134,8 @@ export class DeathService extends ClientListener {
private allowedPlayerAnimations: string[] | null = null;

private readonly playerActorId = 0x14;

private playerDead = false;

private busyForOtherReasonsCounter = 0;
}
3 changes: 2 additions & 1 deletion skymp5-client/src/services/services/remoteServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ const showConnectionError = () => {

let loggingStartMoment = 0;
on('tick', () => {
const maxLoggingDelay = 5000;
// TODO: Should be no hardcoded/magic-number limit
const maxLoggingDelay = 15000;
if (loggingStartMoment && Date.now() - loggingStartMoment > maxLoggingDelay) {
printConsole('Logging in failed. Reconnecting.');
showConnectionError();
Expand Down
48 changes: 29 additions & 19 deletions skymp5-client/src/services/services/sendInputsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { UpdateAnimationMessage } from "../messages/updateAnimationMessage";
import { UpdateEquipmentMessage } from "../messages/updateEquipmentMessage";
import { UpdateAppearanceMessage } from "../messages/updateAppearanceMessage";
import { RemoteServer } from "./remoteServer";
import { DeathService } from "./deathService";

const playerFormId = 0x14;

Expand Down Expand Up @@ -129,26 +130,35 @@ export class SendInputsService extends ClientListener {
this.prevValues.magicka === av.magicka
) {
return;
} else {
if (
currentTime - this.prevActorValuesUpdateTime < 2000 &&
this.actorValuesNeedUpdate === false
) {
return;
}
const message: MessageWithRefrId<ChangeValuesMessage> = {
t: MsgType.ChangeValues,
data: av,
_refrId
};
this.controller.emitter.emit("sendMessageWithRefrId", {
message,
reliability: "unreliable"
});
this.actorValuesNeedUpdate = false;
this.prevValues = av;
this.prevActorValuesUpdateTime = currentTime;
}


if (
currentTime - this.prevActorValuesUpdateTime < 2000 &&
this.actorValuesNeedUpdate === false
) {
return;
}

const deathService = this.controller.lookupListener(DeathService);
if (deathService.isBusy()) {
this.logTrace("Not sending actor values, death service is busy");
return;
}

const message: MessageWithRefrId<ChangeValuesMessage> = {
t: MsgType.ChangeValues,
data: av,
_refrId
};
this.controller.emitter.emit("sendMessageWithRefrId", {
message,
reliability: "unreliable"
});
this.actorValuesNeedUpdate = false;
this.prevValues = av;
this.prevActorValuesUpdateTime = currentTime;

}

private sendAnimation(_refrId?: number) {
Expand Down
3 changes: 3 additions & 0 deletions skymp5-client/src/services/services/skympClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export class SkympClient extends ClientListener {
// this.sp.browser.setFocused(false);

this.startClient();

// TODO: remove this when you will be able to see errors without console
this.sp.browser.setFocused(false);
});

authSystem.main();
Expand Down
2 changes: 1 addition & 1 deletion skymp5-client/src/sync/movementGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const getMovement = (refr: ObjectReference, form?: FormModel): Movement =
isSneaking: !!(ac && isSneaking(ac)),
isBlocking: !!(ac && ac.getAnimationVariableBool("IsBlocking")),
isWeapDrawn: !!(ac && ac.isWeaponDrawn()),
isDead: form?.isDead ?? false,
isDead: (form?.isDead ?? false) || !!(ac && ac.isDead()),
healthPercentage: healthPercentage || 0,
lookAt,
speed
Expand Down

0 comments on commit b50d8a3

Please sign in to comment.