diff --git a/dist/app/Console/Commands/ImportCatalog.php b/dist/app/Console/Commands/ImportCatalog.php new file mode 100644 index 0000000..e5bbfcc --- /dev/null +++ b/dist/app/Console/Commands/ImportCatalog.php @@ -0,0 +1,159 @@ +delete(); + + $catalog = json_decode(file_get_contents(resource_path('js/catalog/catalog.json')), true)['result']; + + $this->info('Strting import of Catalog items...'); + + foreach ($catalog as $item) { + $uuid = Uuid::fromHexadecimal(new Hexadecimal($item['id'])); + + $this->info('Importing Item '.$item['displayName']); + + // parse default costs + $defaultCost['CurrencyC'] = $defaultCost['CurrencyB'] = $defaultCost['CurrencyA'] = null; + foreach ($item['defaultCost'] as $cost) { + $defaultCost[$cost['currencyId']] = $cost['price']; + } + + $newItem = new CatalogItem([ + 'id' => $uuid->toString(), + 'display_name' => $item['displayName'], + 'initial_quantity' => $item['initialQuantity'], + 'consumable' => $item['consumable'], + 'default_cost_currency_a' => $defaultCost['CurrencyA'], + 'default_cost_currency_b' => $defaultCost['CurrencyB'], + 'default_cost_currency_c' => $defaultCost['CurrencyC'], + 'purchasable' => $item['purchasable'], + 'meta_min_player_level' => $item['metaData']['minPlayerLevel'], + 'meta_min_character_level' => $item['metaData']['minCharacterLevel'], + 'meta_is_unbreakable_fullset' => $item['metaData']['isUnbreakableFullset'], + 'meta_origin' => ItemOrigin::tryFrom($item['metaData']['origin']), + 'meta_quality' => ItemQuality::tryFrom($item['metaData']['quality']), + 'meta_group_type' => ItemGroupType::tryFrom($item['metaData']['groupType']), + ]); + + $newItem->save(); + } + + $this->info('Finsiehd importing items.'); + $this->info('importing Relations...'); + + foreach ($catalog as $item) { + $uuid = Uuid::fromHexadecimal(new Hexadecimal($item['id'])); + $itemModel = CatalogItem::findOrFail($uuid->toString()); + + $this->info('Processing Relations for item '.$itemModel->display_name); + + + $itemModel->addGameplayTags($item['metaData']['gameplayTags']); + $itemModel->addChallenges($item['metaData']['requiredChallengesToComplete']); + static::checkForAutoUnlockItems($item, $itemModel); + static::checkForBundleItems($item, $itemModel); + static::checkForItemAssignments($item, $itemModel); + static::checkForPrestigeRewards($item, $itemModel); + + $itemModel->save(); + } + } + + private static function checkForAutoUnlockItems(array &$rawItem, CatalogItem &$itemModel) + { + foreach ($rawItem['metaData']['autoUnlockItemIds'] as $id) { + $uuid = Uuid::fromHexadecimal(new Hexadecimal($id)); + $itemModel->autoUnlockItems()->attach($uuid->toString()); + } + } + + private static function checkForItemAssignments(array &$rawItem, CatalogItem &$itemModel) + { + foreach ($rawItem['metaData']['itemAssignments'] as $id) { + $uuid = Uuid::fromHexadecimal(new Hexadecimal($id)); + $itemModel->itemAssignments()->attach($uuid->toString()); + } + } + + private static function checkForBundleItems(array &$rawItem, CatalogItem &$item) + { + if(!array_key_exists('bundleItems', $rawItem['metaData'])) + return; + + foreach ($rawItem['metaData']['bundleItems'] as $bundleItem) { + $uuid = Uuid::fromHexadecimal(new Hexadecimal($bundleItem)); + $item->bundleItems()->attach($uuid->toString()); + $item->meta_has_bundle_items = true; + $item->has_reward_bundle_items = true; + } + } + + private static function checkForPrestigeRewards(array &$rawItem, CatalogItem &$item) + { + foreach ($rawItem['metaData']['prestigeLevelRewards'] as $prestigeReward) { + $rewards = []; + + $cost['CurrencyC'] = $cost['CurrencyB'] = $cost['CurrencyA'] = null; + foreach ($prestigeReward['costs'] as $rewardCost) { + $cost[$rewardCost['currencyId']] = $rewardCost['price']; + } + + $newPrestigeReward = PrestigeReward::create([ + 'catalog_item_id' => $item->id, + 'cost_currency_a' => $cost['CurrencyA'], + 'cost_currency_b' => $cost['CurrencyB'], + 'cost_currency_c' => $cost['CurrencyC'], + ]); + + foreach ($prestigeReward['rewards'] as $reward) { + $uuid = Uuid::fromHexadecimal(new Hexadecimal($reward['id'])); + + $newReward = 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/Enums/Game/ItemOrigin.php b/dist/app/Enums/Game/ItemOrigin.php index 60fabbe..f23f49a 100644 --- a/dist/app/Enums/Game/ItemOrigin.php +++ b/dist/app/Enums/Game/ItemOrigin.php @@ -8,7 +8,7 @@ enum ItemOrigin: string case Alienware = 'Alienware'; case Deluxe = 'Deluxe'; case DeadByDaylight = 'DeadByDaylight'; - case HeartsAndMinds = 'HeartsAndMinds'; + case HeartsAndMinds = 'HeartAndMinds'; case DeathGarden1 = 'DeathGarden1'; case Event = 'Event'; case DlcT800 = 'DlcT800'; diff --git a/dist/app/Enums/Game/ItemQuality.php b/dist/app/Enums/Game/ItemQuality.php index 830cfa1..bc693b7 100644 --- a/dist/app/Enums/Game/ItemQuality.php +++ b/dist/app/Enums/Game/ItemQuality.php @@ -14,7 +14,7 @@ enum ItemQuality: string case Prestige = 'Prestige'; // Not used in catalog, but in game struct - case Standard = 'Standart'; + case Standard = 'Standard'; case Rare = 'Rare'; case Ultra = 'Ultra'; } diff --git a/dist/app/Http/Controllers/Api/Player/PlayerController.php b/dist/app/Http/Controllers/Api/Player/PlayerController.php index c3cdcf3..6dd028b 100644 --- a/dist/app/Http/Controllers/Api/Player/PlayerController.php +++ b/dist/app/Http/Controllers/Api/Player/PlayerController.php @@ -77,6 +77,8 @@ public function initOrGetGroups(InitOrGetGroupsRequest $request) $response->MetadataGroups = [$runnerMetadata, $hunterMetadata, $playerMetadata]; } + + return json_encode($response); } } diff --git a/dist/app/Http/Responses/Api/Player/InitOrGetGroupsResponse.php b/dist/app/Http/Responses/Api/Player/InitOrGetGroupsResponse.php index c738a54..1872855 100644 --- a/dist/app/Http/Responses/Api/Player/InitOrGetGroupsResponse.php +++ b/dist/app/Http/Responses/Api/Player/InitOrGetGroupsResponse.php @@ -4,7 +4,7 @@ use App\Classes\Unreal\GameplayTag; use App\Enums\Game\Faction; -use App\Models\CharacterData as CharacterDataModel; +use App\Models\Game\CharacterData as CharacterDataModel; class InitOrGetGroupsResponse { @@ -67,7 +67,7 @@ class PlayerData { public bool $hasPlayedDeathGarden1; - public function __construct(\App\Models\PlayerData $playerData) + public function __construct(\App\Models\User\PlayerData $playerData) { $this->LastPlayedFaction = $playerData->last_faction; $this->LastPlayedRunnerId = new GameplayTag($playerData->last_runner->getTag()); diff --git a/dist/app/Models/Game/CatalogItem.php b/dist/app/Models/Game/CatalogItem.php new file mode 100644 index 0000000..69c6c2d --- /dev/null +++ b/dist/app/Models/Game/CatalogItem.php @@ -0,0 +1,161 @@ + false, + 'has_reward_bundle_items' => false, + ]; + + protected $casts = [ + 'meta_origin' => ItemOrigin::class, + 'meta_quality' => ItemQuality::class, + 'meta_group_type' => ItemGroupType::class, + ]; + + public function autoUnlockItems(): BelongsToMany + { + return $this->belongsToMany( + CatalogItem::class, + 'catalog_item_auto_unlock_items', + 'catalog_item_id', + 'unlocked_item_id', + ); + } + + public function bundleItems(): BelongsToMany { + return $this->belongsToMany( + CatalogItem::class, + 'catalog_bundle_items', + 'catalog_item_id', + 'bundle_item', + ); + } + + public function itemAssignments(): BelongsToMany + { + return $this->belongsToMany( + CatalogItem::class, + 'catalog_item_assignment', + 'catalog_item_id', + 'assigned_item_id', + ); + } + + public function prestigeRewards(): HasMany + { + return $this->hasMany( + PrestigeReward::class, + ); + } + + /** + * Adds one or multiple gameplay tags to the item. + * + * @param string|array $tags + * @return void + */ + public function addGameplayTags(string|array $tags): void + { + $table = DB::table('catalog_item_meta_gameplay_tags'); + + if(!is_array($tags)) { + $table->insertOrIgnore([ + 'catalog_item_id' => $this->id, + 'gameplay_tag' => $tags + ]); + return; + } + + foreach ($tags as $tag) { + $table->insertOrIgnore([ + 'catalog_item_id' => $this->id, + 'gameplay_tag' => $tag + ]); + } + } + + public function getGameplayTags(): array + { + $table = DB::table('catalog_item_meta_gameplay_tags'); + $tags = $table->where('catalog_item_id', '=', $this->id)->get(['gameplay_tag']); + $stringArray = []; + + foreach ($tags as $tag) { + $stringArray[] = $tag->gameplay_tag; + } + + return $stringArray; + } + + public function addChallenges(string|array $challenges): void + { + $table = DB::table('catalog_item_challenges'); + + if(!is_array($challenges)) { + $table->insertOrIgnore([ + 'catalog_item_id' => $this->id, + 'challenge_id' => $challenges + ]); + return; + } + + foreach ($challenges as $challenge) { + $table->insertOrIgnore([ + 'catalog_item_id' => $this->id, + 'challenge_id' => $challenge + ]); + } + } + + public function getChallenges(): array + { + $table = DB::table('catalog_item_challenges'); + $challenges = $table->where('catalog_item_id', '=', $this->id)->get(['challenge_id']); + $stringArray = []; + + foreach ($challenges as $challenge) { + $stringArray[] = $challenge->challenge_id; + } + + return $stringArray; + } +} diff --git a/dist/app/Models/CharacterData.php b/dist/app/Models/Game/CharacterData.php similarity index 88% rename from dist/app/Models/CharacterData.php rename to dist/app/Models/Game/CharacterData.php index e11472e..304597c 100644 --- a/dist/app/Models/CharacterData.php +++ b/dist/app/Models/Game/CharacterData.php @@ -1,9 +1,9 @@ hasMany( + PrestigeRewardItem::class, + 'prestige_reward_id', + 'catalog_item_id', + ); + } +} diff --git a/dist/app/Models/Game/PrestigeRewardItem.php b/dist/app/Models/Game/PrestigeRewardItem.php new file mode 100644 index 0000000..3fe2966 --- /dev/null +++ b/dist/app/Models/Game/PrestigeRewardItem.php @@ -0,0 +1,25 @@ +id(); - $table->foreignUuid('catalog_item_id')->constrained(); - $table->integer('amount'); - }); - Schema::create('catalog_prestige_rewards', function (Blueprint $table) { - $table->foreignUuid('catalog_item_id')->references('id')->on('catalog_items')->cascadeOnDelete()->cascadeOnUpdate(); + $table->foreignUuid('catalog_item_id')->references('id')->on('catalog_items') + ->cascadeOnDelete() + ->cascadeOnUpdate(); $table->integer('cost_currency_a')->nullable()->default(null); $table->integer('cost_currency_b')->nullable()->default(null); $table->integer('cost_currency_c')->nullable()->default(null); - $table->foreignId('prestige_reward_id')->constrained(); + }); + + 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->foreignUuid('catalog_item_id')->constrained()->cascadeOnUpdate()->cascadeOnDelete(); + $table->integer('amount'); }); } @@ -31,7 +35,7 @@ public function up(): void */ public function down(): void { - Schema::dropIfExists('catalog_prestige_rewards'); Schema::dropIfExists('prestige_rewards'); + Schema::dropIfExists('catalog_prestige_rewards'); } };