cgserver 6.0.6 → 6.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/AI/AiObject.js +10 -0
- package/dist/lib/AI/Astar.js +133 -0
- package/dist/lib/AI/BehaviorAI.js +307 -0
- package/dist/lib/AI/Entity.js +33 -0
- package/dist/lib/AI/Point.js +68 -0
- package/dist/lib/AI/TriggerMgr.js +201 -0
- package/dist/lib/Config/Config.js +37 -0
- package/dist/lib/Config/FrameworkConfig.js +234 -0
- package/dist/lib/Config/ServerConfig.js +18 -0
- package/dist/lib/Config/_error_.js +35 -0
- package/dist/lib/Core/Core.js +561 -0
- package/dist/lib/Core/Timer.js +116 -0
- package/dist/lib/Database/BaseMongoService.js +79 -0
- package/dist/lib/Database/BaseService.js +281 -0
- package/dist/lib/Database/Decorator/AutoIncrement.js +11 -0
- package/dist/lib/Database/Decorator/DBCache.js +64 -0
- package/dist/lib/Database/Decorator/NotNull.js +11 -0
- package/dist/lib/Database/Decorator/PrimaryKey.js +11 -0
- package/dist/lib/Database/Decorator/Property.js +61 -0
- package/dist/lib/Database/Decorator/Table.js +15 -0
- package/dist/lib/Database/Decorator/Type.js +20 -0
- package/dist/lib/Database/MSSqlManager.js +43 -0
- package/dist/lib/Database/MongoManager.js +401 -0
- package/dist/lib/Database/MysqlManager.js +180 -0
- package/dist/lib/Database/RedisManager.js +408 -0
- package/dist/lib/Logic/CacheTool.js +73 -0
- package/dist/lib/Logic/HttpTool.js +58 -0
- package/dist/lib/Logic/Log.js +77 -0
- package/dist/lib/Service/AccountService.js +473 -0
- package/dist/lib/Service/MongoAccountService.js +396 -0
- package/dist/lib/Service/MongoCacheService.js +27 -0
- package/dist/lib/Service/MongoUserService.js +93 -0
- package/dist/lib/Service/UserService.js +184 -0
- package/dist/lib/Service/ini.js +35 -0
- package/dist/lib/SocketServer/IClientWebSocket.js +71 -0
- package/dist/lib/SocketServer/IServerWebSocket.js +41 -0
- package/dist/lib/SocketServer/ISocketServer.js +190 -0
- package/dist/lib/SocketServer/IWebSocket.js +223 -0
- package/dist/lib/SocketServer/ProtoFilter/GoogleProtoFilter.js +57 -0
- package/dist/lib/SocketServer/ProtoFilter/IProtoFilter.js +8 -0
- package/dist/lib/SocketServer/ProtoFilter/JsonProtoFilter.js +29 -0
- package/dist/lib/SocketServer/ProtoFilter/ProtoFactory.js +31 -0
- package/dist/lib/ThirdParty/AlipayTool.js +122 -0
- package/dist/lib/ThirdParty/Alisms.js +46 -0
- package/dist/lib/ThirdParty/AppleTool.js +234 -0
- package/dist/lib/ThirdParty/EmailTool.js +33 -0
- package/dist/lib/ThirdParty/OpenSocial.js +32 -0
- package/dist/lib/ThirdParty/QQTool.js +115 -0
- package/dist/lib/ThirdParty/QiniuTool.js +21 -0
- package/dist/lib/ThirdParty/WechatOATool.js +61 -0
- package/dist/lib/ThirdParty/WechatTool.js +74 -0
- package/dist/lib/WebServer/Controller/BaseController.js +112 -0
- package/dist/lib/WebServer/Controller/BaseUserController.js +168 -0
- package/dist/lib/WebServer/Controller/MongoBaseUserController.js +168 -0
- package/dist/lib/WebServer/Decorator/AdminValidate.js +19 -0
- package/dist/lib/WebServer/Decorator/AuthorityValidate.js +22 -0
- package/dist/lib/WebServer/Decorator/CreatorValidate.js +19 -0
- package/dist/lib/WebServer/Decorator/JsonAdminValidate.js +15 -0
- package/dist/lib/WebServer/Decorator/JsonAuthorityValidate.js +20 -0
- package/dist/lib/WebServer/Decorator/JsonCreatorValidate.js +19 -0
- package/dist/lib/WebServer/Engine/ControllerManager.js +112 -0
- package/dist/lib/WebServer/Engine/Engine.js +135 -0
- package/dist/lib/WebServer/Engine/RazorJs.js +544 -0
- package/dist/lib/WebServer/Engine/Request.js +214 -0
- package/dist/lib/WebServer/Engine/Response.js +94 -0
- package/dist/lib/WebServer/IWebServer.js +49 -0
- package/dist/lib/cgserver.js +153 -0
- package/dist/{AI → types/AI}/AiObject.d.ts +0 -0
- package/dist/{AI → types/AI}/Astar.d.ts +0 -0
- package/dist/{AI → types/AI}/BehaviorAI.d.ts +0 -0
- package/dist/{AI → types/AI}/Entity.d.ts +0 -0
- package/dist/{AI → types/AI}/Point.d.ts +0 -0
- package/dist/{AI → types/AI}/TriggerMgr.d.ts +0 -0
- package/dist/{Config → types/Config}/Config.d.ts +0 -0
- package/dist/{Config → types/Config}/FrameworkConfig.d.ts +0 -0
- package/dist/{Config → types/Config}/ServerConfig.d.ts +0 -0
- package/dist/{Config → types/Config}/_error_.d.ts +0 -0
- package/dist/{Core → types/Core}/Core.d.ts +0 -0
- package/dist/{Core → types/Core}/Timer.d.ts +0 -0
- package/dist/{Database → types/Database}/BaseMongoService.d.ts +0 -0
- package/dist/{Database → types/Database}/BaseService.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/AutoIncrement.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/DBCache.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/NotNull.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/PrimaryKey.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/Property.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/Table.d.ts +0 -0
- package/dist/{Database → types/Database}/Decorator/Type.d.ts +0 -0
- package/dist/{Database → types/Database}/MSSqlManager.d.ts +0 -0
- package/dist/{Database → types/Database}/MongoManager.d.ts +0 -0
- package/dist/{Database → types/Database}/MysqlManager.d.ts +0 -0
- package/dist/{Database → types/Database}/RedisManager.d.ts +0 -0
- package/dist/{Logic → types/Logic}/CacheTool.d.ts +0 -0
- package/dist/{Logic → types/Logic}/HttpTool.d.ts +0 -0
- package/dist/{Logic → types/Logic}/Log.d.ts +0 -0
- package/dist/{Service → types/Service}/AccountService.d.ts +0 -0
- package/dist/{Service → types/Service}/MongoAccountService.d.ts +0 -0
- package/dist/{Service → types/Service}/MongoCacheService.d.ts +0 -0
- package/dist/{Service → types/Service}/MongoUserService.d.ts +0 -0
- package/dist/{Service → types/Service}/UserService.d.ts +0 -0
- package/dist/{Service → types/Service}/ini.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/IClientWebSocket.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/IServerWebSocket.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/ISocketServer.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/IWebSocket.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/ProtoFilter/GoogleProtoFilter.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/ProtoFilter/IProtoFilter.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/ProtoFilter/JsonProtoFilter.d.ts +0 -0
- package/dist/{SocketServer → types/SocketServer}/ProtoFilter/ProtoFactory.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/AlipayTool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/Alisms.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/AppleTool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/EmailTool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/OpenSocial.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/QQTool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/QiniuTool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/WechatOATool.d.ts +0 -0
- package/dist/{ThirdParty → types/ThirdParty}/WechatTool.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Controller/BaseController.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Controller/BaseUserController.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Controller/MongoBaseUserController.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/AdminValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/AuthorityValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/CreatorValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/JsonAdminValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/JsonAuthorityValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Decorator/JsonCreatorValidate.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Engine/ControllerManager.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Engine/Engine.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Engine/RazorJs.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Engine/Request.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/Engine/Response.d.ts +0 -0
- package/dist/{WebServer → types/WebServer}/IWebServer.d.ts +0 -0
- package/dist/{cgserver.d.ts → types/cgserver.d.ts} +0 -0
- package/package.json +3 -2
- package/dist/cgserver.js +0 -1037
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AStar = exports.Rect = void 0;
|
|
4
|
+
const Point_1 = require("./Point");
|
|
5
|
+
class Rect {
|
|
6
|
+
x = 0;
|
|
7
|
+
y = 0;
|
|
8
|
+
width = 0;
|
|
9
|
+
height = 0;
|
|
10
|
+
}
|
|
11
|
+
exports.Rect = Rect;
|
|
12
|
+
class AStarNode {
|
|
13
|
+
ParentNode = null;
|
|
14
|
+
CurTilePos = null;
|
|
15
|
+
G = 0;
|
|
16
|
+
H = 0;
|
|
17
|
+
constructor(node, tilePos) {
|
|
18
|
+
this.ParentNode = node;
|
|
19
|
+
this.CurTilePos = tilePos;
|
|
20
|
+
if (this.ParentNode) {
|
|
21
|
+
this.G = this.ParentNode.G + 10;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.G = 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
F() {
|
|
28
|
+
return this.G + this.H;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class AStar {
|
|
32
|
+
_markList = null;
|
|
33
|
+
_markedList = null;
|
|
34
|
+
_routes = null;
|
|
35
|
+
_maxTileWidth = 0;
|
|
36
|
+
_maxTileHeight = 0;
|
|
37
|
+
/**
|
|
38
|
+
* 先y在x,p(x:1,y:2),data[2][1]
|
|
39
|
+
*/
|
|
40
|
+
_mapData = null;
|
|
41
|
+
getRoutes(srcTilePos, tarTilePos, mapData) {
|
|
42
|
+
if (srcTilePos.equals(tarTilePos)) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
this._markList = [];
|
|
46
|
+
this._markedList = [];
|
|
47
|
+
this._routes = [];
|
|
48
|
+
this._mapData = mapData;
|
|
49
|
+
this._maxTileWidth = this._mapData.width();
|
|
50
|
+
this._maxTileHeight = this._mapData.height();
|
|
51
|
+
let tp = srcTilePos.sub(tarTilePos);
|
|
52
|
+
let node = new AStarNode(null, srcTilePos);
|
|
53
|
+
node.H = (Math.abs(tp.x) + Math.abs(tp.y)) * 10 + mapData.extraWeight(tarTilePos);
|
|
54
|
+
this._markList.push(node);
|
|
55
|
+
node = this._routing(srcTilePos, tarTilePos);
|
|
56
|
+
while (node) {
|
|
57
|
+
this._routes.push(node.CurTilePos);
|
|
58
|
+
node = node.ParentNode;
|
|
59
|
+
}
|
|
60
|
+
this._routes.reverse();
|
|
61
|
+
this._routes.shift();
|
|
62
|
+
return this._routes;
|
|
63
|
+
}
|
|
64
|
+
_routing(srcTilePos, tarTilePos) {
|
|
65
|
+
if (this._markList.length <= 0) //已经没有节点,是死路根本无法到达
|
|
66
|
+
{
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
let node = this._markList[0];
|
|
70
|
+
let curIndex = 0;
|
|
71
|
+
for (let i = 0; i < this._markList.length; ++i) {
|
|
72
|
+
if (node.F() > this._markList[i].F()) {
|
|
73
|
+
node = this._markList[i];
|
|
74
|
+
curIndex = i;
|
|
75
|
+
}
|
|
76
|
+
if (this._markList[i].CurTilePos.equals(tarTilePos)) //到达终点
|
|
77
|
+
{
|
|
78
|
+
return this._markList[i];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
this._markList.splice(curIndex, 1);
|
|
82
|
+
this._markedList.push(node);
|
|
83
|
+
let tp = new Point_1.Point(0, 0);
|
|
84
|
+
//上
|
|
85
|
+
tp.x = node.CurTilePos.x;
|
|
86
|
+
tp.y = node.CurTilePos.y + 1;
|
|
87
|
+
this._addToMark(tp, tarTilePos, node);
|
|
88
|
+
//下
|
|
89
|
+
tp = new Point_1.Point(0, 0);
|
|
90
|
+
tp.x = node.CurTilePos.x;
|
|
91
|
+
tp.y = node.CurTilePos.y - 1;
|
|
92
|
+
this._addToMark(tp, tarTilePos, node);
|
|
93
|
+
//左
|
|
94
|
+
tp = new Point_1.Point(0, 0);
|
|
95
|
+
tp.x = node.CurTilePos.x - 1;
|
|
96
|
+
tp.y = node.CurTilePos.y;
|
|
97
|
+
this._addToMark(tp, tarTilePos, node);
|
|
98
|
+
//右
|
|
99
|
+
tp = new Point_1.Point(0, 0);
|
|
100
|
+
tp.x = node.CurTilePos.x + 1;
|
|
101
|
+
tp.y = node.CurTilePos.y;
|
|
102
|
+
this._addToMark(tp, tarTilePos, node);
|
|
103
|
+
return this._routing(srcTilePos, tarTilePos);
|
|
104
|
+
}
|
|
105
|
+
_isInMark(tilePos) {
|
|
106
|
+
for (let i = 0; i < this._markList.length; ++i) {
|
|
107
|
+
if (this._markList[i].CurTilePos.equals(tilePos)) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (let i = 0; i < this._markedList.length; ++i) {
|
|
112
|
+
if (this._markedList[i].CurTilePos.equals(tilePos)) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
_addToMark(curTilePos, tarTilePos, parentAStarNode) {
|
|
119
|
+
//无地图数据
|
|
120
|
+
if (curTilePos.x < 0 || curTilePos.y < 0
|
|
121
|
+
|| !this._mapData.canPass(curTilePos)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (!this._isInMark(curTilePos)) //未曾添加
|
|
125
|
+
{
|
|
126
|
+
let newNode = new AStarNode(parentAStarNode, curTilePos);
|
|
127
|
+
let temp_tp = parentAStarNode.CurTilePos.sub(tarTilePos);
|
|
128
|
+
newNode.H = (Math.abs(temp_tp.x) + Math.abs(temp_tp.y)) * 10;
|
|
129
|
+
this._markList.push(newNode);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.AStar = AStar;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BehaviorAI = void 0;
|
|
4
|
+
const Log_1 = require("./../Logic/Log");
|
|
5
|
+
const Core_1 = require("./../Core/Core");
|
|
6
|
+
const _ = require("underscore");
|
|
7
|
+
const TriggerMgr_1 = require("./TriggerMgr");
|
|
8
|
+
class BehaviorAI {
|
|
9
|
+
_obj;
|
|
10
|
+
_targetObjs;
|
|
11
|
+
_triggers;
|
|
12
|
+
_behavior_data;
|
|
13
|
+
_current_behavior;
|
|
14
|
+
_current_behavior_name = "";
|
|
15
|
+
_current_check;
|
|
16
|
+
_targetObj;
|
|
17
|
+
constructor(behavior_data, obj, targetObjs) {
|
|
18
|
+
this._obj = obj;
|
|
19
|
+
this._behavior_data = behavior_data;
|
|
20
|
+
if (Core_1.core.isArray(targetObjs)) {
|
|
21
|
+
this._targetObjs = targetObjs;
|
|
22
|
+
}
|
|
23
|
+
else if (targetObjs) {
|
|
24
|
+
this._targetObjs[0] = targetObjs;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this._targetObjs = [];
|
|
28
|
+
}
|
|
29
|
+
this._triggers = [];
|
|
30
|
+
let code = TriggerMgr_1.GTriggerMgr.addConditionTriggerEvent(TriggerMgr_1.EConditionType.Die, this.onTriggerDie.bind(this), { code: this._obj.getCode() });
|
|
31
|
+
this._triggers.push({ type: TriggerMgr_1.EConditionType.Die, code: code });
|
|
32
|
+
}
|
|
33
|
+
//启动行为树AI
|
|
34
|
+
start() {
|
|
35
|
+
if (!this._behavior_data) {
|
|
36
|
+
Log_1.GLog.info("------------error------------this._behavior_data can not be null!", true);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.goto(this._behavior_data.start);
|
|
40
|
+
}
|
|
41
|
+
//结束行为树AI
|
|
42
|
+
end() {
|
|
43
|
+
for (let i = 0, length = this._triggers.length; i < length; ++i) {
|
|
44
|
+
TriggerMgr_1.GTriggerMgr.removeConditionTriggerEvent(this._triggers[i].type, this._triggers[i].code);
|
|
45
|
+
}
|
|
46
|
+
this._triggers = [];
|
|
47
|
+
}
|
|
48
|
+
//帧检查
|
|
49
|
+
//支持多条件check
|
|
50
|
+
update(dt) {
|
|
51
|
+
if (this._current_check.length < 0) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
for (let i = 0; i < this._current_check.length; ++i) {
|
|
55
|
+
let current = this._current_check[i];
|
|
56
|
+
//目前只支持同时存在一个update检查
|
|
57
|
+
if (current.event_name == "target_insight") {
|
|
58
|
+
let targetInfo = this._getNearestTarget();
|
|
59
|
+
if (targetInfo) {
|
|
60
|
+
let target = targetInfo.target;
|
|
61
|
+
let distance = targetInfo.distance;
|
|
62
|
+
if (distance <= this._behavior_data.insight) //视野发现敌人
|
|
63
|
+
{
|
|
64
|
+
this._current_check = this._current_check.splice(i, 1);
|
|
65
|
+
--i;
|
|
66
|
+
let forceReturn = this._doEvents(this._current_behavior.conditions[current.event_name]);
|
|
67
|
+
if (forceReturn) {
|
|
68
|
+
return; //防止goto修改this._current_check后,做了立刻check
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (current.event_name == "sure") {
|
|
74
|
+
this._current_check = this._current_check.splice(i, 1);
|
|
75
|
+
--i;
|
|
76
|
+
let forceReturn = this._doEvents(this._current_behavior.conditions[current.event_name]);
|
|
77
|
+
if (forceReturn) {
|
|
78
|
+
return; //防止goto修改this._current_check后,做了立刻check
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (current.event_name == "near") {
|
|
82
|
+
if (this._targetObj) {
|
|
83
|
+
let objPos = this._obj.getPosition();
|
|
84
|
+
let tpos = this._targetObj.getPosition();
|
|
85
|
+
let distance = objPos.sub(tpos).length(); //目标和自己的距离
|
|
86
|
+
let dty = objPos.y - tpos.y;
|
|
87
|
+
dty = dty >= 0 ? dty : -dty;
|
|
88
|
+
if (distance <= current.distance && dty <= 10) //视野发现敌人
|
|
89
|
+
{
|
|
90
|
+
this._current_check = this._current_check.splice(i, 1);
|
|
91
|
+
--i;
|
|
92
|
+
let forceReturn = this._doEvents(this._current_behavior.conditions[current.event_name]);
|
|
93
|
+
if (forceReturn) {
|
|
94
|
+
return; //防止goto修改this._current_check后,做了立刻check
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this._current_check = this._current_check.splice(i, 1);
|
|
100
|
+
--i;
|
|
101
|
+
let forceReturn = this._doEvents(this._current_behavior.conditions[current.event_name], true);
|
|
102
|
+
if (forceReturn) {
|
|
103
|
+
return; //防止goto修改this._current_check后,做了立刻check
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (current.event_name == "timeout") {
|
|
108
|
+
current.time -= dt;
|
|
109
|
+
if (current.time <= 0) {
|
|
110
|
+
this._current_check = this._current_check.splice(i, 1);
|
|
111
|
+
--i;
|
|
112
|
+
let forceReturn = this._doEvents(this._current_behavior.conditions[current.event_name]);
|
|
113
|
+
if (forceReturn) {
|
|
114
|
+
return; //防止goto修改this._current_check后,做了立刻check
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//goto事件
|
|
121
|
+
goto(behavior_name) {
|
|
122
|
+
//GLog.info("=====goto behavior=" + behavior_name);
|
|
123
|
+
if (this._behavior_data && this._behavior_data.name == behavior_name) {
|
|
124
|
+
return; //拒绝相同行为跳转
|
|
125
|
+
}
|
|
126
|
+
this._current_check = [];
|
|
127
|
+
this._current_behavior = this._behavior_data.behaviors[behavior_name];
|
|
128
|
+
//全局条件
|
|
129
|
+
if (this._behavior_data.conditions) {
|
|
130
|
+
this._checkConditions(this._behavior_data.conditions);
|
|
131
|
+
}
|
|
132
|
+
//行为条件
|
|
133
|
+
if (this._current_behavior.conditions) {
|
|
134
|
+
this._checkConditions(this._current_behavior.conditions);
|
|
135
|
+
}
|
|
136
|
+
if (this._current_behavior.animation) {
|
|
137
|
+
if (!this._current_behavior.conditions.animation_done) {
|
|
138
|
+
this._obj.behaviorAnimation(this._current_behavior.animation.name, this._current_behavior.animation.loop);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
let self = this;
|
|
142
|
+
this._obj.behaviorAnimation(this._current_behavior.animation.name, this._current_behavior.animation.loop, function () {
|
|
143
|
+
self._doEvents(self._current_behavior.conditions.animation_done);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
Log_1.GLog.info("---------warning--------_goto->behavior_name=" + behavior_name + ".animaiton not exist!");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//检查有没有已经达到的条件,又的话就执行他的相关事件
|
|
152
|
+
_checkConditions(conditions) {
|
|
153
|
+
if (!conditions) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
for (let key in conditions) {
|
|
157
|
+
switch (key) {
|
|
158
|
+
case "target_insight":
|
|
159
|
+
{
|
|
160
|
+
this._current_check.push({ event_name: key });
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
case "timeout":
|
|
164
|
+
{
|
|
165
|
+
this._current_check.push({ event_name: key, time: conditions[key].time });
|
|
166
|
+
}
|
|
167
|
+
break;
|
|
168
|
+
case "sure":
|
|
169
|
+
{
|
|
170
|
+
this._current_check.push({ event_name: key }); //下次update执行
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
case "near":
|
|
174
|
+
{
|
|
175
|
+
this._targetObj = null;
|
|
176
|
+
this._current_check.push({ event_name: key, distance: conditions[key].distance });
|
|
177
|
+
let targetInfo = this._getNearestTarget();
|
|
178
|
+
if (targetInfo) {
|
|
179
|
+
if (this._behavior_data.name == "sm")
|
|
180
|
+
Log_1.GLog.info("distance" + targetInfo.distance);
|
|
181
|
+
this._targetObj = targetInfo.target;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
//执行事件
|
|
191
|
+
_doEvents(events, fail = false) {
|
|
192
|
+
if (!events) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
if (fail && events.failto) {
|
|
196
|
+
this.goto(events.failto);
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
let forceReturn = false;
|
|
200
|
+
for (let key in events) {
|
|
201
|
+
switch (key) {
|
|
202
|
+
case "goto":
|
|
203
|
+
{
|
|
204
|
+
this.goto(events[key]);
|
|
205
|
+
forceReturn = true;
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
case "walk_any":
|
|
209
|
+
{
|
|
210
|
+
if (this._obj.behaviorWalkAny) {
|
|
211
|
+
this._obj.behaviorWalkAny();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
case "persue":
|
|
216
|
+
{
|
|
217
|
+
if (this._obj.behaviorPersue && this._targetObj) {
|
|
218
|
+
this._obj.behaviorPersue(this._targetObj);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
case "call":
|
|
223
|
+
{
|
|
224
|
+
if (events[key].fun && this._obj[events[key].fun]) {
|
|
225
|
+
this._obj[events[key].fun](events[key].params);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
case "random":
|
|
230
|
+
{
|
|
231
|
+
let r = _.random(0, 100); //百分率
|
|
232
|
+
let rate = 0;
|
|
233
|
+
let done = false;
|
|
234
|
+
//最后一条不参与检测
|
|
235
|
+
for (let i = 0, length = events[key].length; i < length - 1; ++i) {
|
|
236
|
+
rate += events[key][i].rate;
|
|
237
|
+
if (r <= rate) {
|
|
238
|
+
forceReturn = this._doEvents(events[key][i].events);
|
|
239
|
+
done = true;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
//如果前面都没有成功,必须保证最后一条得到执行
|
|
244
|
+
if (!done) {
|
|
245
|
+
forceReturn = this._doEvents(events[key][events[key].length - 1].events);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
default:
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return forceReturn;
|
|
253
|
+
}
|
|
254
|
+
//角色死亡触发
|
|
255
|
+
onTriggerDie(userDM) {
|
|
256
|
+
if (!userDM) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (this._obj.getCode() === userDM.code) {
|
|
260
|
+
this.goto("die");
|
|
261
|
+
this.end();
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
for (let i = 0, length = this._targetObjs.length; i < length; ++i) {
|
|
265
|
+
if (this._targetObjs[i].getCode() === userDM.code) {
|
|
266
|
+
this._targetObjs = this._targetObjs.splice(i, 1);
|
|
267
|
+
if (this._targetObj.getCode() === userDM.code) {
|
|
268
|
+
this._targetObj = null;
|
|
269
|
+
}
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
//获取最近的target
|
|
276
|
+
_getNearestTarget() {
|
|
277
|
+
let targetNum = this._targetObjs.length;
|
|
278
|
+
if (targetNum <= 0) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
let objPos = this._obj.getPosition();
|
|
282
|
+
if (targetNum == 1) {
|
|
283
|
+
return { target: this._targetObjs[0], distance: objPos.sub(this._targetObjs[0].getPosition()).length() };
|
|
284
|
+
}
|
|
285
|
+
let minIndex = 0;
|
|
286
|
+
let mindis = objPos.sub(this._targetObjs[0].getPosition()).length();
|
|
287
|
+
for (let i = 1; i < targetNum; ++i) {
|
|
288
|
+
let dis = objPos.sub(this._targetObjs[i].getPosition()).length();
|
|
289
|
+
if (mindis > dis) {
|
|
290
|
+
mindis = dis;
|
|
291
|
+
minIndex = i;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return { target: this._targetObjs[minIndex], distance: mindis };
|
|
295
|
+
}
|
|
296
|
+
//添加target
|
|
297
|
+
addTarget(target) {
|
|
298
|
+
if (!target) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
this._targetObjs.push(target);
|
|
302
|
+
}
|
|
303
|
+
getTargets() {
|
|
304
|
+
return this._targetObjs;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
exports.BehaviorAI = BehaviorAI;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Entity = void 0;
|
|
4
|
+
const Point_1 = require("./Point");
|
|
5
|
+
//世界物体,具有坐标可移动等特性
|
|
6
|
+
class Entity {
|
|
7
|
+
_id = -1;
|
|
8
|
+
get id() {
|
|
9
|
+
return this._id;
|
|
10
|
+
}
|
|
11
|
+
_world_pos = new Point_1.Point();
|
|
12
|
+
get worldPos() {
|
|
13
|
+
return this._world_pos;
|
|
14
|
+
}
|
|
15
|
+
set worldPos(value) {
|
|
16
|
+
this._world_pos = value;
|
|
17
|
+
}
|
|
18
|
+
_cell = new Point_1.Point();
|
|
19
|
+
get cellPos() {
|
|
20
|
+
return this._cell;
|
|
21
|
+
}
|
|
22
|
+
set cellPos(value) {
|
|
23
|
+
this._cell = value;
|
|
24
|
+
}
|
|
25
|
+
initPos(pos) {
|
|
26
|
+
//不能直接赋值,因为是引用
|
|
27
|
+
this._world_pos.x = pos.x + 0.5;
|
|
28
|
+
this._world_pos.y = pos.y + 0.5;
|
|
29
|
+
this._cell.x = pos.x;
|
|
30
|
+
this._cell.y = pos.y;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Entity = Entity;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Point = void 0;
|
|
4
|
+
class Point {
|
|
5
|
+
x = 0;
|
|
6
|
+
y = 0;
|
|
7
|
+
constructor(x = 0, y = 0) {
|
|
8
|
+
this.x = x;
|
|
9
|
+
this.y = y;
|
|
10
|
+
}
|
|
11
|
+
sub(pt) {
|
|
12
|
+
return new Point(this.x - pt.x, this.y - pt.y);
|
|
13
|
+
}
|
|
14
|
+
subSelf(pt) {
|
|
15
|
+
this.x -= pt.x;
|
|
16
|
+
this.y -= pt.y;
|
|
17
|
+
}
|
|
18
|
+
add(pt) {
|
|
19
|
+
return new Point(this.x + pt.x, this.y + pt.y);
|
|
20
|
+
}
|
|
21
|
+
addSelf(pt) {
|
|
22
|
+
this.x += pt.x;
|
|
23
|
+
this.y += pt.y;
|
|
24
|
+
}
|
|
25
|
+
equals(pt) {
|
|
26
|
+
return this.x == pt.x && this.y == pt.y;
|
|
27
|
+
}
|
|
28
|
+
fuzzyEqual(pt, w) {
|
|
29
|
+
let dtx = Math.abs(this.x - pt.x);
|
|
30
|
+
if (dtx >= w) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
let dty = Math.abs(this.y - pt.y);
|
|
34
|
+
if (dty >= w) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
length() {
|
|
40
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
41
|
+
}
|
|
42
|
+
mul(n) {
|
|
43
|
+
return new Point(this.x * n, this.y * n);
|
|
44
|
+
}
|
|
45
|
+
mulSelf(n) {
|
|
46
|
+
this.x *= n;
|
|
47
|
+
this.y *= n;
|
|
48
|
+
}
|
|
49
|
+
toI() {
|
|
50
|
+
return new Point(Math.floor(this.x), Math.floor(this.y));
|
|
51
|
+
}
|
|
52
|
+
normalize() {
|
|
53
|
+
let len = this.length();
|
|
54
|
+
if (len == 0) {
|
|
55
|
+
return new Point();
|
|
56
|
+
}
|
|
57
|
+
return new Point(this.x / len, this.y / len);
|
|
58
|
+
}
|
|
59
|
+
normalizeSelf() {
|
|
60
|
+
let len = this.length();
|
|
61
|
+
if (len == 0) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.x /= len;
|
|
65
|
+
this.y /= len;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.Point = Point;
|