Refine Gear augments and builder levels
This commit is contained in:
@@ -145,6 +145,83 @@ if (typeof iconDefinition?.sql === 'string' && !iconDefinition.sql.includes("'sk
|
||||
await database.exec('ALTER TABLE game_data_icons_expanded RENAME TO game_data_icons');
|
||||
}
|
||||
|
||||
const gearAugmentColumns = await (await database.prepare("PRAGMA table_info('gear_tactical_augments')")).all();
|
||||
if (gearAugmentColumns.length && !gearAugmentColumns.some((column) => column.name === 'effect_type')) {
|
||||
console.log('Separating custom Gear Tactical Augments from fixed base-item percentage upgrades.');
|
||||
await database.exec('ALTER TABLE gear_tactical_augments RENAME TO gear_tactical_augments_legacy');
|
||||
await database.exec(`CREATE TABLE gear_tactical_augments (
|
||||
id TEXT PRIMARY KEY,
|
||||
gear_slot TEXT NOT NULL CHECK(gear_slot IN ('Holster', 'Gloves', 'Backpack', 'Knee Pads', 'Body Armor', 'Mask')),
|
||||
augment_slot INTEGER NOT NULL CHECK(augment_slot BETWEEN 1 AND 4),
|
||||
effect_type TEXT NOT NULL CHECK(effect_type IN ('Custom', 'Base Percentage')),
|
||||
stat_attribute_id TEXT REFERENCES stat_attributes(id),
|
||||
value REAL NOT NULL,
|
||||
unlock_cost INTEGER NOT NULL CHECK(unlock_cost >= 0),
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
UNIQUE(gear_slot, augment_slot),
|
||||
CHECK((gear_slot IN ('Backpack', 'Body Armor') AND augment_slot BETWEEN 1 AND 4) OR (gear_slot NOT IN ('Backpack', 'Body Armor') AND augment_slot BETWEEN 1 AND 3)),
|
||||
CHECK((augment_slot = 1 AND effect_type = 'Custom' AND stat_attribute_id IS NOT NULL) OR (augment_slot > 1 AND effect_type = 'Base Percentage' AND stat_attribute_id IS NULL AND value > 0))
|
||||
)`);
|
||||
await database.exec(`INSERT INTO gear_tactical_augments
|
||||
(id,gear_slot,augment_slot,effect_type,stat_attribute_id,value,unlock_cost,created_at,updated_at)
|
||||
SELECT id,gear_slot,augment_slot,
|
||||
CASE WHEN augment_slot=1 THEN 'Custom' ELSE 'Base Percentage' END,
|
||||
CASE WHEN augment_slot=1 THEN stat_attribute_id ELSE NULL END,
|
||||
CASE
|
||||
WHEN augment_slot=1 THEN value
|
||||
WHEN gear_slot IN ('Backpack','Body Armor') AND augment_slot=2 THEN 40
|
||||
WHEN gear_slot IN ('Backpack','Body Armor') AND augment_slot=3 THEN 70
|
||||
WHEN gear_slot IN ('Backpack','Body Armor') AND augment_slot=4 THEN 100
|
||||
WHEN augment_slot=2 THEN 50
|
||||
ELSE 100
|
||||
END,
|
||||
unlock_cost,created_at,updated_at
|
||||
FROM gear_tactical_augments_legacy`);
|
||||
await database.exec('DROP TABLE gear_tactical_augments_legacy');
|
||||
}
|
||||
|
||||
const tieredGearAugmentColumns = await (await database.prepare("PRAGMA table_info('gear_tactical_augments')")).all();
|
||||
if (tieredGearAugmentColumns.some((column) => column.name === 'unlock_cost')) {
|
||||
console.log('Separating Gear Tactical Augment unlock costs by item tier.');
|
||||
await database.exec('DROP TABLE IF EXISTS gear_tactical_augment_costs');
|
||||
await database.exec('ALTER TABLE gear_tactical_augments RENAME TO gear_tactical_augments_single_cost');
|
||||
await database.exec(`CREATE TABLE gear_tactical_augments (
|
||||
id TEXT PRIMARY KEY,
|
||||
gear_slot TEXT NOT NULL CHECK(gear_slot IN ('Holster', 'Gloves', 'Backpack', 'Knee Pads', 'Body Armor', 'Mask')),
|
||||
augment_slot INTEGER NOT NULL CHECK(augment_slot BETWEEN 1 AND 4),
|
||||
effect_type TEXT NOT NULL CHECK(effect_type IN ('Custom', 'Base Percentage')),
|
||||
stat_attribute_id TEXT REFERENCES stat_attributes(id),
|
||||
value REAL NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
UNIQUE(gear_slot, augment_slot),
|
||||
CHECK((gear_slot IN ('Backpack', 'Body Armor') AND augment_slot BETWEEN 1 AND 4) OR (gear_slot NOT IN ('Backpack', 'Body Armor') AND augment_slot BETWEEN 1 AND 3)),
|
||||
CHECK((augment_slot = 1 AND effect_type = 'Custom' AND stat_attribute_id IS NOT NULL) OR (augment_slot > 1 AND effect_type = 'Base Percentage' AND stat_attribute_id IS NULL AND value > 0))
|
||||
)`);
|
||||
await database.exec(`INSERT INTO gear_tactical_augments
|
||||
(id,gear_slot,augment_slot,effect_type,stat_attribute_id,value,created_at,updated_at)
|
||||
SELECT id,gear_slot,augment_slot,effect_type,stat_attribute_id,value,created_at,updated_at
|
||||
FROM gear_tactical_augments_single_cost`);
|
||||
await database.exec(`CREATE TABLE gear_tactical_augment_costs (
|
||||
augment_id TEXT NOT NULL REFERENCES gear_tactical_augments(id) ON DELETE CASCADE,
|
||||
gear_tier INTEGER NOT NULL CHECK(gear_tier BETWEEN 0 AND 2),
|
||||
unlock_cost INTEGER NOT NULL CHECK(unlock_cost >= 0),
|
||||
PRIMARY KEY(augment_id, gear_tier)
|
||||
)`);
|
||||
await database.exec(`INSERT INTO gear_tactical_augment_costs(augment_id,gear_tier,unlock_cost)
|
||||
SELECT id,0,unlock_cost FROM gear_tactical_augments_single_cost
|
||||
UNION ALL SELECT id,1,unlock_cost FROM gear_tactical_augments_single_cost
|
||||
UNION ALL SELECT id,2,unlock_cost FROM gear_tactical_augments_single_cost`);
|
||||
await database.exec('DROP TABLE gear_tactical_augments_single_cost');
|
||||
}
|
||||
|
||||
const gearColumns = await (await database.prepare("PRAGMA table_info('gear')")).all();
|
||||
if (gearColumns.some((column) => column.name === 'level')) {
|
||||
console.log('Moving Gear level from canonical ISAC data to builder-instance state.');
|
||||
await database.exec('ALTER TABLE gear DROP COLUMN level');
|
||||
}
|
||||
|
||||
console.log(`Applied ${statements.length} schema statements to ${databasePath}`);
|
||||
|
||||
if (!databaseAlreadyExisted) {
|
||||
|
||||
Reference in New Issue
Block a user