From 223f94a07b5d79fe697c9617a1712e3543be6f0f Mon Sep 17 00:00:00 2001 From: Vari Date: Wed, 28 Feb 2024 13:06:56 +0100 Subject: [PATCH] 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. --- dist/app/Console/Commands/ImportCatalog.php | 5 +- .../Api/Player/ChallengeController.php | 65 +++++++++++++++++++ .../GetChallengeProgressionBatchRequest.php | 40 ++++++++++++ .../ChallengeProgressionBatchResponse.php | 8 +++ .../Challenges/ChallengeProgressionEntry.php | 47 ++++++++++++++ dist/app/Models/Game/Challenge.php | 18 +++++ dist/app/Models/Game/PrestigeReward.php | 1 - dist/app/Models/User/PlayerData.php | 6 ++ ...create_catalog_prestige_rewards_tables.php | 8 ++- ..._154546_create_picked_challenges_table.php | 2 +- ...150_create_challenge_player_data_table.php | 30 +++++++++ dist/routes/deathgardenApi.php | 4 ++ 12 files changed, 225 insertions(+), 9 deletions(-) create mode 100644 dist/app/Http/Controllers/Api/Player/ChallengeController.php create mode 100644 dist/app/Http/Requests/Api/Player/GetChallengeProgressionBatchRequest.php create mode 100644 dist/app/Http/Responses/Api/Player/Challenges/ChallengeProgressionBatchResponse.php create mode 100644 dist/app/Http/Responses/Api/Player/Challenges/ChallengeProgressionEntry.php create mode 100644 dist/database/migrations/2024_02_28_032150_create_challenge_player_data_table.php diff --git a/dist/app/Console/Commands/ImportCatalog.php b/dist/app/Console/Commands/ImportCatalog.php index 4d9ee21..9f298ba 100644 --- a/dist/app/Console/Commands/ImportCatalog.php +++ b/dist/app/Console/Commands/ImportCatalog.php @@ -179,15 +179,12 @@ private static function checkForPrestigeRewards(array &$rawItem, CatalogItem &$i foreach ($prestigeReward['rewards'] as $reward) { $uuid = Uuid::fromHexadecimal(new Hexadecimal($reward['id'])); - $newReward = PrestigeRewardItem::create([ + $rewards[] = PrestigeRewardItem::create([ 'catalog_item_id' => $uuid->toString(), 'amount' => $reward['amount'], ]); - $newReward->save(); - $rewards[] = $newReward; } - $newPrestigeReward->save(); $newPrestigeReward->rewardItems()->saveMany($rewards); $item->prestigeRewards()->save($newPrestigeReward); diff --git a/dist/app/Http/Controllers/Api/Player/ChallengeController.php b/dist/app/Http/Controllers/Api/Player/ChallengeController.php new file mode 100644 index 0000000..fbd45fc --- /dev/null +++ b/dist/app/Http/Controllers/Api/Player/ChallengeController.php @@ -0,0 +1,65 @@ + []]); + } + + public function getProgressionBatch(GetChallengeProgressionBatchRequest $request) + { + $user = User::findOrFail($request->userId); + $playerData = $user->playerData(); + + $challengeIdsToCheck = UuidHelper::convertFromHexToUuidCollecton($request->challengeIds, true); + + /** @var Challenge[]|Collection $challengesToCheck */ + $challengesToCheck = Challenge::findMany($challengeIdsToCheck); + /** @var PickedChallenge[]|Collection $pickedChallengesToCheck */ + $pickedChallengesToCheck = PickedChallenge::findMany($challengeIdsToCheck); + + $response = new ChallengeProgressionBatchResponse(); + + foreach ($challengesToCheck as $challenge) { + $progress = $challenge->getProgressForPlayer($playerData->id); + + $newEntry = new ChallengeProgressionEntry( + Uuid::fromString($challenge->id)->getHex()->toString(), + $progress >= $challenge->completion_value, + $progress, + ); + + $response->progressionBatch[] = $newEntry; + } + + foreach ($pickedChallengesToCheck as $challenge) { + $response->progressionBatch[] = new ChallengeProgressionEntry( + Uuid::fromString($challenge->id)->getHex()->toString(), + $challenge->progress >= $challenge->completion_value, + $challenge->progress, + ); + } + + return json_encode($response); + } +} diff --git a/dist/app/Http/Requests/Api/Player/GetChallengeProgressionBatchRequest.php b/dist/app/Http/Requests/Api/Player/GetChallengeProgressionBatchRequest.php new file mode 100644 index 0000000..056ddc6 --- /dev/null +++ b/dist/app/Http/Requests/Api/Player/GetChallengeProgressionBatchRequest.php @@ -0,0 +1,40 @@ +|string> + */ + public function rules(): array + { + return [ + 'data.userId' => 'required|string', + 'data.challengeIds' => 'required|array', + ]; + } + + protected function passedValidation() + { + $this->userId = $this->input('data.userId'); + $this->challengeIds = $this->input('data.challengeIds', []); + } +} diff --git a/dist/app/Http/Responses/Api/Player/Challenges/ChallengeProgressionBatchResponse.php b/dist/app/Http/Responses/Api/Player/Challenges/ChallengeProgressionBatchResponse.php new file mode 100644 index 0000000..9007c15 --- /dev/null +++ b/dist/app/Http/Responses/Api/Player/Challenges/ChallengeProgressionBatchResponse.php @@ -0,0 +1,8 @@ +challengeId = $challengeId; + $this->completed = $completed; + $this->value = $progress; + } + + public function jsonSerialize(): mixed + { + $result = [ + 'challengeId' => $this->challengeId, + 'completed' => $this->completed, + ]; + + if($this->value === 0) + return $result; + else + $result['value'] = $this->value; + + if(!$this->completed) + return $result; + + $result['className'] = $this->className; + $result['schemaVersion'] = $this->schemaVersion; + $result['rewardsClaimed'] = $this->rewardsClaimed; + + return $result; + } +} \ No newline at end of file diff --git a/dist/app/Models/Game/Challenge.php b/dist/app/Models/Game/Challenge.php index 704363a..8b8467f 100644 --- a/dist/app/Models/Game/Challenge.php +++ b/dist/app/Models/Game/Challenge.php @@ -2,6 +2,7 @@ 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; @@ -18,4 +19,21 @@ class Challenge extends Model '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; + } } diff --git a/dist/app/Models/Game/PrestigeReward.php b/dist/app/Models/Game/PrestigeReward.php index c68dd45..b053766 100644 --- a/dist/app/Models/Game/PrestigeReward.php +++ b/dist/app/Models/Game/PrestigeReward.php @@ -30,7 +30,6 @@ public function rewardItems(): HasMany return $this->hasMany( PrestigeRewardItem::class, 'prestige_reward_id', - 'catalog_item_id', ); } } diff --git a/dist/app/Models/User/PlayerData.php b/dist/app/Models/User/PlayerData.php index 9821cb2..5954d31 100644 --- a/dist/app/Models/User/PlayerData.php +++ b/dist/app/Models/User/PlayerData.php @@ -9,6 +9,7 @@ use App\Enums\Game\Runner; use App\Helper\Uuid\UuidHelper; use App\Models\Game\CatalogItem; +use App\Models\Game\Challenge; use App\Models\Game\CharacterData; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -115,6 +116,11 @@ public function lastRunnerCharacterData(): CharacterData|Model { return $this->hasMany(CharacterData::class)->firstOrCreate($attributeValue, $attributeValue); } + public function challenges(): BelongsToMany + { + return $this->belongsToMany(Challenge::class)->withPivot(['progress']); + } + public function getCumulativeExperience(): int { $characterData = $this->characterData; diff --git a/dist/database/migrations/2024_02_17_194931_create_catalog_prestige_rewards_tables.php b/dist/database/migrations/2024_02_17_194931_create_catalog_prestige_rewards_tables.php index 8920836..56be3f8 100644 --- a/dist/database/migrations/2024_02_17_194931_create_catalog_prestige_rewards_tables.php +++ b/dist/database/migrations/2024_02_17_194931_create_catalog_prestige_rewards_tables.php @@ -12,6 +12,7 @@ public function up(): void { Schema::create('catalog_prestige_rewards', function (Blueprint $table) { + $table->id(); $table->foreignUuid('catalog_item_id')->references('id')->on('catalog_items') ->cascadeOnDelete() ->cascadeOnUpdate(); @@ -22,9 +23,10 @@ public function up(): void Schema::create('prestige_rewards', function (Blueprint $table) { $table->id(); - $table->foreignUuid('prestige_reward_id')->nullable() - ->constrained('catalog_prestige_rewards', 'catalog_item_id') - ->cascadeOnDelete()->cascadeOnUpdate(); + $table->foreignId('prestige_reward_id') + ->nullable() + ->constrained('catalog_prestige_rewards') + ->cascadeOnUpdate()->cascadeOnDelete(); $table->foreignUuid('catalog_item_id')->constrained()->cascadeOnUpdate()->cascadeOnDelete(); $table->integer('amount'); }); diff --git a/dist/database/migrations/2024_02_27_154546_create_picked_challenges_table.php b/dist/database/migrations/2024_02_27_154546_create_picked_challenges_table.php index 0fcf5eb..9fbe7af 100644 --- a/dist/database/migrations/2024_02_27_154546_create_picked_challenges_table.php +++ b/dist/database/migrations/2024_02_27_154546_create_picked_challenges_table.php @@ -14,7 +14,7 @@ public function up(): void Schema::create('picked_challenges', function (Blueprint $table) { $table->uuid('id')->unique(); $table->foreignId('character_data_id')->constrained('character_data')->cascadeOnDelete()->cascadeOnUpdate(); - $table->foreignUuid('catalog_item_id')->constrained(); + $table->foreignUuid('catalog_item_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate(); $table->string('asset_path'); $table->unsignedInteger('completion_value'); $table->unsignedInteger('progress'); diff --git a/dist/database/migrations/2024_02_28_032150_create_challenge_player_data_table.php b/dist/database/migrations/2024_02_28_032150_create_challenge_player_data_table.php new file mode 100644 index 0000000..2c68d7b --- /dev/null +++ b/dist/database/migrations/2024_02_28_032150_create_challenge_player_data_table.php @@ -0,0 +1,30 @@ +foreignUuid('challenge_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate(); + $table->foreignId('player_data_id')->constrained('player_data')->cascadeOnDelete()->cascadeOnUpdate(); + $table->unsignedInteger('progress')->default(0); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('challenge_player_data'); + } +}; diff --git a/dist/routes/deathgardenApi.php b/dist/routes/deathgardenApi.php index 2aeadc9..691b6ed 100644 --- a/dist/routes/deathgardenApi.php +++ b/dist/routes/deathgardenApi.php @@ -2,6 +2,7 @@ use App\Http\Controllers\Api\Auth\SteamAuthController; use App\Http\Controllers\Api\Eula\EulaConsentController; +use App\Http\Controllers\Api\Player\ChallengeController; use App\Http\Controllers\Api\Player\CurrencyController; use App\Http\Controllers\Api\Player\MetadataController; use App\Http\Controllers\Api\Player\ModifierCenterController; @@ -42,6 +43,9 @@ Route::post('extensions/progression/initOrGetGroups', [MetadataController::class, 'initOrGetGroups']); Route::post('extensions/progression/updateMetadataGroup', [MetadataController::class, 'updateMetadataGroup']); + Route::post('extensions/challenges/getChallengeProgressionBatch', [ChallengeController::class, 'getProgressionBatch']); + Route::post('extensions/challenges/getChallenges', [ChallengeController::class, 'getChallenges']); + Route::get('wallet/currencies', [CurrencyController::class, 'getCurrencies']); Route::get('inventories', [PlayerController::class, 'getInventory']);