사용자:Senouis/RPGinCity.js
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
- 오페라: Ctrl-F5를 입력.
const usernameStr = mw.user.getName();
const currentpage = mw.config.get("wgPageName");
console.log(currentpage);
function RPGinCity_Title() {
let startbuttondiv = document.getElementById("RPGinCityStart");
if (startbuttondiv !== null){
if (usernameStr === null) {
startbuttondiv.innerHTML = "<p>로그인이 필요합니다</p>";
} else {
let UserDBTitle = new mw.Title("사용자:"+usernameStr+"/RPG in City.json", 2);
if (UserDBTitle.exists === true){
startbuttondiv.innerHTML = "<p><big><a href=\""+mw.util.getUrl(UserDBTitle.toText())+ "\">계속하기</a></big></p>";
} else {
startbuttondiv.innerHTML = "<p><big><a href=\""+mw.util.getUrl(UserDBTitle.toText(),{action: 'edit', preload : '틀:RPG_in_City_DB_양식', summary:'생성'})+ "\">새 데이터 만들기</a></big></p>";
}
}
}
}
function RPGinCity_GoToCheckpoint () {
let JSONDatalist = document.getElementsByClassName("mw-json-value");
if (currentpage === ("사용자:"+usernameStr+"/RPG_in_City.json") && JSONDatalist.length !== 0) {
let MWContent = document.getElementById("mw-content-text");
let GotoLink= document.createElement("a");
GotoLink.href = mw.util.getUrl((JSONDatalist[0].innerText.substring(1, JSONDatalist[0].innerText.length-1)));
console.log(GotoLink.href);
GotoLink.innerText = "게임 계속하기";
MWContent.appendChild(GotoLink);
}
}
function RPGinCity_pushFightInfo(targetUri, Mhp, Ehp, Jam, PJam, BanBomb, Etype, Elevel, Turn) {
targetUri.extend({mhp:Mhp});
targetUri.extend({ehp:Ehp});
targetUri.extend({j:Jam});
targetUri.extend({bj:PJam});
targetUri.extend({bb:BanBomb});
targetUri.extend({etype:Etype});
targetUri.extend({elevel:Elevel});
targetUri.extend({turn:Turn});
return targetUri;
}
function RPGinCity_HandleBattle() {
let Battlelink = new mw.Uri(window.location.href);
console.log("building battle phase...");
let queryparams = Battlelink.query;
// 이제 필요한 값을 구해 화면에 표시한다.
// 플레이어 체력부터...
let mhp = 0;
let playerhealth = document.getElementById("playerhealth");
if (isNaN(queryparams.mhp)) {
mhp = jsonfile.체력;
} else {
mhp = queryparams.mhp; // mhp는 이전 문서의 값을 받는다.
}
playerhealth.innerText = mhp;
//적의 레벨
let enemylevel = document.getElementById("enemylevel");
enemylevel.innerText = queryparams.elevel; // elevel는 항상 undefined이 아니다.
//적의 체력
let enemyhealth = document.getElementById("enemyhealth");
enemyhealth.innerText = queryparams.ehp; // ep는 항상 undefined이 아니다.
//공격 페이즈
let nextPhaseUri = new mw.Uri("https://libertygame.miraheze.org/w/index.php?title="+currentpage);
let attackEnemy = document.getElementById("attackEnemy");
let attackPower = Math.round(Math.random() * jsonfile.레벨);
let attackEnemyUri = RPGinCity_pushFightInfo(nextPhaseUri.clone(), mhp, attackPower >= 0?queryparams.ehp - attackPower : 0, queryparams.j, queryparams.bj, queryparams.bb, queryparams.etype, queryparams.elevel, 2);
if (attackEnemy !== undefined && attackEnemy !== null)attackEnemy.innerHTML="<a href=\"" + attackEnemyUri.toString() + "\">그냥 공격!</a>";
let useJam = document.getElementById("useJam");
let useJamUri = RPGinCity_pushFightInfo(nextPhaseUri.clone(), jsonfile.체력, queryparams.ehp, queryparams.j, queryparams.bj, queryparams.bb, queryparams.etype, queryparams.elevel, 2);
if (useJam !== undefined && useJam !== null)useJam.innerHTML="<a href=\"" + useJamUri.toString() + "\">잼으로 회복!</a>";
let usePJ = document.getElementById("usePJ");
let usePJUri = RPGinCity_pushFightInfo(nextPhaseUri.clone(), mhp, queryparams.ehp > 20 ? queryparams.ehp - 20 : 0, queryparams.j, queryparams.bj, queryparams.bb, queryparams.etype, queryparams.elevel, 2);
if (usePJ !== undefined && usePJ !== null)usePJ.innerHTML="<a href=\"" + usePJUri.toString() + "\">배쨈 열기!</a>";
let useBanbomb = document.getElementById("useBanbomb");
let useBanbombUri = RPGinCity_pushFightInfo(nextPhaseUri.clone(), mhp, queryparams.ehp/2, queryparams.j, queryparams.bj, queryparams.bb, queryparams.etype, queryparams.elevel, 2);
if (useBanbomb !== undefined && useBanbomb !== null)useBanbomb.innerHTML="<a href=\"" + useBanbombUri.toString() + "\">차단폭탄!</a>";
//방어 페이즈
let Blocking = document.getElementById("Block");
let BlockingUri = RPGinCity_pushFightInfo(nextPhaseUri.clone(), mhp- Math.round(Math.random() * queryparams.elevel * 0.75), queryparams.ehp , queryparams.j, queryparams.bj, queryparams.bb, queryparams.etype, queryparams.elevel, 1);
if (Blocking !== undefined && Blocking !== null)Blocking.innerHTML="<a href=\"" + BlockingUri.toString() + "\">방어</a>";
let FailRunning = document.getElementById("FailRunning");
let FailRunningUri = RPGinCity_pushFightInfo(nextPhaseUri.clone(), mhp - Math.round(Math.random() * queryparams.elevel), queryparams.ehp, queryparams.j, queryparams.bj, queryparams.bb, queryparams.etype, queryparams.elevel, 1);
if (FailRunning !== undefined && FailRunning !== null)FailRunning.innerHTML="<a href=\"" + FailRunningUri.toString() + "\">도망치자!</a>";
}
function RPGinCity_SaveHandle(saveGameHandle) {
let Templink = new mw.Uri(window.location.href);
let queryparams = Templink.query;
switch (saveGameHandle.innerText){
case "서브퀘스트완료":
new mw.Api().edit("사용자:"+usernameStr+"/RPG_in_City.json", function (revision) {
let jsondata = JSON.parse(revision.content);
jsondata.추가1 = 0;
return {text: JSON.stringify(jsondata), summary: "서브퀘스트완료"};
}
).then(function () {
alert( 'Saved!' );
saveGameHandle.innerHTML="<a href=\"https://libertygame.miraheze.org/w/index.php?title="+ "사용자:"+usernameStr+"/RPG_in_City.json\">저장 확인하기</a>";
});
break;
case "서브퀘스트수행":
new mw.Api().edit("사용자:"+usernameStr+"/RPG_in_City.json", function (revision) {
let jsondata = JSON.parse(revision.content);
let questID = document.getElementById("questID");
jsondata.추가1 = parseInt(questID);
return {text: JSON.stringify(jsondata), summary: "서브퀘스트수행"};
}
).then(function () {
alert( 'Saved!' );
saveGameHandle.innerHTML="<a href=\"https://libertygame.miraheze.org/w/index.php?title="+ "사용자:"+usernameStr+"/RPG_in_City.json\">저장 확인하기</a>";
});
break;
case "메인퀘스트수행":
new mw.Api().edit("사용자:"+usernameStr+"/RPG_in_City.json", function (revision) {
let jsondata = JSON.parse(revision.content);
let questID = document.getElementById("questID");
jsondata.추가2 = parseInt(questID);
return {text: JSON.stringify(jsondata), summary: "메인퀘스트수행"};
}
).then(function () {
alert( 'Saved!' );
saveGameHandle.innerHTML="<a href=\"https://libertygame.miraheze.org/w/index.php?title="+ "사용자:"+usernameStr+"/RPG_in_City.json\">저장 확인하기</a>";
});
break;
case "동부요금지불":
new mw.Api().edit("사용자:"+usernameStr+"/RPG_in_City.json", function (revision) {
let jsondata = JSON.parse(revision.content);
jsondata.돈 -= 500;
jsondata.추가2 = 5;
return {text: JSON.stringify(jsondata), summary: "동부요금지불"};
}
).then(function () {
alert( 'Saved!' );
saveGameHandle.innerHTML="<a href=\"https://libertygame.miraheze.org/w/index.php?title="+ "사용자:"+usernameStr+"/RPG_in_City.json\">저장 확인하기</a>";
});
break;
case "전투승리":
new mw.Api().edit("사용자:"+usernameStr+"/RPG_in_City.json", function (revision) {
let jsondata = JSON.parse(revision.content);
jsondata.체력 = queryparams.mhp;
jsondata.경험치 += queryparams.elevel*2;
jsondata.돈 += queryparams.elevel*5;
return {text: JSON.stringify(jsondata), summary: "전투승리"};
}
).then(function () {
alert( 'Saved!' );
saveGameHandle.innerHTML="<a href=\"https://libertygame.miraheze.org/w/index.php?title="+ "사용자:"+usernameStr+"/RPG_in_City.json\">저장 확인하기</a>";
});
break;
case "레벨업":
new mw.Api().edit("사용자:"+usernameStr+"/RPG_in_City.json", function (revision) {
let jsondata = JSON.parse(revision.content);
jsondata.레벨 += (jsondata.경험치 - jsondata.경험치 % 128)/128
jsondata.경험치 = jsondata.경험치 % 128;
return {text: JSON.stringify(jsondata), summary: "레벨업"};
}
).then(function () {
alert( 'Saved!' );
saveGameHandle.innerHTML="<a href=\"https://libertygame.miraheze.org/w/index.php?title="+ "사용자:"+usernameStr+"/RPG_in_City.json\">저장 확인하기</a>";
});
break;
case "회복":
new mw.Api().edit("사용자:"+usernameStr+"/RPG_in_City.json", function (revision) {
let jsondata = JSON.parse(revision.content);
jsondata.체력 = jsondata.레벨 * 16;
return {text: JSON.stringify(jsondata), summary: "회복"};
}
).then(function () {
alert( 'Saved!' );
saveGameHandle.innerHTML="<a href=\"https://libertygame.miraheze.org/w/index.php?title="+ "사용자:"+usernameStr+"/RPG_in_City.json\">저장 확인하기</a>";
});
break;
case "결제":
new mw.Api().edit("사용자:"+usernameStr+"/RPG_in_City.json", function (revision) {
let jsondata = JSON.parse(revision.content);
jsondata.잼 += queryparams.j;
jsondata.배쨈 += queryparams.bj;
jsondata.차단폭탄 += queryparams.bb;
jsondata.무기 += queryparams.weapon;
jsondata.돈 -= 50* queryparams.j + 75*queryparams.bj + 150*queryparams.bb + 1000 * queryparams.weapon;
return {text: JSON.stringify(jsondata), summary: "결제"};
}
).then(function () {
alert( 'Saved!' );
saveGameHandle.innerHTML="<a href=\"https://libertygame.miraheze.org/w/index.php?title="+ "사용자:"+usernameStr+"/RPG_in_City.json\">저장 확인하기</a>";
});
break;
default:
alert( 'No proper parameters' );
saveGameHandle.innerHTML="<a href=\"https://libertygame.miraheze.org/w/index.php?title="+ "사용자:"+usernameStr+"/RPG_in_City.json\">저장 확인하기</a>";
break;
}
}
function RPGinCity_Callback_fetchUserInformation(jsonfile) {
// 정보 틀 관련
let playerinfo = document.getElementsByClassName("Playerinfo");
let LevelUpButton = document.getElementById("LevelUp");
playerinfo[0].innerText = jsonfile.레벨;
playerinfo[1].innerText = jsonfile.체력;
playerinfo[2].innerText = jsonfile.경험치;
playerinfo[3].innerText = jsonfile.잼;
playerinfo[4].innerText = jsonfile.배쨈;
playerinfo[5].innerText = jsonfile.차단폭탄;
playerinfo[6].innerText = jsonfile.돈;
playerinfo[7].innerText = jsonfile.무기;
if (jsonfile.경험치 > 128 && jsonfile.레벨 + jsonfile.경험치 /128 <= 50) {
LevelUpButton.innerHTML = "<a href= \"https://libertygame.miraheze.org/wiki/RPG_in_City/레벨_업\">레벨 업!</a>";
}
// RPG in City/집 쉬기 기능
let RestingInHouse = document.getElementById("House");
if (RestingInHouse !== undefined && jsonfile.체력 < jsonfile.레벨 * 16){
RestingInHouse.innerText = "너는 한숨 자고 개운한 마음으로 이곳을 나가려고 한다.\n[[/회복|쉬기]]";
}
// RPG in City 전투 관련 스크립트
let inBattle = document.getElementById("Fight");
if (inBattle !== undefined && inBattle !== null){
RPGinCity_HandleBattle();
} // 전투 틀 처리 완료
// 자동 세이브 처리
let saveGameHandle = document.getElementById("saveGame");
if (saveGameHandle !== undefined && saveGameHandle !== null) {
console.log("Saving...");
RPGinCity_SaveHandle(saveGameHandle);
}
}
// ----------------------------------------------------Main------------------------------------------------------------
if (currentpage === "RPG in City") {
RPGinCity_Title();
}
else if (currentpage === "사용자:"+usernameStr+"/RPG in City.json"){
RPGinCity_GoToCheckpoint();
}
else if (currentpage.substring(0,11) == "RPG_in_City") { // in game but not in title screen
console.log("fetching player info...");
fetch("https://libertygame.miraheze.org/w/index.php?title="+"사용자:"+usernameStr+"/RPG_in_City.json"+"&action=raw")
.then(response => response.json())
.then(response => RPGinCity_Callback_fetchUserInformation(response));
}