Files
Vari 223f94a07b Fixed Catalog item Prestige reard and reward item tables and import using only the catalog item id as id, so we could not differentiate between the prestige levels.
Implemented tracking the progress of Signature challenges.

Also implemented both challenges Endpoints "getChallenges" ans "getChallengeProgressionBatch".

For "getChallenges", we just return an empty array since we dont need weekly and dailies yet.
2024-02-28 13:06:56 +01:00

40 lines
993 B
PHP

<?php
namespace App\Models\Game;
use App\Models\User\PlayerData;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @mixin IdeHelperChallenge
*/
class Challenge extends Model
{
use HasFactory, HasUuids;
protected $fillable = [
'id',
'completion_value',
'asset_path',
];
public function playerData()
{
return $this->belongsToMany(PlayerData::class)->withPivot(['progress']);
}
public function getProgressForPlayer(int $playerDataId): int
{
$foundProgress = $this->playerData()->where('id', '=', $playerDataId)->first();
if ($foundProgress !== null)
return $foundProgress->pivot->progress;
// We create challange relation and just return 0 since you cannot have progress for the challenge we just linked.
$this->playerData()->attach($playerDataId);
return 0;
}
}