-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnpc.js
116 lines (94 loc) · 2.96 KB
/
npc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var extend = require('./oo.js'),
Char = require('./character.js'),
fs = require('fs'),
path = require ('path');
var NPC = extend(function() {
if (!(this instanceof NPC))
return new NPC();
this.wimpy_ratio = 0; //make npc do not flee as default.
this.inquiries = {};
}, Char);
NPC.loadFromJSON = function(data) {
for (var key in data) {
logger.debug('key is ' + key + ', value is' + data[key]);
}
}
NPC.load = function(filename) {
var data = require(filename);
return NPC.loadFromJSON(data);
}
NPC.prototype.accept_fight = function(who) {
if (!who)
return 0;
var RANK_D = global._daemons.rankd;
if (this.is_fighting()) {
if (this.query_flag('can_speak'))
this.command("say", RANK_D.query_respect(who) + "想要倚多取胜吗?");
return 0;
}
if (this.query_flag('can_speak') && this.vitality * 100 / this.max_vitality > 90) {
this.command("say", "既然" + RANK_D.query_respect(who)
+ "赐教," + RANK_D.query_self(this)
+ "只好奉陪,我们点到为止。");
return 1;
}
return 0;
}
NPC.prototype.return_home = function() {
var env = FUNCTIONS.environment(this);
if (!env || env === this.home)
return 1;
if (!this.home || !this.living() || this.is_busy() || this.is_fighting())
return 0;
message("vision", this.name + "急急忙忙的离开了", env, this);
return this.move_to(this.home);
}
NPC.prototype.chat = function() {
var chance = this.query(this.is_fighting() ?
"chat_chance_combat" : "chat_chance");
if (!chance)
return;
}
NPC.prototype.random_move = function() {
//TODO define nps's move area
}
NPC.prototype.is_vender = function() {
return 0;
}
NPC.prototype.add_inquiry = function(id, name, response) {
this.inquiries[id] = {
name : name,
resp : response,
}
}
NPC.prototype.do_inquiry = function(who, about) {
if (!this.inquiries || !this.inquiries[about])
return FUNCTIONS.notify_fail(who, this.name + "向你摇了摇头,看起来并不清楚你要打听的事情。");
if (this.visiable_inquiry
&& typeof(this.visiable_inquiry) === 'function'
&& !this.visiable_inquiry.call(this, about, who))
return FUNCTIONS.notify_fail(who, this.name + "并不清楚你要打听的事情。");
// show inquiry action
FUNCTIONS.message_vision("$N向$n打听关于 $(HIG)" + this.inquiries[about].name + "$NOR 的消息。\n", who, this);
// handle inquiry & response
if (typeof(this.inquiries[about].resp) === 'string') {
FUNCTIONS.message_vision(this.inquiries[about].resp, this, who);
} else if (typeof(this.inquiries[about].resp) === 'function')
this.inquiries[about].resp.call(this, who);
}
NPC.prototype.query_inquiry = function(who) {
var ret = {};
if (this.inquiries) {
for (var k in this.inquiries) {
if (!this.inquiries[k].name)
continue;
if (this.visiable_inquiry
&& typeof(this.visiable_inquiry) === 'function'
&& !this.visiable_inquiry.call(this, k, who))
continue;
ret[k] = this.inquiries[k].name
}
}
return ret;
}
module.exports = NPC;