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

76
world/cmd/dialog/cha.js Normal file
View File

@@ -0,0 +1,76 @@
this.inherits(COMMAND);
this.command = "cha,skills";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.allow_faint = true;
this.enter = function (me, arg) {
var target = me;
var isfollower = false;
if (arg) {
if (arg == "none") return me.notify('{"type":"dialog","dialog":"skills","limit":' + me.skill_limit() + "}");
target = me.find_obj(arg, me.environment);
if (!target && me.user_level > 1) {
target = WORLD.getUser(arg);
}
if (!target) {
return me.notify("这里没有这个人。");
}
if (target.master == me.id) {
isfollower = true;
} else {
if (target.on_checkskill) {
if (target.on_checkskill(me) == false) return;
} else {
if (me.user_level < 4 && !target.is(me.query_temp("master")))
return me.notify("你只能查看自己师父的技能。");
}
}
}
this.render_skill(me, target, isfollower);
}
this.render_skill = function (me, target, isfollower) {
var skills = target.skills;
var str = ['{"type":"dialog","dialog":"'];
str.push(me === target ? 'skills' : 'master');
str.push('","items":[');
if (skills) {
var skill_count = 0;
for (var skid in skills) {
var skill_base = SKILL.get(skid);
if (!skill_base) continue;
if (skill_count > 0) str.push(",");
skill_base.item_to_json(str, skills[skid], target);
skill_count++;
}
}
str.push('],title:"');
str.push(target == me ? "你" : target.name);
str.push(skill_count > 0 ? "共学会" + skill_count + "项技能" : "没有学会任何技能");
str.push('"');
str.push(',limit:');
if (isfollower)
str.push(target.skill_limit());
else
str.push(me.skill_limit());
str.push(',pot:');
str.push(me.pot);
if (target !== me) {
str.push(isfollower ? ",follower:\"" : ',master:\"');
str.push(target.id);
str.push("\"");
if (isfollower) {
str.push(',target:\"');
str.push(target.name);
str.push("\"");
}
} else {
str.push(',sk_group:', WORLD.COMMANDS.skgroup.cur_eqs(me));
}
str.push("}");
me.send(str.join(""));
}

View File

@@ -0,0 +1,64 @@
this.inherits(COMMAND);
this.command = "events";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.allow_faint = true;
this.regex = /^(\w+)(?:\s+(\w+))$/;
this.enter = function (me, type, paras) {
let events = WORLD.USER_EVENTS;
if (type) {
for (let i = 0; i < events.length; i++) {
let evt = events[i];
if (evt.id === type) {
if (this.check_command(evt, me)) {
if (evt.on_command?.(me, paras)) {
me.send('{type:"dialog",dialog:"events",close:true}');
}
}
return;
}
}
return me.send('什么?');
} else {
let str = ['{type:"dialog",dialog:"events",items:['];
let now = Date.now();
for (let i = 0; i < events.length; i++) {
let evt = events[i];
if (evt.check && !evt.check(me))
continue;
if (evt.time > 0 && evt.time < now) {
continue;
}
if (str.length > 1) str.push(',');
str.push(`["${evt.id}","${evt.name}","${evt.query_desc(me)}",${evt.query_grade(me)},${evt.time},"${evt.command ?? ""}"]`);
}
str.push(']}');
me.send(str.join(""));
}
}
this.check_command = function (event, me) {
if (me.hp <= 0 && !event.allow_die) {
return me.notify_fail("你现在是灵魂状态,不能那么做。");
}
if (!event.allow_faint && me.is_faint) {
me.send("你正在昏迷中!");
return false;
}
if (!event.allow_state && me.state) {
return me.notify_fail("你正在" + me.state.title + ",没时间这么做。");
}
if (!event.allow_fight && me.fight_type > 0) {
return me.notify_fail("你正在战斗,待会再说。");
}
if (!event.allow_busy && me.is_busy) {
return me.notify_fail("你现在正忙。");
}
return true;
}

103
world/cmd/dialog/i.js Normal file
View File

@@ -0,0 +1,103 @@
this.inherits(COMMAND);
this.command = "pack";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.allow_faint = true;
this.enter = function (me, arg) {
var target = me;
if (arg) {
if (arg == "none") return me.notify('{"type":"dialog","dialog":"pack","money":' + me.money + "}");
target = me.find_obj(arg, me.environment);
if (!target && me.user_level > 1) {
target = WORLD.getUser(arg);
}
if (!target) {
return me.notify("这里没有这个人。");
}
if (me.user_level < 4 && target.master != me.id)
return me.notify("你只能查看自己的背包。");
}
var str = ['{"type":"dialog","dialog":"'];
if (target != me) {
str.push('pack2",id:"');
str.push(target.id);
str.push('",name:"');
str.push(target.name);
str.push('",');
} else {
str.push('pack",');
}
str.push('"items":[');
var items = target.items;
if (items) {
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (i > 0) str.push(",");
str.push(item.format_to_pack());
// str.push('{name:"');
// str.push(item.color_name);
// str.push('",id:"');
// str.push(item.id);
// str.push('",count:');
// str.push(item.count);
// str.push(',unit:"');
// str.push(item.unit);
// str.push('"');
// str.push(',value:');
// str.push(parseInt(item.value / 10));
// if (item.is_equipment) {
// str.push(',can_eq:1');
// }
// if (item.on_use) {
// str.push(',can_use:1');
// }
// if (item.on_study) {
// str.push(',can_study:1');
// }
// if (item.on_open) {
// str.push(',can_open:1');
// }
// if (item.combine_count) {
// str.push(',can_combine:' + item.combine_count);
// }
// str.push('}');
}
}
str.push('],"money":');
str.push(target.money || 0);
items = target.equipment;
if (items) {
str.push(',eqs:[');
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (i > 0) str.push(",");
if (item) {
str.push(`["${item.color_name}","${item.id}",${item.grade},${item.on_use ? 1 : 0},${item.is_locked ? 1 : 0}]`);
// str.push('{name:"');
// str.push(item.color_name);
// str.push('",id:"');
// str.push(item.id);
// str.push('"');
// if (item.on_use) {
// str.push(',can_use:1');
// }
// str.push('}');
} else {
str.push("null");
}
}
str.push(']');
}
str.push(",max_item_count:");
str.push(target.max_item_count);
if (target === me) {
str.push(",eq_group:");
str.push(target.eq_group);
}
str.push('}');
me.send(str.join(""));
}

385
world/cmd/dialog/jh.js Normal file
View File

@@ -0,0 +1,385 @@
this.inherits(COMMAND);
this.command = "jh";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.allow_faint = true;
this.fbs_json = null;
this.fbs = [];
this.regex = /^(\w+)?\s?(lock|\d+)?(?:\s(start[1|2|3]?))?$/;
this.enter = function (me, type, arg, isstart) {
if (!me.is_player) return;
var unlock = me.query_temp("fb", 0);
var unlock2 = me.query_temp("fb2", 0);
if (arg == "lock")
return me.send(`{type:"dialog",dialog:"jh",unlock:${unlock},unlock2:${unlock2}}`);
if (!this.map_json) {
this.map_json = this.getAllMaps();
}
if (!arg && !type) {
me.send(this.map_json);
me.send(`{type:"dialog",dialog:"jh",unlock:${unlock},unlock2:${unlock2}}`);
} else {
var index = parseInt(arg);
if (!isstart) {
if (type == "fb") return this.return_fbdesc(me, index);
if (type == "fam") return this.return_famdesc(me, index);
else return this.return_areadesc(me, index);
} else {
if (me.check_command({
allow_busy: false, allow_state: false,
allow_die: false, allow_faint: false,
allow_fight: false
}) == false) return;
if (type == "fb") {
var fb = this.fbs[index];
if (fb.is_lock) {
return me.notify("暂未开放,正在修复");
}
if (fb.unlock_index) {
if (fb.unlock_index > unlock) {
return me.notify("你需要完成" + this.fbs[fb.unlock_index - 1].name + "才能解锁" + fb.name + "。");
}
} else if (index > unlock) {
return me.notify(fb.name + "尚未解锁。");
}
if (!me.environment) return me.notify("你不知道在哪。");
if (me.environment.is_fb()) return me.notify("你现在正在副本区域。");
if (!fb || !fb.id) return me.notify("没有这个副本。");
if (fb.start_room && !me.is_in(fb.start_room))
return me.notify('你要进入哪个副本?');
if (isstart == "start1") {
// if (me.team) return me.notify("你目前处于队伍当中,无法进入单人副本。");
var count = me.query_temp("fbc_0_" + fb.fb_index, 0);
if (count) {
me.notify("即将进入副本(" + fb.name + ")区域,已完成" + count + "次,本次副本需要消耗" + fb.expend + "点精力。\n当前精力" + me.query_jingli());
} else {
me.notify("即将进入副本(" + fb.name + ")区域,本次副本需要消耗" + fb.expend + "点精力。\n当前精力" + me.query_jingli());
}
let can_sd = false;
if (fb.unlock_index) {
can_sd = me.query_temp('fb_sao' + index, 0) === 1;
} else {
can_sd = me.query_temp('fb_sao0') >= index;
}
if (can_sd) {
return me.send_commands('cr ' + fb.id, "进入副本", "cr " + fb.id + " 0 1", "扫荡一次",
"cr " + fb.id + " 0 10", "扫荡十次");
} else {
return me.send_commands('cr ' + fb.id, "进入副本");
}
} else if (isstart == "start2") {
// if (me.team) return me.notify("你目前处于队伍当中,无法进入单人副本。");
let count = me.query_temp("fbc_1_" + fb.fb_index, 0);
if (count) {
me.notify("即将进入副本(" + fb.name + ")<hir>困难区域</hir>,已完成" + count + "次,本次副本需要消耗" + fb.expend + "点精力。\n当前精力" + me.query_jingli());
} else {
me.notify("即将进入副本(" + fb.name + ")<hir>困难区域</hir>,本次副本需要消耗" + fb.expend + "点精力。\n当前精力" + me.query_jingli());
}
let can_sd = false;
if (fb.unlock_index) {
can_sd = me.query_temp('fb_sao' + fb.index, 0) === 2;
} else {
can_sd = me.query_temp('fb_sao1') >= index;
}
if (can_sd) {
return me.send_commands('cr ' + fb.id + " 1 0", "进入副本", "cr " + fb.id + " 1 1",
"扫荡一次", "cr " + fb.id + " 1 10", "扫荡十次");
} else {
return me.send_commands('cr ' + fb.id + " 1 0", "进入副本");
}
} else if (isstart == "start3") {
if (!me.team) return me.notify("你目前没有在队伍当中,无法进入组队副本。");
for (var i = 0; i < me.team.length; i++) {
var tm = me.team[i];
if (tm.environment && tm.environment.is_fb() &&
tm.environment.parent != fb) {
return me.notify(tm.name + "现在正在副本【" + tm.environment.parent.name + "】区域,无法开启其它副本。");
}
}
me.send("即将组队进入副本(" + fb.name + ")区域,本次副本需要消耗" + fb.expend + "点精力。\n当前精力" + me.query_jingli() + "/100");
return me.send_commands('cr ' + fb.id + " 2 0", "进入副本");
}
} else if (type === 'ar') {
if (!me.can_trans()) return;
let fb = this.areas[index];
if (!fb || !fb.id) return me.notify("没有这个禁地区域。");
if (!(fb.jd_index >= 0)) return me.notify("没有这个禁地区域。");
if (fb.is_lock) return me.notify("暂未开放,正在修复");
let diff = 0;
if (me.team) diff = 2;
if (!me.isenable_area(fb)) return me.notify("未解锁区域");
if (fb.is_copy && !fb.not_fb) {//禁地类型的副本
this.enter_ar_fb(me, fb, diff);
} else {
if (fb.on_enter(me) == false) {
return;
}
me.moveto(fb.first, me.name + "走了。", me.name + "来了。");
}
} else {
if (!me.can_trans()) return;
let fb = this.families[index];
if (!fb || !fb.first) return me.notify("没有这个门派。");
if (fb.on_enter(me) == false) {
return;
}
me.moveto(ROOM.Get(fb.first), me.name + "走了。", me.name + "来了。");
}
me.send('{type:"dialog",dialog:"jh",close:true}');
}
}
}
this.enter_ar_fb = function (me, fb, diff = 0) {
var count =
me.query_temp(fb.count_key ?? ("fbc_0_" + fb.fb_index), 0);
if (count) {
me.notify("即将进入禁地副本(" + fb.name
+ ")区域,已完成" + count +
"次,本次副本需要消耗<hic>" + fb.expend
+ "</hic>点精力。\n当前精力" + me.query_jingli());
} else {
me.notify("即将进入禁地副本(" + fb.name
+ ")区域,本次副本需要消耗<hic>" + fb.expend
+ "</hic>点精力。\n当前精力" + me.query_jingli());
}
let can_sd = me.query_temp('fb_sao' + fb.fb_index, 0) === 1;
if (can_sd) {
let sd_diff = diff;
if (sd_diff === 2) sd_diff = 0;
return me.send_commands('cr ' + fb.id + " " + diff + " 0",
"进入副本", "cr " + fb.id + " " + sd_diff + " 1",
"扫荡一次", "cr " + fb.id + " " + sd_diff + " 10", "扫荡十次");
} else {
return me.send_commands('cr ' + fb.id + " " + diff + " 0",
"进入副本");
}
}
this.return_famdesc = function (me, index) {
if (!(index >= 0 && index < this.families.length)) return me.notify("没有这个门派。");
var fb = this.families[index];
if (!fb) return me.notify("没有这个门派。");
if (fb.json) return me.send(fb.json);
var obj = {};
obj.type = "dialog";
obj.dialog = "jh";
obj.index = index;
obj.ref = fb.no_cache ? 0 : 1;
obj.desc = fb.query_desc();
obj.actions = fb.query_actions(me);
obj.sp = fb.sp;
obj.t = "fam";
if (fb.family) {
var fam = FAMILIES[fb.family];
if (fam) {
fb.skills = fam.skills;
fb.skills2 = fam.skills2;
fb.skills4 = fam.skills4;
}
}
var str = [];
if (fb.skills) {
str.push("门派武功:\n");
for (var i = 0; i < fb.skills.length; i++) {
str.push("<span cmd='checkskill ");
str.push(fb.skills[i].id);
str.push(" help'>");
str.push(fb.skills[i].color_name);
str.push("</span>\n");
}
}
if (str.length) obj.skills = str.join("");
fb.json = JSON.stringify(obj);
me.send(fb.json);
}
this.return_areadesc = function (me, index) {
if (!(index >= 0 && index < this.areas.length)) return me.notify("没有这个副本。");
var fb = this.areas[index];
if (!fb) return me.notify("没有这个区域。");
if (fb.json) return me.send(fb.json);
var obj = {};
obj.type = "dialog";
obj.dialog = "jh";
obj.t = "ar";
obj.index = index;
obj.desc = fb.desc;
obj.actions = fb.query_actions(me);
// if (fb.is_copy && !fb.not_fb)
// obj.status = this.fb_status(fb);
obj.reward = "掉落或解谜奖励:\n" + this.fb_drops(fb);
fb.json = JSON.stringify(obj);
me.send(fb.json);
}
this.return_fbdesc = function (me, index) {
if (!(index >= 0 && index < this.fbs.length)) return me.notify("没有这个副本。");
var fb = this.fbs[index];
if (!fb) return me.notify("没有这个副本。");
if (fb.json) return me.send(fb.json);;
var obj = {};
obj.type = "dialog";
obj.dialog = "jh";
obj.t = "fb";
obj.index = index;
obj.desc = fb.desc;
obj.status = this.fb_status(fb);
var str = [];
var exp = fb.query_exp();
str.push("获得");
str.push(exp);
str.push("点经验,");
str.push(exp);
str.push("点潜能\n掉落或解谜奖励\n");
str.push(this.fb_drops(fb));
obj.reward = str.join("");
obj.diffs = [1, fb.is_diffi ? 1 : 0, fb.is_multi ? 1 : 0];
fb.json = JSON.stringify(obj);
me.send(fb.json);
}
this.fb_drops = function (fb) {
var json = [];
var drops = fb.drops || [];
fb.drop_items = [];
for (var i = 0; i < drops.length; i++) {
var oitem = OBJ.CREATE(drops[i]);
if (oitem) {
json.push("<span cmd='look3 " + fb.drop_items.length
+ " of fb_" + fb.area_index + "'>" + oitem.color_name + "</span>");
fb.drop_items.push(oitem);
}
}
return json.join("\n");
}
this.fb_status = function (fb) {
let status = [];
let fblock = fb.fb_index + 1;
let fb_key = "fb_first_" + fblock + "_0";
let ss_0 = WORLD.DATA.query_temp(fb_key);
if (ss_0) {
status[0] = [1, ss_0];
} else {
status[0] = [0, fb.is_diffi ? "" : fb.ss_title];
}
if (fb.is_diffi) {
fb_key = "fb_first_" + fblock + "_1";
ss_0 = WORLD.DATA.query_temp(fb_key);
if (ss_0) {
status[1] = [1, ss_0];
} else {
status[1] = [0, fb.ss_title ?? ""];
}
} else {
status[1] = null;
}
if (fb.is_multi) {
fb_key = "fb_first_" + fblock + "_2";
ss_0 = WORLD.DATA.query_temp(fb_key);
if (ss_0) {
status[2] = [1, ss_0];
} else {
status[2] = [0, ""];
}
}
return status;
}
this.init = function () {
this.map_json = this.getAllMaps();
}
this.getAllMaps = function (me) {
var map = {};
map.type = "dialog";
map.dialog = "jh";
map.fbs = [];
map.families = [];
map.areas = [];
this.fbs = [];
this.families = [];
this.areas = [];
for (var i = 0; i < WORLD.AREAS.length; i++) {
var area = WORLD.AREAS[i];
area.area_index = i;
if (AREAS[area.id] >= 0) {
let index = AREAS[area.id];
map.families[index] = area.name;
this.families[index] = area;
// AREAS[area.id] = area;
} else if (FBS[area.id] >= 0) {
area.fb_index = FBS[area.id];
map.fbs.push(area.name);
this.fbs.push(area);
FBS[area.id] = area;
} else if (JDS[area.id] >= 0) {
let index = JDS[area.id];
area.jd_index = index;
this.areas[index] = area;
map.areas[index] = area.name;
}
}
AREA.FBS = this.fbs;
return JSON.stringify(map);
}
AREA.Get_FB = function (id) {
return FBS[id];
}
this.get_area = function (id) {
if (!this.areas) this.getAllMaps();
let index = AREAS[id];
if (index >= 0) {
return this.areas[index];
}
return null;
}
const AREAS = {
yz: 0, wudang: 1, shaolin: 2, huashan: 3, emei: 4,
xiaoyao: 5, gaibang: 6, shashou: 7, xiangyang: 8, wudao: 9
};
const FBS = {
"lw": 0, "cuifu": 1, "lmw": 2, "lcy": 3,
"by": 4, "zhuang": 5, "ao": 6, "tdh": 7
}
const JDS = {
heiying: 0,
// gmp: 4,
// gumen: 5,
// gzc: 6,
// gysd: 7,
// yzjd: 8
};

53
world/cmd/dialog/list.js Normal file
View File

@@ -0,0 +1,53 @@
this.inherits(COMMAND);
this.command = "list";
this.enter = function (me, arg) {
var target = me;
if (arg) {
target = me.find_obj(arg, me.environment);
if (!target) {
return me.notify("这里没有这个人。");
}
}
var selllist = target.sell_list;
if (target.on_sell) {
selllist = target.on_sell(me);
}
if (!selllist) {
return me.notify(target.name + "不出售任何东西。");
}
var str = ['{"type":"dialog","dialog":"list","selllist":['];
for (var i = 0; i < selllist.length; i++) {
if (i > 0) str.push(",");
var item = selllist[i];
str.push(item.format_to_sell());
}
str.push(']');
//,items: [
//items = me.items;
//if (items) {
// for (var i = 0; i < items.length; i++) {
// var item = items[i];
// if (i > 0) str.push(",");
// str.push('{name:"');
// str.push(item.color_name);
// str.push('",id:"');
// str.push(item.id);
// str.push('",count:');
// str.push(item.count);
// str.push(',unit:"');
// str.push(item.unit);
// str.push('"}');
// }
//}
str.push(",title:\"");
str.push(target.name);
str.push("正在贩卖以下物品:\"");
str.push(",seller:\"");
str.push(target.id);
str.push("\"}");
me.send(str.join(""));
}

71
world/cmd/dialog/map.js Normal file
View File

@@ -0,0 +1,71 @@
this.inherits(COMMAND);
this.command = "map";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.map_json;
this.buffer = {};
var world_map = null;
this.enter = function (me, area) {
//if (!area) {
// if (!this.map_json) this.map_json = getAllMaps(me);
// return me.send(this.map_json);
//}
if (!area || area == "here") {
if (!me.environment) return;
var str = me.environment.path;
area = str.substr(0, str.lastIndexOf("/"));
}
var path = area + "/"
if (this.buffer[area]) return me.send(this.buffer[area]);
var area_obj = null;
for (var i = 0; i < WORLD.AREAS.length; i++) {
if (path == WORLD.AREAS[i].room_path) {
area_obj = WORLD.AREAS[i];
break;
}
}
if (!area_obj) return;
if (area_obj.render_map) return area_obj.render_map(me);
this.buffer[area] = this.createMapJson(area_obj, area);
me.send(this.buffer[area]);
}
this.clearCache = function () {
this.buffer = {};
}
this.update_map = function (id, rm, pos) {
this.buffer[id] = null;
if (!rm) {
var area_obj;
for (var i = 0; i < WORLD.AREAS.length; i++) {
if (path == WORLD.AREAS[i].room_path) {
area_obj = WORLD.AREAS[i];
break;
}
}
return;
}
var str = "{type:'updatemap',map:'" + id + "',id:'" + rm.path + "',n:'" + rm.name + "'";
if (pos) str += ",pos:[" + pos.join() + "]}";
else str += "}";
for (var i = 0; i < rm.items.length; i++) {
if (rm.items[i].is_player)
rm.items[i].send(str);
}
}
this.createMapJson = function (area_obj, area) {
if (!area_obj) return '{type:"map",maps:[]}';
var obj = {};
obj.type = "map";
obj.path = area;
obj.map = area_obj.map;
return JSON.stringify(obj);
}
function getAreaByPath(areas, path) {
if (!areas) return;
for (var i = 0; i < areas.length; i++) {
if (areas[i].path == path) return areas[i];
}
}

View File

@@ -0,0 +1,74 @@
this.inherits(COMMAND);
this.command = "message";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.allow_faint = true;
const MESSAGE = WORLD.MESSAGE;
this.regex = /^(\w+)\s(\w+)$/;
this.enter = function (me, arg, arg2) {
if (arg === 'delete') {
if (!arg2) return this.delete_all(me);
return this.delete_from(me, arg2);
}
var obj = {};
obj.type = "dialog";
obj.dialog = "message";
if (arg) {
obj.items = MESSAGE.getMessageFromID(me, arg);
obj.id = arg;
} else {
obj.messages = MESSAGE.getUserMessages(me);
}
// obj.messages = [];
// let notices = MESSAGE.getNotice();
// for (let nt of notices) {
// obj.messages.push({
// id: "notice",
// content: nt.content,
// time: nt.time,
// name: "公告"
// });
// }
// let stores = MESSAGE.getUserMessages(me);
// let diff_time = 24 * 3600000 * 30;
// let now = Date.now();
// if (stores) {
// }
me.send(JSON.stringify(obj));
}
this.delete_from = function (me, from) {
let stores = MESSAGE.stores.get(me.id);
if (!stores) return me.send('你没有消息。');
let store = stores.get(from);
if (!store) return me.send('你没有这个类型的消息。');
if (!this.check_store(store)) {
return me.send('你有未领取的消息,无法删除。');
}
stores.delete(from);
me.send('{type:"dialog",dialog:"message",clear:"' + from + '"}');
}
this.delete_all = function (me) {
let stores = MESSAGE.stores.get(me.id);
if (!stores) return;
stores.forEach((x, y) => {
if (!this.check_store(x)) {
return me.send('你有未领取的消息,无法删除。');
}
});
MESSAGE.stores.delete(me.id);
me.send('{type:"dialog",dialog:"message",clear:true}');
}
this.check_store = function (store) {
let items = store.items;
for (let item of items) {
if (item.attach && !item.rec)
return false;
}
return true;
}

24
world/cmd/dialog/qu.js Normal file
View File

@@ -0,0 +1,24 @@
this.inherits(COMMAND);
this.command = "qu";
this.regex = /^(?:(\d+\s+))?(\w+)$/;
this.enter = function (me, count, arg) {
if (!me.environment.allow_store) return me.notify("这里没有仓库。");
if (!arg) return me.notify("你要取什么东西?");
me.items = me.items || [];
var obj = {};
obj.remove_item_byid = me.remove_item_byid;
obj.items = me.stores || [];
var move_count = 1;
if (count) move_count = parseInt(count);
var moved_obj = obj.remove_item_byid(arg, move_count);
if (!moved_obj) return me.notify("你的仓库里没有这样东西。");
moved_obj = me.push_item(moved_obj);
me.stores = obj.items;
me.send_room("$N从仓库里取出" + UTIL.to_c(move_count) + moved_obj.unit + moved_obj.color_name + "。");
me.notify('{type:"dialog",dialog:"list",id:"' + moved_obj.id + '",storeid:"' + arg + '",store:' + (-move_count) + '}');
}

View File

@@ -0,0 +1,94 @@
this.inherits(COMMAND);
this.command = "relation";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.enter = function (me, arg) {
var str = ['{"type":"dialog","dialog":"relation"'];
if (me.query_temp("shifu")) {
var shifu = WORLD.getUser(me.query_temp("shifu"));
str.push(",shifu:\"");
if (shifu) {
str.push(shifu.color_name);
} else {
str.push(me.query_temp("shifu_n"));
}
str.push("\"");
if (shifu) {
str.push(",sid:\"");
str.push(shifu.id);
str.push("\"");
}
} else if (me.query_temp("tudi")) {
var tudi = WORLD.getUser(me.query_temp("tudi"));
str.push(",tudi:\"");
if (tudi) {
str.push(tudi.color_name);
} else {
str.push(me.query_temp("tudi_n"));
}
str.push("\",st:");
str.push(me.query_temp("st_count", 0));
if (tudi) {
str.push(",tid:\"");
str.push(tudi.id);
str.push("\"");
var lv = tudi.level ? tudi.level : 1;
if (lv < 3) {
str.push(",reward:\"你的徒弟境界提升到");
str.push(["<wht>武士</wht>", "<hig>武师</hig>", "<hiy>宗师</hiy>"][lv]);
str.push("后,你将获得一个");
str.push(["<hig>精铁宝箱</hig>", "<hic>白银宝箱</hic>", "<hiy>黄金宝箱</hiy>"][lv]);
str.push("\"");
}
}
}
if (me.query_temp("st_leave")) {
var time = new Date(me.temp["st_leave"].e) - Date.now();
str.push(",reward:\"你需要");
str.push(parseInt(time / 3600000));
str.push("小时");
str.push(parseInt((time % 3600000) / 60000));
str.push("分后才可以另行收徒或拜师\"");
}
if (me.query_temp("husband")) {
var husband = null;// WORLD.getUser(me.query_temp("husband"));
str.push(",husband:\"");
if (husband) {
str.push(husband.color_name);
} else {
str.push(me.query_temp("husband_n"));
}
str.push("\"");
} else if (me.query_temp("wife")) {
var wife = null;// WORLD.getUser(me.query_temp("wife"));
str.push(",wife:\"");
if (wife) {
str.push(wife.color_name);
} else {
str.push(me.query_temp("wife_n"));
}
str.push("\"");
}
if (me.follower) {
str.push(",fls:[");
let now = Date.now();
for (let item of me.follower) {
let follower = FOLLOWER.GET(me, item);
if (follower) {
str.push('["', follower.long_name(), '","', follower.id, '"');
if (follower.state) {
str.push(',"', follower.state.title, '",', now - follower.state.stime);
}
str.push('],');
}
}
str.push("0]");
}
str.push("}");
me.send(str.join(""));
}

View File

@@ -0,0 +1,65 @@
this.inherits(COMMAND);
this.command = "reward";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.allow_faint = true;
this.regex = /^(\w+)(?:\s+(\d+))?$/;
this.enter = function (me, par, index) {
if (!par) {
return;
}
let rule = this.rules[par];
if (!rule) return me.notify("你要看什么?");
let ary = this[par] ?? [];
let reward = ary[index - 1] ?? "";
me.notify("<hic>" + rule + reward + "</hic>");
}
this.score_reward = function (i) {
return {
obj: "money/exp",
count: (20 - i) * 1000
};
}
this.top_reward = function (i) {
return {
obj: "money/gold",
count: (50 + (10 - i) * 5)
};
}
this.weapon_reward = function (i) {
return {
obj: "st/xuanjing",
count: (50 + (10 - i) * 5)
};
}
this.rules = {
score: "根据你所有学会的武学计算的分数,按照门派榜单发放奖励,",
top: "每日消耗精力获得挑战次数,只可挑战积分比自己高的玩家,挑战成功自己增加积分,失败双方积分不变,按照门派榜单发放奖励,",
weapon: "当武器获得精炼或者自制装备时会计算分数玩家同一部件多件装备取最高分上榜所有榜单奖励总计上限200",
mp: "定时更新,无奖励",
exp: "定时更新,无奖励",
money: "定时更新,无奖励",
};
this.top = [
];
for (let i = 0; i < 10; i++) {
this.top[i] = "每天获得黄金*" + (50 + (10 - i) * 5);
}
this.weapon = [
];
for (let i = 0; i < 10; i++) {
this.weapon[i] = "每天获得玄晶*" + (50 + (10 - i) * 5);
}
this.score = [
];
for (let i = 0; i < 20; i++) {
this.score[i] = "每天获得潜能:" + (20 - i) * 1000;
}

145
world/cmd/dialog/score.js Normal file
View File

@@ -0,0 +1,145 @@
this.inherits(COMMAND);
this.command = "score";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.enter = function (me, arg) {
var target = me;
if (arg) {
if (arg === "title") {
let str = ['{"type":"dialog","dialog":"score"'];
str.push(',titles:[');
if (me.titles) {
for (var i = 0; i < me.titles.length; i++) {
var item = me.titles[i];
if (i > 0) str.push(",");
str.push("{title:\"");
str.push(item.title);
str.push("\"");
if (item.use) {
str.push(",use:true");
}
str.push("}");
}
}
str.push("]}");
return me.send(str.join(""));
}
target = me.find_obj(arg, me.environment);
if (!target && me.user_level > 1) {
target = WORLD.getUser(arg);
}
if (!target) {
return me.notify("你要查看谁的属性。");
}
if (target.master != me.id && me.user_level < 4) {
return me.notify("你要查看谁的属性。");
}
}
let str = ['{"type":"dialog","dialog":"score"'];
str.push(',id:"');
str.push(target.id);
str.push('","name":"');
str.push(target.long_name());
str.push('","id":"');
str.push(target.id);
str.push('","age":"');
var age = target.query_age();
if (age < 10) age = 10;
var int_age = parseInt(age);
str.push(UTIL.to_c(int_age));
str.push('岁');
let month = parseInt((age - int_age) * 12);
if (month) {
str.push(UTIL.to_c(month));
str.push('个月');
}
str.push('","family":"');
str.push(target.family.name);
str.push('",master:\"');
str.push(target.master ? target.master : "无");
str.push('",gender:\"');
str.push(target.gender == 1 ? "男" : "女");
str.push('",level:\"');
str.push(this.get_level_desc(target));
str.push('"');
target.pot = parseInt(target.pot);
target.hp = parseInt(target.hp);
target.mp = parseInt(target.mp);
for (var i = 0; i < this.props.length; i++) {
str.push(',"');
str.push(this.props[i]);
str.push('":');
str.push(target[this.props[i]] || 0);
}
//if (target.dodge_skill.on_score) {
// str.push(',ds:', target.dodge_skill.on_score(target));
//} else {
//}
str.push(',ds:', target.ds);
str.push(',per:');
str.push(target.query_prop("per") + target.per);
str.push(',str_add:');
str.push(target.query_prop("str"));
str.push(',con_add:');
str.push(target.query_prop("con"));
str.push(',dex_add:');
str.push(target.query_prop("dex"));
str.push(',int_add:');
str.push(target.query_prop("int"));
var limit_mp = target.limit_mp + target.query_prop("limit_mp");
str.push(',limit_mp:');
str.push(limit_mp);
if (target.query_jingli) {
str.push(',jingli:"', target.query_temp('ad_jl', 0), '/', target.query_jclimit(), "<hig>(+", 200 - target.query_temp('ex_jl', 0), ')</hig>"');
} else {
str.push(',jingli:0');
}
str.push(',gjsd:');
str.push(target.gjsd / 1000);
str.push(',bj:"');
str.push(target.bj);
str.push('%",');
str.push('master:"');
str.push(MASTER_NAME(target));
str.push('",family:"');
str.push(target.family.name);
str.push('",gongji:');
str.push(target.query_temp("gongji") || 0);
str.push('}');
me.send(str.join(""));
}
const MASTER_NAMES = {};
const MASTER_NAME = function (me) {
let path = me.query_temp('master');
if (!path) return '无';
if (MASTER_NAMES[path])
return MASTER_NAMES[path];
let obj = NPC.GET(path);
MASTER_NAMES[path] = obj.name;
return obj.name
}
this.props = ["hp", "mp", "max_hp", "max_mp", "str", "con",
"dex", "int", "kar", "gj", "fy", "mz", "zj", "exp", "pot"];
const level_descs = ["普通百姓", "武士", "武师", "宗师", "武圣", "武帝", "武神"];
const level_color = ["", "wht", "hig", "hiy", "hiz", "hio", "ord"];
const level6_descs = ["武神", '剑神', '刀皇', '兵主', '战神'];
this.get_level_desc = function (me) {
if (!me.level) return level_descs[me.level];
var cc = level_color[me.level];
if (me.level === 6) {
return "<" + cc + ">" + level6_descs[me.query_temp('lv6', 0)] + "</" + cc + ">";
}
return "<" + cc + ">" + level_descs[me.level] + "</" + cc + ">";
}

View File

@@ -0,0 +1,77 @@
this.inherits(COMMAND);
this.command = "score2";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.enter = function (me, arg) {
var target = me;
if (arg) {
target = me.find_obj(arg, me.environment);
if (!target && me.user_level > 1) {
target = WORLD.getUser(arg);
}
if (!target) {
return me.notify("你要查看谁的属性。");
}
if (target.master != me.id && me.user_level < 4) {
return me.notify("你要查看谁的属性。");
}
}
var str = ['{"type":"dialog","dialog":"score",'];
str.push('id:"');
str.push(target.id);
str.push("\",add_sh:\"");
str.push(target.query_prop("add_sh_per"));
str.push("%\",diff_fy:\"");
str.push(parseInt(target.diff_fy_per * 100) / 100);
str.push("%\",add_bj:\"");
str.push(target.query_prop("add_bjsh_per") + 150);
str.push("%\",diff_sh:\"");
str.push(target.query_prop("diff_sh"));
str.push("+");
str.push(parseInt(target.diff_sh_per * 100) / 100);
str.push("%\",diff_bj:\"");
str.push(target.query_prop("diff_bj"));
str.push("%\",releasetime:\"");
str.push(target.query_prop("releasetime") / 1000);
str.push("秒+");
str.push(target.query_prop("releasetime_per"));
str.push("%\",busy:\"");
str.push(target.query_prop("busy") / 1000);
str.push("秒+");
str.push(target.query_prop("busy_per"));
str.push("%\",diff_busy:\"");
str.push(target.query_prop("diff_busy") / 1000);
str.push("秒+");
str.push(target.query_prop("diff_busy_per"));
str.push("%\",distime:\"");
str.push(target.query_prop("distime") / 1000);
str.push("秒+");
str.push(target.query_prop("distime_per"));
str.push("%\",expend_mp:\"");
str.push(target.query_prop("expend_mp"));
str.push("+");
str.push(target.query_prop("expend_mp_per"));
str.push("%\",dazuo_per:\"");
str.push(target.query_prop("dazuo_per"), '%');
let per = WORLD.DATA.query_temp('dazuo_per', 0) + target.family.query_temp('dazuo_per', 0);
if (per > 0) {
str.push('+', per, '%');
}
str.push('",study_per:"');
str.push(target.query_prop("study_per") + me.int, '%');
per = WORLD.DATA.query_temp('study_per', 0) + target.family.query_temp('study_per', 0);
if (per > 0) {
str.push('+', per, '%');
}
str.push('",lianxi_per:"');
str.push(target.query_prop("lianxi_per") + me.int * 2, '%');
per = WORLD.DATA.query_temp('lianxi_per', 0) + target.family.query_temp('lianxi_per', 0);
if (per > 0) {
str.push('+', per, '%');
}
str.push('",downside_per:"');
str.push(target.query_prop("diff_downside_per"));
str.push('%"}');
me.send(str.join(""));
}

281
world/cmd/dialog/shop.js Normal file
View File

@@ -0,0 +1,281 @@
this.inherits(COMMAND);
this.command = "shop";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.allow_faint = true;
this.regex = /(?:(\w+)\s+(\d+))/;
this.enter = function (me, par, count) {
if (me.query_temp("new")) return me.notify("你先完成新手指导再说。");
if (!me.is_player) return me.notify("你不能购买。");
if (!this.list)
this.load_selllist();
if (count != undefined) {
var item = this.list.get(par);
if (!item) return me.notify("商店不出售这个东西。");
if (item.is_show && item.is_show(me) === false) return me.notify("商店不出售这个东西。");
count = parseInt(count);
if (!(count > 0)) return;
if (item.limit > 0 && me.query_temp(item.limit_key, 0) + count > item.limit) {
return me.notify(item.name + "到达" + (item.limit_time < 3 ?
["本日", '本周', '本月'][item.limit_time] : "") + "购买上限。");
}
if (item.max > 0 && me.query_temp(item.max_key, 0) + count > item.max) {
return me.notify("没有这么多的" + item.name + "出售了。");
}
if (item.on_buy && item.on_buy(me, count) === false) return;
let discount = 1;
if (item.query_discount) discount = item.query_discount(me);
else discount = item.discount ?? 1;
let need_money = 0;
if (item.mtype === 0) {
need_money = item.value * count * 10000;
if (discount < 1) need_money = need_money * discount;
need_money = parseInt(need_money);
if (!(me.money >= need_money)) {
return me.notify("你没有那么多的银两。");
}
me.add_money(-need_money, "购买" + item.name + "");
} else if (item.mtype === 1) {
need_money = item.value * count;
if (discount < 1) need_money = need_money * discount;
need_money = parseInt(need_money);
if (!(me.cash_money >= need_money)) {
return me.notify("你没有那么多的元宝。");
}
me.add_cash(-need_money, "购买" + item.name + "");
} else {
need_money = item.value * count;
if (discount < 1) need_money = need_money * discount;
need_money = parseInt(need_money);
if (!(me.query_temp('my', 0) >= need_money))
return me.notify("你没有那么多的古币。");
me.add_temp('my', -need_money);
}
var obj = me.add_obj(item.path, count);
me.notify("你从商店里购买了" + obj.unit_name(count) + "。");
if (item.limit > 0) {
let val = 0;
if (item.limit_time === 0) {
val = me.add_temp(item.limit_key, count, UTIL.diff_time());
} else if (item.limit_time === 1) {
val = me.add_temp(item.limit_key, count, UTIL.diff_week_time());
} else if (item.limit_time === 2) {
val = me.add_temp(item.limit_key, count, UTIL.diff_month_time());
} else if (item.limit_time > 10000) {
val = me.add_temp(item.limit_key, count, item.limit_time);
}
// me.send(`{"type":"dialog","dialog":"shop",item:["${item.id}",${val}],money:[${me.money},${me.cash_money}]}`);
for (let x of this.list_keys) {
if (x.limit_key === item.limit_key) {
me.send(`{"type":"dialog","dialog":"shop",item:["${x.id}",${Math.min(val, x.limit)}],${format_moneys(me)}}`);
}
}
} else {
me.send(`{"type":"dialog","dialog":"shop",${format_moneys(me)}}`);
}
if (item.max > 0) {
let val = me.add_temp(item.max_key, count);
if (val >= item.max) {
me.send(`{"type":"dialog","dialog":"shop",remove:"${item.id}"}`);
item.on_full && item.on_full(me);
}
}
if (item.mtype === 1 && item.rcash) {
me.add_money(need_money * 10000);
me.notify('你获得' + need_money + '两<hiy>黄金</hiy>。');
}
WORLD.add_recover_obj(me, {
name: obj.unit_name(count),
count: count,
value: need_money,
limit_key: item.limit > 0 ? item.limit_key : null,
max_key: item.max_key,
id: obj.id,
rcash: item.rcash,
path: obj.path
}, 12, item.mtype);
return;
}
if (par && par === this.idx)
return me.send(`{"type":"dialog","dialog":"shop",${format_moneys(me)}}`);
var str = ['{"type":"dialog","dialog":"shop","selllist":['];
for (let i = 0; i < this.groups.length; i++) {
if (i > 0) str.push(',[');
else str.push('[');
for (let item of this.groups[i]) {
if (item.is_show && item.is_show(me) === false) continue;
str.push('["', item.id, '","', item.name, '","', item.desc, '"');
str.push(',', item.value, ',', item.grade, ',');
if (item.query_discount) str.push(item.query_discount(me));
else str.push(item.discount ?? 1);
if (item.limit > 0)
str.push(',', item.limit, ',', me.query_temp(item.limit_key, 0), '');
else if (item.max > 0)
str.push(',', item.max, ',', me.query_temp(item.max_key, 0), '');
str.push('],');
}
str.push('0]');
}
str.push('],', format_moneys(me));
str.push(`,idx:"`, this.idx, `"}`);
me.send(str.join(""));
}
function format_moneys(me) {
return `money:[${me.money},${me.cash_money}]`;
// return `money:[${me.money},${me.cash_money},${me.query_temp('my', 0)}],mtype:"枚<hij>古币</hij>"`;
}
this.list = null;
this.list_keys = null;
this.idx = null;
this.load_selllist = function () {
this.list = new Map();
this.list_keys = [];
this.idx = UTIL.create_id();
for (let i = 0; i < this.groups.length; i++) {
for (let item of this.groups[i]) {
item.mtype = i;
let obj = OBJ.CREATE(item.path);
if (!obj) continue;
item.name = obj.name;
item.unit = obj.unit;
item.grade = obj.grade;
item.id = Object.getPrototypeOf(obj).id + i.toString();
this.list.set(item.id, item);
if (item.limit_key) {
this.list_keys.push(item);
}
}
}
}
//去掉元宝,每周兑换,按月领取,黄金频率降低
function query_age_discount(me) {
var dt = Date.now() - me.reg_time * 60000;
let age = Math.floor(dt / 86400000 / 12);
if (age < 1) age = 1;
else if (age > 10) age = 10;
return age / 10;
}
const start_date = new Date(2026, 1, 15, 0, 0);
const end_date = new Date(2026, 1, 24, 0, 0);
this.groups = [
[
{
name: "<hic>扫荡符</hic>", unit: "张", path: "cash/saodang", grade: 2,
desc: "可以快速完成副本,前提是这个副本你已经解锁相关单人难度的扫荡模式", value: 1,
discount: 0.5,
query_discount: query_age_discount,
limit: 50, limit_time: 0, limit_key: "shp1"
},
{
name: "<hic>天师符</hic>", unit: "张", grade: 3,
path: "cash/tianshifu", desc: "可使你原地复活,不用跑路", value: 5,
query_discount: query_age_discount,
limit: 10, limit_time: 0, limit_key: "shp2"
},
{
name: "<hig>背包扩充</hig>", unit: "块", grade: 1,
path: "cash/pack_add", desc: "使你的背包扩充10格最大100格", value: 128,
limit: 1, limit_time: 1, limit_key: "shp3"
},
{
name: "<hig>仓库扩充</hig>", unit: "块", grade: 1,
path: "cash/ck_add", desc: "使你的仓库扩充10格最大400格", value: 168,
limit: 1, limit_time: 1, limit_key: "shp4"
},
{
name: "<hiy>洗髓丹</hiy>", unit: "颗", grade: 3,
path: "cash/xi", desc: "重置你的先天属性", value: 128,
limit: 5, limit_time: 1, limit_key: "shp5"
},
{
name: "<hic>改名符</hic>", unit: "张", grade: 2,
path: "cash/gaiming", limit: 1, limit_time: 2, limit_key: "shp9",
desc: "更改你的名字", value: 200
},
{
name: "<hio>叛师符</hio>", unit: "张", grade: 5,
path: "cash/tuoli", value: 500,
desc: "重新选择你的门派,会遗忘你当前门派的武功,返还你消耗的潜能(不包括100级前的消耗)",
limit: 3, limit_time: 2, limit_key: "shp6"
},
{
name: "<hio>变性丹</hio>", unit: "颗", grade: 5, value: 500,
path: "cash/bian", desc: "更改性别,会遗忘不符合性别要求的武功,返还你消耗的潜能(不包括100级前的消耗)",
limit: 3, limit_time: 2, limit_key: "shp7",
}
]
, [
{
name: "<hic>扫荡符</hic>", unit: "张", path: "cash/saodang", grade: 2,
desc: "可以快速完成副本,前提是这个副本你已经解锁相关单人难度的扫荡模式", value: 1
},
{
name: "<hic>天师符</hic>", unit: "张", grade: 3,
path: "cash/tianshifu", desc: "可使你原地复活,不用跑路", value: 5
},
{
name: "<hig>背包扩充</hig>", unit: "块", grade: 1,
path: "cash/pack_add", desc: "使你的背包扩充10格最大100格", value: 32
},
{
name: "<hig>仓库扩充</hig>", unit: "块", grade: 1,
path: "cash/ck_add", desc: "使你的仓库扩充10格最大400格", value: 40
},
{
name: "<hiy>洗髓丹</hiy>", unit: "颗", grade: 3,
path: "cash/xi", desc: "重置你的先天属性", value: 80
},
{
name: "<hic>改名符</hic>", unit: "张", grade: 2,
path: "cash/gaiming", desc: "更改你的名字", value: 98
},
{
name: "<hio>叛师符</hio>", unit: "张", grade: 5,
path: "cash/tuoli",
desc: "重新选择你的门派,会遗忘你当前门派的武功,返还你消耗的潜能(不包括100级前的消耗)",
value: 300
},
{
name: "<hio>变性丹</hio>", unit: "颗", grade: 5,
path: "cash/bian", desc: "更改性别,会遗忘不符合性别要求的武功,返还你消耗的潜能(不包括100级前的消耗)",
value: 300
},
{
name: "房契", unit: "颗", grade: 3,
path: "cash/fang", desc: "使用后获得扬州城豪华型住宅,拥有自己的练功房,钓鱼采药的小花园,和管家黄金购买的房子无区别。",
value: 998, max_key: "shpm1", max: 1,
is_show: function (me) {
if (me.query_temp('home', 0) === 2) return false;
if (me.query_bool('gift', 1)) return false;
return true;
},
on_full: function (me) {
me.remove_temp('shpm1');
me.set_bool('gift', 1, true);//gift标志0随从包 1房契 2程灵素
}
}
]
];

418
world/cmd/dialog/stats.js Normal file
View File

@@ -0,0 +1,418 @@
this.inherits(COMMAND);
this.command = "stats";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.allow_faint = true;
this.regex = /^(\w+)(?:\s+([a-z]+))?(?:\s+(\d+))?$/;
const STATS = WORLD.STATS;
this.enter = function (me, par, fam, index) {
if (!par) {
return;
}
if (par === "top") {
if (index) {
return render_top_item(me, fam, index);
}
return renderTops(me, fam);
}
if (par === "weapon") {
if (index) {
return render_eq(me,fam,index);
}
return renderWeapons(me, fam);
}
if (par === "score") {
if (index)
return render_score_item(me,fam, index);
return renderScore(me, fam);
}
if (par === "exp") {
if (index)
return this.render_item(me,EXP_STATS, fam, index);
this.renderExp(me, fam);
}
if (par === "mp") {
if (index)
return this.render_item(me,MP_STATS,fam, index);
this.renderMP(me, fam);
}
if (par === "money") {
if (index)
return this.render_item(me, MONEY_STATS, fam, index);
this.renderMoney(me, fam);
}
}
this.render_item = function (me, cache, fam, index) {
if (!fam) fam = "all";
let stats = cache[fam];
if (!stats|| !stats.result) return me.send('你要看什么?');
index = parseInt(index) - 1;
if (!(index >= 0 && index < stats.result.length))
return me.send('你要看什么?');
let item = stats.result[index];
if (!item) return me.send('没有这个人。');
let user = WORLD.getUser(item.id);
if (!user) return me.send(item.name + "现在不在线。");
if (user.query_desc) {
me.notify(user.query_desc(me, "look1"));
}
}
function render_top_item(me, fam, index) {
let tops = STATS.TOPS;
if (fam) tops = STATS['tops_' + fam.toUpperCase()] ?? [];
let item = tops[index - 1];
if (!item) return me.send('你要看什么?');
return me.notify(item.query_desc(item, 'look1'));
}
function render_score_item(me, fam, index) {
let tops = STATS.SCORE;
if (fam) tops = STATS.SC_STATS[fam.toUpperCase()] ?? [];
let item = tops[index-1];
if (!item) return me.send('你要看什么?');
let user = WORLD.getUser(item.id);
if (!user) return me.send('对方不在线。');
return me.notify(user.query_desc(me));
}
function renderScore(me, fam) {
let tops = STATS.SCORE;
if (fam) tops = STATS.SC_STATS[fam.toUpperCase()] ?? [];
var str = ['{"type":"dialog","dialog":"stats","scores":['];
for (var i = 0; i < tops.length; i++) {
if (i > 19) break;
var item = tops[i];
if (i > 0) str.push(",");
str.push('["');
str.push(item.name);
str.push('",');
str.push(item.score);
str.push(']');
}
str.push('],score:');
str.push(me.score);
str.push("}");
me.send(str.join(""));
}
// this.query_scores = function () {
// return SCORE_STATS;
// }
// const SCORE_STATS = {};
// function renderScore(me, fam) {
// let stype = fam;
// if (!stype) stype = "all";
// let stats = SCORE_STATS[stype];
// if (!stats) {
// stats = new UserStats(
// (me, item) => {
// return me.score < item.value
// },
// me => {
// return {
// id: me.id,
// value: me.score,
// name: me.color_name
// };
// });
// stats.type = "score";
// stats.fam = fam;
// SCORE_STATS[stype] = stats;
// }
// if (stats.isExpire()) {
// stats.order(',score:'+me.score);
// }
// me.send(stats.cache);
// }
function renderTops(me, stype) {
let tops = STATS.TOPS;
let famid = null;
if (stype) {
famid = stype.toUpperCase();
tops = STATS["tops_" + famid];
if (!tops) return me.send('没有这个榜单。');
}
var str = ['{"type":"dialog","dialog":"stats","tops":['];
for (var i = 0; i < tops.length; i++) {
var item = tops[i];
if (i > 0) str.push(",");
str.push('["', item.long_name(),'",',item.score,']');
}
if (!stype || famid === me.family.id) {
str.push('],top:', (me.query_temp(stype ? "top_fam" : "top", 0)));
str.push(',sc:', me.query_temp(stype ? "top_fam_sc" : "top_sc", 0));
} else {
str.push('],top:0');
str.push(',sc:0');
}
str.push(',fam:"', stype,'"');
str.push("}");
me.send(str.join(""));
}
function render_eq(me, type,index) {
if (!type) type = 'weapon';
let eqs = STATS.EQ_STATS[EQUIP_TYPE[type.toUpperCase()]] ?? [];
let wea = eqs[index - 1];
me.send(wea.desc);
}
function renderWeapons(me,type) {
var str = ['{"type":"dialog","dialog":"stats","weapons":['];
if (!type) type = 'weapon';
let eqs = STATS.EQ_STATS[EQUIP_TYPE[type.toUpperCase()]]??[];
for (var i = 0; i < eqs.length; i++) {
if (i > 9) break;
var item = eqs[i];
if (i > 0) str.push(",");
str.push('["');
if (item.name) {
str.push('<wht>');
str.push(item.name);
str.push('的</wht>');
str.push(item.wname);
} else {
str.push('无');
}
str.push('",',item.score,']');
}
str.push(']');
str.push("}");
me.send(str.join(""));
}
const EXP_STATS = {};
this.renderExp = function (me, fam) {
let stype = fam;
if (!stype) stype = "all";
let stats = EXP_STATS[stype];
if (!stats) {
stats = new UserStats(
(me, item) => { return me.exp < item.value },
me => {
return {
id: me.id,
value: me.exp,
name: me.color_name
};
});
stats.type = "exp";
stats.fam = fam;
EXP_STATS[stype] = stats;
}
if (stats.isExpire()) {
stats.order();
}
me.send(stats.cache);
}
const MONEY_STATS = {};
this.renderMoney = function (me, fam) {
let stype = fam;
if (!stype) stype = "all";
let stats = MONEY_STATS[stype];
if (!stats) {
stats = new UserStats(
(me, item) => { return me.money < item.value },
me => {
return {
id: me.id,
value: me.money,
name: me.color_name
};
});
stats.type = "money";
stats.formatter = value => {
if (value >= 10000) {
return '"' + Math.floor(value / 10000) + "两黄金" + '"';
}
if (value > 100) {
return '"' + Math.floor(value / 100) + "两白银" + '"';
}
if (value > 0) {
return '"' + Math.floor(value / 100) + "个铜板" + '"';
}
return '""';
};
stats.fam = fam;
MONEY_STATS[stype] = stats;
}
if (stats.isExpire()) {
stats.order();
}
me.send(stats.cache);
}
const MP_STATS = {};
this.renderMP = function (me, fam) {
let stype = fam;
if (!stype) stype = "all";
let stats = MP_STATS[stype];
if (!stats) {
stats = new UserStats(
(me, item) => { return me.max_mp < item.value },
me => {
return {
id: me.id,
value: me.max_mp,
name: me.color_name
};
});
stats.type = "mp";
stats.fam = fam;
MP_STATS[stype] = stats;
}
if (stats.isExpire()) {
stats.order();
}
me.send(stats.cache);
}
function UserStats(order,added) {
this.result = null;
this.cache = null;
this.time = 0;
this.lessThan = order;
this.addItem = added;
this.maxCount = 20;
this.type = null;
}
UserStats.prototype.formatter = function (val) {
return val;
}
UserStats.prototype.isExpire = function () {
return Date.now() - this.time > 0;
}
UserStats.prototype.order = function (append) {
this.result = [];
this.time = Date.now() + 60000;
let fam = this.fam;
if (fam) fam = fam.toUpperCase();
for (let i = 0; i < WORLD.USERS.length; i++) {
let user = WORLD.USERS[i];
if (user.user_level > 4) continue;
if (fam && user.family.id !== fam)
continue;
this.queue(user);
}
let str = ['{"type":"dialog","dialog":"stats","items":['];
for (let i = 0; i < this.result.length; i++) {
let user = this.result[i];
if (i > 0) str.push(",");
str.push('["', user.name, '",', this.formatter(user.value),']');
}
str.push(']');
str.push(',"time":', Date.now(), '');
str.push(',"st":"', this.type, '"', append ?? "");
str.push(',"fam":"', this.fam,'"');
str.push("}");
this.cache= str.join("");
}
UserStats.prototype.queue = function (me) {
let index = this.result.length - 1;
if (index < 0) {
this.result.push(this.addItem(me));
return;
}
let user = this.result[index];
if (this.result.length >= this.maxCount && this.lessThan(me,user)) {
return;
}
while (index >= 0) {
user = this.result[index];
if (this.lessThan(me, user)) {
this.result.splice(index + 1, 0, this.addItem(me));
break;
}
index--;
}
if (index < 0) {
this.result.splice(0, 0, this.addItem(me));
}
if (this.result.length >= this.maxCount) {
this.result.length = this.maxCount;
}
}
//this.expStats = [];
//this.expStatsCache = null;
//this.expStatsTime = 0;
//this.maxCount = 50;
//this.orderExpBy = function (me, user) {
// return me.exp > user.exp;
//}
//this.addExpItem = function (me) {
// return {
// id: me.id,
// value: me.exp,
// name: me.color_name
// };
//}
//this.reStats = function (result,func) {
// for (let i = 0; i < WORLD.USERS.length; i++) {
// this.addToExpQueue(WORLD.USERS[i], result, func);
// }
// let str = [];
// for (let i = 0; i < result.length; i++) {
// let user = result[i];
// str.push(i + 1, "、\t", user.name, '\t', user.value, '\r\n');
// }
// let time = new Date();
// str.push("最后更新时间", time.getHours() + ":" + time.getMinutes());
// return str.join("");
//}
//this.addToExpQueue = function (me, result, func) {
// let index = result.length - 1;
// if (index < 0) {
// result.push(func(me));
// return;
// }
// let user = result[index];
// if (result.length >= this.maxCount && user.exp > me.exp) {
// return;
// }
// while (index >= 0) {
// user = result[index];
// if (user.exp > me.exp) {
// result.splice(index + 1, 0, func(me));
// break;
// }
// index--;
// }
// if (index < 0) {
// result.splice(0, 0, func(me));
// }
// if (result.length >= this.maxCount) {
// result.length = this.maxCount;
// }
//}

122
world/cmd/dialog/store.js Normal file
View File

@@ -0,0 +1,122 @@
this.inherits(COMMAND);
this.command = "store";
this.regex = /^(?:(\d+)\s)?(\w+)$/;// /^(?:(\d+))?(?:\s+(\w+))?$/;
this.enter = function (me, count, arg) {
if (arg && arg.length < 2) {
count = arg;
arg = null;
}
if (arg) {
me.items = me.items || [];
let target = me;
if (!me.is_player) {
if (!me.master) return;
target = WORLD.getUser(me.master);
if (!target) return;
}
target.stores = target.stores || [];
if (arg === 'all') return this.store_all(target, me);
let move_item = me.find_obj(arg), store_item = null;
if (!move_item) return me.notify("你要存什么东西?");
const st = { items: target.stores, push_item: me.push_item };
if (target.stores.length >= target.max_store_count) {
if (!move_item.combined)
return me.notify("你的仓库放不下那么多东西了。");
store_item = me.find_obj_bypath(move_item.path, st);
if (!store_item) return me.notify("你的仓库放不下那么多东西了。");
// old_item.count += move_count;
}
let move_count = move_item.count;
if (count !== undefined) {
move_count = parseInt(count);
}
if (!(move_count <= move_item.count)) return me.notify("你要存什么东西?");
move_item = me.remove_item_byid(arg, move_count);
if (move_item.combined && store_item) {
store_item.count += move_count;
move_item = store_item;
} else {
move_item = st.push_item(move_item);
}
// move_item = null, move_count = 0;
// if (count !== undefined) {
// move_count = parseInt(count);
// if (!(move_count >= 0)) return;
// move_item = me.remove_item_byid(arg, move_count);
// if (!move_item) return me.notify("你要存什么东西?");
// } else {
// move_item = me.remove_item_byid(arg);
// if (!move_item) return me.notify("你要存什么东西?");
// move_count = move_item.count;
// }
// move_item = st.push_item(move_item);
me.send("你把" + UTIL.to_c(move_count) + move_item.unit + move_item.color_name + "存入仓库。");
return me.notify('{type:"dialog",dialog:"list",id:"' +
arg + '",storeid:"' + move_item.id + '",store:' +
move_count + ',sum:' + target.stores.length + '}');
}
if (!me.is_player) return;
var items = me.stores || [];
var str = ['{"type":"dialog","dialog":"list","stores":['];
if (me.max_store_count > 200) {
var otype = parseInt(count ?? 0);
if (!(otype >= 0)) otype = 0;
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (item.otype !== otype) continue;
if (str.length > 1) str.push(",");
str.push(item.format_to_pack());
}
str.push(']');
str.push(",max_store_count:");
str.push(me.max_store_count);
str.push(",sum:");
str.push(items.length);
} else {
for (var i = 0; i < items.length; i++) {
if (i > 0) str.push(",");
str.push(items[i].format_to_pack());
}
str.push(']');
str.push(",max_store_count:");
str.push(me.max_store_count);
}
str.push("}");
me.send(str.join(""));
}
this.store_all = function (target, me) {//target仓库所有人=玩家 me玩家或者随从
// if (me !== notifier) return;
if (me.query_temp('store_all'))
return me.send('背包的道具已经自动合并到仓库中。');
const idToIndex = new Map();
for (let i = 0; i < target.stores.length; i++) {
let item = target.stores[i];
if (!item.combined) continue;
idToIndex.set(item.path, i);
}
for (let i = 0; i < me.items.length; i++) {
let move_item = me.items[i];
if (!move_item.combined) continue;
const indexIn = idToIndex.get(move_item.path);
if (indexIn >= 0) {
let store_item = target.stores[indexIn];
store_item.count += move_item.count;
me.send("你把" + UTIL.to_c(move_item.count) + move_item.unit + move_item.color_name + "存入仓库。");
target.notify('{type:"dialog",dialog:"list",id:"' + move_item.id + '",storeid:"' + store_item.id + '",store:' + move_item.count + '}');
me.items.splice(i, 1);
i--;
}
}
me.send('你将背包中的道具自动合并到仓库中已有的道具。');
me.set_temp('store_all', 1, 6000);
}

64
world/cmd/dialog/task.js Normal file
View File

@@ -0,0 +1,64 @@
this.inherits(COMMAND);
this.command = "task";
this.regex = /(\w+)\s+(\w+)(?:\s(\w+))?(?:\s(\w+))?/;
this.allow_state = true;
this.enter = function (me, tid, cmd, oid) {
if (!tid || !cmd) return;
if (!me.is_player || !WORLD.is_server(me)) return;
if (tid === 'all') return this.tasks_fin(me);
let task = USERTASK.GET(tid);
if (!task) return me.notify("没有这个任务。");
let target = null;
if (!oid && !(ALLOW_COMMANDS[cmd])) {
oid = cmd;
cmd = 'start';
}
if (oid) {
target = me.find_obj(oid, me.environment);
if (!target) return me.notify("这里没有这个人。");
}
switch (cmd) {
case "fin":
this.task_fin(me, task);
break;
case "start":
task.start(me, target);
break;
case "giveup":
task.giveup(me);
break;
case "fin2":
this.task_fin(me, task, 'ok');
break;
}
}
const ALLOW_COMMANDS = {
start: true,
giveup: true,
fin: true,
fin2: true
};
this.task_fin = function (me, task, par) {
if (task.on_finish(me, par)) {
const obj = {};
obj.type = "dialog";
obj.dialog = "tasks";
obj.id = task.id;
obj.state = task.query_state(me);
if (obj.state) {
obj.title = task.query_title(me);
obj.desc = task.query_desc(me);
}
return me.notify(JSON.stringify(obj));
}
}
this.tasks_fin = function (me) {
for (let i = 0; i < WORLD.TASKS.length; i++) {
const task = WORLD.TASKS[i];
if (task.query_state(me) === 2) {
this.task_fin(me, task);
}
}
}

25
world/cmd/dialog/tasks.js Normal file
View File

@@ -0,0 +1,25 @@
this.inherits(COMMAND);
this.command = "tasks";
this.allow_busy = true;
this.allow_state = true;
this.allow_die = true;
this.allow_faint = true;
this.enter = function (me, arg) {
var obj = {};
obj.type = "dialog";
obj.dialog = "tasks";
obj.items = [];
for (var i = 0; i < WORLD.TASKS.length; i++) {
var task = WORLD.TASKS[i];
var state=task.query_state(me);
if (!state) continue;
obj.items.push({
id:task.id,
title: task.query_title(me),
desc: task.query_desc(me),
state: state,
});
}
me.notify( JSON.stringify(obj));
}

13
world/cmd/dialog/trade.js Normal file
View File

@@ -0,0 +1,13 @@
this.inherits(COMMAND);
this.command = "trade";
this.allow_fight = false;
this.enter = function (me, arg) {
if (!arg) return;
var target = me.find_obj(arg, me.environment);
if (!target) {
return me.notify("这里没有这个人。");
}
if (target.is_player) return me.notify("你不能和玩家交易。");
me.send('{"type":"dialog","dialog":"trade",target:"' + target.id + '",name:"' + target.name + '"}');
}