사용자:Jinhoftyu/Undungeon/플러그인

리버티게임, 모두가 만들어가는 자유로운 게임
< 사용자:Jinhoftyu‎ | Undungeon
Jinhoftyu (토론 | 기여)님의 2023년 10월 18일 (수) 14:55 판
요령 => 아래 변수들의 첫번째 인자들을 내용에 맞게 자르고 붙여넣어주세요

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






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

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

		 // 이부분에 코드 입력 //
class Random {
  nextInt(max) {
    return Math.floor(Math.random() * max);
  }
}

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

  getType() {
    return this.type;
  }

  getName() {
    return this.name;
  }

  getValue() {
    return this.value;
  }

  setName(name) {
    this.name = name;
  }

  setValue(value) {
    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;
  }

  getType() {
    return this.type;
  }

  getName() {
    return this.name;
  }

  getHealth() {
    return this.health;
  }

  getAttack() {
    return Main.getAttack(this.getName());
  }

  setHealth(health) {
    this.health = health;
  }

  getX() {
    return this.x;
  }

  setX(x) {
    this.x = x;
  }

  getY() {
    return this.y;
  }

  setY(y) {
    this.y = y;
  }
}

class StringBuilder {
  constructor() {
    this.data = [];
  }

  append(text) {
    this.data.push(text);
  }

  delete(start, end) {
    this.data.splice(start, end - start);
  }

  length() {
    return this.data.length;
  }

  charAt(index) {
    return this.data[index];
  }

  toString() {
    return this.data.join();
  }
}

const rand = new Random();
let game = false;
const mapY = 20;
const mapX = 80;
const base = new Array(mapY);
const entity = new Array(mapY);
const entities = [];
const item = [];

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

let role;
let name = null;
let pl;
const inv = [];
const log = new StringBuilder();
let showInv = false;

function refLog() {
  let size = 0;
  for (let i = 0; i < log.length(); i++) {
    if (log.charAt(i) === '\n') {
      size++;
    }
  }

  if (size > 3) {
    let index = log.toString().indexOf("\n") + 1;
    log.delete(0, index);
  }
}

function main() {
  for (let i = 0; i < mapY; i++) {
    const row = new Array(mapX);
    base[i] = row;

    const entityRow = new Array(mapX);
    entity[i] = entityRow;
  }

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

  const askName = () => {
    rl.question("Your name? ", (answer) => {
      name = answer;
      while (!game) {
        console.log(`
        Your role?
        a) Monk
        b) Ranger
        c) Valkryie
        d) Wizard`);
        rl.question("Choose your role: ", (roleChoice) => {
          preset(roleChoice);
          mapGen();
          gameLoop();
        });
      }
    });
  };

  askName();
}

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

function pickup() {
  const plx = pl.getX();
  const ply = pl.getY();
  const items = item[ply][plx];
  if (items.length > 0) {
    const item = items[0];
    inv.push(item);
    items.shift();
    updateStack(plx, ply, items);
    log.append("You picked up " + itemName(item) + ".\n");
    turn();
  } else {
    log.append("There is nothing here.\n");
  }
}

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

function itemName(item) {
  return item.getValue() + " " + item.getName() + (item.getValue() > 1 ? "s" : "");
}

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

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

function turn() {
  for (let i = 0; i < entities.length; i++) {
    const e = entities[i];
    if (e !== pl) {
      if (adjacent(e, pl)) {
        attack(e, pl);
      } else {
        const randChoice = rand.nextInt(8);
        switch (randChoice) {
          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