|
|
@@ -1223,49 +1223,8 @@ window.pickupItem = async function() {
|
|
|
|
|
|
// 使用物品函数
|
|
|
window.useItem = async function() {
|
|
|
- if (shouldStopExecution || isColliding.value || isSliding.value) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //取人物当前位置
|
|
|
- let x = playerPosition.value.x;
|
|
|
- let y = playerPosition.value.y;
|
|
|
- let tileMap = walkablePointsMap.get(`${x},${y}`);
|
|
|
-
|
|
|
- // 判断当前位置是否有特殊需求
|
|
|
- if (tileMap && tileMap.type === BLOCKLY_MAP_TYPE_DICT.TASK) {
|
|
|
- // 检查玩家是否携带了需要的物品
|
|
|
- const requiredItems = tileMap.type;
|
|
|
-
|
|
|
- let hasRequiredItem = false;
|
|
|
- let itemIndex = -1;
|
|
|
-
|
|
|
- if (gameState.player.carriedItems.length > 0) {
|
|
|
- hasRequiredItem = true;
|
|
|
- itemIndex = 0;
|
|
|
- }
|
|
|
-
|
|
|
- if (hasRequiredItem) {
|
|
|
-
|
|
|
- // 获取要使用的物品
|
|
|
- const itemToUse = gameState.player.carriedItems[itemIndex];
|
|
|
- // 从携带物品中移除已使用的物品
|
|
|
- gameState.player.carriedItems.splice(itemIndex, 1);
|
|
|
- // 执行物品使用动画,传递finishAnimation
|
|
|
- await animateItemUse(itemToUse, itemIndex, tileMap.finishAnimation);
|
|
|
-
|
|
|
- // 使用物品成功
|
|
|
- showGameMessage(tileMap.finishedTip || CONFIG.TIPS.USE_ITEM_SUCCESS, 'success');
|
|
|
-
|
|
|
- } else {
|
|
|
- // 提示缺少所需物品
|
|
|
- showGameMessage(tileMap.unfinishedTip || CONFIG.TIPS.USE_SPECIAL_ITEM, 'warning');
|
|
|
- }
|
|
|
- } else {
|
|
|
- showGameMessage(CONFIG.TIPS.NO_USE_ITEM, 'info');
|
|
|
- }
|
|
|
-
|
|
|
- await new Promise(resolve => setTimeout(resolve, CONFIG.DELAY.ACTION_DELAY));
|
|
|
+ // 调用修建函数,修建函数已经包含了使用物品的逻辑
|
|
|
+ await window.construct();
|
|
|
}
|
|
|
|
|
|
// 暂停函数
|
|
|
@@ -1329,15 +1288,59 @@ window.playSound = async function() {
|
|
|
await new Promise(resolve => setTimeout(resolve, CONFIG.DELAY.PALY_MP3_TIMES));
|
|
|
};
|
|
|
|
|
|
-// 修建函数
|
|
|
+// 修建函数(通用任务处理函数)
|
|
|
window.construct = async function() {
|
|
|
if (shouldStopExecution || isColliding.value || isSliding.value) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- await new Promise(resolve => setTimeout(resolve, CONFIG.DELAY.TEMP_ITEM_FADE_DURATION));
|
|
|
- //处理特殊任务消失
|
|
|
- processingSpecialTasksDisappearing()
|
|
|
+ //取人物当前位置
|
|
|
+ let x = playerPosition.value.x;
|
|
|
+ let y = playerPosition.value.y;
|
|
|
+ let tileMap = walkablePointsMap.get(`${x},${y}`);
|
|
|
+
|
|
|
+ // 判断当前位置是否有特殊需求
|
|
|
+ if (tileMap && tileMap.type === BLOCKLY_MAP_TYPE_DICT.TASK) {
|
|
|
+ // 检查是否需要物品
|
|
|
+ if (tileMap.needItem) {
|
|
|
+ // 检查玩家是否携带了需要的物品
|
|
|
+ let hasRequiredItem = false;
|
|
|
+ let itemIndex = -1;
|
|
|
+
|
|
|
+ // 查找玩家携带的物品
|
|
|
+ for (let i = 0; i < gameState.player.carriedItems.length; i++) {
|
|
|
+ const item = gameState.player.carriedItems[i];
|
|
|
+ // 检查物品是否匹配任务需求
|
|
|
+ if (item.type === tileMap.needItem || !tileMap.needItem) {
|
|
|
+ hasRequiredItem = true;
|
|
|
+ itemIndex = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hasRequiredItem) {
|
|
|
+ // 获取要使用的物品
|
|
|
+ const itemToUse = gameState.player.carriedItems[itemIndex];
|
|
|
+ // 从携带物品中移除已使用的物品
|
|
|
+ gameState.player.carriedItems.splice(itemIndex, 1);
|
|
|
+ // 执行物品使用动画
|
|
|
+ await animateItemUse(itemToUse, itemIndex, tileMap.finishAnimation);
|
|
|
+ // 使用物品成功
|
|
|
+ showGameMessage(tileMap.finishedTip || CONFIG.TIPS.USE_ITEM_SUCCESS, 'success');
|
|
|
+ } else {
|
|
|
+ // 提示缺少所需物品
|
|
|
+ showGameMessage(tileMap.unfinishedTip || CONFIG.TIPS.USE_SPECIAL_ITEM, 'warning');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 不需要物品的任务,直接处理
|
|
|
+ await new Promise(resolve => setTimeout(resolve, CONFIG.DELAY.TEMP_ITEM_FADE_DURATION));
|
|
|
+ processingSpecialTasksDisappearing();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ showGameMessage(CONFIG.TIPS.NO_USE_ITEM, 'info');
|
|
|
+ }
|
|
|
+
|
|
|
+ await new Promise(resolve => setTimeout(resolve, CONFIG.DELAY.ACTION_DELAY));
|
|
|
};
|
|
|
|
|
|
// 当经过指定形状时执行的函数(返回布尔值,可作为参数使用)
|