Skip to content

Commit

Permalink
Adding API support for item stats
Browse files Browse the repository at this point in the history
  • Loading branch information
thommcgrath committed Jun 19, 2024
1 parent 54a169f commit 18d8313
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
4 changes: 4 additions & 0 deletions Website/api/v4/classes/ArkSA/Engram.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Engram extends MutableBlueprint {
protected ?int $stackSize;
protected ?int $itemId;
protected ?string $gfi;
protected ?array $stats;

protected function __construct(BeaconRecordSet $row) {
parent::__construct($row);
Expand All @@ -22,6 +23,7 @@ protected function __construct(BeaconRecordSet $row) {
$this->stackSize = filter_var($row->Field('stack_size'), FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
$this->itemId = filter_var($row->Field('item_id'), FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
$this->gfi = $row->Field('gfi');
$this->stats = is_null($row->Field('stats')) ? null : json_decode($row->Field('stats'), true);

$recipe = is_null($row->Field('recipe')) ? null : json_decode($row->Field('recipe'), true);
if (is_null($recipe)) {
Expand Down Expand Up @@ -52,6 +54,7 @@ public static function BuildDatabaseSchema(): DatabaseSchema {
$schema->AddColumn(new DatabaseObjectProperty('stackSize', ['columnName' => 'stack_size', 'required' => false, 'editable' => DatabaseObjectProperty::kEditableAlways]));
$schema->AddColumn(new DatabaseObjectProperty('itemId', ['columnName' => 'item_id', 'required' => false, 'editable' => DatabaseObjectProperty::kEditableAlways]));
$schema->AddColumn(new DatabaseObjectProperty('gfi', ['required' => false, 'editable' => DatabaseObjectProperty::kEditableAlways]));
$schema->AddColumn(new DatabaseObjectProperty('stats', ['accessor' => '(SELECT array_to_json(array_agg(row_to_json(template))) FROM (SELECT stat_index AS "statIndex", randomizer_range_override AS "randomizerRangeOverride", randomizer_range_multiplier AS "randomizerRangeMultiplier", state_modifier_scale AS "stateModifierScale", rating_value_multiplier AS "rating_value_multiplier", initial_value_constant AS "initialValueConstant" FROM arksa.engram_stats WHERE engram_stats.engram_id = engrams.object_id ORDER BY stat_index) AS template)', 'required' => false, 'editable' => DatabaseObjectProperty::kEditableAlways]));
return $schema;
}

Expand Down Expand Up @@ -102,6 +105,7 @@ public function jsonSerialize(): mixed {
} else {
$json['recipe'] = $this->recipe;
}
$json['stats'] = $this->stats;
return $json;
}

Expand Down
56 changes: 36 additions & 20 deletions Website/api/v4/classes/ArkSA/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@ class Map extends DatabaseObject implements JsonSerializable {
protected string $arkIdentifier;
protected float $difficultyScale;
protected bool $isOfficial;
protected string $type;
protected int $mask;
protected int $sortOrder;
protected int $engramGroups;
protected int $lastUpdate;

public function __construct(BeaconRecordSet $row) {
$this->mapId = $row->Field('map_id');
$this->contentPackId = $row->Field('content_pack_id');
$this->label = $row->Field('label');
$this->arkIdentifier = $row->Field('ark_identifier');
$this->difficultyScale = filter_var($row->Field('difficulty_scale'), FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE) ?? 4.0;
$this->isOfficial = filter_var($row->Field('official'), FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE) ?? false;
$this->type = $row->Field('type');
$this->mask = filter_var($row->Field('mask'), FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE) ?? 0;
$this->sortOrder = filter_var($row->Field('sort'), FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE) ?? 999;
$this->engramGroups = filter_var($row->Field('engram_groups'), FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE) ?? 10;
$this->lastUpdate = round($row->Field('last_update'));
}

public static function BuildDatabaseSchema(): DatabaseSchema {
return new DatabaseSchema('arksa', 'maps', [
new DatabaseObjectProperty('mapId', ['primaryKey' => true, 'columnName' => 'map_id']),
Expand All @@ -35,25 +39,27 @@ public static function BuildDatabaseSchema(): DatabaseSchema {
new DatabaseObjectProperty('arkIdentifier', ['columnName' => 'ark_identifier']),
new DatabaseObjectProperty('difficultyScale', ['columnName' => 'difficulty_scale']),
new DatabaseObjectProperty('isOfficial', ['columnName' => 'official']),
new DatabaseObjectProperty('type'),
new DatabaseObjectProperty('mask'),
new DatabaseObjectProperty('sortOrder', ['columnName' => 'sort']),
new DatabaseObjectProperty('engramGroups', ['columnName' => 'engram_groups']),
new DatabaseObjectProperty('lastUpdate', ['columnName' => 'last_update', 'accessor' => 'EXTRACT(EPOCH FROM %%TABLE%%.%%COLUMN%%)', 'setter' => 'TO_TIMESTAMP(%%PLACEHOLDER%%)'])
]);
]);
}

protected static function BuildSearchParameters(DatabaseSearchParameters $parameters, array $filters, bool $isNested): void {
$schema = static::DatabaseSchema();
$parameters->allowAll = true;
$parameters->orderBy = $schema->Accessor('isOfficial') . ' DESC, ' . $schema->Accessor('sortOrder') . ', ' . $schema->Accessor('label');
$parameters->AddFromFilter($schema, $filters, 'arkIdentifier');
$parameters->AddFromFilter($schema, $filters, 'lastUpdate', '>');

if (isset($filters['mask'])) {
$maskProperty = $schema->Property('mask');
$parameters->clauses[] = '(' . $schema->Setter($maskProperty, $parameters->placeholder++) . ' & ' . $schema->Accessor($maskProperty) . ') = ' . $schema->Accessor($maskProperty);
$parameters->values[] = $filters['mask'];
}

if (isset($filters['contentPackId'])) {
if (BeaconCommon::IsUUID($filters['contentPackId']) === true) {
$parameters->clauses[] = $schema->Comparison('contentPackId', '=', $parameters->placeholder++);
Expand All @@ -63,48 +69,56 @@ protected static function BuildSearchParameters(DatabaseSearchParameters $parame
$parameters->values[] = $filters['contentPackId'];
}
}

public static function Fetch(string $uuid): ?static {
if (BeaconCommon::IsUUID($uuid)) {
return parent::Fetch($uuid);
}

$results = static::Search(['arkIdentifier' => $uuid], true);
if (count($results) === 1) {
return $results[0];
}

return null;
}

public function Label(): string {
return $this->label;
}

public function MapId(): string {
return $this->map_id;
}

public function Identifier(): string {
return $this->ark_identifier;
}

public function DifficultyScale(): float {
return $this->difficulty_scale;
}

public function IsOfficial(): bool {
return $this->is_official;
}


public function Type(): string {
return $this->type;
}

public function Mask(): int {
return $this->mask;
}

public function SortOrder(): int {
return $this->sort;
}


public function EngramGroups(): int {
return $this->engramGroups;
}

public function jsonSerialize(): mixed {
return [
'mapId' => $this->mapId,
Expand All @@ -113,20 +127,22 @@ public function jsonSerialize(): mixed {
'arkIdentifier' => $this->arkIdentifier,
'difficultyScale' => $this->difficultyScale,
'isOfficial' => $this->isOfficial,
'type' => $this->type,
'mask' => $this->mask,
'sortOrder' => $this->sortOrder,
'lastUpdate' => $this->lastUpdate
'engramGroups' => $this->engramGroups,
'lastUpdate' => $this->lastUpdate,
];
}

public static function CombinedMask(array $maps): int {
$combined = 0;
foreach ($maps as $map) {
$combined = ($combined | $map->Mask());
}
return $combined;
}

public static function Names(array $maps): string {
$names = [];
foreach ($maps as $map) {
Expand Down

0 comments on commit 18d8313

Please sign in to comment.