• R/O
  • SSH
  • HTTPS

thief: Commit


Commit MetaInfo

Revision31 (tree)
Time2012-01-10 02:02:09
Authorseussnu

Log Message

0.0.7-alpha10
・ 階段の昇降処理を追加

Change Summary

Incremental Difference

--- thief.js (revision 30)
+++ thief.js (revision 31)
@@ -45,7 +45,8 @@
4545 languagePriolity : ['en', 'ja'],
4646 statusPosition : 'bottom', // top or bottom
4747 statusLineFormat : [
48- '${THIEF.global.adventurer.%get@name%}' +
48+ '${THIEF.global.actDG.%get@name%}:${THIEF.global.actDG.nowLV}' +
49+ ' ${THIEF.global.adventurer.%get@name%}' +
4950 ' ♥:${THIEF.global.adventurer.%get@hp%}' +
5051 ' STR:${THIEF.global.adventurer.%get@str%}' +
5152 ' CON:${THIEF.global.adventurer.%get@con%}' +
@@ -438,6 +439,29 @@
438439 return result;
439440 };
440441
442+THIEF.func.method.getInventoryRandomFreeSpace = function (obj) {
443+ var point;
444+ var challenge = this.get(THIEF.PROP.inventoryWidth) * this.get(THIEF.PROP.inventoryHeight);
445+ var counter = 0;
446+ while (counter < challenge) {
447+ counter++;
448+ var x = Math.round(Math.random() * this.get(THIEF.PROP.inventoryWidth));
449+ var y = Math.round(Math.random() * this.get(THIEF.PROP.inventoryHeight));
450+ point = this.getInventoryFreeSpace(obj, x, y);
451+
452+ if (typeof point !== 'undefined' && this.inventory[x][y].getLast().type === THIEF.Data.Obj.$Floor.type) {
453+ //if (point.x === 'number' && typeof point.y === 'number') {
454+ break;
455+ }
456+ }
457+ // ランダムに見つからなければ、左上から順に検索
458+ if (typeof point.x !== 'number' && typeof point.y !== 'number') {
459+ point = this.getInventoryFreeSpace(obj);
460+ }
461+
462+ return point;
463+};
464+
441465 THIEF.func.method.getInventoryFreeSpace = function(obj, _x, _y) {
442466
443467 var invCellSize = this.get(THIEF.PROP.inventoryCellSize) || 10;
@@ -472,7 +496,6 @@
472496 if (this.inventory && this.inventory[targetX] && this.inventory[targetX][targetY]) {
473497 if (this.inventory[targetX][targetY].length <= invDepth) {
474498 var lastObj = this.inventory[targetX][targetY].getLast();
475- // TODO
476499 if (lastObj.type !== THIEF.Data.Obj.$Wall.type && (obj.get(THIEF.PROP.stackable) || typeof lastObj === 'undefined' || lastObj.get(THIEF.PROP.stackable)) /* || !lastObj.get(THIEF.PARAM.mergeable) */) {
477500 if (lastObj) {
478501 THIEF.html.addDebugMessage('[' + targetX + ', ' + targetY + ']にある' + lastObj.get(THIEF.PROP.displayName) + 'には重ねられる。');
@@ -1039,7 +1062,7 @@
10391062 }
10401063
10411064 if (typeof finish === 'undefined') {
1042- if(code !== THIEF.KEY.Esc){
1065+ if (code !== THIEF.KEY.Esc) {
10431066 THIEF.html.addMessage(THIEF.util.getText(THIEF.Data.Text.commandNotFound, String.fromCharCode(code)));
10441067 }
10451068 finish = false;
@@ -1054,6 +1077,20 @@
10541077 return finish;
10551078 };
10561079
1080+
1081+THIEF.func.method.spawn = function (obj) {
1082+ THIEF.html.addDebugMessage('湧き処理を開始...');
1083+
1084+ // 空きスペースの検索条件
1085+ var point = this.getInventoryRandomFreeSpace(obj);
1086+ this.addToInventory(obj, point.x, point.y);
1087+ THIEF.html.refreshXy(obj.x, obj.y);
1088+ THIEF.html.addDebugMessage('...湧き処理を完了');
1089+
1090+ return obj;
1091+};
1092+
1093+
10571094 THIEF.func.command = {}; // マニュアルコマンドで実行して良いもの
10581095 THIEF.func.command.goUp = function() {
10591096 return this.move(0, -1);
@@ -1461,13 +1498,12 @@
14611498 return false;
14621499 };
14631500
1464-// TODO
1465-THIEF.func.command.goUpTheStairs = function(){
1501+THIEF.func.command.goUpTheStairs = function() {
14661502 var floor = THIEF.global.actLV.getInventoryXyObjects(this.x, this.y);
14671503 var stairs;
14681504 var flag = false;
1469- for(var i=0; i<floor.length; i++){
1470- if(floor[i].symbol === THIEF.Data.Obj.UpStairs.symbol){
1505+ for (var i = 0; i < floor.length; i++) {
1506+ if (floor[i].symbol === THIEF.Data.Obj.UpStairs.symbol) {
14711507 flag = true;
14721508 stairs = floor[i];
14731509 break;
@@ -1474,22 +1510,48 @@
14741510 }
14751511 }
14761512
1477- if(flag){
1478- THIEF.html.addMessage(THIEF.Data.Text.goUpStairs);
1513+ if (flag) {
1514+ THIEF.html.addMessage(THIEF.util.getText(THIEF.Data.Text.goUpStairs, this.get(THIEF.PROP.displayName)));
14791515 THIEF.util.createLevel(stairs.nextDun, stairs.nextLv);
14801516 THIEF.global.actLV.removeFromInventory(this);
14811517 THIEF.global.actDG = stairs.nextDun;
1482- THIEF.global.actLV = stairs.nextLv;
1483- THIEF.global.actLV.addToInventory(this);
1518+ THIEF.global.actDG.nowLV = stairs.nextLv;
1519+ THIEF.global.actLV = stairs.nextDun[stairs.nextLv];
1520+ THIEF.global.actLV.addToInventory(this, THIEF.global.actLV.downStairsPoint.x, THIEF.global.actLV.downStairsPoint.y);
1521+ THIEF.html.refresh();
14841522 } else {
1485- THIEF.html.addMessage(THIEF.Data.Text.doesNotGoUpStairs);
1523+ THIEF.html.addMessage(THIEF.util.getText(THIEF.Data.Text.doesNotGoUpStairs));
14861524 }
14871525
14881526 return flag;
14891527 };
14901528
1491-THIEF.func.command.goDownTheStairs = function(){
1529+THIEF.func.command.goDownTheStairs = function() {
1530+ var floor = THIEF.global.actLV.getInventoryXyObjects(this.x, this.y);
1531+ var stairs;
1532+ var flag = false;
1533+ for (var i = 0; i < floor.length; i++) {
1534+ if (floor[i].symbol === THIEF.Data.Obj.DownStairs.symbol) {
1535+ flag = true;
1536+ stairs = floor[i];
1537+ break;
1538+ }
1539+ }
14921540
1541+ if (flag) {
1542+ THIEF.html.addMessage(THIEF.util.getText(THIEF.Data.Text.goDownStairs, this.get(THIEF.PROP.displayName)));
1543+ THIEF.util.createLevel(stairs.nextDun, stairs.nextLv);
1544+ THIEF.global.actLV.removeFromInventory(this);
1545+ THIEF.global.actDG = stairs.nextDun;
1546+ THIEF.global.actDG.nowLV = stairs.nextLv;
1547+ THIEF.global.actLV = stairs.nextDun[stairs.nextLv];
1548+ THIEF.global.actLV.addToInventory(this, THIEF.global.actLV.upStairsPoint.x, THIEF.global.actLV.upStairsPoint.y);
1549+ THIEF.html.refresh();
1550+ } else {
1551+ THIEF.html.addMessage(THIEF.util.getText(THIEF.Data.Text.doesNotGoDownStairs));
1552+ }
1553+
1554+ return flag;
14931555 };
14941556
14951557 THIEF.util = {};
@@ -1545,10 +1607,9 @@
15451607 THIEF.global.adventurer.inventoryWidth = 10;
15461608 THIEF.global.adventurer.inventoryCellSize = 1;
15471609 THIEF.global.adventurer.ct = 100;
1610+ var point = THIEF.global.actLV.getInventoryRandomFreeSpace(THIEF.global.adventurer);
1611+ THIEF.global.actLV.addToInventory(THIEF.global.adventurer, point.x, point.y);
15481612
1549- THIEF.global.actLV.addToInventory(THIEF.global.adventurer);
1550-
1551-
15521613 var tmp;
15531614 tmp = THIEF.util.factory(THIEF.Data.Obj.DebugDagger);
15541615 tmp.alphabet = 'k';
@@ -1557,11 +1618,11 @@
15571618 tmp.alphabet = 'r';
15581619 THIEF.global.adventurer.addToInventory(tmp);
15591620
1560- THIEF.util.spawn(THIEF.Data.Obj.DebugDaemon);
1561- THIEF.util.spawn(THIEF.Data.Obj.DebugDaemon);
1562- THIEF.util.spawn(THIEF.Data.Obj.DebugDaemon);
1563- THIEF.util.spawn(THIEF.Data.Obj.DebugHighArmor);
1564- THIEF.util.spawn(THIEF.Data.Obj.DebugHighDagger);
1621+ //THIEF.global.actLV.spawn(THIEF.util.factory(THIEF.Data.Obj.DebugDaemon));
1622+ //THIEF.global.actLV.spawn(THIEF.util.factory(THIEF.Data.Obj.DebugDaemon));
1623+ //THIEF.global.actLV.spawn(THIEF.util.factory(THIEF.Data.Obj.DebugDaemon));
1624+ THIEF.global.actLV.spawn(THIEF.util.factory(THIEF.Data.Obj.DebugHighArmor));
1625+ THIEF.global.actLV.spawn(THIEF.util.factory(THIEF.Data.Obj.DebugHighDagger));
15651626
15661627 };
15671628
@@ -1591,7 +1652,7 @@
15911652
15921653 // 各レベルに実施させること
15931654 if (Math.random() > 0.9) {
1594- THIEF.util.spawn(THIEF.Data.Obj.DebugDaemon);
1655+ THIEF.global.actLV.spawn(THIEF.util.factory(THIEF.Data.Obj.DebugDaemon));
15951656 }
15961657 } else {
15971658 THIEF.html.addDebugMessage('<em>ターン:' + THIEF.global.turn + ' を再開</em>...');
@@ -1949,12 +2010,19 @@
19492010 }
19502011 }
19512012 }
2013+
2014+ dun.get = THIEF.func.method.get;
2015+
19522016 THIEF.html.addDebugMessage('...ダンジョンの作成を完了');
19532017 };
19542018
1955-// TODO
19562019 THIEF.util.createLevel = function(dun, lvNum) {
1957- THIEF.html.addDebugMessage(THIEF.func.method.get.call(dun, THIEF.PROP.name) + 'の第 ' + lvNum + ' レベルを作成...');
2020+ if (dun[lvNum] && dun[lvNum].created) {
2021+ THIEF.html.addDebugMessage(THIEF.func.method.get.call(dun, THIEF.PROP.name) + 'の第 ' + lvNum + ' レベルは既に作成済み');
2022+ return;
2023+ } else {
2024+ THIEF.html.addDebugMessage(THIEF.func.method.get.call(dun, THIEF.PROP.name) + 'の第 ' + lvNum + ' レベルを作成...');
2025+ }
19582026
19592027 var level = THIEF.util.factory(THIEF.Data.Obj.$Level);
19602028 level[THIEF.PROP.inventoryWidth] = dun.width || THIEF.Data.Scenario.$.width || 60;
@@ -1962,9 +2030,10 @@
19622030 level[THIEF.PROP.inventoryDepth] = dun.depth || THIEF.Data.Scenario.$.depth || 256;
19632031 level.inventoryCellSize = 1;
19642032
2033+ var template = {};
2034+
19652035 if (dun[lvNum]) {
19662036 THIEF.html.addDebugMessage('個別シナリオのテンプレート展開...');
1967- var template = {};
19682037
19692038 // レベル系テンプレートの読み込み
19702039 if (dun[lvNum].level) {
@@ -1985,49 +2054,56 @@
19852054 // 特殊分岐実装予定
19862055 }
19872056
1988- // テンプレートに基づいて処理を実行
1989- // for (name in obj) は、オンオフの処理が後々面倒になりそうなので、
1990- // ここで逐次処理にする
1991- if(template.map) {
1992- level.inventory = THIEF.util.mapParser(template.map);
1993- level[THIEF.PROP.inventoryWidth] = level.inventory.length;
1994- level[THIEF.PROP.inventoryHeight] = level.inventory[0].length;
1995- } else {
1996- level.inventory = THIEF.util.createMap(level[THIEF.PROP.inventoryWidth], level[THIEF.PROP.inventoryHeight]);
1997- }
19982057
1999- var stairs;
2000- var point;
2001- if(template.upStairs){
2058+ THIEF.html.addDebugMessage('...展開完了。');
2059+ } else {
2060+ // テンプレートがなければ、とりあえずマップサイズのみ指定
2061+ template.width = level[THIEF.PROP.inventoryWidth];
2062+ template.height = level[THIEF.PROP.inventoryHeight];
2063+ }
20022064
2003- } else {
2065+
2066+ // テンプレートに基づいて処理を実行
2067+ // for (name in obj) は、オンオフの処理が後々面倒になりそうなので、
2068+ // ここで逐次処理にする
2069+ if (template.map) {
2070+ level.inventory = THIEF.util.mapParser(template.map);
2071+ level[THIEF.PROP.inventoryWidth] = level.inventory.length;
2072+ level[THIEF.PROP.inventoryHeight] = level.inventory[0].length;
2073+ } else {
2074+ level.inventory = THIEF.util.createMap(level[THIEF.PROP.inventoryWidth], level[THIEF.PROP.inventoryHeight]);
2075+ }
2076+
2077+ var stairs;
2078+ var point;
2079+
2080+ if (template.upStairs) {
2081+
2082+ } else {
2083+ if (lvNum > 1) {
20042084 stairs = THIEF.util.factory(THIEF.Data.Obj.UpStairs);
20052085 stairs.nextDun = THIEF.global.actDG;
2006- stairs.nextLv = THIEF.global.actDG.nowLV +1;
2007- point = level.getInventoryFreeSpace(stairs);
2086+ stairs.nextLv = lvNum - 1;
2087+ point = level.getInventoryRandomFreeSpace(stairs);
20082088 level.addToInventory(stairs, point.x, point.y);
2089+ level.upStairsPoint = point;
20092090 }
2091+ }
20102092
2011- if(template.downStairs){
2093+ if (template.downStairs) {
20122094
2013- } else {
2095+ } else {
2096+ if (lvNum <= THIEF.global.actDG.levelNum) {
20142097 stairs = THIEF.util.factory(THIEF.Data.Obj.DownStairs);
20152098 stairs.nextDun = THIEF.global.actDG;
2016- stairs.nextLv = THIEF.global.actDG.nowLV -1;
2017- point = level.getInventoryFreeSpace(stairs);
2099+ stairs.nextLv = lvNum + 1;
2100+ point = level.getInventoryRandomFreeSpace(stairs);
20182101 level.addToInventory(stairs, point.x, point.y);
2102+ level.downStairsPoint = point;
20192103 }
2020-
2021- THIEF.html.addDebugMessage('...展開完了。');
2022- } else {
2023- // 個別シナリオがないのであれば自動生成
2024- level.inventory = THIEF.util.createMap(level[THIEF.PROP.inventoryWidth], level[THIEF.PROP.inventoryHeight]);
20252104 }
20262105
2027- if (dun[lvNum].branch) {
2028-
2029- }
2030-
2106+ level.created = true;
20312107 dun[lvNum] = level;
20322108
20332109 THIEF.html.addDebugMessage('...レベルの作成を完了');
@@ -2394,25 +2470,25 @@
23942470 return map;
23952471 };
23962472
2397-THIEF.util.mapParser = function(fmt){
2473+THIEF.util.mapParser = function(fmt) {
23982474 var width = fmt[0].length;
23992475 var height = fmt.length;
24002476 var map = [];
24012477
2402- for(var h=0; h<height; h++){
2403- for(var w=0; w<width; w++){
2478+ for (var h = 0; h < height; h++) {
2479+ for (var w = 0; w < width; w++) {
24042480 switch (fmt[h].charAt(w)) {
24052481 case '.':
2406- if(typeof map[w] === 'undefined'){
2482+ if (typeof map[w] === 'undefined') {
24072483 map[w] = [];
24082484 }
2409- if(typeof map[w][h] === 'undefined'){
2485+ if (typeof map[w][h] === 'undefined') {
24102486 map[w][h] = [];
24112487 }
24122488 map[w][h].push(THIEF.util.factory(THIEF.Data.Obj.LitFloor));
24132489 break;
24142490 default:
2415- THIEF.html.addDebugMessage( map[h].charAt(w) + 'はまだ対応していない。');
2491+ THIEF.html.addDebugMessage(map[h].charAt(w) + 'はまだ対応していない。');
24162492 break;
24172493 }
24182494 }
@@ -2422,7 +2498,7 @@
24222498 // 外枠を追加
24232499 var left = [];
24242500 var right = [];
2425- for(var i=0; i<height; i++){
2501+ for (var i = 0; i < height; i++) {
24262502 left[i] = [];
24272503 right[i] = [];
24282504 left[i].push(THIEF.util.factory(THIEF.Data.Obj.NonDiggableWall));
@@ -2431,49 +2507,15 @@
24312507 map.unshift(left);
24322508 map.push(right);
24332509
2434- for(var j=0; j<map.length; j++){
2510+ for (var j = 0; j < map.length; j++) {
24352511 map[j].unshift([]);
24362512 map[j].push([]);
24372513 map[j][0].push(THIEF.util.factory(THIEF.Data.Obj.NonDiggableWall));
2438- map[j][height+1].push(THIEF.util.factory(THIEF.Data.Obj.NonDiggableWall));
2514+ map[j][height + 1].push(THIEF.util.factory(THIEF.Data.Obj.NonDiggableWall));
24392515 }
24402516 return map;
24412517 };
24422518
2443-THIEF.util.spawn = function (obj) {
2444- THIEF.html.addDebugMessage('湧き処理を開始...');
2445-
2446- var monster = null;
2447- THIEF.html.addDebugMessage('オブジェクトの複製');
2448- if (typeof obj === 'undefined') {
2449- // 条件に応じた対象を選択すること
2450- monster = THIEF.util.factory(THIEF.Data.Obj.DebugDaemon);
2451- } else {
2452- monster = THIEF.util.factory(obj);
2453- }
2454-
2455- // 空きスペースの検索条件
2456- var point;
2457- while (true) {
2458- var x = Math.round(Math.random() * THIEF.global.actLV.get(THIEF.PROP.inventoryWidth));
2459- var y = Math.round(Math.random() * THIEF.global.actLV.get(THIEF.PROP.inventoryHeight));
2460- point = THIEF.global.actLV.getInventoryFreeSpace(monster, x, y);
2461-
2462- if (typeof point !== 'undefined' && THIEF.global.actLV.inventory[x][y].getLast().isBasedOn(THIEF.Data.Obj.LitFloor)) {
2463- //if (point.x === 'number' && typeof point.y === 'number') {
2464- break;
2465- }
2466-
2467- }
2468- if (typeof point.x !== 'number' && typeof point.y !== 'number') {
2469- point = THIEF.global.actLV.getInventoryFreeSpace(monster);
2470- }
2471-
2472- THIEF.global.actLV.addToInventory(monster, point.x, point.y);
2473- THIEF.html.refreshXy(monster.x, monster.y);
2474- THIEF.html.addDebugMessage('...湧き処理を完了')
2475-};
2476-
24772519 THIEF.util.infixToRevP = function (val) {
24782520 //var val = '2d100 * (2 + 15) + Math.max(3, 4) + (Math.round(11.2) * Math.PI + 6)';
24792521 //var val = '2d100*(2+15)+Math.max(3,4)+(Math.round(11.2)*Math.PI+6)';
@@ -2807,7 +2849,7 @@
28072849
28082850
28092851 THIEF.html.refreshXy = function(x, y) {
2810- if(THIEF.global.actLV.inventory[x] && THIEF.global.actLV.inventory[x][y]){
2852+ if (THIEF.global.actLV.inventory[x] && THIEF.global.actLV.inventory[x][y]) {
28112853 var obj = THIEF.global.actLV.inventory[x][y].getLast();
28122854 if (obj.color) {
28132855 THIEF.html.setXy(x, y, '<span style="color:' + obj.color + ';">' + obj.symbol + '</span>');
@@ -3909,6 +3951,14 @@
39093951 cmd : THIEF.func.command.extendedCommand,
39103952 key : THIEF.KEY.Sharp,
39113953 text : THIEF.Data.Text.cmdExecuteCommandDesc
3954+ },
3955+ goUpStairs : {
3956+ cmd : THIEF.func.command.goUpTheStairs,
3957+ key : THIEF.KEY.LT
3958+ },
3959+ goDownStairs : {
3960+ cmd : THIEF.func.command.goDownTheStairs,
3961+ key : THIEF.KEY.GT
39123962 }
39133963 };
39143964
Show on old repository browser