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

fix: don't update kill statistics if player died of own account #242

Merged
merged 5 commits into from
Dec 2, 2021

Conversation

ujjman
Copy link
Member

@ujjman ujjman commented Oct 26, 2021

This PR is to fix issue #234

DarkWeird
DarkWeird previously approved these changes Oct 27, 2021
Copy link
Contributor

@DarkWeird DarkWeird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right.
event.investigator is NullRef when damage happens from falling.

@jdrueckert jdrueckert added Category: Crash Requests, Issues and Changes targeting unexpected terminations, segfaults, etc. Status: Needs Testing Requires to be tested in-game Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness Type: Bug Issues reporting and PRs fixing problems labels Nov 2, 2021
Copy link
Member

@jdrueckert jdrueckert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ujjman I would argue that if the player doesn't have the PlayerStatisticsComponent yet and we want to update statistics, that instead of returning without doing anything, we should create the component 🤔 or am I overlooking anything here?

@ujjman
Copy link
Member Author

ujjman commented Nov 3, 2021

I think we can update the deaths counter of the player but I think it would be unfair to do so because the player died by itself and not being killed by the other player. So what do you think?

@jdrueckert
Copy link
Member

That the player wasn't killed by a person but on their own account is a good point, but it's still a death, so is it really unfair? 🤔 I would be interested in what @skaldarnar has to say about this as we talked about not punishing players, but only rewarding them...

@jdrueckert
Copy link
Member

@ujjman Had a quick check offline with @skaldarnar and he agrees, that we should count it in the deaths statistic.

this PR is to fix the NPE when player dies by itself and not being killed by the other player
@@ -90,6 +90,9 @@ private void dropItemsFromInventory(EntityRef player) {

private void updateStatistics(EntityRef player, String type) {
PlayerStatisticsComponent playerStatisticsComponent = player.getComponent(PlayerStatisticsComponent.class);
if (player.getId() == 0) {
Copy link
Member

@jdrueckert jdrueckert Nov 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question 1: When is the player ID equal to 0 and why do we want to simply return in that case?
Question 2: What happens if a player a different ID dies on their own account but doesn't have a PlayerStatisticsComponent yet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me give a brief explanation of what I have done. So, when the player dies by itself, beforeDestroy() calls updateStatistics().

The first time updateStatistics() is called with parameter event.instigator (which will be NullRef in this case as player dies by itself, returning with EntityRef of ID=0) and "kills". So, in this case we cannot update statistics.

The Second time when updateStatistics() is called with parameter player and "deaths", we get EntityRef of the player (initially having PlayerStatisticsComponent). So, in this case we update the player's deaths.

Answer 1: Player ID=0 when event.instigator is called and player dies by itself. We return in that case because we cannot update the statistics of NullRef (also no point of updating any stats here)

Answer 2: The player gets PlayerStatisticsComponent as soon as the player gets spawned on the fool's platform

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh... so basically you're saying that we run into this NPE because in some cases updateStatistics is called with a NullRef instead of a player entity and obviously NullRef won't have the component we're trying to update?
Interesting find!

I'm wondering, whether we want to fix this here though 🤔 Ideally updateStatistics should always be called with a player entity and it also doesn't really know anything about the possible causes for being called with a NullRef (e.g. player dying without any other entity causing it). So I'd say we'd rather want to fix this in beforeDestroy and only call updateStatistics for "kills" if the event instigator of the BeforeDestroyEvent is not NullRef.

And while we're talking about this: For the spear I think this means that when the spear is thrown, we forgot who threw it by the time it hits and kills a player - hence the event instigator is NullRef and we run into the NPE 💡
With this PR fixing the NPE, I think we will see that killing a player by throwing a spear will increase their death count but not our kill count, so this is a separate bug we need to document (as a GitHub issue) and fix. Can you please create a ticket for this and (in a separate PR) investigate why we forget who threw it and how we can memorize that information?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will investigate on this issue 👍

@jdrueckert jdrueckert changed the title Update PlayerDeathSystem.java fix: don't try to update kill statistics if player died of their own account Dec 2, 2021
@jdrueckert jdrueckert changed the title fix: don't try to update kill statistics if player died of their own account fix: don't update kill statistics if player died of own account Dec 2, 2021
@jdrueckert jdrueckert merged commit 9c30f58 into Terasology:develop Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Crash Requests, Issues and Changes targeting unexpected terminations, segfaults, etc. Status: Needs Testing Requires to be tested in-game Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness Type: Bug Issues reporting and PRs fixing problems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants