FakeFishGames / Barotrauma

A 2D online multiplayer game taking place in a submarine travelling through the icy depths of Jupiter's moon Europa.
http://www.barotraumagame.com/
1.73k stars 403 forks source link

Possible Logical Error in Lines 768-773 in "CharacterInfo.cs": Empty Ragdoll String affecting Personality Trait #8042

Closed TheSurvivalist395 closed 2 years ago

TheSurvivalist395 commented 2 years ago

https://github.com/Regalis11/Barotrauma/blob/d9baeaa2e12618380169dc3d8e3b4161653a9a97/Barotrauma/BarotraumaShared/SharedSource/Characters/CharacterInfo.cs#L768-L773

I think I identified a minor logical error in Lines 768-773.

Personality traits keep changing for saved characters (specifically my saved character) in my Mutliplayer Campaigns every time a session begins. I think I know what's causing this.

Line 769 says ragdollFileName = infoElement.GetAttributeString("ragdoll", string.Empty);. Line 770 says if (!string.IsNullOrEmpty(personalityName)).

I believe Line 769 is actually affecting Line 770 (or vice versa), which explains why personality traits keep randomizing every session, even among saved characters, hence Lines 771-773:

{ personalityTrait = NPCPersonalityTrait.List.Find(p => p.Name == personalityName); }

Since ("ragdoll", string.Empty) is right above if (!string.IsNullOrEmpty(personalityName)), and "ragdoll" is always an empty string, it means that Lines 771-773 will always happen and reset your character's personality type, regardless of what it says on the Campaign_CharacterData.xml.

When I replaced the ragdoll="" line in the Campaign_CharacterData.xml to ragdoll="HumanDefaultRagdoll", my character started having more consistent personality traits. It wasn't perfect (my character's personality trait would always be "Professional" on the first session), but after I saved&quit and reloaded the campaign, my personality trait would always return to "Laid-Back" (which was my character's default personality).

I'd still like to be able to change my character's personality trait directly from the Campaign_CharacterData.xml (I changed it to personality="Tough", but it does nothing to change my trait in-game), but I'll be satisfied with consistent personality traits for multiplayer characters.

Sorry, I should have clarified: What I meant to say is I think if (string.IsNullOrEmpty(personalityName)) is registering ragdollFileName = infoElement.GetAttributeString("ragdoll", string.Empty); as an Empty Personality String, causing it to reset multiplayer character's personality traits.

Jade-Harleyy commented 2 years ago

But isn't the IsNullOrEmpty checking personalityName and not ragdollFileName? So ragdollFileName shouldn't matter in this case.

Additionally, the string.IsNullOrEmpty check has a negator before the method, so it is checking if the string is NOT null or empty, which I believe is the actual problem here. Either that or the personality variable possibly being empty aswell.

Also, if I had to guess, changing the ragdoll variable and it suddenly fixing your problems would be placebo, and the save resetting the personality variable would be steam cloud saving overwriting your save file.

Regalis11 commented 2 years ago

Duplicate of https://github.com/Regalis11/Barotrauma/issues/7626

But isn't the IsNullOrEmpty checking personalityName and not ragdollFileName? So ragdollFileName shouldn't matter in this case.

That's indeed the case: the ragdoll fileName doesn't affect the personality trait in any way here.

Additionally, the string.IsNullOrEmpty check has a negator before the method, so it is checking if the string is NOT null or empty, which I believe is the actual problem here.

That's not the problem: that line tries to find the appropriate PersonalityTrait instance based on the string in the xml file, and only does that if the string is present in the xml (if it's not null or empty).

This seemed to have happened because the server never communicated the personality trait to the clients. The server did load the trait correctly from the xml file, but the clients would rely on the data received from the server, and since it didn't contain the personality trait, the characters would keep the initially assigned random trait client-side.

TheSurvivalist395 commented 2 years ago

The server did load the trait correctly from the xml file, but the clients would rely on the data received from the server, and since it didn't contain the personality trait, the characters would keep the initially assigned random trait client-side.

Is there anything I can do to get my server to send clients (including myself, as I host directly from the game instead of a dedicated server) the data containing personality traits?