Add real-time sales automation and automatic paid repairs
Add independent toggles for auto-accept in Deals and auto-pay repairs in NOC. Save both settings and default them off for older or malformed saves. Check sales every five wall-clock seconds regardless of game speed, and show a small countdown on Accept buttons in Deals, city offers and fiber broker offers. Only sign when all requirements, locations, equipment and service capacity are ready. Trial the added demand before accepting it, protect healthy existing customers and account for booked future events. Use the existing paid repair action for affordable active incidents, including slow router reboots. Skip expired incidents, removed equipment, DDoS attacks and repairs that were already rushed. Pause both automations with the game, hidden pages and open dialogs. Translate the controls into all five supported languages and cover timing, countdowns, capacity, budgets, repair payments, persistence, mobile controls and trial rollback with deterministic tests. Chromium checks verify about five real seconds at both 0.5x and 8x game speed and exercise the supplied large save without changing the save file.
This commit is contained in:
parent
ad94833ad1
commit
abe92fe3b1
14 changed files with 388 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
|||
function newGame(name,home){
|
||||
S={v:1,name,asn:200000+Math.floor(_rand()*15000),home,day:0,cash:START_CASH,
|
||||
ltv:2,t1v:3,auV:1,seen:NETS.map(n=>n.id),spares:{},pops:{[home]:{day:0,bb:null,boost:0,down:0,routers:1,gen:false}},links:[],nni:[],transit:[],ixp:{},rs:{},peers:{},pni:[],caches:[],biz:[],offers:[],myIx:{},
|
||||
ltv:2,t1v:3,auV:1,autoSales:false,autoRepair:false,seen:NETS.map(n=>n.id),spares:{},pops:{[home]:{day:0,bb:null,boost:0,down:0,routers:1,gen:false}},links:[],nni:[],transit:[],ixp:{},rs:{},peers:{},pni:[],caches:[],biz:[],offers:[],myIx:{},
|
||||
done:{},inc:[],ev:{},priceMul:1,nextFail:45,nextEvent:40,usedNames:[],stats:{survived:0,incidents:0,peak:0},cnLic:{state:'none'},scrubs:[],scrubMode:'always',capDeal:null,won:false,lost:false,neg:0,loans:[],loanOffers:[],loanStrikes:0,inbox:{items:[],down:{},tiny:{},rep:0,bot:false,log:[],seq:0},hw:{}};
|
||||
}
|
||||
|
||||
|
|
|
|||
30
src/game/60-features/90-automation.js
Normal file
30
src/game/60-features/90-automation.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* Optional operators use the same sales and repair actions as the player. */
|
||||
const AUTO_SALES_MS=5000;
|
||||
function autoSalesSeconds(now=performance.now()){if(!S||!S.autoSales)return null;
|
||||
const left=UI.autoGame===S&&autoActive()?AUTO_SALES_MS-(now-UI.autoSalesAt):AUTO_SALES_MS;
|
||||
return Math.max(1,Math.min(AUTO_SALES_MS/1000,Math.ceil(left/1000)));}
|
||||
function autoAcceptLabel(){return tr('common.accept')+(S.autoSales?` <small data-auto-sales title="${esc(tr('automation.next_auto_check'))}">(${autoSalesSeconds()})</small>`:'');}
|
||||
function renderAutoCountdown(now=performance.now()){const n=autoSalesSeconds(now);if(UI.autoCount===n)return;UI.autoCount=n;
|
||||
for(const el of document.querySelectorAll('[data-auto-sales]'))el.textContent=n===null?'':`(${n})`;}
|
||||
function offerCustomer(o){return {id:o.id,city:o.city,city2:o.city2||null,reqs:o.reqs||[],latMax:o.latMax||null,route:BIZ_T[o.type].scenic?'scenic':BIZ_T[o.type].lat?'fast':'normal',name:o.name,type:o.type,bw:o.bw,rate:o.rate,mood:100,since:S.day,sites:o.sites||null,start:o.start,dur:o.dur,fee:o.fee,link:o.link,slots:o.slots||0,what:o.what,prov:o.prov,due:BIZ_T[o.type].cap?S.day+o.win:undefined};}
|
||||
function autoOffer(o){if(!o||!own(BIZ_T,o.type)||!(o.exp>S.day)||!(o.bw>0)||o.rate<0||!bCities(o).length||!bCities(o).every(popUp)||!reqOk(o))return null;
|
||||
const T=BIZ_T[o.type],b=offerCustomer(o);if(T.event&&(!(o.start>S.day)||!(o.dur>0)))return null;
|
||||
if(o.type==='capfib'&&S.biz.some(x=>x.type==='capfib'&&capPend(x)&&!x.link&&((x.city===o.city&&x.city2===o.city2)||(x.city===o.city2&&x.city2===o.city))))return null;
|
||||
if(T.fiber){const l=o.type==='capfib'?capFibLink(b):S.links.find(x=>x.id===o.link);if(!l)return null;b.link=l.id;
|
||||
if(!fiberOk(b)||(o.type==='wwave'&&(!(o.slots>0)||freeCh(l)<o.slots))||(o.type==='dfpair'&&!pairFree(l))||
|
||||
(o.type==='pairs'&&(!l.own||S.biz.some(x=>x.link===l.id&&['pairs','capfib','dfpair'].includes(x.type)))))return null;}
|
||||
const state=S,result=R,hot=UI.hotMap,future=S.biz.some(x=>BIZ_T[x.type].event&&x.start>S.day);
|
||||
// Trial the added demand before signing; failed trials leave the live game untouched.
|
||||
try{S={...S,biz:S.biz};
|
||||
// shortcut: future events reserve capacity together; use per-date trials if separate bookings must share capacity.
|
||||
if(future){S.biz=S.biz.map(x=>BIZ_T[x.type].event&&x.start>S.day?{...x,start:S.day}:x);compute();}
|
||||
const healthy=S.biz.filter(x=>!bizWhy(x).length);if(T.event)b.start=S.day;if(T.cap)b.live=true;S.biz=S.biz.concat(b);compute();
|
||||
return !bizWhy(b).length&&healthy.every(x=>!bizWhy(x).length)?b:null;
|
||||
}finally{S=state;R=result;UI.hotMap=hot;b.start=o.start;if(T.cap)delete b.live;}}
|
||||
function autoActive(){return !!(S&&UI.started&&!S.lost&&UI.speed&&$('modal').hidden&&document.visibilityState==='visible');}
|
||||
function automationTick(now){if(UI.autoGame!==S){UI.autoGame=S;UI.autoSalesAt=now;}
|
||||
if(!autoActive()){UI.autoSalesAt=now;return;}
|
||||
if(S.autoRepair&&S.inc.length){purgeInc();for(const i of S.inc.slice()){if(!autoActive())break;
|
||||
if(i.type!=='ddos'&&i.until>S.day&&i.cost>0&&i.cost<=S.cash&&!(i.slow&&i.rushed))ACT.fixInc({id:i.id});}}
|
||||
if(!S.autoSales||!autoActive()){UI.autoSalesAt=now;return;}if(now-UI.autoSalesAt<AUTO_SALES_MS)return;
|
||||
UI.autoSalesAt=now;for(const o of S.offers.slice()){if(!autoActive())break;ACT.accept({id:o.id,auto:true});}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue