diff --git a/_docs/api.md b/_docs/api.md
index becdd230..cdb7332a 100644
--- a/_docs/api.md
+++ b/_docs/api.md
@@ -1320,6 +1320,16 @@ index: 套装编号,自然数
removeItem: fn(itemId?: string, itemNum?: number)
删除某个物品
+setEquip: fn(equipId: string, valueType: string, name: string, value: ?, operator?: string, prefix?: string)
+设置某个装备的属性并计入存档
+例如:core.setEquip('sword1', 'value', 'atk', 300, '+='); // 设置铁剑的攻击力数值再加300
+equipId: 装备id
+valueType: 增幅类型,只能是value(数值)或percentage(百分比)
+name: 要修改的属性名称,如atk
+value: 要修改到的属性数值
+operator: 操作符,可选,如+=表示在原始值上增加
+prefix: 独立开关前缀,一般不需要
+
setItem: fn(itemId: string, itemNum?: number)
设置某种道具的持有量
例如:core.setItem('yellowKey', 3) // 设置黄钥匙为3把
diff --git a/_server/CodeMirror/defs.js b/_server/CodeMirror/defs.js
index c69b4130..faabcec7 100644
--- a/_server/CodeMirror/defs.js
+++ b/_server/CodeMirror/defs.js
@@ -2212,6 +2212,10 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
"!doc": "暂停背景音乐的播放",
"!type": "fn()"
},
+ "setBgmSpeed": {
+ "!doc": "设置背景音乐的播放速度和音调
speed: 播放速度,必须为30-300中间的值。100为正常速度。
usePitch: 是否同时改变音调(部分设备可能不支持)",
+ "!type": "fn(speed: number, usePitch?: bool)"
+ },
"setReplaySpeed": {
"!doc": "设置播放速度",
"!type": "fn(speed: number)"
@@ -2709,6 +2713,10 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
"canEquip": {
"!doc": "检查能否穿上某件装备
例如:core.canEquip('sword5', true) // 主角可以装备神圣剑吗,如果不能会有提示
equipId: 装备id
hint: 无法穿上时是否提示(比如是因为未持有还是别的什么原因)
返回值:true表示可以穿上,false表示无法穿上",
"!type": "fn(equipId: string, hint?: bool) -> bool"
+ },
+ "setEquip": {
+ "!doc": "设置某个装备的属性并计入存档
例如:core.setEquip('sword1', 'value', 'atk', 300, '+='); // 设置铁剑的攻击力数值再加300
equipId: 装备id
valueType: 增幅类型,只能是value(数值)或percentage(百分比)
name: 要修改的属性名称,如atk
value: 要修改到的属性数值
operator: 操作符,可选,如+=表示在原始值上增加
prefix: 独立开关前缀,一般不需要",
+ "!type": "fn(equipId: string, valueType: string, name: string, value: ?, operator?: string, prefix?: string)"
}
},
"utils": {
diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4
index c9d4605f..c541e93c 100644
--- a/_server/MotaAction.g4
+++ b/_server/MotaAction.g4
@@ -752,6 +752,7 @@ action
| setEnemyOnPoint_s
| resetEnemyOnPoint_s
| moveEnemyOnPoint_s
+ | setEquip_s
| setFloor_s
| setGlobalAttribute_s
| setGlobalValue_s
@@ -1149,6 +1150,25 @@ return code;
*/;
+setEquip_s
+ : '设置装备属性' ':' '装备ID' IdString EquipValueType_List '的' EvalString AssignOperator_List expression Newline
+
+
+/* setEquip_s
+tooltip : setEquip:设置某个怪物的属性
+helpUrl : /_docs/#/instruction
+default : ["sword1", "value", "atk", "="]
+allEquips : ['IdString_0']
+colour : this.dataColor
+EquipValueType_List_0 = EquipValueType_List_0 == 'percentage' ? ', "valueType": "percentage"' : ', "valueType": "value"';
+if (AssignOperator_List_0 && AssignOperator_List_0 != '=') {
+ AssignOperator_List_0 = ', "operator": "' + AssignOperator_List_0 + '"';
+} else AssignOperator_List_0 = '';
+var code = '{"type": "setEquip", "id": "'+IdString_0+'"'+EquipValueType_List_0+', "name": "'+EvalString_0+'"'+AssignOperator_List_0+', "value": "'+expression_0+'"},\n';
+return code;
+*/;
+
+
setEnemyOnPoint_s
: '设置某点怪物属性' ':' 'x' PosString? ',' 'y' PosString? '楼层' IdString? '的' EnemyId_List AssignOperator_List expression Newline
@@ -1904,7 +1924,7 @@ tooltip : loadEquip: 装上装备
helpUrl : /_docs/#/instruction
colour : this.dataColor
default : ["sword1"]
-allItems : ['IdString_0']
+allEquips : ['IdString_0']
var code = '{"type": "loadEquip", "id": "'+IdString_0+'"},\n';
return code;
*/;
@@ -3826,6 +3846,10 @@ NextXY_List
: '横坐标'|'纵坐标'
/*NextXY_List ['nextX','nextY']*/;
+EquipValueType_List
+ : '数值项'|'百分比项'
+ /*EquipValueType_List ['value','percentage']*/;
+
Colour
: 'sdeirughvuiyasdeb'+ //为了被识别为复杂词法规则
;
diff --git a/_server/MotaActionParser.js b/_server/MotaActionParser.js
index 3b673eaa..1e97837b 100644
--- a/_server/MotaActionParser.js
+++ b/_server/MotaActionParser.js
@@ -707,6 +707,10 @@ ActionParser.prototype.parseAction = function() {
this.next = MotaActionBlocks['moveEnemyOnPoint_s'].xmlText([
data.from[0], data.from[1], data.to[0], data.to[1], data.floorId||'',this.next]);
break;
+ case "setEquip":
+ this.next = MotaActionBlocks['setEquip_s'].xmlText([
+ MotaActionFunctions.replaceToName_token(data.id), data.valueType||'value', data.name, data["operator"]||'=', this.expandEvalBlock([data.value]), this.next]);
+ break;
case "setFloor":
this.next = MotaActionBlocks['setFloor_s'].xmlText([
data.name, data.floorId||null, JSON.stringify(data.value), this.next]);
diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js
index b983293c..f3d5b6c7 100644
--- a/_server/editor_blockly.js
+++ b/_server/editor_blockly.js
@@ -669,14 +669,18 @@ editor_blockly = function () {
namesObj.allEnemys = Object.keys(core.material.enemys);
if (MotaActionFunctions && !MotaActionFunctions.disableReplace) {
namesObj.allEnemys = namesObj.allEnemys.concat(MotaActionFunctions.pattern.replaceEnemyList.map(function (x) {
- return x[1];
- }))
+ return x[1];
+ }))
}
namesObj.allItems = Object.keys(core.material.items);
+ namesObj.allEquips = namesObj.allItems.filter(function (one) { return core.material.items[one].cls == 'equips' });
if (MotaActionFunctions && !MotaActionFunctions.disableReplace) {
namesObj.allItems = namesObj.allItems.concat(MotaActionFunctions.pattern.replaceItemList.map(function (x) {
- return x[1];
- }))
+ return x[1];
+ }))
+ namesObj.allEquips = namesObj.allEquips.concat(MotaActionFunctions.pattern.replaceItemList.map(function (x) {
+ return x[1];
+ }))
}
namesObj.allAnimates = Object.keys(core.material.animates)
.concat(Object.keys(main.nameMap).filter(function (one) {return core.material.animates[main.nameMap[one]];}));
@@ -710,7 +714,7 @@ editor_blockly = function () {
// 对音效进行补全
// 对全局商店进行补全
// 对楼层名进行补全
- for(var ii=0,names;names=['allIds','allEnemys','allItems','allImages','allAnimates','allBgms','allSounds','allShops','allFloorIds','allDoors','allEvents'][ii];ii++){
+ for(var ii=0,names;names=['allIds','allEnemys','allItems','allEquips','allImages','allAnimates','allBgms','allSounds','allShops','allFloorIds','allDoors','allEvents'][ii];ii++){
if (MotaActionBlocks[type][names] && eval(MotaActionBlocks[type][names]).indexOf(name)!==-1) {
return filter(namesObj[names], content);
}
diff --git a/_server/editor_blocklyconfig.js b/_server/editor_blocklyconfig.js
index 2e9ab074..cf800ae9 100644
--- a/_server/editor_blocklyconfig.js
+++ b/_server/editor_blocklyconfig.js
@@ -124,6 +124,7 @@ editor_blocklyconfig=(function(){
MotaActionBlocks['setEnemyOnPoint_s'].xmlText(),
MotaActionBlocks['resetEnemyOnPoint_s'].xmlText(),
MotaActionBlocks['moveEnemyOnPoint_s'].xmlText(),
+ MotaActionBlocks['setEquip_s'].xmlText(),
MotaActionBlocks['setFloor_s'].xmlText(),
MotaActionBlocks['setGlobalAttribute_s'].xmlText(),
MotaActionBlocks['setGlobalValue_s'].xmlText(),
diff --git a/libs/events.js b/libs/events.js
index 6e0c2966..9f302de6 100644
--- a/libs/events.js
+++ b/libs/events.js
@@ -1208,7 +1208,7 @@ events.prototype.__precompile_getArray = function () {
"closeDoor", "battle", "trigger", "insert", "setEnemyOnPoint", "resetEnemyOnPoint"
];
var values = [
- "setValue", "setEnemy", "setFloor", "setGlobalValue",
+ "setValue", "setEnemy", "setEnemyOnPoint", "setEquip", "setFloor", "setGlobalValue",
];
var uievents = [
"clearMap", "fillText", "fillBoldText", "fillRect", "strokeRect", "fillEllipse", "strokeEllipse",
@@ -1795,6 +1795,11 @@ events.prototype._action_moveEnemyOnPoint = function (data, x, y, prefix) {
core.doAction();
}
+events.prototype._action_setEquip = function (data, x, y, prefix) {
+ core.setEquip(data.id, data.valueType, data.name, data.value, data.operator, prefix);
+ core.doAction();
+}
+
events.prototype._action_setFloor = function (data, x, y, prefix) {
this.setFloorInfo(data.name, data.value, data.floorId, prefix);
core.doAction();
diff --git a/libs/items.js b/libs/items.js
index 0eb64da1..77f1327c 100644
--- a/libs/items.js
+++ b/libs/items.js
@@ -16,7 +16,14 @@ items.prototype._init = function () {
////// 获得所有道具 //////
items.prototype.getItems = function () {
- return core.clone(this.items);
+ var items = core.clone(this.items);
+ var equipInfo = core.getFlag('equipInfo');
+ if (equipInfo) {
+ for (var id in equipInfo) {
+ items[id].equip = core.clone(equipInfo[id]);
+ }
+ }
+ return items;
}
////// “即捡即用类”道具的使用效果 //////
@@ -404,3 +411,25 @@ items.prototype.quickLoadEquip = function (index) {
core.drawTip("成功换上" + index + "号套装");
}
+
+////// 设置装备属性 //////
+items.prototype.setEquip = function (equipId, valueType, name, value, operator, prefix) {
+ var equip = core.material.items[equipId];
+ if (!equip || equip.cls != 'equips') return;
+ var equipInfo = equip.equip || {};
+ if (!equipInfo[valueType]) equipInfo[valueType] = {};
+ var toEquipInfo = core.clone(equipInfo);
+ toEquipInfo[valueType][name] = core.events._updateValueByOperator(core.calValue(value, prefix), equipInfo[valueType][name], operator);
+ // 如果是穿上状态,则还需要直接修改当前数值
+ if (core.hasEquip(equipId)) {
+ // 设置一个临时装备,然后模拟换装操作
+ var tempId = 'temp:' + equipId;
+ core.material.items[tempId] = {'cls': 'equips', 'equip': core.clone(toEquipInfo)};
+ this._loadEquipEffect(tempId, equipId);
+ delete core.material.items[tempId];
+ core.updateStatusBar();
+ }
+ equip.equip = core.clone(toEquipInfo);
+ flags.equipInfo = flags.equipInfo || {};
+ flags.equipInfo[equipId] = core.clone(toEquipInfo);
+}
diff --git a/runtime.d.ts b/runtime.d.ts
index 8f393565..e0a6c239 100644
--- a/runtime.d.ts
+++ b/runtime.d.ts
@@ -2032,6 +2032,18 @@ declare class items {
/** 根据类型获得一个可用的装备孔 */
getEquipTypeByName(name?: string): void
+
+ /**
+ * 设置某个装备的属性并计入存档
+ * @example core.setEquip('sword1', 'value', 'atk', 300, '+='); // 设置铁剑的攻击力数值再加300
+ * @param equipId 装备id
+ * @param valueType 增幅类型,只能是value(数值)或percentage(百分比)
+ * @param name 要修改的属性名称,如atk
+ * @param value 要修改到的属性数值
+ * @param operator 操作符,可选,如+=表示在原始值上增加
+ * @param prefix 独立开关前缀,一般不需要
+ */
+ setEquip(equipId: string, valueType: string, name: string, value: any, operator?: string, prefix?: string): void
}
/** @file ui.js 主要用来进行UI窗口的绘制,如对话框、怪物手册、楼传器、存读档界面等等。*/