Pokemon
var _nature, _stats, _type, _gen; export var nature; export var stats; export var type; export var gen; export var loading = async()=>{ var a = await Promise.all( ['nature', 'stats', 'type', 'gen'].map(async v=>( await fetch(`/local--files/pokemon/${v}.json`) ).json()) ); [_nature, _stats, _type, _gen] = a; [nature, stats, type, gen] = a.map(v=>Object.assign({}, v)); return true; } export var chemistry = (version, ...key)=>{ var _ = {}; var __ = {}; var t = _type[version]; Object.keys(t).forEach(k=>{_[k]=1}) for(var k of key) { var a = t[k].chem; a[0].forEach(function(t) { _[t] = 0; }); a[50].forEach(function(t) { _[t] /= 2; }); a[200].forEach(function(t) { _[t] *= 2; }); } for(var k in _) { if(_[k]!==1) { __[_[k]] = __[_[k]] || []; __[_[k]].push(t[k].name); } } return {received: key.map(k=>t[k].name), chemistry: __}; } export var tool = {}; var tree = {a: 'ア', i: 'イ', u: 'ウ', e: 'エ', o: 'オ', k: {a: 'カ', i: 'キ', u: 'ク', e: 'ケ', o: 'コ',y: { a: 'キャ', i: 'キィ', u: 'キュ', e: 'キェ', o: 'キョ' }},s: {a: 'サ', i: 'シ', u: 'ス', e: 'セ', o: 'ソ',h: { a: 'シャ', i: 'シ', u: 'シュ', e: 'シェ', o: 'ショ' },y: { a: 'キャ', i: 'キィ', u: 'キュ', e: 'キェ', o: 'キョ' }},t: {a: 'タ', i: 'チ', u: 'ツ', e: 'テ', o: 'ト',h: { a: 'テャ', i: 'ティ', u: 'テュ', e: 'テェ', o: 'テョ' },y: { a: 'チャ', i: 'チィ', u: 'チュ', e: 'チェ', o: 'チョ' },s: { a: 'ツァ', i: 'ツィ', u: 'ツ', e: 'ツェ', o: 'ツォ' }},c: {a: 'カ', i: 'シ', u: 'ク', e: 'セ', o: 'コ',h: { a: 'チャ', i: 'チ', u: 'チュ', e: 'チェ', o: 'チョ' },y: { a: 'チャ', i: 'チィ', u: 'チュ', e: 'チェ', o: 'チョ' }},q: {a: 'クァ', i: 'クィ', u: 'ク', e: 'クェ', o: 'クォ'},n: {a: 'ナ', i: 'ニ', u: 'ヌ', e: 'ネ', o: 'ノ', n: 'ン',y: { a: 'ニャ', i: 'ニィ', u: 'ニュ', e: 'ニェ', o: 'ニョ' }},h: {a: 'ハ', i: 'ヒ', u: 'フ', e: 'ヘ', o: 'ホ',y: { a: 'ヒャ', i: 'ヒィ', u: 'ヒュ', e: 'ヒェ', o: 'ヒョ' }},f: {a: 'ファ', i: 'フィ', u: 'フ', e: 'フェ', o: 'フォ',y: { a: 'フャ', u: 'フュ', o: 'フョ' }},m: {a: 'マ', i: 'ミ', u: 'ム', e: 'メ', o: 'モ',y: { a: 'ミャ', i: 'ミィ', u: 'ミュ', e: 'ミェ', o: 'ミョ' }},y: { a: 'ヤ', i: 'イ', u: 'ユ', e: 'イェ', o: 'ヨ' },r: {a: 'ラ', i: 'リ', u: 'ル', e: 'レ', o: 'ロ',y: { a: 'リャ', i: 'リィ', u: 'リュ', e: 'リェ', o: 'リョ' }},w: { a: 'ワ', i: 'ウィ', u: 'ウ', e: 'ウェ', o: 'ヲ' },g: {a: 'ガ', i: 'ギ', u: 'グ', e: 'ゲ', o: 'ゴ',y: { a: 'ギャ', i: 'ギィ', u: 'ギュ', e: 'ギェ', o: 'ギョ' }},z: {a: 'ザ', i: 'ジ', u: 'ズ', e: 'ゼ', o: 'ゾ',y: { a: 'ジャ', i: 'ジィ', u: 'ジュ', e: 'ジェ', o: 'ジョ' }},j: {a: 'ジャ', i: 'ジ', u: 'ジュ', e: 'ジェ', o: 'ジョ',y: { a: 'ジャ', i: 'ジィ', u: 'ジュ', e: 'ジェ', o: 'ジョ' }},d: {a: 'ダ', i: 'ヂ', u: 'ヅ', e: 'デ', o: 'ド',h: { a: 'デャ', i: 'ディ', u: 'デュ', e: 'デェ', o: 'デョ' },y: { a: 'ヂャ', i: 'ヂィ', u: 'ヂュ', e: 'ヂェ', o: 'ヂョ' }},b: {a: 'バ', i: 'ビ', u: 'ブ', e: 'ベ', o: 'ボ',y: { a: 'ビャ', i: 'ビィ', u: 'ビュ', e: 'ビェ', o: 'ビョ' }},v: {a: 'ヴァ', i: 'ヴィ', u: 'ヴ', e: 'ヴェ', o: 'ヴォ',y: { a: 'ヴャ', i: 'ヴィ', u: 'ヴュ', e: 'ヴェ', o: 'ヴョ' }},p: {a: 'パ', i: 'ピ', u: 'プ', e: 'ペ', o: 'ポ',y: { a: 'ピャ', i: 'ピィ', u: 'ピュ', e: 'ピェ', o: 'ピョ' }},x: {a: 'ァ', i: 'ィ', u: 'ゥ', e: 'ェ', o: 'ォ',y: {a: 'ャ', i: 'ィ', u: 'ュ', e: 'ェ', o: 'ョ'},t: {u: 'ッ',s: {u: 'ッ'}}},l: {a: 'ァ', i: 'ィ', u: 'ゥ', e: 'ェ', o: 'ォ',y: {a: 'ャ', i: 'ィ', u: 'ュ', e: 'ェ', o: 'ョ'},t: {u: 'ッ',s: {u: 'ッ'}}}, '-': 'ー'}; tool.romaToKana =r=>{ var str = r.replace(/[A-Za-z]/, s => String.fromCharCode(s.charCodeAt(0)-65248)).toLowerCase(), result = '', tmp = '', index = 0, len = str.length, node = tree, push = (c,t=true)=>(result+=c, tmp='', node=t?tree:node); while(index < len) { var char = str.charAt(index); if(char.match(/[a-z\-]/)) { if(char in node) { var next = node[char]; if(typeof next === 'string') { push(next); }else { tmp += r.charAt(index); node = next; } index++; continue; } var prev = str.charAt(index - 1); if(prev && (prev === 'n' || prev === char)) { push(prev === 'n' ? 'ン' : 'ッ', false); } if(node !== tree && char in tree) { push(tmp); continue; } } push(tmp + char); index++; } tmp = tmp.replace(/n$/, 'ン'); push(tmp); return result; }; tool.hiraToKana = s=>s.replace(/[\u3041-\u3096]/g, m=>String.fromCharCode(m.charCodeAt(0)+0x60)); //tool.romaToKana('jyaro-da'); //tool.hiraToKana('じゃろーだ'); // 'ジャローダ' export var hiddenPower = (()=>{ var _ = {0:{0:{0:{0:{0:{0:1,1:2},1:{0:8,1:10}},1:{0:{0:4,1:6},1:{0:12,1:14}}},1:{0:{0:{0:1,1:3},1:{0:9,1:11}},1:{0:{0:5,1:7},1:{0:13,1:15}}}},1:{0:{0:{0:{0:1,1:3},1:{0:9,1:11}},1:{0:{0:5,1:7},1:{0:12,1:14}}},1:{0:{0:{0:2,1:4},1:{0:10,1:11}},1:{0:{0:6,1:8},1:{0:13,1:15}}}}},1:{0:{0:{0:{0:{0:1,1:3},1:{0:8,1:10}},1:{0:{0:5,1:6},1:{0:12,1:14}}},1:{0:{0:{0:2,1:4},1:{0:9,1:11}},1:{0:{0:6,1:7},1:{0:13,1:15}}}},1:{0:{0:{0:{0:1,1:3},1:{0:9,1:11}},1:{0:{0:5,1:7},1:{0:13,1:15}}},1:{0:{0:{0:2,1:4},1:{0:10,1:12}},1:{0:{0:6,1:8},1:{0:14,1:16}}}}}}; var t = (n,r)=>(n%4==2||n%4==3)?r:0; var _hp = ({h=0,a=0,b=0,c=0,d=0,s=0}={})=>({received: {h:h,a:a,b:b,c:c,d:d,s:s}, type: _type.old[_[h%2][a%2][b%2][c%2][d%2][s%2]].name, power: (t(h,1)+t(a,2)+t(b,4)+t(s,8)+t(c,16)+t(d,32))*40/63+30|0}); return _hp; })(); /* hiddenPower({ h: 31, a: 28, b: 31, c: 9, d: 31, s: 10 }) */ export var I = (()=>{ function _I({h=100, a=100, b=100, c=100, d=100, s=100}={}) { var _ = function(n) { return isNaN(n) || n == ''; } if (_(h) || _(a) || _(b) || _(c) || _(d) || _(s)) { throw new Error('Invalid base stats'); } this.indivisual = {}; this.effort = {}; this.value = {}; this.base = {}, this.base.h = h, this.base.a = a, this.base.b = b, this.base.c = c, this.base.d = d, this.base.s = s; } _I.prototype.setNature = function(nature='がんばりや') { this.nature = _nature[nature]; return this; } _I.prototype.setLv = function(lv=1) { if (lv < 0 || 100 < lv) { throw new Error('Invalid Lv'); } this.lv = lv; return this; } _I.prototype.setValues = function({h=0, a=0, b=0, c=0, d=0, s=0}={}) { var _ = function(n) { return n < 0 || isNaN(n); } if (_(h) || _(a) || _(b) || _(c) || _(d) || _(s)) { throw new Error('Invalid values'); } this.value.h = h, this.value.a = a, this.value.b = b, this.value.c = c, this.value.d = d, this.value.s = s; return this; } _I.prototype.setIndivisuals = function({h=0, a=0, b=0, c=0, d=0, s=0}={}) { var _ = function(n) { return n > 31 || n < 0 || isNaN(n); } if (_(h) || _(a) || _(b) || _(c) || _(d) || _(s)) { throw new Error('Invalid indivisual values'); } this.indivisual.h = h, this.indivisual.a = a, this.indivisual.b = b, this.indivisual.c = c, this.indivisual.d = d, this.indivisual.s = s; return this; } _I.prototype.setEfforts = function({h=0, a=0, b=0, c=0, d=0, s=0}={}) { var _ = function(n) { return n > 255 || n < 0 || isNaN(n); } if (_(h) || _(a) || _(b) || _(c) || _(d) || _(s) || (h + a + b + c + d + s) > 510) { throw new Error('Invalid effort values'); } this.effort.h = h, this.effort.a = a, this.effort.b = b, this.effort.c = c, this.effort.d = d, this.effort.s = s; return this; } _I.prototype.getIndivisuals = function({h=0, a=0, b=0, c=0, d=0, s=0}={}) { var _ = { h: null, a: null, b: null, c: null, d: null, s: null, }; for(var k in _) { var x = 1; if(this.nature.up == k) { x = 1.1; } else if(this.nature.down == k) { x = 0.9; } var y; try { y = ((400 * this.value[k] - (k=='h' ? 4000 : 2000)) / this.lv - (k=='h' ? 400 : 0) - 8 * this.base[k] - this.effort[k]) / 4; }catch(e) {} _[k] = y; } return _; } return _I; })();
// dummy
<head> <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0"/> <script type="module"> import * as Pokemon from '/local--code_/pokemon/1' var wrap = document.querySelector('#wrap'); var area = document.querySelectorAll('textarea'); var _ip = (n, p)=>{ var l = document.createElement('label'); var s = document.createElement('span'); var i = document.createElement('input'); l.appendChild(s); l.appendChild(i); p.appendChild(l); s.innerHTML = n; i.type = 'number'; i.max = 31; i.min = 0; i.value = 31; return i; } (async()=>{ await Pokemon.loading(); wrap.innerText =''; var [h,a,b,c,d,s] = ['h','a','b','c','d','s'].map(v=>_ip(`<b>${v}: </b>`, wrap)); var calc = ()=>{ var r = Pokemon.hiddenPower({h:h.value, a:a.value, b:b.value, c:c.value, d:d.value, s:s.value}); area[0].value = `タイプ: ${r.type}\n威力: ${r.power}`; } for(var i of [h,a,b,c,d,s]) { i.addEventListener('change', calc); } calc(); })(); </script> </head> <body> <div id="wrap"><h1>読み込み中です</h1></div> <textarea readonly></textarea> </body>
ページリビジョン: 53, 最終更新: 03 Nov 2020 05:29