Skip to content

Commit

Permalink
Synchronize Damage Feature
Browse files Browse the repository at this point in the history
- Added a new config synchronize_damage, when set to "yes", the client will display the damage of normal monster attacks at the exact time it is applied on the server, removing position lag (fixes #259)
  • Loading branch information
Playtester committed May 4, 2024
1 parent e89d89e commit 82afe60
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions conf/battle/client.conf
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,9 @@ macro_detection_punishment: 0
// Amount of time in minutes that the punishment type is active for. Use 0 for infinite.
// Official: 0
macro_detection_punishment_time: 0

// Should the damage timing be synchronized between the client and server?
// This is not official behavior, but it removes the position lag after being hit.
// Right now it only works for being hit by normal monster attacks.
// Tired of Dark Illusion hitting you 5 seconds too late? Then turn this on. (Note 1)
synchronize_damage: no
10 changes: 9 additions & 1 deletion src/map/battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,14 @@ int battle_delay_damage(t_tick tick, int amotion, struct block_list *src, struct
dat->additional_effects = additional_effects;
dat->src_type = src->type;
dat->isspdamage = isspdamage;
if (src->type != BL_PC && amotion > 1000)
if (skill_id == 0 && src->type == BL_MOB && battle_config.synchronize_damage) {
mob_data* md = BL_CAST(BL_MOB, src);
// The client refuses to display animations slower than 1x speed
// So we need to shorten AttackMotion to be in-sync with the client in this case
if (amotion > md->status.clientamotion)
amotion = md->status.clientamotion;
}
else if (src->type != BL_PC && amotion > 1000)
amotion = 1000; //Aegis places a damage-delay cap of 1 sec to non player attacks. [Skotlex]

if( src->type == BL_PC )
Expand Down Expand Up @@ -11461,6 +11468,7 @@ static const struct _battle_data {
#else
{ "feature.instance_allow_reconnect", &battle_config.instance_allow_reconnect, 0, 0, 1, },
#endif
{ "synchronize_damage", &battle_config.synchronize_damage, 0, 0, 1, },

#include <custom/battle_config_init.inc>
};
Expand Down
1 change: 1 addition & 0 deletions src/map/battle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ struct Battle_Config
int feature_stylist;
int feature_banking_state_enforce;
int instance_allow_reconnect;
int synchronize_damage;

#include <custom/battle_config_struct.inc>
};
Expand Down
7 changes: 7 additions & 0 deletions src/map/clif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5242,6 +5242,13 @@ int clif_damage(struct block_list* src, struct block_list* dst, t_tick tick, int
}
}

// Calculate what sdelay to send to the client so it applies damage at the same time as the server
if (src->type == BL_MOB && battle_config.synchronize_damage) {
mob_data* md = BL_CAST(BL_MOB, src);
// The client only accepts values between 0 and 432; 432 stands for 1x animation speed
sdelay = sdelay * 432 / md->status.clientamotion;
}

WBUFW(buf,0) = cmd;
WBUFL(buf,2) = src->id;
WBUFL(buf,6) = dst->id;
Expand Down

0 comments on commit 82afe60

Please sign in to comment.