-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a way for CL to prevent/modify damage from OnCharacterDamaged
#247
base: main
Are you sure you want to change the base?
Conversation
@@ -38,6 +38,8 @@ public string Name { | |||
public bool Dead; | |||
public bool CustomDamageEnabled; | |||
public int CustomDamage; | |||
public bool CustomDamageReceivedEnabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't think too hard about these names, there is probably something clearer to call them
{ | ||
damage = CustomDamageReceived; | ||
CustomDamageReceivedEnabled = false; | ||
if (damage == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be controversial, since GetDamagedRPC
did not previously return early if damage == 0
, however, I think modifying damage to 0 from CL should have consistent results whether or not the damage was from GetHitRPC
or GetDamagedRPC
.
@@ -525,9 +544,10 @@ public void NotifyDamagedRPC(int viewId, string name, int damage, PhotonMessageI | |||
if (killer.IsMainCharacter() && CustomLogicManager.Evaluator != null && CustomLogicManager.Evaluator.DefaultAddKillScore) | |||
_inGameManager.RegisterMainCharacterDamage(this, damage); | |||
} | |||
if (CustomLogicManager.Evaluator == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PLEASE NOTE: I removed the early return here where CustomLogicManager.Evaluator == null
.
This means that the Game Feed section below will still run in that case. I assume that was an oversight since I can't see why the Game Feed shouldn't still be updated, but I just wanted to point out the potential change in behavior which is unrelated to the main changes.
Creating this as an example of one way for the Custom Logic
OnCharacterDamaged
callback to prevent damage (for the character owner only).Instead of only calling
OnCharacterDamaged
fromNotifyDamagedRPC
, we now only call it there for clients who are not the owner. For the character owner,OnCharacterDamaged
is instead called before damage is even applied. This enables these callbacks to use the newCharacter.CustomDamageReceivedEnabled
andCharacter.CustomDamageReceived
fields (which mirror theCharacter.CustomDamageEnabled
andCharacter.CustomDamage
fields) to modify received damage before it is actually applied. If the damage is modified to 0, the hit is fully cancelled; character health is not modified and other clients are not even notified of the hit.The ability to modify or cancel damage from the receiving end (rather than only from the attacking end) allows CL to modify damage using data that the attacker does not own (and therefore does not have realtime access to), such as whether or not the attacked player is invincible. Combined with
Character.CustomDamage
, it allows data owned by both clients to participate in damage calculations.