사용자:Jinhoftyu/Undungeon/플러그인: 두 판 사이의 차이

리버티게임, 모두가 만들어가는 자유로운 게임
편집 요약 없음
태그: 수동 되돌리기
잔글 ("사용자:Jinhoftyu/Undungeon/플러그인" 문서를 보호했습니다: 플러그인 코드는 자동 인증된 사용자부터 편집 가능하게 할 예정 ([편집=자동 인증된 사용자만 허용] (무기한) [이동=자동 인증된 사용자만 허용] (무기한)))
 

2024년 8월 13일 (화) 16:37 기준 최신판

요령 => 아래 변수들의 첫번째 인자들을 내용에 맞게 자르고 붙여넣어주세요

!!!!!!!!!!!!!!!! 플러그인 정보 입력 구간 윗부분은 만지지 마시오 절대로!!!!!!!!!!!!!!!!!






!!!!!!!!!!!!!!!! 플러그인 정보 입력 구간 끝 아래는 만지지 마시오!!!!!!!!!!!!!!!!!

이 플러그인에 대한 설명문서는 사용자:Jinhoftyu/Undungeon/플러그인/설명문서에서 만들 수 있습니다.

		 // 이부분에 코드 입력 //
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

class Item {
  constructor(type, name, value) {
    this.type = type;
    this.name = name;
    this.value = value;
  }
}

class Entity {
  constructor(type, name, x, y, health) {
    this.type = type;
    this.name = name;
    this.x = x;
    this.y = y;
    this.health = health;
  }

  getAttack() {
    return getAttack(this.name);
  }
}

const rand = new (function() {
  const seed = new Date().getTime();
  this.nextInt = (n) => Math.floor(Math.random() * n);
  this.seed = (s) => {};
})();

let game = false;
let mapY = 20;
let mapX = 80;
const base = new Array(mapY).fill(null).map(() => new Array(mapX).fill(null));
const entity = new Array(mapY).fill(null).map(() => new Array(mapX).fill(null));
const entities = [];
const item = [];

let dl = 0;
let xl = 0;
let hp = 0;
let maxhp = 0;
let pw = 0;
let maxpw = 0;
let time = 0;

let role;
let name = null;
let pl;
const inv = [];

const log = [];

function refLog() {
  while (log.length > 3) {
    log.shift();
  }
}

async function main() {
  for (let i = 0; i < mapY; i++) {
    const row = [];
    for (let j = 0; j < mapX; j++) {
      row.push([]);
    }
    item.push(row);
  }

  while (name === null) {
    name = await askQuestion('Your name?');
  }

  while (!game) {
    const roleInput = await askQuestion(`
                    Your role?
                    a) Monk
                    b) Ranger
                    c) Valkryie
                    d) Wizard`);
    preset(roleInput);
  }

  mapGen();

  while (game) {
    if (showInv) {
      inventory();
      await askQuestion();
    } else {
      display();
      const cmd = (await askQuestion()).split(' ');
      switch (cmd[0]) {
        case '.':
          turn();
          break;
        case 'h':
          move(pl, -1, 0);
          break;
        case 'l':
          move(pl, 1, 0);
          break;
        case 'j':
          move(pl, 0, -1);
          break;
        case 'k':
          move(pl, 0, 1);
          break;
        case 'y':
          move(pl, -1, -1);
          break;
        case 'u':
          move(pl, 1, -1);
          break;
        case 'b':
          move(pl, -1, 1);
          break;
        case 'n':
          move(pl, 1, 1);
          break;
        case '<':
          ascend();
          break;
        case ',':
          pickup();
          break;
        case 'i':
          showInv = true;
          break;
        case 'Q':
          process.exit(0);
          break;
      }
    }
  }
}

function updateStack(x, y, items) {
  item[y][x] = items;
}

async function pickup() {
  const plx = pl.x;
  const ply = pl.y;
  const items = item[ply][plx];
  if (items.length > 0) {
    const i = items[0];
    inv.push(i);
    items.shift();
    updateStack(plx, ply, items);
    log.push(`You picked up ${itemName(i)}.`);
    turn();
  } else {
    log.push('There is nothing here.');
  }
}

function ascend() {
  const plx = pl.x;
  const ply = pl.y;
  if (base[ply][plx] === '<') {
    console.log('You escaped from the dungeon.');
    process.exit(0);
  } else {
    log.push("You can't go up here.");
  }
}

function itemName(i) {
  return `${i.value} ${i.name}${i.value > 1 ? 's' : }`;
}

async function move(en, dx, dy) {
  const x = en.x;
  const y = en.y;
  if (base[y + dy][x + dx] !== '#' && entity[y + dy][x + dx] === null) {
    entity[y][x] = null;
    en.x += dx;
    en.y += dy;
    const floor = base[en.y][en.x];
    entity[en.y][en.x] = en;
    const items = item[en.y][en.x];

    // log output
    if (en === pl) {
      turn();
      if (floor !== '.' && floor !== '\0') {
        log.push(`You are standing in ${floorDes(floor)}.`);
      }
      if (items.length > 1) {
        log.push('You see here several items.');
      } else if (items.length > 0) {
        const i = items[0];
        log.push(`You see here ${itemName(i)}.`);
      }
    }
  }
}

async function turn() {
  for (const e of entities) {
    if (e !== pl) {
      if (adjacent(e, pl)) {
        attack(e, pl);
      } else {
        switch (rand.nextInt(8)) {
          case 0:
            move(e, -1, 0);
            break;
          case 1:
            move(e, 1, 0);
            break;
          case 2:
            move(e, 0, -1);
            break;
          case 3:
            move(e, 0, 1);
            break;
          case 4:
            move(e, -1, -1);
            break;
          case 5:
            move(e, 1, -1);
            break;
          case 6:
            move(e, -1, 1);
            break;
          case 7:
            move(e, 1, 1);
            break;
        }
      }
    }
  }
  time++;
}

function mapGen() {
  for (let y = 0; y < mapY; y++) {
    for (let x = 0; x < mapX; x++) {
      // old mapgen
      const xborder = (y === 1