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 66 kB

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

智龙迷城队伍图制作工具