UchuServer / Uchu

LEGO Universe server written in C#
GNU Affero General Public License v3.0
85 stars 20 forks source link

Fix respawning for racing #348

Closed enteryournamehere closed 1 year ago

enteryournamehere commented 1 year ago

The previous code

var playerInfo = Players.Find(info => info.Player.Id == player.Id);
playerInfo.Vehicle = car;

was broken because Players contains RacingPlayerInfo structs, which is a value type, not a reference type. This means that var playerInfo = ... results in a local copy of the data. The following line then only modifies this local copy, leaving Players unchanged.

This new code creates a local copy of the data, modifies it, and then updates the struct stored in the Players list.

enteryournamehere commented 1 year ago

Oh, good catch!

TecCheck commented 1 year ago

I made this code after all... The more I look at it, the more I want to redo the whole thing xD