init: add workspace files

This commit is contained in:
2026-05-26 16:41:20 +08:00
commit f4f2393f72
1041 changed files with 67405 additions and 0 deletions

49
os/task/events.js Normal file
View File

@@ -0,0 +1,49 @@
EVENTS = function () {
}
EVENTS.inherits(BASE);
EVENTS.add = function (item) {
if (!item || !item.id) return;
Object.setPrototypeOf(item, EVENT_BASE);
const items = WORLD.USER_EVENTS;
for (var i = 0; i < items.length; i++) {
if (items[i].id == item.id) {
items[i] = item;
return this.notify(item, 1);
}
}
items.push(item);
this.notify(item, 0);
}
EVENTS.ACTIONS = ['add', 'update', 'finish'];
EVENTS.notify = function (item, act) {
let users = WORLD.USERS;
let msg = `{type: "dialog", dialog: "events",${EVENTS.ACTIONS[act]}:1}`;
for (let user of users) {
if (!user.socket) continue;
if (item.check && !item.check(user))
continue;
user.send(msg);
}
}
EVENTS.remove = function (id) {
if (!id) return;
const items = WORLD.USER_EVENTS;
for (var i = 0; i < items.length; i++) {
if (items[i].id == id) {
EVENTS.notify(items[i], 2);
return items.splice(i, 1);
}
}
}
const EVENT_BASE = {
query_desc: function () {
return this.desc;
},
query_grade: function () {
return this.grade;
}
};

48
os/task/playertask.js Normal file
View File

@@ -0,0 +1,48 @@
require("../util/util");
USERTASK = function () {
}
USERTASK.inherits(BASE);
USERTASK.prototype.create = function (path) {
WORLD.TASKS.push(this);
this.on_create && this.on_create();
}
USERTASK.prototype.update = function (path) {
this.on_create && this.on_create();
for (var i = 0; i < WORLD.TASKS.length; i++) {
if (WORLD.TASKS[i].path == path) {
WORLD.TASKS[i] = this;
return;
}
}
WORLD.TASKS.push(this);
}
USERTASK.prototype.query_title = function () {
}
USERTASK.prototype.start = function () {
}
USERTASK.prototype.query_desc = function () {
}
USERTASK.prototype.query_state = function () {
//0 不显示 1进行中2.可领取 3.已完成
}
USERTASK.RUN = function (id, player) {
for (var i = 0; i < WORLD.TASKS.length; i++) {
if (WORLD.TASKS[i].id == id) {
return WORLD.TASKS[i].start(player);
}
}
return false;
}
USERTASK.GET = function (id) {
for (var i = 0; i < WORLD.TASKS.length; i++) {
if (WORLD.TASKS[i].id == id) {
return WORLD.TASKS[i];
}
}
}

36
os/task/task.js Normal file
View File

@@ -0,0 +1,36 @@
TASK = function () {
}
TASK.inherits(BASE);
TASK.prototype.create = function () {
WORLD.SYSTEMTASKS.push(this);
this.startup();
}
TASK.GET = function (id) {
for (var i = 0; i < WORLD.SYSTEMTASKS.length; i++) {
if (WORLD.SYSTEMTASKS[i].id == id) {
return WORLD.SYSTEMTASKS[i];
}
}
}
TASK.prototype.update = function (path) {
var oldtask = null;
for (var i = 0; i < WORLD.SYSTEMTASKS.length; i++) {
if (WORLD.SYSTEMTASKS[i].path == path) {
WORLD.SYSTEMTASKS[i].stop();
oldtask = WORLD.SYSTEMTASKS[i];
WORLD.SYSTEMTASKS[i] = this;
}
}
if (!oldtask) {
WORLD.SYSTEMTASKS.push(this);
}
this.startup(oldtask);
}
TASK.prototype.startup = function () {
}
TASK.prototype.stop = function () {
}