commit 4297e6998c39547dfcda6e56290644e69a5bcef6 Author: oc Date: Mon Dec 4 01:35:38 2017 +0800 First Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..7ae4cf2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + + + diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..7f0771f3 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..17b6b9a1 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..f7251ba2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/mota-js.iml b/.idea/mota-js.iml new file mode 100644 index 00000000..24643cc3 --- /dev/null +++ b/.idea/mota-js.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml new file mode 100644 index 00000000..157a5562 --- /dev/null +++ b/.idea/watcherTasks.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/fonts/number.ttf b/fonts/number.ttf new file mode 100644 index 00000000..bcf90fae Binary files /dev/null and b/fonts/number.ttf differ diff --git a/images/animates.png b/images/animates.png new file mode 100644 index 00000000..c1dbdf3d Binary files /dev/null and b/images/animates.png differ diff --git a/images/atk.png b/images/atk.png new file mode 100644 index 00000000..bce8cdbd Binary files /dev/null and b/images/atk.png differ diff --git a/images/bg.png b/images/bg.png new file mode 100644 index 00000000..d235379c Binary files /dev/null and b/images/bg.png differ diff --git a/images/book.png b/images/book.png new file mode 100644 index 00000000..b42b205f Binary files /dev/null and b/images/book.png differ diff --git a/images/def.png b/images/def.png new file mode 100644 index 00000000..306f84c6 Binary files /dev/null and b/images/def.png differ diff --git a/images/enemys.png b/images/enemys.png new file mode 100644 index 00000000..6797ae59 Binary files /dev/null and b/images/enemys.png differ diff --git a/images/experience.png b/images/experience.png new file mode 100644 index 00000000..8317a8dd Binary files /dev/null and b/images/experience.png differ diff --git a/images/floor.png b/images/floor.png new file mode 100644 index 00000000..ee904aa9 Binary files /dev/null and b/images/floor.png differ diff --git a/images/fly.png b/images/fly.png new file mode 100644 index 00000000..ae767082 Binary files /dev/null and b/images/fly.png differ diff --git a/images/ground.png b/images/ground.png new file mode 100644 index 00000000..84055d7f Binary files /dev/null and b/images/ground.png differ diff --git a/images/heros.png b/images/heros.png new file mode 100644 index 00000000..0564323a Binary files /dev/null and b/images/heros.png differ diff --git a/images/hp.png b/images/hp.png new file mode 100644 index 00000000..49c16e74 Binary files /dev/null and b/images/hp.png differ diff --git a/images/items.png b/images/items.png new file mode 100644 index 00000000..5df16337 Binary files /dev/null and b/images/items.png differ diff --git a/images/load.png b/images/load.png new file mode 100644 index 00000000..26243925 Binary files /dev/null and b/images/load.png differ diff --git a/images/mdef.png b/images/mdef.png new file mode 100644 index 00000000..e22f498b Binary files /dev/null and b/images/mdef.png differ diff --git a/images/meaning.txt b/images/meaning.txt new file mode 100644 index 00000000..1f4c43f4 --- /dev/null +++ b/images/meaning.txt @@ -0,0 +1,83 @@ +# 此文件是每个数字所代表的意思,可被地图生成器读取和使用 +# 可以模仿此格式在后面写上任意被识别内容 + + +# 文件格式: +# 编号,图标所在的图片名,图标在图片上的索引(从上到下第几个,从0开始计算) +# 注意中间以小逗号分开;不要有空格;后面可以加任意"#"代表注释 + +### 0-20 地形 ### +0,terrains,0 # 路面 +1,terrains,1 # 黄色墙(经典墙) +2,terrains,2 # 白色墙 +3,terrains,3 # 蓝色墙 +4,terrains,4 # 星空 +5,terrains,5 # 岩浆 +6,terrains,15 # 蓝色商店左 +7,terrains,16 # 蓝色商店右 +8,terrains,17 # 红色商店左 +9,terrains,18 # 红色商店右 +10,animates,23 #血网(经过收到伤害) +# 备注:11-20待定,也许是毒网等地形 + +### 21-80 物品 ### +# 消耗品 +21,items,0 # 黄钥匙 +22,items,1 # 蓝钥匙 +23,items,2 # 红钥匙 +24,items,3 # 绿钥匙 +25,items,4 # 铁门钥匙 +26,items,6 # 大黄门钥匙(钥匙盒) +27,items,16 # 红宝石 +28,items,17 # 蓝宝石 +29,items,18 # 绿宝石 +30,items,19 # 黄宝石 +31,items,20 # 红血瓶 +32,items,21 # 蓝血瓶 +33,items,22 # 绿血瓶 +34,items,23 # 黄血瓶 +35,items,50 # 铁剑 +36,items,55 # 铁盾 +37,items,51 # 银剑 +38,items,56 # 银盾 +39,items,52 # 骑士剑 +40,items,57 # 骑士盾 +41,items,53 # 圣剑 +42,items,58 # 圣盾 +43,items,54 # 神圣剑 +44,items,59 # 神圣盾 +# 特殊道具 +45,items,9 # 怪物手册 +46,items,12 # 楼层传送器 +47,items,45 # 破墙镐 +48,items,44 # 破冰镐 +49,items,43 # 炸弹 +50,items,13 # 中心对称飞行器 +51,items,15 # 上楼器 +52,items,14 # 下楼器 +53,items,11 # 幸运金币 +54,items,41 # 冰冻徽章 +55,items,40 # 十字架 +56,items,29 # 圣水 +57,items,8 # 地震卷轴 +58,items,24 # 解毒药水 +59,items,25 # 解衰药水 +60,items,26 # 解咒药水 +61,items,28 # 万能药水 +62,items,42 # 屠龙匕首 +# 备注:63-80待定,比如类似于新新魔塔的魔杖 + +### 81-100 门、楼梯、传送门 ### +81,terrains,9 # 黄门 +82,terrains,10 # 蓝门 +83,terrains,11 # 红门 +84,terrains,12 # 绿门 +85,terrains,13 # 机关门 +86,terrains,14 # 铁门 +87,terrains,7 # 上楼梯 +88,terrains,6 # 下楼梯 +89,animates,21 # 传送门 + +### 101-200 怪物 ### +# 将会按照enemys.png顺序依次读取怪物 +# 如101绿色史莱姆,102红色史莱姆,依次类推 diff --git a/images/money.png b/images/money.png new file mode 100644 index 00000000..bbfa6b40 Binary files /dev/null and b/images/money.png differ diff --git a/images/npcs.png b/images/npcs.png new file mode 100644 index 00000000..3df2b21d Binary files /dev/null and b/images/npcs.png differ diff --git a/images/save.png b/images/save.png new file mode 100644 index 00000000..325e36dc Binary files /dev/null and b/images/save.png differ diff --git a/images/settings.png b/images/settings.png new file mode 100644 index 00000000..06b14685 Binary files /dev/null and b/images/settings.png differ diff --git a/images/shop.png b/images/shop.png new file mode 100644 index 00000000..9c49debf Binary files /dev/null and b/images/shop.png differ diff --git a/images/terrains.png b/images/terrains.png new file mode 100644 index 00000000..99a26359 Binary files /dev/null and b/images/terrains.png differ diff --git a/images/toolbox.png b/images/toolbox.png new file mode 100644 index 00000000..7122eeea Binary files /dev/null and b/images/toolbox.png differ diff --git a/index.html b/index.html new file mode 100644 index 00000000..a08f5712 --- /dev/null +++ b/index.html @@ -0,0 +1,93 @@ + + + + + + + + + 魔塔样板 - HTML5魔塔 + + + + + + + + + + + +
+

请稍后...

+
+
+
+
+
+

资源即将开始加载

+
+ + + +
+
+ 开始游戏 + 载入游戏 + 关于本塔 +
+
+ + 简单 + 普通 + 困难 +
+
+
+
+

+

+

+
+
+ +

+ +

+ +

+ +

+ +

+ +

+ +

+

+

+

+

+

+

+ + + + + + + +

+
+
+ + + + + + 此浏览器不支持HTML5 +
+ + + \ No newline at end of file diff --git a/libs/core.js b/libs/core.js new file mode 100644 index 00000000..c8874175 --- /dev/null +++ b/libs/core.js @@ -0,0 +1,3120 @@ +/** + * 初始化 start + */ + +function core() { + this.dom = {}; + this.statusBar = {}; + this.canvas = {}; + this.images = []; + this.sounds = {}; + this.firstData = {}; + this.material = { + 'images': {}, + 'sounds': {}, + 'ground': null, + 'items': {}, + 'enemys': {}, + 'icons': {}, + 'events': {}, + 'npcs': {} + } + this.timeout = { + 'getItemTipTimeout': null + } + this.interval = { + 'twoAnimate': null, + 'fourAnimate': null, + 'boxAnimate': null, + 'heroMoveTriggerInterval': null, + 'heroMoveInterval': null, + 'heroAutoMoveScan': null, + "tipAnimate": null, + 'openDoorAnimate': null + } + this.musicStatus = { + 'isIOS': false, + 'loaded': false, + 'bgmStatus': false, + 'soundStatus': true, + 'playedSound': null, + 'playedBgm': null, + } + // 各元素位置、大小信息 + this.position = { + 'gameGroup': {}, + 'canvas': {}, + 'statusBar': {}, + 'toolBar': {}, + 'items': {}, + 'scale': 1.0, + 'screenMode': 'bigScreen', + } + this.initStatus = { + 'played': false, + + // 勇士属性 + 'hero': { + 'id': '', + 'name': '', + 'hp': 0, + 'atk': 0, + 'def': 0, + 'mdef': 0, + 'money': 0, + 'experience': 0, + 'loc': {'direction': 'down', 'x': 0, 'y': 0}, + 'flyRange': [], + 'items': [], + }, + + // 当前地图 + 'floorId': null, + 'thisMap': null, + 'maps': null, + + // 勇士状态;自动寻路相关 + 'heroMoving': false, + 'heroStop': true, + 'lockControl': false, + 'autoHeroMove': false, + 'automaticRouting': false, + 'automaticRouted': false, + 'autoStep': 0, + 'movedStep': 0, + 'destStep': 0, + 'automaticRoutingTemp': {'destX': 0, 'destY': 0, 'moveStep': []}, + 'autoStepRoutes': [], + 'holdingPath': 0, + 'stepPostfix': [], + 'mouseOutCheck': 1, + 'moveStepBeforeStop': [], + + // event事件 + 'savePage': null, + 'shops': {}, + 'npcs': {}, + 'event': { + 'id': null, + 'data': null + }, + 'openingDoor': null, + + // 动画 + 'twoAnimateObjs': [], + 'fourAnimateObjs': [], + 'boxAnimateObjs': [], + }; + this.status = {}; + this.flags = {}; +} + +/////////// 系统事件相关 /////////// + +core.prototype.init = function (dom, statusBar, canvas, images, sounds, coreData) { + core.dom = dom; + core.statusBar = statusBar; + core.canvas = canvas; + core.images = images; + core.sounds = sounds; + for (var key in coreData) { + core[key] = coreData[key]; + } + core.firstData = core.data.getFirstData(); + core.initStatus.shops = core.firstData.shops; + core.initStatus.npcs = core.firstData.npcs; + core.dom.versionLabel.innerHTML = core.firstData.version; + core.dom.logoLabel.innerHTML = core.firstData.title; + core.material.items = core.items.getItems(); + // core.status.maps = core.maps.getMaps(); + core.initStatus.maps = core.maps.getMaps(); + core.material.enemys = core.clone(core.enemys.getEnemys()); + core.material.icons = core.icons.getIcons(); + core.material.events = core.events.getEvents(); + core.material.npcs = core.npcs.getNpcs(); + core.flags = core.data.flags; + + // test if iOS + core.musicStatus.soundStatus = core.getLocalStorage('soundStatus', true); + var userAgent = navigator.userAgent; + + if (userAgent.indexOf('iPhone') > -1 || userAgent.indexOf('iPad') > -1) { + console.log("你的设备为iphone,不自动播放音乐!"); + core.musicStatus.isIOS = true; + core.musicStatus.soundStatus = false; + } + + core.material.ground = new Image(); + core.material.ground.src = "images/ground.png"; + + core.loader(function () { + console.log(core.material); + // core.playGame(); + core.showStartAnimate(function() {}); + }); +} + +core.prototype.showStartAnimate = function (callback) { + core.dom.startPanel.style.opacity=1; + core.dom.startPanel.style.display="block"; + core.dom.startTop.style.opacity=1; + core.dom.startTop.style.display="block"; + core.dom.startButtonGroup.style.display = 'none'; + core.dom.startButtons.style.display = 'block'; + core.dom.levelChooseButtons.style.display = 'none'; + core.status.played = false; + core.clearStatus(); + core.clearMap('all'); + + var opacityVal = 1; + var startAnimate = window.setInterval(function () { + opacityVal -= 0.03; + if (opacityVal < 0) { + clearInterval(startAnimate); + core.dom.startTop.style.display = 'none'; + // core.playGame(); + core.dom.startButtonGroup.style.display = 'block'; + if (core.isset(callback)) callback(); + } + core.dom.startTop.style.opacity = opacityVal; + }, 20); +} + +core.prototype.hideStartAnimate = function (callback) { + var opacityVal = 1; + var startAnimate = window.setInterval(function () { + opacityVal -= 0.03; + if (opacityVal < 0) { + clearInterval(startAnimate); + core.dom.startPanel.style.display = 'none'; + callback(); + } + core.dom.startPanel.style.opacity = opacityVal; + }, 20); +} + +core.prototype.setStartProgressVal = function (val) { + core.dom.startTopProgress.style.width = val + '%'; +} + +core.prototype.setStartLoadTipText = function (text) { + core.dom.startTopLoadTips.innerHTML = text; +} + +core.prototype.loader = function (callback) { + var loadedImageNum = 0, allImageNum = 0, loadSoundNum = 0, allSoundNum = 0; + allImageNum = core.images.length; + for (var key in core.sounds) { + allSoundNum += core.sounds[key].length; + } + for (var i = 0; i < core.images.length; i++) { + core.loadImage(core.images[i], function (imgName, image) { + core.setStartLoadTipText('正在加载图片 ' + imgName + "..."); + imgName = imgName.split('-'); + imgName = imgName[0]; + core.material.images[imgName] = image; + loadedImageNum++; + core.setStartLoadTipText(imgName + ' 加载完毕...'); + core.setStartProgressVal(loadedImageNum * (100 / allImageNum)); + if (loadedImageNum == allImageNum) { + // 加载音频 + for (var key in core.sounds) { + for (var i = 0; i < core.sounds[key].length; i++) { + var soundName=core.sounds[key][i]; + soundName = soundName.split('-'); + var sound = new Audio(); + sound.preload = 'none'; + sound.src = 'sounds/' + soundName[0] + '.' + key; + if (soundName[1] == 'loop') { + sound.loop = 'loop'; + } + + if (!core.isset(core.material.sounds[key])) + core.material.sounds[key] = {}; + core.material.sounds[key][soundName[0]] = sound; + } + } + callback(); + } + }); + } +} + +core.prototype.loadImage = function (imgName, callback) { + try { + core.setStartLoadTipText('加载图片 ' + imgName + ' 中...'); + var image = new Image(); + image.src = 'images/' + imgName + '.png'; + if (image.complete) { + callback(imgName, image); + return; + } + image.onload = function () { + callback(imgName, image); + } + } + catch (e) { + alert(e); + } +} + +core.prototype.loadSound = function() { + if (!core.isset(core.material.sounds.mp3)) return; + if (core.musicStatus.isIOS) return; + if (core.musicStatus.loaded) return; + core.musicStatus.loaded=true; + console.log("加载音乐"); + + var toLoadList = []; + + for (var key in core.material.sounds) { + for (var name in core.material.sounds[key]) { + toLoadList.push(core.material.sounds[key][name]); + } + } + core.loadSoundItem(toLoadList); +} + +core.prototype.loadSoundItem = function (toLoadList) { + if (toLoadList.length==0) { + // if (core.musicStatus.bgmStatus==0) core.musicStatus.bgmStatus=-1; + if (core.musicStatus.bgmStatus>0) return; + core.musicStatus.bgmStatus=1; + if (core.musicStatus.soundStatus) + core.playBgm('bgm', 'mp3'); + return; + } + var item = toLoadList.shift(); + item.oncanplay = function() { + core.loadSoundItem(toLoadList); + } + item.load(); +} + +core.prototype.isPlaying = function() { + if (core.isset(core.status.played) && core.status.played) + return true; + return false; +} + + +core.prototype.clearStatus = function() { + // 停止各个Timeout和Interval + for (var i in core.interval) { + clearInterval(core.interval[i]); + } + core.status = {}; + core.clearStatusBar(); + core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); +} + +core.prototype.resetStatus = function(hero, hard, floorId, maps) { + + // 停止各个Timeout和Interval + for (var i in core.interval) { + clearInterval(core.interval[i]); + } + + // 初始化status + core.status = core.clone(core.initStatus); + core.status.played = true; + // 初始化maps + core.status.floorId = floorId; + core.status.maps = core.clone(maps); + // 初始化怪物 + core.material.enemys = core.clone(core.enemys.getEnemys()); + // 初始化人物属性 + core.status.hero = core.clone(hero); + core.status.hard = hard; + // 保存页面 + core.status.savePage = core.getLocalStorage('savePage', 0); + + core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); + +} + +core.prototype.startGame = function (hard, callback) { + console.log('开始游戏'); + + core.resetStatus(core.firstData.hero, hard, core.firstData.floorId, + core.initStatus.maps); + + core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, function() { + core.setHeroMoveTriggerInterval(); + if (core.isset(callback)) callback(); + }); +} + + +core.prototype.restart = function() { + + /* + core.resetStatus(core.firstData.hero, core.firstData.hard, core.firstData.floorId, + core.initStatus.maps); + + core.changeFloor(core.firstData.floorId, null, core.firstData.hero.loc, function() { + core.drawTip('重新开始游戏'); + core.setHeroMoveTriggerInterval(); + }); + + */ + core.showStartAnimate(); +} + +/////////// 系统事件相关 END /////////// + + + + +/////////// 键盘、鼠标事件相关 /////////// + +core.prototype.keyDown = function(e) { + if(!core.status.played) { + return; + } + if(core.status.automaticRouting || core.status.automaticRouted) { + core.stopAutomaticRoute(); + } + if (core.status.lockControl) { + if (core.status.event.id == 'book') { + if (e.keyCode==37) core.ui.drawEnemyBook(core.status.event.data - 1); + else if (e.keyCode==39) core.ui.drawEnemyBook(core.status.event.data + 1); + return; + } + if (core.status.event.id == 'fly') { + if (e.keyCode==38) core.ui.drawFly(core.status.event.data+1); + else if (e.keyCode==40) core.ui.drawFly(core.status.event.data-1); + return; + } + if (core.status.event.id == 'save' || core.status.event.id == 'load') { + if (e.keyCode==37) core.ui.drawSLPanel(core.status.event.data-1); + else if (e.keyCode==39) core.ui.drawSLPanel(core.status.event.data+1); + return; + } + return; + } + switch(e.keyCode) { + case 37: + core.moveHero('left'); + break; + case 38: + core.moveHero('up'); + break; + case 39: + core.moveHero('right'); + break; + case 40: + core.moveHero('down'); + break; + } +} + +core.prototype.keyUp = function(e) { + if(!core.status.played) { + return; + } + + if (core.status.lockControl) { + if (core.status.event.id == 'book' && (e.keyCode==27 || e.keyCode==88)) + core.ui.closePanel(true); + if (core.status.event.id == 'fly' && (e.keyCode==71 || e.keyCode==27)) + core.ui.closePanel(); + if (core.status.event.id == 'fly' && e.keyCode==13) { + var index=core.status.hero.flyRange.indexOf(core.status.floorId); + var stair=core.status.event.datamax){ + index=ii; + max=directionDistance[ii]; + } + } + pos=[{'x':0,'y':1},{'x':-1,'y':0},{'x':0,'y':-1},{'x':1,'y':0},false][index] + if(pos){ + pos.x+=pos0.x; + pos.y+=pos0.y; + core.status.stepPostfix.push(pos); + core.fillPosWithPoint(pos); + } +} + +core.prototype.onup = function () { + core.status.holdingPath=0; + if(core.status.stepPostfix.length>0){ + var stepPostfix = []; + var direction={'0':{'1':'down','-1':'up'},'-1':{'0':'left'},'1':{'0':'right'}}; + for(var ii=1;ii12 || y>12) return; + + // 寻路 + if (!core.status.lockControl) { + core.setAutomaticRoute(x, y, stepPostfix); + return; + } + + // 怪物手册 + if (core.status.event.id == 'book') { + core.events.clickBook(x,y); + return; + } + + // 楼层飞行器 + if (core.status.event.id == 'fly') { + core.events.clickFly(x,y); + return; + } + + // 设置 + if (core.status.event.id == 'settings') { + core.events.clickSettings(x,y); + return; + } + + // 商店 + if (core.status.event.id == 'shop') { + core.events.clickShop(x,y); + return; + } + + // 快捷商店 + if (core.status.event.id == 'selectShop') { + core.events.clickSelectShop(x,y); + return; + } + + // 工具栏 + if (core.status.event.id == 'toolbox') { + core.events.clickToolbox(x,y); + return; + } + + // 存读档 + if (core.status.event.id == 'save' || core.status.event.id == 'load') { + core.events.clickSL(x,y); + return; + } + + // 选项 + if (core.status.event.id == 'confirmBox') { + if ((x == 4 || x == 5) && y == 7 && core.isset(core.status.event.data.yes)) + core.status.event.data.yes(); + if ((x == 7 || x == 8) && y == 7 && core.isset(core.status.event.data.no)) + core.status.event.data.no(); + return; + } + + // 关于 + if (core.status.event.id == 'about') { + if (core.isPlaying()) + core.ui.closePanel(false); + else + core.showStartAnimate(); + return; + } + + // 纯文本 + if (core.status.event.id == 'text') { + core.drawText(); + return; + } + + // NPC + if (core.status.event.id == 'npc') { + core.events.clickNPC(x,y); + return; + } + + // 同步存档 + if (core.status.event.id == 'syncSave') { + if (x>=4 && x<=8) { + if (y==5) { + core.ui.drawConfirmBox("你确定要将本地存档同步到服务器吗?", function(){ + // console.log("同步存档..."); + core.ui.drawWaiting("正在同步,请稍后..."); + + var formData = new FormData(); + formData.append('type', 'save'); + var saves = []; + for (var i=1;i<=180;i++) { + var data = core.getLocalStorage("save"+i, null); + if (core.isset(data)) { + saves.push(data); + } + } + var save_text = JSON.stringify(saves); + formData.append('data', save_text); + + // send + var xhr = new XMLHttpRequest(); + xhr.open("POST", "../sync.php"); + xhr.timeout = 1000; + xhr.onload = function(e) { + if (xhr.status==200) { + // console.log("同步成功。"); + var response = JSON.parse(xhr.response); + if (response.code<0) { + core.drawText("出错啦!\n无法同步存档到服务器。"); + } + else { + core.drawText("同步成功!\n\n您的存档编号: "+response.code+"\n您的存档密码: "+response.msg+"\n\n请牢记以上两个信息(如截图等),在从服务器\n同步存档时使用。") + } + } + else { + core.drawText("出错啦!\n无法同步存档到服务器。"); + } + }; + xhr.ontimeout = function(e) { + console.log(e); + core.drawText("出错啦!\n无法同步存档到服务器。"); + } + xhr.onerror = function(e) { + console.log(e); + core.drawText("出错啦!\n无法同步存档到服务器。"); + } + xhr.send(formData); + }, function() { + core.ui.drawSyncSave(); + }) + } + if (y==6) { + core.ui.drawConfirmBox("你确定要从服务器加载存档吗?\n该操作将覆盖所有本地存档且不可逆!", function(){ + var id = prompt("请输入存档编号:"); + if (id==null || id=="") { + core.ui.drawSyncSave(); return; + } + var password = prompt("请输入存档密码:"); + if (password==null || password=="") { + core.ui.drawSyncSave(); return; + } + core.ui.drawWaiting("正在同步,请稍后..."); + + var formData = new FormData(); + formData.append('type', 'load'); + formData.append('id', id); + formData.append('password', password); + + // send + var xhr = new XMLHttpRequest(); + xhr.open("POST", "../sync.php"); + xhr.timeout = 1000; + xhr.onload = function(e) { + if (xhr.status==200) { + // console.log("同步成功。"); + var response = JSON.parse(xhr.response); + switch (response.code) { + case 0: + // 成功 + var data=JSON.parse(response.msg); + // console.log(data); + for (var i=1;i<=180;i++) { + if (i<=data.length) { + core.setLocalStorage("save"+i, data[i-1]); + } + else { + core.removeLocalStorage("save"+i); + } + } + core.drawText("同步成功!\n你的本地所有存档均已被覆盖。"); + break; + case -1: + core.drawText("出错啦!\n存档编号"+id+"不存在!"); + break; + case -2: + core.drawText("出错啦!\n存档密码错误!"); + break; + default: + core.drawText("出错啦!\n无法从服务器同步存档。"); + break; + } + + } + else { + core.drawText("出错啦!\n无法从服务器同步存档。"); + } + }; + xhr.ontimeout = function(e) { + console.log(e); + core.drawText("出错啦!\n无法从服务器同步存档。"); + } + xhr.onerror = function(e) { + console.log(e); + core.drawText("出错啦!\n无法从服务器同步存档。"); + } + xhr.send(formData); + }, function() { + core.ui.drawSyncSave(); + }) + } + } + if (x>=5 && x<=7 && y==7) { + core.ui.drawSettings(false); + } + } + +} + +core.prototype.onmousewheel = function (direct) { + // 楼层飞行器 + if (core.status.lockControl && core.status.event.id == 'fly') { + if (direct==-1) core.ui.drawFly(core.status.event.data-1); + if (direct==1) core.ui.drawFly(core.status.event.data+1); + return; + } +} + +/////////// 键盘、鼠标事件相关 END /////////// + + + + +/////////// 寻路代码相关 /////////// + +core.prototype.clearAutomaticRouteNode = function (x, y) { + core.canvas.ui.clearRect(x * 32 + 5, y * 32 + 5, 27, 27); +} + +core.prototype.stopAutomaticRoute = function () { + if (!core.status.played) { + return; + } + core.stopAutoHeroMove(); + core.status.automaticRouting = false; + core.status.automaticRouted = false; + core.status.autoStepRoutes = []; + core.status.automaticRoutingTemp = {'destX': 0, 'destY': 0, 'moveStep': []}; + if (core.status.moveStepBeforeStop.length==0) + core.canvas.ui.clearRect(0, 0, 416, 416); +} + +core.prototype.continueAutomaticRoute = function () { + //此函数只应由events.afterOpenDoor和events.afterBattle调用 + var moveStep = core.status.moveStepBeforeStop; + core.status.moveStepBeforeStop = []; + if(moveStep.length===0)return; + if(moveStep.length===1 && moveStep[0].step===1)return; + core.status.automaticRouting = true; + core.setAutoHeroMove(moveStep); +} + +core.prototype.clearContinueAutomaticRoute = function () { + core.canvas.ui.clearRect(0, 0, 416, 416); + core.status.moveStepBeforeStop=[]; +} + +core.prototype.setAutomaticRoute = function (destX, destY, stepPostfix) { + if (!core.status.played || core.status.lockControl) { + return; + } + else if (core.status.automaticRouting) { + core.stopAutomaticRoute(); + return; + } + if (destX == core.status.hero.loc.x && destY == core.status.hero.loc.y) { + core.turnHero(); + return; + } + // 直接移动 + /* + if(core.status.automaticRoutingTemp.moveStep.length != 0 && core.status.automaticRoutingTemp.destX == destX && core.status.automaticRoutingTemp.destY == destY) { + core.status.automaticRouting = true; + core.setAutoHeroMove(core.status.automaticRoutingTemp.moveStep); + core.status.automaticRoutingTemp = {'destX': 0, 'destY': 0, 'moveStep': []}; + return; + } + */ + var step = 0; + var tempStep = null; + var moveStep; + core.status.automaticRoutingTemp = {'destX': 0, 'destY': 0, 'moveStep': []}; + if (!(moveStep = core.automaticRoute(destX, destY))) { + core.canvas.ui.clearRect(0, 0, 416, 416); + return false; + } + moveStep=moveStep.concat(stepPostfix); + core.status.automaticRoutingTemp.destX = destX; + core.status.automaticRoutingTemp.destY = destY; + core.canvas.ui.save(); + core.canvas.ui.clearRect(0, 0, 416, 416); + core.canvas.ui.fillStyle = '#bfbfbf'; + core.canvas.ui.strokeStyle = '#bfbfbf'; + core.canvas.ui.lineWidth = 8; + for (var m = 0; m < moveStep.length; m++) { + if (tempStep == null) { + step++; + tempStep = moveStep[m].direction; + } + else if (tempStep == moveStep[m].direction) { + step++; + } + else { + core.status.automaticRoutingTemp.moveStep.push({'direction': tempStep, 'step': step}); + step = 1; + tempStep = moveStep[m].direction; + } + if (m == moveStep.length - 1) { + core.status.automaticRoutingTemp.moveStep.push({'direction': tempStep, 'step': step}); + core.canvas.ui.fillRect(moveStep[m].x * 32 + 10, moveStep[m].y * 32 + 10, 12, 12); + } + else { + core.canvas.ui.beginPath(); + if (core.isset(moveStep[m + 1]) && tempStep != moveStep[m + 1].direction) { + if (tempStep == 'up' && moveStep[m + 1].direction == 'left' || tempStep == 'right' && moveStep[m + 1].direction == 'down') { + core.canvas.ui.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); + } + else if (tempStep == 'up' && moveStep[m + 1].direction == 'right' || tempStep == 'left' && moveStep[m + 1].direction == 'down') { + core.canvas.ui.moveTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); + } + else if (tempStep == 'left' && moveStep[m + 1].direction == 'up' || tempStep == 'down' && moveStep[m + 1].direction == 'right') { + core.canvas.ui.moveTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); + } + else if (tempStep == 'right' && moveStep[m + 1].direction == 'up' || tempStep == 'down' && moveStep[m + 1].direction == 'left') { + core.canvas.ui.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); + } + core.canvas.ui.stroke(); + continue; + } + switch (tempStep) { + case 'up': + case 'down': + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); + core.canvas.ui.stroke(); + break; + case 'left': + case 'right': + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); + core.canvas.ui.stroke(); + break; + } + } + } + core.canvas.ui.restore(); + core.status.automaticRouted = true; + + // 立刻移动 + core.status.automaticRouting = true; + // core.setAutoHeroMove(core.status.automaticRoutingTemp.moveStep); + core.setAutoHeroMove(core.status.automaticRoutingTemp.moveStep); + core.status.automaticRoutingTemp = {'destX': 0, 'destY': 0, 'moveStep': []}; + +} +// BFS +core.prototype.automaticRoute = function (destX, destY) { + var startX = core.getHeroLoc('x'); + var startY = core.getHeroLoc('y'); + var nowX = startX; + var nowY = startY; + var scanItem = {'x': 0, 'y': 0}; + var scan = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0} + }; + var queue = []; + var nowDeep = 0; + var route = []; + var ans = [] + + if (destX == startX && destY == startY) return false; + queue.push(13 * startX + startY); + queue.push(-1); + route[13 * startX + startY] = ''; + + while (queue.length != 1) { + var f = queue.shift(); + if (f===-1) {nowDeep+=1;queue.push(-1);continue;} + var deep = ~~(f/169); + if (deep!==nowDeep) {queue.push(f);continue;} + f=f%169; + var nowX = parseInt(f / 13), nowY = f % 13; + + for (var direction in scan) { + + var nx = nowX + scan[direction].x; + var ny = nowY + scan[direction].y; + if (nx<0 || nx>12 || ny<0 || ny>12) continue; + var nid = 13 * nx + ny; + + if (core.isset(route[nid])) continue; + + if (nx == destX && ny == destY) { + route[nid] = direction; + break; + } + if (core.noPassExists(nx, ny)) + continue; + var deepAdd=1; + if (core.idEndWith(nx,ny,'lavaNet')) deepAdd=100; + // 自动绕过血瓶 + if (!core.flags.potionWhileRouting && core.idEndWith(nx,ny,'Potion')) deepAdd=20; + route[nid] = direction; + queue.push(169*(nowDeep+deepAdd)+nid); + } + if (core.isset(route[13 * destX + destY])) break; + } + + if (!core.isset(route[13 * destX + destY])) { + return false; + } + + var nowX = destX, nowY = destY; + while (nowX != startX || nowY != startY) { + var dir = route[13 * nowX + nowY]; + ans.push({'direction': dir, 'x': nowX, 'y': nowY}); + nowX -= scan[dir].x; + nowY -= scan[dir].y; + } + + ans.reverse(); + return ans; +} + +core.prototype.fillPosWithPoint = function (pos) { + core.fillRect('ui', pos.x*32+12,pos.y*32+12,8,8, '#bfbfbf'); +} + +core.prototype.clearStepPostfix = function () { + if(core.status.mouseOutCheck >0){ + core.status.mouseOutCheck--; + window.setTimeout(core.clearStepPostfix,1000); + return; + } + core.status.holdingPath=0; + if(core.status.stepPostfix.length>0){ + core.status.stepPostfix=[]; + core.canvas.ui.clearRect(0, 0, 416,416); + core.canvas.ui.restore(); + } +} + +/////////// 寻路代码相关 END /////////// + + + +/////////// 自动行走 & 行走控制 /////////// + +core.prototype.stopAutoHeroMove = function () { + core.status.autoHeroMove = false; + core.status.automaticRouting = false; + core.status.automaticRouted = false; + core.status.autoStep = 0; + core.status.destStep = 0; + core.status.movedStep = 0; + core.status.autoStepRoutes = []; + core.stopHero(); + clearInterval(core.interval.heroAutoMoveScan); +} + +core.prototype.setAutoHeroMove = function (steps, start) { + if (steps.length == 0) { + return; + } + core.status.autoStepRoutes = steps; + core.status.autoStep = 0; + clearInterval(core.interval.heroAutoMoveScan); + core.interval.heroAutoMoveScan = window.setInterval(function () { + if (!core.status.autoHeroMove) { + if (core.status.autoStep == core.status.autoStepRoutes.length) { + core.stopAutoHeroMove(); + return; + } + core.autoHeroMove(core.status.autoStepRoutes[core.status.autoStep].direction, core.status.autoStepRoutes[core.status.autoStep].step); + core.status.autoStep++; + } + }, 80); +} + +core.prototype.autoHeroMove = function (direction, step) { + core.status.autoHeroMove = true; + core.status.destStep = step; + core.moveHero(direction); +} + +core.prototype.setHeroMoveInterval = function (direction, x, y, callback) { + if (core.status.heroMoving) { + return; + } + core.status.heroMoving = true; + var moveStep = 0; + core.interval.heroMoveInterval = window.setInterval(function () { + switch (direction) { + case 'up': + moveStep -= 4; + if (moveStep == -4 || moveStep == -8 || moveStep == -12 || moveStep == -16) { + core.drawHero(direction, x, y, 'leftFoot', 0, moveStep); + } + else if (moveStep == -20 || moveStep == -24 || moveStep == -28 || moveStep == -32) { + core.drawHero(direction, x, y, 'rightFoot', 0, moveStep); + } + if (moveStep == -32) { + core.setHeroLoc('y', '--'); + core.moveOneStep(); + if (core.status.heroStop) { + core.drawHero(direction, x, y - 1, 'stop'); + } + if (core.isset(callback)) { + callback(); + } + } + break; + case 'left': + moveStep -= 4; + if (moveStep == -4 || moveStep == -8 || moveStep == -12 || moveStep == -16) { + core.drawHero(direction, x, y, 'leftFoot', moveStep); + } + else if (moveStep == -20 || moveStep == -24 || moveStep == -28 || moveStep == -32) { + core.drawHero(direction, x, y, 'rightFoot', moveStep); + } + if (moveStep == -32) { + core.setHeroLoc('x', '--'); + core.moveOneStep(); + if (core.status.heroStop) { + core.drawHero(direction, x - 1, y, 'stop'); + } + if (core.isset(callback)) { + callback(); + } + } + break; + case 'down': + moveStep+=4; + if(moveStep == 4 || moveStep == 8 || moveStep == 12 || moveStep == 16) { + core.drawHero(direction, x, y, 'leftFoot', 0, moveStep); + } + else if(moveStep == 20 || moveStep == 24 ||moveStep == 28 || moveStep == 32) { + core.drawHero(direction, x, y, 'rightFoot', 0, moveStep); + } + if (moveStep == 32) { + core.setHeroLoc('y', '++'); + core.moveOneStep(); + if (core.status.heroStop) { + core.drawHero(direction, x, y + 1, 'stop'); + } + if (core.isset(callback)) { + callback(); + } + } + break; + case 'right': + moveStep+=4; + if(moveStep == 4 || moveStep == 8 || moveStep == 12 || moveStep == 16) { + core.drawHero(direction, x, y, 'leftFoot', moveStep); + } + else if(moveStep == 20 || moveStep == 24 ||moveStep == 28 || moveStep == 32) { + core.drawHero(direction, x, y, 'rightFoot', moveStep); + } + if (moveStep == 32) { + core.setHeroLoc('x', '++'); + core.moveOneStep(); + if (core.status.heroStop) { + core.drawHero(direction, x + 1, y, 'stop'); + } + if (core.isset(callback)) { + callback(); + } + } + break; + } + }, 10); +} + +core.prototype.setHeroMoveTriggerInterval = function () { + var direction, x, y; + var scan = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0} + }; + core.interval.heroMoveTriggerInterval = window.setInterval(function () { + if (!core.status.heroStop) { + direction = core.getHeroLoc('direction'); + x = core.getHeroLoc('x'); + y = core.getHeroLoc('y'); + var noPass; + noPass = core.noPass(x + scan[direction].x, y + scan[direction].y); + if (noPass) { + core.trigger(x + scan[direction].x, y + scan[direction].y); + core.drawHero(direction, x, y, 'stop'); + if (core.status.autoHeroMove) { + core.status.movedStep++; + if (core.status.destStep == core.status.movedStep) { + core.status.autoHeroMove = false; + core.status.destStep = 0; + core.status.movedStep = 0; + // core.stopHero(); + core.status.moveStepBeforeStop=[]; + core.stopAutomaticRoute(); + } + } + else { + core.status.heroStop = true; + } + return; + } + core.setHeroMoveInterval(direction, x, y, function () { + if (core.status.autoHeroMove) { + core.status.movedStep++; + if (core.status.destStep == core.status.movedStep) { + core.status.autoHeroMove = false; + core.status.destStep = 0; + core.status.movedStep = 0; + core.stopHero(); + core.drawHero(core.getHeroLoc('direction'), core.getHeroLoc('x'), core.getHeroLoc('y'), 'stop'); + } + } + else if (core.status.heroStop) { + core.drawHero(core.getHeroLoc('direction'), core.getHeroLoc('x'), core.getHeroLoc('y'), 'stop'); + } + core.trigger(core.getHeroLoc('x'), core.getHeroLoc('y')); + clearInterval(core.interval.heroMoveInterval); + core.status.heroMoving = false; + }); + } + }, 50); +} + +core.prototype.turnHero = function(direction) { + if (core.isset(direction)) { + core.status.hero.loc.direction = direction; + } + else if (core.status.hero.loc.direction == 'up') core.status.hero.loc.direction = 'right'; + else if (core.status.hero.loc.direction == 'right') core.status.hero.loc.direction = 'down'; + else if (core.status.hero.loc.direction == 'down') core.status.hero.loc.direction = 'left'; + else if (core.status.hero.loc.direction == 'left') core.status.hero.loc.direction = 'up'; + core.drawHero(core.status.hero.loc.direction, core.status.hero.loc.x, core.status.hero.loc.y, 'stop', 0, 0); + core.status.automaticRoutingTemp = {'destX': 0, 'destY': 0, 'moveStep': []}; + core.canvas.ui.clearRect(0, 0, 416, 416); +} + +core.prototype.moveHero = function (direction) { + core.setHeroLoc('direction', direction); + core.status.heroStop = false; +} + +core.prototype.moveOneStep = function() { + core.status.hero.steps++; +} + +core.prototype.waitHeroToStop = function(callback) { + core.stopAutomaticRoute(); + if (core.isset(callback)) { + core.lockControl(); + setTimeout(function(){callback()}, 30); + } +} + +core.prototype.stopHero = function () { + core.status.heroStop = true; +} + +core.prototype.drawHero = function (direction, x, y, status, offsetX, offsetY) { + offsetX = offsetX || 0; + offsetY = offsetY || 0; + core.clearAutomaticRouteNode(x, y); + var heroIcon = core.material.icons.heros[core.status.hero.id][direction]; + x = x * heroIcon.size; + y = y * heroIcon.size; + core.canvas.hero.clearRect(x - 32, y - 32, 96, 96); + core.canvas.hero.drawImage(core.material.images.heros, heroIcon.loc[status] * heroIcon.size, heroIcon.loc.iconLoc * heroIcon.size, heroIcon.size, heroIcon.size, x + offsetX, y + offsetY, heroIcon.size, heroIcon.size); +} + +/////////// 自动行走 & 行走控制 END /////////// + + + +/////////// 地图处理 /////////// + +// 开门 +core.prototype.openDoor = function (id, x, y, needKey, callback) { + // 是否存在门 + if (!core.terrainExists(x, y, id)) return; + // core.lockControl(); + if (core.status.moveStepBeforeStop.length==0) { + core.status.moveStepBeforeStop=core.status.autoStepRoutes.slice(core.status.autoStep-1,core.status.autoStepRoutes.length); + if (core.status.moveStepBeforeStop.length>=1)core.status.moveStepBeforeStop[0].step-=core.status.movedStep; + } + core.stopHero(); + core.stopAutomaticRoute(); + if (needKey) { + var key = id.replace("Door", "Key"); + if (!core.useKey(key)) { + if (key != "specialKey") + core.drawTip("你没有" + core.material.items[key].name + "!", "normal"); + else core.drawTip("无法开启此门。"); + core.clearContinueAutomaticRoute(); + return; + } + } + // open + core.playSound("door", "ogg"); + var state = 0; + var door = core.material.icons.animates[id]; + core.interval.openDoorAnimate = window.setInterval(function () { + state++; + if (state == 4) { + clearInterval(core.interval.openDoorAnimate); + core.removeBlock('event', x, y); + core.events.afterOpenDoor(id); + if (core.isset(callback)) callback(); + return; + } + core.canvas.event.clearRect(32 * x, 32 * y, 32, 32); + core.canvas.event.drawImage(core.material.images.animates, 32 * state, 32 * door.loc, 32, 32, 32 * x, 32 * y, 32, 32); + }, 30) +} + +// 战斗 +core.prototype.battle = function (id, x, y, callback) { + if (typeof(core.status.moveStepBeforeStop)=="undefined" || core.status.moveStepBeforeStop.length==0) { + core.status.moveStepBeforeStop=core.status.autoStepRoutes.slice(core.status.autoStep-1,core.status.autoStepRoutes.length); + if (core.status.moveStepBeforeStop.length>=1)core.status.moveStepBeforeStop[0].step-=core.status.movedStep; + } + core.stopHero(); + core.stopAutomaticRoute(); + + var damage = core.enemys.getDamage(id); + if (damage >= core.status.hero.hp) { + core.drawTip("你打不过此怪物!"); + core.clearContinueAutomaticRoute(); + return; + } + core.playSound('attack', 'ogg'); + core.status.hero.hp -= damage; + var money = core.material.enemys[id].money; + if (core.hasItem('coin')) + core.status.hero.money += core.material.enemys[id].money; + core.status.hero.money += money; + core.status.hero.experience += core.material.enemys[id].experience; + core.updateStatusBar(); + core.removeBlock('event', x, y); + core.canvas.event.clearRect(32 * x, 32 * y, 32, 32); + core.updateFg(); + var hint = "打败 " + core.material.enemys[id].name + ",金币+" + money; + if (core.flags.enableExperience) + hint += ",经验+" + core.material.enemys[id].experience; + core.drawTip(hint); + + // 打完怪物,触发事件 + core.events.afterBattle(id); + if (core.isset(callback)) + callback(); +} + +// 楼层切换 +core.prototype.changeFloor = function (floorId, stair, heroLoc, callback) { + core.lockControl(); + core.stopHero(); + core.stopAutomaticRoute(); + core.dom.floorNameLabel.innerHTML = core.status.maps[floorId].title; + if (core.isset(stair)) { + // find heroLoc + heroLoc = core.status.hero.loc; + var blocks = core.status.maps[floorId].blocks; + for (var i in blocks) { + if (core.isset(blocks[i].event) && blocks[i].event.id === stair) { + heroLoc.x = blocks[i].x; + heroLoc.y = blocks[i].y; + } + } + if (core.status.maps[floorId].canFlyTo && core.status.hero.flyRange.indexOf(floorId)<0) { + if (stair=='upFloor') core.status.hero.flyRange.unshift(floorId); + if (stair=='downFloor') core.status.hero.flyRange.push(floorId); + } + } + + window.setTimeout(function () { + // console.log('地图切换到' + floorId); + core.playSound('floor', 'mp3'); + core.mapChangeAnimate('show', function () { + core.statusBar.floor.innerHTML = core.status.maps[floorId].name; + core.updateStatusBar(); + core.drawMap(floorId, function () { + core.hide(core.dom.floorMsgGroup, 10, function () { + core.unLockControl(); + core.events.afterChangeFloor(floorId); + if (core.isset(callback)) callback(); + }); + core.setHeroLoc('direction', heroLoc.direction); + core.setHeroLoc('x', heroLoc.x); + core.setHeroLoc('y', heroLoc.y); + core.drawHero(core.getHeroLoc('direction'), core.getHeroLoc('x'), core.getHeroLoc('y'), 'stop'); + core.updateFg(); + }); + }); + }, 50); +} + +// 地图切换 +core.prototype.mapChangeAnimate = function (mode, callback) { + if (mode == 'show') { + core.show(core.dom.floorMsgGroup, 15, function () { + callback(); + }); + } + else { + core.hide(core.dom.floorMsgGroup, 20, function () { + callback(); + }); + } +} + +core.prototype.clearMap = function (map, x, y, width, height) { + if (map == 'all') { + for (var m in core.canvas) { + core.canvas[m].clearRect(0, 0, 416, 416); + } + } + else { + core.canvas[map].clearRect(x, y, width, height); + } +} + +core.prototype.fillText = function (map, text, x, y, style, font) { + if (core.isset(style)) { + core.setFillStyle(map, style); + } + if (core.isset(font)) { + core.setFont(map, font); + } + core.canvas[map].fillText(text, x, y); +} + +core.prototype.fillRect = function (map, x, y, width, height, style) { + if (core.isset(style)) { + core.setFillStyle(map, style); + } + core.canvas[map].fillRect(x, y, width, height); +} + +core.prototype.strokeRect = function (map, x, y, width, height, style, lineWidth) { + if (core.isset(style)) { + core.setStrokeStyle(map, style); + } + if (core.isset(lineWidth)) { + core.setLineWidth(map, lineWidth); + } + core.canvas[map].strokeRect(x, y, width, height); +} + +core.prototype.drawBlock = function (map, image, cutX, cutY, x, y, size, zoom, clear) { + zoom = zoom || 1; + if (core.isset(clear) && clear == true) { + core.canvas[map].clearRect(x * size, y * size, size, size); + } + core.canvas[map].drawImage(core.material.images[image], cutX * size, cutY * size, size, size, x * size, y * size, size * zoom, size * zoom); +} + +core.prototype.setFont = function (map, font) { + core.canvas[map].font = font; +} + +core.prototype.setLineWidth = function (map, lineWidth) { + if (map == 'all') { + for (var m in core.canvas) { + core.canvas[m].lineWidth = lineWidth; + } + } + core.canvas[map].lineWidth = lineWidth; +} + +core.prototype.saveCanvas = function (map) { + core.canvas[map].save(); +} + +core.prototype.loadCanvas = function (map) { + core.canvas[map].restore(); +} + +core.prototype.setOpacity = function (map, opacity) { + if (map == 'all') { + for (var m in core.canvas) { + core.canvas[m].globalAlpha = opacity; + } + } + core.canvas[map].globalAlpha = opacity; +} + +core.prototype.setStrokeStyle = function (map, style) { + if (map == 'all') { + for (var m in core.canvas) { + core.canvas[m].strokeStyle = style; + } + } + else { + core.canvas[map].strokeStyle = style; + } +} + +core.prototype.setAlpha = function (map, alpha) { + if (map == 'all') { + for (var m in core.canvas) { + core.canvas[m].globalAlpha = alpha; + } + } + else core.canvas[map].globalAlpha = alpha; +} + +core.prototype.setOpacity = function (map, opacity) { + if (map == 'all') { + for (var m in core.canvas) { + core.canvas[m].canvas.style.opacity = opacity; + } + } + else core.canvas[map].canvas.style.opacity = opacity; +} + +core.prototype.setFillStyle = function (map, style) { + if (map == 'all') { + for (var m in core.canvas) { + core.canvas[m].fillStyle = style; + } + } + else { + core.canvas[map].fillStyle = style; + } +} + +/** + * 地图绘制 + * @param mapName 地图ID + * @param callback 绘制完毕后的回调函数 + */ +core.prototype.drawMap = function (mapName, callback) { + var mapData = core.status.maps[mapName]; + var mapBlocks = mapData.blocks; + core.status.floorId = mapName; + core.status.thisMap = mapData; + var x, y, blockIcon, blockImage; + core.clearMap('all'); + core.rmGlobalAnimate(null, null, true); + core.enabledAllTrigger(); + for (x = 0; x < 13; x++) { + for (y = 0; y < 13; y++) { + blockIcon = core.material.icons.terrains.ground; + blockImage = core.material.images.terrains; + core.canvas.bg.drawImage(blockImage, 0, blockIcon.loc * blockIcon.size, blockIcon.size, blockIcon.size, x * blockIcon.size, y * blockIcon.size, blockIcon.size, blockIcon.size); + } + } + x = 0; + y = 0; + for (var b = 0; b < mapBlocks.length; b++) { + if (core.isset(mapBlocks[b].bg)) { + blockIcon = core.material.icons[mapBlocks[b].bg.cls][mapBlocks[b].bg.id]; + blockImage = core.material.images[mapBlocks[b].bg.cls]; + x = mapBlocks[b].x * blockIcon.size; + y = mapBlocks[b].y * blockIcon.size; + if (mapBlocks[b].bg.cls != 'empty') { + core.canvas.bg.drawImage(blockImage, 0, blockIcon.loc * blockIcon.size, blockIcon.size, blockIcon.size, x, y, blockIcon.size, blockIcon.size); + core.addGlobalAnimate(mapBlocks[b].bg.animate, x, y, 'bg', blockIcon.loc, blockIcon.size, blockImage); + } + else { + core.canvas.bg.clearRect(x, y, blockIcon.size, blockIcon.size); + } + } + else { + blockIcon = core.material.icons.terrains.ground; + blockImage = core.material.images.terrains; + x = mapBlocks[b].x * blockIcon.size; + y = mapBlocks[b].y * blockIcon.size; + core.canvas.bg.drawImage(blockImage, 0, blockIcon.loc * blockIcon.size, blockIcon.size, blockIcon.size, x, y, blockIcon.size, blockIcon.size); + } + if (core.isset(mapBlocks[b].event)) { + blockIcon = core.material.icons[mapBlocks[b].event.cls][mapBlocks[b].event.id]; + blockImage = core.material.images[mapBlocks[b].event.cls]; + core.canvas.event.drawImage(core.material.images[mapBlocks[b].event.cls], 0, blockIcon.loc * blockIcon.size, blockIcon.size, blockIcon.size, x, y, blockIcon.size, blockIcon.size); + core.addGlobalAnimate(mapBlocks[b].event.animate, x, y, 'event', blockIcon.loc, blockIcon.size, blockImage); + } + } + core.setGlobalAnimate(core.firstData.animateSpeed); + if (core.isset(callback)) + callback(); +} + +/** + * 是否存在不可通行节点 + * @param x + * @param y + * @returns {boolean} + */ +core.prototype.noPassExists = function (x, y) { + var blocks = core.status.thisMap.blocks; + for (var n = 0; n < blocks.length; n++) { + if (blocks[n].x == x && blocks[n].y == y && core.isset(blocks[n].event) && core.isset(blocks[n].event.noPass) && blocks[n].event.noPass) { + return true; + } + } + return false; +} + +/** + * 是否存在NPC节点 + * @param x + * @param y + * @returns {boolean} + */ +core.prototype.npcExists = function (x, y) { + var blocks = core.status.thisMap.blocks; + for (var n = 0; n < blocks.length; n++) { + if (blocks[n].x == x && blocks[n].y == y && core.isset(blocks[n].event) && blocks[n].event.cls == 'npcs') { + return true; + } + } + return false; +} + +/** + * 是否存在地形 + * @param x + * @param y + * @param id + * @returns {boolean} + */ +core.prototype.terrainExists = function (x, y, id) { + if (x > 12 || y > 12 || x < 0 || y < 0) { + return true; + } + if (core.stairExists(x, y)) { + return false; + } + var blocks = core.status.thisMap.blocks; + for (var t = 0; t < blocks.length; t++) { + if (blocks[t].x == x && blocks[t].y == y) { + for (var map in core.canvas) { + if (core.isset(blocks[t][map]) && (blocks[t][map].cls == 'terrains' || (blocks[t][map].cls == 'animates' && core.isset(blocks[t][map].noPass) && blocks[t][map].noPass == true)) && ((core.isset(id) && core.isset(blocks[t][map].id)) ? blocks[t][map].id == id : true)) { + return true; + } + } + } + } + return false; +} + +/** + * 是否存在楼梯 + * @param x + * @param y + * @returns {boolean} + */ +core.prototype.stairExists = function (x, y) { + var blocks = core.status.thisMap.blocks; + for (var s = 0; s < blocks.length; s++) { + if (blocks[s].x == x && blocks[s].y == y && core.isset(blocks[s].event) && blocks[s].event.cls == 'terrains' && core.isset(blocks[s].event.id) && (blocks[s].event.id == 'upFloor' || blocks[s].event.id == 'downFloor')) { + return true; + } + } + return false; +} + +core.prototype.enemyExists = function (x, y, id) { + var blocks = core.status.thisMap.blocks; + for (var e = 0; e < blocks.length; e++) { + if (blocks[e].x == x && blocks[e].y == y && core.isset(blocks[e].event) && blocks[e].event.cls == 'enemys' && ((core.isset(id) && core.isset(blocks[e].event.id)) ? blocks[e].event.id == id : true)) { + return true; + } + } + return false; +} + +core.prototype.idEndWith = function (x, y, idStr) { + var blocks = core.status.thisMap.blocks; + for (var n = 0; n < blocks.length; n++) { + if (blocks[n].x == x && blocks[n].y == y && core.isset(blocks[n].event)) { + var id = blocks[n].event.id; + return id.substring(id.length-idStr.length)==idStr; + } + } + return false; +} + +core.prototype.removeBlock = function (map, x, y) { + var map = map.split(','); + var mapBlocks = core.status.thisMap.blocks; + var blockIcon; + for (var b = 0; b < mapBlocks.length; b++) { + if (mapBlocks[b].x == x && mapBlocks[b].y == y) { + core.rmGlobalAnimate(x, y); + for (var m = 0; m < map.length; m++) { + if (!core.isset(mapBlocks[b][map[m]])) { + continue; + } + blockIcon = core.material.icons[mapBlocks[b][map[m]].cls][mapBlocks[b][map[m]].id]; + core.canvas[map[m]].clearRect(x * blockIcon.size, y * blockIcon.size, blockIcon.size, blockIcon.size); + // delete core.status.thisMap.blocks[b][map[m]]; + } + core.status.thisMap.blocks.splice(b, 1); + break; + } + } +} + +core.prototype.removeBlockByIds = function (floorId, ids) { + ids.sort(function (a,b) {return b-a}).forEach(function (id) { + core.status.maps[floorId].blocks.splice(id, 1); + }); +} + +core.prototype.noPass = function (x, y) { + if (x > 12 || y > 12 || x < 0 || y < 0) { + return true; + } + var mapBlocks = core.status.thisMap.blocks; + var noPass; + for (var b = 0; b < mapBlocks.length; b++) { + if (mapBlocks[b].x == x && mapBlocks[b].y == y) { + return noPass = (mapBlocks[b].event && mapBlocks[b].event.noPass) || (mapBlocks[b].bg && mapBlocks[b].bg.noPass); + } + } +} + +core.prototype.trigger = function (x, y) { + var mapBlocks = core.status.thisMap.blocks; + var noPass; + for (var b = 0; b < mapBlocks.length; b++) { + if (mapBlocks[b].x == x && mapBlocks[b].y == y) { + noPass = (mapBlocks[b].event && mapBlocks[b].event.noPass) || (mapBlocks[b].bg && mapBlocks[b].bg.noPass); + if (noPass) { + core.clearAutomaticRouteNode(x, y); + } + /* + if(core.isset(mapBlocks[b].fg) && core.isset(mapBlocks[b].fg.trigger) && (core.isset(mapBlocks[b].fg.disabledTrigger) ? mapBlocks[b].fg.disabledTrigger == false : true)) { + core.material.events[mapBlocks[b].fg.trigger](mapBlocks[b], core, function(data) { + + }); + } + */ + if (core.isset(mapBlocks[b].event) && core.isset(mapBlocks[b].event.trigger) && (core.isset(mapBlocks[b].event.disabledTrigger) ? mapBlocks[b].event.disabledTrigger == false : true) + && !(core.isset(mapBlocks[b].event.noTriggerCross) && mapBlocks[b].event.noTriggerCross && (core.status.autoHeroMove || core.status.autoStep 0) { + var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); + core.drawBoxAnimate(background); + core.interval.boxAnimate = setInterval(function () { + core.drawBoxAnimate(background); + }, speed); + } +} + +core.prototype.drawBoxAnimate = function (background) { + for (var a = 0; a < core.status.boxAnimateObjs.length; a++) { + var obj = core.status.boxAnimateObjs[a]; + obj.status = obj.status == 0 ? 1 : 0; + core.clearMap('ui', obj.bgx, obj.bgy, obj.bgsize, obj.bgsize); + core.fillRect('ui', obj.bgx, obj.bgy, obj.bgsize, obj.bgsize, background); + core.canvas.ui.drawImage(obj.image, obj.status * obj.icon.size, obj.icon.loc * obj.icon.size, + obj.icon.size, obj.icon.size, obj.x, obj.y, obj.icon.size, obj.icon.size); + } +} + +core.prototype.setHeroLoc = function (itemName, itemVal) { + if (itemVal == '++') { + core.status.hero.loc[itemName]++; + return; + } + else if (itemVal == '--') { + core.status.hero.loc[itemName]--; + return; + } + core.status.hero.loc[itemName] = itemVal; +} + +core.prototype.getHeroLoc = function (itemName) { + return core.status.hero.loc[itemName]; +} + +/** + * 更新显伤 + */ +core.prototype.updateFg = function () { + if (!core.isset(core.status.thisMap) || !core.isset(core.status.thisMap.blocks)) return; + // 更新显伤 + var mapBlocks = core.status.thisMap.blocks; + core.clearMap('fg', 0, 0, 416, 416); + // 没有怪物手册 + if (!core.hasItem('book')) return; + core.setFont('fg', "bold 11px Arial"); + var hero_hp = core.status.hero.hp; + for (var b = 0; b < mapBlocks.length; b++) { + var x = mapBlocks[b].x, y = mapBlocks[b].y; + if (core.isset(mapBlocks[b].event) && mapBlocks[b].event.cls == 'enemys') { + var id = mapBlocks[b].event.id; + + var damage = core.enemys.getDamage(id); + var color = "#000000"; + if (damage <= 0) color = '#00FF00'; + else if (damage < hero_hp / 3) color = '#FFFFFF'; + else if (damage < hero_hp * 2 / 3) color = '#FFFF00'; + else if (damage < hero_hp) color = '#FF7F00'; + else color = '#FF0000'; + + if (damage >= 999999999) damage = "???"; + else if (damage > 100000) damage = (damage / 10000).toFixed(1) + "w"; + + core.setFillStyle('fg', '#000000'); + core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1) - 2); + core.canvas.fg.fillText(damage, 32 * x, 32 * (y + 1) - 2); + core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1)); + core.canvas.fg.fillText(damage, 32 * x, 32 * (y + 1)); + + core.setFillStyle('fg', color); + core.canvas.fg.fillText(damage, 32 * x + 1, 32 * (y + 1) - 1); + + } + } +} + + + +/** + * 物品处理 start + */ +core.prototype.itemCount = function (itemId) { + if (!core.isset(itemId) || !core.isset(core.material.items[itemId])) return 0; + var itemCls = core.material.items[itemId].cls; + return core.isset(core.status.hero.items[itemCls][itemId]) ? core.status.hero.items[itemCls][itemId] : 0; +} + +core.prototype.hasItem = function (itemId) { + return core.itemCount(itemId) > 0; +} + +core.prototype.setItem = function (itemId, itemNum) { + var itemCls = core.material.items[itemId].cls; + if (itemCls == 'item') return; + if (!core.isset(core.status.hero.items[itemCls])) { + core.status.hero.items[itemCls] = {}; + } + core.status.hero.items[itemCls][itemId] = itemNum; +} + +core.prototype.useKey = function (itemId) { + if (!core.hasItem(itemId)) return false; + var itemCls = core.material.items[itemId].cls; + core.status.hero.items[itemCls][itemId]--; + core.updateStatusBar(); + return true; +} + +core.prototype.useItem = function (itemId) { + core.items.useItem(itemId); + return; +} + +core.prototype.canUseItem = function (itemId) { + return core.items.canUseItem(itemId); +} + +core.prototype.addItem = function (itemId, itemNum) { + var itemData = core.material.items[itemId]; + var itemCls = itemData.cls; + if (itemCls == 'item') return; + if (!core.isset(core.status.hero.items[itemCls])) { + core.status.hero.items[itemCls] = {}; + core.status.hero.items[itemCls][itemId] = 0; + } + else if (!core.isset(core.status.hero.items[itemCls][itemId])) { + core.status.hero.items[itemCls][itemId] = 0; + } + core.status.hero.items[itemCls][itemId] += itemNum; +} + +/* +core.prototype.removeBlock = function(itemX, itemY) { + var mapBlocks = core.status.thisMap.blocks; + for(var b = 0;b < mapBlocks.length;b++) { + if(mapBlocks[b].x == itemX && mapBlocks[b].y == itemY) { + // delete mapBlocks[b].event; + // mapBlocks[b] + core.status.thisMap.blocks.splice(b,1); + break; + } + } +} +*/ + +core.prototype.getItemEffect = function (itemId, itemNum) { + core.items.getItemEffect(itemId, itemNum); +} + +core.prototype.getItemEffectTip = function (itemId) { + return core.items.getItemEffectTip(itemId); +} + +core.prototype.getItem = function (itemId, itemNum, itemX, itemY, callback) { + // core.getItemAnimate(itemId, itemNum, itemX, itemY); + core.playSound('item', 'ogg'); + var itemCls = core.material.items[itemId].cls; + core.getItemEffect(itemId, itemNum); + core.removeBlock('event', itemX, itemY); + var text = '获得 ' + core.material.items[itemId].name; + if (itemNum > 1) text += "x" + itemNum; + if (itemCls === 'items') text += core.getItemEffectTip(itemId); + core.drawTip(text, 'image', core.material.icons.items[itemId]); + core.canvas.event.clearRect(itemX * 32, itemY * 32, 32, 32); + core.updateStatusBar(); + if (core.isset(callback)) callback(); +} + +core.prototype.drawTip = function (text, type, itemIcon) { + type = type || 'normal'; + var textX, textY, width, height, hide = false, opacityVal = 0; + clearInterval(core.interval.tipAnimate); + core.setFont('data', "16px Arial"); + core.saveCanvas('data'); + core.setOpacity('data', 0); + if (type == 'normal') { + textX = 16; + textY = 18; + width = textX + core.canvas.data.measureText(text).width + 16; + height = 42; + } + else if (type == 'image' && core.isset(itemIcon)) { + textX = 44; + textY = 18; + width = textX + core.canvas.data.measureText(text).width + 8; + height = 42; + } + else { + core.loadCanvas('data'); + return; + } + core.interval.tipAnimate = window.setInterval(function () { + if (hide) { + opacityVal -= 0.1; + } + else { + opacityVal += 0.1; + } + core.setOpacity('data', opacityVal); + core.clearMap('data', 5, 5, 400, height); + core.fillRect('data', 5, 5, width, height, '#000'); + if (core.isset(itemIcon)) { + core.canvas.data.drawImage(core.material.images.items, 0, itemIcon.loc * itemIcon.size, itemIcon.size, itemIcon.size, 10, 8, itemIcon.size, itemIcon.size); + } + core.fillText('data', text, textX + 5, textY + 15, '#fff'); + if (opacityVal > 0.6 || opacityVal < 0) { + if (hide) { + core.loadCanvas('data'); + core.clearMap('data', 5, 5, 400, height); + core.setOpacity('data', 1); + clearInterval(core.interval.tipAnimate); + return; + } + else { + if (!core.timeout.getItemTipTimeout) { + core.timeout.getItemTipTimeout = window.setTimeout(function () { + hide = true; + core.timeout.getItemTipTimeout = null; + }, 1000); + } + opacityVal = 0.6; + core.setOpacity('data', opacityVal); + } + } + }, 30); +} + +core.prototype.drawText = function (contents, callback) { + if (core.isset(contents)) { + if (typeof contents == 'string') { + contents = [{'content': contents}]; + } + else if (contents instanceof Object && core.isset(contents.content)) { + contents = [contents]; + } + else if (!(contents instanceof Array)) { + core.drawTip("出错了"); + console.log(contents); + return; + } + + core.status.event = {'id': 'text', 'data': {'list': contents, 'callback': callback}}; + core.lockControl(); + + // wait the hero to stop + core.stopAutomaticRoute(); + setTimeout(function() { + core.drawText(); + }, 30); + return; + } + + if (core.status.event.data.list.length==0) { + var callback = core.status.event.data.callback; + core.ui.closePanel(false); + if (core.isset(callback)) callback(); + return; + } + + var data=core.status.event.data.list.shift(); + if (typeof data == 'string') + core.ui.drawTextBox(data); + else + core.ui.drawTextBox(data.content, data.id); + // core.drawTextBox(content); +} + +/////////// 地图相关 END /////////// + +/* + * NPC事件 + */ +core.prototype.visitNpc = function (npcId, x, y, callback) { + + // 正在移动中... + if (!core.status.heroStop) { + setTimeout(function () { + core.visitNpc(npcId, x, y, callback); + }, 30); + return; + } + + if (!core.isset(core.status.npcs[npcId])) + core.status.npcs[npcId] = 0; + var times=core.status.npcs[npcId]; + + var list = core.npcs.getEffect(npcId, times); + if (list.length==0) return; + + core.status.event.data = {'x': x, 'y': y, 'id': npcId, 'list': list, 'callback': callback}; + core.status.event.id = 'npc'; + core.lockControl(); + + core.npcAction(); +} + +core.prototype.npcAction = function() { + + if (core.status.event.data.list.length==0) { + if (core.isset(core.status.event.data.callback)) + core.status.event.data.callback(); + core.ui.closePanel(false); + return; + } + + var data = core.status.event.data.list.shift(); + core.status.event.data.current = data; + + var id=core.status.event.data.id, x=core.status.event.data.x, y=core.status.event.data.y; + + // 对话 + if (data.action=='text') { + core.ui.drawTextBox(data.content, core.isset(data.isHero)&&data.isHero?'hero':data.id); + return; + } + // 显示选项 + if (data.action=='choices') { + var npc = core.material.npcs[data.id]; + + var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); + + clearInterval(core.interval.tipAnimate); + core.clearMap('data', 0, 0, 416, 416); + core.setOpacity('data', 1); + + core.clearMap('ui', 0, 0, 416, 416); + core.setAlpha('ui', 1); + core.setFillStyle('ui', background); + + var left = 97, top = 64, right = 416 - 2 * left, bottom = 416 - 2 * top; + core.fillRect('ui', left, top, right, bottom, background); + core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); + + // 名称 + core.canvas.ui.textAlign = "center"; + core.fillText('ui', npc.name, left + 135, top + 34, '#FFFFFF', 'bold 19px Verdana'); + + // 动画 + core.strokeRect('ui', left + 15 - 1, top + 30 - 1, 34, 34, '#DDDDDD', 2); + core.status.boxAnimateObjs = []; + core.status.boxAnimateObjs.push({ + 'bgx': left + 15, 'bgy': top + 30, 'bgsize': 32, + 'image': core.material.images.npcs, + 'x': left + 15, 'y': top + 30, 'icon': core.material.icons.npcs[npc.icon] + }); + core.setBoxAnimate(core.firstData.animateSpeed); + + // 对话 + core.canvas.ui.textAlign = "left"; + var contents = data.hint.split('\n'); + for (var i=0;i0) { + setTimeout(function() {core.upload();}, delay); + return; + } + + core.updateTime(); + + var xmlHttp = new XMLHttpRequest(); + var parameters = "action=upload"; + parameters+="&starttime="+core.status.hero.time.starttime.getTime()/1000; + parameters+="&hard="+core.status.hard; + parameters+="&floor="+core.status.maps[core.status.floorId].name; + parameters+="&hp="+core.status.hero.hp+"&atk="+core.status.hero.atk+"&def="+core.status.hero.def+"&mdef="+core.status.hero.mdef+"&money="+core.status.hero.money; + parameters+="&yellow="+core.status.hero.items.keys.yellowKey+"&blue="+core.status.hero.items.keys.blueKey; + parameters+="&playtime="+core.status.hero.time.playtime+"&totaltime="+core.status.hero.time.totaltime+"&step="+core.status.hero.steps+"&ending="+(core.status.event.id=='win'?1:0); + + //xmlHttp.open("GET", "/service/mota/mota4.php?"+parameters, true); + //xmlHttp.send(); + } + catch (e) { + } + */ +} + +// 作弊 +core.prototype.debug = function() { + core.setStatus('hp', 999999); + core.setStatus('atk', 10000); + core.setStatus('def', 10000); + core.setStatus('mdef', 10000); + core.setStatus('money', 10000); + core.setStatus('experience', 10000); + core.setItem('yellowKey', 50); + core.setItem('blueKey', 50); + core.setItem('redKey', 50); + core.setItem('book', 1); + core.setItem('fly', 1); + for (var i in core.status.maps) + if (core.status.maps[i].canFlyTo && core.status.hero.flyRange.indexOf(i)<0) + core.status.hero.flyRange.push(i); + core.updateStatusBar(); + core.drawTip("作弊成功"); +} + + +core.prototype.checkStatus = function (name, need, item, clearData) { + if (need && core.status.event.id == name) { + core.ui.closePanel(clearData); + return false; + } + + if (need && core.status.lockControl) return false; + if (core.isset(item) && item && !core.hasItem(name)) { + core.drawTip("你没有" + core.material.items[name].name); + return false; + } + if (!core.status.heroStop) { + core.drawTip("请先停止勇士行动"); + return false; + } + + core.lockControl(); + core.status.automaticRoutingTemp = {'destX': 0, 'destY': 0, 'moveStep': []}; + core.status.event.id = name; + return true; +} + +core.prototype.openBook = function (need) { + if (!core.checkStatus('book', need, true, true)) + return; + core.useItem('book'); +} + +core.prototype.useFly = function (need) { + if (!core.checkStatus('fly', need, true)) + return; + if (!core.canUseItem('fly')) { + core.drawTip("楼层传送器好像失效了"); + core.unLockControl(); + core.status.event.data = null; + core.status.event.id = null; + return; + } + core.useItem('fly'); + return; +} + +core.prototype.openToolbox = function (need) { + if (!core.checkStatus('toolbox', need)) + return; + // core.drawTip("工具箱还未完成"); + core.ui.drawToolbox(); +} + +core.prototype.save = function(need) { + if (!core.checkStatus('save', need)) + return; + core.ui.drawSLPanel(core.status.savePage); +} + +core.prototype.load = function (need) { + + // 游戏开始前读档 + if (!core.isPlaying()) { + core.status.event = {'id': 'load', 'data': null}; + core.status.lockControl = true; + core.dom.startPanel.style.display = 'none'; + var page = core.getLocalStorage('savePage', 0); + core.ui.drawSLPanel(page); + return; + } + + if (!core.checkStatus('load', need)) + return; + core.ui.drawSLPanel(core.status.savePage); +} + +core.prototype.doSL = function (id, type) { + if (type=='save') { + if (core.saveData("save"+id)) { + core.ui.closePanel(); + core.drawTip('存档成功!'); + core.setLocalStorage('savePage', core.status.savePage); + } + else { + core.drawTip('存储空间不足,请覆盖已有的存档或在菜单栏中进行清理'); + } + return; + } + else if (type=='load') { + var data = core.getLocalStorage("save"+id, null); + if (!core.isset(data)) { + core.drawTip("无效的存档"); + return; + } + core.ui.closePanel(); + core.loadData(data, function() { + core.setLocalStorage('savePage', core.status.savePage); + core.drawTip("读档成功"); + }); + return; + } +} + +core.prototype.saveData = function(dataId) { + core.updateTime(); + var data = { + 'floorId': core.status.floorId, + 'hero': core.clone(core.status.hero), + 'hard': core.status.hard, + 'maps': core.maps.save(core.status.maps), + 'npcs': {}, + 'shops': {}, + 'version': core.firstData.version, + 'time': new Date().getTime() + }; + data.hero.time.starttime=core.status.hero.time.starttime.getTime(); + // set shop times + for (var shop in core.status.shops) { + data.shops[shop]={ + 'times': core.status.shops[shop].times, + 'visited': core.status.shops[shop].visited + } + } + // core.upload(); + core.events.beforeSaveData(data); + + return core.setLocalStorage(dataId, data); + // console.log(core.getLocalStorage(dataId)); +} + +core.prototype.loadData = function (data, callback) { + core.upload(); + + var totaltime=null, lasttime = null; + + if (core.isPlaying()) { + core.updateTime(); + var totaltime = core.status.hero.time.totaltime; + var lasttime = core.clone(core.status.hero.time.lasttime); + } + + core.resetStatus(data.hero, data.hard, data.floorId, + core.maps.load(data.maps)); + + // load shop times + for (var shop in core.status.shops) { + core.status.shops[shop].times = data.shops[shop].times; + core.status.shops[shop].visited = data.shops[shop].visited; + } + + core.status.hero.time.starttime = new Date(core.status.hero.time.starttime); + if (core.isset(totaltime) && totaltime>core.status.hero.time.totaltime) + core.status.hero.time.totaltime=totaltime; + if (core.isset(lasttime)) + core.status.hero.time.lasttime = lasttime; + else core.status.hero.time.lasttime = new Date(); + + core.events.afterLoadData(data); + + core.changeFloor(data.floorId, null, data.hero.loc, function() { + core.setHeroMoveTriggerInterval(); + if (core.isset(callback)) callback(); + }); + + core.upload(1500); +} + +core.prototype.setStatus = function (statusName, statusVal) { + if (core.isset(core.status.hero[statusName])) { + core.status.hero[statusName] = statusVal; + } +} + +core.prototype.getStatus = function (statusName) { + if (core.isset(core.status.hero[statusName])) { + return core.status.hero[statusName]; + } +} + +core.prototype.setFlag = function(flag, value) { + if (!core.isset(core.status.hero)) return; + core.status.hero.flags[flag]=value; +} + +core.prototype.getFlag = function(flag, defaultValue) { + if (!core.isset(core.status.hero)) return defaultValue; + var value = core.status.hero.flags[flag]; + if (core.isset(value)) return value; + return defaultValue; +} + +// 只有不为0或false时才会返回true +core.prototype.hasFlag = function(flag) { + if (core.getFlag(flag)) return true; + return false; +} + +core.prototype.lockControl = function () { + core.status.lockControl = true; +} + +core.prototype.unLockControl = function () { + core.status.lockControl = false; +} + +core.prototype.isset = function (val) { + if (val == undefined || val == null) { + return false; + } + return true +} + +core.prototype.playSound = function (soundName, soundType) { + if (!core.musicStatus.soundStatus || !core.musicStatus.loaded) { + return; + } + /* + if (core.isset(core.musicStatus.playedSound)) { + // core.musicStatus.playedSound.pause(); + } + */ + core.musicStatus.playedSound = core.material.sounds[soundType][soundName]; + core.musicStatus.playedSound.play(); +} + +core.prototype.playBgm = function (bgmName, bgmType) { + if (core.musicStatus.isIOS || !core.musicStatus.loaded) return; + if (core.isset(core.musicStatus.playedBgm)) { + core.musicStatus.playedBgm.pause(); + } + core.musicStatus.playedBgm = core.material.sounds[bgmType][bgmName]; + if (core.musicStatus.soundStatus) + core.musicStatus.playedBgm.play(); +} + +core.prototype.changeSoundStatus = function () { + if (core.musicStatus.soundStatus) { + main.core.disabledSound(); + } + else { + main.core.enabledSound(); + } +} + +core.prototype.enabledSound = function () { + // core.musicStatus.playedBgm.play(); + core.musicStatus.soundStatus = true; + core.playBgm('bgm', 'mp3'); + core.setLocalStorage('soundStatus', true); +} + +core.prototype.disabledSound = function () { + core.musicStatus.playedBgm.pause(); + core.musicStatus.soundStatus = false; + core.setLocalStorage('soundStatus', false); +} + +core.prototype.show = function (obj, speed, callback) { + if (!core.isset(speed)) { + obj.style.display = 'block'; + return; + } + obj.style.display = 'block'; + obj.style.opacity = 0; + var opacityVal = 0; + var showAnimate = window.setInterval(function () { + opacityVal += 0.03; + obj.style.opacity = opacityVal; + if (opacityVal > 1) { + clearInterval(showAnimate); + if (core.isset(callback)) { + callback(); + } + } + }, speed); +} + +core.prototype.hide = function (obj, speed, callback) { + if (!core.isset(speed)) { + obj.style.display = 'none'; + return; + } + var opacityVal = 1; + var hideAnimate = window.setInterval(function () { + opacityVal -= 0.03; + obj.style.opacity = opacityVal; + if (opacityVal < 0) { + obj.style.display = 'none'; + clearInterval(hideAnimate); + if (core.isset(callback)) { + callback(); + } + } + }, speed); +} + + +////// 状态栏相关 ////// + +core.prototype.clearStatusBar = function() { + var statusList = ['floor', 'hp', 'atk', 'def', /*'mdef',*/ 'money', 'experience', 'yellowKey', 'blueKey', 'redKey', 'hard']; + statusList.forEach(function (e) { + core.statusBar[e].innerHTML = ""; + }); + core.statusBar.image.book.style.opacity = 0.3; + core.statusBar.image.fly.style.opacity = 0.3; +} + +/** + * 更新状态栏 + */ +core.prototype.updateStatusBar = function () { + + // 上限999999 + if (core.flags.HPMAX>0) { + core.setStatus('hp', Math.min(core.flags.HPMAX, core.getStatus('hp'))); + } + + // core.statusBar.floor.innerHTML = core.maps.maps[core.status.floorId].name; + var statusList = ['hp', 'atk', 'def', 'mdef', 'money', 'experience']; + statusList.forEach(function (item) { + core.statusBar[item].innerHTML = core.getStatus(item); + }); + var keys = ['yellowKey', 'blueKey', 'redKey']; + keys.forEach(function (key) { + core.statusBar[key].innerHTML = core.setTwoDigits(core.status.hero.items.keys[key]); + }) + core.statusBar.poison.innerHTML = core.hasFlag('poison')?"毒":""; + core.statusBar.weak.innerHTML = core.hasFlag('weak')?"衰":""; + core.statusBar.curse.innerHTML = core.hasFlag('curse')?"咒":""; + core.statusBar.hard.innerHTML = core.status.hard; + if (core.hasItem('book')) { + core.statusBar.image.book.style.opacity = 1; + } else { + core.statusBar.image.book.style.opacity = 0.3; + } + if (core.hasItem('fly')) { + core.statusBar.image.fly.style.opacity = 1; + } else { + core.statusBar.image.fly.style.opacity = 0.3; + } + core.updateFg(); +} + +core.prototype.resize = function(clientWidth, clientHeight) { + + // 画布大小 + var canvasWidth = 416; + // 竖屏状态下,默认StatusBar高度(不计算边框) + var statusBarHeight = 83; + // 竖屏状态下,底端默认ToolBar高度(不计算边框) + var toolBarHeight = 49; + + // 横屏状态下,默认StatusBar宽度(不计算边框) + var statusBarWidth = 132; + + //适配宽度阈值, 6为两倍的边框宽度 + var ADAPT_WIDTH = canvasWidth + 6; + + var width = clientWidth; + var isHorizontal = false; + if(clientWidth > clientHeight && clientHeight < 422){ + isHorizontal = true; + width = clientHeight; + } + + // 移动端 + if (width < ADAPT_WIDTH) { + var zoom = (ADAPT_WIDTH - width) / 4.22; + var scale = 1 - zoom / 100; + + core.position.scale = scale; + canvasWidth = width - 6; + + if(!isHorizontal){ //竖屏 + core.position.screenMode = 'vertical'; + + statusBarHeight *= scale; + toolBarHeight *= scale; + + core.position.gameGroup = { + 'width': canvasWidth, + 'height': width+statusBarHeight+toolBarHeight, + 'top': (clientHeight-width-statusBarHeight-toolBarHeight)/2, + 'left': 3 + } + + // 这几项都是相对gameGroup的位置 + core.position.statusBar = { + 'width': canvasWidth, + 'height': statusBarHeight, + 'top': 0, + 'left': 0, + 'fontSize': 16 * scale + } + core.position.canvas = { + 'width': canvasWidth, + 'height': canvasWidth, + 'top': statusBarHeight, // 3px计算在内边框 + 'left': 0, + 'borderLeft': '', + 'borderTop': '3px #fff solid', + 'borderBottom': '3px #fff solid' + } + core.position.toolBar = { + 'display': 'block', + 'width': canvasWidth, 'height': toolBarHeight, + 'top': statusBarHeight + 3 + canvasWidth, + } + + var icon_firstline = 8 * scale, icon_secondline = 44 * scale; + var icon_toolline = core.position.toolBar.top + 13 * scale; + var icon_toolline_per = 46 * scale; + + var text_firstline = 14 * scale, text_secondline = 50 * scale, text_thirdline = 75 * scale; + var text_toolline = core.position.toolBar.top + 18 * scale; + + // 如果同时启用mdef和experience,则不显示当前层数 + if (core.flags.enableMDef && core.flags.enableExperience) { + core.position.items = { + 'image': { + 'size': 32*scale, + 'floor': {'top': 0, 'left': 0, 'display': 'none'}, + 'hp': {'top': icon_firstline, 'left': 8 * scale}, + 'atk': {'top': icon_firstline, 'left': 126 * scale}, + 'def': {'top': icon_firstline, 'left': 226 * scale}, + 'mdef': {'top': icon_secondline, 'left': 8 * scale, 'display': 'block'}, + 'money': {'top': icon_secondline, 'left': 108 * scale}, + 'experience': {'top': icon_secondline, 'left': 208 * scale, 'display': 'block'}, + 'book': {'top': icon_toolline, 'left': 8 * scale}, + 'fly': {'top': icon_toolline, 'left': 8 * scale + icon_toolline_per}, + 'toolbox': {'top': icon_toolline, 'left': 8 * scale + icon_toolline_per * 2}, + 'shop': {'top': icon_toolline, 'left': 8*scale+icon_toolline_per*3, 'display': 'block'}, + 'save': {'top': icon_toolline, 'left': 8 * scale + icon_toolline_per * 4}, + 'load': {'top': icon_toolline, 'left': 8 * scale + icon_toolline_per * 5}, + 'settings': {'top': icon_toolline, 'left': 8 * scale + icon_toolline_per * 6} + }, + 'floor': {'top': 0, 'left': 0, 'display': 'none'}, + 'hp': {'top': text_firstline, 'left': 42 * scale}, + 'atk': {'top': text_firstline, 'left': 160 * scale}, + 'def': {'top': text_firstline, 'left': 260 * scale}, + 'mdef': {'top': text_secondline, 'left': 42 * scale, 'display': 'block'}, + 'money': {'top': text_secondline, 'left': 144 * scale}, + 'experience': {'top': text_secondline, 'left': 242 * scale, 'display': 'block'}, + 'yellowKey': {'top': text_secondline, 'left': 308 * scale}, + 'blueKey': {'top': text_secondline, 'left': 342 * scale}, + 'redKey': {'top': text_secondline, 'left': 376 * scale}, + 'poison': {'top': text_firstline, 'left': 330* scale}, + 'weak': {'top': text_firstline, 'left': 355* scale}, + 'curse': {'top': text_firstline, 'left': 380*scale}, + 'hard': {'top': text_toolline, 'left': 320*scale} + } + } + + // 否则显示层数 + else { + core.position.items = { + 'image': { + 'size': 32*scale, + 'floor': {'top': icon_firstline, 'left': 8 * scale, 'display': 'block'}, + 'hp': {'top': icon_firstline, 'left': 90 * scale}, + 'atk': {'top': icon_firstline, 'left': 208 * scale}, + 'def': {'top': icon_firstline, 'left': 308 * scale}, + 'mdef': {'top': icon_secondline, 'left': 8 * scale, 'display': core.flags.enableMDef?'block':'none'}, + 'money': {'top': icon_secondline, 'left': (core.flags.enableMDef?108:8) * scale}, + 'experience': {'top': icon_secondline, 'left': 108 * scale, 'display': core.flags.enableExperience?'block':'none'}, + 'book': {'top': icon_toolline, 'left': 8 * scale}, + 'fly': {'top': icon_toolline, 'left': 8 * scale + icon_toolline_per}, + 'toolbox': {'top': icon_toolline, 'left': 8 * scale + icon_toolline_per * 2}, + 'shop': {'top': icon_toolline, 'left': 8*scale+icon_toolline_per*3, 'display': 'block'}, + 'save': {'top': icon_toolline, 'left': 8 * scale + icon_toolline_per * 4}, + 'load': {'top': icon_toolline, 'left': 8 * scale + icon_toolline_per * 5}, + 'settings': {'top': icon_toolline, 'left': 8 * scale + icon_toolline_per * 6} + }, + 'floor': {'top': text_firstline, 'left': 44 * scale}, + 'hp': {'top': text_firstline, 'left': 124 * scale}, + 'atk': {'top': text_firstline, 'left': 242 * scale}, + 'def': {'top': text_firstline, 'left': 342 * scale}, + 'mdef': {'top': text_secondline, 'left': 44*scale, 'display': core.flags.enableMDef?'block':'none'}, + 'money': {'top': text_secondline, 'left': (core.flags.enableMDef?144:44) * scale}, + 'experience': {'top': text_secondline, 'left': 142 * scale, 'display': core.flags.enableExperience?'block':'none'}, + 'yellowKey': {'top': text_secondline, 'left': 216 * scale}, + 'blueKey': {'top': text_secondline, 'left': 250 * scale}, + 'redKey': {'top': text_secondline, 'left': 284 * scale}, + 'poison': {'top': text_secondline, 'left': 330* scale}, + 'weak': {'top': text_secondline, 'left': 355* scale}, + 'curse': {'top': text_secondline, 'left': 380*scale}, + 'hard': {'top': text_toolline, 'left': 320*scale} + } + } + }else { //横屏 + core.position.screenMode = 'horizontal'; + statusBarWidth *= scale + + core.position.gameGroup = { + 'width': statusBarWidth + canvasWidth + 3, + 'height': canvasWidth, + 'top': 3, + 'left': (clientWidth - width - statusBarWidth)/2, + } + + // 这几项都是相对gameGroup的位置 + core.position.statusBar = { + 'top': 0, 'left': 0, + 'width': statusBarWidth, + 'height': canvasWidth, + 'fontSize': 16 * scale + } + core.position.canvas = { + 'borderTop': '', + 'borderLeft': '3px #fff solid', + 'borderBottom': '', + 'top': 0, + 'left': statusBarWidth, + 'width': canvasWidth, + 'height': canvasWidth + } + core.position.toolBar = { + 'display': 'none', 'top': 0, 'left': 0, 'width': 0, 'height': 0 + } + core.resizeIconHorizontal(scale); + } + + }else { //大屏设备 pc端 + core.position.scale = 1; + core.position.screenMode = 'bigScreen'; + + var totalWidth = statusBarWidth + 3 + canvasWidth; + + core.position.gameGroup = { + 'top': (clientHeight-canvasWidth)/2, + 'left': (width-totalWidth)/2, + 'width': totalWidth, 'height': canvasWidth + } + + // 这几项都是相对gameGroup的位置 + core.position.statusBar = { + 'top': 0, 'left': 0, + 'width': statusBarWidth, 'height': canvasWidth, + 'fontSize': 16 + } + core.position.canvas = { + 'borderTop': '', 'borderBottom': '', 'borderLeft': '3px #fff solid', + 'top': 0, 'left': statusBarWidth, 'width': canvasWidth, 'height': canvasWidth + } + core.position.toolBar = { + 'display': 'none', 'top': 0, 'left': 0, 'width': 0, 'height': 0 + } + core.resizeIconHorizontal(1); + } + core.resetSize(); +} + +core.prototype.resizeIconHorizontal = function(scale) { + var first_col = 8 * scale, second_col = 50 * scale, third_col = 92 * scale; + var first_icon_row = 20 * scale, first_text_row = 28 * scale, first_tool_row = 303 * scale; + var per_row = 36 * scale, tool_per_row = 40*scale; + + // 如果同时启用mdef和experience,则不显示当前层数 + if (core.flags.enableMDef && core.flags.enableExperience) { + core.position.items = { + 'image': { + 'size': 32*scale, + 'floor': {'top': 0, 'left': 0, 'display': 'none'}, + 'hp': {'top': first_icon_row , 'left': first_col}, + 'atk': {'top': first_icon_row + per_row, 'left': first_col}, + 'def': {'top': first_icon_row + per_row * 2, 'left': first_col}, + 'mdef': {'top': first_icon_row + per_row * 3, 'left': first_col, 'display': 'block'}, + 'money': {'top': first_icon_row + per_row * 4, 'left': first_col}, + 'experience': {'top': first_icon_row + per_row * 5, 'left': first_col, 'display': 'block'}, + 'book': {'top': first_tool_row, 'left': first_col}, + 'fly': {'top': first_tool_row, 'left': second_col}, + 'toolbox': {'top': first_tool_row, 'left': third_col}, + 'shop': {'top': 0, 'left': 0, 'display': 'none'}, + 'save': {'top': first_tool_row + tool_per_row, 'left': first_col}, + 'load': {'top': first_tool_row + tool_per_row, 'left': second_col}, + 'settings': {'top': first_tool_row + tool_per_row, 'left': third_col} + }, + 'floor': {'top': 0, 'left': 0, 'display': 'none'}, + 'hp': {'top': first_text_row, 'left': second_col}, + 'atk': {'top': first_text_row + per_row, 'left': second_col}, + 'def': {'top': first_text_row + per_row * 2, 'left': second_col}, + 'mdef': {'top': first_text_row + per_row * 3, 'left': second_col, 'display': 'block'}, + 'money': {'top': first_text_row + per_row * 4, 'left': second_col}, + 'experience': {'top': first_text_row + per_row * 5, 'left': second_col, 'display': 'block'}, + 'yellowKey': {'top': first_text_row + per_row * 6, 'left': first_col}, + 'blueKey':{'top': first_text_row + per_row * 6, 'left': second_col}, + 'redKey': {'top': first_text_row + per_row * 6, 'left': third_col}, + 'poison': {'top': first_text_row + per_row * 6.75, 'left': first_col+10 * scale}, + 'weak': {'top': first_text_row + per_row * 6.75, 'left': first_col + 35 * scale}, + 'curse': {'top': first_text_row + per_row * 6.75, 'left': first_col + 60 * scale}, + 'hard': {'top': 383*scale, 'left': 0} + } + } + // 否则显示层数 + else { + core.position.items = { + 'image': { + 'size': 32*scale, + 'floor': {'top': first_icon_row, 'left': first_col, 'display': 'block'}, + 'hp': {'top': first_icon_row + per_row, 'left': first_col}, + 'atk': {'top': first_icon_row + per_row * 2, 'left': first_col}, + 'def': {'top': first_icon_row + per_row * 3, 'left': first_col}, + 'mdef': {'top': first_icon_row + per_row * 4, 'left': first_col, 'display': core.flags.enableMDef?'block':'none'}, + 'money': {'top': first_icon_row + per_row * (core.flags.enableMDef?5:4), 'left': first_col}, + 'experience': {'top': first_icon_row + per_row * 5, 'left': first_col, 'display': core.flags.enableExperience?'block':'none'}, + 'book': {'top': first_tool_row, 'left': first_col}, + 'fly': {'top': first_tool_row, 'left': second_col}, + 'toolbox': {'top': first_tool_row, 'left': third_col}, + 'shop': {'top': 0, 'left': 0, 'display': 'none'}, + 'save': {'top': first_tool_row + tool_per_row, 'left': first_col}, + 'load': {'top': first_tool_row + tool_per_row, 'left': second_col}, + 'settings': {'top': first_tool_row + tool_per_row, 'left': third_col} + }, + 'floor': {'top': first_text_row, 'left': second_col, 'display': 'block'}, + 'hp': {'top': first_text_row + per_row, 'left': second_col}, + 'atk': {'top': first_text_row + per_row * 2, 'left': second_col}, + 'def': {'top': first_text_row + per_row * 3, 'left': second_col}, + 'mdef': {'top': first_text_row + per_row * 4, 'left': second_col, 'display': core.flags.enableMDef?'block':'none'}, + 'money': {'top': first_text_row + per_row * (core.flags.enableMDef?5:4), 'left': second_col}, + 'experience': {'top': first_text_row + per_row * 5, 'left': second_col, 'display': core.flags.enableExperience?'block':'none'}, + 'yellowKey': {'top': first_text_row + per_row * 6, 'left': first_col}, + 'blueKey':{'top': first_text_row + per_row * 6, 'left': second_col}, + 'redKey': {'top': first_text_row + per_row * 6, 'left': third_col}, + 'poison': {'top': first_text_row + per_row * 6.75, 'left': first_col+10 * scale}, + 'weak': {'top': first_text_row + per_row * 6.75, 'left': first_col + 35 * scale}, + 'curse': {'top': first_text_row + per_row * 6.75, 'left': first_col + 60 * scale}, + 'hard': {'top': 383*scale, 'left': 0} + } + } +} + +core.prototype.resetSize = function () { + + core.dom.gameGroup.style.left = core.position.gameGroup.left + "px"; + core.dom.gameGroup.style.top = core.position.gameGroup.top + "px"; + core.dom.gameGroup.style.width = core.position.gameGroup.width + "px"; + core.dom.gameGroup.style.height = core.position.gameGroup.height + "px"; + + core.dom.statusBar.style.width = core.position.statusBar.width + "px"; + core.dom.statusBar.style.height = core.position.statusBar.height + "px"; + core.dom.statusBar.style.fontSize = core.position.statusBar.fontSize + "px"; + + core.dom.toolBar.style.top = core.position.toolBar.top + "px"; + core.dom.toolBar.style.width = core.position.toolBar.width + "px"; + core.dom.toolBar.style.height = core.position.toolBar.height + "px"; + core.dom.toolBar.style.display = core.position.toolBar.display; + + core.dom.floorMsgGroup.style.width = core.position.canvas.width + "px"; + + for (var i = 0; i < core.dom.gameCanvas.length; i++) { + core.dom.gameCanvas[i].style.borderTop = core.position.canvas.borderTop; + core.dom.gameCanvas[i].style.borderLeft = core.position.canvas.borderLeft; + core.dom.gameCanvas[i].style.top = core.position.canvas.top + "px"; + core.dom.gameCanvas[i].style.left = core.position.canvas.left + "px"; + core.dom.gameCanvas[i].style.width = core.position.canvas.width + "px"; + core.dom.gameCanvas[i].style.height = core.position.canvas.height + "px"; + } + + // images + for (var item in core.statusBar.image) { + if (core.isset(core.position.items.image[item].display)) + core.statusBar.image[item].style.display = core.position.items.image[item].display; + else + core.statusBar.image[item].style.display = 'block'; + core.statusBar.image[item].style.width = core.position.items.image.size + "px"; + core.statusBar.image[item].style.height = core.position.items.image.size + "px"; + core.statusBar.image[item].style.top = core.position.items.image[item].top + "px"; + core.statusBar.image[item].style.left = core.position.items.image[item].left + "px"; + } + + // texts + for (var item in core.statusBar) { + if (item == 'image') continue; + if (core.isset(core.position.items[item].display)) + core.statusBar[item].style.display = core.position.items[item].display; + else + core.statusBar[item].style.display = 'block'; + core.statusBar[item].style.top = core.position.items[item].top + "px"; + core.statusBar[item].style.left = core.position.items[item].left + "px"; + } + +} + +/** + * 系统机制 end + */ + +var core = new core(); +main.instance.core = core; diff --git a/libs/core.min.js b/libs/core.min.js new file mode 100644 index 00000000..1e60e949 --- /dev/null +++ b/libs/core.min.js @@ -0,0 +1 @@ +function core(){this.dom={};this.statusBar={};this.canvas={};this.images=[];this.sounds={};this.firstData={};this.material={images:{},sounds:{},ground:null,items:{},enemys:{},icons:{},events:{},npcs:{}};this.timeout={getItemTipTimeout:null};this.interval={twoAnimate:null,fourAnimate:null,boxAnimate:null,heroMoveTriggerInterval:null,heroMoveInterval:null,heroAutoMoveScan:null,tipAnimate:null,openDoorAnimate:null};this.musicStatus={isIOS:false,loaded:false,bgmStatus:false,soundStatus:true,playedSound:null,playedBgm:null};this.position={gameGroup:{},canvas:{},statusBar:{},toolBar:{},items:{},scale:1,screenMode:"bigScreen"};this.initStatus={played:false,hero:{id:"",name:"",hp:0,atk:0,def:0,mdef:0,money:0,experience:0,loc:{direction:"down",x:0,y:0},flyRange:[],items:[]},floorId:null,thisMap:null,maps:null,heroMoving:false,heroStop:true,lockControl:false,autoHeroMove:false,automaticRouting:false,automaticRouted:false,autoStep:0,movedStep:0,destStep:0,automaticRoutingTemp:{destX:0,destY:0,moveStep:[]},autoStepRoutes:[],holdingPath:0,stepPostfix:[],mouseOutCheck:1,moveStepBeforeStop:[],savePage:null,shops:{},npcs:{},event:{id:null,data:null},openingDoor:null,twoAnimateObjs:[],fourAnimateObjs:[],boxAnimateObjs:[]};this.status={};this.flags={}}core.prototype.init=function(h,c,d,b,a,f){core.dom=h;core.statusBar=c;core.canvas=d;core.images=b;core.sounds=a;for(var e in f){core[e]=f[e]}core.firstData=core.data.getFirstData();core.initStatus.shops=core.firstData.shops;core.initStatus.npcs=core.firstData.npcs;core.dom.versionLabel.innerHTML=core.firstData.version;core.material.items=core.items.getItems();core.initStatus.maps=core.maps.getMaps();core.material.enemys=core.clone(core.enemys.getEnemys());core.material.icons=core.icons.getIcons();core.material.events=core.events.getEvents();core.material.npcs=core.npcs.getNpcs();core.flags=core.data.flags;core.musicStatus.soundStatus=core.getLocalStorage("soundStatus",true);var g=navigator.userAgent;if(g.indexOf("iPhone")>-1||g.indexOf("iPad")>-1){console.log("你的设备为iphone,不自动播放音乐!");core.musicStatus.isIOS=true;core.musicStatus.soundStatus=false}core.material.ground=new Image();core.material.ground.src="images/ground.png";core.loader(function(){console.log(core.material);core.showStartAnimate(function(){})})};core.prototype.showStartAnimate=function(c){core.dom.startPanel.style.opacity=1;core.dom.startPanel.style.display="block";core.dom.startTop.style.opacity=1;core.dom.startTop.style.display="block";core.dom.startButtonGroup.style.display="none";core.dom.startButtons.style.display="block";core.dom.levelChooseButtons.style.display="none";core.status.played=false;core.clearStatus();core.clearMap("all");var b=1;var a=window.setInterval(function(){b-=0.03;if(b<0){clearInterval(a);core.dom.startTop.style.display="none";core.dom.startButtonGroup.style.display="block";if(core.isset(c)){c()}}core.dom.startTop.style.opacity=b},20)};core.prototype.hideStartAnimate=function(c){var b=1;var a=window.setInterval(function(){b-=0.03;if(b<0){clearInterval(a);core.dom.startPanel.style.display="none";c()}core.dom.startPanel.style.opacity=b},20)};core.prototype.setStartProgressVal=function(a){core.dom.startTopProgress.style.width=a+"%"};core.prototype.setStartLoadTipText=function(a){core.dom.startTopLoadTips.innerHTML=a};core.prototype.loader=function(g){var e=0,a=0,f=0,d=0;a=core.images.length;for(var c in core.sounds){d+=core.sounds[c].length}for(var b=0;b0){return}core.musicStatus.bgmStatus=1;if(core.musicStatus.soundStatus){core.playBgm("bgm","mp3")}return}var a=b.shift();a.oncanplay=function(){core.loadSoundItem(b)};a.load()};core.prototype.isPlaying=function(){if(core.isset(core.status.played)&&core.status.played){return true}return false};core.prototype.clearStatus=function(){for(var a in core.interval){clearInterval(core.interval[a])}core.status={};core.clearStatusBar();core.resize(main.dom.body.clientWidth,main.dom.body.clientHeight)};core.prototype.resetStatus=function(c,e,b,d){for(var a in core.interval){clearInterval(core.interval[a])}core.status=core.clone(core.initStatus);core.status.played=true;core.status.floorId=b;core.status.maps=core.clone(d);core.material.enemys=core.clone(core.enemys.getEnemys());core.status.hero=core.clone(c);core.status.hard=e;core.status.savePage=core.getLocalStorage("savePage",0);core.resize(main.dom.body.clientWidth,main.dom.body.clientHeight)};core.prototype.startGame=function(b,a){console.log("开始游戏");core.resetStatus(core.firstData.hero,b,core.firstData.floorId,core.initStatus.maps);core.changeFloor(core.status.floorId,null,core.firstData.hero.loc,function(){core.setHeroMoveTriggerInterval();if(core.isset(a)){a()}})};core.prototype.restart=function(){core.showStartAnimate()};core.prototype.keyDown=function(a){if(!core.status.played){return}if(core.status.automaticRouting||core.status.automaticRouted){core.stopAutomaticRoute()}if(core.status.lockControl){if(core.status.event.id=="book"){if(a.keyCode==37){core.ui.drawEnemyBook(core.status.event.data-1)}else{if(a.keyCode==39){core.ui.drawEnemyBook(core.status.event.data+1)}}return}if(core.status.event.id=="fly"){if(a.keyCode==38){core.ui.drawFly(core.status.event.data+1)}else{if(a.keyCode==40){core.ui.drawFly(core.status.event.data-1)}}return}if(core.status.event.id=="save"||core.status.event.id=="load"){if(a.keyCode==37){core.ui.drawSLPanel(core.status.event.data-1)}else{if(a.keyCode==39){core.ui.drawSLPanel(core.status.event.data+1)}}return}return}switch(a.keyCode){case 37:core.moveHero("left");break;case 38:core.moveHero("up");break;case 39:core.moveHero("right");break;case 40:core.moveHero("down");break}};core.prototype.keyUp=function(d){if(!core.status.played){return}if(core.status.lockControl){if(core.status.event.id=="book"&&(d.keyCode==27||d.keyCode==88)){core.ui.closePanel(true)}if(core.status.event.id=="fly"&&(d.keyCode==71||d.keyCode==27)){core.ui.closePanel()}if(core.status.event.id=="fly"&&d.keyCode==13){var a=core.status.hero.flyRange.indexOf(core.status.floorId);var c=core.status.event.dataa){c=d;a=f[d]}}g=[{x:0,y:1},{x:-1,y:0},{x:0,y:-1},{x:1,y:0},false][c];if(g){g.x+=e.x;g.y+=e.y;core.status.stepPostfix.push(g);core.fillPosWithPoint(g)}};core.prototype.onup=function(){core.status.holdingPath=0;if(core.status.stepPostfix.length>0){var b=[];var e={"0":{"1":"down","-1":"up"},"-1":{"0":"left"},"1":{"0":"right"}};for(var c=1;c12||c>12){return}if(!core.status.lockControl){core.setAutomaticRoute(b,c,a);return}if(core.status.event.id=="book"){core.events.clickBook(b,c);return}if(core.status.event.id=="fly"){core.events.clickFly(b,c);return}if(core.status.event.id=="settings"){core.events.clickSettings(b,c);return}if(core.status.event.id=="shop"){core.events.clickShop(b,c);return}if(core.status.event.id=="selectShop"){core.events.clickSelectShop(b,c);return}if(core.status.event.id=="toolbox"){core.events.clickToolbox(b,c);return}if(core.status.event.id=="save"||core.status.event.id=="load"){core.events.clickSL(b,c);return}if(core.status.event.id=="confirmBox"){if((b==4||b==5)&&c==7&&core.isset(core.status.event.data.yes)){core.status.event.data.yes()}if((b==7||b==8)&&c==7&&core.isset(core.status.event.data.no)){core.status.event.data.no()}return}if(core.status.event.id=="about"){if(core.isPlaying()){core.ui.closePanel(false)}else{core.showStartAnimate()}return}if(core.status.event.id=="text"){core.drawText();return}if(core.status.event.id=="npc"){core.events.clickNPC(b,c);return}if(core.status.event.id=="syncSave"){if(b>=4&&b<=8){if(c==5){core.showConfirmBox("你确定要将本地存档同步到服务器吗?",function(){core.waiting("正在同步,请稍后...");var h=new FormData();h.append("type","save");var d=[];for(var e=1;e<=180;e++){var g=core.getLocalStorage("save"+e,null);if(core.isset(g)){d.push(g)}}var f=JSON.stringify(d);h.append("data",f);var j=new XMLHttpRequest();j.open("POST","../sync.php");j.timeout=1000;j.onload=function(k){if(j.status==200){var i=JSON.parse(j.response);if(i.code<0){core.drawText("出错啦!\n无法同步存档到服务器。")}else{core.drawText("同步成功!\n\n您的存档编号: "+i.code+"\n您的存档密码: "+i.msg+"\n\n请牢记以上两个信息(如截图等),在从服务器\n同步存档时使用。")}}else{core.drawText("出错啦!\n无法同步存档到服务器。")}};j.ontimeout=function(i){console.log(i);core.drawText("出错啦!\n无法同步存档到服务器。")};j.onerror=function(i){console.log(i);core.drawText("出错啦!\n无法同步存档到服务器。")};j.send(h)},function(){core.syncSave()})}if(c==6){core.showConfirmBox("你确定要从服务器加载存档吗?\n该操作将覆盖所有本地存档且不可逆!",function(){var g=prompt("请输入存档编号:");if(g==null||g==""){core.syncSave();return}var d=prompt("请输入存档密码:");if(d==null||d==""){core.syncSave();return}core.waiting("正在同步,请稍后...");var e=new FormData();e.append("type","load");e.append("id",g);e.append("password",d);var f=new XMLHttpRequest();f.open("POST","../sync.php");f.timeout=1000;f.onload=function(l){if(f.status==200){var h=JSON.parse(f.response);switch(h.code){case 0:var k=JSON.parse(h.msg);for(var j=1;j<=180;j++){if(j<=k.length){core.setLocalStorage("save"+j,k[j-1])}else{core.removeLocalStorage("save"+j)}}core.drawText("同步成功!\n你的本地所有存档均已被覆盖。");break;case -1:core.drawText("出错啦!\n存档编号"+g+"不存在!");break;case -2:core.drawText("出错啦!\n存档密码错误!");break;default:core.drawText("出错啦!\n无法从服务器同步存档。");break}}else{core.drawText("出错啦!\n无法从服务器同步存档。")}};f.ontimeout=function(h){console.log(h);core.drawText("出错啦!\n无法从服务器同步存档。")};f.onerror=function(h){console.log(h);core.drawText("出错啦!\n无法从服务器同步存档。")};f.send(e)},function(){core.syncSave()})}}if(b>=5&&b<=7&&c==7){core.ui.openSettings(false)}}};core.prototype.onmousewheel=function(a){if(core.status.lockControl&&core.status.event.id=="fly"){if(a==-1){core.ui.drawFly(core.status.event.data-1)}if(a==1){core.ui.drawFly(core.status.event.data+1)}return}};core.prototype.clearAutomaticRouteNode=function(a,b){core.canvas.ui.clearRect(a*32+5,b*32+5,27,27)};core.prototype.stopAutomaticRoute=function(){if(!core.status.played){return}core.stopAutoHeroMove();core.status.automaticRouting=false;core.status.automaticRouted=false;core.status.autoStepRoutes=[];core.status.automaticRoutingTemp={destX:0,destY:0,moveStep:[]};if(core.status.moveStepBeforeStop.length==0){core.canvas.ui.clearRect(0,0,416,416)}};core.prototype.continueAutomaticRoute=function(){var a=core.status.moveStepBeforeStop;core.status.moveStepBeforeStop=[];if(a.length===0){return}if(a.length===1&&a[0].step===1){return}core.status.automaticRouting=true;core.setAutoHeroMove(a)};core.prototype.clearContinueAutomaticRoute=function(){core.canvas.ui.clearRect(0,0,416,416);core.status.moveStepBeforeStop=[]};core.prototype.setAutomaticRoute=function(d,c,b){if(!core.status.played||core.status.lockControl){return}else{if(core.status.automaticRouting){core.stopAutomaticRoute();return}}if(d==core.status.hero.loc.x&&c==core.status.hero.loc.y){core.turnHero();return}var f=0;var g=null;var e;core.status.automaticRoutingTemp={destX:0,destY:0,moveStep:[]};if(!(e=core.automaticRoute(d,c))){core.canvas.ui.clearRect(0,0,416,416);return false}e=e.concat(b);core.status.automaticRoutingTemp.destX=d;core.status.automaticRoutingTemp.destY=c;core.canvas.ui.save();core.canvas.ui.clearRect(0,0,416,416);core.canvas.ui.fillStyle="#bfbfbf";core.canvas.ui.strokeStyle="#bfbfbf";core.canvas.ui.lineWidth=8;for(var a=0;a12||p<0||p>12){continue}var e=13*q+p;if(core.isset(s[e])){continue}if(q==u&&p==t){s[e]=r;break}if(core.noPassExists(q,p)){continue}var a=1;if(core.idEndWith(q,p,"lavaNet")){a=100}if(!core.flags.potionWhileRouting&&core.idEndWith(q,p,"Potion")){a=20}s[e]=r;k.push(169*(g+a)+e)}if(core.isset(s[13*u+t])){break}}if(!core.isset(s[13*u+t])){return false}var d=u,c=t;while(d!=o||c!=m){var i=s[13*d+c];j.push({direction:i,x:d,y:c});d-=h[i].x;c-=h[i].y}j.reverse();return j};core.prototype.fillPosWithPoint=function(a){core.fillRect("ui",a.x*32+12,a.y*32+12,8,8,"#bfbfbf")};core.prototype.clearStepPostfix=function(){if(core.status.mouseOutCheck>0){core.status.mouseOutCheck--;window.setTimeout(core.clearStepPostfix,1000);return}core.status.holdingPath=0;if(core.status.stepPostfix.length>0){core.status.stepPostfix=[];core.canvas.ui.clearRect(0,0,416,416);core.canvas.ui.restore()}};core.prototype.stopAutoHeroMove=function(){core.status.autoHeroMove=false;core.status.automaticRouting=false;core.status.automaticRouted=false;core.status.autoStep=0;core.status.destStep=0;core.status.movedStep=0;core.status.autoStepRoutes=[];core.stopHero();clearInterval(core.interval.heroAutoMoveScan)};core.prototype.setAutoHeroMove=function(a,b){if(a.length==0){return}core.status.autoStepRoutes=a;core.status.autoStep=0;clearInterval(core.interval.heroAutoMoveScan);core.interval.heroAutoMoveScan=window.setInterval(function(){if(!core.status.autoHeroMove){if(core.status.autoStep==core.status.autoStepRoutes.length){core.stopAutoHeroMove();return}core.autoHeroMove(core.status.autoStepRoutes[core.status.autoStep].direction,core.status.autoStepRoutes[core.status.autoStep].step);core.status.autoStep++}},80)};core.prototype.autoHeroMove=function(b,a){core.status.autoHeroMove=true;core.status.destStep=a;core.moveHero(b)};core.prototype.setHeroMoveInterval=function(c,a,e,d){if(core.status.heroMoving){return}core.status.heroMoving=true;var b=0;core.interval.heroMoveInterval=window.setInterval(function(){switch(c){case"up":b-=4;if(b==-4||b==-8||b==-12||b==-16){core.drawHero(c,a,e,"leftFoot",0,b)}else{if(b==-20||b==-24||b==-28||b==-32){core.drawHero(c,a,e,"rightFoot",0,b)}}if(b==-32){core.setHeroLoc("y","--");core.moveOneStep();if(core.status.heroStop){core.drawHero(c,a,e-1,"stop")}if(core.isset(d)){d()}}break;case"left":b-=4;if(b==-4||b==-8||b==-12||b==-16){core.drawHero(c,a,e,"leftFoot",b)}else{if(b==-20||b==-24||b==-28||b==-32){core.drawHero(c,a,e,"rightFoot",b)}}if(b==-32){core.setHeroLoc("x","--");core.moveOneStep();if(core.status.heroStop){core.drawHero(c,a-1,e,"stop")}if(core.isset(d)){d()}}break;case"down":b+=4;if(b==4||b==8||b==12||b==16){core.drawHero(c,a,e,"leftFoot",0,b)}else{if(b==20||b==24||b==28||b==32){core.drawHero(c,a,e,"rightFoot",0,b)}}if(b==32){core.setHeroLoc("y","++");core.moveOneStep();if(core.status.heroStop){core.drawHero(c,a,e+1,"stop")}if(core.isset(d)){d()}}break;case"right":b+=4;if(b==4||b==8||b==12||b==16){core.drawHero(c,a,e,"leftFoot",b)}else{if(b==20||b==24||b==28||b==32){core.drawHero(c,a,e,"rightFoot",b)}}if(b==32){core.setHeroLoc("x","++");core.moveOneStep();if(core.status.heroStop){core.drawHero(c,a+1,e,"stop")}if(core.isset(d)){d()}}break}},10)};core.prototype.setHeroMoveTriggerInterval=function(){var c,a,d;var b={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};core.interval.heroMoveTriggerInterval=window.setInterval(function(){if(!core.status.heroStop){c=core.getHeroLoc("direction");a=core.getHeroLoc("x");d=core.getHeroLoc("y");var e;e=core.noPass(a+b[c].x,d+b[c].y);if(e){core.trigger(a+b[c].x,d+b[c].y);core.drawHero(c,a,d,"stop");if(core.status.autoHeroMove){core.status.movedStep++;if(core.status.destStep==core.status.movedStep){core.status.autoHeroMove=false;core.status.destStep=0;core.status.movedStep=0;core.status.moveStepBeforeStop=[];core.stopAutomaticRoute()}}else{core.status.heroStop=true}return}core.setHeroMoveInterval(c,a,d,function(){if(core.status.autoHeroMove){core.status.movedStep++;if(core.status.destStep==core.status.movedStep){core.status.autoHeroMove=false;core.status.destStep=0;core.status.movedStep=0;core.stopHero();core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop")}}else{if(core.status.heroStop){core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop")}}core.trigger(core.getHeroLoc("x"),core.getHeroLoc("y"));clearInterval(core.interval.heroMoveInterval);core.status.heroMoving=false})}},50)};core.prototype.turnHero=function(a){if(core.isset(a)){core.status.hero.loc.direction=a}else{if(core.status.hero.loc.direction=="up"){core.status.hero.loc.direction="right"}else{if(core.status.hero.loc.direction=="right"){core.status.hero.loc.direction="down"}else{if(core.status.hero.loc.direction=="down"){core.status.hero.loc.direction="left"}else{if(core.status.hero.loc.direction=="left"){core.status.hero.loc.direction="up"}}}}}core.drawHero(core.status.hero.loc.direction,core.status.hero.loc.x,core.status.hero.loc.y,"stop",0,0);core.status.automaticRoutingTemp={destX:0,destY:0,moveStep:[]};core.canvas.ui.clearRect(0,0,416,416)};core.prototype.moveHero=function(a){core.setHeroLoc("direction",a);core.status.heroStop=false};core.prototype.moveOneStep=function(){core.status.hero.steps++};core.prototype.waitHeroToStop=function(a){core.stopAutomaticRoute();if(core.isset(a)){core.lockControl();setTimeout(function(){a()},30)}};core.prototype.stopHero=function(){core.status.heroStop=true};core.prototype.drawHero=function(d,b,g,c,a,f){a=a||0;f=f||0;core.clearAutomaticRouteNode(b,g);var e=core.material.icons.heros[core.status.hero.id][d];b=b*e.size;g=g*e.size;core.canvas.hero.clearRect(b-32,g-32,96,96);core.canvas.hero.drawImage(core.material.images.heros,e.loc[c]*e.size,e.loc.iconLoc*e.size,e.size,e.size,b+a,g+f,e.size,e.size)};core.prototype.openDoor=function(h,b,g,a,f){if(!core.terrainExists(b,g,h)){return}if(core.status.moveStepBeforeStop.length==0){core.status.moveStepBeforeStop=core.status.autoStepRoutes.slice(core.status.autoStep-1,core.status.autoStepRoutes.length);if(core.status.moveStepBeforeStop.length>=1){core.status.moveStepBeforeStop[0].step-=core.status.movedStep}}core.stopHero();core.stopAutomaticRoute();if(a){var d=h.replace("Door","Key");if(!core.useKey(d)){if(d!="specialKey"){core.drawTip("你没有"+core.material.items[d].name+"!","normal")}else{core.drawTip("无法开启此门。")}core.clearContinueAutomaticRoute();return}}core.playSound("door","ogg");var e=0;var c=core.material.icons.animates[h];core.interval.openDoorAnimate=window.setInterval(function(){e++;if(e==4){clearInterval(core.interval.openDoorAnimate);core.removeBlock("event",b,g);core.events.afterOpenDoor(h);if(core.isset(f)){f()}return}core.canvas.event.clearRect(32*b,32*g,32,32);core.canvas.event.drawImage(core.material.images.animates,32*e,32*c.loc,32,32,32*b,32*g,32,32)},30)};core.prototype.battle=function(g,a,f,e){if(typeof(core.status.moveStepBeforeStop)=="undefined"||core.status.moveStepBeforeStop.length==0){core.status.moveStepBeforeStop=core.status.autoStepRoutes.slice(core.status.autoStep-1,core.status.autoStepRoutes.length);if(core.status.moveStepBeforeStop.length>=1){core.status.moveStepBeforeStop[0].step-=core.status.movedStep}}core.stopHero();core.stopAutomaticRoute();var c=core.enemys.getDamage(g);if(c>=core.status.hero.hp){core.drawTip("你打不过此怪物!");core.clearContinueAutomaticRoute();return}core.playSound("attack","ogg");core.status.hero.hp-=c;var b=core.material.enemys[g].money;if(core.hasItem("coin")){core.status.hero.money+=core.material.enemys[g].money}core.status.hero.money+=b;core.status.hero.experience+=core.material.enemys[g].experience;core.updateStatusBar();core.removeBlock("event",a,f);core.canvas.event.clearRect(32*a,32*f,32,32);core.updateFg();var d="打败 "+core.material.enemys[g].name+",金币+"+b;if(core.flags.enableExperience){d+=",经验+"+core.material.enemys[g].experience}core.drawTip(d);core.events.afterBattle(g);if(core.isset(e)){e()}};core.prototype.changeFloor=function(d,c,a,f){core.lockControl();core.stopHero();core.stopAutomaticRoute();core.dom.floorNameLabel.innerHTML=core.status.maps[d].title;if(core.isset(c)){a=core.status.hero.loc;var e=core.status.maps[d].blocks;for(var b in e){if(core.isset(e[b].event)&&e[b].event.id===c){a.x=e[b].x;a.y=e[b].y}}if(core.status.maps[d].canFlyTo&&core.status.hero.flyRange.indexOf(d)<0){if(c=="upFloor"){core.status.hero.flyRange.unshift(d)}if(c=="downFloor"){core.status.hero.flyRange.push(d)}}}window.setTimeout(function(){core.playSound("floor","mp3");core.mapChangeAnimate("show",function(){core.statusBar.floor.innerHTML=core.status.maps[d].name;core.updateStatusBar();core.drawMap(d,function(){core.hide(core.dom.floorMsgGroup,10,function(){core.unLockControl();core.events.afterChangeFloor(d);if(core.isset(f)){f()}});core.setHeroLoc("direction",a.direction);core.setHeroLoc("x",a.x);core.setHeroLoc("y",a.y);core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop");core.updateFg()})})},50)};core.prototype.mapChangeAnimate=function(a,b){if(a=="show"){core.show(core.dom.floorMsgGroup,15,function(){b()})}else{core.hide(core.dom.floorMsgGroup,20,function(){b()})}};core.prototype.clearMap=function(e,c,f,d,b){if(e=="all"){for(var a in core.canvas){core.canvas[a].clearRect(0,0,416,416)}}else{core.canvas[e].clearRect(c,f,d,b)}};core.prototype.fillText=function(d,e,a,f,c,b){if(core.isset(c)){core.setFillStyle(d,c)}if(core.isset(b)){core.setFont(d,b)}core.canvas[d].fillText(e,a,f)};core.prototype.fillRect=function(e,b,f,d,a,c){if(core.isset(c)){core.setFillStyle(e,c)}core.canvas[e].fillRect(b,f,d,a)};core.prototype.strokeRect=function(f,c,g,e,b,d,a){if(core.isset(d)){core.setStrokeStyle(f,d)}if(core.isset(a)){core.setLineWidth(f,a)}core.canvas[f].strokeRect(c,g,e,b)};core.prototype.drawBlock=function(a,b,d,c,g,f,i,h,e){h=h||1;if(core.isset(e)&&e==true){core.canvas[a].clearRect(g*i,f*i,i,i)}core.canvas[a].drawImage(core.material.images[b],d*i,c*i,i,i,g*i,f*i,i*h,i*h)};core.prototype.setFont=function(b,a){core.canvas[b].font=a};core.prototype.setLineWidth=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].lineWidth=b}}core.canvas[c].lineWidth=b};core.prototype.saveCanvas=function(a){core.canvas[a].save()};core.prototype.loadCanvas=function(a){core.canvas[a].restore()};core.prototype.setOpacity=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].globalAlpha=b}}core.canvas[c].globalAlpha=b};core.prototype.setStrokeStyle=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].strokeStyle=b}}else{core.canvas[c].strokeStyle=b}};core.prototype.setAlpha=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].globalAlpha=b}}else{core.canvas[c].globalAlpha=b}};core.prototype.setOpacity=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].canvas.style.opacity=b}}else{core.canvas[c].canvas.style.opacity=b}};core.prototype.setFillStyle=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].fillStyle=b}}else{core.canvas[c].fillStyle=b}};core.prototype.drawMap=function(c,i){var j=core.status.maps[c];var g=j.blocks;core.status.floorId=c;core.status.thisMap=j;var h,f,a,d;core.clearMap("all");core.rmGlobalAnimate(null,null,true);core.enabledAllTrigger();for(h=0;h<13;h++){for(f=0;f<13;f++){a=core.material.icons.terrains.ground;d=core.material.images.terrains;core.canvas.bg.drawImage(d,0,a.loc*a.size,a.size,a.size,h*a.size,f*a.size,a.size,a.size)}}h=0;f=0;for(var e=0;e12||f>12||a<0||f<0){return true}if(core.stairExists(a,f)){return false}var d=core.status.thisMap.blocks;for(var b=0;b12||f>12||d<0||f<0){return true}var e=core.status.thisMap.blocks;var c;for(var a=0;a0){var a=core.canvas.ui.createPattern(core.material.ground,"repeat");core.drawBoxAnimate(a);core.interval.boxAnimate=setInterval(function(){core.drawBoxAnimate(a)},b)}};core.prototype.drawBoxAnimate=function(c){for(var b=0;b=999999999){f="???"}else{if(f>100000){f=(f/10000).toFixed(1)+"w"}}core.setFillStyle("fg","#000000");core.canvas.fg.fillText(f,32*a+2,32*(i+1)-2);core.canvas.fg.fillText(f,32*a,32*(i+1)-2);core.canvas.fg.fillText(f,32*a+2,32*(i+1));core.canvas.fg.fillText(f,32*a,32*(i+1));core.setFillStyle("fg",d);core.canvas.fg.fillText(f,32*a+1,32*(i+1)-1)}}};core.prototype.itemCount=function(b){if(!core.isset(b)||!core.isset(core.material.items[b])){return 0}var a=core.material.items[b].cls;return core.isset(core.status.hero.items[a][b])?core.status.hero.items[a][b]:0};core.prototype.hasItem=function(a){return core.itemCount(a)>0};core.prototype.setItem=function(c,b){var a=core.material.items[c].cls;if(a=="item"){return}if(!core.isset(core.status.hero.items[a])){core.status.hero.items[a]={}}core.status.hero.items[a][c]=b};core.prototype.useKey=function(b){if(!core.hasItem(b)){return false}var a=core.material.items[b].cls;core.status.hero.items[a][b]--;core.updateStatusBar();return true};core.prototype.useItem=function(a){core.items.useItem(a);return};core.prototype.canUseItem=function(a){return core.items.canUseItem(a)};core.prototype.addItem=function(d,c){var a=core.material.items[d];var b=a.cls;if(b=="item"){return}if(!core.isset(core.status.hero.items[b])){core.status.hero.items[b]={};core.status.hero.items[b][d]=0}else{if(!core.isset(core.status.hero.items[b][d])){core.status.hero.items[b][d]=0}}core.status.hero.items[b][d]+=c};core.prototype.getItemEffect=function(b,a){core.items.getItemEffect(b,a)};core.prototype.getItemEffectTip=function(a){return core.items.getItemEffectTip(a)};core.prototype.getItem=function(f,e,c,a,g){core.playSound("item","ogg");var b=core.material.items[f].cls;core.getItemEffect(f,e);core.removeBlock("event",c,a);var d="获得 "+core.material.items[f].name;if(e>1){d+="x"+e}if(b==="items"){d+=core.getItemEffectTip(f)}core.drawTip(d,"image",core.material.icons.items[f]);core.canvas.event.clearRect(c*32,a*32,32,32);core.updateStatusBar();if(core.isset(g)){g()}};core.prototype.drawTip=function(h,g,f){g=g||"normal";var d,c,b,i,e=false,a=0;clearInterval(core.interval.tipAnimate);core.setFont("data","16px Arial");core.saveCanvas("data");core.setOpacity("data",0);if(g=="normal"){d=16;c=18;b=d+core.canvas.data.measureText(h).width+16;i=42}else{if(g=="image"&&core.isset(f)){d=44;c=18;b=d+core.canvas.data.measureText(h).width+8;i=42}else{core.loadCanvas("data");return}}core.interval.tipAnimate=window.setInterval(function(){if(e){a-=0.1}else{a+=0.1}core.setOpacity("data",a);core.clearMap("data",5,5,400,i);core.fillRect("data",5,5,b,i,"#000");if(core.isset(f)){core.canvas.data.drawImage(core.material.images.items,0,f.loc*f.size,f.size,f.size,10,8,f.size,f.size)}core.fillText("data",h,d+5,c+15,"#fff");if(a>0.6||a<0){if(e){core.loadCanvas("data");core.clearMap("data",5,5,400,i);core.setOpacity("data",1);clearInterval(core.interval.tipAnimate);return}else{if(!core.timeout.getItemTipTimeout){core.timeout.getItemTipTimeout=window.setTimeout(function(){e=true;core.timeout.getItemTipTimeout=null},1000)}a=0.6;core.setOpacity("data",a)}}},30)};core.prototype.drawText=function(a,c){if(core.isset(a)){if(typeof a=="string"){a=[{content:a}]}else{if(a instanceof Object&&core.isset(a.content)){a=[a]}else{if(!(a instanceof Array)){core.drawTip("出错了");console.log(a);return}}}core.status.event={id:"text",data:{list:a,callback:c}};core.lockControl();core.stopAutomaticRoute();setTimeout(function(){core.drawText()},30);return}if(core.status.event.data.list.length==0){var c=core.status.event.data.callback;core.ui.closePanel(false);if(core.isset(c)){c()}return}var b=core.status.event.data.list.shift();if(typeof b=="string"){core.ui.drawTextBox(b)}else{core.ui.drawTextBox(b.content,b.id)}};core.prototype.visitNpc=function(b,a,f,e){if(!core.status.heroStop){setTimeout(function(){core.visitNpc(b,a,f,e)},30);return}if(!core.isset(core.status.npcs[b])){core.status.npcs[b]=0}var d=core.status.npcs[b];var c=core.npcs.getEffect(b,d);if(c.length==0){return}core.status.event.data={x:a,y:f,id:b,list:c,callback:e};core.status.event.id="npc";core.lockControl();core.npcAction()};core.prototype.npcAction=function(){if(core.status.event.data.list.length==0){if(core.isset(core.status.event.data.callback)){core.status.event.data.callback()}core.ui.closePanel(false);return}var g=core.status.event.data.list.shift();core.status.event.data.current=g;var c=core.status.event.data.id,l=core.status.event.data.x,j=core.status.event.data.y;if(g.action=="text"){core.ui.drawTextBox(g.content,core.isset(g.isHero)&&g.isHero?"hero":g.id);return}if(g.action=="choices"){var h=core.material.npcs[g.id];var b=core.canvas.ui.createPattern(core.material.ground,"repeat");clearInterval(core.interval.tipAnimate);core.clearMap("data",0,0,416,416);core.setOpacity("data",1);core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);core.setFillStyle("ui",b);var e=97,k=64,m=416-2*e,a=416-2*k;core.fillRect("ui",e,k,m,a,b);core.strokeRect("ui",e-1,k-1,m+1,a+1,"#FFFFFF",2);core.canvas.ui.textAlign="center";core.fillText("ui",h.name,e+135,k+34,"#FFFFFF","bold 19px Verdana");core.strokeRect("ui",e+15-1,k+30-1,34,34,"#DDDDDD",2);core.status.boxAnimateObjs=[];core.status.boxAnimateObjs.push({bgx:e+15,bgy:k+30,bgsize:32,image:core.material.images.npcs,x:e+15,y:k+30,icon:core.material.icons.npcs[h.icon]});core.setBoxAnimate(core.firstData.animateSpeed);core.canvas.ui.textAlign="left";var d=g.hint.split("\n");for(var f=0;fcore.status.hero.time.totaltime){core.status.hero.time.totaltime=d}if(core.isset(a)){core.status.hero.time.lasttime=a}else{core.status.hero.time.lasttime=new Date()}core.events.afterLoadData(b);core.changeFloor(b.floorId,null,b.hero.loc,function(){core.setHeroMoveTriggerInterval();if(core.isset(e)){e()}});core.upload(1500)};core.prototype.setStatus=function(a,b){if(core.isset(core.status.hero[a])){core.status.hero[a]=b}};core.prototype.getStatus=function(a){if(core.isset(core.status.hero[a])){return core.status.hero[a]}};core.prototype.lockControl=function(){core.status.lockControl=true};core.prototype.unLockControl=function(){core.status.lockControl=false};core.prototype.isset=function(a){if(a==undefined||a==null){return false}return true};core.prototype.playSound=function(b,a){if(!core.musicStatus.soundStatus||!core.musicStatus.loaded){return}core.musicStatus.playedSound=core.material.sounds[a][b];core.musicStatus.playedSound.play()};core.prototype.playBgm=function(a,b){if(core.musicStatus.isIOS||!core.musicStatus.loaded){return}if(core.isset(core.musicStatus.playedBgm)){core.musicStatus.playedBgm.pause()}core.musicStatus.playedBgm=core.material.sounds[b][a];if(core.musicStatus.soundStatus){core.musicStatus.playedBgm.play()}};core.prototype.changeSoundStatus=function(){if(core.musicStatus.soundStatus){main.core.disabledSound()}else{main.core.enabledSound()}};core.prototype.enabledSound=function(){core.musicStatus.soundStatus=true;core.playBgm("bgm","mp3");core.setLocalStorage("soundStatus",true)};core.prototype.disabledSound=function(){core.musicStatus.playedBgm.pause();core.musicStatus.soundStatus=false;core.setLocalStorage("soundStatus",false)};core.prototype.show=function(d,b,e){if(!core.isset(b)){d.style.display="block";return}d.style.display="block";d.style.opacity=0;var c=0;var a=window.setInterval(function(){c+=0.03;d.style.opacity=c;if(c>1){clearInterval(a);if(core.isset(e)){e()}}},b)};core.prototype.hide=function(d,b,e){if(!core.isset(b)){d.style.display="none";return}var c=1;var a=window.setInterval(function(){c-=0.03;d.style.opacity=c;if(c<0){d.style.display="none";clearInterval(a);if(core.isset(e)){e()}}},b)};core.prototype.clearStatusBar=function(){var a=["floor","hp","atk","def","money","experience","yellowKey","blueKey","redKey","hard"];a.forEach(function(b){core.statusBar[b].innerHTML=""});core.statusBar.image.book.style.opacity=0.3;core.statusBar.image.fly.style.opacity=0.3};core.prototype.updateStatusBar=function(){if(core.flags.HPMAX>0){core.setStatus("hp",Math.min(core.flags.HPMAX,core.getStatus("hp")))}var b=["hp","atk","def","money","experience"];b.forEach(function(c){core.statusBar[c].innerHTML=core.getStatus(c)});var a=["yellowKey","blueKey","redKey"];a.forEach(function(c){core.statusBar[c].innerHTML=core.setTwoDigits(core.status.hero.items.keys[c])});core.statusBar.hard.innerHTML="Lv"+core.status.hard;if(core.hasItem("book")){core.statusBar.image.book.style.opacity=1}else{core.statusBar.image.book.style.opacity=0.3}if(core.hasItem("fly")){core.statusBar.image.fly.style.opacity=1}else{core.statusBar.image.fly.style.opacity=0.3}core.updateFg()};core.prototype.resize=function(t,j){var v=416;var k=83;var x=49;var A=129;var m=v+6;var s=t;var n=false;if(t>j&&j<422){n=true;s=j}if(s=10 && x<=12 && y==12) { + core.ui.closePanel(true); + } + return; +} + +// 飞行器 +events.prototype.clickFly = function(x,y) { + if ((x==10 || x==11) && y==9) core.ui.drawFly(core.status.event.data-1); + if ((x==10 || x==11) && y==5) core.ui.drawFly(core.status.event.data+1); + if (x>=5 && x<=7 && y==12) core.ui.closePanel(); + if (x>=0 && x<=9 && y>=3 && y<=11) { + var index=core.status.hero.flyRange.indexOf(core.status.floorId); + var stair=core.status.event.data= 5 && x <= 7) { + if (y >= 5 && y <= 8) { + if (y >= 5 + core.status.event.data.choices.length) return; + + var money = core.getStatus('money'), experience = core.getStatus('experience'); + + var shop = core.status.event.data; + var times = shop.times, need = eval(shop.need); + var use = shop.use; + var use_text = use=='money'?"金币":"经验"; + + var choice = shop.choices[y-5]; + if (core.isset(choice.need)) + need = eval(choice.need); + + if (need > eval(use)) { + core.drawTip("你的"+use_text+"不足"); + return; + } + + eval(use+'-='+need); + core.setStatus('money', money); + core.setStatus('experience', experience); + core.updateStatusBar(); + + core.npcEffect(choice.effect); + + core.status.event.data.times++; + core.ui.openShop(core.status.event.data.id); + return; + } + + // 退出商店 + if (y == 9) { + core.status.event.data = null; + core.ui.closePanel(); + return; + } + } +} + +events.prototype.clickSelectShop = function(x,y) { + if (x >= 5 && x <= 7) { + var shopList = core.status.shops, keys = Object.keys(shopList); + var topIndex = 6 - parseInt((keys.length + 1) / 2); + var exitIndex = 6 + parseInt((keys.length + 1) / 2); + + if (y >= topIndex && y - topIndex < keys.length) { + var reason = core.events.canUseQuickShop(y-topIndex); + if (core.isset(reason)) { + core.drawText(reason); + return; + } + var shop=shopList[keys[y - topIndex]]; + if (!shop.visited) { + if (shop.times==0) core.drawTip('该商店尚未开启'); + else core.drawTip('该商店已失效'); + return; + } + core.ui.drawShop(keys[y - topIndex]); + } + if (y == exitIndex) { + core.ui.closePanel(); + } + } +} + +// 工具栏 +events.prototype.clickToolbox = function(x,y) { + + // 返回 + if (x>=10 && x<=12 && y==12) { + core.ui.closePanel(false); + return; + } + + var itemId = null; + var items = null; + + if (y>=4 && y<=7 && x!=12) + items = Object.keys(core.status.hero.items.tools).sort(); + + if (y>=9 && y<=12 && x!=12) + items = Object.keys(core.status.hero.items.constants).sort(); + + if (items==null) return; + var index=0; + if (y==4||y==5||y==9||y==10) index=parseInt(x/2); + else index=6+parseInt(x/2); + + if (index>=items.length) return; + itemId=items[index]; + + if (itemId==core.status.event.data) { + core.events.useItem(itemId); + } + else { + core.ui.drawToolbox(itemId); + } +} + +// 存读档 +events.prototype.clickSL = function(x,y) { + // 上一页 + if ((x == 3 || x == 4) && y == 12) { + core.ui.drawSLPanel(core.status.event.data - 1); + } + // 下一页 + if ((x == 8 || x == 9) && y == 12) { + core.ui.drawSLPanel(core.status.event.data + 1); + } + // 返回 + if (x>=10 && x<=12 && y==12) { + core.ui.closePanel(false); + if (!core.isPlaying()) { + core.showStartAnimate(); + } + return; + } + + var index=6*core.status.event.data+1; + if (y>=1 && y<=4) { + if (x>=1 && x<=3) core.doSL(index, core.status.event.id); + if (x>=5 && x<=7) core.doSL(index+1, core.status.event.id); + if (x>=9 && x<=11) core.doSL(index+2, core.status.event.id); + } + if (y>=7 && y<=10) { + if (x>=1 && x<=3) core.doSL(index+3, core.status.event.id); + if (x>=5 && x<=7) core.doSL(index+4, core.status.event.id); + if (x>=9 && x<=11) core.doSL(index+5, core.status.event.id); + } +} + +// 菜单栏 +events.prototype.clickSettings = function (x,y) { + if (x<5 || x>7) return; + if (y == 3) { + if (core.musicStatus.isIOS) { + core.drawTip("iOS设备不支持播放音乐"); + return; + } + core.changeSoundStatus(); + core.ui.drawSettings(false); + } + if (y == 4) core.ui.drawSelectShop(); + if (y == 5) this.decreaseHard(); + if (y == 6) { + core.ui.drawSyncSave(); + } + if (y == 7) { + core.ui.drawConfirmBox("你确定要重新开始吗?", function () { + core.ui.closePanel(); + core.restart(); + }, function () { + core.ui.drawSettings(false); + }); + } + if (y==8) { + core.ui.drawAbout(); + // core.debug(); + } + if (y == 9) core.ui.closePanel(); + return; +} + +events.prototype.clickNPC = function(x,y) { + + var data = core.status.event.data.current; + if (core.isset(data)) { + + // 对话,任意位置继续 + if (data.action == 'text') { + core.npcAction(); + return; + } + if (data.action == 'choices') { + if (x >= 5 && x <= 7) { + if (y >= 5 && y <= 8) { + if (y >= 5 + data.choices.length) return; + + var choice = data.choices[y - 5]; + if (core.isset(choice.need)) { + var able = true; + choice.need.split(';').forEach(function (e) { + var ones = e.split(','); + var type = ones[0], key = ones[1], value = ones[2]; + if (type == 'status') { + if (core.getStatus(key)=10&&a<=12&&b==12){core.ui.closePanel(true)}return};events.prototype.clickFly=function(a,e){if((a==10||a==11)&&e==9){core.ui.drawFly(core.status.event.data-1)}if((a==10||a==11)&&e==5){core.ui.drawFly(core.status.event.data+1)}if(a>=5&&a<=7&&e==12){core.ui.closePanel()}if(a>=0&&a<=9&&e>=3&&e<=11){var b=core.status.hero.flyRange.indexOf(core.status.floorId);var d=core.status.event.data=5&&x<=7){if(y>=5&&y<=8){if(y>=5+core.status.event.data.choices.length){return}var money=core.getStatus("money"),experience=core.getStatus("experience");var shop=core.status.event.data;var times=shop.times,need=eval(shop.need);var use=shop.use;var use_text=use=="money"?"金币":"经验";var choice=shop.choices[y-5];if(core.isset(choice.need)){need=eval(choice.need)}if(need>eval(use)){core.drawTip("你的"+use_text+"不足");return}eval(use+"-="+need);core.setStatus("money",money);core.setStatus("experience",experience);core.updateStatusBar();core.npcEffect(choice.effect);core.status.event.data.times++;core.ui.openShop(core.status.event.data.id);return}if(y==9){core.status.event.data=null;core.ui.closePanel();return}}};events.prototype.clickSelectShop=function(a,h){if(a>=5&&a<=7){var c=core.status.shops,e=Object.keys(c);var d=6-parseInt((e.length+1)/2);var b=6+parseInt((e.length+1)/2);if(h>=d&&h-d=10&&a<=12&&e==12){core.ui.closePanel(false);return}var d=null;var b=null;if(e>=4&&e<=7&&a!=12){b=Object.keys(core.status.hero.items.tools).sort()}if(e>=9&&e<=12&&a!=12){b=Object.keys(core.status.hero.items.constants).sort()}if(b==null){return}var c=0;if(e==4||e==5||e==9||e==10){c=parseInt(a/2)}else{c=6+parseInt(a/2)}if(c>=b.length){return}d=b[c];if(d==core.status.event.data){core.events.useItem(d)}else{core.ui.drawToolbox(d)}};events.prototype.clickSL=function(a,c){if((a==3||a==4)&&c==12){core.ui.drawSLPanel(core.status.event.data-1)}if((a==8||a==9)&&c==12){core.ui.drawSLPanel(core.status.event.data+1)}if(a>=10&&a<=12&&c==12){core.ui.closePanel(false);if(!core.isPlaying()){core.showStartAnimate()}return}var b=6*core.status.event.data+1;if(c>=1&&c<=4){if(a>=1&&a<=3){core.doSL(b,core.status.event.id)}if(a>=5&&a<=7){core.doSL(b+1,core.status.event.id)}if(a>=9&&a<=11){core.doSL(b+2,core.status.event.id)}}if(c>=7&&c<=10){if(a>=1&&a<=3){core.doSL(b+3,core.status.event.id)}if(a>=5&&a<=7){core.doSL(b+4,core.status.event.id)}if(a>=9&&a<=11){core.doSL(b+5,core.status.event.id)}}};events.prototype.clickSettings=function(a,b){if(a<5||a>7){return}if(b==3){if(core.musicStatus.isIOS){core.drawTip("iOS设备不支持播放音乐");return}core.changeSoundStatus();core.ui.openSettings(false)}if(b==4){core.ui.drawSelectShop()}if(b==5){this.decreaseHard()}if(b==6){core.ui.syncSave()}if(b==7){core.ui.showConfirmBox("你确定要重新开始吗?",function(){core.ui.closePanel();core.restart()},function(){core.ui.openSettings(false)})}if(b==8){core.ui.drawAbout()}if(b==9){core.ui.closePanel()}return};events.prototype.clickNPC=function(a,e){var d=core.status.event.data.current;if(core.isset(d)){if(d.action=="text"){core.npcAction();return}if(d.action=="choices"){if(a>=5&&a<=7){if(e>=5&&e<=8){if(e>=5+d.choices.length){return}var b=d.choices[e-5];if(core.isset(b.need)){var c=true;b.need.split(";").forEach(function(j){var h=j.split(",");var g=h[0],f=h[1],i=h[2];if(g=="status"){if(core.getStatus(f)=0; + if (itemId == 'pickaxe') { + // 破墙镐 + var ids = []; + for (var i in core.status.thisMap.blocks) { + var block = core.status.thisMap.blocks[i]; + if (core.isset(block.event) && block.event.id == 'yellowWall') { + + // 四个方向 + if (core.flags.pickaxeFourDirections) { + if (Math.abs(block.x-core.status.hero.loc.x)+Math.abs(block.y-core.status.hero.loc.y)<=1) { + ids.push(i); + } + } + else { + // 获得勇士的下一个位置 + var scan = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0} + }; + if (block.x == core.status.hero.loc.x+scan[core.status.hero.loc.direction].x && block.y == core.status.hero.loc.y+scan[core.status.hero.loc.direction].y) { + ids.push(i); + } + } + } + } + if (ids.length>0) { + core.status.event.data = ids; + return true; + } + return false; + } + if (itemId == 'bomb') { + // 炸弹 + var ids = []; + for (var i in core.status.thisMap.blocks) { + var block = core.status.thisMap.blocks[i]; + if (core.isset(block.event) && block.event.cls == 'enemys' && Math.abs(block.x-core.status.hero.loc.x)+Math.abs(block.y-core.status.hero.loc.y)<=1) { + var enemy = core.material.enemys[block.event.id]; + if (core.isset(enemy.bomb) && !enemy.bomb) continue; + ids.push(i); + } + } + if (ids.length>0) { + core.status.event.data = ids; + return true; + } + return false; + } + if (itemId == 'earthquake') { + var ids = [] + for (var i in core.status.thisMap.blocks) { + var block = core.status.thisMap.blocks[i]; + if (core.isset(block.event) && (block.event.id == 'yellowWall' || block.event.id == 'blueWall' || block.event.id == 'whiteWall')) + ids.push(i); + } + if (ids.length>0) { + core.status.event.data = ids; + return true; + } + return false; + } + if (itemId == 'centerFly') { + // 中心对称 + var toX = 12 - core.getHeroLoc('x'), toY = 12-core.getHeroLoc('y'); + var blocks = core.status.thisMap.blocks; + for (var s = 0; s < blocks.length; s++) { + if (blocks[s].x == toX && blocks[s].y == toY) { + return false; + } + } + core.status.event.data = {'x': toX, 'y': toY}; + return true; + } + if (itemId == 'upFly') { + // 上楼器 + if (core.status.floorId == 'MT20' || core.status.floorId == 'MT21') // 禁用条件 + return false; + var toId = null, found = false; // 上楼后的楼层ID + for (var id in core.status.maps) { + if (found) {toId = id; break;} + if (id == core.status.floorId) found=true; + } + if (!found) return false; + // 检查是否存在block(不是空地) + var toX = core.getHeroLoc('x'), toY = core.getHeroLoc('y'); + var blocks = core.status.maps[toId].blocks; + for (var s = 0; s < blocks.length; s++) { + if (blocks[s].x == toX && blocks[s].y == toY) { + return false; + } + } + // 可以上楼,记录下位置信息,返回true + core.status.event.data = {'id': toId, 'x': toX, 'y': toY}; + return true; + } + if (itemId == 'downFly') { + // 下楼器 + if (core.status.floorId == 'MT0' || core.status.floorId == 'MT21') + return false; + var toId = null; + for (var id in core.status.maps) { + if (id == core.status.floorId) break; + toId = id; + } + if (toId == null) return false; + var toX = core.getHeroLoc('x'), toY = core.getHeroLoc('y'); + var blocks = core.status.maps[toId].blocks; + for (var s = 0; s < blocks.length; s++) { + if (blocks[s].x == toX && blocks[s].y == toY) { + return false; + } + } + core.status.event.data = {'id': toId, 'x': toX, 'y': toY}; + return true; + } + return false; +} + +items.prototype.getItemEffect = function(itemId, itemNum) { + var itemCls = core.material.items[itemId].cls; + // 消耗品 + if (itemCls === 'items') { + if (itemId === 'redJewel') core.status.hero.atk += 3; + if (itemId === 'blueJewel') core.status.hero.def += 3; + if (itemId === 'greenJewel') core.status.hero.mdef += 3; + // if (itemId == 'yellowJewel') core.status.hero.atk+=0; + if (itemId === 'redPotion') core.status.hero.hp += 200; + if (itemId === 'bluePotion') core.status.hero.hp += 500; + if (itemId === 'yellowPotion') core.status.hero.hp += 500; + if (itemId === 'greenPotion') core.status.hero.hp += 800; + if (itemId === 'sword1') core.status.hero.atk += 10; + if (itemId === 'sword2') core.status.hero.atk += 100; + if (itemId === 'sword5') core.status.hero.atk += 1000; + if (itemId === 'shield1') core.status.hero.def += 10; + if (itemId === 'shield2') core.status.hero.def += 100; + if (itemId === 'shield5') { + core.status.hero.def += 1000; + core.status.hero.flags.hasShield5 = true; + } + if (itemId === 'bigKey') { + core.status.hero.items.keys.yellowKey++; + core.status.hero.items.keys.blueKey++; + core.status.hero.items.keys.redKey++; + } + if (itemId == 'superPotion') core.status.hero.hp *= 2; + } + else { + core.addItem(itemId, itemNum); + } +} + +items.prototype.getItemEffectTip = function(itemId) { + if (itemId === 'redJewel') return ",攻击+3"; + if (itemId === 'blueJewel') return ",防御+3"; + if (itemId === 'greenJewel') return ",魔防+3"; + // if (itemId == 'yellowJewel') ; + if (itemId === 'redPotion') return ",生命+200"; + if (itemId === 'bluePotion') return ",生命+500"; + if (itemId === 'yellowPotion') return ",生命+500"; + if (itemId === 'greenPotion') return ",生命+800"; + if (itemId === 'sword1') return ",攻击+10"; + if (itemId === 'sword2') return ",攻击+100"; + if (itemId === 'sword5') return ",攻击+1000"; + if (itemId === 'shield1') return ",防御+10"; + if (itemId === 'shield2') return ",防御+100"; + if (itemId === 'shield5') return ",防御+1000"; + if (itemId === 'bigKey') return ",全钥匙+1"; + if (itemId === 'superPotion') return ",生命值翻倍"; + return ""; +} diff --git a/libs/items.min.js b/libs/items.min.js new file mode 100644 index 00000000..b90ddebb --- /dev/null +++ b/libs/items.min.js @@ -0,0 +1 @@ +function items(){}items.prototype.init=function(){this.items={yellowKey:{cls:"keys",name:"黄钥匙"},blueKey:{cls:"keys",name:"蓝钥匙"},redKey:{cls:"keys",name:"红钥匙"},redJewel:{cls:"items",name:"红宝石"},blueJewel:{cls:"items",name:"蓝宝石"},greenJewel:{cls:"items",name:"绿宝石"},yellowJewel:{cls:"items",name:"黄宝石"},redPotion:{cls:"items",name:"红血瓶"},bluePotion:{cls:"items",name:"蓝血瓶"},yellowPotion:{cls:"items",name:"黄血瓶"},greenPotion:{cls:"items",name:"绿血瓶"},sword1:{cls:"items",name:"铁剑"},sword2:{cls:"items",name:"银剑"},sword3:{cls:"items",name:"骑士剑"},sword4:{cls:"items",name:"圣剑"},sword5:{cls:"items",name:"神圣剑"},shield1:{cls:"items",name:"铁盾"},shield2:{cls:"items",name:"银盾"},shield3:{cls:"items",name:"骑士盾"},shield4:{cls:"items",name:"圣盾"},shield5:{cls:"items",name:"神圣盾"},superPotion:{cls:"items",name:"圣水"},bigKey:{cls:"items",name:"钥匙盒"},greenKey:{cls:"tools",name:"绿钥匙",text:"可以打开一扇绿门"},steelKey:{cls:"tools",name:"铁门钥匙",text:"可以打开一扇铁门"},book:{cls:"constants",name:"怪物手册",text:"可以查看当前楼层各怪物属性。"},fly:{cls:"constants",name:"楼层传送器",text:"可以自由往来去过的楼层。"},coin:{cls:"constants",name:"幸运金币",text:"持有时打败怪物可得双倍金币"},snow:{cls:"constants",name:"冰冻徽章",text:"可以将面前的一块熔岩变成平地"},cross:{cls:"constants",name:"十字架",text:"持有后无视怪物的无敌属性"},pickaxe:{cls:"tools",name:"破墙镐",text:"可以破坏勇士四周的墙。"},icePickaxe:{cls:"tools",name:"破冰稿",text:"可以破坏勇士面前的一堵冰墙。"},bomb:{cls:"tools",name:"炸弹",text:"可以炸掉勇士四周的怪物。"},centerFly:{cls:"tools",name:"中心对称飞行器",text:"可以飞向当前楼层中心对称的位置。"},upFly:{cls:"tools",name:"上楼器",text:"可以飞往楼上的相同位置。"},downFly:{cls:"tools",name:"下楼器",text:"可以飞往楼下的相同位置。"},earthquake:{cls:"tools",name:"地震卷轴",text:"可以破坏当前层的所有墙"}}};items.prototype.getItems=function(a){if(a==undefined){return this.items}return this.items[itemsName]};main.instance.items=new items();items.prototype.useItem=function(b){if(!this.canUseItem(b)){return}var a=core.material.items[b].cls;if(a=="constants"){if(b=="book"){core.ui.drawEnemyBook(1)}if(b=="fly"){core.ui.drawFly(core.status.hero.flyRange.indexOf(core.status.floorId))}}if(a=="tools"){core.status.hero.items[a][b]--;if(b=="earthquake"||b=="bomb"||b=="pickaxe"){core.removeBlockByIds(core.status.floorId,core.status.event.data);core.drawMap(core.status.floorId,function(){core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop");core.updateFg();core.drawTip(core.material.items[b].name+"使用成功");if(b=="bomb"&&core.flags.bombTrigger){core.events.afterBattle()}})}if(b=="centerFly"){core.clearMap("hero",0,0,416,416);core.setHeroLoc("x",core.status.event.data.x);core.setHeroLoc("y",core.status.event.data.y);core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop");core.drawTip(core.material.items[b].name+"使用成功")}if(b=="upFly"||b=="downFly"){core.changeFloor(core.status.event.data.id,null,{direction:core.status.hero.loc.direction,x:core.status.event.data.x,y:core.status.event.data.y},function(){core.drawTip(core.material.items[b].name+"使用成功")})}if(core.status.hero.items[a][b]==0){delete core.status.hero.items[a][b]}}};items.prototype.canUseItem=function(k){if(!core.hasItem(k)){return false}var e=core.material.items[k].cls;if(k=="book"){return true}if(k=="fly"){return core.status.hero.flyRange.indexOf(core.status.floorId)>=0}if(k=="pickaxe"){var b=[];for(var h in core.status.thisMap.blocks){var g=core.status.thisMap.blocks[h];if(core.isset(g.event)&&g.event.id=="yellowWall"){if(core.flags.picaxeFourDirections){if(Math.abs(g.x-core.status.hero.loc.x)+Math.abs(g.y-core.status.hero.loc.y)<=1){b.push(h)}}else{var o={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};if(g.x==core.status.hero.loc.x+o[core.status.hero.loc.direction].x&&g.y==core.status.hero.loc.y+o[core.status.hero.loc.direction].y){b.push(h)}}}}if(b.length>0){core.status.event.data=b;return true}return false}if(k=="bomb"){var b=[];for(var h in core.status.thisMap.blocks){var g=core.status.thisMap.blocks[h];if(core.isset(g.event)&&g.event.cls=="enemys"&&Math.abs(g.x-core.status.hero.loc.x)+Math.abs(g.y-core.status.hero.loc.y)<=1){var f=core.material.enemys[g.event.id];if(core.isset(f.bomb)&&!f.bomb){continue}b.push(h)}}if(b.length>0){core.status.event.data=b;return true}return false}if(k=="earthquake"){var b=[];for(var h in core.status.thisMap.blocks){var g=core.status.thisMap.blocks[h];if(core.isset(g.event)&&(g.event.id=="yellowWall"||g.event.id=="blueWall"||g.event.id=="whiteWall")){b.push(h)}}if(b.length>0){core.status.event.data=b;return true}return false}if(k=="centerFly"){var l=12-core.getHeroLoc("x"),j=12-core.getHeroLoc("y");var a=core.status.thisMap.blocks;for(var n=0;n', 270, top+height-13, '#CCCCCC', '13px Verdana'); +} + +/** + * 绘制确认/取消警告 + * @param text + * @param yesCallback + * @param noCallback + */ +ui.prototype.drawConfirmBox = function (text, yesCallback, noCallback) { + core.status.event.id = 'confirmBox'; + core.status.event.data = {'yes': yesCallback, 'no': noCallback}; + + var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); + core.clearMap('ui', 0, 0, 416, 416); + core.setAlpha('ui', 1); + core.setFillStyle('ui', background); + core.setFont('ui', "bold 19px Verdana"); + + var contents = text.split('\n'); + var lines = contents.length; + var max_length = 0; + for (var i in contents) { + max_length = Math.max(max_length, core.canvas.ui.measureText(contents[i]).width); + } + + var left = Math.min(208 - 40 - max_length / 2, 100); + var top = 140 - (lines-1)*30; + var right = 416 - 2 * left, bottom = 416 - 140 - top; + + core.fillRect('ui', left, top, right, bottom, background); + core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); + core.canvas.ui.textAlign = "center"; + for (var i in contents) { + core.fillText('ui', contents[i], 208, top + 50 + i*30, "#FFFFFF"); + } + + core.fillText('ui', "确定", 208 - 38, top + bottom - 35, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "取消", 208 + 38, top + bottom - 35); +} + +/** + * 绘制菜单栏 + * @param need + */ +ui.prototype.drawSettings = function (need) { + if (!core.checkStatus('settings', need)) + return; + + var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); + core.clearMap('ui', 0, 0, 416, 416); + core.setAlpha('ui', 1); + core.setFillStyle('ui', background); + var left = 97, top = 64, right = 416 - 2 * left, bottom = 416 - 2 * top; + core.fillRect('ui', left, top, right, bottom, background); + core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); + + core.canvas.ui.textAlign = "center"; + core.fillText('ui', "音乐: " + (core.musicStatus.soundStatus ? "[ON]" : "[OFF]"), 208, top + 56, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "快捷商店", 208, top + 88, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "降低难度", 208, top + 120, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "同步存档", 208, top + 152, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "重新开始", 208, top + 184, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "关于本塔", 208, top + 216, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "返回游戏", 208, top + 248, "#FFFFFF", "bold 17px Verdana"); + +} + +/** + * 绘制“选择商店”窗口 + * @param need + */ +ui.prototype.drawSelectShop = function (need) { + + if (core.isset(need) && !core.checkStatus('selectShop', need)) + return; + + core.status.event.id = 'selectShop'; + var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); + core.clearMap('ui', 0, 0, 416, 416); + core.setAlpha('ui', 1); + core.setFillStyle('ui', background); + + var shopList = core.status.shops, keys = Object.keys(shopList); + var len = keys.length + 1; + if (len % 2 == 0) len++; + + var left = 97, top = 208 - 32 - 16 * len, right = 416 - 2 * left, bottom = 416 - 2 * top; + core.fillRect('ui', left, top, right, bottom, background); + core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); + + core.canvas.ui.textAlign = "center"; + for (var i = 0; i < keys.length; i++) { + core.fillText('ui', shopList[keys[i]].name, 208, top + 56 + 32 * i, "#FFFFFF", "bold 17px Verdana"); + } + + core.fillText('ui', "返回游戏", 208, top + bottom - 40); + +} + +/** + * 绘制商店 + * @param id + */ +ui.prototype.drawShop = function (id) { + var shop = core.status.shops[id]; + // 正在移动中... + + if (!core.status.heroStop) { + setTimeout(function () { + core.ui.drawShop(id); + }, 30); + return; + } + + core.status.event.data = shop; + core.status.event.id = 'shop'; + core.lockControl(); + shop.visited = true; + + var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); + + var times = shop.times, need = eval(shop.need); + + clearInterval(core.interval.tipAnimate); + core.clearMap('data', 0, 0, 416, 416); + core.setOpacity('data', 1); + + core.clearMap('ui', 0, 0, 416, 416); + core.setAlpha('ui', 1); + core.setFillStyle('ui', background); + + var left = 97, top = 64, right = 416 - 2 * left, bottom = 416 - 2 * top; + core.fillRect('ui', left, top, right, bottom, background); + core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); + + // 名称 + core.canvas.ui.textAlign = "center"; + core.fillText('ui', shop.title, left + 135, top + 34, '#FFFFFF', 'bold 19px Verdana'); + + // 动画 + core.strokeRect('ui', left + 15 - 1, top + 30 - 1, 34, 34, '#DDDDDD', 2); + core.status.boxAnimateObjs = []; + core.status.boxAnimateObjs.push({ + 'bgx': left + 15, 'bgy': top + 30, 'bgsize': 32, + 'image': core.material.images.npcs, + 'x': left + 15, 'y': top + 30, 'icon': core.material.icons.npcs[shop.icon] + }); + core.setBoxAnimate(core.firstData.animateSpeed); + + // 对话 + core.canvas.ui.textAlign = "left"; + if (need<0) need="若干"; + var use = shop.use=='experience'?"经验":"金币"; + core.fillText('ui', "勇敢的武士啊,给我" + need, left + 60, top + 65, '#FFFFFF', 'bold 14px Verdana'); + core.fillText('ui', use + "你就可以:", left + 60, top + 83); + + // 选项 + core.canvas.ui.textAlign = "center"; + for (var i = 0; i < shop.choices.length; i++) { + var choice = shop.choices[i]; + var text = choice.text; + if (core.isset(choice.need)) + text += "("+eval(choice.need)+use+")" + core.fillText('ui', text, 208, top + 120 + 32 * i, "#FFFFFF", "bold 17px Verdana"); + } + core.fillText('ui', "退出商店", 208, top + 248); + +} + + +/** + * 绘制“请等候...” + * @param text + */ +ui.prototype.drawWaiting = function(text) { + + core.lockControl(); + core.status.event.id = 'waiting'; + + var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); + core.clearMap('ui', 0, 0, 416, 416); + core.setAlpha('ui', 1); + core.setFillStyle('ui', background); + + var left = 97, top = 208 - 32 - 16, right = 416 - 2 * left, bottom = 416 - 2 * top; + core.fillRect('ui', left, top, right, bottom, background); + core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); + + core.canvas.ui.textAlign = "center"; + core.fillText('ui', text, 208, top + 56, "#FFFFFF", "bold 17px Verdana"); + +} + +/** + * 绘制“存档同步”选项 + */ +ui.prototype.drawSyncSave = function () { + + core.status.event.id = 'syncSave'; + var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); + core.clearMap('ui', 0, 0, 416, 416); + core.setAlpha('ui', 1); + core.setFillStyle('ui', background); + + var left = 97, top = 208 - 32 - 16 * 3, right = 416 - 2 * left, bottom = 416 - 2 * top; + core.fillRect('ui', left, top, right, bottom, background); + core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); + + core.canvas.ui.textAlign = "center"; + core.fillText('ui', "同步存档到服务器", 208, top + 56, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "从服务器加载存档", 208, top + 56 + 32, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "返回游戏", 208, top + bottom - 40); +} + +/** + * 绘制“分页” + * @param page + * @param totalPage + */ +ui.prototype.drawPagination = function (page, totalPage) { + + core.setFont('ui', 'bold 15px Verdana'); + core.setFillStyle('ui', '#DDDDDD'); + + var length = core.canvas.ui.measureText(page + " / " + page).width; + + core.canvas.ui.textAlign = 'left'; + core.fillText('ui', page + " / " + totalPage, (416 - length) / 2, 403); + + core.canvas.ui.textAlign = 'center'; + if (page > 1) + core.fillText('ui', '上一页', 208 - 80, 403); + if (page < totalPage) + core.fillText('ui', '下一页', 208 + 80, 403); + + // 退出 + core.fillText('ui', '返回游戏', 370, 403); + +} + +/** + * 绘制怪物手册 + * @param page 页数 + */ +ui.prototype.drawEnemyBook = function (page) { + + var enemys = core.enemys.getCurrentEnemys(); + var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); + + clearInterval(core.interval.tipAnimate); + core.clearMap('data', 0, 0, 416, 416); + core.setOpacity('data', 1); + + core.clearMap('ui', 0, 0, 416, 416); + core.setAlpha('ui', 1); + core.setFillStyle('ui', background); + core.fillRect('ui', 0, 0, 416, 416); + + core.setAlpha('ui', 0.6); + core.setFillStyle('ui', '#000000'); + core.fillRect('ui', 0, 0, 416, 416); + + core.setAlpha('ui', 1); + core.canvas.ui.textAlign = 'left'; + core.setFont('ui', 'bold 15px Verdana'); + + if (enemys.length == 0) { + core.fillText('ui', "本层无怪物", 83, 222, '#999999', "bold 50px Verdana"); + // 退出 + core.canvas.ui.textAlign = 'center'; + core.fillText('ui', '返回游戏', 370, 403,'#DDDDDD', 'bold 15px Verdana'); + return; + } + + var perpage = 6; + var totalPage = parseInt((enemys.length - 1) / perpage) + 1; + if (page < 1) page = 1; + if (page > totalPage) page = totalPage; + core.status.event.data = page; + var start = (page - 1) * perpage, end = Math.min(page * perpage, enemys.length); + + enemys = enemys.slice(start, end); + core.status.boxAnimateObjs = []; + for (var i = 0; i < enemys.length; i++) { + // 边框 + var enemy = enemys[i]; + core.strokeRect('ui', 22, 62 * i + 22, 42, 42, '#DDDDDD', 2); + + // 怪物 + core.status.boxAnimateObjs.push({ + 'bgx': 22, 'bgy': 62 * i + 22, 'bgsize': 42, + 'image': core.material.images.enemys, + 'x': 27, 'y': 62 * i + 27, 'icon': core.material.icons.enemys[enemy.id] + }); + + // 数据 + core.canvas.ui.textAlign = "center"; + core.fillText('ui', enemy.name, 115, 62 * i + 47, '#DDDDDD', 'bold 17px Verdana'); + core.canvas.ui.textAlign = "left"; + core.fillText('ui', '生命', 165, 62 * i + 32, '#DDDDDD', '13px Verdana'); + core.fillText('ui', enemy.hp, 195, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana'); + core.fillText('ui', '攻击', 255, 62 * i + 32, '#DDDDDD', '13px Verdana'); + core.fillText('ui', enemy.atk, 285, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana'); + core.fillText('ui', '防御', 335, 62 * i + 32, '#DDDDDD', '13px Verdana'); + core.fillText('ui', enemy.def, 365, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana'); + core.fillText('ui', '金币', 165, 62 * i + 50, '#DDDDDD', '13px Verdana'); + core.fillText('ui', enemy.money, 195, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana'); + + var damage_offset = 326; + if (core.flags.enableExperience) { + core.canvas.ui.textAlign = "left"; + core.fillText('ui', '经验', 255, 62 * i + 50, '#DDDDDD', '13px Verdana'); + core.fillText('ui', enemy.experience, 285, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana'); + damage_offset = 361; + } + + core.canvas.ui.textAlign = "center"; + var damage = enemy.damage; + var color = '#FFFF00'; + if (damage >= core.status.hero.hp) color = '#FF0000'; + if (damage == 0) color = '#00FF00'; + if (damage >= 999999999) damage = '无法战斗'; + var length = core.canvas.ui.measureText(damage).width; + core.fillText('ui', damage, damage_offset, 62 * i + 50, color, 'bold 13px Verdana'); + + core.canvas.ui.textAlign = "left"; + // 属性 + if (enemy.special != '') { + core.setFont('data', 'bold 12px Verdana'); + var length = core.canvas.data.measureText(enemy.special).width; + core.setAlpha('data', '0.4'); + core.fillRect('data', 64 - 4 - length, 62 * i + 46, length + 4, 17, '#000000'); + core.setAlpha('data', '1'); + core.fillText('data', enemy.special, 64 - 2 - length, 62 * i + 59, '#FF6A6A', 'bold 12px Verdana') + } + + core.fillText('ui', '临界', 165, 62 * i + 68, '#DDDDDD', '13px Verdana'); + core.fillText('ui', enemy.critical, 195, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana'); + core.fillText('ui', '减伤', 255, 62 * i + 68, '#DDDDDD', '13px Verdana'); + core.fillText('ui', enemy.criticalDamage, 285, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana'); + core.fillText('ui', '1防', 335, 62 * i + 68, '#DDDDDD', '13px Verdana'); + core.fillText('ui', enemy.defDamage, 365, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana'); + + } + core.setBoxAnimate(core.firstData.animateSpeed); + this.drawPagination(page, totalPage); +} + +/** + * 绘制楼传器 + * @param page + */ +ui.prototype.drawFly = function(page) { + + if (page<0) page=0; + if (page>=core.status.hero.flyRange.length) page=core.status.hero.flyRange.length-1; + core.status.event.data = page; + + var floorId = core.status.hero.flyRange[page]; + var title = core.status.maps[floorId].title; + + 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.canvas.ui.textAlign = 'center'; + core.fillText('ui', '楼层跳跃', 208, 60, '#FFFFFF', "bold 28px Verdana"); + core.fillText('ui', '返回游戏', 208, 403, '#FFFFFF', "bold 15px Verdana") + core.fillText('ui', title, 356, 247, '#FFFFFF', "bold 19px Verdana"); + if (page0) + core.fillText('ui', '▼', 356, 247+64, '#FFFFFF', "17px Verdana"); + core.strokeRect('ui', 20, 100, 273, 273, '#FFFFFF', 2); + this.drawThumbnail('ui', core.status.maps[floorId].blocks, 20, 100, 273); +} + +/** + * 绘制工具栏 + * @param selectId + */ +ui.prototype.drawToolbox = function(selectId) { + + if (!core.hasItem(selectId)) + selectId=null; + core.status.event.data=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; + + // 画线 + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(0, 130); + core.canvas.ui.lineTo(416, 130); + core.canvas.ui.stroke(); + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(0,129); + core.canvas.ui.lineTo(0,105); + core.canvas.ui.lineTo(72,105); + core.canvas.ui.lineTo(102,129); + core.canvas.ui.fill(); + + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(0, 290); + core.canvas.ui.lineTo(416, 290); + core.canvas.ui.stroke(); + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(0,289); + core.canvas.ui.lineTo(0,265); + core.canvas.ui.lineTo(72,265); + core.canvas.ui.lineTo(102,289); + core.canvas.ui.fill(); + + // 文字 + core.canvas.ui.textAlign = 'left'; + core.fillText('ui', "消耗道具", 5, 124, '#333333', "bold 16px Verdana"); + core.fillText('ui', "永久道具", 5, 284); + + // 描述 + if (core.isset(selectId)) { + var item=core.material.items[selectId]; + core.fillText('ui', item.name, 10, 32, '#FFD700', "bold 20px Verdana") + core.fillText('ui', item.text, 10, 62, '#FFFFFF', '17px Verdana'); + core.fillText('ui', '<继续点击该道具即可进行使用>', 10, 89, '#CCCCCC', '14px Verdana'); + } + + core.canvas.ui.textAlign = 'right'; + var images = core.material.images.items; + // 消耗道具 + var tools = Object.keys(core.status.hero.items.tools).sort(); + for (var i=0;i=30) page=29; + core.status.event.data = page; + core.status.savePage = page; + + 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.canvas.ui.textAlign = 'center'; + + var u=416/6, size=117; + + var name=core.status.event.id=='save'?"存档":"读档"; + for (var i=0;i<6;i++) { + var id=6*page+i+1; + var data=core.getLocalStorage("save"+id,null); + + if (i<3) { + core.fillText('ui', name+id, (2*i+1)*u, 35, '#FFFFFF', "bold 17px Verdana"); + core.strokeRect('ui', (2*i+1)*u-size/2, 50, size, size, '#FFFFFF', 2); + if (core.isset(data) && core.isset(data.floorId)) { + this.drawThumbnail('ui', core.maps.load(data.maps, data.floorId).blocks, (2*i+1)*u-size/2, 50, size, data.hero.loc, data.hero.id); + core.fillText('ui', core.formatDate(new Date(data.time)), (2*i+1)*u, 65+size, '#FFFFFF', '10px Verdana'); + } + else { + core.fillRect('ui', (2*i+1)*u-size/2, 50, size, size, '#333333', 2); + core.fillText('ui', '空', (2*i+1)*u, 117, '#FFFFFF', 'bold 30px Verdana'); + } + } + else { + core.fillText('ui', name+id, (2*i-5)*u, 230, '#FFFFFF', "bold 17px Verdana"); + core.strokeRect('ui', (2*i-5)*u-size/2, 245, size, size, '#FFFFFF', 2); + if (core.isset(data) && core.isset(data.floorId)) { + this.drawThumbnail('ui', core.maps.load(data.maps, data.floorId).blocks, (2*i-5)*u-size/2, 245, size, data.hero.loc, data.hero.id); + core.fillText('ui', core.formatDate(new Date(data.time)), (2*i-5)*u, 260+size, '#FFFFFF', '10px Verdana'); + } + else { + core.fillRect('ui', (2*i-5)*u-size/2, 245, size, size, '#333333', 2); + core.fillText('ui', '空', (2*i-5)*u, 245+70, '#FFFFFF', 'bold 30px Verdana'); + } + } + } + this.drawPagination(page+1, 30); + +} + +/** + * 绘制缩略图 + * @param canvas + * @param blocks + * @param x + * @param y + * @param size + * @param heroLoc + * @param heroId + */ +ui.prototype.drawThumbnail = function(canvas, blocks, x, y, size, heroLoc, heroId) { + core.clearMap(canvas, x, y, size, size); + var persize = size/13; + for (var i=0;i<13;i++) { + for (var j=0;j<13;j++) { + var blockIcon = core.material.icons.terrains.ground; + var blockImage = core.material.images.terrains; + core.canvas[canvas].drawImage(blockImage, 0, blockIcon.loc * blockIcon.size, blockIcon.size, blockIcon.size, x + i * persize, y + j * persize, persize, persize); + } + } + for (var b in blocks) { + var block = blocks[b]; + if (core.isset(block.event)) { + var i = block.x, j = block.y; + var blockIcon = core.material.icons[block.event.cls][block.event.id]; + var blockImage = core.material.images[block.event.cls]; + //core.canvas[canvas].clearRect(x + i * persize, y + j * persize, persize, persize); + core.canvas[canvas].drawImage(blockImage, 0, blockIcon.loc * blockIcon.size, blockIcon.size, blockIcon.size, x + i * persize, y + j * persize, persize, persize); + } + } + if (core.isset(heroLoc)) { + var id = core.isset(heroId)?heroId:core.status.hero.id; + var heroIcon = core.material.icons.heros[id][heroLoc.direction]; + core.canvas[canvas].drawImage(core.material.images.heros, heroIcon.loc['stop'] * heroIcon.size, heroIcon.loc.iconLoc * heroIcon.size, heroIcon.size, heroIcon.size, x+persize*heroLoc.x, y+persize*heroLoc.y, persize, persize); + } +} + +/** + * 绘制"关于" + */ +ui.prototype.drawAbout = function() { + + if (!core.isPlaying()) { + core.status.event = {'id': null, 'data': null}; + core.dom.startPanel.style.display = 'none'; + } + core.lockControl(); + core.status.event.id = 'about'; + + core.clearMap('ui', 0, 0, 416, 416); + var left = 48, top = 36, right = 416 - 2 * left, bottom = 416 - 2 * top; + + core.setAlpha('ui', 0.85); + core.fillRect('ui', left, top, right, bottom, '#000000'); + core.setAlpha('ui', 1); + core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); + + var text_start = left + 24; + + // 名称 + core.canvas.ui.textAlign = "left"; + core.fillText('ui', "异空间", text_start, top+35, "#FFD700", "bold 22px Verdana"); + core.fillText('ui', "HTML5复刻版", text_start+75, top+37, "#DDDDDD", "bold 15px Verdana"); + core.fillText('ui', "作者: 艾之葵", text_start, top + 80, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "原作: ss433_2", text_start, top + 112, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "制作工具: WebStorm", text_start, top + 144, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', "测试平台: Chrome/微信/iOS", text_start, top + 176, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', '特别鸣谢: ss433_2', text_start, top+208); + var len = core.canvas.ui.measureText('特别鸣谢: ').width; + core.fillText('ui', 'iEcho', text_start+len, top+240); + core.fillText('ui', '打Dota的喵', text_start+len, top+272); + core.fillText('ui', 'HTML5魔塔交流群:539113091', text_start, top+304); +} \ No newline at end of file diff --git a/libs/ui.min.js b/libs/ui.min.js new file mode 100644 index 00000000..cae71961 --- /dev/null +++ b/libs/ui.min.js @@ -0,0 +1 @@ +function ui(){}ui.prototype.init=function(){};main.instance.ui=new ui();ui.prototype.closePanel=function(a){core.status.boxAnimateObjs=[];core.setBoxAnimate(core.firstData.animateSpeed);core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);if(core.isset(a)&&a){core.clearMap("data",0,0,416,416)}core.unLockControl();core.status.event.data=null;core.status.event.id=null};ui.prototype.drawTextBox=function(l,e){core.lockControl();if(core.status.event.id==null){core.status.event.id="text"}var c=core.canvas.ui.createPattern(core.material.ground,"repeat");var g=l.split("\n");core.clearMap("ui",0,0,416,416);var q=416-10-Math.min(416-24*(g.length+1)-65,250);var f=10,n=(416-q)/2,p=416-2*f,a=q;core.setAlpha("ui",0.85);core.fillRect("ui",f,n,p,a,"#000000");core.setAlpha("ui",1);core.strokeRect("ui",f-1,n-1,p+1,a+1,"#FFFFFF",2);core.canvas.ui.textAlign="left";var d=f+25,o=n+35;if(core.isset(e)){d=f+63;o=n+57;var b,h,r;core.strokeRect("ui",f+15-1,n+40-1,34,34,"#FFD700",2);if(e=="hero"){core.fillText("ui",core.status.hero.name,f+63,n+30,"#FFD700","bold 22px Verdana");core.status.boxAnimateObjs=[];core.setBoxAnimate(core.firstData.animateSpeed);core.clearMap("ui",f+15,n+40,32,32);core.fillRect("ui",f+15,n+40,32,32,c);var k=core.material.icons.heros[core.status.hero.id]["down"];core.canvas.ui.drawImage(core.material.images.heros,k.loc.stop*k.size,k.loc.iconLoc*k.size,k.size,k.size,f+15,n+40,32,32)}else{var b=null,h=null,m=null;if(core.material.npcs.hasOwnProperty(e)){b=core.material.npcs[e].name;h=core.material.images.npcs;m=core.material.icons.npcs[core.material.npcs[e].icon]}else{if(core.material.enemys.hasOwnProperty(e)){b=core.material.enemys[e].name;h=core.material.images.enemys;m=core.material.icons.enemys[e]}}if(b!=null){core.fillText("ui",b,f+63,n+30,"#FFD700","bold 22px Verdana");core.status.boxAnimateObjs=[];core.status.boxAnimateObjs.push({bgx:f+15,bgy:n+40,bgsize:32,image:h,x:f+15,y:n+40,icon:m});core.setBoxAnimate(core.firstData.animateSpeed)}}}for(var j=0;j",270,n+q-13,"#CCCCCC","13px Verdana")};ui.prototype.showConfirmBox=function(k,e,l){core.status.event.id="confirmBox";core.status.event.data={yes:e,no:l};var b=core.canvas.ui.createPattern(core.material.ground,"repeat");core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);core.setFillStyle("ui",b);core.setFont("ui","bold 19px Verdana");var d=k.split("\n");var m=d.length;var j=0;for(var f in d){j=Math.max(j,core.canvas.ui.measureText(d[f]).width)}var c=Math.min(208-40-j/2,100);var g=140-(m-1)*30;var h=416-2*c,a=416-140-g;core.fillRect("ui",c,g,h,a,b);core.strokeRect("ui",c-1,g-1,h+1,a+1,"#FFFFFF",2);core.canvas.ui.textAlign="center";for(var f in d){core.fillText("ui",d[f],208,g+50+f*30,"#FFFFFF")}core.fillText("ui","确定",208-38,g+a-35,"#FFFFFF","bold 17px Verdana");core.fillText("ui","取消",208+38,g+a-35)};ui.prototype.drawSettings=function(d){if(!core.checkStatus("settings",d)){return}var c=core.canvas.ui.createPattern(core.material.ground,"repeat");core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);core.setFillStyle("ui",c);var f=97,e=64,b=416-2*f,a=416-2*e;core.fillRect("ui",f,e,b,a,c);core.strokeRect("ui",f-1,e-1,b+1,a+1,"#FFFFFF",2);core.canvas.ui.textAlign="center";core.fillText("ui","音乐: "+(core.musicStatus.soundStatus?"[ON]":"[OFF]"),208,e+56,"#FFFFFF","bold 17px Verdana");core.fillText("ui","快捷商店",208,e+88,"#FFFFFF","bold 17px Verdana");core.fillText("ui","降低难度",208,e+120,"#FFFFFF","bold 17px Verdana");core.fillText("ui","同步存档",208,e+152,"#FFFFFF","bold 17px Verdana");core.fillText("ui","重新开始",208,e+184,"#FFFFFF","bold 17px Verdana");core.fillText("ui","关于本塔",208,e+216,"#FFFFFF","bold 17px Verdana");core.fillText("ui","返回游戏",208,e+248,"#FFFFFF","bold 17px Verdana")};ui.prototype.drawSelectShop=function(g){if(core.isset(g)&&!core.checkStatus("selectShop",g)){return}core.status.event.id="selectShop";var b=core.canvas.ui.createPattern(core.material.ground,"repeat");core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);core.setFillStyle("ui",b);var k=core.status.shops,j=Object.keys(k);var e=j.length+1;if(e%2==0){e++}var c=97,f=208-32-16*e,h=416-2*c,a=416-2*f;core.fillRect("ui",c,f,h,a,b);core.strokeRect("ui",c-1,f-1,h+1,a+1,"#FFFFFF",2);core.canvas.ui.textAlign="center";for(var d=0;d1){core.fillText("ui","上一页",208-80,403)}if(cj){k=j}core.status.event.data=k;var b=(k-1)*g,f=Math.min(k*g,m.length);m=m.slice(b,f);core.status.boxAnimateObjs=[];for(var h=0;h=core.status.hero.hp){e="#FF0000"}if(l==0){e="#00FF00"}if(l>=999999999){l="无法战斗"}var c=core.canvas.ui.measureText(l).width;core.fillText("ui",l,n,62*h+50,e,"bold 13px Verdana");core.canvas.ui.textAlign="left";if(d.special!=""){core.setFont("data","bold 12px Verdana");var c=core.canvas.data.measureText(d.special).width;core.setAlpha("data","0.4");core.fillRect("data",64-4-c,62*h+46,c+4,17,"#000000");core.setAlpha("data","1");core.fillText("data",d.special,64-2-c,62*h+59,"#FF6A6A","bold 12px Verdana")}core.fillText("ui","临界",165,62*h+68,"#DDDDDD","13px Verdana");core.fillText("ui",d.critical,195,62*h+68,"#DDDDDD","bold 13px Verdana");core.fillText("ui","减伤",255,62*h+68,"#DDDDDD","13px Verdana");core.fillText("ui",d.criticalDamage,285,62*h+68,"#DDDDDD","bold 13px Verdana");core.fillText("ui","1防",335,62*h+68,"#DDDDDD","13px Verdana");core.fillText("ui",d.defDamage,365,62*h+68,"#DDDDDD","bold 13px Verdana")}core.setBoxAnimate(core.firstData.animateSpeed);this.drawPagination(k,j)};ui.prototype.drawFly=function(b){if(b<0){b=0}if(b>=core.status.hero.flyRange.length){b=core.status.hero.flyRange.length-1}core.status.event.data=b;var a=core.status.hero.flyRange[b];var c=core.status.maps[a].title;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.canvas.ui.textAlign="center";core.fillText("ui","楼层跳跃",208,60,"#FFFFFF","bold 28px Verdana");core.fillText("ui","返回游戏",208,403,"#FFFFFF","bold 15px Verdana");core.fillText("ui",c,356,247,"#FFFFFF","bold 19px Verdana");if(b0){core.fillText("ui","▼",356,247+64,"#FFFFFF","17px Verdana")}core.strokeRect("ui",20,100,273,273,"#FFFFFF",2);this.drawThumbnail("ui",core.status.maps[a].blocks,20,100,273)};ui.prototype.drawToolbox=function(a){if(!core.hasItem(a)){a=null}core.status.event.data=a;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;core.canvas.ui.beginPath();core.canvas.ui.moveTo(0,130);core.canvas.ui.lineTo(416,130);core.canvas.ui.stroke();core.canvas.ui.beginPath();core.canvas.ui.moveTo(0,129);core.canvas.ui.lineTo(0,105);core.canvas.ui.lineTo(72,105);core.canvas.ui.lineTo(102,129);core.canvas.ui.fill();core.canvas.ui.beginPath();core.canvas.ui.moveTo(0,290);core.canvas.ui.lineTo(416,290);core.canvas.ui.stroke();core.canvas.ui.beginPath();core.canvas.ui.moveTo(0,289);core.canvas.ui.lineTo(0,265);core.canvas.ui.lineTo(72,265);core.canvas.ui.lineTo(102,289);core.canvas.ui.fill();core.canvas.ui.textAlign="left";core.fillText("ui","消耗道具",5,124,"#333333","bold 16px Verdana");core.fillText("ui","永久道具",5,284);if(core.isset(a)){var h=core.material.items[a];core.fillText("ui",h.name,10,32,"#FFD700","bold 20px Verdana");core.fillText("ui",h.text,10,62,"#FFFFFF","17px Verdana");core.fillText("ui","<继续点击该道具即可进行使用>",10,89,"#CCCCCC","14px Verdana")}core.canvas.ui.textAlign="right";var f=core.material.images.items;var c=Object.keys(core.status.hero.items.tools).sort();for(var b=0;b=30){f=29}core.status.event.data=f;core.status.savePage=f;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.canvas.ui.textAlign="center";var b=416/6,d=117;var a=core.status.event.id=="save"?"存档":"读档";for(var c=0;c<6;c++){var g=6*f+c+1;var e=core.getLocalStorage("save"+g,null);if(c<3){core.fillText("ui",a+g,(2*c+1)*b,35,"#FFFFFF","bold 17px Verdana");core.strokeRect("ui",(2*c+1)*b-d/2,50,d,d,"#FFFFFF",2);if(core.isset(e)&&core.isset(e.floorId)){this.drawThumbnail("ui",core.maps.load(e.maps,e.floorId).blocks,(2*c+1)*b-d/2,50,d,e.hero.loc,e.hero.id);core.fillText("ui",core.formatDate(new Date(e.time)),(2*c+1)*b,65+d,"#FFFFFF","10px Verdana")}else{core.fillRect("ui",(2*c+1)*b-d/2,50,d,d,"#333333",2);core.fillText("ui","空",(2*c+1)*b,117,"#FFFFFF","bold 30px Verdana")}}else{core.fillText("ui",a+g,(2*c-5)*b,230,"#FFFFFF","bold 17px Verdana");core.strokeRect("ui",(2*c-5)*b-d/2,245,d,d,"#FFFFFF",2);if(core.isset(e)&&core.isset(e.floorId)){this.drawThumbnail("ui",core.maps.load(e.maps,e.floorId).blocks,(2*c-5)*b-d/2,245,d,e.hero.loc,e.hero.id);core.fillText("ui",core.formatDate(new Date(e.time)),(2*c-5)*b,260+d,"#FFFFFF","10px Verdana")}else{core.fillRect("ui",(2*c-5)*b-d/2,245,d,d,"#333333",2);core.fillText("ui","空",(2*c-5)*b,245+70,"#FFFFFF","bold 30px Verdana")}}}this.drawPagination(f+1,30)};ui.prototype.drawThumbnail=function(d,a,r,o,s,e,p){core.clearMap(d,r,o,s,s);var q=s/13;for(var k=0;k<13;k++){for(var h=0;h<13;h++){var g=core.material.icons.terrains.ground;var m=core.material.images.terrains;core.canvas[d].drawImage(m,0,g.loc*g.size,g.size,g.size,r+k*q,o+h*q,q,q)}}for(var n in a){var f=a[n];if(core.isset(f.event)){var k=f.x,h=f.y;var g=core.material.icons[f.event.cls][f.event.id];var m=core.material.images[f.event.cls];core.canvas[d].drawImage(m,0,g.loc*g.size,g.size,g.size,r+k*q,o+h*q,q,q)}}if(core.isset(e)){var c=core.isset(p)?p:core.status.hero.id;var l=core.material.icons.heros[c][e.direction];core.canvas[d].drawImage(core.material.images.heros,l.loc.stop*l.size,l.loc.iconLoc*l.size,l.size,l.size,r+q*e.x,o+q*e.y,q,q)}};ui.prototype.drawAbout=function(){if(!core.isPlaying()){core.status.event={id:null,data:null};core.dom.startPanel.style.display="none"}core.lockControl();core.status.event.id="about";core.clearMap("ui",0,0,416,416);var f=48,e=36,c=416-2*f,b=416-2*e;core.setAlpha("ui",0.85);core.fillRect("ui",f,e,c,b,"#000000");core.setAlpha("ui",1);core.strokeRect("ui",f-1,e-1,c+1,b+1,"#FFFFFF",2);var d=f+24;core.canvas.ui.textAlign="left";core.fillText("ui","异空间",d,e+35,"#FFD700","bold 22px Verdana");core.fillText("ui","HTML5复刻版",d+75,e+37,"#DDDDDD","bold 15px Verdana");core.fillText("ui","作者: 艾之葵",d,e+80,"#FFFFFF","bold 17px Verdana");core.fillText("ui","原作: ss433_2",d,e+112,"#FFFFFF","bold 17px Verdana");core.fillText("ui","制作工具: WebStorm",d,e+144,"#FFFFFF","bold 17px Verdana");core.fillText("ui","测试平台: Chrome/微信/iOS",d,e+176,"#FFFFFF","bold 17px Verdana");core.fillText("ui","特别鸣谢: ss433_2",d,e+208);var a=core.canvas.ui.measureText("特别鸣谢: ").width;core.fillText("ui","iEcho",d+a,e+240);core.fillText("ui","打Dota的喵",d+a,e+272);core.fillText("ui","HTML5魔塔交流群:539113091",d,e+304)}; \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 00000000..fc41fef9 --- /dev/null +++ b/main.js @@ -0,0 +1,313 @@ +function main() { + this.dom = { + 'body': document.body, + 'gameGroup': document.getElementById('gameGroup'), + 'mainTips': document.getElementById('mainTips'), + 'musicBtn': document.getElementById('musicBtn'), + 'startPanel': document.getElementById('startPanel'), + 'startTop': document.getElementById('startTop'), + 'startTopProgressBar': document.getElementById('startTopProgressBar'), + 'startTopProgress': document.getElementById('startTopProgress'), + 'startTopLoadTips': document.getElementById('startTopLoadTips'), + 'startBackground': document.getElementById('startBackground'), + 'startButtonGroup': document.getElementById('startButtonGroup'), + 'floorMsgGroup': document.getElementById('floorMsgGroup'), + 'logoLabel': document.getElementById('logoLabel'), + 'versionLabel': document.getElementById('versionLabel'), + 'floorNameLabel': document.getElementById('floorNameLabel'), + 'statusBar': document.getElementById('statusBar'), + 'toolBar': document.getElementById('toolBar'), + 'gameCanvas': document.getElementsByClassName('gameCanvas'), + 'startButtons': document.getElementById('startButtons'), + 'playGame': document.getElementById('playGame'), + 'loadGame': document.getElementById('loadGame'), + 'aboutGame': document.getElementById('aboutGame'), + 'levelChooseButtons': document.getElementById('levelChooseButtons'), + 'easyLevel': document.getElementById('easyLevel'), + 'normalLevel': document.getElementById('normalLevel'), + 'hardLevel': document.getElementById('hardLevel'), + 'data': document.getElementById('data'), + 'statusLabels': document.getElementsByClassName('statusLabel') + }; + // console.log('加载游戏容器和开始界面dom对象完成 如下'); + // console.log(this.dom); + this.loadList = [ + 'items', 'icons', 'maps', 'enemys', 'events', + 'npcs', 'data', 'ui', 'core' + ]; + // console.log('加载js文件列表加载完成' + this.loadList); + this.images = [ + 'animates', 'enemys', 'heros', 'items', 'npcs', 'terrains' + ]; + this.sounds = { + 'mp3': ['bgm-loop', 'floor'], + 'ogg': ['attack', 'door', 'item'] + } + this.statusBar = { + 'image': { + 'floor': document.getElementById('img-floor'), + 'hp': document.getElementById("img-hp"), + 'atk': document.getElementById("img-atk"), + 'def': document.getElementById("img-def"), + 'mdef': document.getElementById("img-mdef"), + 'money': document.getElementById("img-money"), + 'experience': document.getElementById("img-experience"), + 'book': document.getElementById("img-book"), + 'fly': document.getElementById("img-fly"), + 'toolbox': document.getElementById("img-toolbox"), + 'shop': document.getElementById("img-shop"), + 'save': document.getElementById("img-save"), + 'load': document.getElementById("img-load"), + 'settings': document.getElementById("img-settings") + }, + 'floor': document.getElementById('floor'), + 'hp': document.getElementById('hp'), + 'atk': document.getElementById('atk'), + 'def': document.getElementById("def"), + 'mdef': document.getElementById('mdef'), + 'money': document.getElementById("money"), + 'experience': document.getElementById("experience"), + 'yellowKey': document.getElementById("yellowKey"), + 'blueKey': document.getElementById("blueKey"), + 'redKey': document.getElementById("redKey"), + 'poison': document.getElementById('poison'), + 'weak':document.getElementById('weak'), + 'curse': document.getElementById('curse'), + 'hard': document.getElementById("hard") + } + this.floorIds = [ + "MT1" + ] + this.floors = {} + this.instance = {}; + this.canvas = {}; +} + +main.prototype.init = function () { + for (var i = 0; i < main.dom.gameCanvas.length; i++) { + main.canvas[main.dom.gameCanvas[i].id] = main.dom.gameCanvas[i].getContext('2d'); + } + main.loader(function () { + var coreData = {}; + for (i = 0; i < main.loadList.length; i++) { + var name = main.loadList[i]; + // end with ".min" + if (name.indexOf(".min")==name.length-4) + name=name.substring(0, name.length-4); + if (name === 'core') { + continue; + } + main[name].init(main.dom); + coreData[name] = main[name]; + } + main.core.init(main.dom, main.statusBar, main.canvas, main.images, main.sounds, coreData); + main.core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); + }); +} + +main.prototype.loader = function (callback) { + var instanceNum = 0; + for (var i = 0; i < main.loadList.length; i++) { + main.loadMod(main.loadList[i], function (modName) { + instanceNum = 0; + main.setMainTipsText(modName + '.js 加载完毕'); + for (var key in main.instance) { + instanceNum++; + } + if (instanceNum === main.loadList.length) { + delete main.instance; + main.dom.mainTips.style.display = 'none'; + callback(); + } + }); + } +} + +main.prototype.loadMod = function (modName, callback) { + var script = document.createElement('script'); + var name = modName; + // end with ".min" + if (name.indexOf(".min")==name.length-4) + name=name.substring(0, name.length-4); + script.src = 'libs/' + modName + '.js'; + main.dom.body.appendChild(script); + script.onload = function () { + main[name] = main.instance[name]; + callback(name); + } +} + +main.prototype.setMainTipsText = function (text) { + main.dom.mainTips.innerHTML = text; +} + +var main = new main(); +main.init(); + +window.onresize = function () { + try { + main.core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); + }catch (e) {} +} + +main.dom.body.onkeydown = function(e) { + if (main.core.isPlaying()) + main.core.keyDown(e); +} + +main.dom.body.onkeyup = function(e) { + try { + if (main.core.isPlaying()) + main.core.keyUp(e); + } catch (e) {} +} + +main.dom.body.onselectstart = function () { + return false; +} + +document.onmousemove = function() { + try { + main.core.loadSound(); + }catch (e) {} +} + +document.ontouchstart = function() { + try { + main.core.loadSound(); + }catch (e) {} +} + +main.dom.data.onmousedown = function (e) { + try { + e.stopPropagation(); + var loc = main.core.getClickLoc(e.clientX, e.clientY); + if (loc == null) return; + var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); + main.core.ondown(x, y); + } catch (e) {} +} + +main.dom.data.onmousemove = function (e) { + try { + e.stopPropagation(); + var loc = main.core.getClickLoc(e.clientX, e.clientY); + if (loc == null) return; + var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); + main.core.onmove(x, y); + }catch (e) {} +} + +main.dom.data.onmouseup = function () { + try { + main.core.onup(); + }catch (e) {} +} + +main.dom.data.onmousewheel = function(e) { + try { + if (e.wheelDelta) + main.core.onmousewheel(Math.sign(e.wheelDelta)) + else if (e.detal) + main.core.onmousewheel(Math.sign(e.detail)); + } catch (ee) {} +} + +main.dom.data.ontouchstart = function (e) { + try { + e.preventDefault(); + var loc = main.core.getClickLoc(e.targetTouches[0].clientX, e.targetTouches[0].clientY); + if (loc == null) return; + var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); + //main.core.onclick(x, y, []); + main.core.ondown(x, y); + }catch (e) {} +} + +main.dom.data.ontouchmove = function (e) { + try { + e.preventDefault(); + var loc = main.core.getClickLoc(e.targetTouches[0].clientX, e.targetTouches[0].clientY); + if (loc == null) return; + var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); + main.core.onmove(x, y); + }catch (e) {} +} + +main.dom.data.ontouchend = function () { + try { + main.core.onup(); + } catch (e) { + } +} + +main.statusBar.image.book.onclick = function () { + if (main.core.isPlaying()) + main.core.openBook(true); +} + +main.statusBar.image.fly.onclick = function (e) { + if (main.core.isPlaying()) + main.core.useFly(true); +} + +main.statusBar.image.toolbox.onclick = function (e) { + if (main.core.isPlaying()) + main.core.openToolbox(true); +} + +main.statusBar.image.shop.onclick = function () { + if (main.core.isPlaying()) + main.core.ui.drawSelectShop(true); +} + +main.statusBar.image.save.onclick = function (e) { + if (main.core.isPlaying()) + main.core.save(true); +} + +main.statusBar.image.load.onclick = function (e) { + if (main.core.isPlaying()) + main.core.load(true); +} + +main.statusBar.image.settings.onclick = function (e) { + if (main.core.isPlaying()) + main.core.ui.drawSettings(true); +} + +main.dom.playGame.onclick = function () { + main.dom.startButtons.style.display='none'; + + /** + * 如果点击“开始游戏”直接开始游戏而不是进入难度选择页面,则将下面这个改成true + */ + var startGameNow = false; + + if (startGameNow) { + core.events.startGame(); + } + else { + main.dom.levelChooseButtons.style.display='block'; + } +} + +main.dom.loadGame.onclick = function() { + main.core.load(); +} + +main.dom.aboutGame.onclick = function () { + main.core.ui.drawAbout(); +} + +main.dom.easyLevel.onclick = function() { + core.events.startGame('Easy'); +} + +main.dom.normalLevel.onclick = function () { + core.events.startGame('Normal'); +} + +main.dom.hardLevel.onclick = function () { + core.events.startGame('Gard'); +} diff --git a/main.min.js b/main.min.js new file mode 100644 index 00000000..dc70826e --- /dev/null +++ b/main.min.js @@ -0,0 +1 @@ +function main(){this.dom={body:document.body,gameGroup:document.getElementById("gameGroup"),mainTips:document.getElementById("mainTips"),musicBtn:document.getElementById("musicBtn"),startPanel:document.getElementById("startPanel"),startTop:document.getElementById("startTop"),startTopProgressBar:document.getElementById("startTopProgressBar"),startTopProgress:document.getElementById("startTopProgress"),startTopLoadTips:document.getElementById("startTopLoadTips"),startBackground:document.getElementById("startBackground"),startButtonGroup:document.getElementById("startButtonGroup"),floorMsgGroup:document.getElementById("floorMsgGroup"),versionLabel:document.getElementById("versionLabel"),floorNameLabel:document.getElementById("floorNameLabel"),statusBar:document.getElementById("statusBar"),toolBar:document.getElementById("toolBar"),gameCanvas:document.getElementsByClassName("gameCanvas"),startButtons:document.getElementById("startButtons"),playGame:document.getElementById("playGame"),loadGame:document.getElementById("loadGame"),aboutGame:document.getElementById("aboutGame"),levelChooseButtons:document.getElementById("levelChooseButtons"),easyLevel:document.getElementById("easyLevel"),normalLevel:document.getElementById("normalLevel"),hardLevel:document.getElementById("hardLevel"),data:document.getElementById("data"),statusLabels:document.getElementsByClassName("statusLabel")};this.loadList=["items","icons","maps","enemys","events","npcs","data","ui","core"];this.images=["animates","enemys","heros","items","npcs","terrains"];this.sounds={mp3:["bgm-loop","floor"],ogg:["attack","door","item"]};this.statusBar={image:{floor:document.getElementById("img-floor"),hp:document.getElementById("img-hp"),atk:document.getElementById("img-atk"),def:document.getElementById("img-def"),money:document.getElementById("img-money"),experience:document.getElementById("img-experience"),book:document.getElementById("img-book"),fly:document.getElementById("img-fly"),toolbox:document.getElementById("img-toolbox"),shop:document.getElementById("img-shop"),save:document.getElementById("img-save"),load:document.getElementById("img-load"),settings:document.getElementById("img-settings")},floor:document.getElementById("floor"),hp:document.getElementById("hp"),atk:document.getElementById("atk"),def:document.getElementById("def"),money:document.getElementById("money"),experience:document.getElementById("experience"),yellowKey:document.getElementById("yellowKey"),blueKey:document.getElementById("blueKey"),redKey:document.getElementById("redKey"),hard:document.getElementById("hard")};this.instance={};this.canvas={}}main.prototype.init=function(){for(var a=0;a