Enable Level Up

This commit is contained in:
oc 2017-12-28 09:17:35 +08:00
parent cf02a59dee
commit 68f0a28a61
7 changed files with 117 additions and 25 deletions

View File

@ -1537,12 +1537,11 @@ core.prototype.afterBattle = function(id, x, y, callback) {
var experience = core.material.enemys[id].experience;
if (core.hasFlag('curse')) experience=0;
core.status.hero.experience += experience;
core.updateStatusBar();
if (core.isset(x) && core.isset(y)) {
core.removeBlock(x, y);
core.canvas.event.clearRect(32 * x, 32 * y, 32, 32);
}
core.updateFg();
// core.updateStatusBar();
var hint = "打败 " + core.material.enemys[id].name;
if (core.flags.enableMoney)
hint += ",金币+" + money;
@ -1625,7 +1624,6 @@ core.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback)
core.statusBar.floor.style.fontStyle = 'italic';
else core.statusBar.floor.style.fontStyle = 'normal';
core.updateStatusBar();
core.drawMap(floorId, function () {
setTimeout(function() {
core.mapChangeAnimate('hide', time/4, function () {
@ -1638,9 +1636,10 @@ core.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback)
core.setHeroLoc('x', heroLoc.x);
core.setHeroLoc('y', heroLoc.y);
core.drawHero(core.getHeroLoc('direction'), core.getHeroLoc('x'), core.getHeroLoc('y'), 'stop');
core.updateCheckBlockMap();
core.updateCheckBlock();
core.updateFg();
core.updateStatusBar();
// core.updateCheckBlockMap();
// core.updateCheckBlock();
// core.updateFg();
}, 15)
});
});
@ -2783,6 +2782,21 @@ core.prototype.calValue = function (value) {
return eval(value);
}
core.prototype.doEffect = function (expression) {
// 必须使用"+="
var arr = expression.split("+=");
if (arr.length!=2) return;
var name=arr[0], value=core.calValue(arr[1]);
if (name.indexOf("status:")==0) {
var status=name.substring(7);
core.setStatus(status, core.getStatus(status)+value);
}
else if (name.indexOf("item:")==0) {
var itemId=name.substring(5);
core.setItem(itemId, core.itemCount(itemId)+value);
}
}
core.prototype.splitLines = function(canvas, text, maxLength, font) {
if (core.isset(font)) core.setFont(canvas, font);
@ -3334,6 +3348,9 @@ core.prototype.clearStatusBar = function() {
*/
core.prototype.updateStatusBar = function () {
// 检查登记
core.checkLvUp();
// 上限999999
if (core.values.HPMAX>0) {
core.setStatus('hp', Math.min(core.values.HPMAX, core.getStatus('hp')));
@ -3349,6 +3366,12 @@ core.prototype.updateStatusBar = function () {
statusList.forEach(function (item) {
core.statusBar[item].innerHTML = core.getStatus(item);
});
// 进阶
if (core.flags.enableLevelUp && core.status.hero.lv<core.firstData.levelUp.length) {
core.statusBar.up.innerHTML = core.firstData.levelUp[core.status.hero.lv].need || "&nbsp;";
}
else core.statusBar.up.innerHTML = "&nbsp;";
var keys = ['yellowKey', 'blueKey', 'redKey'];
keys.forEach(function (key) {
core.statusBar[key].innerHTML = core.setTwoDigits(core.status.hero.items.keys[key]);
@ -3374,6 +3397,27 @@ core.prototype.updateStatusBar = function () {
core.updateFg();
}
core.prototype.checkLvUp = function () {
if (!core.flags.enableLevelUp || core.status.hero.lv>=core.firstData.levelUp.length) return;
// 计算下一个所需要的数值
var need=core.firstData.levelUp[core.status.hero.lv].need;
if (!core.isset(need)) return;
if (core.status.hero.experience>=need) {
// 升级
core.status.hero.lv++;
var effect = core.firstData.levelUp[core.status.hero.lv-1].effect;
if (typeof effect == "string") {
effect.split(";").forEach(function (t) {
core.doEffect(t);
});
}
else if (effect instanceof Function) {
effect();
}
core.checkLvUp();
}
}
core.prototype.resize = function(clientWidth, clientHeight) {
// 默认画布大小

View File

@ -7,7 +7,7 @@ data.prototype.init = function() {
"title": "魔塔样板", // 游戏名,将显示在标题页面以及切换楼层的界面中
"name": "template", // 游戏的唯一英文标识符。由英文、数字、下划线组成不能超过20个字符。
"version": "Ver 1.0.0 (Beta)", // 当前游戏版本;版本不一致的存档不能通用。
"floorId": "sample0", // 初始楼层ID
"floorId": "test", // 初始楼层ID
"hero": { // 勇士初始数据
"name": "阳光", // 勇士名;可以改成喜欢的
'lv': 1, // 初始等级,该项必须为正整数
@ -27,7 +27,7 @@ data.prototype.init = function() {
"tools": {}
},
"flyRange": [], // 初始可飞的楼层;一般留空数组即可
"loc": {"direction": "up", "x": 6, "y": 10}, // 勇士初始位置
"loc": {"direction": "up", "x": 6, "y": 12}, // 勇士初始位置
"flags": { // 游戏过程中的变量或flags
"poison": false, // 毒
"weak": false, // 衰
@ -84,13 +84,22 @@ data.prototype.init = function() {
},
"levelUp": [ // 经验升级所需要的数值,是一个数组
{}, // 第一项为初始等级可以简单留空也可以写name
{"need": 20, "name": "第二级", "effect": "status:hp+=2*(status:atk+status:def);status:atk+=10;status:def+=10"}, // 先将生命提升攻防和的2倍再将攻击+10防御+10
// 每一个里面可以含有三个参数 name, need, effect
// need为所需要的经验数值是一个正整数。请确保need所需的依次递增
// name为该等级的名称也可以省略代表使用系统默认值本项将显示在状态栏中
// effect为本次升级所执行的操作可由若干项组成由分号分开
// effect为本次升级所执行的操作可由若干项组成由分号分开
// 其中每一项写法和上面的商店完全相同同样必须是X+=Y的形式Y是一个表达式同样可以使用status:xxx或item:xxx代表勇士的某项数值/道具个数
{"need": 40, "effect": "status:hp+=2*(status:atk+status:def);status:atk+=10;status:def+=10"},
{"need": 20, "name": "第二级", "effect": "status:hp+=2*(status:atk+status:def);status:atk+=10;status:def+=10"}, // 先将生命提升攻防和的2倍再将攻击+10防御+10
// effect也允许写一个function代表本次升级将会执行的操作
{"need": 40, "effect": function () {
core.drawText("恭喜升级!");
core.status.hero.hp *= 2;
core.status.hero.atk += 100;
core.status.hero.def += 100;
}},
// 依次往下写需要的数值即可
]
}
@ -132,13 +141,13 @@ data.prototype.init = function() {
this.flags = {
/****** 角色状态相关 ******/
"enableNegativeDamage": true, // 是否支持负伤害(回血)
"enableFloor": true, // 是否在状态栏显示当前楼层
"enableLv": false, // 是否在状态栏显示当前等级
"enableFloor": false, // 是否在状态栏显示当前楼层
"enableLv": true, // 是否在状态栏显示当前等级
"enableMDef": true, // 是否在状态栏及战斗界面显示魔防(护盾)
"enableMoney": true, // 是否在状态栏、怪物手册及战斗界面显示金币
"enableExperience": true, // 是否在状态栏、怪物手册及战斗界面显示经验
"enableLevelUp": false, // 是否允许等级提升进阶如果上面enableExperience为false则此项恒视为false
"enableDebuff": true, // 是否涉及毒衰咒如果此项为false则不会在状态栏中显示毒衰咒的debuff
"enableLevelUp": true, // 是否允许等级提升进阶如果上面enableExperience为false则此项恒视为false
"enableDebuff": false, // 是否涉及毒衰咒如果此项为false则不会在状态栏中显示毒衰咒的debuff
////// 上述的几个开关将直接影响状态栏的显示效果 //////
/****** 道具相关 ******/
"flyNearStair": true, // 是否需要在楼梯边使用传送器

View File

@ -5,7 +5,7 @@ function enemys() {
enemys.prototype.init = function () {
// 怪物属性初始化定义:
this.enemys = {
'greenSlime': {'name': '绿头怪', 'hp': 100, 'atk': 120, 'def': 0, 'money': 1, 'experience': 0, 'special': 0},
'greenSlime': {'name': '绿头怪', 'hp': 100, 'atk': 120, 'def': 0, 'money': 1, 'experience': 1, 'special': 0},
'redSlime': {'name': '红头怪', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'blackSlime': {'name': '青头怪', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'slimelord': {'name': '怪王', 'hp': 100, 'atk': 120, 'def': 0, 'money': 10, 'experience': 0, 'special': 9},

View File

@ -329,7 +329,6 @@ events.prototype.doAction = function() {
core.status.hero.hp=0;
core.updateStatusBar();
core.events.lose('damage');
}
else {
core.updateStatusBar();
@ -817,12 +816,7 @@ events.prototype.clickShop = function(x,y) {
// 更新属性
choice.effect.split(";").forEach(function (t) {
if (t.indexOf("status:")==0) {
eval(t.replace("status:", "core.status.hero."));
}
else if (t.indexOf("item:")==0) {
eval(t.replace("item:", "core.getItem('").replace("+=", "', ")+")");
}
core.doEffect(t);
});
core.updateStatusBar();
shop.times++;

View File

@ -4,7 +4,7 @@
main.floors.MT0 = {
"floorId": "MT0", // 楼层唯一标识符,需要和名字完全一致
"title": "主塔 0 层", // 楼层中文名
"name": 0, // 显示在状态栏中的层数
"name": "0", // 显示在状态栏中的层数
"canFlyTo": true, // 该楼能否被楼传器飞到(不能的话在该楼也不允许使用楼传器)
"canUseQuickShop": true, // 该层是否允许使用快捷商店
"defaultGround": "ground", // 默认地面的图块IDterrains中

45
libs/floors/test.js Normal file
View File

@ -0,0 +1,45 @@
// 这里需要改楼层名请和文件名及下面的floorId保持完全一致
// 楼层唯一标识符仅能由字母、数字、下划线组成,且不能由数字开头
// 推荐用法第20层就用MT20第38层就用MT38地下6层就用MT_6用下划线代替负号隐藏3层用MT3hh表示隐藏等等
main.floors.test = {
"floorId": "test", // 楼层唯一标识符,需要和名字完全一致
"title": "test", // 楼层中文名
"name": "", // 显示在状态栏中的层数
"canFlyTo": true, // 该楼能否被楼传器飞到(不能的话在该楼也不允许使用楼传器)
"canUseQuickShop": true, // 该层是否允许使用快捷商店
"defaultGround": "ground", // 默认地面的图块IDterrains中
"map": [ // 地图数据需要是13x13建议使用地图生成器来生成
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201, 45,201,201,201,201,201,201],
[201,201,201,201,201,201, 0,201,201,201,201,201,201]
],
"firstArrive": [ // 第一次到该楼层触发的事件
],
"events": { // 该楼的所有可能事件列表
},
"changeFloor": { // 楼层转换事件该事件不能和上面的events有冲突同位置点否则会被覆盖
},
"afterBattle": { // 战斗后可能触发的事件列表
},
"afterGetItem": { // 获得道具后可能触发的事件列表
},
"afterOpenDoor": { // 开完门后可能触发的事件列表
}
}

View File

@ -97,7 +97,7 @@ function main() {
// 如果要进行剧本的修改请务必将其改成false。
this.floorIds = [ // 在这里按顺序放所有的楼层;其顺序直接影响到楼层传送器的顺序和上楼器/下楼器的顺序
"sample0", "sample1", "sample2"
"sample0", "sample1", "sample2", "test"
]
//------------------------ 用户修改内容 END ------------------------//