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

69
os/item/container.js Normal file
View File

@@ -0,0 +1,69 @@
require("./obj.js");
CONTAINER = function () {
this.count = 1;
this.combined = false;
}
CONTAINER.inherits(OBJ);
CONTAINER.prototype.is_container = true;
CONTAINER.prototype.on_get = function () {
return false;
}
CONTAINER.prototype.set_items = function () {
for (var i = 0; i < arguments.length; i++) {
var item = arguments[i];
if (item) {
if (typeof item == "string") {
OBJ.clone_to(item, this);
} else if (item.length) {
OBJ.clone_to(item[0], this,item[1]);
}
}
}
}
CONTAINER.prototype.query_items = function () {
return this.items;
}
//这个单纯的字符串描述
CONTAINER.prototype.get_desc = function (me) {
var str = [this.color_name, this.desc];
var items = this.query_items(me);
if (items && items.length) {
str.push("它里面有:");
for (var i = 0; i <items.length; i++) {
var item = items[i];
str.push("\t" + UTIL.to_c(item.count) + item.unit + item.color_name);
}
} else {
str.push("它里面什么都没有。");
}
return str.join("\n");
}
CONTAINER.prototype.clear_items = function (me) {
this.items.length = 0;
}
//这个提供给LOOK SELECT命令的
CONTAINER.prototype.query_desc = function (me) {
if (this.json) return this.json;
var obj = {};
obj.type = "item";
obj.id = this.id;
obj.desc = this.get_desc(me);
obj.commands = [];
obj.commands.push({
cmd: "get all from " + this.id,
name: "全部拾取"
});
this.json = JSON.stringify(obj)
return this.json;
}
CONTAINER.CREATE = function (name,desc,lv,odds) {
var obj = OBJ.CREATE("sp/box#lv");
obj.items = OBJ.create_by_odds(odds);
obj.name = name;
obj.desc = desc || obj.desc;
obj.grade = lv;
obj.create();
return obj;
}

71
os/item/corpse.js Normal file
View File

@@ -0,0 +1,71 @@
require("../item/obj.js");
CORPSE = function () {
this.unit = "具";
this.count = 1;
this.no_alloc = false;
}
CORPSE.inherits(CONTAINER);
CORPSE.prototype.on_get = function (player) {
return false;
}
CORPSE.prototype.init = function (player, iskeep) {
this.create_id();
this.fromid = player.id;
this.name = player.name + "的尸体";
this.color_name = "<wht>" + this.name + "</wht>";
this.environment = player.environment;
this.desc = "然而" + player.call3() + "已经死了,只剩下一具尸体静静地躺在这里。";
this.items = player.query_drop();
if (!iskeep) this.call_out(this.disappear, 60000);
}
CORPSE.prototype.query_items = function (player) {
if (this.environment.is_fb() && player.team) {
if (!this.no_drops) {
this.no_drops = [];
for (var i = 0; i < player.team.length; i++) {
if (!this.environment.query_temp(player, player.team[i].id)) {
this.no_drops.push(player.team[i].id);
}
}
this.on_getitem = this.check_get;
}
}
return this.items;
}
CORPSE.prototype.clear_items = function (me, noget) {
this.items.length = 0;
if (noget && noget.length) this.items = noget;
}
CORPSE.prototype.check_get = function (player, item) {
if (!this.no_drops) return true;
if (this.no_drops.indexOf(player.id) == -1) return true;
player.notify('你不可以拾取' + item.color_name + "。");
return false;
}
CORPSE.prototype.disappear = function () {
if (this.items) this.items.length = 0;
if (this.environment) {
this.environment.notify("一阵风吹去," + this.name + "已经不见了。");
this.environment.item_changed(this, false);
}
}
CORPSE.prototype.query_desc = function (me) {
if (this.json) return this.json;
var obj = {};
obj.type = "item";
obj.desc = this.get_desc(me);
obj.id = this.id;
obj.commands = [];
obj.commands.push({
cmd: "get all from " + this.id,
name: "全部拾取"
});
if (this.no_alloc) {
return JSON.stringify(obj);
}
this.json = JSON.stringify(obj);
return this.json;
}

450
os/item/equipment.js Normal file
View File

@@ -0,0 +1,450 @@
require("../util/util.js");
EQUIPMENT = function () {
this.eq_type = EQUIP_TYPE.WEAPON;
this.level = 0;
this.exp = 0;
this.grade = 0;
this.count = 1;
this.combined = false;
this.showAction = true;
this.allow_fight = true;
this.otype = 4;
}
EQUIPMENT.inherits(OBJ);
EQUIPMENT.prototype.is_equipment = true;
EQUIPMENT.prototype.transable = true;
//EQUIPMENT.prototype.eq_msg = "$N装备上$n。";
//EQUIPMENT.prototype.uneq_msg = "$N脱下$n。";
EQUIPMENT.prototype.change_prop = function (me, is_attach) {
me.change_prop(this.prop, is_attach);
if (this.st_prop) {
for (var i = 0; i < this.st_prop.length; i++) {
me.change_prop(this.st_prop[i].prop, is_attach);
}
}
}
EQUIPMENT.prototype.notify_action = function (me, isadd) {
if (!this.on_use) return;
isadd = me.equipment[this.eq_type] == this;
if (isadd)
me.send("{type:'addAction',id:'" + this.id + "',name:'" + this.name + "',distime:" + (this.distime || 0) + "}");
else
me.send("{type:'removeAction',id:'" + this.id + "'}");
}
EQUIPMENT.prototype.check = function (me) {
if (!this.condition) return true;
for (var key in this.condition) {
var val = this.condition[key];
switch (key) {
case "skill":
for (var sk in val) {
if (me.query_skill(sk, 0) < val[sk]) {
var sk_base = SKILL.get(sk);
return me.notify_fail("你的" + sk_base.color_name + "等级不够" + val[sk] + ",无法装备" + this.color_name + "。");
}
}
break;
case "str1":
case "con1":
case "dex1":
case "int1":
if (me[key.replace("1", "")] < val) {
return me.notify_fail("你的先天" + PROPERTIES[key] + "不够" + val + ",无法装备" + this.color_name + "。");;
}
break;
case "str":
case "con":
case "dex":
case "int":
if (me[key] + me.query_prop(key) < val) {
return me.notify_fail("你的" + PROPERTIES[key] + "不够" + val + ",无法装备" + this.color_name + "。");;
}
break;
case "gender":
if (me.gender != val) return me.notify_fail("你不是" + (val == 1 ? "男性" : "女性") + ",无法装备" + this.color_name + "。");
break;
case "desc":
break;
default:
var me_val = me[key] || 0;
me_val = me_val + me.query_prop(key);
if (!me_val || me_val < val) {
return me.notify_fail("你的" + PROPERTIES[key] + "不够" + val + ",无法装备" + this.color_name + "。");;
}
break;
}
}
return true;
}
EQUIPMENT.prototype.eq = function (me, notsend) {
if (this.check(me) == false) {
return false;
}
if (this.on_eq && this.on_eq(me) == false) {
return false;
}
this.change_prop(me, true);
this.check_group(me, true);
//me.add_score(this.query_score());
if (!notsend) {
if (this.eq_msg)
me.send_room(this.eq_msg, this);
else {
var msg;
switch (this.eq_type) {
case EQUIP_TYPE.WEAPON:
msg = "$N抽出一" + this.unit + this.color_name + "拿在手上。";
break;
case EQUIP_TYPE.CLOTH:
case EQUIP_TYPE.SHOES:
case EQUIP_TYPE.PANTS:
msg = "$N穿上一" + this.unit + this.color_name + "。";
break;
case EQUIP_TYPE.RING:
msg = "$N拿出一" + this.unit + this.color_name + "戴在手上。";
break;
case EQUIP_TYPE.NECKLACE:
case EQUIP_TYPE.JEWELS:
case EQUIP_TYPE.WRIST:
msg = "$N戴上一" + this.unit + this.color_name + "。";
break;
default:
msg = "$N装备上一" + this.unit + this.color_name + "。";
break;
}
me.send_room(msg, this);
}
}
me.send('{type:"dialog",dialog:"pack",id:"' + this.id + '",eq:' + this.eq_type + '}');
}
EQUIPMENT.prototype.uneq = function (me, notsend) {
this.on_uneq && this.on_uneq(me);
this.change_prop(me, false);
this.check_group(me, false);
//me.add_score(-this.query_score());
if (!notsend) {
if (this.uneq_msg)
me.send_room(this.uneq_msg, this);
else {
var msg;
switch (this.eq_type) {
case EQUIP_TYPE.WEAPON:
msg = "$N收回手中的" + this.color_name + "。";
break;
case EQUIP_TYPE.CLOTH:
case EQUIP_TYPE.SHOES:
case EQUIP_TYPE.PANTS:
case EQUIP_TYPE.WRIST:
msg = "$N将" + this.color_name + "脱了下来。";
break;
case EQUIP_TYPE.RING:
case EQUIP_TYPE.NECKLACE:
case EQUIP_TYPE.JEWELS:
msg = "$N将" + this.color_name + "取了下来。";
break;
default:
msg = "$N脱下一" + this.unit + this.color_name + "。";
break;
}
me.send_room(msg, this);
}
}
me.send('{type:"dialog",dialog:"pack",id:"' + this.id + '",uneq:' + this.eq_type + '}');
}
EQUIPMENT.prototype.condition_tostring = function (str) {
if (!this.condition) return;
for (var key in this.condition) {
var val = this.condition[key];
switch (key) {
case "skill":
for (var sk in val) {
var sk_base = SKILL.get(sk);
str.push(sk_base.name + "要求:" + val[sk] + "级");
}
break;
case "desc":
str.push(desc);
break;
case "gender":
str.push("性别要求:" + (val == 1 ? "男" : "女"));
break;
default:
str.push(PROPERTIES[key] + "要求:" + val);
break;
}
str.push("\n");
}
}
EQUIPMENT.prototype.parts = ['武器', '衣服', '鞋', '头部', '披风', '戒指', '项链', '饰品', '护腕', '腰带', '暗器'];
EQUIPMENT.prototype.qualities = ["普通", "精良", "高级", "稀有", "绝世", "传说", "神器"];
EQUIPMENT.prototype.get_desc = function (me) {
var str = [this.color_name];
str.push("\n");
str.push(this.parts[this.eq_type]);
//str.push("\n");
//str.push(this.query_quality());
str.push("\n");
this.condition_tostring(str);
if (this.desc) str.push(this.desc);
str.push("\n");
if (this.prop) {
str.push("<");
str.push(this.query_grade_color());
str.push(">");
str.push(UTIL.prop_toString(this.prop));
str.push("</");
str.push(this.query_grade_color());
str.push(">\n");
}
if (this.st_prop) {
for (var i = 0; i < this.st_prop.length; i++) {
str.push(this.st_prop[i].name);
str.push("\n");
}
}
if (this.hole_count) {
for (var i = 0; i < this.hole_count; i++) {
str.push("◇");
}
}
this.query_group_desc(me, str);
return str.join("");
}
EQUIPMENT.prototype.query_quality = function () {
return this.qualities[this.grade];
}
const level_desc = ["", "☆", "★", "★☆", "★★", "★★☆", "★★★",
"★★★☆", "★★★★", "★★★★☆", "★★★★★", "★★★★★☆", "★★★★★★"];
EQUIPMENT.prototype.level_up = function (lev) {
var cc = this.query_grade_color();
this.prop = {};
this.level = lev;
this.levelchange_prop();
this.color_name = "<" + cc + ">" + level_desc[this.level] + this.name + "</" + cc + ">";
this.json = null;
}
EQUIPMENT.prototype.levelData = [
0, 10, 20, 40, 70, 110, 160, 220, 290, 370, 460, 560, 670
];
EQUIPMENT.prototype.levelchange_prop = function () {
if (!(this.level >= 0 && this.level < 13)) return;
const base_props = this.original_prop ?? Object.getPrototypeOf(this).prop;
var val = this.levelData[this.level];
for (var key in base_props) {
var value = base_props[key];
switch (key) {
case "desc":
case "str1":
case "con1":
case "dex1":
case "int1":
case "per":
case "kar":
case "skill":
this.prop[key] = value;
break;
case "fy_per":
case "zj_per":
case "mz_per":
case "hp_per":
case "ds_per":
case "gj_per":
case "diff_busy":
case "busy_per":
case "caiyao1":
case "diaoyu1":
case "kuang1":
case "lianyao1":
case "diff_sh":
case "expend_mp":
this.prop[key] = value + parseInt(value * val / 1000);
break;
case "diff_downside_per":
case "gjsd":
case "releasetime":
case "distime":
case "diff_downside":
case "distime_per":
case "releasetime_per":
case "gjsd_per":
case "bj_per":
case "diff_bj":
case "add_bjsh_per":
case "add_sh_per":
case "diff_busy_per":
case "diff_sh_per":
case "diff_fy_per":
case "expend_mp_per":
case "busy":
this.prop[key] = value;
break;
default:
if (PROPERTIES[key])
this.prop[key] = value + parseInt(value * val / 100);
else
this.prop[key] = value;
break;
}
}
}
EQUIPMENT.prototype.clear_stone = function () {
if (!this.st_prop) return;
this.hole_count += (this.st_prop.length);
this.st_prop.length = 0;
}
EQUIPMENT.prototype.push_stone = function (stone) {
if (!stone || !stone.prop) return false;
if (!this.hole_count) return false;
if (!this.st_prop) this.st_prop = [];
this.hole_count--;
var cc = stone.query_grade_color();
var str = ["<", cc, ">◆", stone.name, " "];
str.push(UTIL.prop_toString(stone.prop, " "));
str.push("</");
str.push(cc);
str.push(">");
this.json = null;
this.st_prop.push({
id: stone.id,
path: stone.path,
name: str.join(""),
prop: stone.prop,
grade: stone.grade
});
}
EQUIPMENT.prototype.clone = function (me) {
var obj = OBJ.CREATE(this.path);
if (this.temp) {
obj.temp = {};
for (var key in this.temp) {
obj.temp[key] = this.temp[key];
}
}
obj.on_reload && obj.on_reload(me);
obj.level_up(this.level);
obj.st_prop = this.st_prop;
return obj;
}
EQUIPMENT.prototype.save_db = function (str) {
str.push('["', this.path, '","', this.id, '",', this.level);
if (this.st_prop && this.st_prop.length) {
str.push(",[");
for (var i = 0; i < this.st_prop.length; i++) {
if (i > 0) str.push(",");
str.push('"', this.st_prop[i].path, '"');
}
str.push("]");
}
// else {
// str.push(',[]');
// }
if (this.is_locked)
str.push(',1');
if (this.temp)
str.push(",", this.format_temp(this.temp));
str.push("]");
}
EQUIPMENT.prototype.load_db = function (data) {
//const [path, id, level, sts, locked,temp] = data;
this.id = data[1];
if (data[2] > 0) {
this.level = data[2];
}
for (let i = 3; i < data.length; i++) {
let value = data[i];
if (value === 1) this.is_locked = true;
else if (Array.isArray(value)) {
for (var j = 0; j < value.length; j++) {
var st_item = OBJ.CREATE(value[j]);
if (st_item) {
this.push_stone(st_item);
}
}
} else if (typeof value === 'object') {
this.temp = value;
}
}
}
EQUIPMENT.prototype.on_load = function (me) {
this.on_reload && this.on_reload(me);
if (this.level > 0) {
this.level_up(this.level);
}
}
EQUIPMENT.prototype.VALUES = [100, 1000, 2000, 10000, 100000, 1000000, 100000000];
EQUIPMENT.prototype.on_create = function (path, par) {
this.value = this.VALUES[this.grade];
}
EQUIPMENT.prototype.query_group_desc = function (me, str) {
if (!this.group_prop || !this.group_name) return;
var count = 0;
if (me && me.equipment) {
for (var i = 0; i < me.equipment.length; i++) {
if (me.equipment[i] && me.equipment[i].group_name == this.group_name) {
count++;
}
}
}
for (var i = 2; i < 8; i++) {
var prop = this.group_prop(i);
if (prop) {
var cc = i <= count ? this.query_grade_color() : "blk";
str.push("<");
str.push(cc);
str.push(">");
str.push("\n");
str.push(UTIL.to_c(i));
str.push("件套:");
str.push(UTIL.prop_toString(prop, " "));
str.push("</");
str.push(cc);
str.push(">");
}
}
}
EQUIPMENT.prototype.check_group = function (me, isadd) {
if (!this.group_prop || !this.group_name) return;
var count = isadd ? 1 : 0;
for (var i = 0; i < me.equipment.length; i++) {
if (me.equipment[i] && me.equipment[i].group_name == this.group_name) {
count++;
}
}
var prop = this.group_prop(count);
if (prop) {
me.change_prop(prop, isadd);
}
}

25
os/item/money.js Normal file
View File

@@ -0,0 +1,25 @@
require("../item/obj.js");
MONEY = function () {
this.is_cash = false;
this.combined = true;
this.count = 1;
}
MONEY.inherits(OBJ);
MONEY.prototype.is_money = true;
MONEY.prototype.transable = true;
MONEY.prototype.create = function () {
this.create_id();
if (this.is_cash) {
this.color_name = "<hio>" + this.name + "</hio>";
} else {
if (this.value == 1)
this.color_name = "<yel>" + this.name + "</yel>";
else if (this.value == 100)
this.color_name = "<hiw>" + this.name + "</hiw>";
else
this.color_name = "<hiy>" + this.name + "</hiy>";
}
}

228
os/item/obj.js Normal file
View File

@@ -0,0 +1,228 @@
OBJ = function () {
this.unit = "个";
this.path = null;
this.count = 1;
this.combined = true;
this.grade = 0;
this.otype = 0;
}
OBJ.inherits(ITEM);
OBJ.prototype.transable = false;
OBJ.prototype.init = function (me) {
this.on_init && this.on_init(me);
}
OBJ.prototype.long_name = function () {
if (this.combined) return UTIL.to_c(this.count) + this.unit + this.color_name;
return this.color_name;
}
OBJ.prototype.unit_name = function (count) {
return UTIL.to_c(count || this.count) + this.unit + this.color_name;
}
OBJ.prototype.item_to_json = function () {
return `["${this.name}","${this.id}",${this.count},${this.grade},"${this.unit}",${parseInt(this.value / 10)},${this.is_equipment ? 1 : 0},${this.on_use ? 1 : 0},${this.on_study ? 1 : 0},${this.on_open ? 1 : 0},${this.combine_count > 0 ? this.combine_count : 0}]`;
}
OBJ.prototype.query_commands = function (me) {
return this.query_desc(me);
}
OBJ.prototype.query_desc = function (me) {
if (this.json) return this.json;
var obj = {};
obj.type = "item";
obj.id = this.id;
obj.desc = this.get_desc(me);
obj.commands = [];
obj.commands.push({
cmd: "get " + this.id,
name: "捡起"
});
this.json = JSON.stringify(obj)
return this.json;
}
OBJ.prototype.get_desc = function () {
return this.color_name + "\n" + this.desc;
}
OBJ.prototype.uncombine = function (spcount) {
if (!spcount || spcount === this.count) return this;
if (spcount < this.count) {
var item = this.clone();
item.count = spcount;
this.count -= spcount;
return item;
}
}
OBJ.prototype.clone = function () {
var item = OBJ.CREATE(this.path);
if (this.temp) {
item.temp = Object.assign({}, this.temp);
}
return item;
}
OBJ.prototype.combineTemp = function (target, source) {
if (!source) return target;
if (!target) return source;
for (let key in source) {
let val = source[key];
if (val && typeof val === "number") {
let thisVal = target[key];
if (!thisVal) {
target[key] = val;
} else if (typeof thisVal === "number") {
target[key] = thisVal > val ? thisVal : val;
}
}
}
return target;
}
OBJ.prototype.combine = function (obj) {
if (this.is(obj)) {
if (obj.temp || this.temp) {
this.temp = this.combineTemp(this.temp, obj.temp);
}
this.count += (obj.count || 0);
}
}
OBJ.clone_to = function (otype, to, count) {
if (!otype || !to) return;
var item = OBJ.CREATE(otype);
if (!item) return;
count = count || 1;
if (item.is_money && to.money != undefined) {
item.count = count;
to.money += item.value * item.count;
return item;
}
if (!to.items) to.items = [];
if (item.combined) {
for (var i = 0; i < to.items.length; i++) {
if (to.items[i].is(item)) {
to.items[i].count += count;
return to.items[i];
}
}
item.count = count;
to.items.push(item);
} else {
to.items.push(item);
for (var i = 0; i < count - 1; i++) {
item = OBJ.CREATE(otype, 1);
to.items.push(item);
}
}
return item;
}
OBJ.prototype.save_db = function (str) {
str.push('["', this.path, '","', this.id, '",', this.count);
if (this.is_locked) {
str.push(',1');
}
if (this.temp)
str.push(",", this.format_temp(this.temp));
str.push(']');
}
OBJ.prototype.load_db = function (data) {
//path, id, count, temp or lock
this.id = data[1];
if (data[2] > 1) this.count = data[2];
if (data[3]) {
if (data[3] === 1) {
this.is_locked = true;
} else if (typeof data[3] === 'object') {
this.temp = data[3];
return;
}
}
if (data[4]) this.temp = data[4];
}
OBJ.prototype.on_load = function (me) {
this.on_reload && this.on_reload(me);
}
OBJ.prototype.on_clone = function () {
}
OBJ.CREATE = function (otype, count) {
let base = WORLD.OBJ_STROE.get(otype);
if (!base) {
base = BASE.CREATE(__PATH.OBJ, otype);
if (!base) throw new Error('没有物品' + otype + "的定义。");
//这里会自己调用create方法存储到OBJ_STROE记住了吗
}
// var item = BASE.CREATE(__PATH.OBJ, otype);
// if (!item) return;
let item = Object.create(base);
item.create_id();
item.on_clone();
if (count > 1)
item.count = count;
return item;
}
var grade_color = ["wht", "hig", "hic", "hiy", "HIZ", "hio", "ord"];
OBJ.prototype.create = function (path, par) {
if (par) this.path = path + par;
this.create_id();
this.on_create && this.on_create(path, par);
var cc = grade_color[this.grade];
this.color_name = "<" + cc + ">" + this.name + "</" + cc + ">";
WORLD.OBJ_STROE.set(this.path, this);
}
OBJ.prototype.update = function (path, par) {
this.create(path, par);
}
OBJ.prototype.query_grade_color = function () {
return grade_color[this.grade];
}
OBJ.prototype.notify_action = function (me, isadd) {
if (!this.on_use) return;
if (!this.showAction) return;
if (isadd)
me.send("{type:'addAction',id:'" + this.id + "',name:'" + this.name + "',distime:" + (this.distime || 0) + "}");
else
me.send("{type:'removeAction',id:'" + this.id + "'}");
}
OBJ.prototype.query_temp = CHARACTER.prototype.query_temp;
OBJ.prototype.set_temp = CHARACTER.prototype.set_temp;
OBJ.prototype.remove_temp = CHARACTER.prototype.remove_temp;
OBJ.prototype.add_temp = CHARACTER.prototype.add_temp;
OBJ.create_by_odds = function (args) {
var items = [];
if (!args) return items;
let drop = null, per = null,
obj = null;
for (var i = 0; i < args.length; i++) {
drop = args[i];
if (!drop) continue;
per = Math.random() * 10000;
obj = (drop.odds || 10000) > per ? drop.obj : drop.fall_obj;
if (obj) {
if (drop.min_count) hit_count = 0;
var count = drop.count || 1;
if (drop.min && drop.max) {
count = Math.floor(Math.random() * (drop.max - drop.min + 1)) + drop.min;
}
if (count > 0) {
if (obj instanceof Array) obj = obj.random();
items.push(OBJ.CREATE(obj, count));
}
}
}
return items;
}