update UpdateMetadta to set the metadata of the player iven with 'playerId'.

This commit is contained in:
Vari
2024-03-06 22:52:48 +01:00
parent c631053ce0
commit 3f9a257821
3 changed files with 26 additions and 7 deletions

View File

@@ -29,10 +29,10 @@ public function initOrGetGroups(InitOrGetGroupsRequest $request)
// if not use the current authenticated user from this session.
// This is important because the hosts requests the progression and metadata groups for the other players
// for tracking challenges and so on.
if($request->playerId !== null)
$user = User::find($request->playerId);
else
if($request->playerId === null)
$user = Auth::user();
else
$user = User::find($request->playerId);
foreach (ItemGroupType::cases() as $group) {
if ($group == ItemGroupType::None)
@@ -75,7 +75,16 @@ public function updateMetadataGroup(UpdateMetadataGroupRequest $request)
private function handleUpdateCharacterMetadata(UpdateMetadataGroupRequest &$request): string|bool
{
$user = Auth::user();
// If the request has set a player Id, use it.
// if not use the current authenticated user from this session.
// This is important because the hosts requests the progression and metadata groups for the other players
// for tracking challenges and so on.
if($request->playerId === null)
$user = Auth::user();
else
$user = User::find($request->playerId);
$characterData = $user->playerData()->characterDataForCharacter($request->group->getCharacter());
$convertedIds = UuidHelper::convertFromHexToUuidCollecton($request->metadata['equipment'], true);
@@ -127,7 +136,14 @@ private function handleUpdateCharacterMetadata(UpdateMetadataGroupRequest &$requ
private function handleUpdatePlayerMetadata(UpdateMetadataGroupRequest &$request): string|bool
{
$user = Auth::user();
// If the request has set a player Id, use it.
// if not use the current authenticated user from this session.
// This is important because the hosts requests the progression and metadata groups for the other players
// for tracking challenges and so on.
if($request->playerId === null)
$user = Auth::user();
else
$user = User::find($request->playerId);
$playerData = $user->playerData();
$playerData->last_faction = Faction::tryFrom($request->metadata['lastPlayedFaction']);