一部分任务系统

This commit is contained in:
strawberry 2025-07-29 12:10:18 +08:00
parent 87df9d9e9c
commit 4bc212f292
3 changed files with 291 additions and 18 deletions

View File

@ -1438,6 +1438,9 @@ control.prototype.checkBlock = function () {
var damage = core.status.checkBlock.damage[loc];
if (damage) {
core.status.hero.hp -= damage;
core.taskSystem.tasksInfo.forEach(v => v.tasks.forEach(a => {
if (a.type==="specialBlock"&&core.status.checkBlock.type[loc][a.specialType])a.has++
}))
var text =
Object.keys(core.status.checkBlock.type[loc] || {}).join("") || "伤害";
core.drawTip("受到" + text + damage + "点");

View File

@ -189,7 +189,16 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
} else {
// 每次抵达楼层执行的事件
core.insertAction(core.floors[floorId].eachArrive);
core.taskSystem.tasksInfo.forEach(v => v.tasks.forEach(a => {
switch (a.type) {
case "changeFloor":
a.has++
break;
case "arrival":
if (a.floorId === floorId) a.has = 1
break;
}
}))
// 首次抵达楼层时执行的事件(后插入,先执行)
if (!core.hasVisitedFloor(floorId)) {
core.insertAction(core.floors[floorId].firstArrive);
@ -417,7 +426,29 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
} else {
core.updateStatusBar();
}
core.taskSystem.tasksInfo.forEach(v => v.tasks.forEach(a => {
switch (a.type) {
case "kill":
if (a.kill === enemyId && (!a.floorIds || a.floorIds.includes(core.status.floorId))) a.has++
break
case "killLocs":
a.killLocs.forEach(b => {
if (x === b[0] && y === b[1] && core.status.floorId === b[2]) a.has++
})
break
case "killCount":
if (!a.floorIds || a.floorIds.includes(core.status.floorId)) a.has++
break
case "killSpecial":
if (!a.floorIds || a.floorIds.includes(core.status.floorId)) {
if (core.hasSpecial(special, a.killSpecial)) a.has++
}
break
}
}))
// 如果已有事件正在处理中
if (core.status.event.id == null)
core.continueAutomaticRoute();
@ -1292,7 +1323,8 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
time: new Date().getTime(),
cg: cg,
animateObjs: core.status.animateObjs.filter(v => v.loop),
playing: [...core.plugin.playing].filter(v => v.loop)
playing: [...core.plugin.playing].filter(v => v.loop),
task: core.taskSystem.save()
};
return data;
},
@ -1337,6 +1369,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
core.setFlag("__fromLoad__", true);
// TODO增加自己的一些读档处理
core.taskSystem.load(data.task)
core.ui.statusBar.clearItemInfo();
core.ui.statusBar.update();
core.status.animateObjs = data.animateObjs

View File

@ -27449,24 +27449,261 @@ let time=0
});
},
"任务系统": function () {
// 在此增加新插件
this.task = { //任务总表(键名和id后期改为"floorId+'.'+npc+'.'+Number"的格式,即“楼层名.npc名.任务序号”)
1: { id: 1, name: "寻找丢失的钱袋", text: "梅尔森的钱袋被小偷偷走了,去找到小偷并拿回梅尔森的钱袋", type: "物品" }
}
// 在此增加新插件
class TaskSystem {
constructor() {
this.tasksInfo = []
}
setTask(name, text, info, n) {
this.tasksInfo.push({ name, text, n, tasks: info.map(v => new Task(v)) })
this.tasksInfo[this.tasksInfo.length - 1].complter = this.checkTask(this.tasksInfo.length - 1)
}
checkTask(index) {
if (this.tasksInfo[index].success) return true
else return this.tasksInfo[index].tasks.reduce((a, b) => a + Number(b.check()), 0) >= this.tasksInfo[index].n
}
removeTaskByName(name) {
const index = this.tasksInfo.findIndex(v => v.name === name)
removeTask(index)
}
removeTask(index) {
this.tasksInfo.splice(index, 1)
}
clearTesk() {
this.tasksInfo = []
}
checkAll() {
for (let i = 0; i < this.tasksInfo.length; i++) {
this.checkTask(i)
}
}
submitTask() {
if (!flags.score) flags.score = 0
for (let i = 0; i < this.tasksInfo.length; i++) {
flags.score += Number(this.tasksInfo[i].complter)
}
this.clearTesk()
}
successTesk(index) {
this.tasksInfo[index].success = true
this.tasksInfo[index].complter = true
}
successTeskByName(name) {
const index = this.tasksInfo.findIndex(v => v.name === name)
this.tsuccessTesk(index)
}
save() {
return this.tasksInfo.map(v => {
const c = core.clone(v)
const b = v.tasks.map(a => a.save());
c.tasks = b
return c
})
}
load(data) {
this.tasksInfo = data.map(v => {
const c = core.clone(v)
const b = v.tasks.map(a => new Task(a))
c.tasks = b
return c
})
this.taskAccept = function (id) { //任务接取
let accept = core.getFlag("accept") ?? []; //正在进行任务
let success = core.getFlag("success") ?? []; //已提交任务
let nocontinue = false
accept.forEach(v => { if (v.id === id) nocontinue = ture })
success.forEach(v => { if (v.id === id) nocontinue = ture })
if (nocontinue) return //已接取或已完成该任务return
let task = this.task[id] //获取任务内容
switch (task.type) {
case "物品":
}
break;
}
}
class Task {
constructor(info) {
this.type = info.type
this.text = info.text
if (info.type === "checkItem") {
this.checkItem = info.checkItem
this.count = info.count
this.operator = info.operator
this.has = info.has ?? core.itemCount(this.checkItem)
} else if (info.type === "checkStatus") {
this.checkStatus = info.checkStatus
this.count = info.count
this.operator = info.operator
this.has = core.getRealStatus(this.checkStatus)
} else if (info.type === "checkFlag") {
this.checkFlag = info.checkFlag
this.count = info.count
this.operator = info.operator
this.has = info.has ?? core.getFlag(this.checkFlag)
} else if (info.type === "checkBlock") {
this.checkBlock = info.checkBlock
this.count = info.count
this.operator = info.operator
this.floorIds = info.floorIds
this.has = info.has ?? core.searchBlock(this.checkBlock, this.floorIds).length
} else if (info.type === "checkEnemyType") {
this.checkEnemyType = info.checkEnemyType
this.count = info.count
this.operator = info.operator
this.floorIds = info.floorIds
this.has = info.has ?? core.searchBlockWithFilter(block => block.event.cls.startsWith("enemy") && block.event.type === this.checkEnemyType, this.floorIds).length
} else if (info.type === "kill") {
this.kill = info.kill
this.count = info.count
this.has = info.has ?? 0
this.operator = info.operator
} else if (info.type === "killLocs") {
this.killLocs = info.killLocs
this.count = info.count
this.has = info.has ?? 0
this.operator = info.operator
} else if (info.type === "killCount") {
this.count = info.count
this.has = info.has ?? 0
this.operator = info.operator
} else if (info.type === "killSpecial") {
this.killSpecial = info.killSpecial
this.count = info.count
this.has = info.has ?? 0
this.operator = info.operator
} else if (info.type === "killAll") {
this.floorIds = info.floorIds
this.has = info.has ?? core.searchBlockWithFilter(block => block.event.cls.startsWith("enemy"), this.floorIds).length
} else if (info.type === "specialBlock") {
this.specialType = info.specialType
this.count = info.count
this.has = info.has ?? 0
this.operator = info.operator
} else if (info.type === "changeFloor") {
this.count = info.count
this.has = info.has ?? 0
this.operator = info.operator
} else if (info.type === "arrival") {
this.floorId = info.floorId
this.has = info.has ?? 0
}
}
check() {
if (this.type === "checkItem") return this.checkInfo(this.count, this.has = core.itemCount(this.checkItem))
else if (this.type === "checkStatus") return this.checkInfo(this.count, this.has = core.getRealStatus(this.checkStatus))
else if (this.type === "checkFlag") return this.checkInfo(this.count, this.has = core.getFlag(this.checkFlag))
else if (this.type === "checkBlock") return this.checkInfo(this.count, this.has = core.searchBlock(this.checkBlock, this.floorIds).length)
else if (this.type === "checkEnemyType") return this.checkInfo(this.count, this.has = core.searchBlockWithFilter(block => block.event.cls.startsWith("enemy") && block.event.type === this.checkEnemyType, this.floorIds).length)
else if (this.type === "killAll") return this.has = core.searchBlockWithFilter(block => block.event.cls.startsWith("enemy"), this.floorIds).length, this.has === 0
else if (this.type === "specialBlock" || this.type === "changeFloor" || this.type === "kill" || this.type === "killSpecial" || this.type === "killLocs" || this.type === "killCount") return this.checkInfo(this.count, this.has)
else if (this.type === "arrival") return Boolean(this.has)
else if (this.type === "outer") return false
}
checkInfo(check, has) {
switch (this.operator) {
case "=":
return has === check
case "<":
return has < check
case "<=":
return has <= check
case ">":
return has > check
case ">=":
return has >= check
}
}
save() {
let info = { type: this.type, text: this.text }
if (info.type === "checkItem") {
info.checkItem = this.checkItem
info.count = this.count
info.operator = this.operator
info.has = this.has
} else if (info.type === "checkStatus") {
info.checkStatus = this.checkStatus
info.count = this.count
info.operator = this.operator
info.has = this.has
} else if (info.type === "checkFlag") {
info.checkFlag = this.checkFlag
info.count = this.count
info.operator = this.operator
info.has = this.has
} else if (info.type === "checkBlock") {
info.checkBlock = this.checkBlock
info.count = this.count
info.operator = this.operator
info.floorIds = this.floorIds
info.has = this.has
} else if (info.type === "checkEnemyType") {
info.checkEnemyType = this.checkEnemyType
info.count = this.count
info.operator = this.operator
info.floorIds = this.floorIds
info.has = this.has
} else if (info.type === "kill") {
info.kill = this.kill
info.count = this.count
info.has = this.has
info.operator = this.operator
} else if (info.type === "killLocs") {
info.killLocs = this.killLocs
info.count = this.locs.length
info.has = this.has
info.operator = this.operator
} else if (info.type === "killCount") {
info.count = this.count
info.has = this.has
info.operator = this.operator
} else if (info.type === "killSpecial") {
info.killSpecial = this.killSpecial
info.count = this.count
info.has = this.has
info.operator = this.operator
} else if (info.type === "killAll") {
info.floorIds = this.floorIds
info.has = this.has
} else if (info.type === "specialBlock") {
info.specialType = this.specialType
info.count = this.count
info.has = this.has
info.operator = this.operator
} else if (info.type === "changeFloor") {
info.count = this.count
info.has = this.has
info.operator = this.operator
} else if (info.type === "arrival") {
info.floorId = this.floorId
info.has = this.has
}
return info
}
}
core.taskSystem = new TaskSystem()
core.registerEvent("setTask", (data) => {
core.taskSystem.setTask(data.name, data.text, data.info, data.n)
core.doAction()
})
core.registerEvent("removeTask", (data) => {
core.taskSystem.removeTask(data.index)
core.doAction()
})
core.registerEvent("removeTaskByName", (data) => {
core.taskSystem.removeTaskByName(data.name)
core.doAction()
})
core.registerEvent("successTask", (data) => {
core.taskSystem.successTask(data.index)
core.doAction()
})
core.registerEvent("successTaskByName", (data) => {
core.taskSystem.successTaskByName(data.name)
core.doAction()
})
core.registerEvent("clearTask", () => {
core.taskSystem.clearTask()
core.doAction()
})
core.registerEvent("submitTask", () => {
core.taskSystem.submitTask()
core.doAction()
})
}
}