Files
mini-browser-games/touchline-manager.html
2026-08-07 15:24:36 +08:00

104 lines
42 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="description" content="完整足球经理生涯:阵容轮换、对手情报、三阶段临场指挥、训练转会、设施建设与联赛杯赛。">
<title>绿茵经理:临场冠军路</title>
<style>
:root{color-scheme:dark;--bg:#091612;--panel:#173229;--panel2:#0e241d;--line:#416c5c;--text:#f1f7ed;--muted:#a9c6b8;--gold:#ffd46e;--green:#70da98;--red:#ff747c;--blue:#73bee6}
*{box-sizing:border-box}html,body{margin:0;min-height:100%;background:radial-gradient(circle at 50% -20%,#396b4b,#091612 48%);color:var(--text);font-family:"Microsoft YaHei","PingFang SC",system-ui,sans-serif}button,textarea{font:inherit;color:inherit}.app{width:min(1280px,100%);margin:auto;padding:10px}.top{display:flex;align-items:center;justify-content:space-between;gap:10px;padding-bottom:9px;border-bottom:1px solid var(--line)}h1{margin:0;font-size:clamp(24px,3.8vw,36px)}.sub{margin-top:3px;color:var(--muted);font-size:10px;line-height:1.5}.stats{display:flex;gap:6px;flex-wrap:wrap}.stat{min-width:75px;padding:6px 9px;border:1px solid var(--line);border-radius:7px;background:#0a1a15}.stat small{display:block;color:var(--muted);font-size:8px}.stat b{color:var(--gold);font-size:16px}.tabs,.controls{display:flex;gap:5px;flex-wrap:wrap}.tabs{margin:8px 0}.btn,.tab{min-height:39px;padding:8px 10px;border:1px solid #557d6e;border-radius:7px;background:#315c4c;color:#fff;font-weight:800;cursor:pointer}.btn:hover,.tab:hover{filter:brightness(1.12)}.btn:disabled{opacity:.36;cursor:not-allowed}.btn.primary,.tab.active{border-color:var(--gold);background:var(--gold);color:#362800}.btn.red{background:#794046}.view{display:none}.view.active{display:block}.layout{display:grid;grid-template-columns:minmax(0,1fr) 310px;gap:8px}.panel{border:1px solid var(--line);border-radius:9px;background:rgba(23,50,42,.97)}.section{padding:9px}.section h2{margin:0 0 7px;font-size:17px}.side{display:flex;flex-direction:column;gap:7px}.fixture{padding:12px;border:1px solid #4c806d;border-radius:8px;background:linear-gradient(135deg,#174837,#10251f);text-align:center}.fixture .teams{display:flex;align-items:center;justify-content:space-around;font-size:34px}.fixture h3{margin:5px}.fixture p{margin:3px 0;color:var(--muted);font-size:9px}.message{min-height:42px;padding:8px;border-left:3px solid var(--gold);background:#0b1b16;font-size:9px;line-height:1.45}.events{max-height:200px;overflow:auto;font-size:9px}.events div{padding:5px;border-bottom:1px solid #ffffff10}.objective{padding:9px;border:1px solid #3e6859;border-radius:7px;background:#10251f}.objective+.objective{margin-top:6px}.objective b,.objective small{display:block}.objective small{color:var(--muted);font-size:8px;line-height:1.45}.progress{height:5px;margin-top:5px;overflow:hidden;border-radius:7px;background:#081510}.progress i{display:block;height:100%;background:var(--green)}.squad{display:grid;grid-template-columns:repeat(3,1fr);gap:6px}.player{min-width:0;padding:8px;border:1px solid #3e6859;border-radius:7px;background:#10251f;cursor:pointer}.player.starter{outline:2px solid var(--gold)}.player.injured{opacity:.55}.player header,.market-card header,.facility header{display:flex;justify-content:space-between;gap:6px}.player p,.market-card p,.facility p,.training-card p{margin:4px 0;color:var(--muted);font-size:8px;line-height:1.45}.bars{display:grid;grid-template-columns:1fr 1fr;gap:5px}.bar{height:5px;overflow:hidden;border-radius:6px;background:#081510}.bar i{display:block;height:100%;background:var(--green)}.bar.morale i{background:var(--blue)}.tactics{display:grid;grid-template-columns:repeat(3,1fr);gap:7px}.tactic-card,.training-card,.market-card,.facility{padding:9px;border:1px solid #3e6859;border-radius:7px;background:#10251f}.tactic-card h3{margin:0 0 6px;font-size:13px}.choice-row{display:flex;gap:4px;flex-wrap:wrap}.choice-row .btn{flex:1;min-width:68px}.training,.market,.facilities{display:grid;grid-template-columns:repeat(3,1fr);gap:7px}.training-card span,.market-card .avatar,.facility .icon{font-size:34px}.training-card p,.market-card p,.facility p{min-height:35px}.table{width:100%;border-collapse:collapse;font-size:9px}.table th,.table td{padding:5px;border-bottom:1px solid #ffffff12;text-align:center}.table tr.me{background:#335b47}.overlay{position:fixed;inset:0;z-index:20;display:flex;align-items:center;justify-content:center;padding:12px;background:#081411ed}.overlay.hidden{display:none}.modal{width:min(930px,100%);max-height:93vh;overflow:auto;padding:16px;border:1px solid #507a6a;border-radius:9px;background:#18332c}.modal h2{margin:0 0 4px;font-size:25px}.modal>p{color:var(--muted);font-size:10px;line-height:1.55}.clubs{display:grid;grid-template-columns:repeat(4,1fr);gap:7px}.club{text-align:left;padding:10px;border:1px solid #3e6859;border-radius:7px;background:#10251f;color:#fff;cursor:pointer}.club span{font-size:35px}.club h3{margin:5px 0}.club p{color:var(--muted);font-size:8px;line-height:1.5}.savebox{width:100%;height:125px;padding:8px;border:1px solid var(--line);background:#0b1b16;color:#fff}.live-modal{width:min(850px,100%)}.live-score{display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:12px;padding:14px;border:1px solid #4d7a69;border-radius:9px;background:linear-gradient(135deg,#164b37,#0d251d);text-align:center}.live-team span{display:block;font-size:42px}.live-team b{font-size:15px}.score{color:var(--gold);font-size:42px;font-weight:900;white-space:nowrap}.minute{color:var(--muted);font-size:10px}.phase-track{display:grid;grid-template-columns:repeat(3,1fr);gap:5px;margin:9px 0}.phase-step{padding:7px;border:1px solid #456f60;border-radius:6px;color:var(--muted);text-align:center;font-size:9px}.phase-step.done{color:#082015;background:var(--green)}.phase-step.active{color:#322400;background:var(--gold)}.live-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px}.scout-report,.live-events{padding:10px;border:1px solid #3e6859;border-radius:7px;background:#10251f}.scout-report h3,.live-events h3{margin:0 0 5px;font-size:13px}.scout-report p{margin:4px 0;color:var(--muted);font-size:9px;line-height:1.55}.live-events{max-height:180px;overflow:auto}.live-events div{padding:4px 0;border-bottom:1px solid #ffffff10;font-size:9px}.instructions{display:grid;grid-template-columns:repeat(4,1fr);gap:6px;margin-top:9px}.instruction{text-align:left;min-height:108px;padding:8px;border:1px solid #4e7768;border-radius:7px;background:#17392e;cursor:pointer}.instruction:hover{border-color:var(--gold)}.instruction span{font-size:25px}.instruction b,.instruction small{display:block}.instruction small{margin-top:3px;color:var(--muted);font-size:8px;line-height:1.35}.live-tools{display:flex;gap:6px;flex-wrap:wrap;margin-top:8px}.toast{position:fixed;left:50%;bottom:18px;z-index:40;transform:translateX(-50%);padding:8px 13px;border:1px solid var(--gold);border-radius:6px;background:#10251f;font-size:10px}
@media(max-width:850px){.layout{grid-template-columns:1fr}.side{display:grid;grid-template-columns:1fr 1fr}.side .panel:last-child{grid-column:1/-1}}
@media(max-width:580px){.app{padding:5px}.top{align-items:flex-start;flex-direction:column}.stats{width:100%}.stat{flex:1;min-width:62px}.tabs{flex-wrap:nowrap;overflow-x:auto}.tab{flex:0 0 auto;white-space:nowrap}.side{display:flex}.squad{grid-template-columns:repeat(2,1fr)}.tactics,.training,.market,.facilities{grid-template-columns:1fr}.clubs{grid-template-columns:1fr 1fr}.live-modal{padding:10px}.live-score{padding:9px}.live-team span{font-size:31px}.live-team b{font-size:11px}.score{font-size:32px}.live-grid{grid-template-columns:1fr}.instructions{grid-template-columns:repeat(2,1fr)}.instruction{min-height:94px}.live-tools{display:grid;grid-template-columns:1fr 1fr}}
</style>
</head>
<body>
<main class="app">
<header class="top"><div><h1>绿茵经理:临场冠军路</h1><div class="sub">完整联赛与杯赛、阵容轮换、对手情报、三阶段临场指挥、训练转会和俱乐部建设。</div></div><div class="stats"><div class="stat"><small>赛季</small><b id="season">第1季</b></div><div class="stat"><small>赛程</small><b id="round">1 / 21</b></div><div class="stat"><small>资金</small><b id="money">0</b></div><div class="stat"><small>声望</small><b id="rep">0</b></div><div class="stat"><small>联赛排名</small><b id="rank">--</b></div><div class="stat"><small>杯赛</small><b id="cup">进行中</b></div></div></header>
<nav class="tabs"><button class="tab active" data-view="match">比赛日</button><button class="tab" data-view="squad">一线队</button><button class="tab" data-view="tactics">阵型战术</button><button class="tab" data-view="training">训练中心</button><button class="tab" data-view="transfer">球探转会</button><button class="tab" data-view="club">俱乐部</button><button class="tab" data-view="league">积分榜</button><button class="tab" id="saveBtn">档案码</button><button class="tab" id="newBtn">新生涯</button></nav>
<section class="view active" id="matchView"><div class="layout"><section class="panel section"><div class="fixture" id="fixture"></div><div class="controls" style="justify-content:center;margin-top:9px"><button class="btn primary" id="playBtn">进入指挥席</button></div><div class="message" id="message"></div><h3>比赛事件</h3><div class="events" id="events"></div></section><aside class="side"><section class="panel section"><h3 style="margin-top:0">赛前情报</h3><div id="preview"></div></section><section class="panel section"><h3 style="margin-top:0">董事会目标</h3><div id="objectives"></div></section><section class="panel section"><h3 style="margin-top:0">近期赛果</h3><div class="events" id="results"></div></section></aside></div></section>
<section class="view" id="squadView"><div class="panel section"><h2>一线队阵容</h2><p class="sub">点击球员切换首发,右键或长按思路可在转会页出售替补。位置结构、体能、士气和伤病共同影响比赛。</p><div class="squad" id="squad"></div></div></section>
<section class="view" id="tacticsView"><div class="panel section"><h2>阵型与比赛计划</h2><div class="tactics" id="tactics"></div></div></section>
<section class="view" id="trainingView"><div class="panel section"><h2>本轮训练</h2><p class="sub">每个赛程只能安排一次训练;强度越高,成长和体能风险越明显。</p><div class="training" id="training"></div></div></section>
<section class="view" id="transferView"><div class="panel section"><h2>球探名单</h2><div class="market" id="market"></div><div class="controls" style="margin-top:9px"><button class="btn" id="scoutBtn">刷新球探名单 18资金</button><button class="btn red" id="sellBtn">出售选中替补</button></div></div></section>
<section class="view" id="clubView"><div class="panel section"><h2>俱乐部建设</h2><div class="facilities" id="facilities"></div></div></section>
<section class="view" id="leagueView"><div class="panel section"><h2>联赛积分榜</h2><table class="table"><thead><tr><th>#</th><th>球队</th><th>赛</th><th>胜</th><th>平</th><th>负</th><th>净胜</th><th>分</th></tr></thead><tbody id="league"></tbody></table></div></section>
</main>
<div class="overlay" id="startOverlay"><section class="modal"><h2>选择执教俱乐部</h2><p>四支球队的阵容倾向、预算和董事会期待不同。每场比赛都要读取对手计划并完成三段临场指挥。</p><div class="clubs" id="clubs"></div></section></div>
<div class="overlay hidden" id="infoOverlay"><section class="modal"><h2 id="infoTitle">经理档案</h2><div id="infoBody"></div><div class="controls"><button class="btn primary" id="closeInfoBtn">返回俱乐部</button></div></section></div>
<div class="overlay hidden" id="liveOverlay"><section class="modal live-modal"><h2 id="liveTitle">比赛日指挥席</h2><div class="live-score"><div class="live-team"><span id="homeIcon"></span><b id="homeName"></b></div><div><div class="score" id="liveScore">0 - 0</div><div class="minute" id="liveMinute">0'</div></div><div class="live-team"><span id="awayIcon"></span><b id="awayName"></b></div></div><div class="phase-track" id="phaseTrack"></div><div class="live-grid"><div class="scout-report" id="liveReport"></div><div class="live-events"><h3>比赛事件</h3><div id="liveEvents"></div></div></div><div class="instructions" id="instructions"></div><div class="live-tools"><button class="btn" id="autoSubBtn">自动对位换人</button><button class="btn primary" id="confirmResultBtn" hidden>确认赛果</button></div></section></div>
<script>
(()=>{"use strict";
const $=id=>document.getElementById(id),SAVE="touchlineManagerV4",LEGACY_SAVE="touchlineManagerV3";
const CLUBS={harbor:{i:"⚓",n:"港湾竞技",d:"均衡阵容与中等预算,目标进入前六。",money:150,bonus:{def:2},target:6},academy:{i:"🌱",n:"青苗联队",d:"年轻球员潜力高,预算紧张,目标前八。",money:115,bonus:{pot:5},target:8},royal:{i:"👑",n:"王冠城",d:"豪华进攻线和高期待,目标争冠。",money:210,bonus:{atk:4},target:2},forge:{i:"🛡️",n:"铁炉工人",d:"强硬防守与高体能,目标前四。",money:135,bonus:{def:5,fit:5},target:4}};
const FORMATIONS={f433:{n:"4-3-3",need:{GK:1,DF:4,MF:3,FW:3},note:"边路宽度"},f442:{n:"4-4-2",need:{GK:1,DF:4,MF:4,FW:2},note:"攻守均衡"},f352:{n:"3-5-2",need:{GK:1,DF:3,MF:5,FW:2},note:"中场人数"},f532:{n:"5-3-2",need:{GK:1,DF:5,MF:3,FW:2},note:"低位反击"}};
const TACTICS={mentality:["谨慎","均衡","进攻"],press:["低位","区域","高压"],tempo:["控球","均衡","快速"],focus:["中路","均衡","边路"]};
const INSTRUCTIONS={probe:{i:"🔍",n:"稳态试探",d:"风险低、消耗小,读取对手但不形成明显克制。",fatigue:2},press:{i:"🔥",n:"前场强压",d:"克制控球组织,提高机会也会暴露身后。",fatigue:5},control:{i:"🧭",n:"控球降速",d:"克制快速反击,同时压低双方机会。",fatigue:3},counter:{i:"⚡",n:"收缩反击",d:"克制前场强压,主动让出球权等待纵深。",fatigue:3}};
const OPPONENTS=[{n:"均衡演练",style:"probe",plan:["probe","control","press"],weak:"随局势改变"},{n:"青春风暴",style:"press",plan:["press","press","control"],weak:"连续压迫后的体能空档"},{n:"王冠控场",style:"control",plan:["control","control","press"],weak:"身后纵深与转换速度"},{n:"铁炉低墙",style:"counter",plan:["counter","control","counter"],weak:"落后时缺少主动推进"},{n:"星海边锋",style:"press",plan:["probe","press","press"],weak:"边后卫前插留下的空当"},{n:"北境长传",style:"counter",plan:["counter","press","counter"],weak:"第二落点控制"},{n:"河谷传控",style:"control",plan:["control","probe","control"],weak:"高压下的后场出球"},{n:"红杉阵地",style:"control",plan:["probe","control","counter"],weak:"推进节奏偏慢"},{n:"银翼冲刺",style:"press",plan:["press","counter","press"],weak:"高速回合后的体能"},{n:"旧港奇兵",style:"counter",plan:["probe","counter","press"],weak:"计划切换时的站位"}];
const TRAINING=[{id:"attack",i:"🎯",n:"进攻套路",d:"中前场进攻成长,体能 -8。"},{id:"defense",i:"🛡️",n:"防线协作",d:"门将后卫防守成长,体能 -7。"},{id:"fitness",i:"🏃",n:"体能恢复",d:"全队体能 +16。"},{id:"morale",i:"🤝",n:"团队建设",d:"全队士气 +12。"},{id:"youth",i:"🌟",n:"潜力训练",d:"三名 U23 球员双项成长。"},{id:"rest",i:"🛏️",n:"完全休整",d:"体能 +22,伤员恢复。"}];
const FACILITIES={stadium:{i:"🏟️",n:"主场看台",d:"主场收入与比赛优势提高。",base:100,max:4},academy:{i:"🌱",n:"青训学院",d:"球探更容易发现高潜年轻人。",base:130,max:4},medical:{i:"🏥",n:"运动医学",d:"降低伤病率并加快恢复。",base:120,max:4},scouting:{i:"🔭",n:"球探网络",d:"转会名单数量与质量提高。",base:110,max:4},training:{i:"🏋️",n:"训练基地",d:"训练成长效果提高。",base:140,max:4},commercial:{i:"📣",n:"商务中心",d:"每场比赛增加稳定收入。",base:150,max:4}};
const NAMES=["林赫","秦川","苏野","罗伊","叶锋","韩森","周岚","顾北","江驰","许明","陆航","唐溪","魏安","沈岳","白川","程风","余野","陈星","夏洛","岳青","孟凡","杜衡","段宇","宁舟","乔恩","米洛","安德","莱奥","凯文","诺亚"];
const TEAMS=[["港湾竞技","⚓"],["青苗联队","🌱"],["王冠城","👑"],["铁炉工人","🛡️"],["星海城","⭐"],["北境狼","🐺"],["河谷联","🌊"],["红杉队","🌲"],["银翼城","🪽"],["旧港FC","🚢"]];
let profile={v:4,seasons:0,trophies:0,best:10,careerRep:0,tacticalWins:0},q=null,activeView="match",selectedSell=null;
function teamFor(id,club=q?.club){if(id===0)return[CLUBS[club].n,CLUBS[club].i];return TEAMS[id][0]===CLUBS[club].n?TEAMS[0]:TEAMS[id]}
function opponentFor(id,club=q?.club){return TEAMS[id][0]===CLUBS[club].n?OPPONENTS[0]:OPPONENTS[id]}
function hash(text){let h=2166136261;for(const ch of String(text)){h^=ch.charCodeAt(0);h=Math.imul(h,16777619)}return h>>>0}
function randomAt(seed,index=0){let x=(seed+Math.imul(index+1,0x9e3779b1))>>>0;x+=0x6d2b79f5;x=Math.imul(x^x>>>15,x|1);x^=x+Math.imul(x^x>>>7,x|61);return((x^x>>>14)>>>0)/4294967296}
function clamp(value,min,max){return Math.max(min,Math.min(max,value))}
function makePlayer(i,club,market=false,seed=1){const r=n=>randomAt(seed,n),pos=i%18===0?"GK":i%18<7?"DF":i%18<13?"MF":"FW",age=18+Math.floor(r(1)*15),base=(market?54:55)+Math.floor(r(2)*(market?22:17)),bonus=CLUBS[club]?.bonus||{};return{uid:`p${seed.toString(36)}${i}`,n:NAMES[Math.floor(r(3)*NAMES.length)],pos,age,atk:Math.min(90,base+(pos==="FW"?8:pos==="MF"?3:0)+(bonus.atk||0)),def:Math.min(90,base+(pos==="DF"?8:pos==="GK"?10:0)+(bonus.def||0)),fit:Math.min(100,78+Math.floor(r(4)*22)+(bonus.fit||0)),morale:70+Math.floor(r(5)*25),pot:Math.min(95,base+8+Math.floor(r(6)*14)+(bonus.pot||0)),value:Math.round(base*.8),injured:0,form:0,trait:["领袖","快马","铁人","组织者","门前猎手","大场面"][i%6]}}
function makeSchedule(){const league=[];for(let round=0;round<18;round++)league.push({type:"league",opp:1+round%9,home:round%2===0});league.splice(5,0,{type:"cup",round:"八强",opp:4,home:true});league.splice(11,0,{type:"cup",round:"半决赛",opp:6,home:false});league.splice(18,0,{type:"cup",round:"决赛",opp:2,home:true});return league}
function makeTable(club){return TEAMS.map((_,id)=>{const team=teamFor(id,club);return{id,n:team[0],i:team[1],p:0,w:0,d:0,l:0,gf:0,ga:0,pts:0}})}
function marketFor(club,round,count,seed){return Array.from({length:count},(_,i)=>makePlayer(30+i+round*7,club,true,hash(`${seed}|market|${round}|${i}`)))}
function fresh(club){const seed=hash(`${club}|${profile.seasons+1}|touchline-v4`),players=Array.from({length:18},(_,i)=>makePlayer(i,club,false,hash(`${seed}|player|${i}`))),starterIndexes=[0,1,2,3,4,7,8,9,13,14,15];return{v:4,seed,club,season:profile.seasons+1,round:0,leagueRound:0,money:CLUBS[club].money,rep:10,players,starters:starterIndexes.map(index=>players[index].uid),formation:"f433",mentality:1,press:1,tempo:1,focus:1,trained:false,market:marketFor(club,0,5,seed),table:makeTable(club),schedule:makeSchedule(),cupAlive:true,facilities:{stadium:0,academy:0,medical:0,scouting:0,training:0,commercial:0},results:[],events:["新赛季集结,教练组完成第一份对手报告。"],message:"选择首发和战术后进入比赛日指挥席。",live:null,tacticalWins:0}}
function save(){localStorage.setItem(SAVE,JSON.stringify({v:4,profile,q}))}
function migrate(data){if(!data)return null;data.v=4;data.profile={...profile,...data.profile,v:4};if(data.q){data.q={...data.q,v:4,seed:data.q.seed||hash(`${data.q.club}|${data.q.season}|migrated`),live:data.q.live||null,tacticalWins:data.q.tacticalWins||0};data.q.players=data.q.players.map((player,index)=>({...player,uid:player.uid||`m${index}`}))}return data}
function load(){try{const data=JSON.parse(localStorage.getItem(SAVE)||localStorage.getItem(LEGACY_SAVE));if(data&&(data.v===3||data.v===4)){const migrated=migrate(data);profile=migrated.profile;q=migrated.q;save()}}catch{}}
function checksum(text){return hash(text).toString(36)}
function exportCode(){const payload=btoa(unescape(encodeURIComponent(JSON.stringify({v:4,profile,q}))));return`TM4-${payload}-${checksum(payload)}`}
function decodeCode(code){const match=String(code).trim().match(/^TM([34])-(.+)-([a-z0-9]+)$/i);if(!match||checksum(match[2])!==match[3])throw Error("档案校验失败");const data=JSON.parse(decodeURIComponent(escape(atob(match[2]))));if(![3,4].includes(data.v))throw Error("档案版本不兼容");return migrate(data)}
function importCode(code){const data=decodeCode(code);profile=data.profile;q=data.q;save();draw()}
function toast(text){const el=document.createElement("div");el.className="toast";el.textContent=text;document.body.append(el);setTimeout(()=>el.remove(),1500)}
function msg(text){q.message=text;q.events.unshift(text);q.events=q.events.slice(0,28)}
function starters(){return q.starters.map(id=>q.players.find(player=>player.uid===id)).filter(Boolean)}
function overall(player){return Math.round((player.atk+player.def)/2+player.form)}
function formationFit(list=starters()){const need=FORMATIONS[q.formation].need,have={GK:0,DF:0,MF:0,FW:0};list.forEach(player=>have[player.pos]++);return 8-Object.keys(need).reduce((sum,key)=>sum+Math.abs(need[key]-have[key])*2,0)}
function lineupPower(){const list=starters();if(list.length!==11)return 0;const average=list.reduce((sum,player)=>sum+overall(player)*(player.fit/100)*(.75+player.morale/400),0)/11;return average+formationFit(list)+q.facilities.training*.6}
function currentFixture(){return q.schedule[q.round]}
function sortedTable(){return[...q.table].sort((a,b)=>b.pts-a.pts||(b.gf-b.ga)-(a.gf-a.ga)||b.gf-a.gf)}
function toggleStarter(uid){if(q.live)return toast("比赛进行中不能修改首发");const player=q.players.find(item=>item.uid===uid);if(player.injured)return toast("伤员无法进入首发");if(q.starters.includes(uid))q.starters=q.starters.filter(id=>id!==uid);else{if(q.starters.length>=11)return toast("首发最多 11 人");q.starters.push(uid)}draw()}
function tacticBonus(opponent){let bonus=0;if(q.mentality===2&&opponent.style==="control")bonus+=2;if(q.mentality===0&&opponent.style==="press")bonus+=2;if(q.press===2&&q.tempo===2)bonus+=2;if(q.focus===2&&q.formation==="f433")bonus+=2;if(q.focus===0&&q.formation==="f352")bonus+=2;if(q.press===0&&q.formation==="f532")bonus+=2;return bonus}
function instructionMatch(player,opponent){if(player==="probe")return 0;if(player==="press"&&opponent==="control")return 3;if(player==="control"&&opponent==="counter")return 3;if(player==="counter"&&opponent==="press")return 3;if(opponent==="press"&&player==="control")return-2;if(opponent==="control"&&player==="counter")return-2;if(opponent==="counter"&&player==="press")return-2;return 0}
function phaseModel(instruction){const live=q.live,fixture=live.fixture,opponent=opponentFor(fixture.opp),opponentInstruction=opponent.plan[live.phase],seed=live.seed+live.phase*97+hash(instruction),me=lineupPower(),opp=58+fixture.opp*1.15+q.season*.8+randomAt(live.seed,40)*4,matchup=instructionMatch(instruction,opponentInstruction),tactics=tacticBonus(opponent),home=fixture.home?2+q.facilities.stadium*.7:0,fit=starters().reduce((sum,player)=>sum+player.fit,0)/11;let myXg=.34+(me+tactics+home-opp)/48+matchup*.075+live.momentum*.025+(fit-70)/500,oppXg=.30+(opp-me-tactics-home)/53-matchup*.06-live.momentum*.02;if(instruction==="press"){myXg+=.15;oppXg+=.08}if(instruction==="control"){myXg-=.06;oppXg-=.11}if(instruction==="counter"&&opponentInstruction==="press")myXg+=.12;myXg=clamp(myXg,.05,1.25);oppXg=clamp(oppXg,.04,1.15);const score=(xg,a,b)=>(randomAt(seed,a)<Math.min(.82,xg*.72)?1:0)+(randomAt(seed,b)<Math.max(0,xg-.72)*.5?1:0);return{instruction,opponentInstruction,matchup,myXg,oppXg,myGoals:score(myXg,1,2),oppGoals:score(oppXg,3,4),fatigue:INSTRUCTIONS[instruction].fatigue,me,opp}}
function beginMatch(){if(q.starters.length!==11)return toast("必须选择 11 名首发");if(starters().some(player=>player.injured))return toast("首发中有伤员");const fixture=currentFixture();if(!fixture)return endSeason();if(fixture.type==="cup"&&!q.cupAlive){q.round++;return beginMatch()}q.live={fixture:{...fixture},seed:hash(`${q.seed}|${q.round}|${fixture.opp}`),phase:0,score:[0,0],xg:[0,0],momentum:0,events:["0' 裁判鸣哨,双方按赛前计划落位。"],instructions:[],played:[...q.starters],substituted:false,successes:0,finished:false};save();renderLive();$("liveOverlay").classList.remove("hidden")}
function scorer(seed){const candidates=starters().filter(player=>player.pos!=="GK");return candidates[Math.floor(randomAt(seed,7)*candidates.length)]||starters()[0]}
function resolvePhase(instruction){if(!q.live||q.live.finished)return;const live=q.live,phase=live.phase,model=phaseModel(instruction),start=phase*30+1,end=(phase+1)*30;live.instructions.push(instruction);live.xg[0]+=model.myXg;live.xg[1]+=model.oppXg;live.score[0]+=model.myGoals;live.score[1]+=model.oppGoals;live.momentum=clamp(live.momentum+(model.matchup>0?1:model.matchup<0?-1:0)+(model.myGoals-model.oppGoals)*.7,-2,2);if(model.matchup>0){live.successes++;live.events.unshift(`${start}' 指令奏效:${INSTRUCTIONS[instruction].n}克制对方${INSTRUCTIONS[model.opponentInstruction].n}。`)}else if(model.matchup<0)live.events.unshift(`${start}' 对手读懂部署,我方这一阶段处于战术下风。`);else live.events.unshift(`${start}' 双方计划没有形成直接克制。`);for(let index=0;index<model.myGoals;index++){const player=scorer(live.seed+phase*13+index);live.events.unshift(`${Math.min(end,start+8+index*12)}' ⚽ ${player.n} 为我方进球`);player.form=Math.min(5,player.form+1)}for(let index=0;index<model.oppGoals;index++)live.events.unshift(`${Math.min(end,start+13+index*11)}' 对手完成一次有效终结`);starters().forEach(player=>player.fit=Math.max(18,player.fit-model.fatigue-(q.press===2?1:0)));live.phase++;if(live.phase>=3){live.finished=true;live.events.unshift(`90' 全场结束,比分 ${live.score[0]}-${live.score[1]}。`)}save();renderLive()}
function autoSub(){const live=q.live;if(!live||live.phase<1||live.finished||live.substituted)return toast("换人需在 30–60 分钟之间完成且每场仅一次");const bench=q.players.filter(player=>!q.starters.includes(player.uid)&&!player.injured),pair=starters().map(outgoing=>({outgoing,incoming:bench.filter(player=>player.pos===outgoing.pos).sort((a,b)=>overall(b)*b.fit-overall(a)*a.fit)[0]})).filter(item=>item.incoming).sort((a,b)=>a.outgoing.fit-b.outgoing.fit)[0];if(!pair)return toast("替补席没有可用的对位球员");const{outgoing,incoming}=pair;q.starters=q.starters.map(id=>id===outgoing.uid?incoming.uid:id);live.played.push(incoming.uid);live.substituted=true;live.events.unshift(`${live.phase*30}' 🔁 ${incoming.n} 换下 ${outgoing.n},完成对位换人。`);save();renderLive()}
function updateTable(a,b,gf,ga){for(const[id,forGoals,against]of[[a,gf,ga],[b,ga,gf]]){const team=q.table[id];team.p++;team.gf+=forGoals;team.ga+=against;if(forGoals>against){team.w++;team.pts+=3}else if(forGoals===against){team.d++;team.pts++}else team.l++}}
function simulateOthers(excluded){const teams=Array.from({length:9},(_,index)=>index+1).filter(id=>id!==excluded);for(let index=0;index<teams.length;index+=2){const a=teams[index],b=teams[index+1],seed=hash(`${q.seed}|table|${q.leagueRound}|${a}|${b}`),ga=Math.floor(randomAt(seed,1)*4),gb=Math.floor(randomAt(seed,2)*4);updateTable(a,b,ga,gb)}}
function finalizeMatch(){const live=q.live;if(!live?.finished)return;const fixture=live.fixture,gf=live.score[0],ga=live.score[1],won=gf>ga,drawn=gf===ga,fee=12+q.facilities.commercial*5+(fixture.home?q.facilities.stadium*4:0),other=teamFor(fixture.opp);q.money+=fee+(won?8:drawn?3:0);q.rep=Math.max(0,q.rep+(won?3:drawn?1:-2)+live.successes);q.tacticalWins+=live.successes;q.results.unshift(`${fixture.type==="cup"?"杯赛":"联赛"} ${CLUBS[q.club].i} ${gf}-${ga} ${other[1]}`);q.results=q.results.slice(0,10);q.events=[...live.events];if(fixture.type==="league"){updateTable(0,fixture.opp,gf,ga);simulateOthers(fixture.opp);q.leagueRound++}else if(!won){q.cupAlive=false;msg(`${fixture.round}出局,杯赛征程结束。`)}else{q.money+=20+q.round*2;q.rep+=4;msg(`晋级杯赛${fixture.round},获得晋级奖金。`)}q.players.forEach((player,index)=>{if(live.played.includes(player.uid)){player.morale=clamp(player.morale+(won?6:drawn?1:-5),20,100);const risk=Math.max(.004,.035-q.facilities.medical*.007)*(player.fit<40?1.8:1);if(randomAt(live.seed,index+80)<risk)player.injured=Math.max(1,3-q.facilities.medical)}else player.fit=Math.min(100,player.fit+8);if(player.injured)player.injured--});q.round++;q.trained=false;q.market=marketFor(q.club,q.round,5+q.facilities.scouting,q.seed);q.message=`${gf}-${ga} ${won?"获胜":drawn?"战平":"失利"};三段部署命中 ${live.successes} 次,获得 ${fee+(won?8:drawn?3:0)} 资金。`;q.live=null;$("liveOverlay").classList.add("hidden");save();if(q.round>=q.schedule.length)return endSeason();draw()}
function train(id){if(q.live)return toast("比赛进行中无法训练");if(q.trained)return toast("本轮已经安排训练");const bonus=1+q.facilities.training*.25;if(id==="attack")q.players.filter(player=>["MF","FW"].includes(player.pos)).forEach(player=>{player.atk=Math.min(player.pot,player.atk+bonus);player.fit=Math.max(18,player.fit-8)});if(id==="defense")q.players.filter(player=>["GK","DF"].includes(player.pos)).forEach(player=>{player.def=Math.min(player.pot,player.def+bonus);player.fit=Math.max(18,player.fit-7)});if(id==="fitness")q.players.forEach(player=>player.fit=Math.min(100,player.fit+16+q.facilities.medical*2));if(id==="morale")q.players.forEach(player=>player.morale=Math.min(100,player.morale+12));if(id==="youth")q.players.filter(player=>player.age<23).sort((a,b)=>hash(a.uid+q.round)-hash(b.uid+q.round)).slice(0,3).forEach(player=>{player.atk=Math.min(player.pot,player.atk+bonus);player.def=Math.min(player.pot,player.def+bonus)});if(id==="rest")q.players.forEach(player=>{player.fit=Math.min(100,player.fit+22);player.injured=Math.max(0,player.injured-1)});q.trained=true;msg(`完成训练:${TRAINING.find(item=>item.id===id).n}`);save();draw()}
function scout(){if(q.money<18)return toast("资金不足");q.money-=18;q.market=marketFor(q.club,q.round+q.rep,5+q.facilities.scouting,q.seed);save();draw()}
function buy(index){const player=q.market[index],cost=Math.round(player.value*1.5);if(q.money<cost)return toast("转会资金不足");q.money-=cost;q.players.push(player);q.market.splice(index,1);msg(`签下 ${player.pos} ${player.n},转会费 ${cost}。`);save();draw()}
function sell(){const player=q.players.find(item=>item.uid===selectedSell);if(!player||q.starters.includes(player.uid))return toast("先在阵容中右键选择一名替补");if(q.players.length<=16)return toast("阵容至少保留 16 人");q.money+=player.value;q.players=q.players.filter(item=>item!==player);selectedSell=null;msg(`出售 ${player.n},回收 ${player.value} 资金。`);save();draw()}
function upgrade(id){const item=FACILITIES[id],level=q.facilities[id],cost=Math.round(item.base*Math.pow(1.7,level));if(level>=item.max||q.money<cost)return toast("资金不足或设施满级");q.money-=cost;q.facilities[id]++;q.rep++;msg(`${item.n}升级到 Lv.${q.facilities[id]}。`);save();draw()}
function endSeason(){const place=sortedTable().findIndex(team=>team.id===0)+1,champion=place===1;profile.seasons++;profile.best=Math.min(profile.best,place);profile.trophies+=champion?1:0;profile.careerRep+=q.rep;profile.tacticalWins+=q.tacticalWins;save();$("infoTitle").textContent="赛季结算";$("infoBody").innerHTML=`<h3>${CLUBS[q.club].i}${CLUBS[q.club].n} · 联赛第 ${place} 名</h3><p>积分 ${q.table[0].pts} · 净胜 ${q.table[0].gf-q.table[0].ga} · 临场克制 ${q.tacticalWins} 次 · ${q.cupAlive?"杯赛坚持到最后":"杯赛已出局"} · 资金 ${Math.floor(q.money)}</p><button class="btn primary" id="nextCareer">开启新赛季</button>`;$("infoOverlay").classList.remove("hidden");$("nextCareer").onclick=()=>{q=null;save();$("infoOverlay").classList.add("hidden");clubScreen();$("startOverlay").classList.remove("hidden")}}
function showSave(){const code=exportCode();$("infoTitle").textContent="跨设备经理生涯";$("infoBody").innerHTML=`<p class="sub">赛季荣誉、阵容、战术、积分榜、转会、设施和未完成的临场阶段都会导出,并带完整性校验。</p><textarea class="savebox" id="saveCode">${code}</textarea><div class="controls"><button class="btn" id="copyCode">复制导出</button><button class="btn" id="importCodeBtn">导入上方档案</button></div>`;$("infoOverlay").classList.remove("hidden");$("copyCode").onclick=()=>navigator.clipboard?.writeText($("saveCode").value);$("importCodeBtn").onclick=()=>{try{importCode($("saveCode").value);$("infoOverlay").classList.add("hidden");if(q?.live){renderLive();$("liveOverlay").classList.remove("hidden")}toast("经理生涯导入成功")}catch(error){toast(error.message)}}}
function switchView(view){activeView=view;document.querySelectorAll(".tab[data-view]").forEach(button=>button.classList.toggle("active",button.dataset.view===view));document.querySelectorAll(".view").forEach(section=>section.classList.toggle("active",section.id===`${view}View`))}
function renderLive(){const live=q.live;if(!live)return;const fixture=live.fixture,opp=opponentFor(fixture.opp),our=CLUBS[q.club],other=teamFor(fixture.opp),home=fixture.home?[our.i,our.n]:[other[1],other[0]],away=fixture.home?[other[1],other[0]]:[our.i,our.n];$("homeIcon").textContent=home[0];$("homeName").textContent=home[1];$("awayIcon").textContent=away[0];$("awayName").textContent=away[1];$("liveScore").textContent=fixture.home?`${live.score[0]} - ${live.score[1]}`:`${live.score[1]} - ${live.score[0]}`;$("liveMinute").textContent=`${Math.min(90,live.phase*30)}' · xG ${live.xg[0].toFixed(2)}-${live.xg[1].toFixed(2)}`;$("phaseTrack").innerHTML=["0–30' 建立局势","31–60' 中场调整","61–90' 决胜阶段"].map((text,index)=>`<div class="phase-step ${index<live.phase?"done":index===live.phase&&!live.finished?"active":""}">${text}</div>`).join("");const next=opp.plan[Math.min(live.phase,2)];$("liveReport").innerHTML=`<h3>🔭 ${opp.n}</h3><p>预计本阶段:<b>${INSTRUCTIONS[next].n}</b><br>弱点:${opp.weak}<br>我方 ${FORMATIONS[q.formation].n} · ${TACTICS.mentality[q.mentality]} · ${TACTICS.press[q.press]}逼抢<br>当前强度 ${lineupPower().toFixed(1)} · 动量 ${live.momentum.toFixed(1)}</p>`;$("liveEvents").innerHTML=live.events.map(event=>`<div>${event}</div>`).join("");$("instructions").innerHTML=live.finished?"":Object.entries(INSTRUCTIONS).map(([id,item])=>`<button class="instruction" data-instruction="${id}"><span>${item.i}</span><b>${item.n}</b><small>${item.d}<br>本段体能 -${item.fatigue}</small></button>`).join("");document.querySelectorAll("[data-instruction]").forEach(button=>button.onclick=()=>resolvePhase(button.dataset.instruction));$("autoSubBtn").disabled=live.phase<1||live.phase>=3||live.substituted;$("autoSubBtn").textContent=live.substituted?"已完成换人":"自动对位换人";$("confirmResultBtn").hidden=!live.finished}
function draw(){if(!q)return;const fixture=currentFixture(),table=sortedTable(),place=table.findIndex(team=>team.id===0)+1,opponent=fixture?opponentFor(fixture.opp):null;$("season").textContent=`第${q.season}季`;$("round").textContent=`${Math.min(q.round+1,q.schedule.length)} / ${q.schedule.length}`;$("money").textContent=Math.floor(q.money);$("rep").textContent=q.rep;$("rank").textContent=place||"--";$("cup").textContent=q.cupAlive?"进行中":"已出局";$("message").textContent=q.message;
if(fixture){const other=teamFor(fixture.opp);$("fixture").innerHTML=`<div class="sub">${fixture.type==="cup"?`杯赛${fixture.round}`:`联赛第 ${q.leagueRound+1} 轮`} · ${fixture.home?"主场":"客场"}</div><div class="teams"><span>${CLUBS[q.club].i}</span><b>VS</b><span>${other[1]}</span></div><h3>${CLUBS[q.club].n} vs ${other[0]}</h3><p>对手模型:${opponent.n} · 首段预计 ${INSTRUCTIONS[opponent.plan[0]].n}</p>`}else $("fixture").innerHTML="<h3>赛季赛程已经完成</h3>";$("preview").innerHTML=`<div class="objective"><b>我方强度 ${lineupPower().toFixed(1)}</b><small>${q.starters.length}/11 首发 · 阵型适配 ${formationFit()} · ${FORMATIONS[q.formation].n}</small></div>${opponent?`<div class="objective"><b>${opponent.n}</b><small>三段计划:${opponent.plan.map(id=>INSTRUCTIONS[id].n).join(" → ")}<br>弱点:${opponent.weak}</small></div>`:""}`;$("events").innerHTML=q.events.map(event=>`<div>${event}</div>`).join("");$("results").innerHTML=q.results.map(result=>`<div>${result}</div>`).join("")||"<div>尚无赛果</div>";const target=CLUBS[q.club].target;$("objectives").innerHTML=`<div class="objective"><b>联赛进入前 ${target}</b><small>当前第 ${place} 名</small><div class="progress"><i style="width:${Math.min(100,target/Math.max(1,place)*100)}%"></i></div></div><div class="objective"><b>临场克制 12 次</b><small>${q.tacticalWins}/12</small><div class="progress"><i style="width:${Math.min(100,q.tacticalWins/12*100)}%"></i></div></div>`;
$("squad").innerHTML=[...q.players].sort((a,b)=>["GK","DF","MF","FW"].indexOf(a.pos)-["GK","DF","MF","FW"].indexOf(b.pos)||overall(b)-overall(a)).map(player=>`<article class="player ${q.starters.includes(player.uid)?"starter":""} ${player.injured?"injured":""}" data-player="${player.uid}"><header><b>${player.pos} ${player.n}</b><span>${overall(player)}</span></header><p>${player.age}岁 · 潜力 ${player.pot} · ${player.trait}${player.injured?` · 伤 ${player.injured}轮`:""}<br>攻${Math.round(player.atk)} 防${Math.round(player.def)} · 身价${player.value}</p><div class="bars"><div class="bar"><i style="width:${player.fit}%"></i></div><div class="bar morale"><i style="width:${player.morale}%"></i></div></div></article>`).join("");document.querySelectorAll("[data-player]").forEach(card=>{card.onclick=()=>toggleStarter(card.dataset.player);card.oncontextmenu=event=>{event.preventDefault();selectedSell=card.dataset.player;toast(`已选择出售:${q.players.find(player=>player.uid===selectedSell).n}`)}});
$("tactics").innerHTML=[["阵型","formation",Object.entries(FORMATIONS).map(([id,item])=>[id,item.n])],["比赛心态","mentality",TACTICS.mentality.map((item,index)=>[index,item])],["逼抢方式","press",TACTICS.press.map((item,index)=>[index,item])],["推进节奏","tempo",TACTICS.tempo.map((item,index)=>[index,item])],["进攻重心","focus",TACTICS.focus.map((item,index)=>[index,item])]].map(([title,id,options])=>`<article class="tactic-card"><h3>${title}</h3><div class="choice-row">${options.map(([value,name])=>`<button class="btn ${String(q[id])===String(value)?"primary":""}" data-tactic="${id}" data-value="${value}">${name}</button>`).join("")}</div></article>`).join("");document.querySelectorAll("[data-tactic]").forEach(button=>button.onclick=()=>{if(q.live)return toast("比赛中只能下达阶段指令");q[button.dataset.tactic]=button.dataset.tactic==="formation"?button.dataset.value:+button.dataset.value;draw()});
$("training").innerHTML=TRAINING.map(item=>`<article class="training-card"><span>${item.i}</span><h3>${item.n}</h3><p>${item.d}</p><button class="btn" data-train="${item.id}" ${q.trained?"disabled":""}>安排训练</button></article>`).join("");document.querySelectorAll("[data-train]").forEach(button=>button.onclick=()=>train(button.dataset.train));$("market").innerHTML=q.market.map((player,index)=>{const cost=Math.round(player.value*1.5);return`<article class="market-card"><header><b>${player.pos} ${player.n}</b><span>${overall(player)}</span></header><div class="avatar">${player.pos==="GK"?"🧤":player.pos==="DF"?"🛡️":player.pos==="MF"?"🎯":"⚽"}</div><p>${player.age}岁 · 潜力${player.pot} · ${player.trait}<br>攻${player.atk} 防${player.def}</p><button class="btn" data-buy="${index}">签约 ${cost}</button></article>`}).join("");document.querySelectorAll("[data-buy]").forEach(button=>button.onclick=()=>buy(+button.dataset.buy));
$("facilities").innerHTML=Object.entries(FACILITIES).map(([id,item])=>{const level=q.facilities[id],cost=Math.round(item.base*Math.pow(1.7,level));return`<article class="facility"><header><b>${item.i}${item.n}</b><span>Lv.${level}/${item.max}</span></header><p>${item.d}</p><button class="btn" data-up="${id}" ${level>=item.max?"disabled":""}>${level>=item.max?"满级":`升级 ${cost}`}</button></article>`}).join("");document.querySelectorAll("[data-up]").forEach(button=>button.onclick=()=>upgrade(button.dataset.up));$("league").innerHTML=table.map((team,index)=>`<tr class="${team.id===0?"me":""}"><td>${index+1}</td><td>${team.i}${team.n}</td><td>${team.p}</td><td>${team.w}</td><td>${team.d}</td><td>${team.l}</td><td>${team.gf-team.ga}</td><td><b>${team.pts}</b></td></tr>`).join("");$("playBtn").disabled=!fixture;save();if(q.live){renderLive();$("liveOverlay").classList.remove("hidden")}}
function clubScreen(){$("clubs").innerHTML=Object.entries(CLUBS).map(([id,club])=>`<button class="club" data-club="${id}"><span>${club.i}</span><h3>${club.n}</h3><p>${club.d}<br>预算 ${club.money} · 目标前 ${club.target}</p></button>`).join("");document.querySelectorAll("[data-club]").forEach(button=>button.onclick=()=>startCareer(button.dataset.club))}
function startCareer(club){q=fresh(club);$("startOverlay").classList.add("hidden");save();draw()}
function validateContent(){const schedule=makeSchedule(),badPlans=OPPONENTS.flatMap((opponent,index)=>opponent.plan.filter(id=>!INSTRUCTIONS[id]).map(id=>`${index}:${id}`));return{valid:Object.keys(CLUBS).length===4&&Object.keys(INSTRUCTIONS).length===4&&OPPONENTS.length===10&&schedule.length===21&&!badPlans.length,clubs:Object.keys(CLUBS).length,instructions:Object.keys(INSTRUCTIONS).length,opponents:OPPONENTS.length,fixtures:schedule.length,badPlans}}
document.querySelectorAll("[data-view]").forEach(button=>button.onclick=()=>switchView(button.dataset.view));$("playBtn").onclick=beginMatch;$("autoSubBtn").onclick=autoSub;$("confirmResultBtn").onclick=finalizeMatch;$("scoutBtn").onclick=scout;$("sellBtn").onclick=sell;$("saveBtn").onclick=()=>q&&showSave();$("closeInfoBtn").onclick=()=>$("infoOverlay").classList.add("hidden");$("newBtn").onclick=()=>{if(!q||confirm("放弃当前生涯并重新选择俱乐部?")){q=null;save();clubScreen();$("startOverlay").classList.remove("hidden")}};
load();clubScreen();if(q){$("startOverlay").classList.add("hidden");draw()}
window.__touchlineManager={CLUBS,FORMATIONS,INSTRUCTIONS,OPPONENTS,validateContent,fresh,state:()=>q,profile:()=>profile,start:startCareer,begin:beginMatch,model:phaseModel,match:instructionMatch,resolve:resolvePhase,sub:autoSub,finish:finalizeMatch,encode:exportCode,decode:decodeCode};
})();
</script>
</body>
</html>