75 lines
1.9 KiB
JavaScript
75 lines
1.9 KiB
JavaScript
import * as s from './stages.mjs';
|
|||
|
|
import {
|
||
|
|
Reader,
|
||
|
|
zigzag
|
||
|
|
} from './trait_effects.mjs';
|
||
|
|
const e=s.primitive;
|
||
|
|
export const COST={
|
||
|
|
1:'gold',
|
||
|
|
2:'hp'
|
||
|
|
}, RESOURCES={
|
||
|
|
1:'gold',
|
||
|
|
2:'refresh',
|
||
|
|
3:'exp',
|
||
|
|
4:'hp'
|
||
|
|
};
|
||
|
|
export function decode(raw){
|
||
|
|
const r=new Reader(raw),
|
||
|
|
rows=[],
|
||
|
|
count=Math.floor(Number(r.var())/2);
|
||
|
|
for(let i=0; i<count; i++){
|
||
|
|
const mask=BigInt(r.var()),
|
||
|
|
row={
|
||
|
|
};
|
||
|
|
if(mask&1n)row.id=r.var();
|
||
|
|
if(mask&2n)row.name={
|
||
|
|
hash:r.var(),
|
||
|
|
hash64:r.var()
|
||
|
|
};
|
||
|
|
if(mask&4n)row.amounts=Array.from({
|
||
|
|
length:Math.floor(Number(r.var())/2)
|
||
|
|
}, ()=>r.var());
|
||
|
|
if(mask&8n)row.param=r.var();
|
||
|
|
if(mask&16n)row.cost_type=zigzag(r.var());
|
||
|
|
if(mask&32n)row.price=r.var();
|
||
|
|
if(mask>>6n)e.fail('GridFightJadeUniqueTrait: unknown fields');
|
||
|
|
rows.push(row);
|
||
|
|
}
|
||
|
|
r.done('GridFightJadeUniqueTrait');
|
||
|
|
return rows;
|
||
|
|
}
|
||
|
|
export function goods(rows){
|
||
|
|
const out=[];
|
||
|
|
for(const r of rows){
|
||
|
|
const cost=COST[r.cost_type??0];
|
||
|
|
if(cost===undefined)e.fail('Jade goods '+r.id+': unknown cost type '+r.cost_type);
|
||
|
|
const param=r.param??0,
|
||
|
|
good={
|
||
|
|
id:r.id,
|
||
|
|
cost,
|
||
|
|
price:r.price??0,
|
||
|
|
param
|
||
|
|
};
|
||
|
|
if('name'in r&¶m in RESOURCES){
|
||
|
|
if((r.amounts??[]).length!==1)e.fail('Jade goods '+r.id+': resource reward needs one amount');
|
||
|
|
good.resource=RESOURCES[param];
|
||
|
|
good.amount=r.amounts[0];
|
||
|
|
}
|
||
|
|
out.push(good);
|
||
|
|
}
|
||
|
|
if(!e.uniqueValues(out, g=>g.id))e.fail('duplicate Jade goods ID');
|
||
|
|
return out;
|
||
|
|
}
|
||
|
|
export function main(){
|
||
|
|
const a=e.cli(['client'], {
|
||
|
|
output:e.resource('jade.json')
|
||
|
|
}),
|
||
|
|
[raw, proof]=new s.Assets(a.client).get('BakedConfig/ExcelOutput/GridFightJadeUniqueTrait.bytes'),
|
||
|
|
out={
|
||
|
|
goods:goods(decode(raw)),
|
||
|
|
provenance:proof
|
||
|
|
};
|
||
|
|
e.atomic_json(a.output, out, 1, true);
|
||
|
|
console.log(`${a.output}: ${out.goods.length} goods`);
|
||
|
|
}
|
||
|
|
e.runMain(import.meta.url, main);
|