Scope admin tower to its co-op route and balance range

This commit is contained in:
Emporex committed 2026-10-11 21:34:36 +02:00
1 parent a536b698f7
commit 8777f28595
5 files changed
+44 -11

No files matched your search

+15 -3
View File
@@ -57,7 +57,7 @@ var DIFFICULTIES = [
];
function defaultBalanceConfig() {
return {schema:2,towers:JSON.parse(JSON.stringify(TOWERS)),enemies:JSON.parse(JSON.stringify(ENEMIES))};
return {schema:3,towers:JSON.parse(JSON.stringify(TOWERS)),enemies:JSON.parse(JSON.stringify(ENEMIES)),admin_tower:{range:650,cooldown:0.08}};
}
function boundedNumber(value, fallback, minimum, maximum, integer) {
var number = Number(value);
@@ -93,7 +93,12 @@ function sanitizeBalanceConfig(input) {
shieldResistance:boundedNumber(candidate.shieldResistance,base.shieldResistance,0.01,1,false)
};
});
return {schema:2,towers:towers,enemies:enemies};
var adminInput=input.admin_tower||{};
var adminTower={
range:boundedNumber(adminInput.range,defaults.admin_tower.range,80,1200,false),
cooldown:boundedNumber(adminInput.cooldown,defaults.admin_tower.cooldown,0.04,20,false)
};
return {schema:3,towers:towers,enemies:enemies,admin_tower:adminTower};
}
function readBalanceConfig(nk) {
var record = nk && typeof nk.storageRead === "function" ? readStorageRecord(nk,BALANCE_COLLECTION,BALANCE_KEY,SYSTEM_USER_ID) : null;
@@ -108,6 +113,8 @@ function readBalanceConfig(nk) {
var legacyBoss = storedConfig.enemies[5] || {};
if (Number(legacyTower.damage) === 20) config.towers[6].damage = 22;
if (Number(legacyBoss.hp) === 740) config.enemies[5].hp = 620;
}
if (Number(storedConfig.schema || 1) < 3) {
updatedAt = Date.now();
if (nk && typeof nk.storageWrite === "function") {
try { nk.storageWrite([{collection:BALANCE_COLLECTION,key:BALANCE_KEY,userId:SYSTEM_USER_ID,value:{config:config,updated_at:updatedAt},permissionRead:0,permissionWrite:0,version:record.version||"*"}]); }
@@ -574,7 +581,10 @@ function matchLeave(ctx,logger,nk,dispatcher,tick,state,presences) {
}
function parseMessage(nk,message) { try { return JSON.parse(nk.binaryToString(message.data)||"{}"); } catch (error) { return null; } }
function towerInfo(state,type) {
if (type===ADMIN_TOWER_TYPE) return {cost:0,damage:1000000,range:3000,cooldown:0.08,targetClass:"both",bothScale:1};
if (type===ADMIN_TOWER_TYPE) {
var admin=state.balance&&state.balance.admin_tower||defaultBalanceConfig().admin_tower;
return {cost:0,damage:1000000,range:admin.range,cooldown:admin.cooldown,targetClass:"both",bothScale:1};
}
return state.balance && state.balance.towers[type] || TOWERS[type];
}
function enemyInfo(state,type) { return state.balance && state.balance.enemies[type] || ENEMIES[type]; }
@@ -659,6 +669,7 @@ function spawnEnemy(state) {
state.enemies.push({id:state.nextEnemyId++,type:type,x:route[0][0],y:route[0][1],path_index:1,route_id:routeId,hp:base.hp*hullScale,max_hp:base.hp*hullScale,speed:base.speed*(1+state.wave*0.012)*(boss?0.82:1)*d.speed,reward:Math.floor((base.reward+state.wave)*(boss?4:1)*d.income),angle:0,boss:boss,shield:hasShield,shield_hp:maxShieldHp,max_shield_hp:maxShieldHp,shield_resistance:base.shieldResistance});
}
function applyDamageToEnemy(enemy,damage,towerType) {
if (towerType===ADMIN_TOWER_TYPE) { enemy.shield=false; enemy.shield_hp=0; enemy.hp=0; return; }
var applied=damage;
if (enemy.shield) {
if (towerType===1) {
@@ -688,6 +699,7 @@ function updateTowers(state,delta) {
var t=state.towers[i],tower=towerInfo(state,t.type); t.cooldown-=delta; var range=towerRange(state,t),targetIndex=-1,best=-1,bestShield=false;
for (var j=0;j<state.enemies.length;j++) {
var candidate=state.enemies[j];
if (t.type===ADMIN_TOWER_TYPE&&candidate.route_id!==(t.x<MIRROR_X?0:1)) continue;
if ((tower.targetClass==="both"||tower.targetClass===enemyInfo(state,candidate.type).category)&&distanceSquared(t.x,t.y,candidate.x,candidate.y)<=range*range) {
var p=enemyProgress(candidate),shieldPriority=t.type===1&&candidate.shield===true;
if (targetIndex<0||(shieldPriority&&!bestShield)||(shieldPriority===bestShield&&p>best)) { best=p; bestShield=shieldPriority; targetIndex=j; }