Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ninj1337
Copy link
Contributor

@ninj1337 ninj1337 commented Jan 6, 2025

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 from NotifyDamagedRPC, 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 new Character.CustomDamageReceivedEnabled and Character.CustomDamageReceived fields (which mirror the Character.CustomDamageEnabled and Character.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.

@@ -38,6 +38,8 @@ public string Name {
public bool Dead;
public bool CustomDamageEnabled;
public int CustomDamage;
public bool CustomDamageReceivedEnabled;
Copy link
Contributor Author

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)
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.

@AutumnThyme AutumnThyme requested a review from rc174945 January 6, 2025 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant