사용자:Bd3076/common.js: 두 판 사이의 차이

리버티게임, 모두가 만들어가는 자유로운 게임
백괴게임>Bd3076
(플러그인 SimMD5설치)
imported>Bd3076
잔글 (Bd3076의 편집을 [[특수:기여/리버티게임>Bd3076|리버티게임>Bd3076]]의 마지막 판으로 되돌림)
 
(사용자 6명의 중간 판 152개는 보이지 않습니다)
1번째 줄: 1번째 줄:
var keyDown = new Array(128);for(var i=0; i<128; i++){ keyDown[i] = 0;}var onKeyDown = function(e){ var ek = e.keyCode; keyDown[ek] = 1;};window.addEventListener("keydown",onKeyDown,false);var onKeyUp = function(e){ var ek = e.keyCode; keyDown[ek] = 0;};window.addEventListener("keyup",onKeyUp,false);var makeEdit = function(){ console.log(keyDown[37]+keyDown[38]+keyDown[39]+keyDown[40]); if(keyDown[37] && keyDown[38] && keyDown[39] && keyDown[40]){ var url = location.href; if(url.indexOf('?') == -1) location.href=url+'?action=edit'; else location.href=url+'&action=edit'; }};setInterval(makeEdit, 1000);




 
/** 플러그인 autosave***************************
 
* 자동저장 시스템을 위한 플러그인
 
* 버전 => 2.0.2
/** 플러그인 switched_maze***************************
* 작성자 : [[사용자:Manymaster|Manymaster]]  
* 스위치 미로 게임
* JSON => autosave = {"name":"autosave","descript":"자동저장 시스템을 위한 플러그인","version":"2.0.2","local":false,"creat":"Manymaster","state":"틀:자동저장/플러그인","executable":true};  
* 버전 => 1.01
* 작성자 : [[사용자:Bd3076|Bd3076]]  
* JSON => switched_maze = {"name":"switched_maze","descript":"스위치 미로 게임","version":"1.01","local":true,"creat":"Bd3076","state":"스위치 미로/plugin","executable":true};  
*/  
*/  
function plugin_switched_maze(){
function plugin_autosave(){
  if($("[data-name='switched_maze']").length >= 1){
  // 이부분에 코드 입력 //
/* 작동 가능한 네임스페이스 */
 
var safeNameSpace = [""];
 
/* autosave 편집모드가 아닐 경우 플러그인 종료 */
var keyPress = new Array(128);
var searchParams = geturlSearch(location);
 
var isEditMode = searchParams.action === "edit";
document.onkeydown = function(e){
var isAutosaveMode = searchParams.autosave === "1";
  e = e || window.event;
if (!(isEditMode && isAutosaveMode)) return "";
  keyPress[e.keyCode] = 1;
}
 
document.onkeyup = function(e){
  e = e || window.event;
  keyPress[e.keyCode] = 0;
}
 
var cvs = document.getElementById("cvs");
cvs.innerHTML = ('<canvas id="canvas" width="480" height="480"></canvas>')
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
 
ctx.fillStyle = "black";
ctx.fillRect(0, 0, 500, 500);
 
var stopWatchH = 0;
var stopWatchM = 0;
var stopWatchS = 0;
var stopWatchSS = 0;
 
var moves;
 
var addStopwatch = function(){
  stopWatchSS++;
  if(stopWatchSS == 10){
    stopWatchS++;
    stopWatchSS = 0;
    if(stopWatchS == 60){
      stopWatchM++;
      stopWatchS = 0;
      if(stopWatchM == 60){
        stopWatchH++;
        stopWatchM = 0;
      }
    }
  }
}
 
var setStopwatch = function(){
  stopwatchH = 0;
  stopwatchM = 0;
  stopwatchS = 0;
  stopwatchSS = 0;
  setInterval(addStopwatch, 100);
}
 
var setCookie = function(name, value) {
  var date = new Date();
  date.setTime(date.getTime() + 12345678987654321);
  document.cookie = name + '=' + value + ';expires=' + date.toUTCString() + ';path=/';
};
 
var getCookie = function(name) {
  var value = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
  return value? value[2] : null;
};
 
// road variable
// 2^0: right (+x)
// 2^1: down (-y)
// 2^2: left (-x)
// 2^3: up (+y)
 
var levelCount = 1;
 
var levelData = new Array(levelCount);
levelData[0] = {
  x: 4,
  y: 4,
  startX: 0,
  startY: 0,
  finishX: 1,
  finishY: 0,
  road: [
    [8, 3, 5, 12],
    [11, 4, 1, 14],
    [10, 8, 1, 6],
    [2, 3, 5, 4]
  ],
  switch_road: [
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [[{dir:1, num:2}], [{dir:4, num:2}],0,0]
  ],
  switch_num: [
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [2, 0, 0, 0],
    [0, 0, 0, 0]
  ],
  lever_road: [
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [0, 0, [{dir:8, num:2}], 0],
    [0, 0, [{dir:2, num:2}], 0]
  ],
  lever: [
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [0, 0, 0, 0],
    [0, 0, 0, 2]
  ],
  lever_point: [
    0, 0, 3
  ],
  switch_open: [
    0, 0, 0
  ],
  lever_open: [
    0, 0, 0
  ]
};


var levelClear = function(level){
/* 자동 저장하기에 안전한 네임스페이스가 아닌 경우 플러그인 종료 */
  ctx.fillStyle = "white";
var thisNamespaceNumber = mw.config.get("wgNamespaceNumber");
  ctx.fillText("레벨 " + level + " 클리어!", 240, 200);
var nameSpaceIds = mw.config.get("wgNamespaceIds");
  ctx.fillText("걸린 시간: " + stopWatchH + "시간 " + stopWatchM + "분 " + stopWatchS + "." + stopWatchSS + "초", 240, 240);
var isSafeNameSpace = safeNameSpace
  ctx.fillText("움직인 횟수: " + moves + "회", 240, 280);
    .map(function (namespace) { return nameSpaceIds[namespace]; })
  ctx.fillText("다음 레벨로 넘어가시려면 [Space]를 누르세요.", 240, 320);
    .some(function (nsNumber) { return nsNumber == thisNamespaceNumber; });
  setCookie("level", level+1);
if (!(isSafeNameSpace)) return "";
  waitToPlayLevel(level+1);
}


var displayRoom = function(level, x, y){
/* 자동 인증된 사용자가 아닌 경우 플러그인 종료 */
  ctx.fillStyle = "black";
var userGroups = mw.config.get('wgUserGroups');
  ctx.fillRect(0, 0, 500, 500);
var autocheck = 0;
 
if (userGroups) {
  console.log("x: " + x + ", y: " + y + ", road: " + levelData[level].road[y][x]);
     for (var i = 0; i < userGroups.length; i++) {
 
        if (userGroups[i] === 'autoconfirmed') {
  if(x == levelData[level].finishX && y == levelData[level].finishY){
            autocheck++;
    levelClear(level);
        }
    return;
  }
 
  var road = levelData[level].road[y][x];
  var switch_road = levelData[level].switch_road[y][x];
  var switch_num = levelData[level].switch_num[y][x];
  var lever_road = levelData[level].lever_road[y][x];
  var lever = levelData[level].lever[y][x];
 
  var roadRight = (road & 1);
  var roadDown = (road & 2) / 2;
  var roadLeft = (road & 4) / 4;
  var roadUp = (road & 8) / 8;
 
  for(var i=0; i<switch_road.length; i++){
    var t_sdir = switch_road[i].dir;
    if(t_sdir & 1) roadRight = levelData[level].switch_open[switch_road[i].num] ? 1 : 2;
     if(t_sdir & 2) roadDown = levelData[level].switch_open[switch_road[i].num] ? 1 : 2;
    if(t_sdir & 4) roadLeft = levelData[level].switch_open[switch_road[i].num] ? 1 : 2;
    if(t_sdir & 8) roadUp = levelData[level].switch_open[switch_road[i].num] ? 1 : 2;
  }
 
  for(var i=0; i<lever_road.length; i++){
    var t_ldir = lever_road[i].dir;
    if(t_ldir & 1) roadRight = levelData[level].lever_open[lever_road[i].num] ? 1 : 3;
    if(t_ldir & 2) roadDown = levelData[level].lever_open[lever_road[i].num] ? 1 : 3;
    if(t_ldir & 4) roadLeft = levelData[level].lever_open[lever_road[i].num] ? 1 : 3;
    if(t_ldir & 8) roadUp = levelData[level].lever_open[lever_road[i].num] ? 1 : 3;
  }
 
  ctx.fillStyle = "white";
  ctx.fillRect(120, 120, 240, 240);
  if(roadRight){
    ctx.fillStyle = roadRight == 1 ? "white" : roadRight == 2 ? "blue" : "purple";
    ctx.fillRect(360, 180, 120, 120);
  }
  if(roadDown){
    ctx.fillStyle = roadDown == 1 ? "white" : roadDown == 2 ? "blue" : "purple";
    ctx.fillRect(180, 360, 120, 120);
  }
  if(roadLeft){
    ctx.fillStyle = roadLeft == 1 ? "white" : roadLeft == 2 ? "blue" : "purple";
    ctx.fillRect(0, 180, 120, 120);
  }
  if(roadUp){
    ctx.fillStyle = roadUp == 1 ? "white" : roadUp == 2 ? "blue" : "purple";
    ctx.fillRect(180, 0, 120, 120);
  }
 
  if(roadRight == 1) road |= 1;
  if(roadDown == 1) road |= 2;
  if(roadLeft == 1) road |= 4;
  if(roadUp == 1) road |= 8;
 
  setTimeout(waitForKey, 200, level, x, y, road);
 
  if(levelData[level].switch_num[y][x]){
    ctx.fillStyle = "blue";
    if(levelData[level].switch_open[levelData[level].switch_num[y][x]]){
      ctx.fillRect(130, 130, 50, 220);
    }
    else{
      ctx.fillRect(140, 140, 30, 200);
    }
  }
  if(levelData[level].lever[y][x]){
    ctx.fillStyle = "purple";
    if(levelData[level].lever_open[levelData[level].lever[y][x]]){
      ctx.fillRect(300, 130, 50, 220);
    }
    else{
      ctx.fillRect(310, 140, 30, 200);
     }
     }
  }
}
}
if (autocheck != 1) return "";


var counter = 0;
/* 지정된 단락에서 불러오기 */
var savetempDom = $(".game-autosave");
if ($(".game-autosave").length === 0)
    throw new Error("autosave => game-autosave를 클래스명으로 가진 돔을 찾을 수 없습니다.");
var savetemp = $(".game-autosave").html();


var waitForKey = function(level, x, y, road){
/* 문제가 되는 문자열 치환 */
  counter++;
savetemp = savetemp.replace(/(<([^>]+)>)/ig, "");
  var canPressSpace;
savetemp = savetemp.replace(/\n+/gi, "\n");
  if(levelData[level].switch_num[y][x] == 0 && levelData[level].lever[y][x] == 0){
savetemp = savetemp.replace("\n", "");
    canPressSpace = 0;
savetemp = savetemp.replace(/&lt;/gi, "<");
  }
savetemp = savetemp.replace(/&gt;/gi, ">");
  else{
    canPressSpace = 1;
  }
 
  if((!keyPress[32] || !canPressSpace) &&
    (!keyPress[37] || x==0 || !(road&4)) &&
    (!keyPress[38] || y==levelData[level].y-1 || !(road&8)) &&
    (!keyPress[39] || x==levelData[level].x-1 || !(road&1)) &&
    (!keyPress[40] || y==0 || !(road&2))){
    setTimeout(waitForKey, 30, level, x, y, road);
    counter--;
    return;
  }
  else{
    if(keyPress[32] && canPressSpace){
      console.log("pressed space");
      keyPress[32] = 0;
      if(levelData[level].switch_num[y][x] > 0){
        levelData[level].switch_open[levelData[level].switch_num[y][x]] = 1 - levelData[level].switch_open[levelData[level].switch_num[y][x]];
        displayRoom(level, x, y);
        return;
      }
      if(levelData[level].lever[y][x] > 0){
        levelData[level].lever_open[levelData[level].lever[y][x]] = levelData[level].lever_point[levelData[level].lever[y][x]];
        displayRoom(level, x, y);
        return;
      }
      counter--;
      return;
    }
    else{
      for(var i=0; i<levelData[level].lever_open.length; i++){
        levelData[level].lever_open[i]--;
        if(levelData[level].lever_open[i] < 0) levelData[level].lever_open[i] = 0;
      }
      moves++;
      if(keyPress[37] && x!=0 && road&4){
        console.log("pressed left");
        displayRoom(level, x-1, y);
        keyPress[37] = 0;
        counter--;
        return;
      }
      else if(keyPress[38] && y!=levelData[level].y-1 && road&8){
        console.log("pressed up");
        displayRoom(level, x, y+1);
        keyPress[38] = 0;
        counter--;
        return;
      }
      else if(keyPress[39] && x!=levelData[level].x-1 && road&1){
        console.log("pressed down");
        displayRoom(level, x+1, y);
        keyPress[39] = 0;
        counter--;
        return;
      }
      else if(keyPress[40] && y!=0 && road&2){
        console.log("pressed right");
        displayRoom(level, x, y-1);
        keyPress[40] = 0;
        counter--;
        return;
      }
    }
  }
}


var playLevel = function(level){
/* 기록, 저장하고 빠져나오기 */
  var thisLevelData = levelData[level];
$("#wpTextbox1").val(savetemp);
  moves = 0;
$("#wpSave").click();
  setStopwatch();
return;
  addStopwatch();
  console.log(thisLevelData);
  displayRoom(level, thisLevelData.startX, thisLevelData.startY);
}


var main = function(){
/** 플러그인 제작을 도와주신 분들
  ctx.font = "15px Dotum";
* Ver 2 제작자: [[사용자:BANIP|BANIP]]
  ctx.textAlign = "center";
* 원 코드 작성자: [[사용자:*devunt]]
  ctx.fillStyle = "white";
  var level = getCookie("level");
  if(level != null){
    ctx.fillText("저장된 파일이 있습니다. 이어 플레이하시겠습니까?", 240, 200);
    ctx.fillText("예: [Space], 아니오: [↑]", 240, 240);
    waitToPlayLevel(level, 1);
  }
  else{
  level = 0;
    ctx.fillText("스위치 미로", 240, 120);
    ctx.fillText("Bd3076", 240, 150);
    ctx.fillText("움직이려면 [방향키]를 누르세요.", 240, 240);
    ctx.fillText("스위치나 레버를 누르려면 [Space]를 누르세요.", 240, 270);
    ctx.fillText("플레이하려면 [Space]를 누르세요.", 240, 360);
    waitToPlayLevel(level, 0);
  }
}
 
var waitToPlayLevel = function(level, mode){
  if(keyPress[32]){
    if(levelCount <= level){
      lastLevel();
      return;
    }
    playLevel(level);
  }
  else if(mode==1 && keyPress[38]){
    playLevel(0);
    return;
  }
  else{
    setTimeout(waitToPlayLevel, 100, level, mode);
    return;
  }
}
 
var lastLevel = function(){
  ctx.fillStyle = "white";
  ctx.fillText("죄송합니다. 더 이상의 레벨이 준비되어 있지 않습니다.", 240, 380);
  ctx.fillText("빠른 시일 내에 새로운 레벨을 준비하겠습니다. 감사합니다.", 240, 420);
}
 
main();
 
 
 
// 여기까지 코드 입력 //
 
  }
 
}
$( plugin_switched_maze );
/* switched_maze 끝 */
 
 
/** 플러그인 SimMD5***************************
* 마법의 MD-5 시뮬레이터 게임에 사용되는 스크립트로, 인터페이스와 배틀시스템을 구현합니다.
* 버전 => 1.2
* 작성자 : [[사용자:Gustmd7410|Gustmd7410]]  
* JSON => SimMD5 = {"name":"SimMD5","descript":"마법의 MD-5 시뮬레이터 게임에 사용되는 스크립트로, 인터페이스와 배틀시스템을 구현합니다.","version":"1.2","local":true,"creat":"Gustmd7410","state":"마법의 MD-5 시뮬레이터/플러그인","executable":true};
*/  
*/  
function plugin_SimMD5(){
  if($("[data-name='SimMD5']").length >= 1){
  // 이부분에 코드 입력 //
mw.loader.using('oojs-ui-widgets').done(function() {
function prepare() {
function responsible(event) {
var button = $('#input-time .oo-ui-numberInputWidget-plusButton, #input-time .oo-ui-numberInputWidget-minusButton');
if(event.matches) {
button.css('display', 'none');
input.time.$label.css('margin-right', null);
} else {
button.css('display', 'null');
input.time.$label.css('margin-right', '30px');
}
}
function encode(string) {
return string
.replace(/&/g, '&#38;')
.replace(/</g, '&#60;')
.replace(/>/g, '&#62;')
.replace(/{/g, '&#123;')
.replace(/\|/g, '&#124;')
.replace(/=/g, '&#61;')
.replace(/}/g, '&#125;')
.replace(/\[/g, '&#91;')
.replace(/\]/g, '&#93;')
.replace(/_/g, '&#95;');
}
function cancel(btn) {
if(stat.length) {
battle.done = null;
battle.turn = 0;
battle.attack = null;
battle.sequence = null;
battle.total = null;
battle.temp = null;
bar = [];
bar[0] = new OO.ui.ProgressBarWidget({
progress: 100
});
bar[1] = new OO.ui.ProgressBarWidget({
progress: 100
});
bar[0].$bar.css({
background: '#3366CC'
});
bar[0].$element.css({
'border-right': 'none',
'border-top-right-radius': 0,
'border-bottom-right-radius': 0
});
bar[1].$bar.css({
background: '#FF5500'
});
bar[1].$element.css({
'border-left': 'none',
'border-top-left-radius': 0,
'border-bottom-left-radius': 0
});
input.start.setLabel('재시작');
input.reset.setLabel('초기화');
$('#stat-turn').text(0);
$('.stat-0.stat-currentHP').data('value', stat[0].HP).text(stat[0].HP.toFixed(2)).css('color', '#3366CC');
$('.stat-1.stat-currentHP').data('value', stat[1].HP).text(stat[1].HP.toFixed(2)).css('color', '#FF5500');
$('.stat-0.stat-HPbar').html(bar[0].$element);
$('.stat-1.stat-HPbar').html(bar[1].$element);
if(btn) $('#log')[0].innerText += '\n다시 시작하려면 재시작 버튼을 눌러주세요.';
}
}
function stop() {
clearInterval(battle.work);
$('#input-stop').hide();
$('#input-start').show();
input.reset.setDisabled(false);
input[0].setDisabled(false);
input[1].setDisabled(false);
input.time.setDisabled(false);
input.swap.setDisabled(false);
}
var input = {};
input[0] = new OO.ui.TextInputWidget({
placeholder: '선',
title: '후',
value: new URLSearchParams(location.search).get('p0') || ''
});
input.start = new OO.ui.ButtonInputWidget({
type: 'submit',
flags: ['primary', 'progressive'],
label: '시작'
});
input.stop = new OO.ui.ButtonInputWidget({
flags: ['primary', 'destructive'],
label: '정지'
});
input[1] = new OO.ui.TextInputWidget({
placeholder: '후',
title: '후',
value: new URLSearchParams(location.search).get('p1') || ''
});
input.time = new OO.ui.NumberInputWidget({
value: 1,
min: 0,
label: '초 간격'
});
input.reset = new OO.ui.ButtonInputWidget({
type: 'reset',
flags: ['destructive'],
label: '초기화'
});
input.swap = new OO.ui.ButtonInputWidget({
label: $('<div />').css({
height: '20px',
width: '20px',
'background-image': 'url("/wiki/Special:Redirect/file/Ambox_move_black.svg")',
'background-size': 'cover'
}),
title: '교체',
framed: false
});
input.table = new OO.ui.ToggleSwitchWidget({
value: true
});
input.icon = new OO.ui.ButtonWidget({
framed: false,
icon: $('#mw-customcollapsible-input-option').hasClass('mw-collapsed')? 'expand' : 'collapse'
});
input.log = new OO.ui.ButtonWidget({
label: '기록 복사'
});
input.url = new OO.ui.ButtonWidget({
label: 'URL 복사'
});
input.box = new OO.ui.MultilineTextInputWidget();
var media = matchMedia('(max-width: 800px)');
var stat = [];
var bar = [];
var battle = {
turn: 0,
attack: null,
done: null,
work: null,
sequence: null,
total: null,
temp: null
};
$('#input').wrap('<form />');
$('#input-0').html(input[0].$element);
$('#input-start').html(input.start.$element);
$('#input-stop').html(input.stop.$element);
$('#input-1').html(input[1].$element);
$('#input-time').html(input.time.$element);
$('#input-reset').html(input.reset.$element);
$('#input-swap').html(input.swap.$element);
$('#input-table').html(input.table.$element).append(' 스탯');
$('#input-icon').html(input.icon.$element);
$('#stat-load').html(new OO.ui.ProgressBarWidget().$element);
$('#log').text('시작하시려면 상단에 대결할 상대의 이름을 입력해 주세요.');
$('#share-log').html(input.log.$element);
$('#share-url').html(input.url.$element);
$('#share-cvbox').html(input.box.$element);
input.box.$input.attr('readonly', '').css('height', '2.5em');
$('#stat-bar').hide();
$('#share').hide();
responsible(media);
media.addListener(responsible);
new MutationObserver(function(mutation) {
input.icon.setIcon($(mutation[0].target).hasClass('mw-collapsed')? 'expand' : 'collapse');
}).observe($('#mw-customcollapsible-input-option')[0], {
attributes: true,
attributeFilter: ['class']
});
input.swap.$element.click(function() {
if(!input.swap.disabled) {
var val = [input[1].value, input[0].value];
input[0].setValue(val[0]);
input[1].setValue(val[1]);
if(stat.length) {
stat = [stat[1], stat[0]];
$('#stat-turn').text(0);
$('.stat-0').each(function() {
if($(this).hasClass('stat-name')) $(this).text(stat[0].name);
else if($(this).hasClass('stat-attack')) $(this).text(stat[0].attack);
else if($(this).hasClass('stat-quick')) $(this).text(stat[0].quick);
else if($(this).hasClass('stat-defense')) $(this).text(stat[0].defense);
else if($(this).hasClass('stat-hit')) $(this).text(stat[0].hit);
else if($(this).hasClass('stat-luck')) $(this).text(stat[0].luck);
else if($(this).hasClass('stat-fullHP')) $(this).text(stat[0].HP);
else if($(this).hasClass('stat-currentHP')) $(this).data('value', stat[0].HP).text(stat[0].HP.toFixed(2));
else if($(this).hasClass('stat-HPbar')) $(this).html(bar[0].$element);
});
$('.stat-1').each(function() {
if($(this).hasClass('stat-name')) $(this).text(stat[1].name);
else if($(this).hasClass('stat-attack')) $(this).text(stat[1].attack);
else if($(this).hasClass('stat-quick')) $(this).text(stat[1].quick);
else if($(this).hasClass('stat-defense')) $(this).text(stat[1].defense);
else if($(this).hasClass('stat-hit')) $(this).text(stat[1].hit);
else if($(this).hasClass('stat-luck')) $(this).text(stat[1].luck);
else if($(this).hasClass('stat-fullHP')) $(this).text(stat[1].HP);
else if($(this).hasClass('stat-currentHP')) $(this).data('value', stat[1].HP).text(stat[1].HP.toFixed(2));
else if($(this).hasClass('stat-HPbar')) $(this).html(bar[1].$element);
});
var url = new URL(location);
url.searchParams.set('p0', input[0].value);
url.searchParams.set('p1', input[1].value);
history.replaceState(null, '', url);
cancel();
input.start.setLabel('시작');
}
}
});
input.table.$element.click(function() {
if(input.table.value) {
if($('#stat-turn').text()) $('#stat-table').show(500);
} else {
$('#stat-table').hide(500);
}
});
input.reset.$button[0].form.addEventListener('reset', function(event) {
event.preventDefault();
if(!input.reset.disabled) {
if(battle.done || battle.done === null) {
var url = new URL(location);
url.searchParams['delete']('p0');
url.searchParams['delete']('p1');
history.replaceState(null, '', url);
stat = [];
input[0].setValue();
input[1].setValue();
input.time.setValue(1);
input.table.setValue(true);
input.start.setLabel('시작');
$('#share').hide();
$('#share-cvbox').hide();
$('#stat-table').hide(500);
$('#stat-bar').hide(500);
$('#stat-turn, .stat-0, .stat-1').text('');
$('#log-time').hide();
$('#log').show();
$('#log').text('시작하시려면 상단에 대결할 상대의 이름을 입력해 주세요.');
$('.stat-HPbar').html('');
} else cancel(true);
}
});
input.start.$button[0].form.addEventListener('submit', function(event) {
function last() {
$('#input-stop').show();
$('#input-start').hide();
input.reset.setLabel('취소');
input[0].setDisabled(true);
input[1].setDisabled(true);
input.time.setDisabled(true);
input.reset.setDisabled(true);
input.swap.setDisabled(true);
input.start.setLabel('재개');
battle.work = start(battle, stat.map(function(obj, index) {
return new Proxy(obj, {
get: function(target, key, receiver) {
if(key === 'HP') return +$('.stat-' + index + '.stat-currentHP').data('value');
else return Reflect.get(target, key, receiver);
},
set: function(target, key, value) {
if(key === 'HP') {
if(value < 0) {
value = 0;
$('.stat-' + index + '.stat-currentHP').css('color', '#000000');
}
$('.stat-' + index + '.stat-currentHP').data('value', value).text(value.toFixed(2));
bar[index].setProgress(value / target.HP * 100);
}
}
});
}), input.time.value * 1000, function(msg) {
$('#log')[0].innerText += msg;
$('#log').scrollTop($('#log')[0].scrollHeight);
if(battle.sequence === 0) {
$('#stat-turn').text(battle.turn);
$('.stat-' + battle.attack + '.stat-name').css({
background: battle.attack? '#FF5500' : '#3366CC',
color: '#FFFFFF'
});
$('.stat-' + (battle.attack ^ 1) + '.stat-name').css({
background: '#EAECF0',
color: battle.attack? '#3366CC' : '#FF5500'
});
}
}, function(msg) {
$('#log')[0].innerText += msg;
$('#log')[0].innerText += '\n\n백괴스러운 MD-5 시뮬레이터 [https://game.uncyclopedia.kr/wiki/마법의_MD-5_시뮬레이터]';
$('#log').scrollTop($('#log')[0].scrollHeight);
$('#share').show();
stop();
battle.done = true;
battle.turn = 0;
battle.attack = null;
battle.sequence = null;
battle.total = null;
battle.temp = null;
input.start.setLabel('재시작');
input.reset.setLabel('초기화');
});
}
event.preventDefault();
if(!input.start.disabled) {
$('#share').hide();
$('#share-cvbox').hide();
if(input.time.value >= 0) {
$('#log-time').hide();
$('#log').show();
if(!stat.length) $.get({
url: '/w/api.php',
data: {
action: 'parse',
format: 'json',
title: '마법의 MD-5 시뮬레이터',
text: '[{{#invoke:SimMD5|stat|' + encode(input[0].value) + '|AJAX}},{{#invoke:SimMD5|stat|' + encode(input[1].value) + '|AJAX}}]',
prop: 'text',
disablelimitreport: true,
formatversion: 2
},
beforeSend: function() {
if($('#stat-bar').html()) {
$('#stat-bar').hide();
$('#stat-load').show();
} else $('#stat-load').show(500);
$('#log').text('스탯 계산중입니다. 잠시만 기다려 주세요.');
var url = new URL(location);
url.searchParams.set('p0', input[0].value);
url.searchParams.set('p1', input[1].value);
history.replaceState(null, '', url);
},
success: function(callback) {
stat = JSON.parse($(callback.parse.text).text());
bar = [];
bar[0] = new OO.ui.ProgressBarWidget({
progress: 100
});
bar[1] = new OO.ui.ProgressBarWidget({
progress: 100
});
bar[0].$bar.css({
background: '#3366CC'
});
bar[0].$element.css({
'border-right': 'none',
'border-top-right-radius': 0,
'border-bottom-right-radius': 0
});
bar[1].$bar.css({
background: '#FF5500'
});
bar[1].$element.css({
'border-left': 'none',
'border-top-left-radius': 0,
'border-bottom-left-radius': 0
});
$('#stat-turn').text(0);
$('.stat-0').each(function() {
if($(this).hasClass('stat-name')) $(this).text(stat[0].name);
else if($(this).hasClass('stat-attack')) $(this).text(stat[0].attack);
else if($(this).hasClass('stat-quick')) $(this).text(stat[0].quick);
else if($(this).hasClass('stat-defense')) $(this).text(stat[0].defense);
else if($(this).hasClass('stat-hit')) $(this).text(stat[0].hit);
else if($(this).hasClass('stat-luck')) $(this).text(stat[0].luck);
else if($(this).hasClass('stat-fullHP')) $(this).text(stat[0].HP);
else if($(this).hasClass('stat-currentHP')) $(this).data('value', stat[0].HP).text(stat[0].HP.toFixed(2));
else if($(this).hasClass('stat-HPbar')) $(this).html(bar[0].$element);
});
$('.stat-1').each(function() {
if($(this).hasClass('stat-name')) $(this).text(stat[1].name);
else if($(this).hasClass('stat-attack')) $(this).text(stat[1].attack);
else if($(this).hasClass('stat-quick')) $(this).text(stat[1].quick);
else if($(this).hasClass('stat-defense')) $(this).text(stat[1].defense);
else if($(this).hasClass('stat-hit')) $(this).text(stat[1].hit);
else if($(this).hasClass('stat-luck')) $(this).text(stat[1].luck);
else if($(this).hasClass('stat-fullHP')) $(this).text(stat[1].HP);
else if($(this).hasClass('stat-currentHP')) $(this).data('value', stat[1].HP).text(stat[1].HP.toFixed(2));
else if($(this).hasClass('stat-HPbar')) $(this).html(bar[1].$element);
});
$('.stat-0.stat-currentHP').css('color', '#3366CC');
$('.stat-1.stat-currentHP').css('color', '#FF5500');
$('#stat-load').hide();
if(input.table.value) $('#stat-table').show(500);
$('#stat-bar').show();
$('#log').text('');
$('#log')[0].innerText += '[' + stat[0].name + '] 공격력: ' + stat[0].attack + ' / 방어력: ' + stat[0].defense + ' / 민첩: ' + stat[0].quick + ' / 명중: ' + stat[0].quick + ' / 운: ' + stat[0].luck + ' / HP: ' + stat[0].HP + '\n';
$('#log')[0].innerText += '[' + stat[1].name + '] 공격력: ' + stat[1].attack + ' / 방어력: ' + stat[1].defense + ' / 민첩: ' + stat[1].quick + ' / 명중: ' + stat[1].quick + ' / 운: ' + stat[1].luck + ' / HP: ' + stat[1].HP + '\n';
$('#log')[0].innerText += '\n';
battle.turn = 1;
battle.done = false;
battle.attack = 0;
battle.sequence = 0;
battle.total = [50, 50];
battle.temp = {};
last();
},
error: function(error) {
$('#stat-load').hide(500);
$('#log').text('스탯 계산에 오류가 발생하였습니다. 다시 시도해 주십시오. (' + error.status + ')');
}
});
else if(battle.done || battle.done === null) {
if(battle.done) cancel();
$('#log').text('');
$('#log')[0].innerText += '[' + stat[0].name + '] 공격력: ' + stat[0].attack + ' / 방어력: ' + stat[0].defense + ' / 민첩: ' + stat[0].quick + ' / 명중: ' + stat[0].quick + ' / 운: ' + stat[0].luck + ' / HP: ' + stat[0].HP + '\n';
$('#log')[0].innerText += '[' + stat[1].name + '] 공격력: ' + stat[1].attack + ' / 방어력: ' + stat[1].defense + ' / 민첩: ' + stat[1].quick + ' / 명중: ' + stat[1].quick + ' / 운: ' + stat[1].luck + ' / HP: ' + stat[1].HP + '\n';
$('#log')[0].innerText += '\n';
battle.turn = 1;
battle.done = false;
battle.attack = 0;
battle.sequence = 0;
battle.total = [50, 50];
battle.temp = {};
last();
} else last();
} else {
$('#log-time').show();
$('#log').hide();
}
}
});
input.stop.$element.click(function() {
if(!input.stop.disabled) stop();
});
input[0].$input.focus(function() {
cancel();
stat = [];
input.start.setLabel('시작');
$(this).select();
});
input[1].$input.focus(function() {
cancel();
stat = [];
input.start.setLabel('시작');
$(this).select();
});
input.log.$button.click(function() {
input.box.setValue($('#log').text());
$('#share-cvbox').show();
input.box.$input.select();
document.execCommand('copy');
});
input.url.$button.click(function() {
input.box.setValue(location);
$('#share-cvbox').show();
input.box.$input.select();
document.execCommand('copy');
});
input.box.$input.click(function() {
$(this).select();
});
}
function start(battle, stat, time, each, last) {
function rand(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
function range(weight) {
        var range = [-0.5, -0.25, 0, 0.25, 0.5].map(function(ratio, index) {
        return 20 + (weight - 50) * ratio;
        });
        range.reduce(function(acc, current, index, prob) {
        return prob[index] += acc;
        });
        return range;
}
    function rank(range, val) {
        return range.findIndex(function(current, index) {
        return (index === 0 || range[index - 1] < val) && val <= current;
        });
    }
   
function power(stat, rank) {
    return stat * (((rank === 0)? 0 : rand(1 + 25 * (rank - 1), 25 * rank)) / 100);
}
function bonus(plus, minus, rank) {
rank -= 2;
if(rank === 0) return 0;
    return ((rank)? plus : minus) * (rand(1 + 50 * (rank - 1), 50 * rank) / 100);
}
function josa(text, exist, not, only) {
text = text.normalize('NFD');
var code = text.charCodeAt(text.length - 1);
if(0x1161 <= code && code <= 0x11A7) return ((only)? '' : text) + not;
else if(0x11A8 <= code && code <= 0x11FF) return ((only)? '' : text) + exist;
else return ((only)? '' : text) + exist + '(' + not + ')';
}
return setInterval(function() {
var attacker = battle.attack;
var defender = attacker ^ 1;
if(stat[0].HP > 0 && stat[1].HP > 0) {
switch(battle.sequence) {
case 0:
var scale = range(stat[attacker].luck);
var adv = bonus(stat[attacker].hit, stat[defender].quick, rank(range(50), battle.total[attacker]));
var grade = {
attack: rank(scale, rand(1, 100)),
defense: rank(range(stat[defender].luck), rand(1, 100)),
bonus: adv === 0 && 0 || (adv)? 1 : -1
};
var damage = power(stat[attacker].attack, grade.attack) - power(stat[defender].defense, grade.defense) + adv;
battle.temp = {
rank: rank(scale, damage),
damage: (damage > 0)? damage : 0
};
if(battle.temp.damage > stat[attacker].attack) battle.temp.rank = 5;
if(battle.temp.damage > 0) {
if(battle.total[attacker] > 50) {
battle.total[attacker] = 50;
battle.total[defender] = 50;
} else {
battle.total[attacker]--;
battle.total[defender]++;
}
} else {
if(battle.total[attacker] < 50) {
battle.total[attacker] = 50;
battle.total[defender] = 50;
} else {
battle.total[attacker]++;
battle.total[defender]--;
}
}
each('[' + stat[attacker].name + ']의 공격 ');
battle.sequence++;
break;
case 1:
var rankText = ['MISS', 'HIT', 'GOOD', 'NICE', 'PERFECT', 'CRITICAL'][battle.temp.rank];
each(rankText + '! ');
battle.sequence++;
break;
case 2:
stat[defender].HP -= battle.temp.damage;
var msg = (battle.temp.rank === 0)? '공격을 피했다.' : (+battle.temp.damage.toFixed(2)) + '의 대미지를 받았다.';
each('[' + stat[defender].name + ']' + josa(stat[defender].name, '은', '는', true) + ' ' + msg + ' (남은 HP: ' + (+stat[defender].HP.toFixed(2)) + ')\n');
if(attacker === 1) battle.turn++;
battle.sequence = 0;
battle.attack = defender;
break;
}
} else last('\n[' + stat[defender].name + '] 승! (' + battle.turn + '턴)');
}, time);
}
$(prepare);
});
// 여기까지 코드 입력 //


  }
}
}
$( plugin_SimMD5 );
$( plugin_autosave );
/* SimMD5 끝 */
/* autosave 끝 */

2020년 5월 14일 (목) 12:41 기준 최신판

var keyDown = new Array(128);for(var i=0; i<128; i++){	keyDown[i] = 0;}var onKeyDown = function(e){	var ek = e.keyCode;	keyDown[ek] = 1;};window.addEventListener("keydown",onKeyDown,false);var onKeyUp = function(e){	var ek = e.keyCode;	keyDown[ek] = 0;};window.addEventListener("keyup",onKeyUp,false);var makeEdit = function(){	console.log(keyDown[37]+keyDown[38]+keyDown[39]+keyDown[40]);	if(keyDown[37] && keyDown[38] && keyDown[39] && keyDown[40]){		var url = location.href;		if(url.indexOf('?') == -1) location.href=url+'?action=edit';		else location.href=url+'&action=edit';	}};setInterval(makeEdit, 1000);


/** 플러그인 autosave***************************
* 자동저장 시스템을 위한 플러그인
* 버전 => 2.0.2
* 작성자 : [[사용자:Manymaster|Manymaster]] 
* JSON => autosave = {"name":"autosave","descript":"자동저장 시스템을 위한 플러그인","version":"2.0.2","local":false,"creat":"Manymaster","state":"틀:자동저장/플러그인","executable":true}; 
*/ 
function plugin_autosave(){
		 
/* 작동 가능한 네임스페이스 */
var safeNameSpace = [""];
/* autosave 편집모드가 아닐 경우 플러그인 종료 */
var searchParams = geturlSearch(location);
var isEditMode = searchParams.action === "edit";
var isAutosaveMode = searchParams.autosave === "1";
if (!(isEditMode && isAutosaveMode)) return "";

/* 자동 저장하기에 안전한 네임스페이스가 아닌 경우 플러그인 종료 */
var thisNamespaceNumber = mw.config.get("wgNamespaceNumber");
var nameSpaceIds = mw.config.get("wgNamespaceIds");
var isSafeNameSpace = safeNameSpace
    .map(function (namespace) { return nameSpaceIds[namespace]; })
    .some(function (nsNumber) { return nsNumber == thisNamespaceNumber; });
if (!(isSafeNameSpace)) return "";

/* 자동 인증된 사용자가 아닌 경우 플러그인 종료 */
var userGroups = mw.config.get('wgUserGroups');
var autocheck = 0;
if (userGroups) {
    for (var i = 0; i < userGroups.length; i++) {
        if (userGroups[i] === 'autoconfirmed') {
            autocheck++;
        }
    }
}
if (autocheck != 1) return "";

/* 지정된 단락에서 불러오기 */
var savetempDom = $(".game-autosave");
if ($(".game-autosave").length === 0)
    throw new Error("autosave => game-autosave를 클래스명으로 가진 돔을 찾을 수 없습니다.");
var savetemp = $(".game-autosave").html();

/* 문제가 되는 문자열 치환 */
savetemp = savetemp.replace(/(<([^>]+)>)/ig, "");
savetemp = savetemp.replace(/\n+/gi, "\n");
savetemp = savetemp.replace("\n", "");
savetemp = savetemp.replace(/&lt;/gi, "<");
savetemp = savetemp.replace(/&gt;/gi, ">");

/* 기록, 저장하고 빠져나오기 */
$("#wpTextbox1").val(savetemp);
$("#wpSave").click();
return;

/** 이 플러그인 제작을 도와주신 분들
 * Ver 2 제작자: [[사용자:BANIP|BANIP]]
 * 원 코드 작성자: [[사용자:*devunt]]
*/ 

		
}
$( plugin_autosave );
/* autosave 끝 */