|
示例三 完整的剑心居打坐、吐纳、学习技能、读书、领悟和练习的示例,大家可以参考修改
- class Jianxinju {
- //剑心居机器人
- constructor(api, sys) {
- this.api = api;
- this.sys = sys;
- this.init();
- }
- init() {
- const self = this; // 保存this引用
- this.api.alias("learn_skills.stop", () => (self.api.loops.learn_skills = false));
- this.api.alias("learn_skills.start", async () => self.learn_skills());
- this.api.alias("read_shediao.stop", () => (self.api.loops.read_shediao = false));
- this.api.alias("read_shediao.start", async () => self.read_shediao());
- this.api.alias("dazuo.stop", () => (self.api.loops.dazuo = false));
- this.api.alias("dazuo.start", async () => self.dazuo());
- this.api.alias("tuna.stop", () => (self.api.loops.tuna = false));
- this.api.alias("tuna.start", async () => self.tuna());
- this.api.alias("lingwu_lianxi.stop", () => (self.api.loops.lingwu_lianxi = false));
- this.api.alias("lingwu_lianxi.start", async () => self.lingwu_lianxi());
- this.api.action("你的内力修为似乎已经达到了瓶颈。", "dazuo.stop");
- this.api.action("你的精力修为已经达到了瓶颈。", "tuna.stop");
- this.sys.actionOnce("你附近没有 ding 这个人,请用 id here 指令看看周围人物 id 。", "clap 3;teacher;", 60); //找师傅,60秒内只触发一次
- }
- //自动补充食物水
- async auto_food_water() {
- let food = this.api.session.player.data.food;
- let water = this.api.session.player.data.water;
- if (water < 200) {
- this.sys.sendAndEcho("drink");
- await this.sys.sleep(1);
- }
- if (food < 200) {
- this.sys.sendAndEcho("eat gan liang");
- await this.sys.sleep(1);
- }
- }
- //睡眠恢复jing去做消耗jing的动作
- async recover_jing() {
- if (this.api.session.player.data.neili < 30) {
- await this.sys.retry("sleep", "你一觉醒来,精神抖擞地活动了几下手脚", 5, 60);
- }
- if (this.api.session.player.data.jing < 50) {
- this.sys.sendAndEcho("e2");
- await this.sys.sleep(1);
- }
- this.auto_food_water();
- await this.sys.sleep(1);
- }
- async learn_skills() {
- this.api.loops.learn_skills = true;
- while (this.api.loops.learn_skills) {
- await this.recover_jing();
- this.sys.sendAndEcho("xue ding for huagong-dafa 5;xue ding for poison 5");
- }
- this.sys.log("学习技能循环结束");
- }
- async read_shediao() {
- this.api.loops.read_shediao = true;
- while (this.api.loops.read_shediao) {
- await this.recover_jing();
- this.sys.sendAndEcho("read shediao 5");
- }
- this.sys.log("读射雕循环结束");
- }
- async dazuo() {
- this.api.loops.dazuo = true;
- while (this.api.loops.dazuo) {
- let max_neili = this.api.session.player.data.max_neili;
- let neili = this.api.session.player.data.neili;
- let neilipercent = neili / max_neili;
- let qi = this.api.session.player.data.qi;
- if (neilipercent <= 1.2 && qi < 100) {
- await this.sys.retry("sleep", "你一觉醒来,精神抖擞地活动了几下手脚", 5, 30);
- }
- this.auto_food_water();
- if (neili > max_neili * 2 - 30) {
- await this.sys.try("dazuo 10", "你运功完毕,深深吸了口气,站了起来。", 10);
- } else {
- await this.sys.try("dazuo max", "你运功完毕,深深吸了口气,站了起来。", 60);
- }
- await this.sys.sleep(1);
- }
- this.sys.log("打坐循环结束");
- }
- async tuna() {
- this.api.loops.tuna = true;
- while (this.api.loops.tuna) {
- await this.recover_jing();
- let max_jingli = this.api.session.player.data.max_jingli;
- let jingli = this.api.session.player.data.jingli;
- if (jingli > max_jingli * 2 - 20) {
- await this.sys.try("tuna 10", '你吐纳完毕,睁开双眼,站了起来。', 10);
- } else {
- await this.sys.try("tuna max", '你吐纳完毕,睁开双眼,站了起来。', 60);
- }
- }
- this.sys.log("吐纳循环结束");
- }
- async lingwu_lianxi() {
- let self = this;
- let point = 20;
- let cmds = [
- 'lian throwing ' + point, 'lingwu throwing ' + point,
- 'lingwu force ' + point,
- 'lian parry ' + point, 'lingwu parry ' + point,
- 'lian dodge ' + point, 'lingwu dodge ' + point,
- 'lian strike ' + point, 'lingwu strike ' + point]
- this.api.loops.lingwu_lianxi = true;
- this.api.vars.lingwu_lianxi = 0;
- this.api.action('你需要提高基本功,不然练得再多也没有用', () => (self.api.vars.lingwu_lianxi++));
- this.api.action('不能通过练习来提高了', () => (self.api.vars.lingwu_lianxi++));
- this.api.action('你已经达到你的技能等级极限', () => (self.api.vars.lingwu_lianxi++));
- this.api.action('你的基本功夫比你的高级功夫还高', () => (self.api.vars.lingwu_lianxi++));
- this.api.action('你需要提高基本功,不然练得再多也没有用', () => (self.api.vars.lingwu_lianxi++));
- this.api.action('受限于天资', () => (self.api.vars.lingwu_lianxi++));
- this.api.action('必须空手', 'unwield all;');
- try {
- while (this.api.loops.lingwu_lianxi) {
- this.auto_food_water();
- if (this.api.vars.lingwu_lianxi >= cmds.length) {
- this.api.vars.lingwu_lianxi = 0;
- }
- let neili = this.api.session.player.data.neili;
- let qi = this.api.session.player.data.qi;
- let jing = this.api.session.player.data.jing;
- this.sys.log('当前内力:' + neili + ' 当前气:' + qi+ ' 当前精力:' + jing)
- if (neili < 100 && (qi < 100|| jing < 100)) {
- await this.sys.retry("sleep", "你一觉醒来,精神抖擞地活动了几下手脚", 5, 30);
- }
- await this.sys.sleep(1);
- this.api.send('e1;e2;' + cmds[this.api.vars.lingwu_lianxi])
- }
- this.sys.log("领悟练习结束");
- } catch (e) {
- this.sys.log("领悟练习失败:" + e.message);
- this.api.loops.lingwu_lianxi = false;
- }
- }
- }
- module.exports = Jianxinju;
复制代码
|
|