diff --git a/_server/comment.js b/_server/comment.js index e6e61334..f2aeffdd 100644 --- a/_server/comment.js +++ b/_server/comment.js @@ -19,10 +19,11 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "keys", "items", "constants", - "tools" + "tools", + "equips" ] }, - "_data": "只能取keys(钥匙) items(宝石、血瓶) constants(永久物品) tools(消耗道具)" + "_data": "只能取keys(钥匙) items(宝石、血瓶) constants(永久物品) tools(消耗道具) equip(装备)" }, "name": { "_leaf": true, @@ -35,7 +36,39 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_type": "textarea", "_string": true, "_data": "道具在道具栏中显示的描述" - } + }, + "equip": { + "_leaf": false, + "_type": "object", + "_data": { + "type": { + "_leaf": true, + "_type": "textarea", + "_data": "装备的类别,与equipName按顺序对应" + }, + "atk": { + "_leaf": true, + "_type": "textarea", + "_data": "装备增加的攻击数值" + }, + "def": { + "_leaf": true, + "_type": "textarea", + "_data": "装备增加的防御数值" + }, + "mdef": { + "_leaf": true, + "_type": "textarea", + "_data": "装备增加的魔防数值" + }, + "animate": { + "_leaf": true, + "_type": "textarea", + "_string": true, + "_data": "装备的攻击动画,仅对type为0的装备有效" + } + } + }, } }, "itemEffect": { @@ -57,14 +90,14 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_type": "textarea", "_string": true, "_lint": true, - "_data": "cls为tools或contants时的使用物品效果。" + "_data": "cls为tools或constants时的使用物品效果。" }, "canUseItemEffect": { "_leaf": true, "_type": "textarea", "_string": true, "_lint": true, - "_data": "cls为tools或contants时对当前能否使用该物品的判断。" + "_data": "cls为tools或constants时对当前能否使用该物品的判断。" } } }, diff --git a/_server/data.comment.js b/_server/data.comment.js index 3cd98103..69715eaf 100644 --- a/_server/data.comment.js +++ b/_server/data.comment.js @@ -47,6 +47,11 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_type": "textarea", "_data": "难度选择:每个数组的第一个是其在标题界面显示的难度,第二个是在游戏内部传输的字符串,会显示在状态栏,修改此处后需要在project/functions中作相应更改" }, + "equipName": { + "_leaf": true, + "_type": "textarea", + "_data": "装备位名称,为不超过6个的数组,此项的顺序与equiptype数值关联" + }, "statusLeftBackground": { "_leaf": true, "_type": "textarea", @@ -144,6 +149,11 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_type": "textarea", "_data": "初始经验" }, + "equipment": { + "_leaf": true, + "_type": "textarea", + "_data": "初始装备" + }, "items": { "_leaf": false, "_type": "object", @@ -162,6 +172,11 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_leaf": true, "_type": "textarea", "_data": "初始消耗道具个数,例如初始有两破可以写 {\"pickaxe\": 2}" + }, + "equips": { + "_leaf": true, + "_type": "textarea", + "_data": "初始装备个数,例如初始送铁剑可以写 {\"sword1\": 1}" } } }, @@ -276,66 +291,6 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_type": "textarea", "_data": "绿血瓶加血数值" }, - "sword0": { - "_leaf": true, - "_type": "textarea", - "_data": "空剑的攻击力,此项请保持为0" - }, - "shield0": { - "_leaf": true, - "_type": "textarea", - "_data": "空盾的防御力,此项请保持为0" - }, - "sword1": { - "_leaf": true, - "_type": "textarea", - "_data": "铁剑加攻数值" - }, - "shield1": { - "_leaf": true, - "_type": "textarea", - "_data": "铁盾加防数值" - }, - "sword2": { - "_leaf": true, - "_type": "textarea", - "_data": "银剑加攻数值" - }, - "shield2": { - "_leaf": true, - "_type": "textarea", - "_data": "银盾加防数值" - }, - "sword3": { - "_leaf": true, - "_type": "textarea", - "_data": "骑士剑加攻数值" - }, - "shield3": { - "_leaf": true, - "_type": "textarea", - "_data": "骑士盾加防数值" - }, - "sword4": { - "_leaf": true, - "_type": "textarea", - "_data": "圣剑加攻数值" - }, - "shield4": { - "_leaf": true, - "_type": "textarea", - "_data": "圣盾加防数值" - }, - "sword5": { - "_leaf": true, - "_type": "textarea", - "_data": "神圣剑加攻数值" - }, - "shield5": { - "_leaf": true, - "_type": "textarea", - "_data": "神圣盾加防数值" - }, "moneyPocket": { "_leaf": true, "_type": "textarea", @@ -472,7 +427,13 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_leaf": true, "_type": "checkbox", "_bool": "bool", - "_data": "剑和盾是否直接作为装备。如果此项为true,则作为装备,需要在道具栏使用,否则将直接加属性。" + "_data": "剑和盾是否作为装备。如果此项为true,则作为装备,需要在装备栏使用,否则将直接加属性。" + }, + "equipboxBotton": { + "_leaf": true, + "_type": "checkbox", + "_bool": "bool", + "_data": "若此项为true则将状态栏中的楼层转换器按钮换为装备栏按钮,同时启用装备栏,无论equipment是否为true" }, /* "enableDeleteItem": { diff --git a/libs/actions.js b/libs/actions.js index de4ca739..53fb05ae 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -113,6 +113,10 @@ actions.prototype.keyDown = function(keyCode) { this.keyDownQuickShop(keyCode); return; } + if (core.status.event.id=='equipbox') { + this.keyDownEquipbox(keyCode); + return; + } if (core.status.event.id=='toolbox') { this.keyDownToolbox(keyCode); return; @@ -226,6 +230,10 @@ actions.prototype.keyUp = function(keyCode, fromReplay) { this.keyUpToolbox(keyCode); return; } + if (core.status.event.id=='equipbox') { + this.keyUpEquipbox(keyCode); + return; + } if (core.status.event.id=='save' || core.status.event.id=='load' || core.status.event.id=='replayLoad') { this.keyUpSL(keyCode); return; @@ -281,6 +289,10 @@ actions.prototype.keyUp = function(keyCode, fromReplay) { if (core.status.heroStop) core.useFly(true); break; + case 81: // Q + if (core.status.heroStop) + core.openEquipbox(true); + break; case 88: // X if (core.status.heroStop) core.openBook(true); @@ -585,6 +597,12 @@ actions.prototype.onclick = function (x, y, stepPostfix) { return; } + // 装备栏 + if (core.status.event.id == 'equipbox') { + this.clickEquipbox(x,y); + return; + } + // 工具栏 if (core.status.event.id == 'toolbox') { this.clickToolbox(x,y); @@ -1202,6 +1220,12 @@ actions.prototype.keyUpQuickShop = function (keycode) { ////// 工具栏界面时的点击操作 ////// actions.prototype.clickToolbox = function(x,y) { + // 装备栏 + if (x>=10 && x<=12 && y==0 && core.flags.equipment) { + core.ui.closePanel(); + core.openEquipbox(); + return; + } // 返回 if (x>=10 && x<=12 && y==12) { core.ui.closePanel(); @@ -1220,36 +1244,33 @@ actions.prototype.clickToolbox = function(x,y) { return; } */ - - // 当前页面 - var page = parseInt((core.status.event.selection%1000)/12)+1; - + var toolsPage = core.status.event.data.toolsPage; + var constantsPage = core.status.event.data.constantsPage // 上一页 - if ((x == 3 || x == 4) && y == 12) { - if (page>1) { - core.ui.drawToolbox(core.status.event.selection-12); - } + if (x == 3 || x == 4) { + if ( y == 7 && toolsPage>1) + core.status.event.data.toolsPage--; + if ( y == 12 && constantsPage>1) + core.status.event.data.constantsPage--; + core.ui.drawToolbox(core.status.event.selection) return; } // 下一页 - if ((x == 8 || x == 9) && y == 12) { - var toolPage = Math.ceil(Object.keys(core.status.hero.items.tools).length/12), - constantPage = Math.ceil(Object.keys(core.status.hero.items.constants).length/12); - if (page=0) this.clickToolboxIndex(index); @@ -1258,17 +1279,19 @@ actions.prototype.clickToolbox = function(x,y) { ////// 选择工具栏界面中某个Index后的操作 ////// actions.prototype.clickToolboxIndex = function(index) { var items = null; - var ii=index; - if (ii<1000) + var select; + if (index<12) { + select = index + 12 * (core.status.event.data.toolsPage-1); items = Object.keys(core.status.hero.items.tools).sort(); + } else { - ii-=1000; + select = index%12 + 12 * (core.status.event.data.constantsPage-1); items = Object.keys(core.status.hero.items.constants).sort(); } if (items==null) return; - if (ii>=items.length) return; - var itemId=items[ii]; - if (itemId==core.status.event.data) { + if (select>=items.length) return; + var itemId=items[select]; + if (itemId==core.status.event.data.selectId) { core.events.useItem(itemId); } else { @@ -1282,67 +1305,83 @@ actions.prototype.keyDownToolbox = function (keycode) { var tools = Object.keys(core.status.hero.items.tools).sort(); var constants = Object.keys(core.status.hero.items.constants).sort(); - var index=core.status.event.selection; - var page=parseInt(index%1000/12), offset=12*page; + var index = core.status.event.selection; + var toolsPage = core.status.event.data.toolsPage; + var constantsPage = core.status.event.data.constantsPage; + var toolsTotalPage = Math.ceil(tools.length/12); + var constantsTotalPage = Math.ceil(constants.length/12); if (keycode==37) { // left - if ((index>0 && index<1000) || index>1000) { - this.clickToolboxIndex(index-1); - return; - } - if (index==1000 && tools.length>0) { - this.clickToolboxIndex(tools.length-1); - return; - } + if (index==0) // 处理向前翻页 + if (toolsPage>1) { + core.status.event.data.toolsPage--; + index = 11; + } + else return; // 第一页不向前翻 + else if (index==12) + if (constantsPage>1) { + core.status.event.data.constantsPage--; + index = 23; + } + else return; + else index -= 1 ; + this.clickToolboxIndex(index); + return; } if (keycode==38) { // up - if ((index>offset+5 && index<1000) || index>offset+1005) { - this.clickToolboxIndex(index-6); - return; - } - if (index>=offset+1000 && index<=offset+1005) { - if (tools.length>offset+6) { - this.clickToolboxIndex(Math.min(tools.length-1, index-1000+6)); - } - else if (tools.length>offset) { - this.clickToolboxIndex(Math.min(tools.length-1, index-1000)); - } - return; + if (toolsPage==toolsTotalPage&&index<18&&index>11) { // 进入tools + if (toolsTotalPage==0) return; + if (tools.length%12<=6 && tools.length%12>index%12) index -= 12; + else if (tools.length%12>6 && tools.length%6>index%12) index -= 6; + else index = tools.length%12-1; } + else if (index<6) return; // 第一行没有向上 + else index -= 6; + this.clickToolboxIndex(index); + return; } if (keycode==39) { // right - if ((index=1000 && index0) { - this.clickToolboxIndex(1000); - return; + else if (constantsPageoffset+6) { - this.clickToolboxIndex(Math.min(tools.length-1, index+6)); - } - else if (constants.length>offset) { - this.clickToolboxIndex(1000+Math.min(constants.length-1, index)); - } - return; - } - if (index>offset+5 && indexoffset) { - this.clickToolboxIndex(1000+Math.min(constants.length-1, index-6)); - return; - } - if (index>=offset+1000 && index<=offset+1005 && constants.length>offset+6) { - this.clickToolboxIndex(Math.min(1000+constants.length-1, index+6)); - return; + if ((index>5 || (toolsPage==toolsTotalPage && tools.length%12<=6)) && index<12) {// 进入constant + if (constantsTotalPage == 0) return; + if (constantsTotalPage == constantsPage && constants.length%12<(index%6+1)) + index = constants.length%12+11; + else if (index<6) index += 12; + else index += 6; } + else if (toolsPage==toolsTotalPage && tools.length%12>6 && index > tools.length%6 &&index<6) + index = tools.length%12-1; + else if (constantsPage==constantsTotalPage && constants.length%12>6 && index>constants.length%6+11 && index<18) + index = constants.length%12+11; + else if (index>17 || (constantsPage==constantsTotalPage && constants.length%12<=6 && index>11)) return;//最后一行无操作 + else index += 6; + this.clickToolboxIndex(index); + return; } } ////// 工具栏界面时,放开某个键的操作 ////// actions.prototype.keyUpToolbox = function (keycode) { + if (keycode==81){ + core.ui.closePanel(); + core.openEquipbox(); + return; + } if (keycode==84 || keycode==27 || keycode==88) { core.ui.closePanel(); return; @@ -1370,6 +1409,165 @@ actions.prototype.keyUpToolbox = function (keycode) { } + +////// 装备栏界面时的点击操作 ////// +actions.prototype.clickEquipbox = function(x,y) { + // 道具栏 + if (x>=10 && x<=12 && y==0) { + core.ui.closePanel(); + core.openToolbox(); + return; + } + // 返回 + if (x>=10 && x<=12 && y==12) { + core.ui.closePanel(); + return; + } + + // 当前页面 + var page = core.status.event.data.page; + + // 上一页 + if ((x == 3 || x == 4) && y == 12) { + if (page>1) { + core.status.event.data.page--; + core.ui.drawEquipbox(core.status.event.selection); + } + return; + } + // 下一页 + if ((x == 8 || x == 9) && y == 12) { + var lastPage = Math.ceil(Object.keys(core.status.hero.items.equips).length/12); + if (page=0) + this.clickEquipboxIndex(index); +} + +////// 选择装备栏界面中某个Index后的操作 ////// +actions.prototype.clickEquipboxIndex = function(index) { + if (index<12) { + if (index>=core.status.hero.equipment.length) return; + if (index==core.status.event.selection && core.status.hero.equipment[index] != "blank") { + core.unloadEquip(index); + } + } + else { + var equips = null; + equips = Object.keys(core.status.hero.items.equips).sort(); + if (equips==null) return; + if (index>=equips.length+12) return; + if (index==core.status.event.selection) { + var equipId = equips[index-12]; + core.loadEquip(equipId); + equips = Object.keys(core.status.hero.items.equips).sort(); + if ( equips.length == 0) + index = core.status.hero.equipment.length-1; + } + } + core.ui.drawEquipbox(index); +} + +////// 装备栏界面时,按下某个键的操作 ////// +actions.prototype.keyDownEquipbox = function (keycode) { + if (!core.isset(core.status.event.data)) return; + + var equipCapacity = core.status.hero.equipment.length; + var ownEquipment = Object.keys(core.status.hero.items.equips).sort(); + var index = core.status.event.selection; + var page = core.status.event.data.page; + var totalPage = Math.ceil(ownEquipment.length/12); + + if (keycode==37) { // left + if (index==0) return; + if (index==12) + if (page>1) { + core.status.event.data.page--; + index = 23; + } + else if (page==1) + index = equipCapacity-1; + else return; + else index -= 1; + this.clickEquipboxIndex(index); + return; + } + if (keycode==38) { // up + if (index<18 && index>11) { // 进入当前装备 + index = Math.ceil((index-12)/2); + if (equipCapacity<=3 && equipCapacity>index) index += 0; + else if (equipCapacity>3 && equipCapacity>index) index += 3; + else index = equipCapacity-1; + } + else if (index<3) return; // 第一行没有向上 + else if (index<12) index -= 3; + else index -= 6; + this.clickEquipboxIndex(index); + return; + } + if (keycode==39) { // right + if (page0) + index = 12; + else if (page==totalPage && index==ownEquipment.length%12+11) + return; + else index += 1; + this.clickEquipboxIndex(index); + return; + } + if (keycode==40) { // down + if ((index>2 || equipCapacity<=3) && index<12) {// 进入拥有装备 + index = (index%3)*2+13; + if (totalPage == 0) return; + if (totalPage == page && ownEquipment.length%12<(index%6+1)) + index = ownEquipment.length%12+11; + } + else if (equipCapacity>3 && equipCapacity%36 && index>ownEquipment.length%6+11 && index<18) + index = ownEquipment.length%12+11; + else if (index>17 || (totalPage==page && ownEquipment.length%12<=6 && index>11)) return;//最后一行无操作 + else if (index<12) index += 3; + else index += 6; + this.clickEquipboxIndex(index); + return; + } +} + +////// 装备栏界面时,放开某个键的操作 ////// +actions.prototype.keyUpEquipbox = function (keycode) { + if (keycode==84){ + core.ui.closePanel(); + core.openToolbox(); + return; + } + if (keycode==81 || keycode==27 || keycode==88) { + core.ui.closePanel(); + return; + } + if (!core.isset(core.status.event.data.selectId)) return; + + if (keycode==13 || keycode==32 || keycode==67) { + this.clickEquipboxIndex(core.status.event.selection); + return; + } +} + ////// 存读档界面时的点击操作 ////// actions.prototype.clickSL = function(x,y) { diff --git a/libs/control.js b/libs/control.js index bd1db38c..c8c9c5a3 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1945,18 +1945,51 @@ control.prototype.replay = function () { var tools = Object.keys(core.status.hero.items.tools).sort(); var constants = Object.keys(core.status.hero.items.constants).sort(); var index; - if ((index=tools.indexOf(itemId))>=0 || (index=constants.indexOf(itemId)+1000)>=1000) { - core.ui.drawToolbox(index); + if ((index=tools.indexOf(itemId))>=0) { + core.status.event.data = {"toolsPage":Math.floor(index/12)+1, "constantsPage":1, "selectId":null} + index = index%12; + } + else if (index=constants.indexOf(itemId)>=0) { + core.status.event.data = {"toolsPage":1, "constantsPage":Math.floor(index/12)+1, "selectId":null} + index = index%12+12; + } + core.ui.drawToolbox(index); setTimeout(function () { core.ui.closePanel(); core.useItem(itemId, function () { core.replay(); }); }, 750 / Math.max(1, core.status.replay.speed)); - } return; } } + else if (action.indexOf("unEquip:")==0) { + var unloadEquipId = action.substring(8); + var equipType = core.material.items[unloadEquipId].equip.type; + core.ui.drawEquipbox(equipType); + setTimeout(function () { + core.ui.closePanel(); + core.unloadEquip(equipType, function () { + core.replay(); + }); + }, 750 / Math.max(1, core.status.replay.speed)); + return; + } + else if (action.indexOf("equip:")==0) { + var equipId = action.substring(6); + var ownEquipment = Object.keys(core.status.hero.items.equips).sort(); + var index = ownEquipment.indexOf(equipId); + core.status.event.data = {"page":Math.floor(index/12)+1, "selectId":null} + index = index%12+12; + core.ui.drawEquipbox(index); + setTimeout(function () { + core.ui.closePanel(); + core.loadEquip(equipId, function () { + core.replay(); + }); + }, 750 / Math.max(1, core.status.replay.speed)); + return; + } else if (action.indexOf("fly:")==0) { var floorId=action.substring(4); var toIndex=core.status.hero.flyRange.indexOf(floorId); @@ -2128,6 +2161,14 @@ control.prototype.useFly = function (need) { return; } +////// 点击装备栏时的打开操作 ////// +control.prototype.openEquipbox = function (need) { + if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + if (!core.checkStatus('equipbox', need)) + return; + core.ui.drawEquipbox(); +} + ////// 点击工具栏时的打开操作 ////// control.prototype.openToolbox = function (need) { if (core.isset(core.status.replay)&&core.status.replay.replaying) return; @@ -2650,7 +2691,9 @@ control.prototype.clearStatusBar = function() { core.statusBar[e].innerHTML = " "; }); core.statusBar.image.book.style.opacity = 0.3; - core.statusBar.image.fly.style.opacity = 0.3; + if (!core.flags.equipboxBotton) { + core.statusBar.image.fly.style.opacity = 0.3; + } } ////// 更新状态栏 ////// @@ -2726,8 +2769,14 @@ control.prototype.updateStatusBar = function () { core.statusBar.image.book.src = core.statusBar.icons.book.src; core.statusBar.image.book.style.opacity = core.hasItem('book')?1:0.3; - core.statusBar.image.fly.src = core.statusBar.icons.fly.src; - core.statusBar.image.fly.style.opacity = core.hasItem('fly')?1:0.3; + if (!core.flags.equipboxBotton) { + core.statusBar.image.fly.src = core.statusBar.icons.fly.src; + core.statusBar.image.fly.style.opacity = core.hasItem('fly')?1:0.3; + } + else { + core.statusBar.image.fly.src = core.statusBar.icons.equipbox.src; + core.statusBar.image.fly.style.opacity = 1; + } core.statusBar.image.toolbox.src = core.statusBar.icons.toolbox.src; diff --git a/libs/core.js b/libs/core.js index 98705b78..1c6a8625 100644 --- a/libs/core.js +++ b/libs/core.js @@ -833,6 +833,11 @@ core.prototype.hasItem = function (itemId) { return core.items.hasItem(itemId); } +////// 是否装备某件装备 ////// +core.prototype.hasEquip = function (equipId) { + return core.items.hasEquip(equipId); +} + ////// 设置某个物品的个数 ////// core.prototype.setItem = function (itemId, itemNum) { core.items.setItem(itemId, itemNum); @@ -853,6 +858,21 @@ core.prototype.canUseItem = function (itemId) { return core.items.canUseItem(itemId); } +////// 换上某件装备 ////// +core.prototype.loadEquip = function (equipId, callback) { + core.items.loadEquip(equipId,callback); +} + +////// 卸下某件装备 ////// +core.prototype.unloadEquip = function (equipType, callback) { + core.items.unloadEquip(equipType,callback); +} + +////// 比较某件装备与当前装备 ////// +core.prototype.compareEquipment = function (equipId, beComparedEquipId) { + return core.items.compareEquipment(equipId, beComparedEquipId); +} + ////// 增加某个物品的个数 ////// core.prototype.addItem = function (itemId, itemNum) { core.items.addItem(itemId, itemNum); @@ -1072,6 +1092,11 @@ core.prototype.useFly = function (need) { core.control.useFly(need); } +////// 点击装备栏时的打开操作 ////// +core.prototype.openEquipbox = function (need) { + core.control.openEquipbox(need); +} + ////// 点击工具栏时的打开操作 ////// core.prototype.openToolbox = function (need) { core.control.openToolbox(need); diff --git a/libs/events.js b/libs/events.js index c69f1623..748782ae 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1087,9 +1087,11 @@ events.prototype.battle = function (id, x, y, force, callback) { } else { - if (core.flags.equipment && core.getFlag('sword', 'sword0')!='sword0') { - core.playSound('zone.mp3'); - core.drawAnimate('sword', x, y); + if (core.flags.equipment) { + var equipId = core.status.hero.equipment[0]; + if (core.isset(equipId)) + if (core.isset(core.material.items[equipId].equip.animate)) + core.drawAnimate(core.material.items[equipId].equip.animate, x, y); } else { core.playSound('attack.mp3'); diff --git a/libs/items.js b/libs/items.js index 82ee9204..4b477361 100644 --- a/libs/items.js +++ b/libs/items.js @@ -96,6 +96,12 @@ items.prototype.hasItem = function (itemId) { return core.itemCount(itemId) > 0; } +////// 是否装备某件装备 ////// +items.prototype.hasEquip = function (equipId) { + var equiptype = core.material.items[equipId].equip.type; + return core.status.hero.equipment[equiptype] == equipId; +} + ////// 设置某个物品的个数 ////// items.prototype.setItem = function (itemId, itemNum) { var itemCls = core.material.items[itemId].cls; @@ -140,3 +146,82 @@ items.prototype.addItem = function (itemId, itemNum) { core.status.hero.items[itemCls][itemId] = 1; } + +////// 换上 ////// +items.prototype.loadEquip = function (equipId, callback) { + + core.playSound('equip.mp3'); + + var loadEquip = core.material.items[equipId]; + var loadEquipType = loadEquip.equip.type; + var unloadEquipId = core.status.hero.equipment[loadEquipType]; + + // 比较能力值 + var result = core.compareEquipment(equipId,unloadEquipId); + + core.status.hero.atk += result.atk; + core.status.hero.def += result.def; + core.status.hero.mdef += result.mdef; + + // 更新装备状态 + core.status.hero.equipment[loadEquipType] = equipId; + core.updateStatusBar(); + + // 记录路线 + core.status.route.push("equip:"+equipId); + + // 装备更换完毕:删除换上的装备 + core.status.hero.items["equips"][equipId]--; + if (core.status.hero.items["equips"][equipId]==0) + delete core.status.hero.items["equips"][equipId]; + + // 装备更换完毕:增加卸下的装备 + if (core.isset(unloadEquipId)) + core.addItem(unloadEquipId, 1); + + if (core.isset(callback)) callback(); +} + +////// 卸下 ////// +items.prototype.unloadEquip = function (equipType, callback) { + + core.playSound('equip.mp3'); + + var unloadEquipId = core.status.hero.equipment[equipType]; + var unloadEquip = core.material.items[unloadEquipId]; + + // 处理能力值改变 + core.status.hero.atk -= unloadEquip.equip.atk || 0; + core.status.hero.def -= unloadEquip.equip.def || 0; + core.status.hero.mdef -= unloadEquip.equip.mdef || 0; + + // 更新装备状态 + core.status.hero.equipment[equipType] = null; + + core.updateStatusBar(); + + // 记录路线 + core.status.route.push("unEquip:"+unloadEquipId); + + // 装备更换完毕:增加卸下的装备 + core.addItem(unloadEquipId, 1); + + if (core.isset(callback)) callback(); +} + +items.prototype.compareEquipment = function (compareEquipId, beComparedEquipId) { + var compareAtk = 0, compareDef = 0, compareMdef = 0; + if (core.isset(compareEquipId)) { + var compareEquip = core.material.items[compareEquipId]; + compareAtk += compareEquip.equip.atk || 0; + compareDef += compareEquip.equip.def || 0; + compareMdef += compareEquip.equip.mdef || 0; + } + if (core.isset(beComparedEquipId)) { + var beComparedEquip = core.material.items[beComparedEquipId]; + compareAtk -= beComparedEquip.equip.atk || 0; + compareDef -= beComparedEquip.equip.def || 0; + compareMdef -= beComparedEquip.equip.mdef || 0; + } + return {"atk":compareAtk,"def":compareDef,"mdef":compareMdef}; +} \ No newline at end of file diff --git a/libs/ui.js b/libs/ui.js index a6d022c0..68d7c2d7 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1205,7 +1205,8 @@ ui.prototype.drawReplay = function () { } ////// 绘制分页 ////// -ui.prototype.drawPagination = function (page, totalPage) { +ui.prototype.drawPagination = function (page, totalPage, top) { + if (totalPage <= 1) return; core.setFont('ui', 'bold 15px Verdana'); core.setFillStyle('ui', '#DDDDDD'); @@ -1213,17 +1214,13 @@ ui.prototype.drawPagination = function (page, totalPage) { var length = core.canvas.ui.measureText(page + " / " + page).width; core.canvas.ui.textAlign = 'left'; - core.fillText('ui', page + " / " + totalPage, parseInt((416 - length) / 2), 403); + core.fillText('ui', page + " / " + totalPage, parseInt((416 - length) / 2), top*32+19); core.canvas.ui.textAlign = 'center'; if (page > 1) - core.fillText('ui', '上一页', 208 - 80, 403); + core.fillText('ui', '上一页', 208 - 80, top*32+19); if (page < totalPage) - core.fillText('ui', '下一页', 208 + 80, 403); - - // 退出 - core.fillText('ui', '返回游戏', 370, 403); - + core.fillText('ui', '下一页', 208 + 80, top*32+19); } ////// 绘制键盘光标 ////// @@ -1391,7 +1388,9 @@ ui.prototype.drawBook = function (index) { } core.drawBoxAnimate(); - this.drawPagination(page, totalPage); + this.drawPagination(page, totalPage, 12); + // 退出 + core.fillText('ui', '返回游戏', 370, 403,'#DDDDDD', 'bold 15px Verdana'); } ////// 绘制怪物属性的详细信息 ////// @@ -1583,35 +1582,45 @@ ui.prototype.drawMaps = function (index, x, y) { ////// 绘制道具栏 ////// ui.prototype.drawToolbox = function(index) { + // 设定eventdata + if (!core.isset(core.status.event.data)) + core.status.event.data = {"toolsPage":1, "constantsPage":1, "selectId":null} + // 获取物品列表 var tools = Object.keys(core.status.hero.items.tools).sort(); var constants = Object.keys(core.status.hero.items.constants).sort(); + // 处理页数 + var toolsPage = core.status.event.data.toolsPage; + var constantsPage = core.status.event.data.constantsPage; + var toolsTotalPage = Math.ceil(tools.length/12); + var constantsTotalPage = Math.ceil(constants.length/12); + + // 处理index if (!core.isset(index)) { if (tools.length>0) index=0; - else if (constants.length>0) index=1000; + else if (constants.length>0) index=12; else index=0; } - core.status.event.selection=index; + // 确认选择对象 + var select; var selectId; - if (index<1000) { - if (index>=tools.length) index=Math.max(0, tools.length-1); - selectId = tools[index]; + if (index<12) { + select = index + (toolsPage-1)*12; + if (select>=tools.length) select=Math.max(0, tools.length-1); + selectId = tools[select]; } else { - if (index-1000>=constants.length) index=1000+Math.max(0, constants.length-1); - selectId = constants[index-1000]; + select = index%12 + (constantsPage-1)*12; + if (select>=constants.length) select=Math.max(0, constants.length-1); + selectId = constants[select]; } - - var page = parseInt((index%1000)/12)+1; - var totalPage = Math.ceil(Math.max(tools.length, constants.length)/12); - if (!core.hasItem(selectId)) selectId=null; + core.status.event.data.selectId=selectId; - core.status.event.data=selectId; - + // 绘制 core.clearMap('ui'); core.setAlpha('ui', 0.85); core.fillRect('ui', 0, 0, 416, 416, '#000000'); @@ -1673,51 +1682,211 @@ ui.prototype.drawToolbox = function(index) { core.canvas.ui.textAlign = 'right'; var images = core.material.images.items; - // 消耗道具 + // 消耗道具 for (var i=0;i<12;i++) { - var tool=tools[12*(page-1)+i]; + var tool=tools[12*(toolsPage-1)+i]; if (!core.isset(tool)) break; var icon=core.material.icons.items[tool]; - if (i<6) { - core.canvas.ui.drawImage(images, 0, icon*32, 32, 32, 16*(4*i+1)+5, 144+5-ydelta, 32, 32) - // 个数 - core.fillText('ui', core.itemCount(tool), 16*(4*i+1)+40, 144+38-ydelta, '#FFFFFF', "bold 14px Verdana"); - if (selectId == tool) - core.strokeRect('ui', 16*(4*i+1)+1, 144+1-ydelta, 40, 40, '#FFD700'); - } - else { - core.canvas.ui.drawImage(images, 0, icon*32, 32, 32, 16*(4*(i-6)+1)+5, 144+64+5-ydelta, 32, 32) - // 个数 - core.fillText('ui', core.itemCount(tool), 16*(4*(i-6)+1)+40, 144+64+38-ydelta, '#FFFFFF', "bold 14px Verdana"); - if (selectId == tool) - core.strokeRect('ui', 16*(4*(i-6)+1)+1, 144+64+1-ydelta, 40, 40, '#FFD700'); - - } + core.canvas.ui.drawImage(images, 0, icon*32, 32, 32, 16*(4*(i%6)+1)+5, 144+Math.floor(i/6)*64+5-ydelta, 32, 32) + // 个数 + core.fillText('ui', core.itemCount(tool), 16*(4*(i%6)+1)+40, 144+Math.floor(i/6)*64+38-ydelta, '#FFFFFF', "bold 14px Verdana"); + if (selectId == tool) + core.strokeRect('ui', 16*(4*(i%6)+1)+1, 144+Math.floor(i/6)*64+1-ydelta, 40, 40, '#FFD700'); } // 永久道具 for (var i=0;i<12;i++) { - var constant=constants[12*(page-1)+i]; + var constant=constants[12*(constantsPage-1)+i]; if (!core.isset(constant)) break; var icon=core.material.icons.items[constant]; - if (i<6) { - core.canvas.ui.drawImage(images, 0, icon*32, 32, 32, 16*(4*i+1)+5, 304+5-ydelta, 32, 32) + core.canvas.ui.drawImage(images, 0, icon*32, 32, 32, 16*(4*(i%6)+1)+5, 304+Math.floor(i/6)*64+5-ydelta, 32, 32) + if (selectId == constant) + core.strokeRect('ui', 16*(4*(i%6)+1)+1, 304+Math.floor(i/6)*64+1-ydelta, 40, 40, '#FFD700'); + } - if (selectId == constant) - core.strokeRect('ui', 16*(4*i+1)+1, 304+1-ydelta, 40, 40, '#FFD700'); + // 分页 + this.drawPagination(toolsPage, toolsTotalPage, 7); + this.drawPagination(constantsPage, constantsTotalPage, 12); + + core.canvas.ui.textAlign = 'center'; + + // 装备栏 + if (core.flags.equipment) + core.fillText('ui', '装备栏', 370, 19,'#DDDDDD', 'bold 15px Verdana'); + // core.fillText('ui', '删除道具', 370, 32,'#DDDDDD', 'bold 15px Verdana'); + // 退出 + core.fillText('ui', '返回游戏', 370, 403,'#DDDDDD', 'bold 15px Verdana'); +} + +////// 绘制装备界面 ////// +ui.prototype.drawEquipbox = function(index) { + // 设定eventdata + if (!core.isset(core.status.event.data)) + core.status.event.data = {"page":1, "selectId":null} + + var equipEquipment = core.status.hero.equipment; + var ownEquipment = Object.keys(core.status.hero.items.equips).sort(); + + var page = core.status.event.data.page; + var totalPage = Math.ceil(ownEquipment.length/12); + + // 处理index + if (!core.isset(index)) { + if (equipEquipment.length>0) index=0; + else if (ownEquipment.length>0) index=12; + else index=0; + } + core.status.event.selection=index; + + var selectId; + if (index<12) { + if (index>=equipEquipment.length) index=Math.max(0, equipEquipment.length-1); + selectId = equipEquipment[index]; + } + else { + if (index+12*(page-2)>=ownEquipment.length) index=12+Math.max(0, ownEquipment.length%12-1); + selectId = ownEquipment[index-12]; + if (!core.hasItem(selectId)) selectId=null; + } + core.status.event.data.selectId=selectId; + + core.clearMap('ui', 0, 0, 416, 416); + core.setAlpha('ui', 0.85); + core.fillRect('ui', 0, 0, 416, 416, '#000000'); + core.setAlpha('ui', 1); + core.setFillStyle('ui', '#DDDDDD'); + core.setStrokeStyle('ui', '#DDDDDD'); + core.canvas.ui.lineWidth = 2; + core.canvas.ui.strokeWidth = 2; + + var ydelta = 20; + + // 画线 + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(0, 130-ydelta); + core.canvas.ui.lineTo(416, 130-ydelta); + core.canvas.ui.stroke(); + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(416,129-ydelta); + core.canvas.ui.lineTo(416,105-ydelta); + core.canvas.ui.lineTo(416-72,105-ydelta); + core.canvas.ui.lineTo(416-102,129-ydelta); + core.canvas.ui.fill(); + + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(0, 290-ydelta); + core.canvas.ui.lineTo(416, 290-ydelta); + core.canvas.ui.stroke(); + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(416,289-ydelta); + core.canvas.ui.lineTo(416,265-ydelta); + core.canvas.ui.lineTo(416-72,265-ydelta); + core.canvas.ui.lineTo(416-102,289-ydelta); + core.canvas.ui.fill(); + + // 文字 + core.canvas.ui.textAlign = 'right'; + core.fillText('ui', "当前装备", 411, 124-ydelta, '#333333', "bold 16px Verdana"); + core.fillText('ui', "拥有装备", 411, 284-ydelta); + + core.canvas.ui.textAlign = 'left'; + + console.log(equipEquipment[0]); + // 描述 + if (core.isset(selectId)) { + var equip=core.material.items[selectId]; + core.fillText('ui', equip.name, 10, 32, '#FFD700', "bold 20px Verdana") + + var text = equip.text||"该装备暂无描述。"; + var lines = core.splitLines('ui', text, 406, '17px Verdana'); + + core.fillText('ui', lines[0], 10, 62, '#FFFFFF', '17px Verdana'); + + // 比较属性 + if (lines.length==1) { + var compare; + if (index<12) compare = core.compareEquipment(null, selectId); + else { + compare = core.compareEquipment(selectId, equipEquipment[equip.equip.type]); + } + // 绘制 + var drawList; //= [['攻击',atk],['防御',def],['魔防',mdef]]; + var drawPointer = 0; + var color; + if (compare.atk!=0) { + if (compare.atk>0) color = '#00FF00'; + else color = '#FF0000'; + drawList = '攻击 '+core.status.hero.atk+'->'; + core.fillText('ui', drawList, 10+drawPointer, 89, '#CCCCCC', 'bold 14px Verdana'); + drawPointer += core.canvas.ui.measureText(drawList).width; + + drawList = (core.status.hero.atk+compare.atk)+' '; + core.fillText('ui', drawList, 10+drawPointer, 89, color, 'bold 14px Verdana'); + drawPointer += core.canvas.ui.measureText(drawList).width; + } + if (compare.def!=0) { + if (compare.def>0) color = '#00FF00'; + else color = '#FF0000'; + drawList = '防御 '+core.status.hero.atk+'->'; + core.fillText('ui', drawList, 10+drawPointer, 89, '#CCCCCC', 'bold 14px Verdana'); + drawPointer += core.canvas.ui.measureText(drawList).width; + + drawList = (core.status.hero.atk+compare.def)+' '; + core.fillText('ui', drawList, 10+drawPointer, 89, color, 'bold 14px Verdana'); + drawPointer += core.canvas.ui.measureText(drawList).width; + } + if (compare.mdef!=0) { + if (compare.mdef>0) color = '#00FF00'; + else color = '#FF0000'; + drawList = '魔防 '+core.status.hero.atk+'->'; + core.fillText('ui', drawList, 10+drawPointer, 89, '#CCCCCC', 'bold 14px Verdana'); + drawPointer += core.canvas.ui.measureText(drawList).width; + + drawList = (core.status.hero.atk+compare.mdef)+' '; + core.fillText('ui', drawList, 10+drawPointer, 89, color, 'bold 14px Verdana'); + drawPointer += core.canvas.ui.measureText(drawList).width; + } } else { - core.canvas.ui.drawImage(images, 0, icon*32, 32, 32, 16*(4*(i-6)+1)+5, 304+64+5-ydelta, 32, 32) - if (selectId == constant) - core.strokeRect('ui', 16*(4*(i-6)+1)+1, 304+64+1-ydelta, 40, 40, '#FFD700'); + var leftText = text.substring(lines[0].length); + core.fillText('ui', leftText, 10, 89, '#FFFFFF', '17px Verdana'); } } - // 退出 - this.drawPagination(page, totalPage); + core.canvas.ui.textAlign = 'right'; + var images = core.material.images.items; + + // 当前装备 + for (var i = 0 ; i < core.status.hero.equipment.length ; i++) { + var equipId = core.status.hero.equipment[i]; + if (core.isset(equipId)) { + var icon = core.material.icons.items[equipId]; + core.canvas.ui.drawImage(images, 0, icon*32, 32, 32, 16*(8*(i%3)+5)+5, 144+Math.floor(i/3)*64+5-ydelta, 32, 32); + } + core.fillText('ui', main.equipName[i], 16*(8*(i%3)+1)+40, 144+Math.floor(i/3)*64+32-ydelta, '#FFFFFF', "bold 16px Verdana"); + if (index == i) + core.strokeRect('ui', 16*(8*(i%3)+5)+1, 144+Math.floor(i/3)*64+1-ydelta, 40, 40, '#FFD700'); + } + + // 现有装备 + for (var i=0;i<12;i++) { + var ownEquip=ownEquipment[12*(page-1)+i]; + if (!core.isset(ownEquip)) break; + var icon=core.material.icons.items[ownEquip]; + core.canvas.ui.drawImage(images, 0, icon*32, 32, 32, 16*(4*(i%6)+1)+5, 304+Math.floor(i/6)*64+5-ydelta, 32, 32) + // 个数 + if (core.itemCount(ownEquip)>1) + core.fillText('ui', core.itemCount(ownEquip), 16*(4*(i%6)+1)+40, 304+Math.floor(i/6)*64+38-ydelta, '#FFFFFF', "bold 14px Verdana"); + if (selectId == ownEquip) + core.strokeRect('ui', 16*(4*(i%6)+1)+1, 304+Math.floor(i/6)*64+1-ydelta, 40, 40, '#FFD700'); + } + + this.drawPagination(page, totalPage, 12); + // 道具栏 core.canvas.ui.textAlign = 'center'; - // core.fillText('ui', '删除道具', 370, 32,'#DDDDDD', 'bold 15px Verdana'); + core.fillText('ui', '道具栏', 370, 19,'#DDDDDD', 'bold 15px Verdana'); + // 退出按钮 core.fillText('ui', '返回游戏', 370, 403,'#DDDDDD', 'bold 15px Verdana'); } @@ -1804,7 +1973,9 @@ ui.prototype.drawSLPanel = function(index, refresh) { } else drawAll(); - this.drawPagination(page+1, max_page); + this.drawPagination(page+1, max_page, 12); + // 退出 + core.fillText('ui', '返回游戏', 370, 403,'#DDDDDD', 'bold 15px Verdana'); if (core.status.event.selection) core.setFillStyle('ui', '#FF6A6A'); diff --git a/libs/utils.js b/libs/utils.js index d7e0881f..3551cea1 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -324,6 +324,10 @@ utils.prototype.encodeRoute = function (route) { } if (t.indexOf('item:')==0) ans+="I"+t.substring(5)+":"; + else if (t.indexOf('unEquip:')==0) + ans+="u"+t.substring(8)+":"; + else if (t.indexOf('equip:')==0) + ans+="e"+t.substring(6)+":"; else if (t.indexOf('fly:')==0) ans+="F"+t.substring(4)+":"; else if (t.indexOf('choices:')==0) @@ -383,7 +387,7 @@ utils.prototype.decodeRoute = function (route) { while (index=0&&nx=0&&ny