Skip to content

Commit 8c293d9

Browse files
committed
feat: Import clothing radiation resistance
wip: best bet for now is to rely on Description Data, as RadiationResistance is not set on every item Ref: StarCitizenWiki/scunpacked-data#18
1 parent 0c51b34 commit 8c293d9

File tree

8 files changed

+132
-0
lines changed

8 files changed

+132
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Http\Resources\SC\Char;
6+
7+
use App\Http\Resources\AbstractBaseResource;
8+
use Illuminate\Http\Request;
9+
use OpenApi\Attributes as OA;
10+
11+
#[OA\Schema(
12+
schema: 'clothing_radiation_resistance_v2',
13+
title: 'Clothing Radiation Resistance',
14+
description: 'Radiation Resistance of Clothes or Armors',
15+
properties: [
16+
new OA\Property(
17+
property: 'maximum_radiation_capacity',
18+
description: 'Radiation Protection',
19+
type: 'double',
20+
nullable: true
21+
),
22+
new OA\Property(
23+
property: 'radiation_dissipation_rate',
24+
description: 'Scrub Rate',
25+
type: 'double',
26+
nullable: true
27+
),
28+
],
29+
type: 'object'
30+
)]
31+
class ClothingRadiationResistanceResource extends AbstractBaseResource
32+
{
33+
public function toArray(Request $request): array
34+
{
35+
return [
36+
'maximum_radiation_capacity' => $this->maximum_radiation_capacity,
37+
'radiation_dissipation_rate' => $this->radiation_dissipation_rate,
38+
];
39+
}
40+
}

app/Http/Resources/SC/Char/ClothingResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function toArray(Request $request): array
8484
'damage_reduction' => $this->damage_reduction,
8585
'temp_resistance_min' => $this->temp_resistance_min,
8686
'temp_resistance_max' => $this->temp_resistance_max,
87+
'radiation_resistance' => ClothingRadiationResistanceResource::make($this->radiation_resistance),
8788
'resistances' => ClothingResistanceResource::collection($this->damageResistances),
8889
];
8990
}

app/Jobs/SC/Import/Clothing.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function handle(): void
3737
$item = $parser->getData();
3838

3939
try {
40+
/** @var \App\Models\SC\Char\Clothing\Clothing $model */
4041
$model = \App\Models\SC\Char\Clothing\Clothing::query()->withoutGlobalScopes()->where('uuid', $item['uuid'])->firstOrFail();
4142
} catch (ModelNotFoundException $e) {
4243
return;
@@ -60,5 +61,14 @@ public function handle(): void
6061
]);
6162
}
6263
}
64+
65+
if (!empty($item['radiation_resistance'])) {
66+
$model->radiationResistance()->updateOrCreate([
67+
'item_uuid' => $item['uuid'],
68+
], [
69+
'maximum_radiation_capacity' => $item['radiation_resistance']['maximum_radiation_capacity'],
70+
'radiation_dissipation_rate' => $item['radiation_resistance']['radiation_dissipation_rate'],
71+
]);
72+
}
6373
}
6474
}

app/Models/SC/Char/Clothing/Clothing.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ public function resistances(): HasMany
5353
);
5454
}
5555

56+
public function radiationResistance(): HasMany
57+
{
58+
return $this->hasMany(
59+
RadiationResistance::class,
60+
'item_uuid',
61+
'uuid',
62+
);
63+
}
64+
5665
public function damageResistances(): HasMany
5766
{
5867
return $this->resistances()->whereNotIn('type', ['temp_min', 'temp_max', 'damage_reduction']);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Models\SC\Char\Clothing;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class RadiationResistance extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $table = 'sc_clothing_radiation_resistances';
13+
14+
protected $fillable = [
15+
'item_uuid',
16+
'maximum_radiation_capacity',
17+
'radiation_dissipation_rate',
18+
];
19+
20+
protected $casts = [
21+
'maximum_radiation_capacity' => 'double',
22+
'radiation_dissipation_rate' => 'double',
23+
];
24+
}

app/Services/Parser/SC/Clothing.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function getData(): ?array
3838
'type' => trim($type),
3939
'damage_reduction' => $data['damage_reduction'] ?? null,
4040
'carrying_capacity' => $data['carrying_capacity'] ?? null,
41+
'radiation_resistance' => $this->loadRadiationResistance(),
4142
] + $this->loadResistances();
4243
}
4344

@@ -85,6 +86,16 @@ private function loadResistances(): array
8586
];
8687
}
8788

89+
private function loadRadiationResistance(): array
90+
{
91+
$radiationResistance = $this->get('SCItemClothingParams.RadiationResistance', []);
92+
93+
return [
94+
'maximum_radiation_capacity' => $radiationResistance['MaximumRadiationCapacity'] ?? null,
95+
'radiation_dissipation_rate' => $radiationResistance['RadiationDissipationRate'] ?? null,
96+
];
97+
}
98+
8899
private function getType(string $type, string $name): string
89100
{
90101
switch (true) {

app/Services/Parser/SC/Item.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public function getData(): ?array
104104
'Plaque' => 'Plaque',
105105
'Poster' => 'Poster',
106106
'Power Transfer' => 'Power Transfer',
107+
'Radiation Protection' => 'Radiation Protection',
108+
'Radiation Scrub Rate' => 'Radiation Scrub Rate',
107109
'Rate Of Fire' => 'Rate Of Fire',
108110
'Resistance' => 'Resistance',
109111
'Schematic' => 'Schematic',
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('sc_clothing_radiation_resistances', static function (Blueprint $table) {
15+
$table->id();
16+
$table->uuid('item_uuid');
17+
$table->double('maximum_radiation_capacity')->nullable();
18+
$table->double('radiation_dissipation_rate')->nullable();
19+
$table->timestamps();
20+
21+
$table->foreign('item_uuid', 'fk_sc_c_r_res_item_uuid')
22+
->references('uuid')
23+
->on('sc_items')
24+
->onDelete('cascade');
25+
});
26+
}
27+
28+
/**
29+
* Reverse the migrations.
30+
*/
31+
public function down(): void
32+
{
33+
Schema::dropIfExists('sc_clothing_radiation_resistances');
34+
}
35+
};

0 commit comments

Comments
 (0)