Skip to content

Commit

Permalink
feat: Import SWeaponModifierComponentParams
Browse files Browse the repository at this point in the history
In reference to #106
  • Loading branch information
octfx committed Mar 9, 2024
1 parent 3277158 commit d4c848f
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 13 deletions.
4 changes: 4 additions & 0 deletions app/Http/Resources/SC/Item/ItemResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
new OA\Property(property: 'power', ref: '#/components/schemas/item_power_data_v2', nullable: true),
new OA\Property(property: 'distortion', ref: '#/components/schemas/item_distortion_data_v2', nullable: true),
new OA\Property(property: 'durability', ref: '#/components/schemas/item_durability_data_v2', nullable: true),
new OA\Property(property: 'weapon_modifier', ref: '#/components/schemas/item_weapon_modifier_data_v2', nullable: true),
new OA\Property(property: 'shops', ref: '#/components/schemas/shop_v2', nullable: true),
new OA\Property(property: 'base_variant', ref: '#/components/schemas/item_link_v2', nullable: true),
new OA\Property(
Expand Down Expand Up @@ -216,6 +217,9 @@ public function toArray(Request $request): array
$this->mergeWhen(! $this->onlySimpleData && $this->relationLoaded('durabilityData'), [
'durability' => new ItemDurabilityDataResource($this->durabilityData),
]),
$this->mergeWhen($this->type === 'WeaponAttachment', [
'weapon_modifier' => new ItemWeaponModifierDataResource($this->weaponModifierData),
]),
'shops' => ShopResource::collection($this->whenLoaded('shops')),
$this->mergeWhen($this->base_id !== null, [
'base_variant' => new ItemLinkResource($this->baseVariant),
Expand Down
135 changes: 135 additions & 0 deletions app/Http/Resources/SC/Item/ItemWeaponModifierDataResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources\SC\Item;

use App\Http\Resources\AbstractBaseResource;
use Illuminate\Http\Request;
use OpenApi\Attributes as OA;

#[OA\Schema(
schema: 'item_weapon_modifier_data_v2',
title: 'Item Weapon Modifier Data',
description: 'The complete SWeaponModifierComponentParams output',
properties: [
new OA\Property(property: 'fire_rate_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'damage_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'damage_over_time_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'projectile_speed_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'ammo_cost_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'heat_generation_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'sound_radius_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'charge_time_multiplier', type: 'double', nullable: true),
new OA\Property(
property: 'recoil',
type: 'array',
items: new OA\Items(
properties: [
new OA\Property(property: 'decay_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'end_decay_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'fire_recoil_time_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'fire_recoil_strength_first_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'fire_recoil_strength_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'angle_recoil_strength_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'randomness_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'randomness_back_push_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'frontal_oscillation_rotation_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'frontal_oscillation_strength_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'frontal_oscillation_decay_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'frontal_oscillation_randomness_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'animated_recoil_multiplier', type: 'double', nullable: true),
]
), nullable: true
),
new OA\Property(
property: 'spread',
type: 'array',
items: new OA\Items(
properties: [
new OA\Property(property: 'min_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'max_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'first_attack_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'attack_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'decay_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'additive_modifier', type: 'double', nullable: true),
]
), nullable: true
),
new OA\Property(
property: 'aim',
type: 'array',
items: new OA\Items(
properties: [
new OA\Property(property: 'zoom_scale', type: 'double', nullable: true),
new OA\Property(property: 'zoom_time_scale', type: 'double', nullable: true),
]
), nullable: true
),
new OA\Property(
property: 'slavage',
type: 'array',
items: new OA\Items(
properties: [
new OA\Property(property: 'radius_multiplier', type: 'double', nullable: true),
new OA\Property(property: 'extraction_efficiency', type: 'double', nullable: true),
new OA\Property(property: 'speed_multiplier', type: 'double', nullable: true),
]
), nullable: true
),


],
type: 'object'
)]
class ItemWeaponModifierDataResource extends AbstractBaseResource
{
/**
* Transform the resource collection into an array.
*/
public function toArray(Request $request): array
{
return [
'fire_rate_multiplier' => $this->fire_rate_multiplier,
'damage_multiplier' => $this->damage_multiplier,
'damage_over_time_multiplier' => $this->damage_over_time_multiplier,
'projectile_speed_multiplier' => $this->projectile_speed_multiplier,
'ammo_cost_multiplier' => $this->ammo_cost_multiplier,
'heat_generation_multiplier' => $this->heat_generation_multiplier,
'sound_radius_multiplier' => $this->sound_radius_multiplier,
'charge_time_multiplier' => $this->charge_time_multiplier,
'recoil' => array_filter([
'decay_multiplier' => $this->recoil_decay_multiplier,
'end_decay_multiplier' => $this->recoil_end_decay_multiplier,
'fire_recoil_time_multiplier' => $this->recoil_fire_recoil_time_multiplier,
'fire_recoil_strength_first_multiplier' => $this->recoil_fire_recoil_strength_first_multiplier,
'fire_recoil_strength_multiplier' => $this->recoil_fire_recoil_strength_multiplier,
'angle_recoil_strength_multiplier' => $this->recoil_angle_recoil_strength_multiplier,
'randomness_multiplier' => $this->recoil_randomness_multiplier,
'randomness_back_push_multiplier' => $this->recoil_randomness_back_push_multiplier,
'frontal_oscillation_rotation_multiplier' => $this->recoil_frontal_oscillation_rotation_multiplier,
'frontal_oscillation_strength_multiplier' => $this->recoil_frontal_oscillation_strength_multiplier,
'frontal_oscillation_decay_multiplier' => $this->recoil_frontal_oscillation_decay_multiplier,
'frontal_oscillation_randomness_multiplier' => $this->recoil_frontal_oscillation_randomness_multiplier,
'animated_recoil_multiplier' => $this->recoil_animated_recoil_multiplier,
]),
'spread' => array_filter([
'min_multiplier' => $this->spread_min_multiplier,
'max_multiplier' => $this->spread_max_multiplier,
'first_attack_multiplier' => $this->spread_first_attack_multiplier,
'attack_multiplier' => $this->spread_attack_multiplier,
'decay_multiplier' => $this->spread_decay_multiplier,
'additive_modifier' => $this->spread_additive_modifier,
]),
'aim' => array_filter([
'zoom_scale' => $this->aim_zoom_scale,
'zoom_time_scale' => $this->aim_zoom_time_scale,
]),
'salvage' => array_filter([
'salvage_speed_multiplier' => $this->spread_salvage_speed_multiplier,
'radius_multiplier' => $this->salvage_radius_multiplier,
'extraction_efficiency' => $this->salvage_extraction_efficiency,
]),
];
}
}
1 change: 1 addition & 0 deletions app/Jobs/SC/Import/ItemSpecificationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static function createSpecification(array $itemData, string $filePath): v
break;
case $type === 'WeaponAttachment':
WeaponAttachment::dispatch($filePath);
WeaponModifier::dispatch($filePath);
break;

case $subType === 'Hacking':
Expand Down
93 changes: 93 additions & 0 deletions app/Jobs/SC/Import/WeaponModifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

declare(strict_types=1);

namespace App\Jobs\SC\Import;

use App\Models\SC\Item\ItemWeaponModifierData;
use App\Services\Parser\SC\Labels;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use JsonException;

class WeaponModifier implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;

private string $filePath;

public function __construct(string $filePath)
{
$this->filePath = $filePath;
}

/**
* Execute the job.
*/
public function handle(): void
{
$labels = (new Labels())->getData();

try {
$parser = new \App\Services\Parser\SC\WeaponModifier($this->filePath, $labels);
} catch (FileNotFoundException|JsonException $e) {
$this->fail($e);

return;
}
$data = $parser->getData();

if ($data === null) {
return;
}

/** @var ItemWeaponModifierData $model */
ItemWeaponModifierData::updateOrCreate([
'item_uuid' => $data['uuid'],
], [
'fire_rate_multiplier' => $data['fire_rate_multiplier'] ?? null,
'damage_multiplier' => $data['damage_multiplier'] ?? null,
'damage_over_time_multiplier' => $data['damage_over_time_multiplier'] ?? null,
'projectile_speed_multiplier' => $data['projectile_speed_multiplier'] ?? null,
'ammo_cost_multiplier' => $data['ammo_cost_multiplier'] ?? null,
'heat_generation_multiplier' => $data['heat_generation_multiplier'] ?? null,
'sound_radius_multiplier' => $data['sound_radius_multiplier'] ?? null,
'charge_time_multiplier' => $data['charge_time_multiplier'] ?? null,

'recoil_decay_multiplier' => $data['recoil_decay_multiplier'] ?? null,
'recoil_end_decay_multiplier' => $data['recoil_end_decay_multiplier'] ?? null,
'recoil_fire_recoil_time_multiplier' => $data['recoil_fire_recoil_time_multiplier'] ?? null,
'recoil_fire_recoil_strength_first_multiplier' => $data['recoil_fire_recoil_strength_first_multiplier'] ?? null,
'recoil_fire_recoil_strength_multiplier' => $data['recoil_fire_recoil_strength_multiplier'] ?? null,
'recoil_angle_recoil_strength_multiplier' => $data['recoil_angle_recoil_strength_multiplier'] ?? null,
'recoil_randomness_multiplier' => $data['recoil_randomness_multiplier'] ?? null,
'recoil_randomness_back_push_multiplier' => $data['recoil_randomness_back_push_multiplier'] ?? null,
'recoil_frontal_oscillation_rotation_multiplier' => $data['recoil_frontal_oscillation_rotation_multiplier'] ?? null,
'recoil_frontal_oscillation_strength_multiplier' => $data['recoil_frontal_oscillation_strength_multiplier'] ?? null,
'recoil_frontal_oscillation_decay_multiplier' => $data['recoil_frontal_oscillation_decay_multiplier'] ?? null,
'recoil_frontal_oscillation_randomness_multiplier' => $data['recoil_frontal_oscillation_randomness_multiplier'] ?? null,
'recoil_animated_recoil_multiplier' => $data['recoil_animated_recoil_multiplier'] ?? null,

'spread_min_multiplier' => $data['spread_min_multiplier'] ?? null,
'spread_max_multiplier' => $data['spread_max_multiplier'] ?? null,
'spread_first_attack_multiplier' => $data['spread_first_attack_multiplier'] ?? null,
'spread_attack_multiplier' => $data['spread_attack_multiplier'] ?? null,
'spread_decay_multiplier' => $data['spread_decay_multiplier'] ?? null,
'spread_additive_modifier' => $data['spread_additive_modifier'] ?? null,

'aim_zoom_scale' => $data['aim_zoom_scale'] ?? null,
'aim_zoom_time_scale' => $data['aim_zoom_time_scale'] ?? null,

'salvage_speed_multiplier' => $data['salvage_speed_multiplier'] ?? null,
'salvage_radius_multiplier' => $data['salvage_radius_multiplier'] ?? null,
'salvage_extraction_efficiency' => $data['salvage_extraction_efficiency'] ?? null,
]);
}
}
14 changes: 1 addition & 13 deletions app/Models/SC/CommodityItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ abstract class CommodityItem extends HasTranslations
use HasFactory;

protected $with = [
'item'
'item',
];

/**
* @return BelongsTo
*/
public function item(): BelongsTo
{
return $this->belongsTo(Item::class, 'item_uuid', 'uuid');
Expand All @@ -40,17 +37,11 @@ public function getVersionAttribute()
return $this->item?->version;
}

/**
* @return HasMany
*/
public function translations(): HasMany
{
return $this->item->translations();
}

/**
* @return HasManyThrough
*/
public function shops(): HasManyThrough
{
return $this->hasManyThrough(
Expand All @@ -63,9 +54,6 @@ public function shops(): HasManyThrough
);
}

/**
* @return HasManyThrough
*/
public function descriptionData(): HasManyThrough
{
return $this->hasManyThrough(
Expand Down
10 changes: 10 additions & 0 deletions app/Models/SC/Item/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,16 @@ public function descriptionData(): HasMany
);
}


public function weaponModifierData(): HasOne
{
return $this->hasOne(
ItemWeaponModifierData::class,
'item_uuid',
'uuid'
);
}

public function manufacturer(): HasOne
{
return $this->hasOne(Manufacturer::class, 'id', 'manufacturer_id');
Expand Down
Loading

0 comments on commit d4c848f

Please sign in to comment.