You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

script-skill-parser.js 64 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807
  1. //带标签的模板字符串
  2. function tp(strings, ...keys) {
  3. return (function(...values) {
  4. let dict = values[values.length - 1] || {};
  5. let fragment = document.createDocumentFragment();
  6. fragment.appendChild(document.createTextNode(strings[0]));
  7. //let result = [strings[0]];
  8. keys.forEach(function(key, i, arr) {
  9. let value = Number.isInteger(key) ? values[key] : dict[key];
  10. if (value == undefined)
  11. {
  12. console.log("模板字符串中 %s 未找到输入数据",key);
  13. }else
  14. {
  15. if (!(value instanceof Node))
  16. {
  17. value = document.createTextNode(value);
  18. }
  19. try{
  20. fragment.appendChild(arr.lastIndexOf(key) == i ? value : value.cloneNode(true));
  21. }catch(e)
  22. {
  23. console.log(value, e);
  24. console.log(keys, values);
  25. }
  26. }
  27. fragment.appendChild(document.createTextNode(strings[i + 1]));
  28. });
  29. return fragment;
  30. });
  31. }
  32. const Attributes = {
  33. /*0: "Fire",
  34. 1: "Water",
  35. 2: "Wood",
  36. 3: "Light",
  37. 4: "Dark",
  38. 5: "Heart",
  39. 6: "Jammer",
  40. 7: "Poison",
  41. 8: "MPoison",
  42. 9: "Bomb",*/
  43. Fire: 0,
  44. Water: 1,
  45. Wood: 2,
  46. Light: 3,
  47. Dark: 4,
  48. Heart: 5,
  49. Jammer: 6,
  50. Poison: 7,
  51. MPoison: 8,
  52. Bomb: 9,
  53. }
  54. for (let name in Attributes)
  55. {
  56. Attributes[Attributes[name]] = name;
  57. }
  58. Attributes.all = function () {
  59. return [
  60. this.Fire,
  61. this.Water,
  62. this.Wood,
  63. this.Light,
  64. this.Dark
  65. ];
  66. }
  67. Attributes.orbs = function () {
  68. return [
  69. this.Fire,
  70. this.Water,
  71. this.Wood,
  72. this.Light,
  73. this.Dark,
  74. this.Heart,
  75. this.Jammer,
  76. this.Poison,
  77. this.MPoison,
  78. this.Bomb,
  79. ];
  80. }
  81. class Board
  82. {
  83. #rowCount = 6;
  84. #columnCount = 7;
  85. #data = [];
  86. constructor(def = null)
  87. {
  88. for (let ri=0;ri<this.#rowCount;ri++)
  89. {
  90. this.#data.push(new Array(this.#columnCount).fill(Array.isArray(def) ? null : def));
  91. }
  92. if (Array.isArray(def))
  93. {
  94. this.randomFill(def);
  95. }
  96. }
  97. randomFill(attrs)
  98. {
  99. let valueArray = new Uint8Array(this.#rowCount * this.#columnCount);
  100. crypto.getRandomValues(valueArray); //获取符合密码学要求的安全的随机值
  101. valueArray = Array.from(valueArray.map(x => attrs[x % attrs.length])); //用所有宝珠随机填充
  102. //之后用每种颜色填充前3个
  103. attrs.forEach((attr,idx)=>{
  104. valueArray.fill(attr, idx * 3, idx * 3 + 3);
  105. });
  106. //将上方数据重新乱序排列
  107. const randomData = [];
  108. //将65版之后的的提出来
  109. let secondaryData = valueArray.splice((this.#rowCount - 1) * (this.#columnCount - 1));
  110. while(valueArray.length > 0)
  111. {
  112. randomData.push(valueArray.randomShift());
  113. }
  114. while(secondaryData.length > 0)
  115. {
  116. randomData.push(secondaryData.randomShift());
  117. }
  118. const o = randomData.entries();
  119. //65版部分
  120. for (let ri=0;ri<this.#data.length;ri++)
  121. {
  122. if (ri == 2) ri++;
  123. const row = this.#data[ri];
  124. for (let ci=0;ci<row.length;ci++)
  125. {
  126. if (ci == 3) ci++;
  127. //从数组中随机取出一个
  128. row[ci] = o.next().value?.[1];
  129. }
  130. }
  131. //填充剩下的部分
  132. for (let ri=0;ri<this.#data.length;ri++)
  133. {
  134. if (ri == 2) ri++;
  135. const row = this.#data[ri];
  136. row[3] = o.next().value?.[1];
  137. }
  138. const row = this.#data[2];
  139. for (let ci=0;ci<row.length;ci++)
  140. {
  141. row[ci] = o.next().value?.[1];
  142. }
  143. }
  144. overlayBoard(board)
  145. {
  146. }
  147. setRow(rows, attr = 0) //设定横行
  148. {
  149. for (let row of rows)
  150. {
  151. if (row >= 2) row++;
  152. const rowData = this.#data[row];
  153. for (let ri=0;ri<rowData.length;ri++)
  154. {
  155. rowData[ri] = attr;
  156. }
  157. //this.#data[row] = this.#data[row].map(()=>attr);
  158. }
  159. }
  160. setColumn(cols, attr = 0) //设定横行
  161. {
  162. for (let col of cols)
  163. {
  164. if (col >= 3) col++;
  165. for (let row of this.#data)
  166. {
  167. row[col] = attr;
  168. }
  169. }
  170. }
  171. setShape(matrix, attr = 0)
  172. {
  173. function fillRow(rowData, inputRow, attr)
  174. {
  175. for (let col of inputRow)
  176. {
  177. if (col == 3) rowData[col] = attr;
  178. if (col >= 3) col++;
  179. rowData[col] = attr;
  180. }
  181. }
  182. for (let ri=0;ri<matrix.length;ri++)
  183. {
  184. if (ri == 2)
  185. {
  186. fillRow(this.#data[ri], matrix[ri], attr);
  187. }
  188. fillRow(this.#data[ri >= 2 ? ri+1 : ri], matrix[ri], attr);
  189. }
  190. }
  191. valueOf()
  192. {
  193. return this.#data;
  194. }
  195. toTable()
  196. {
  197. const table = document.createElement("table");
  198. table.className = "board";
  199. this.#data.forEach((rowData, ri, rArr) => {
  200. const row = table.insertRow();
  201. if (ri == 2 && rArr.length > 5) row.classList.add("board-row4");
  202. rowData.forEach((orbType, ci, cArr) => {
  203. const cell = row.insertCell();
  204. const orb = cell.appendChild(document.createElement('icon'));
  205. orb.className = "orb";
  206. if (orbType != null) orb.setAttribute("data-orb-icon", orbType);
  207. if (ci == 3 && cArr.length > 6) cell.classList.add("board-cell5");
  208. });
  209. });
  210. if (this.#data.length > 5)
  211. {
  212. table.onclick = function() {
  213. this.classList.toggle("board-76");
  214. };
  215. }
  216. return table;
  217. }
  218. }
  219. const SkillValue = {
  220. isLess: function (value) {
  221. if (value.kind === SkillValueKind.Percent) return value.value < 1;
  222. if (value.kind === SkillValueKind.Constant) return value.value < 0;
  223. return false;
  224. }
  225. };
  226. const SkillValueKind = {
  227. Percent: 'mul',
  228. Constant: 'const',
  229. ConstantTo: 'const-to',
  230. xMaxHP: 'mul-maxhp',
  231. xHP: 'mul-hp',
  232. xATK: 'mul-atk',
  233. xRCV: 'mul-rcv',
  234. RandomATK: 'random-atk',
  235. HPScale: 'hp-scale',
  236. xTeamHP: 'mul-team-hp',
  237. xTeamATK: 'mul-team-atk',
  238. xTeamRCV: 'mul-team-rcv',
  239. xAwakenings: 'mul-awakenings',
  240. };
  241. const SkillPowerUpKind = {
  242. Multiplier: 'mul',
  243. ScaleAttributes: 'scale-attrs',
  244. ScaleCombos: 'scale-combos',
  245. ScaleMatchLength: 'scale-match-len',
  246. ScaleMatchAttrs: 'scale-match-attrs',
  247. ScaleCross: 'scale-cross',
  248. ScaleAwakenings: 'scale-awakenings',
  249. };
  250. const SkillKinds = {
  251. Unknown: "unknown",
  252. ActiveTurns: "active-turns",
  253. DamageEnemy: "damage-enemy",
  254. Vampire: "vampire",
  255. ReduceDamage: "reduce-damage",
  256. SelfHarm: "self-harm",
  257. Heal: "heal",
  258. AutoHealBuff: "auto-heal-buff",
  259. ChangeOrbs: "change-orbs",
  260. GenerateOrbs: "generate-orbs",
  261. FixedOrbs: "fixed-orbs",
  262. PowerUp: "power-up",
  263. CounterAttack: "counter-attack",
  264. SetOrbState: "set-orb-state",
  265. RateMultiply: "rate-mul",
  266. OrbDropIncrease: "orb-drop-incr",
  267. Resolve: "resolve",
  268. Delay: "delay",
  269. DefenseBreak: "def-break",
  270. MassAttack: "mass-attack",
  271. BoardChange: "board-change",
  272. Unbind: "unbind",
  273. RandomSkills: "random-skills",
  274. ChangeAttribute: "change-attr",
  275. SkillBoost: "skill-boost",
  276. AddCombo: "add-combo",
  277. VoidEnemyBuff: "void-enemy-buff",
  278. Poison: "poison",
  279. CTW: "ctw",
  280. Gravity: "gravity",
  281. FollowAttack: "follow-attack",
  282. AutoHeal: "auto-heal",
  283. TimeExtend: "time-extend",
  284. DropRefresh: "drop-refresh",
  285. LeaderChange: "leader-change",
  286. MinMatchLength: "min-match-len",
  287. FixedTime: "fixed-time",
  288. Drum: "drum",
  289. Board7x6: "7x6-board",
  290. NoSkyfall: "no-skyfall",
  291. }
  292. function skillParser(skillId)
  293. {
  294. /*function merge(skills)
  295. {
  296. //解封部分的合并
  297. let unbinds = skills.filter(skill=>skill.kind == SkillKinds.Unbind);
  298. if (unbinds.length>1)
  299. { //把后面的全都合并到第一个
  300. unbinds.reduce((pre,cur)=>{
  301. pre.normal = pre.normal || cur.normal;
  302. pre.awakenings = pre.awakenings || cur.awakenings;
  303. pre.matches = pre.matches || cur.matches;
  304. return pre
  305. });
  306. unbinds.shift(); //去除第一个
  307. unbinds.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
  308. }
  309. let fixedDamages = skills.filter(skill=>skill.kind == SkillKinds.DamageEnemy && skill.attr === 'fixed').filter((skill,idx,arr)=>skill.id==arr[0].id);
  310. if (fixedDamages.length>1)
  311. { //把后面的全都合并到第一个
  312. fixedDamages[0].times = 5;
  313. fixedDamages.shift(); //去除第一个
  314. fixedDamages.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
  315. }
  316. }*/
  317. const skill = Skills[skillId];
  318. if (!skill) return [];
  319. if (!parsers[skill.type]) {
  320. return [{ kind: SkillKinds.Unknown }];
  321. }
  322. //此处用apply将这个parser传递到后面解析函数的this里,用于递归解析
  323. const result = parsers[skill.type].apply({ parser: skillParser }, skill.params);
  324. const skills = (Array.isArray(result) ? result : [result])
  325. .filter(s => Boolean(s))
  326. .map(s => ({ id: skillId, type: skill.type, params: skill.params, ...s }));
  327. //merge(skills);
  328. return skills;
  329. }
  330. //返回flag里值为true的数组,如[1,4,7]
  331. function flags(num){
  332. /*
  333. return Array.from(new Array(32),(i,n)=>n).filter(n => num & (1 << n)); //性能太差
  334. return new Array(32).fill(null).map((i,n)=>n).filter(n => num & (1 << n)); //性能比上者好,但还是不够快
  335. */
  336. const arr = [];
  337. for (let i = 0; i<32;i++)
  338. {
  339. if (num & (1<<i))
  340. {
  341. arr.push(i);
  342. }
  343. }
  344. return arr;
  345. }
  346. const v = {
  347. percent: function(value) {
  348. return { kind: SkillValueKind.Percent, value: (value / 100) || 1 };
  349. },
  350. constant: function(value) {
  351. return { kind: SkillValueKind.Constant, value: value ?? 0 };
  352. },
  353. constantTo: function(value) {
  354. return { kind: SkillValueKind.ConstantTo, value: value || 1 };
  355. },
  356. xMaxHP: function(value) {
  357. return { kind: SkillValueKind.xMaxHP, value: (value / 100) || 1 };
  358. },
  359. xHP: function(value) {
  360. return { kind: SkillValueKind.xHP, value: (value / 100) || 1 };
  361. },
  362. xATK: function(value) {
  363. return { kind: SkillValueKind.xATK, value: (value / 100) || 1 };
  364. },
  365. xRCV: function(value) {
  366. return { kind: SkillValueKind.xRCV, value: (value / 100) || 1 };
  367. },
  368. randomATK: function(min, max) {
  369. return { kind: SkillValueKind.RandomATK, min: (min / 100) || 1, max: (max / 100) || 1, scale: 1 };
  370. },
  371. hpScale: function(min, max, scale) {
  372. return { kind: SkillValueKind.HPScale, min: (min / 100) || 1, max: (max / 100) || 1, scale: (scale / 100) || 1 };
  373. },
  374. xTeamHP: function(value) {
  375. return { kind: SkillValueKind.xTeamHP, value: (value / 100) || 1 };
  376. },
  377. xTeamATK: function(attrs, value) {
  378. return { kind: SkillValueKind.xTeamATK, attrs: attrs, value: (value / 100) || 1 };
  379. },
  380. xTeamRCV: function(value) {
  381. return { kind: SkillValueKind.xTeamRCV, value: (value / 100) || 1 };
  382. },
  383. percentAwakenings: function(awakenings, value) {
  384. return { kind: SkillValueKind.xAwakenings, awakenings: awakenings, value: value / 100 };
  385. },
  386. };
  387. const c = {
  388. hp: function (min, max) {
  389. return { hp: { min: min / 100, max: max / 100 } };
  390. },
  391. exact: function (type, value, attrs) {
  392. if (attrs === void 0) { attrs = Attributes.all(); }
  393. return { exact: { type: type, value: value, attrs: attrs } };
  394. },
  395. compo: function (type, ids) {
  396. return { compo: { type: type, ids: ids } };
  397. },
  398. remainOrbs: function (count) { return { remainOrbs: { count: count } }; },
  399. useSkill: function () { return { useSkill: true }; },
  400. multiplayer: function () { return { multiplayer: true }; },
  401. prob: function (percent) { return { prob: percent }; },
  402. }
  403. const p = {
  404. mul: function (values) {
  405. if (Array.isArray(values)) {
  406. return {
  407. kind: SkillPowerUpKind.Multiplier,
  408. hp: 1,
  409. atk: values[0] / 100,
  410. rcv: values[1] / 100
  411. };
  412. }
  413. else {
  414. return {
  415. kind: SkillPowerUpKind.Multiplier,
  416. hp: (values.hp || 100) / 100,
  417. atk: (values.atk || 100) / 100,
  418. rcv: (values.rcv || 100) / 100
  419. };
  420. }
  421. },
  422. stats: function (value) {
  423. let statTypes = Array.from(arguments).slice(1);
  424. return [
  425. statTypes.indexOf(1) >= 0 ? value : 100,
  426. statTypes.indexOf(2) >= 0 ? value : 100
  427. ];
  428. },
  429. scale: function (min, max, baseMul, bonusMul) {
  430. return {
  431. min: min,
  432. max: max || min,
  433. baseAtk: (baseMul[0] / 100) || 1,
  434. baseRcv: (baseMul[1] / 100) || 1,
  435. bonusAtk: (bonusMul[0] / 100) ?? 0,
  436. bonusRcv: (bonusMul[1] / 100) ?? 0
  437. };
  438. },
  439. scaleAttrs: function (attrs, min, max, baseMul, bonusMul) {
  440. return { kind: SkillPowerUpKind.ScaleAttributes, attrs: attrs ,...this.scale(min, max, baseMul, bonusMul) };
  441. },
  442. scaleCombos: function (min, max, baseMul, bonusMul) {
  443. return { kind: SkillPowerUpKind.ScaleCombos ,...this.scale(min, max, baseMul, bonusMul) };
  444. },
  445. scaleMatchLength: function (attrs, min, max, baseMul, bonusMul) {
  446. return { kind: SkillPowerUpKind.ScaleMatchLength, attrs: attrs ,...this.scale(min, max, baseMul, bonusMul) };
  447. },
  448. scaleMatchAttrs: function (matches, min, max, baseMul, bonusMul) {
  449. return { kind: SkillPowerUpKind.ScaleMatchAttrs, matches: matches ,...this.scale(min, max, baseMul, bonusMul) };
  450. },
  451. scaleCross: function (crosses) {
  452. return { kind: SkillPowerUpKind.ScaleCross, crosses: crosses.map(cross => ({ ...cross, mul: (cross.mul / 100) || 1 })) };
  453. },
  454. scaleAwakenings: function (awakenings, value) {
  455. return { kind: SkillPowerUpKind.ScaleAwakenings, awakenings: awakenings, value: value / 100 };
  456. },
  457. }
  458. function activeTurns(turns, skill) {
  459. return skill ? { kind: SkillKinds.ActiveTurns, turns: turns, skill: skill } : null;
  460. }
  461. function damageEnemy(target, attr, damage) {
  462. return { kind: SkillKinds.DamageEnemy, target: target, attr: attr, damage: damage };
  463. }
  464. function vampire(attr, damageValue, healValue) {
  465. return { kind: SkillKinds.Vampire, attr: attr, damage: damageValue, heal: healValue };
  466. }
  467. function reduceDamage(attrs, percent, condition) {
  468. return { kind: SkillKinds.ReduceDamage, attrs: attrs, percent: percent, condition: condition };
  469. }
  470. function selfHarm(value) {
  471. return { kind: SkillKinds.SelfHarm, value: value };
  472. }
  473. function heal(value) {
  474. return { kind: SkillKinds.Heal, value: value };
  475. }
  476. function autoHealBuff(value) {
  477. return { kind: SkillKinds.AutoHealBuff, value: value };
  478. }
  479. function fromTo(from, to) {
  480. return { from: from, to: to };
  481. }
  482. function changeOrbs() {
  483. return { kind: SkillKinds.ChangeOrbs, changes: Array.from(arguments) };
  484. }
  485. function generateOrbs(to, exclude, count) {
  486. return { kind: SkillKinds.GenerateOrbs, to: to, exclude: exclude, count: count };
  487. }
  488. function fixedOrbs() {
  489. return { kind: SkillKinds.FixedOrbs, generates: Array.from(arguments) };
  490. }
  491. function powerUp(attrs, types, value, condition, reduceDamageValue) {
  492. if (value.kind === SkillPowerUpKind.Multiplier) {
  493. let hp = value.hp, atk = value.atk, rcv = value.rcv;
  494. if (hp === 1 && atk === 1 && rcv === 1 && !reduceDamage)
  495. return null;
  496. }
  497. return { kind: SkillKinds.PowerUp, attrs: attrs, types: types, condition: condition, value: value, reduceDamage: reduceDamageValue };
  498. }
  499. function counterAttack(attr, prob, value) {
  500. return { kind: SkillKinds.CounterAttack, attr: attr, prob: prob, value: value };
  501. }
  502. function setOrbState(orbs, state) {
  503. return { kind: SkillKinds.SetOrbState, orbs: orbs, state: state };
  504. }
  505. function rateMultiply(value, rate) {
  506. return { kind: SkillKinds.RateMultiply, value: value, rate: rate };
  507. }
  508. function orbDropIncrease(value, attrs) {
  509. return { kind: SkillKinds.OrbDropIncrease, value: value, attrs: attrs };
  510. }
  511. function resolve(min, prob) {
  512. return { kind: SkillKinds.Resolve, min: min, max: 1, prob: prob };
  513. }
  514. function unbind(normal, awakenings, matches) {
  515. return { kind: SkillKinds.Unbind, normal: normal, awakenings: awakenings , matches: matches};
  516. }
  517. function boardChange(attrs) {
  518. return { kind: SkillKinds.BoardChange, attrs: attrs };
  519. }
  520. function randomSkills(skills) {
  521. return { kind: SkillKinds.RandomSkills, skills: skills };
  522. }
  523. function changeAttr(target, attr) {
  524. return { kind: SkillKinds.ChangeAttribute, target: target, attr: attr ?? 0 };
  525. }
  526. function gravity(value) {
  527. return { kind: SkillKinds.Gravity, value: value };
  528. }
  529. function voidEnemyBuff(buffs) {
  530. return { kind: SkillKinds.VoidEnemyBuff, buffs: buffs };
  531. }
  532. function skillBoost(value) { return { kind: SkillKinds.SkillBoost, value: value }; }
  533. function minMatch(value) { return { kind: SkillKinds.MinMatchLength, value: value }; }
  534. function fixedTime(value) { return { kind: SkillKinds.FixedTime, value: v.constant(value) }; }
  535. function addCombo(value) { return { kind: SkillKinds.AddCombo, value: value }; }
  536. function defBreak(value) { return { kind: SkillKinds.DefenseBreak, value: value }; }
  537. function poison(value) { return { kind: SkillKinds.Poison, value: value }; }
  538. function CTW(value) { return { kind: SkillKinds.CTW, value: value }; }
  539. function followAttack(value) { return { kind: SkillKinds.FollowAttack, value: value }; }
  540. function autoHeal(value) { return { kind: SkillKinds.AutoHeal, value: value }; }
  541. function timeExtend(value) { return { kind: SkillKinds.TimeExtend, value: value }; }
  542. function delay() { return { kind: SkillKinds.Delay }; }
  543. function massAttack() { return { kind: SkillKinds.MassAttack }; }
  544. function dropRefresh() { return { kind: SkillKinds.DropRefresh }; }
  545. function drum() { return { kind: SkillKinds.Drum }; }
  546. function leaderChange() { return { kind: SkillKinds.LeaderChange }; }
  547. function board7x6() { return { kind: SkillKinds.Board7x6 }; }
  548. function noSkyfall() { return { kind: SkillKinds.NoSkyfall }; }
  549. const parsers = {
  550. parser: (() => []), //这个用来解决代码提示的报错问题,不起实际作用
  551. [0](attr, mul) { return damageEnemy('all', attr, v.xATK(mul)); },
  552. [1](attr, value) { return damageEnemy('all', attr, v.constant(value)); },
  553. [2](mul) { return damageEnemy('single', 'self', v.xATK(mul)); },
  554. [3](turns, percent) { return activeTurns(turns, reduceDamage('all', v.percent(percent))); },
  555. [4](mul) { return poison(v.xATK(mul)); },
  556. [5](time) { return CTW(v.constant(time)); },
  557. [6](percent) { return gravity(v.xHP(percent)); },
  558. [7](mul) { return heal(v.xRCV(mul)); },
  559. [8](value) { return heal(v.constant(value)); },
  560. [9](from, to) { return changeOrbs(fromTo([from ?? 0], [to ?? 0])); },
  561. [10]() { return dropRefresh(); },
  562. [11](attr, mul) { return powerUp([attr], null, p.mul({ atk: mul })); },
  563. [12](mul) { return followAttack(v.xATK(mul)); },
  564. [13](mul) { return autoHeal(v.xRCV(mul)); },
  565. [14](min, prob) { return resolve(v.percent(min), v.percent(prob)); },
  566. [15](time) { return timeExtend(v.constant(time / 100)); },
  567. [16](percent) { return reduceDamage('all', v.percent(percent)); },
  568. [17](attr, percent) { return reduceDamage([attr], v.percent(percent)); },
  569. [18](turns) { return activeTurns(turns, delay()); },
  570. [19](turns, percent) { return activeTurns(turns, defBreak(v.percent(percent))); },
  571. [20](from1, to1, from2, to2) {
  572. if ((to1 ?? 0) == (to2 ?? 0))
  573. return changeOrbs(fromTo([from1 ?? 0, from2 ?? 0], [to1 ?? 0]));
  574. else
  575. return changeOrbs(
  576. fromTo([from1 ?? 0], [to1 ?? 0]),
  577. fromTo([from2 ?? 0], [to2 ?? 0])
  578. );
  579. },
  580. [21](turns, attr, percent) { return activeTurns(turns, reduceDamage([attr], v.percent(percent))); },
  581. [22](type, mul) { return powerUp(null, [type], p.mul({ atk: mul })); },
  582. [23](type, mul) { return powerUp(null, [type], p.mul({ hp: mul })); },
  583. [24](type, mul) { return powerUp(null, [type], p.mul({ rcv: mul })); },
  584. [26](mul) { return powerUp(null, null, p.mul({ atk: mul })); },
  585. [28](attr, mul) { return powerUp([attr], null, p.mul({ atk: mul, rcv: mul })); },
  586. [29](attr, mul) { return powerUp([attr], null, p.mul({ hp: mul, atk: mul, rcv: mul })); },
  587. [30](type1, type2, mul) { return powerUp(null, [type1, type2], p.mul({ hp: mul })); },
  588. [31](type1, type2, mul) { return powerUp(null, [type1, type2], p.mul({ atk: mul })); },
  589. [33]() { return drum(); },
  590. [35](mul, percent) { return vampire('self', v.xATK(mul), v.percent(percent)); },
  591. [36](attr1, attr2, percent) { return reduceDamage([attr1, attr2], v.percent(percent)); },
  592. [37](attr, mul) { return damageEnemy('single', attr, v.xATK(mul)); },
  593. [38](max, _, percent) { return reduceDamage('all', v.percent(percent), max === 100 ? c.hp(max, max) : c.hp(0, max)); },
  594. [39](percent, stats1, stats2, mul) { return powerUp(null, null, p.mul(p.stats(mul, stats1, stats2)), c.hp(0, percent)); },
  595. [40](attr1, attr2, mul) { return powerUp([attr1, attr2], null, p.mul({ atk: mul })); },
  596. [41](prob, mul, attr) { return counterAttack(attr ?? 0, v.percent(prob), v.percent(mul)); },
  597. [42](targetAttr, dmgAttr, value) { return damageEnemy(targetAttr, dmgAttr, v.constant(value)); },
  598. [43](min, max, percent) { return reduceDamage('all', v.percent(percent), c.hp(min, max)); },
  599. [44](percent, stats1, stats2, mul) { return powerUp(null, null, p.mul(p.stats(mul, stats1, stats2)), c.hp(percent, 100)); },
  600. [45](attr, mul) { return powerUp([attr], null, p.mul({ hp: mul, atk: mul })); },
  601. [46](attr1, attr2, mul) { return powerUp([attr1, attr2], null, p.mul({ hp: mul })); },
  602. [48](attr, mul) { return powerUp([attr], null, p.mul({ hp: mul })); },
  603. [49](attr, mul) { return powerUp([attr], null, p.mul({ rcv: mul })); },
  604. [50](turns, attr, mul) { return activeTurns(turns, powerUp([attr], null, p.mul({ atk: mul }))); },
  605. [51](turns) { return activeTurns(turns, massAttack()); },
  606. [52](attr) { return setOrbState([attr], 'enhanced'); },
  607. [53](mul) { return rateMultiply(v.percent(mul), 'drop'); },
  608. [54](mul) { return rateMultiply(v.percent(mul), 'coin'); },
  609. [55](value) { return damageEnemy('single', 'fixed', v.constant(value)); },
  610. [56](value) { return damageEnemy('all', 'fixed', v.constant(value)); },
  611. [58](attr, min, max) { return damageEnemy('all', attr, v.randomATK(min, max)); },
  612. [59](attr, min, max) { return damageEnemy('single', attr, v.randomATK(min, max)); },
  613. [60](turns, mul, attr) { return activeTurns(turns, counterAttack(attr, v.percent(100), v.percent(mul))); },
  614. [61](attrs, min, base, bonus, incr) { return powerUp(null, null, p.scaleAttrs(flags(attrs), min, min + (incr ?? 0), [base, 100], [bonus, 0])); },
  615. [62](type, mul) { return powerUp(null, [type], p.mul({ hp: mul, atk: mul })); },
  616. [63](type, mul) { return powerUp(null, [type], p.mul({ hp: mul, rcv: mul })); },
  617. [64](type, mul) { return powerUp(null, [type], p.mul({ atk: mul, rcv: mul })); },
  618. [65](type, mul) { return powerUp(null, [type], p.mul({ hp: mul, atk: mul, rcv: mul })); },
  619. [66](combo, mul) { return powerUp(null, null, p.scaleCombos(combo, combo, [mul, 100], [0, 0])); },
  620. [67](attr, mul) { return powerUp([attr], null, p.mul({ hp: mul, rcv: mul })); },
  621. [69](attr, type, mul) { return powerUp([attr], [type], p.mul({ atk: mul })); },
  622. [71](...attrs) { return boardChange(attrs.filter(attr => attr >= 0)); },
  623. [73](attr, type, mul) { return powerUp([attr], [type], p.mul({ hp: mul, atk: mul })); },
  624. [75](attr, type, mul) { return powerUp([attr], [type], p.mul({ atk: mul, rcv: mul })); },
  625. [76](attr, type, mul) { return powerUp([attr], [type], p.mul({ hp: mul, atk: mul, rcv: mul })); },
  626. [77](type1, type2, mul) { return powerUp(null, [type1, type2], p.mul({ hp: mul, atk: mul })); },
  627. [79](type1, type2, mul) { return powerUp(null, [type1, type2], p.mul({ atk: mul, rcv: mul })); },
  628. [84](attr, min, max, percent) {
  629. return [
  630. selfHarm(percent ? v.xHP(100 - percent) : v.constantTo(1)),
  631. damageEnemy('single', attr, v.randomATK(min, max))
  632. ];
  633. },
  634. [85](attr, min, max, percent) {
  635. return [
  636. selfHarm(percent ? v.xHP(100 - percent) : v.constantTo(1)),
  637. damageEnemy('all', attr, v.randomATK(min, max))
  638. ];
  639. },
  640. [86](attr, value, _, percent) {
  641. return [
  642. selfHarm(percent ? v.xHP(100 - percent) : v.constantTo(1)),
  643. damageEnemy('single', attr, v.constant(value))
  644. ];
  645. },
  646. [87](attr, value, _, percent) {
  647. return [
  648. selfHarm(percent ? v.xHP(100 - percent) : v.constantTo(1)),
  649. damageEnemy('all', attr, v.constant(value))
  650. ];
  651. },
  652. [88](turns, type, mul) { return activeTurns(turns, powerUp(null, [type], p.mul({ atk: mul }))); },
  653. [90](turns, attr1, attr2, mul) { return activeTurns(turns, powerUp([attr1, attr2], null, p.mul({ atk: mul }))); },
  654. [91](attr1, attr2) { return setOrbState([attr1, attr2], 'enhanced'); },
  655. [92](turns, type1, type2, mul) { return activeTurns(turns, powerUp(null, [type1, type2], p.mul({ atk: mul }))); },
  656. [93]() { return leaderChange(); },
  657. [94](percent, attr, stats1, stats2, mul) { return powerUp([attr], null, p.mul(p.stats(mul, stats1, stats2)), c.hp(0, percent)); },
  658. [95](percent, type, stats1, stats2, mul) { return powerUp(null, [type], p.mul(p.stats(mul, stats1, stats2)), c.hp(0, percent)); },
  659. [96](percent, attr, stats1, stats2, mul) { return powerUp([attr], null, p.mul(p.stats(mul, stats1, stats2)), c.hp(percent, 100)); },
  660. [97](percent, type, stats1, stats2, mul) { return powerUp(null, [type], p.mul(p.stats(mul, stats1, stats2)), c.hp(percent, 100)); },
  661. [98](min, base, bonus, max) { return powerUp(null, null, p.scaleCombos(min, max, [base, 100], [bonus, 0])); },
  662. [100](stats1, stats2, mul) { return powerUp(null, null, p.mul(p.stats(mul, stats1, stats2)), c.useSkill()); },
  663. [101](combo, mul) { return powerUp(null, null, p.mul({ atk: mul }), c.exact('combo', combo)); },
  664. [103](combo, stats1, stats2, mul) { return powerUp(null, null, p.scaleCombos(combo, combo, p.stats(mul, stats1, stats2), [0, 0])); },
  665. [104](combo, attrs, stats1, stats2, mul) { return powerUp(flags(attrs), null, p.scaleCombos(combo, combo, p.stats(mul, stats1, stats2), [0, 0])); },
  666. [105](rcv, atk) { return powerUp(null, null, p.mul({ rcv, atk })); },
  667. [106](hp, atk) { return powerUp(null, null, p.mul({ hp, atk })); },
  668. [107](hp) { return powerUp(null, null, p.mul({ hp })); },
  669. [108](hp, type, atk) { return [powerUp(null, null, p.mul({ hp })), powerUp(null, [type], p.mul({ atk }))]; },
  670. [109](attrs, len, mul) { return powerUp(null, null, p.scaleMatchLength(flags(attrs), len, len, [mul, 100], [0, 0])); },
  671. [110](single, attr, min, max, scale) { return damageEnemy(single ? 'single' : 'all', attr, v.hpScale(min, max, scale)); },
  672. [111](attr1, attr2, mul) { return powerUp([attr1, attr2], null, p.mul({ hp: mul, atk: mul })); },
  673. [114](attr1, attr2, mul) { return powerUp([attr1, attr2], null, p.mul({ hp: mul, atk: mul, rcv: mul })); },
  674. [115](attr, mul, percent) { return vampire(attr, v.xATK(mul), v.percent(percent)); },
  675. [116](...ids) { return ids.flatMap(id => this.parser(id)); },
  676. [117](bind, rcv, constant, hp, awokenBind) {
  677. return [
  678. rcv ? heal(v.xRCV(rcv)) : hp ? heal(v.xMaxHP(hp)) : constant ? heal(v.constant(constant)) : null,
  679. (bind || awokenBind) ? unbind(bind ?? 0, awokenBind ?? 0) : null,
  680. ].filter(Boolean);
  681. },
  682. [118](...ids) { return randomSkills(ids.map(id => this.parser(id))); },
  683. [119](attrs, min, base, bonus, max) { return powerUp(null, null, p.scaleMatchLength(flags(attrs), min, max, [base, 100], [bonus, 0])); },
  684. [121](attrs, types, hp, atk, rcv) { return powerUp(flags(attrs), flags(types), p.mul({ hp, atk, rcv })); },
  685. [122](percent, attrs, types, atk, rcv) { return powerUp(flags(attrs), flags(types), p.mul({ atk, rcv }), c.hp(0, percent)); },
  686. [123](percent, attrs, types, atk, rcv) { return powerUp(flags(attrs), flags(types), p.mul({ atk, rcv }), c.hp(percent, 100)); },
  687. [124](attrs1, attrs2, attrs3, attrs4, attrs5, min, mul, bonus) {
  688. const attrs = [attrs1, attrs2, attrs3, attrs4, attrs5].filter(Boolean);
  689. return powerUp(null, null, p.scaleMatchAttrs(attrs.map(flags), min, bonus ? attrs.length : min, [mul, 100], [bonus, 0]));
  690. },
  691. [125](mon1, mon2, mon3, mon4, mon5, hp, atk, rcv) { return powerUp(null, null, p.mul({ hp, atk, rcv }), c.compo('card', [mon1, mon2, mon3, mon4, mon5].filter(Boolean))); },
  692. [126](attrs, turns, _, percent) { return activeTurns(turns, orbDropIncrease(v.percent(percent), flags(attrs))); },
  693. [127](cols1, attrs1, cols2, attrs2) {
  694. return fixedOrbs(
  695. { to: flags(attrs1), type: 'col', positions: flags(cols1) },
  696. { to: flags(attrs2), type: 'col', positions: flags(cols2) }
  697. );
  698. },
  699. [128](rows1, attrs1, rows2, attrs2) {
  700. return fixedOrbs(
  701. { to: flags(attrs1), type: 'row', positions: flags(rows1) },
  702. { to: flags(attrs2), type: 'row', positions: flags(rows2) }
  703. );
  704. },
  705. [129](attrs, types, hp, atk, rcv, rAttrs, rPercent) {
  706. return [
  707. powerUp(flags(attrs), flags(types), p.mul({ hp, atk, rcv })),
  708. rPercent && reduceDamage(flags(rAttrs), v.percent(rPercent)) || null
  709. ];
  710. },
  711. [130](percent, attrs, types, atk, rcv, rAttrs, rPercent) {
  712. return [
  713. powerUp(flags(attrs), flags(types), p.mul({ atk, rcv }), c.hp(0, percent)),
  714. rPercent && reduceDamage(flags(rAttrs), v.percent(rPercent), c.hp(0, percent)) || null
  715. ];
  716. },
  717. [131](percent, attrs, types, atk, rcv, rAttrs, rPercent) {
  718. return [
  719. powerUp(flags(attrs), flags(types), p.mul({ atk, rcv }), c.hp(percent, 100)),
  720. rPercent && reduceDamage(flags(rAttrs), v.percent(rPercent), c.hp(percent, 100)) || null
  721. ];
  722. },
  723. [132](turns, time, percent) { return activeTurns(turns, timeExtend(time ? v.constant(time / 10) : v.percent(percent))); },
  724. [133](attrs, types, atk, rcv) { return powerUp(flags(attrs), flags(types), p.mul({ atk, rcv }), c.useSkill()); },
  725. [136](attrs1, hp1, atk1, rcv1, attrs2, hp2, atk2, rcv2) {
  726. return [
  727. powerUp(flags(attrs1), null, p.mul({ hp: hp1, atk: atk1, rcv: rcv1 })),
  728. powerUp(flags(attrs2), null, p.mul({ hp: hp2, atk: atk2, rcv: rcv2 })),
  729. ];
  730. },
  731. [137](types1, hp1, atk1, rcv1, types2, hp2, atk2, rcv2) {
  732. return [
  733. powerUp(null, flags(types1), p.mul({ hp: hp1, atk: atk1, rcv: rcv1 })),
  734. powerUp(null, flags(types2), p.mul({ hp: hp2, atk: atk2, rcv: rcv2 })),
  735. ];
  736. },
  737. [138](...ids) { return ids.flatMap(id => this.parser(id)); },
  738. [139](attrs, types, percent1, less1, mul1, percent2, less2, mul2) {
  739. return [
  740. powerUp(flags(attrs), flags(types), p.mul({ atk: mul1 }), less1 ? c.hp(0, percent1) : c.hp(percent1, 100)),
  741. powerUp(flags(attrs), flags(types), p.mul({ atk: mul2 }), less1 ?
  742. (less2 ? c.hp(percent1, percent2) : c.hp(percent2, 100)) :
  743. (less2 ? c.hp(0, percent2) : c.hp(percent2, percent1))
  744. ),
  745. ];
  746. },
  747. [140](attrs) { return setOrbState(flags(attrs), 'enhanced'); },
  748. [141](count, to, exclude) { return generateOrbs(flags(to), flags(exclude), count); },
  749. [142](turns, attr) { return activeTurns(turns, changeAttr('self', attr)); },
  750. [143](mul, dmgAttr) { return damageEnemy('all', dmgAttr ?? 0, v.xTeamHP(mul)); },
  751. [144](teamAttrs, mul, single, dmgAttr) { return damageEnemy(single ? 'single' : 'all', dmgAttr, v.xTeamATK(flags(teamAttrs), mul)); },
  752. [145](mul) { return heal(v.xTeamRCV(mul)); },
  753. [146](turns) { return skillBoost(v.constant(turns)); },
  754. [148](percent) { return rateMultiply(v.percent(percent), 'exp'); },
  755. [149](mul) { return powerUp(null, null, p.mul({ rcv: mul }), c.exact('match-length', 4, [Attributes.Heart])); },
  756. [150](_, mul) { return powerUp(null, null, p.mul({ atk: mul }), c.exact('match-length', 5, 'enhanced')); },
  757. [151](mul, _, percent) {
  758. return [
  759. powerUp(null, null, p.scaleCross([{ single: true, attr: Attributes.Heart, mul }]), undefined, v.percent(percent)),
  760. ];
  761. },
  762. [152](attrs) { return setOrbState(flags(attrs), 'locked'); },
  763. [153](attr) { return changeAttr('opponent', attr); },
  764. [154](from, to) { return changeOrbs(fromTo(flags(from), flags(to))); },
  765. [155](attrs, types, hp, atk, rcv) { return powerUp(flags(attrs), flags(types), p.mul({ hp, atk, rcv }), c.multiplayer()); },
  766. [156](turns, awoken1, awoken2, awoken3, type, mul) {
  767. return activeTurns(turns, type === 2 ?
  768. powerUp(null, null, p.scaleAwakenings([awoken1, awoken2, awoken3].filter(Boolean), mul)) :
  769. reduceDamage('all', v.percentAwakenings([awoken1, awoken2, awoken3].filter(Boolean), mul))
  770. );
  771. },
  772. [157](attr1, mul1, attr2, mul2, attr3, mul3) {
  773. return powerUp(null, null, p.scaleCross([
  774. { single: false, attr: attr1, mul: mul1 },
  775. { single: false, attr: attr2, mul: mul2 },
  776. { single: false, attr: attr3, mul: mul3 }
  777. ].filter(cross => cross.mul)));
  778. },
  779. [158](len, attrs, types, atk, hp, rcv) {
  780. return [
  781. minMatch(len),
  782. powerUp(flags(attrs), flags(types), p.mul({ hp, atk, rcv }))
  783. ];
  784. },
  785. [159](attrs, min, base, bonus, max) { return powerUp(null, null, p.scaleMatchLength(flags(attrs), min, max, [base, 100], [bonus, 0])); },
  786. [160](turns, combo) { return activeTurns(turns, addCombo(combo)); },
  787. [161](percent) { return gravity(v.xMaxHP(percent)); },
  788. [162]() { return board7x6(); },
  789. [163](attrs, types, hp, atk, rcv, rAttrs, rPercent) {
  790. return [
  791. noSkyfall(),
  792. powerUp(flags(attrs), flags(types), p.mul({ hp, atk, rcv })),
  793. rPercent && reduceDamage(flags(rAttrs), v.percent(rPercent)) || null,
  794. ];
  795. },
  796. [164](attrs1, attrs2, attrs3, attrs4, min, atk, rcv, bonus) {
  797. const attrs = [attrs1, attrs2, attrs3, attrs4].filter(Boolean);
  798. return powerUp(null, null, p.scaleMatchAttrs(attrs.map(flags), min, attrs.length, [atk, rcv], [bonus, bonus]));
  799. },
  800. [165](attrs, min, baseAtk, baseRcv, bonusAtk, bonusRcv, incr) { return powerUp(null, null, p.scaleAttrs(flags(attrs), min, min + (incr ?? 0), [baseAtk, baseRcv], [bonusAtk, bonusRcv])); },
  801. [166](min, baseAtk, baseRcv, bonusAtk, bonusRcv, max) { return powerUp(null, null, p.scaleCombos(min, max, [baseAtk, baseRcv], [bonusAtk, bonusRcv])); },
  802. [167](attrs, min, baseAtk, baseRcv, bonusAtk, bonusRcv, max) { return powerUp(null, null, p.scaleMatchLength(flags(attrs), min, max, [baseAtk, baseRcv], [bonusAtk, bonusRcv])); },
  803. [169](combo, mul, percent) { return powerUp(null, null, p.scaleCombos(combo, combo, [mul, 100], [0, 0]), undefined, v.percent(percent)); },
  804. [170](attrs, min, mul, percent) { return powerUp(null, null, p.scaleAttrs(flags(attrs), min, min, [mul, 100], [0, 0]), undefined, v.percent(percent)); },
  805. [171](attrs1, attrs2, attrs3, attrs4, min, mul, percent) {
  806. const attrs = [attrs1, attrs2, attrs3, attrs4].filter(Boolean);
  807. return powerUp(null, null, p.scaleMatchAttrs(attrs.map(flags), min, min, [mul, 0], [0, 0]), undefined, v.percent(percent));
  808. },
  809. [172]() { return setOrbState(null, 'unlocked'); },
  810. [173](turns, attrAbsorb, _, damageAbsorb) {
  811. return activeTurns(turns, voidEnemyBuff(
  812. [
  813. attrAbsorb && 'attr-absorb',
  814. damageAbsorb && 'damage-absorb'
  815. ].filter((buff) => typeof buff === 'string')
  816. ));
  817. },
  818. [175](series1, series2, series3, hp, atk, rcv) { return powerUp(null, null, p.mul({ hp, atk, rcv }), c.compo('series', [series1, series2, series3].filter(Boolean))); },
  819. [176](row1, row2, row3, row4, row5, attrs) {
  820. return fixedOrbs(
  821. { to: [attrs ?? 0], type: 'shape', positions: [row1, row2, row3, row4, row5].map(row=>flags(row)) }
  822. );
  823. },
  824. [177](_0, _1, _2, _3, _4, remains, mul) {
  825. return [
  826. noSkyfall(),
  827. powerUp(null, null, p.mul({ atk: mul }), c.remainOrbs(remains))
  828. ];
  829. },
  830. [178](time, attrs, types, hp, atk, rcv) {
  831. return [
  832. fixedTime(time),
  833. powerUp(flags(attrs), flags(types), p.mul({ hp, atk, rcv }))
  834. ];
  835. },
  836. [179](turns, value, percent, bind, awokenBind) {
  837. return [
  838. (bind || awokenBind) ? unbind(bind ?? 0, awokenBind ?? 0) : null,
  839. activeTurns(turns, autoHealBuff(value ? v.constant(value) : v.xMaxHP(percent)))
  840. ].filter(Boolean);
  841. },
  842. [180](turns, percent) { return activeTurns(turns, orbDropIncrease(v.percent(percent), 'enhanced')); },
  843. [182](attrs, len, mul, percent) { return powerUp(null, null, p.scaleMatchLength(flags(attrs), len, len, [mul, 100], [0, 0]), undefined, v.percent(percent)); },
  844. [183](attrs, types, percent1, atk1, rcv1, percent2, atk2, rcv2) {
  845. return [
  846. powerUp(flags(attrs), flags(types), p.mul({ atk: atk1, rcv: rcv1 }), c.hp(percent1, 100)),
  847. powerUp(flags(attrs), flags(types), p.mul({ atk: atk2, rcv: rcv2 }), c.hp(0, percent2 || percent1)),
  848. ];
  849. },
  850. [184](turns) { return activeTurns(turns, noSkyfall()); },
  851. [185](time, attrs, types, hp, atk, rcv) {
  852. return [
  853. timeExtend(v.constant(time / 100)),
  854. powerUp(flags(attrs), flags(types), p.mul({ hp, atk, rcv })),
  855. ];
  856. },
  857. [186](attrs, types, hp, atk, rcv) {
  858. return [
  859. board7x6(),
  860. powerUp(flags(attrs), flags(types), p.mul({ hp, atk, rcv })),
  861. ];
  862. },
  863. [188](value) {
  864. return damageEnemy('single', 'fixed', v.constant(value));
  865. },
  866. [195](percent) {
  867. return selfHarm(percent ? v.xHP(percent) : v.constantTo(1));
  868. },
  869. [196](matches) {
  870. return unbind(0,0,matches);
  871. },
  872. [218](turns) { return skillBoost(v.constant(-turns)); },
  873. };
  874. //将内容添加到代码片段
  875. DocumentFragment.prototype.ap = function(arg)
  876. {
  877. if (Array.isArray(arg)) //数组,递归自身
  878. {
  879. arg.forEach(element=>this.ap(element));
  880. }
  881. else if (arg instanceof Node) //属于Node的直接添加
  882. {
  883. this.appendChild(arg);
  884. }
  885. else //其他内容的转换为文字添加
  886. {
  887. this.appendChild(document.createTextNode(arg));
  888. }
  889. return this;
  890. }
  891. //将数组和分隔符添加到一个代码片段,类似join
  892. Array.prototype.nodeJoin = function(separator)
  893. {
  894. const frg = document.createDocumentFragment();
  895. this.forEach((item, idx, arr)=>{
  896. frg.ap(item);
  897. if (idx < (arr.length - 1) && separator != null)
  898. frg.ap(separator instanceof Node ? separator.cloneNode(true) : separator);
  899. });
  900. return frg;
  901. }
  902. //按住Ctrl点击技能在控制台输出技能的对象
  903. function showParsedSkill(event) {
  904. if (event.ctrlKey) {
  905. console.log(this.skill);
  906. }
  907. }
  908. function renderSkillEntry(skills)
  909. {
  910. const ul = document.createElement("ul");
  911. ul.className = "card-skill-list";
  912. skills.forEach(skill=>{
  913. const li = ul.appendChild(document.createElement("li"));
  914. li.className = skill.kind;
  915. li.appendChild(renderSkill(skill));
  916. li.skill = skill;
  917. li.addEventListener("click", showParsedSkill);
  918. });
  919. return ul;
  920. }
  921. function renderSkill(skill, option = {})
  922. {
  923. const frg = document.createDocumentFragment();
  924. if (typeof localTranslating == "undefined") return frg;
  925. const tsp = localTranslating.skill_parse;
  926. function createIcon(iconType, className){
  927. const idoc = document.createElement("icon");
  928. idoc.className = `icon-skill${className ? ` ${className}` : ''}`;
  929. idoc.setAttribute("data-icon-type", iconType);
  930. return idoc;
  931. }
  932. if (Array.isArray(skill))
  933. {
  934. frg.ap(skill.map(_skill=>renderSkill(_skill)));
  935. return frg;
  936. }
  937. switch (skill.kind) {
  938. case SkillKinds.Unknown: {
  939. let dict = {
  940. type: skill.kind
  941. };
  942. frg.ap(tsp.skill.unknown(dict));
  943. break;
  944. }
  945. case SkillKinds.ActiveTurns: { //有回合的行动
  946. let turns = skill.turns, actionSkill = skill.skill;
  947. let dict = {
  948. turns: turns,
  949. actionSkill: renderSkill(actionSkill),
  950. };
  951. frg.ap(tsp.skill.active_turns(dict));
  952. break;
  953. }
  954. case SkillKinds.RandomSkills: { //随机技能
  955. let skills = skill.skills;
  956. const ul = document.createElement("ul");
  957. ul.className = "random-active-skill";
  958. skills.forEach(subSkills=>{
  959. const li = ul.appendChild(document.createElement("li"));
  960. li.appendChild(renderSkillEntry(subSkills));
  961. });
  962. let dict = {
  963. skills: ul,
  964. };
  965. frg.ap(tsp.skill.random_skills(dict));
  966. break;
  967. }
  968. case SkillKinds.Delay: { //威吓
  969. let dict = {
  970. icon: createIcon(skill.kind),
  971. };
  972. frg.ap(tsp.skill.delay(dict));
  973. break;
  974. }
  975. case SkillKinds.MassAttack: { //全体攻击
  976. let dict = {
  977. icon: createIcon(skill.kind),
  978. };
  979. frg.ap(tsp.skill.mass_attack(dict));
  980. break;
  981. }
  982. case SkillKinds.LeaderChange: { //切换队长
  983. let dict = {
  984. icon: createIcon(skill.kind),
  985. };
  986. frg.ap(tsp.skill.leader_change(dict));
  987. break;
  988. }
  989. case SkillKinds.NoSkyfall: { //无天降
  990. let dict = {
  991. icon: createIcon(skill.kind),
  992. };
  993. frg.ap(tsp.skill.no_skyfall(dict));
  994. break;
  995. }
  996. case SkillKinds.SelfHarm: { //主动自残
  997. let value = skill.value;
  998. let dict = {
  999. icon: createIcon("heal", "hp-decr"),
  1000. value: renderValue(value, {percent: true}),
  1001. stats: tsp.stats.hp(),
  1002. };
  1003. frg.ap(tsp.skill.self_harm(dict));
  1004. break;
  1005. }
  1006. case SkillKinds.Heal: { //主动回血buff
  1007. let value = skill.value;
  1008. let dict = {
  1009. icon: createIcon("heal", "hp-incr"),
  1010. //icon: createIcon("auto-heal"),
  1011. value: renderValue(value, {unit: tsp.unit.point, percent: value.kind == SkillValueKind.xRCV ? false : true}),
  1012. stats: tsp.stats.hp(),
  1013. };
  1014. frg.ap(tsp.skill.heal(dict));
  1015. break;
  1016. }
  1017. case SkillKinds.AutoHealBuff: { //自动回血buff
  1018. let dict = {
  1019. icon: createIcon("auto-heal"),
  1020. value: renderValue(skill.value, {unit: tsp.unit.point, percent: true}),
  1021. stats: tsp.stats.hp(),
  1022. };
  1023. frg.ap(tsp.skill.auto_heal_buff(dict));
  1024. break;
  1025. }
  1026. case SkillKinds.DefenseBreak: { //破防
  1027. let dict = {
  1028. icon: createIcon(skill.kind),
  1029. value: renderValue(skill.value, {percent: true}),
  1030. };
  1031. frg.ap(tsp.skill.defense_break(dict));
  1032. break;
  1033. }
  1034. case SkillKinds.Poison: { //毒
  1035. let dict = {
  1036. icon: createIcon(skill.kind),
  1037. belong_to: tsp.target.self(),
  1038. target: tsp.target.enemy(),
  1039. stats: tsp.stats.hp(),
  1040. value: renderValue(skill.value),
  1041. };
  1042. frg.ap(tsp.skill.poison(dict));
  1043. break;
  1044. }
  1045. case SkillKinds.TimeExtend: { //时间变化buff
  1046. let value = skill.value;
  1047. let dict = {
  1048. icon: createIcon("status-time", SkillValue.isLess(value) ? "time-decr" : "time-incr"),
  1049. value: renderValue(value, { unit:tsp.unit.seconds, plusSign: value.kind != SkillValueKind.Percent, percent: SkillValue.isLess(value) }),
  1050. };
  1051. frg.ap(tsp.skill.time_extend(dict));
  1052. break;
  1053. }
  1054. case SkillKinds.FollowAttack: { //队长技追打
  1055. let dict = {
  1056. //icon: createIcon("follow_attack"),
  1057. belong_to: tsp.target.self(),
  1058. target: tsp.target.enemy(),
  1059. value: renderValue(skill.value),
  1060. };
  1061. frg.ap(tsp.skill.follow_attack(dict));
  1062. break;
  1063. }
  1064. case SkillKinds.AutoHeal: { //队长技自动回血
  1065. let dict = {
  1066. icon: createIcon(skill.kind),
  1067. belong_to: tsp.target.self(),
  1068. value: renderValue(skill.value),
  1069. stats: tsp.stats.hp(),
  1070. };
  1071. frg.ap(tsp.skill.auto_heal(dict));
  1072. break;
  1073. }
  1074. case SkillKinds.CTW: { //时间暂停
  1075. let dict = {
  1076. icon: createIcon(skill.kind),
  1077. value: renderValue(skill.value, { unit: tsp.unit.seconds }),
  1078. };
  1079. frg.ap(tsp.skill.ctw(dict));
  1080. break;
  1081. }
  1082. case SkillKinds.Gravity: { //重力
  1083. let dict = {
  1084. icon: createIcon(skill.kind),
  1085. target: tsp.target.enemy(),
  1086. value: renderValue(skill.value, { percent:true }),
  1087. };
  1088. frg.ap(tsp.skill.gravity(dict));
  1089. break;
  1090. }
  1091. case SkillKinds.Resolve: { //根性
  1092. let prob = skill.prob;
  1093. let dict = {
  1094. icon: createIcon(skill.kind),
  1095. stats: renderStat('hp'),
  1096. value: renderValue(skill.min, { percent:true }),
  1097. prob: prob.value < 1 ? tsp.value.prob({value: renderValue(prob, { percent:true })}) : null,
  1098. };
  1099. frg.ap(tsp.skill.resolve(dict));
  1100. break;
  1101. }
  1102. case SkillKinds.DamageEnemy: { //大炮和固伤
  1103. let attr = skill.attr, target = skill.target, damage = skill.damage;
  1104. if (attr == null) break; //没有属性时,编号为0的空技能
  1105. dict = {
  1106. target: target === 'all' ? tsp.target.enemy_all() : target === 'single' ? tsp.target.enemy_one() : tsp.target.enemy_attr({attr: renderAttrs(target)}),
  1107. damage: renderValue(damage, {unit: tsp.unit.point}),
  1108. attr: renderAttrs(attr, {affix: (attr === 'self' || attr === 'fixed') ? false : true})
  1109. };
  1110. frg.ap(tsp.skill.damage_enemy(dict));
  1111. break;
  1112. }
  1113. case SkillKinds.Unbind: { //解封
  1114. let normal = skill.normal, awakenings = skill.awakenings, matches = skill.matches;
  1115. let effects = [];
  1116. if (normal)
  1117. effects.push(tsp.skill.unbind_normal({icon: createIcon("unbind-normal"), turns: normal}));
  1118. if (awakenings)
  1119. effects.push(tsp.skill.unbind_awakenings({icon: createIcon("unbind-awakenings"), turns: awakenings}));
  1120. if (matches)
  1121. effects.push(tsp.skill.unbind_matches({icon: createIcon("unbind-matches"), turns: matches}));
  1122. frg.ap(effects.nodeJoin(tsp.word.comma()));
  1123. break;
  1124. }
  1125. case SkillKinds.BoardChange: { //洗版
  1126. const attrs = skill.attrs;
  1127. dict = {
  1128. attrs: renderOrbs(attrs),
  1129. };
  1130. let board = new Board(attrs);
  1131. frg.ap(tsp.skill.board_change(dict));
  1132. frg.ap(board.toTable());
  1133. break;
  1134. }
  1135. case SkillKinds.SkillBoost: { //溜
  1136. const value = skill.value;
  1137. let dict = {
  1138. icon: createIcon(skill.kind, SkillValue.isLess(skill.value) ? "boost-decr" : "boost-incr"),
  1139. turns: renderValue(value, { unit:tsp.unit.turns, plusSign:true }),
  1140. };
  1141. frg.ap(tsp.skill.skill_boost(dict));
  1142. break;
  1143. }
  1144. case SkillKinds.AddCombo: { //+C
  1145. const value = skill.value;
  1146. let icon = createIcon(skill.kind);
  1147. icon.setAttribute("data-add-combo", value);
  1148. let dict = {
  1149. icon: icon,
  1150. value: value,
  1151. };
  1152. frg.ap(tsp.skill.add_combo(dict));
  1153. break;
  1154. }
  1155. case SkillKinds.FixedTime: { //固定手指
  1156. const value = skill.value;
  1157. let dict = {
  1158. icon: createIcon(skill.kind),
  1159. value: renderValue(value, { unit: tsp.unit.seconds }),
  1160. };
  1161. frg.ap(tsp.skill.fixed_time(dict));
  1162. break;
  1163. }
  1164. case SkillKinds.MinMatchLength: { //最低匹配长度
  1165. const value = skill.value;
  1166. let dict = {
  1167. icon: createIcon(skill.kind),
  1168. value: value,
  1169. };
  1170. frg.ap(tsp.skill.min_match_length(dict));
  1171. break;
  1172. }
  1173. case SkillKinds.DropRefresh: { //刷版
  1174. let dict = {
  1175. icon: createIcon(skill.kind),
  1176. };
  1177. frg.ap(tsp.skill.drop_refresh(dict));
  1178. break;
  1179. }
  1180. case SkillKinds.Drum: { //太鼓达人音效
  1181. let dict = {
  1182. //icon: createIcon(skill.kind),
  1183. };
  1184. frg.ap(tsp.skill.drum(dict));
  1185. break;
  1186. }
  1187. case SkillKinds.Board7x6: { //76版
  1188. let dict = {
  1189. icon: createIcon(skill.kind),
  1190. };
  1191. frg.ap(tsp.skill.board7x6(dict));
  1192. break;
  1193. }
  1194. case SkillKinds.Vampire: { //吸血
  1195. let attr = skill.attr, damage = skill.damage, heal = skill.heal;
  1196. dict = {
  1197. icon: createIcon("heal", "hp-incr"),
  1198. target: tsp.target.enemy_one(),
  1199. damage: renderValue(damage),
  1200. attr: renderAttrs(attr, {affix: (attr === 'self' || attr === 'fixed') ? false : true}),
  1201. heal: renderValue(heal, {percent: true}),
  1202. };
  1203. frg.ap(tsp.skill.vampire(dict));
  1204. break;
  1205. }
  1206. case SkillKinds.CounterAttack: { //反击
  1207. let attr = skill.attr, prob = skill.prob, value = skill.value;
  1208. dict = {
  1209. icon: createIcon(skill.kind),
  1210. target: tsp.target.enemy(),
  1211. prob: prob.value < 1 ? tsp.value.prob({value: renderValue(prob, { percent:true })}) : null,
  1212. value: renderValue(value),
  1213. attr: renderAttrs(attr),
  1214. };
  1215. frg.ap(tsp.skill.counter_attack(dict));
  1216. break;
  1217. }
  1218. case SkillKinds.ChangeOrbs: { //珠子变换
  1219. let changes = skill.changes;
  1220. let changesDocument = [];
  1221. for (const change of changes)
  1222. {
  1223. dict = {
  1224. from: renderOrbs(change.from),
  1225. to: renderOrbs(change.to),
  1226. };
  1227. changesDocument.push(tsp.skill.change_orbs(dict));
  1228. }
  1229. frg.ap(changesDocument.nodeJoin(tsp.word.comma()));
  1230. break;
  1231. }
  1232. case SkillKinds.GenerateOrbs: { //产生珠子
  1233. let to = skill.to, exclude = skill.exclude, count = skill.count;
  1234. dict = {
  1235. exclude: exclude.length ? tsp.word.affix_exclude({cotent: renderOrbs(exclude)}) : void 0,
  1236. to: renderOrbs(to),
  1237. count: count,
  1238. };
  1239. frg.ap(tsp.skill.generate_orbs(dict));
  1240. break;
  1241. }
  1242. case SkillKinds.FixedOrbs: { //固定位置产生珠子
  1243. let generates = skill.generates;
  1244. let slight_pause = tsp.word.slight_pause().textContent;
  1245. let changesDocument = [];
  1246. //let board = new Array(5).fill(null).map(i=>new Array(6).fill(null));
  1247. let board = new Board();
  1248. function posSplit(pos, max)
  1249. {
  1250. return {sequence: pos.filter(n=>n<=2).map(n=>n+1), reverse: pos.filter(n=>n>=3).reverse().map(n=>max-n)};
  1251. }
  1252. for (const generate of generates)
  1253. {
  1254. let _to = generate.to?.[0];
  1255. dict = {
  1256. to: renderOrbs(generate.to),
  1257. };
  1258. if (generate.type == 'shape')
  1259. {
  1260. dict.position = tsp.position.shape();
  1261. board.setShape(generate.positions, _to);
  1262. }else
  1263. {
  1264. let posFrgs = [];
  1265. if (generate.positions.length == 0) continue;
  1266. if (generate.type == 'row')
  1267. {
  1268. const pos = posSplit(generate.positions, 5);
  1269. if (pos.sequence.length) posFrgs.push(tsp.position.top({pos: pos.sequence.join(slight_pause)}));
  1270. if (pos.reverse.length) posFrgs.push(tsp.position.bottom({pos: pos.reverse.join(slight_pause)}));
  1271. board.setRow(generate.positions, _to);
  1272. }else
  1273. {
  1274. const pos = posSplit(generate.positions, 6);
  1275. if (pos.sequence.length) posFrgs.push(tsp.position.left({pos: pos.sequence.join(slight_pause)}));
  1276. if (pos.reverse.length) posFrgs.push(tsp.position.right({pos: pos.reverse.join(slight_pause)}));
  1277. board.setColumn(generate.positions, _to);
  1278. }
  1279. dict.position = posFrgs.nodeJoin(tsp.word.slight_pause());
  1280. }
  1281. changesDocument.push(tsp.skill.fixed_orbs(dict));
  1282. }
  1283. frg.ap(changesDocument.nodeJoin(tsp.word.comma()));
  1284. frg.ap(board.toTable());
  1285. break;
  1286. }
  1287. /*
  1288. case SkillKinds.OrbDropIncrease: {
  1289. const { attrs, value } = skill as Skill.OrbDropIncrease;
  1290. let attrElems: React.ReactNode[];
  1291. if (attrs === 'enhanced')
  1292. attrElems = [<Asset assetId="status-orb-enhanced" className="CardSkill-icon" key="enhanced" />];
  1293. else
  1294. attrElems = renderOrbs(attrs);
  1295. attrElems = attrElems.map((elem, i) => (
  1296. <AssetBox className="CardSkill-icon-box" key={i}>
  1297. {elem}
  1298. <Asset assetId="overlay-drop" className="CardSkill-icon" />
  1299. </AssetBox>
  1300. ));
  1301. return (
  1302. <span className="CardSkill-skill">
  1303. {attrElems}
  1304. {renderValue(value)}
  1305. </span>
  1306. );
  1307. }
  1308. case SkillKinds.VoidEnemyBuff: {
  1309. const { buffs } = skill as Skill.VoidEnemyBuff;
  1310. return (
  1311. <span className="CardSkill-skill">{
  1312. buffs.map(buff => {
  1313. switch (buff) {
  1314. case 'attr-absorb': return (
  1315. <AssetBox className="CardSkill-icon-box" key={buff}>
  1316. <Asset assetId="status-all-attrs" className="CardSkill-icon" />
  1317. <Asset assetId="overlay-heal" className="CardSkill-icon" />
  1318. <Asset assetId="overlay-cross" className="CardSkill-icon" style={{ opacity: 0.75 }} />
  1319. </AssetBox>
  1320. );
  1321. case 'damage-absorb': return (
  1322. <AssetBox className="CardSkill-icon-box" key={buff}>
  1323. <Asset assetId="status-damage-absorb" className="CardSkill-icon" />
  1324. <Asset assetId="overlay-cross" className="CardSkill-icon" style={{ opacity: 0.75 }} />
  1325. </AssetBox>
  1326. );
  1327. }
  1328. })
  1329. } </span>
  1330. );
  1331. }
  1332. case SkillKinds.ChangeAttribute: {
  1333. const { attr, target } = skill as Skill.ChangeAttribute;
  1334. return (
  1335. <span className="CardSkill-skill">
  1336. {target === 'self' && 'Self'}
  1337. {target === 'opponent' && 'enemy'}
  1338. &nbsp;&rArr; {renderAttrs(attr)}
  1339. </span>
  1340. );
  1341. }
  1342. case SkillKinds.SetOrbState: {
  1343. const { orbs, state } = skill as Skill.SetOrbState;
  1344. let orbElems: React.ReactNode[];
  1345. if (!orbs) {
  1346. orbElems = [<Asset assetId="orb-blind" className="CardSkill-icon" key="all" />];
  1347. } else {
  1348. orbElems = renderOrbs(orbs);
  1349. }
  1350. return (
  1351. <span className="CardSkill-skill">
  1352. {(state === 'enhanced' || state === 'locked') && orbElems}
  1353. {state === 'unlocked' && orbElems.map((elem, i) => (
  1354. <AssetBox className="CardSkill-icon-box" key={i}>
  1355. {elem}
  1356. <Asset assetId="orb-locked" className="CardSkill-icon" />
  1357. </AssetBox>
  1358. ))}
  1359. &rArr;
  1360. {state === 'enhanced' && orbElems.map((elem, i) => (
  1361. <AssetBox className="CardSkill-icon-box" key={i}>
  1362. {elem}
  1363. <Asset assetId="orb-enhanced" className="CardSkill-icon" />
  1364. </AssetBox>
  1365. ))}
  1366. {state === 'locked' && orbElems.map((elem, i) => (
  1367. <AssetBox className="CardSkill-icon-box" key={i}>
  1368. {elem}
  1369. <Asset assetId="orb-locked" className="CardSkill-icon" />
  1370. </AssetBox>
  1371. ))}
  1372. {state === 'unlocked' && orbElems}
  1373. </span>
  1374. );
  1375. }
  1376. case SkillKinds.RateMultiply: {
  1377. const { rate, value } = skill as Skill.RateMultiply;
  1378. return (
  1379. <span className="CardSkill-skill">
  1380. {rate === 'drop' && 'drop rate'}
  1381. {rate === 'coin' && 'coins'}
  1382. {rate === 'exp' && 'EXP'}
  1383. &nbsp;&times;&nbsp;
  1384. {renderValue(value)}
  1385. </span>
  1386. );
  1387. }
  1388. case SkillKinds.ReduceDamage: {
  1389. const { attrs, percent, condition } = skill as Skill.ReduceDamage;
  1390. return (
  1391. <span className="CardSkill-skill">
  1392. {!!condition && <>{renderCondition(condition)} &rArr; </>}
  1393. <Asset assetId="status-def" className="CardSkill-icon" />
  1394. {(Array.isArray(attrs) && !isEqual(attrs, Attributes.all())) && renderAttrs(attrs)}
  1395. {renderValue(percent)}
  1396. </span>
  1397. );
  1398. }
  1399. case SkillKinds.PowerUp: {
  1400. const { attrs, types, condition, value, reduceDamage } = skill as Skill.PowerUp;
  1401. const targets: React.ReactNode[] = [];
  1402. if (attrs && !isEqual(attrs, Attributes.all())) targets.push(...renderAttrs(attrs || []));
  1403. if (types) targets.push(...renderTypes(types || []));
  1404. return (
  1405. <span className="CardSkill-skill">
  1406. {condition && <>{renderCondition(condition)} &rArr; </>}
  1407. {targets.length > 0 && <>{targets}</>}
  1408. {!!value && renderPowerUp(value)}
  1409. {!!reduceDamage && <>
  1410. <Asset assetId="status-def" className="CardSkill-icon" />
  1411. {renderValue(reduceDamage)}
  1412. </>}
  1413. </span>
  1414. );
  1415. }
  1416. */
  1417. default: {
  1418. console.log("未处理的技能类型",skill.kind, skill);
  1419. frg.ap(skill.kind);
  1420. }
  1421. }
  1422. return frg;
  1423. };
  1424. function renderStat(stat, option) {
  1425. const frg = document.createDocumentFragment();
  1426. if (typeof localTranslating == "undefined") return frg;
  1427. const tspt = localTranslating.skill_parse.stats;
  1428. if (tspt[stat])
  1429. frg.ap(tspt[stat](option));
  1430. else
  1431. {
  1432. console.log("未知状态类型",stat);
  1433. frg.ap(tspt.unknown({ type: stat }));
  1434. }
  1435. return frg;
  1436. }
  1437. function renderAttrs(attrs, option = {}) {
  1438. if (!Array.isArray(attrs))
  1439. attrs = [attrs ?? 0];
  1440. const frg = document.createDocumentFragment();
  1441. if (typeof localTranslating == "undefined") return frg;
  1442. const tsp = localTranslating.skill_parse;
  1443. const contentFrg = attrs.map(attr => {
  1444. const icon = document.createElement("icon");
  1445. icon.className = "attr";
  1446. icon.setAttribute("data-attr-icon",attr);
  1447. return tsp.attrs[attr]({icon: icon});
  1448. })
  1449. .nodeJoin(tsp.word.slight_pause());
  1450. frg.ap(option.affix ? tsp.word.affix_attr({cotent: contentFrg}) : contentFrg);
  1451. return frg;
  1452. }
  1453. function renderOrbs(attrs, option = {}) {
  1454. if (!Array.isArray(attrs))
  1455. attrs = [attrs ?? 0];
  1456. const frg = document.createDocumentFragment();
  1457. if (typeof localTranslating == "undefined") return frg;
  1458. const tsp = localTranslating.skill_parse;
  1459. const contentFrg = attrs.map(attr => {
  1460. const icon = document.createElement("icon");
  1461. icon.className = "orb";
  1462. icon.setAttribute("data-orb-icon",attr);
  1463. return tsp.orbs[attr]({icon: icon});
  1464. })
  1465. .nodeJoin(tsp.word.slight_pause());
  1466. frg.ap(option.affix ? tsp.word.affix_attr({cotent: contentFrg}) : contentFrg);
  1467. return frg;
  1468. }
  1469. /*
  1470. function renderTypes(types: Types | Types[]) {
  1471. if (!Array.isArray(types))
  1472. types = [types];
  1473. return types.map(type => <Asset assetId={`type-${type}`} key={type} className="CardSkill-icon" />);
  1474. }
  1475. function renderCondition(cond: SkillCondition) {
  1476. if (cond.hp) {
  1477. if (cond.hp.min === cond.hp.max)
  1478. return <>{renderStat('hp')} = {formatNumber(cond.hp.min * 100)}%</>;
  1479. else if (cond.hp.min === 0)
  1480. return <>{renderStat('hp')} &le; {formatNumber(cond.hp.max * 100)}%</>;
  1481. else if (cond.hp.max === 1)
  1482. return <>{renderStat('hp')} &ge; {formatNumber(cond.hp.min * 100)}%</>;
  1483. else
  1484. return <>{renderStat('hp')} &in; [{formatNumber(cond.hp.min * 100)}%, {formatNumber(cond.hp.max * 100)}%]</>;
  1485. } else if (cond.useSkill) {
  1486. return <>use skill</>;
  1487. } else if (cond.multiplayer) {
  1488. return <>in multiplayer</>;
  1489. } else if (cond.remainOrbs) {
  1490. return <>&le; {cond.remainOrbs.count} orbs remain</>;
  1491. } else if (cond.exact) {
  1492. if (cond.exact.type === 'combo') {
  1493. return <>= {cond.exact.value} combos</>;
  1494. } else if (cond.exact.type === 'match-length') {
  1495. return <>= {cond.exact.value} {cond.exact.attrs === 'enhanced' ? 'Enhanced' : renderAttrs(cond.exact.attrs)} orbs</>;
  1496. }
  1497. } else if (cond.compo) {
  1498. return <>{cond.compo.type} [{cond.compo.ids.join()}] in team</>;
  1499. }
  1500. return <>[ unknown condition ]</>;
  1501. }
  1502. function renderPowerUp(powerUp: SkillPowerUp) {
  1503. function renderStats(hp: number, atk: number, rcv: number, mul = true) {
  1504. const operator = mul ? <>&times;</> : <>+</>;
  1505. let list: Array<['hp' | 'atk' | 'rcv', number]> = [['hp', hp], ['atk', atk], ['rcv', rcv]];
  1506. list = list.filter(([, value]) => value !== (mul ? 1 : 0));
  1507. if (list.length === 0) return null;
  1508. if (list.every(([, value]) => value === list[0][1])) {
  1509. return <>
  1510. {list.map(([name], i) => <React.Fragment key={name}>{i !== 0 && ', '}{renderStat(name)}</React.Fragment>)}
  1511. &nbsp;{operator} {formatNumber(list[0][1])}
  1512. </>;
  1513. } else {
  1514. return <>
  1515. {list.map(([name, value], i) => (
  1516. <React.Fragment key={name}>
  1517. {i !== 0 ? '; ' : ''}
  1518. {renderStat(name)}
  1519. &nbsp;{operator} {formatNumber(value)}
  1520. </React.Fragment>
  1521. ))}
  1522. </>;
  1523. }
  1524. }
  1525. switch (powerUp.kind) {
  1526. case SkillPowerUpKind.Multiplier: {
  1527. const { hp, atk, rcv } = powerUp as SkillPowerUp.Mul;
  1528. return renderStats(hp, atk, rcv);
  1529. }
  1530. case SkillPowerUpKind.ScaleAttributes: {
  1531. const { attrs, min, max, baseAtk, baseRcv, bonusAtk, bonusRcv } = powerUp as SkillPowerUp.ScaleAttrs;
  1532. return <>
  1533. &ge; {min} of [{renderAttrs(attrs)}] &rArr; {renderStats(1, baseAtk, baseRcv)}
  1534. {max !== min && <> for each &le; {max} attributes: {renderStats(0, bonusAtk, bonusRcv, false)}</>}
  1535. </>;
  1536. }
  1537. case SkillPowerUpKind.ScaleCombos: {
  1538. const { min, max, baseAtk, baseRcv, bonusAtk, bonusRcv } = powerUp as SkillPowerUp.Scale;
  1539. return <>
  1540. &ge; {min} combos &rArr; {renderStats(1, baseAtk, baseRcv)}
  1541. {max !== min && <> for each &le; {max} combos: {renderStats(0, bonusAtk, bonusRcv, false)}</>}
  1542. </>;
  1543. }
  1544. case SkillPowerUpKind.ScaleMatchAttrs: {
  1545. const { matches, min, max, baseAtk, baseRcv, bonusAtk, bonusRcv } = powerUp as SkillPowerUp.ScaleMultiAttrs;
  1546. return <>
  1547. &ge; {min} matches of [{matches.map((attrs, i) =>
  1548. <React.Fragment key={i}>{i !== 0 && ', '}{renderAttrs(attrs)}</React.Fragment>
  1549. )}] &rArr; {renderStats(1, baseAtk, baseRcv)}
  1550. {max !== min && <> for each &le; {max} matches: {renderStats(0, bonusAtk, bonusRcv, false)}</>}
  1551. </>;
  1552. }
  1553. case SkillPowerUpKind.ScaleMatchLength: {
  1554. const { attrs, min, max, baseAtk, baseRcv, bonusAtk, bonusRcv } = powerUp as SkillPowerUp.ScaleAttrs;
  1555. return <>
  1556. &ge; {min} &times; {renderAttrs(attrs)} &rArr; {renderStats(1, baseAtk, baseRcv)}
  1557. {max !== min && <> for each &le; {max} orbs: {renderStats(0, bonusAtk, bonusRcv, false)}</>}
  1558. </>;
  1559. }
  1560. case SkillPowerUpKind.ScaleCross: {
  1561. const { crosses } = powerUp as SkillPowerUp.ScaleCross;
  1562. return crosses.map(({ single, attr, mul }, i) => <React.Fragment key={i}>
  1563. {i !== 0 && ', '}
  1564. {mul !== 1 && <>{renderStat('atk')} &times; {formatNumber(mul)} </>}
  1565. {single ? 'when' : 'for each'} cross of {renderAttrs(attr)}
  1566. </React.Fragment>);
  1567. }
  1568. case SkillPowerUpKind.ScaleAwakenings: {
  1569. const { awakenings, value } = powerUp as SkillPowerUp.ScaleAwakenings;
  1570. return <>
  1571. {renderStat('atk')} &times; {formatNumber(value - 1)} for each {awakenings.map(id =>
  1572. <Asset assetId={`awakening-${id}`} className="CardSkill-icon" key={id} />
  1573. )}
  1574. </>;
  1575. }
  1576. default:
  1577. return <>[ unknown power up ]</>;
  1578. }
  1579. }
  1580. */
  1581. function renderValue(_value, option = {}) {
  1582. const frg = document.createDocumentFragment();
  1583. if (typeof localTranslating == "undefined") return frg;
  1584. const tsp = localTranslating.skill_parse
  1585. const tspv = tsp.value;
  1586. const od = option.decimalDigits, os = option.plusSign;
  1587. let dict;
  1588. switch (_value.kind) {
  1589. case SkillValueKind.Percent: {
  1590. dict = {
  1591. value: option.percent ? (_value.value * 100).keepCounts(od,os) : _value.value.keepCounts(od,os),
  1592. };
  1593. frg.ap(
  1594. option.percent ?
  1595. tspv.mul_percent(dict) :
  1596. tspv.mul_times(dict)
  1597. );
  1598. break;
  1599. }
  1600. case SkillValueKind.Constant: {
  1601. dict = {
  1602. value: _value.value.keepCounts(od,os),
  1603. unit: option.unit ? option.unit() : undefined,
  1604. };
  1605. frg.ap(tspv.const(dict));
  1606. break;
  1607. }
  1608. case SkillValueKind.ConstantTo: {
  1609. dict = {
  1610. value: _value.value.keepCounts(od,os)
  1611. };
  1612. frg.ap(tspv.const_to(dict));
  1613. break;
  1614. }
  1615. case SkillValueKind.xMaxHP: {
  1616. dict = {
  1617. value: option.percent ? (_value.value * 100).keepCounts(od,os) : _value.value.keepCounts(od,os),
  1618. stats: renderStat('maxhp'),
  1619. };
  1620. frg.ap(
  1621. option.percent ?
  1622. tspv.mul_of_percent(dict) :
  1623. tspv.mul_of_times(dict)
  1624. );
  1625. break;
  1626. }
  1627. case SkillValueKind.xHP: {
  1628. dict = {
  1629. value: option.percent ? (_value.value * 100).keepCounts(od,os) : _value.value.keepCounts(od,os),
  1630. stats: renderStat('hp'),
  1631. };
  1632. frg.ap(
  1633. option.percent ?
  1634. tspv.mul_of_percent(dict) :
  1635. tspv.mul_of_times(dict)
  1636. );
  1637. break;
  1638. }
  1639. case SkillValueKind.xATK: {
  1640. dict = {
  1641. value: option.percent ? (_value.value * 100).keepCounts(od,os) : _value.value.keepCounts(od,os),
  1642. stats: renderStat('atk'),
  1643. };
  1644. frg.ap(
  1645. option.percent ?
  1646. tspv.mul_of_percent(dict) :
  1647. tspv.mul_of_times(dict)
  1648. );
  1649. break;
  1650. }
  1651. case SkillValueKind.xRCV: {
  1652. dict = {
  1653. value: option.percent ? (_value.value * 100).keepCounts(od,os) : _value.value.keepCounts(od,os),
  1654. stats: renderStat('rcv'),
  1655. };
  1656. frg.ap(
  1657. option.percent ?
  1658. tspv.mul_of_percent(dict) :
  1659. tspv.mul_of_times(dict)
  1660. );
  1661. break;
  1662. }
  1663. case SkillValueKind.xTeamHP: {
  1664. let value = _value.value;
  1665. dict = {
  1666. value: option.percent ? (value * 100).keepCounts(od,os) : value.keepCounts(od,os),
  1667. stats: renderStat('teamhp'),
  1668. };
  1669. frg.ap(
  1670. option.percent ?
  1671. tspv.mul_of_percent(dict) :
  1672. tspv.mul_of_times(dict)
  1673. );
  1674. break;
  1675. }
  1676. case SkillValueKind.xTeamRCV: {
  1677. dict = {
  1678. value: option.percent ? (_value.value * 100).keepCounts(od,os) : _value.value.keepCounts(od,os),
  1679. stats: renderStat('teamrcv'),
  1680. };
  1681. frg.ap(
  1682. option.percent ?
  1683. tspv.mul_of_percent(dict) :
  1684. tspv.mul_of_times(dict)
  1685. );
  1686. break;
  1687. }
  1688. case SkillValueKind.xTeamATK: {
  1689. let attrs = _value.attrs, value = _value.value;
  1690. dict = {
  1691. value: option.percent ? (value * 100).keepCounts(od,os) : value.keepCounts(od,os),
  1692. stats: renderStat('teamatk', {attrs: renderAttrs(attrs, {affix: true})}),
  1693. };
  1694. frg.ap(
  1695. option.percent ?
  1696. tspv.mul_of_percent(dict) :
  1697. tspv.mul_of_times(dict)
  1698. );
  1699. break;
  1700. }
  1701. case SkillValueKind.HPScale: {
  1702. let min = _value.min, max = _value.max;
  1703. dict = {
  1704. min: tspv.mul_of_times({value: min.keepCounts(od,os), stats:renderStat('atk')}),
  1705. max: tspv.mul_of_times({value: max.keepCounts(od,os), stats:renderStat('atk')}),
  1706. hp: renderStat('hp'),
  1707. };
  1708. frg.ap(tspv.hp_scale(dict));
  1709. break;
  1710. }
  1711. case SkillValueKind.RandomATK: {
  1712. let min = _value.min, max = _value.max;
  1713. dict = {
  1714. min: min.keepCounts(od,os),
  1715. atk: renderStat('atk'),
  1716. };
  1717. if (max != min)
  1718. {
  1719. dict.max = tsp.word.range_hyphen().ap(max.keepCounts(od,os));
  1720. }
  1721. frg.ap(tspv.random_atk(dict));
  1722. break;
  1723. }
  1724. /*
  1725. case SkillValueKind.xAwakenings: {
  1726. const { value, awakenings } = _value as SkillValue.WithAwakenings;
  1727. return <span>{formatNumber(value * 100)}% &times; each of {awakenings.map(id =>
  1728. <Asset assetId={`awakening-${id}`} className="CardSkill-icon" key={id} />
  1729. )}</span>;
  1730. }
  1731. */
  1732. default: {
  1733. console.log("未知数值类型",_value.kind, _value);
  1734. frg.ap(tspv.unknown({ type: _value.kind }));
  1735. }
  1736. }
  1737. return frg;
  1738. }

智龙迷城队伍图制作工具