Hitting !!

This commit is contained in:
2026-09-30 15:41:30 -03:00
parent 3af5f6e54b
commit 5e2b415f5c
9 changed files with 82 additions and 7 deletions
+8 -2
View File
@@ -760,6 +760,9 @@ export class GameServer {
this.#attack_entity(player, message.id);
}
break;
case "swing":
player.attack_strength_ticker = 0;
break;
case "use_item":
this.#use_item(player);
break;
@@ -841,6 +844,9 @@ export class GameServer {
// left click on an entity or another player: hurts them with the player's attack_damage and pushes them away.
// they can't be hurt again for a moment, see LivingEntity.hurt
#attack_entity(player: ServerPlayer, id: string) {
// like minecraft, any swing starts the cooldown over, hit or not. their client does the same for its indicator
const strength = player.attack_strength();
player.attack_strength_ticker = 0;
const entity = this.entities.get_entity(id) ?? this.players().find((other) => other.id === id);
if (
!(entity instanceof LivingEntity) || entity === player || !entity.alive || !player.alive ||
@@ -850,8 +856,6 @@ export class GameServer {
}
const source = { type: "physical", cause: "player_attack", attacker: player, by_player: true } as const;
// like minecraft, attacking again before the attack speed allows hits weaker
const strength = player.attack_strength();
player.attack_strength_ticker = 0;
const damage = player.attribute(ATTRIBUTES.attack_damage) * (0.2 + strength * strength * 0.8);
if (entity.hurt(damage, source)) {
player.vitals.add_exhaustion(EXHAUSTION.attack);
@@ -1576,6 +1580,8 @@ export class GameServer {
const { food, saturation } = player.vitals;
const health = player.health;
sync("vitals", [health, food, saturation], () => ({ type: "vitals", health, food, saturation }));
const attack_speed = player.attribute(ATTRIBUTES.attack_speed);
sync("attack_speed", attack_speed, () => ({ type: "attack_speed", value: attack_speed }));
if (player.screen) {
const items = player.screen.container.to_synced_data();