사용자:Senouis/RPGinCity.js: 두 판 사이의 차이
imported>Senouis 잔글편집 요약 없음 |
imported>Senouis 잔글편집 요약 없음 |
||
75번째 줄: | 75번째 줄: | ||
if (playerhealth !== undefined) { | if (playerhealth !== undefined) { | ||
let mhp = queryparams.mhp; // mhp는 undefined, NaN일 수 있다. | let mhp = queryparams.mhp; // mhp는 undefined, NaN일 수 있다. | ||
if (mhp === undefined || mhp === null || mhp | if (mhp === undefined || mhp === null || isNaN(mhp)) { | ||
mhp = jsonfile.체력; | |||
} | |||
playerhealth.innerText = mhp; | |||
} | } | ||
//적의 레벨 | //적의 레벨 |
2020년 12월 2일 (수) 18:01 판
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_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){
let Battlelink = new mw.Uri(window.location.href);
console.log("building battle phase...");
let queryparams = Battlelink.query;
// 이제 필요한 값을 구해 화면에 표시한다.
// 플레이어 체력부터...
let playerhealth = document.getElementById("playerhealth");
if (playerhealth !== undefined) {
let mhp = queryparams.mhp; // mhp는 undefined, NaN일 수 있다.
if (mhp === undefined || mhp === null || isNaN(mhp)) {
mhp = jsonfile.체력;
}
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 attackEnemyUri = RPGinCity_pushFightInfo(nextPhaseUri.clone(), queryparams.mhp, queryparams.ehp - Math.round(Math.random() * jsonfile.레벨), 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(), queryparams.mhp, queryparams.ehp - 20, 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(), queryparams.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(), queryparams.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(), queryparams.mhp, queryparams.ehp - Math.round(Math.random() * queryparams.elevel), queryparams.j, queryparams.bj, queryparams.bb, queryparams.etype, queryparams.elevel, 1);
if (FailRunning !== undefined && FailRunning !== null)FailRunning.innerHTML="<a href=\"" + FailRunningUri.toString() + "\">도망치자!</a>";
} // 전투 틀 처리 완료
}
// ----------------------------------------------------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));
}