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

智龙迷城队伍图制作工具