From d05d534b32a7c184818257445915ac3e4fed54a3 Mon Sep 17 00:00:00 2001 From: zengmn <761458545@qq.com> Date: Mon, 19 Mar 2018 17:58:46 +0800 Subject: [PATCH 01/17] kbengine ts plugins beta --- kbengine_ts/bin/kbengine.d.ts | 541 +++++ kbengine_ts/bin/kbengine.js | 3217 +++++++++++++++++++++++++++ kbengine_ts/bin/kbengine.min.js | 3 + kbengine_ts/package.json | 4 + kbengine_ts/src/KBEngine.ts | 3610 +++++++++++++++++++++++++++++++ kbengine_ts/tsconfig.json | 12 + 6 files changed, 7387 insertions(+) create mode 100644 kbengine_ts/bin/kbengine.d.ts create mode 100644 kbengine_ts/bin/kbengine.js create mode 100644 kbengine_ts/bin/kbengine.min.js create mode 100644 kbengine_ts/package.json create mode 100644 kbengine_ts/src/KBEngine.ts create mode 100644 kbengine_ts/tsconfig.json diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts new file mode 100644 index 0000000..9cb7228 --- /dev/null +++ b/kbengine_ts/bin/kbengine.d.ts @@ -0,0 +1,541 @@ +/** + * KBEngine的html5客户端扩展ts版 + */ +declare namespace KBEngine { + class Class { + } + const PACKET_MAX_SIZE = 1500; + const PACKET_MAX_SIZE_TCP = 1460; + const PACKET_MAX_SIZE_UDP = 1472; + const MESSAGE_ID_LENGTH = 2; + const MESSAGE_LENGTH_LENGTH = 2; + const CLIENT_NO_FLOAT = 0; + const KBE_FLT_MAX = 3.402823466e+38; + class INT64 { + constructor(lo: any, hi: any); + lo: number; + hi: number; + sign: number; + toString(): string; + } + class UINT64 { + constructor(lo: any, hi: any); + lo: number; + hi: number; + toString(): string; + } + function INFO_MSG(s: any): void; + function DEBUG_MSG(s: any): void; + function ERROR_MSG(s: any): void; + function WARNING_MSG(s: any): void; + function utf8ArrayToString(array: Array): any; + function stringToUTF8Bytes(str: string): any[]; + class EventInfo { + constructor(classinst: any, callbackfn: any); + classinst: any; + callbackfn: any; + } + interface IEvents { + [evtName: string]: EventInfo[]; + } + class Events { + constructor(); + _events: IEvents; + register(evtName: string, classinst: any, strCallback: string): void; + deregister(evtName: any, classinst: any): void; + fire(evtName: any, ...args: any[]): void; + } + const Event: Events; + class MemoryStream { + constructor(size_or_buffer: any); + buffer: ArrayBuffer; + rpos: number; + wpos: number; + readInt8(): number; + readInt16(): number; + readInt32(): number; + readInt64(): INT64; + readUint8(): number; + readUint16(): number; + readUint32(): number; + readUint64(): UINT64; + readFloat(): any; + readDouble(): any; + readString(): string; + readBlob(): Uint8Array; + readStream(): MemoryStream; + readPackXZ(): any[]; + readPackY(): number; + writeInt8(v: any): void; + writeInt16(v: any): void; + writeInt32(v: any): void; + writeInt64(v: any): void; + writeUint8(v: any): void; + writeUint16(v: any): void; + writeUint32(v: any): void; + writeUint64(v: any): void; + writeFloat(v: any): void; + writeDouble(v: any): void; + writeBlob(v: any): void; + writeString(v: any): void; + readSkip(v: any): void; + space(): number; + length(): number; + readEOF(): boolean; + done(): void; + getbuffer(v: any): ArrayBuffer; + } + module MemoryStream { + class PackFloatXType { + _unionData: ArrayBuffer; + fv: Float32Array; + uv: Uint32Array; + iv: Int32Array; + constructor(); + } + } + class Bundle { + constructor(); + memorystreams: Array; + stream: MemoryStream; + numMessage: number; + messageLengthBuffer: any; + msgtype: any; + messageLength: number; + newMessage(msgtype: any): void; + writeMsgLength(v: any): void; + fini(issend: any): void; + send(network: any): void; + checkStream(v: any): void; + writeInt8(v: any): void; + writeInt16(v: any): void; + writeInt32(v: any): void; + writeInt64(v: any): void; + writeUint8(v: any): void; + writeUint16(v: any): void; + writeUint32(v: any): void; + writeUint64(v: any): void; + writeFloat(v: any): void; + writeDouble(v: any): void; + writeString(v: any): void; + writeBlob(v: any): void; + } + const reader: MemoryStream; + interface IDataType2Id { + [type: string]: number; + } + let datatype2id: IDataType2Id; + function mappingDataType(): void; + function bindWriter(writer: any, argType: number): any; + function bindReader(argType: number): () => any; + class Message { + constructor(id: any, name: any, length: any, argstype: any, args: any, handler: any); + id: any; + name: any; + length: any; + argsType: any; + args: any; + handler: any; + createFromStream(msgstream: any): any; + handleMessage(msgstream: any): void; + } + module messages { + const loginapp: {}; + const baseapp: {}; + const Loginapp_importClientMessages: Message; + const Baseapp_importClientMessages: Message; + const Baseapp_importClientEntityDef: Message; + const onImportClientMessages: Message; + } + let clientmessages: {}; + let bufferedCreateEntityMessage: {}; + class Vector3 extends Class { + constructor(x: any, y: any, z: any); + x: number; + y: number; + z: number; + distance(pos: Vector3): number; + } + function clampf(value: any, min_inclusive: any, max_inclusive: any): any; + function int82angle(angle: any, half: any): number; + function angle2int8(v: number, half: boolean): number; + class Entity extends Class { + constructor(); + id: number; + className: string; + position: Vector3; + direction: Vector3; + velocity: number; + cell: any; + base: any; + inWorld: boolean; + inited: boolean; + isControlled: boolean; + entityLastLocalPos: Vector3; + entityLastLocalDir: Vector3; + isOnGround: boolean; + __init__(): void; + callPropertysSetMethods(): void; + onDestroy(): void; + onControlled(bIsControlled: any): void; + isPlayer(): boolean; + baseCall(...params: any[]): void; + cellCall(...params: any[]): void; + enterWorld(): void; + onEnterWorld(): void; + leaveWorld(): void; + onLeaveWorld(): void; + enterSpace(): void; + onEnterSpace(): void; + leaveSpace(): void; + onLeaveSpace(): void; + set_position(): void; + onUpdateVolatileData(): void; + set_direction(old: any): void; + } + const ENTITYCALL_TYPE_CELL = 0; + const ENTITYCALL_TYPE_BASE = 1; + class EntityCall { + constructor(); + id: number; + className: string; + type: number; + networkInterface: KBEngineApp; + bundle: any; + isBase(): boolean; + isCell(): boolean; + newCall(): any; + sendCall(bundle: any): void; + } + const moduledefs: {}; + class DATATYPE_UINT8 { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_UINT16 { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_UINT32 { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_UINT64 { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_INT8 { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_INT16 { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_INT32 { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_INT64 { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_FLOAT { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_DOUBLE extends DATATYPE_FLOAT { + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + } + class DATATYPE_STRING { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_VECTOR2 { + bind(): void; + createFromStream(stream: any): Vector3; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_VECTOR3 { + bind(): void; + createFromStream(stream: any): Vector3; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_VECTOR4 { + bind(): void; + createFromStream(stream: any): Vector3; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_PYTHON { + bind(): void; + createFromStream(stream: any): void; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_UNICODE { + bind(): void; + createFromStream(stream: any): any; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): string; + isSameType(v: any): boolean; + } + class DATATYPE_ENTITYCALL { + bind(): void; + createFromStream(stream: any): void; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_BLOB { + bind(): void; + createFromStream(stream: any): Uint8Array; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_ARRAY { + type: any; + bind(): void; + createFromStream(stream: any): any[]; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + class DATATYPE_FIXED_DICT { + dicttype: {}; + implementedBy: any; + bind(): void; + createFromStream(stream: any): {}; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): any; + isSameType(v: any): boolean; + } + module datatypes { + const UINT8: DATATYPE_UINT8; + const UINT16: DATATYPE_UINT16; + const UINT32: DATATYPE_UINT32; + const UINT64: DATATYPE_UINT64; + const INT8: DATATYPE_INT8; + const INT16: DATATYPE_INT16; + const INT32: DATATYPE_INT32; + const INT64: DATATYPE_INT64; + const FLOAT: DATATYPE_FLOAT; + const DOUBLE: DATATYPE_DOUBLE; + const STRING: DATATYPE_STRING; + const VECTOR2: DATATYPE_VECTOR2; + const VECTOR3: DATATYPE_VECTOR3; + const VECTOR4: DATATYPE_VECTOR4; + const PYTHON: DATATYPE_PYTHON; + const UNICODE: DATATYPE_UNICODE; + const ENTITYCALL: DATATYPE_ENTITYCALL; + const BLOB: DATATYPE_BLOB; + } + class KBEngineArgs { + ip: string; + port: number; + updateHZ: number; + serverHeartbeatTick: number; + clientType: number; + isOnInitCallPropertysSetMethods: boolean; + } + class KBEngineApp { + constructor(args: KBEngineArgs); + args: KBEngineArgs; + baseappIp: string; + username: string; + password: string; + clientdatas: string; + encryptedKey: string; + loginappMessageImported: boolean; + baseappMessageImported: boolean; + serverErrorsDescrImported: boolean; + entitydefImported: boolean; + serverErrs: { + [err: string]: ServerErr; + }; + ip: string; + port: number; + baseappIP: string; + baseappPort: number; + socket: any; + currserver: string; + currstate: string; + serverdatas: string; + serverVersion: string; + serverScriptVersion: string; + serverProtocolMD5: string; + serverEntityDefMD5: string; + clientVersion: string; + clientScriptVersion: string; + entity_uuid: any; + entity_id: number; + entity_type: string; + entityServerPos: Vector3; + entities: {}; + entityIDAliasIDList: any[]; + controlledEntities: any[]; + spacedata: {}; + spaceID: number; + spaceResPath: string; + isLoadedGeometry: boolean; + lastTickTime: number; + lastTickCBTime: number; + component: any; + resetSocket(): void; + reset(): void; + installEvents(): void; + uninstallEvents(): void; + hello(): void; + player(): any; + findEntity(entityID: any): any; + connect(addr: any): void; + disconnect(): void; + onopen(): void; + onerror_before_onopen(evt: any): void; + onerror_after_onopen(evt: any): void; + onmessage(msg: any): void; + onclose(): void; + send(msg: any): void; + close(): void; + update(): void; + Client_onAppActiveTickCB(): void; + serverErr(id: any): string; + Client_onImportServerErrorsDescr(stream: any): void; + onOpenLoginapp_login(): void; + onOpenLoginapp_createAccount(): void; + onImportClientMessagesCompleted(): void; + createDataTypeFromStreams(stream: any, canprint: any): void; + createDataTypeFromStream(stream: any, canprint: any): void; + Client_onImportClientEntityDef(stream: any): void; + Client_onVersionNotMatch(stream: any): void; + Client_onScriptVersionNotMatch(stream: any): void; + onImportEntityDefCompleted(): void; + Client_onImportClientMessages(msg: any): void; + createAccount(username: any, password: any, datas: any): void; + createAccount_loginapp(noconnect: any): void; + bindAccountEmail(emailAddress: any): void; + newPassword(old_password: any, new_password: any): void; + login(username: any, password: any, datas: any): void; + login_loginapp(noconnect: any): void; + onOpenLoginapp_resetpassword(): void; + reset_password(username: any): void; + resetpassword_loginapp(noconnect: any): void; + onOpenBaseapp(): void; + login_baseapp(noconnect: any): void; + reloginBaseapp(): void; + onReOpenBaseapp(): void; + Client_onHelloCB(args: any): void; + Client_onLoginFailed(args: any): void; + Client_onLoginSuccessfully(args: any): void; + Client_onLoginBaseappFailed(failedcode: any): void; + Client_onReloginBaseappFailed(failedcode: any): void; + Client_onReloginBaseappSuccessfully(stream: any): void; + entityclass: {}; + getentityclass(entityType: any): any; + Client_onCreatedProxies(rndUUID: any, eid: any, entityType: any): void; + getViewEntityIDFromStream(stream: any): number; + onUpdatePropertys_(eid: any, stream: any): void; + Client_onUpdatePropertysOptimized(stream: any): void; + Client_onUpdatePropertys(stream: any): void; + onRemoteMethodCall_(eid: any, stream: any): void; + Client_onRemoteMethodCallOptimized(stream: any): void; + Client_onRemoteMethodCall(stream: any): void; + Client_onEntityEnterWorld(stream: any): void; + Client_onEntityLeaveWorldOptimized(stream: any): void; + Client_onEntityLeaveWorld(eid: any): void; + Client_onEntityDestroyed(eid: any): void; + Client_onEntityEnterSpace(stream: any): void; + Client_onEntityLeaveSpace(eid: any): void; + Client_onKicked(failedcode: any): void; + Client_onCreateAccountResult(stream: any): void; + Client_onControlEntity(eid: any, isControlled: any): void; + updatePlayerToServer(): void; + addSpaceGeometryMapping(spaceID: any, respath: any): void; + clearSpace(isAll: any): void; + clearEntities(isAll: any): void; + Client_initSpaceData(stream: any): void; + Client_setSpaceData(spaceID: any, key: any, value: any): void; + Client_delSpaceData(spaceID: any, key: any): void; + Client_getSpaceData(spaceID: any, key: any): any; + Client_onUpdateBasePos(x: any, y: any, z: any): void; + Client_onUpdateBasePosXZ(x: any, z: any): void; + Client_onUpdateData(stream: any): void; + Client_onSetEntityPosAndDir(stream: any): void; + Client_onUpdateData_ypr(stream: any): void; + Client_onUpdateData_yp(stream: any): void; + Client_onUpdateData_yr(stream: any): void; + Client_onUpdateData_pr(stream: any): void; + Client_onUpdateData_y(stream: any): void; + Client_onUpdateData_p(stream: any): void; + Client_onUpdateData_r(stream: any): void; + Client_onUpdateData_xz(stream: any): void; + Client_onUpdateData_xz_ypr(stream: any): void; + Client_onUpdateData_xz_yp(stream: any): void; + Client_onUpdateData_xz_yr(stream: any): void; + Client_onUpdateData_xz_pr(stream: any): void; + Client_onUpdateData_xz_y(stream: any): void; + Client_onUpdateData_xz_p(stream: any): void; + Client_onUpdateData_xz_r(stream: any): void; + Client_onUpdateData_xyz(stream: any): void; + Client_onUpdateData_xyz_ypr(stream: any): void; + Client_onUpdateData_xyz_yp(stream: any): void; + Client_onUpdateData_xyz_yr(stream: any): void; + Client_onUpdateData_xyz_pr(stream: any): void; + Client_onUpdateData_xyz_y(stream: any): void; + Client_onUpdateData_xyz_p(stream: any): void; + Client_onUpdateData_xyz_r(stream: any): void; + _updateVolatileData(entityID: any, x: any, y: any, z: any, yaw: any, pitch: any, roll: any, isOnGround: any): void; + Client_onStreamDataStarted(id: any, datasize: any, descr: any): void; + Client_onStreamDataRecv(stream: any): void; + Client_onStreamDataCompleted(id: any): void; + Client_onReqAccountResetPasswordCB(failedcode: any): void; + Client_onReqAccountBindEmailCB(failedcode: any): void; + Client_onReqAccountNewPasswordCB(failedcode: any): void; + } + class ServerErr { + name: string; + descr: string; + id: number; + } + let app: KBEngineApp; + function create(args: KBEngineArgs): void; + function destroy(): void; +} diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js new file mode 100644 index 0000000..4b216c0 --- /dev/null +++ b/kbengine_ts/bin/kbengine.js @@ -0,0 +1,3217 @@ +var __reflect = (this && this.__reflect) || function (p, c, t) { + p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t; +}; +var __extends = this && this.__extends || function __extends(t, e) { + function r() { + this.constructor = t; +} +for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]); +r.prototype = e.prototype, t.prototype = new r(); +}; +/** + * KBEngine的html5客户端扩展ts版 + */ +var KBEngine; +(function (KBEngine) { + var Class = (function () { + function Class() { + } + return Class; + }()); + KBEngine.Class = Class; + __reflect(Class.prototype, "KBEngine.Class"); + /*----------------------------------------------------------------------------------------- + global + -----------------------------------------------------------------------------------------*/ + KBEngine.PACKET_MAX_SIZE = 1500; + KBEngine.PACKET_MAX_SIZE_TCP = 1460; + KBEngine.PACKET_MAX_SIZE_UDP = 1472; + KBEngine.MESSAGE_ID_LENGTH = 2; + KBEngine.MESSAGE_LENGTH_LENGTH = 2; + KBEngine.CLIENT_NO_FLOAT = 0; + KBEngine.KBE_FLT_MAX = 3.402823466e+38; + /*----------------------------------------------------------------------------------------- + number64bits + -----------------------------------------------------------------------------------------*/ + var INT64 = (function () { + function INT64(lo, hi) { + this.sign = 1; + this.lo = lo; + this.hi = hi; + if (hi >= 2147483648) { + this.sign = -1; + if (this.lo > 0) { + this.lo = (4294967296 - this.lo) & 0xffffffff; + this.hi = 4294967295 - this.hi; + } + else { + this.lo = (4294967296 - this.lo) & 0xffffffff; + this.hi = 4294967296 - this.hi; + } + } + } + INT64.prototype.toString = function () { + var result = ""; + if (this.sign < 0) { + result += "-"; + } + var low = this.lo.toString(16); + var high = this.hi.toString(16); + if (this.hi > 0) { + result += high; + for (var i = 8 - low.length; i > 0; --i) { + result += "0"; + } + } + result += low; + return result; + }; + return INT64; + }()); + KBEngine.INT64 = INT64; + __reflect(INT64.prototype, "KBEngine.INT64"); + var UINT64 = (function () { + function UINT64(lo, hi) { + this.lo = lo; + this.hi = hi; + } + UINT64.prototype.toString = function () { + var low = this.lo.toString(16); + var high = this.hi.toString(16); + var result = ""; + if (this.hi > 0) { + result += high; + for (var i = 8 - low.length; i > 0; --i) { + result += "0"; + } + } + result += low; + return result; + }; + return UINT64; + }()); + KBEngine.UINT64 = UINT64; + __reflect(UINT64.prototype, "KBEngine.UINT64"); + /*----------------------------------------------------------------------------------------- + debug + -----------------------------------------------------------------------------------------*/ + function INFO_MSG(s) { + console.info(s); + } + KBEngine.INFO_MSG = INFO_MSG; + function DEBUG_MSG(s) { + console.debug(s); + } + KBEngine.DEBUG_MSG = DEBUG_MSG; + function ERROR_MSG(s) { + console.error(s); + } + KBEngine.ERROR_MSG = ERROR_MSG; + function WARNING_MSG(s) { + console.warn(s); + } + KBEngine.WARNING_MSG = WARNING_MSG; + /*----------------------------------------------------------------------------------------- + string + -----------------------------------------------------------------------------------------*/ + function utf8ArrayToString(array) { + var out, i, len, c; + var char2, char3; + out = ""; + len = array.length; + i = 0; + while (i < len) { + c = array[i++]; + switch (c >> 4) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + // 0xxxxxxx + out += String.fromCharCode(c); + break; + case 12: + case 13: + // 110x xxxx 10xx xxxx + char2 = array[i++]; + out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); + break; + case 14: + // 1110 xxxx 10xx xxxx 10xx xxxx + char2 = array[i++]; + char3 = array[i++]; + out += String.fromCharCode(((c & 0x0F) << 12) | + ((char2 & 0x3F) << 6) | + ((char3 & 0x3F) << 0)); + break; + } + } + return out; + } + KBEngine.utf8ArrayToString = utf8ArrayToString; + function stringToUTF8Bytes(str) { + var utf8 = []; + for (var i = 0; i < str.length; i++) { + var charcode = str.charCodeAt(i); + if (charcode < 0x80) + utf8.push(charcode); + else if (charcode < 0x800) { + utf8.push(0xc0 | (charcode >> 6), 0x80 | (charcode & 0x3f)); + } + else if (charcode < 0xd800 || charcode >= 0xe000) { + utf8.push(0xe0 | (charcode >> 12), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f)); + } + else { + i++; + // UTF-16 encodes 0x10000-0x10FFFF by + // subtracting 0x10000 and splitting the + // 20 bits of 0x0-0xFFFFF into two halves + charcode = 0x10000 + (((charcode & 0x3ff) << 10) + | (str.charCodeAt(i) & 0x3ff)); + utf8.push(0xf0 | (charcode >> 18), 0x80 | ((charcode >> 12) & 0x3f), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f)); + } + } + return utf8; + } + KBEngine.stringToUTF8Bytes = stringToUTF8Bytes; + /*----------------------------------------------------------------------------------------- + event + -----------------------------------------------------------------------------------------*/ + var EventInfo = (function () { + function EventInfo(classinst, callbackfn) { + this.callbackfn = callbackfn; + this.classinst = classinst; + } + return EventInfo; + }()); + KBEngine.EventInfo = EventInfo; + __reflect(EventInfo.prototype, "KBEngine.EventInfo"); + var Events = (function () { + function Events() { + this._events = {}; + } + Events.prototype.register = function (evtName, classinst, strCallback) { + var callbackfn = eval("classinst." + strCallback); + if (callbackfn == undefined) { + ERROR_MSG('export class Event::fire: not found strCallback(' + classinst + ")!" + strCallback); + return; + } + var evtlst = this._events[evtName]; + if (evtlst == undefined) { + evtlst = []; + this._events[evtName] = evtlst; + } + var info = new EventInfo(classinst, callbackfn); + evtlst.push(info); + }; + Events.prototype.deregister = function (evtName, classinst) { + for (var itemkey in this._events) { + var evtlst = this._events[itemkey]; + while (true) { + var found = false; + for (var i = 0; i < evtlst.length; i++) { + var info = evtlst[i]; + if (info.classinst == classinst) { + evtlst.splice(i, 1); + found = true; + break; + } + } + if (!found) + break; + } + } + }; + Events.prototype.fire = function (evtName) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + if (arguments.length < 1) { + ERROR_MSG('export class Event::fire: not found eventName!'); + return; + } + var evtlst = this._events[evtName]; + if (evtlst == undefined) { + return; + } + var ars = []; + for (var i = 1; i < args.length; i++) + ars.push(args[i]); + for (var i = 0; i < evtlst.length; i++) { + var info = evtlst[i]; + if (ars.length < 1) { + info.callbackfn.apply(info.classinst); + } + else { + info.callbackfn.apply(info.classinst, ars); + } + } + }; + return Events; + }()); + KBEngine.Events = Events; + __reflect(Events.prototype, "KBEngine.Events"); + KBEngine.Event = new Events(); + /*----------------------------------------------------------------------------------------- + memorystream + -----------------------------------------------------------------------------------------*/ + var MemoryStream = (function () { + function MemoryStream(size_or_buffer) { + this.rpos = 0; + this.wpos = 0; + if (size_or_buffer instanceof ArrayBuffer) { + this.buffer = size_or_buffer; + } + else { + this.buffer = new ArrayBuffer(size_or_buffer); + } + this.rpos = 0; + this.wpos = 0; + } + //--------------------------------------------------------------------------------- + MemoryStream.prototype.readInt8 = function () { + var buf = new Int8Array(this.buffer, this.rpos, 1); + this.rpos += 1; + return buf[0]; + }; + MemoryStream.prototype.readInt16 = function () { + var v = this.readUint16(); + if (v >= 32768) + v -= 65536; + return v; + }; + MemoryStream.prototype.readInt32 = function () { + var v = this.readUint32(); + if (v >= 2147483648) + v -= 4294967296; + return v; + }; + MemoryStream.prototype.readInt64 = function () { + return new INT64(this.readUint32(), this.readUint32()); + }; + MemoryStream.prototype.readUint8 = function () { + var buf = new Uint8Array(this.buffer, this.rpos, 1); + this.rpos += 1; + return buf[0]; + }; + MemoryStream.prototype.readUint16 = function () { + var buf = new Uint8Array(this.buffer, this.rpos); + this.rpos += 2; + return ((buf[1] & 0xff) << 8) + (buf[0] & 0xff); + }; + MemoryStream.prototype.readUint32 = function () { + var buf = new Uint8Array(this.buffer, this.rpos); + this.rpos += 4; + return (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0]; + }; + MemoryStream.prototype.readUint64 = function () { + return new UINT64(this.readUint32(), this.readUint32()); + }; + MemoryStream.prototype.readFloat = function () { + var buf; + try { + buf = new Float32Array(this.buffer, this.rpos, 1); + } + catch (e) { + buf = new Float32Array(this.buffer.slice(this.rpos, this.rpos + 4)); + } + this.rpos += 4; + return buf[0]; + }; + MemoryStream.prototype.readDouble = function () { + var buf; + try { + buf = new Float64Array(this.buffer, this.rpos, 1); + } + catch (e) { + buf = new Float64Array(this.buffer.slice(this.rpos, this.rpos + 8), 0, 1); + } + this.rpos += 8; + return buf[0]; + }; + MemoryStream.prototype.readString = function () { + var buf = new Uint8Array(this.buffer, this.rpos); + var i = 0; + var s = ""; + while (true) { + if (buf[i] != 0) { + s += String.fromCharCode(buf[i]); + } + else { + i++; + break; + } + i++; + if (this.rpos + i >= this.buffer.byteLength) + throw (new Error("export class MemoryStream::readString: rpos(" + (this.rpos + i) + ")>=" + + this.buffer.byteLength + " overflow!")); + } + this.rpos += i; + return s; + }; + MemoryStream.prototype.readBlob = function () { + var size = this.readUint32(); + var buf = new Uint8Array(this.buffer, this.rpos, size); + this.rpos += size; + return buf; + }; + MemoryStream.prototype.readStream = function () { + var buf = new Uint8Array(this.buffer, this.rpos, this.buffer.byteLength - this.rpos); + this.rpos = this.buffer.byteLength; + return new MemoryStream(buf); + }; + MemoryStream.prototype.readPackXZ = function () { + var xPackData = new MemoryStream.PackFloatXType(); + var zPackData = new MemoryStream.PackFloatXType(); + xPackData.fv[0] = 0.0; + zPackData.fv[0] = 0.0; + xPackData.uv[0] = 0x40000000; + zPackData.uv[0] = 0x40000000; + var v1 = this.readUint8(); + var v2 = this.readUint8(); + var v3 = this.readUint8(); + var data = 0; + data |= (v1 << 16); + data |= (v2 << 8); + data |= v3; + xPackData.uv[0] |= (data & 0x7ff000) << 3; + zPackData.uv[0] |= (data & 0x0007ff) << 15; + xPackData.fv[0] -= 2.0; + zPackData.fv[0] -= 2.0; + xPackData.uv[0] |= (data & 0x800000) << 8; + zPackData.uv[0] |= (data & 0x000800) << 20; + var d = new Array(2); + d[0] = xPackData.fv[0]; + d[1] = zPackData.fv[0]; + return d; + }; + MemoryStream.prototype.readPackY = function () { + var v = this.readUint16(); + return v; + }; + //--------------------------------------------------------------------------------- + MemoryStream.prototype.writeInt8 = function (v) { + var buf = new Int8Array(this.buffer, this.wpos, 1); + buf[0] = v; + this.wpos += 1; + }; + MemoryStream.prototype.writeInt16 = function (v) { + this.writeInt8(v & 0xff); + this.writeInt8(v >> 8 & 0xff); + }; + MemoryStream.prototype.writeInt32 = function (v) { + for (var i = 0; i < 4; i++) + this.writeInt8(v >> i * 8 & 0xff); + }; + MemoryStream.prototype.writeInt64 = function (v) { + this.writeInt32(v.lo); + this.writeInt32(v.hi); + }; + MemoryStream.prototype.writeUint8 = function (v) { + var buf = new Uint8Array(this.buffer, this.wpos, 1); + buf[0] = v; + this.wpos += 1; + }; + MemoryStream.prototype.writeUint16 = function (v) { + this.writeUint8(v & 0xff); + this.writeUint8(v >> 8 & 0xff); + }; + MemoryStream.prototype.writeUint32 = function (v) { + for (var i = 0; i < 4; i++) + this.writeUint8(v >> i * 8 & 0xff); + }; + MemoryStream.prototype.writeUint64 = function (v) { + this.writeUint32(v.lo); + this.writeUint32(v.hi); + }; + MemoryStream.prototype.writeFloat = function (v) { + try { + var buf = new Float32Array(this.buffer, this.wpos, 1); + buf[0] = v; + } + catch (e) { + var buf = new Float32Array(1); + buf[0] = v; + var buf1 = new Uint8Array(this.buffer); + var buf2 = new Uint8Array(buf.buffer); + buf1.set(buf2, this.wpos); + } + this.wpos += 4; + }; + MemoryStream.prototype.writeDouble = function (v) { + try { + var buf = new Float64Array(this.buffer, this.wpos, 1); + buf[0] = v; + } + catch (e) { + var buf = new Float64Array(1); + buf[0] = v; + var buf1 = new Uint8Array(this.buffer); + var buf2 = new Uint8Array(buf.buffer); + buf1.set(buf2, this.wpos); + } + this.wpos += 8; + }; + MemoryStream.prototype.writeBlob = function (v) { + var size = v.length; + if (size + 4 > this.space()) { + ERROR_MSG("memorystream::writeBlob: no free!"); + return; + } + this.writeUint32(size); + var buf = new Uint8Array(this.buffer, this.wpos, size); + if (typeof (v) == "string") { + for (var i = 0; i < size; i++) { + buf[i] = v.charCodeAt(i); + } + } + else { + for (var i = 0; i < size; i++) { + buf[i] = v[i]; + } + } + this.wpos += size; + }; + MemoryStream.prototype.writeString = function (v) { + if (v.length > this.space()) { + ERROR_MSG("memorystream::writeString: no free!"); + return; + } + var buf = new Uint8Array(this.buffer, this.wpos); + var i = 0; + for (var idx = 0; idx < v.length; idx++) { + buf[i++] = v.charCodeAt(idx); + } + buf[i++] = 0; + this.wpos += i; + }; + //--------------------------------------------------------------------------------- + MemoryStream.prototype.readSkip = function (v) { + this.rpos += v; + }; + //--------------------------------------------------------------------------------- + MemoryStream.prototype.space = function () { + return this.buffer.byteLength - this.wpos; + }; + //--------------------------------------------------------------------------------- + MemoryStream.prototype.length = function () { + return this.wpos - this.rpos; + }; + //--------------------------------------------------------------------------------- + MemoryStream.prototype.readEOF = function () { + return this.buffer.byteLength - this.rpos <= 0; + }; + //--------------------------------------------------------------------------------- + MemoryStream.prototype.done = function () { + this.rpos = this.wpos; + }; + //--------------------------------------------------------------------------------- + MemoryStream.prototype.getbuffer = function (v) { + return this.buffer.slice(this.rpos, this.wpos); + }; + return MemoryStream; + }()); + KBEngine.MemoryStream = MemoryStream; + __reflect(MemoryStream.prototype, "KBEngine.MemoryStream"); + (function (MemoryStream) { + var PackFloatXType = (function () { + function PackFloatXType() { + this._unionData = new ArrayBuffer(4); + this.fv = new Float32Array(this._unionData, 0, 1); + this.uv = new Uint32Array(this._unionData, 0, 1); + this.iv = new Int32Array(this._unionData, 0, 1); + } + ; + return PackFloatXType; + }()); + MemoryStream.PackFloatXType = PackFloatXType; + __reflect(PackFloatXType.prototype, "KBEngine.MemoryStream.PackFloatXType"); + })(MemoryStream = KBEngine.MemoryStream || (KBEngine.MemoryStream = {})); + /*----------------------------------------------------------------------------------------- + bundle + -----------------------------------------------------------------------------------------*/ + var Bundle = (function () { + function Bundle() { + this.memorystreams = new Array(); + this.numMessage = 0; + this.messageLengthBuffer = null; + this.msgtype = null; + this.messageLength = 0; + this.stream = new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); + } + //--------------------------------------------------------------------------------- + Bundle.prototype.newMessage = function (msgtype) { + this.fini(false); + this.msgtype = msgtype; + this.numMessage += 1; + if (this.msgtype.length == -1) { + this.messageLengthBuffer = new Uint8Array(this.stream.buffer, this.stream.wpos + KBEngine.MESSAGE_ID_LENGTH, 2); + } + this.writeUint16(msgtype.id); + if (this.messageLengthBuffer) { + this.writeUint16(0); + this.messageLengthBuffer[0] = 0; + this.messageLengthBuffer[1] = 0; + this.messageLength = 0; + } + }; + //--------------------------------------------------------------------------------- + Bundle.prototype.writeMsgLength = function (v) { + if (this.messageLengthBuffer) { + this.messageLengthBuffer[0] = v & 0xff; + this.messageLengthBuffer[1] = v >> 8 & 0xff; + } + }; + //--------------------------------------------------------------------------------- + Bundle.prototype.fini = function (issend) { + if (this.numMessage > 0) { + this.writeMsgLength(this.messageLength); + if (this.stream) + this.memorystreams.push(this.stream); + } + if (issend) { + this.messageLengthBuffer = null; + this.numMessage = 0; + this.msgtype = null; + } + }; + //--------------------------------------------------------------------------------- + Bundle.prototype.send = function (network) { + this.fini(true); + for (var i = 0; i < this.memorystreams.length; i++) { + var stream = this.memorystreams[i]; + network.send(stream.getbuffer()); + } + this.memorystreams = new Array(); + this.stream = new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); + }; + //--------------------------------------------------------------------------------- + Bundle.prototype.checkStream = function (v) { + if (v > this.stream.space()) { + this.memorystreams.push(this.stream); + this.stream = new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); + } + this.messageLength += v; + }; + //--------------------------------------------------------------------------------- + Bundle.prototype.writeInt8 = function (v) { + this.checkStream(1); + this.stream.writeInt8(v); + }; + Bundle.prototype.writeInt16 = function (v) { + this.checkStream(2); + this.stream.writeInt16(v); + }; + Bundle.prototype.writeInt32 = function (v) { + this.checkStream(4); + this.stream.writeInt32(v); + }; + Bundle.prototype.writeInt64 = function (v) { + this.checkStream(8); + this.stream.writeInt64(v); + }; + Bundle.prototype.writeUint8 = function (v) { + this.checkStream(1); + this.stream.writeUint8(v); + }; + Bundle.prototype.writeUint16 = function (v) { + this.checkStream(2); + this.stream.writeUint16(v); + }; + Bundle.prototype.writeUint32 = function (v) { + this.checkStream(4); + this.stream.writeUint32(v); + }; + Bundle.prototype.writeUint64 = function (v) { + this.checkStream(8); + this.stream.writeUint64(v); + }; + Bundle.prototype.writeFloat = function (v) { + this.checkStream(4); + this.stream.writeFloat(v); + }; + Bundle.prototype.writeDouble = function (v) { + this.checkStream(8); + this.stream.writeDouble(v); + }; + Bundle.prototype.writeString = function (v) { + this.checkStream(v.length + 1); + this.stream.writeString(v); + }; + Bundle.prototype.writeBlob = function (v) { + this.checkStream(v.length + 4); + this.stream.writeBlob(v); + }; + return Bundle; + }()); + KBEngine.Bundle = Bundle; + __reflect(Bundle.prototype, "KBEngine.Bundle"); + KBEngine.reader = new MemoryStream(0); + KBEngine.datatype2id = {}; + function mappingDataType() { + KBEngine.datatype2id = {}; + KBEngine.datatype2id["STRING"] = 1; + KBEngine.datatype2id["STD::STRING"] = 1; + KBEngine.datatype2id["UINT8"] = 2; + KBEngine.datatype2id["BOOL"] = 2; + KBEngine.datatype2id["DATATYPE"] = 2; + KBEngine.datatype2id["CHAR"] = 2; + KBEngine.datatype2id["DETAIL_TYPE"] = 2; + KBEngine.datatype2id["ENTITYCALL_CALL_TYPE"] = 2; + KBEngine.datatype2id["UINT16"] = 3; + KBEngine.datatype2id["UNSIGNED SHORT"] = 3; + KBEngine.datatype2id["SERVER_ERROR_CODE"] = 3; + KBEngine.datatype2id["ENTITY_TYPE"] = 3; + KBEngine.datatype2id["ENTITY_PROPERTY_UID"] = 3; + KBEngine.datatype2id["ENTITY_METHOD_UID"] = 3; + KBEngine.datatype2id["ENTITY_SCRIPT_UID"] = 3; + KBEngine.datatype2id["DATATYPE_UID"] = 3; + KBEngine.datatype2id["UINT32"] = 4; + KBEngine.datatype2id["UINT"] = 4; + KBEngine.datatype2id["UNSIGNED INT"] = 4; + KBEngine.datatype2id["ARRAYSIZE"] = 4; + KBEngine.datatype2id["SPACE_ID"] = 4; + KBEngine.datatype2id["GAME_TIME"] = 4; + KBEngine.datatype2id["TIMER_ID"] = 4; + KBEngine.datatype2id["UINT64"] = 5; + KBEngine.datatype2id["DBID"] = 5; + KBEngine.datatype2id["COMPONENT_ID"] = 5; + KBEngine.datatype2id["INT8"] = 6; + KBEngine.datatype2id["COMPONENT_ORDER"] = 6; + KBEngine.datatype2id["INT16"] = 7; + KBEngine.datatype2id["SHORT"] = 7; + KBEngine.datatype2id["INT32"] = 8; + KBEngine.datatype2id["INT"] = 8; + KBEngine.datatype2id["ENTITY_ID"] = 8; + KBEngine.datatype2id["CALLBACK_ID"] = 8; + KBEngine.datatype2id["COMPONENT_TYPE"] = 8; + KBEngine.datatype2id["INT64"] = 9; + KBEngine.datatype2id["PYTHON"] = 10; + KBEngine.datatype2id["PY_DICT"] = 10; + KBEngine.datatype2id["PY_TUPLE"] = 10; + KBEngine.datatype2id["PY_LIST"] = 10; + KBEngine.datatype2id["ENTITYCALL"] = 10; + KBEngine.datatype2id["BLOB"] = 11; + KBEngine.datatype2id["UNICODE"] = 12; + KBEngine.datatype2id["FLOAT"] = 13; + KBEngine.datatype2id["DOUBLE"] = 14; + KBEngine.datatype2id["VECTOR2"] = 15; + KBEngine.datatype2id["VECTOR3"] = 16; + KBEngine.datatype2id["VECTOR4"] = 17; + KBEngine.datatype2id["FIXED_DICT"] = 18; + KBEngine.datatype2id["ARRAY"] = 19; + } + KBEngine.mappingDataType = mappingDataType; + mappingDataType(); + function bindWriter(writer, argType) { + switch (argType) { + case KBEngine.datatype2id["UINT8"]: return writer.writeUint8; + case KBEngine.datatype2id["UINT16"]: return writer.writeUint16; + case KBEngine.datatype2id["UINT32"]: return writer.writeUint32; + case KBEngine.datatype2id["UINT64"]: return writer.writeUint64; + case KBEngine.datatype2id["INT8"]: return writer.writeInt8; + case KBEngine.datatype2id["INT16"]: return writer.writeInt16; + case KBEngine.datatype2id["INT32"]: return writer.writeInt32; + case KBEngine.datatype2id["INT64"]: return writer.writeInt64; + case KBEngine.datatype2id["FLOAT"]: return writer.writeFloat; + case KBEngine.datatype2id["DOUBLE"]: return writer.writeDouble; + case KBEngine.datatype2id["STRING"]: return writer.writeString; + case KBEngine.datatype2id["FIXED_DICT"]: return writer.writeStream; + case KBEngine.datatype2id["ARRAY"]: return writer.writeStream; + default: return writer.writeStream; + } + } + KBEngine.bindWriter = bindWriter; + function bindReader(argType) { + switch (argType) { + case KBEngine.datatype2id["UINT8"]: return KBEngine.reader.readUint8; + case KBEngine.datatype2id["UINT16"]: return KBEngine.reader.readUint16; + case KBEngine.datatype2id["UINT32"]: return KBEngine.reader.readUint32; + case KBEngine.datatype2id["UINT64"]: return KBEngine.reader.readUint64; + case KBEngine.datatype2id["INT8"]: return KBEngine.reader.readInt8; + case KBEngine.datatype2id["INT16"]: return KBEngine.reader.readInt16; + case KBEngine.datatype2id["INT32"]: return KBEngine.reader.readInt32; + case KBEngine.datatype2id["INT64"]: return KBEngine.reader.readInt64; + case KBEngine.datatype2id["FLOAT"]: return KBEngine.reader.readFloat; + case KBEngine.datatype2id["DOUBLE"]: return KBEngine.reader.readDouble; + case KBEngine.datatype2id["STRING"]: return KBEngine.reader.readString; + case KBEngine.datatype2id["FIXED_DICT"]: return KBEngine.reader.readStream; + case KBEngine.datatype2id["ARRAY"]: return KBEngine.reader.readStream; + default: return KBEngine.reader.readStream; + } + } + KBEngine.bindReader = bindReader; + var Message = (function () { + function Message(id, name, length, argstype, args, handler) { + this.id = id; + this.name = name; + this.length = length; + this.argsType = argstype; + for (var i = 0; i < args.length; i++) { + args[i] = bindReader(args[i]); + } + this.args = args; + this.handler = handler; + } + Message.prototype.createFromStream = function (msgstream) { + if (this.args.length <= 0) + return msgstream; + var result = new Array(this.args.length); + for (var i = 0; i < this.args.length; i++) { + result[i] = this.args[i].call(msgstream); + } + return result; + }; + Message.prototype.handleMessage = function (msgstream) { + if (this.handler == null) { + ERROR_MSG("Message::handleMessage: interface(" + this.name + "/" + this.id + ") no implement!"); + return; + } + if (this.args.length <= 0) { + if (this.argsType < 0) + this.handler(msgstream); + else + this.handler(); + } + else { + this.handler.apply(KBEngine.app, this.createFromStream(msgstream)); + } + }; + return Message; + }()); + KBEngine.Message = Message; + __reflect(Message.prototype, "KBEngine.Message"); + var messages; + (function (messages) { + messages.loginapp = {}; + messages.baseapp = {}; + messages.Loginapp_importClientMessages = new Message(5, "importClientMessages", 0, 0, new Array(), null); + messages.Baseapp_importClientMessages = new Message(207, "importClientMessages", 0, 0, new Array(), null); + messages.Baseapp_importClientEntityDef = new Message(208, "importClientEntityDef", 0, 0, new Array(), null); + messages.onImportClientMessages = new Message(518, "onImportClientMessages", -1, -1, new Array(), null); + })(messages = KBEngine.messages || (KBEngine.messages = {})); + KBEngine.clientmessages = {}; + KBEngine.bufferedCreateEntityMessage = {}; + /*----------------------------------------------------------------------------------------- + math + -----------------------------------------------------------------------------------------*/ + var Vector3 = (function (_super) { + __extends(Vector3, _super); + function Vector3(x, y, z) { + var _this = _super.call(this) || this; + _this.x = x; + _this.y = y; + _this.z = z; + return _this; + } + Vector3.prototype.distance = function (pos) { + var x = pos.x - this.x; + var y = pos.y - this.y; + var z = pos.z - this.z; + return Math.sqrt(x * x + y * y + z * z); + }; + return Vector3; + }(Class)); + KBEngine.Vector3 = Vector3; + __reflect(Vector3.prototype, "KBEngine.Vector3"); + function clampf(value, min_inclusive, max_inclusive) { + if (min_inclusive > max_inclusive) { + var temp = min_inclusive; + min_inclusive = max_inclusive; + max_inclusive = temp; + } + return value < min_inclusive ? min_inclusive : value < max_inclusive ? value : max_inclusive; + } + KBEngine.clampf = clampf; + function int82angle(angle, half) { + return angle * (Math.PI / (half ? 254.0 : 128.0)); + } + KBEngine.int82angle = int82angle; + function angle2int8(v, half) { + var angle = 0; + if (!half) { + //todo 原来写的float(Math.PI),因为js没有float这个方法所以去掉了 + angle = Math.floor((v * 128.0) / Math.PI + 0.5); + } + else { + angle = clampf(Math.floor((v * 254.0) / Math.PI + 0.5), -128.0, 127.0); + } + return angle; + } + KBEngine.angle2int8 = angle2int8; + /*----------------------------------------------------------------------------------------- + entity + -----------------------------------------------------------------------------------------*/ + var Entity = (function (_super) { + __extends(Entity, _super); + function Entity() { + var _this = _super.call(this) || this; + _this.id = 0; + _this.className = ""; + _this.position = new Vector3(0, 0, 0); + _this.direction = new Vector3(0, 0, 0); + _this.velocity = 0; + _this.cell = null; + _this.base = null; + // enterworld之后设置为true + _this.inWorld = false; + // __init__调用之后设置为true + _this.inited = false; + // 是否被控制 + _this.isControlled = false; + _this.entityLastLocalPos = new Vector3(0.0, 0.0, 0.0); + _this.entityLastLocalDir = new Vector3(0.0, 0.0, 0.0); + // 玩家是否在地面上 + _this.isOnGround = false; + return _this; + } + Entity.prototype.__init__ = function () { + }; + Entity.prototype.callPropertysSetMethods = function () { + var currModule = KBEngine.moduledefs[this.className]; + for (var name_1 in currModule.propertys) { + var propertydata = currModule.propertys[name_1]; + var properUtype = propertydata[0]; + name_1 = propertydata[2]; + var setmethod = propertydata[5]; + var flags = propertydata[6]; + var oldval = this[name_1]; + if (setmethod != null) { + // base类属性或者进入世界后cell类属性会触发set_*方法 + // ED_FLAG_BASE_AND_CLIENT、ED_FLAG_BASE + if (flags == 0x00000020 || flags == 0x00000040) { + if (this.inited && !this.inWorld) + setmethod.call(this, oldval); + } + else { + if (this.inWorld) { + if (flags == 0x00000008 || flags == 0x00000010) { + if (!this.isPlayer()) + continue; + } + setmethod.call(this, oldval); + } + } + } + } + ; + }; + Entity.prototype.onDestroy = function () { + }; + Entity.prototype.onControlled = function (bIsControlled) { + }; + Entity.prototype.isPlayer = function () { + return this.id == KBEngine.app.entity_id; + }; + Entity.prototype.baseCall = function () { + var params = []; + for (var _i = 0; _i < arguments.length; _i++) { + params[_i] = arguments[_i]; + } + if (params.length < 1) { + ERROR_MSG('Entity::baseCall: not fount interfaceName!'); + return; + } + if (this.base == undefined) { + ERROR_MSG('Entity::baseCall: base is None!'); + return; + } + var method = KBEngine.moduledefs[this.className].base_methods[params[0]]; + if (method == undefined) { + ERROR_MSG("Entity::baseCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); + return; + } + var methodID = method[0]; + var args = method[3]; + if (args.length - 1 != args.length) { + ERROR_MSG("Entity::baseCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); + return; + } + this.base.newCall(); + this.base.bundle.writeUint16(methodID); + try { + for (var i = 0; i < args.length; i++) { + if (args[i].isSameType(args[i + 1])) { + args[i].addToStream(this.base.bundle, args[i + 1]); + } + else { + throw new Error("Entity::baseCall: arg[" + i + "] is error!"); + } + } + } + catch (e) { + ERROR_MSG(e.toString()); + ERROR_MSG('Entity::baseCall: args is error!'); + this.base.bundle = null; + return; + } + this.base.sendCall(); + }; + Entity.prototype.cellCall = function () { + var params = []; + for (var _i = 0; _i < arguments.length; _i++) { + params[_i] = arguments[_i]; + } + if (params.length < 1) { + ERROR_MSG('Entity::cellCall: not fount interfaceName!'); + return; + } + if (this.cell == undefined) { + ERROR_MSG('Entity::cellCall: cell is None!'); + return; + } + var method = KBEngine.moduledefs[this.className].cell_methods[params[0]]; + if (method == undefined) { + ERROR_MSG("Entity::cellCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); + return; + } + var methodID = method[0]; + var args = method[3]; + if (args.length - 1 != args.length) { + ERROR_MSG("Entity::cellCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); + return; + } + this.cell.newCall(); + this.cell.bundle.writeUint16(methodID); + try { + for (var i = 0; i < args.length; i++) { + if (args[i].isSameType(args[i + 1])) { + args[i].addToStream(this.cell.bundle, args[i + 1]); + } + else { + throw new Error("Entity::cellCall: arg[" + i + "] is error!"); + } + } + } + catch (e) { + ERROR_MSG(e.toString()); + ERROR_MSG('Entity::cellCall: args is error!'); + this.cell.bundle = null; + return; + } + this.cell.sendCall(); + }; + Entity.prototype.enterWorld = function () { + INFO_MSG(this.className + '::enterWorld: ' + this.id); + this.inWorld = true; + this.onEnterWorld(); + KBEngine.Event.fire("onEnterWorld", this); + }; + Entity.prototype.onEnterWorld = function () { + }; + Entity.prototype.leaveWorld = function () { + INFO_MSG(this.className + '::leaveWorld: ' + this.id); + this.inWorld = false; + this.onLeaveWorld(); + KBEngine.Event.fire("onLeaveWorld", this); + }; + Entity.prototype.onLeaveWorld = function () { + }; + Entity.prototype.enterSpace = function () { + INFO_MSG(this.className + '::enterSpace: ' + this.id); + this.onEnterSpace(); + KBEngine.Event.fire("onEnterSpace", this); + // 要立即刷新表现层对象的位置 + KBEngine.Event.fire("set_position", this); + KBEngine.Event.fire("set_direction", this); + }; + Entity.prototype.onEnterSpace = function () { + }; + Entity.prototype.leaveSpace = function () { + INFO_MSG(this.className + '::leaveSpace: ' + this.id); + this.onLeaveSpace(); + KBEngine.Event.fire("onLeaveSpace", this); + }; + Entity.prototype.onLeaveSpace = function () { + }; + Entity.prototype.set_position = function () { + // DEBUG_MSG(this.className + "::set_position: " + old); + if (this.isPlayer()) { + KBEngine.app.entityServerPos.x = this.position.x; + KBEngine.app.entityServerPos.y = this.position.y; + KBEngine.app.entityServerPos.z = this.position.z; + } + KBEngine.Event.fire("set_position", this); + }; + Entity.prototype.onUpdateVolatileData = function () { + }; + Entity.prototype.set_direction = function (old) { + // DEBUG_MSG(this.className + "::set_direction: " + old); + KBEngine.Event.fire("set_direction", this); + }; + return Entity; + }(Class)); + KBEngine.Entity = Entity; + __reflect(Entity.prototype, "KBEngine.Entity"); + /*----------------------------------------------------------------------------------------- + EntityCall + -----------------------------------------------------------------------------------------*/ + KBEngine.ENTITYCALL_TYPE_CELL = 0; + KBEngine.ENTITYCALL_TYPE_BASE = 1; + var EntityCall = (function () { + function EntityCall() { + this.id = 0; + this.className = ''; + this.type = KBEngine.ENTITYCALL_TYPE_CELL; + this.networkInterface = KBEngine.app; + this.bundle = null; + } + EntityCall.prototype.isBase = function () { + return this.type == KBEngine.ENTITYCALL_TYPE_BASE; + }; + EntityCall.prototype.isCell = function () { + return this.type == KBEngine.ENTITYCALL_TYPE_CELL; + }; + EntityCall.prototype.newCall = function () { + if (this.bundle == null) + this.bundle = new Bundle(); + if (this.type == KBEngine.ENTITYCALL_TYPE_CELL) + this.bundle.newMessage(messages['Baseapp_onRemoteCallCellMethodFromClient']); + else + this.bundle.newMessage(messages['Entity_onRemoteMethodCall']); + this.bundle.writeInt32(this.id); + return this.bundle; + }; + EntityCall.prototype.sendCall = function (bundle) { + if (bundle == undefined) + bundle = this.bundle; + bundle.send(this.networkInterface); + if (this.bundle == bundle) + this.bundle = null; + }; + return EntityCall; + }()); + KBEngine.EntityCall = EntityCall; + __reflect(EntityCall.prototype, "KBEngine.EntityCall"); + KBEngine.moduledefs = {}; + var DATATYPE_UINT8 = (function () { + function DATATYPE_UINT8() { + } + DATATYPE_UINT8.prototype.bind = function () { + }; + DATATYPE_UINT8.prototype.createFromStream = function (stream) { + return KBEngine.reader.readUint8.call(stream); + }; + DATATYPE_UINT8.prototype.addToStream = function (stream, v) { + stream.writeUint8(v); + }; + DATATYPE_UINT8.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_UINT8.prototype.isSameType = function (v) { + if (typeof (v) != "number") { + return false; + } + if (v < 0 || v > 0xff) { + return false; + } + return true; + }; + return DATATYPE_UINT8; + }()); + KBEngine.DATATYPE_UINT8 = DATATYPE_UINT8; + __reflect(DATATYPE_UINT8.prototype, "KBEngine.DATATYPE_UINT8"); + var DATATYPE_UINT16 = (function () { + function DATATYPE_UINT16() { + } + DATATYPE_UINT16.prototype.bind = function () { + }; + DATATYPE_UINT16.prototype.createFromStream = function (stream) { + return KBEngine.reader.readUint16.call(stream); + }; + DATATYPE_UINT16.prototype.addToStream = function (stream, v) { + stream.writeUint16(v); + }; + DATATYPE_UINT16.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_UINT16.prototype.isSameType = function (v) { + if (typeof (v) != "number") { + return false; + } + if (v < 0 || v > 0xffff) { + return false; + } + return true; + }; + return DATATYPE_UINT16; + }()); + KBEngine.DATATYPE_UINT16 = DATATYPE_UINT16; + __reflect(DATATYPE_UINT16.prototype, "KBEngine.DATATYPE_UINT16"); + var DATATYPE_UINT32 = (function () { + function DATATYPE_UINT32() { + } + DATATYPE_UINT32.prototype.bind = function () { + }; + DATATYPE_UINT32.prototype.createFromStream = function (stream) { + return KBEngine.reader.readUint32.call(stream); + }; + DATATYPE_UINT32.prototype.addToStream = function (stream, v) { + stream.writeUint32(v); + }; + DATATYPE_UINT32.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_UINT32.prototype.isSameType = function (v) { + if (typeof (v) != "number") { + return false; + } + if (v < 0 || v > 0xffffffff) { + return false; + } + return true; + }; + return DATATYPE_UINT32; + }()); + KBEngine.DATATYPE_UINT32 = DATATYPE_UINT32; + __reflect(DATATYPE_UINT32.prototype, "KBEngine.DATATYPE_UINT32"); + var DATATYPE_UINT64 = (function () { + function DATATYPE_UINT64() { + } + DATATYPE_UINT64.prototype.bind = function () { + }; + DATATYPE_UINT64.prototype.createFromStream = function (stream) { + return KBEngine.reader.readUint64.call(stream); + }; + DATATYPE_UINT64.prototype.addToStream = function (stream, v) { + stream.writeUint64(v); + }; + DATATYPE_UINT64.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_UINT64.prototype.isSameType = function (v) { + return v instanceof UINT64; + }; + return DATATYPE_UINT64; + }()); + KBEngine.DATATYPE_UINT64 = DATATYPE_UINT64; + __reflect(DATATYPE_UINT64.prototype, "KBEngine.DATATYPE_UINT64"); + var DATATYPE_INT8 = (function () { + function DATATYPE_INT8() { + } + DATATYPE_INT8.prototype.bind = function () { + }; + DATATYPE_INT8.prototype.createFromStream = function (stream) { + return KBEngine.reader.readInt8.call(stream); + }; + DATATYPE_INT8.prototype.addToStream = function (stream, v) { + stream.writeInt8(v); + }; + DATATYPE_INT8.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_INT8.prototype.isSameType = function (v) { + if (typeof (v) != "number") { + return false; + } + if (v < -0x80 || v > 0x7f) { + return false; + } + return true; + }; + return DATATYPE_INT8; + }()); + KBEngine.DATATYPE_INT8 = DATATYPE_INT8; + __reflect(DATATYPE_INT8.prototype, "KBEngine.DATATYPE_INT8"); + var DATATYPE_INT16 = (function () { + function DATATYPE_INT16() { + } + DATATYPE_INT16.prototype.bind = function () { + }; + DATATYPE_INT16.prototype.createFromStream = function (stream) { + return KBEngine.reader.readInt16.call(stream); + }; + DATATYPE_INT16.prototype.addToStream = function (stream, v) { + stream.writeInt16(v); + }; + DATATYPE_INT16.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_INT16.prototype.isSameType = function (v) { + if (typeof (v) != "number") { + return false; + } + if (v < -0x8000 || v > 0x7fff) { + return false; + } + return true; + }; + return DATATYPE_INT16; + }()); + KBEngine.DATATYPE_INT16 = DATATYPE_INT16; + __reflect(DATATYPE_INT16.prototype, "KBEngine.DATATYPE_INT16"); + var DATATYPE_INT32 = (function () { + function DATATYPE_INT32() { + } + DATATYPE_INT32.prototype.bind = function () { + }; + DATATYPE_INT32.prototype.createFromStream = function (stream) { + return KBEngine.reader.readInt32.call(stream); + }; + DATATYPE_INT32.prototype.addToStream = function (stream, v) { + stream.writeInt32(v); + }; + DATATYPE_INT32.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_INT32.prototype.isSameType = function (v) { + if (typeof (v) != "number") { + return false; + } + if (v < -0x80000000 || v > 0x7fffffff) { + return false; + } + return true; + }; + return DATATYPE_INT32; + }()); + KBEngine.DATATYPE_INT32 = DATATYPE_INT32; + __reflect(DATATYPE_INT32.prototype, "KBEngine.DATATYPE_INT32"); + var DATATYPE_INT64 = (function () { + function DATATYPE_INT64() { + } + DATATYPE_INT64.prototype.bind = function () { + }; + DATATYPE_INT64.prototype.createFromStream = function (stream) { + return KBEngine.reader.readInt64.call(stream); + }; + DATATYPE_INT64.prototype.addToStream = function (stream, v) { + stream.writeInt64(v); + }; + DATATYPE_INT64.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_INT64.prototype.isSameType = function (v) { + return v instanceof INT64; + }; + return DATATYPE_INT64; + }()); + KBEngine.DATATYPE_INT64 = DATATYPE_INT64; + __reflect(DATATYPE_INT64.prototype, "KBEngine.DATATYPE_INT64"); + var DATATYPE_FLOAT = (function () { + function DATATYPE_FLOAT() { + } + DATATYPE_FLOAT.prototype.bind = function () { + }; + DATATYPE_FLOAT.prototype.createFromStream = function (stream) { + return KBEngine.reader.readFloat.call(stream); + }; + DATATYPE_FLOAT.prototype.addToStream = function (stream, v) { + stream.writeFloat(v); + }; + DATATYPE_FLOAT.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_FLOAT.prototype.isSameType = function (v) { + return typeof (v) == "number"; + }; + return DATATYPE_FLOAT; + }()); + KBEngine.DATATYPE_FLOAT = DATATYPE_FLOAT; + __reflect(DATATYPE_FLOAT.prototype, "KBEngine.DATATYPE_FLOAT"); + var DATATYPE_DOUBLE = (function (_super) { + __extends(DATATYPE_DOUBLE, _super); + function DATATYPE_DOUBLE() { + return _super !== null && _super.apply(this, arguments) || this; + } + DATATYPE_DOUBLE.prototype.createFromStream = function (stream) { + return KBEngine.reader.readDouble.call(stream); + }; + DATATYPE_DOUBLE.prototype.addToStream = function (stream, v) { + stream.writeDouble(v); + }; + return DATATYPE_DOUBLE; + }(DATATYPE_FLOAT)); + KBEngine.DATATYPE_DOUBLE = DATATYPE_DOUBLE; + __reflect(DATATYPE_DOUBLE.prototype, "KBEngine.DATATYPE_DOUBLE"); + var DATATYPE_STRING = (function () { + function DATATYPE_STRING() { + } + DATATYPE_STRING.prototype.bind = function () { + }; + DATATYPE_STRING.prototype.createFromStream = function (stream) { + return KBEngine.reader.readString.call(stream); + }; + DATATYPE_STRING.prototype.addToStream = function (stream, v) { + stream.writeString(v); + }; + DATATYPE_STRING.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_STRING.prototype.isSameType = function (v) { + return typeof (v) == "string"; + }; + return DATATYPE_STRING; + }()); + KBEngine.DATATYPE_STRING = DATATYPE_STRING; + __reflect(DATATYPE_STRING.prototype, "KBEngine.DATATYPE_STRING"); + var DATATYPE_VECTOR2 = (function () { + function DATATYPE_VECTOR2() { + } + DATATYPE_VECTOR2.prototype.bind = function () { + }; + DATATYPE_VECTOR2.prototype.createFromStream = function (stream) { + if (KBEngine.CLIENT_NO_FLOAT) { + return new Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); + } + else { + return new Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); + } + }; + DATATYPE_VECTOR2.prototype.addToStream = function (stream, v) { + if (KBEngine.CLIENT_NO_FLOAT) { + stream.writeInt32(v.x); + stream.writeInt32(v.y); + } + else { + stream.writeFloat(v.x); + stream.writeFloat(v.y); + } + }; + DATATYPE_VECTOR2.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_VECTOR2.prototype.isSameType = function (v) { + if (!(v instanceof Vector3)) { + return false; + } + return true; + }; + return DATATYPE_VECTOR2; + }()); + KBEngine.DATATYPE_VECTOR2 = DATATYPE_VECTOR2; + __reflect(DATATYPE_VECTOR2.prototype, "KBEngine.DATATYPE_VECTOR2"); + var DATATYPE_VECTOR3 = (function () { + function DATATYPE_VECTOR3() { + } + DATATYPE_VECTOR3.prototype.bind = function () { + }; + DATATYPE_VECTOR3.prototype.createFromStream = function (stream) { + if (KBEngine.CLIENT_NO_FLOAT) { + return new Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); + } + else { + return new Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); + } + }; + DATATYPE_VECTOR3.prototype.addToStream = function (stream, v) { + if (KBEngine.CLIENT_NO_FLOAT) { + stream.writeInt32(v.x); + stream.writeInt32(v.y); + stream.writeInt32(v.z); + } + else { + stream.writeFloat(v.x); + stream.writeFloat(v.y); + stream.writeFloat(v.z); + } + }; + DATATYPE_VECTOR3.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_VECTOR3.prototype.isSameType = function (v) { + if (!(v instanceof Vector3)) { + return false; + } + return true; + }; + return DATATYPE_VECTOR3; + }()); + KBEngine.DATATYPE_VECTOR3 = DATATYPE_VECTOR3; + __reflect(DATATYPE_VECTOR3.prototype, "KBEngine.DATATYPE_VECTOR3"); + var DATATYPE_VECTOR4 = (function () { + function DATATYPE_VECTOR4() { + } + DATATYPE_VECTOR4.prototype.bind = function () { + }; + DATATYPE_VECTOR4.prototype.createFromStream = function (stream) { + if (KBEngine.CLIENT_NO_FLOAT) { + return new Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); + } + else { + return new Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); + } + }; + DATATYPE_VECTOR4.prototype.addToStream = function (stream, v) { + if (KBEngine.CLIENT_NO_FLOAT) { + stream.writeInt32(v.x); + stream.writeInt32(v.y); + stream.writeInt32(v.z); + stream.writeInt32(v.w); + } + else { + stream.writeFloat(v.x); + stream.writeFloat(v.y); + stream.writeFloat(v.z); + stream.writeFloat(v.w); + } + }; + DATATYPE_VECTOR4.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_VECTOR4.prototype.isSameType = function (v) { + if (!(v instanceof Vector3)) { + return false; + } + return true; + }; + return DATATYPE_VECTOR4; + }()); + KBEngine.DATATYPE_VECTOR4 = DATATYPE_VECTOR4; + __reflect(DATATYPE_VECTOR4.prototype, "KBEngine.DATATYPE_VECTOR4"); + var DATATYPE_PYTHON = (function () { + function DATATYPE_PYTHON() { + } + DATATYPE_PYTHON.prototype.bind = function () { + }; + DATATYPE_PYTHON.prototype.createFromStream = function (stream) { + }; + DATATYPE_PYTHON.prototype.addToStream = function (stream, v) { + }; + DATATYPE_PYTHON.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_PYTHON.prototype.isSameType = function (v) { + return false; + }; + return DATATYPE_PYTHON; + }()); + KBEngine.DATATYPE_PYTHON = DATATYPE_PYTHON; + __reflect(DATATYPE_PYTHON.prototype, "KBEngine.DATATYPE_PYTHON"); + var DATATYPE_UNICODE = (function () { + function DATATYPE_UNICODE() { + } + DATATYPE_UNICODE.prototype.bind = function () { + }; + DATATYPE_UNICODE.prototype.createFromStream = function (stream) { + return utf8ArrayToString(KBEngine.reader.readBlob.call(stream)); + }; + DATATYPE_UNICODE.prototype.addToStream = function (stream, v) { + stream.writeBlob(stringToUTF8Bytes(v)); + }; + DATATYPE_UNICODE.prototype.parseDefaultValStr = function (v) { + if (typeof (v) == "string") + return v; + return ""; + }; + DATATYPE_UNICODE.prototype.isSameType = function (v) { + return typeof (v) == "string"; + }; + return DATATYPE_UNICODE; + }()); + KBEngine.DATATYPE_UNICODE = DATATYPE_UNICODE; + __reflect(DATATYPE_UNICODE.prototype, "KBEngine.DATATYPE_UNICODE"); + var DATATYPE_ENTITYCALL = (function () { + function DATATYPE_ENTITYCALL() { + } + DATATYPE_ENTITYCALL.prototype.bind = function () { + }; + DATATYPE_ENTITYCALL.prototype.createFromStream = function (stream) { + }; + DATATYPE_ENTITYCALL.prototype.addToStream = function (stream, v) { + }; + DATATYPE_ENTITYCALL.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_ENTITYCALL.prototype.isSameType = function (v) { + return false; + }; + return DATATYPE_ENTITYCALL; + }()); + KBEngine.DATATYPE_ENTITYCALL = DATATYPE_ENTITYCALL; + __reflect(DATATYPE_ENTITYCALL.prototype, "KBEngine.DATATYPE_ENTITYCALL"); + var DATATYPE_BLOB = (function () { + function DATATYPE_BLOB() { + } + DATATYPE_BLOB.prototype.bind = function () { + }; + DATATYPE_BLOB.prototype.createFromStream = function (stream) { + var size = KBEngine.reader.readUint32.call(stream); + var buf = new Uint8Array(stream.buffer, stream.rpos, size); + stream.rpos += size; + return buf; + }; + DATATYPE_BLOB.prototype.addToStream = function (stream, v) { + stream.writeBlob(v); + }; + DATATYPE_BLOB.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_BLOB.prototype.isSameType = function (v) { + return true; + }; + return DATATYPE_BLOB; + }()); + KBEngine.DATATYPE_BLOB = DATATYPE_BLOB; + __reflect(DATATYPE_BLOB.prototype, "KBEngine.DATATYPE_BLOB"); + var DATATYPE_ARRAY = (function () { + function DATATYPE_ARRAY() { + this.type = null; + } + DATATYPE_ARRAY.prototype.bind = function () { + if (typeof (this.type) == "number") + this.type = datatypes[this.type]; + }; + DATATYPE_ARRAY.prototype.createFromStream = function (stream) { + var size = stream.readUint32(); + var datas = []; + while (size > 0) { + size--; + datas.push(this.type.createFromStream(stream)); + } + ; + return datas; + }; + DATATYPE_ARRAY.prototype.addToStream = function (stream, v) { + stream.writeUint32(v.length); + for (var i = 0; i < v.length; i++) { + this.type.addToStream(stream, v[i]); + } + }; + DATATYPE_ARRAY.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_ARRAY.prototype.isSameType = function (v) { + for (var i = 0; i < v.length; i++) { + if (!this.type.isSameType(v[i])) { + return false; + } + } + return true; + }; + return DATATYPE_ARRAY; + }()); + KBEngine.DATATYPE_ARRAY = DATATYPE_ARRAY; + __reflect(DATATYPE_ARRAY.prototype, "KBEngine.DATATYPE_ARRAY"); + var DATATYPE_FIXED_DICT = (function () { + function DATATYPE_FIXED_DICT() { + this.dicttype = {}; + this.implementedBy = null; + } + DATATYPE_FIXED_DICT.prototype.bind = function () { + for (var itemkey in this.dicttype) { + var utype = this.dicttype[itemkey]; + if (typeof (this.dicttype[itemkey]) == "number") + this.dicttype[itemkey] = datatypes[utype]; + } + }; + DATATYPE_FIXED_DICT.prototype.createFromStream = function (stream) { + var datas = {}; + for (var itemkey in this.dicttype) { + datas[itemkey] = this.dicttype[itemkey].createFromStream(stream); + } + return datas; + }; + DATATYPE_FIXED_DICT.prototype.addToStream = function (stream, v) { + for (var itemkey in this.dicttype) { + this.dicttype[itemkey].addToStream(stream, v[itemkey]); + } + }; + DATATYPE_FIXED_DICT.prototype.parseDefaultValStr = function (v) { + return eval(v); + }; + DATATYPE_FIXED_DICT.prototype.isSameType = function (v) { + for (var itemkey in this.dicttype) { + if (!this.dicttype[itemkey].isSameType(v[itemkey])) { + return false; + } + } + return true; + }; + return DATATYPE_FIXED_DICT; + }()); + KBEngine.DATATYPE_FIXED_DICT = DATATYPE_FIXED_DICT; + __reflect(DATATYPE_FIXED_DICT.prototype, "KBEngine.DATATYPE_FIXED_DICT"); + var datatypes; + (function (datatypes) { + datatypes.UINT8 = new DATATYPE_UINT8(); + datatypes.UINT16 = new DATATYPE_UINT16(); + datatypes.UINT32 = new DATATYPE_UINT32(); + datatypes.UINT64 = new DATATYPE_UINT64(); + datatypes.INT8 = new DATATYPE_INT8(); + datatypes.INT16 = new DATATYPE_INT16(); + datatypes.INT32 = new DATATYPE_INT32(); + datatypes.INT64 = new DATATYPE_INT64(); + datatypes.FLOAT = new DATATYPE_FLOAT(); + datatypes.DOUBLE = new DATATYPE_DOUBLE(); + datatypes.STRING = new DATATYPE_STRING(); + datatypes.VECTOR2 = new DATATYPE_VECTOR2; + datatypes.VECTOR3 = new DATATYPE_VECTOR3; + datatypes.VECTOR4 = new DATATYPE_VECTOR4; + datatypes.PYTHON = new DATATYPE_PYTHON(); + datatypes.UNICODE = new DATATYPE_UNICODE(); + datatypes.ENTITYCALL = new DATATYPE_ENTITYCALL(); + datatypes.BLOB = new DATATYPE_BLOB(); + })(datatypes = KBEngine.datatypes || (KBEngine.datatypes = {})); + ; + /*----------------------------------------------------------------------------------------- + KBEngine args + -----------------------------------------------------------------------------------------*/ + var KBEngineArgs = (function () { + function KBEngineArgs() { + this.ip = '127.0.0.1'; + this.port = 20013; + this.updateHZ = 100; + this.serverHeartbeatTick = 15; + // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types + this.clientType = 5; + // 在Entity初始化时是否触发属性的set_*事件(callPropertysSetMethods) + this.isOnInitCallPropertysSetMethods = true; + } + return KBEngineArgs; + }()); + KBEngine.KBEngineArgs = KBEngineArgs; + __reflect(KBEngineArgs.prototype, "KBEngine.KBEngineArgs"); + /*----------------------------------------------------------------------------------------- + KBEngine app + -----------------------------------------------------------------------------------------*/ + var KBEngineApp = (function () { + function KBEngineApp(args) { + this.username = "testhtml51"; + this.password = "123456"; + this.clientdatas = ""; + this.encryptedKey = ""; + this.loginappMessageImported = false; + this.baseappMessageImported = false; + this.serverErrorsDescrImported = false; + this.entitydefImported = false; + this.serverErrs = {}; + // 服务端分配的baseapp地址 + this.baseappIP = ''; + this.baseappPort = 0; + this.currstate = "create"; + // 扩展数据 + this.serverdatas = ""; + // 版本信息 + this.serverVersion = ""; + this.serverScriptVersion = ""; + this.serverProtocolMD5 = ""; + this.serverEntityDefMD5 = ""; + this.clientVersion = "1.1.5"; + this.clientScriptVersion = "0.1.0"; + // player的相关信息 + this.entity_uuid = null; + this.entity_id = 0; + this.entity_type = ""; + // 当前玩家最后一次同步到服务端的位置与朝向与服务端最后一次同步过来的位置 + this.entityServerPos = new Vector3(0.0, 0.0, 0.0); + // 客户端所有的实体 + this.entities = {}; + this.entityIDAliasIDList = []; + this.controlledEntities = []; + // 空间的信息 + this.spacedata = {}; + this.spaceID = 0; + this.spaceResPath = ""; + this.isLoadedGeometry = false; + this.lastTickTime = Date.now(); + this.lastTickCBTime = Date.now(); + this.entityclass = {}; + console.assert(KBEngine.app == null || KBEngine.app == undefined, "Assertion of app not is null"); + KBEngine.app = this; + this.args = args; + } + KBEngineApp.prototype.resetSocket = function () { + try { + if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) { + var sock = KBEngine.app.socket; + sock.onopen = undefined; + sock.onerror = undefined; + sock.onmessage = undefined; + sock.onclose = undefined; + KBEngine.app.socket = null; + sock.close(); + } + } + catch (e) { + } + }; + KBEngineApp.prototype.reset = function () { + if (KBEngine.app.entities != undefined && KBEngine.app.entities != null) { + KBEngine.app.clearEntities(true); + } + KBEngine.app.resetSocket(); + KBEngine.app.currserver = "loginapp"; + KBEngine.app.currstate = "create"; + // 扩展数据 + KBEngine.app.serverdatas = ""; + // 版本信息 + KBEngine.app.serverVersion = ""; + KBEngine.app.serverScriptVersion = ""; + KBEngine.app.serverProtocolMD5 = ""; + KBEngine.app.serverEntityDefMD5 = ""; + KBEngine.app.clientVersion = "1.1.5"; + KBEngine.app.clientScriptVersion = "0.1.0"; + // player的相关信息 + KBEngine.app.entity_uuid = null; + KBEngine.app.entity_id = 0; + KBEngine.app.entity_type = ""; + // 当前玩家最后一次同步到服务端的位置与朝向与服务端最后一次同步过来的位置 + KBEngine.app.entityServerPos = new Vector3(0.0, 0.0, 0.0); + // 客户端所有的实体 + KBEngine.app.entities = {}; + KBEngine.app.entityIDAliasIDList = []; + KBEngine.app.controlledEntities = []; + // 空间的信息 + KBEngine.app.spacedata = {}; + KBEngine.app.spaceID = 0; + KBEngine.app.spaceResPath = ""; + KBEngine.app.isLoadedGeometry = false; + var dateObject = new Date(); + KBEngine.app.lastTickTime = dateObject.getTime(); + KBEngine.app.lastTickCBTime = dateObject.getTime(); + mappingDataType(); + // 当前组件类别, 配套服务端体系 + KBEngine.app.component = "client"; + }; + KBEngineApp.prototype.installEvents = function () { + KBEngine.Event.register("createAccount", KBEngine.app, "createAccount"); + KBEngine.Event.register("login", KBEngine.app, "login"); + KBEngine.Event.register("reloginBaseapp", KBEngine.app, "reloginBaseapp"); + KBEngine.Event.register("bindAccountEmail", KBEngine.app, "bindAccountEmail"); + KBEngine.Event.register("newPassword", KBEngine.app, "newPassword"); + }; + KBEngineApp.prototype.uninstallEvents = function () { + KBEngine.Event.deregister("reloginBaseapp", KBEngine.app); + KBEngine.Event.deregister("login", KBEngine.app); + KBEngine.Event.deregister("createAccount", KBEngine.app); + }; + KBEngineApp.prototype.hello = function () { + var bundle = new Bundle(); + if (KBEngine.app.currserver == "loginapp") + bundle.newMessage(messages['Loginapp_hello']); + else + bundle.newMessage(messages['Baseapp_hello']); + bundle.writeString(KBEngine.app.clientVersion); + bundle.writeString(KBEngine.app.clientScriptVersion); + bundle.writeBlob(KBEngine.app.encryptedKey); + bundle.send(KBEngine.app); + }; + KBEngineApp.prototype.player = function () { + return KBEngine.app.entities[KBEngine.app.entity_id]; + }; + KBEngineApp.prototype.findEntity = function (entityID) { + return KBEngine.app.entities[entityID]; + }; + KBEngineApp.prototype.connect = function (addr) { + console.assert(KBEngine.app.socket == null, "Assertion of socket not is null"); + try { + //todo 应该是在这里设置wss + KBEngine.app.socket = new WebSocket(addr); + } + catch (e) { + ERROR_MSG('WebSocket init error!'); + KBEngine.Event.fire("onConnectionState", false); + return; + } + KBEngine.app.socket.binaryType = "arraybuffer"; + KBEngine.app.socket.onopen = KBEngine.app.onopen; + KBEngine.app.socket.onerror = KBEngine.app.onerror_before_onopen; + KBEngine.app.socket.onmessage = KBEngine.app.onmessage; + KBEngine.app.socket.onclose = KBEngine.app.onclose; + }; + KBEngineApp.prototype.disconnect = function () { + KBEngine.app.resetSocket(); + }; + KBEngineApp.prototype.onopen = function () { + INFO_MSG('connect success!'); + KBEngine.app.socket.onerror = KBEngine.app.onerror_after_onopen; + KBEngine.Event.fire("onConnectionState", true); + }; + KBEngineApp.prototype.onerror_before_onopen = function (evt) { + ERROR_MSG('connect error:' + evt.data); + KBEngine.app.resetSocket(); + KBEngine.Event.fire("onConnectionState", false); + }; + KBEngineApp.prototype.onerror_after_onopen = function (evt) { + ERROR_MSG('connect error:' + evt.data); + KBEngine.app.resetSocket(); + KBEngine.Event.fire("onDisconnected"); + }; + KBEngineApp.prototype.onmessage = function (msg) { + var stream = new MemoryStream(msg.data); + stream.wpos = msg.data.byteLength; + while (stream.rpos < stream.wpos) { + var msgid = stream.readUint16(); + var msgHandler = KBEngine.clientmessages[msgid]; + if (!msgHandler) { + ERROR_MSG("KBEngineApp::onmessage[" + KBEngine.app.currserver + "]: not found msg(" + msgid + ")!"); + } + else { + var msglen = msgHandler.length; + if (msglen == -1) { + msglen = stream.readUint16(); + // 扩展长度 + if (msglen == 65535) + msglen = stream.readUint32(); + } + var wpos = stream.wpos; + var rpos = stream.rpos + msglen; + stream.wpos = rpos; + msgHandler.handleMessage(stream); + stream.wpos = wpos; + stream.rpos = rpos; + } + } + }; + KBEngineApp.prototype.onclose = function () { + INFO_MSG('connect close:' + KBEngine.app.currserver); + KBEngine.app.resetSocket(); + KBEngine.Event.fire("onDisconnected"); + //if(app.currserver != "loginapp") + // app.reset(); + }; + KBEngineApp.prototype.send = function (msg) { + KBEngine.app.socket.send(msg); + }; + KBEngineApp.prototype.close = function () { + INFO_MSG('KBEngine::close()'); + KBEngine.app.socket.close(); + KBEngine.app.reset(); + }; + KBEngineApp.prototype.update = function () { + if (KBEngine.app.socket == null) + return; + var dateObject = new Date(); + if ((dateObject.getTime() - KBEngine.app.lastTickTime) / 1000 > KBEngine.app.args.serverHeartbeatTick) { + // 如果心跳回调接收时间小于心跳发送时间,说明没有收到回调 + // 此时应该通知客户端掉线了 + if (KBEngine.app.lastTickCBTime < KBEngine.app.lastTickTime) { + ERROR_MSG("sendTick: Receive appTick timeout!"); + KBEngine.app.socket.close(); + } + if (KBEngine.app.currserver == "loginapp") { + if (messages['Loginapp_onClientActiveTick'] != undefined) { + var bundle = new Bundle(); + bundle.newMessage(messages['Loginapp_onClientActiveTick']); + bundle.send(KBEngine.app); + } + } + else { + if (messages['Baseapp_onClientActiveTick'] != undefined) { + var bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_onClientActiveTick']); + bundle.send(KBEngine.app); + } + } + KBEngine.app.lastTickTime = dateObject.getTime(); + } + KBEngine.app.updatePlayerToServer(); + }; + KBEngineApp.prototype.Client_onAppActiveTickCB = function () { + var dateObject = new Date(); + KBEngine.app.lastTickCBTime = dateObject.getTime(); + }; + KBEngineApp.prototype.serverErr = function (id) { + var e = KBEngine.app.serverErrs[id]; + if (e == undefined) { + return ""; + } + return e.name + " [" + e.descr + "]"; + }; + KBEngineApp.prototype.Client_onImportServerErrorsDescr = function (stream) { + var size = stream.readUint16(); + while (size > 0) { + size -= 1; + var e = new ServerErr(); + e.id = stream.readUint16(); + e.name = utf8ArrayToString(stream.readBlob()); + e.descr = utf8ArrayToString(stream.readBlob()); + KBEngine.app.serverErrs[e.id] = e; + INFO_MSG("Client_onImportServerErrorsDescr: id=" + e.id + ", name=" + e.name + ", descr=" + e.descr); + } + }; + KBEngineApp.prototype.onOpenLoginapp_login = function () { + INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"); + KBEngine.Event.fire("onConnectionState", true); + KBEngine.app.currserver = "loginapp"; + KBEngine.app.currstate = "login"; + if (!KBEngine.app.loginappMessageImported) { + var bundle = new Bundle(); + bundle.newMessage(messages.Loginapp_importClientMessages); + bundle.send(KBEngine.app); + KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; + INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."); + KBEngine.Event.fire("Loginapp_importClientMessages"); + } + else { + KBEngine.app.onImportClientMessagesCompleted(); + } + }; + KBEngineApp.prototype.onOpenLoginapp_createAccount = function () { + KBEngine.Event.fire("onConnectionState", true); + INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"); + KBEngine.app.currserver = "loginapp"; + KBEngine.app.currstate = "createAccount"; + if (!KBEngine.app.loginappMessageImported) { + var bundle = new Bundle(); + bundle.newMessage(messages.Loginapp_importClientMessages); + bundle.send(KBEngine.app); + KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; + INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."); + KBEngine.Event.fire("Loginapp_importClientMessages"); + } + else { + KBEngine.app.onImportClientMessagesCompleted(); + } + }; + KBEngineApp.prototype.onImportClientMessagesCompleted = function () { + INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"); + KBEngine.app.socket.onmessage = KBEngine.app.onmessage; + KBEngine.app.hello(); + if (KBEngine.app.currserver == "loginapp") { + if (!KBEngine.app.serverErrorsDescrImported) { + INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"); + KBEngine.app.serverErrorsDescrImported = true; + var bundle = new Bundle(); + bundle.newMessage(messages['Loginapp_importServerErrorsDescr']); + bundle.send(KBEngine.app); + } + if (KBEngine.app.currstate == "login") + KBEngine.app.login_loginapp(false); + else if (KBEngine.app.currstate == "resetpassword") + KBEngine.app.resetpassword_loginapp(false); + else + KBEngine.app.createAccount_loginapp(false); + KBEngine.app.loginappMessageImported = true; + } + else { + KBEngine.app.baseappMessageImported = true; + if (!KBEngine.app.entitydefImported) { + INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ..."); + var bundle = new Bundle(); + bundle.newMessage(messages.Baseapp_importClientEntityDef); + bundle.send(KBEngine.app); + KBEngine.Event.fire("Baseapp_importClientEntityDef"); + } + else { + KBEngine.app.onImportEntityDefCompleted(); + } + } + }; + KBEngineApp.prototype.createDataTypeFromStreams = function (stream, canprint) { + var aliassize = stream.readUint16(); + INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size=" + aliassize + ")!"); + while (aliassize > 0) { + aliassize--; + KBEngine.app.createDataTypeFromStream(stream, canprint); + } + ; + for (var datatype in datatypes) { + if (datatypes[datatype] != undefined) { + datatypes[datatype].bind(); + } + } + }; + KBEngineApp.prototype.createDataTypeFromStream = function (stream, canprint) { + var utype = stream.readUint16(); + var name = stream.readString(); + var valname = stream.readString(); + var length; + /* 有一些匿名类型,我们需要提供一个唯一名称放到datatypes中 + 如: + + ARRAY INT8 + + */ + if (valname.length == 0) + length = "Null_" + utype; + if (canprint) + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias(" + name + ":" + valname + ")!"); + if (name == "FIXED_DICT") { + var datatype = new DATATYPE_FIXED_DICT(); + var keysize = stream.readUint8(); + datatype.implementedBy = stream.readString(); + while (keysize > 0) { + keysize--; + var keyname = stream.readString(); + var keyutype = stream.readUint16(); + datatype.dicttype[keyname] = keyutype; + } + ; + datatypes[valname] = datatype; + } + else if (name == "ARRAY") { + var uitemtype = stream.readUint16(); + var datatype = new DATATYPE_ARRAY(); + datatype.type = uitemtype; + datatypes[valname] = datatype; + } + else { + datatypes[valname] = datatypes[name]; + } + datatypes[utype] = datatypes[valname]; + // 将用户自定义的类型补充到映射表中 + KBEngine.datatype2id[valname] = utype; + }; + KBEngineApp.prototype.Client_onImportClientEntityDef = function (stream) { + KBEngine.app.createDataTypeFromStreams(stream, true); + while (!stream.readEOF()) { + var scriptmodule_name = stream.readString(); + var scriptUtype = stream.readUint16(); + var propertysize = stream.readUint16(); + var methodsize = stream.readUint16(); + var base_methodsize = stream.readUint16(); + var cell_methodsize = stream.readUint16(); + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import(" + scriptmodule_name + "), propertys(" + propertysize + "), " + + "clientMethods(" + methodsize + "), baseMethods(" + base_methodsize + "), cellMethods(" + cell_methodsize + ")!"); + KBEngine.moduledefs[scriptmodule_name] = {}; + var currModuleDefs = KBEngine.moduledefs[scriptmodule_name]; + currModuleDefs["name"] = scriptmodule_name; + currModuleDefs["propertys"] = {}; + currModuleDefs["methods"] = {}; + currModuleDefs["base_methods"] = {}; + currModuleDefs["cell_methods"] = {}; + KBEngine.moduledefs[scriptUtype] = currModuleDefs; + var self_propertys = currModuleDefs["propertys"]; + var self_methods = currModuleDefs["methods"]; + var self_base_methods = currModuleDefs["base_methods"]; + var self_cell_methods = currModuleDefs["cell_methods"]; + try { + var Class_1 = eval("" + scriptmodule_name); + } + catch (e) { + var Class_2 = undefined; + } + while (propertysize > 0) { + propertysize--; + var properUtype = stream.readUint16(); + var properFlags = stream.readUint32(); + var aliasID = stream.readInt16(); + var name_2 = stream.readString(); + var defaultValStr = stream.readString(); + var utype = datatypes[stream.readUint16()]; + var setmethod = null; + if (Class != undefined) { + setmethod = Class.prototype["set_" + name_2]; + if (setmethod == undefined) + setmethod = null; + } + var savedata = [properUtype, aliasID, name_2, defaultValStr, utype, setmethod, properFlags]; + self_propertys[name_2] = savedata; + if (aliasID != -1) { + self_propertys[aliasID] = savedata; + currModuleDefs["usePropertyDescrAlias"] = true; + } + else { + self_propertys[properUtype] = savedata; + currModuleDefs["usePropertyDescrAlias"] = false; + } + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), property(" + name_2 + "/" + properUtype + ")."); + } + ; + while (methodsize > 0) { + methodsize--; + var methodUtype = stream.readUint16(); + var aliasID = stream.readInt16(); + var name_3 = stream.readString(); + var argssize = stream.readUint8(); + var args = []; + while (argssize > 0) { + argssize--; + args.push(datatypes[stream.readUint16()]); + } + ; + var savedata = [methodUtype, aliasID, name_3, args]; + self_methods[name_3] = savedata; + if (aliasID != -1) { + self_methods[aliasID] = savedata; + currModuleDefs["useMethodDescrAlias"] = true; + } + else { + self_methods[methodUtype] = savedata; + currModuleDefs["useMethodDescrAlias"] = false; + } + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), method(" + name_3 + ")."); + } + ; + while (base_methodsize > 0) { + base_methodsize--; + var methodUtype = stream.readUint16(); + var aliasID = stream.readInt16(); + var name_4 = stream.readString(); + var argssize = stream.readUint8(); + var args = []; + while (argssize > 0) { + argssize--; + args.push(datatypes[stream.readUint16()]); + } + ; + self_base_methods[name_4] = [methodUtype, aliasID, name_4, args]; + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), base_method(" + name_4 + ")."); + } + ; + while (cell_methodsize > 0) { + cell_methodsize--; + var methodUtype = stream.readUint16(); + var aliasID = stream.readInt16(); + var name_5 = stream.readString(); + var argssize = stream.readUint8(); + var args = []; + while (argssize > 0) { + argssize--; + args.push(datatypes[stream.readUint16()]); + } + ; + self_cell_methods[name_5] = [methodUtype, aliasID, name_5, args]; + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), cell_method(" + name_5 + ")."); + } + ; + var defmethod = void 0; + try { + defmethod = eval("" + scriptmodule_name); + } + catch (e) { + ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module(" + scriptmodule_name + ") not found!"); + defmethod = undefined; + } + for (var name_6 in currModuleDefs.propertys) { + var infos = currModuleDefs.propertys[name_6]; + var properUtype = infos[0]; + var aliasID = infos[1]; + var n = infos[2]; + var defaultValStr = infos[3]; + var utype = infos[4]; + if (defmethod != undefined) + defmethod.prototype[n] = utype.parseDefaultValStr(defaultValStr); + } + ; + for (var name_7 in currModuleDefs.methods) { + var infos = currModuleDefs.methods[name_7]; + var properUtype = infos[0]; + var aliasID = infos[1]; + var n = infos[2]; + var args = infos[3]; + if (defmethod != undefined && defmethod.prototype[n] == undefined) { + WARNING_MSG(scriptmodule_name + ":: method(" + n + ") no implement!"); + } + } + ; + } + KBEngine.app.onImportEntityDefCompleted(); + }; + KBEngineApp.prototype.Client_onVersionNotMatch = function (stream) { + KBEngine.app.serverVersion = stream.readString(); + ERROR_MSG("Client_onVersionNotMatch: verInfo=" + KBEngine.app.clientVersion + " not match(server: " + KBEngine.app.serverVersion + ")"); + KBEngine.Event.fire("onVersionNotMatch", KBEngine.app.clientVersion, KBEngine.app.serverVersion); + }; + KBEngineApp.prototype.Client_onScriptVersionNotMatch = function (stream) { + KBEngine.app.serverScriptVersion = stream.readString(); + ERROR_MSG("Client_onScriptVersionNotMatch: verInfo=" + KBEngine.app.clientScriptVersion + " not match(server: " + KBEngine.app.serverScriptVersion + ")"); + KBEngine.Event.fire("onScriptVersionNotMatch", KBEngine.app.clientScriptVersion, KBEngine.app.serverScriptVersion); + }; + KBEngineApp.prototype.onImportEntityDefCompleted = function () { + INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"); + KBEngine.app.entitydefImported = true; + KBEngine.app.login_baseapp(false); + }; + KBEngineApp.prototype.Client_onImportClientMessages = function (msg) { + var stream = new MemoryStream(msg.data); + var msgid = stream.readUint16(); + if (msgid == messages.onImportClientMessages.id) { + var msglen = stream.readUint16(); + var msgcount = stream.readUint16(); + INFO_MSG("KBEngineApp::onImportClientMessages: start(" + msgcount + ") ...!"); + while (msgcount > 0) { + msgcount--; + msgid = stream.readUint16(); + msglen = stream.readInt16(); + var msgname = stream.readString(); + var argtype = stream.readInt8(); + var argsize = stream.readUint8(); + var argstypes = new Array(argsize); + for (var i = 0; i < argsize; i++) { + argstypes[i] = stream.readUint8(); + } + var handler = null; + var isClientMethod = msgname.indexOf("Client_") >= 0; + if (isClientMethod) { + handler = KBEngine.app[msgname]; + if (handler == null || handler == undefined) { + WARNING_MSG("KBEngineApp::onImportClientMessages[" + KBEngine.app.currserver + "]: interface(" + msgname + "/" + msgid + ") no implement!"); + handler = null; + } + else { + INFO_MSG("KBEngineApp::onImportClientMessages: import(" + msgname + ") successfully!"); + } + } + if (msgname.length > 0) { + messages[msgname] = new Message(msgid, msgname, msglen, argtype, argstypes, handler); + if (isClientMethod) + KBEngine.clientmessages[msgid] = messages[msgname]; + else + messages[KBEngine.app.currserver][msgid] = messages[msgname]; + } + else { + messages[KBEngine.app.currserver][msgid] = new Message(msgid, msgname, msglen, argtype, argstypes, handler); + } + } + ; + KBEngine.app.onImportClientMessagesCompleted(); + } + else + ERROR_MSG("KBEngineApp::onmessage: not found msg(" + msgid + ")!"); + }; + KBEngineApp.prototype.createAccount = function (username, password, datas) { + KBEngine.app.reset(); + KBEngine.app.username = username; + KBEngine.app.password = password; + KBEngine.app.clientdatas = datas; + KBEngine.app.createAccount_loginapp(true); + }; + KBEngineApp.prototype.createAccount_loginapp = function (noconnect) { + if (noconnect) { + INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + KBEngine.app.ip + ":" + KBEngine.app.port + "!"); + KBEngine.app.connect("ws://" + KBEngine.app.ip + ":" + KBEngine.app.port); + KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_createAccount; + } + else { + var bundle = new Bundle(); + bundle.newMessage(messages['Loginapp_reqCreateAccount']); + bundle.writeString(KBEngine.app.username); + bundle.writeString(KBEngine.app.password); + bundle.writeBlob(KBEngine.app.clientdatas); + bundle.send(KBEngine.app); + } + }; + KBEngineApp.prototype.bindAccountEmail = function (emailAddress) { + var bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_reqAccountBindEmail']); + bundle.writeInt32(KBEngine.app.entity_id); + bundle.writeString(KBEngine.app.password); + bundle.writeString(emailAddress); + bundle.send(KBEngine.app); + }; + KBEngineApp.prototype.newPassword = function (old_password, new_password) { + var bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_reqAccountNewPassword']); + bundle.writeInt32(KBEngine.app.entity_id); + bundle.writeString(old_password); + bundle.writeString(new_password); + bundle.send(KBEngine.app); + }; + KBEngineApp.prototype.login = function (username, password, datas) { + KBEngine.app.reset(); + KBEngine.app.username = username; + KBEngine.app.password = password; + KBEngine.app.clientdatas = datas; + KBEngine.app.login_loginapp(true); + }; + KBEngineApp.prototype.login_loginapp = function (noconnect) { + if (noconnect) { + INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://" + KBEngine.app.ip + ":" + KBEngine.app.port + "!"); + KBEngine.app.connect("ws://" + KBEngine.app.ip + ":" + KBEngine.app.port); + KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_login; + } + else { + var bundle = new Bundle(); + bundle.newMessage(messages['Loginapp_login']); + bundle.writeInt8(KBEngine.app.args.clientType); // clientType + bundle.writeBlob(KBEngine.app.clientdatas); + bundle.writeString(KBEngine.app.username); + bundle.writeString(KBEngine.app.password); + bundle.send(KBEngine.app); + } + }; + KBEngineApp.prototype.onOpenLoginapp_resetpassword = function () { + INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"); + KBEngine.app.currserver = "loginapp"; + KBEngine.app.currstate = "resetpassword"; + if (!KBEngine.app.loginappMessageImported) { + var bundle = new Bundle(); + bundle.newMessage(messages.Loginapp_importClientMessages); + bundle.send(KBEngine.app); + KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; + INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ..."); + } + else { + KBEngine.app.onImportClientMessagesCompleted(); + } + }; + KBEngineApp.prototype.reset_password = function (username) { + KBEngine.app.reset(); + KBEngine.app.username = username; + KBEngine.app.resetpassword_loginapp(true); + }; + KBEngineApp.prototype.resetpassword_loginapp = function (noconnect) { + if (noconnect) { + INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + KBEngine.app.ip + ":" + KBEngine.app.port + "!"); + KBEngine.app.connect("ws://" + KBEngine.app.ip + ":" + KBEngine.app.port); + KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_resetpassword; + } + else { + var bundle = new Bundle(); + bundle.newMessage(messages['Loginapp_reqAccountResetPassword']); + bundle.writeString(KBEngine.app.username); + bundle.send(KBEngine.app); + } + }; + KBEngineApp.prototype.onOpenBaseapp = function () { + INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"); + KBEngine.app.currserver = "baseapp"; + if (!KBEngine.app.baseappMessageImported) { + var bundle = new Bundle(); + bundle.newMessage(messages.Baseapp_importClientMessages); + bundle.send(KBEngine.app); + KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; + KBEngine.Event.fire("Baseapp_importClientMessages"); + } + else { + KBEngine.app.onImportClientMessagesCompleted(); + } + }; + KBEngineApp.prototype.login_baseapp = function (noconnect) { + if (noconnect) { + KBEngine.Event.fire("onLoginBaseapp"); + INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "!"); + KBEngine.app.connect("ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort); + if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) + KBEngine.app.socket.onopen = KBEngine.app.onOpenBaseapp; + } + else { + var bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_loginBaseapp']); + bundle.writeString(KBEngine.app.username); + bundle.writeString(KBEngine.app.password); + bundle.send(KBEngine.app); + } + }; + KBEngineApp.prototype.reloginBaseapp = function () { + if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) + return; + KBEngine.app.resetSocket(); + KBEngine.Event.fire("onReloginBaseapp"); + INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "!"); + KBEngine.app.connect("ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort); + if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) + KBEngine.app.socket.onopen = KBEngine.app.onReOpenBaseapp; + }; + KBEngineApp.prototype.onReOpenBaseapp = function () { + INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"); + KBEngine.app.currserver = "baseapp"; + var bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_reloginBaseapp']); + bundle.writeString(KBEngine.app.username); + bundle.writeString(KBEngine.app.password); + bundle.writeUint64(KBEngine.app.entity_uuid); + bundle.writeInt32(KBEngine.app.entity_id); + bundle.send(KBEngine.app); + var dateObject = new Date(); + KBEngine.app.lastTickCBTime = dateObject.getTime(); + }; + KBEngineApp.prototype.Client_onHelloCB = function (args) { + KBEngine.app.serverVersion = args.readString(); + KBEngine.app.serverScriptVersion = args.readString(); + KBEngine.app.serverProtocolMD5 = args.readString(); + KBEngine.app.serverEntityDefMD5 = args.readString(); + var ctype = args.readInt32(); + INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo(" + KBEngine.app.serverVersion + "), scriptVerInfo(" + + KBEngine.app.serverScriptVersion + "), serverProtocolMD5(" + KBEngine.app.serverProtocolMD5 + "), serverEntityDefMD5(" + + KBEngine.app.serverEntityDefMD5 + "), ctype(" + ctype + ")!"); + var dateObject = new Date(); + KBEngine.app.lastTickCBTime = dateObject.getTime(); + }; + KBEngineApp.prototype.Client_onLoginFailed = function (args) { + var failedcode = args.readUint16(); + KBEngine.app.serverdatas = args.readBlob(); + ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + "), datas(" + KBEngine.app.serverdatas.length + ")!"); + KBEngine.Event.fire("onLoginFailed", failedcode); + }; + KBEngineApp.prototype.Client_onLoginSuccessfully = function (args) { + var accountName = args.readString(); + KBEngine.app.username = accountName; + KBEngine.app.baseappIp = args.readString(); + KBEngine.app.baseappPort = args.readUint16(); + KBEngine.app.serverdatas = args.readBlob(); + INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName(" + accountName + "), addr(" + + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "), datas(" + KBEngine.app.serverdatas.length + ")!"); + KBEngine.app.disconnect(); + KBEngine.app.login_baseapp(true); + }; + KBEngineApp.prototype.Client_onLoginBaseappFailed = function (failedcode) { + ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); + KBEngine.Event.fire("onLoginBaseappFailed", failedcode); + }; + KBEngineApp.prototype.Client_onReloginBaseappFailed = function (failedcode) { + ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); + KBEngine.Event.fire("onReloginBaseappFailed", failedcode); + }; + KBEngineApp.prototype.Client_onReloginBaseappSuccessfully = function (stream) { + KBEngine.app.entity_uuid = stream.readUint64(); + DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: " + KBEngine.app.username); + KBEngine.Event.fire("onReloginBaseappSuccessfully"); + }; + KBEngineApp.prototype.getentityclass = function (entityType) { + var runclass = KBEngine.app.entityclass[entityType]; + if (runclass == undefined) { + runclass = eval("" + entityType); + if (runclass == undefined) { + ERROR_MSG("KBEngineApp::getentityclass: entityType(" + entityType + ") is error!"); + return runclass; + } + else + KBEngine.app.entityclass[entityType] = runclass; + } + return runclass; + }; + KBEngineApp.prototype.Client_onCreatedProxies = function (rndUUID, eid, entityType) { + INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid(" + eid + "), entityType(" + entityType + ")!"); + var entity = KBEngine.app.entities[eid]; + KBEngine.app.entity_uuid = rndUUID; + KBEngine.app.entity_id = eid; + if (entity == undefined) { + var runclass = KBEngine.app.getentityclass(entityType); + if (runclass == undefined) + return; + var entity_1 = new runclass(); + entity_1.id = eid; + entity_1.className = entityType; + entity_1.base = new EntityCall(); + entity_1.base.id = eid; + entity_1.base.className = entityType; + entity_1.base.type = KBEngine.ENTITYCALL_TYPE_BASE; + KBEngine.app.entities[eid] = entity_1; + var entityMessage = KBEngine.bufferedCreateEntityMessage[eid]; + if (entityMessage != undefined) { + KBEngine.app.Client_onUpdatePropertys(entityMessage); + delete KBEngine.bufferedCreateEntityMessage[eid]; + } + entity_1.__init__(); + entity_1.inited = true; + if (KBEngine.app.args.isOnInitCallPropertysSetMethods) + entity_1.callPropertysSetMethods(); + } + else { + var entityMessage = KBEngine.bufferedCreateEntityMessage[eid]; + if (entityMessage != undefined) { + KBEngine.app.Client_onUpdatePropertys(entityMessage); + delete KBEngine.bufferedCreateEntityMessage[eid]; + } + } + }; + KBEngineApp.prototype.getViewEntityIDFromStream = function (stream) { + var id = 0; + if (KBEngine.app.entityIDAliasIDList.length > 255) { + id = stream.readInt32(); + } + else { + var aliasID = stream.readUint8(); + // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 + // 则可以忽略这个错误, 因为cellapp可能一直在向baseapp发送同步消息, 当客户端重连上时未等 + // 服务端初始化步骤开始则收到同步信息, 此时这里就会出错。 + if (KBEngine.app.entityIDAliasIDList.length <= aliasID) + return 0; + id = KBEngine.app.entityIDAliasIDList[aliasID]; + } + return id; + }; + KBEngineApp.prototype.onUpdatePropertys_ = function (eid, stream) { + var entity = KBEngine.app.entities[eid]; + if (entity == undefined) { + var entityMessage = KBEngine.bufferedCreateEntityMessage[eid]; + if (entityMessage != undefined) { + ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity(" + eid + ") not found!"); + return; + } + var stream1 = new MemoryStream(stream.buffer); + stream1.wpos = stream.wpos; + stream1.rpos = stream.rpos - 4; + KBEngine.bufferedCreateEntityMessage[eid] = stream1; + return; + } + var currModule = KBEngine.moduledefs[entity.className]; + var pdatas = currModule.propertys; + while (stream.length() > 0) { + var utype = 0; + if (currModule.usePropertyDescrAlias) + utype = stream.readUint8(); + else + utype = stream.readUint16(); + var propertydata = pdatas[utype]; + var setmethod = propertydata[5]; + var flags = propertydata[6]; + var val = propertydata[4].createFromStream(stream); + var oldval = entity[propertydata[2]]; + INFO_MSG("KBEngineApp::Client_onUpdatePropertys: " + entity.className + "(id=" + eid + " " + propertydata[2] + ", val=" + val + ")!"); + entity[propertydata[2]] = val; + if (setmethod != null) { + // base类属性或者进入世界后cell类属性会触发set_*方法 + if (flags == 0x00000020 || flags == 0x00000040) { + if (entity.inited) + setmethod.call(entity, oldval); + } + else { + if (entity.inWorld) + setmethod.call(entity, oldval); + } + } + } + }; + KBEngineApp.prototype.Client_onUpdatePropertysOptimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + KBEngine.app.onUpdatePropertys_(eid, stream); + }; + KBEngineApp.prototype.Client_onUpdatePropertys = function (stream) { + var eid = stream.readInt32(); + KBEngine.app.onUpdatePropertys_(eid, stream); + }; + KBEngineApp.prototype.onRemoteMethodCall_ = function (eid, stream) { + var entity = KBEngine.app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); + return; + } + var methodUtype = 0; + if (KBEngine.moduledefs[entity.className].useMethodDescrAlias) + methodUtype = stream.readUint8(); + else + methodUtype = stream.readUint16(); + var methoddata = KBEngine.moduledefs[entity.className].methods[methodUtype]; + var args = []; + var argsdata = methoddata[3]; + for (var i = 0; i < argsdata.length; i++) { + args.push(argsdata[i].createFromStream(stream)); + } + if (entity[methoddata[2]] != undefined) { + entity[methoddata[2]].apply(entity, args); + } + else { + ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found method(" + methoddata[2] + ")!"); + } + }; + KBEngineApp.prototype.Client_onRemoteMethodCallOptimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + KBEngine.app.onRemoteMethodCall_(eid, stream); + }; + KBEngineApp.prototype.Client_onRemoteMethodCall = function (stream) { + var eid = stream.readInt32(); + KBEngine.app.onRemoteMethodCall_(eid, stream); + }; + KBEngineApp.prototype.Client_onEntityEnterWorld = function (stream) { + var eid = stream.readInt32(); + if (KBEngine.app.entity_id > 0 && eid != KBEngine.app.entity_id) + KBEngine.app.entityIDAliasIDList.push(eid); + var entityType; + if (KBEngine.moduledefs['Length'] > 255) + entityType = stream.readUint16(); + else + entityType = stream.readUint8(); + var isOnGround = true; + if (stream.length() > 0) + isOnGround = stream.readInt8(); + entityType = KBEngine.moduledefs[entityType].name; + INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: " + entityType + "(" + eid + "), spaceID(" + KBEngine.app.spaceID + "), isOnGround(" + isOnGround + ")!"); + var entity = KBEngine.app.entities[eid]; + if (entity == undefined) { + var entityMessage = KBEngine.bufferedCreateEntityMessage[eid]; + if (entityMessage == undefined) { + ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity(" + eid + ") not found!"); + return; + } + var runclass = KBEngine.app.getentityclass(entityType); + if (runclass == undefined) + return; + var entity_2 = new runclass(); + entity_2.id = eid; + entity_2.className = entityType; + entity_2.cell = new EntityCall(); + entity_2.cell.id = eid; + entity_2.cell.className = entityType; + entity_2.cell.type = KBEngine.ENTITYCALL_TYPE_CELL; + KBEngine.app.entities[eid] = entity_2; + KBEngine.app.Client_onUpdatePropertys(entityMessage); + delete KBEngine.bufferedCreateEntityMessage[eid]; + // entity.isOnGround = isOnGround > 0; + entity_2.isOnGround = isOnGround; + entity_2.__init__(); + entity_2.inited = true; + entity_2.inWorld = true; + entity_2.enterWorld(); + if (KBEngine.app.args.isOnInitCallPropertysSetMethods) + entity_2.callPropertysSetMethods(); + entity_2.set_direction(entity_2.direction); + entity_2.set_position(entity_2.position); + } + else { + if (!entity.inWorld) { + entity.cell = new EntityCall(); + entity.cell.id = eid; + entity.cell.className = entityType; + entity.cell.type = KBEngine.ENTITYCALL_TYPE_CELL; + // 安全起见, 这里清空一下 + // 如果服务端上使用giveClientTo切换控制权 + // 之前的实体已经进入世界, 切换后的实体也进入世界, 这里可能会残留之前那个实体进入世界的信息 + KBEngine.app.entityIDAliasIDList = []; + KBEngine.app.entities = {}; + KBEngine.app.entities[entity.id] = entity; + entity.set_direction(entity.direction); + entity.set_position(entity.position); + KBEngine.app.entityServerPos.x = entity.position.x; + KBEngine.app.entityServerPos.y = entity.position.y; + KBEngine.app.entityServerPos.z = entity.position.z; + entity.isOnGround = isOnGround; + // entity.isOnGround = isOnGround > 0; + entity.inWorld = true; + entity.enterWorld(); + if (KBEngine.app.args.isOnInitCallPropertysSetMethods) + entity.callPropertysSetMethods(); + } + } + }; + KBEngineApp.prototype.Client_onEntityLeaveWorldOptimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + KBEngine.app.Client_onEntityLeaveWorld(eid); + }; + KBEngineApp.prototype.Client_onEntityLeaveWorld = function (eid) { + var entity = KBEngine.app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity(" + eid + ") not found!"); + return; + } + if (entity.inWorld) + entity.leaveWorld(); + if (KBEngine.app.entity_id > 0 && eid != KBEngine.app.entity_id) { + var newArray0 = []; + for (var i = 0; i < KBEngine.app.controlledEntities.length; i++) { + if (KBEngine.app.controlledEntities[i] != eid) { + newArray0.push(KBEngine.app.controlledEntities[i]); + } + else { + KBEngine.Event.fire("onLoseControlledEntity"); + } + } + KBEngine.app.controlledEntities = newArray0; + delete KBEngine.app.entities[eid]; + var newArray = []; + for (var i = 0; i < KBEngine.app.entityIDAliasIDList.length; i++) { + if (KBEngine.app.entityIDAliasIDList[i] != eid) { + newArray.push(KBEngine.app.entityIDAliasIDList[i]); + } + } + KBEngine.app.entityIDAliasIDList = newArray; + } + else { + KBEngine.app.clearSpace(false); + entity.cell = null; + } + }; + KBEngineApp.prototype.Client_onEntityDestroyed = function (eid) { + INFO_MSG("KBEngineApp::Client_onEntityDestroyed: entity(" + eid + ")!"); + var entity = KBEngine.app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onEntityDestroyed: entity(" + eid + ") not found!"); + return; + } + if (entity.inWorld) { + if (KBEngine.app.entity_id == eid) + KBEngine.app.clearSpace(false); + entity.leaveWorld(); + } + delete KBEngine.app.entities[eid]; + }; + KBEngineApp.prototype.Client_onEntityEnterSpace = function (stream) { + var eid = stream.readInt32(); + KBEngine.app.spaceID = stream.readUint32(); + var isOnGround = true; + if (stream.length() > 0) + isOnGround = stream.readInt8(); + var entity = KBEngine.app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity(" + eid + ") not found!"); + return; + } + entity.isOnGround = isOnGround; + KBEngine.app.entityServerPos.x = entity.position.x; + KBEngine.app.entityServerPos.y = entity.position.y; + KBEngine.app.entityServerPos.z = entity.position.z; + entity.enterSpace(); + }; + KBEngineApp.prototype.Client_onEntityLeaveSpace = function (eid) { + var entity = KBEngine.app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity(" + eid + ") not found!"); + return; + } + KBEngine.app.clearSpace(false); + entity.leaveSpace(); + }; + KBEngineApp.prototype.Client_onKicked = function (failedcode) { + ERROR_MSG("KBEngineApp::Client_onKicked: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); + KBEngine.Event.fire("onKicked", failedcode); + }; + KBEngineApp.prototype.Client_onCreateAccountResult = function (stream) { + var retcode = stream.readUint16(); + var datas = stream.readBlob(); + KBEngine.Event.fire("onCreateAccountResult", retcode, datas); + if (retcode != 0) { + ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: " + KBEngine.app.username + " create is failed! code=" + KBEngine.app.serverErrs[retcode].name + "!"); + return; + } + INFO_MSG("KBEngineApp::Client_onCreateAccountResult: " + KBEngine.app.username + " create is successfully!"); + }; + KBEngineApp.prototype.Client_onControlEntity = function (eid, isControlled) { + // eid = stream.readInt32(); + var entity = KBEngine.app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onControlEntity: entity(" + eid + ") not found!"); + return; + } + var isCont = isControlled != 0; + if (isCont) { + // 如果被控制者是玩家自己,那表示玩家自己被其它人控制了 + // 所以玩家自己不应该进入这个被控制列表 + if (KBEngine.app.player().id != entity.id) { + KBEngine.app.controlledEntities.push(entity); + } + } + else { + var newArray = []; + for (var i = 0; i < KBEngine.app.controlledEntities.length; i++) + if (KBEngine.app.controlledEntities[i] != entity.id) + newArray.push(KBEngine.app.controlledEntities[i]); + KBEngine.app.controlledEntities = newArray; + } + entity.isControlled = isCont; + try { + entity.onControlled(isCont); + KBEngine.Event.fire("onControlled", entity, isCont); + } + catch (e) { + ERROR_MSG("KBEngine::Client_onControlEntity: entity id = '" + eid + "', is controlled = '" + isCont + "', error = '" + e + "'"); + } + }; + KBEngineApp.prototype.updatePlayerToServer = function () { + var player = KBEngine.app.player(); + if (player == undefined || player.inWorld == false || KBEngine.app.spaceID == 0 || player.isControlled) + return; + if (player.entityLastLocalPos.distance(player.position) > 0.001 || player.entityLastLocalDir.distance(player.direction) > 0.001) { + // 记录玩家最后一次上报位置时自身当前的位置 + player.entityLastLocalPos.x = player.position.x; + player.entityLastLocalPos.y = player.position.y; + player.entityLastLocalPos.z = player.position.z; + player.entityLastLocalDir.x = player.direction.x; + player.entityLastLocalDir.y = player.direction.y; + player.entityLastLocalDir.z = player.direction.z; + var bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_onUpdateDataFromClient']); + bundle.writeFloat(player.position.x); + bundle.writeFloat(player.position.y); + bundle.writeFloat(player.position.z); + bundle.writeFloat(player.direction.x); + bundle.writeFloat(player.direction.y); + bundle.writeFloat(player.direction.z); + bundle.writeUint8(player.isOnGround); + bundle.writeUint32(KBEngine.app.spaceID); + bundle.send(KBEngine.app); + } + // 开始同步所有被控制了的entity的位置 + for (var i in KBEngine.app.controlledEntities) { + var entity = KBEngine.app.controlledEntities[i]; + var position = entity.position; + var direction = entity.direction; + var posHasChanged = entity.entityLastLocalPos.distance(position) > 0.001; + var dirHasChanged = entity.entityLastLocalDir.distance(direction) > 0.001; + if (posHasChanged || dirHasChanged) { + entity.entityLastLocalPos = position; + entity.entityLastLocalDir = direction; + var bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_onUpdateDataFromClientForControlledEntity']); + bundle.writeInt32(entity.id); + bundle.writeFloat(position.x); + bundle.writeFloat(position.y); + bundle.writeFloat(position.z); + bundle.writeFloat(direction.x); + bundle.writeFloat(direction.y); + bundle.writeFloat(direction.z); + bundle.writeUint8(entity.isOnGround); + bundle.writeUint32(KBEngine.app.spaceID); + bundle.send(KBEngine.app); + } + } + }; + KBEngineApp.prototype.addSpaceGeometryMapping = function (spaceID, respath) { + INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID(" + spaceID + "), respath(" + respath + ")!"); + KBEngine.app.spaceID = spaceID; + KBEngine.app.spaceResPath = respath; + KBEngine.Event.fire("addSpaceGeometryMapping", respath); + }; + KBEngineApp.prototype.clearSpace = function (isAll) { + KBEngine.app.entityIDAliasIDList = []; + KBEngine.app.spacedata = {}; + KBEngine.app.clearEntities(isAll); + KBEngine.app.isLoadedGeometry = false; + KBEngine.app.spaceID = 0; + }; + KBEngineApp.prototype.clearEntities = function (isAll) { + KBEngine.app.controlledEntities = []; + if (!isAll) { + var entity = KBEngine.app.player(); + for (var eid in KBEngine.app.entities) { + if (eid == entity.id) + continue; + if (KBEngine.app.entities[eid].inWorld) { + KBEngine.app.entities[eid].leaveWorld(); + } + KBEngine.app.entities[eid].onDestroy(); + } + KBEngine.app.entities = {}; + KBEngine.app.entities[entity.id] = entity; + } + else { + for (var eid in KBEngine.app.entities) { + if (KBEngine.app.entities[eid].inWorld) { + KBEngine.app.entities[eid].leaveWorld(); + } + KBEngine.app.entities[eid].onDestroy(); + } + KBEngine.app.entities = {}; + } + }; + KBEngineApp.prototype.Client_initSpaceData = function (stream) { + KBEngine.app.clearSpace(false); + KBEngine.app.spaceID = stream.readInt32(); + while (stream.length() > 0) { + var key = stream.readString(); + var value = stream.readString(); + KBEngine.app.Client_setSpaceData(KBEngine.app.spaceID, key, value); + } + INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID(" + KBEngine.app.spaceID + "), datas(" + KBEngine.app.spacedata + ")!"); + }; + KBEngineApp.prototype.Client_setSpaceData = function (spaceID, key, value) { + INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID(" + spaceID + "), key(" + key + "), value(" + value + ")!"); + KBEngine.app.spacedata[key] = value; + if (key == "_mapping") + KBEngine.app.addSpaceGeometryMapping(spaceID, value); + KBEngine.Event.fire("onSetSpaceData", spaceID, key, value); + }; + KBEngineApp.prototype.Client_delSpaceData = function (spaceID, key) { + INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID(" + spaceID + "), key(" + key + ")!"); + delete KBEngine.app.spacedata[key]; + KBEngine.Event.fire("onDelSpaceData", spaceID, key); + }; + KBEngineApp.prototype.Client_getSpaceData = function (spaceID, key) { + return KBEngine.app.spacedata[key]; + }; + KBEngineApp.prototype.Client_onUpdateBasePos = function (x, y, z) { + KBEngine.app.entityServerPos.x = x; + KBEngine.app.entityServerPos.y = y; + KBEngine.app.entityServerPos.z = z; + }; + KBEngineApp.prototype.Client_onUpdateBasePosXZ = function (x, z) { + KBEngine.app.entityServerPos.x = x; + KBEngine.app.entityServerPos.z = z; + }; + KBEngineApp.prototype.Client_onUpdateData = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var entity = KBEngine.app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onUpdateData: entity(" + eid + ") not found!"); + return; + } + }; + KBEngineApp.prototype.Client_onSetEntityPosAndDir = function (stream) { + var eid = stream.readInt32(); + var entity = KBEngine.app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity(" + eid + ") not found!"); + return; + } + entity.position.x = stream.readFloat(); + entity.position.y = stream.readFloat(); + entity.position.z = stream.readFloat(); + entity.direction.x = stream.readFloat(); + entity.direction.y = stream.readFloat(); + entity.direction.z = stream.readFloat(); + // 记录玩家最后一次上报位置时自身当前的位置 + entity.entityLastLocalPos.x = entity.position.x; + entity.entityLastLocalPos.y = entity.position.y; + entity.entityLastLocalPos.z = entity.position.z; + entity.entityLastLocalDir.x = entity.direction.x; + entity.entityLastLocalDir.y = entity.direction.y; + entity.entityLastLocalDir.z = entity.direction.z; + entity.set_direction(entity.direction); + entity.set_position(entity.position); + }; + KBEngineApp.prototype.Client_onUpdateData_ypr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var y = stream.readInt8(); + var p = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, p, r, -1); + }; + KBEngineApp.prototype.Client_onUpdateData_yp = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var y = stream.readInt8(); + var p = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, p, KBEngine.KBE_FLT_MAX, -1); + }; + KBEngineApp.prototype.Client_onUpdateData_yr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var y = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, KBEngine.KBE_FLT_MAX, r, -1); + }; + KBEngineApp.prototype.Client_onUpdateData_pr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var p = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, p, r, -1); + }; + KBEngineApp.prototype.Client_onUpdateData_y = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var y = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, -1); + }; + KBEngineApp.prototype.Client_onUpdateData_p = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var p = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, -1); + }; + KBEngineApp.prototype.Client_onUpdateData_r = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, r, -1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_ypr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readInt8(); + var p = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, p, r, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_yp = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readInt8(); + var p = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, p, KBEngine.KBE_FLT_MAX, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_yr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, KBEngine.KBE_FLT_MAX, r, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_pr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var p = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, p, r, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_y = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_p = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var p = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_r = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, r, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readPackY(); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_ypr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readPackY(); + var yaw = stream.readInt8(); + var p = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, r, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_yp = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readPackY(); + var yaw = stream.readInt8(); + var p = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, KBEngine.KBE_FLT_MAX, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_yr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readPackY(); + var yaw = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBEngine.KBE_FLT_MAX, r, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_pr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readPackY(); + var p = stream.readInt8(); + var r = stream.readInt8(); + ERROR_MSG('调用错误方法,无法找到x,z'); + //todo 这个是手动注释,如果错误再修改 + // app._updateVolatileData(eid, x, y, z, KBE_FLT_MAX, p, r, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_y = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readPackY(); + var yaw = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_p = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readPackY(); + var p = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_r = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + var y = stream.readPackY(); + //todo 这个是自己加的,如果错误再修改 + var r = stream.readInt8(); + var p = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], r, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0); + }; + KBEngineApp.prototype._updateVolatileData = function (entityID, x, y, z, yaw, pitch, roll, isOnGround) { + var entity = KBEngine.app.entities[entityID]; + if (entity == undefined) { + // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 + // 则可以忽略这个错误, 因为cellapp可能一直在向baseapp发送同步消息, 当客户端重连上时未等 + // 服务端初始化步骤开始则收到同步信息, 此时这里就会出错。 + ERROR_MSG("KBEngineApp::_updateVolatileData: entity(" + entityID + ") not found!"); + return; + } + // 小于0不设置 + if (isOnGround >= 0) { + entity.isOnGround = (isOnGround > 0); + } + var changeDirection = false; + if (roll != KBEngine.KBE_FLT_MAX) { + changeDirection = true; + entity.direction.x = int82angle(roll, false); + } + if (pitch != KBEngine.KBE_FLT_MAX) { + changeDirection = true; + entity.direction.y = int82angle(pitch, false); + } + if (yaw != KBEngine.KBE_FLT_MAX) { + changeDirection = true; + entity.direction.z = int82angle(yaw, false); + } + var done = false; + if (changeDirection == true) { + KBEngine.Event.fire("set_direction", entity); + done = true; + } + var positionChanged = false; + if (x != KBEngine.KBE_FLT_MAX || y != KBEngine.KBE_FLT_MAX || z != KBEngine.KBE_FLT_MAX) + positionChanged = true; + if (x == KBEngine.KBE_FLT_MAX) + x = 0.0; + if (y == KBEngine.KBE_FLT_MAX) + y = 0.0; + if (z == KBEngine.KBE_FLT_MAX) + z = 0.0; + if (positionChanged) { + entity.position.x = x + KBEngine.app.entityServerPos.x; + entity.position.y = y + KBEngine.app.entityServerPos.y; + entity.position.z = z + KBEngine.app.entityServerPos.z; + done = true; + KBEngine.Event.fire("updatePosition", entity); + } + if (done) + entity.onUpdateVolatileData(); + }; + KBEngineApp.prototype.Client_onStreamDataStarted = function (id, datasize, descr) { + KBEngine.Event.fire("onStreamDataStarted", id, datasize, descr); + }; + KBEngineApp.prototype.Client_onStreamDataRecv = function (stream) { + var id = stream.readUint16(); + var data = stream.readBlob(); + KBEngine.Event.fire("onStreamDataRecv", id, data); + }; + KBEngineApp.prototype.Client_onStreamDataCompleted = function (id) { + KBEngine.Event.fire("onStreamDataCompleted", id); + }; + KBEngineApp.prototype.Client_onReqAccountResetPasswordCB = function (failedcode) { + if (failedcode != 0) { + ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: " + KBEngine.app.username + " is failed! code=" + KBEngine.app.serverErrs[failedcode].name + "!"); + return; + } + INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: " + KBEngine.app.username + " is successfully!"); + }; + KBEngineApp.prototype.Client_onReqAccountBindEmailCB = function (failedcode) { + if (failedcode != 0) { + ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: " + KBEngine.app.username + " is failed! code=" + KBEngine.app.serverErrs[failedcode].name + "!"); + return; + } + INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: " + KBEngine.app.username + " is successfully!"); + }; + KBEngineApp.prototype.Client_onReqAccountNewPasswordCB = function (failedcode) { + if (failedcode != 0) { + ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: " + KBEngine.app.username + " is failed! code=" + KBEngine.app.serverErrs[failedcode].name + "!"); + return; + } + INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: " + KBEngine.app.username + " is successfully!"); + }; + return KBEngineApp; + }()); + KBEngine.KBEngineApp = KBEngineApp; + __reflect(KBEngineApp.prototype, "KBEngine.KBEngineApp"); + // 描述服务端返回的错误信息 + var ServerErr = (function () { + function ServerErr() { + this.name = ""; + this.descr = ""; + this.id = 0; + } + return ServerErr; + }()); + KBEngine.ServerErr = ServerErr; + __reflect(ServerErr.prototype, "KBEngine.ServerErr"); + var idInterval; + function create(args) { + if (KBEngine.app != undefined) + return; + if (args.constructor != KBEngineArgs) { + ERROR_MSG("create(): args(" + args + ") error! not is KBEngineArgs"); + return; + } + new KBEngineApp(args); + KBEngine.app.reset(); + KBEngine.app.installEvents(); + idInterval = setInterval(KBEngine.app.update, args.updateHZ); + } + KBEngine.create = create; + function destroy() { + if (idInterval != undefined) + clearInterval(idInterval); + if (KBEngine.app == undefined) + return; + KBEngine.app.uninstallEvents(); + KBEngine.app.reset(); + KBEngine.app = undefined; + } + KBEngine.destroy = destroy; +})(KBEngine || (KBEngine = {})); diff --git a/kbengine_ts/bin/kbengine.min.js b/kbengine_ts/bin/kbengine.min.js new file mode 100644 index 0000000..3148fa3 --- /dev/null +++ b/kbengine_ts/bin/kbengine.min.js @@ -0,0 +1,3 @@ +var __reflect=this&&this.__reflect||function(e,n,t){e.__class__=n,t?t.push(n):t=[n],e.__types__=e.__types__?t.concat(e.__types__):t},__extends=this&&this.__extends||function(e,n){function t(){this.constructor=e}for(var i in n)n.hasOwnProperty(i)&&(e[i]=n[i]);t.prototype=n.prototype,e.prototype=new t},KBEngine;!function(KBEngine){function INFO_MSG(e){console.info(e)}function DEBUG_MSG(e){console.debug(e)}function ERROR_MSG(e){console.error(e)}function WARNING_MSG(e){console.warn(e)}function utf8ArrayToString(e){var n,t,i,r,a,p;for(n="",i=e.length,t=0;i>t;)switch(r=e[t++],r>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:n+=String.fromCharCode(r);break;case 12:case 13:a=e[t++],n+=String.fromCharCode((31&r)<<6|63&a);break;case 14:a=e[t++],p=e[t++],n+=String.fromCharCode((15&r)<<12|(63&a)<<6|(63&p)<<0)}return n}function stringToUTF8Bytes(e){for(var n=[],t=0;ti?n.push(i):2048>i?n.push(192|i>>6,128|63&i):55296>i||i>=57344?n.push(224|i>>12,128|i>>6&63,128|63&i):(t++,i=65536+((1023&i)<<10|1023&e.charCodeAt(t)),n.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return n}function mappingDataType(){KBEngine.datatype2id={},KBEngine.datatype2id.STRING=1,KBEngine.datatype2id["STD::STRING"]=1,KBEngine.datatype2id.UINT8=2,KBEngine.datatype2id.BOOL=2,KBEngine.datatype2id.DATATYPE=2,KBEngine.datatype2id.CHAR=2,KBEngine.datatype2id.DETAIL_TYPE=2,KBEngine.datatype2id.ENTITYCALL_CALL_TYPE=2,KBEngine.datatype2id.UINT16=3,KBEngine.datatype2id["UNSIGNED SHORT"]=3,KBEngine.datatype2id.SERVER_ERROR_CODE=3,KBEngine.datatype2id.ENTITY_TYPE=3,KBEngine.datatype2id.ENTITY_PROPERTY_UID=3,KBEngine.datatype2id.ENTITY_METHOD_UID=3,KBEngine.datatype2id.ENTITY_SCRIPT_UID=3,KBEngine.datatype2id.DATATYPE_UID=3,KBEngine.datatype2id.UINT32=4,KBEngine.datatype2id.UINT=4,KBEngine.datatype2id["UNSIGNED INT"]=4,KBEngine.datatype2id.ARRAYSIZE=4,KBEngine.datatype2id.SPACE_ID=4,KBEngine.datatype2id.GAME_TIME=4,KBEngine.datatype2id.TIMER_ID=4,KBEngine.datatype2id.UINT64=5,KBEngine.datatype2id.DBID=5,KBEngine.datatype2id.COMPONENT_ID=5,KBEngine.datatype2id.INT8=6,KBEngine.datatype2id.COMPONENT_ORDER=6,KBEngine.datatype2id.INT16=7,KBEngine.datatype2id.SHORT=7,KBEngine.datatype2id.INT32=8,KBEngine.datatype2id.INT=8,KBEngine.datatype2id.ENTITY_ID=8,KBEngine.datatype2id.CALLBACK_ID=8,KBEngine.datatype2id.COMPONENT_TYPE=8,KBEngine.datatype2id.INT64=9,KBEngine.datatype2id.PYTHON=10,KBEngine.datatype2id.PY_DICT=10,KBEngine.datatype2id.PY_TUPLE=10,KBEngine.datatype2id.PY_LIST=10,KBEngine.datatype2id.ENTITYCALL=10,KBEngine.datatype2id.BLOB=11,KBEngine.datatype2id.UNICODE=12,KBEngine.datatype2id.FLOAT=13,KBEngine.datatype2id.DOUBLE=14,KBEngine.datatype2id.VECTOR2=15,KBEngine.datatype2id.VECTOR3=16,KBEngine.datatype2id.VECTOR4=17,KBEngine.datatype2id.FIXED_DICT=18,KBEngine.datatype2id.ARRAY=19}function bindWriter(e,n){switch(n){case KBEngine.datatype2id.UINT8:return e.writeUint8;case KBEngine.datatype2id.UINT16:return e.writeUint16;case KBEngine.datatype2id.UINT32:return e.writeUint32;case KBEngine.datatype2id.UINT64:return e.writeUint64;case KBEngine.datatype2id.INT8:return e.writeInt8;case KBEngine.datatype2id.INT16:return e.writeInt16;case KBEngine.datatype2id.INT32:return e.writeInt32;case KBEngine.datatype2id.INT64:return e.writeInt64;case KBEngine.datatype2id.FLOAT:return e.writeFloat;case KBEngine.datatype2id.DOUBLE:return e.writeDouble;case KBEngine.datatype2id.STRING:return e.writeString;case KBEngine.datatype2id.FIXED_DICT:return e.writeStream;case KBEngine.datatype2id.ARRAY:return e.writeStream;default:return e.writeStream}}function bindReader(e){switch(e){case KBEngine.datatype2id.UINT8:return KBEngine.reader.readUint8;case KBEngine.datatype2id.UINT16:return KBEngine.reader.readUint16;case KBEngine.datatype2id.UINT32:return KBEngine.reader.readUint32;case KBEngine.datatype2id.UINT64:return KBEngine.reader.readUint64;case KBEngine.datatype2id.INT8:return KBEngine.reader.readInt8;case KBEngine.datatype2id.INT16:return KBEngine.reader.readInt16;case KBEngine.datatype2id.INT32:return KBEngine.reader.readInt32;case KBEngine.datatype2id.INT64:return KBEngine.reader.readInt64;case KBEngine.datatype2id.FLOAT:return KBEngine.reader.readFloat;case KBEngine.datatype2id.DOUBLE:return KBEngine.reader.readDouble;case KBEngine.datatype2id.STRING:return KBEngine.reader.readString;case KBEngine.datatype2id.FIXED_DICT:return KBEngine.reader.readStream;case KBEngine.datatype2id.ARRAY:return KBEngine.reader.readStream;default:return KBEngine.reader.readStream}}function clampf(e,n,t){if(n>t){var i=n;n=t,t=i}return n>e?n:t>e?e:t}function int82angle(e,n){return e*(Math.PI/(n?254:128))}function angle2int8(e,n){var t=0;return t=n?clampf(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}function create(e){if(void 0==KBEngine.app){if(e.constructor!=KBEngineArgs)return void ERROR_MSG("create(): args("+e+") error! not is KBEngineArgs");new KBEngineApp(e),KBEngine.app.reset(),KBEngine.app.installEvents(),idInterval=setInterval(KBEngine.app.update,e.updateHZ)}}function destroy(){void 0!=idInterval&&clearInterval(idInterval),void 0!=KBEngine.app&&(KBEngine.app.uninstallEvents(),KBEngine.app.reset(),KBEngine.app=void 0)}var Class=function(){function e(){}return e}();KBEngine.Class=Class,__reflect(Class.prototype,"KBEngine.Class"),KBEngine.PACKET_MAX_SIZE=1500,KBEngine.PACKET_MAX_SIZE_TCP=1460,KBEngine.PACKET_MAX_SIZE_UDP=1472,KBEngine.MESSAGE_ID_LENGTH=2,KBEngine.MESSAGE_LENGTH_LENGTH=2,KBEngine.CLIENT_NO_FLOAT=0,KBEngine.KBE_FLT_MAX=3.402823466e38;var INT64=function(){function e(e,n){this.sign=1,this.lo=e,this.hi=n,n>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var n=this.lo.toString(16),t=this.hi.toString(16);if(this.hi>0){e+=t;for(var i=8-n.length;i>0;--i)e+="0"}return e+=n},e}();KBEngine.INT64=INT64,__reflect(INT64.prototype,"KBEngine.INT64");var UINT64=function(){function e(e,n){this.lo=e,this.hi=n}return e.prototype.toString=function(){var e=this.lo.toString(16),n=this.hi.toString(16),t="";if(this.hi>0){t+=n;for(var i=8-e.length;i>0;--i)t+="0"}return t+=e},e}();KBEngine.UINT64=UINT64,__reflect(UINT64.prototype,"KBEngine.UINT64"),KBEngine.INFO_MSG=INFO_MSG,KBEngine.DEBUG_MSG=DEBUG_MSG,KBEngine.ERROR_MSG=ERROR_MSG,KBEngine.WARNING_MSG=WARNING_MSG,KBEngine.utf8ArrayToString=utf8ArrayToString,KBEngine.stringToUTF8Bytes=stringToUTF8Bytes;var EventInfo=function(){function e(e,n){this.callbackfn=n,this.classinst=e}return e}();KBEngine.EventInfo=EventInfo,__reflect(EventInfo.prototype,"KBEngine.EventInfo");var Events=function(){function Events(){this._events={}}return Events.prototype.register=function(evtName,classinst,strCallback){var callbackfn=eval("classinst."+strCallback);if(void 0==callbackfn)return void ERROR_MSG("export class Event::fire: not found strCallback("+classinst+")!"+strCallback);var evtlst=this._events[evtName];void 0==evtlst&&(evtlst=[],this._events[evtName]=evtlst);var info=new EventInfo(classinst,callbackfn);evtlst.push(info)},Events.prototype.deregister=function(e,n){for(var t in this._events)for(var i=this._events[t];;){for(var r=!1,a=0;a=32768&&(e-=65536),e},e.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},e.prototype.readInt64=function(){return new INT64(this.readUint32(),this.readUint32())},e.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},e.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},e.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},e.prototype.readUint64=function(){return new UINT64(this.readUint32(),this.readUint32())},e.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(n){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},e.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(n){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},e.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),n=0,t="";;){if(0==e[n]){n++;break}if(t+=String.fromCharCode(e[n]),n++,this.rpos+n>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+n)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=n,t},e.prototype.readBlob=function(){var e=this.readUint32(),n=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,n},e.prototype.readStream=function(){var n=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new e(n)},e.prototype.readPackXZ=function(){var n=new e.PackFloatXType,t=new e.PackFloatXType;n.fv[0]=0,t.fv[0]=0,n.uv[0]=1073741824,t.uv[0]=1073741824;var i=this.readUint8(),r=this.readUint8(),a=this.readUint8(),p=0;p|=i<<16,p|=r<<8,p|=a,n.uv[0]|=(8384512&p)<<3,t.uv[0]|=(2047&p)<<15,n.fv[0]-=2,t.fv[0]-=2,n.uv[0]|=(8388608&p)<<8,t.uv[0]|=(2048&p)<<20;var o=new Array(2);return o[0]=n.fv[0],o[1]=t.fv[0],o},e.prototype.readPackY=function(){var e=this.readUint16();return e},e.prototype.writeInt8=function(e){var n=new Int8Array(this.buffer,this.wpos,1);n[0]=e,this.wpos+=1},e.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},e.prototype.writeInt32=function(e){for(var n=0;4>n;n++)this.writeInt8(e>>8*n&255)},e.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},e.prototype.writeUint8=function(e){var n=new Uint8Array(this.buffer,this.wpos,1);n[0]=e,this.wpos+=1},e.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},e.prototype.writeUint32=function(e){for(var n=0;4>n;n++)this.writeUint8(e>>8*n&255)},e.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},e.prototype.writeFloat=function(e){try{var n=new Float32Array(this.buffer,this.wpos,1);n[0]=e}catch(t){var n=new Float32Array(1);n[0]=e;var i=new Uint8Array(this.buffer),r=new Uint8Array(n.buffer);i.set(r,this.wpos)}this.wpos+=4},e.prototype.writeDouble=function(e){try{var n=new Float64Array(this.buffer,this.wpos,1);n[0]=e}catch(t){var n=new Float64Array(1);n[0]=e;var i=new Uint8Array(this.buffer),r=new Uint8Array(n.buffer);i.set(r,this.wpos)}this.wpos+=8},e.prototype.writeBlob=function(e){var n=e.length;if(n+4>this.space())return void ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var t=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof e)for(var i=0;n>i;i++)t[i]=e.charCodeAt(i);else for(var i=0;n>i;i++)t[i]=e[i];this.wpos+=n},e.prototype.writeString=function(e){if(e.length>this.space())return void ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),t=0,i=0;i>8&255)},e.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},e.prototype.send=function(e){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP)),this.messageLength+=e},e.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},e.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},e.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},e.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},e.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},e.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},e.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},e.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},e.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},e.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},e.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},e.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},e}();KBEngine.Bundle=Bundle,__reflect(Bundle.prototype,"KBEngine.Bundle"),KBEngine.reader=new MemoryStream(0),KBEngine.datatype2id={},KBEngine.mappingDataType=mappingDataType,mappingDataType(),KBEngine.bindWriter=bindWriter,KBEngine.bindReader=bindReader;var Message=function(){function e(e,n,t,i,r,a){this.id=e,this.name=n,this.length=t,this.argsType=i;for(var p=0;pe||e>255?!1:!0},DATATYPE_UINT8}();KBEngine.DATATYPE_UINT8=DATATYPE_UINT8,__reflect(DATATYPE_UINT8.prototype,"KBEngine.DATATYPE_UINT8");var DATATYPE_UINT16=function(){function DATATYPE_UINT16(){}return DATATYPE_UINT16.prototype.bind=function(){},DATATYPE_UINT16.prototype.createFromStream=function(e){return KBEngine.reader.readUint16.call(e)},DATATYPE_UINT16.prototype.addToStream=function(e,n){e.writeUint16(n)},DATATYPE_UINT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},DATATYPE_UINT16}();KBEngine.DATATYPE_UINT16=DATATYPE_UINT16,__reflect(DATATYPE_UINT16.prototype,"KBEngine.DATATYPE_UINT16");var DATATYPE_UINT32=function(){function DATATYPE_UINT32(){}return DATATYPE_UINT32.prototype.bind=function(){},DATATYPE_UINT32.prototype.createFromStream=function(e){return KBEngine.reader.readUint32.call(e)},DATATYPE_UINT32.prototype.addToStream=function(e,n){e.writeUint32(n)},DATATYPE_UINT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},DATATYPE_UINT32}();KBEngine.DATATYPE_UINT32=DATATYPE_UINT32,__reflect(DATATYPE_UINT32.prototype,"KBEngine.DATATYPE_UINT32");var DATATYPE_UINT64=function(){function DATATYPE_UINT64(){}return DATATYPE_UINT64.prototype.bind=function(){},DATATYPE_UINT64.prototype.createFromStream=function(e){return KBEngine.reader.readUint64.call(e)},DATATYPE_UINT64.prototype.addToStream=function(e,n){e.writeUint64(n)},DATATYPE_UINT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT64.prototype.isSameType=function(e){return e instanceof UINT64},DATATYPE_UINT64}();KBEngine.DATATYPE_UINT64=DATATYPE_UINT64,__reflect(DATATYPE_UINT64.prototype,"KBEngine.DATATYPE_UINT64");var DATATYPE_INT8=function(){function DATATYPE_INT8(){}return DATATYPE_INT8.prototype.bind=function(){},DATATYPE_INT8.prototype.createFromStream=function(e){return KBEngine.reader.readInt8.call(e)},DATATYPE_INT8.prototype.addToStream=function(e,n){e.writeInt8(n)},DATATYPE_INT8.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT8.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},DATATYPE_INT8}();KBEngine.DATATYPE_INT8=DATATYPE_INT8,__reflect(DATATYPE_INT8.prototype,"KBEngine.DATATYPE_INT8");var DATATYPE_INT16=function(){function DATATYPE_INT16(){}return DATATYPE_INT16.prototype.bind=function(){},DATATYPE_INT16.prototype.createFromStream=function(e){return KBEngine.reader.readInt16.call(e)},DATATYPE_INT16.prototype.addToStream=function(e,n){e.writeInt16(n)},DATATYPE_INT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},DATATYPE_INT16}();KBEngine.DATATYPE_INT16=DATATYPE_INT16,__reflect(DATATYPE_INT16.prototype,"KBEngine.DATATYPE_INT16");var DATATYPE_INT32=function(){function DATATYPE_INT32(){}return DATATYPE_INT32.prototype.bind=function(){},DATATYPE_INT32.prototype.createFromStream=function(e){return KBEngine.reader.readInt32.call(e)},DATATYPE_INT32.prototype.addToStream=function(e,n){e.writeInt32(n)},DATATYPE_INT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},DATATYPE_INT32}();KBEngine.DATATYPE_INT32=DATATYPE_INT32,__reflect(DATATYPE_INT32.prototype,"KBEngine.DATATYPE_INT32");var DATATYPE_INT64=function(){function DATATYPE_INT64(){}return DATATYPE_INT64.prototype.bind=function(){},DATATYPE_INT64.prototype.createFromStream=function(e){return KBEngine.reader.readInt64.call(e)},DATATYPE_INT64.prototype.addToStream=function(e,n){e.writeInt64(n)},DATATYPE_INT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT64.prototype.isSameType=function(e){return e instanceof INT64},DATATYPE_INT64}();KBEngine.DATATYPE_INT64=DATATYPE_INT64,__reflect(DATATYPE_INT64.prototype,"KBEngine.DATATYPE_INT64");var DATATYPE_FLOAT=function(){function DATATYPE_FLOAT(){}return DATATYPE_FLOAT.prototype.bind=function(){},DATATYPE_FLOAT.prototype.createFromStream=function(e){return KBEngine.reader.readFloat.call(e)},DATATYPE_FLOAT.prototype.addToStream=function(e,n){e.writeFloat(n)},DATATYPE_FLOAT.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_FLOAT.prototype.isSameType=function(e){return"number"==typeof e},DATATYPE_FLOAT}();KBEngine.DATATYPE_FLOAT=DATATYPE_FLOAT,__reflect(DATATYPE_FLOAT.prototype,"KBEngine.DATATYPE_FLOAT");var DATATYPE_DOUBLE=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.createFromStream=function(e){return KBEngine.reader.readDouble.call(e)},n.prototype.addToStream=function(e,n){e.writeDouble(n)},n}(DATATYPE_FLOAT);KBEngine.DATATYPE_DOUBLE=DATATYPE_DOUBLE,__reflect(DATATYPE_DOUBLE.prototype,"KBEngine.DATATYPE_DOUBLE");var DATATYPE_STRING=function(){function DATATYPE_STRING(){}return DATATYPE_STRING.prototype.bind=function(){},DATATYPE_STRING.prototype.createFromStream=function(e){return KBEngine.reader.readString.call(e)},DATATYPE_STRING.prototype.addToStream=function(e,n){e.writeString(n)},DATATYPE_STRING.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_STRING.prototype.isSameType=function(e){return"string"==typeof e},DATATYPE_STRING}();KBEngine.DATATYPE_STRING=DATATYPE_STRING,__reflect(DATATYPE_STRING.prototype,"KBEngine.DATATYPE_STRING");var DATATYPE_VECTOR2=function(){function DATATYPE_VECTOR2(){}return DATATYPE_VECTOR2.prototype.bind=function(){},DATATYPE_VECTOR2.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR2.prototype.addToStream=function(e,n){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y)):(e.writeFloat(n.x),e.writeFloat(n.y))},DATATYPE_VECTOR2.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR2.prototype.isSameType=function(e){return e instanceof Vector3?!0:!1},DATATYPE_VECTOR2}();KBEngine.DATATYPE_VECTOR2=DATATYPE_VECTOR2,__reflect(DATATYPE_VECTOR2.prototype,"KBEngine.DATATYPE_VECTOR2");var DATATYPE_VECTOR3=function(){function DATATYPE_VECTOR3(){}return DATATYPE_VECTOR3.prototype.bind=function(){},DATATYPE_VECTOR3.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR3.prototype.addToStream=function(e,n){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z))},DATATYPE_VECTOR3.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR3.prototype.isSameType=function(e){return e instanceof Vector3?!0:!1},DATATYPE_VECTOR3}();KBEngine.DATATYPE_VECTOR3=DATATYPE_VECTOR3,__reflect(DATATYPE_VECTOR3.prototype,"KBEngine.DATATYPE_VECTOR3");var DATATYPE_VECTOR4=function(){function DATATYPE_VECTOR4(){}return DATATYPE_VECTOR4.prototype.bind=function(){},DATATYPE_VECTOR4.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR4.prototype.addToStream=function(e,n){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z),e.writeInt32(n.w)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z),e.writeFloat(n.w))},DATATYPE_VECTOR4.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR4.prototype.isSameType=function(e){return e instanceof Vector3?!0:!1},DATATYPE_VECTOR4}();KBEngine.DATATYPE_VECTOR4=DATATYPE_VECTOR4,__reflect(DATATYPE_VECTOR4.prototype,"KBEngine.DATATYPE_VECTOR4");var DATATYPE_PYTHON=function(){function DATATYPE_PYTHON(){}return DATATYPE_PYTHON.prototype.bind=function(){},DATATYPE_PYTHON.prototype.createFromStream=function(e){},DATATYPE_PYTHON.prototype.addToStream=function(e,n){},DATATYPE_PYTHON.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_PYTHON.prototype.isSameType=function(e){return!1},DATATYPE_PYTHON}();KBEngine.DATATYPE_PYTHON=DATATYPE_PYTHON,__reflect(DATATYPE_PYTHON.prototype,"KBEngine.DATATYPE_PYTHON");var DATATYPE_UNICODE=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return utf8ArrayToString(KBEngine.reader.readBlob.call(e))},e.prototype.addToStream=function(e,n){e.writeBlob(stringToUTF8Bytes(n))},e.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},e.prototype.isSameType=function(e){return"string"==typeof e},e}();KBEngine.DATATYPE_UNICODE=DATATYPE_UNICODE,__reflect(DATATYPE_UNICODE.prototype,"KBEngine.DATATYPE_UNICODE");var DATATYPE_ENTITYCALL=function(){function DATATYPE_ENTITYCALL(){}return DATATYPE_ENTITYCALL.prototype.bind=function(){},DATATYPE_ENTITYCALL.prototype.createFromStream=function(e){},DATATYPE_ENTITYCALL.prototype.addToStream=function(e,n){},DATATYPE_ENTITYCALL.prototype.parseDefaultValStr=function(v){return eval(v) +},DATATYPE_ENTITYCALL.prototype.isSameType=function(e){return!1},DATATYPE_ENTITYCALL}();KBEngine.DATATYPE_ENTITYCALL=DATATYPE_ENTITYCALL,__reflect(DATATYPE_ENTITYCALL.prototype,"KBEngine.DATATYPE_ENTITYCALL");var DATATYPE_BLOB=function(){function DATATYPE_BLOB(){}return DATATYPE_BLOB.prototype.bind=function(){},DATATYPE_BLOB.prototype.createFromStream=function(e){var n=KBEngine.reader.readUint32.call(e),t=new Uint8Array(e.buffer,e.rpos,n);return e.rpos+=n,t},DATATYPE_BLOB.prototype.addToStream=function(e,n){e.writeBlob(n)},DATATYPE_BLOB.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_BLOB.prototype.isSameType=function(e){return!0},DATATYPE_BLOB}();KBEngine.DATATYPE_BLOB=DATATYPE_BLOB,__reflect(DATATYPE_BLOB.prototype,"KBEngine.DATATYPE_BLOB");var DATATYPE_ARRAY=function(){function DATATYPE_ARRAY(){this.type=null}return DATATYPE_ARRAY.prototype.bind=function(){"number"==typeof this.type&&(this.type=datatypes[this.type])},DATATYPE_ARRAY.prototype.createFromStream=function(e){for(var n=e.readUint32(),t=[];n>0;)n--,t.push(this.type.createFromStream(e));return t},DATATYPE_ARRAY.prototype.addToStream=function(e,n){e.writeUint32(n.length);for(var t=0;tKBEngine.app.args.serverHeartbeatTick){if(KBEngine.app.lastTickCBTime0;){n-=1;var t=new ServerErr;t.id=e.readUint16(),t.name=utf8ArrayToString(e.readBlob()),t.descr=utf8ArrayToString(e.readBlob()),KBEngine.app.serverErrs[t.id]=t,INFO_MSG("Client_onImportServerErrorsDescr: id="+t.id+", name="+t.name+", descr="+t.descr)}},KBEngineApp.prototype.onOpenLoginapp_login=function(){if(INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),KBEngine.Event.fire("onConnectionState",!0),KBEngine.app.currserver="loginapp",KBEngine.app.currstate="login",KBEngine.app.loginappMessageImported)KBEngine.app.onImportClientMessagesCompleted();else{var e=new Bundle;e.newMessage(messages.Loginapp_importClientMessages),e.send(KBEngine.app),KBEngine.app.socket.onmessage=KBEngine.app.Client_onImportClientMessages,INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),KBEngine.Event.fire("Loginapp_importClientMessages")}},KBEngineApp.prototype.onOpenLoginapp_createAccount=function(){if(KBEngine.Event.fire("onConnectionState",!0),INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),KBEngine.app.currserver="loginapp",KBEngine.app.currstate="createAccount",KBEngine.app.loginappMessageImported)KBEngine.app.onImportClientMessagesCompleted();else{var e=new Bundle;e.newMessage(messages.Loginapp_importClientMessages),e.send(KBEngine.app),KBEngine.app.socket.onmessage=KBEngine.app.Client_onImportClientMessages,INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),KBEngine.Event.fire("Loginapp_importClientMessages")}},KBEngineApp.prototype.onImportClientMessagesCompleted=function(){if(INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),KBEngine.app.socket.onmessage=KBEngine.app.onmessage,KBEngine.app.hello(),"loginapp"==KBEngine.app.currserver){if(!KBEngine.app.serverErrorsDescrImported){INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),KBEngine.app.serverErrorsDescrImported=!0;var e=new Bundle;e.newMessage(messages.Loginapp_importServerErrorsDescr),e.send(KBEngine.app)}"login"==KBEngine.app.currstate?KBEngine.app.login_loginapp(!1):"resetpassword"==KBEngine.app.currstate?KBEngine.app.resetpassword_loginapp(!1):KBEngine.app.createAccount_loginapp(!1),KBEngine.app.loginappMessageImported=!0}else if(KBEngine.app.baseappMessageImported=!0,KBEngine.app.entitydefImported)KBEngine.app.onImportEntityDefCompleted();else{INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var e=new Bundle;e.newMessage(messages.Baseapp_importClientEntityDef),e.send(KBEngine.app),KBEngine.Event.fire("Baseapp_importClientEntityDef")}},KBEngineApp.prototype.createDataTypeFromStreams=function(e,n){var t=e.readUint16();for(INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+t+")!");t>0;)t--,KBEngine.app.createDataTypeFromStream(e,n);for(var i in datatypes)void 0!=datatypes[i]&&datatypes[i].bind()},KBEngineApp.prototype.createDataTypeFromStream=function(e,n){var t,i=e.readUint16(),r=e.readString(),a=e.readString();if(0==a.length&&(t="Null_"+i),n&&INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+r+":"+a+")!"),"FIXED_DICT"==r){var p=new DATATYPE_FIXED_DICT,o=e.readUint8();for(p.implementedBy=e.readString();o>0;){o--;var s=e.readString(),E=e.readUint16();p.dicttype[s]=E}datatypes[a]=p}else if("ARRAY"==r){var g=e.readUint16(),p=new DATATYPE_ARRAY;p.type=g,datatypes[a]=p}else datatypes[a]=datatypes[r];datatypes[i]=datatypes[a],KBEngine.datatype2id[a]=i},KBEngineApp.prototype.Client_onImportClientEntityDef=function(stream){for(KBEngine.app.createDataTypeFromStreams(stream,!0);!stream.readEOF();){var scriptmodule_name=stream.readString(),scriptUtype=stream.readUint16(),propertysize=stream.readUint16(),methodsize=stream.readUint16(),base_methodsize=stream.readUint16(),cell_methodsize=stream.readUint16();INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+scriptmodule_name+"), propertys("+propertysize+"), clientMethods("+methodsize+"), baseMethods("+base_methodsize+"), cellMethods("+cell_methodsize+")!"),KBEngine.moduledefs[scriptmodule_name]={};var currModuleDefs=KBEngine.moduledefs[scriptmodule_name];currModuleDefs.name=scriptmodule_name,currModuleDefs.propertys={},currModuleDefs.methods={},currModuleDefs.base_methods={},currModuleDefs.cell_methods={},KBEngine.moduledefs[scriptUtype]=currModuleDefs;var self_propertys=currModuleDefs.propertys,self_methods=currModuleDefs.methods,self_base_methods=currModuleDefs.base_methods,self_cell_methods=currModuleDefs.cell_methods;try{var Class_1=eval(""+scriptmodule_name)}catch(e){var Class_2=void 0}for(;propertysize>0;){propertysize--;var properUtype=stream.readUint16(),properFlags=stream.readUint32(),aliasID=stream.readInt16(),name_2=stream.readString(),defaultValStr=stream.readString(),utype=datatypes[stream.readUint16()],setmethod=null;void 0!=Class&&(setmethod=Class.prototype["set_"+name_2],void 0==setmethod&&(setmethod=null));var savedata=[properUtype,aliasID,name_2,defaultValStr,utype,setmethod,properFlags];self_propertys[name_2]=savedata,-1!=aliasID?(self_propertys[aliasID]=savedata,currModuleDefs.usePropertyDescrAlias=!0):(self_propertys[properUtype]=savedata,currModuleDefs.usePropertyDescrAlias=!1),INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+scriptmodule_name+"), property("+name_2+"/"+properUtype+").")}for(;methodsize>0;){methodsize--;for(var methodUtype=stream.readUint16(),aliasID=stream.readInt16(),name_3=stream.readString(),argssize=stream.readUint8(),args=[];argssize>0;)argssize--,args.push(datatypes[stream.readUint16()]);var savedata=[methodUtype,aliasID,name_3,args];self_methods[name_3]=savedata,-1!=aliasID?(self_methods[aliasID]=savedata,currModuleDefs.useMethodDescrAlias=!0):(self_methods[methodUtype]=savedata,currModuleDefs.useMethodDescrAlias=!1),INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+scriptmodule_name+"), method("+name_3+").")}for(;base_methodsize>0;){base_methodsize--;for(var methodUtype=stream.readUint16(),aliasID=stream.readInt16(),name_4=stream.readString(),argssize=stream.readUint8(),args=[];argssize>0;)argssize--,args.push(datatypes[stream.readUint16()]);self_base_methods[name_4]=[methodUtype,aliasID,name_4,args],INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+scriptmodule_name+"), base_method("+name_4+").")}for(;cell_methodsize>0;){cell_methodsize--;for(var methodUtype=stream.readUint16(),aliasID=stream.readInt16(),name_5=stream.readString(),argssize=stream.readUint8(),args=[];argssize>0;)argssize--,args.push(datatypes[stream.readUint16()]);self_cell_methods[name_5]=[methodUtype,aliasID,name_5,args],INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+scriptmodule_name+"), cell_method("+name_5+").")}var defmethod=void 0;try{defmethod=eval(""+scriptmodule_name)}catch(e){ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+scriptmodule_name+") not found!"),defmethod=void 0}for(var name_6 in currModuleDefs.propertys){var infos=currModuleDefs.propertys[name_6],properUtype=infos[0],aliasID=infos[1],n=infos[2],defaultValStr=infos[3],utype=infos[4];void 0!=defmethod&&(defmethod.prototype[n]=utype.parseDefaultValStr(defaultValStr))}for(var name_7 in currModuleDefs.methods){var infos=currModuleDefs.methods[name_7],properUtype=infos[0],aliasID=infos[1],n=infos[2],args=infos[3];void 0!=defmethod&&void 0==defmethod.prototype[n]&&WARNING_MSG(scriptmodule_name+":: method("+n+") no implement!")}}KBEngine.app.onImportEntityDefCompleted()},KBEngineApp.prototype.Client_onVersionNotMatch=function(e){KBEngine.app.serverVersion=e.readString(),ERROR_MSG("Client_onVersionNotMatch: verInfo="+KBEngine.app.clientVersion+" not match(server: "+KBEngine.app.serverVersion+")"),KBEngine.Event.fire("onVersionNotMatch",KBEngine.app.clientVersion,KBEngine.app.serverVersion)},KBEngineApp.prototype.Client_onScriptVersionNotMatch=function(e){KBEngine.app.serverScriptVersion=e.readString(),ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+KBEngine.app.clientScriptVersion+" not match(server: "+KBEngine.app.serverScriptVersion+")"),KBEngine.Event.fire("onScriptVersionNotMatch",KBEngine.app.clientScriptVersion,KBEngine.app.serverScriptVersion)},KBEngineApp.prototype.onImportEntityDefCompleted=function(){INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),KBEngine.app.entitydefImported=!0,KBEngine.app.login_baseapp(!1)},KBEngineApp.prototype.Client_onImportClientMessages=function(e){var n=new MemoryStream(e.data),t=n.readUint16();if(t==messages.onImportClientMessages.id){var i=n.readUint16(),r=n.readUint16();for(INFO_MSG("KBEngineApp::onImportClientMessages: start("+r+") ...!");r>0;){r--,t=n.readUint16(),i=n.readInt16();for(var a=n.readString(),p=n.readInt8(),o=n.readUint8(),s=new Array(o),E=0;o>E;E++)s[E]=n.readUint8();var g=null,l=a.indexOf("Client_")>=0;l&&(g=KBEngine.app[a],null==g||void 0==g?(WARNING_MSG("KBEngineApp::onImportClientMessages["+KBEngine.app.currserver+"]: interface("+a+"/"+t+") no implement!"),g=null):INFO_MSG("KBEngineApp::onImportClientMessages: import("+a+") successfully!")),a.length>0?(messages[a]=new Message(t,a,i,p,s,g),l?KBEngine.clientmessages[t]=messages[a]:messages[KBEngine.app.currserver][t]=messages[a]):messages[KBEngine.app.currserver][t]=new Message(t,a,i,p,s,g)}KBEngine.app.onImportClientMessagesCompleted()}else ERROR_MSG("KBEngineApp::onmessage: not found msg("+t+")!")},KBEngineApp.prototype.createAccount=function(e,n,t){KBEngine.app.reset(),KBEngine.app.username=e,KBEngine.app.password=n,KBEngine.app.clientdatas=t,KBEngine.app.createAccount_loginapp(!0)},KBEngineApp.prototype.createAccount_loginapp=function(e){if(e)INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+KBEngine.app.ip+":"+KBEngine.app.port+"!"),KBEngine.app.connect("ws://"+KBEngine.app.ip+":"+KBEngine.app.port),KBEngine.app.socket.onopen=KBEngine.app.onOpenLoginapp_createAccount;else{var n=new Bundle;n.newMessage(messages.Loginapp_reqCreateAccount),n.writeString(KBEngine.app.username),n.writeString(KBEngine.app.password),n.writeBlob(KBEngine.app.clientdatas),n.send(KBEngine.app)}},KBEngineApp.prototype.bindAccountEmail=function(e){var n=new Bundle;n.newMessage(messages.Baseapp_reqAccountBindEmail),n.writeInt32(KBEngine.app.entity_id),n.writeString(KBEngine.app.password),n.writeString(e),n.send(KBEngine.app)},KBEngineApp.prototype.newPassword=function(e,n){var t=new Bundle;t.newMessage(messages.Baseapp_reqAccountNewPassword),t.writeInt32(KBEngine.app.entity_id),t.writeString(e),t.writeString(n),t.send(KBEngine.app)},KBEngineApp.prototype.login=function(e,n,t){KBEngine.app.reset(),KBEngine.app.username=e,KBEngine.app.password=n,KBEngine.app.clientdatas=t,KBEngine.app.login_loginapp(!0)},KBEngineApp.prototype.login_loginapp=function(e){if(e)INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+KBEngine.app.ip+":"+KBEngine.app.port+"!"),KBEngine.app.connect("ws://"+KBEngine.app.ip+":"+KBEngine.app.port),KBEngine.app.socket.onopen=KBEngine.app.onOpenLoginapp_login;else{var n=new Bundle;n.newMessage(messages.Loginapp_login),n.writeInt8(KBEngine.app.args.clientType),n.writeBlob(KBEngine.app.clientdatas),n.writeString(KBEngine.app.username),n.writeString(KBEngine.app.password),n.send(KBEngine.app)}},KBEngineApp.prototype.onOpenLoginapp_resetpassword=function(){if(INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),KBEngine.app.currserver="loginapp",KBEngine.app.currstate="resetpassword",KBEngine.app.loginappMessageImported)KBEngine.app.onImportClientMessagesCompleted();else{var e=new Bundle;e.newMessage(messages.Loginapp_importClientMessages),e.send(KBEngine.app),KBEngine.app.socket.onmessage=KBEngine.app.Client_onImportClientMessages,INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},KBEngineApp.prototype.reset_password=function(e){KBEngine.app.reset(),KBEngine.app.username=e,KBEngine.app.resetpassword_loginapp(!0)},KBEngineApp.prototype.resetpassword_loginapp=function(e){if(e)INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+KBEngine.app.ip+":"+KBEngine.app.port+"!"),KBEngine.app.connect("ws://"+KBEngine.app.ip+":"+KBEngine.app.port),KBEngine.app.socket.onopen=KBEngine.app.onOpenLoginapp_resetpassword;else{var n=new Bundle;n.newMessage(messages.Loginapp_reqAccountResetPassword),n.writeString(KBEngine.app.username),n.send(KBEngine.app)}},KBEngineApp.prototype.onOpenBaseapp=function(){if(INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),KBEngine.app.currserver="baseapp",KBEngine.app.baseappMessageImported)KBEngine.app.onImportClientMessagesCompleted();else{var e=new Bundle;e.newMessage(messages.Baseapp_importClientMessages),e.send(KBEngine.app),KBEngine.app.socket.onmessage=KBEngine.app.Client_onImportClientMessages,KBEngine.Event.fire("Baseapp_importClientMessages")}},KBEngineApp.prototype.login_baseapp=function(e){if(e)KBEngine.Event.fire("onLoginBaseapp"),INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+KBEngine.app.baseappIp+":"+KBEngine.app.baseappPort+"!"),KBEngine.app.connect("ws://"+KBEngine.app.baseappIp+":"+KBEngine.app.baseappPort),void 0!=KBEngine.app.socket&&null!=KBEngine.app.socket&&(KBEngine.app.socket.onopen=KBEngine.app.onOpenBaseapp);else{var n=new Bundle;n.newMessage(messages.Baseapp_loginBaseapp),n.writeString(KBEngine.app.username),n.writeString(KBEngine.app.password),n.send(KBEngine.app)}},KBEngineApp.prototype.reloginBaseapp=function(){(void 0==KBEngine.app.socket||null==KBEngine.app.socket)&&(KBEngine.app.resetSocket(),KBEngine.Event.fire("onReloginBaseapp"),INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+KBEngine.app.baseappIp+":"+KBEngine.app.baseappPort+"!"),KBEngine.app.connect("ws://"+KBEngine.app.baseappIp+":"+KBEngine.app.baseappPort),void 0!=KBEngine.app.socket&&null!=KBEngine.app.socket&&(KBEngine.app.socket.onopen=KBEngine.app.onReOpenBaseapp))},KBEngineApp.prototype.onReOpenBaseapp=function(){INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),KBEngine.app.currserver="baseapp";var e=new Bundle;e.newMessage(messages.Baseapp_reloginBaseapp),e.writeString(KBEngine.app.username),e.writeString(KBEngine.app.password),e.writeUint64(KBEngine.app.entity_uuid),e.writeInt32(KBEngine.app.entity_id),e.send(KBEngine.app);var n=new Date;KBEngine.app.lastTickCBTime=n.getTime()},KBEngineApp.prototype.Client_onHelloCB=function(e){KBEngine.app.serverVersion=e.readString(),KBEngine.app.serverScriptVersion=e.readString(),KBEngine.app.serverProtocolMD5=e.readString(),KBEngine.app.serverEntityDefMD5=e.readString();var n=e.readInt32();INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+KBEngine.app.serverVersion+"), scriptVerInfo("+KBEngine.app.serverScriptVersion+"), serverProtocolMD5("+KBEngine.app.serverProtocolMD5+"), serverEntityDefMD5("+KBEngine.app.serverEntityDefMD5+"), ctype("+n+")!");var t=new Date;KBEngine.app.lastTickCBTime=t.getTime()},KBEngineApp.prototype.Client_onLoginFailed=function(e){var n=e.readUint16();KBEngine.app.serverdatas=e.readBlob(),ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+KBEngine.app.serverErrs[n].name+"), datas("+KBEngine.app.serverdatas.length+")!"),KBEngine.Event.fire("onLoginFailed",n)},KBEngineApp.prototype.Client_onLoginSuccessfully=function(e){var n=e.readString();KBEngine.app.username=n,KBEngine.app.baseappIp=e.readString(),KBEngine.app.baseappPort=e.readUint16(),KBEngine.app.serverdatas=e.readBlob(),INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+KBEngine.app.baseappIp+":"+KBEngine.app.baseappPort+"), datas("+KBEngine.app.serverdatas.length+")!"),KBEngine.app.disconnect(),KBEngine.app.login_baseapp(!0)},KBEngineApp.prototype.Client_onLoginBaseappFailed=function(e){ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+KBEngine.app.serverErrs[e].name+")!"),KBEngine.Event.fire("onLoginBaseappFailed",e)},KBEngineApp.prototype.Client_onReloginBaseappFailed=function(e){ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+KBEngine.app.serverErrs[e].name+")!"),KBEngine.Event.fire("onReloginBaseappFailed",e)},KBEngineApp.prototype.Client_onReloginBaseappSuccessfully=function(e){KBEngine.app.entity_uuid=e.readUint64(),DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+KBEngine.app.username),KBEngine.Event.fire("onReloginBaseappSuccessfully")},KBEngineApp.prototype.getentityclass=function(entityType){var runclass=KBEngine.app.entityclass[entityType];if(void 0==runclass){if(runclass=eval(""+entityType),void 0==runclass)return ERROR_MSG("KBEngineApp::getentityclass: entityType("+entityType+") is error!"),runclass;KBEngine.app.entityclass[entityType]=runclass}return runclass},KBEngineApp.prototype.Client_onCreatedProxies=function(e,n,t){INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+t+")!");var i=KBEngine.app.entities[n];if(KBEngine.app.entity_uuid=e,KBEngine.app.entity_id=n,void 0==i){var r=KBEngine.app.getentityclass(t);if(void 0==r)return;var a=new r;a.id=n,a.className=t,a.base=new EntityCall,a.base.id=n,a.base.className=t,a.base.type=KBEngine.ENTITYCALL_TYPE_BASE,KBEngine.app.entities[n]=a;var p=KBEngine.bufferedCreateEntityMessage[n];void 0!=p&&(KBEngine.app.Client_onUpdatePropertys(p),delete KBEngine.bufferedCreateEntityMessage[n]),a.__init__(),a.inited=!0,KBEngine.app.args.isOnInitCallPropertysSetMethods&&a.callPropertysSetMethods()}else{var p=KBEngine.bufferedCreateEntityMessage[n];void 0!=p&&(KBEngine.app.Client_onUpdatePropertys(p),delete KBEngine.bufferedCreateEntityMessage[n])}},KBEngineApp.prototype.getViewEntityIDFromStream=function(e){var n=0;if(KBEngine.app.entityIDAliasIDList.length>255)n=e.readInt32();else{var t=e.readUint8();if(KBEngine.app.entityIDAliasIDList.length<=t)return 0;n=KBEngine.app.entityIDAliasIDList[t]}return n},KBEngineApp.prototype.onUpdatePropertys_=function(e,n){var t=KBEngine.app.entities[e];if(void 0==t){var i=KBEngine.bufferedCreateEntityMessage[e];if(void 0!=i)return void ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+e+") not found!");var r=new MemoryStream(n.buffer);return r.wpos=n.wpos,r.rpos=n.rpos-4,void(KBEngine.bufferedCreateEntityMessage[e]=r)}for(var a=KBEngine.moduledefs[t.className],p=a.propertys;n.length()>0;){var o=0;o=a.usePropertyDescrAlias?n.readUint8():n.readUint16();var s=p[o],E=s[5],g=s[6],l=s[4].createFromStream(n),d=t[s[2]];INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+t.className+"(id="+e+" "+s[2]+", val="+l+")!"),t[s[2]]=l,null!=E&&(32==g||64==g?t.inited&&E.call(t,d):t.inWorld&&E.call(t,d))}},KBEngineApp.prototype.Client_onUpdatePropertysOptimized=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e);KBEngine.app.onUpdatePropertys_(n,e)},KBEngineApp.prototype.Client_onUpdatePropertys=function(e){var n=e.readInt32();KBEngine.app.onUpdatePropertys_(n,e)},KBEngineApp.prototype.onRemoteMethodCall_=function(e,n){var t=KBEngine.app.entities[e];if(void 0==t)return void ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+e+") not found!");var i=0;i=KBEngine.moduledefs[t.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var r=KBEngine.moduledefs[t.className].methods[i],a=[],p=r[3],o=0;o0&&n!=KBEngine.app.entity_id&&KBEngine.app.entityIDAliasIDList.push(n);var t;t=KBEngine.moduledefs.Length>255?e.readUint16():e.readUint8();var i=!0;e.length()>0&&(i=e.readInt8()),t=KBEngine.moduledefs[t].name,INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+t+"("+n+"), spaceID("+KBEngine.app.spaceID+"), isOnGround("+i+")!");var r=KBEngine.app.entities[n];if(void 0==r){var a=KBEngine.bufferedCreateEntityMessage[n];if(void 0==a)return void ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=KBEngine.app.getentityclass(t);if(void 0==p)return;var o=new p;o.id=n,o.className=t,o.cell=new EntityCall,o.cell.id=n,o.cell.className=t,o.cell.type=KBEngine.ENTITYCALL_TYPE_CELL,KBEngine.app.entities[n]=o,KBEngine.app.Client_onUpdatePropertys(a),delete KBEngine.bufferedCreateEntityMessage[n],o.isOnGround=i,o.__init__(),o.inited=!0,o.inWorld=!0,o.enterWorld(),KBEngine.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods(),o.set_direction(o.direction),o.set_position(o.position)}else r.inWorld||(r.cell=new EntityCall,r.cell.id=n,r.cell.className=t,r.cell.type=KBEngine.ENTITYCALL_TYPE_CELL,KBEngine.app.entityIDAliasIDList=[],KBEngine.app.entities={},KBEngine.app.entities[r.id]=r,r.set_direction(r.direction),r.set_position(r.position),KBEngine.app.entityServerPos.x=r.position.x,KBEngine.app.entityServerPos.y=r.position.y,KBEngine.app.entityServerPos.z=r.position.z,r.isOnGround=i,r.inWorld=!0,r.enterWorld(),KBEngine.app.args.isOnInitCallPropertysSetMethods&&r.callPropertysSetMethods())},KBEngineApp.prototype.Client_onEntityLeaveWorldOptimized=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e);KBEngine.app.Client_onEntityLeaveWorld(n)},KBEngineApp.prototype.Client_onEntityLeaveWorld=function(e){var n=KBEngine.app.entities[e];if(void 0==n)return void ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+e+") not found!");if(n.inWorld&&n.leaveWorld(),KBEngine.app.entity_id>0&&e!=KBEngine.app.entity_id){for(var t=[],i=0;i0&&(t=e.readInt8());var i=KBEngine.app.entities[n];return void 0==i?void ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(i.isOnGround=t,KBEngine.app.entityServerPos.x=i.position.x,KBEngine.app.entityServerPos.y=i.position.y,KBEngine.app.entityServerPos.z=i.position.z,void i.enterSpace())},KBEngineApp.prototype.Client_onEntityLeaveSpace=function(e){var n=KBEngine.app.entities[e];return void 0==n?void ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+e+") not found!"):(KBEngine.app.clearSpace(!1),void n.leaveSpace())},KBEngineApp.prototype.Client_onKicked=function(e){ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+KBEngine.app.serverErrs[e].name+")!"),KBEngine.Event.fire("onKicked",e)},KBEngineApp.prototype.Client_onCreateAccountResult=function(e){var n=e.readUint16(),t=e.readBlob();return KBEngine.Event.fire("onCreateAccountResult",n,t),0!=n?void ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+KBEngine.app.username+" create is failed! code="+KBEngine.app.serverErrs[n].name+"!"):void INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+KBEngine.app.username+" create is successfully!")},KBEngineApp.prototype.Client_onControlEntity=function(e,n){var t=KBEngine.app.entities[e];if(void 0==t)return void ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+e+") not found!");var i=0!=n;if(i)KBEngine.app.player().id!=t.id&&KBEngine.app.controlledEntities.push(t);else{for(var r=[],a=0;a.001||e.entityLastLocalDir.distance(e.direction)>.001){e.entityLastLocalPos.x=e.position.x,e.entityLastLocalPos.y=e.position.y,e.entityLastLocalPos.z=e.position.z,e.entityLastLocalDir.x=e.direction.x,e.entityLastLocalDir.y=e.direction.y,e.entityLastLocalDir.z=e.direction.z;var n=new Bundle;n.newMessage(messages.Baseapp_onUpdateDataFromClient),n.writeFloat(e.position.x),n.writeFloat(e.position.y),n.writeFloat(e.position.z),n.writeFloat(e.direction.x),n.writeFloat(e.direction.y),n.writeFloat(e.direction.z),n.writeUint8(e.isOnGround),n.writeUint32(KBEngine.app.spaceID),n.send(KBEngine.app)}for(var t in KBEngine.app.controlledEntities){var i=KBEngine.app.controlledEntities[t],r=i.position,a=i.direction,p=i.entityLastLocalPos.distance(r)>.001,o=i.entityLastLocalDir.distance(a)>.001;if(p||o){i.entityLastLocalPos=r,i.entityLastLocalDir=a;var n=new Bundle;n.newMessage(messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(i.id),n.writeFloat(r.x),n.writeFloat(r.y),n.writeFloat(r.z),n.writeFloat(a.x),n.writeFloat(a.y),n.writeFloat(a.z),n.writeUint8(i.isOnGround),n.writeUint32(KBEngine.app.spaceID),n.send(KBEngine.app)}}}},KBEngineApp.prototype.addSpaceGeometryMapping=function(e,n){INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+e+"), respath("+n+")!"),KBEngine.app.spaceID=e,KBEngine.app.spaceResPath=n,KBEngine.Event.fire("addSpaceGeometryMapping",n)},KBEngineApp.prototype.clearSpace=function(e){KBEngine.app.entityIDAliasIDList=[],KBEngine.app.spacedata={},KBEngine.app.clearEntities(e),KBEngine.app.isLoadedGeometry=!1,KBEngine.app.spaceID=0},KBEngineApp.prototype.clearEntities=function(e){if(KBEngine.app.controlledEntities=[],e){for(var n in KBEngine.app.entities)KBEngine.app.entities[n].inWorld&&KBEngine.app.entities[n].leaveWorld(),KBEngine.app.entities[n].onDestroy();KBEngine.app.entities={}}else{var t=KBEngine.app.player();for(var n in KBEngine.app.entities)n!=t.id&&(KBEngine.app.entities[n].inWorld&&KBEngine.app.entities[n].leaveWorld(),KBEngine.app.entities[n].onDestroy());KBEngine.app.entities={},KBEngine.app.entities[t.id]=t}},KBEngineApp.prototype.Client_initSpaceData=function(e){for(KBEngine.app.clearSpace(!1),KBEngine.app.spaceID=e.readInt32();e.length()>0;){var n=e.readString(),t=e.readString();KBEngine.app.Client_setSpaceData(KBEngine.app.spaceID,n,t)}INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+KBEngine.app.spaceID+"), datas("+KBEngine.app.spacedata+")!")},KBEngineApp.prototype.Client_setSpaceData=function(e,n,t){INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+e+"), key("+n+"), value("+t+")!"),KBEngine.app.spacedata[n]=t,"_mapping"==n&&KBEngine.app.addSpaceGeometryMapping(e,t),KBEngine.Event.fire("onSetSpaceData",e,n,t)},KBEngineApp.prototype.Client_delSpaceData=function(e,n){INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+e+"), key("+n+")!"),delete KBEngine.app.spacedata[n],KBEngine.Event.fire("onDelSpaceData",e,n)},KBEngineApp.prototype.Client_getSpaceData=function(e,n){return KBEngine.app.spacedata[n]},KBEngineApp.prototype.Client_onUpdateBasePos=function(e,n,t){KBEngine.app.entityServerPos.x=e,KBEngine.app.entityServerPos.y=n,KBEngine.app.entityServerPos.z=t},KBEngineApp.prototype.Client_onUpdateBasePosXZ=function(e,n){KBEngine.app.entityServerPos.x=e,KBEngine.app.entityServerPos.z=n},KBEngineApp.prototype.Client_onUpdateData=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=KBEngine.app.entities[n];return void 0==t?void ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},KBEngineApp.prototype.Client_onSetEntityPosAndDir=function(e){var n=e.readInt32(),t=KBEngine.app.entities[n];return void 0==t?void ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(t.position.x=e.readFloat(),t.position.y=e.readFloat(),t.position.z=e.readFloat(),t.direction.x=e.readFloat(),t.direction.y=e.readFloat(),t.direction.z=e.readFloat(),t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z,t.set_direction(t.direction),void t.set_position(t.position))},KBEngineApp.prototype.Client_onUpdateData_ypr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8(),i=e.readInt8(),r=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,i,r,-1)},KBEngineApp.prototype.Client_onUpdateData_yp=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8(),i=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,i,KBEngine.KBE_FLT_MAX,-1)},KBEngineApp.prototype.Client_onUpdateData_yr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8(),i=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,KBEngine.KBE_FLT_MAX,i,-1)},KBEngineApp.prototype.Client_onUpdateData_pr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8(),i=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,i,-1)},KBEngineApp.prototype.Client_onUpdateData_y=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,-1)},KBEngineApp.prototype.Client_onUpdateData_p=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,KBEngine.KBE_FLT_MAX,-1)},KBEngineApp.prototype.Client_onUpdateData_r=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,-1)},KBEngineApp.prototype.Client_onUpdateData_xz=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,1)},KBEngineApp.prototype.Client_onUpdateData_xz_ypr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8(),r=e.readInt8(),a=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],i,r,a,1)},KBEngineApp.prototype.Client_onUpdateData_xz_yp=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8(),r=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],i,r,KBEngine.KBE_FLT_MAX,1)},KBEngineApp.prototype.Client_onUpdateData_xz_yr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8(),r=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],i,KBEngine.KBE_FLT_MAX,r,1)},KBEngineApp.prototype.Client_onUpdateData_xz_pr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8(),r=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],KBEngine.KBE_FLT_MAX,i,r,1)},KBEngineApp.prototype.Client_onUpdateData_xz_y=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],i,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,1)},KBEngineApp.prototype.Client_onUpdateData_xz_p=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],KBEngine.KBE_FLT_MAX,i,KBEngine.KBE_FLT_MAX,1)},KBEngineApp.prototype.Client_onUpdateData_xz_r=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,i,1)},KBEngineApp.prototype.Client_onUpdateData_xyz=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY();KBEngine.app._updateVolatileData(n,t[0],i,t[1],KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_ypr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8(),a=e.readInt8(),p=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],r,a,p,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_yp=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8(),a=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],r,a,KBEngine.KBE_FLT_MAX,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_yr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8(),a=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],r,KBEngine.KBE_FLT_MAX,a,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_pr=function(e){KBEngine.app.getViewEntityIDFromStream(e),e.readPackXZ(),e.readPackY(),e.readInt8(),e.readInt8();ERROR_MSG("调用错误方法,无法找到x,z")},KBEngineApp.prototype.Client_onUpdateData_xyz_y=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],r,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_p=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],KBEngine.KBE_FLT_MAX,r,KBEngine.KBE_FLT_MAX,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_r=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8();e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],r,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,0)},KBEngineApp.prototype._updateVolatileData=function(e,n,t,i,r,a,p,o){var s=KBEngine.app.entities[e];if(void 0==s)return void ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+e+") not found!");o>=0&&(s.isOnGround=o>0);var E=!1;p!=KBEngine.KBE_FLT_MAX&&(E=!0,s.direction.x=int82angle(p,!1)),a!=KBEngine.KBE_FLT_MAX&&(E=!0,s.direction.y=int82angle(a,!1)),r!=KBEngine.KBE_FLT_MAX&&(E=!0,s.direction.z=int82angle(r,!1));var g=!1;1==E&&(KBEngine.Event.fire("set_direction",s),g=!0);var l=!1;(n!=KBEngine.KBE_FLT_MAX||t!=KBEngine.KBE_FLT_MAX||i!=KBEngine.KBE_FLT_MAX)&&(l=!0),n==KBEngine.KBE_FLT_MAX&&(n=0),t==KBEngine.KBE_FLT_MAX&&(t=0),i==KBEngine.KBE_FLT_MAX&&(i=0),l&&(s.position.x=n+KBEngine.app.entityServerPos.x,s.position.y=t+KBEngine.app.entityServerPos.y,s.position.z=i+KBEngine.app.entityServerPos.z,g=!0,KBEngine.Event.fire("updatePosition",s)),g&&s.onUpdateVolatileData()},KBEngineApp.prototype.Client_onStreamDataStarted=function(e,n,t){KBEngine.Event.fire("onStreamDataStarted",e,n,t)},KBEngineApp.prototype.Client_onStreamDataRecv=function(e){var n=e.readUint16(),t=e.readBlob();KBEngine.Event.fire("onStreamDataRecv",n,t)},KBEngineApp.prototype.Client_onStreamDataCompleted=function(e){KBEngine.Event.fire("onStreamDataCompleted",e)},KBEngineApp.prototype.Client_onReqAccountResetPasswordCB=function(e){return 0!=e?void ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+KBEngine.app.username+" is failed! code="+KBEngine.app.serverErrs[e].name+"!"):void INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+KBEngine.app.username+" is successfully!")},KBEngineApp.prototype.Client_onReqAccountBindEmailCB=function(e){return 0!=e?void ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+KBEngine.app.username+" is failed! code="+KBEngine.app.serverErrs[e].name+"!"):void INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+KBEngine.app.username+" is successfully!")},KBEngineApp.prototype.Client_onReqAccountNewPasswordCB=function(e){return 0!=e?void ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+KBEngine.app.username+" is failed! code="+KBEngine.app.serverErrs[e].name+"!"):void INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+KBEngine.app.username+" is successfully!")},KBEngineApp}();KBEngine.KBEngineApp=KBEngineApp,__reflect(KBEngineApp.prototype,"KBEngine.KBEngineApp");var ServerErr=function(){function e(){this.name="",this.descr="",this.id=0}return e}();KBEngine.ServerErr=ServerErr,__reflect(ServerErr.prototype,"KBEngine.ServerErr");var idInterval;KBEngine.create=create,KBEngine.destroy=destroy}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/package.json b/kbengine_ts/package.json new file mode 100644 index 0000000..ff3dc69 --- /dev/null +++ b/kbengine_ts/package.json @@ -0,0 +1,4 @@ +{ + "name": "kbengine_ts", + "compilerVersion": "5.1.7" +} \ No newline at end of file diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts new file mode 100644 index 0000000..3540209 --- /dev/null +++ b/kbengine_ts/src/KBEngine.ts @@ -0,0 +1,3610 @@ +/** + * KBEngine的html5客户端扩展ts版 + * todo 类型匹配未完善 + * 缺少测试 + * 缺少类型Vector2,Vector4,暂时修改为Vector3,如果出问题再修改 + */ +namespace KBEngine { + export class Class { + + } + /*----------------------------------------------------------------------------------------- + global + -----------------------------------------------------------------------------------------*/ + export const PACKET_MAX_SIZE = 1500; + export const PACKET_MAX_SIZE_TCP = 1460; + export const PACKET_MAX_SIZE_UDP = 1472; + + export const MESSAGE_ID_LENGTH = 2; + export const MESSAGE_LENGTH_LENGTH = 2; + + export const CLIENT_NO_FLOAT = 0; + export const KBE_FLT_MAX = 3.402823466e+38; + /*----------------------------------------------------------------------------------------- + number64bits + -----------------------------------------------------------------------------------------*/ + export class INT64 { + constructor(lo, hi) { + this.lo = lo; + this.hi = hi; + + if (hi >= 2147483648) { + this.sign = -1; + if (this.lo > 0) { + this.lo = (4294967296 - this.lo) & 0xffffffff; + this.hi = 4294967295 - this.hi; + } + else { + this.lo = (4294967296 - this.lo) & 0xffffffff; + this.hi = 4294967296 - this.hi; + } + } + } + lo: number; + hi: number; + sign: number = 1; + toString() { + let result = ""; + + if (this.sign < 0) { + result += "-" + } + + let low = this.lo.toString(16); + let high = this.hi.toString(16); + + if (this.hi > 0) { + result += high; + for (let i = 8 - low.length; i > 0; --i) { + result += "0"; + } + } + result += low; + + return result; + } + } + export class UINT64 { + constructor(lo, hi) { + this.lo = lo; + this.hi = hi; + } + lo: number; + hi: number; + toString() { + let low = this.lo.toString(16); + let high = this.hi.toString(16); + + let result = ""; + if (this.hi > 0) { + result += high; + for (let i = 8 - low.length; i > 0; --i) { + result += "0"; + } + } + result += low; + return result; + } + } + /*----------------------------------------------------------------------------------------- + debug + -----------------------------------------------------------------------------------------*/ + export function INFO_MSG(s) { + console.info(s); + } + export function DEBUG_MSG(s) { + console.debug(s); + } + export function ERROR_MSG(s) { + console.error(s); + } + export function WARNING_MSG(s) { + console.warn(s); + } + + /*----------------------------------------------------------------------------------------- + string + -----------------------------------------------------------------------------------------*/ + export function utf8ArrayToString(array: Array) { + let out, i, len, c; + let char2, char3; + + out = ""; + len = array.length; + i = 0; + + while (i < len) { + c = array[i++]; + + switch (c >> 4) { + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: + // 0xxxxxxx + out += String.fromCharCode(c); + break; + case 12: case 13: + // 110x xxxx 10xx xxxx + char2 = array[i++]; + out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); + break; + case 14: + // 1110 xxxx 10xx xxxx 10xx xxxx + char2 = array[i++]; + char3 = array[i++]; + out += String.fromCharCode(((c & 0x0F) << 12) | + ((char2 & 0x3F) << 6) | + ((char3 & 0x3F) << 0)); + break; + } + } + + return out; + } + export function stringToUTF8Bytes(str: string) { + let utf8 = []; + for (let i = 0; i < str.length; i++) { + let charcode = str.charCodeAt(i); + if (charcode < 0x80) utf8.push(charcode); + else if (charcode < 0x800) { + utf8.push(0xc0 | (charcode >> 6), + 0x80 | (charcode & 0x3f)); + } + else if (charcode < 0xd800 || charcode >= 0xe000) { + utf8.push(0xe0 | (charcode >> 12), + 0x80 | ((charcode >> 6) & 0x3f), + 0x80 | (charcode & 0x3f)); + } + // surrogate pair + else { + i++; + // UTF-16 encodes 0x10000-0x10FFFF by + // subtracting 0x10000 and splitting the + // 20 bits of 0x0-0xFFFFF into two halves + charcode = 0x10000 + (((charcode & 0x3ff) << 10) + | (str.charCodeAt(i) & 0x3ff)) + utf8.push(0xf0 | (charcode >> 18), + 0x80 | ((charcode >> 12) & 0x3f), + 0x80 | ((charcode >> 6) & 0x3f), + 0x80 | (charcode & 0x3f)); + } + } + return utf8; + } + + /*----------------------------------------------------------------------------------------- + event + -----------------------------------------------------------------------------------------*/ + export class EventInfo { + constructor(classinst, callbackfn) { + this.callbackfn = callbackfn; + this.classinst = classinst; + } + classinst; + callbackfn; + } + export interface IEvents { + [evtName: string]: EventInfo[]; + } + export class Events { + constructor() { + + } + _events: IEvents = {}; + register(evtName: string, classinst, strCallback: string) { + let callbackfn = eval("classinst." + strCallback); + if (callbackfn == undefined) { + ERROR_MSG('export class Event::fire: not found strCallback(' + classinst + ")!" + strCallback); + return; + } + + let evtlst = this._events[evtName]; + if (evtlst == undefined) { + evtlst = []; + this._events[evtName] = evtlst; + } + + let info = new EventInfo(classinst, callbackfn); + evtlst.push(info); + } + deregister(evtName, classinst) { + for (let itemkey in this._events) { + let evtlst = this._events[itemkey]; + while (true) { + let found = false; + for (let i = 0; i < evtlst.length; i++) { + let info = evtlst[i]; + if (info.classinst == classinst) { + evtlst.splice(i, 1); + found = true; + break; + } + } + + if (!found) + break; + } + } + } + fire(evtName, ...args) { + if (arguments.length < 1) { + ERROR_MSG('export class Event::fire: not found eventName!'); + return; + } + + let evtlst = this._events[evtName]; + + if (evtlst == undefined) { + return; + } + + let ars = []; + for (let i = 1; i < args.length; i++) + ars.push(args[i]); + + for (let i = 0; i < evtlst.length; i++) { + let info = evtlst[i]; + if (ars.length < 1) { + info.callbackfn.apply(info.classinst); + } + else { + info.callbackfn.apply(info.classinst, ars); + } + } + } + } + export const Event = new Events(); + + /*----------------------------------------------------------------------------------------- + memorystream + -----------------------------------------------------------------------------------------*/ + export class MemoryStream { + constructor(size_or_buffer) { + if (size_or_buffer instanceof ArrayBuffer) { + this.buffer = size_or_buffer; + } + else { + this.buffer = new ArrayBuffer(size_or_buffer); + } + + this.rpos = 0; + this.wpos = 0; + } + + buffer: ArrayBuffer; + rpos: number = 0; + wpos: number = 0; + //--------------------------------------------------------------------------------- + readInt8() { + let buf = new Int8Array(this.buffer, this.rpos, 1); + this.rpos += 1; + return buf[0]; + } + + readInt16() { + let v = this.readUint16(); + if (v >= 32768) + v -= 65536; + return v; + } + + readInt32() { + let v = this.readUint32(); + if (v >= 2147483648) + v -= 4294967296; + return v; + } + + readInt64() { + return new INT64(this.readUint32(), this.readUint32()); + } + + readUint8() { + let buf = new Uint8Array(this.buffer, this.rpos, 1); + this.rpos += 1; + return buf[0]; + } + + readUint16() { + let buf = new Uint8Array(this.buffer, this.rpos); + this.rpos += 2; + return ((buf[1] & 0xff) << 8) + (buf[0] & 0xff); + } + + readUint32() { + let buf = new Uint8Array(this.buffer, this.rpos); + this.rpos += 4; + return (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0]; + } + + readUint64() { + return new UINT64(this.readUint32(), this.readUint32()); + } + + readFloat() { + let buf ; + try { + buf = new Float32Array(this.buffer, this.rpos, 1); + } + catch (e) { + buf = new Float32Array(this.buffer.slice(this.rpos, this.rpos + 4)); + } + + this.rpos += 4; + return buf[0]; + } + + readDouble() { + let buf; + try { + buf = new Float64Array(this.buffer, this.rpos, 1); + } + catch (e) { + buf = new Float64Array(this.buffer.slice(this.rpos, this.rpos + 8), 0, 1); + } + + this.rpos += 8; + return buf[0]; + } + + readString() { + let buf = new Uint8Array(this.buffer, this.rpos); + let i = 0; + let s = ""; + + while (true) { + if (buf[i] != 0) { + s += String.fromCharCode(buf[i]); + } + else { + i++; + break; + } + + i++; + + if (this.rpos + i >= this.buffer.byteLength) + throw (new Error("export class MemoryStream::readString: rpos(" + (this.rpos + i) + ")>=" + + this.buffer.byteLength + " overflow!")); + } + + this.rpos += i; + return s; + } + + readBlob() { + let size = this.readUint32(); + let buf = new Uint8Array(this.buffer, this.rpos, size); + this.rpos += size; + return buf; + } + + readStream() { + let buf = new Uint8Array(this.buffer, this.rpos, this.buffer.byteLength - this.rpos); + this.rpos = this.buffer.byteLength; + return new MemoryStream(buf); + } + + readPackXZ() { + let xPackData = new MemoryStream.PackFloatXType(); + let zPackData = new MemoryStream.PackFloatXType(); + + xPackData.fv[0] = 0.0; + zPackData.fv[0] = 0.0; + + xPackData.uv[0] = 0x40000000; + zPackData.uv[0] = 0x40000000; + + let v1 = this.readUint8(); + let v2 = this.readUint8(); + let v3 = this.readUint8(); + + let data = 0; + data |= (v1 << 16); + data |= (v2 << 8); + data |= v3; + + xPackData.uv[0] |= (data & 0x7ff000) << 3; + zPackData.uv[0] |= (data & 0x0007ff) << 15; + + xPackData.fv[0] -= 2.0; + zPackData.fv[0] -= 2.0; + + xPackData.uv[0] |= (data & 0x800000) << 8; + zPackData.uv[0] |= (data & 0x000800) << 20; + + let d = new Array(2); + d[0] = xPackData.fv[0]; + d[1] = zPackData.fv[0]; + return d; + } + + readPackY() { + let v = this.readUint16(); + return v; + } + + //--------------------------------------------------------------------------------- + writeInt8(v) { + let buf = new Int8Array(this.buffer, this.wpos, 1); + buf[0] = v; + this.wpos += 1; + } + + writeInt16(v) { + this.writeInt8(v & 0xff); + this.writeInt8(v >> 8 & 0xff); + } + + writeInt32(v) { + for (let i = 0; i < 4; i++) + this.writeInt8(v >> i * 8 & 0xff); + } + + writeInt64(v) { + this.writeInt32(v.lo); + this.writeInt32(v.hi); + } + + writeUint8(v) { + let buf = new Uint8Array(this.buffer, this.wpos, 1); + buf[0] = v; + this.wpos += 1; + } + + writeUint16(v) { + this.writeUint8(v & 0xff); + this.writeUint8(v >> 8 & 0xff); + } + + writeUint32(v) { + for (let i = 0; i < 4; i++) + this.writeUint8(v >> i * 8 & 0xff); + } + + writeUint64(v) { + this.writeUint32(v.lo); + this.writeUint32(v.hi); + } + + writeFloat(v) { + try { + let buf = new Float32Array(this.buffer, this.wpos, 1); + buf[0] = v; + } + catch (e) { + let buf = new Float32Array(1); + buf[0] = v; + let buf1 = new Uint8Array(this.buffer); + let buf2 = new Uint8Array(buf.buffer); + buf1.set(buf2, this.wpos); + } + + this.wpos += 4; + } + + writeDouble(v) { + try { + let buf = new Float64Array(this.buffer, this.wpos, 1); + buf[0] = v; + } + catch (e) { + let buf = new Float64Array(1); + buf[0] = v; + let buf1 = new Uint8Array(this.buffer); + let buf2 = new Uint8Array(buf.buffer); + buf1.set(buf2, this.wpos); + } + + this.wpos += 8; + } + + writeBlob(v) { + let size = v.length; + if (size + 4 > this.space()) { + ERROR_MSG("memorystream::writeBlob: no free!"); + return; + } + + this.writeUint32(size); + let buf = new Uint8Array(this.buffer, this.wpos, size); + + if (typeof (v) == "string") { + for (let i = 0; i < size; i++) { + buf[i] = v.charCodeAt(i); + } + } + else { + for (let i = 0; i < size; i++) { + buf[i] = v[i]; + } + } + + this.wpos += size; + } + + writeString(v) { + if (v.length > this.space()) { + ERROR_MSG("memorystream::writeString: no free!"); + return; + } + + let buf = new Uint8Array(this.buffer, this.wpos); + let i = 0; + for (let idx = 0; idx < v.length; idx++) { + buf[i++] = v.charCodeAt(idx); + } + + buf[i++] = 0; + this.wpos += i; + } + + //--------------------------------------------------------------------------------- + readSkip(v) { + this.rpos += v; + } + + //--------------------------------------------------------------------------------- + space() { + return this.buffer.byteLength - this.wpos; + } + + //--------------------------------------------------------------------------------- + length() { + return this.wpos - this.rpos; + } + + //--------------------------------------------------------------------------------- + readEOF() { + return this.buffer.byteLength - this.rpos <= 0; + } + + //--------------------------------------------------------------------------------- + done() { + this.rpos = this.wpos; + } + + //--------------------------------------------------------------------------------- + getbuffer(v) { + return this.buffer.slice(this.rpos, this.wpos); + } + } + export module MemoryStream { + export class PackFloatXType { + _unionData: ArrayBuffer; + fv: Float32Array; + uv: Uint32Array; + iv: Int32Array; + constructor() { + this._unionData = new ArrayBuffer(4); + this.fv = new Float32Array(this._unionData, 0, 1); + this.uv = new Uint32Array(this._unionData, 0, 1); + this.iv = new Int32Array(this._unionData, 0, 1); + }; + } + } + + /*----------------------------------------------------------------------------------------- + bundle + -----------------------------------------------------------------------------------------*/ + export class Bundle { + constructor() { + this.stream = new MemoryStream(PACKET_MAX_SIZE_TCP); + } + memorystreams: Array = new Array(); + stream: MemoryStream; + numMessage: number = 0; + messageLengthBuffer = null; + msgtype = null; + messageLength: number = 0; + //--------------------------------------------------------------------------------- + newMessage(msgtype) { + this.fini(false); + + this.msgtype = msgtype; + this.numMessage += 1; + + if (this.msgtype.length == -1) { + this.messageLengthBuffer = new Uint8Array(this.stream.buffer, this.stream.wpos + MESSAGE_ID_LENGTH, 2); + } + + this.writeUint16(msgtype.id); + + if (this.messageLengthBuffer) { + this.writeUint16(0); + this.messageLengthBuffer[0] = 0; + this.messageLengthBuffer[1] = 0; + this.messageLength = 0; + } + } + + //--------------------------------------------------------------------------------- + writeMsgLength(v) { + if (this.messageLengthBuffer) { + this.messageLengthBuffer[0] = v & 0xff; + this.messageLengthBuffer[1] = v >> 8 & 0xff; + } + } + + //--------------------------------------------------------------------------------- + fini(issend) { + if (this.numMessage > 0) { + this.writeMsgLength(this.messageLength); + if (this.stream) + this.memorystreams.push(this.stream); + } + + if (issend) { + this.messageLengthBuffer = null; + this.numMessage = 0; + this.msgtype = null; + } + } + + //--------------------------------------------------------------------------------- + send(network) { + this.fini(true); + + for (let i = 0; i < this.memorystreams.length; i++) { + let stream = this.memorystreams[i]; + network.send(stream.getbuffer()); + } + + this.memorystreams = new Array(); + this.stream = new MemoryStream(PACKET_MAX_SIZE_TCP); + } + + //--------------------------------------------------------------------------------- + checkStream(v) { + if (v > this.stream.space()) { + this.memorystreams.push(this.stream); + this.stream = new MemoryStream(PACKET_MAX_SIZE_TCP); + } + + this.messageLength += v; + } + + //--------------------------------------------------------------------------------- + writeInt8(v) { + this.checkStream(1); + this.stream.writeInt8(v); + } + + writeInt16(v) { + this.checkStream(2); + this.stream.writeInt16(v); + } + + writeInt32(v) { + this.checkStream(4); + this.stream.writeInt32(v); + } + + writeInt64(v) { + this.checkStream(8); + this.stream.writeInt64(v); + } + + writeUint8(v) { + this.checkStream(1); + this.stream.writeUint8(v); + } + + writeUint16(v) { + this.checkStream(2); + this.stream.writeUint16(v); + } + + writeUint32(v) { + this.checkStream(4); + this.stream.writeUint32(v); + } + + writeUint64(v) { + this.checkStream(8); + this.stream.writeUint64(v); + } + + writeFloat(v) { + this.checkStream(4); + this.stream.writeFloat(v); + } + + writeDouble(v) { + this.checkStream(8); + this.stream.writeDouble(v); + } + + writeString(v) { + this.checkStream(v.length + 1); + this.stream.writeString(v); + } + + writeBlob(v) { + this.checkStream(v.length + 4); + this.stream.writeBlob(v); + } + } + export const reader = new MemoryStream(0); + export interface IDataType2Id { + [type: string]: number; + } + export let datatype2id: IDataType2Id = {}; + + export function mappingDataType() { + datatype2id = {}; + datatype2id["STRING"] = 1; + datatype2id["STD::STRING"] = 1; + + datatype2id["UINT8"] = 2; + datatype2id["BOOL"] = 2; + datatype2id["DATATYPE"] = 2; + datatype2id["CHAR"] = 2; + datatype2id["DETAIL_TYPE"] = 2; + datatype2id["ENTITYCALL_CALL_TYPE"] = 2; + + datatype2id["UINT16"] = 3; + datatype2id["UNSIGNED SHORT"] = 3; + datatype2id["SERVER_ERROR_CODE"] = 3; + datatype2id["ENTITY_TYPE"] = 3; + datatype2id["ENTITY_PROPERTY_UID"] = 3; + datatype2id["ENTITY_METHOD_UID"] = 3; + datatype2id["ENTITY_SCRIPT_UID"] = 3; + datatype2id["DATATYPE_UID"] = 3; + + datatype2id["UINT32"] = 4; + datatype2id["UINT"] = 4; + datatype2id["UNSIGNED INT"] = 4; + datatype2id["ARRAYSIZE"] = 4; + datatype2id["SPACE_ID"] = 4; + datatype2id["GAME_TIME"] = 4; + datatype2id["TIMER_ID"] = 4; + + datatype2id["UINT64"] = 5; + datatype2id["DBID"] = 5; + datatype2id["COMPONENT_ID"] = 5; + + datatype2id["INT8"] = 6; + datatype2id["COMPONENT_ORDER"] = 6; + + datatype2id["INT16"] = 7; + datatype2id["SHORT"] = 7; + + datatype2id["INT32"] = 8; + datatype2id["INT"] = 8; + datatype2id["ENTITY_ID"] = 8; + datatype2id["CALLBACK_ID"] = 8; + datatype2id["COMPONENT_TYPE"] = 8; + + datatype2id["INT64"] = 9; + + datatype2id["PYTHON"] = 10; + datatype2id["PY_DICT"] = 10; + datatype2id["PY_TUPLE"] = 10; + datatype2id["PY_LIST"] = 10; + datatype2id["ENTITYCALL"] = 10; + + datatype2id["BLOB"] = 11; + + datatype2id["UNICODE"] = 12; + + datatype2id["FLOAT"] = 13; + + datatype2id["DOUBLE"] = 14; + + datatype2id["VECTOR2"] = 15; + + datatype2id["VECTOR3"] = 16; + + datatype2id["VECTOR4"] = 17; + + datatype2id["FIXED_DICT"] = 18; + + datatype2id["ARRAY"] = 19; + } + mappingDataType(); + + export function bindWriter(writer, argType: number) { + switch (argType) { + case datatype2id["UINT8"]: return writer.writeUint8; + case datatype2id["UINT16"]: return writer.writeUint16; + case datatype2id["UINT32"]: return writer.writeUint32; + case datatype2id["UINT64"]: return writer.writeUint64; + case datatype2id["INT8"]: return writer.writeInt8; + case datatype2id["INT16"]: return writer.writeInt16; + case datatype2id["INT32"]: return writer.writeInt32; + case datatype2id["INT64"]: return writer.writeInt64; + case datatype2id["FLOAT"]: return writer.writeFloat; + case datatype2id["DOUBLE"]: return writer.writeDouble; + case datatype2id["STRING"]: return writer.writeString; + case datatype2id["FIXED_DICT"]: return writer.writeStream; + case datatype2id["ARRAY"]: return writer.writeStream; + default: return writer.writeStream; + } + } + export function bindReader(argType: number) { + switch (argType) { + case datatype2id["UINT8"]: return reader.readUint8; + case datatype2id["UINT16"]: return reader.readUint16; + case datatype2id["UINT32"]: return reader.readUint32; + case datatype2id["UINT64"]: return reader.readUint64; + case datatype2id["INT8"]: return reader.readInt8; + case datatype2id["INT16"]: return reader.readInt16; + case datatype2id["INT32"]: return reader.readInt32; + case datatype2id["INT64"]: return reader.readInt64; + case datatype2id["FLOAT"]: return reader.readFloat; + case datatype2id["DOUBLE"]: return reader.readDouble; + case datatype2id["STRING"]: return reader.readString; + case datatype2id["FIXED_DICT"]: return reader.readStream; + case datatype2id["ARRAY"]: return reader.readStream; + default: return reader.readStream; + } + } + export class Message { + constructor(id, name, length, argstype, args, handler) { + this.id = id; + this.name = name; + this.length = length; + this.argsType = argstype; + for (let i = 0; i < args.length; i++) { + args[i] = bindReader(args[i]); + } + + this.args = args; + this.handler = handler; + } + id; + name; + length; + argsType; + args; + handler; + createFromStream(msgstream) { + if (this.args.length <= 0) + return msgstream; + + let result = new Array(this.args.length); + for (let i = 0; i < this.args.length; i++) { + result[i] = this.args[i].call(msgstream); + } + + return result; + } + + handleMessage (msgstream) { + if (this.handler == null) { + ERROR_MSG("Message::handleMessage: interface(" + this.name + "/" + this.id + ") no implement!"); + return; + } + + if (this.args.length <= 0) { + if (this.argsType < 0) + this.handler(msgstream); + else + this.handler(); + } + else { + this.handler.apply(app, this.createFromStream(msgstream)); + } + } + } + + export module messages { + export const loginapp = {}; + export const baseapp = {}; + export const Loginapp_importClientMessages = new Message(5, "importClientMessages", 0, 0, new Array(), null); + export const Baseapp_importClientMessages = new Message(207, "importClientMessages", 0, 0, new Array(), null); + export const Baseapp_importClientEntityDef = new Message(208, "importClientEntityDef", 0, 0, new Array(), null); + export const onImportClientMessages = new Message(518, "onImportClientMessages", -1, -1, new Array(), null); + } + export let clientmessages = {}; + export let bufferedCreateEntityMessage = {}; + + /*----------------------------------------------------------------------------------------- + math + -----------------------------------------------------------------------------------------*/ + export class Vector3 extends Class { + constructor(x, y, z) { + super(); + this.x = x; + this.y = y; + this.z = z; + } + x: number; + y: number; + z: number; + distance(pos: Vector3) { + let x = pos.x - this.x; + let y = pos.y - this.y; + let z = pos.z - this.z; + return Math.sqrt(x * x + y * y + z * z); + } + } + export function clampf(value, min_inclusive, max_inclusive) { + if (min_inclusive > max_inclusive) { + let temp = min_inclusive; + min_inclusive = max_inclusive; + max_inclusive = temp; + } + return value < min_inclusive ? min_inclusive : value < max_inclusive ? value : max_inclusive; + } + export function int82angle(angle, half) { + return angle * (Math.PI / (half ? 254.0 : 128.0)); + } + export function angle2int8(v: number, half: boolean) { + let angle = 0; + if (!half) { + //todo 原来写的float(Math.PI),因为js没有float这个方法所以去掉了 + angle = Math.floor((v * 128.0) / Math.PI + 0.5); + } + else { + angle = clampf(Math.floor((v * 254.0) / Math.PI + 0.5), -128.0, 127.0); + } + + return angle; + } + /*----------------------------------------------------------------------------------------- + entity + -----------------------------------------------------------------------------------------*/ + export class Entity extends Class { + constructor() { + super(); + } + id: number = 0; + className: string = ""; + position: Vector3 = new Vector3(0, 0, 0); + direction: Vector3 = new Vector3(0, 0, 0); + velocity: number = 0; + + cell = null; + base = null; + + // enterworld之后设置为true + inWorld = false; + + // __init__调用之后设置为true + inited = false; + + // 是否被控制 + isControlled = false; + + entityLastLocalPos = new Vector3(0.0, 0.0, 0.0); + entityLastLocalDir = new Vector3(0.0, 0.0, 0.0); + + // 玩家是否在地面上 + isOnGround = false; + + __init__() { + + } + callPropertysSetMethods() { + let currModule = moduledefs[this.className]; + for (let name in currModule.propertys) { + let propertydata = currModule.propertys[name]; + let properUtype = propertydata[0]; + name = propertydata[2]; + let setmethod = propertydata[5]; + let flags = propertydata[6]; + let oldval = this[name]; + + if (setmethod != null) { + // base类属性或者进入世界后cell类属性会触发set_*方法 + // ED_FLAG_BASE_AND_CLIENT、ED_FLAG_BASE + if (flags == 0x00000020 || flags == 0x00000040) { + if (this.inited && !this.inWorld) + setmethod.call(this, oldval); + } + else { + if (this.inWorld) { + if (flags == 0x00000008 || flags == 0x00000010) { + if (!this.isPlayer()) + continue; + } + + setmethod.call(this, oldval); + } + } + } + }; + } + onDestroy() { + + } + onControlled(bIsControlled) { + + } + isPlayer() { + return this.id == app.entity_id; + } + baseCall(...params:any[]) { + if (params.length < 1) { + ERROR_MSG('Entity::baseCall: not fount interfaceName!'); + return; + } + + if (this.base == undefined) { + ERROR_MSG('Entity::baseCall: base is None!'); + return; + } + + let method = moduledefs[this.className].base_methods[params[0]]; + + if (method == undefined) { + ERROR_MSG("Entity::baseCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); + return; + } + + let methodID = method[0]; + let args = method[3]; + + if (args.length - 1 != args.length) { + ERROR_MSG("Entity::baseCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); + return; + } + + this.base.newCall(); + this.base.bundle.writeUint16(methodID); + + try { + for (let i = 0; i < args.length; i++) { + if (args[i].isSameType(args[i + 1])) { + args[i].addToStream(this.base.bundle, args[i + 1]); + } + else { + throw new Error("Entity::baseCall: arg[" + i + "] is error!"); + } + } + } + catch (e) { + ERROR_MSG(e.toString()); + ERROR_MSG('Entity::baseCall: args is error!'); + this.base.bundle = null; + return; + } + + this.base.sendCall(); + } + cellCall(...params) { + if (params.length < 1) { + ERROR_MSG('Entity::cellCall: not fount interfaceName!'); + return; + } + + if (this.cell == undefined) { + ERROR_MSG('Entity::cellCall: cell is None!'); + return; + } + + let method = moduledefs[this.className].cell_methods[params[0]]; + + if (method == undefined) { + ERROR_MSG("Entity::cellCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); + return; + } + + let methodID = method[0]; + let args = method[3]; + + if (args.length - 1 != args.length) { + ERROR_MSG("Entity::cellCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); + return; + } + + this.cell.newCall(); + this.cell.bundle.writeUint16(methodID); + + try { + for (let i = 0; i < args.length; i++) { + if (args[i].isSameType(args[i + 1])) { + args[i].addToStream(this.cell.bundle, args[i + 1]); + } + else { + throw new Error("Entity::cellCall: arg[" + i + "] is error!"); + } + } + } + catch (e) { + ERROR_MSG(e.toString()); + ERROR_MSG('Entity::cellCall: args is error!'); + this.cell.bundle = null; + return; + } + + this.cell.sendCall(); + } + enterWorld() { + INFO_MSG(this.className + '::enterWorld: ' + this.id); + this.inWorld = true; + this.onEnterWorld(); + + Event.fire("onEnterWorld", this); + } + onEnterWorld() { + + } + leaveWorld() { + INFO_MSG(this.className + '::leaveWorld: ' + this.id); + this.inWorld = false; + this.onLeaveWorld(); + Event.fire("onLeaveWorld", this); + } + onLeaveWorld() { + + } + enterSpace() { + INFO_MSG(this.className + '::enterSpace: ' + this.id); + this.onEnterSpace(); + Event.fire("onEnterSpace", this); + + // 要立即刷新表现层对象的位置 + Event.fire("set_position", this); + Event.fire("set_direction", this); + } + onEnterSpace() { + + } + leaveSpace() { + INFO_MSG(this.className + '::leaveSpace: ' + this.id); + this.onLeaveSpace(); + Event.fire("onLeaveSpace", this); + } + onLeaveSpace() { + + } + set_position() { + // DEBUG_MSG(this.className + "::set_position: " + old); + if (this.isPlayer()) { + app.entityServerPos.x = this.position.x; + app.entityServerPos.y = this.position.y; + app.entityServerPos.z = this.position.z; + } + + Event.fire("set_position", this); + } + onUpdateVolatileData() { + + } + set_direction(old) { + // DEBUG_MSG(this.className + "::set_direction: " + old); + Event.fire("set_direction", this); + } + } + + /*----------------------------------------------------------------------------------------- + EntityCall + -----------------------------------------------------------------------------------------*/ + export const ENTITYCALL_TYPE_CELL = 0; + export const ENTITYCALL_TYPE_BASE = 1; + + export class EntityCall { + constructor() { + + } + id: number = 0; + className = ''; + type: number = ENTITYCALL_TYPE_CELL; + networkInterface = app; + bundle = null; + + isBase() { + return this.type == ENTITYCALL_TYPE_BASE; + } + isCell() { + return this.type == ENTITYCALL_TYPE_CELL; + } + newCall() { + if (this.bundle == null) + this.bundle = new Bundle(); + + if (this.type == ENTITYCALL_TYPE_CELL) + this.bundle.newMessage(messages['Baseapp_onRemoteCallCellMethodFromClient']); + else + this.bundle.newMessage(messages['Entity_onRemoteMethodCall']); + + this.bundle.writeInt32(this.id); + + return this.bundle; + } + sendCall(bundle) { + if (bundle == undefined) + bundle = this.bundle; + + bundle.send(this.networkInterface); + + if (this.bundle == bundle) + this.bundle = null; + } + } + export const moduledefs = {}; + + export class DATATYPE_UINT8 { + bind () { + } + + createFromStream (stream) { + return reader.readUint8.call(stream); + } + + addToStream (stream, v) { + stream.writeUint8(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + if (typeof (v) != "number") { + return false; + } + + if (v < 0 || v > 0xff) { + return false; + } + + return true; + } + } + export class DATATYPE_UINT16 { + bind () { + } + + createFromStream (stream) { + return reader.readUint16.call(stream); + } + + addToStream (stream, v) { + stream.writeUint16(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + if (typeof (v) != "number") { + return false; + } + + if (v < 0 || v > 0xffff) { + return false; + } + + return true; + } + } + export class DATATYPE_UINT32 { + bind () { + } + createFromStream (stream) { + return reader.readUint32.call(stream); + } + + addToStream (stream, v) { + stream.writeUint32(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + if (typeof (v) != "number") { + return false; + } + + if (v < 0 || v > 0xffffffff) { + return false; + } + + return true; + } + } + export class DATATYPE_UINT64 { + bind () { + } + + createFromStream (stream) { + return reader.readUint64.call(stream); + } + + addToStream (stream, v) { + stream.writeUint64(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + return v instanceof UINT64; + } + } + export class DATATYPE_INT8 { + bind () { + } + + createFromStream (stream) { + return reader.readInt8.call(stream); + } + + addToStream (stream, v) { + stream.writeInt8(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + if (typeof (v) != "number") { + return false; + } + + if (v < -0x80 || v > 0x7f) { + return false; + } + + return true; + } + } + export class DATATYPE_INT16 { + bind () { + } + + createFromStream (stream) { + return reader.readInt16.call(stream); + } + + addToStream (stream, v) { + stream.writeInt16(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + if (typeof (v) != "number") { + return false; + } + + if (v < -0x8000 || v > 0x7fff) { + return false; + } + + return true; + } + } + export class DATATYPE_INT32 { + bind () { + } + + createFromStream (stream) { + return reader.readInt32.call(stream); + } + + addToStream (stream, v) { + stream.writeInt32(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + if (typeof (v) != "number") { + return false; + } + + if (v < -0x80000000 || v > 0x7fffffff) { + return false; + } + + return true; + } + } + export class DATATYPE_INT64 { + bind () { + } + + createFromStream (stream) { + return reader.readInt64.call(stream); + } + + addToStream (stream, v) { + stream.writeInt64(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + return v instanceof INT64; + } + } + export class DATATYPE_FLOAT { + bind () { + } + + createFromStream (stream) { + return reader.readFloat.call(stream); + } + + addToStream (stream, v) { + stream.writeFloat(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + return typeof (v) == "number"; + } + } + export class DATATYPE_DOUBLE extends DATATYPE_FLOAT { + createFromStream (stream) { + return reader.readDouble.call(stream); + } + + addToStream (stream, v) { + stream.writeDouble(v); + } + } + export class DATATYPE_STRING { + bind () { + } + + createFromStream (stream) { + return reader.readString.call(stream); + } + + addToStream (stream, v) { + stream.writeString(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + return typeof (v) == "string"; + } + } + export class DATATYPE_VECTOR2 { + bind () { + } + + createFromStream (stream) { + if (CLIENT_NO_FLOAT) { + return new Vector3(reader.readInt32.call(stream), + reader.readInt32.call(stream), reader.readInt32.call(stream)); + } + else { + return new Vector3(reader.readFloat.call(stream), + reader.readFloat.call(stream), reader.readFloat.call(stream)); + } + } + + addToStream (stream, v) { + if (CLIENT_NO_FLOAT) { + stream.writeInt32(v.x); + stream.writeInt32(v.y); + } + else { + stream.writeFloat(v.x); + stream.writeFloat(v.y); + } + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + if (!(v instanceof Vector3)) { + return false; + } + + return true; + } + } + export class DATATYPE_VECTOR3 { + bind () { + } + + createFromStream (stream) { + if (CLIENT_NO_FLOAT) { + return new Vector3(reader.readInt32.call(stream), + reader.readInt32.call(stream), reader.readInt32.call(stream)); + } + else { + return new Vector3(reader.readFloat.call(stream), + reader.readFloat.call(stream), reader.readFloat.call(stream)); + } + } + + addToStream (stream, v) { + if (CLIENT_NO_FLOAT) { + stream.writeInt32(v.x); + stream.writeInt32(v.y); + stream.writeInt32(v.z); + } + else { + stream.writeFloat(v.x); + stream.writeFloat(v.y); + stream.writeFloat(v.z); + } + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + if (!(v instanceof Vector3)) { + return false; + } + + return true; + } + } + export class DATATYPE_VECTOR4 { + bind () { + } + + createFromStream (stream) { + if (CLIENT_NO_FLOAT) { + return new Vector3(reader.readInt32.call(stream), + reader.readInt32.call(stream), reader.readInt32.call(stream)); + } + else { + return new Vector3(reader.readFloat.call(stream), + reader.readFloat.call(stream), reader.readFloat.call(stream)); + } + } + + addToStream (stream, v) { + if (CLIENT_NO_FLOAT) { + stream.writeInt32(v.x); + stream.writeInt32(v.y); + stream.writeInt32(v.z); + stream.writeInt32(v.w); + } + else { + stream.writeFloat(v.x); + stream.writeFloat(v.y); + stream.writeFloat(v.z); + stream.writeFloat(v.w); + } + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + if (!(v instanceof Vector3)) { + return false; + } + + return true; + } + } + export class DATATYPE_PYTHON { + bind () { + } + + createFromStream (stream) { + } + + addToStream (stream, v) { + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + return false; + } + } + export class DATATYPE_UNICODE { + bind () { + } + + createFromStream (stream) { + return utf8ArrayToString(reader.readBlob.call(stream)); + } + + addToStream (stream, v) { + stream.writeBlob(stringToUTF8Bytes(v)); + } + + parseDefaultValStr (v) { + if (typeof (v) == "string") + return v; + + return ""; + } + + isSameType (v) { + return typeof (v) == "string"; + } + } + export class DATATYPE_ENTITYCALL { + bind () { + } + + createFromStream (stream) { + } + + addToStream (stream, v) { + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + return false; + } + } + export class DATATYPE_BLOB { + bind () { + } + + createFromStream (stream) { + let size = reader.readUint32.call(stream); + let buf = new Uint8Array(stream.buffer, stream.rpos, size); + stream.rpos += size; + return buf; + } + + addToStream (stream, v) { + stream.writeBlob(v); + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + return true; + } + } + export class DATATYPE_ARRAY { + type = null; + + bind () { + if (typeof (this.type) == "number") + this.type = datatypes[this.type]; + } + + createFromStream (stream) { + let size = stream.readUint32(); + let datas = []; + + while (size > 0) { + size--; + datas.push(this.type.createFromStream(stream)); + }; + + return datas; + } + + addToStream (stream, v) { + stream.writeUint32(v.length); + for (let i = 0; i < v.length; i++) { + this.type.addToStream(stream, v[i]); + } + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + for (let i = 0; i < v.length; i++) { + if (!this.type.isSameType(v[i])) { + return false; + } + } + + return true; + } + } + export class DATATYPE_FIXED_DICT { + dicttype = {}; + implementedBy = null; + + bind () { + for (let itemkey in this.dicttype) { + let utype = this.dicttype[itemkey]; + + if (typeof (this.dicttype[itemkey]) == "number") + this.dicttype[itemkey] = datatypes[utype]; + } + } + + createFromStream (stream) { + let datas = {}; + for (let itemkey in this.dicttype) { + datas[itemkey] = this.dicttype[itemkey].createFromStream(stream); + } + + return datas; + } + + addToStream (stream, v) { + for (let itemkey in this.dicttype) { + this.dicttype[itemkey].addToStream(stream, v[itemkey]); + } + } + + parseDefaultValStr (v) { + return eval(v); + } + + isSameType (v) { + for (let itemkey in this.dicttype) { + if (!this.dicttype[itemkey].isSameType(v[itemkey])) { + return false; + } + } + + return true; + } + } + + export module datatypes { + export const UINT8 = new DATATYPE_UINT8(); + export const UINT16 = new DATATYPE_UINT16(); + export const UINT32 = new DATATYPE_UINT32(); + export const UINT64 = new DATATYPE_UINT64(); + + export const INT8 = new DATATYPE_INT8(); + export const INT16 = new DATATYPE_INT16(); + export const INT32 = new DATATYPE_INT32(); + export const INT64 = new DATATYPE_INT64(); + + export const FLOAT = new DATATYPE_FLOAT(); + export const DOUBLE = new DATATYPE_DOUBLE(); + + export const STRING = new DATATYPE_STRING(); + export const VECTOR2 = new DATATYPE_VECTOR2; + export const VECTOR3 = new DATATYPE_VECTOR3; + export const VECTOR4 = new DATATYPE_VECTOR4; + export const PYTHON = new DATATYPE_PYTHON(); + export const UNICODE = new DATATYPE_UNICODE(); + export const ENTITYCALL = new DATATYPE_ENTITYCALL(); + export const BLOB = new DATATYPE_BLOB(); + }; + + /*----------------------------------------------------------------------------------------- + KBEngine args + -----------------------------------------------------------------------------------------*/ + export class KBEngineArgs { + ip = '127.0.0.1'; + port = 20013; + updateHZ = 100; + serverHeartbeatTick = 15; + + // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types + clientType = 5; + + // 在Entity初始化时是否触发属性的set_*事件(callPropertysSetMethods) + isOnInitCallPropertysSetMethods = true; + } + + /*----------------------------------------------------------------------------------------- + KBEngine app + -----------------------------------------------------------------------------------------*/ + export class KBEngineApp { + constructor(args: KBEngineArgs) { + console.assert(app == null || app == undefined, "Assertion of app not is null"); + + app = this; + this.args = args; + } + args: KBEngineArgs; + baseappIp:string; + username = "testhtml51"; + password = "123456"; + clientdatas = ""; + encryptedKey = ""; + + loginappMessageImported = false; + baseappMessageImported = false; + serverErrorsDescrImported = false; + entitydefImported = false; + + serverErrs: { [err: string]: ServerErr } = {}; + + // 登录loginapp的地址 + ip: string; + port: number; + + // 服务端分配的baseapp地址 + baseappIP = ''; + baseappPort = 0; + + socket; + currserver:string; + currstate = "create"; + + // 扩展数据 + serverdatas = ""; + + // 版本信息 + serverVersion = ""; + serverScriptVersion = ""; + serverProtocolMD5 = ""; + serverEntityDefMD5 = ""; + clientVersion = "1.1.5"; + clientScriptVersion = "0.1.0"; + + // player的相关信息 + entity_uuid = null; + entity_id = 0; + entity_type = ""; + + // 当前玩家最后一次同步到服务端的位置与朝向与服务端最后一次同步过来的位置 + entityServerPos = new Vector3(0.0, 0.0, 0.0); + + // 客户端所有的实体 + entities = {}; + entityIDAliasIDList = []; + controlledEntities = []; + + // 空间的信息 + spacedata = {}; + spaceID = 0; + spaceResPath = ""; + isLoadedGeometry = false; + + lastTickTime = Date.now(); + lastTickCBTime = Date.now(); + component; + resetSocket() { + try { + if (app.socket != undefined && app.socket != null) { + let sock = app.socket; + + sock.onopen = undefined; + sock.onerror = undefined; + sock.onmessage = undefined; + sock.onclose = undefined; + app.socket = null; + sock.close(); + } + } + catch (e) { + } + } + reset() { + if (app.entities != undefined && app.entities != null) { + app.clearEntities(true); + } + + app.resetSocket(); + + app.currserver = "loginapp"; + app.currstate = "create"; + + // 扩展数据 + app.serverdatas = ""; + + // 版本信息 + app.serverVersion = ""; + app.serverScriptVersion = ""; + app.serverProtocolMD5 = ""; + app.serverEntityDefMD5 = ""; + app.clientVersion = "1.1.5"; + app.clientScriptVersion = "0.1.0"; + + // player的相关信息 + app.entity_uuid = null; + app.entity_id = 0; + app.entity_type = ""; + + // 当前玩家最后一次同步到服务端的位置与朝向与服务端最后一次同步过来的位置 + app.entityServerPos = new Vector3(0.0, 0.0, 0.0); + + // 客户端所有的实体 + app.entities = {}; + app.entityIDAliasIDList = []; + app.controlledEntities = []; + + // 空间的信息 + app.spacedata = {}; + app.spaceID = 0; + app.spaceResPath = ""; + app.isLoadedGeometry = false; + + let dateObject = new Date(); + app.lastTickTime = dateObject.getTime(); + app.lastTickCBTime = dateObject.getTime(); + + mappingDataType(); + + // 当前组件类别, 配套服务端体系 + app.component = "client"; + } + installEvents () { + Event.register("createAccount", app, "createAccount"); + Event.register("login", app, "login"); + Event.register("reloginBaseapp", app, "reloginBaseapp"); + Event.register("bindAccountEmail", app, "bindAccountEmail"); + Event.register("newPassword", app, "newPassword"); + } + uninstallEvents () { + Event.deregister("reloginBaseapp", app); + Event.deregister("login", app); + Event.deregister("createAccount", app); + } + hello () { + let bundle = new Bundle(); + + if (app.currserver == "loginapp") + bundle.newMessage(messages['Loginapp_hello']); + else + bundle.newMessage(messages['Baseapp_hello']); + + bundle.writeString(app.clientVersion); + bundle.writeString(app.clientScriptVersion); + bundle.writeBlob(app.encryptedKey); + bundle.send(app); + } + player () { + return app.entities[app.entity_id]; + } + findEntity (entityID) { + return app.entities[entityID]; + } + connect (addr) { + console.assert(app.socket == null, "Assertion of socket not is null"); + + try { + //todo 应该是在这里设置wss + app.socket = new WebSocket(addr); + } + catch (e) { + ERROR_MSG('WebSocket init error!'); + Event.fire("onConnectionState", false); + return; + } + + app.socket.binaryType = "arraybuffer"; + app.socket.onopen = app.onopen; + app.socket.onerror = app.onerror_before_onopen; + app.socket.onmessage = app.onmessage; + app.socket.onclose = app.onclose; + } + disconnect () { + app.resetSocket(); + } + onopen () { + INFO_MSG('connect success!'); + app.socket.onerror = app.onerror_after_onopen; + Event.fire("onConnectionState", true); + } + onerror_before_onopen (evt) { + ERROR_MSG('connect error:' + evt.data); + app.resetSocket(); + Event.fire("onConnectionState", false); + } + onerror_after_onopen (evt) { + ERROR_MSG('connect error:' + evt.data); + app.resetSocket(); + Event.fire("onDisconnected"); + } + onmessage (msg) { + let stream = new MemoryStream(msg.data); + stream.wpos = msg.data.byteLength; + + while (stream.rpos < stream.wpos) { + let msgid = stream.readUint16(); + let msgHandler = clientmessages[msgid]; + + if (!msgHandler) { + ERROR_MSG("KBEngineApp::onmessage[" + app.currserver + "]: not found msg(" + msgid + ")!"); + } + else { + let msglen = msgHandler.length; + if (msglen == -1) { + msglen = stream.readUint16(); + + // 扩展长度 + if (msglen == 65535) + msglen = stream.readUint32(); + } + + let wpos = stream.wpos; + let rpos = stream.rpos + msglen; + stream.wpos = rpos; + msgHandler.handleMessage(stream); + stream.wpos = wpos; + stream.rpos = rpos; + } + } + } + onclose () { + INFO_MSG('connect close:' + app.currserver); + app.resetSocket(); + Event.fire("onDisconnected"); + //if(app.currserver != "loginapp") + // app.reset(); + } + send (msg) { + app.socket.send(msg); + } + close () { + INFO_MSG('KBEngine::close()'); + app.socket.close(); + app.reset(); + } + update () { + if (app.socket == null) + return; + + let dateObject = new Date(); + if ((dateObject.getTime() - app.lastTickTime) / 1000 > app.args.serverHeartbeatTick) { + // 如果心跳回调接收时间小于心跳发送时间,说明没有收到回调 + // 此时应该通知客户端掉线了 + if (app.lastTickCBTime < app.lastTickTime) { + ERROR_MSG("sendTick: Receive appTick timeout!"); + app.socket.close(); + } + + if (app.currserver == "loginapp") { + if (messages['Loginapp_onClientActiveTick'] != undefined) { + let bundle = new Bundle(); + bundle.newMessage(messages['Loginapp_onClientActiveTick']); + bundle.send(app); + } + } + else { + if (messages['Baseapp_onClientActiveTick'] != undefined) { + let bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_onClientActiveTick']); + bundle.send(app); + } + } + + app.lastTickTime = dateObject.getTime(); + } + + app.updatePlayerToServer(); + } + Client_onAppActiveTickCB () { + let dateObject = new Date(); + app.lastTickCBTime = dateObject.getTime(); + } + serverErr (id) { + let e = app.serverErrs[id]; + + if (e == undefined) { + return ""; + } + + return e.name + " [" + e.descr + "]"; + } + Client_onImportServerErrorsDescr (stream) { + let size = stream.readUint16(); + while (size > 0) { + size -= 1; + + let e = new ServerErr(); + e.id = stream.readUint16(); + e.name = utf8ArrayToString(stream.readBlob()); + e.descr = utf8ArrayToString(stream.readBlob()); + + app.serverErrs[e.id] = e; + + INFO_MSG("Client_onImportServerErrorsDescr: id=" + e.id + ", name=" + e.name + ", descr=" + e.descr); + } + } + onOpenLoginapp_login () { + INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"); + Event.fire("onConnectionState", true); + + app.currserver = "loginapp"; + app.currstate = "login"; + + if (!app.loginappMessageImported) { + let bundle = new Bundle(); + bundle.newMessage(messages.Loginapp_importClientMessages); + bundle.send(app); + app.socket.onmessage = app.Client_onImportClientMessages; + INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."); + Event.fire("Loginapp_importClientMessages"); + } + else { + app.onImportClientMessagesCompleted(); + } + } + onOpenLoginapp_createAccount () { + Event.fire("onConnectionState", true); + INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"); + app.currserver = "loginapp"; + app.currstate = "createAccount"; + + if (!app.loginappMessageImported) { + let bundle = new Bundle(); + bundle.newMessage(messages.Loginapp_importClientMessages); + bundle.send(app); + app.socket.onmessage = app.Client_onImportClientMessages; + INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."); + Event.fire("Loginapp_importClientMessages"); + } + else { + app.onImportClientMessagesCompleted(); + } + } + onImportClientMessagesCompleted () { + INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"); + app.socket.onmessage = app.onmessage; + app.hello(); + + if (app.currserver == "loginapp") { + if (!app.serverErrorsDescrImported) { + INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"); + app.serverErrorsDescrImported = true; + let bundle = new Bundle(); + bundle.newMessage(messages['Loginapp_importServerErrorsDescr']); + bundle.send(app); + } + + if (app.currstate == "login") + app.login_loginapp(false); + else if (app.currstate == "resetpassword") + app.resetpassword_loginapp(false); + else + app.createAccount_loginapp(false); + + app.loginappMessageImported = true; + } + else { + app.baseappMessageImported = true; + + if (!app.entitydefImported) { + INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ..."); + let bundle = new Bundle(); + bundle.newMessage(messages.Baseapp_importClientEntityDef); + bundle.send(app); + Event.fire("Baseapp_importClientEntityDef"); + } + else { + app.onImportEntityDefCompleted(); + } + } + } + createDataTypeFromStreams (stream, canprint) { + let aliassize = stream.readUint16(); + INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size=" + aliassize + ")!"); + + while (aliassize > 0) { + aliassize--; + app.createDataTypeFromStream(stream, canprint); + }; + + for (let datatype in datatypes) { + if (datatypes[datatype] != undefined) { + datatypes[datatype].bind(); + } + } + } + createDataTypeFromStream (stream, canprint) { + let utype = stream.readUint16(); + let name = stream.readString(); + let valname = stream.readString(); + let length : string; + /* 有一些匿名类型,我们需要提供一个唯一名称放到datatypes中 + 如: + + ARRAY INT8 + + */ + if (valname.length == 0) + length = "Null_" + utype; + + if (canprint) + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias(" + name + ":" + valname + ")!"); + + if (name == "FIXED_DICT") { + let datatype = new DATATYPE_FIXED_DICT(); + let keysize = stream.readUint8(); + datatype.implementedBy = stream.readString(); + + while (keysize > 0) { + keysize--; + + let keyname = stream.readString(); + let keyutype = stream.readUint16(); + datatype.dicttype[keyname] = keyutype; + }; + + datatypes[valname] = datatype; + } + else if (name == "ARRAY") { + let uitemtype = stream.readUint16(); + let datatype = new DATATYPE_ARRAY(); + datatype.type = uitemtype; + datatypes[valname] = datatype; + } + else { + datatypes[valname] = datatypes[name]; + } + + datatypes[utype] = datatypes[valname]; + + // 将用户自定义的类型补充到映射表中 + datatype2id[valname] = utype; + } + Client_onImportClientEntityDef (stream) { + app.createDataTypeFromStreams(stream, true); + + while (!stream.readEOF()) { + let scriptmodule_name = stream.readString(); + let scriptUtype = stream.readUint16(); + let propertysize = stream.readUint16(); + let methodsize = stream.readUint16(); + let base_methodsize = stream.readUint16(); + let cell_methodsize = stream.readUint16(); + + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import(" + scriptmodule_name + "), propertys(" + propertysize + "), " + + "clientMethods(" + methodsize + "), baseMethods(" + base_methodsize + "), cellMethods(" + cell_methodsize + ")!"); + + moduledefs[scriptmodule_name] = {}; + let currModuleDefs = moduledefs[scriptmodule_name]; + currModuleDefs["name"] = scriptmodule_name; + currModuleDefs["propertys"] = {}; + currModuleDefs["methods"] = {}; + currModuleDefs["base_methods"] = {}; + currModuleDefs["cell_methods"] = {}; + moduledefs[scriptUtype] = currModuleDefs; + + let self_propertys = currModuleDefs["propertys"]; + let self_methods = currModuleDefs["methods"]; + let self_base_methods = currModuleDefs["base_methods"]; + let self_cell_methods = currModuleDefs["cell_methods"]; + + try { + let Class = eval("" + scriptmodule_name); + } + catch (e) { + let Class = undefined; + } + + while (propertysize > 0) { + propertysize--; + + let properUtype = stream.readUint16(); + let properFlags = stream.readUint32(); + let aliasID = stream.readInt16(); + let name = stream.readString(); + let defaultValStr = stream.readString(); + let utype = datatypes[stream.readUint16()]; + let setmethod = null; + + if (Class != undefined) { + setmethod = Class.prototype["set_" + name]; + if (setmethod == undefined) + setmethod = null; + } + + let savedata = [properUtype, aliasID, name, defaultValStr, utype, setmethod, properFlags]; + self_propertys[name] = savedata; + + if (aliasID != -1) { + self_propertys[aliasID] = savedata; + currModuleDefs["usePropertyDescrAlias"] = true; + } + else { + self_propertys[properUtype] = savedata; + currModuleDefs["usePropertyDescrAlias"] = false; + } + + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), property(" + name + "/" + properUtype + ")."); + }; + + while (methodsize > 0) { + methodsize--; + + let methodUtype = stream.readUint16(); + let aliasID = stream.readInt16(); + let name = stream.readString(); + let argssize = stream.readUint8(); + let args = []; + + while (argssize > 0) { + argssize--; + args.push(datatypes[stream.readUint16()]); + }; + + let savedata = [methodUtype, aliasID, name, args]; + self_methods[name] = savedata; + + if (aliasID != -1) { + self_methods[aliasID] = savedata; + currModuleDefs["useMethodDescrAlias"] = true; + } + else { + self_methods[methodUtype] = savedata; + currModuleDefs["useMethodDescrAlias"] = false; + } + + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), method(" + name + ")."); + }; + + while (base_methodsize > 0) { + base_methodsize--; + + let methodUtype = stream.readUint16(); + let aliasID = stream.readInt16(); + let name = stream.readString(); + let argssize = stream.readUint8(); + let args = []; + + while (argssize > 0) { + argssize--; + args.push(datatypes[stream.readUint16()]); + }; + + self_base_methods[name] = [methodUtype, aliasID, name, args]; + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), base_method(" + name + ")."); + }; + + while (cell_methodsize > 0) { + cell_methodsize--; + + let methodUtype = stream.readUint16(); + let aliasID = stream.readInt16(); + let name = stream.readString(); + let argssize = stream.readUint8(); + let args = []; + + while (argssize > 0) { + argssize--; + args.push(datatypes[stream.readUint16()]); + }; + + self_cell_methods[name] = [methodUtype, aliasID, name, args]; + INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), cell_method(" + name + ")."); + }; + let defmethod + try { + defmethod = eval("" + scriptmodule_name); + } + catch (e) { + ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module(" + scriptmodule_name + ") not found!"); + defmethod = undefined; + } + + for (let name in currModuleDefs.propertys) { + let infos = currModuleDefs.propertys[name]; + let properUtype = infos[0]; + let aliasID = infos[1]; + let n = infos[2]; + let defaultValStr = infos[3]; + let utype = infos[4]; + + if (defmethod != undefined) + defmethod.prototype[n] = utype.parseDefaultValStr(defaultValStr); + }; + + for (let name in currModuleDefs.methods) { + let infos = currModuleDefs.methods[name]; + let properUtype = infos[0]; + let aliasID = infos[1]; + let n = infos[2]; + let args = infos[3]; + + if (defmethod != undefined && defmethod.prototype[n] == undefined) { + WARNING_MSG(scriptmodule_name + ":: method(" + n + ") no implement!"); + } + }; + } + + app.onImportEntityDefCompleted(); + } + Client_onVersionNotMatch (stream) { + app.serverVersion = stream.readString(); + ERROR_MSG("Client_onVersionNotMatch: verInfo=" + app.clientVersion + " not match(server: " + app.serverVersion + ")"); + Event.fire("onVersionNotMatch", app.clientVersion, app.serverVersion); + } + Client_onScriptVersionNotMatch (stream) { + app.serverScriptVersion = stream.readString(); + ERROR_MSG("Client_onScriptVersionNotMatch: verInfo=" + app.clientScriptVersion + " not match(server: " + app.serverScriptVersion + ")"); + Event.fire("onScriptVersionNotMatch", app.clientScriptVersion, app.serverScriptVersion); + } + onImportEntityDefCompleted () { + INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"); + app.entitydefImported = true; + app.login_baseapp(false); + } + Client_onImportClientMessages (msg) { + let stream = new MemoryStream(msg.data); + let msgid = stream.readUint16(); + + if (msgid == messages.onImportClientMessages.id) { + let msglen = stream.readUint16(); + let msgcount = stream.readUint16(); + + INFO_MSG("KBEngineApp::onImportClientMessages: start(" + msgcount + ") ...!"); + + while (msgcount > 0) { + msgcount--; + + msgid = stream.readUint16(); + msglen = stream.readInt16(); + let msgname = stream.readString(); + let argtype = stream.readInt8(); + let argsize = stream.readUint8(); + let argstypes = new Array(argsize); + + for (let i = 0; i < argsize; i++) { + argstypes[i] = stream.readUint8(); + } + + let handler = null; + let isClientMethod = msgname.indexOf("Client_") >= 0; + if (isClientMethod) { + handler = app[msgname]; + if (handler == null || handler == undefined) { + WARNING_MSG("KBEngineApp::onImportClientMessages[" + app.currserver + "]: interface(" + msgname + "/" + msgid + ") no implement!"); + handler = null; + } + else { + INFO_MSG("KBEngineApp::onImportClientMessages: import(" + msgname + ") successfully!"); + } + } + + if (msgname.length > 0) { + messages[msgname] = new Message(msgid, msgname, msglen, argtype, argstypes, handler); + + if (isClientMethod) + clientmessages[msgid] = messages[msgname]; + else + messages[app.currserver][msgid] = messages[msgname]; + } + else { + messages[app.currserver][msgid] = new Message(msgid, msgname, msglen, argtype, argstypes, handler); + } + }; + + app.onImportClientMessagesCompleted(); + } + else + ERROR_MSG("KBEngineApp::onmessage: not found msg(" + msgid + ")!"); + } + createAccount (username, password, datas) { + app.reset(); + app.username = username; + app.password = password; + app.clientdatas = datas; + + app.createAccount_loginapp(true); + } + createAccount_loginapp (noconnect) { + if (noconnect) { + INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + app.ip + ":" + app.port + "!"); + app.connect("ws://" + app.ip + ":" + app.port); + app.socket.onopen = app.onOpenLoginapp_createAccount; + } + else { + let bundle = new Bundle(); + bundle.newMessage(messages['Loginapp_reqCreateAccount']); + bundle.writeString(app.username); + bundle.writeString(app.password); + bundle.writeBlob(app.clientdatas); + bundle.send(app); + } + } + bindAccountEmail (emailAddress) { + let bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_reqAccountBindEmail']); + bundle.writeInt32(app.entity_id); + bundle.writeString(app.password); + bundle.writeString(emailAddress); + bundle.send(app); + } + newPassword (old_password, new_password) { + let bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_reqAccountNewPassword']); + bundle.writeInt32(app.entity_id); + bundle.writeString(old_password); + bundle.writeString(new_password); + bundle.send(app); + } + login (username, password, datas) { + app.reset(); + app.username = username; + app.password = password; + app.clientdatas = datas; + + app.login_loginapp(true); + } + login_loginapp (noconnect) { + if (noconnect) { + INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://" + app.ip + ":" + app.port + "!"); + app.connect("ws://" + app.ip + ":" + app.port); + app.socket.onopen = app.onOpenLoginapp_login; + } + else { + let bundle = new Bundle(); + bundle.newMessage(messages['Loginapp_login']); + bundle.writeInt8(app.args.clientType); // clientType + bundle.writeBlob(app.clientdatas); + bundle.writeString(app.username); + bundle.writeString(app.password); + bundle.send(app); + } + } + onOpenLoginapp_resetpassword () { + INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"); + app.currserver = "loginapp"; + app.currstate = "resetpassword"; + + if (!app.loginappMessageImported) { + let bundle = new Bundle(); + bundle.newMessage(messages.Loginapp_importClientMessages); + bundle.send(app); + app.socket.onmessage = app.Client_onImportClientMessages; + INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ..."); + } + else { + app.onImportClientMessagesCompleted(); + } + } + reset_password (username) { + app.reset(); + app.username = username; + app.resetpassword_loginapp(true); + } + resetpassword_loginapp (noconnect) { + if (noconnect) { + INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + app.ip + ":" + app.port + "!"); + app.connect("ws://" + app.ip + ":" + app.port); + app.socket.onopen = app.onOpenLoginapp_resetpassword; + } + else { + let bundle = new Bundle(); + bundle.newMessage(messages['Loginapp_reqAccountResetPassword']); + bundle.writeString(app.username); + bundle.send(app); + } + } + onOpenBaseapp () { + INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"); + app.currserver = "baseapp"; + + if (!app.baseappMessageImported) { + let bundle = new Bundle(); + bundle.newMessage(messages.Baseapp_importClientMessages); + bundle.send(app); + app.socket.onmessage = app.Client_onImportClientMessages; + Event.fire("Baseapp_importClientMessages"); + } + else { + app.onImportClientMessagesCompleted(); + } + } + login_baseapp (noconnect) { + if (noconnect) { + Event.fire("onLoginBaseapp"); + INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://" + app.baseappIp + ":" + app.baseappPort + "!"); + app.connect("ws://" + app.baseappIp + ":" + app.baseappPort); + + if (app.socket != undefined && app.socket != null) + app.socket.onopen = app.onOpenBaseapp; + } + else { + let bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_loginBaseapp']); + bundle.writeString(app.username); + bundle.writeString(app.password); + bundle.send(app); + } + } + reloginBaseapp () { + if (app.socket != undefined && app.socket != null) + return; + + app.resetSocket(); + Event.fire("onReloginBaseapp"); + INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://" + app.baseappIp + ":" + app.baseappPort + "!"); + app.connect("ws://" + app.baseappIp + ":" + app.baseappPort); + + if (app.socket != undefined && app.socket != null) + app.socket.onopen = app.onReOpenBaseapp; + } + onReOpenBaseapp () { + INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"); + app.currserver = "baseapp"; + + let bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_reloginBaseapp']); + bundle.writeString(app.username); + bundle.writeString(app.password); + bundle.writeUint64(app.entity_uuid); + bundle.writeInt32(app.entity_id); + bundle.send(app); + + let dateObject = new Date(); + app.lastTickCBTime = dateObject.getTime(); + } + Client_onHelloCB (args) { + app.serverVersion = args.readString(); + app.serverScriptVersion = args.readString(); + app.serverProtocolMD5 = args.readString(); + app.serverEntityDefMD5 = args.readString(); + + let ctype = args.readInt32(); + + INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo(" + app.serverVersion + "), scriptVerInfo(" + + app.serverScriptVersion + "), serverProtocolMD5(" + app.serverProtocolMD5 + "), serverEntityDefMD5(" + + app.serverEntityDefMD5 + "), ctype(" + ctype + ")!"); + + let dateObject = new Date(); + app.lastTickCBTime = dateObject.getTime(); + } + Client_onLoginFailed (args) { + let failedcode = args.readUint16(); + app.serverdatas = args.readBlob(); + ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode(" + app.serverErrs[failedcode].name + "), datas(" + app.serverdatas.length + ")!"); + Event.fire("onLoginFailed", failedcode); + } + Client_onLoginSuccessfully (args) { + let accountName = args.readString(); + app.username = accountName; + app.baseappIp = args.readString(); + app.baseappPort = args.readUint16(); + app.serverdatas = args.readBlob(); + + INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName(" + accountName + "), addr(" + + app.baseappIp + ":" + app.baseappPort + "), datas(" + app.serverdatas.length + ")!"); + + app.disconnect(); + app.login_baseapp(true); + } + Client_onLoginBaseappFailed (failedcode) { + ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode(" + app.serverErrs[failedcode].name + ")!"); + Event.fire("onLoginBaseappFailed", failedcode); + } + Client_onReloginBaseappFailed (failedcode) { + ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode(" + app.serverErrs[failedcode].name + ")!"); + Event.fire("onReloginBaseappFailed", failedcode); + } + Client_onReloginBaseappSuccessfully (stream) { + app.entity_uuid = stream.readUint64(); + DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: " + app.username); + Event.fire("onReloginBaseappSuccessfully"); + } + entityclass = {}; + getentityclass (entityType) { + let runclass = app.entityclass[entityType]; + if (runclass == undefined) { + runclass = eval("" + entityType); + if (runclass == undefined) { + ERROR_MSG("KBEngineApp::getentityclass: entityType(" + entityType + ") is error!"); + return runclass; + } + else + app.entityclass[entityType] = runclass; + } + + return runclass; + } + Client_onCreatedProxies (rndUUID, eid, entityType) { + INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid(" + eid + "), entityType(" + entityType + ")!"); + + let entity = app.entities[eid]; + + app.entity_uuid = rndUUID; + app.entity_id = eid; + + if (entity == undefined) { + let runclass = app.getentityclass(entityType); + if (runclass == undefined) + return; + + let entity = new runclass(); + entity.id = eid; + entity.className = entityType; + + entity.base = new EntityCall(); + entity.base.id = eid; + entity.base.className = entityType; + entity.base.type = ENTITYCALL_TYPE_BASE; + + app.entities[eid] = entity; + + let entityMessage = bufferedCreateEntityMessage[eid]; + if (entityMessage != undefined) { + app.Client_onUpdatePropertys(entityMessage); + delete bufferedCreateEntityMessage[eid]; + } + + entity.__init__(); + entity.inited = true; + + if (app.args.isOnInitCallPropertysSetMethods) + entity.callPropertysSetMethods(); + } + else { + let entityMessage = bufferedCreateEntityMessage[eid]; + if (entityMessage != undefined) { + app.Client_onUpdatePropertys(entityMessage); + delete bufferedCreateEntityMessage[eid]; + } + } + } + getViewEntityIDFromStream (stream) { + let id = 0; + if (app.entityIDAliasIDList.length > 255) { + id = stream.readInt32(); + } + else { + let aliasID = stream.readUint8(); + + // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 + // 则可以忽略这个错误, 因为cellapp可能一直在向baseapp发送同步消息, 当客户端重连上时未等 + // 服务端初始化步骤开始则收到同步信息, 此时这里就会出错。 + if (app.entityIDAliasIDList.length <= aliasID) + return 0; + + id = app.entityIDAliasIDList[aliasID]; + } + + return id; + } + onUpdatePropertys_ (eid, stream) { + let entity = app.entities[eid]; + + if (entity == undefined) { + let entityMessage = bufferedCreateEntityMessage[eid]; + if (entityMessage != undefined) { + ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity(" + eid + ") not found!"); + return; + } + + let stream1 = new MemoryStream(stream.buffer); + stream1.wpos = stream.wpos; + stream1.rpos = stream.rpos - 4; + bufferedCreateEntityMessage[eid] = stream1; + return; + } + + let currModule = moduledefs[entity.className]; + let pdatas = currModule.propertys; + while (stream.length() > 0) { + let utype = 0; + if (currModule.usePropertyDescrAlias) + utype = stream.readUint8(); + else + utype = stream.readUint16(); + + let propertydata = pdatas[utype]; + let setmethod = propertydata[5]; + let flags = propertydata[6]; + let val = propertydata[4].createFromStream(stream); + let oldval = entity[propertydata[2]]; + + INFO_MSG("KBEngineApp::Client_onUpdatePropertys: " + entity.className + "(id=" + eid + " " + propertydata[2] + ", val=" + val + ")!"); + + entity[propertydata[2]] = val; + if (setmethod != null) { + // base类属性或者进入世界后cell类属性会触发set_*方法 + if (flags == 0x00000020 || flags == 0x00000040) { + if (entity.inited) + setmethod.call(entity, oldval); + } + else { + if (entity.inWorld) + setmethod.call(entity, oldval); + } + } + } + } + Client_onUpdatePropertysOptimized (stream) { + let eid = app.getViewEntityIDFromStream(stream); + app.onUpdatePropertys_(eid, stream); + } + Client_onUpdatePropertys (stream) { + let eid = stream.readInt32(); + app.onUpdatePropertys_(eid, stream); + } + onRemoteMethodCall_ (eid, stream) { + let entity = app.entities[eid]; + + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); + return; + } + + let methodUtype = 0; + if (moduledefs[entity.className].useMethodDescrAlias) + methodUtype = stream.readUint8(); + else + methodUtype = stream.readUint16(); + + let methoddata = moduledefs[entity.className].methods[methodUtype]; + let args = []; + let argsdata = methoddata[3]; + for (let i = 0; i < argsdata.length; i++) { + args.push(argsdata[i].createFromStream(stream)); + } + + if (entity[methoddata[2]] != undefined) { + entity[methoddata[2]].apply(entity, args); + } + else { + ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found method(" + methoddata[2] + ")!"); + } + } + Client_onRemoteMethodCallOptimized (stream) { + let eid = app.getViewEntityIDFromStream(stream); + app.onRemoteMethodCall_(eid, stream); + } + Client_onRemoteMethodCall (stream) { + let eid = stream.readInt32(); + app.onRemoteMethodCall_(eid, stream); + } + Client_onEntityEnterWorld (stream) { + let eid = stream.readInt32(); + if (app.entity_id > 0 && eid != app.entity_id) + app.entityIDAliasIDList.push(eid) + + let entityType; + if (moduledefs['Length'] > 255) + entityType = stream.readUint16(); + else + entityType = stream.readUint8(); + + let isOnGround = true; + + if (stream.length() > 0) + isOnGround = stream.readInt8(); + + entityType = moduledefs[entityType].name; + INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: " + entityType + "(" + eid + "), spaceID(" + app.spaceID + "), isOnGround(" + isOnGround + ")!"); + + let entity = app.entities[eid]; + if (entity == undefined) { + let entityMessage = bufferedCreateEntityMessage[eid]; + if (entityMessage == undefined) { + ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity(" + eid + ") not found!"); + return; + } + + let runclass = app.getentityclass(entityType); + if (runclass == undefined) + return; + + let entity = new runclass(); + entity.id = eid; + entity.className = entityType; + + entity.cell = new EntityCall(); + entity.cell.id = eid; + entity.cell.className = entityType; + entity.cell.type = ENTITYCALL_TYPE_CELL; + + app.entities[eid] = entity; + + app.Client_onUpdatePropertys(entityMessage); + delete bufferedCreateEntityMessage[eid]; + + // entity.isOnGround = isOnGround > 0; + entity.isOnGround = isOnGround ; + entity.__init__(); + entity.inited = true; + entity.inWorld = true; + entity.enterWorld(); + + if (app.args.isOnInitCallPropertysSetMethods) + entity.callPropertysSetMethods(); + + entity.set_direction(entity.direction); + entity.set_position(entity.position); + } + else { + if (!entity.inWorld) { + entity.cell = new EntityCall(); + entity.cell.id = eid; + entity.cell.className = entityType; + entity.cell.type = ENTITYCALL_TYPE_CELL; + + // 安全起见, 这里清空一下 + // 如果服务端上使用giveClientTo切换控制权 + // 之前的实体已经进入世界, 切换后的实体也进入世界, 这里可能会残留之前那个实体进入世界的信息 + app.entityIDAliasIDList = []; + app.entities = {} + app.entities[entity.id] = entity; + + entity.set_direction(entity.direction); + entity.set_position(entity.position); + + app.entityServerPos.x = entity.position.x; + app.entityServerPos.y = entity.position.y; + app.entityServerPos.z = entity.position.z; + + entity.isOnGround = isOnGround ; + // entity.isOnGround = isOnGround > 0; + + entity.inWorld = true; + entity.enterWorld(); + + if (app.args.isOnInitCallPropertysSetMethods) + entity.callPropertysSetMethods(); + } + } + } + Client_onEntityLeaveWorldOptimized (stream) { + let eid = app.getViewEntityIDFromStream(stream); + app.Client_onEntityLeaveWorld(eid); + } + Client_onEntityLeaveWorld (eid) { + let entity = app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity(" + eid + ") not found!"); + return; + } + + if (entity.inWorld) + entity.leaveWorld(); + + if (app.entity_id > 0 && eid != app.entity_id) { + let newArray0 = []; + + for (let i = 0; i < app.controlledEntities.length; i++) { + if (app.controlledEntities[i] != eid) { + newArray0.push(app.controlledEntities[i]); + } + else { + Event.fire("onLoseControlledEntity"); + } + } + + app.controlledEntities = newArray0 + + delete app.entities[eid]; + + let newArray = []; + for (let i = 0; i < app.entityIDAliasIDList.length; i++) { + if (app.entityIDAliasIDList[i] != eid) { + newArray.push(app.entityIDAliasIDList[i]); + } + } + + app.entityIDAliasIDList = newArray + } + else { + app.clearSpace(false); + entity.cell = null; + } + } + Client_onEntityDestroyed (eid) { + INFO_MSG("KBEngineApp::Client_onEntityDestroyed: entity(" + eid + ")!"); + + let entity = app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onEntityDestroyed: entity(" + eid + ") not found!"); + return; + } + + if (entity.inWorld) { + if (app.entity_id == eid) + app.clearSpace(false); + + entity.leaveWorld(); + } + + delete app.entities[eid]; + } + Client_onEntityEnterSpace (stream) { + let eid = stream.readInt32(); + app.spaceID = stream.readUint32(); + let isOnGround = true; + + if (stream.length() > 0) + isOnGround = stream.readInt8(); + + let entity = app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity(" + eid + ") not found!"); + return; + } + + entity.isOnGround = isOnGround; + app.entityServerPos.x = entity.position.x; + app.entityServerPos.y = entity.position.y; + app.entityServerPos.z = entity.position.z; + entity.enterSpace(); + } + Client_onEntityLeaveSpace (eid) { + let entity = app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity(" + eid + ") not found!"); + return; + } + + app.clearSpace(false); + entity.leaveSpace(); + } + Client_onKicked (failedcode) { + ERROR_MSG("KBEngineApp::Client_onKicked: failedcode(" + app.serverErrs[failedcode].name + ")!"); + Event.fire("onKicked", failedcode); + } + Client_onCreateAccountResult (stream) { + let retcode = stream.readUint16(); + let datas = stream.readBlob(); + + Event.fire("onCreateAccountResult", retcode, datas); + + if (retcode != 0) { + ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: " + app.username + " create is failed! code=" + app.serverErrs[retcode].name + "!"); + return; + } + + INFO_MSG("KBEngineApp::Client_onCreateAccountResult: " + app.username + " create is successfully!"); + } + Client_onControlEntity (eid, isControlled) { + // eid = stream.readInt32(); + let entity = app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onControlEntity: entity(" + eid + ") not found!"); + return; + } + + let isCont = isControlled != 0; + if (isCont) { + // 如果被控制者是玩家自己,那表示玩家自己被其它人控制了 + // 所以玩家自己不应该进入这个被控制列表 + if (app.player().id != entity.id) { + app.controlledEntities.push(entity) + } + } + else { + let newArray = []; + + for (let i = 0; i < app.controlledEntities.length; i++) + if (app.controlledEntities[i] != entity.id) + newArray.push(app.controlledEntities[i]); + + app.controlledEntities = newArray + } + + entity.isControlled = isCont; + + try { + entity.onControlled(isCont); + Event.fire("onControlled", entity, isCont); + } + catch (e) { + ERROR_MSG("KBEngine::Client_onControlEntity: entity id = '" + eid + "', is controlled = '" + isCont + "', error = '" + e + "'"); + } + } + updatePlayerToServer () { + let player = app.player(); + if (player == undefined || player.inWorld == false || app.spaceID == 0 || player.isControlled) + return; + + if (player.entityLastLocalPos.distance(player.position) > 0.001 || player.entityLastLocalDir.distance(player.direction) > 0.001) { + // 记录玩家最后一次上报位置时自身当前的位置 + player.entityLastLocalPos.x = player.position.x; + player.entityLastLocalPos.y = player.position.y; + player.entityLastLocalPos.z = player.position.z; + player.entityLastLocalDir.x = player.direction.x; + player.entityLastLocalDir.y = player.direction.y; + player.entityLastLocalDir.z = player.direction.z; + + let bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_onUpdateDataFromClient']); + bundle.writeFloat(player.position.x); + bundle.writeFloat(player.position.y); + bundle.writeFloat(player.position.z); + bundle.writeFloat(player.direction.x); + bundle.writeFloat(player.direction.y); + bundle.writeFloat(player.direction.z); + bundle.writeUint8(player.isOnGround); + bundle.writeUint32(app.spaceID); + bundle.send(app); + } + + // 开始同步所有被控制了的entity的位置 + for (let i in app.controlledEntities) { + let entity = app.controlledEntities[i]; + let position = entity.position; + let direction = entity.direction; + + let posHasChanged = entity.entityLastLocalPos.distance(position) > 0.001; + let dirHasChanged = entity.entityLastLocalDir.distance(direction) > 0.001; + + if (posHasChanged || dirHasChanged) { + entity.entityLastLocalPos = position; + entity.entityLastLocalDir = direction; + + let bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_onUpdateDataFromClientForControlledEntity']); + bundle.writeInt32(entity.id); + bundle.writeFloat(position.x); + bundle.writeFloat(position.y); + bundle.writeFloat(position.z); + + bundle.writeFloat(direction.x); + bundle.writeFloat(direction.y); + bundle.writeFloat(direction.z); + bundle.writeUint8(entity.isOnGround); + bundle.writeUint32(app.spaceID); + bundle.send(app); + } + } + } + addSpaceGeometryMapping (spaceID, respath) { + INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID(" + spaceID + "), respath(" + respath + ")!"); + + app.spaceID = spaceID; + app.spaceResPath = respath; + Event.fire("addSpaceGeometryMapping", respath); + } + clearSpace (isAll) { + app.entityIDAliasIDList = []; + app.spacedata = {}; + app.clearEntities(isAll); + app.isLoadedGeometry = false; + app.spaceID = 0; + } + clearEntities (isAll) { + app.controlledEntities = [] + + if (!isAll) { + let entity = app.player(); + + for (let eid in app.entities) { + if (eid == entity.id) + continue; + + if (app.entities[eid].inWorld) { + app.entities[eid].leaveWorld(); + } + + app.entities[eid].onDestroy(); + } + + app.entities = {} + app.entities[entity.id] = entity; + } + else { + for (let eid in app.entities) { + if (app.entities[eid].inWorld) { + app.entities[eid].leaveWorld(); + } + + app.entities[eid].onDestroy(); + } + + app.entities = {} + } + } + Client_initSpaceData (stream) { + app.clearSpace(false); + + app.spaceID = stream.readInt32(); + while (stream.length() > 0) { + let key = stream.readString(); + let value = stream.readString(); + app.Client_setSpaceData(app.spaceID, key, value); + } + + INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID(" + app.spaceID + "), datas(" + app.spacedata + ")!"); + } + Client_setSpaceData (spaceID, key, value) { + INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID(" + spaceID + "), key(" + key + "), value(" + value + ")!"); + + app.spacedata[key] = value; + + if (key == "_mapping") + app.addSpaceGeometryMapping(spaceID, value); + + Event.fire("onSetSpaceData", spaceID, key, value); + } + Client_delSpaceData (spaceID, key) { + INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID(" + spaceID + "), key(" + key + ")!"); + + delete app.spacedata[key]; + Event.fire("onDelSpaceData", spaceID, key); + } + Client_getSpaceData (spaceID, key) { + return app.spacedata[key]; + } + Client_onUpdateBasePos (x, y, z) { + app.entityServerPos.x = x; + app.entityServerPos.y = y; + app.entityServerPos.z = z; + } + Client_onUpdateBasePosXZ (x, z) { + app.entityServerPos.x = x; + app.entityServerPos.z = z; + } + Client_onUpdateData (stream) { + let eid = app.getViewEntityIDFromStream(stream); + let entity = app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onUpdateData: entity(" + eid + ") not found!"); + return; + } + } + Client_onSetEntityPosAndDir (stream) { + let eid = stream.readInt32(); + let entity = app.entities[eid]; + if (entity == undefined) { + ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity(" + eid + ") not found!"); + return; + } + + entity.position.x = stream.readFloat(); + entity.position.y = stream.readFloat(); + entity.position.z = stream.readFloat(); + entity.direction.x = stream.readFloat(); + entity.direction.y = stream.readFloat(); + entity.direction.z = stream.readFloat(); + + // 记录玩家最后一次上报位置时自身当前的位置 + entity.entityLastLocalPos.x = entity.position.x; + entity.entityLastLocalPos.y = entity.position.y; + entity.entityLastLocalPos.z = entity.position.z; + entity.entityLastLocalDir.x = entity.direction.x; + entity.entityLastLocalDir.y = entity.direction.y; + entity.entityLastLocalDir.z = entity.direction.z; + + entity.set_direction(entity.direction); + entity.set_position(entity.position); + } + Client_onUpdateData_ypr (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let y = stream.readInt8(); + let p = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, p, r, -1); + } + Client_onUpdateData_yp (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let y = stream.readInt8(); + let p = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, p, KBE_FLT_MAX, -1); + } + Client_onUpdateData_yr (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let y = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, KBE_FLT_MAX, r, -1); + } + Client_onUpdateData_pr (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let p = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, p, r, -1); + } + Client_onUpdateData_y (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let y = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, KBE_FLT_MAX, KBE_FLT_MAX, -1); + } + Client_onUpdateData_p (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let p = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, p, KBE_FLT_MAX, -1); + } + Client_onUpdateData_r (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let r = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, r, -1); + } + Client_onUpdateData_xz (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, 1); + } + Client_onUpdateData_xz_ypr (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + + let y = stream.readInt8(); + let p = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, p, r, 1); + } + Client_onUpdateData_xz_yp (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + + let y = stream.readInt8(); + let p = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, p, KBE_FLT_MAX, 1); + } + Client_onUpdateData_xz_yr (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + + let y = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, KBE_FLT_MAX, r, 1); + } + Client_onUpdateData_xz_pr (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + + let p = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, p, r, 1); + } + Client_onUpdateData_xz_y (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + + let y = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, KBE_FLT_MAX, KBE_FLT_MAX, 1); + } + Client_onUpdateData_xz_p (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + + let p = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, p, KBE_FLT_MAX, 1); + } + Client_onUpdateData_xz_r (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + + let r = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, r, 1); + } + Client_onUpdateData_xyz (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + let y = stream.readPackY(); + + app._updateVolatileData(eid, xz[0], y, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, 0); + } + Client_onUpdateData_xyz_ypr (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + let y = stream.readPackY(); + + let yaw = stream.readInt8(); + let p = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, r, 0); + } + Client_onUpdateData_xyz_yp (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + let y = stream.readPackY(); + + let yaw = stream.readInt8(); + let p = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, KBE_FLT_MAX, 0); + } + Client_onUpdateData_xyz_yr (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + let y = stream.readPackY(); + + let yaw = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBE_FLT_MAX, r, 0); + } + Client_onUpdateData_xyz_pr (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + let y = stream.readPackY(); + + let p = stream.readInt8(); + let r = stream.readInt8(); + + ERROR_MSG('调用错误方法,无法找到x,z'); + //todo 这个是手动注释,如果错误再修改 + // app._updateVolatileData(eid, x, y, z, KBE_FLT_MAX, p, r, 0); + } + Client_onUpdateData_xyz_y (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + let y = stream.readPackY(); + + let yaw = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBE_FLT_MAX, KBE_FLT_MAX, 0); + } + Client_onUpdateData_xyz_p (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + let y = stream.readPackY(); + + let p = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], y, xz[1], KBE_FLT_MAX, p, KBE_FLT_MAX, 0); + } + Client_onUpdateData_xyz_r (stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + let y = stream.readPackY(); + //todo 这个是自己加的,如果错误再修改 + let r = stream.readInt8(); + + let p = stream.readInt8(); + + app._updateVolatileData(eid, xz[0], y, xz[1], r, KBE_FLT_MAX, KBE_FLT_MAX, 0); + } + _updateVolatileData (entityID, x, y, z, yaw, pitch, roll, isOnGround) { + let entity = app.entities[entityID]; + if (entity == undefined) { + // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 + // 则可以忽略这个错误, 因为cellapp可能一直在向baseapp发送同步消息, 当客户端重连上时未等 + // 服务端初始化步骤开始则收到同步信息, 此时这里就会出错。 + ERROR_MSG("KBEngineApp::_updateVolatileData: entity(" + entityID + ") not found!"); + return; + } + + // 小于0不设置 + if (isOnGround >= 0) { + entity.isOnGround = (isOnGround > 0); + } + + let changeDirection = false; + + if (roll != KBE_FLT_MAX) { + changeDirection = true; + entity.direction.x = int82angle(roll, false); + } + + if (pitch != KBE_FLT_MAX) { + changeDirection = true; + entity.direction.y = int82angle(pitch, false); + } + + if (yaw != KBE_FLT_MAX) { + changeDirection = true; + entity.direction.z = int82angle(yaw, false); + } + + let done = false; + if (changeDirection == true) { + Event.fire("set_direction", entity); + done = true; + } + + let positionChanged = false; + if (x != KBE_FLT_MAX || y != KBE_FLT_MAX || z != KBE_FLT_MAX) + positionChanged = true; + + if (x == KBE_FLT_MAX) x = 0.0; + if (y == KBE_FLT_MAX) y = 0.0; + if (z == KBE_FLT_MAX) z = 0.0; + + if (positionChanged) { + entity.position.x = x + app.entityServerPos.x; + entity.position.y = y + app.entityServerPos.y; + entity.position.z = z + app.entityServerPos.z; + + done = true; + Event.fire("updatePosition", entity); + } + + if (done) + entity.onUpdateVolatileData(); + } + Client_onStreamDataStarted (id, datasize, descr) { + Event.fire("onStreamDataStarted", id, datasize, descr); + } + Client_onStreamDataRecv (stream) { + let id = stream.readUint16(); + let data = stream.readBlob(); + Event.fire("onStreamDataRecv", id, data); + } + Client_onStreamDataCompleted (id) { + Event.fire("onStreamDataCompleted", id); + } + Client_onReqAccountResetPasswordCB (failedcode) { + if (failedcode != 0) { + ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: " + app.username + " is failed! code=" + app.serverErrs[failedcode].name + "!"); + return; + } + + INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: " + app.username + " is successfully!"); + } + Client_onReqAccountBindEmailCB (failedcode) { + if (failedcode != 0) { + ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: " + app.username + " is failed! code=" + app.serverErrs[failedcode].name + "!"); + return; + } + + INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: " + app.username + " is successfully!"); + } + Client_onReqAccountNewPasswordCB (failedcode) { + if (failedcode != 0) { + ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: " + app.username + " is failed! code=" + app.serverErrs[failedcode].name + "!"); + return; + } + + INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: " + app.username + " is successfully!"); + } + } + // 描述服务端返回的错误信息 + export class ServerErr { + name = ""; + descr = ""; + id = 0; + } + export let app: KBEngineApp; + let idInterval; + export function create(args: KBEngineArgs) { + if (app != undefined) + return; + + if (args.constructor != KBEngineArgs) { + ERROR_MSG("create(): args(" + args + ") error! not is KBEngineArgs"); + return; + } + + new KBEngineApp(args); + + app.reset(); + app.installEvents(); + idInterval = setInterval(app.update, args.updateHZ); + } + export function destroy() { + if (idInterval != undefined) + clearInterval(idInterval); + + if (app == undefined) + return; + + app.uninstallEvents(); + app.reset(); + app = undefined; + } +} \ No newline at end of file diff --git a/kbengine_ts/tsconfig.json b/kbengine_ts/tsconfig.json new file mode 100644 index 0000000..cc5f009 --- /dev/null +++ b/kbengine_ts/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "es5", + "noImplicitAny": false, + "sourceMap": false, + "declaration": true, + "outFile": "bin/kbengine.js" + }, + "include": [ + "src" + ] +} \ No newline at end of file From 6c931fc01e68d6e0c05c9803330ed28ba78765a7 Mon Sep 17 00:00:00 2001 From: oblivion <761458545@qq.com> Date: Thu, 29 Mar 2018 21:21:43 +0800 Subject: [PATCH 02/17] bug fix --- kbengine_ts/src/KBEngine.ts | 181 +++++++++++++++++++----------------- 1 file changed, 97 insertions(+), 84 deletions(-) diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index 3540209..d9faa68 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -4,13 +4,10 @@ * 缺少测试 * 缺少类型Vector2,Vector4,暂时修改为Vector3,如果出问题再修改 */ +/*----------------------------------------------------------------------------------------- + global +-----------------------------------------------------------------------------------------*/ namespace KBEngine { - export class Class { - - } - /*----------------------------------------------------------------------------------------- - global - -----------------------------------------------------------------------------------------*/ export const PACKET_MAX_SIZE = 1500; export const PACKET_MAX_SIZE_TCP = 1460; export const PACKET_MAX_SIZE_UDP = 1472; @@ -20,9 +17,11 @@ namespace KBEngine { export const CLIENT_NO_FLOAT = 0; export const KBE_FLT_MAX = 3.402823466e+38; - /*----------------------------------------------------------------------------------------- +} +/*----------------------------------------------------------------------------------------- number64bits - -----------------------------------------------------------------------------------------*/ +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { export class INT64 { constructor(lo, hi) { this.lo = lo; @@ -86,9 +85,11 @@ namespace KBEngine { return result; } } - /*----------------------------------------------------------------------------------------- - debug - -----------------------------------------------------------------------------------------*/ +} +/*----------------------------------------------------------------------------------------- + debug +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { export function INFO_MSG(s) { console.info(s); } @@ -101,10 +102,11 @@ namespace KBEngine { export function WARNING_MSG(s) { console.warn(s); } - - /*----------------------------------------------------------------------------------------- - string - -----------------------------------------------------------------------------------------*/ +} +/*----------------------------------------------------------------------------------------- + string +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { export function utf8ArrayToString(array: Array) { let out, i, len, c; let char2, char3; @@ -169,10 +171,12 @@ namespace KBEngine { } return utf8; } +} - /*----------------------------------------------------------------------------------------- - event - -----------------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------------------- + event +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { export class EventInfo { constructor(classinst, callbackfn) { this.callbackfn = callbackfn; @@ -190,7 +194,7 @@ namespace KBEngine { } _events: IEvents = {}; register(evtName: string, classinst, strCallback: string) { - let callbackfn = eval("classinst." + strCallback); + let callbackfn = classinst[strCallback]; if (callbackfn == undefined) { ERROR_MSG('export class Event::fire: not found strCallback(' + classinst + ")!" + strCallback); return; @@ -205,7 +209,7 @@ namespace KBEngine { let info = new EventInfo(classinst, callbackfn); evtlst.push(info); } - deregister(evtName, classinst) { + deregister(evtName:string, classinst) { for (let itemkey in this._events) { let evtlst = this._events[itemkey]; while (true) { @@ -224,7 +228,7 @@ namespace KBEngine { } } } - fire(evtName, ...args) { + fire(evtName:string, ...args:any[]) { if (arguments.length < 1) { ERROR_MSG('export class Event::fire: not found eventName!'); return; @@ -236,26 +240,28 @@ namespace KBEngine { return; } - let ars = []; - for (let i = 1; i < args.length; i++) - ars.push(args[i]); + // let ars = []; + // for (let i = 0; i < args.length; i++) + // ars.push(args[i]); for (let i = 0; i < evtlst.length; i++) { let info = evtlst[i]; - if (ars.length < 1) { - info.callbackfn.apply(info.classinst); - } - else { - info.callbackfn.apply(info.classinst, ars); - } + info.callbackfn.apply(info.classinst, args || []); + // if (args.length < 1) { + // info.callbackfn.apply(info.classinst); + // } + // else { + // info.callbackfn.apply(info.classinst, args); + // } } } } export const Event = new Events(); - - /*----------------------------------------------------------------------------------------- - memorystream - -----------------------------------------------------------------------------------------*/ +} +/*----------------------------------------------------------------------------------------- + memorystream +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { export class MemoryStream { constructor(size_or_buffer) { if (size_or_buffer instanceof ArrayBuffer) { @@ -581,10 +587,11 @@ namespace KBEngine { }; } } - - /*----------------------------------------------------------------------------------------- - bundle - -----------------------------------------------------------------------------------------*/ +} +/*----------------------------------------------------------------------------------------- + bundle +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { export class Bundle { constructor() { this.stream = new MemoryStream(PACKET_MAX_SIZE_TCP); @@ -592,7 +599,7 @@ namespace KBEngine { memorystreams: Array = new Array(); stream: MemoryStream; numMessage: number = 0; - messageLengthBuffer = null; + messageLengthBuffer:Uint8Array = null; msgtype = null; messageLength: number = 0; //--------------------------------------------------------------------------------- @@ -897,13 +904,14 @@ namespace KBEngine { } export let clientmessages = {}; export let bufferedCreateEntityMessage = {}; - - /*----------------------------------------------------------------------------------------- - math - -----------------------------------------------------------------------------------------*/ - export class Vector3 extends Class { +} +/*----------------------------------------------------------------------------------------- + math +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { + export class Vector3 { constructor(x, y, z) { - super(); + this.x = x; this.y = y; this.z = z; @@ -941,12 +949,17 @@ namespace KBEngine { return angle; } - /*----------------------------------------------------------------------------------------- - entity - -----------------------------------------------------------------------------------------*/ - export class Entity extends Class { +} +/*----------------------------------------------------------------------------------------- + entity +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { + export namespace Entities { + + } + export class Entity { constructor() { - super(); + } id: number = 0; className: string = ""; @@ -1167,10 +1180,11 @@ namespace KBEngine { Event.fire("set_direction", this); } } - - /*----------------------------------------------------------------------------------------- - EntityCall - -----------------------------------------------------------------------------------------*/ +} +/*----------------------------------------------------------------------------------------- + EntityCall +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { export const ENTITYCALL_TYPE_CELL = 0; export const ENTITYCALL_TYPE_BASE = 1; @@ -1213,7 +1227,6 @@ namespace KBEngine { this.bundle = null; } } - export const moduledefs = {}; export class DATATYPE_UINT8 { bind () { @@ -1780,15 +1793,18 @@ namespace KBEngine { export const ENTITYCALL = new DATATYPE_ENTITYCALL(); export const BLOB = new DATATYPE_BLOB(); }; - - /*----------------------------------------------------------------------------------------- - KBEngine args - -----------------------------------------------------------------------------------------*/ +} +/*----------------------------------------------------------------------------------------- + KBEngine args +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { export class KBEngineArgs { ip = '127.0.0.1'; port = 20013; updateHZ = 100; serverHeartbeatTick = 15; + + protocol:string = "ws://"; // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types clientType = 5; @@ -1796,10 +1812,12 @@ namespace KBEngine { // 在Entity初始化时是否触发属性的set_*事件(callPropertysSetMethods) isOnInitCallPropertysSetMethods = true; } - - /*----------------------------------------------------------------------------------------- - KBEngine app - -----------------------------------------------------------------------------------------*/ +} +/*----------------------------------------------------------------------------------------- + KBEngine app +-----------------------------------------------------------------------------------------*/ +namespace KBEngine { + export const moduledefs = {}; export class KBEngineApp { constructor(args: KBEngineArgs) { console.assert(app == null || app == undefined, "Assertion of app not is null"); @@ -1821,9 +1839,9 @@ namespace KBEngine { serverErrs: { [err: string]: ServerErr } = {}; - // 登录loginapp的地址 - ip: string; - port: number; + // // 登录loginapp的地址 + // ip: string; + // port: number; // 服务端分配的baseapp地址 baseappIP = ''; @@ -2271,7 +2289,7 @@ namespace KBEngine { let self_cell_methods = currModuleDefs["cell_methods"]; try { - let Class = eval("" + scriptmodule_name); + var Class = Entities[scriptmodule_name]; } catch (e) { let Class = undefined; @@ -2375,7 +2393,7 @@ namespace KBEngine { }; let defmethod try { - defmethod = eval("" + scriptmodule_name); + defmethod = Entities[scriptmodule_name]; } catch (e) { ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module(" + scriptmodule_name + ") not found!"); @@ -2489,8 +2507,8 @@ namespace KBEngine { } createAccount_loginapp (noconnect) { if (noconnect) { - INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + app.ip + ":" + app.port + "!"); - app.connect("ws://" + app.ip + ":" + app.port); + INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + app.args.ip + ":" + app.args.port + "!"); + app.connect(app.args.protocol + app.args.ip + ":" + app.args.port); app.socket.onopen = app.onOpenLoginapp_createAccount; } else { @@ -2528,8 +2546,8 @@ namespace KBEngine { } login_loginapp (noconnect) { if (noconnect) { - INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://" + app.ip + ":" + app.port + "!"); - app.connect("ws://" + app.ip + ":" + app.port); + INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://" + app.args.ip + ":" + app.args.port + "!"); + app.connect(app.args.protocol + app.args.ip + ":" + app.args.port); app.socket.onopen = app.onOpenLoginapp_login; } else { @@ -2565,8 +2583,8 @@ namespace KBEngine { } resetpassword_loginapp (noconnect) { if (noconnect) { - INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + app.ip + ":" + app.port + "!"); - app.connect("ws://" + app.ip + ":" + app.port); + INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + app.args.ip + ":" + app.args.port + "!"); + app.connect(app.args.protocol + app.args.ip + ":" + app.args.port); app.socket.onopen = app.onOpenLoginapp_resetpassword; } else { @@ -2595,7 +2613,7 @@ namespace KBEngine { if (noconnect) { Event.fire("onLoginBaseapp"); INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://" + app.baseappIp + ":" + app.baseappPort + "!"); - app.connect("ws://" + app.baseappIp + ":" + app.baseappPort); + app.connect(app.args.protocol + app.baseappIp + ":" + app.baseappPort); if (app.socket != undefined && app.socket != null) app.socket.onopen = app.onOpenBaseapp; @@ -2615,7 +2633,7 @@ namespace KBEngine { app.resetSocket(); Event.fire("onReloginBaseapp"); INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://" + app.baseappIp + ":" + app.baseappPort + "!"); - app.connect("ws://" + app.baseappIp + ":" + app.baseappPort); + app.connect(app.args.protocol + app.baseappIp + ":" + app.baseappPort); if (app.socket != undefined && app.socket != null) app.socket.onopen = app.onReOpenBaseapp; @@ -2684,15 +2702,10 @@ namespace KBEngine { } entityclass = {}; getentityclass (entityType) { - let runclass = app.entityclass[entityType]; + let runclass = Entities[entityType]; if (runclass == undefined) { - runclass = eval("" + entityType); - if (runclass == undefined) { - ERROR_MSG("KBEngineApp::getentityclass: entityType(" + entityType + ") is error!"); - return runclass; - } - else - app.entityclass[entityType] = runclass; + ERROR_MSG("KBEngineApp::getentityclass: entityType(" + entityType + ") is error!"); + return runclass; } return runclass; From acb2f1cc832606702a2a34ede2cc02780c9cfb72 Mon Sep 17 00:00:00 2001 From: zengmn <761458545@qq.com> Date: Wed, 4 Apr 2018 09:27:14 +0800 Subject: [PATCH 03/17] build --- kbengine_ts/bin/kbengine.d.ts | 44 ++- kbengine_ts/bin/kbengine.js | 590 ++++++++++++++++---------------- kbengine_ts/bin/kbengine.min.js | 6 +- 3 files changed, 338 insertions(+), 302 deletions(-) diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index 9cb7228..d610138 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -1,9 +1,10 @@ /** * KBEngine的html5客户端扩展ts版 + * todo 类型匹配未完善 + * 缺少测试 + * 缺少类型Vector2,Vector4,暂时修改为Vector3,如果出问题再修改 */ declare namespace KBEngine { - class Class { - } const PACKET_MAX_SIZE = 1500; const PACKET_MAX_SIZE_TCP = 1460; const PACKET_MAX_SIZE_UDP = 1472; @@ -11,6 +12,8 @@ declare namespace KBEngine { const MESSAGE_LENGTH_LENGTH = 2; const CLIENT_NO_FLOAT = 0; const KBE_FLT_MAX = 3.402823466e+38; +} +declare namespace KBEngine { class INT64 { constructor(lo: any, hi: any); lo: number; @@ -24,12 +27,18 @@ declare namespace KBEngine { hi: number; toString(): string; } +} +declare namespace KBEngine { function INFO_MSG(s: any): void; function DEBUG_MSG(s: any): void; function ERROR_MSG(s: any): void; function WARNING_MSG(s: any): void; +} +declare namespace KBEngine { function utf8ArrayToString(array: Array): any; function stringToUTF8Bytes(str: string): any[]; +} +declare namespace KBEngine { class EventInfo { constructor(classinst: any, callbackfn: any); classinst: any; @@ -42,10 +51,12 @@ declare namespace KBEngine { constructor(); _events: IEvents; register(evtName: string, classinst: any, strCallback: string): void; - deregister(evtName: any, classinst: any): void; - fire(evtName: any, ...args: any[]): void; + deregister(evtName: string, classinst: any): void; + fire(evtName: string, ...args: any[]): void; } const Event: Events; +} +declare namespace KBEngine { class MemoryStream { constructor(size_or_buffer: any); buffer: ArrayBuffer; @@ -94,12 +105,14 @@ declare namespace KBEngine { constructor(); } } +} +declare namespace KBEngine { class Bundle { constructor(); memorystreams: Array; stream: MemoryStream; numMessage: number; - messageLengthBuffer: any; + messageLengthBuffer: Uint8Array; msgtype: any; messageLength: number; newMessage(msgtype: any): void; @@ -149,7 +162,9 @@ declare namespace KBEngine { } let clientmessages: {}; let bufferedCreateEntityMessage: {}; - class Vector3 extends Class { +} +declare namespace KBEngine { + class Vector3 { constructor(x: any, y: any, z: any); x: number; y: number; @@ -159,7 +174,11 @@ declare namespace KBEngine { function clampf(value: any, min_inclusive: any, max_inclusive: any): any; function int82angle(angle: any, half: any): number; function angle2int8(v: number, half: boolean): number; - class Entity extends Class { +} +declare namespace KBEngine { + module Entities { + } + class Entity { constructor(); id: number; className: string; @@ -193,6 +212,8 @@ declare namespace KBEngine { onUpdateVolatileData(): void; set_direction(old: any): void; } +} +declare namespace KBEngine { const ENTITYCALL_TYPE_CELL = 0; const ENTITYCALL_TYPE_BASE = 1; class EntityCall { @@ -207,7 +228,6 @@ declare namespace KBEngine { newCall(): any; sendCall(bundle: any): void; } - const moduledefs: {}; class DATATYPE_UINT8 { bind(): void; createFromStream(stream: any): any; @@ -368,14 +388,20 @@ declare namespace KBEngine { const ENTITYCALL: DATATYPE_ENTITYCALL; const BLOB: DATATYPE_BLOB; } +} +declare namespace KBEngine { class KBEngineArgs { ip: string; port: number; updateHZ: number; serverHeartbeatTick: number; + protocol: string; clientType: number; isOnInitCallPropertysSetMethods: boolean; } +} +declare namespace KBEngine { + const moduledefs: {}; class KBEngineApp { constructor(args: KBEngineArgs); args: KBEngineArgs; @@ -391,8 +417,6 @@ declare namespace KBEngine { serverErrs: { [err: string]: ServerErr; }; - ip: string; - port: number; baseappIP: string; baseappPort: number; socket: any; diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index 4b216c0..2c77051 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -10,19 +10,15 @@ r.prototype = e.prototype, t.prototype = new r(); }; /** * KBEngine的html5客户端扩展ts版 + * todo 类型匹配未完善 + * 缺少测试 + * 缺少类型Vector2,Vector4,暂时修改为Vector3,如果出问题再修改 */ +/*----------------------------------------------------------------------------------------- + global +-----------------------------------------------------------------------------------------*/ var KBEngine; (function (KBEngine) { - var Class = (function () { - function Class() { - } - return Class; - }()); - KBEngine.Class = Class; - __reflect(Class.prototype, "KBEngine.Class"); - /*----------------------------------------------------------------------------------------- - global - -----------------------------------------------------------------------------------------*/ KBEngine.PACKET_MAX_SIZE = 1500; KBEngine.PACKET_MAX_SIZE_TCP = 1460; KBEngine.PACKET_MAX_SIZE_UDP = 1472; @@ -30,9 +26,11 @@ var KBEngine; KBEngine.MESSAGE_LENGTH_LENGTH = 2; KBEngine.CLIENT_NO_FLOAT = 0; KBEngine.KBE_FLT_MAX = 3.402823466e+38; - /*----------------------------------------------------------------------------------------- +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- number64bits - -----------------------------------------------------------------------------------------*/ +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { var INT64 = (function () { function INT64(lo, hi) { this.sign = 1; @@ -92,9 +90,11 @@ var KBEngine; }()); KBEngine.UINT64 = UINT64; __reflect(UINT64.prototype, "KBEngine.UINT64"); - /*----------------------------------------------------------------------------------------- - debug - -----------------------------------------------------------------------------------------*/ +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + debug +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { function INFO_MSG(s) { console.info(s); } @@ -111,9 +111,11 @@ var KBEngine; console.warn(s); } KBEngine.WARNING_MSG = WARNING_MSG; - /*----------------------------------------------------------------------------------------- - string - -----------------------------------------------------------------------------------------*/ +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + string +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { function utf8ArrayToString(array) { var out, i, len, c; var char2, char3; @@ -178,9 +180,11 @@ var KBEngine; return utf8; } KBEngine.stringToUTF8Bytes = stringToUTF8Bytes; - /*----------------------------------------------------------------------------------------- - event - -----------------------------------------------------------------------------------------*/ +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + event +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { var EventInfo = (function () { function EventInfo(classinst, callbackfn) { this.callbackfn = callbackfn; @@ -195,9 +199,9 @@ var KBEngine; this._events = {}; } Events.prototype.register = function (evtName, classinst, strCallback) { - var callbackfn = eval("classinst." + strCallback); + var callbackfn = classinst[strCallback]; if (callbackfn == undefined) { - ERROR_MSG('export class Event::fire: not found strCallback(' + classinst + ")!" + strCallback); + KBEngine.ERROR_MSG('export class Event::fire: not found strCallback(' + classinst + ")!" + strCallback); return; } var evtlst = this._events[evtName]; @@ -232,24 +236,25 @@ var KBEngine; args[_i - 1] = arguments[_i]; } if (arguments.length < 1) { - ERROR_MSG('export class Event::fire: not found eventName!'); + KBEngine.ERROR_MSG('export class Event::fire: not found eventName!'); return; } var evtlst = this._events[evtName]; if (evtlst == undefined) { return; } - var ars = []; - for (var i = 1; i < args.length; i++) - ars.push(args[i]); + // let ars = []; + // for (let i = 0; i < args.length; i++) + // ars.push(args[i]); for (var i = 0; i < evtlst.length; i++) { var info = evtlst[i]; - if (ars.length < 1) { - info.callbackfn.apply(info.classinst); - } - else { - info.callbackfn.apply(info.classinst, ars); - } + info.callbackfn.apply(info.classinst, args || []); + // if (args.length < 1) { + // info.callbackfn.apply(info.classinst); + // } + // else { + // info.callbackfn.apply(info.classinst, args); + // } } }; return Events; @@ -257,9 +262,11 @@ var KBEngine; KBEngine.Events = Events; __reflect(Events.prototype, "KBEngine.Events"); KBEngine.Event = new Events(); - /*----------------------------------------------------------------------------------------- - memorystream - -----------------------------------------------------------------------------------------*/ +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + memorystream +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { var MemoryStream = (function () { function MemoryStream(size_or_buffer) { this.rpos = 0; @@ -292,7 +299,7 @@ var KBEngine; return v; }; MemoryStream.prototype.readInt64 = function () { - return new INT64(this.readUint32(), this.readUint32()); + return new KBEngine.INT64(this.readUint32(), this.readUint32()); }; MemoryStream.prototype.readUint8 = function () { var buf = new Uint8Array(this.buffer, this.rpos, 1); @@ -310,7 +317,7 @@ var KBEngine; return (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0]; }; MemoryStream.prototype.readUint64 = function () { - return new UINT64(this.readUint32(), this.readUint32()); + return new KBEngine.UINT64(this.readUint32(), this.readUint32()); }; MemoryStream.prototype.readFloat = function () { var buf; @@ -460,7 +467,7 @@ var KBEngine; MemoryStream.prototype.writeBlob = function (v) { var size = v.length; if (size + 4 > this.space()) { - ERROR_MSG("memorystream::writeBlob: no free!"); + KBEngine.ERROR_MSG("memorystream::writeBlob: no free!"); return; } this.writeUint32(size); @@ -479,7 +486,7 @@ var KBEngine; }; MemoryStream.prototype.writeString = function (v) { if (v.length > this.space()) { - ERROR_MSG("memorystream::writeString: no free!"); + KBEngine.ERROR_MSG("memorystream::writeString: no free!"); return; } var buf = new Uint8Array(this.buffer, this.wpos); @@ -532,9 +539,11 @@ var KBEngine; MemoryStream.PackFloatXType = PackFloatXType; __reflect(PackFloatXType.prototype, "KBEngine.MemoryStream.PackFloatXType"); })(MemoryStream = KBEngine.MemoryStream || (KBEngine.MemoryStream = {})); - /*----------------------------------------------------------------------------------------- - bundle - -----------------------------------------------------------------------------------------*/ +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + bundle +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { var Bundle = (function () { function Bundle() { this.memorystreams = new Array(); @@ -542,7 +551,7 @@ var KBEngine; this.messageLengthBuffer = null; this.msgtype = null; this.messageLength = 0; - this.stream = new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); + this.stream = new KBEngine.MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); } //--------------------------------------------------------------------------------- Bundle.prototype.newMessage = function (msgtype) { @@ -588,13 +597,13 @@ var KBEngine; network.send(stream.getbuffer()); } this.memorystreams = new Array(); - this.stream = new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); + this.stream = new KBEngine.MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); }; //--------------------------------------------------------------------------------- Bundle.prototype.checkStream = function (v) { if (v > this.stream.space()) { this.memorystreams.push(this.stream); - this.stream = new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); + this.stream = new KBEngine.MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); } this.messageLength += v; }; @@ -651,7 +660,7 @@ var KBEngine; }()); KBEngine.Bundle = Bundle; __reflect(Bundle.prototype, "KBEngine.Bundle"); - KBEngine.reader = new MemoryStream(0); + KBEngine.reader = new KBEngine.MemoryStream(0); KBEngine.datatype2id = {}; function mappingDataType() { KBEngine.datatype2id = {}; @@ -769,7 +778,7 @@ var KBEngine; }; Message.prototype.handleMessage = function (msgstream) { if (this.handler == null) { - ERROR_MSG("Message::handleMessage: interface(" + this.name + "/" + this.id + ") no implement!"); + KBEngine.ERROR_MSG("Message::handleMessage: interface(" + this.name + "/" + this.id + ") no implement!"); return; } if (this.args.length <= 0) { @@ -797,17 +806,16 @@ var KBEngine; })(messages = KBEngine.messages || (KBEngine.messages = {})); KBEngine.clientmessages = {}; KBEngine.bufferedCreateEntityMessage = {}; - /*----------------------------------------------------------------------------------------- - math - -----------------------------------------------------------------------------------------*/ - var Vector3 = (function (_super) { - __extends(Vector3, _super); +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + math +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { + var Vector3 = (function () { function Vector3(x, y, z) { - var _this = _super.call(this) || this; - _this.x = x; - _this.y = y; - _this.z = z; - return _this; + this.x = x; + this.y = y; + this.z = z; } Vector3.prototype.distance = function (pos) { var x = pos.x - this.x; @@ -816,7 +824,7 @@ var KBEngine; return Math.sqrt(x * x + y * y + z * z); }; return Vector3; - }(Class)); + }()); KBEngine.Vector3 = Vector3; __reflect(Vector3.prototype, "KBEngine.Vector3"); function clampf(value, min_inclusive, max_inclusive) { @@ -844,31 +852,30 @@ var KBEngine; return angle; } KBEngine.angle2int8 = angle2int8; - /*----------------------------------------------------------------------------------------- - entity - -----------------------------------------------------------------------------------------*/ - var Entity = (function (_super) { - __extends(Entity, _super); +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + entity +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { + var Entity = (function () { function Entity() { - var _this = _super.call(this) || this; - _this.id = 0; - _this.className = ""; - _this.position = new Vector3(0, 0, 0); - _this.direction = new Vector3(0, 0, 0); - _this.velocity = 0; - _this.cell = null; - _this.base = null; + this.id = 0; + this.className = ""; + this.position = new KBEngine.Vector3(0, 0, 0); + this.direction = new KBEngine.Vector3(0, 0, 0); + this.velocity = 0; + this.cell = null; + this.base = null; // enterworld之后设置为true - _this.inWorld = false; + this.inWorld = false; // __init__调用之后设置为true - _this.inited = false; + this.inited = false; // 是否被控制 - _this.isControlled = false; - _this.entityLastLocalPos = new Vector3(0.0, 0.0, 0.0); - _this.entityLastLocalDir = new Vector3(0.0, 0.0, 0.0); + this.isControlled = false; + this.entityLastLocalPos = new KBEngine.Vector3(0.0, 0.0, 0.0); + this.entityLastLocalDir = new KBEngine.Vector3(0.0, 0.0, 0.0); // 玩家是否在地面上 - _this.isOnGround = false; - return _this; + this.isOnGround = false; } Entity.prototype.__init__ = function () { }; @@ -914,22 +921,22 @@ var KBEngine; params[_i] = arguments[_i]; } if (params.length < 1) { - ERROR_MSG('Entity::baseCall: not fount interfaceName!'); + KBEngine.ERROR_MSG('Entity::baseCall: not fount interfaceName!'); return; } if (this.base == undefined) { - ERROR_MSG('Entity::baseCall: base is None!'); + KBEngine.ERROR_MSG('Entity::baseCall: base is None!'); return; } var method = KBEngine.moduledefs[this.className].base_methods[params[0]]; if (method == undefined) { - ERROR_MSG("Entity::baseCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); + KBEngine.ERROR_MSG("Entity::baseCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); return; } var methodID = method[0]; var args = method[3]; if (args.length - 1 != args.length) { - ERROR_MSG("Entity::baseCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); + KBEngine.ERROR_MSG("Entity::baseCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); return; } this.base.newCall(); @@ -945,8 +952,8 @@ var KBEngine; } } catch (e) { - ERROR_MSG(e.toString()); - ERROR_MSG('Entity::baseCall: args is error!'); + KBEngine.ERROR_MSG(e.toString()); + KBEngine.ERROR_MSG('Entity::baseCall: args is error!'); this.base.bundle = null; return; } @@ -958,22 +965,22 @@ var KBEngine; params[_i] = arguments[_i]; } if (params.length < 1) { - ERROR_MSG('Entity::cellCall: not fount interfaceName!'); + KBEngine.ERROR_MSG('Entity::cellCall: not fount interfaceName!'); return; } if (this.cell == undefined) { - ERROR_MSG('Entity::cellCall: cell is None!'); + KBEngine.ERROR_MSG('Entity::cellCall: cell is None!'); return; } var method = KBEngine.moduledefs[this.className].cell_methods[params[0]]; if (method == undefined) { - ERROR_MSG("Entity::cellCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); + KBEngine.ERROR_MSG("Entity::cellCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); return; } var methodID = method[0]; var args = method[3]; if (args.length - 1 != args.length) { - ERROR_MSG("Entity::cellCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); + KBEngine.ERROR_MSG("Entity::cellCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); return; } this.cell.newCall(); @@ -989,15 +996,15 @@ var KBEngine; } } catch (e) { - ERROR_MSG(e.toString()); - ERROR_MSG('Entity::cellCall: args is error!'); + KBEngine.ERROR_MSG(e.toString()); + KBEngine.ERROR_MSG('Entity::cellCall: args is error!'); this.cell.bundle = null; return; } this.cell.sendCall(); }; Entity.prototype.enterWorld = function () { - INFO_MSG(this.className + '::enterWorld: ' + this.id); + KBEngine.INFO_MSG(this.className + '::enterWorld: ' + this.id); this.inWorld = true; this.onEnterWorld(); KBEngine.Event.fire("onEnterWorld", this); @@ -1005,7 +1012,7 @@ var KBEngine; Entity.prototype.onEnterWorld = function () { }; Entity.prototype.leaveWorld = function () { - INFO_MSG(this.className + '::leaveWorld: ' + this.id); + KBEngine.INFO_MSG(this.className + '::leaveWorld: ' + this.id); this.inWorld = false; this.onLeaveWorld(); KBEngine.Event.fire("onLeaveWorld", this); @@ -1013,7 +1020,7 @@ var KBEngine; Entity.prototype.onLeaveWorld = function () { }; Entity.prototype.enterSpace = function () { - INFO_MSG(this.className + '::enterSpace: ' + this.id); + KBEngine.INFO_MSG(this.className + '::enterSpace: ' + this.id); this.onEnterSpace(); KBEngine.Event.fire("onEnterSpace", this); // 要立即刷新表现层对象的位置 @@ -1023,7 +1030,7 @@ var KBEngine; Entity.prototype.onEnterSpace = function () { }; Entity.prototype.leaveSpace = function () { - INFO_MSG(this.className + '::leaveSpace: ' + this.id); + KBEngine.INFO_MSG(this.className + '::leaveSpace: ' + this.id); this.onLeaveSpace(); KBEngine.Event.fire("onLeaveSpace", this); }; @@ -1045,12 +1052,14 @@ var KBEngine; KBEngine.Event.fire("set_direction", this); }; return Entity; - }(Class)); + }()); KBEngine.Entity = Entity; __reflect(Entity.prototype, "KBEngine.Entity"); - /*----------------------------------------------------------------------------------------- - EntityCall - -----------------------------------------------------------------------------------------*/ +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + EntityCall +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { KBEngine.ENTITYCALL_TYPE_CELL = 0; KBEngine.ENTITYCALL_TYPE_BASE = 1; var EntityCall = (function () { @@ -1069,11 +1078,11 @@ var KBEngine; }; EntityCall.prototype.newCall = function () { if (this.bundle == null) - this.bundle = new Bundle(); + this.bundle = new KBEngine.Bundle(); if (this.type == KBEngine.ENTITYCALL_TYPE_CELL) - this.bundle.newMessage(messages['Baseapp_onRemoteCallCellMethodFromClient']); + this.bundle.newMessage(KBEngine.messages['Baseapp_onRemoteCallCellMethodFromClient']); else - this.bundle.newMessage(messages['Entity_onRemoteMethodCall']); + this.bundle.newMessage(KBEngine.messages['Entity_onRemoteMethodCall']); this.bundle.writeInt32(this.id); return this.bundle; }; @@ -1088,7 +1097,6 @@ var KBEngine; }()); KBEngine.EntityCall = EntityCall; __reflect(EntityCall.prototype, "KBEngine.EntityCall"); - KBEngine.moduledefs = {}; var DATATYPE_UINT8 = (function () { function DATATYPE_UINT8() { } @@ -1185,7 +1193,7 @@ var KBEngine; return eval(v); }; DATATYPE_UINT64.prototype.isSameType = function (v) { - return v instanceof UINT64; + return v instanceof KBEngine.UINT64; }; return DATATYPE_UINT64; }()); @@ -1287,7 +1295,7 @@ var KBEngine; return eval(v); }; DATATYPE_INT64.prototype.isSameType = function (v) { - return v instanceof INT64; + return v instanceof KBEngine.INT64; }; return DATATYPE_INT64; }()); @@ -1357,10 +1365,10 @@ var KBEngine; }; DATATYPE_VECTOR2.prototype.createFromStream = function (stream) { if (KBEngine.CLIENT_NO_FLOAT) { - return new Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); + return new KBEngine.Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); } else { - return new Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); + return new KBEngine.Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); } }; DATATYPE_VECTOR2.prototype.addToStream = function (stream, v) { @@ -1377,7 +1385,7 @@ var KBEngine; return eval(v); }; DATATYPE_VECTOR2.prototype.isSameType = function (v) { - if (!(v instanceof Vector3)) { + if (!(v instanceof KBEngine.Vector3)) { return false; } return true; @@ -1393,10 +1401,10 @@ var KBEngine; }; DATATYPE_VECTOR3.prototype.createFromStream = function (stream) { if (KBEngine.CLIENT_NO_FLOAT) { - return new Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); + return new KBEngine.Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); } else { - return new Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); + return new KBEngine.Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); } }; DATATYPE_VECTOR3.prototype.addToStream = function (stream, v) { @@ -1415,7 +1423,7 @@ var KBEngine; return eval(v); }; DATATYPE_VECTOR3.prototype.isSameType = function (v) { - if (!(v instanceof Vector3)) { + if (!(v instanceof KBEngine.Vector3)) { return false; } return true; @@ -1431,10 +1439,10 @@ var KBEngine; }; DATATYPE_VECTOR4.prototype.createFromStream = function (stream) { if (KBEngine.CLIENT_NO_FLOAT) { - return new Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); + return new KBEngine.Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); } else { - return new Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); + return new KBEngine.Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); } }; DATATYPE_VECTOR4.prototype.addToStream = function (stream, v) { @@ -1455,7 +1463,7 @@ var KBEngine; return eval(v); }; DATATYPE_VECTOR4.prototype.isSameType = function (v) { - if (!(v instanceof Vector3)) { + if (!(v instanceof KBEngine.Vector3)) { return false; } return true; @@ -1489,10 +1497,10 @@ var KBEngine; DATATYPE_UNICODE.prototype.bind = function () { }; DATATYPE_UNICODE.prototype.createFromStream = function (stream) { - return utf8ArrayToString(KBEngine.reader.readBlob.call(stream)); + return KBEngine.utf8ArrayToString(KBEngine.reader.readBlob.call(stream)); }; DATATYPE_UNICODE.prototype.addToStream = function (stream, v) { - stream.writeBlob(stringToUTF8Bytes(v)); + stream.writeBlob(KBEngine.stringToUTF8Bytes(v)); }; DATATYPE_UNICODE.prototype.parseDefaultValStr = function (v) { if (typeof (v) == "string") @@ -1649,15 +1657,18 @@ var KBEngine; datatypes.BLOB = new DATATYPE_BLOB(); })(datatypes = KBEngine.datatypes || (KBEngine.datatypes = {})); ; - /*----------------------------------------------------------------------------------------- - KBEngine args - -----------------------------------------------------------------------------------------*/ +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + KBEngine args +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { var KBEngineArgs = (function () { function KBEngineArgs() { this.ip = '127.0.0.1'; this.port = 20013; this.updateHZ = 100; this.serverHeartbeatTick = 15; + this.protocol = "ws://"; // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types this.clientType = 5; // 在Entity初始化时是否触发属性的set_*事件(callPropertysSetMethods) @@ -1667,9 +1678,12 @@ var KBEngine; }()); KBEngine.KBEngineArgs = KBEngineArgs; __reflect(KBEngineArgs.prototype, "KBEngine.KBEngineArgs"); - /*----------------------------------------------------------------------------------------- - KBEngine app - -----------------------------------------------------------------------------------------*/ +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + KBEngine app +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { + KBEngine.moduledefs = {}; var KBEngineApp = (function () { function KBEngineApp(args) { this.username = "testhtml51"; @@ -1681,6 +1695,9 @@ var KBEngine; this.serverErrorsDescrImported = false; this.entitydefImported = false; this.serverErrs = {}; + // // 登录loginapp的地址 + // ip: string; + // port: number; // 服务端分配的baseapp地址 this.baseappIP = ''; this.baseappPort = 0; @@ -1699,7 +1716,7 @@ var KBEngine; this.entity_id = 0; this.entity_type = ""; // 当前玩家最后一次同步到服务端的位置与朝向与服务端最后一次同步过来的位置 - this.entityServerPos = new Vector3(0.0, 0.0, 0.0); + this.entityServerPos = new KBEngine.Vector3(0.0, 0.0, 0.0); // 客户端所有的实体 this.entities = {}; this.entityIDAliasIDList = []; @@ -1752,7 +1769,7 @@ var KBEngine; KBEngine.app.entity_id = 0; KBEngine.app.entity_type = ""; // 当前玩家最后一次同步到服务端的位置与朝向与服务端最后一次同步过来的位置 - KBEngine.app.entityServerPos = new Vector3(0.0, 0.0, 0.0); + KBEngine.app.entityServerPos = new KBEngine.Vector3(0.0, 0.0, 0.0); // 客户端所有的实体 KBEngine.app.entities = {}; KBEngine.app.entityIDAliasIDList = []; @@ -1765,7 +1782,7 @@ var KBEngine; var dateObject = new Date(); KBEngine.app.lastTickTime = dateObject.getTime(); KBEngine.app.lastTickCBTime = dateObject.getTime(); - mappingDataType(); + KBEngine.mappingDataType(); // 当前组件类别, 配套服务端体系 KBEngine.app.component = "client"; }; @@ -1782,11 +1799,11 @@ var KBEngine; KBEngine.Event.deregister("createAccount", KBEngine.app); }; KBEngineApp.prototype.hello = function () { - var bundle = new Bundle(); + var bundle = new KBEngine.Bundle(); if (KBEngine.app.currserver == "loginapp") - bundle.newMessage(messages['Loginapp_hello']); + bundle.newMessage(KBEngine.messages['Loginapp_hello']); else - bundle.newMessage(messages['Baseapp_hello']); + bundle.newMessage(KBEngine.messages['Baseapp_hello']); bundle.writeString(KBEngine.app.clientVersion); bundle.writeString(KBEngine.app.clientScriptVersion); bundle.writeBlob(KBEngine.app.encryptedKey); @@ -1805,7 +1822,7 @@ var KBEngine; KBEngine.app.socket = new WebSocket(addr); } catch (e) { - ERROR_MSG('WebSocket init error!'); + KBEngine.ERROR_MSG('WebSocket init error!'); KBEngine.Event.fire("onConnectionState", false); return; } @@ -1819,28 +1836,28 @@ var KBEngine; KBEngine.app.resetSocket(); }; KBEngineApp.prototype.onopen = function () { - INFO_MSG('connect success!'); + KBEngine.INFO_MSG('connect success!'); KBEngine.app.socket.onerror = KBEngine.app.onerror_after_onopen; KBEngine.Event.fire("onConnectionState", true); }; KBEngineApp.prototype.onerror_before_onopen = function (evt) { - ERROR_MSG('connect error:' + evt.data); + KBEngine.ERROR_MSG('connect error:' + evt.data); KBEngine.app.resetSocket(); KBEngine.Event.fire("onConnectionState", false); }; KBEngineApp.prototype.onerror_after_onopen = function (evt) { - ERROR_MSG('connect error:' + evt.data); + KBEngine.ERROR_MSG('connect error:' + evt.data); KBEngine.app.resetSocket(); KBEngine.Event.fire("onDisconnected"); }; KBEngineApp.prototype.onmessage = function (msg) { - var stream = new MemoryStream(msg.data); + var stream = new KBEngine.MemoryStream(msg.data); stream.wpos = msg.data.byteLength; while (stream.rpos < stream.wpos) { var msgid = stream.readUint16(); var msgHandler = KBEngine.clientmessages[msgid]; if (!msgHandler) { - ERROR_MSG("KBEngineApp::onmessage[" + KBEngine.app.currserver + "]: not found msg(" + msgid + ")!"); + KBEngine.ERROR_MSG("KBEngineApp::onmessage[" + KBEngine.app.currserver + "]: not found msg(" + msgid + ")!"); } else { var msglen = msgHandler.length; @@ -1860,7 +1877,7 @@ var KBEngine; } }; KBEngineApp.prototype.onclose = function () { - INFO_MSG('connect close:' + KBEngine.app.currserver); + KBEngine.INFO_MSG('connect close:' + KBEngine.app.currserver); KBEngine.app.resetSocket(); KBEngine.Event.fire("onDisconnected"); //if(app.currserver != "loginapp") @@ -1870,7 +1887,7 @@ var KBEngine; KBEngine.app.socket.send(msg); }; KBEngineApp.prototype.close = function () { - INFO_MSG('KBEngine::close()'); + KBEngine.INFO_MSG('KBEngine::close()'); KBEngine.app.socket.close(); KBEngine.app.reset(); }; @@ -1882,20 +1899,20 @@ var KBEngine; // 如果心跳回调接收时间小于心跳发送时间,说明没有收到回调 // 此时应该通知客户端掉线了 if (KBEngine.app.lastTickCBTime < KBEngine.app.lastTickTime) { - ERROR_MSG("sendTick: Receive appTick timeout!"); + KBEngine.ERROR_MSG("sendTick: Receive appTick timeout!"); KBEngine.app.socket.close(); } if (KBEngine.app.currserver == "loginapp") { - if (messages['Loginapp_onClientActiveTick'] != undefined) { - var bundle = new Bundle(); - bundle.newMessage(messages['Loginapp_onClientActiveTick']); + if (KBEngine.messages['Loginapp_onClientActiveTick'] != undefined) { + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Loginapp_onClientActiveTick']); bundle.send(KBEngine.app); } } else { - if (messages['Baseapp_onClientActiveTick'] != undefined) { - var bundle = new Bundle(); - bundle.newMessage(messages['Baseapp_onClientActiveTick']); + if (KBEngine.messages['Baseapp_onClientActiveTick'] != undefined) { + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Baseapp_onClientActiveTick']); bundle.send(KBEngine.app); } } @@ -1920,23 +1937,23 @@ var KBEngine; size -= 1; var e = new ServerErr(); e.id = stream.readUint16(); - e.name = utf8ArrayToString(stream.readBlob()); - e.descr = utf8ArrayToString(stream.readBlob()); + e.name = KBEngine.utf8ArrayToString(stream.readBlob()); + e.descr = KBEngine.utf8ArrayToString(stream.readBlob()); KBEngine.app.serverErrs[e.id] = e; - INFO_MSG("Client_onImportServerErrorsDescr: id=" + e.id + ", name=" + e.name + ", descr=" + e.descr); + KBEngine.INFO_MSG("Client_onImportServerErrorsDescr: id=" + e.id + ", name=" + e.name + ", descr=" + e.descr); } }; KBEngineApp.prototype.onOpenLoginapp_login = function () { - INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"); + KBEngine.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"); KBEngine.Event.fire("onConnectionState", true); KBEngine.app.currserver = "loginapp"; KBEngine.app.currstate = "login"; if (!KBEngine.app.loginappMessageImported) { - var bundle = new Bundle(); - bundle.newMessage(messages.Loginapp_importClientMessages); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages.Loginapp_importClientMessages); bundle.send(KBEngine.app); KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; - INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."); + KBEngine.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."); KBEngine.Event.fire("Loginapp_importClientMessages"); } else { @@ -1945,15 +1962,15 @@ var KBEngine; }; KBEngineApp.prototype.onOpenLoginapp_createAccount = function () { KBEngine.Event.fire("onConnectionState", true); - INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"); + KBEngine.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"); KBEngine.app.currserver = "loginapp"; KBEngine.app.currstate = "createAccount"; if (!KBEngine.app.loginappMessageImported) { - var bundle = new Bundle(); - bundle.newMessage(messages.Loginapp_importClientMessages); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages.Loginapp_importClientMessages); bundle.send(KBEngine.app); KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; - INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."); + KBEngine.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."); KBEngine.Event.fire("Loginapp_importClientMessages"); } else { @@ -1961,15 +1978,15 @@ var KBEngine; } }; KBEngineApp.prototype.onImportClientMessagesCompleted = function () { - INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"); + KBEngine.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"); KBEngine.app.socket.onmessage = KBEngine.app.onmessage; KBEngine.app.hello(); if (KBEngine.app.currserver == "loginapp") { if (!KBEngine.app.serverErrorsDescrImported) { - INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"); + KBEngine.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"); KBEngine.app.serverErrorsDescrImported = true; - var bundle = new Bundle(); - bundle.newMessage(messages['Loginapp_importServerErrorsDescr']); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Loginapp_importServerErrorsDescr']); bundle.send(KBEngine.app); } if (KBEngine.app.currstate == "login") @@ -1983,9 +2000,9 @@ var KBEngine; else { KBEngine.app.baseappMessageImported = true; if (!KBEngine.app.entitydefImported) { - INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ..."); - var bundle = new Bundle(); - bundle.newMessage(messages.Baseapp_importClientEntityDef); + KBEngine.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ..."); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages.Baseapp_importClientEntityDef); bundle.send(KBEngine.app); KBEngine.Event.fire("Baseapp_importClientEntityDef"); } @@ -1996,15 +2013,15 @@ var KBEngine; }; KBEngineApp.prototype.createDataTypeFromStreams = function (stream, canprint) { var aliassize = stream.readUint16(); - INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size=" + aliassize + ")!"); + KBEngine.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size=" + aliassize + ")!"); while (aliassize > 0) { aliassize--; KBEngine.app.createDataTypeFromStream(stream, canprint); } ; - for (var datatype in datatypes) { - if (datatypes[datatype] != undefined) { - datatypes[datatype].bind(); + for (var datatype in KBEngine.datatypes) { + if (KBEngine.datatypes[datatype] != undefined) { + KBEngine.datatypes[datatype].bind(); } } }; @@ -2022,9 +2039,9 @@ var KBEngine; if (valname.length == 0) length = "Null_" + utype; if (canprint) - INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias(" + name + ":" + valname + ")!"); + KBEngine.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias(" + name + ":" + valname + ")!"); if (name == "FIXED_DICT") { - var datatype = new DATATYPE_FIXED_DICT(); + var datatype = new KBEngine.DATATYPE_FIXED_DICT(); var keysize = stream.readUint8(); datatype.implementedBy = stream.readString(); while (keysize > 0) { @@ -2034,18 +2051,18 @@ var KBEngine; datatype.dicttype[keyname] = keyutype; } ; - datatypes[valname] = datatype; + KBEngine.datatypes[valname] = datatype; } else if (name == "ARRAY") { var uitemtype = stream.readUint16(); - var datatype = new DATATYPE_ARRAY(); + var datatype = new KBEngine.DATATYPE_ARRAY(); datatype.type = uitemtype; - datatypes[valname] = datatype; + KBEngine.datatypes[valname] = datatype; } else { - datatypes[valname] = datatypes[name]; + KBEngine.datatypes[valname] = KBEngine.datatypes[name]; } - datatypes[utype] = datatypes[valname]; + KBEngine.datatypes[utype] = KBEngine.datatypes[valname]; // 将用户自定义的类型补充到映射表中 KBEngine.datatype2id[valname] = utype; }; @@ -2058,7 +2075,7 @@ var KBEngine; var methodsize = stream.readUint16(); var base_methodsize = stream.readUint16(); var cell_methodsize = stream.readUint16(); - INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import(" + scriptmodule_name + "), propertys(" + propertysize + "), " + + KBEngine.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import(" + scriptmodule_name + "), propertys(" + propertysize + "), " + "clientMethods(" + methodsize + "), baseMethods(" + base_methodsize + "), cellMethods(" + cell_methodsize + ")!"); KBEngine.moduledefs[scriptmodule_name] = {}; var currModuleDefs = KBEngine.moduledefs[scriptmodule_name]; @@ -2073,10 +2090,10 @@ var KBEngine; var self_base_methods = currModuleDefs["base_methods"]; var self_cell_methods = currModuleDefs["cell_methods"]; try { - var Class_1 = eval("" + scriptmodule_name); + var Class = Entities[scriptmodule_name]; } catch (e) { - var Class_2 = undefined; + var Class_1 = undefined; } while (propertysize > 0) { propertysize--; @@ -2085,7 +2102,7 @@ var KBEngine; var aliasID = stream.readInt16(); var name_2 = stream.readString(); var defaultValStr = stream.readString(); - var utype = datatypes[stream.readUint16()]; + var utype = KBEngine.datatypes[stream.readUint16()]; var setmethod = null; if (Class != undefined) { setmethod = Class.prototype["set_" + name_2]; @@ -2102,7 +2119,7 @@ var KBEngine; self_propertys[properUtype] = savedata; currModuleDefs["usePropertyDescrAlias"] = false; } - INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), property(" + name_2 + "/" + properUtype + ")."); + KBEngine.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), property(" + name_2 + "/" + properUtype + ")."); } ; while (methodsize > 0) { @@ -2114,7 +2131,7 @@ var KBEngine; var args = []; while (argssize > 0) { argssize--; - args.push(datatypes[stream.readUint16()]); + args.push(KBEngine.datatypes[stream.readUint16()]); } ; var savedata = [methodUtype, aliasID, name_3, args]; @@ -2127,7 +2144,7 @@ var KBEngine; self_methods[methodUtype] = savedata; currModuleDefs["useMethodDescrAlias"] = false; } - INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), method(" + name_3 + ")."); + KBEngine.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), method(" + name_3 + ")."); } ; while (base_methodsize > 0) { @@ -2139,11 +2156,11 @@ var KBEngine; var args = []; while (argssize > 0) { argssize--; - args.push(datatypes[stream.readUint16()]); + args.push(KBEngine.datatypes[stream.readUint16()]); } ; self_base_methods[name_4] = [methodUtype, aliasID, name_4, args]; - INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), base_method(" + name_4 + ")."); + KBEngine.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), base_method(" + name_4 + ")."); } ; while (cell_methodsize > 0) { @@ -2155,19 +2172,19 @@ var KBEngine; var args = []; while (argssize > 0) { argssize--; - args.push(datatypes[stream.readUint16()]); + args.push(KBEngine.datatypes[stream.readUint16()]); } ; self_cell_methods[name_5] = [methodUtype, aliasID, name_5, args]; - INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), cell_method(" + name_5 + ")."); + KBEngine.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add(" + scriptmodule_name + "), cell_method(" + name_5 + ")."); } ; var defmethod = void 0; try { - defmethod = eval("" + scriptmodule_name); + defmethod = Entities[scriptmodule_name]; } catch (e) { - ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module(" + scriptmodule_name + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module(" + scriptmodule_name + ") not found!"); defmethod = undefined; } for (var name_6 in currModuleDefs.propertys) { @@ -2188,7 +2205,7 @@ var KBEngine; var n = infos[2]; var args = infos[3]; if (defmethod != undefined && defmethod.prototype[n] == undefined) { - WARNING_MSG(scriptmodule_name + ":: method(" + n + ") no implement!"); + KBEngine.WARNING_MSG(scriptmodule_name + ":: method(" + n + ") no implement!"); } } ; @@ -2197,26 +2214,26 @@ var KBEngine; }; KBEngineApp.prototype.Client_onVersionNotMatch = function (stream) { KBEngine.app.serverVersion = stream.readString(); - ERROR_MSG("Client_onVersionNotMatch: verInfo=" + KBEngine.app.clientVersion + " not match(server: " + KBEngine.app.serverVersion + ")"); + KBEngine.ERROR_MSG("Client_onVersionNotMatch: verInfo=" + KBEngine.app.clientVersion + " not match(server: " + KBEngine.app.serverVersion + ")"); KBEngine.Event.fire("onVersionNotMatch", KBEngine.app.clientVersion, KBEngine.app.serverVersion); }; KBEngineApp.prototype.Client_onScriptVersionNotMatch = function (stream) { KBEngine.app.serverScriptVersion = stream.readString(); - ERROR_MSG("Client_onScriptVersionNotMatch: verInfo=" + KBEngine.app.clientScriptVersion + " not match(server: " + KBEngine.app.serverScriptVersion + ")"); + KBEngine.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo=" + KBEngine.app.clientScriptVersion + " not match(server: " + KBEngine.app.serverScriptVersion + ")"); KBEngine.Event.fire("onScriptVersionNotMatch", KBEngine.app.clientScriptVersion, KBEngine.app.serverScriptVersion); }; KBEngineApp.prototype.onImportEntityDefCompleted = function () { - INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"); + KBEngine.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"); KBEngine.app.entitydefImported = true; KBEngine.app.login_baseapp(false); }; KBEngineApp.prototype.Client_onImportClientMessages = function (msg) { - var stream = new MemoryStream(msg.data); + var stream = new KBEngine.MemoryStream(msg.data); var msgid = stream.readUint16(); - if (msgid == messages.onImportClientMessages.id) { + if (msgid == KBEngine.messages.onImportClientMessages.id) { var msglen = stream.readUint16(); var msgcount = stream.readUint16(); - INFO_MSG("KBEngineApp::onImportClientMessages: start(" + msgcount + ") ...!"); + KBEngine.INFO_MSG("KBEngineApp::onImportClientMessages: start(" + msgcount + ") ...!"); while (msgcount > 0) { msgcount--; msgid = stream.readUint16(); @@ -2233,29 +2250,29 @@ var KBEngine; if (isClientMethod) { handler = KBEngine.app[msgname]; if (handler == null || handler == undefined) { - WARNING_MSG("KBEngineApp::onImportClientMessages[" + KBEngine.app.currserver + "]: interface(" + msgname + "/" + msgid + ") no implement!"); + KBEngine.WARNING_MSG("KBEngineApp::onImportClientMessages[" + KBEngine.app.currserver + "]: interface(" + msgname + "/" + msgid + ") no implement!"); handler = null; } else { - INFO_MSG("KBEngineApp::onImportClientMessages: import(" + msgname + ") successfully!"); + KBEngine.INFO_MSG("KBEngineApp::onImportClientMessages: import(" + msgname + ") successfully!"); } } if (msgname.length > 0) { - messages[msgname] = new Message(msgid, msgname, msglen, argtype, argstypes, handler); + KBEngine.messages[msgname] = new KBEngine.Message(msgid, msgname, msglen, argtype, argstypes, handler); if (isClientMethod) - KBEngine.clientmessages[msgid] = messages[msgname]; + KBEngine.clientmessages[msgid] = KBEngine.messages[msgname]; else - messages[KBEngine.app.currserver][msgid] = messages[msgname]; + KBEngine.messages[KBEngine.app.currserver][msgid] = KBEngine.messages[msgname]; } else { - messages[KBEngine.app.currserver][msgid] = new Message(msgid, msgname, msglen, argtype, argstypes, handler); + KBEngine.messages[KBEngine.app.currserver][msgid] = new KBEngine.Message(msgid, msgname, msglen, argtype, argstypes, handler); } } ; KBEngine.app.onImportClientMessagesCompleted(); } else - ERROR_MSG("KBEngineApp::onmessage: not found msg(" + msgid + ")!"); + KBEngine.ERROR_MSG("KBEngineApp::onmessage: not found msg(" + msgid + ")!"); }; KBEngineApp.prototype.createAccount = function (username, password, datas) { KBEngine.app.reset(); @@ -2266,13 +2283,13 @@ var KBEngine; }; KBEngineApp.prototype.createAccount_loginapp = function (noconnect) { if (noconnect) { - INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + KBEngine.app.ip + ":" + KBEngine.app.port + "!"); - KBEngine.app.connect("ws://" + KBEngine.app.ip + ":" + KBEngine.app.port); + KBEngine.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + KBEngine.app.args.ip + ":" + KBEngine.app.args.port + "!"); + KBEngine.app.connect(KBEngine.app.args.protocol + KBEngine.app.args.ip + ":" + KBEngine.app.args.port); KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_createAccount; } else { - var bundle = new Bundle(); - bundle.newMessage(messages['Loginapp_reqCreateAccount']); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Loginapp_reqCreateAccount']); bundle.writeString(KBEngine.app.username); bundle.writeString(KBEngine.app.password); bundle.writeBlob(KBEngine.app.clientdatas); @@ -2280,16 +2297,16 @@ var KBEngine; } }; KBEngineApp.prototype.bindAccountEmail = function (emailAddress) { - var bundle = new Bundle(); - bundle.newMessage(messages['Baseapp_reqAccountBindEmail']); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Baseapp_reqAccountBindEmail']); bundle.writeInt32(KBEngine.app.entity_id); bundle.writeString(KBEngine.app.password); bundle.writeString(emailAddress); bundle.send(KBEngine.app); }; KBEngineApp.prototype.newPassword = function (old_password, new_password) { - var bundle = new Bundle(); - bundle.newMessage(messages['Baseapp_reqAccountNewPassword']); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Baseapp_reqAccountNewPassword']); bundle.writeInt32(KBEngine.app.entity_id); bundle.writeString(old_password); bundle.writeString(new_password); @@ -2304,13 +2321,13 @@ var KBEngine; }; KBEngineApp.prototype.login_loginapp = function (noconnect) { if (noconnect) { - INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://" + KBEngine.app.ip + ":" + KBEngine.app.port + "!"); - KBEngine.app.connect("ws://" + KBEngine.app.ip + ":" + KBEngine.app.port); + KBEngine.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://" + KBEngine.app.args.ip + ":" + KBEngine.app.args.port + "!"); + KBEngine.app.connect(KBEngine.app.args.protocol + KBEngine.app.args.ip + ":" + KBEngine.app.args.port); KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_login; } else { - var bundle = new Bundle(); - bundle.newMessage(messages['Loginapp_login']); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Loginapp_login']); bundle.writeInt8(KBEngine.app.args.clientType); // clientType bundle.writeBlob(KBEngine.app.clientdatas); bundle.writeString(KBEngine.app.username); @@ -2319,15 +2336,15 @@ var KBEngine; } }; KBEngineApp.prototype.onOpenLoginapp_resetpassword = function () { - INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"); + KBEngine.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"); KBEngine.app.currserver = "loginapp"; KBEngine.app.currstate = "resetpassword"; if (!KBEngine.app.loginappMessageImported) { - var bundle = new Bundle(); - bundle.newMessage(messages.Loginapp_importClientMessages); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages.Loginapp_importClientMessages); bundle.send(KBEngine.app); KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; - INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ..."); + KBEngine.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ..."); } else { KBEngine.app.onImportClientMessagesCompleted(); @@ -2340,23 +2357,23 @@ var KBEngine; }; KBEngineApp.prototype.resetpassword_loginapp = function (noconnect) { if (noconnect) { - INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + KBEngine.app.ip + ":" + KBEngine.app.port + "!"); - KBEngine.app.connect("ws://" + KBEngine.app.ip + ":" + KBEngine.app.port); + KBEngine.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + KBEngine.app.args.ip + ":" + KBEngine.app.args.port + "!"); + KBEngine.app.connect(KBEngine.app.args.protocol + KBEngine.app.args.ip + ":" + KBEngine.app.args.port); KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_resetpassword; } else { - var bundle = new Bundle(); - bundle.newMessage(messages['Loginapp_reqAccountResetPassword']); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Loginapp_reqAccountResetPassword']); bundle.writeString(KBEngine.app.username); bundle.send(KBEngine.app); } }; KBEngineApp.prototype.onOpenBaseapp = function () { - INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"); + KBEngine.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"); KBEngine.app.currserver = "baseapp"; if (!KBEngine.app.baseappMessageImported) { - var bundle = new Bundle(); - bundle.newMessage(messages.Baseapp_importClientMessages); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages.Baseapp_importClientMessages); bundle.send(KBEngine.app); KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; KBEngine.Event.fire("Baseapp_importClientMessages"); @@ -2368,14 +2385,14 @@ var KBEngine; KBEngineApp.prototype.login_baseapp = function (noconnect) { if (noconnect) { KBEngine.Event.fire("onLoginBaseapp"); - INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "!"); - KBEngine.app.connect("ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort); + KBEngine.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "!"); + KBEngine.app.connect(KBEngine.app.args.protocol + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort); if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) KBEngine.app.socket.onopen = KBEngine.app.onOpenBaseapp; } else { - var bundle = new Bundle(); - bundle.newMessage(messages['Baseapp_loginBaseapp']); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Baseapp_loginBaseapp']); bundle.writeString(KBEngine.app.username); bundle.writeString(KBEngine.app.password); bundle.send(KBEngine.app); @@ -2386,16 +2403,16 @@ var KBEngine; return; KBEngine.app.resetSocket(); KBEngine.Event.fire("onReloginBaseapp"); - INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "!"); - KBEngine.app.connect("ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort); + KBEngine.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "!"); + KBEngine.app.connect(KBEngine.app.args.protocol + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort); if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) KBEngine.app.socket.onopen = KBEngine.app.onReOpenBaseapp; }; KBEngineApp.prototype.onReOpenBaseapp = function () { - INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"); + KBEngine.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"); KBEngine.app.currserver = "baseapp"; - var bundle = new Bundle(); - bundle.newMessage(messages['Baseapp_reloginBaseapp']); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Baseapp_reloginBaseapp']); bundle.writeString(KBEngine.app.username); bundle.writeString(KBEngine.app.password); bundle.writeUint64(KBEngine.app.entity_uuid); @@ -2410,7 +2427,7 @@ var KBEngine; KBEngine.app.serverProtocolMD5 = args.readString(); KBEngine.app.serverEntityDefMD5 = args.readString(); var ctype = args.readInt32(); - INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo(" + KBEngine.app.serverVersion + "), scriptVerInfo(" + + KBEngine.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo(" + KBEngine.app.serverVersion + "), scriptVerInfo(" + KBEngine.app.serverScriptVersion + "), serverProtocolMD5(" + KBEngine.app.serverProtocolMD5 + "), serverEntityDefMD5(" + KBEngine.app.serverEntityDefMD5 + "), ctype(" + ctype + ")!"); var dateObject = new Date(); @@ -2419,7 +2436,7 @@ var KBEngine; KBEngineApp.prototype.Client_onLoginFailed = function (args) { var failedcode = args.readUint16(); KBEngine.app.serverdatas = args.readBlob(); - ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + "), datas(" + KBEngine.app.serverdatas.length + ")!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + "), datas(" + KBEngine.app.serverdatas.length + ")!"); KBEngine.Event.fire("onLoginFailed", failedcode); }; KBEngineApp.prototype.Client_onLoginSuccessfully = function (args) { @@ -2428,39 +2445,34 @@ var KBEngine; KBEngine.app.baseappIp = args.readString(); KBEngine.app.baseappPort = args.readUint16(); KBEngine.app.serverdatas = args.readBlob(); - INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName(" + accountName + "), addr(" + + KBEngine.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName(" + accountName + "), addr(" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "), datas(" + KBEngine.app.serverdatas.length + ")!"); KBEngine.app.disconnect(); KBEngine.app.login_baseapp(true); }; KBEngineApp.prototype.Client_onLoginBaseappFailed = function (failedcode) { - ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); KBEngine.Event.fire("onLoginBaseappFailed", failedcode); }; KBEngineApp.prototype.Client_onReloginBaseappFailed = function (failedcode) { - ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); KBEngine.Event.fire("onReloginBaseappFailed", failedcode); }; KBEngineApp.prototype.Client_onReloginBaseappSuccessfully = function (stream) { KBEngine.app.entity_uuid = stream.readUint64(); - DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: " + KBEngine.app.username); + KBEngine.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: " + KBEngine.app.username); KBEngine.Event.fire("onReloginBaseappSuccessfully"); }; KBEngineApp.prototype.getentityclass = function (entityType) { - var runclass = KBEngine.app.entityclass[entityType]; + var runclass = Entities[entityType]; if (runclass == undefined) { - runclass = eval("" + entityType); - if (runclass == undefined) { - ERROR_MSG("KBEngineApp::getentityclass: entityType(" + entityType + ") is error!"); - return runclass; - } - else - KBEngine.app.entityclass[entityType] = runclass; + KBEngine.ERROR_MSG("KBEngineApp::getentityclass: entityType(" + entityType + ") is error!"); + return runclass; } return runclass; }; KBEngineApp.prototype.Client_onCreatedProxies = function (rndUUID, eid, entityType) { - INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid(" + eid + "), entityType(" + entityType + ")!"); + KBEngine.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid(" + eid + "), entityType(" + entityType + ")!"); var entity = KBEngine.app.entities[eid]; KBEngine.app.entity_uuid = rndUUID; KBEngine.app.entity_id = eid; @@ -2471,7 +2483,7 @@ var KBEngine; var entity_1 = new runclass(); entity_1.id = eid; entity_1.className = entityType; - entity_1.base = new EntityCall(); + entity_1.base = new KBEngine.EntityCall(); entity_1.base.id = eid; entity_1.base.className = entityType; entity_1.base.type = KBEngine.ENTITYCALL_TYPE_BASE; @@ -2515,10 +2527,10 @@ var KBEngine; if (entity == undefined) { var entityMessage = KBEngine.bufferedCreateEntityMessage[eid]; if (entityMessage != undefined) { - ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity(" + eid + ") not found!"); return; } - var stream1 = new MemoryStream(stream.buffer); + var stream1 = new KBEngine.MemoryStream(stream.buffer); stream1.wpos = stream.wpos; stream1.rpos = stream.rpos - 4; KBEngine.bufferedCreateEntityMessage[eid] = stream1; @@ -2537,7 +2549,7 @@ var KBEngine; var flags = propertydata[6]; var val = propertydata[4].createFromStream(stream); var oldval = entity[propertydata[2]]; - INFO_MSG("KBEngineApp::Client_onUpdatePropertys: " + entity.className + "(id=" + eid + " " + propertydata[2] + ", val=" + val + ")!"); + KBEngine.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: " + entity.className + "(id=" + eid + " " + propertydata[2] + ", val=" + val + ")!"); entity[propertydata[2]] = val; if (setmethod != null) { // base类属性或者进入世界后cell类属性会触发set_*方法 @@ -2563,7 +2575,7 @@ var KBEngine; KBEngineApp.prototype.onRemoteMethodCall_ = function (eid, stream) { var entity = KBEngine.app.entities[eid]; if (entity == undefined) { - ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); return; } var methodUtype = 0; @@ -2581,7 +2593,7 @@ var KBEngine; entity[methoddata[2]].apply(entity, args); } else { - ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found method(" + methoddata[2] + ")!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found method(" + methoddata[2] + ")!"); } }; KBEngineApp.prototype.Client_onRemoteMethodCallOptimized = function (stream) { @@ -2605,12 +2617,12 @@ var KBEngine; if (stream.length() > 0) isOnGround = stream.readInt8(); entityType = KBEngine.moduledefs[entityType].name; - INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: " + entityType + "(" + eid + "), spaceID(" + KBEngine.app.spaceID + "), isOnGround(" + isOnGround + ")!"); + KBEngine.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: " + entityType + "(" + eid + "), spaceID(" + KBEngine.app.spaceID + "), isOnGround(" + isOnGround + ")!"); var entity = KBEngine.app.entities[eid]; if (entity == undefined) { var entityMessage = KBEngine.bufferedCreateEntityMessage[eid]; if (entityMessage == undefined) { - ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity(" + eid + ") not found!"); return; } var runclass = KBEngine.app.getentityclass(entityType); @@ -2619,7 +2631,7 @@ var KBEngine; var entity_2 = new runclass(); entity_2.id = eid; entity_2.className = entityType; - entity_2.cell = new EntityCall(); + entity_2.cell = new KBEngine.EntityCall(); entity_2.cell.id = eid; entity_2.cell.className = entityType; entity_2.cell.type = KBEngine.ENTITYCALL_TYPE_CELL; @@ -2639,7 +2651,7 @@ var KBEngine; } else { if (!entity.inWorld) { - entity.cell = new EntityCall(); + entity.cell = new KBEngine.EntityCall(); entity.cell.id = eid; entity.cell.className = entityType; entity.cell.type = KBEngine.ENTITYCALL_TYPE_CELL; @@ -2670,7 +2682,7 @@ var KBEngine; KBEngineApp.prototype.Client_onEntityLeaveWorld = function (eid) { var entity = KBEngine.app.entities[eid]; if (entity == undefined) { - ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity(" + eid + ") not found!"); return; } if (entity.inWorld) @@ -2701,10 +2713,10 @@ var KBEngine; } }; KBEngineApp.prototype.Client_onEntityDestroyed = function (eid) { - INFO_MSG("KBEngineApp::Client_onEntityDestroyed: entity(" + eid + ")!"); + KBEngine.INFO_MSG("KBEngineApp::Client_onEntityDestroyed: entity(" + eid + ")!"); var entity = KBEngine.app.entities[eid]; if (entity == undefined) { - ERROR_MSG("KBEngineApp::Client_onEntityDestroyed: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onEntityDestroyed: entity(" + eid + ") not found!"); return; } if (entity.inWorld) { @@ -2722,7 +2734,7 @@ var KBEngine; isOnGround = stream.readInt8(); var entity = KBEngine.app.entities[eid]; if (entity == undefined) { - ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity(" + eid + ") not found!"); return; } entity.isOnGround = isOnGround; @@ -2734,14 +2746,14 @@ var KBEngine; KBEngineApp.prototype.Client_onEntityLeaveSpace = function (eid) { var entity = KBEngine.app.entities[eid]; if (entity == undefined) { - ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity(" + eid + ") not found!"); return; } KBEngine.app.clearSpace(false); entity.leaveSpace(); }; KBEngineApp.prototype.Client_onKicked = function (failedcode) { - ERROR_MSG("KBEngineApp::Client_onKicked: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); KBEngine.Event.fire("onKicked", failedcode); }; KBEngineApp.prototype.Client_onCreateAccountResult = function (stream) { @@ -2749,16 +2761,16 @@ var KBEngine; var datas = stream.readBlob(); KBEngine.Event.fire("onCreateAccountResult", retcode, datas); if (retcode != 0) { - ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: " + KBEngine.app.username + " create is failed! code=" + KBEngine.app.serverErrs[retcode].name + "!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: " + KBEngine.app.username + " create is failed! code=" + KBEngine.app.serverErrs[retcode].name + "!"); return; } - INFO_MSG("KBEngineApp::Client_onCreateAccountResult: " + KBEngine.app.username + " create is successfully!"); + KBEngine.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: " + KBEngine.app.username + " create is successfully!"); }; KBEngineApp.prototype.Client_onControlEntity = function (eid, isControlled) { // eid = stream.readInt32(); var entity = KBEngine.app.entities[eid]; if (entity == undefined) { - ERROR_MSG("KBEngineApp::Client_onControlEntity: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity(" + eid + ") not found!"); return; } var isCont = isControlled != 0; @@ -2782,7 +2794,7 @@ var KBEngine; KBEngine.Event.fire("onControlled", entity, isCont); } catch (e) { - ERROR_MSG("KBEngine::Client_onControlEntity: entity id = '" + eid + "', is controlled = '" + isCont + "', error = '" + e + "'"); + KBEngine.ERROR_MSG("KBEngine::Client_onControlEntity: entity id = '" + eid + "', is controlled = '" + isCont + "', error = '" + e + "'"); } }; KBEngineApp.prototype.updatePlayerToServer = function () { @@ -2797,8 +2809,8 @@ var KBEngine; player.entityLastLocalDir.x = player.direction.x; player.entityLastLocalDir.y = player.direction.y; player.entityLastLocalDir.z = player.direction.z; - var bundle = new Bundle(); - bundle.newMessage(messages['Baseapp_onUpdateDataFromClient']); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Baseapp_onUpdateDataFromClient']); bundle.writeFloat(player.position.x); bundle.writeFloat(player.position.y); bundle.writeFloat(player.position.z); @@ -2819,8 +2831,8 @@ var KBEngine; if (posHasChanged || dirHasChanged) { entity.entityLastLocalPos = position; entity.entityLastLocalDir = direction; - var bundle = new Bundle(); - bundle.newMessage(messages['Baseapp_onUpdateDataFromClientForControlledEntity']); + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Baseapp_onUpdateDataFromClientForControlledEntity']); bundle.writeInt32(entity.id); bundle.writeFloat(position.x); bundle.writeFloat(position.y); @@ -2835,7 +2847,7 @@ var KBEngine; } }; KBEngineApp.prototype.addSpaceGeometryMapping = function (spaceID, respath) { - INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID(" + spaceID + "), respath(" + respath + ")!"); + KBEngine.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID(" + spaceID + "), respath(" + respath + ")!"); KBEngine.app.spaceID = spaceID; KBEngine.app.spaceResPath = respath; KBEngine.Event.fire("addSpaceGeometryMapping", respath); @@ -2880,17 +2892,17 @@ var KBEngine; var value = stream.readString(); KBEngine.app.Client_setSpaceData(KBEngine.app.spaceID, key, value); } - INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID(" + KBEngine.app.spaceID + "), datas(" + KBEngine.app.spacedata + ")!"); + KBEngine.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID(" + KBEngine.app.spaceID + "), datas(" + KBEngine.app.spacedata + ")!"); }; KBEngineApp.prototype.Client_setSpaceData = function (spaceID, key, value) { - INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID(" + spaceID + "), key(" + key + "), value(" + value + ")!"); + KBEngine.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID(" + spaceID + "), key(" + key + "), value(" + value + ")!"); KBEngine.app.spacedata[key] = value; if (key == "_mapping") KBEngine.app.addSpaceGeometryMapping(spaceID, value); KBEngine.Event.fire("onSetSpaceData", spaceID, key, value); }; KBEngineApp.prototype.Client_delSpaceData = function (spaceID, key) { - INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID(" + spaceID + "), key(" + key + ")!"); + KBEngine.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID(" + spaceID + "), key(" + key + ")!"); delete KBEngine.app.spacedata[key]; KBEngine.Event.fire("onDelSpaceData", spaceID, key); }; @@ -2910,7 +2922,7 @@ var KBEngine; var eid = KBEngine.app.getViewEntityIDFromStream(stream); var entity = KBEngine.app.entities[eid]; if (entity == undefined) { - ERROR_MSG("KBEngineApp::Client_onUpdateData: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity(" + eid + ") not found!"); return; } }; @@ -2918,7 +2930,7 @@ var KBEngine; var eid = stream.readInt32(); var entity = KBEngine.app.entities[eid]; if (entity == undefined) { - ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity(" + eid + ") not found!"); return; } entity.position.x = stream.readFloat(); @@ -3066,7 +3078,7 @@ var KBEngine; var y = stream.readPackY(); var p = stream.readInt8(); var r = stream.readInt8(); - ERROR_MSG('调用错误方法,无法找到x,z'); + KBEngine.ERROR_MSG('调用错误方法,无法找到x,z'); //todo 这个是手动注释,如果错误再修改 // app._updateVolatileData(eid, x, y, z, KBE_FLT_MAX, p, r, 0); }; @@ -3099,7 +3111,7 @@ var KBEngine; // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 // 则可以忽略这个错误, 因为cellapp可能一直在向baseapp发送同步消息, 当客户端重连上时未等 // 服务端初始化步骤开始则收到同步信息, 此时这里就会出错。 - ERROR_MSG("KBEngineApp::_updateVolatileData: entity(" + entityID + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::_updateVolatileData: entity(" + entityID + ") not found!"); return; } // 小于0不设置 @@ -3109,15 +3121,15 @@ var KBEngine; var changeDirection = false; if (roll != KBEngine.KBE_FLT_MAX) { changeDirection = true; - entity.direction.x = int82angle(roll, false); + entity.direction.x = KBEngine.int82angle(roll, false); } if (pitch != KBEngine.KBE_FLT_MAX) { changeDirection = true; - entity.direction.y = int82angle(pitch, false); + entity.direction.y = KBEngine.int82angle(pitch, false); } if (yaw != KBEngine.KBE_FLT_MAX) { changeDirection = true; - entity.direction.z = int82angle(yaw, false); + entity.direction.z = KBEngine.int82angle(yaw, false); } var done = false; if (changeDirection == true) { @@ -3156,24 +3168,24 @@ var KBEngine; }; KBEngineApp.prototype.Client_onReqAccountResetPasswordCB = function (failedcode) { if (failedcode != 0) { - ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: " + KBEngine.app.username + " is failed! code=" + KBEngine.app.serverErrs[failedcode].name + "!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: " + KBEngine.app.username + " is failed! code=" + KBEngine.app.serverErrs[failedcode].name + "!"); return; } - INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: " + KBEngine.app.username + " is successfully!"); + KBEngine.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: " + KBEngine.app.username + " is successfully!"); }; KBEngineApp.prototype.Client_onReqAccountBindEmailCB = function (failedcode) { if (failedcode != 0) { - ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: " + KBEngine.app.username + " is failed! code=" + KBEngine.app.serverErrs[failedcode].name + "!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: " + KBEngine.app.username + " is failed! code=" + KBEngine.app.serverErrs[failedcode].name + "!"); return; } - INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: " + KBEngine.app.username + " is successfully!"); + KBEngine.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: " + KBEngine.app.username + " is successfully!"); }; KBEngineApp.prototype.Client_onReqAccountNewPasswordCB = function (failedcode) { if (failedcode != 0) { - ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: " + KBEngine.app.username + " is failed! code=" + KBEngine.app.serverErrs[failedcode].name + "!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: " + KBEngine.app.username + " is failed! code=" + KBEngine.app.serverErrs[failedcode].name + "!"); return; } - INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: " + KBEngine.app.username + " is successfully!"); + KBEngine.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: " + KBEngine.app.username + " is successfully!"); }; return KBEngineApp; }()); @@ -3194,8 +3206,8 @@ var KBEngine; function create(args) { if (KBEngine.app != undefined) return; - if (args.constructor != KBEngineArgs) { - ERROR_MSG("create(): args(" + args + ") error! not is KBEngineArgs"); + if (args.constructor != KBEngine.KBEngineArgs) { + KBEngine.ERROR_MSG("create(): args(" + args + ") error! not is KBEngineArgs"); return; } new KBEngineApp(args); diff --git a/kbengine_ts/bin/kbengine.min.js b/kbengine_ts/bin/kbengine.min.js index 3148fa3..ac142a8 100644 --- a/kbengine_ts/bin/kbengine.min.js +++ b/kbengine_ts/bin/kbengine.min.js @@ -1,3 +1,3 @@ -var __reflect=this&&this.__reflect||function(e,n,t){e.__class__=n,t?t.push(n):t=[n],e.__types__=e.__types__?t.concat(e.__types__):t},__extends=this&&this.__extends||function(e,n){function t(){this.constructor=e}for(var i in n)n.hasOwnProperty(i)&&(e[i]=n[i]);t.prototype=n.prototype,e.prototype=new t},KBEngine;!function(KBEngine){function INFO_MSG(e){console.info(e)}function DEBUG_MSG(e){console.debug(e)}function ERROR_MSG(e){console.error(e)}function WARNING_MSG(e){console.warn(e)}function utf8ArrayToString(e){var n,t,i,r,a,p;for(n="",i=e.length,t=0;i>t;)switch(r=e[t++],r>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:n+=String.fromCharCode(r);break;case 12:case 13:a=e[t++],n+=String.fromCharCode((31&r)<<6|63&a);break;case 14:a=e[t++],p=e[t++],n+=String.fromCharCode((15&r)<<12|(63&a)<<6|(63&p)<<0)}return n}function stringToUTF8Bytes(e){for(var n=[],t=0;ti?n.push(i):2048>i?n.push(192|i>>6,128|63&i):55296>i||i>=57344?n.push(224|i>>12,128|i>>6&63,128|63&i):(t++,i=65536+((1023&i)<<10|1023&e.charCodeAt(t)),n.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return n}function mappingDataType(){KBEngine.datatype2id={},KBEngine.datatype2id.STRING=1,KBEngine.datatype2id["STD::STRING"]=1,KBEngine.datatype2id.UINT8=2,KBEngine.datatype2id.BOOL=2,KBEngine.datatype2id.DATATYPE=2,KBEngine.datatype2id.CHAR=2,KBEngine.datatype2id.DETAIL_TYPE=2,KBEngine.datatype2id.ENTITYCALL_CALL_TYPE=2,KBEngine.datatype2id.UINT16=3,KBEngine.datatype2id["UNSIGNED SHORT"]=3,KBEngine.datatype2id.SERVER_ERROR_CODE=3,KBEngine.datatype2id.ENTITY_TYPE=3,KBEngine.datatype2id.ENTITY_PROPERTY_UID=3,KBEngine.datatype2id.ENTITY_METHOD_UID=3,KBEngine.datatype2id.ENTITY_SCRIPT_UID=3,KBEngine.datatype2id.DATATYPE_UID=3,KBEngine.datatype2id.UINT32=4,KBEngine.datatype2id.UINT=4,KBEngine.datatype2id["UNSIGNED INT"]=4,KBEngine.datatype2id.ARRAYSIZE=4,KBEngine.datatype2id.SPACE_ID=4,KBEngine.datatype2id.GAME_TIME=4,KBEngine.datatype2id.TIMER_ID=4,KBEngine.datatype2id.UINT64=5,KBEngine.datatype2id.DBID=5,KBEngine.datatype2id.COMPONENT_ID=5,KBEngine.datatype2id.INT8=6,KBEngine.datatype2id.COMPONENT_ORDER=6,KBEngine.datatype2id.INT16=7,KBEngine.datatype2id.SHORT=7,KBEngine.datatype2id.INT32=8,KBEngine.datatype2id.INT=8,KBEngine.datatype2id.ENTITY_ID=8,KBEngine.datatype2id.CALLBACK_ID=8,KBEngine.datatype2id.COMPONENT_TYPE=8,KBEngine.datatype2id.INT64=9,KBEngine.datatype2id.PYTHON=10,KBEngine.datatype2id.PY_DICT=10,KBEngine.datatype2id.PY_TUPLE=10,KBEngine.datatype2id.PY_LIST=10,KBEngine.datatype2id.ENTITYCALL=10,KBEngine.datatype2id.BLOB=11,KBEngine.datatype2id.UNICODE=12,KBEngine.datatype2id.FLOAT=13,KBEngine.datatype2id.DOUBLE=14,KBEngine.datatype2id.VECTOR2=15,KBEngine.datatype2id.VECTOR3=16,KBEngine.datatype2id.VECTOR4=17,KBEngine.datatype2id.FIXED_DICT=18,KBEngine.datatype2id.ARRAY=19}function bindWriter(e,n){switch(n){case KBEngine.datatype2id.UINT8:return e.writeUint8;case KBEngine.datatype2id.UINT16:return e.writeUint16;case KBEngine.datatype2id.UINT32:return e.writeUint32;case KBEngine.datatype2id.UINT64:return e.writeUint64;case KBEngine.datatype2id.INT8:return e.writeInt8;case KBEngine.datatype2id.INT16:return e.writeInt16;case KBEngine.datatype2id.INT32:return e.writeInt32;case KBEngine.datatype2id.INT64:return e.writeInt64;case KBEngine.datatype2id.FLOAT:return e.writeFloat;case KBEngine.datatype2id.DOUBLE:return e.writeDouble;case KBEngine.datatype2id.STRING:return e.writeString;case KBEngine.datatype2id.FIXED_DICT:return e.writeStream;case KBEngine.datatype2id.ARRAY:return e.writeStream;default:return e.writeStream}}function bindReader(e){switch(e){case KBEngine.datatype2id.UINT8:return KBEngine.reader.readUint8;case KBEngine.datatype2id.UINT16:return KBEngine.reader.readUint16;case KBEngine.datatype2id.UINT32:return KBEngine.reader.readUint32;case KBEngine.datatype2id.UINT64:return KBEngine.reader.readUint64;case KBEngine.datatype2id.INT8:return KBEngine.reader.readInt8;case KBEngine.datatype2id.INT16:return KBEngine.reader.readInt16;case KBEngine.datatype2id.INT32:return KBEngine.reader.readInt32;case KBEngine.datatype2id.INT64:return KBEngine.reader.readInt64;case KBEngine.datatype2id.FLOAT:return KBEngine.reader.readFloat;case KBEngine.datatype2id.DOUBLE:return KBEngine.reader.readDouble;case KBEngine.datatype2id.STRING:return KBEngine.reader.readString;case KBEngine.datatype2id.FIXED_DICT:return KBEngine.reader.readStream;case KBEngine.datatype2id.ARRAY:return KBEngine.reader.readStream;default:return KBEngine.reader.readStream}}function clampf(e,n,t){if(n>t){var i=n;n=t,t=i}return n>e?n:t>e?e:t}function int82angle(e,n){return e*(Math.PI/(n?254:128))}function angle2int8(e,n){var t=0;return t=n?clampf(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}function create(e){if(void 0==KBEngine.app){if(e.constructor!=KBEngineArgs)return void ERROR_MSG("create(): args("+e+") error! not is KBEngineArgs");new KBEngineApp(e),KBEngine.app.reset(),KBEngine.app.installEvents(),idInterval=setInterval(KBEngine.app.update,e.updateHZ)}}function destroy(){void 0!=idInterval&&clearInterval(idInterval),void 0!=KBEngine.app&&(KBEngine.app.uninstallEvents(),KBEngine.app.reset(),KBEngine.app=void 0)}var Class=function(){function e(){}return e}();KBEngine.Class=Class,__reflect(Class.prototype,"KBEngine.Class"),KBEngine.PACKET_MAX_SIZE=1500,KBEngine.PACKET_MAX_SIZE_TCP=1460,KBEngine.PACKET_MAX_SIZE_UDP=1472,KBEngine.MESSAGE_ID_LENGTH=2,KBEngine.MESSAGE_LENGTH_LENGTH=2,KBEngine.CLIENT_NO_FLOAT=0,KBEngine.KBE_FLT_MAX=3.402823466e38;var INT64=function(){function e(e,n){this.sign=1,this.lo=e,this.hi=n,n>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var n=this.lo.toString(16),t=this.hi.toString(16);if(this.hi>0){e+=t;for(var i=8-n.length;i>0;--i)e+="0"}return e+=n},e}();KBEngine.INT64=INT64,__reflect(INT64.prototype,"KBEngine.INT64");var UINT64=function(){function e(e,n){this.lo=e,this.hi=n}return e.prototype.toString=function(){var e=this.lo.toString(16),n=this.hi.toString(16),t="";if(this.hi>0){t+=n;for(var i=8-e.length;i>0;--i)t+="0"}return t+=e},e}();KBEngine.UINT64=UINT64,__reflect(UINT64.prototype,"KBEngine.UINT64"),KBEngine.INFO_MSG=INFO_MSG,KBEngine.DEBUG_MSG=DEBUG_MSG,KBEngine.ERROR_MSG=ERROR_MSG,KBEngine.WARNING_MSG=WARNING_MSG,KBEngine.utf8ArrayToString=utf8ArrayToString,KBEngine.stringToUTF8Bytes=stringToUTF8Bytes;var EventInfo=function(){function e(e,n){this.callbackfn=n,this.classinst=e}return e}();KBEngine.EventInfo=EventInfo,__reflect(EventInfo.prototype,"KBEngine.EventInfo");var Events=function(){function Events(){this._events={}}return Events.prototype.register=function(evtName,classinst,strCallback){var callbackfn=eval("classinst."+strCallback);if(void 0==callbackfn)return void ERROR_MSG("export class Event::fire: not found strCallback("+classinst+")!"+strCallback);var evtlst=this._events[evtName];void 0==evtlst&&(evtlst=[],this._events[evtName]=evtlst);var info=new EventInfo(classinst,callbackfn);evtlst.push(info)},Events.prototype.deregister=function(e,n){for(var t in this._events)for(var i=this._events[t];;){for(var r=!1,a=0;a=32768&&(e-=65536),e},e.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},e.prototype.readInt64=function(){return new INT64(this.readUint32(),this.readUint32())},e.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},e.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},e.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},e.prototype.readUint64=function(){return new UINT64(this.readUint32(),this.readUint32())},e.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(n){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},e.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(n){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},e.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),n=0,t="";;){if(0==e[n]){n++;break}if(t+=String.fromCharCode(e[n]),n++,this.rpos+n>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+n)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=n,t},e.prototype.readBlob=function(){var e=this.readUint32(),n=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,n},e.prototype.readStream=function(){var n=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new e(n)},e.prototype.readPackXZ=function(){var n=new e.PackFloatXType,t=new e.PackFloatXType;n.fv[0]=0,t.fv[0]=0,n.uv[0]=1073741824,t.uv[0]=1073741824;var i=this.readUint8(),r=this.readUint8(),a=this.readUint8(),p=0;p|=i<<16,p|=r<<8,p|=a,n.uv[0]|=(8384512&p)<<3,t.uv[0]|=(2047&p)<<15,n.fv[0]-=2,t.fv[0]-=2,n.uv[0]|=(8388608&p)<<8,t.uv[0]|=(2048&p)<<20;var o=new Array(2);return o[0]=n.fv[0],o[1]=t.fv[0],o},e.prototype.readPackY=function(){var e=this.readUint16();return e},e.prototype.writeInt8=function(e){var n=new Int8Array(this.buffer,this.wpos,1);n[0]=e,this.wpos+=1},e.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},e.prototype.writeInt32=function(e){for(var n=0;4>n;n++)this.writeInt8(e>>8*n&255)},e.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},e.prototype.writeUint8=function(e){var n=new Uint8Array(this.buffer,this.wpos,1);n[0]=e,this.wpos+=1},e.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},e.prototype.writeUint32=function(e){for(var n=0;4>n;n++)this.writeUint8(e>>8*n&255)},e.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},e.prototype.writeFloat=function(e){try{var n=new Float32Array(this.buffer,this.wpos,1);n[0]=e}catch(t){var n=new Float32Array(1);n[0]=e;var i=new Uint8Array(this.buffer),r=new Uint8Array(n.buffer);i.set(r,this.wpos)}this.wpos+=4},e.prototype.writeDouble=function(e){try{var n=new Float64Array(this.buffer,this.wpos,1);n[0]=e}catch(t){var n=new Float64Array(1);n[0]=e;var i=new Uint8Array(this.buffer),r=new Uint8Array(n.buffer);i.set(r,this.wpos)}this.wpos+=8},e.prototype.writeBlob=function(e){var n=e.length;if(n+4>this.space())return void ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var t=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof e)for(var i=0;n>i;i++)t[i]=e.charCodeAt(i);else for(var i=0;n>i;i++)t[i]=e[i];this.wpos+=n},e.prototype.writeString=function(e){if(e.length>this.space())return void ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),t=0,i=0;i>8&255)},e.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},e.prototype.send=function(e){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP)),this.messageLength+=e},e.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},e.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},e.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},e.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},e.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},e.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},e.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},e.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},e.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},e.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},e.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},e.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},e}();KBEngine.Bundle=Bundle,__reflect(Bundle.prototype,"KBEngine.Bundle"),KBEngine.reader=new MemoryStream(0),KBEngine.datatype2id={},KBEngine.mappingDataType=mappingDataType,mappingDataType(),KBEngine.bindWriter=bindWriter,KBEngine.bindReader=bindReader;var Message=function(){function e(e,n,t,i,r,a){this.id=e,this.name=n,this.length=t,this.argsType=i;for(var p=0;pe||e>255?!1:!0},DATATYPE_UINT8}();KBEngine.DATATYPE_UINT8=DATATYPE_UINT8,__reflect(DATATYPE_UINT8.prototype,"KBEngine.DATATYPE_UINT8");var DATATYPE_UINT16=function(){function DATATYPE_UINT16(){}return DATATYPE_UINT16.prototype.bind=function(){},DATATYPE_UINT16.prototype.createFromStream=function(e){return KBEngine.reader.readUint16.call(e)},DATATYPE_UINT16.prototype.addToStream=function(e,n){e.writeUint16(n)},DATATYPE_UINT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},DATATYPE_UINT16}();KBEngine.DATATYPE_UINT16=DATATYPE_UINT16,__reflect(DATATYPE_UINT16.prototype,"KBEngine.DATATYPE_UINT16");var DATATYPE_UINT32=function(){function DATATYPE_UINT32(){}return DATATYPE_UINT32.prototype.bind=function(){},DATATYPE_UINT32.prototype.createFromStream=function(e){return KBEngine.reader.readUint32.call(e)},DATATYPE_UINT32.prototype.addToStream=function(e,n){e.writeUint32(n)},DATATYPE_UINT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},DATATYPE_UINT32}();KBEngine.DATATYPE_UINT32=DATATYPE_UINT32,__reflect(DATATYPE_UINT32.prototype,"KBEngine.DATATYPE_UINT32");var DATATYPE_UINT64=function(){function DATATYPE_UINT64(){}return DATATYPE_UINT64.prototype.bind=function(){},DATATYPE_UINT64.prototype.createFromStream=function(e){return KBEngine.reader.readUint64.call(e)},DATATYPE_UINT64.prototype.addToStream=function(e,n){e.writeUint64(n)},DATATYPE_UINT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT64.prototype.isSameType=function(e){return e instanceof UINT64},DATATYPE_UINT64}();KBEngine.DATATYPE_UINT64=DATATYPE_UINT64,__reflect(DATATYPE_UINT64.prototype,"KBEngine.DATATYPE_UINT64");var DATATYPE_INT8=function(){function DATATYPE_INT8(){}return DATATYPE_INT8.prototype.bind=function(){},DATATYPE_INT8.prototype.createFromStream=function(e){return KBEngine.reader.readInt8.call(e)},DATATYPE_INT8.prototype.addToStream=function(e,n){e.writeInt8(n)},DATATYPE_INT8.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT8.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},DATATYPE_INT8}();KBEngine.DATATYPE_INT8=DATATYPE_INT8,__reflect(DATATYPE_INT8.prototype,"KBEngine.DATATYPE_INT8");var DATATYPE_INT16=function(){function DATATYPE_INT16(){}return DATATYPE_INT16.prototype.bind=function(){},DATATYPE_INT16.prototype.createFromStream=function(e){return KBEngine.reader.readInt16.call(e)},DATATYPE_INT16.prototype.addToStream=function(e,n){e.writeInt16(n)},DATATYPE_INT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},DATATYPE_INT16}();KBEngine.DATATYPE_INT16=DATATYPE_INT16,__reflect(DATATYPE_INT16.prototype,"KBEngine.DATATYPE_INT16");var DATATYPE_INT32=function(){function DATATYPE_INT32(){}return DATATYPE_INT32.prototype.bind=function(){},DATATYPE_INT32.prototype.createFromStream=function(e){return KBEngine.reader.readInt32.call(e)},DATATYPE_INT32.prototype.addToStream=function(e,n){e.writeInt32(n)},DATATYPE_INT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},DATATYPE_INT32}();KBEngine.DATATYPE_INT32=DATATYPE_INT32,__reflect(DATATYPE_INT32.prototype,"KBEngine.DATATYPE_INT32");var DATATYPE_INT64=function(){function DATATYPE_INT64(){}return DATATYPE_INT64.prototype.bind=function(){},DATATYPE_INT64.prototype.createFromStream=function(e){return KBEngine.reader.readInt64.call(e)},DATATYPE_INT64.prototype.addToStream=function(e,n){e.writeInt64(n)},DATATYPE_INT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT64.prototype.isSameType=function(e){return e instanceof INT64},DATATYPE_INT64}();KBEngine.DATATYPE_INT64=DATATYPE_INT64,__reflect(DATATYPE_INT64.prototype,"KBEngine.DATATYPE_INT64");var DATATYPE_FLOAT=function(){function DATATYPE_FLOAT(){}return DATATYPE_FLOAT.prototype.bind=function(){},DATATYPE_FLOAT.prototype.createFromStream=function(e){return KBEngine.reader.readFloat.call(e)},DATATYPE_FLOAT.prototype.addToStream=function(e,n){e.writeFloat(n)},DATATYPE_FLOAT.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_FLOAT.prototype.isSameType=function(e){return"number"==typeof e},DATATYPE_FLOAT}();KBEngine.DATATYPE_FLOAT=DATATYPE_FLOAT,__reflect(DATATYPE_FLOAT.prototype,"KBEngine.DATATYPE_FLOAT");var DATATYPE_DOUBLE=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.createFromStream=function(e){return KBEngine.reader.readDouble.call(e)},n.prototype.addToStream=function(e,n){e.writeDouble(n)},n}(DATATYPE_FLOAT);KBEngine.DATATYPE_DOUBLE=DATATYPE_DOUBLE,__reflect(DATATYPE_DOUBLE.prototype,"KBEngine.DATATYPE_DOUBLE");var DATATYPE_STRING=function(){function DATATYPE_STRING(){}return DATATYPE_STRING.prototype.bind=function(){},DATATYPE_STRING.prototype.createFromStream=function(e){return KBEngine.reader.readString.call(e)},DATATYPE_STRING.prototype.addToStream=function(e,n){e.writeString(n)},DATATYPE_STRING.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_STRING.prototype.isSameType=function(e){return"string"==typeof e},DATATYPE_STRING}();KBEngine.DATATYPE_STRING=DATATYPE_STRING,__reflect(DATATYPE_STRING.prototype,"KBEngine.DATATYPE_STRING");var DATATYPE_VECTOR2=function(){function DATATYPE_VECTOR2(){}return DATATYPE_VECTOR2.prototype.bind=function(){},DATATYPE_VECTOR2.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR2.prototype.addToStream=function(e,n){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y)):(e.writeFloat(n.x),e.writeFloat(n.y))},DATATYPE_VECTOR2.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR2.prototype.isSameType=function(e){return e instanceof Vector3?!0:!1},DATATYPE_VECTOR2}();KBEngine.DATATYPE_VECTOR2=DATATYPE_VECTOR2,__reflect(DATATYPE_VECTOR2.prototype,"KBEngine.DATATYPE_VECTOR2");var DATATYPE_VECTOR3=function(){function DATATYPE_VECTOR3(){}return DATATYPE_VECTOR3.prototype.bind=function(){},DATATYPE_VECTOR3.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR3.prototype.addToStream=function(e,n){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z))},DATATYPE_VECTOR3.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR3.prototype.isSameType=function(e){return e instanceof Vector3?!0:!1},DATATYPE_VECTOR3}();KBEngine.DATATYPE_VECTOR3=DATATYPE_VECTOR3,__reflect(DATATYPE_VECTOR3.prototype,"KBEngine.DATATYPE_VECTOR3");var DATATYPE_VECTOR4=function(){function DATATYPE_VECTOR4(){}return DATATYPE_VECTOR4.prototype.bind=function(){},DATATYPE_VECTOR4.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR4.prototype.addToStream=function(e,n){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z),e.writeInt32(n.w)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z),e.writeFloat(n.w))},DATATYPE_VECTOR4.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR4.prototype.isSameType=function(e){return e instanceof Vector3?!0:!1},DATATYPE_VECTOR4}();KBEngine.DATATYPE_VECTOR4=DATATYPE_VECTOR4,__reflect(DATATYPE_VECTOR4.prototype,"KBEngine.DATATYPE_VECTOR4");var DATATYPE_PYTHON=function(){function DATATYPE_PYTHON(){}return DATATYPE_PYTHON.prototype.bind=function(){},DATATYPE_PYTHON.prototype.createFromStream=function(e){},DATATYPE_PYTHON.prototype.addToStream=function(e,n){},DATATYPE_PYTHON.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_PYTHON.prototype.isSameType=function(e){return!1},DATATYPE_PYTHON}();KBEngine.DATATYPE_PYTHON=DATATYPE_PYTHON,__reflect(DATATYPE_PYTHON.prototype,"KBEngine.DATATYPE_PYTHON");var DATATYPE_UNICODE=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return utf8ArrayToString(KBEngine.reader.readBlob.call(e))},e.prototype.addToStream=function(e,n){e.writeBlob(stringToUTF8Bytes(n))},e.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},e.prototype.isSameType=function(e){return"string"==typeof e},e}();KBEngine.DATATYPE_UNICODE=DATATYPE_UNICODE,__reflect(DATATYPE_UNICODE.prototype,"KBEngine.DATATYPE_UNICODE");var DATATYPE_ENTITYCALL=function(){function DATATYPE_ENTITYCALL(){}return DATATYPE_ENTITYCALL.prototype.bind=function(){},DATATYPE_ENTITYCALL.prototype.createFromStream=function(e){},DATATYPE_ENTITYCALL.prototype.addToStream=function(e,n){},DATATYPE_ENTITYCALL.prototype.parseDefaultValStr=function(v){return eval(v) -},DATATYPE_ENTITYCALL.prototype.isSameType=function(e){return!1},DATATYPE_ENTITYCALL}();KBEngine.DATATYPE_ENTITYCALL=DATATYPE_ENTITYCALL,__reflect(DATATYPE_ENTITYCALL.prototype,"KBEngine.DATATYPE_ENTITYCALL");var DATATYPE_BLOB=function(){function DATATYPE_BLOB(){}return DATATYPE_BLOB.prototype.bind=function(){},DATATYPE_BLOB.prototype.createFromStream=function(e){var n=KBEngine.reader.readUint32.call(e),t=new Uint8Array(e.buffer,e.rpos,n);return e.rpos+=n,t},DATATYPE_BLOB.prototype.addToStream=function(e,n){e.writeBlob(n)},DATATYPE_BLOB.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_BLOB.prototype.isSameType=function(e){return!0},DATATYPE_BLOB}();KBEngine.DATATYPE_BLOB=DATATYPE_BLOB,__reflect(DATATYPE_BLOB.prototype,"KBEngine.DATATYPE_BLOB");var DATATYPE_ARRAY=function(){function DATATYPE_ARRAY(){this.type=null}return DATATYPE_ARRAY.prototype.bind=function(){"number"==typeof this.type&&(this.type=datatypes[this.type])},DATATYPE_ARRAY.prototype.createFromStream=function(e){for(var n=e.readUint32(),t=[];n>0;)n--,t.push(this.type.createFromStream(e));return t},DATATYPE_ARRAY.prototype.addToStream=function(e,n){e.writeUint32(n.length);for(var t=0;tKBEngine.app.args.serverHeartbeatTick){if(KBEngine.app.lastTickCBTime0;){n-=1;var t=new ServerErr;t.id=e.readUint16(),t.name=utf8ArrayToString(e.readBlob()),t.descr=utf8ArrayToString(e.readBlob()),KBEngine.app.serverErrs[t.id]=t,INFO_MSG("Client_onImportServerErrorsDescr: id="+t.id+", name="+t.name+", descr="+t.descr)}},KBEngineApp.prototype.onOpenLoginapp_login=function(){if(INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),KBEngine.Event.fire("onConnectionState",!0),KBEngine.app.currserver="loginapp",KBEngine.app.currstate="login",KBEngine.app.loginappMessageImported)KBEngine.app.onImportClientMessagesCompleted();else{var e=new Bundle;e.newMessage(messages.Loginapp_importClientMessages),e.send(KBEngine.app),KBEngine.app.socket.onmessage=KBEngine.app.Client_onImportClientMessages,INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),KBEngine.Event.fire("Loginapp_importClientMessages")}},KBEngineApp.prototype.onOpenLoginapp_createAccount=function(){if(KBEngine.Event.fire("onConnectionState",!0),INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),KBEngine.app.currserver="loginapp",KBEngine.app.currstate="createAccount",KBEngine.app.loginappMessageImported)KBEngine.app.onImportClientMessagesCompleted();else{var e=new Bundle;e.newMessage(messages.Loginapp_importClientMessages),e.send(KBEngine.app),KBEngine.app.socket.onmessage=KBEngine.app.Client_onImportClientMessages,INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),KBEngine.Event.fire("Loginapp_importClientMessages")}},KBEngineApp.prototype.onImportClientMessagesCompleted=function(){if(INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),KBEngine.app.socket.onmessage=KBEngine.app.onmessage,KBEngine.app.hello(),"loginapp"==KBEngine.app.currserver){if(!KBEngine.app.serverErrorsDescrImported){INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),KBEngine.app.serverErrorsDescrImported=!0;var e=new Bundle;e.newMessage(messages.Loginapp_importServerErrorsDescr),e.send(KBEngine.app)}"login"==KBEngine.app.currstate?KBEngine.app.login_loginapp(!1):"resetpassword"==KBEngine.app.currstate?KBEngine.app.resetpassword_loginapp(!1):KBEngine.app.createAccount_loginapp(!1),KBEngine.app.loginappMessageImported=!0}else if(KBEngine.app.baseappMessageImported=!0,KBEngine.app.entitydefImported)KBEngine.app.onImportEntityDefCompleted();else{INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var e=new Bundle;e.newMessage(messages.Baseapp_importClientEntityDef),e.send(KBEngine.app),KBEngine.Event.fire("Baseapp_importClientEntityDef")}},KBEngineApp.prototype.createDataTypeFromStreams=function(e,n){var t=e.readUint16();for(INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+t+")!");t>0;)t--,KBEngine.app.createDataTypeFromStream(e,n);for(var i in datatypes)void 0!=datatypes[i]&&datatypes[i].bind()},KBEngineApp.prototype.createDataTypeFromStream=function(e,n){var t,i=e.readUint16(),r=e.readString(),a=e.readString();if(0==a.length&&(t="Null_"+i),n&&INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+r+":"+a+")!"),"FIXED_DICT"==r){var p=new DATATYPE_FIXED_DICT,o=e.readUint8();for(p.implementedBy=e.readString();o>0;){o--;var s=e.readString(),E=e.readUint16();p.dicttype[s]=E}datatypes[a]=p}else if("ARRAY"==r){var g=e.readUint16(),p=new DATATYPE_ARRAY;p.type=g,datatypes[a]=p}else datatypes[a]=datatypes[r];datatypes[i]=datatypes[a],KBEngine.datatype2id[a]=i},KBEngineApp.prototype.Client_onImportClientEntityDef=function(stream){for(KBEngine.app.createDataTypeFromStreams(stream,!0);!stream.readEOF();){var scriptmodule_name=stream.readString(),scriptUtype=stream.readUint16(),propertysize=stream.readUint16(),methodsize=stream.readUint16(),base_methodsize=stream.readUint16(),cell_methodsize=stream.readUint16();INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+scriptmodule_name+"), propertys("+propertysize+"), clientMethods("+methodsize+"), baseMethods("+base_methodsize+"), cellMethods("+cell_methodsize+")!"),KBEngine.moduledefs[scriptmodule_name]={};var currModuleDefs=KBEngine.moduledefs[scriptmodule_name];currModuleDefs.name=scriptmodule_name,currModuleDefs.propertys={},currModuleDefs.methods={},currModuleDefs.base_methods={},currModuleDefs.cell_methods={},KBEngine.moduledefs[scriptUtype]=currModuleDefs;var self_propertys=currModuleDefs.propertys,self_methods=currModuleDefs.methods,self_base_methods=currModuleDefs.base_methods,self_cell_methods=currModuleDefs.cell_methods;try{var Class_1=eval(""+scriptmodule_name)}catch(e){var Class_2=void 0}for(;propertysize>0;){propertysize--;var properUtype=stream.readUint16(),properFlags=stream.readUint32(),aliasID=stream.readInt16(),name_2=stream.readString(),defaultValStr=stream.readString(),utype=datatypes[stream.readUint16()],setmethod=null;void 0!=Class&&(setmethod=Class.prototype["set_"+name_2],void 0==setmethod&&(setmethod=null));var savedata=[properUtype,aliasID,name_2,defaultValStr,utype,setmethod,properFlags];self_propertys[name_2]=savedata,-1!=aliasID?(self_propertys[aliasID]=savedata,currModuleDefs.usePropertyDescrAlias=!0):(self_propertys[properUtype]=savedata,currModuleDefs.usePropertyDescrAlias=!1),INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+scriptmodule_name+"), property("+name_2+"/"+properUtype+").")}for(;methodsize>0;){methodsize--;for(var methodUtype=stream.readUint16(),aliasID=stream.readInt16(),name_3=stream.readString(),argssize=stream.readUint8(),args=[];argssize>0;)argssize--,args.push(datatypes[stream.readUint16()]);var savedata=[methodUtype,aliasID,name_3,args];self_methods[name_3]=savedata,-1!=aliasID?(self_methods[aliasID]=savedata,currModuleDefs.useMethodDescrAlias=!0):(self_methods[methodUtype]=savedata,currModuleDefs.useMethodDescrAlias=!1),INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+scriptmodule_name+"), method("+name_3+").")}for(;base_methodsize>0;){base_methodsize--;for(var methodUtype=stream.readUint16(),aliasID=stream.readInt16(),name_4=stream.readString(),argssize=stream.readUint8(),args=[];argssize>0;)argssize--,args.push(datatypes[stream.readUint16()]);self_base_methods[name_4]=[methodUtype,aliasID,name_4,args],INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+scriptmodule_name+"), base_method("+name_4+").")}for(;cell_methodsize>0;){cell_methodsize--;for(var methodUtype=stream.readUint16(),aliasID=stream.readInt16(),name_5=stream.readString(),argssize=stream.readUint8(),args=[];argssize>0;)argssize--,args.push(datatypes[stream.readUint16()]);self_cell_methods[name_5]=[methodUtype,aliasID,name_5,args],INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+scriptmodule_name+"), cell_method("+name_5+").")}var defmethod=void 0;try{defmethod=eval(""+scriptmodule_name)}catch(e){ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+scriptmodule_name+") not found!"),defmethod=void 0}for(var name_6 in currModuleDefs.propertys){var infos=currModuleDefs.propertys[name_6],properUtype=infos[0],aliasID=infos[1],n=infos[2],defaultValStr=infos[3],utype=infos[4];void 0!=defmethod&&(defmethod.prototype[n]=utype.parseDefaultValStr(defaultValStr))}for(var name_7 in currModuleDefs.methods){var infos=currModuleDefs.methods[name_7],properUtype=infos[0],aliasID=infos[1],n=infos[2],args=infos[3];void 0!=defmethod&&void 0==defmethod.prototype[n]&&WARNING_MSG(scriptmodule_name+":: method("+n+") no implement!")}}KBEngine.app.onImportEntityDefCompleted()},KBEngineApp.prototype.Client_onVersionNotMatch=function(e){KBEngine.app.serverVersion=e.readString(),ERROR_MSG("Client_onVersionNotMatch: verInfo="+KBEngine.app.clientVersion+" not match(server: "+KBEngine.app.serverVersion+")"),KBEngine.Event.fire("onVersionNotMatch",KBEngine.app.clientVersion,KBEngine.app.serverVersion)},KBEngineApp.prototype.Client_onScriptVersionNotMatch=function(e){KBEngine.app.serverScriptVersion=e.readString(),ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+KBEngine.app.clientScriptVersion+" not match(server: "+KBEngine.app.serverScriptVersion+")"),KBEngine.Event.fire("onScriptVersionNotMatch",KBEngine.app.clientScriptVersion,KBEngine.app.serverScriptVersion)},KBEngineApp.prototype.onImportEntityDefCompleted=function(){INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),KBEngine.app.entitydefImported=!0,KBEngine.app.login_baseapp(!1)},KBEngineApp.prototype.Client_onImportClientMessages=function(e){var n=new MemoryStream(e.data),t=n.readUint16();if(t==messages.onImportClientMessages.id){var i=n.readUint16(),r=n.readUint16();for(INFO_MSG("KBEngineApp::onImportClientMessages: start("+r+") ...!");r>0;){r--,t=n.readUint16(),i=n.readInt16();for(var a=n.readString(),p=n.readInt8(),o=n.readUint8(),s=new Array(o),E=0;o>E;E++)s[E]=n.readUint8();var g=null,l=a.indexOf("Client_")>=0;l&&(g=KBEngine.app[a],null==g||void 0==g?(WARNING_MSG("KBEngineApp::onImportClientMessages["+KBEngine.app.currserver+"]: interface("+a+"/"+t+") no implement!"),g=null):INFO_MSG("KBEngineApp::onImportClientMessages: import("+a+") successfully!")),a.length>0?(messages[a]=new Message(t,a,i,p,s,g),l?KBEngine.clientmessages[t]=messages[a]:messages[KBEngine.app.currserver][t]=messages[a]):messages[KBEngine.app.currserver][t]=new Message(t,a,i,p,s,g)}KBEngine.app.onImportClientMessagesCompleted()}else ERROR_MSG("KBEngineApp::onmessage: not found msg("+t+")!")},KBEngineApp.prototype.createAccount=function(e,n,t){KBEngine.app.reset(),KBEngine.app.username=e,KBEngine.app.password=n,KBEngine.app.clientdatas=t,KBEngine.app.createAccount_loginapp(!0)},KBEngineApp.prototype.createAccount_loginapp=function(e){if(e)INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+KBEngine.app.ip+":"+KBEngine.app.port+"!"),KBEngine.app.connect("ws://"+KBEngine.app.ip+":"+KBEngine.app.port),KBEngine.app.socket.onopen=KBEngine.app.onOpenLoginapp_createAccount;else{var n=new Bundle;n.newMessage(messages.Loginapp_reqCreateAccount),n.writeString(KBEngine.app.username),n.writeString(KBEngine.app.password),n.writeBlob(KBEngine.app.clientdatas),n.send(KBEngine.app)}},KBEngineApp.prototype.bindAccountEmail=function(e){var n=new Bundle;n.newMessage(messages.Baseapp_reqAccountBindEmail),n.writeInt32(KBEngine.app.entity_id),n.writeString(KBEngine.app.password),n.writeString(e),n.send(KBEngine.app)},KBEngineApp.prototype.newPassword=function(e,n){var t=new Bundle;t.newMessage(messages.Baseapp_reqAccountNewPassword),t.writeInt32(KBEngine.app.entity_id),t.writeString(e),t.writeString(n),t.send(KBEngine.app)},KBEngineApp.prototype.login=function(e,n,t){KBEngine.app.reset(),KBEngine.app.username=e,KBEngine.app.password=n,KBEngine.app.clientdatas=t,KBEngine.app.login_loginapp(!0)},KBEngineApp.prototype.login_loginapp=function(e){if(e)INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+KBEngine.app.ip+":"+KBEngine.app.port+"!"),KBEngine.app.connect("ws://"+KBEngine.app.ip+":"+KBEngine.app.port),KBEngine.app.socket.onopen=KBEngine.app.onOpenLoginapp_login;else{var n=new Bundle;n.newMessage(messages.Loginapp_login),n.writeInt8(KBEngine.app.args.clientType),n.writeBlob(KBEngine.app.clientdatas),n.writeString(KBEngine.app.username),n.writeString(KBEngine.app.password),n.send(KBEngine.app)}},KBEngineApp.prototype.onOpenLoginapp_resetpassword=function(){if(INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),KBEngine.app.currserver="loginapp",KBEngine.app.currstate="resetpassword",KBEngine.app.loginappMessageImported)KBEngine.app.onImportClientMessagesCompleted();else{var e=new Bundle;e.newMessage(messages.Loginapp_importClientMessages),e.send(KBEngine.app),KBEngine.app.socket.onmessage=KBEngine.app.Client_onImportClientMessages,INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},KBEngineApp.prototype.reset_password=function(e){KBEngine.app.reset(),KBEngine.app.username=e,KBEngine.app.resetpassword_loginapp(!0)},KBEngineApp.prototype.resetpassword_loginapp=function(e){if(e)INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+KBEngine.app.ip+":"+KBEngine.app.port+"!"),KBEngine.app.connect("ws://"+KBEngine.app.ip+":"+KBEngine.app.port),KBEngine.app.socket.onopen=KBEngine.app.onOpenLoginapp_resetpassword;else{var n=new Bundle;n.newMessage(messages.Loginapp_reqAccountResetPassword),n.writeString(KBEngine.app.username),n.send(KBEngine.app)}},KBEngineApp.prototype.onOpenBaseapp=function(){if(INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),KBEngine.app.currserver="baseapp",KBEngine.app.baseappMessageImported)KBEngine.app.onImportClientMessagesCompleted();else{var e=new Bundle;e.newMessage(messages.Baseapp_importClientMessages),e.send(KBEngine.app),KBEngine.app.socket.onmessage=KBEngine.app.Client_onImportClientMessages,KBEngine.Event.fire("Baseapp_importClientMessages")}},KBEngineApp.prototype.login_baseapp=function(e){if(e)KBEngine.Event.fire("onLoginBaseapp"),INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+KBEngine.app.baseappIp+":"+KBEngine.app.baseappPort+"!"),KBEngine.app.connect("ws://"+KBEngine.app.baseappIp+":"+KBEngine.app.baseappPort),void 0!=KBEngine.app.socket&&null!=KBEngine.app.socket&&(KBEngine.app.socket.onopen=KBEngine.app.onOpenBaseapp);else{var n=new Bundle;n.newMessage(messages.Baseapp_loginBaseapp),n.writeString(KBEngine.app.username),n.writeString(KBEngine.app.password),n.send(KBEngine.app)}},KBEngineApp.prototype.reloginBaseapp=function(){(void 0==KBEngine.app.socket||null==KBEngine.app.socket)&&(KBEngine.app.resetSocket(),KBEngine.Event.fire("onReloginBaseapp"),INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+KBEngine.app.baseappIp+":"+KBEngine.app.baseappPort+"!"),KBEngine.app.connect("ws://"+KBEngine.app.baseappIp+":"+KBEngine.app.baseappPort),void 0!=KBEngine.app.socket&&null!=KBEngine.app.socket&&(KBEngine.app.socket.onopen=KBEngine.app.onReOpenBaseapp))},KBEngineApp.prototype.onReOpenBaseapp=function(){INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),KBEngine.app.currserver="baseapp";var e=new Bundle;e.newMessage(messages.Baseapp_reloginBaseapp),e.writeString(KBEngine.app.username),e.writeString(KBEngine.app.password),e.writeUint64(KBEngine.app.entity_uuid),e.writeInt32(KBEngine.app.entity_id),e.send(KBEngine.app);var n=new Date;KBEngine.app.lastTickCBTime=n.getTime()},KBEngineApp.prototype.Client_onHelloCB=function(e){KBEngine.app.serverVersion=e.readString(),KBEngine.app.serverScriptVersion=e.readString(),KBEngine.app.serverProtocolMD5=e.readString(),KBEngine.app.serverEntityDefMD5=e.readString();var n=e.readInt32();INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+KBEngine.app.serverVersion+"), scriptVerInfo("+KBEngine.app.serverScriptVersion+"), serverProtocolMD5("+KBEngine.app.serverProtocolMD5+"), serverEntityDefMD5("+KBEngine.app.serverEntityDefMD5+"), ctype("+n+")!");var t=new Date;KBEngine.app.lastTickCBTime=t.getTime()},KBEngineApp.prototype.Client_onLoginFailed=function(e){var n=e.readUint16();KBEngine.app.serverdatas=e.readBlob(),ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+KBEngine.app.serverErrs[n].name+"), datas("+KBEngine.app.serverdatas.length+")!"),KBEngine.Event.fire("onLoginFailed",n)},KBEngineApp.prototype.Client_onLoginSuccessfully=function(e){var n=e.readString();KBEngine.app.username=n,KBEngine.app.baseappIp=e.readString(),KBEngine.app.baseappPort=e.readUint16(),KBEngine.app.serverdatas=e.readBlob(),INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+KBEngine.app.baseappIp+":"+KBEngine.app.baseappPort+"), datas("+KBEngine.app.serverdatas.length+")!"),KBEngine.app.disconnect(),KBEngine.app.login_baseapp(!0)},KBEngineApp.prototype.Client_onLoginBaseappFailed=function(e){ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+KBEngine.app.serverErrs[e].name+")!"),KBEngine.Event.fire("onLoginBaseappFailed",e)},KBEngineApp.prototype.Client_onReloginBaseappFailed=function(e){ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+KBEngine.app.serverErrs[e].name+")!"),KBEngine.Event.fire("onReloginBaseappFailed",e)},KBEngineApp.prototype.Client_onReloginBaseappSuccessfully=function(e){KBEngine.app.entity_uuid=e.readUint64(),DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+KBEngine.app.username),KBEngine.Event.fire("onReloginBaseappSuccessfully")},KBEngineApp.prototype.getentityclass=function(entityType){var runclass=KBEngine.app.entityclass[entityType];if(void 0==runclass){if(runclass=eval(""+entityType),void 0==runclass)return ERROR_MSG("KBEngineApp::getentityclass: entityType("+entityType+") is error!"),runclass;KBEngine.app.entityclass[entityType]=runclass}return runclass},KBEngineApp.prototype.Client_onCreatedProxies=function(e,n,t){INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+t+")!");var i=KBEngine.app.entities[n];if(KBEngine.app.entity_uuid=e,KBEngine.app.entity_id=n,void 0==i){var r=KBEngine.app.getentityclass(t);if(void 0==r)return;var a=new r;a.id=n,a.className=t,a.base=new EntityCall,a.base.id=n,a.base.className=t,a.base.type=KBEngine.ENTITYCALL_TYPE_BASE,KBEngine.app.entities[n]=a;var p=KBEngine.bufferedCreateEntityMessage[n];void 0!=p&&(KBEngine.app.Client_onUpdatePropertys(p),delete KBEngine.bufferedCreateEntityMessage[n]),a.__init__(),a.inited=!0,KBEngine.app.args.isOnInitCallPropertysSetMethods&&a.callPropertysSetMethods()}else{var p=KBEngine.bufferedCreateEntityMessage[n];void 0!=p&&(KBEngine.app.Client_onUpdatePropertys(p),delete KBEngine.bufferedCreateEntityMessage[n])}},KBEngineApp.prototype.getViewEntityIDFromStream=function(e){var n=0;if(KBEngine.app.entityIDAliasIDList.length>255)n=e.readInt32();else{var t=e.readUint8();if(KBEngine.app.entityIDAliasIDList.length<=t)return 0;n=KBEngine.app.entityIDAliasIDList[t]}return n},KBEngineApp.prototype.onUpdatePropertys_=function(e,n){var t=KBEngine.app.entities[e];if(void 0==t){var i=KBEngine.bufferedCreateEntityMessage[e];if(void 0!=i)return void ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+e+") not found!");var r=new MemoryStream(n.buffer);return r.wpos=n.wpos,r.rpos=n.rpos-4,void(KBEngine.bufferedCreateEntityMessage[e]=r)}for(var a=KBEngine.moduledefs[t.className],p=a.propertys;n.length()>0;){var o=0;o=a.usePropertyDescrAlias?n.readUint8():n.readUint16();var s=p[o],E=s[5],g=s[6],l=s[4].createFromStream(n),d=t[s[2]];INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+t.className+"(id="+e+" "+s[2]+", val="+l+")!"),t[s[2]]=l,null!=E&&(32==g||64==g?t.inited&&E.call(t,d):t.inWorld&&E.call(t,d))}},KBEngineApp.prototype.Client_onUpdatePropertysOptimized=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e);KBEngine.app.onUpdatePropertys_(n,e)},KBEngineApp.prototype.Client_onUpdatePropertys=function(e){var n=e.readInt32();KBEngine.app.onUpdatePropertys_(n,e)},KBEngineApp.prototype.onRemoteMethodCall_=function(e,n){var t=KBEngine.app.entities[e];if(void 0==t)return void ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+e+") not found!");var i=0;i=KBEngine.moduledefs[t.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var r=KBEngine.moduledefs[t.className].methods[i],a=[],p=r[3],o=0;o0&&n!=KBEngine.app.entity_id&&KBEngine.app.entityIDAliasIDList.push(n);var t;t=KBEngine.moduledefs.Length>255?e.readUint16():e.readUint8();var i=!0;e.length()>0&&(i=e.readInt8()),t=KBEngine.moduledefs[t].name,INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+t+"("+n+"), spaceID("+KBEngine.app.spaceID+"), isOnGround("+i+")!");var r=KBEngine.app.entities[n];if(void 0==r){var a=KBEngine.bufferedCreateEntityMessage[n];if(void 0==a)return void ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=KBEngine.app.getentityclass(t);if(void 0==p)return;var o=new p;o.id=n,o.className=t,o.cell=new EntityCall,o.cell.id=n,o.cell.className=t,o.cell.type=KBEngine.ENTITYCALL_TYPE_CELL,KBEngine.app.entities[n]=o,KBEngine.app.Client_onUpdatePropertys(a),delete KBEngine.bufferedCreateEntityMessage[n],o.isOnGround=i,o.__init__(),o.inited=!0,o.inWorld=!0,o.enterWorld(),KBEngine.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods(),o.set_direction(o.direction),o.set_position(o.position)}else r.inWorld||(r.cell=new EntityCall,r.cell.id=n,r.cell.className=t,r.cell.type=KBEngine.ENTITYCALL_TYPE_CELL,KBEngine.app.entityIDAliasIDList=[],KBEngine.app.entities={},KBEngine.app.entities[r.id]=r,r.set_direction(r.direction),r.set_position(r.position),KBEngine.app.entityServerPos.x=r.position.x,KBEngine.app.entityServerPos.y=r.position.y,KBEngine.app.entityServerPos.z=r.position.z,r.isOnGround=i,r.inWorld=!0,r.enterWorld(),KBEngine.app.args.isOnInitCallPropertysSetMethods&&r.callPropertysSetMethods())},KBEngineApp.prototype.Client_onEntityLeaveWorldOptimized=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e);KBEngine.app.Client_onEntityLeaveWorld(n)},KBEngineApp.prototype.Client_onEntityLeaveWorld=function(e){var n=KBEngine.app.entities[e];if(void 0==n)return void ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+e+") not found!");if(n.inWorld&&n.leaveWorld(),KBEngine.app.entity_id>0&&e!=KBEngine.app.entity_id){for(var t=[],i=0;i0&&(t=e.readInt8());var i=KBEngine.app.entities[n];return void 0==i?void ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(i.isOnGround=t,KBEngine.app.entityServerPos.x=i.position.x,KBEngine.app.entityServerPos.y=i.position.y,KBEngine.app.entityServerPos.z=i.position.z,void i.enterSpace())},KBEngineApp.prototype.Client_onEntityLeaveSpace=function(e){var n=KBEngine.app.entities[e];return void 0==n?void ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+e+") not found!"):(KBEngine.app.clearSpace(!1),void n.leaveSpace())},KBEngineApp.prototype.Client_onKicked=function(e){ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+KBEngine.app.serverErrs[e].name+")!"),KBEngine.Event.fire("onKicked",e)},KBEngineApp.prototype.Client_onCreateAccountResult=function(e){var n=e.readUint16(),t=e.readBlob();return KBEngine.Event.fire("onCreateAccountResult",n,t),0!=n?void ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+KBEngine.app.username+" create is failed! code="+KBEngine.app.serverErrs[n].name+"!"):void INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+KBEngine.app.username+" create is successfully!")},KBEngineApp.prototype.Client_onControlEntity=function(e,n){var t=KBEngine.app.entities[e];if(void 0==t)return void ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+e+") not found!");var i=0!=n;if(i)KBEngine.app.player().id!=t.id&&KBEngine.app.controlledEntities.push(t);else{for(var r=[],a=0;a.001||e.entityLastLocalDir.distance(e.direction)>.001){e.entityLastLocalPos.x=e.position.x,e.entityLastLocalPos.y=e.position.y,e.entityLastLocalPos.z=e.position.z,e.entityLastLocalDir.x=e.direction.x,e.entityLastLocalDir.y=e.direction.y,e.entityLastLocalDir.z=e.direction.z;var n=new Bundle;n.newMessage(messages.Baseapp_onUpdateDataFromClient),n.writeFloat(e.position.x),n.writeFloat(e.position.y),n.writeFloat(e.position.z),n.writeFloat(e.direction.x),n.writeFloat(e.direction.y),n.writeFloat(e.direction.z),n.writeUint8(e.isOnGround),n.writeUint32(KBEngine.app.spaceID),n.send(KBEngine.app)}for(var t in KBEngine.app.controlledEntities){var i=KBEngine.app.controlledEntities[t],r=i.position,a=i.direction,p=i.entityLastLocalPos.distance(r)>.001,o=i.entityLastLocalDir.distance(a)>.001;if(p||o){i.entityLastLocalPos=r,i.entityLastLocalDir=a;var n=new Bundle;n.newMessage(messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(i.id),n.writeFloat(r.x),n.writeFloat(r.y),n.writeFloat(r.z),n.writeFloat(a.x),n.writeFloat(a.y),n.writeFloat(a.z),n.writeUint8(i.isOnGround),n.writeUint32(KBEngine.app.spaceID),n.send(KBEngine.app)}}}},KBEngineApp.prototype.addSpaceGeometryMapping=function(e,n){INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+e+"), respath("+n+")!"),KBEngine.app.spaceID=e,KBEngine.app.spaceResPath=n,KBEngine.Event.fire("addSpaceGeometryMapping",n)},KBEngineApp.prototype.clearSpace=function(e){KBEngine.app.entityIDAliasIDList=[],KBEngine.app.spacedata={},KBEngine.app.clearEntities(e),KBEngine.app.isLoadedGeometry=!1,KBEngine.app.spaceID=0},KBEngineApp.prototype.clearEntities=function(e){if(KBEngine.app.controlledEntities=[],e){for(var n in KBEngine.app.entities)KBEngine.app.entities[n].inWorld&&KBEngine.app.entities[n].leaveWorld(),KBEngine.app.entities[n].onDestroy();KBEngine.app.entities={}}else{var t=KBEngine.app.player();for(var n in KBEngine.app.entities)n!=t.id&&(KBEngine.app.entities[n].inWorld&&KBEngine.app.entities[n].leaveWorld(),KBEngine.app.entities[n].onDestroy());KBEngine.app.entities={},KBEngine.app.entities[t.id]=t}},KBEngineApp.prototype.Client_initSpaceData=function(e){for(KBEngine.app.clearSpace(!1),KBEngine.app.spaceID=e.readInt32();e.length()>0;){var n=e.readString(),t=e.readString();KBEngine.app.Client_setSpaceData(KBEngine.app.spaceID,n,t)}INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+KBEngine.app.spaceID+"), datas("+KBEngine.app.spacedata+")!")},KBEngineApp.prototype.Client_setSpaceData=function(e,n,t){INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+e+"), key("+n+"), value("+t+")!"),KBEngine.app.spacedata[n]=t,"_mapping"==n&&KBEngine.app.addSpaceGeometryMapping(e,t),KBEngine.Event.fire("onSetSpaceData",e,n,t)},KBEngineApp.prototype.Client_delSpaceData=function(e,n){INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+e+"), key("+n+")!"),delete KBEngine.app.spacedata[n],KBEngine.Event.fire("onDelSpaceData",e,n)},KBEngineApp.prototype.Client_getSpaceData=function(e,n){return KBEngine.app.spacedata[n]},KBEngineApp.prototype.Client_onUpdateBasePos=function(e,n,t){KBEngine.app.entityServerPos.x=e,KBEngine.app.entityServerPos.y=n,KBEngine.app.entityServerPos.z=t},KBEngineApp.prototype.Client_onUpdateBasePosXZ=function(e,n){KBEngine.app.entityServerPos.x=e,KBEngine.app.entityServerPos.z=n},KBEngineApp.prototype.Client_onUpdateData=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=KBEngine.app.entities[n];return void 0==t?void ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},KBEngineApp.prototype.Client_onSetEntityPosAndDir=function(e){var n=e.readInt32(),t=KBEngine.app.entities[n];return void 0==t?void ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(t.position.x=e.readFloat(),t.position.y=e.readFloat(),t.position.z=e.readFloat(),t.direction.x=e.readFloat(),t.direction.y=e.readFloat(),t.direction.z=e.readFloat(),t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z,t.set_direction(t.direction),void t.set_position(t.position))},KBEngineApp.prototype.Client_onUpdateData_ypr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8(),i=e.readInt8(),r=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,i,r,-1)},KBEngineApp.prototype.Client_onUpdateData_yp=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8(),i=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,i,KBEngine.KBE_FLT_MAX,-1)},KBEngineApp.prototype.Client_onUpdateData_yr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8(),i=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,KBEngine.KBE_FLT_MAX,i,-1)},KBEngineApp.prototype.Client_onUpdateData_pr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8(),i=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,i,-1)},KBEngineApp.prototype.Client_onUpdateData_y=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,-1)},KBEngineApp.prototype.Client_onUpdateData_p=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,KBEngine.KBE_FLT_MAX,-1)},KBEngineApp.prototype.Client_onUpdateData_r=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readInt8();KBEngine.app._updateVolatileData(n,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,t,-1)},KBEngineApp.prototype.Client_onUpdateData_xz=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,1)},KBEngineApp.prototype.Client_onUpdateData_xz_ypr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8(),r=e.readInt8(),a=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],i,r,a,1)},KBEngineApp.prototype.Client_onUpdateData_xz_yp=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8(),r=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],i,r,KBEngine.KBE_FLT_MAX,1)},KBEngineApp.prototype.Client_onUpdateData_xz_yr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8(),r=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],i,KBEngine.KBE_FLT_MAX,r,1)},KBEngineApp.prototype.Client_onUpdateData_xz_pr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8(),r=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],KBEngine.KBE_FLT_MAX,i,r,1)},KBEngineApp.prototype.Client_onUpdateData_xz_y=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],i,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,1)},KBEngineApp.prototype.Client_onUpdateData_xz_p=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],KBEngine.KBE_FLT_MAX,i,KBEngine.KBE_FLT_MAX,1)},KBEngineApp.prototype.Client_onUpdateData_xz_r=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],KBEngine.KBE_FLT_MAX,t[1],KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,i,1)},KBEngineApp.prototype.Client_onUpdateData_xyz=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY();KBEngine.app._updateVolatileData(n,t[0],i,t[1],KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_ypr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8(),a=e.readInt8(),p=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],r,a,p,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_yp=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8(),a=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],r,a,KBEngine.KBE_FLT_MAX,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_yr=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8(),a=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],r,KBEngine.KBE_FLT_MAX,a,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_pr=function(e){KBEngine.app.getViewEntityIDFromStream(e),e.readPackXZ(),e.readPackY(),e.readInt8(),e.readInt8();ERROR_MSG("调用错误方法,无法找到x,z")},KBEngineApp.prototype.Client_onUpdateData_xyz_y=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],r,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_p=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],KBEngine.KBE_FLT_MAX,r,KBEngine.KBE_FLT_MAX,0)},KBEngineApp.prototype.Client_onUpdateData_xyz_r=function(e){var n=KBEngine.app.getViewEntityIDFromStream(e),t=e.readPackXZ(),i=e.readPackY(),r=e.readInt8();e.readInt8();KBEngine.app._updateVolatileData(n,t[0],i,t[1],r,KBEngine.KBE_FLT_MAX,KBEngine.KBE_FLT_MAX,0)},KBEngineApp.prototype._updateVolatileData=function(e,n,t,i,r,a,p,o){var s=KBEngine.app.entities[e];if(void 0==s)return void ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+e+") not found!");o>=0&&(s.isOnGround=o>0);var E=!1;p!=KBEngine.KBE_FLT_MAX&&(E=!0,s.direction.x=int82angle(p,!1)),a!=KBEngine.KBE_FLT_MAX&&(E=!0,s.direction.y=int82angle(a,!1)),r!=KBEngine.KBE_FLT_MAX&&(E=!0,s.direction.z=int82angle(r,!1));var g=!1;1==E&&(KBEngine.Event.fire("set_direction",s),g=!0);var l=!1;(n!=KBEngine.KBE_FLT_MAX||t!=KBEngine.KBE_FLT_MAX||i!=KBEngine.KBE_FLT_MAX)&&(l=!0),n==KBEngine.KBE_FLT_MAX&&(n=0),t==KBEngine.KBE_FLT_MAX&&(t=0),i==KBEngine.KBE_FLT_MAX&&(i=0),l&&(s.position.x=n+KBEngine.app.entityServerPos.x,s.position.y=t+KBEngine.app.entityServerPos.y,s.position.z=i+KBEngine.app.entityServerPos.z,g=!0,KBEngine.Event.fire("updatePosition",s)),g&&s.onUpdateVolatileData()},KBEngineApp.prototype.Client_onStreamDataStarted=function(e,n,t){KBEngine.Event.fire("onStreamDataStarted",e,n,t)},KBEngineApp.prototype.Client_onStreamDataRecv=function(e){var n=e.readUint16(),t=e.readBlob();KBEngine.Event.fire("onStreamDataRecv",n,t)},KBEngineApp.prototype.Client_onStreamDataCompleted=function(e){KBEngine.Event.fire("onStreamDataCompleted",e)},KBEngineApp.prototype.Client_onReqAccountResetPasswordCB=function(e){return 0!=e?void ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+KBEngine.app.username+" is failed! code="+KBEngine.app.serverErrs[e].name+"!"):void INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+KBEngine.app.username+" is successfully!")},KBEngineApp.prototype.Client_onReqAccountBindEmailCB=function(e){return 0!=e?void ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+KBEngine.app.username+" is failed! code="+KBEngine.app.serverErrs[e].name+"!"):void INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+KBEngine.app.username+" is successfully!")},KBEngineApp.prototype.Client_onReqAccountNewPasswordCB=function(e){return 0!=e?void ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+KBEngine.app.username+" is failed! code="+KBEngine.app.serverErrs[e].name+"!"):void INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+KBEngine.app.username+" is successfully!")},KBEngineApp}();KBEngine.KBEngineApp=KBEngineApp,__reflect(KBEngineApp.prototype,"KBEngine.KBEngineApp");var ServerErr=function(){function e(){this.name="",this.descr="",this.id=0}return e}();KBEngine.ServerErr=ServerErr,__reflect(ServerErr.prototype,"KBEngine.ServerErr");var idInterval;KBEngine.create=create,KBEngine.destroy=destroy}(KBEngine||(KBEngine={})); \ No newline at end of file +var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(e){console.info(e)}function n(e){console.debug(e)}function r(e){console.error(e)}function a(e){console.warn(e)}e.INFO_MSG=t,e.DEBUG_MSG=n,e.ERROR_MSG=r,e.WARNING_MSG=a}(KBEngine||(KBEngine={})),function(e){function t(e){var t,n,r,a,i,o;for(t="",r=e.length,n=0;r>n;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=a,__reflect(a.prototype,"KBEngine.Vector3"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(){for(var t=[],n=0;ne||e>255?!1:!0},DATATYPE_UINT8}();KBEngine.DATATYPE_UINT8=DATATYPE_UINT8,__reflect(DATATYPE_UINT8.prototype,"KBEngine.DATATYPE_UINT8");var DATATYPE_UINT16=function(){function DATATYPE_UINT16(){}return DATATYPE_UINT16.prototype.bind=function(){},DATATYPE_UINT16.prototype.createFromStream=function(e){return KBEngine.reader.readUint16.call(e)},DATATYPE_UINT16.prototype.addToStream=function(e,t){e.writeUint16(t)},DATATYPE_UINT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},DATATYPE_UINT16}();KBEngine.DATATYPE_UINT16=DATATYPE_UINT16,__reflect(DATATYPE_UINT16.prototype,"KBEngine.DATATYPE_UINT16");var DATATYPE_UINT32=function(){function DATATYPE_UINT32(){}return DATATYPE_UINT32.prototype.bind=function(){},DATATYPE_UINT32.prototype.createFromStream=function(e){return KBEngine.reader.readUint32.call(e)},DATATYPE_UINT32.prototype.addToStream=function(e,t){e.writeUint32(t)},DATATYPE_UINT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},DATATYPE_UINT32}();KBEngine.DATATYPE_UINT32=DATATYPE_UINT32,__reflect(DATATYPE_UINT32.prototype,"KBEngine.DATATYPE_UINT32");var DATATYPE_UINT64=function(){function DATATYPE_UINT64(){}return DATATYPE_UINT64.prototype.bind=function(){},DATATYPE_UINT64.prototype.createFromStream=function(e){return KBEngine.reader.readUint64.call(e)},DATATYPE_UINT64.prototype.addToStream=function(e,t){e.writeUint64(t)},DATATYPE_UINT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT64.prototype.isSameType=function(e){return e instanceof KBEngine.UINT64},DATATYPE_UINT64}();KBEngine.DATATYPE_UINT64=DATATYPE_UINT64,__reflect(DATATYPE_UINT64.prototype,"KBEngine.DATATYPE_UINT64");var DATATYPE_INT8=function(){function DATATYPE_INT8(){}return DATATYPE_INT8.prototype.bind=function(){},DATATYPE_INT8.prototype.createFromStream=function(e){return KBEngine.reader.readInt8.call(e)},DATATYPE_INT8.prototype.addToStream=function(e,t){e.writeInt8(t)},DATATYPE_INT8.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT8.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},DATATYPE_INT8}();KBEngine.DATATYPE_INT8=DATATYPE_INT8,__reflect(DATATYPE_INT8.prototype,"KBEngine.DATATYPE_INT8");var DATATYPE_INT16=function(){function DATATYPE_INT16(){}return DATATYPE_INT16.prototype.bind=function(){},DATATYPE_INT16.prototype.createFromStream=function(e){return KBEngine.reader.readInt16.call(e)},DATATYPE_INT16.prototype.addToStream=function(e,t){e.writeInt16(t)},DATATYPE_INT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},DATATYPE_INT16}();KBEngine.DATATYPE_INT16=DATATYPE_INT16,__reflect(DATATYPE_INT16.prototype,"KBEngine.DATATYPE_INT16");var DATATYPE_INT32=function(){function DATATYPE_INT32(){}return DATATYPE_INT32.prototype.bind=function(){},DATATYPE_INT32.prototype.createFromStream=function(e){return KBEngine.reader.readInt32.call(e)},DATATYPE_INT32.prototype.addToStream=function(e,t){e.writeInt32(t)},DATATYPE_INT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},DATATYPE_INT32}();KBEngine.DATATYPE_INT32=DATATYPE_INT32,__reflect(DATATYPE_INT32.prototype,"KBEngine.DATATYPE_INT32");var DATATYPE_INT64=function(){function DATATYPE_INT64(){}return DATATYPE_INT64.prototype.bind=function(){},DATATYPE_INT64.prototype.createFromStream=function(e){return KBEngine.reader.readInt64.call(e)},DATATYPE_INT64.prototype.addToStream=function(e,t){e.writeInt64(t)},DATATYPE_INT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT64.prototype.isSameType=function(e){return e instanceof KBEngine.INT64},DATATYPE_INT64}();KBEngine.DATATYPE_INT64=DATATYPE_INT64,__reflect(DATATYPE_INT64.prototype,"KBEngine.DATATYPE_INT64");var DATATYPE_FLOAT=function(){function DATATYPE_FLOAT(){}return DATATYPE_FLOAT.prototype.bind=function(){},DATATYPE_FLOAT.prototype.createFromStream=function(e){return KBEngine.reader.readFloat.call(e)},DATATYPE_FLOAT.prototype.addToStream=function(e,t){e.writeFloat(t)},DATATYPE_FLOAT.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_FLOAT.prototype.isSameType=function(e){return"number"==typeof e},DATATYPE_FLOAT}();KBEngine.DATATYPE_FLOAT=DATATYPE_FLOAT,__reflect(DATATYPE_FLOAT.prototype,"KBEngine.DATATYPE_FLOAT");var DATATYPE_DOUBLE=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.createFromStream=function(e){return KBEngine.reader.readDouble.call(e)},t.prototype.addToStream=function(e,t){e.writeDouble(t)},t}(DATATYPE_FLOAT);KBEngine.DATATYPE_DOUBLE=DATATYPE_DOUBLE,__reflect(DATATYPE_DOUBLE.prototype,"KBEngine.DATATYPE_DOUBLE");var DATATYPE_STRING=function(){function DATATYPE_STRING(){}return DATATYPE_STRING.prototype.bind=function(){},DATATYPE_STRING.prototype.createFromStream=function(e){return KBEngine.reader.readString.call(e)},DATATYPE_STRING.prototype.addToStream=function(e,t){e.writeString(t)},DATATYPE_STRING.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_STRING.prototype.isSameType=function(e){return"string"==typeof e},DATATYPE_STRING}();KBEngine.DATATYPE_STRING=DATATYPE_STRING,__reflect(DATATYPE_STRING.prototype,"KBEngine.DATATYPE_STRING");var DATATYPE_VECTOR2=function(){function DATATYPE_VECTOR2(){}return DATATYPE_VECTOR2.prototype.bind=function(){},DATATYPE_VECTOR2.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR2.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y)):(e.writeFloat(t.x),e.writeFloat(t.y))},DATATYPE_VECTOR2.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR2.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR2}();KBEngine.DATATYPE_VECTOR2=DATATYPE_VECTOR2,__reflect(DATATYPE_VECTOR2.prototype,"KBEngine.DATATYPE_VECTOR2");var DATATYPE_VECTOR3=function(){function DATATYPE_VECTOR3(){}return DATATYPE_VECTOR3.prototype.bind=function(){},DATATYPE_VECTOR3.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR3.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y),e.writeInt32(t.z)):(e.writeFloat(t.x),e.writeFloat(t.y),e.writeFloat(t.z))},DATATYPE_VECTOR3.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR3.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR3}();KBEngine.DATATYPE_VECTOR3=DATATYPE_VECTOR3,__reflect(DATATYPE_VECTOR3.prototype,"KBEngine.DATATYPE_VECTOR3");var DATATYPE_VECTOR4=function(){function DATATYPE_VECTOR4(){}return DATATYPE_VECTOR4.prototype.bind=function(){},DATATYPE_VECTOR4.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR4.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y),e.writeInt32(t.z),e.writeInt32(t.w)):(e.writeFloat(t.x),e.writeFloat(t.y),e.writeFloat(t.z),e.writeFloat(t.w))},DATATYPE_VECTOR4.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR4.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR4}();KBEngine.DATATYPE_VECTOR4=DATATYPE_VECTOR4,__reflect(DATATYPE_VECTOR4.prototype,"KBEngine.DATATYPE_VECTOR4");var DATATYPE_PYTHON=function(){function DATATYPE_PYTHON(){}return DATATYPE_PYTHON.prototype.bind=function(){},DATATYPE_PYTHON.prototype.createFromStream=function(e){},DATATYPE_PYTHON.prototype.addToStream=function(e,t){},DATATYPE_PYTHON.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_PYTHON.prototype.isSameType=function(e){return!1},DATATYPE_PYTHON}();KBEngine.DATATYPE_PYTHON=DATATYPE_PYTHON,__reflect(DATATYPE_PYTHON.prototype,"KBEngine.DATATYPE_PYTHON");var DATATYPE_UNICODE=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return KBEngine.utf8ArrayToString(KBEngine.reader.readBlob.call(e))},e.prototype.addToStream=function(e,t){e.writeBlob(KBEngine.stringToUTF8Bytes(t))},e.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},e.prototype.isSameType=function(e){return"string"==typeof e},e}();KBEngine.DATATYPE_UNICODE=DATATYPE_UNICODE,__reflect(DATATYPE_UNICODE.prototype,"KBEngine.DATATYPE_UNICODE");var DATATYPE_ENTITYCALL=function(){function DATATYPE_ENTITYCALL(){}return DATATYPE_ENTITYCALL.prototype.bind=function(){},DATATYPE_ENTITYCALL.prototype.createFromStream=function(e){},DATATYPE_ENTITYCALL.prototype.addToStream=function(e,t){},DATATYPE_ENTITYCALL.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_ENTITYCALL.prototype.isSameType=function(e){return!1},DATATYPE_ENTITYCALL}();KBEngine.DATATYPE_ENTITYCALL=DATATYPE_ENTITYCALL,__reflect(DATATYPE_ENTITYCALL.prototype,"KBEngine.DATATYPE_ENTITYCALL");var DATATYPE_BLOB=function(){function DATATYPE_BLOB(){}return DATATYPE_BLOB.prototype.bind=function(){},DATATYPE_BLOB.prototype.createFromStream=function(e){var t=KBEngine.reader.readUint32.call(e),n=new Uint8Array(e.buffer,e.rpos,t);return e.rpos+=t,n},DATATYPE_BLOB.prototype.addToStream=function(e,t){e.writeBlob(t)},DATATYPE_BLOB.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_BLOB.prototype.isSameType=function(e){return!0},DATATYPE_BLOB}();KBEngine.DATATYPE_BLOB=DATATYPE_BLOB,__reflect(DATATYPE_BLOB.prototype,"KBEngine.DATATYPE_BLOB");var DATATYPE_ARRAY=function(){function DATATYPE_ARRAY(){this.type=null}return DATATYPE_ARRAY.prototype.bind=function(){"number"==typeof this.type&&(this.type=datatypes[this.type])},DATATYPE_ARRAY.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},DATATYPE_ARRAY.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,T=s.cell_methods;try{var u=Entities[n]}catch(_){}for(;a>0;){a--;var E=t.readUint16(),y=t.readUint32(),f=t.readInt16(),A=t.readString(),g=t.readString(),v=e.datatypes[t.readUint16()],h=null;void 0!=u&&(h=u.prototype["set_"+A],void 0==h&&(h=null));var m=[E,f,A,g,v,h,y];l[A]=m,-1!=f?(l[f]=m,s.usePropertyDescrAlias=!0):(l[E]=m,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+A+"/"+E+").")}for(;i>0;){i--;for(var I=t.readUint16(),f=t.readInt16(),D=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);var m=[I,f,D,B];c[D]=m,-1!=f?(c[f]=m,s.useMethodDescrAlias=!0):(c[I]=m,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+D+").")}for(;o>0;){o--;for(var I=t.readUint16(),f=t.readInt16(),P=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);d[P]=[I,f,P,B],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+P+").")}for(;p>0;){p--;for(var I=t.readUint16(),f=t.readInt16(),C=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);T[C]=[I,f,C,B],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+C+").")}var w=void 0;try{w=Entities[n]}catch(_){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),w=void 0}for(var M in s.propertys){var N=s.propertys[M],E=N[0],f=N[1],Y=N[2],g=N[3],v=N[4];void 0!=w&&(w.prototype[Y]=v.parseDefaultValStr(g))}for(var L in s.methods){var N=s.methods[L],E=N[0],f=N[1],Y=N[2],B=N[3];void 0!=w&&void 0==w.prototype[Y]&&e.WARNING_MSG(n+":: method("+Y+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,T=o.indexOf("Client_")>=0;T&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),T?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.args.protocol+e.app.baseappIp+":"+e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.args.protocol+e.app.baseappIp+":"+e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessage[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessage[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],T=l[4].createFromStream(n),u=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+T+")!"),r[l[2]]=T,null!=c&&(32==d||64==d?r.inited&&c.call(r,u):r.inWorld&&c.call(r,u))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessage[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessage[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(); +e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0)},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var T=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(T=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),T&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file From afede99865be0d6c1d1ae2e757a062955bc1235f Mon Sep 17 00:00:00 2001 From: zengmn <761458545@qq.com> Date: Sun, 8 Apr 2018 18:07:21 +0800 Subject: [PATCH 04/17] bug fix --- kbengine_ts/bin/kbengine.d.ts | 6 ++-- kbengine_ts/bin/kbengine.js | 60 ++++++++++++++++----------------- kbengine_ts/bin/kbengine.min.js | 6 ++-- kbengine_ts/src/KBEngine.ts | 52 ++++++++++++++-------------- 4 files changed, 62 insertions(+), 62 deletions(-) diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index d610138..138e609 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -176,7 +176,7 @@ declare namespace KBEngine { function angle2int8(v: number, half: boolean): number; } declare namespace KBEngine { - module Entities { + namespace Entities { } class Entity { constructor(); @@ -198,8 +198,8 @@ declare namespace KBEngine { onDestroy(): void; onControlled(bIsControlled: any): void; isPlayer(): boolean; - baseCall(...params: any[]): void; - cellCall(...params: any[]): void; + baseCall(type: string, ...params: any[]): void; + cellCall(type: string, ...params: any[]): void; enterWorld(): void; onEnterWorld(): void; leaveWorld(): void; diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index 2c77051..706e4de 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -915,36 +915,36 @@ var KBEngine; Entity.prototype.isPlayer = function () { return this.id == KBEngine.app.entity_id; }; - Entity.prototype.baseCall = function () { + Entity.prototype.baseCall = function (type) { + // if (params.length < 1) { + // ERROR_MSG('Entity::baseCall: not fount interfaceName!'); + // return; + // } var params = []; - for (var _i = 0; _i < arguments.length; _i++) { - params[_i] = arguments[_i]; - } - if (params.length < 1) { - KBEngine.ERROR_MSG('Entity::baseCall: not fount interfaceName!'); - return; + for (var _i = 1; _i < arguments.length; _i++) { + params[_i - 1] = arguments[_i]; } if (this.base == undefined) { KBEngine.ERROR_MSG('Entity::baseCall: base is None!'); return; } - var method = KBEngine.moduledefs[this.className].base_methods[params[0]]; + var method = KBEngine.moduledefs[this.className].base_methods[type]; if (method == undefined) { - KBEngine.ERROR_MSG("Entity::baseCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); + KBEngine.ERROR_MSG("Entity::baseCall: The server did not find the def_method(" + this.className + "." + type + ")!"); return; } var methodID = method[0]; var args = method[3]; - if (args.length - 1 != args.length) { - KBEngine.ERROR_MSG("Entity::baseCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); + if (params.length != args.length) { + KBEngine.ERROR_MSG("Entity::baseCall: args(" + (params.length - 1) + "!= " + args.length + ") size is error!"); return; } this.base.newCall(); this.base.bundle.writeUint16(methodID); try { - for (var i = 0; i < args.length; i++) { - if (args[i].isSameType(args[i + 1])) { - args[i].addToStream(this.base.bundle, args[i + 1]); + for (var i = 0; i < params.length; i++) { + if (args[i].isSameType(params[i])) { + args[i].addToStream(this.base.bundle, params[i + 1]); } else { throw new Error("Entity::baseCall: arg[" + i + "] is error!"); @@ -959,36 +959,36 @@ var KBEngine; } this.base.sendCall(); }; - Entity.prototype.cellCall = function () { + Entity.prototype.cellCall = function (type) { + // if (params.length < 1) { + // ERROR_MSG('Entity::cellCall: not fount interfaceName!'); + // return; + // } var params = []; - for (var _i = 0; _i < arguments.length; _i++) { - params[_i] = arguments[_i]; - } - if (params.length < 1) { - KBEngine.ERROR_MSG('Entity::cellCall: not fount interfaceName!'); - return; + for (var _i = 1; _i < arguments.length; _i++) { + params[_i - 1] = arguments[_i]; } if (this.cell == undefined) { KBEngine.ERROR_MSG('Entity::cellCall: cell is None!'); return; } - var method = KBEngine.moduledefs[this.className].cell_methods[params[0]]; + var method = KBEngine.moduledefs[this.className].cell_methods[type]; if (method == undefined) { - KBEngine.ERROR_MSG("Entity::cellCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); + KBEngine.ERROR_MSG("Entity::cellCall: The server did not find the def_method(" + this.className + "." + type + ")!"); return; } var methodID = method[0]; var args = method[3]; - if (args.length - 1 != args.length) { - KBEngine.ERROR_MSG("Entity::cellCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); + if (params.length != args.length) { + KBEngine.ERROR_MSG("Entity::cellCall: args(" + (params.length) + "!= " + args.length + ") size is error!"); return; } this.cell.newCall(); this.cell.bundle.writeUint16(methodID); try { for (var i = 0; i < args.length; i++) { - if (args[i].isSameType(args[i + 1])) { - args[i].addToStream(this.cell.bundle, args[i + 1]); + if (args[i].isSameType(params[i])) { + args[i].addToStream(this.cell.bundle, params[i]); } else { throw new Error("Entity::cellCall: arg[" + i + "] is error!"); @@ -2090,7 +2090,7 @@ var KBEngine; var self_base_methods = currModuleDefs["base_methods"]; var self_cell_methods = currModuleDefs["cell_methods"]; try { - var Class = Entities[scriptmodule_name]; + var Class = KBEngine['Entities'][scriptmodule_name]; } catch (e) { var Class_1 = undefined; @@ -2181,7 +2181,7 @@ var KBEngine; ; var defmethod = void 0; try { - defmethod = Entities[scriptmodule_name]; + defmethod = KBEngine['Entities'][scriptmodule_name]; } catch (e) { KBEngine.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module(" + scriptmodule_name + ") not found!"); @@ -2464,7 +2464,7 @@ var KBEngine; KBEngine.Event.fire("onReloginBaseappSuccessfully"); }; KBEngineApp.prototype.getentityclass = function (entityType) { - var runclass = Entities[entityType]; + var runclass = KBEngine['Entities'][entityType]; if (runclass == undefined) { KBEngine.ERROR_MSG("KBEngineApp::getentityclass: entityType(" + entityType + ") is error!"); return runclass; diff --git a/kbengine_ts/bin/kbengine.min.js b/kbengine_ts/bin/kbengine.min.js index ac142a8..817ea7e 100644 --- a/kbengine_ts/bin/kbengine.min.js +++ b/kbengine_ts/bin/kbengine.min.js @@ -1,3 +1,3 @@ -var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(e){console.info(e)}function n(e){console.debug(e)}function r(e){console.error(e)}function a(e){console.warn(e)}e.INFO_MSG=t,e.DEBUG_MSG=n,e.ERROR_MSG=r,e.WARNING_MSG=a}(KBEngine||(KBEngine={})),function(e){function t(e){var t,n,r,a,i,o;for(t="",r=e.length,n=0;r>n;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=a,__reflect(a.prototype,"KBEngine.Vector3"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(){for(var t=[],n=0;ne||e>255?!1:!0},DATATYPE_UINT8}();KBEngine.DATATYPE_UINT8=DATATYPE_UINT8,__reflect(DATATYPE_UINT8.prototype,"KBEngine.DATATYPE_UINT8");var DATATYPE_UINT16=function(){function DATATYPE_UINT16(){}return DATATYPE_UINT16.prototype.bind=function(){},DATATYPE_UINT16.prototype.createFromStream=function(e){return KBEngine.reader.readUint16.call(e)},DATATYPE_UINT16.prototype.addToStream=function(e,t){e.writeUint16(t)},DATATYPE_UINT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},DATATYPE_UINT16}();KBEngine.DATATYPE_UINT16=DATATYPE_UINT16,__reflect(DATATYPE_UINT16.prototype,"KBEngine.DATATYPE_UINT16");var DATATYPE_UINT32=function(){function DATATYPE_UINT32(){}return DATATYPE_UINT32.prototype.bind=function(){},DATATYPE_UINT32.prototype.createFromStream=function(e){return KBEngine.reader.readUint32.call(e)},DATATYPE_UINT32.prototype.addToStream=function(e,t){e.writeUint32(t)},DATATYPE_UINT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},DATATYPE_UINT32}();KBEngine.DATATYPE_UINT32=DATATYPE_UINT32,__reflect(DATATYPE_UINT32.prototype,"KBEngine.DATATYPE_UINT32");var DATATYPE_UINT64=function(){function DATATYPE_UINT64(){}return DATATYPE_UINT64.prototype.bind=function(){},DATATYPE_UINT64.prototype.createFromStream=function(e){return KBEngine.reader.readUint64.call(e)},DATATYPE_UINT64.prototype.addToStream=function(e,t){e.writeUint64(t)},DATATYPE_UINT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT64.prototype.isSameType=function(e){return e instanceof KBEngine.UINT64},DATATYPE_UINT64}();KBEngine.DATATYPE_UINT64=DATATYPE_UINT64,__reflect(DATATYPE_UINT64.prototype,"KBEngine.DATATYPE_UINT64");var DATATYPE_INT8=function(){function DATATYPE_INT8(){}return DATATYPE_INT8.prototype.bind=function(){},DATATYPE_INT8.prototype.createFromStream=function(e){return KBEngine.reader.readInt8.call(e)},DATATYPE_INT8.prototype.addToStream=function(e,t){e.writeInt8(t)},DATATYPE_INT8.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT8.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},DATATYPE_INT8}();KBEngine.DATATYPE_INT8=DATATYPE_INT8,__reflect(DATATYPE_INT8.prototype,"KBEngine.DATATYPE_INT8");var DATATYPE_INT16=function(){function DATATYPE_INT16(){}return DATATYPE_INT16.prototype.bind=function(){},DATATYPE_INT16.prototype.createFromStream=function(e){return KBEngine.reader.readInt16.call(e)},DATATYPE_INT16.prototype.addToStream=function(e,t){e.writeInt16(t)},DATATYPE_INT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},DATATYPE_INT16}();KBEngine.DATATYPE_INT16=DATATYPE_INT16,__reflect(DATATYPE_INT16.prototype,"KBEngine.DATATYPE_INT16");var DATATYPE_INT32=function(){function DATATYPE_INT32(){}return DATATYPE_INT32.prototype.bind=function(){},DATATYPE_INT32.prototype.createFromStream=function(e){return KBEngine.reader.readInt32.call(e)},DATATYPE_INT32.prototype.addToStream=function(e,t){e.writeInt32(t)},DATATYPE_INT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},DATATYPE_INT32}();KBEngine.DATATYPE_INT32=DATATYPE_INT32,__reflect(DATATYPE_INT32.prototype,"KBEngine.DATATYPE_INT32");var DATATYPE_INT64=function(){function DATATYPE_INT64(){}return DATATYPE_INT64.prototype.bind=function(){},DATATYPE_INT64.prototype.createFromStream=function(e){return KBEngine.reader.readInt64.call(e)},DATATYPE_INT64.prototype.addToStream=function(e,t){e.writeInt64(t)},DATATYPE_INT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT64.prototype.isSameType=function(e){return e instanceof KBEngine.INT64},DATATYPE_INT64}();KBEngine.DATATYPE_INT64=DATATYPE_INT64,__reflect(DATATYPE_INT64.prototype,"KBEngine.DATATYPE_INT64");var DATATYPE_FLOAT=function(){function DATATYPE_FLOAT(){}return DATATYPE_FLOAT.prototype.bind=function(){},DATATYPE_FLOAT.prototype.createFromStream=function(e){return KBEngine.reader.readFloat.call(e)},DATATYPE_FLOAT.prototype.addToStream=function(e,t){e.writeFloat(t)},DATATYPE_FLOAT.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_FLOAT.prototype.isSameType=function(e){return"number"==typeof e},DATATYPE_FLOAT}();KBEngine.DATATYPE_FLOAT=DATATYPE_FLOAT,__reflect(DATATYPE_FLOAT.prototype,"KBEngine.DATATYPE_FLOAT");var DATATYPE_DOUBLE=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.createFromStream=function(e){return KBEngine.reader.readDouble.call(e)},t.prototype.addToStream=function(e,t){e.writeDouble(t)},t}(DATATYPE_FLOAT);KBEngine.DATATYPE_DOUBLE=DATATYPE_DOUBLE,__reflect(DATATYPE_DOUBLE.prototype,"KBEngine.DATATYPE_DOUBLE");var DATATYPE_STRING=function(){function DATATYPE_STRING(){}return DATATYPE_STRING.prototype.bind=function(){},DATATYPE_STRING.prototype.createFromStream=function(e){return KBEngine.reader.readString.call(e)},DATATYPE_STRING.prototype.addToStream=function(e,t){e.writeString(t)},DATATYPE_STRING.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_STRING.prototype.isSameType=function(e){return"string"==typeof e},DATATYPE_STRING}();KBEngine.DATATYPE_STRING=DATATYPE_STRING,__reflect(DATATYPE_STRING.prototype,"KBEngine.DATATYPE_STRING");var DATATYPE_VECTOR2=function(){function DATATYPE_VECTOR2(){}return DATATYPE_VECTOR2.prototype.bind=function(){},DATATYPE_VECTOR2.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR2.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y)):(e.writeFloat(t.x),e.writeFloat(t.y))},DATATYPE_VECTOR2.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR2.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR2}();KBEngine.DATATYPE_VECTOR2=DATATYPE_VECTOR2,__reflect(DATATYPE_VECTOR2.prototype,"KBEngine.DATATYPE_VECTOR2");var DATATYPE_VECTOR3=function(){function DATATYPE_VECTOR3(){}return DATATYPE_VECTOR3.prototype.bind=function(){},DATATYPE_VECTOR3.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR3.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y),e.writeInt32(t.z)):(e.writeFloat(t.x),e.writeFloat(t.y),e.writeFloat(t.z))},DATATYPE_VECTOR3.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR3.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR3}();KBEngine.DATATYPE_VECTOR3=DATATYPE_VECTOR3,__reflect(DATATYPE_VECTOR3.prototype,"KBEngine.DATATYPE_VECTOR3");var DATATYPE_VECTOR4=function(){function DATATYPE_VECTOR4(){}return DATATYPE_VECTOR4.prototype.bind=function(){},DATATYPE_VECTOR4.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR4.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y),e.writeInt32(t.z),e.writeInt32(t.w)):(e.writeFloat(t.x),e.writeFloat(t.y),e.writeFloat(t.z),e.writeFloat(t.w))},DATATYPE_VECTOR4.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR4.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR4}();KBEngine.DATATYPE_VECTOR4=DATATYPE_VECTOR4,__reflect(DATATYPE_VECTOR4.prototype,"KBEngine.DATATYPE_VECTOR4");var DATATYPE_PYTHON=function(){function DATATYPE_PYTHON(){}return DATATYPE_PYTHON.prototype.bind=function(){},DATATYPE_PYTHON.prototype.createFromStream=function(e){},DATATYPE_PYTHON.prototype.addToStream=function(e,t){},DATATYPE_PYTHON.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_PYTHON.prototype.isSameType=function(e){return!1},DATATYPE_PYTHON}();KBEngine.DATATYPE_PYTHON=DATATYPE_PYTHON,__reflect(DATATYPE_PYTHON.prototype,"KBEngine.DATATYPE_PYTHON");var DATATYPE_UNICODE=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return KBEngine.utf8ArrayToString(KBEngine.reader.readBlob.call(e))},e.prototype.addToStream=function(e,t){e.writeBlob(KBEngine.stringToUTF8Bytes(t))},e.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},e.prototype.isSameType=function(e){return"string"==typeof e},e}();KBEngine.DATATYPE_UNICODE=DATATYPE_UNICODE,__reflect(DATATYPE_UNICODE.prototype,"KBEngine.DATATYPE_UNICODE");var DATATYPE_ENTITYCALL=function(){function DATATYPE_ENTITYCALL(){}return DATATYPE_ENTITYCALL.prototype.bind=function(){},DATATYPE_ENTITYCALL.prototype.createFromStream=function(e){},DATATYPE_ENTITYCALL.prototype.addToStream=function(e,t){},DATATYPE_ENTITYCALL.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_ENTITYCALL.prototype.isSameType=function(e){return!1},DATATYPE_ENTITYCALL}();KBEngine.DATATYPE_ENTITYCALL=DATATYPE_ENTITYCALL,__reflect(DATATYPE_ENTITYCALL.prototype,"KBEngine.DATATYPE_ENTITYCALL");var DATATYPE_BLOB=function(){function DATATYPE_BLOB(){}return DATATYPE_BLOB.prototype.bind=function(){},DATATYPE_BLOB.prototype.createFromStream=function(e){var t=KBEngine.reader.readUint32.call(e),n=new Uint8Array(e.buffer,e.rpos,t);return e.rpos+=t,n},DATATYPE_BLOB.prototype.addToStream=function(e,t){e.writeBlob(t)},DATATYPE_BLOB.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_BLOB.prototype.isSameType=function(e){return!0},DATATYPE_BLOB}();KBEngine.DATATYPE_BLOB=DATATYPE_BLOB,__reflect(DATATYPE_BLOB.prototype,"KBEngine.DATATYPE_BLOB");var DATATYPE_ARRAY=function(){function DATATYPE_ARRAY(){this.type=null}return DATATYPE_ARRAY.prototype.bind=function(){"number"==typeof this.type&&(this.type=datatypes[this.type])},DATATYPE_ARRAY.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},DATATYPE_ARRAY.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,T=s.cell_methods;try{var u=Entities[n]}catch(_){}for(;a>0;){a--;var E=t.readUint16(),y=t.readUint32(),f=t.readInt16(),A=t.readString(),g=t.readString(),v=e.datatypes[t.readUint16()],h=null;void 0!=u&&(h=u.prototype["set_"+A],void 0==h&&(h=null));var m=[E,f,A,g,v,h,y];l[A]=m,-1!=f?(l[f]=m,s.usePropertyDescrAlias=!0):(l[E]=m,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+A+"/"+E+").")}for(;i>0;){i--;for(var I=t.readUint16(),f=t.readInt16(),D=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);var m=[I,f,D,B];c[D]=m,-1!=f?(c[f]=m,s.useMethodDescrAlias=!0):(c[I]=m,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+D+").")}for(;o>0;){o--;for(var I=t.readUint16(),f=t.readInt16(),P=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);d[P]=[I,f,P,B],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+P+").")}for(;p>0;){p--;for(var I=t.readUint16(),f=t.readInt16(),C=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);T[C]=[I,f,C,B],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+C+").")}var w=void 0;try{w=Entities[n]}catch(_){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),w=void 0}for(var M in s.propertys){var N=s.propertys[M],E=N[0],f=N[1],Y=N[2],g=N[3],v=N[4];void 0!=w&&(w.prototype[Y]=v.parseDefaultValStr(g))}for(var L in s.methods){var N=s.methods[L],E=N[0],f=N[1],Y=N[2],B=N[3];void 0!=w&&void 0==w.prototype[Y]&&e.WARNING_MSG(n+":: method("+Y+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,T=o.indexOf("Client_")>=0;T&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),T?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.args.protocol+e.app.baseappIp+":"+e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.args.protocol+e.app.baseappIp+":"+e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessage[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessage[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],T=l[4].createFromStream(n),u=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+T+")!"),r[l[2]]=T,null!=c&&(32==d||64==d?r.inited&&c.call(r,u):r.inWorld&&c.call(r,u))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessage[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessage[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(); -e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0)},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var T=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(T=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),T&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file +var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(e){console.info(e)}function n(e){console.debug(e)}function r(e){console.error(e)}function a(e){console.warn(e)}e.INFO_MSG=t,e.DEBUG_MSG=n,e.ERROR_MSG=r,e.WARNING_MSG=a}(KBEngine||(KBEngine={})),function(e){function t(e){var t,n,r,a,i,o;for(t="",r=e.length,n=0;r>n;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=a,__reflect(a.prototype,"KBEngine.Vector3"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(t){for(var n=[],r=1;re||e>255?!1:!0},DATATYPE_UINT8}();KBEngine.DATATYPE_UINT8=DATATYPE_UINT8,__reflect(DATATYPE_UINT8.prototype,"KBEngine.DATATYPE_UINT8");var DATATYPE_UINT16=function(){function DATATYPE_UINT16(){}return DATATYPE_UINT16.prototype.bind=function(){},DATATYPE_UINT16.prototype.createFromStream=function(e){return KBEngine.reader.readUint16.call(e)},DATATYPE_UINT16.prototype.addToStream=function(e,t){e.writeUint16(t)},DATATYPE_UINT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},DATATYPE_UINT16}();KBEngine.DATATYPE_UINT16=DATATYPE_UINT16,__reflect(DATATYPE_UINT16.prototype,"KBEngine.DATATYPE_UINT16");var DATATYPE_UINT32=function(){function DATATYPE_UINT32(){}return DATATYPE_UINT32.prototype.bind=function(){},DATATYPE_UINT32.prototype.createFromStream=function(e){return KBEngine.reader.readUint32.call(e)},DATATYPE_UINT32.prototype.addToStream=function(e,t){e.writeUint32(t)},DATATYPE_UINT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},DATATYPE_UINT32}();KBEngine.DATATYPE_UINT32=DATATYPE_UINT32,__reflect(DATATYPE_UINT32.prototype,"KBEngine.DATATYPE_UINT32");var DATATYPE_UINT64=function(){function DATATYPE_UINT64(){}return DATATYPE_UINT64.prototype.bind=function(){},DATATYPE_UINT64.prototype.createFromStream=function(e){return KBEngine.reader.readUint64.call(e)},DATATYPE_UINT64.prototype.addToStream=function(e,t){e.writeUint64(t)},DATATYPE_UINT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT64.prototype.isSameType=function(e){return e instanceof KBEngine.UINT64},DATATYPE_UINT64}();KBEngine.DATATYPE_UINT64=DATATYPE_UINT64,__reflect(DATATYPE_UINT64.prototype,"KBEngine.DATATYPE_UINT64");var DATATYPE_INT8=function(){function DATATYPE_INT8(){}return DATATYPE_INT8.prototype.bind=function(){},DATATYPE_INT8.prototype.createFromStream=function(e){return KBEngine.reader.readInt8.call(e)},DATATYPE_INT8.prototype.addToStream=function(e,t){e.writeInt8(t)},DATATYPE_INT8.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT8.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},DATATYPE_INT8}();KBEngine.DATATYPE_INT8=DATATYPE_INT8,__reflect(DATATYPE_INT8.prototype,"KBEngine.DATATYPE_INT8");var DATATYPE_INT16=function(){function DATATYPE_INT16(){}return DATATYPE_INT16.prototype.bind=function(){},DATATYPE_INT16.prototype.createFromStream=function(e){return KBEngine.reader.readInt16.call(e)},DATATYPE_INT16.prototype.addToStream=function(e,t){e.writeInt16(t)},DATATYPE_INT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},DATATYPE_INT16}();KBEngine.DATATYPE_INT16=DATATYPE_INT16,__reflect(DATATYPE_INT16.prototype,"KBEngine.DATATYPE_INT16");var DATATYPE_INT32=function(){function DATATYPE_INT32(){}return DATATYPE_INT32.prototype.bind=function(){},DATATYPE_INT32.prototype.createFromStream=function(e){return KBEngine.reader.readInt32.call(e)},DATATYPE_INT32.prototype.addToStream=function(e,t){e.writeInt32(t)},DATATYPE_INT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},DATATYPE_INT32}();KBEngine.DATATYPE_INT32=DATATYPE_INT32,__reflect(DATATYPE_INT32.prototype,"KBEngine.DATATYPE_INT32");var DATATYPE_INT64=function(){function DATATYPE_INT64(){}return DATATYPE_INT64.prototype.bind=function(){},DATATYPE_INT64.prototype.createFromStream=function(e){return KBEngine.reader.readInt64.call(e)},DATATYPE_INT64.prototype.addToStream=function(e,t){e.writeInt64(t)},DATATYPE_INT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT64.prototype.isSameType=function(e){return e instanceof KBEngine.INT64},DATATYPE_INT64}();KBEngine.DATATYPE_INT64=DATATYPE_INT64,__reflect(DATATYPE_INT64.prototype,"KBEngine.DATATYPE_INT64");var DATATYPE_FLOAT=function(){function DATATYPE_FLOAT(){}return DATATYPE_FLOAT.prototype.bind=function(){},DATATYPE_FLOAT.prototype.createFromStream=function(e){return KBEngine.reader.readFloat.call(e)},DATATYPE_FLOAT.prototype.addToStream=function(e,t){e.writeFloat(t)},DATATYPE_FLOAT.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_FLOAT.prototype.isSameType=function(e){return"number"==typeof e},DATATYPE_FLOAT}();KBEngine.DATATYPE_FLOAT=DATATYPE_FLOAT,__reflect(DATATYPE_FLOAT.prototype,"KBEngine.DATATYPE_FLOAT");var DATATYPE_DOUBLE=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.createFromStream=function(e){return KBEngine.reader.readDouble.call(e)},t.prototype.addToStream=function(e,t){e.writeDouble(t)},t}(DATATYPE_FLOAT);KBEngine.DATATYPE_DOUBLE=DATATYPE_DOUBLE,__reflect(DATATYPE_DOUBLE.prototype,"KBEngine.DATATYPE_DOUBLE");var DATATYPE_STRING=function(){function DATATYPE_STRING(){}return DATATYPE_STRING.prototype.bind=function(){},DATATYPE_STRING.prototype.createFromStream=function(e){return KBEngine.reader.readString.call(e)},DATATYPE_STRING.prototype.addToStream=function(e,t){e.writeString(t)},DATATYPE_STRING.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_STRING.prototype.isSameType=function(e){return"string"==typeof e},DATATYPE_STRING}();KBEngine.DATATYPE_STRING=DATATYPE_STRING,__reflect(DATATYPE_STRING.prototype,"KBEngine.DATATYPE_STRING");var DATATYPE_VECTOR2=function(){function DATATYPE_VECTOR2(){}return DATATYPE_VECTOR2.prototype.bind=function(){},DATATYPE_VECTOR2.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR2.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y)):(e.writeFloat(t.x),e.writeFloat(t.y))},DATATYPE_VECTOR2.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR2.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR2}();KBEngine.DATATYPE_VECTOR2=DATATYPE_VECTOR2,__reflect(DATATYPE_VECTOR2.prototype,"KBEngine.DATATYPE_VECTOR2");var DATATYPE_VECTOR3=function(){function DATATYPE_VECTOR3(){}return DATATYPE_VECTOR3.prototype.bind=function(){},DATATYPE_VECTOR3.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR3.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y),e.writeInt32(t.z)):(e.writeFloat(t.x),e.writeFloat(t.y),e.writeFloat(t.z))},DATATYPE_VECTOR3.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR3.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR3}();KBEngine.DATATYPE_VECTOR3=DATATYPE_VECTOR3,__reflect(DATATYPE_VECTOR3.prototype,"KBEngine.DATATYPE_VECTOR3");var DATATYPE_VECTOR4=function(){function DATATYPE_VECTOR4(){}return DATATYPE_VECTOR4.prototype.bind=function(){},DATATYPE_VECTOR4.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR4.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y),e.writeInt32(t.z),e.writeInt32(t.w)):(e.writeFloat(t.x),e.writeFloat(t.y),e.writeFloat(t.z),e.writeFloat(t.w))},DATATYPE_VECTOR4.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR4.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR4}();KBEngine.DATATYPE_VECTOR4=DATATYPE_VECTOR4,__reflect(DATATYPE_VECTOR4.prototype,"KBEngine.DATATYPE_VECTOR4");var DATATYPE_PYTHON=function(){function DATATYPE_PYTHON(){}return DATATYPE_PYTHON.prototype.bind=function(){},DATATYPE_PYTHON.prototype.createFromStream=function(e){},DATATYPE_PYTHON.prototype.addToStream=function(e,t){},DATATYPE_PYTHON.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_PYTHON.prototype.isSameType=function(e){return!1},DATATYPE_PYTHON}();KBEngine.DATATYPE_PYTHON=DATATYPE_PYTHON,__reflect(DATATYPE_PYTHON.prototype,"KBEngine.DATATYPE_PYTHON");var DATATYPE_UNICODE=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return KBEngine.utf8ArrayToString(KBEngine.reader.readBlob.call(e))},e.prototype.addToStream=function(e,t){e.writeBlob(KBEngine.stringToUTF8Bytes(t))},e.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},e.prototype.isSameType=function(e){return"string"==typeof e},e}();KBEngine.DATATYPE_UNICODE=DATATYPE_UNICODE,__reflect(DATATYPE_UNICODE.prototype,"KBEngine.DATATYPE_UNICODE");var DATATYPE_ENTITYCALL=function(){function DATATYPE_ENTITYCALL(){}return DATATYPE_ENTITYCALL.prototype.bind=function(){},DATATYPE_ENTITYCALL.prototype.createFromStream=function(e){},DATATYPE_ENTITYCALL.prototype.addToStream=function(e,t){},DATATYPE_ENTITYCALL.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_ENTITYCALL.prototype.isSameType=function(e){return!1},DATATYPE_ENTITYCALL}();KBEngine.DATATYPE_ENTITYCALL=DATATYPE_ENTITYCALL,__reflect(DATATYPE_ENTITYCALL.prototype,"KBEngine.DATATYPE_ENTITYCALL");var DATATYPE_BLOB=function(){function DATATYPE_BLOB(){}return DATATYPE_BLOB.prototype.bind=function(){},DATATYPE_BLOB.prototype.createFromStream=function(e){var t=KBEngine.reader.readUint32.call(e),n=new Uint8Array(e.buffer,e.rpos,t);return e.rpos+=t,n},DATATYPE_BLOB.prototype.addToStream=function(e,t){e.writeBlob(t)},DATATYPE_BLOB.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_BLOB.prototype.isSameType=function(e){return!0},DATATYPE_BLOB}();KBEngine.DATATYPE_BLOB=DATATYPE_BLOB,__reflect(DATATYPE_BLOB.prototype,"KBEngine.DATATYPE_BLOB");var DATATYPE_ARRAY=function(){function DATATYPE_ARRAY(){this.type=null}return DATATYPE_ARRAY.prototype.bind=function(){"number"==typeof this.type&&(this.type=datatypes[this.type])},DATATYPE_ARRAY.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},DATATYPE_ARRAY.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,T=s.cell_methods;try{var u=e.Entities[n]}catch(_){}for(;a>0;){a--;var E=t.readUint16(),y=t.readUint32(),f=t.readInt16(),A=t.readString(),g=t.readString(),v=e.datatypes[t.readUint16()],h=null;void 0!=u&&(h=u.prototype["set_"+A],void 0==h&&(h=null));var m=[E,f,A,g,v,h,y];l[A]=m,-1!=f?(l[f]=m,s.usePropertyDescrAlias=!0):(l[E]=m,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+A+"/"+E+").")}for(;i>0;){i--;for(var I=t.readUint16(),f=t.readInt16(),D=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);var m=[I,f,D,B];c[D]=m,-1!=f?(c[f]=m,s.useMethodDescrAlias=!0):(c[I]=m,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+D+").")}for(;o>0;){o--;for(var I=t.readUint16(),f=t.readInt16(),P=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);d[P]=[I,f,P,B],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+P+").")}for(;p>0;){p--;for(var I=t.readUint16(),f=t.readInt16(),C=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);T[C]=[I,f,C,B],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+C+").")}var w=void 0;try{w=e.Entities[n]}catch(_){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),w=void 0}for(var M in s.propertys){var Y=s.propertys[M],E=Y[0],f=Y[1],N=Y[2],g=Y[3],v=Y[4];void 0!=w&&(w.prototype[N]=v.parseDefaultValStr(g))}for(var L in s.methods){var Y=s.methods[L],E=Y[0],f=Y[1],N=Y[2],B=Y[3];void 0!=w&&void 0==w.prototype[N]&&e.WARNING_MSG(n+":: method("+N+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,T=o.indexOf("Client_")>=0;T&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),T?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.args.protocol+e.app.baseappIp+":"+e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.args.protocol+e.app.baseappIp+":"+e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=e.Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessage[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessage[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],T=l[4].createFromStream(n),u=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+T+")!"),r[l[2]]=T,null!=c&&(32==d||64==d?r.inited&&c.call(r,u):r.inWorld&&c.call(r,u))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessage[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessage[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(); +e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0)},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var T=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(T=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),T&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index d9faa68..c13d491 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -1027,29 +1027,29 @@ namespace KBEngine { isPlayer() { return this.id == app.entity_id; } - baseCall(...params:any[]) { - if (params.length < 1) { - ERROR_MSG('Entity::baseCall: not fount interfaceName!'); - return; - } + baseCall(type:string,...params:any[]) { + // if (params.length < 1) { + // ERROR_MSG('Entity::baseCall: not fount interfaceName!'); + // return; + // } if (this.base == undefined) { ERROR_MSG('Entity::baseCall: base is None!'); return; } - let method = moduledefs[this.className].base_methods[params[0]]; + let method = moduledefs[this.className].base_methods[type]; if (method == undefined) { - ERROR_MSG("Entity::baseCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); + ERROR_MSG("Entity::baseCall: The server did not find the def_method(" + this.className + "." + type + ")!"); return; } let methodID = method[0]; let args = method[3]; - if (args.length - 1 != args.length) { - ERROR_MSG("Entity::baseCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); + if (params.length != args.length) { + ERROR_MSG("Entity::baseCall: args(" + (params.length - 1) + "!= " + args.length + ") size is error!"); return; } @@ -1057,9 +1057,9 @@ namespace KBEngine { this.base.bundle.writeUint16(methodID); try { - for (let i = 0; i < args.length; i++) { - if (args[i].isSameType(args[i + 1])) { - args[i].addToStream(this.base.bundle, args[i + 1]); + for (let i = 0; i < params.length; i++) { + if (args[i].isSameType(params[i])) { + args[i].addToStream(this.base.bundle, params[i]); } else { throw new Error("Entity::baseCall: arg[" + i + "] is error!"); @@ -1075,29 +1075,29 @@ namespace KBEngine { this.base.sendCall(); } - cellCall(...params) { - if (params.length < 1) { - ERROR_MSG('Entity::cellCall: not fount interfaceName!'); - return; - } + cellCall(type:string,...params:any[]) { + // if (params.length < 1) { + // ERROR_MSG('Entity::cellCall: not fount interfaceName!'); + // return; + // } if (this.cell == undefined) { ERROR_MSG('Entity::cellCall: cell is None!'); return; } - let method = moduledefs[this.className].cell_methods[params[0]]; + let method = moduledefs[this.className].cell_methods[type]; if (method == undefined) { - ERROR_MSG("Entity::cellCall: The server did not find the def_method(" + this.className + "." + params[0] + ")!"); + ERROR_MSG("Entity::cellCall: The server did not find the def_method(" + this.className + "." + type + ")!"); return; } let methodID = method[0]; let args = method[3]; - if (args.length - 1 != args.length) { - ERROR_MSG("Entity::cellCall: args(" + (args.length - 1) + "!= " + args.length + ") size is error!"); + if (params.length != args.length) { + ERROR_MSG("Entity::cellCall: args(" + (params.length ) + "!= " + args.length + ") size is error!"); return; } @@ -1106,8 +1106,8 @@ namespace KBEngine { try { for (let i = 0; i < args.length; i++) { - if (args[i].isSameType(args[i + 1])) { - args[i].addToStream(this.cell.bundle, args[i + 1]); + if (args[i].isSameType(params[i])) { + args[i].addToStream(this.cell.bundle, params[i]); } else { throw new Error("Entity::cellCall: arg[" + i + "] is error!"); @@ -2289,7 +2289,7 @@ namespace KBEngine { let self_cell_methods = currModuleDefs["cell_methods"]; try { - var Class = Entities[scriptmodule_name]; + var Class = KBEngine['Entities'][scriptmodule_name]; } catch (e) { let Class = undefined; @@ -2393,7 +2393,7 @@ namespace KBEngine { }; let defmethod try { - defmethod = Entities[scriptmodule_name]; + defmethod = KBEngine['Entities'][scriptmodule_name]; } catch (e) { ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module(" + scriptmodule_name + ") not found!"); @@ -2702,7 +2702,7 @@ namespace KBEngine { } entityclass = {}; getentityclass (entityType) { - let runclass = Entities[entityType]; + let runclass = KBEngine['Entities'][entityType]; if (runclass == undefined) { ERROR_MSG("KBEngineApp::getentityclass: entityType(" + entityType + ") is error!"); return runclass; From 6d7ecdf08093e2818efcbfdfeec42a2bfbdc52d5 Mon Sep 17 00:00:00 2001 From: zengmn <761458545@qq.com> Date: Sat, 28 Apr 2018 11:33:07 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E5=8E=BB=E6=8E=89eval?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kbengine_ts/bin/kbengine.d.ts | 79 +++-- kbengine_ts/bin/kbengine.js | 133 +++++--- kbengine_ts/bin/kbengine.min.js | 6 +- kbengine_ts/src/KBEngine.ts | 587 +++++++++++++++++--------------- kbengine_ts/tsconfig.json | 1 + 5 files changed, 474 insertions(+), 332 deletions(-) diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index 138e609..5328410 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -1,8 +1,16 @@ /** - * KBEngine的html5客户端扩展ts版 - * todo 类型匹配未完善 - * 缺少测试 - * 缺少类型Vector2,Vector4,暂时修改为Vector3,如果出问题再修改 + * KBEngine的html5客户端扩展ts版 1.1.5版本 + * cocos creator 环境下使用方法 + * 将bin/kbengine.js导入为插件,将bin/kbengine.d.ts放在项目根目录下,即可 + * + * todo 未完成内容 + * 1、强类型匹配 + * 2、代码注释 + * + * 注:(下面的是重点) + * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 + * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 window['KBEngine'] = window['KBEngine'] || {};window['KBEngine']['你的实体类名']=你的实体类名 + * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; */ declare namespace KBEngine { const PACKET_MAX_SIZE = 1500; @@ -29,6 +37,7 @@ declare namespace KBEngine { } } declare namespace KBEngine { + /** todo 调试输出模块,这里需要根据使用的引擎不同在这里加入判断条件 */ function INFO_MSG(s: any): void; function DEBUG_MSG(s: any): void; function ERROR_MSG(s: any): void; @@ -164,6 +173,12 @@ declare namespace KBEngine { let bufferedCreateEntityMessage: {}; } declare namespace KBEngine { + class Vector2 { + constructor(x: any, y: any); + x: number; + y: number; + distance(pos: Vector2): number; + } class Vector3 { constructor(x: any, y: any, z: any); x: number; @@ -171,6 +186,20 @@ declare namespace KBEngine { z: number; distance(pos: Vector3): number; } + /** + * todo 这个类的第四个参数的没搞清楚,所有如果没有必要,不要用这个东西 + */ + class Vector4 { + constructor(x: any, y: any, z: any, w: any); + x: number; + y: number; + z: number; + w: number; + /** + * todo 因为不清楚这个vector4的 w 的含义,所以不确定这个方法的正确性 + */ + distance(pos: Vector4): number; + } function clampf(value: any, min_inclusive: any, max_inclusive: any): any; function int82angle(angle: any, half: any): number; function angle2int8(v: number, half: boolean): number; @@ -232,63 +261,63 @@ declare namespace KBEngine { bind(): void; createFromStream(stream: any): any; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): number; isSameType(v: any): boolean; } class DATATYPE_UINT16 { bind(): void; createFromStream(stream: any): any; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): number; isSameType(v: any): boolean; } class DATATYPE_UINT32 { bind(): void; createFromStream(stream: any): any; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): number; isSameType(v: any): boolean; } class DATATYPE_UINT64 { bind(): void; createFromStream(stream: any): any; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): number; isSameType(v: any): boolean; } class DATATYPE_INT8 { bind(): void; createFromStream(stream: any): any; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): number; isSameType(v: any): boolean; } class DATATYPE_INT16 { bind(): void; createFromStream(stream: any): any; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): number; isSameType(v: any): boolean; } class DATATYPE_INT32 { bind(): void; createFromStream(stream: any): any; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): number; isSameType(v: any): boolean; } class DATATYPE_INT64 { bind(): void; createFromStream(stream: any): any; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): number; isSameType(v: any): boolean; } class DATATYPE_FLOAT { bind(): void; createFromStream(stream: any): any; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): number; isSameType(v: any): boolean; } class DATATYPE_DOUBLE extends DATATYPE_FLOAT { @@ -299,35 +328,35 @@ declare namespace KBEngine { bind(): void; createFromStream(stream: any): any; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): string; isSameType(v: any): boolean; } class DATATYPE_VECTOR2 { bind(): void; - createFromStream(stream: any): Vector3; + createFromStream(stream: any): Vector2; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): Vector2; isSameType(v: any): boolean; } class DATATYPE_VECTOR3 { bind(): void; createFromStream(stream: any): Vector3; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): Vector3; isSameType(v: any): boolean; } class DATATYPE_VECTOR4 { bind(): void; - createFromStream(stream: any): Vector3; + createFromStream(stream: any): Vector4; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): Vector4; isSameType(v: any): boolean; } class DATATYPE_PYTHON { bind(): void; createFromStream(stream: any): void; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): Uint8Array; isSameType(v: any): boolean; } class DATATYPE_UNICODE { @@ -341,14 +370,14 @@ declare namespace KBEngine { bind(): void; createFromStream(stream: any): void; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): Uint8Array; isSameType(v: any): boolean; } class DATATYPE_BLOB { bind(): void; createFromStream(stream: any): Uint8Array; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): Uint8Array; isSameType(v: any): boolean; } class DATATYPE_ARRAY { @@ -356,7 +385,7 @@ declare namespace KBEngine { bind(): void; createFromStream(stream: any): any[]; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): any[]; isSameType(v: any): boolean; } class DATATYPE_FIXED_DICT { @@ -365,7 +394,7 @@ declare namespace KBEngine { bind(): void; createFromStream(stream: any): {}; addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): any; + parseDefaultValStr(v: any): {}; isSameType(v: any): boolean; } module datatypes { @@ -450,7 +479,7 @@ declare namespace KBEngine { hello(): void; player(): any; findEntity(entityID: any): any; - connect(addr: any): void; + connect(host: any, port: any): void; disconnect(): void; onopen(): void; onerror_before_onopen(evt: any): void; diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index 706e4de..7d17a7c 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -9,10 +9,19 @@ for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]); r.prototype = e.prototype, t.prototype = new r(); }; /** - * KBEngine的html5客户端扩展ts版 - * todo 类型匹配未完善 - * 缺少测试 - * 缺少类型Vector2,Vector4,暂时修改为Vector3,如果出问题再修改 + * KBEngine的html5客户端扩展ts版 1.1.5版本 + * cocos creator 环境下使用方法 + * 将bin/kbengine.js导入为插件,将bin/kbengine.d.ts放在项目根目录下,即可 + * + * todo 未完成内容 + * 1、强类型匹配 + * 2、代码注释 + * + * 注:(下面的是重点) + * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 + * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 window['KBEngine'] = window['KBEngine'] || {};window['KBEngine']['你的实体类名']=你的实体类名 + * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; + * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ /*----------------------------------------------------------------------------------------- global @@ -27,6 +36,10 @@ var KBEngine; KBEngine.CLIENT_NO_FLOAT = 0; KBEngine.KBE_FLT_MAX = 3.402823466e+38; })(KBEngine || (KBEngine = {})); +/** + * 加上声明避免cocos creator编辑器报错 + */ +window['KBEngine'] = KBEngine; /*----------------------------------------------------------------------------------------- number64bits -----------------------------------------------------------------------------------------*/ @@ -95,6 +108,7 @@ var KBEngine; debug -----------------------------------------------------------------------------------------*/ (function (KBEngine) { + /** todo 调试输出模块,这里需要根据使用的引擎不同在这里加入判断条件 */ function INFO_MSG(s) { console.info(s); } @@ -235,7 +249,7 @@ var KBEngine; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } - if (arguments.length < 1) { + if (!evtName) { KBEngine.ERROR_MSG('export class Event::fire: not found eventName!'); return; } @@ -811,6 +825,20 @@ var KBEngine; math -----------------------------------------------------------------------------------------*/ (function (KBEngine) { + var Vector2 = (function () { + function Vector2(x, y) { + this.x = x; + this.y = y; + } + Vector2.prototype.distance = function (pos) { + var x = pos.x - this.x; + var y = pos.y - this.y; + return Math.sqrt(x * x + y * y); + }; + return Vector2; + }()); + KBEngine.Vector2 = Vector2; + __reflect(Vector2.prototype, "KBEngine.Vector2"); var Vector3 = (function () { function Vector3(x, y, z) { this.x = x; @@ -827,6 +855,29 @@ var KBEngine; }()); KBEngine.Vector3 = Vector3; __reflect(Vector3.prototype, "KBEngine.Vector3"); + /** + * todo 这个类的第四个参数的没搞清楚,所有如果没有必要,不要用这个东西 + */ + var Vector4 = (function () { + function Vector4(x, y, z, w) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + /** + * todo 因为不清楚这个vector4的 w 的含义,所以不确定这个方法的正确性 + */ + Vector4.prototype.distance = function (pos) { + var x = pos.x - this.x; + var y = pos.y - this.y; + var z = pos.z - this.z; + return Math.sqrt(x * x + y * y + z * z); + }; + return Vector4; + }()); + KBEngine.Vector4 = Vector4; + __reflect(Vector4.prototype, "KBEngine.Vector4"); function clampf(value, min_inclusive, max_inclusive) { if (min_inclusive > max_inclusive) { var temp = min_inclusive; @@ -944,7 +995,7 @@ var KBEngine; try { for (var i = 0; i < params.length; i++) { if (args[i].isSameType(params[i])) { - args[i].addToStream(this.base.bundle, params[i + 1]); + args[i].addToStream(this.base.bundle, params[i]); } else { throw new Error("Entity::baseCall: arg[" + i + "] is error!"); @@ -1109,7 +1160,7 @@ var KBEngine; stream.writeUint8(v); }; DATATYPE_UINT8.prototype.parseDefaultValStr = function (v) { - return eval(v); + return parseInt(v); }; DATATYPE_UINT8.prototype.isSameType = function (v) { if (typeof (v) != "number") { @@ -1136,7 +1187,7 @@ var KBEngine; stream.writeUint16(v); }; DATATYPE_UINT16.prototype.parseDefaultValStr = function (v) { - return eval(v); + return parseInt(v); }; DATATYPE_UINT16.prototype.isSameType = function (v) { if (typeof (v) != "number") { @@ -1163,7 +1214,7 @@ var KBEngine; stream.writeUint32(v); }; DATATYPE_UINT32.prototype.parseDefaultValStr = function (v) { - return eval(v); + return parseInt(v); }; DATATYPE_UINT32.prototype.isSameType = function (v) { if (typeof (v) != "number") { @@ -1190,7 +1241,7 @@ var KBEngine; stream.writeUint64(v); }; DATATYPE_UINT64.prototype.parseDefaultValStr = function (v) { - return eval(v); + return parseInt(v); }; DATATYPE_UINT64.prototype.isSameType = function (v) { return v instanceof KBEngine.UINT64; @@ -1211,7 +1262,7 @@ var KBEngine; stream.writeInt8(v); }; DATATYPE_INT8.prototype.parseDefaultValStr = function (v) { - return eval(v); + return parseInt(v); }; DATATYPE_INT8.prototype.isSameType = function (v) { if (typeof (v) != "number") { @@ -1238,7 +1289,7 @@ var KBEngine; stream.writeInt16(v); }; DATATYPE_INT16.prototype.parseDefaultValStr = function (v) { - return eval(v); + return parseInt(v); }; DATATYPE_INT16.prototype.isSameType = function (v) { if (typeof (v) != "number") { @@ -1265,7 +1316,7 @@ var KBEngine; stream.writeInt32(v); }; DATATYPE_INT32.prototype.parseDefaultValStr = function (v) { - return eval(v); + return parseInt(v); }; DATATYPE_INT32.prototype.isSameType = function (v) { if (typeof (v) != "number") { @@ -1292,7 +1343,7 @@ var KBEngine; stream.writeInt64(v); }; DATATYPE_INT64.prototype.parseDefaultValStr = function (v) { - return eval(v); + return parseInt(v); }; DATATYPE_INT64.prototype.isSameType = function (v) { return v instanceof KBEngine.INT64; @@ -1313,7 +1364,7 @@ var KBEngine; stream.writeFloat(v); }; DATATYPE_FLOAT.prototype.parseDefaultValStr = function (v) { - return eval(v); + return parseFloat(v); }; DATATYPE_FLOAT.prototype.isSameType = function (v) { return typeof (v) == "number"; @@ -1349,7 +1400,9 @@ var KBEngine; stream.writeString(v); }; DATATYPE_STRING.prototype.parseDefaultValStr = function (v) { - return eval(v); + if (typeof (v) == "string") + return v; + return ""; }; DATATYPE_STRING.prototype.isSameType = function (v) { return typeof (v) == "string"; @@ -1365,10 +1418,10 @@ var KBEngine; }; DATATYPE_VECTOR2.prototype.createFromStream = function (stream) { if (KBEngine.CLIENT_NO_FLOAT) { - return new KBEngine.Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); + return new KBEngine.Vector2(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); } else { - return new KBEngine.Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); + return new KBEngine.Vector2(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); } }; DATATYPE_VECTOR2.prototype.addToStream = function (stream, v) { @@ -1382,10 +1435,11 @@ var KBEngine; } }; DATATYPE_VECTOR2.prototype.parseDefaultValStr = function (v) { - return eval(v); + return new KBEngine.Vector2(0.0, 0.0); + ; }; DATATYPE_VECTOR2.prototype.isSameType = function (v) { - if (!(v instanceof KBEngine.Vector3)) { + if (!(v instanceof KBEngine.Vector2)) { return false; } return true; @@ -1420,7 +1474,7 @@ var KBEngine; } }; DATATYPE_VECTOR3.prototype.parseDefaultValStr = function (v) { - return eval(v); + return new KBEngine.Vector3(0.0, 0.0, 0.0); }; DATATYPE_VECTOR3.prototype.isSameType = function (v) { if (!(v instanceof KBEngine.Vector3)) { @@ -1439,10 +1493,10 @@ var KBEngine; }; DATATYPE_VECTOR4.prototype.createFromStream = function (stream) { if (KBEngine.CLIENT_NO_FLOAT) { - return new KBEngine.Vector3(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); + return new KBEngine.Vector4(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readFloat.call(stream)); } else { - return new KBEngine.Vector3(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); + return new KBEngine.Vector4(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); } }; DATATYPE_VECTOR4.prototype.addToStream = function (stream, v) { @@ -1460,10 +1514,10 @@ var KBEngine; } }; DATATYPE_VECTOR4.prototype.parseDefaultValStr = function (v) { - return eval(v); + return new KBEngine.Vector4(0.0, 0.0, 0.0, 0.0); }; DATATYPE_VECTOR4.prototype.isSameType = function (v) { - if (!(v instanceof KBEngine.Vector3)) { + if (!(v instanceof KBEngine.Vector4)) { return false; } return true; @@ -1482,7 +1536,7 @@ var KBEngine; DATATYPE_PYTHON.prototype.addToStream = function (stream, v) { }; DATATYPE_PYTHON.prototype.parseDefaultValStr = function (v) { - return eval(v); + return new Uint8Array(0); }; DATATYPE_PYTHON.prototype.isSameType = function (v) { return false; @@ -1524,7 +1578,8 @@ var KBEngine; DATATYPE_ENTITYCALL.prototype.addToStream = function (stream, v) { }; DATATYPE_ENTITYCALL.prototype.parseDefaultValStr = function (v) { - return eval(v); + return new Uint8Array(0); + ; }; DATATYPE_ENTITYCALL.prototype.isSameType = function (v) { return false; @@ -1548,7 +1603,7 @@ var KBEngine; stream.writeBlob(v); }; DATATYPE_BLOB.prototype.parseDefaultValStr = function (v) { - return eval(v); + return new Uint8Array(0); }; DATATYPE_BLOB.prototype.isSameType = function (v) { return true; @@ -1582,7 +1637,7 @@ var KBEngine; } }; DATATYPE_ARRAY.prototype.parseDefaultValStr = function (v) { - return eval(v); + return []; }; DATATYPE_ARRAY.prototype.isSameType = function (v) { for (var i = 0; i < v.length; i++) { @@ -1621,7 +1676,7 @@ var KBEngine; } }; DATATYPE_FIXED_DICT.prototype.parseDefaultValStr = function (v) { - return eval(v); + return {}; }; DATATYPE_FIXED_DICT.prototype.isSameType = function (v) { for (var itemkey in this.dicttype) { @@ -1668,6 +1723,7 @@ var KBEngine; this.port = 20013; this.updateHZ = 100; this.serverHeartbeatTick = 15; + // this.protocol = "ws://"; // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types this.clientType = 5; @@ -1686,6 +1742,7 @@ var KBEngine; KBEngine.moduledefs = {}; var KBEngineApp = (function () { function KBEngineApp(args) { + // console.assert(app == null || app == undefined, "Assertion of app not is null"); this.username = "testhtml51"; this.password = "123456"; this.clientdatas = ""; @@ -1729,7 +1786,6 @@ var KBEngine; this.lastTickTime = Date.now(); this.lastTickCBTime = Date.now(); this.entityclass = {}; - console.assert(KBEngine.app == null || KBEngine.app == undefined, "Assertion of app not is null"); KBEngine.app = this; this.args = args; } @@ -1815,9 +1871,10 @@ var KBEngine; KBEngineApp.prototype.findEntity = function (entityID) { return KBEngine.app.entities[entityID]; }; - KBEngineApp.prototype.connect = function (addr) { - console.assert(KBEngine.app.socket == null, "Assertion of socket not is null"); + KBEngineApp.prototype.connect = function (host, port) { + // console.assert(app.socket == null, "Assertion of socket not is null"); try { + var addr = KBEngine.app.args.protocol + host + ':' + port; //todo 应该是在这里设置wss KBEngine.app.socket = new WebSocket(addr); } @@ -2284,7 +2341,7 @@ var KBEngine; KBEngineApp.prototype.createAccount_loginapp = function (noconnect) { if (noconnect) { KBEngine.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + KBEngine.app.args.ip + ":" + KBEngine.app.args.port + "!"); - KBEngine.app.connect(KBEngine.app.args.protocol + KBEngine.app.args.ip + ":" + KBEngine.app.args.port); + KBEngine.app.connect(KBEngine.app.args.ip, KBEngine.app.args.port); KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_createAccount; } else { @@ -2322,7 +2379,7 @@ var KBEngine; KBEngineApp.prototype.login_loginapp = function (noconnect) { if (noconnect) { KBEngine.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://" + KBEngine.app.args.ip + ":" + KBEngine.app.args.port + "!"); - KBEngine.app.connect(KBEngine.app.args.protocol + KBEngine.app.args.ip + ":" + KBEngine.app.args.port); + KBEngine.app.connect(KBEngine.app.args.ip, KBEngine.app.args.port); KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_login; } else { @@ -2358,7 +2415,7 @@ var KBEngine; KBEngineApp.prototype.resetpassword_loginapp = function (noconnect) { if (noconnect) { KBEngine.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + KBEngine.app.args.ip + ":" + KBEngine.app.args.port + "!"); - KBEngine.app.connect(KBEngine.app.args.protocol + KBEngine.app.args.ip + ":" + KBEngine.app.args.port); + KBEngine.app.connect(KBEngine.app.args.ip, KBEngine.app.args.port); KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_resetpassword; } else { @@ -2386,7 +2443,7 @@ var KBEngine; if (noconnect) { KBEngine.Event.fire("onLoginBaseapp"); KBEngine.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "!"); - KBEngine.app.connect(KBEngine.app.args.protocol + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort); + KBEngine.app.connect(KBEngine.app.baseappIp, KBEngine.app.baseappPort); if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) KBEngine.app.socket.onopen = KBEngine.app.onOpenBaseapp; } @@ -2404,7 +2461,7 @@ var KBEngine; KBEngine.app.resetSocket(); KBEngine.Event.fire("onReloginBaseapp"); KBEngine.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "!"); - KBEngine.app.connect(KBEngine.app.args.protocol + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort); + KBEngine.app.connect(KBEngine.app.baseappIp, KBEngine.app.baseappPort); if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) KBEngine.app.socket.onopen = KBEngine.app.onReOpenBaseapp; }; diff --git a/kbengine_ts/bin/kbengine.min.js b/kbengine_ts/bin/kbengine.min.js index 817ea7e..7888bbd 100644 --- a/kbengine_ts/bin/kbengine.min.js +++ b/kbengine_ts/bin/kbengine.min.js @@ -1,3 +1,3 @@ -var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(e){console.info(e)}function n(e){console.debug(e)}function r(e){console.error(e)}function a(e){console.warn(e)}e.INFO_MSG=t,e.DEBUG_MSG=n,e.ERROR_MSG=r,e.WARNING_MSG=a}(KBEngine||(KBEngine={})),function(e){function t(e){var t,n,r,a,i,o;for(t="",r=e.length,n=0;r>n;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=a,__reflect(a.prototype,"KBEngine.Vector3"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(t){for(var n=[],r=1;re||e>255?!1:!0},DATATYPE_UINT8}();KBEngine.DATATYPE_UINT8=DATATYPE_UINT8,__reflect(DATATYPE_UINT8.prototype,"KBEngine.DATATYPE_UINT8");var DATATYPE_UINT16=function(){function DATATYPE_UINT16(){}return DATATYPE_UINT16.prototype.bind=function(){},DATATYPE_UINT16.prototype.createFromStream=function(e){return KBEngine.reader.readUint16.call(e)},DATATYPE_UINT16.prototype.addToStream=function(e,t){e.writeUint16(t)},DATATYPE_UINT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},DATATYPE_UINT16}();KBEngine.DATATYPE_UINT16=DATATYPE_UINT16,__reflect(DATATYPE_UINT16.prototype,"KBEngine.DATATYPE_UINT16");var DATATYPE_UINT32=function(){function DATATYPE_UINT32(){}return DATATYPE_UINT32.prototype.bind=function(){},DATATYPE_UINT32.prototype.createFromStream=function(e){return KBEngine.reader.readUint32.call(e)},DATATYPE_UINT32.prototype.addToStream=function(e,t){e.writeUint32(t)},DATATYPE_UINT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},DATATYPE_UINT32}();KBEngine.DATATYPE_UINT32=DATATYPE_UINT32,__reflect(DATATYPE_UINT32.prototype,"KBEngine.DATATYPE_UINT32");var DATATYPE_UINT64=function(){function DATATYPE_UINT64(){}return DATATYPE_UINT64.prototype.bind=function(){},DATATYPE_UINT64.prototype.createFromStream=function(e){return KBEngine.reader.readUint64.call(e)},DATATYPE_UINT64.prototype.addToStream=function(e,t){e.writeUint64(t)},DATATYPE_UINT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_UINT64.prototype.isSameType=function(e){return e instanceof KBEngine.UINT64},DATATYPE_UINT64}();KBEngine.DATATYPE_UINT64=DATATYPE_UINT64,__reflect(DATATYPE_UINT64.prototype,"KBEngine.DATATYPE_UINT64");var DATATYPE_INT8=function(){function DATATYPE_INT8(){}return DATATYPE_INT8.prototype.bind=function(){},DATATYPE_INT8.prototype.createFromStream=function(e){return KBEngine.reader.readInt8.call(e)},DATATYPE_INT8.prototype.addToStream=function(e,t){e.writeInt8(t)},DATATYPE_INT8.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT8.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},DATATYPE_INT8}();KBEngine.DATATYPE_INT8=DATATYPE_INT8,__reflect(DATATYPE_INT8.prototype,"KBEngine.DATATYPE_INT8");var DATATYPE_INT16=function(){function DATATYPE_INT16(){}return DATATYPE_INT16.prototype.bind=function(){},DATATYPE_INT16.prototype.createFromStream=function(e){return KBEngine.reader.readInt16.call(e)},DATATYPE_INT16.prototype.addToStream=function(e,t){e.writeInt16(t)},DATATYPE_INT16.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT16.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},DATATYPE_INT16}();KBEngine.DATATYPE_INT16=DATATYPE_INT16,__reflect(DATATYPE_INT16.prototype,"KBEngine.DATATYPE_INT16");var DATATYPE_INT32=function(){function DATATYPE_INT32(){}return DATATYPE_INT32.prototype.bind=function(){},DATATYPE_INT32.prototype.createFromStream=function(e){return KBEngine.reader.readInt32.call(e)},DATATYPE_INT32.prototype.addToStream=function(e,t){e.writeInt32(t)},DATATYPE_INT32.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT32.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},DATATYPE_INT32}();KBEngine.DATATYPE_INT32=DATATYPE_INT32,__reflect(DATATYPE_INT32.prototype,"KBEngine.DATATYPE_INT32");var DATATYPE_INT64=function(){function DATATYPE_INT64(){}return DATATYPE_INT64.prototype.bind=function(){},DATATYPE_INT64.prototype.createFromStream=function(e){return KBEngine.reader.readInt64.call(e)},DATATYPE_INT64.prototype.addToStream=function(e,t){e.writeInt64(t)},DATATYPE_INT64.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_INT64.prototype.isSameType=function(e){return e instanceof KBEngine.INT64},DATATYPE_INT64}();KBEngine.DATATYPE_INT64=DATATYPE_INT64,__reflect(DATATYPE_INT64.prototype,"KBEngine.DATATYPE_INT64");var DATATYPE_FLOAT=function(){function DATATYPE_FLOAT(){}return DATATYPE_FLOAT.prototype.bind=function(){},DATATYPE_FLOAT.prototype.createFromStream=function(e){return KBEngine.reader.readFloat.call(e)},DATATYPE_FLOAT.prototype.addToStream=function(e,t){e.writeFloat(t)},DATATYPE_FLOAT.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_FLOAT.prototype.isSameType=function(e){return"number"==typeof e},DATATYPE_FLOAT}();KBEngine.DATATYPE_FLOAT=DATATYPE_FLOAT,__reflect(DATATYPE_FLOAT.prototype,"KBEngine.DATATYPE_FLOAT");var DATATYPE_DOUBLE=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.createFromStream=function(e){return KBEngine.reader.readDouble.call(e)},t.prototype.addToStream=function(e,t){e.writeDouble(t)},t}(DATATYPE_FLOAT);KBEngine.DATATYPE_DOUBLE=DATATYPE_DOUBLE,__reflect(DATATYPE_DOUBLE.prototype,"KBEngine.DATATYPE_DOUBLE");var DATATYPE_STRING=function(){function DATATYPE_STRING(){}return DATATYPE_STRING.prototype.bind=function(){},DATATYPE_STRING.prototype.createFromStream=function(e){return KBEngine.reader.readString.call(e)},DATATYPE_STRING.prototype.addToStream=function(e,t){e.writeString(t)},DATATYPE_STRING.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_STRING.prototype.isSameType=function(e){return"string"==typeof e},DATATYPE_STRING}();KBEngine.DATATYPE_STRING=DATATYPE_STRING,__reflect(DATATYPE_STRING.prototype,"KBEngine.DATATYPE_STRING");var DATATYPE_VECTOR2=function(){function DATATYPE_VECTOR2(){}return DATATYPE_VECTOR2.prototype.bind=function(){},DATATYPE_VECTOR2.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR2.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y)):(e.writeFloat(t.x),e.writeFloat(t.y))},DATATYPE_VECTOR2.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR2.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR2}();KBEngine.DATATYPE_VECTOR2=DATATYPE_VECTOR2,__reflect(DATATYPE_VECTOR2.prototype,"KBEngine.DATATYPE_VECTOR2");var DATATYPE_VECTOR3=function(){function DATATYPE_VECTOR3(){}return DATATYPE_VECTOR3.prototype.bind=function(){},DATATYPE_VECTOR3.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR3.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y),e.writeInt32(t.z)):(e.writeFloat(t.x),e.writeFloat(t.y),e.writeFloat(t.z))},DATATYPE_VECTOR3.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR3.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR3}();KBEngine.DATATYPE_VECTOR3=DATATYPE_VECTOR3,__reflect(DATATYPE_VECTOR3.prototype,"KBEngine.DATATYPE_VECTOR3");var DATATYPE_VECTOR4=function(){function DATATYPE_VECTOR4(){}return DATATYPE_VECTOR4.prototype.bind=function(){},DATATYPE_VECTOR4.prototype.createFromStream=function(e){return KBEngine.CLIENT_NO_FLOAT?new KBEngine.Vector3(KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e),KBEngine.reader.readInt32.call(e)):new KBEngine.Vector3(KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e),KBEngine.reader.readFloat.call(e))},DATATYPE_VECTOR4.prototype.addToStream=function(e,t){KBEngine.CLIENT_NO_FLOAT?(e.writeInt32(t.x),e.writeInt32(t.y),e.writeInt32(t.z),e.writeInt32(t.w)):(e.writeFloat(t.x),e.writeFloat(t.y),e.writeFloat(t.z),e.writeFloat(t.w))},DATATYPE_VECTOR4.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_VECTOR4.prototype.isSameType=function(e){return e instanceof KBEngine.Vector3?!0:!1},DATATYPE_VECTOR4}();KBEngine.DATATYPE_VECTOR4=DATATYPE_VECTOR4,__reflect(DATATYPE_VECTOR4.prototype,"KBEngine.DATATYPE_VECTOR4");var DATATYPE_PYTHON=function(){function DATATYPE_PYTHON(){}return DATATYPE_PYTHON.prototype.bind=function(){},DATATYPE_PYTHON.prototype.createFromStream=function(e){},DATATYPE_PYTHON.prototype.addToStream=function(e,t){},DATATYPE_PYTHON.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_PYTHON.prototype.isSameType=function(e){return!1},DATATYPE_PYTHON}();KBEngine.DATATYPE_PYTHON=DATATYPE_PYTHON,__reflect(DATATYPE_PYTHON.prototype,"KBEngine.DATATYPE_PYTHON");var DATATYPE_UNICODE=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return KBEngine.utf8ArrayToString(KBEngine.reader.readBlob.call(e))},e.prototype.addToStream=function(e,t){e.writeBlob(KBEngine.stringToUTF8Bytes(t))},e.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},e.prototype.isSameType=function(e){return"string"==typeof e},e}();KBEngine.DATATYPE_UNICODE=DATATYPE_UNICODE,__reflect(DATATYPE_UNICODE.prototype,"KBEngine.DATATYPE_UNICODE");var DATATYPE_ENTITYCALL=function(){function DATATYPE_ENTITYCALL(){}return DATATYPE_ENTITYCALL.prototype.bind=function(){},DATATYPE_ENTITYCALL.prototype.createFromStream=function(e){},DATATYPE_ENTITYCALL.prototype.addToStream=function(e,t){},DATATYPE_ENTITYCALL.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_ENTITYCALL.prototype.isSameType=function(e){return!1},DATATYPE_ENTITYCALL}();KBEngine.DATATYPE_ENTITYCALL=DATATYPE_ENTITYCALL,__reflect(DATATYPE_ENTITYCALL.prototype,"KBEngine.DATATYPE_ENTITYCALL");var DATATYPE_BLOB=function(){function DATATYPE_BLOB(){}return DATATYPE_BLOB.prototype.bind=function(){},DATATYPE_BLOB.prototype.createFromStream=function(e){var t=KBEngine.reader.readUint32.call(e),n=new Uint8Array(e.buffer,e.rpos,t);return e.rpos+=t,n},DATATYPE_BLOB.prototype.addToStream=function(e,t){e.writeBlob(t)},DATATYPE_BLOB.prototype.parseDefaultValStr=function(v){return eval(v)},DATATYPE_BLOB.prototype.isSameType=function(e){return!0},DATATYPE_BLOB}();KBEngine.DATATYPE_BLOB=DATATYPE_BLOB,__reflect(DATATYPE_BLOB.prototype,"KBEngine.DATATYPE_BLOB");var DATATYPE_ARRAY=function(){function DATATYPE_ARRAY(){this.type=null}return DATATYPE_ARRAY.prototype.bind=function(){"number"==typeof this.type&&(this.type=datatypes[this.type])},DATATYPE_ARRAY.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},DATATYPE_ARRAY.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,T=s.cell_methods;try{var u=e.Entities[n]}catch(_){}for(;a>0;){a--;var E=t.readUint16(),y=t.readUint32(),f=t.readInt16(),A=t.readString(),g=t.readString(),v=e.datatypes[t.readUint16()],h=null;void 0!=u&&(h=u.prototype["set_"+A],void 0==h&&(h=null));var m=[E,f,A,g,v,h,y];l[A]=m,-1!=f?(l[f]=m,s.usePropertyDescrAlias=!0):(l[E]=m,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+A+"/"+E+").")}for(;i>0;){i--;for(var I=t.readUint16(),f=t.readInt16(),D=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);var m=[I,f,D,B];c[D]=m,-1!=f?(c[f]=m,s.useMethodDescrAlias=!0):(c[I]=m,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+D+").")}for(;o>0;){o--;for(var I=t.readUint16(),f=t.readInt16(),P=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);d[P]=[I,f,P,B],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+P+").")}for(;p>0;){p--;for(var I=t.readUint16(),f=t.readInt16(),C=t.readString(),S=t.readUint8(),B=[];S>0;)S--,B.push(e.datatypes[t.readUint16()]);T[C]=[I,f,C,B],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+C+").")}var w=void 0;try{w=e.Entities[n]}catch(_){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),w=void 0}for(var M in s.propertys){var Y=s.propertys[M],E=Y[0],f=Y[1],N=Y[2],g=Y[3],v=Y[4];void 0!=w&&(w.prototype[N]=v.parseDefaultValStr(g))}for(var L in s.methods){var Y=s.methods[L],E=Y[0],f=Y[1],N=Y[2],B=Y[3];void 0!=w&&void 0==w.prototype[N]&&e.WARNING_MSG(n+":: method("+N+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,T=o.indexOf("Client_")>=0;T&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),T?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.protocol+e.app.args.ip+":"+e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.args.protocol+e.app.baseappIp+":"+e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.args.protocol+e.app.baseappIp+":"+e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=e.Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessage[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessage[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],T=l[4].createFromStream(n),u=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+T+")!"),r[l[2]]=T,null!=c&&(32==d||64==d?r.inited&&c.call(r,u):r.inWorld&&c.call(r,u))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessage[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessage[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(); -e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0)},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var T=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(T=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),T&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file +var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(e){console.info(e)}function n(e){console.debug(e)}function r(e){console.error(e)}function a(e){console.warn(e)}e.INFO_MSG=t,e.DEBUG_MSG=n,e.ERROR_MSG=r,e.WARNING_MSG=a}(KBEngine||(KBEngine={})),function(e){function t(e){var t,n,r,a,i,o;for(t="",r=e.length,n=0;r>n;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t){this.x=e,this.y=t}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y;return Math.sqrt(t*t+n*n)},e}();e.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function e(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(t){for(var n=[],r=1;re||e>255?!1:!0},t}();e.DATATYPE_UINT8=n,__reflect(n.prototype,"KBEngine.DATATYPE_UINT8");var r=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint16.call(t)},t.prototype.addToStream=function(e,t){e.writeUint16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},t}();e.DATATYPE_UINT16=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT16");var a=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint32.call(t)},t.prototype.addToStream=function(e,t){e.writeUint32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},t}();e.DATATYPE_UINT32=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT32");var i=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint64.call(t)},t.prototype.addToStream=function(e,t){e.writeUint64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.UINT64},t}();e.DATATYPE_UINT64=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT64");var o=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt8.call(t)},t.prototype.addToStream=function(e,t){e.writeInt8(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},t}();e.DATATYPE_INT8=o,__reflect(o.prototype,"KBEngine.DATATYPE_INT8");var p=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt16.call(t)},t.prototype.addToStream=function(e,t){e.writeInt16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},t}();e.DATATYPE_INT16=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT16");var s=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt32.call(t)},t.prototype.addToStream=function(e,t){e.writeInt32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},t}();e.DATATYPE_INT32=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT32");var l=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt64.call(t)},t.prototype.addToStream=function(e,t){e.writeInt64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.INT64},t}();e.DATATYPE_INT64=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT64");var c=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readFloat.call(t)},t.prototype.addToStream=function(e,t){e.writeFloat(t)},t.prototype.parseDefaultValStr=function(e){return parseFloat(e)},t.prototype.isSameType=function(e){return"number"==typeof e},t}();e.DATATYPE_FLOAT=c,__reflect(c.prototype,"KBEngine.DATATYPE_FLOAT");var d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),n.prototype.createFromStream=function(t){return e.reader.readDouble.call(t)},n.prototype.addToStream=function(e,t){e.writeDouble(t)},n}(c);e.DATATYPE_DOUBLE=d,__reflect(d.prototype,"KBEngine.DATATYPE_DOUBLE");var u=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readString.call(t)},t.prototype.addToStream=function(e,t){e.writeString(t)},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_STRING=u,__reflect(u.prototype,"KBEngine.DATATYPE_STRING");var y=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector2(e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector2(e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y)):(t.writeFloat(n.x),t.writeFloat(n.y))},t.prototype.parseDefaultValStr=function(t){return new e.Vector2(0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector2?!0:!1},t}();e.DATATYPE_VECTOR2=y,__reflect(y.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector3(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector3(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z))},t.prototype.parseDefaultValStr=function(t){return new e.Vector3(0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector3?!0:!1},t}();e.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var _=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector4(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readFloat.call(t)):new e.Vector4(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z),t.writeInt32(n.w)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z),t.writeFloat(n.w))},t.prototype.parseDefaultValStr=function(t){return new e.Vector4(0,0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector4?!0:!1},t}();e.DATATYPE_VECTOR4=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR4");var E=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_PYTHON=E,__reflect(E.prototype,"KBEngine.DATATYPE_PYTHON");var g=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.utf8ArrayToString(e.reader.readBlob.call(t))},t.prototype.addToStream=function(t,n){t.writeBlob(e.stringToUTF8Bytes(n))},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_UNICODE=g,__reflect(g.prototype,"KBEngine.DATATYPE_UNICODE");var h=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_ENTITYCALL=h,__reflect(h.prototype,"KBEngine.DATATYPE_ENTITYCALL");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){var n=e.reader.readUint32.call(t),r=new Uint8Array(t.buffer,t.rpos,n);return t.rpos+=n,r},t.prototype.addToStream=function(e,t){e.writeBlob(t)},t.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},t.prototype.isSameType=function(e){return!0},t}();e.DATATYPE_BLOB=m,__reflect(m.prototype,"KBEngine.DATATYPE_BLOB");var v=function(){function e(){this.type=null}return e.prototype.bind=function(){"number"==typeof this.type&&(this.type=T[this.type])},e.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},e.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods;try{var y=e.Entities[n]}catch(f){}for(;a>0;){a--;var _=t.readUint16(),E=t.readUint32(),g=t.readInt16(),h=t.readString(),m=t.readString(),v=e.datatypes[t.readUint16()],S=null;void 0!=y&&(S=y.prototype["set_"+h],void 0==S&&(S=null));var T=[_,g,h,m,v,S,E];l[h]=T,-1!=g?(l[g]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+h+"/"+_+").")}for(;i>0;){i--;for(var I=t.readUint16(),g=t.readInt16(),w=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);var T=[I,g,w,C];c[w]=T,-1!=g?(c[g]=T,s.useMethodDescrAlias=!0):(c[I]=T,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+w+").")}for(;o>0;){o--;for(var I=t.readUint16(),g=t.readInt16(),B=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);d[B]=[I,g,B,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+B+").")}for(;p>0;){p--;for(var I=t.readUint16(),g=t.readInt16(),D=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);u[D]=[I,g,D,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+D+").")}var M=void 0;try{M=e.Entities[n]}catch(f){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),M=void 0}for(var L in s.propertys){var F=s.propertys[L],_=F[0],g=F[1],R=F[2],m=F[3],v=F[4];void 0!=M&&(M.prototype[R]=v.parseDefaultValStr(m))}for(var K in s.methods){var F=s.methods[K],_=F[0],g=F[1],R=F[2],C=F[3];void 0!=M&&void 0==M.prototype[R]&&e.WARNING_MSG(n+":: method("+R+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,u=o.indexOf("Client_")>=0;u&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),u?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=e.Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessage[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessage[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],u=l[4].createFromStream(n),y=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+u+")!"),r[l[2]]=u,null!=c&&(32==d||64==d?r.inited&&c.call(r,y):r.inWorld&&c.call(r,y))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessage[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessage[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0)},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(); +e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var u=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(u=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),u&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index c13d491..f0477f4 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -1,9 +1,19 @@ /** - * KBEngine的html5客户端扩展ts版 - * todo 类型匹配未完善 - * 缺少测试 - * 缺少类型Vector2,Vector4,暂时修改为Vector3,如果出问题再修改 + * KBEngine的html5客户端扩展ts版 1.1.5版本 + * cocos creator 环境下使用方法 + * 将bin/kbengine.js导入为插件,将bin/kbengine.d.ts放在项目根目录下,即可 + * + * todo 未完成内容 + * 1、强类型匹配 + * 2、代码注释 + * + * 注:(下面的是重点) + * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 + * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 window['KBEngine'] = window['KBEngine'] || {};window['KBEngine']['你的实体类名']=你的实体类名;将声明提升至全局 + * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; + * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ + /*----------------------------------------------------------------------------------------- global -----------------------------------------------------------------------------------------*/ @@ -18,6 +28,10 @@ namespace KBEngine { export const CLIENT_NO_FLOAT = 0; export const KBE_FLT_MAX = 3.402823466e+38; } +/** + * 加上声明避免cocos creator编辑器报错 + */ +window['KBEngine']=KBEngine; /*----------------------------------------------------------------------------------------- number64bits -----------------------------------------------------------------------------------------*/ @@ -90,6 +104,7 @@ namespace KBEngine { debug -----------------------------------------------------------------------------------------*/ namespace KBEngine { + /** todo 调试输出模块,这里需要根据使用的引擎不同在这里加入判断条件 */ export function INFO_MSG(s) { console.info(s); } @@ -209,7 +224,7 @@ namespace KBEngine { let info = new EventInfo(classinst, callbackfn); evtlst.push(info); } - deregister(evtName:string, classinst) { + deregister(evtName: string, classinst) { for (let itemkey in this._events) { let evtlst = this._events[itemkey]; while (true) { @@ -228,8 +243,8 @@ namespace KBEngine { } } } - fire(evtName:string, ...args:any[]) { - if (arguments.length < 1) { + fire(evtName: string, ...args: any[]) { + if (!evtName) { ERROR_MSG('export class Event::fire: not found eventName!'); return; } @@ -326,7 +341,7 @@ namespace KBEngine { } readFloat() { - let buf ; + let buf; try { buf = new Float32Array(this.buffer, this.rpos, 1); } @@ -599,7 +614,7 @@ namespace KBEngine { memorystreams: Array = new Array(); stream: MemoryStream; numMessage: number = 0; - messageLengthBuffer:Uint8Array = null; + messageLengthBuffer: Uint8Array = null; msgtype = null; messageLength: number = 0; //--------------------------------------------------------------------------------- @@ -876,7 +891,7 @@ namespace KBEngine { return result; } - handleMessage (msgstream) { + handleMessage(msgstream) { if (this.handler == null) { ERROR_MSG("Message::handleMessage: interface(" + this.name + "/" + this.id + ") no implement!"); return; @@ -909,9 +924,21 @@ namespace KBEngine { math -----------------------------------------------------------------------------------------*/ namespace KBEngine { - export class Vector3 { + export class Vector2 { + constructor(x, y) { + this.x = x; + this.y = y; + } + x: number; + y: number; + distance(pos: Vector2) { + let x = pos.x - this.x; + let y = pos.y - this.y; + return Math.sqrt(x * x + y * y); + } + } + export class Vector3 { constructor(x, y, z) { - this.x = x; this.y = y; this.z = z; @@ -926,6 +953,30 @@ namespace KBEngine { return Math.sqrt(x * x + y * y + z * z); } } + /** + * todo 这个类的第四个参数的没搞清楚,所有如果没有必要,不要用这个东西 + */ + export class Vector4 { + constructor(x, y, z,w) { + this.x = x; + this.y = y; + this.z = z; + this.w =w; + } + x: number; + y: number; + z: number; + w:number; + /** + * todo 因为不清楚这个vector4的 w 的含义,所以不确定这个方法的正确性 + */ + distance(pos: Vector4) { + let x = pos.x - this.x; + let y = pos.y - this.y; + let z = pos.z - this.z; + return Math.sqrt(x * x + y * y + z * z); + } + } export function clampf(value, min_inclusive, max_inclusive) { if (min_inclusive > max_inclusive) { let temp = min_inclusive; @@ -957,9 +1008,9 @@ namespace KBEngine { export namespace Entities { } - export class Entity { + export class Entity { constructor() { - + } id: number = 0; className: string = ""; @@ -1027,7 +1078,7 @@ namespace KBEngine { isPlayer() { return this.id == app.entity_id; } - baseCall(type:string,...params:any[]) { + baseCall(type: string, ...params: any[]) { // if (params.length < 1) { // ERROR_MSG('Entity::baseCall: not fount interfaceName!'); // return; @@ -1048,7 +1099,7 @@ namespace KBEngine { let methodID = method[0]; let args = method[3]; - if (params.length != args.length) { + if (params.length != args.length) { ERROR_MSG("Entity::baseCall: args(" + (params.length - 1) + "!= " + args.length + ") size is error!"); return; } @@ -1075,7 +1126,7 @@ namespace KBEngine { this.base.sendCall(); } - cellCall(type:string,...params:any[]) { + cellCall(type: string, ...params: any[]) { // if (params.length < 1) { // ERROR_MSG('Entity::cellCall: not fount interfaceName!'); // return; @@ -1097,7 +1148,7 @@ namespace KBEngine { let args = method[3]; if (params.length != args.length) { - ERROR_MSG("Entity::cellCall: args(" + (params.length ) + "!= " + args.length + ") size is error!"); + ERROR_MSG("Entity::cellCall: args(" + (params.length) + "!= " + args.length + ") size is error!"); return; } @@ -1229,22 +1280,22 @@ namespace KBEngine { } export class DATATYPE_UINT8 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return reader.readUint8.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeUint8(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return parseInt(v); } - isSameType (v) { + isSameType(v) { if (typeof (v) != "number") { return false; } @@ -1257,22 +1308,22 @@ namespace KBEngine { } } export class DATATYPE_UINT16 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return reader.readUint16.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeUint16(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return parseInt(v); } - isSameType (v) { + isSameType(v) { if (typeof (v) != "number") { return false; } @@ -1285,21 +1336,21 @@ namespace KBEngine { } } export class DATATYPE_UINT32 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return reader.readUint32.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeUint32(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return parseInt(v); } - isSameType (v) { + isSameType(v) { if (typeof (v) != "number") { return false; } @@ -1312,42 +1363,42 @@ namespace KBEngine { } } export class DATATYPE_UINT64 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return reader.readUint64.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeUint64(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return parseInt(v); } - isSameType (v) { + isSameType(v) { return v instanceof UINT64; } } export class DATATYPE_INT8 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return reader.readInt8.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeInt8(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return parseInt(v); } - isSameType (v) { + isSameType(v) { if (typeof (v) != "number") { return false; } @@ -1360,22 +1411,22 @@ namespace KBEngine { } } export class DATATYPE_INT16 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return reader.readInt16.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeInt16(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return parseInt(v); } - isSameType (v) { + isSameType(v) { if (typeof (v) != "number") { return false; } @@ -1388,22 +1439,22 @@ namespace KBEngine { } } export class DATATYPE_INT32 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return reader.readInt32.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeInt32(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return parseInt(v); } - isSameType (v) { + isSameType(v) { if (typeof (v) != "number") { return false; } @@ -1416,90 +1467,93 @@ namespace KBEngine { } } export class DATATYPE_INT64 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return reader.readInt64.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeInt64(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return parseInt(v); } - isSameType (v) { + isSameType(v) { return v instanceof INT64; } } export class DATATYPE_FLOAT { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return reader.readFloat.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeFloat(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return parseFloat(v); } - isSameType (v) { + isSameType(v) { return typeof (v) == "number"; } } export class DATATYPE_DOUBLE extends DATATYPE_FLOAT { - createFromStream (stream) { + createFromStream(stream) { return reader.readDouble.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeDouble(v); } } export class DATATYPE_STRING { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return reader.readString.call(stream); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeString(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + if (typeof (v) == "string") + return v; + + return ""; } - isSameType (v) { + isSameType(v) { return typeof (v) == "string"; } } export class DATATYPE_VECTOR2 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { if (CLIENT_NO_FLOAT) { - return new Vector3(reader.readInt32.call(stream), - reader.readInt32.call(stream), reader.readInt32.call(stream)); + return new Vector2(reader.readInt32.call(stream), + reader.readInt32.call(stream)); } else { - return new Vector3(reader.readFloat.call(stream), - reader.readFloat.call(stream), reader.readFloat.call(stream)); + return new Vector2(reader.readFloat.call(stream), + reader.readFloat.call(stream)); } } - addToStream (stream, v) { + addToStream(stream, v) { if (CLIENT_NO_FLOAT) { stream.writeInt32(v.x); stream.writeInt32(v.y); @@ -1510,12 +1564,12 @@ namespace KBEngine { } } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return new KBEngine.Vector2(0.0, 0.0);; } - isSameType (v) { - if (!(v instanceof Vector3)) { + isSameType(v) { + if (!(v instanceof Vector2)) { return false; } @@ -1523,10 +1577,10 @@ namespace KBEngine { } } export class DATATYPE_VECTOR3 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { if (CLIENT_NO_FLOAT) { return new Vector3(reader.readInt32.call(stream), reader.readInt32.call(stream), reader.readInt32.call(stream)); @@ -1537,7 +1591,7 @@ namespace KBEngine { } } - addToStream (stream, v) { + addToStream(stream, v) { if (CLIENT_NO_FLOAT) { stream.writeInt32(v.x); stream.writeInt32(v.y); @@ -1550,11 +1604,11 @@ namespace KBEngine { } } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return new KBEngine.Vector3(0.0, 0.0, 0.0); } - isSameType (v) { + isSameType(v) { if (!(v instanceof Vector3)) { return false; } @@ -1563,21 +1617,21 @@ namespace KBEngine { } } export class DATATYPE_VECTOR4 { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { if (CLIENT_NO_FLOAT) { - return new Vector3(reader.readInt32.call(stream), - reader.readInt32.call(stream), reader.readInt32.call(stream)); + return new Vector4(reader.readInt32.call(stream), + reader.readInt32.call(stream), reader.readInt32.call(stream),reader.readFloat.call(stream)); } else { - return new Vector3(reader.readFloat.call(stream), - reader.readFloat.call(stream), reader.readFloat.call(stream)); + return new Vector4(reader.readFloat.call(stream), + reader.readFloat.call(stream), reader.readFloat.call(stream),reader.readFloat.call(stream)); } } - addToStream (stream, v) { + addToStream(stream, v) { if (CLIENT_NO_FLOAT) { stream.writeInt32(v.x); stream.writeInt32(v.y); @@ -1592,12 +1646,12 @@ namespace KBEngine { } } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return new KBEngine.Vector4(0.0, 0.0, 0.0,0.0); } - isSameType (v) { - if (!(v instanceof Vector3)) { + isSameType(v) { + if (!(v instanceof Vector4)) { return false; } @@ -1605,96 +1659,96 @@ namespace KBEngine { } } export class DATATYPE_PYTHON { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { } - addToStream (stream, v) { + addToStream(stream, v) { } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return new Uint8Array(0); } - isSameType (v) { + isSameType(v) { return false; } } export class DATATYPE_UNICODE { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { return utf8ArrayToString(reader.readBlob.call(stream)); } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeBlob(stringToUTF8Bytes(v)); } - parseDefaultValStr (v) { + parseDefaultValStr(v) { if (typeof (v) == "string") return v; return ""; } - isSameType (v) { + isSameType(v) { return typeof (v) == "string"; } } export class DATATYPE_ENTITYCALL { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { } - addToStream (stream, v) { + addToStream(stream, v) { } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return new Uint8Array(0);; } - isSameType (v) { + isSameType(v) { return false; } } export class DATATYPE_BLOB { - bind () { + bind() { } - createFromStream (stream) { + createFromStream(stream) { let size = reader.readUint32.call(stream); let buf = new Uint8Array(stream.buffer, stream.rpos, size); stream.rpos += size; return buf; } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeBlob(v); } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return new Uint8Array(0); } - isSameType (v) { + isSameType(v) { return true; } } export class DATATYPE_ARRAY { type = null; - bind () { + bind() { if (typeof (this.type) == "number") this.type = datatypes[this.type]; } - createFromStream (stream) { + createFromStream(stream) { let size = stream.readUint32(); let datas = []; @@ -1706,18 +1760,18 @@ namespace KBEngine { return datas; } - addToStream (stream, v) { + addToStream(stream, v) { stream.writeUint32(v.length); for (let i = 0; i < v.length; i++) { this.type.addToStream(stream, v[i]); } } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return []; } - isSameType (v) { + isSameType(v) { for (let i = 0; i < v.length; i++) { if (!this.type.isSameType(v[i])) { return false; @@ -1731,7 +1785,7 @@ namespace KBEngine { dicttype = {}; implementedBy = null; - bind () { + bind() { for (let itemkey in this.dicttype) { let utype = this.dicttype[itemkey]; @@ -1740,7 +1794,7 @@ namespace KBEngine { } } - createFromStream (stream) { + createFromStream(stream) { let datas = {}; for (let itemkey in this.dicttype) { datas[itemkey] = this.dicttype[itemkey].createFromStream(stream); @@ -1749,17 +1803,17 @@ namespace KBEngine { return datas; } - addToStream (stream, v) { + addToStream(stream, v) { for (let itemkey in this.dicttype) { this.dicttype[itemkey].addToStream(stream, v[itemkey]); } } - parseDefaultValStr (v) { - return eval(v); + parseDefaultValStr(v) { + return {}; } - isSameType (v) { + isSameType(v) { for (let itemkey in this.dicttype) { if (!this.dicttype[itemkey].isSameType(v[itemkey])) { return false; @@ -1803,8 +1857,8 @@ namespace KBEngine { port = 20013; updateHZ = 100; serverHeartbeatTick = 15; - - protocol:string = "ws://"; + // + protocol: string = "ws://"; // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types clientType = 5; @@ -1812,6 +1866,7 @@ namespace KBEngine { // 在Entity初始化时是否触发属性的set_*事件(callPropertysSetMethods) isOnInitCallPropertysSetMethods = true; } + } /*----------------------------------------------------------------------------------------- KBEngine app @@ -1820,13 +1875,13 @@ namespace KBEngine { export const moduledefs = {}; export class KBEngineApp { constructor(args: KBEngineArgs) { - console.assert(app == null || app == undefined, "Assertion of app not is null"); + // console.assert(app == null || app == undefined, "Assertion of app not is null"); app = this; this.args = args; } args: KBEngineArgs; - baseappIp:string; + baseappIp: string; username = "testhtml51"; password = "123456"; clientdatas = ""; @@ -1848,7 +1903,7 @@ namespace KBEngine { baseappPort = 0; socket; - currserver:string; + currserver: string; currstate = "create"; // 扩展数据 @@ -1949,19 +2004,19 @@ namespace KBEngine { // 当前组件类别, 配套服务端体系 app.component = "client"; } - installEvents () { + installEvents() { Event.register("createAccount", app, "createAccount"); Event.register("login", app, "login"); Event.register("reloginBaseapp", app, "reloginBaseapp"); Event.register("bindAccountEmail", app, "bindAccountEmail"); Event.register("newPassword", app, "newPassword"); } - uninstallEvents () { + uninstallEvents() { Event.deregister("reloginBaseapp", app); Event.deregister("login", app); Event.deregister("createAccount", app); } - hello () { + hello() { let bundle = new Bundle(); if (app.currserver == "loginapp") @@ -1974,16 +2029,16 @@ namespace KBEngine { bundle.writeBlob(app.encryptedKey); bundle.send(app); } - player () { + player() { return app.entities[app.entity_id]; } - findEntity (entityID) { + findEntity(entityID) { return app.entities[entityID]; } - connect (addr) { - console.assert(app.socket == null, "Assertion of socket not is null"); - + connect(host, port) { + // console.assert(app.socket == null, "Assertion of socket not is null"); try { + let addr = app.args.protocol + host + ':' + port //todo 应该是在这里设置wss app.socket = new WebSocket(addr); } @@ -1999,25 +2054,25 @@ namespace KBEngine { app.socket.onmessage = app.onmessage; app.socket.onclose = app.onclose; } - disconnect () { + disconnect() { app.resetSocket(); } - onopen () { + onopen() { INFO_MSG('connect success!'); app.socket.onerror = app.onerror_after_onopen; Event.fire("onConnectionState", true); } - onerror_before_onopen (evt) { + onerror_before_onopen(evt) { ERROR_MSG('connect error:' + evt.data); app.resetSocket(); Event.fire("onConnectionState", false); } - onerror_after_onopen (evt) { + onerror_after_onopen(evt) { ERROR_MSG('connect error:' + evt.data); app.resetSocket(); Event.fire("onDisconnected"); } - onmessage (msg) { + onmessage(msg) { let stream = new MemoryStream(msg.data); stream.wpos = msg.data.byteLength; @@ -2047,22 +2102,22 @@ namespace KBEngine { } } } - onclose () { + onclose() { INFO_MSG('connect close:' + app.currserver); app.resetSocket(); Event.fire("onDisconnected"); //if(app.currserver != "loginapp") // app.reset(); } - send (msg) { + send(msg) { app.socket.send(msg); } - close () { + close() { INFO_MSG('KBEngine::close()'); app.socket.close(); app.reset(); } - update () { + update() { if (app.socket == null) return; @@ -2095,11 +2150,11 @@ namespace KBEngine { app.updatePlayerToServer(); } - Client_onAppActiveTickCB () { + Client_onAppActiveTickCB() { let dateObject = new Date(); app.lastTickCBTime = dateObject.getTime(); } - serverErr (id) { + serverErr(id) { let e = app.serverErrs[id]; if (e == undefined) { @@ -2108,7 +2163,7 @@ namespace KBEngine { return e.name + " [" + e.descr + "]"; } - Client_onImportServerErrorsDescr (stream) { + Client_onImportServerErrorsDescr(stream) { let size = stream.readUint16(); while (size > 0) { size -= 1; @@ -2123,7 +2178,7 @@ namespace KBEngine { INFO_MSG("Client_onImportServerErrorsDescr: id=" + e.id + ", name=" + e.name + ", descr=" + e.descr); } } - onOpenLoginapp_login () { + onOpenLoginapp_login() { INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"); Event.fire("onConnectionState", true); @@ -2142,7 +2197,7 @@ namespace KBEngine { app.onImportClientMessagesCompleted(); } } - onOpenLoginapp_createAccount () { + onOpenLoginapp_createAccount() { Event.fire("onConnectionState", true); INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"); app.currserver = "loginapp"; @@ -2160,7 +2215,7 @@ namespace KBEngine { app.onImportClientMessagesCompleted(); } } - onImportClientMessagesCompleted () { + onImportClientMessagesCompleted() { INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"); app.socket.onmessage = app.onmessage; app.hello(); @@ -2198,7 +2253,7 @@ namespace KBEngine { } } } - createDataTypeFromStreams (stream, canprint) { + createDataTypeFromStreams(stream, canprint) { let aliassize = stream.readUint16(); INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size=" + aliassize + ")!"); @@ -2213,11 +2268,11 @@ namespace KBEngine { } } } - createDataTypeFromStream (stream, canprint) { + createDataTypeFromStream(stream, canprint) { let utype = stream.readUint16(); let name = stream.readString(); let valname = stream.readString(); - let length : string; + let length: string; /* 有一些匿名类型,我们需要提供一个唯一名称放到datatypes中 如: @@ -2260,7 +2315,7 @@ namespace KBEngine { // 将用户自定义的类型补充到映射表中 datatype2id[valname] = utype; } - Client_onImportClientEntityDef (stream) { + Client_onImportClientEntityDef(stream) { app.createDataTypeFromStreams(stream, true); while (!stream.readEOF()) { @@ -2427,22 +2482,22 @@ namespace KBEngine { app.onImportEntityDefCompleted(); } - Client_onVersionNotMatch (stream) { + Client_onVersionNotMatch(stream) { app.serverVersion = stream.readString(); ERROR_MSG("Client_onVersionNotMatch: verInfo=" + app.clientVersion + " not match(server: " + app.serverVersion + ")"); Event.fire("onVersionNotMatch", app.clientVersion, app.serverVersion); } - Client_onScriptVersionNotMatch (stream) { + Client_onScriptVersionNotMatch(stream) { app.serverScriptVersion = stream.readString(); ERROR_MSG("Client_onScriptVersionNotMatch: verInfo=" + app.clientScriptVersion + " not match(server: " + app.serverScriptVersion + ")"); Event.fire("onScriptVersionNotMatch", app.clientScriptVersion, app.serverScriptVersion); } - onImportEntityDefCompleted () { + onImportEntityDefCompleted() { INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"); app.entitydefImported = true; app.login_baseapp(false); } - Client_onImportClientMessages (msg) { + Client_onImportClientMessages(msg) { let stream = new MemoryStream(msg.data); let msgid = stream.readUint16(); @@ -2497,7 +2552,7 @@ namespace KBEngine { else ERROR_MSG("KBEngineApp::onmessage: not found msg(" + msgid + ")!"); } - createAccount (username, password, datas) { + createAccount(username, password, datas) { app.reset(); app.username = username; app.password = password; @@ -2505,10 +2560,10 @@ namespace KBEngine { app.createAccount_loginapp(true); } - createAccount_loginapp (noconnect) { + createAccount_loginapp(noconnect) { if (noconnect) { INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + app.args.ip + ":" + app.args.port + "!"); - app.connect(app.args.protocol + app.args.ip + ":" + app.args.port); + app.connect(app.args.ip, app.args.port); app.socket.onopen = app.onOpenLoginapp_createAccount; } else { @@ -2520,7 +2575,7 @@ namespace KBEngine { bundle.send(app); } } - bindAccountEmail (emailAddress) { + bindAccountEmail(emailAddress) { let bundle = new Bundle(); bundle.newMessage(messages['Baseapp_reqAccountBindEmail']); bundle.writeInt32(app.entity_id); @@ -2528,7 +2583,7 @@ namespace KBEngine { bundle.writeString(emailAddress); bundle.send(app); } - newPassword (old_password, new_password) { + newPassword(old_password, new_password) { let bundle = new Bundle(); bundle.newMessage(messages['Baseapp_reqAccountNewPassword']); bundle.writeInt32(app.entity_id); @@ -2536,7 +2591,7 @@ namespace KBEngine { bundle.writeString(new_password); bundle.send(app); } - login (username, password, datas) { + login(username, password, datas) { app.reset(); app.username = username; app.password = password; @@ -2544,10 +2599,10 @@ namespace KBEngine { app.login_loginapp(true); } - login_loginapp (noconnect) { + login_loginapp(noconnect) { if (noconnect) { INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://" + app.args.ip + ":" + app.args.port + "!"); - app.connect(app.args.protocol + app.args.ip + ":" + app.args.port); + app.connect(app.args.ip, app.args.port); app.socket.onopen = app.onOpenLoginapp_login; } else { @@ -2560,7 +2615,7 @@ namespace KBEngine { bundle.send(app); } } - onOpenLoginapp_resetpassword () { + onOpenLoginapp_resetpassword() { INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"); app.currserver = "loginapp"; app.currstate = "resetpassword"; @@ -2576,15 +2631,15 @@ namespace KBEngine { app.onImportClientMessagesCompleted(); } } - reset_password (username) { + reset_password(username) { app.reset(); app.username = username; app.resetpassword_loginapp(true); } - resetpassword_loginapp (noconnect) { + resetpassword_loginapp(noconnect) { if (noconnect) { INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + app.args.ip + ":" + app.args.port + "!"); - app.connect(app.args.protocol + app.args.ip + ":" + app.args.port); + app.connect(app.args.ip, app.args.port); app.socket.onopen = app.onOpenLoginapp_resetpassword; } else { @@ -2594,7 +2649,7 @@ namespace KBEngine { bundle.send(app); } } - onOpenBaseapp () { + onOpenBaseapp() { INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"); app.currserver = "baseapp"; @@ -2609,11 +2664,11 @@ namespace KBEngine { app.onImportClientMessagesCompleted(); } } - login_baseapp (noconnect) { + login_baseapp(noconnect) { if (noconnect) { Event.fire("onLoginBaseapp"); INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://" + app.baseappIp + ":" + app.baseappPort + "!"); - app.connect(app.args.protocol + app.baseappIp + ":" + app.baseappPort); + app.connect(app.baseappIp, app.baseappPort); if (app.socket != undefined && app.socket != null) app.socket.onopen = app.onOpenBaseapp; @@ -2626,19 +2681,19 @@ namespace KBEngine { bundle.send(app); } } - reloginBaseapp () { + reloginBaseapp() { if (app.socket != undefined && app.socket != null) return; app.resetSocket(); Event.fire("onReloginBaseapp"); INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://" + app.baseappIp + ":" + app.baseappPort + "!"); - app.connect(app.args.protocol + app.baseappIp + ":" + app.baseappPort); + app.connect(app.baseappIp, app.baseappPort); if (app.socket != undefined && app.socket != null) app.socket.onopen = app.onReOpenBaseapp; } - onReOpenBaseapp () { + onReOpenBaseapp() { INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"); app.currserver = "baseapp"; @@ -2653,7 +2708,7 @@ namespace KBEngine { let dateObject = new Date(); app.lastTickCBTime = dateObject.getTime(); } - Client_onHelloCB (args) { + Client_onHelloCB(args) { app.serverVersion = args.readString(); app.serverScriptVersion = args.readString(); app.serverProtocolMD5 = args.readString(); @@ -2668,13 +2723,13 @@ namespace KBEngine { let dateObject = new Date(); app.lastTickCBTime = dateObject.getTime(); } - Client_onLoginFailed (args) { + Client_onLoginFailed(args) { let failedcode = args.readUint16(); app.serverdatas = args.readBlob(); ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode(" + app.serverErrs[failedcode].name + "), datas(" + app.serverdatas.length + ")!"); Event.fire("onLoginFailed", failedcode); } - Client_onLoginSuccessfully (args) { + Client_onLoginSuccessfully(args) { let accountName = args.readString(); app.username = accountName; app.baseappIp = args.readString(); @@ -2687,21 +2742,21 @@ namespace KBEngine { app.disconnect(); app.login_baseapp(true); } - Client_onLoginBaseappFailed (failedcode) { + Client_onLoginBaseappFailed(failedcode) { ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode(" + app.serverErrs[failedcode].name + ")!"); Event.fire("onLoginBaseappFailed", failedcode); } - Client_onReloginBaseappFailed (failedcode) { + Client_onReloginBaseappFailed(failedcode) { ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode(" + app.serverErrs[failedcode].name + ")!"); Event.fire("onReloginBaseappFailed", failedcode); } - Client_onReloginBaseappSuccessfully (stream) { + Client_onReloginBaseappSuccessfully(stream) { app.entity_uuid = stream.readUint64(); DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: " + app.username); Event.fire("onReloginBaseappSuccessfully"); } entityclass = {}; - getentityclass (entityType) { + getentityclass(entityType) { let runclass = KBEngine['Entities'][entityType]; if (runclass == undefined) { ERROR_MSG("KBEngineApp::getentityclass: entityType(" + entityType + ") is error!"); @@ -2710,7 +2765,7 @@ namespace KBEngine { return runclass; } - Client_onCreatedProxies (rndUUID, eid, entityType) { + Client_onCreatedProxies(rndUUID, eid, entityType) { INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid(" + eid + "), entityType(" + entityType + ")!"); let entity = app.entities[eid]; @@ -2754,7 +2809,7 @@ namespace KBEngine { } } } - getViewEntityIDFromStream (stream) { + getViewEntityIDFromStream(stream) { let id = 0; if (app.entityIDAliasIDList.length > 255) { id = stream.readInt32(); @@ -2773,7 +2828,7 @@ namespace KBEngine { return id; } - onUpdatePropertys_ (eid, stream) { + onUpdatePropertys_(eid, stream) { let entity = app.entities[eid]; if (entity == undefined) { @@ -2821,15 +2876,15 @@ namespace KBEngine { } } } - Client_onUpdatePropertysOptimized (stream) { + Client_onUpdatePropertysOptimized(stream) { let eid = app.getViewEntityIDFromStream(stream); app.onUpdatePropertys_(eid, stream); } - Client_onUpdatePropertys (stream) { + Client_onUpdatePropertys(stream) { let eid = stream.readInt32(); app.onUpdatePropertys_(eid, stream); } - onRemoteMethodCall_ (eid, stream) { + onRemoteMethodCall_(eid, stream) { let entity = app.entities[eid]; if (entity == undefined) { @@ -2857,15 +2912,15 @@ namespace KBEngine { ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found method(" + methoddata[2] + ")!"); } } - Client_onRemoteMethodCallOptimized (stream) { + Client_onRemoteMethodCallOptimized(stream) { let eid = app.getViewEntityIDFromStream(stream); app.onRemoteMethodCall_(eid, stream); } - Client_onRemoteMethodCall (stream) { + Client_onRemoteMethodCall(stream) { let eid = stream.readInt32(); app.onRemoteMethodCall_(eid, stream); } - Client_onEntityEnterWorld (stream) { + Client_onEntityEnterWorld(stream) { let eid = stream.readInt32(); if (app.entity_id > 0 && eid != app.entity_id) app.entityIDAliasIDList.push(eid) @@ -2911,7 +2966,7 @@ namespace KBEngine { delete bufferedCreateEntityMessage[eid]; // entity.isOnGround = isOnGround > 0; - entity.isOnGround = isOnGround ; + entity.isOnGround = isOnGround; entity.__init__(); entity.inited = true; entity.inWorld = true; @@ -2944,7 +2999,7 @@ namespace KBEngine { app.entityServerPos.y = entity.position.y; app.entityServerPos.z = entity.position.z; - entity.isOnGround = isOnGround ; + entity.isOnGround = isOnGround; // entity.isOnGround = isOnGround > 0; entity.inWorld = true; @@ -2955,11 +3010,11 @@ namespace KBEngine { } } } - Client_onEntityLeaveWorldOptimized (stream) { + Client_onEntityLeaveWorldOptimized(stream) { let eid = app.getViewEntityIDFromStream(stream); app.Client_onEntityLeaveWorld(eid); } - Client_onEntityLeaveWorld (eid) { + Client_onEntityLeaveWorld(eid) { let entity = app.entities[eid]; if (entity == undefined) { ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity(" + eid + ") not found!"); @@ -2999,7 +3054,7 @@ namespace KBEngine { entity.cell = null; } } - Client_onEntityDestroyed (eid) { + Client_onEntityDestroyed(eid) { INFO_MSG("KBEngineApp::Client_onEntityDestroyed: entity(" + eid + ")!"); let entity = app.entities[eid]; @@ -3017,7 +3072,7 @@ namespace KBEngine { delete app.entities[eid]; } - Client_onEntityEnterSpace (stream) { + Client_onEntityEnterSpace(stream) { let eid = stream.readInt32(); app.spaceID = stream.readUint32(); let isOnGround = true; @@ -3037,7 +3092,7 @@ namespace KBEngine { app.entityServerPos.z = entity.position.z; entity.enterSpace(); } - Client_onEntityLeaveSpace (eid) { + Client_onEntityLeaveSpace(eid) { let entity = app.entities[eid]; if (entity == undefined) { ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity(" + eid + ") not found!"); @@ -3047,11 +3102,11 @@ namespace KBEngine { app.clearSpace(false); entity.leaveSpace(); } - Client_onKicked (failedcode) { + Client_onKicked(failedcode) { ERROR_MSG("KBEngineApp::Client_onKicked: failedcode(" + app.serverErrs[failedcode].name + ")!"); Event.fire("onKicked", failedcode); } - Client_onCreateAccountResult (stream) { + Client_onCreateAccountResult(stream) { let retcode = stream.readUint16(); let datas = stream.readBlob(); @@ -3064,7 +3119,7 @@ namespace KBEngine { INFO_MSG("KBEngineApp::Client_onCreateAccountResult: " + app.username + " create is successfully!"); } - Client_onControlEntity (eid, isControlled) { + Client_onControlEntity(eid, isControlled) { // eid = stream.readInt32(); let entity = app.entities[eid]; if (entity == undefined) { @@ -3100,7 +3155,7 @@ namespace KBEngine { ERROR_MSG("KBEngine::Client_onControlEntity: entity id = '" + eid + "', is controlled = '" + isCont + "', error = '" + e + "'"); } } - updatePlayerToServer () { + updatePlayerToServer() { let player = app.player(); if (player == undefined || player.inWorld == false || app.spaceID == 0 || player.isControlled) return; @@ -3133,7 +3188,7 @@ namespace KBEngine { let position = entity.position; let direction = entity.direction; - let posHasChanged = entity.entityLastLocalPos.distance(position) > 0.001; + let posHasChanged = entity.entityLastLocalPos.distance(position) > 0.001; let dirHasChanged = entity.entityLastLocalDir.distance(direction) > 0.001; if (posHasChanged || dirHasChanged) { @@ -3156,21 +3211,21 @@ namespace KBEngine { } } } - addSpaceGeometryMapping (spaceID, respath) { + addSpaceGeometryMapping(spaceID, respath) { INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID(" + spaceID + "), respath(" + respath + ")!"); app.spaceID = spaceID; app.spaceResPath = respath; Event.fire("addSpaceGeometryMapping", respath); } - clearSpace (isAll) { + clearSpace(isAll) { app.entityIDAliasIDList = []; app.spacedata = {}; app.clearEntities(isAll); app.isLoadedGeometry = false; app.spaceID = 0; } - clearEntities (isAll) { + clearEntities(isAll) { app.controlledEntities = [] if (!isAll) { @@ -3202,7 +3257,7 @@ namespace KBEngine { app.entities = {} } } - Client_initSpaceData (stream) { + Client_initSpaceData(stream) { app.clearSpace(false); app.spaceID = stream.readInt32(); @@ -3214,7 +3269,7 @@ namespace KBEngine { INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID(" + app.spaceID + "), datas(" + app.spacedata + ")!"); } - Client_setSpaceData (spaceID, key, value) { + Client_setSpaceData(spaceID, key, value) { INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID(" + spaceID + "), key(" + key + "), value(" + value + ")!"); app.spacedata[key] = value; @@ -3224,25 +3279,25 @@ namespace KBEngine { Event.fire("onSetSpaceData", spaceID, key, value); } - Client_delSpaceData (spaceID, key) { + Client_delSpaceData(spaceID, key) { INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID(" + spaceID + "), key(" + key + ")!"); delete app.spacedata[key]; Event.fire("onDelSpaceData", spaceID, key); } - Client_getSpaceData (spaceID, key) { + Client_getSpaceData(spaceID, key) { return app.spacedata[key]; } - Client_onUpdateBasePos (x, y, z) { + Client_onUpdateBasePos(x, y, z) { app.entityServerPos.x = x; app.entityServerPos.y = y; app.entityServerPos.z = z; } - Client_onUpdateBasePosXZ (x, z) { + Client_onUpdateBasePosXZ(x, z) { app.entityServerPos.x = x; app.entityServerPos.z = z; } - Client_onUpdateData (stream) { + Client_onUpdateData(stream) { let eid = app.getViewEntityIDFromStream(stream); let entity = app.entities[eid]; if (entity == undefined) { @@ -3250,7 +3305,7 @@ namespace KBEngine { return; } } - Client_onSetEntityPosAndDir (stream) { + Client_onSetEntityPosAndDir(stream) { let eid = stream.readInt32(); let entity = app.entities[eid]; if (entity == undefined) { @@ -3276,7 +3331,7 @@ namespace KBEngine { entity.set_direction(entity.direction); entity.set_position(entity.position); } - Client_onUpdateData_ypr (stream) { + Client_onUpdateData_ypr(stream) { let eid = app.getViewEntityIDFromStream(stream); let y = stream.readInt8(); @@ -3285,7 +3340,7 @@ namespace KBEngine { app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, p, r, -1); } - Client_onUpdateData_yp (stream) { + Client_onUpdateData_yp(stream) { let eid = app.getViewEntityIDFromStream(stream); let y = stream.readInt8(); @@ -3293,7 +3348,7 @@ namespace KBEngine { app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, p, KBE_FLT_MAX, -1); } - Client_onUpdateData_yr (stream) { + Client_onUpdateData_yr(stream) { let eid = app.getViewEntityIDFromStream(stream); let y = stream.readInt8(); @@ -3301,7 +3356,7 @@ namespace KBEngine { app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, KBE_FLT_MAX, r, -1); } - Client_onUpdateData_pr (stream) { + Client_onUpdateData_pr(stream) { let eid = app.getViewEntityIDFromStream(stream); let p = stream.readInt8(); @@ -3309,35 +3364,35 @@ namespace KBEngine { app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, p, r, -1); } - Client_onUpdateData_y (stream) { + Client_onUpdateData_y(stream) { let eid = app.getViewEntityIDFromStream(stream); let y = stream.readInt8(); app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, KBE_FLT_MAX, KBE_FLT_MAX, -1); } - Client_onUpdateData_p (stream) { + Client_onUpdateData_p(stream) { let eid = app.getViewEntityIDFromStream(stream); let p = stream.readInt8(); app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, p, KBE_FLT_MAX, -1); } - Client_onUpdateData_r (stream) { + Client_onUpdateData_r(stream) { let eid = app.getViewEntityIDFromStream(stream); let r = stream.readInt8(); app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, r, -1); } - Client_onUpdateData_xz (stream) { + Client_onUpdateData_xz(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, 1); } - Client_onUpdateData_xz_ypr (stream) { + Client_onUpdateData_xz_ypr(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3348,7 +3403,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, p, r, 1); } - Client_onUpdateData_xz_yp (stream) { + Client_onUpdateData_xz_yp(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3358,7 +3413,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, p, KBE_FLT_MAX, 1); } - Client_onUpdateData_xz_yr (stream) { + Client_onUpdateData_xz_yr(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3368,7 +3423,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, KBE_FLT_MAX, r, 1); } - Client_onUpdateData_xz_pr (stream) { + Client_onUpdateData_xz_pr(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3378,7 +3433,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, p, r, 1); } - Client_onUpdateData_xz_y (stream) { + Client_onUpdateData_xz_y(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3387,7 +3442,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, KBE_FLT_MAX, KBE_FLT_MAX, 1); } - Client_onUpdateData_xz_p (stream) { + Client_onUpdateData_xz_p(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3396,7 +3451,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, p, KBE_FLT_MAX, 1); } - Client_onUpdateData_xz_r (stream) { + Client_onUpdateData_xz_r(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3405,7 +3460,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, r, 1); } - Client_onUpdateData_xyz (stream) { + Client_onUpdateData_xyz(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3413,7 +3468,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], y, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, 0); } - Client_onUpdateData_xyz_ypr (stream) { + Client_onUpdateData_xyz_ypr(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3425,7 +3480,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, r, 0); } - Client_onUpdateData_xyz_yp (stream) { + Client_onUpdateData_xyz_yp(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3436,7 +3491,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, KBE_FLT_MAX, 0); } - Client_onUpdateData_xyz_yr (stream) { + Client_onUpdateData_xyz_yr(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3447,7 +3502,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBE_FLT_MAX, r, 0); } - Client_onUpdateData_xyz_pr (stream) { + Client_onUpdateData_xyz_pr(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3460,7 +3515,7 @@ namespace KBEngine { //todo 这个是手动注释,如果错误再修改 // app._updateVolatileData(eid, x, y, z, KBE_FLT_MAX, p, r, 0); } - Client_onUpdateData_xyz_y (stream) { + Client_onUpdateData_xyz_y(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3470,7 +3525,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBE_FLT_MAX, KBE_FLT_MAX, 0); } - Client_onUpdateData_xyz_p (stream) { + Client_onUpdateData_xyz_p(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3480,7 +3535,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], y, xz[1], KBE_FLT_MAX, p, KBE_FLT_MAX, 0); } - Client_onUpdateData_xyz_r (stream) { + Client_onUpdateData_xyz_r(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3492,7 +3547,7 @@ namespace KBEngine { app._updateVolatileData(eid, xz[0], y, xz[1], r, KBE_FLT_MAX, KBE_FLT_MAX, 0); } - _updateVolatileData (entityID, x, y, z, yaw, pitch, roll, isOnGround) { + _updateVolatileData(entityID, x, y, z, yaw, pitch, roll, isOnGround) { let entity = app.entities[entityID]; if (entity == undefined) { // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 @@ -3550,18 +3605,18 @@ namespace KBEngine { if (done) entity.onUpdateVolatileData(); } - Client_onStreamDataStarted (id, datasize, descr) { + Client_onStreamDataStarted(id, datasize, descr) { Event.fire("onStreamDataStarted", id, datasize, descr); } - Client_onStreamDataRecv (stream) { + Client_onStreamDataRecv(stream) { let id = stream.readUint16(); let data = stream.readBlob(); Event.fire("onStreamDataRecv", id, data); } - Client_onStreamDataCompleted (id) { + Client_onStreamDataCompleted(id) { Event.fire("onStreamDataCompleted", id); } - Client_onReqAccountResetPasswordCB (failedcode) { + Client_onReqAccountResetPasswordCB(failedcode) { if (failedcode != 0) { ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: " + app.username + " is failed! code=" + app.serverErrs[failedcode].name + "!"); return; @@ -3569,7 +3624,7 @@ namespace KBEngine { INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: " + app.username + " is successfully!"); } - Client_onReqAccountBindEmailCB (failedcode) { + Client_onReqAccountBindEmailCB(failedcode) { if (failedcode != 0) { ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: " + app.username + " is failed! code=" + app.serverErrs[failedcode].name + "!"); return; @@ -3577,7 +3632,7 @@ namespace KBEngine { INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: " + app.username + " is successfully!"); } - Client_onReqAccountNewPasswordCB (failedcode) { + Client_onReqAccountNewPasswordCB(failedcode) { if (failedcode != 0) { ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: " + app.username + " is failed! code=" + app.serverErrs[failedcode].name + "!"); return; diff --git a/kbengine_ts/tsconfig.json b/kbengine_ts/tsconfig.json index cc5f009..51cd203 100644 --- a/kbengine_ts/tsconfig.json +++ b/kbengine_ts/tsconfig.json @@ -7,6 +7,7 @@ "outFile": "bin/kbengine.js" }, "include": [ + "libs", "src" ] } \ No newline at end of file From 311df042b11086e56d80ba5a11e8e710f3a5ac37 Mon Sep 17 00:00:00 2001 From: zengmn <761458545@qq.com> Date: Sat, 28 Apr 2018 11:42:52 +0800 Subject: [PATCH 06/17] =?UTF-8?q?log=E5=A4=9A=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kbengine_ts/bin/kbengine.d.ts | 11 ++++++----- kbengine_ts/bin/kbengine.js | 34 ++++++++++++++++++++++++--------- kbengine_ts/bin/kbengine.min.js | 6 +++--- kbengine_ts/src/KBEngine.ts | 16 ++++++++-------- 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index 5328410..06ac7c1 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -9,8 +9,9 @@ * * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 window['KBEngine'] = window['KBEngine'] || {};window['KBEngine']['你的实体类名']=你的实体类名 + * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 window['KBEngine'] = window['KBEngine'] || {};window['KBEngine']['你的实体类名']=你的实体类名;将声明提升至全局 * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; + * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ declare namespace KBEngine { const PACKET_MAX_SIZE = 1500; @@ -38,10 +39,10 @@ declare namespace KBEngine { } declare namespace KBEngine { /** todo 调试输出模块,这里需要根据使用的引擎不同在这里加入判断条件 */ - function INFO_MSG(s: any): void; - function DEBUG_MSG(s: any): void; - function ERROR_MSG(s: any): void; - function WARNING_MSG(s: any): void; + function INFO_MSG(...args: any[]): void; + function DEBUG_MSG(...args: any[]): void; + function ERROR_MSG(...args: any[]): void; + function WARNING_MSG(...args: any[]): void; } declare namespace KBEngine { function utf8ArrayToString(array: Array): any; diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index 7d17a7c..fd97e74 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -19,7 +19,7 @@ r.prototype = e.prototype, t.prototype = new r(); * * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 window['KBEngine'] = window['KBEngine'] || {};window['KBEngine']['你的实体类名']=你的实体类名 + * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 window['KBEngine'] = window['KBEngine'] || {};window['KBEngine']['你的实体类名']=你的实体类名;将声明提升至全局 * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ @@ -109,20 +109,36 @@ window['KBEngine'] = KBEngine; -----------------------------------------------------------------------------------------*/ (function (KBEngine) { /** todo 调试输出模块,这里需要根据使用的引擎不同在这里加入判断条件 */ - function INFO_MSG(s) { - console.info(s); + function INFO_MSG() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + console.info.apply(console, args); } KBEngine.INFO_MSG = INFO_MSG; - function DEBUG_MSG(s) { - console.debug(s); + function DEBUG_MSG() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + console.debug.apply(console, args); } KBEngine.DEBUG_MSG = DEBUG_MSG; - function ERROR_MSG(s) { - console.error(s); + function ERROR_MSG() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + console.error.apply(console, args); } KBEngine.ERROR_MSG = ERROR_MSG; - function WARNING_MSG(s) { - console.warn(s); + function WARNING_MSG() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + console.warn.apply(console, args); } KBEngine.WARNING_MSG = WARNING_MSG; })(KBEngine || (KBEngine = {})); diff --git a/kbengine_ts/bin/kbengine.min.js b/kbengine_ts/bin/kbengine.min.js index 7888bbd..71f8860 100644 --- a/kbengine_ts/bin/kbengine.min.js +++ b/kbengine_ts/bin/kbengine.min.js @@ -1,3 +1,3 @@ -var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(e){console.info(e)}function n(e){console.debug(e)}function r(e){console.error(e)}function a(e){console.warn(e)}e.INFO_MSG=t,e.DEBUG_MSG=n,e.ERROR_MSG=r,e.WARNING_MSG=a}(KBEngine||(KBEngine={})),function(e){function t(e){var t,n,r,a,i,o;for(t="",r=e.length,n=0;r>n;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t){this.x=e,this.y=t}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y;return Math.sqrt(t*t+n*n)},e}();e.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function e(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(t){for(var n=[],r=1;re||e>255?!1:!0},t}();e.DATATYPE_UINT8=n,__reflect(n.prototype,"KBEngine.DATATYPE_UINT8");var r=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint16.call(t)},t.prototype.addToStream=function(e,t){e.writeUint16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},t}();e.DATATYPE_UINT16=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT16");var a=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint32.call(t)},t.prototype.addToStream=function(e,t){e.writeUint32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},t}();e.DATATYPE_UINT32=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT32");var i=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint64.call(t)},t.prototype.addToStream=function(e,t){e.writeUint64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.UINT64},t}();e.DATATYPE_UINT64=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT64");var o=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt8.call(t)},t.prototype.addToStream=function(e,t){e.writeInt8(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},t}();e.DATATYPE_INT8=o,__reflect(o.prototype,"KBEngine.DATATYPE_INT8");var p=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt16.call(t)},t.prototype.addToStream=function(e,t){e.writeInt16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},t}();e.DATATYPE_INT16=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT16");var s=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt32.call(t)},t.prototype.addToStream=function(e,t){e.writeInt32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},t}();e.DATATYPE_INT32=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT32");var l=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt64.call(t)},t.prototype.addToStream=function(e,t){e.writeInt64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.INT64},t}();e.DATATYPE_INT64=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT64");var c=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readFloat.call(t)},t.prototype.addToStream=function(e,t){e.writeFloat(t)},t.prototype.parseDefaultValStr=function(e){return parseFloat(e)},t.prototype.isSameType=function(e){return"number"==typeof e},t}();e.DATATYPE_FLOAT=c,__reflect(c.prototype,"KBEngine.DATATYPE_FLOAT");var d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),n.prototype.createFromStream=function(t){return e.reader.readDouble.call(t)},n.prototype.addToStream=function(e,t){e.writeDouble(t)},n}(c);e.DATATYPE_DOUBLE=d,__reflect(d.prototype,"KBEngine.DATATYPE_DOUBLE");var u=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readString.call(t)},t.prototype.addToStream=function(e,t){e.writeString(t)},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_STRING=u,__reflect(u.prototype,"KBEngine.DATATYPE_STRING");var y=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector2(e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector2(e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y)):(t.writeFloat(n.x),t.writeFloat(n.y))},t.prototype.parseDefaultValStr=function(t){return new e.Vector2(0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector2?!0:!1},t}();e.DATATYPE_VECTOR2=y,__reflect(y.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector3(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector3(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z))},t.prototype.parseDefaultValStr=function(t){return new e.Vector3(0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector3?!0:!1},t}();e.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var _=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector4(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readFloat.call(t)):new e.Vector4(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z),t.writeInt32(n.w)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z),t.writeFloat(n.w))},t.prototype.parseDefaultValStr=function(t){return new e.Vector4(0,0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector4?!0:!1},t}();e.DATATYPE_VECTOR4=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR4");var E=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_PYTHON=E,__reflect(E.prototype,"KBEngine.DATATYPE_PYTHON");var g=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.utf8ArrayToString(e.reader.readBlob.call(t))},t.prototype.addToStream=function(t,n){t.writeBlob(e.stringToUTF8Bytes(n))},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_UNICODE=g,__reflect(g.prototype,"KBEngine.DATATYPE_UNICODE");var h=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_ENTITYCALL=h,__reflect(h.prototype,"KBEngine.DATATYPE_ENTITYCALL");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){var n=e.reader.readUint32.call(t),r=new Uint8Array(t.buffer,t.rpos,n);return t.rpos+=n,r},t.prototype.addToStream=function(e,t){e.writeBlob(t)},t.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},t.prototype.isSameType=function(e){return!0},t}();e.DATATYPE_BLOB=m,__reflect(m.prototype,"KBEngine.DATATYPE_BLOB");var v=function(){function e(){this.type=null}return e.prototype.bind=function(){"number"==typeof this.type&&(this.type=T[this.type])},e.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},e.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods;try{var y=e.Entities[n]}catch(f){}for(;a>0;){a--;var _=t.readUint16(),E=t.readUint32(),g=t.readInt16(),h=t.readString(),m=t.readString(),v=e.datatypes[t.readUint16()],S=null;void 0!=y&&(S=y.prototype["set_"+h],void 0==S&&(S=null));var T=[_,g,h,m,v,S,E];l[h]=T,-1!=g?(l[g]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+h+"/"+_+").")}for(;i>0;){i--;for(var I=t.readUint16(),g=t.readInt16(),w=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);var T=[I,g,w,C];c[w]=T,-1!=g?(c[g]=T,s.useMethodDescrAlias=!0):(c[I]=T,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+w+").")}for(;o>0;){o--;for(var I=t.readUint16(),g=t.readInt16(),B=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);d[B]=[I,g,B,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+B+").")}for(;p>0;){p--;for(var I=t.readUint16(),g=t.readInt16(),D=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);u[D]=[I,g,D,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+D+").")}var M=void 0;try{M=e.Entities[n]}catch(f){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),M=void 0}for(var L in s.propertys){var F=s.propertys[L],_=F[0],g=F[1],R=F[2],m=F[3],v=F[4];void 0!=M&&(M.prototype[R]=v.parseDefaultValStr(m))}for(var K in s.methods){var F=s.methods[K],_=F[0],g=F[1],R=F[2],C=F[3];void 0!=M&&void 0==M.prototype[R]&&e.WARNING_MSG(n+":: method("+R+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,u=o.indexOf("Client_")>=0;u&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),u?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=e.Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessage[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessage[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],u=l[4].createFromStream(n),y=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+u+")!"),r[l[2]]=u,null!=c&&(32==d||64==d?r.inited&&c.call(r,y):r.inWorld&&c.call(r,y))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessage[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessage[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0)},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(); -e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var u=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(u=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),u&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file +var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(){for(var e=[],t=0;tn;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t){this.x=e,this.y=t}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y;return Math.sqrt(t*t+n*n)},e}();e.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function e(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(t){for(var n=[],r=1;re||e>255?!1:!0},t}();e.DATATYPE_UINT8=n,__reflect(n.prototype,"KBEngine.DATATYPE_UINT8");var r=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint16.call(t)},t.prototype.addToStream=function(e,t){e.writeUint16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},t}();e.DATATYPE_UINT16=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT16");var a=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint32.call(t)},t.prototype.addToStream=function(e,t){e.writeUint32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},t}();e.DATATYPE_UINT32=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT32");var i=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint64.call(t)},t.prototype.addToStream=function(e,t){e.writeUint64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.UINT64},t}();e.DATATYPE_UINT64=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT64");var o=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt8.call(t)},t.prototype.addToStream=function(e,t){e.writeInt8(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},t}();e.DATATYPE_INT8=o,__reflect(o.prototype,"KBEngine.DATATYPE_INT8");var p=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt16.call(t)},t.prototype.addToStream=function(e,t){e.writeInt16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},t}();e.DATATYPE_INT16=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT16");var s=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt32.call(t)},t.prototype.addToStream=function(e,t){e.writeInt32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},t}();e.DATATYPE_INT32=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT32");var l=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt64.call(t)},t.prototype.addToStream=function(e,t){e.writeInt64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.INT64},t}();e.DATATYPE_INT64=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT64");var c=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readFloat.call(t)},t.prototype.addToStream=function(e,t){e.writeFloat(t)},t.prototype.parseDefaultValStr=function(e){return parseFloat(e)},t.prototype.isSameType=function(e){return"number"==typeof e},t}();e.DATATYPE_FLOAT=c,__reflect(c.prototype,"KBEngine.DATATYPE_FLOAT");var d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),n.prototype.createFromStream=function(t){return e.reader.readDouble.call(t)},n.prototype.addToStream=function(e,t){e.writeDouble(t)},n}(c);e.DATATYPE_DOUBLE=d,__reflect(d.prototype,"KBEngine.DATATYPE_DOUBLE");var u=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readString.call(t)},t.prototype.addToStream=function(e,t){e.writeString(t)},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_STRING=u,__reflect(u.prototype,"KBEngine.DATATYPE_STRING");var y=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector2(e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector2(e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y)):(t.writeFloat(n.x),t.writeFloat(n.y))},t.prototype.parseDefaultValStr=function(t){return new e.Vector2(0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector2?!0:!1},t}();e.DATATYPE_VECTOR2=y,__reflect(y.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector3(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector3(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z))},t.prototype.parseDefaultValStr=function(t){return new e.Vector3(0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector3?!0:!1},t}();e.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var _=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector4(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readFloat.call(t)):new e.Vector4(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z),t.writeInt32(n.w)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z),t.writeFloat(n.w))},t.prototype.parseDefaultValStr=function(t){return new e.Vector4(0,0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector4?!0:!1},t}();e.DATATYPE_VECTOR4=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR4");var g=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_PYTHON=g,__reflect(g.prototype,"KBEngine.DATATYPE_PYTHON");var E=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.utf8ArrayToString(e.reader.readBlob.call(t))},t.prototype.addToStream=function(t,n){t.writeBlob(e.stringToUTF8Bytes(n))},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_UNICODE=E,__reflect(E.prototype,"KBEngine.DATATYPE_UNICODE");var h=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_ENTITYCALL=h,__reflect(h.prototype,"KBEngine.DATATYPE_ENTITYCALL");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){var n=e.reader.readUint32.call(t),r=new Uint8Array(t.buffer,t.rpos,n);return t.rpos+=n,r},t.prototype.addToStream=function(e,t){e.writeBlob(t)},t.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},t.prototype.isSameType=function(e){return!0},t}();e.DATATYPE_BLOB=m,__reflect(m.prototype,"KBEngine.DATATYPE_BLOB");var v=function(){function e(){this.type=null}return e.prototype.bind=function(){"number"==typeof this.type&&(this.type=T[this.type])},e.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},e.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods;try{var y=e.Entities[n]}catch(f){}for(;a>0;){a--;var _=t.readUint16(),g=t.readUint32(),E=t.readInt16(),h=t.readString(),m=t.readString(),v=e.datatypes[t.readUint16()],S=null;void 0!=y&&(S=y.prototype["set_"+h],void 0==S&&(S=null));var T=[_,E,h,m,v,S,g];l[h]=T,-1!=E?(l[E]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+h+"/"+_+").")}for(;i>0;){i--;for(var I=t.readUint16(),E=t.readInt16(),w=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);var T=[I,E,w,C];c[w]=T,-1!=E?(c[E]=T,s.useMethodDescrAlias=!0):(c[I]=T,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+w+").")}for(;o>0;){o--;for(var I=t.readUint16(),E=t.readInt16(),B=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);d[B]=[I,E,B,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+B+").")}for(;p>0;){p--;for(var I=t.readUint16(),E=t.readInt16(),D=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);u[D]=[I,E,D,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+D+").")}var M=void 0;try{M=e.Entities[n]}catch(f){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),M=void 0}for(var L in s.propertys){var F=s.propertys[L],_=F[0],E=F[1],R=F[2],m=F[3],v=F[4];void 0!=M&&(M.prototype[R]=v.parseDefaultValStr(m))}for(var K in s.methods){var F=s.methods[K],_=F[0],E=F[1],R=F[2],C=F[3];void 0!=M&&void 0==M.prototype[R]&&e.WARNING_MSG(n+":: method("+R+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,u=o.indexOf("Client_")>=0;u&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),u?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=e.Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessage[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessage[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],u=l[4].createFromStream(n),y=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+u+")!"),r[l[2]]=u,null!=c&&(32==d||64==d?r.inited&&c.call(r,y):r.inWorld&&c.call(r,y))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessage[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessage[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8(); +e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0)},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var u=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(u=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),u&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index f0477f4..fe2a6f8 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -105,17 +105,17 @@ namespace KBEngine { -----------------------------------------------------------------------------------------*/ namespace KBEngine { /** todo 调试输出模块,这里需要根据使用的引擎不同在这里加入判断条件 */ - export function INFO_MSG(s) { - console.info(s); + export function INFO_MSG(...args:any[]) { + console.info.apply(console,args); } - export function DEBUG_MSG(s) { - console.debug(s); + export function DEBUG_MSG(...args:any[]) { + console.debug.apply(console,args); } - export function ERROR_MSG(s) { - console.error(s); + export function ERROR_MSG(...args:any[]) { + console.error.apply(console,args); } - export function WARNING_MSG(s) { - console.warn(s); + export function WARNING_MSG(...args:any[]) { + console.warn.apply(console,args); } } /*----------------------------------------------------------------------------------------- From f1ba96157ef1055c12e7c050f7d73e13c9932acf Mon Sep 17 00:00:00 2001 From: zengmn <761458545@qq.com> Date: Thu, 3 May 2018 14:24:28 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kbengine_ts/src/KBEngine.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index fe2a6f8..23e37a2 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -9,7 +9,7 @@ * * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 window['KBEngine'] = window['KBEngine'] || {};window['KBEngine']['你的实体类名']=你的实体类名;将声明提升至全局 + * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 KBEngine['Entities'] = KBEngine['Entities'] || {};KBEngine['Entities']['你的实体类名']=你的实体类名;将声明提升至全局 * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ @@ -918,7 +918,7 @@ namespace KBEngine { export const onImportClientMessages = new Message(518, "onImportClientMessages", -1, -1, new Array(), null); } export let clientmessages = {}; - export let bufferedCreateEntityMessage = {}; + export let bufferedCreateEntityMessages = {}; } /*----------------------------------------------------------------------------------------- math @@ -1857,8 +1857,9 @@ namespace KBEngine { port = 20013; updateHZ = 100; serverHeartbeatTick = 15; - // + //todo wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 protocol: string = "ws://"; + forceBasePort:number = 0; // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types clientType = 5; @@ -1891,7 +1892,8 @@ namespace KBEngine { baseappMessageImported = false; serverErrorsDescrImported = false; entitydefImported = false; - + // 这个参数的选择必须与kbengine_defs.xml::cellapp/aliasEntityID的参数保持一致 + useAliasEntityID = true; serverErrs: { [err: string]: ServerErr } = {}; // // 登录loginapp的地址 @@ -2789,10 +2791,10 @@ namespace KBEngine { app.entities[eid] = entity; - let entityMessage = bufferedCreateEntityMessage[eid]; + let entityMessage = bufferedCreateEntityMessages[eid]; if (entityMessage != undefined) { app.Client_onUpdatePropertys(entityMessage); - delete bufferedCreateEntityMessage[eid]; + delete bufferedCreateEntityMessages[eid]; } entity.__init__(); @@ -2802,10 +2804,10 @@ namespace KBEngine { entity.callPropertysSetMethods(); } else { - let entityMessage = bufferedCreateEntityMessage[eid]; + let entityMessage = bufferedCreateEntityMessages[eid]; if (entityMessage != undefined) { app.Client_onUpdatePropertys(entityMessage); - delete bufferedCreateEntityMessage[eid]; + delete bufferedCreateEntityMessages[eid]; } } } @@ -2832,7 +2834,7 @@ namespace KBEngine { let entity = app.entities[eid]; if (entity == undefined) { - let entityMessage = bufferedCreateEntityMessage[eid]; + let entityMessage = bufferedCreateEntityMessages[eid]; if (entityMessage != undefined) { ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity(" + eid + ") not found!"); return; @@ -2841,7 +2843,7 @@ namespace KBEngine { let stream1 = new MemoryStream(stream.buffer); stream1.wpos = stream.wpos; stream1.rpos = stream.rpos - 4; - bufferedCreateEntityMessage[eid] = stream1; + bufferedCreateEntityMessages[eid] = stream1; return; } @@ -2941,7 +2943,7 @@ namespace KBEngine { let entity = app.entities[eid]; if (entity == undefined) { - let entityMessage = bufferedCreateEntityMessage[eid]; + let entityMessage = bufferedCreateEntityMessages[eid]; if (entityMessage == undefined) { ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity(" + eid + ") not found!"); return; @@ -2963,7 +2965,7 @@ namespace KBEngine { app.entities[eid] = entity; app.Client_onUpdatePropertys(entityMessage); - delete bufferedCreateEntityMessage[eid]; + delete bufferedCreateEntityMessages[eid]; // entity.isOnGround = isOnGround > 0; entity.isOnGround = isOnGround; From da999033860ce2ced1548f07cd72eae1df04b470 Mon Sep 17 00:00:00 2001 From: oblivion <761458545@qq.com> Date: Fri, 11 May 2018 23:28:46 +0800 Subject: [PATCH 08/17] 1.1.8 --- kbengine_ts/bin/kbengine.d.ts | 8 +++++--- kbengine_ts/bin/kbengine.js | 33 ++++++++++++++++++--------------- kbengine_ts/bin/kbengine.min.js | 6 +++--- kbengine_ts/src/KBEngine.ts | 8 ++++---- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index 06ac7c1..3778111 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -1,5 +1,5 @@ /** - * KBEngine的html5客户端扩展ts版 1.1.5版本 + * KBEngine的html5客户端扩展ts版 1.x版本 * cocos creator 环境下使用方法 * 将bin/kbengine.js导入为插件,将bin/kbengine.d.ts放在项目根目录下,即可 * @@ -9,7 +9,7 @@ * * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 window['KBEngine'] = window['KBEngine'] || {};window['KBEngine']['你的实体类名']=你的实体类名;将声明提升至全局 + * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 KBEngine['Entities'] = KBEngine['Entities'] || {};KBEngine['Entities']['你的实体类名']=你的实体类名;将声明提升至全局 * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ @@ -171,7 +171,7 @@ declare namespace KBEngine { const onImportClientMessages: Message; } let clientmessages: {}; - let bufferedCreateEntityMessage: {}; + let bufferedCreateEntityMessages: {}; } declare namespace KBEngine { class Vector2 { @@ -426,6 +426,7 @@ declare namespace KBEngine { updateHZ: number; serverHeartbeatTick: number; protocol: string; + forceBasePort: number; clientType: number; isOnInitCallPropertysSetMethods: boolean; } @@ -444,6 +445,7 @@ declare namespace KBEngine { baseappMessageImported: boolean; serverErrorsDescrImported: boolean; entitydefImported: boolean; + useAliasEntityID: boolean; serverErrs: { [err: string]: ServerErr; }; diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index fd97e74..d65b131 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -9,7 +9,7 @@ for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]); r.prototype = e.prototype, t.prototype = new r(); }; /** - * KBEngine的html5客户端扩展ts版 1.1.5版本 + * KBEngine的html5客户端扩展ts版 1.x版本 * cocos creator 环境下使用方法 * 将bin/kbengine.js导入为插件,将bin/kbengine.d.ts放在项目根目录下,即可 * @@ -19,7 +19,7 @@ r.prototype = e.prototype, t.prototype = new r(); * * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 window['KBEngine'] = window['KBEngine'] || {};window['KBEngine']['你的实体类名']=你的实体类名;将声明提升至全局 + * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 KBEngine['Entities'] = KBEngine['Entities'] || {};KBEngine['Entities']['你的实体类名']=你的实体类名;将声明提升至全局 * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ @@ -835,7 +835,7 @@ window['KBEngine'] = KBEngine; messages.onImportClientMessages = new Message(518, "onImportClientMessages", -1, -1, new Array(), null); })(messages = KBEngine.messages || (KBEngine.messages = {})); KBEngine.clientmessages = {}; - KBEngine.bufferedCreateEntityMessage = {}; + KBEngine.bufferedCreateEntityMessages = {}; })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- math @@ -1739,8 +1739,9 @@ window['KBEngine'] = KBEngine; this.port = 20013; this.updateHZ = 100; this.serverHeartbeatTick = 15; - // + //todo wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 this.protocol = "ws://"; + this.forceBasePort = 0; // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types this.clientType = 5; // 在Entity初始化时是否触发属性的set_*事件(callPropertysSetMethods) @@ -1767,6 +1768,8 @@ window['KBEngine'] = KBEngine; this.baseappMessageImported = false; this.serverErrorsDescrImported = false; this.entitydefImported = false; + // 这个参数的选择必须与kbengine_defs.xml::cellapp/aliasEntityID的参数保持一致 + this.useAliasEntityID = true; this.serverErrs = {}; // // 登录loginapp的地址 // ip: string; @@ -1782,7 +1785,7 @@ window['KBEngine'] = KBEngine; this.serverScriptVersion = ""; this.serverProtocolMD5 = ""; this.serverEntityDefMD5 = ""; - this.clientVersion = "1.1.5"; + this.clientVersion = "1.1.8"; this.clientScriptVersion = "0.1.0"; // player的相关信息 this.entity_uuid = null; @@ -1834,8 +1837,8 @@ window['KBEngine'] = KBEngine; KBEngine.app.serverScriptVersion = ""; KBEngine.app.serverProtocolMD5 = ""; KBEngine.app.serverEntityDefMD5 = ""; - KBEngine.app.clientVersion = "1.1.5"; - KBEngine.app.clientScriptVersion = "0.1.0"; + // app.clientVersion = "1.1.5"; + // app.clientScriptVersion = "0.1.0"; // player的相关信息 KBEngine.app.entity_uuid = null; KBEngine.app.entity_id = 0; @@ -2561,10 +2564,10 @@ window['KBEngine'] = KBEngine; entity_1.base.className = entityType; entity_1.base.type = KBEngine.ENTITYCALL_TYPE_BASE; KBEngine.app.entities[eid] = entity_1; - var entityMessage = KBEngine.bufferedCreateEntityMessage[eid]; + var entityMessage = KBEngine.bufferedCreateEntityMessages[eid]; if (entityMessage != undefined) { KBEngine.app.Client_onUpdatePropertys(entityMessage); - delete KBEngine.bufferedCreateEntityMessage[eid]; + delete KBEngine.bufferedCreateEntityMessages[eid]; } entity_1.__init__(); entity_1.inited = true; @@ -2572,10 +2575,10 @@ window['KBEngine'] = KBEngine; entity_1.callPropertysSetMethods(); } else { - var entityMessage = KBEngine.bufferedCreateEntityMessage[eid]; + var entityMessage = KBEngine.bufferedCreateEntityMessages[eid]; if (entityMessage != undefined) { KBEngine.app.Client_onUpdatePropertys(entityMessage); - delete KBEngine.bufferedCreateEntityMessage[eid]; + delete KBEngine.bufferedCreateEntityMessages[eid]; } } }; @@ -2598,7 +2601,7 @@ window['KBEngine'] = KBEngine; KBEngineApp.prototype.onUpdatePropertys_ = function (eid, stream) { var entity = KBEngine.app.entities[eid]; if (entity == undefined) { - var entityMessage = KBEngine.bufferedCreateEntityMessage[eid]; + var entityMessage = KBEngine.bufferedCreateEntityMessages[eid]; if (entityMessage != undefined) { KBEngine.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity(" + eid + ") not found!"); return; @@ -2606,7 +2609,7 @@ window['KBEngine'] = KBEngine; var stream1 = new KBEngine.MemoryStream(stream.buffer); stream1.wpos = stream.wpos; stream1.rpos = stream.rpos - 4; - KBEngine.bufferedCreateEntityMessage[eid] = stream1; + KBEngine.bufferedCreateEntityMessages[eid] = stream1; return; } var currModule = KBEngine.moduledefs[entity.className]; @@ -2693,7 +2696,7 @@ window['KBEngine'] = KBEngine; KBEngine.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: " + entityType + "(" + eid + "), spaceID(" + KBEngine.app.spaceID + "), isOnGround(" + isOnGround + ")!"); var entity = KBEngine.app.entities[eid]; if (entity == undefined) { - var entityMessage = KBEngine.bufferedCreateEntityMessage[eid]; + var entityMessage = KBEngine.bufferedCreateEntityMessages[eid]; if (entityMessage == undefined) { KBEngine.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity(" + eid + ") not found!"); return; @@ -2710,7 +2713,7 @@ window['KBEngine'] = KBEngine; entity_2.cell.type = KBEngine.ENTITYCALL_TYPE_CELL; KBEngine.app.entities[eid] = entity_2; KBEngine.app.Client_onUpdatePropertys(entityMessage); - delete KBEngine.bufferedCreateEntityMessage[eid]; + delete KBEngine.bufferedCreateEntityMessages[eid]; // entity.isOnGround = isOnGround > 0; entity_2.isOnGround = isOnGround; entity_2.__init__(); diff --git a/kbengine_ts/bin/kbengine.min.js b/kbengine_ts/bin/kbengine.min.js index 71f8860..01f617b 100644 --- a/kbengine_ts/bin/kbengine.min.js +++ b/kbengine_ts/bin/kbengine.min.js @@ -1,3 +1,3 @@ -var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(){for(var e=[],t=0;tn;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t){this.x=e,this.y=t}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y;return Math.sqrt(t*t+n*n)},e}();e.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function e(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(t){for(var n=[],r=1;re||e>255?!1:!0},t}();e.DATATYPE_UINT8=n,__reflect(n.prototype,"KBEngine.DATATYPE_UINT8");var r=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint16.call(t)},t.prototype.addToStream=function(e,t){e.writeUint16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},t}();e.DATATYPE_UINT16=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT16");var a=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint32.call(t)},t.prototype.addToStream=function(e,t){e.writeUint32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},t}();e.DATATYPE_UINT32=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT32");var i=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint64.call(t)},t.prototype.addToStream=function(e,t){e.writeUint64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.UINT64},t}();e.DATATYPE_UINT64=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT64");var o=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt8.call(t)},t.prototype.addToStream=function(e,t){e.writeInt8(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},t}();e.DATATYPE_INT8=o,__reflect(o.prototype,"KBEngine.DATATYPE_INT8");var p=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt16.call(t)},t.prototype.addToStream=function(e,t){e.writeInt16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},t}();e.DATATYPE_INT16=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT16");var s=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt32.call(t)},t.prototype.addToStream=function(e,t){e.writeInt32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},t}();e.DATATYPE_INT32=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT32");var l=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt64.call(t)},t.prototype.addToStream=function(e,t){e.writeInt64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.INT64},t}();e.DATATYPE_INT64=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT64");var c=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readFloat.call(t)},t.prototype.addToStream=function(e,t){e.writeFloat(t)},t.prototype.parseDefaultValStr=function(e){return parseFloat(e)},t.prototype.isSameType=function(e){return"number"==typeof e},t}();e.DATATYPE_FLOAT=c,__reflect(c.prototype,"KBEngine.DATATYPE_FLOAT");var d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),n.prototype.createFromStream=function(t){return e.reader.readDouble.call(t)},n.prototype.addToStream=function(e,t){e.writeDouble(t)},n}(c);e.DATATYPE_DOUBLE=d,__reflect(d.prototype,"KBEngine.DATATYPE_DOUBLE");var u=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readString.call(t)},t.prototype.addToStream=function(e,t){e.writeString(t)},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_STRING=u,__reflect(u.prototype,"KBEngine.DATATYPE_STRING");var y=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector2(e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector2(e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y)):(t.writeFloat(n.x),t.writeFloat(n.y))},t.prototype.parseDefaultValStr=function(t){return new e.Vector2(0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector2?!0:!1},t}();e.DATATYPE_VECTOR2=y,__reflect(y.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector3(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector3(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z))},t.prototype.parseDefaultValStr=function(t){return new e.Vector3(0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector3?!0:!1},t}();e.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var _=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector4(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readFloat.call(t)):new e.Vector4(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z),t.writeInt32(n.w)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z),t.writeFloat(n.w))},t.prototype.parseDefaultValStr=function(t){return new e.Vector4(0,0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector4?!0:!1},t}();e.DATATYPE_VECTOR4=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR4");var g=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_PYTHON=g,__reflect(g.prototype,"KBEngine.DATATYPE_PYTHON");var E=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.utf8ArrayToString(e.reader.readBlob.call(t))},t.prototype.addToStream=function(t,n){t.writeBlob(e.stringToUTF8Bytes(n))},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_UNICODE=E,__reflect(E.prototype,"KBEngine.DATATYPE_UNICODE");var h=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_ENTITYCALL=h,__reflect(h.prototype,"KBEngine.DATATYPE_ENTITYCALL");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){var n=e.reader.readUint32.call(t),r=new Uint8Array(t.buffer,t.rpos,n);return t.rpos+=n,r},t.prototype.addToStream=function(e,t){e.writeBlob(t)},t.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},t.prototype.isSameType=function(e){return!0},t}();e.DATATYPE_BLOB=m,__reflect(m.prototype,"KBEngine.DATATYPE_BLOB");var v=function(){function e(){this.type=null}return e.prototype.bind=function(){"number"==typeof this.type&&(this.type=T[this.type])},e.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},e.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods;try{var y=e.Entities[n]}catch(f){}for(;a>0;){a--;var _=t.readUint16(),g=t.readUint32(),E=t.readInt16(),h=t.readString(),m=t.readString(),v=e.datatypes[t.readUint16()],S=null;void 0!=y&&(S=y.prototype["set_"+h],void 0==S&&(S=null));var T=[_,E,h,m,v,S,g];l[h]=T,-1!=E?(l[E]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+h+"/"+_+").")}for(;i>0;){i--;for(var I=t.readUint16(),E=t.readInt16(),w=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);var T=[I,E,w,C];c[w]=T,-1!=E?(c[E]=T,s.useMethodDescrAlias=!0):(c[I]=T,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+w+").")}for(;o>0;){o--;for(var I=t.readUint16(),E=t.readInt16(),B=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);d[B]=[I,E,B,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+B+").")}for(;p>0;){p--;for(var I=t.readUint16(),E=t.readInt16(),D=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);u[D]=[I,E,D,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+D+").")}var M=void 0;try{M=e.Entities[n]}catch(f){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),M=void 0}for(var L in s.propertys){var F=s.propertys[L],_=F[0],E=F[1],R=F[2],m=F[3],v=F[4];void 0!=M&&(M.prototype[R]=v.parseDefaultValStr(m))}for(var K in s.methods){var F=s.methods[K],_=F[0],E=F[1],R=F[2],C=F[3];void 0!=M&&void 0==M.prototype[R]&&e.WARNING_MSG(n+":: method("+R+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,u=o.indexOf("Client_")>=0;u&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),u?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=e.Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessage[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessage[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessage[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessage[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],u=l[4].createFromStream(n),y=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+u+")!"),r[l[2]]=u,null!=c&&(32==d||64==d?r.inited&&c.call(r,y):r.inWorld&&c.call(r,y))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessage[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessage[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8(); -e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0)},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var u=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(u=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),u&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file +var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(){for(var e=[],t=0;tn;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t){this.x=e,this.y=t}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y;return Math.sqrt(t*t+n*n)},e}();e.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function e(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(t){for(var n=[],r=1;re||e>255?!1:!0},t}();e.DATATYPE_UINT8=n,__reflect(n.prototype,"KBEngine.DATATYPE_UINT8");var r=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint16.call(t)},t.prototype.addToStream=function(e,t){e.writeUint16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},t}();e.DATATYPE_UINT16=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT16");var a=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint32.call(t)},t.prototype.addToStream=function(e,t){e.writeUint32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},t}();e.DATATYPE_UINT32=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT32");var i=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint64.call(t)},t.prototype.addToStream=function(e,t){e.writeUint64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.UINT64},t}();e.DATATYPE_UINT64=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT64");var o=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt8.call(t)},t.prototype.addToStream=function(e,t){e.writeInt8(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},t}();e.DATATYPE_INT8=o,__reflect(o.prototype,"KBEngine.DATATYPE_INT8");var p=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt16.call(t)},t.prototype.addToStream=function(e,t){e.writeInt16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},t}();e.DATATYPE_INT16=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT16");var s=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt32.call(t)},t.prototype.addToStream=function(e,t){e.writeInt32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},t}();e.DATATYPE_INT32=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT32");var l=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt64.call(t)},t.prototype.addToStream=function(e,t){e.writeInt64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.INT64},t}();e.DATATYPE_INT64=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT64");var c=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readFloat.call(t)},t.prototype.addToStream=function(e,t){e.writeFloat(t)},t.prototype.parseDefaultValStr=function(e){return parseFloat(e)},t.prototype.isSameType=function(e){return"number"==typeof e},t}();e.DATATYPE_FLOAT=c,__reflect(c.prototype,"KBEngine.DATATYPE_FLOAT");var d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),n.prototype.createFromStream=function(t){return e.reader.readDouble.call(t)},n.prototype.addToStream=function(e,t){e.writeDouble(t)},n}(c);e.DATATYPE_DOUBLE=d,__reflect(d.prototype,"KBEngine.DATATYPE_DOUBLE");var u=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readString.call(t)},t.prototype.addToStream=function(e,t){e.writeString(t)},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_STRING=u,__reflect(u.prototype,"KBEngine.DATATYPE_STRING");var y=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector2(e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector2(e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y)):(t.writeFloat(n.x),t.writeFloat(n.y))},t.prototype.parseDefaultValStr=function(t){return new e.Vector2(0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector2?!0:!1},t}();e.DATATYPE_VECTOR2=y,__reflect(y.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector3(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector3(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z))},t.prototype.parseDefaultValStr=function(t){return new e.Vector3(0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector3?!0:!1},t}();e.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var _=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector4(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readFloat.call(t)):new e.Vector4(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z),t.writeInt32(n.w)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z),t.writeFloat(n.w))},t.prototype.parseDefaultValStr=function(t){return new e.Vector4(0,0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector4?!0:!1},t}();e.DATATYPE_VECTOR4=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR4");var g=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_PYTHON=g,__reflect(g.prototype,"KBEngine.DATATYPE_PYTHON");var E=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.utf8ArrayToString(e.reader.readBlob.call(t))},t.prototype.addToStream=function(t,n){t.writeBlob(e.stringToUTF8Bytes(n))},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_UNICODE=E,__reflect(E.prototype,"KBEngine.DATATYPE_UNICODE");var h=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_ENTITYCALL=h,__reflect(h.prototype,"KBEngine.DATATYPE_ENTITYCALL");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){var n=e.reader.readUint32.call(t),r=new Uint8Array(t.buffer,t.rpos,n);return t.rpos+=n,r},t.prototype.addToStream=function(e,t){e.writeBlob(t)},t.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},t.prototype.isSameType=function(e){return!0},t}();e.DATATYPE_BLOB=m,__reflect(m.prototype,"KBEngine.DATATYPE_BLOB");var v=function(){function e(){this.type=null}return e.prototype.bind=function(){"number"==typeof this.type&&(this.type=T[this.type])},e.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},e.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods;try{var y=e.Entities[n]}catch(f){}for(;a>0;){a--;var _=t.readUint16(),g=t.readUint32(),E=t.readInt16(),h=t.readString(),m=t.readString(),v=e.datatypes[t.readUint16()],S=null;void 0!=y&&(S=y.prototype["set_"+h],void 0==S&&(S=null));var T=[_,E,h,m,v,S,g];l[h]=T,-1!=E?(l[E]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+h+"/"+_+").")}for(;i>0;){i--;for(var I=t.readUint16(),E=t.readInt16(),w=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);var T=[I,E,w,C];c[w]=T,-1!=E?(c[E]=T,s.useMethodDescrAlias=!0):(c[I]=T,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+w+").")}for(;o>0;){o--;for(var I=t.readUint16(),E=t.readInt16(),B=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);d[B]=[I,E,B,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+B+").")}for(;p>0;){p--;for(var I=t.readUint16(),E=t.readInt16(),D=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);u[D]=[I,E,D,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+D+").")}var M=void 0;try{M=e.Entities[n]}catch(f){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),M=void 0}for(var L in s.propertys){var F=s.propertys[L],_=F[0],E=F[1],R=F[2],m=F[3],v=F[4];void 0!=M&&(M.prototype[R]=v.parseDefaultValStr(m))}for(var K in s.methods){var F=s.methods[K],_=F[0],E=F[1],R=F[2],C=F[3];void 0!=M&&void 0==M.prototype[R]&&e.WARNING_MSG(n+":: method("+R+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,u=o.indexOf("Client_")>=0;u&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),u?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=e.Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessages[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessages[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessages[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessages[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessages[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessages[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],u=l[4].createFromStream(n),y=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+u+")!"),r[l[2]]=u,null!=c&&(32==d||64==d?r.inited&&c.call(r,y):r.inWorld&&c.call(r,y))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessages[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessages[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0) +},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var u=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(u=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),u&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index 23e37a2..b69e408 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -1,5 +1,5 @@ /** - * KBEngine的html5客户端扩展ts版 1.1.5版本 + * KBEngine的html5客户端扩展ts版 1.x版本 * cocos creator 环境下使用方法 * 将bin/kbengine.js导入为插件,将bin/kbengine.d.ts放在项目根目录下,即可 * @@ -1916,7 +1916,7 @@ namespace KBEngine { serverScriptVersion = ""; serverProtocolMD5 = ""; serverEntityDefMD5 = ""; - clientVersion = "1.1.5"; + clientVersion = "1.1.8"; clientScriptVersion = "0.1.0"; // player的相关信息 @@ -1975,8 +1975,8 @@ namespace KBEngine { app.serverScriptVersion = ""; app.serverProtocolMD5 = ""; app.serverEntityDefMD5 = ""; - app.clientVersion = "1.1.5"; - app.clientScriptVersion = "0.1.0"; + // app.clientVersion = "1.1.5"; + // app.clientScriptVersion = "0.1.0"; // player的相关信息 app.entity_uuid = null; From 44c8d02648a6c0ed5b94bd9e2702464ad4b5e16d Mon Sep 17 00:00:00 2001 From: oblivion <761458545@qq.com> Date: Sat, 9 Jun 2018 17:01:30 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kbengine_ts/bin/kbengine.d.ts | 2 ++ kbengine_ts/bin/kbengine.js | 8 +++++--- kbengine_ts/bin/kbengine.min.js | 6 +++--- kbengine_ts/src/KBEngine.ts | 9 ++++++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index 3778111..0583dec 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -14,6 +14,8 @@ * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ declare namespace KBEngine { + const CLIENT_VERSION = "1.1.8"; + const CLIENT_SCRIPT_VERSION = "0.1.0"; const PACKET_MAX_SIZE = 1500; const PACKET_MAX_SIZE_TCP = 1460; const PACKET_MAX_SIZE_UDP = 1472; diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index d65b131..90583b1 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -28,6 +28,8 @@ r.prototype = e.prototype, t.prototype = new r(); -----------------------------------------------------------------------------------------*/ var KBEngine; (function (KBEngine) { + KBEngine.CLIENT_VERSION = '1.1.8'; + KBEngine.CLIENT_SCRIPT_VERSION = '0.1.0'; KBEngine.PACKET_MAX_SIZE = 1500; KBEngine.PACKET_MAX_SIZE_TCP = 1460; KBEngine.PACKET_MAX_SIZE_UDP = 1472; @@ -1739,7 +1741,7 @@ window['KBEngine'] = KBEngine; this.port = 20013; this.updateHZ = 100; this.serverHeartbeatTick = 15; - //todo wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 + //TODO wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 this.protocol = "ws://"; this.forceBasePort = 0; // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types @@ -1785,8 +1787,8 @@ window['KBEngine'] = KBEngine; this.serverScriptVersion = ""; this.serverProtocolMD5 = ""; this.serverEntityDefMD5 = ""; - this.clientVersion = "1.1.8"; - this.clientScriptVersion = "0.1.0"; + this.clientVersion = KBEngine.CLIENT_VERSION; + this.clientScriptVersion = KBEngine.CLIENT_SCRIPT_VERSION; // player的相关信息 this.entity_uuid = null; this.entity_id = 0; diff --git a/kbengine_ts/bin/kbengine.min.js b/kbengine_ts/bin/kbengine.min.js index 01f617b..b8c9c18 100644 --- a/kbengine_ts/bin/kbengine.min.js +++ b/kbengine_ts/bin/kbengine.min.js @@ -1,3 +1,3 @@ -var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(){for(var e=[],t=0;tn;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t){this.x=e,this.y=t}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y;return Math.sqrt(t*t+n*n)},e}();e.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function e(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(t){for(var n=[],r=1;re||e>255?!1:!0},t}();e.DATATYPE_UINT8=n,__reflect(n.prototype,"KBEngine.DATATYPE_UINT8");var r=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint16.call(t)},t.prototype.addToStream=function(e,t){e.writeUint16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},t}();e.DATATYPE_UINT16=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT16");var a=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint32.call(t)},t.prototype.addToStream=function(e,t){e.writeUint32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},t}();e.DATATYPE_UINT32=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT32");var i=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint64.call(t)},t.prototype.addToStream=function(e,t){e.writeUint64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.UINT64},t}();e.DATATYPE_UINT64=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT64");var o=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt8.call(t)},t.prototype.addToStream=function(e,t){e.writeInt8(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},t}();e.DATATYPE_INT8=o,__reflect(o.prototype,"KBEngine.DATATYPE_INT8");var p=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt16.call(t)},t.prototype.addToStream=function(e,t){e.writeInt16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},t}();e.DATATYPE_INT16=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT16");var s=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt32.call(t)},t.prototype.addToStream=function(e,t){e.writeInt32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},t}();e.DATATYPE_INT32=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT32");var l=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt64.call(t)},t.prototype.addToStream=function(e,t){e.writeInt64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.INT64},t}();e.DATATYPE_INT64=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT64");var c=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readFloat.call(t)},t.prototype.addToStream=function(e,t){e.writeFloat(t)},t.prototype.parseDefaultValStr=function(e){return parseFloat(e)},t.prototype.isSameType=function(e){return"number"==typeof e},t}();e.DATATYPE_FLOAT=c,__reflect(c.prototype,"KBEngine.DATATYPE_FLOAT");var d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),n.prototype.createFromStream=function(t){return e.reader.readDouble.call(t)},n.prototype.addToStream=function(e,t){e.writeDouble(t)},n}(c);e.DATATYPE_DOUBLE=d,__reflect(d.prototype,"KBEngine.DATATYPE_DOUBLE");var u=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readString.call(t)},t.prototype.addToStream=function(e,t){e.writeString(t)},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_STRING=u,__reflect(u.prototype,"KBEngine.DATATYPE_STRING");var y=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector2(e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector2(e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y)):(t.writeFloat(n.x),t.writeFloat(n.y))},t.prototype.parseDefaultValStr=function(t){return new e.Vector2(0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector2?!0:!1},t}();e.DATATYPE_VECTOR2=y,__reflect(y.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector3(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector3(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z))},t.prototype.parseDefaultValStr=function(t){return new e.Vector3(0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector3?!0:!1},t}();e.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var _=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector4(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readFloat.call(t)):new e.Vector4(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z),t.writeInt32(n.w)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z),t.writeFloat(n.w))},t.prototype.parseDefaultValStr=function(t){return new e.Vector4(0,0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector4?!0:!1},t}();e.DATATYPE_VECTOR4=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR4");var g=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_PYTHON=g,__reflect(g.prototype,"KBEngine.DATATYPE_PYTHON");var E=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.utf8ArrayToString(e.reader.readBlob.call(t))},t.prototype.addToStream=function(t,n){t.writeBlob(e.stringToUTF8Bytes(n))},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_UNICODE=E,__reflect(E.prototype,"KBEngine.DATATYPE_UNICODE");var h=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_ENTITYCALL=h,__reflect(h.prototype,"KBEngine.DATATYPE_ENTITYCALL");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){var n=e.reader.readUint32.call(t),r=new Uint8Array(t.buffer,t.rpos,n);return t.rpos+=n,r},t.prototype.addToStream=function(e,t){e.writeBlob(t)},t.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},t.prototype.isSameType=function(e){return!0},t}();e.DATATYPE_BLOB=m,__reflect(m.prototype,"KBEngine.DATATYPE_BLOB");var v=function(){function e(){this.type=null}return e.prototype.bind=function(){"number"==typeof this.type&&(this.type=T[this.type])},e.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},e.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods;try{var y=e.Entities[n]}catch(f){}for(;a>0;){a--;var _=t.readUint16(),g=t.readUint32(),E=t.readInt16(),h=t.readString(),m=t.readString(),v=e.datatypes[t.readUint16()],S=null;void 0!=y&&(S=y.prototype["set_"+h],void 0==S&&(S=null));var T=[_,E,h,m,v,S,g];l[h]=T,-1!=E?(l[E]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+h+"/"+_+").")}for(;i>0;){i--;for(var I=t.readUint16(),E=t.readInt16(),w=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);var T=[I,E,w,C];c[w]=T,-1!=E?(c[E]=T,s.useMethodDescrAlias=!0):(c[I]=T,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+w+").")}for(;o>0;){o--;for(var I=t.readUint16(),E=t.readInt16(),B=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);d[B]=[I,E,B,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+B+").")}for(;p>0;){p--;for(var I=t.readUint16(),E=t.readInt16(),D=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);u[D]=[I,E,D,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+D+").")}var M=void 0;try{M=e.Entities[n]}catch(f){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),M=void 0}for(var L in s.propertys){var F=s.propertys[L],_=F[0],E=F[1],R=F[2],m=F[3],v=F[4];void 0!=M&&(M.prototype[R]=v.parseDefaultValStr(m))}for(var K in s.methods){var F=s.methods[K],_=F[0],E=F[1],R=F[2],C=F[3];void 0!=M&&void 0==M.prototype[R]&&e.WARNING_MSG(n+":: method("+R+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,u=o.indexOf("Client_")>=0;u&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),u?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=e.Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessages[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessages[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessages[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessages[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessages[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessages[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],u=l[4].createFromStream(n),y=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+u+")!"),r[l[2]]=u,null!=c&&(32==d||64==d?r.inited&&c.call(r,y):r.inWorld&&c.call(r,y))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessages[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessages[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0) -},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var u=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(u=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),u&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file +var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.CLIENT_VERSION="1.1.8",e.CLIENT_SCRIPT_VERSION="0.1.0",e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(){for(var e=[],t=0;tn;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t){this.x=e,this.y=t}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y;return Math.sqrt(t*t+n*n)},e}();e.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function e(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(t){for(var n=[],r=1;re||e>255?!1:!0},t}();e.DATATYPE_UINT8=n,__reflect(n.prototype,"KBEngine.DATATYPE_UINT8");var r=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint16.call(t)},t.prototype.addToStream=function(e,t){e.writeUint16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},t}();e.DATATYPE_UINT16=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT16");var a=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint32.call(t)},t.prototype.addToStream=function(e,t){e.writeUint32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},t}();e.DATATYPE_UINT32=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT32");var i=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint64.call(t)},t.prototype.addToStream=function(e,t){e.writeUint64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.UINT64},t}();e.DATATYPE_UINT64=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT64");var o=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt8.call(t)},t.prototype.addToStream=function(e,t){e.writeInt8(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},t}();e.DATATYPE_INT8=o,__reflect(o.prototype,"KBEngine.DATATYPE_INT8");var p=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt16.call(t)},t.prototype.addToStream=function(e,t){e.writeInt16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},t}();e.DATATYPE_INT16=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT16");var s=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt32.call(t)},t.prototype.addToStream=function(e,t){e.writeInt32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},t}();e.DATATYPE_INT32=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT32");var l=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt64.call(t)},t.prototype.addToStream=function(e,t){e.writeInt64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.INT64},t}();e.DATATYPE_INT64=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT64");var c=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readFloat.call(t)},t.prototype.addToStream=function(e,t){e.writeFloat(t)},t.prototype.parseDefaultValStr=function(e){return parseFloat(e)},t.prototype.isSameType=function(e){return"number"==typeof e},t}();e.DATATYPE_FLOAT=c,__reflect(c.prototype,"KBEngine.DATATYPE_FLOAT");var d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),n.prototype.createFromStream=function(t){return e.reader.readDouble.call(t)},n.prototype.addToStream=function(e,t){e.writeDouble(t)},n}(c);e.DATATYPE_DOUBLE=d,__reflect(d.prototype,"KBEngine.DATATYPE_DOUBLE");var u=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readString.call(t)},t.prototype.addToStream=function(e,t){e.writeString(t)},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_STRING=u,__reflect(u.prototype,"KBEngine.DATATYPE_STRING");var y=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector2(e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector2(e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y)):(t.writeFloat(n.x),t.writeFloat(n.y))},t.prototype.parseDefaultValStr=function(t){return new e.Vector2(0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector2?!0:!1},t}();e.DATATYPE_VECTOR2=y,__reflect(y.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector3(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector3(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z))},t.prototype.parseDefaultValStr=function(t){return new e.Vector3(0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector3?!0:!1},t}();e.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var _=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector4(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readFloat.call(t)):new e.Vector4(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z),t.writeInt32(n.w)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z),t.writeFloat(n.w))},t.prototype.parseDefaultValStr=function(t){return new e.Vector4(0,0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector4?!0:!1},t}();e.DATATYPE_VECTOR4=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR4");var E=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_PYTHON=E,__reflect(E.prototype,"KBEngine.DATATYPE_PYTHON");var g=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.utf8ArrayToString(e.reader.readBlob.call(t))},t.prototype.addToStream=function(t,n){t.writeBlob(e.stringToUTF8Bytes(n))},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_UNICODE=g,__reflect(g.prototype,"KBEngine.DATATYPE_UNICODE");var h=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_ENTITYCALL=h,__reflect(h.prototype,"KBEngine.DATATYPE_ENTITYCALL");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){var n=e.reader.readUint32.call(t),r=new Uint8Array(t.buffer,t.rpos,n);return t.rpos+=n,r},t.prototype.addToStream=function(e,t){e.writeBlob(t)},t.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},t.prototype.isSameType=function(e){return!0},t}();e.DATATYPE_BLOB=m,__reflect(m.prototype,"KBEngine.DATATYPE_BLOB");var v=function(){function e(){this.type=null}return e.prototype.bind=function(){"number"==typeof this.type&&(this.type=T[this.type])},e.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},e.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods;try{var y=e.Entities[n]}catch(f){}for(;a>0;){a--;var _=t.readUint16(),E=t.readUint32(),g=t.readInt16(),h=t.readString(),m=t.readString(),v=e.datatypes[t.readUint16()],S=null;void 0!=y&&(S=y.prototype["set_"+h],void 0==S&&(S=null));var T=[_,g,h,m,v,S,E];l[h]=T,-1!=g?(l[g]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+h+"/"+_+").")}for(;i>0;){i--;for(var I=t.readUint16(),g=t.readInt16(),w=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);var T=[I,g,w,C];c[w]=T,-1!=g?(c[g]=T,s.useMethodDescrAlias=!0):(c[I]=T,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+w+").")}for(;o>0;){o--;for(var I=t.readUint16(),g=t.readInt16(),B=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);d[B]=[I,g,B,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+B+").")}for(;p>0;){p--;for(var I=t.readUint16(),g=t.readInt16(),D=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);u[D]=[I,g,D,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+D+").")}var M=void 0;try{M=e.Entities[n]}catch(f){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),M=void 0}for(var L in s.propertys){var F=s.propertys[L],_=F[0],g=F[1],R=F[2],m=F[3],v=F[4];void 0!=M&&(M.prototype[R]=v.parseDefaultValStr(m))}for(var K in s.methods){var F=s.methods[K],_=F[0],g=F[1],R=F[2],C=F[3];void 0!=M&&void 0==M.prototype[R]&&e.WARNING_MSG(n+":: method("+R+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,u=o.indexOf("Client_")>=0;u&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),u?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=e.Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessages[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessages[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessages[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessages[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessages[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessages[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],u=l[4].createFromStream(n),y=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+u+")!"),r[l[2]]=u,null!=c&&(32==d||64==d?r.inited&&c.call(r,y):r.inWorld&&c.call(r,y))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessages[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessages[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8(); +e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0)},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var u=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(u=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),u&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index b69e408..1823a42 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -18,6 +18,8 @@ global -----------------------------------------------------------------------------------------*/ namespace KBEngine { + export const CLIENT_VERSION ='1.1.8'; + export const CLIENT_SCRIPT_VERSION ='0.1.0'; export const PACKET_MAX_SIZE = 1500; export const PACKET_MAX_SIZE_TCP = 1460; export const PACKET_MAX_SIZE_UDP = 1472; @@ -1857,7 +1859,8 @@ namespace KBEngine { port = 20013; updateHZ = 100; serverHeartbeatTick = 15; - //todo wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 + + //TODO wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 protocol: string = "ws://"; forceBasePort:number = 0; @@ -1916,8 +1919,8 @@ namespace KBEngine { serverScriptVersion = ""; serverProtocolMD5 = ""; serverEntityDefMD5 = ""; - clientVersion = "1.1.8"; - clientScriptVersion = "0.1.0"; + clientVersion = CLIENT_VERSION; + clientScriptVersion = CLIENT_SCRIPT_VERSION; // player的相关信息 entity_uuid = null; From 0c6c9572943673c257d7473e640d5bf7cb223f76 Mon Sep 17 00:00:00 2001 From: oblivion <761458545@qq.com> Date: Thu, 12 Jul 2018 21:43:07 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E5=88=B02.x=E7=89=88=E6=9C=AC=EF=BC=88=E7=99=BB=E9=99=86?= =?UTF-8?q?=E6=B2=A1=E9=97=AE=E9=A2=98=EF=BC=8CentityComponent=E6=97=A0?= =?UTF-8?q?=E7=94=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kbengine_ts/bin/kbengine.d.ts | 13 ++- kbengine_ts/bin/kbengine.js | 160 ++++++++++++++++------------------ kbengine_ts/src/KBEngine.ts | 29 +++++- 3 files changed, 117 insertions(+), 85 deletions(-) diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index 0583dec..64b13c7 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -14,7 +14,7 @@ * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ declare namespace KBEngine { - const CLIENT_VERSION = "1.1.8"; + const CLIENT_VERSION = "2.0.0"; const CLIENT_SCRIPT_VERSION = "0.1.0"; const PACKET_MAX_SIZE = 1500; const PACKET_MAX_SIZE_TCP = 1460; @@ -248,6 +248,8 @@ declare namespace KBEngine { declare namespace KBEngine { const ENTITYCALL_TYPE_CELL = 0; const ENTITYCALL_TYPE_BASE = 1; + class EntityComponent { + } class EntityCall { constructor(); id: number; @@ -369,6 +371,13 @@ declare namespace KBEngine { parseDefaultValStr(v: any): string; isSameType(v: any): boolean; } + class DATATYPE_ENTITY_COMPONENT { + bind(): void; + createFromStream(stream: any): void; + addToStream(stream: any, v: any): void; + parseDefaultValStr(v: any): Uint8Array; + isSameType(v: any): boolean; + } class DATATYPE_ENTITYCALL { bind(): void; createFromStream(stream: any): void; @@ -418,6 +427,7 @@ declare namespace KBEngine { const PYTHON: DATATYPE_PYTHON; const UNICODE: DATATYPE_UNICODE; const ENTITYCALL: DATATYPE_ENTITYCALL; + const ENTITY_COMPONENT: DATATYPE_ENTITY_COMPONENT; const BLOB: DATATYPE_BLOB; } } @@ -453,6 +463,7 @@ declare namespace KBEngine { }; baseappIP: string; baseappPort: number; + baseappUdpPort: number; socket: any; currserver: string; currstate: string; diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index 90583b1..f82c20a 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -1,13 +1,13 @@ -var __reflect = (this && this.__reflect) || function (p, c, t) { - p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t; -}; -var __extends = this && this.__extends || function __extends(t, e) { - function r() { - this.constructor = t; -} -for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]); -r.prototype = e.prototype, t.prototype = new r(); -}; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); /** * KBEngine的html5客户端扩展ts版 1.x版本 * cocos creator 环境下使用方法 @@ -28,7 +28,7 @@ r.prototype = e.prototype, t.prototype = new r(); -----------------------------------------------------------------------------------------*/ var KBEngine; (function (KBEngine) { - KBEngine.CLIENT_VERSION = '1.1.8'; + KBEngine.CLIENT_VERSION = '2.0.0'; KBEngine.CLIENT_SCRIPT_VERSION = '0.1.0'; KBEngine.PACKET_MAX_SIZE = 1500; KBEngine.PACKET_MAX_SIZE_TCP = 1460; @@ -46,7 +46,7 @@ window['KBEngine'] = KBEngine; number64bits -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var INT64 = (function () { + var INT64 = /** @class */ (function () { function INT64(lo, hi) { this.sign = 1; this.lo = lo; @@ -82,8 +82,7 @@ window['KBEngine'] = KBEngine; return INT64; }()); KBEngine.INT64 = INT64; - __reflect(INT64.prototype, "KBEngine.INT64"); - var UINT64 = (function () { + var UINT64 = /** @class */ (function () { function UINT64(lo, hi) { this.lo = lo; this.hi = hi; @@ -104,7 +103,6 @@ window['KBEngine'] = KBEngine; return UINT64; }()); KBEngine.UINT64 = UINT64; - __reflect(UINT64.prototype, "KBEngine.UINT64"); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- debug @@ -199,6 +197,7 @@ window['KBEngine'] = KBEngine; else if (charcode < 0xd800 || charcode >= 0xe000) { utf8.push(0xe0 | (charcode >> 12), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f)); } + // surrogate pair else { i++; // UTF-16 encodes 0x10000-0x10FFFF by @@ -217,7 +216,7 @@ window['KBEngine'] = KBEngine; event -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var EventInfo = (function () { + var EventInfo = /** @class */ (function () { function EventInfo(classinst, callbackfn) { this.callbackfn = callbackfn; this.classinst = classinst; @@ -225,8 +224,7 @@ window['KBEngine'] = KBEngine; return EventInfo; }()); KBEngine.EventInfo = EventInfo; - __reflect(EventInfo.prototype, "KBEngine.EventInfo"); - var Events = (function () { + var Events = /** @class */ (function () { function Events() { this._events = {}; } @@ -292,14 +290,13 @@ window['KBEngine'] = KBEngine; return Events; }()); KBEngine.Events = Events; - __reflect(Events.prototype, "KBEngine.Events"); KBEngine.Event = new Events(); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- memorystream -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var MemoryStream = (function () { + var MemoryStream = /** @class */ (function () { function MemoryStream(size_or_buffer) { this.rpos = 0; this.wpos = 0; @@ -556,9 +553,8 @@ window['KBEngine'] = KBEngine; return MemoryStream; }()); KBEngine.MemoryStream = MemoryStream; - __reflect(MemoryStream.prototype, "KBEngine.MemoryStream"); (function (MemoryStream) { - var PackFloatXType = (function () { + var PackFloatXType = /** @class */ (function () { function PackFloatXType() { this._unionData = new ArrayBuffer(4); this.fv = new Float32Array(this._unionData, 0, 1); @@ -569,14 +565,13 @@ window['KBEngine'] = KBEngine; return PackFloatXType; }()); MemoryStream.PackFloatXType = PackFloatXType; - __reflect(PackFloatXType.prototype, "KBEngine.MemoryStream.PackFloatXType"); })(MemoryStream = KBEngine.MemoryStream || (KBEngine.MemoryStream = {})); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- bundle -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var Bundle = (function () { + var Bundle = /** @class */ (function () { function Bundle() { this.memorystreams = new Array(); this.numMessage = 0; @@ -691,7 +686,6 @@ window['KBEngine'] = KBEngine; return Bundle; }()); KBEngine.Bundle = Bundle; - __reflect(Bundle.prototype, "KBEngine.Bundle"); KBEngine.reader = new KBEngine.MemoryStream(0); KBEngine.datatype2id = {}; function mappingDataType() { @@ -787,7 +781,7 @@ window['KBEngine'] = KBEngine; } } KBEngine.bindReader = bindReader; - var Message = (function () { + var Message = /** @class */ (function () { function Message(id, name, length, argstype, args, handler) { this.id = id; this.name = name; @@ -826,7 +820,6 @@ window['KBEngine'] = KBEngine; return Message; }()); KBEngine.Message = Message; - __reflect(Message.prototype, "KBEngine.Message"); var messages; (function (messages) { messages.loginapp = {}; @@ -843,7 +836,7 @@ window['KBEngine'] = KBEngine; math -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var Vector2 = (function () { + var Vector2 = /** @class */ (function () { function Vector2(x, y) { this.x = x; this.y = y; @@ -856,8 +849,7 @@ window['KBEngine'] = KBEngine; return Vector2; }()); KBEngine.Vector2 = Vector2; - __reflect(Vector2.prototype, "KBEngine.Vector2"); - var Vector3 = (function () { + var Vector3 = /** @class */ (function () { function Vector3(x, y, z) { this.x = x; this.y = y; @@ -872,11 +864,10 @@ window['KBEngine'] = KBEngine; return Vector3; }()); KBEngine.Vector3 = Vector3; - __reflect(Vector3.prototype, "KBEngine.Vector3"); /** * todo 这个类的第四个参数的没搞清楚,所有如果没有必要,不要用这个东西 */ - var Vector4 = (function () { + var Vector4 = /** @class */ (function () { function Vector4(x, y, z, w) { this.x = x; this.y = y; @@ -895,7 +886,6 @@ window['KBEngine'] = KBEngine; return Vector4; }()); KBEngine.Vector4 = Vector4; - __reflect(Vector4.prototype, "KBEngine.Vector4"); function clampf(value, min_inclusive, max_inclusive) { if (min_inclusive > max_inclusive) { var temp = min_inclusive; @@ -926,7 +916,7 @@ window['KBEngine'] = KBEngine; entity -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var Entity = (function () { + var Entity = /** @class */ (function () { function Entity() { this.id = 0; this.className = ""; @@ -1123,7 +1113,6 @@ window['KBEngine'] = KBEngine; return Entity; }()); KBEngine.Entity = Entity; - __reflect(Entity.prototype, "KBEngine.Entity"); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- EntityCall @@ -1131,7 +1120,14 @@ window['KBEngine'] = KBEngine; (function (KBEngine) { KBEngine.ENTITYCALL_TYPE_CELL = 0; KBEngine.ENTITYCALL_TYPE_BASE = 1; - var EntityCall = (function () { + //这个东西好像没有同步给客户端 + var EntityComponent = /** @class */ (function () { + function EntityComponent() { + } + return EntityComponent; + }()); + KBEngine.EntityComponent = EntityComponent; + var EntityCall = /** @class */ (function () { function EntityCall() { this.id = 0; this.className = ''; @@ -1165,8 +1161,7 @@ window['KBEngine'] = KBEngine; return EntityCall; }()); KBEngine.EntityCall = EntityCall; - __reflect(EntityCall.prototype, "KBEngine.EntityCall"); - var DATATYPE_UINT8 = (function () { + var DATATYPE_UINT8 = /** @class */ (function () { function DATATYPE_UINT8() { } DATATYPE_UINT8.prototype.bind = function () { @@ -1192,8 +1187,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_UINT8; }()); KBEngine.DATATYPE_UINT8 = DATATYPE_UINT8; - __reflect(DATATYPE_UINT8.prototype, "KBEngine.DATATYPE_UINT8"); - var DATATYPE_UINT16 = (function () { + var DATATYPE_UINT16 = /** @class */ (function () { function DATATYPE_UINT16() { } DATATYPE_UINT16.prototype.bind = function () { @@ -1219,8 +1213,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_UINT16; }()); KBEngine.DATATYPE_UINT16 = DATATYPE_UINT16; - __reflect(DATATYPE_UINT16.prototype, "KBEngine.DATATYPE_UINT16"); - var DATATYPE_UINT32 = (function () { + var DATATYPE_UINT32 = /** @class */ (function () { function DATATYPE_UINT32() { } DATATYPE_UINT32.prototype.bind = function () { @@ -1246,8 +1239,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_UINT32; }()); KBEngine.DATATYPE_UINT32 = DATATYPE_UINT32; - __reflect(DATATYPE_UINT32.prototype, "KBEngine.DATATYPE_UINT32"); - var DATATYPE_UINT64 = (function () { + var DATATYPE_UINT64 = /** @class */ (function () { function DATATYPE_UINT64() { } DATATYPE_UINT64.prototype.bind = function () { @@ -1267,8 +1259,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_UINT64; }()); KBEngine.DATATYPE_UINT64 = DATATYPE_UINT64; - __reflect(DATATYPE_UINT64.prototype, "KBEngine.DATATYPE_UINT64"); - var DATATYPE_INT8 = (function () { + var DATATYPE_INT8 = /** @class */ (function () { function DATATYPE_INT8() { } DATATYPE_INT8.prototype.bind = function () { @@ -1294,8 +1285,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_INT8; }()); KBEngine.DATATYPE_INT8 = DATATYPE_INT8; - __reflect(DATATYPE_INT8.prototype, "KBEngine.DATATYPE_INT8"); - var DATATYPE_INT16 = (function () { + var DATATYPE_INT16 = /** @class */ (function () { function DATATYPE_INT16() { } DATATYPE_INT16.prototype.bind = function () { @@ -1321,8 +1311,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_INT16; }()); KBEngine.DATATYPE_INT16 = DATATYPE_INT16; - __reflect(DATATYPE_INT16.prototype, "KBEngine.DATATYPE_INT16"); - var DATATYPE_INT32 = (function () { + var DATATYPE_INT32 = /** @class */ (function () { function DATATYPE_INT32() { } DATATYPE_INT32.prototype.bind = function () { @@ -1348,8 +1337,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_INT32; }()); KBEngine.DATATYPE_INT32 = DATATYPE_INT32; - __reflect(DATATYPE_INT32.prototype, "KBEngine.DATATYPE_INT32"); - var DATATYPE_INT64 = (function () { + var DATATYPE_INT64 = /** @class */ (function () { function DATATYPE_INT64() { } DATATYPE_INT64.prototype.bind = function () { @@ -1369,8 +1357,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_INT64; }()); KBEngine.DATATYPE_INT64 = DATATYPE_INT64; - __reflect(DATATYPE_INT64.prototype, "KBEngine.DATATYPE_INT64"); - var DATATYPE_FLOAT = (function () { + var DATATYPE_FLOAT = /** @class */ (function () { function DATATYPE_FLOAT() { } DATATYPE_FLOAT.prototype.bind = function () { @@ -1390,8 +1377,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_FLOAT; }()); KBEngine.DATATYPE_FLOAT = DATATYPE_FLOAT; - __reflect(DATATYPE_FLOAT.prototype, "KBEngine.DATATYPE_FLOAT"); - var DATATYPE_DOUBLE = (function (_super) { + var DATATYPE_DOUBLE = /** @class */ (function (_super) { __extends(DATATYPE_DOUBLE, _super); function DATATYPE_DOUBLE() { return _super !== null && _super.apply(this, arguments) || this; @@ -1405,8 +1391,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_DOUBLE; }(DATATYPE_FLOAT)); KBEngine.DATATYPE_DOUBLE = DATATYPE_DOUBLE; - __reflect(DATATYPE_DOUBLE.prototype, "KBEngine.DATATYPE_DOUBLE"); - var DATATYPE_STRING = (function () { + var DATATYPE_STRING = /** @class */ (function () { function DATATYPE_STRING() { } DATATYPE_STRING.prototype.bind = function () { @@ -1428,8 +1413,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_STRING; }()); KBEngine.DATATYPE_STRING = DATATYPE_STRING; - __reflect(DATATYPE_STRING.prototype, "KBEngine.DATATYPE_STRING"); - var DATATYPE_VECTOR2 = (function () { + var DATATYPE_VECTOR2 = /** @class */ (function () { function DATATYPE_VECTOR2() { } DATATYPE_VECTOR2.prototype.bind = function () { @@ -1465,8 +1449,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_VECTOR2; }()); KBEngine.DATATYPE_VECTOR2 = DATATYPE_VECTOR2; - __reflect(DATATYPE_VECTOR2.prototype, "KBEngine.DATATYPE_VECTOR2"); - var DATATYPE_VECTOR3 = (function () { + var DATATYPE_VECTOR3 = /** @class */ (function () { function DATATYPE_VECTOR3() { } DATATYPE_VECTOR3.prototype.bind = function () { @@ -1503,8 +1486,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_VECTOR3; }()); KBEngine.DATATYPE_VECTOR3 = DATATYPE_VECTOR3; - __reflect(DATATYPE_VECTOR3.prototype, "KBEngine.DATATYPE_VECTOR3"); - var DATATYPE_VECTOR4 = (function () { + var DATATYPE_VECTOR4 = /** @class */ (function () { function DATATYPE_VECTOR4() { } DATATYPE_VECTOR4.prototype.bind = function () { @@ -1543,8 +1525,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_VECTOR4; }()); KBEngine.DATATYPE_VECTOR4 = DATATYPE_VECTOR4; - __reflect(DATATYPE_VECTOR4.prototype, "KBEngine.DATATYPE_VECTOR4"); - var DATATYPE_PYTHON = (function () { + var DATATYPE_PYTHON = /** @class */ (function () { function DATATYPE_PYTHON() { } DATATYPE_PYTHON.prototype.bind = function () { @@ -1562,8 +1543,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_PYTHON; }()); KBEngine.DATATYPE_PYTHON = DATATYPE_PYTHON; - __reflect(DATATYPE_PYTHON.prototype, "KBEngine.DATATYPE_PYTHON"); - var DATATYPE_UNICODE = (function () { + var DATATYPE_UNICODE = /** @class */ (function () { function DATATYPE_UNICODE() { } DATATYPE_UNICODE.prototype.bind = function () { @@ -1585,8 +1565,26 @@ window['KBEngine'] = KBEngine; return DATATYPE_UNICODE; }()); KBEngine.DATATYPE_UNICODE = DATATYPE_UNICODE; - __reflect(DATATYPE_UNICODE.prototype, "KBEngine.DATATYPE_UNICODE"); - var DATATYPE_ENTITYCALL = (function () { + var DATATYPE_ENTITY_COMPONENT = /** @class */ (function () { + function DATATYPE_ENTITY_COMPONENT() { + } + DATATYPE_ENTITY_COMPONENT.prototype.bind = function () { + }; + DATATYPE_ENTITY_COMPONENT.prototype.createFromStream = function (stream) { + }; + DATATYPE_ENTITY_COMPONENT.prototype.addToStream = function (stream, v) { + }; + DATATYPE_ENTITY_COMPONENT.prototype.parseDefaultValStr = function (v) { + return new Uint8Array(0); + ; + }; + DATATYPE_ENTITY_COMPONENT.prototype.isSameType = function (v) { + return false; + }; + return DATATYPE_ENTITY_COMPONENT; + }()); + KBEngine.DATATYPE_ENTITY_COMPONENT = DATATYPE_ENTITY_COMPONENT; + var DATATYPE_ENTITYCALL = /** @class */ (function () { function DATATYPE_ENTITYCALL() { } DATATYPE_ENTITYCALL.prototype.bind = function () { @@ -1605,8 +1603,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_ENTITYCALL; }()); KBEngine.DATATYPE_ENTITYCALL = DATATYPE_ENTITYCALL; - __reflect(DATATYPE_ENTITYCALL.prototype, "KBEngine.DATATYPE_ENTITYCALL"); - var DATATYPE_BLOB = (function () { + var DATATYPE_BLOB = /** @class */ (function () { function DATATYPE_BLOB() { } DATATYPE_BLOB.prototype.bind = function () { @@ -1629,8 +1626,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_BLOB; }()); KBEngine.DATATYPE_BLOB = DATATYPE_BLOB; - __reflect(DATATYPE_BLOB.prototype, "KBEngine.DATATYPE_BLOB"); - var DATATYPE_ARRAY = (function () { + var DATATYPE_ARRAY = /** @class */ (function () { function DATATYPE_ARRAY() { this.type = null; } @@ -1668,8 +1664,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_ARRAY; }()); KBEngine.DATATYPE_ARRAY = DATATYPE_ARRAY; - __reflect(DATATYPE_ARRAY.prototype, "KBEngine.DATATYPE_ARRAY"); - var DATATYPE_FIXED_DICT = (function () { + var DATATYPE_FIXED_DICT = /** @class */ (function () { function DATATYPE_FIXED_DICT() { this.dicttype = {}; this.implementedBy = null; @@ -1707,7 +1702,6 @@ window['KBEngine'] = KBEngine; return DATATYPE_FIXED_DICT; }()); KBEngine.DATATYPE_FIXED_DICT = DATATYPE_FIXED_DICT; - __reflect(DATATYPE_FIXED_DICT.prototype, "KBEngine.DATATYPE_FIXED_DICT"); var datatypes; (function (datatypes) { datatypes.UINT8 = new DATATYPE_UINT8(); @@ -1727,6 +1721,7 @@ window['KBEngine'] = KBEngine; datatypes.PYTHON = new DATATYPE_PYTHON(); datatypes.UNICODE = new DATATYPE_UNICODE(); datatypes.ENTITYCALL = new DATATYPE_ENTITYCALL(); + datatypes.ENTITY_COMPONENT = new DATATYPE_ENTITY_COMPONENT(); datatypes.BLOB = new DATATYPE_BLOB(); })(datatypes = KBEngine.datatypes || (KBEngine.datatypes = {})); ; @@ -1735,7 +1730,7 @@ window['KBEngine'] = KBEngine; KBEngine args -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var KBEngineArgs = (function () { + var KBEngineArgs = /** @class */ (function () { function KBEngineArgs() { this.ip = '127.0.0.1'; this.port = 20013; @@ -1752,14 +1747,13 @@ window['KBEngine'] = KBEngine; return KBEngineArgs; }()); KBEngine.KBEngineArgs = KBEngineArgs; - __reflect(KBEngineArgs.prototype, "KBEngine.KBEngineArgs"); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- KBEngine app -----------------------------------------------------------------------------------------*/ (function (KBEngine) { KBEngine.moduledefs = {}; - var KBEngineApp = (function () { + var KBEngineApp = /** @class */ (function () { function KBEngineApp(args) { // console.assert(app == null || app == undefined, "Assertion of app not is null"); this.username = "testhtml51"; @@ -1779,6 +1773,7 @@ window['KBEngine'] = KBEngine; // 服务端分配的baseapp地址 this.baseappIP = ''; this.baseappPort = 0; + this.baseappUdpPort = 0; this.currstate = "create"; // 扩展数据 this.serverdatas = ""; @@ -2522,6 +2517,7 @@ window['KBEngine'] = KBEngine; KBEngine.app.username = accountName; KBEngine.app.baseappIp = args.readString(); KBEngine.app.baseappPort = args.readUint16(); + KBEngine.app.baseappUdpPort = args.readUint16(); KBEngine.app.serverdatas = args.readBlob(); KBEngine.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName(" + accountName + "), addr(" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "), datas(" + KBEngine.app.serverdatas.length + ")!"); @@ -3268,9 +3264,8 @@ window['KBEngine'] = KBEngine; return KBEngineApp; }()); KBEngine.KBEngineApp = KBEngineApp; - __reflect(KBEngineApp.prototype, "KBEngine.KBEngineApp"); // 描述服务端返回的错误信息 - var ServerErr = (function () { + var ServerErr = /** @class */ (function () { function ServerErr() { this.name = ""; this.descr = ""; @@ -3279,7 +3274,6 @@ window['KBEngine'] = KBEngine; return ServerErr; }()); KBEngine.ServerErr = ServerErr; - __reflect(ServerErr.prototype, "KBEngine.ServerErr"); var idInterval; function create(args) { if (KBEngine.app != undefined) diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index 1823a42..a137620 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -18,8 +18,9 @@ global -----------------------------------------------------------------------------------------*/ namespace KBEngine { - export const CLIENT_VERSION ='1.1.8'; + export const CLIENT_VERSION ='2.0.0'; export const CLIENT_SCRIPT_VERSION ='0.1.0'; + export const PACKET_MAX_SIZE = 1500; export const PACKET_MAX_SIZE_TCP = 1460; export const PACKET_MAX_SIZE_UDP = 1472; @@ -1240,6 +1241,11 @@ namespace KBEngine { namespace KBEngine { export const ENTITYCALL_TYPE_CELL = 0; export const ENTITYCALL_TYPE_BASE = 1; + + //这个东西好像没有同步给客户端 + export class EntityComponent{ + + } export class EntityCall { constructor() { @@ -1701,6 +1707,24 @@ namespace KBEngine { return typeof (v) == "string"; } } + export class DATATYPE_ENTITY_COMPONENT{ + bind() { + } + + createFromStream(stream) { + } + + addToStream(stream, v) { + } + + parseDefaultValStr(v) { + return new Uint8Array(0);; + } + + isSameType(v) { + return false; + } + } export class DATATYPE_ENTITYCALL { bind() { } @@ -1847,6 +1871,7 @@ namespace KBEngine { export const PYTHON = new DATATYPE_PYTHON(); export const UNICODE = new DATATYPE_UNICODE(); export const ENTITYCALL = new DATATYPE_ENTITYCALL(); + export const ENTITY_COMPONENT = new DATATYPE_ENTITY_COMPONENT(); export const BLOB = new DATATYPE_BLOB(); }; } @@ -1906,6 +1931,7 @@ namespace KBEngine { // 服务端分配的baseapp地址 baseappIP = ''; baseappPort = 0; + baseappUdpPort = 0; socket; currserver: string; @@ -2739,6 +2765,7 @@ namespace KBEngine { app.username = accountName; app.baseappIp = args.readString(); app.baseappPort = args.readUint16(); + app.baseappUdpPort = args.readUint16(); app.serverdatas = args.readBlob(); INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName(" + accountName + "), addr(" + From 19bea5a7c5af8272f09e0e90c15c9e1db07dfc55 Mon Sep 17 00:00:00 2001 From: oblivion <761458545@qq.com> Date: Thu, 2 Aug 2018 21:25:24 +0800 Subject: [PATCH 11/17] =?UTF-8?q?=E5=A2=9E=E5=8A=A0python=E3=80=81PY=5FDIC?= =?UTF-8?q?T=E3=80=81PY=5FLIST=E7=AD=89=E4=BA=8C=E8=BF=9B=E5=88=B6?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=20=E5=A2=9E=E5=8A=A0Vector2=E3=80=81Vector4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kbengine_ts/bin/kbengine.d.ts | 28 +++- kbengine_ts/bin/kbengine.js | 242 +++++++++++++++++++++------------- kbengine_ts/src/KBEngine.ts | 172 ++++++++++++++++++++---- 3 files changed, 316 insertions(+), 126 deletions(-) diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index 0583dec..29d54cf 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -177,31 +177,43 @@ declare namespace KBEngine { } declare namespace KBEngine { class Vector2 { - constructor(x: any, y: any); + constructor(x: number, y: number); x: number; y: number; distance(pos: Vector2): number; + add(vec2: Vector2): this; + sub(vec2: Vector2): this; + mul(num: number): this; + div(num: number): this; + neg(): this; } class Vector3 { - constructor(x: any, y: any, z: any); + constructor(x: number, y: number, z: number); x: number; y: number; z: number; distance(pos: Vector3): number; + add(vec3: Vector3): this; + sub(vec3: Vector3): this; + mul(num: number): this; + div(num: number): this; + neg(): this; } /** * todo 这个类的第四个参数的没搞清楚,所有如果没有必要,不要用这个东西 */ class Vector4 { - constructor(x: any, y: any, z: any, w: any); + constructor(x: number, y: number, z: number, w: number); x: number; y: number; z: number; w: number; - /** - * todo 因为不清楚这个vector4的 w 的含义,所以不确定这个方法的正确性 - */ distance(pos: Vector4): number; + add(vec4: Vector4): this; + sub(vec4: Vector4): this; + mul(num: number): this; + div(num: number): this; + neg(): this; } function clampf(value: any, min_inclusive: any, max_inclusive: any): any; function int82angle(angle: any, half: any): number; @@ -357,7 +369,7 @@ declare namespace KBEngine { } class DATATYPE_PYTHON { bind(): void; - createFromStream(stream: any): void; + createFromStream(stream: any): any; addToStream(stream: any, v: any): void; parseDefaultValStr(v: any): Uint8Array; isSameType(v: any): boolean; @@ -416,6 +428,8 @@ declare namespace KBEngine { const VECTOR3: DATATYPE_VECTOR3; const VECTOR4: DATATYPE_VECTOR4; const PYTHON: DATATYPE_PYTHON; + const PY_DICT: DATATYPE_PYTHON; + const PY_LIST: DATATYPE_PYTHON; const UNICODE: DATATYPE_UNICODE; const ENTITYCALL: DATATYPE_ENTITYCALL; const BLOB: DATATYPE_BLOB; diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index 90583b1..58e1924 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -1,13 +1,13 @@ -var __reflect = (this && this.__reflect) || function (p, c, t) { - p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t; -}; -var __extends = this && this.__extends || function __extends(t, e) { - function r() { - this.constructor = t; -} -for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]); -r.prototype = e.prototype, t.prototype = new r(); -}; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); /** * KBEngine的html5客户端扩展ts版 1.x版本 * cocos creator 环境下使用方法 @@ -46,7 +46,7 @@ window['KBEngine'] = KBEngine; number64bits -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var INT64 = (function () { + var INT64 = /** @class */ (function () { function INT64(lo, hi) { this.sign = 1; this.lo = lo; @@ -82,8 +82,7 @@ window['KBEngine'] = KBEngine; return INT64; }()); KBEngine.INT64 = INT64; - __reflect(INT64.prototype, "KBEngine.INT64"); - var UINT64 = (function () { + var UINT64 = /** @class */ (function () { function UINT64(lo, hi) { this.lo = lo; this.hi = hi; @@ -104,7 +103,6 @@ window['KBEngine'] = KBEngine; return UINT64; }()); KBEngine.UINT64 = UINT64; - __reflect(UINT64.prototype, "KBEngine.UINT64"); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- debug @@ -199,6 +197,7 @@ window['KBEngine'] = KBEngine; else if (charcode < 0xd800 || charcode >= 0xe000) { utf8.push(0xe0 | (charcode >> 12), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f)); } + // surrogate pair else { i++; // UTF-16 encodes 0x10000-0x10FFFF by @@ -217,7 +216,7 @@ window['KBEngine'] = KBEngine; event -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var EventInfo = (function () { + var EventInfo = /** @class */ (function () { function EventInfo(classinst, callbackfn) { this.callbackfn = callbackfn; this.classinst = classinst; @@ -225,8 +224,7 @@ window['KBEngine'] = KBEngine; return EventInfo; }()); KBEngine.EventInfo = EventInfo; - __reflect(EventInfo.prototype, "KBEngine.EventInfo"); - var Events = (function () { + var Events = /** @class */ (function () { function Events() { this._events = {}; } @@ -292,14 +290,13 @@ window['KBEngine'] = KBEngine; return Events; }()); KBEngine.Events = Events; - __reflect(Events.prototype, "KBEngine.Events"); KBEngine.Event = new Events(); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- memorystream -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var MemoryStream = (function () { + var MemoryStream = /** @class */ (function () { function MemoryStream(size_or_buffer) { this.rpos = 0; this.wpos = 0; @@ -556,9 +553,8 @@ window['KBEngine'] = KBEngine; return MemoryStream; }()); KBEngine.MemoryStream = MemoryStream; - __reflect(MemoryStream.prototype, "KBEngine.MemoryStream"); (function (MemoryStream) { - var PackFloatXType = (function () { + var PackFloatXType = /** @class */ (function () { function PackFloatXType() { this._unionData = new ArrayBuffer(4); this.fv = new Float32Array(this._unionData, 0, 1); @@ -569,14 +565,13 @@ window['KBEngine'] = KBEngine; return PackFloatXType; }()); MemoryStream.PackFloatXType = PackFloatXType; - __reflect(PackFloatXType.prototype, "KBEngine.MemoryStream.PackFloatXType"); })(MemoryStream = KBEngine.MemoryStream || (KBEngine.MemoryStream = {})); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- bundle -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var Bundle = (function () { + var Bundle = /** @class */ (function () { function Bundle() { this.memorystreams = new Array(); this.numMessage = 0; @@ -691,7 +686,6 @@ window['KBEngine'] = KBEngine; return Bundle; }()); KBEngine.Bundle = Bundle; - __reflect(Bundle.prototype, "KBEngine.Bundle"); KBEngine.reader = new KBEngine.MemoryStream(0); KBEngine.datatype2id = {}; function mappingDataType() { @@ -787,7 +781,7 @@ window['KBEngine'] = KBEngine; } } KBEngine.bindReader = bindReader; - var Message = (function () { + var Message = /** @class */ (function () { function Message(id, name, length, argstype, args, handler) { this.id = id; this.name = name; @@ -826,7 +820,6 @@ window['KBEngine'] = KBEngine; return Message; }()); KBEngine.Message = Message; - __reflect(Message.prototype, "KBEngine.Message"); var messages; (function (messages) { messages.loginapp = {}; @@ -843,7 +836,7 @@ window['KBEngine'] = KBEngine; math -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var Vector2 = (function () { + var Vector2 = /** @class */ (function () { function Vector2(x, y) { this.x = x; this.y = y; @@ -853,11 +846,35 @@ window['KBEngine'] = KBEngine; var y = pos.y - this.y; return Math.sqrt(x * x + y * y); }; + Vector2.prototype.add = function (vec2) { + this.x += vec2.x; + this.y += vec2.y; + return this; + }; + Vector2.prototype.sub = function (vec2) { + this.x -= vec2.x; + this.y -= vec2.y; + return this; + }; + Vector2.prototype.mul = function (num) { + this.x *= num; + this.y *= num; + return this; + }; + Vector2.prototype.div = function (num) { + this.x /= num; + this.y /= num; + return this; + }; + Vector2.prototype.neg = function () { + this.x = -this.x; + this.y = -this.y; + return this; + }; return Vector2; }()); KBEngine.Vector2 = Vector2; - __reflect(Vector2.prototype, "KBEngine.Vector2"); - var Vector3 = (function () { + var Vector3 = /** @class */ (function () { function Vector3(x, y, z) { this.x = x; this.y = y; @@ -869,33 +886,99 @@ window['KBEngine'] = KBEngine; var z = pos.z - this.z; return Math.sqrt(x * x + y * y + z * z); }; + //向量加法 + Vector3.prototype.add = function (vec3) { + this.x += vec3.x; + this.y += vec3.y; + this.z += vec3.z; + return this; + }; + //向量减法 + Vector3.prototype.sub = function (vec3) { + this.x -= vec3.x; + this.y -= vec3.y; + this.z -= vec3.z; + return this; + }; + //向量乘法 + Vector3.prototype.mul = function (num) { + this.x *= num; + this.y *= num; + this.z *= num; + return this; + }; + //向量除法 + Vector3.prototype.div = function (num) { + this.x /= num; + this.y /= num; + this.z /= num; + return this; + }; + // 向量取反 + Vector3.prototype.neg = function () { + this.x = -this.x; + this.y = -this.y; + this.z = -this.z; + return this; + }; return Vector3; }()); KBEngine.Vector3 = Vector3; - __reflect(Vector3.prototype, "KBEngine.Vector3"); /** * todo 这个类的第四个参数的没搞清楚,所有如果没有必要,不要用这个东西 */ - var Vector4 = (function () { + var Vector4 = /** @class */ (function () { function Vector4(x, y, z, w) { this.x = x; this.y = y; this.z = z; this.w = w; } - /** - * todo 因为不清楚这个vector4的 w 的含义,所以不确定这个方法的正确性 - */ Vector4.prototype.distance = function (pos) { var x = pos.x - this.x; var y = pos.y - this.y; var z = pos.z - this.z; - return Math.sqrt(x * x + y * y + z * z); + var w = pos.w - this.w; + return Math.sqrt(x * x + y * y + z * z + w * w); + }; + Vector4.prototype.add = function (vec4) { + this.x += vec4.x; + this.y += vec4.y; + this.z += vec4.z; + this.w += vec4.w; + return this; + }; + Vector4.prototype.sub = function (vec4) { + this.x -= vec4.x; + this.y -= vec4.y; + this.z -= vec4.z; + this.w -= vec4.w; + return this; + }; + Vector4.prototype.mul = function (num) { + this.x *= num; + this.y *= num; + this.z *= num; + this.w *= num; + return this; + }; + Vector4.prototype.div = function (num) { + this.x /= num; + this.y /= num; + this.z /= num; + this.w /= num; + return this; + }; + Vector4.prototype.neg = function () { + this.x = -this.x; + this.y = -this.y; + this.z = -this.z; + this.w = -this.w; + return this; }; return Vector4; }()); KBEngine.Vector4 = Vector4; - __reflect(Vector4.prototype, "KBEngine.Vector4"); function clampf(value, min_inclusive, max_inclusive) { if (min_inclusive > max_inclusive) { var temp = min_inclusive; @@ -926,7 +1009,7 @@ window['KBEngine'] = KBEngine; entity -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var Entity = (function () { + var Entity = /** @class */ (function () { function Entity() { this.id = 0; this.className = ""; @@ -1123,7 +1206,6 @@ window['KBEngine'] = KBEngine; return Entity; }()); KBEngine.Entity = Entity; - __reflect(Entity.prototype, "KBEngine.Entity"); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- EntityCall @@ -1131,7 +1213,7 @@ window['KBEngine'] = KBEngine; (function (KBEngine) { KBEngine.ENTITYCALL_TYPE_CELL = 0; KBEngine.ENTITYCALL_TYPE_BASE = 1; - var EntityCall = (function () { + var EntityCall = /** @class */ (function () { function EntityCall() { this.id = 0; this.className = ''; @@ -1165,8 +1247,7 @@ window['KBEngine'] = KBEngine; return EntityCall; }()); KBEngine.EntityCall = EntityCall; - __reflect(EntityCall.prototype, "KBEngine.EntityCall"); - var DATATYPE_UINT8 = (function () { + var DATATYPE_UINT8 = /** @class */ (function () { function DATATYPE_UINT8() { } DATATYPE_UINT8.prototype.bind = function () { @@ -1192,8 +1273,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_UINT8; }()); KBEngine.DATATYPE_UINT8 = DATATYPE_UINT8; - __reflect(DATATYPE_UINT8.prototype, "KBEngine.DATATYPE_UINT8"); - var DATATYPE_UINT16 = (function () { + var DATATYPE_UINT16 = /** @class */ (function () { function DATATYPE_UINT16() { } DATATYPE_UINT16.prototype.bind = function () { @@ -1219,8 +1299,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_UINT16; }()); KBEngine.DATATYPE_UINT16 = DATATYPE_UINT16; - __reflect(DATATYPE_UINT16.prototype, "KBEngine.DATATYPE_UINT16"); - var DATATYPE_UINT32 = (function () { + var DATATYPE_UINT32 = /** @class */ (function () { function DATATYPE_UINT32() { } DATATYPE_UINT32.prototype.bind = function () { @@ -1246,8 +1325,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_UINT32; }()); KBEngine.DATATYPE_UINT32 = DATATYPE_UINT32; - __reflect(DATATYPE_UINT32.prototype, "KBEngine.DATATYPE_UINT32"); - var DATATYPE_UINT64 = (function () { + var DATATYPE_UINT64 = /** @class */ (function () { function DATATYPE_UINT64() { } DATATYPE_UINT64.prototype.bind = function () { @@ -1267,8 +1345,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_UINT64; }()); KBEngine.DATATYPE_UINT64 = DATATYPE_UINT64; - __reflect(DATATYPE_UINT64.prototype, "KBEngine.DATATYPE_UINT64"); - var DATATYPE_INT8 = (function () { + var DATATYPE_INT8 = /** @class */ (function () { function DATATYPE_INT8() { } DATATYPE_INT8.prototype.bind = function () { @@ -1294,8 +1371,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_INT8; }()); KBEngine.DATATYPE_INT8 = DATATYPE_INT8; - __reflect(DATATYPE_INT8.prototype, "KBEngine.DATATYPE_INT8"); - var DATATYPE_INT16 = (function () { + var DATATYPE_INT16 = /** @class */ (function () { function DATATYPE_INT16() { } DATATYPE_INT16.prototype.bind = function () { @@ -1321,8 +1397,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_INT16; }()); KBEngine.DATATYPE_INT16 = DATATYPE_INT16; - __reflect(DATATYPE_INT16.prototype, "KBEngine.DATATYPE_INT16"); - var DATATYPE_INT32 = (function () { + var DATATYPE_INT32 = /** @class */ (function () { function DATATYPE_INT32() { } DATATYPE_INT32.prototype.bind = function () { @@ -1348,8 +1423,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_INT32; }()); KBEngine.DATATYPE_INT32 = DATATYPE_INT32; - __reflect(DATATYPE_INT32.prototype, "KBEngine.DATATYPE_INT32"); - var DATATYPE_INT64 = (function () { + var DATATYPE_INT64 = /** @class */ (function () { function DATATYPE_INT64() { } DATATYPE_INT64.prototype.bind = function () { @@ -1369,8 +1443,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_INT64; }()); KBEngine.DATATYPE_INT64 = DATATYPE_INT64; - __reflect(DATATYPE_INT64.prototype, "KBEngine.DATATYPE_INT64"); - var DATATYPE_FLOAT = (function () { + var DATATYPE_FLOAT = /** @class */ (function () { function DATATYPE_FLOAT() { } DATATYPE_FLOAT.prototype.bind = function () { @@ -1390,8 +1463,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_FLOAT; }()); KBEngine.DATATYPE_FLOAT = DATATYPE_FLOAT; - __reflect(DATATYPE_FLOAT.prototype, "KBEngine.DATATYPE_FLOAT"); - var DATATYPE_DOUBLE = (function (_super) { + var DATATYPE_DOUBLE = /** @class */ (function (_super) { __extends(DATATYPE_DOUBLE, _super); function DATATYPE_DOUBLE() { return _super !== null && _super.apply(this, arguments) || this; @@ -1405,8 +1477,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_DOUBLE; }(DATATYPE_FLOAT)); KBEngine.DATATYPE_DOUBLE = DATATYPE_DOUBLE; - __reflect(DATATYPE_DOUBLE.prototype, "KBEngine.DATATYPE_DOUBLE"); - var DATATYPE_STRING = (function () { + var DATATYPE_STRING = /** @class */ (function () { function DATATYPE_STRING() { } DATATYPE_STRING.prototype.bind = function () { @@ -1428,8 +1499,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_STRING; }()); KBEngine.DATATYPE_STRING = DATATYPE_STRING; - __reflect(DATATYPE_STRING.prototype, "KBEngine.DATATYPE_STRING"); - var DATATYPE_VECTOR2 = (function () { + var DATATYPE_VECTOR2 = /** @class */ (function () { function DATATYPE_VECTOR2() { } DATATYPE_VECTOR2.prototype.bind = function () { @@ -1465,8 +1535,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_VECTOR2; }()); KBEngine.DATATYPE_VECTOR2 = DATATYPE_VECTOR2; - __reflect(DATATYPE_VECTOR2.prototype, "KBEngine.DATATYPE_VECTOR2"); - var DATATYPE_VECTOR3 = (function () { + var DATATYPE_VECTOR3 = /** @class */ (function () { function DATATYPE_VECTOR3() { } DATATYPE_VECTOR3.prototype.bind = function () { @@ -1503,15 +1572,14 @@ window['KBEngine'] = KBEngine; return DATATYPE_VECTOR3; }()); KBEngine.DATATYPE_VECTOR3 = DATATYPE_VECTOR3; - __reflect(DATATYPE_VECTOR3.prototype, "KBEngine.DATATYPE_VECTOR3"); - var DATATYPE_VECTOR4 = (function () { + var DATATYPE_VECTOR4 = /** @class */ (function () { function DATATYPE_VECTOR4() { } DATATYPE_VECTOR4.prototype.bind = function () { }; DATATYPE_VECTOR4.prototype.createFromStream = function (stream) { if (KBEngine.CLIENT_NO_FLOAT) { - return new KBEngine.Vector4(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readFloat.call(stream)); + return new KBEngine.Vector4(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); } else { return new KBEngine.Vector4(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); @@ -1543,15 +1611,16 @@ window['KBEngine'] = KBEngine; return DATATYPE_VECTOR4; }()); KBEngine.DATATYPE_VECTOR4 = DATATYPE_VECTOR4; - __reflect(DATATYPE_VECTOR4.prototype, "KBEngine.DATATYPE_VECTOR4"); - var DATATYPE_PYTHON = (function () { + var DATATYPE_PYTHON = /** @class */ (function () { function DATATYPE_PYTHON() { } DATATYPE_PYTHON.prototype.bind = function () { }; DATATYPE_PYTHON.prototype.createFromStream = function (stream) { + return stream.readBlob(); }; DATATYPE_PYTHON.prototype.addToStream = function (stream, v) { + stream.writeBlob(v); }; DATATYPE_PYTHON.prototype.parseDefaultValStr = function (v) { return new Uint8Array(0); @@ -1562,8 +1631,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_PYTHON; }()); KBEngine.DATATYPE_PYTHON = DATATYPE_PYTHON; - __reflect(DATATYPE_PYTHON.prototype, "KBEngine.DATATYPE_PYTHON"); - var DATATYPE_UNICODE = (function () { + var DATATYPE_UNICODE = /** @class */ (function () { function DATATYPE_UNICODE() { } DATATYPE_UNICODE.prototype.bind = function () { @@ -1585,8 +1653,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_UNICODE; }()); KBEngine.DATATYPE_UNICODE = DATATYPE_UNICODE; - __reflect(DATATYPE_UNICODE.prototype, "KBEngine.DATATYPE_UNICODE"); - var DATATYPE_ENTITYCALL = (function () { + var DATATYPE_ENTITYCALL = /** @class */ (function () { function DATATYPE_ENTITYCALL() { } DATATYPE_ENTITYCALL.prototype.bind = function () { @@ -1605,8 +1672,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_ENTITYCALL; }()); KBEngine.DATATYPE_ENTITYCALL = DATATYPE_ENTITYCALL; - __reflect(DATATYPE_ENTITYCALL.prototype, "KBEngine.DATATYPE_ENTITYCALL"); - var DATATYPE_BLOB = (function () { + var DATATYPE_BLOB = /** @class */ (function () { function DATATYPE_BLOB() { } DATATYPE_BLOB.prototype.bind = function () { @@ -1629,8 +1695,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_BLOB; }()); KBEngine.DATATYPE_BLOB = DATATYPE_BLOB; - __reflect(DATATYPE_BLOB.prototype, "KBEngine.DATATYPE_BLOB"); - var DATATYPE_ARRAY = (function () { + var DATATYPE_ARRAY = /** @class */ (function () { function DATATYPE_ARRAY() { this.type = null; } @@ -1668,8 +1733,7 @@ window['KBEngine'] = KBEngine; return DATATYPE_ARRAY; }()); KBEngine.DATATYPE_ARRAY = DATATYPE_ARRAY; - __reflect(DATATYPE_ARRAY.prototype, "KBEngine.DATATYPE_ARRAY"); - var DATATYPE_FIXED_DICT = (function () { + var DATATYPE_FIXED_DICT = /** @class */ (function () { function DATATYPE_FIXED_DICT() { this.dicttype = {}; this.implementedBy = null; @@ -1707,7 +1771,6 @@ window['KBEngine'] = KBEngine; return DATATYPE_FIXED_DICT; }()); KBEngine.DATATYPE_FIXED_DICT = DATATYPE_FIXED_DICT; - __reflect(DATATYPE_FIXED_DICT.prototype, "KBEngine.DATATYPE_FIXED_DICT"); var datatypes; (function (datatypes) { datatypes.UINT8 = new DATATYPE_UINT8(); @@ -1721,10 +1784,12 @@ window['KBEngine'] = KBEngine; datatypes.FLOAT = new DATATYPE_FLOAT(); datatypes.DOUBLE = new DATATYPE_DOUBLE(); datatypes.STRING = new DATATYPE_STRING(); - datatypes.VECTOR2 = new DATATYPE_VECTOR2; - datatypes.VECTOR3 = new DATATYPE_VECTOR3; - datatypes.VECTOR4 = new DATATYPE_VECTOR4; + datatypes.VECTOR2 = new DATATYPE_VECTOR2(); + datatypes.VECTOR3 = new DATATYPE_VECTOR3(); + datatypes.VECTOR4 = new DATATYPE_VECTOR4(); datatypes.PYTHON = new DATATYPE_PYTHON(); + datatypes.PY_DICT = new DATATYPE_PYTHON(); + datatypes.PY_LIST = new DATATYPE_PYTHON(); datatypes.UNICODE = new DATATYPE_UNICODE(); datatypes.ENTITYCALL = new DATATYPE_ENTITYCALL(); datatypes.BLOB = new DATATYPE_BLOB(); @@ -1735,7 +1800,7 @@ window['KBEngine'] = KBEngine; KBEngine args -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var KBEngineArgs = (function () { + var KBEngineArgs = /** @class */ (function () { function KBEngineArgs() { this.ip = '127.0.0.1'; this.port = 20013; @@ -1752,14 +1817,13 @@ window['KBEngine'] = KBEngine; return KBEngineArgs; }()); KBEngine.KBEngineArgs = KBEngineArgs; - __reflect(KBEngineArgs.prototype, "KBEngine.KBEngineArgs"); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- KBEngine app -----------------------------------------------------------------------------------------*/ (function (KBEngine) { KBEngine.moduledefs = {}; - var KBEngineApp = (function () { + var KBEngineApp = /** @class */ (function () { function KBEngineApp(args) { // console.assert(app == null || app == undefined, "Assertion of app not is null"); this.username = "testhtml51"; @@ -3268,9 +3332,8 @@ window['KBEngine'] = KBEngine; return KBEngineApp; }()); KBEngine.KBEngineApp = KBEngineApp; - __reflect(KBEngineApp.prototype, "KBEngine.KBEngineApp"); // 描述服务端返回的错误信息 - var ServerErr = (function () { + var ServerErr = /** @class */ (function () { function ServerErr() { this.name = ""; this.descr = ""; @@ -3279,7 +3342,6 @@ window['KBEngine'] = KBEngine; return ServerErr; }()); KBEngine.ServerErr = ServerErr; - __reflect(ServerErr.prototype, "KBEngine.ServerErr"); var idInterval; function create(args) { if (KBEngine.app != undefined) diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index 1823a42..1a70f43 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -33,7 +33,7 @@ namespace KBEngine { /** * 加上声明避免cocos creator编辑器报错 */ -window['KBEngine']=KBEngine; +window['KBEngine'] = KBEngine; /*----------------------------------------------------------------------------------------- number64bits -----------------------------------------------------------------------------------------*/ @@ -107,17 +107,17 @@ namespace KBEngine { -----------------------------------------------------------------------------------------*/ namespace KBEngine { /** todo 调试输出模块,这里需要根据使用的引擎不同在这里加入判断条件 */ - export function INFO_MSG(...args:any[]) { - console.info.apply(console,args); + export function INFO_MSG(...args: any[]) { + console.info.apply(console, args); } - export function DEBUG_MSG(...args:any[]) { - console.debug.apply(console,args); + export function DEBUG_MSG(...args: any[]) { + console.debug.apply(console, args); } - export function ERROR_MSG(...args:any[]) { - console.error.apply(console,args); + export function ERROR_MSG(...args: any[]) { + console.error.apply(console, args); } - export function WARNING_MSG(...args:any[]) { - console.warn.apply(console,args); + export function WARNING_MSG(...args: any[]) { + console.warn.apply(console, args); } } /*----------------------------------------------------------------------------------------- @@ -927,7 +927,7 @@ namespace KBEngine { -----------------------------------------------------------------------------------------*/ namespace KBEngine { export class Vector2 { - constructor(x, y) { + constructor(x:number, y:number) { this.x = x; this.y = y; } @@ -938,9 +938,38 @@ namespace KBEngine { let y = pos.y - this.y; return Math.sqrt(x * x + y * y); } + add(vec2: Vector2) { + this.x += vec2.x; + this.y += vec2.y; + return this; + } + + sub(vec2: Vector2) { + this.x -= vec2.x; + this.y -= vec2.y; + return this; + } + + mul(num: number) { + this.x *= num; + this.y *= num; + return this; + } + + div(num: number) { + this.x /= num; + this.y /= num; + return this; + } + + neg() { + this.x = -this.x; + this.y = -this.y; + return this; + } } export class Vector3 { - constructor(x, y, z) { + constructor(x:number, y:number, z:number) { this.x = x; this.y = y; this.z = z; @@ -954,29 +983,106 @@ namespace KBEngine { let z = pos.z - this.z; return Math.sqrt(x * x + y * y + z * z); } + + //向量加法 + add(vec3: Vector3) { + this.x += vec3.x; + this.y += vec3.y; + this.z += vec3.z; + return this; + } + + //向量减法 + sub(vec3: Vector3) { + this.x -= vec3.x; + this.y -= vec3.y; + this.z -= vec3.z; + return this; + } + + //向量乘法 + mul(num: number) { + this.x *= num; + this.y *= num; + this.z *= num; + return this; + } + + //向量除法 + div(num: number) { + this.x /= num; + this.y /= num; + this.z /= num; + return this; + } + + // 向量取反 + neg() { + this.x = -this.x; + this.y = -this.y; + this.z = -this.z; + return this; + } } /** * todo 这个类的第四个参数的没搞清楚,所有如果没有必要,不要用这个东西 */ export class Vector4 { - constructor(x, y, z,w) { + constructor(x:number, y:number, z:number, w:number) { this.x = x; this.y = y; this.z = z; - this.w =w; + this.w = w; } x: number; y: number; z: number; - w:number; - /** - * todo 因为不清楚这个vector4的 w 的含义,所以不确定这个方法的正确性 - */ + w: number; distance(pos: Vector4) { - let x = pos.x - this.x; - let y = pos.y - this.y; - let z = pos.z - this.z; - return Math.sqrt(x * x + y * y + z * z); + var x = pos.x - this.x; + var y = pos.y - this.y; + var z = pos.z - this.z; + var w = pos.w - this.w; + return Math.sqrt(x * x + y * y + z * z + w * w); + } + + add(vec4:Vector4) { + this.x += vec4.x; + this.y += vec4.y; + this.z += vec4.z; + this.w += vec4.w; + return this; + } + + sub(vec4:Vector4) { + this.x -= vec4.x; + this.y -= vec4.y; + this.z -= vec4.z; + this.w -= vec4.w; + return this; + } + + mul(num:number) { + this.x *= num; + this.y *= num; + this.z *= num; + this.w *= num; + return this; + } + div(num:number) { + this.x /= num; + this.y /= num; + this.z /= num; + this.w /= num; + return this; + } + + neg() { + this.x = -this.x; + this.y = -this.y; + this.z = -this.z; + this.w = -this.w; + return this; } } export function clampf(value, min_inclusive, max_inclusive) { @@ -1625,11 +1731,15 @@ namespace KBEngine { createFromStream(stream) { if (CLIENT_NO_FLOAT) { return new Vector4(reader.readInt32.call(stream), - reader.readInt32.call(stream), reader.readInt32.call(stream),reader.readFloat.call(stream)); + reader.readInt32.call(stream), + reader.readInt32.call(stream), + reader.readInt32.call(stream)); } else { return new Vector4(reader.readFloat.call(stream), - reader.readFloat.call(stream), reader.readFloat.call(stream),reader.readFloat.call(stream)); + reader.readFloat.call(stream), + reader.readFloat.call(stream), + reader.readFloat.call(stream)); } } @@ -1649,7 +1759,7 @@ namespace KBEngine { } parseDefaultValStr(v) { - return new KBEngine.Vector4(0.0, 0.0, 0.0,0.0); + return new KBEngine.Vector4(0.0, 0.0, 0.0, 0.0); } isSameType(v) { @@ -1665,9 +1775,11 @@ namespace KBEngine { } createFromStream(stream) { + return stream.readBlob(); } addToStream(stream, v) { + stream.writeBlob(v); } parseDefaultValStr(v) { @@ -1841,10 +1953,12 @@ namespace KBEngine { export const DOUBLE = new DATATYPE_DOUBLE(); export const STRING = new DATATYPE_STRING(); - export const VECTOR2 = new DATATYPE_VECTOR2; - export const VECTOR3 = new DATATYPE_VECTOR3; - export const VECTOR4 = new DATATYPE_VECTOR4; + export const VECTOR2 = new DATATYPE_VECTOR2(); + export const VECTOR3 = new DATATYPE_VECTOR3(); + export const VECTOR4 = new DATATYPE_VECTOR4(); export const PYTHON = new DATATYPE_PYTHON(); + export const PY_DICT = new DATATYPE_PYTHON(); + export const PY_LIST = new DATATYPE_PYTHON(); export const UNICODE = new DATATYPE_UNICODE(); export const ENTITYCALL = new DATATYPE_ENTITYCALL(); export const BLOB = new DATATYPE_BLOB(); @@ -1862,7 +1976,7 @@ namespace KBEngine { //TODO wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 protocol: string = "ws://"; - forceBasePort:number = 0; + forceBasePort: number = 0; // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types clientType = 5; @@ -1896,7 +2010,7 @@ namespace KBEngine { serverErrorsDescrImported = false; entitydefImported = false; // 这个参数的选择必须与kbengine_defs.xml::cellapp/aliasEntityID的参数保持一致 - useAliasEntityID = true; + useAliasEntityID = true; serverErrs: { [err: string]: ServerErr } = {}; // // 登录loginapp的地址 From c98eb243c7a8298beaa6af4fd6a8a315d5427ebd Mon Sep 17 00:00:00 2001 From: zengmingnan Date: Tue, 26 Feb 2019 10:50:49 +0800 Subject: [PATCH 12/17] up --- kbengine_ts/bin/kbengine.d.ts | 165 +++- kbengine_ts/bin/kbengine.js | 1063 +++++++++++++++++++------ kbengine_ts/bin/kbengine.min.js | 3 - kbengine_ts/src/KBEngine.ts | 1279 ++++++++++++++++++++++++------- kbengine_ts/sync.bat | 15 + kbengine_ts/tsconfig.json | 4 + 6 files changed, 1997 insertions(+), 532 deletions(-) delete mode 100644 kbengine_ts/bin/kbengine.min.js create mode 100644 kbengine_ts/sync.bat diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index fbf75e3..d94b0a3 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -1,16 +1,21 @@ /** - * KBEngine的html5客户端扩展ts版 1.x版本 + * KBEngine的html5客户端扩展ts版 2.x版本 * cocos creator 环境下使用方法 - * 将bin/kbengine.js导入为插件,将bin/kbengine.d.ts放在项目根目录下,即可 + * 将bin/js导入为插件,将bin/d.ts放在项目根目录下,即可 * * todo 未完成内容 * 1、强类型匹配 * 2、代码注释 * * 注:(下面的是重点) - * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 KBEngine['Entities'] = KBEngine['Entities'] || {};KBEngine['Entities']['你的实体类名']=你的实体类名;将声明提升至全局 - * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; + * 1、实体声明的命名空间为Entities,与官方的KBEngine不同 + * 2、cocos creator环境下,实体类声明完成后,需要类声明时加上@registerEntity('你的类名'),用于将变量提升至全局,加入下方一段用于代码提示 + * declare global{ + namespace Entities{ + class 类名 extends 类{} + } + } + * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends Entity{}; * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ declare namespace KBEngine { @@ -21,6 +26,8 @@ declare namespace KBEngine { const PACKET_MAX_SIZE_UDP = 1472; const MESSAGE_ID_LENGTH = 2; const MESSAGE_LENGTH_LENGTH = 2; + const MESSAGE_LENGTH1_LENGTH = 4; + const MESSAGE_MAX_SIZE = 65535; const CLIENT_NO_FLOAT = 0; const KBE_FLT_MAX = 3.402823466e+38; } @@ -52,9 +59,15 @@ declare namespace KBEngine { } declare namespace KBEngine { class EventInfo { - constructor(classinst: any, callbackfn: any); classinst: any; callbackfn: any; + constructor(classinst: any, callbackfn: any); + } + class FiredEvent { + evtName: any; + evtInfo: any; + ars: any; + constructor(evtName: any, evtInfo: any, ars: any); } interface IEvents { [evtName: string]: EventInfo[]; @@ -62,15 +75,32 @@ declare namespace KBEngine { class Events { constructor(); _events: IEvents; + _isPause: boolean; + _firedEvents: FiredEvent[]; register(evtName: string, classinst: any, strCallback: string): void; + deregisterAll(classinst: any): void; deregister(evtName: string, classinst: any): void; + removeAllFiredEvent(classinst: any): void; + removeFiredEvent(evtName: string, classinst: any): void; fire(evtName: string, ...args: any[]): void; + pasue(): void; + resume(): void; + clear(): void; } const Event: Events; } declare namespace KBEngine { + class PackFloatXType { + _unionData: ArrayBuffer; + fv: Float32Array; + uv: Uint32Array; + iv: Int32Array; + } + const _xPackData: PackFloatXType; + const _yPackData: PackFloatXType; + const _zPackData: PackFloatXType; class MemoryStream { - constructor(size_or_buffer: any); + constructor(size_or_buffer: number | ArrayBuffer); buffer: ArrayBuffer; rpos: number; wpos: number; @@ -96,19 +126,25 @@ declare namespace KBEngine { writeUint8(v: any): void; writeUint16(v: any): void; writeUint32(v: any): void; - writeUint64(v: any): void; + writeUint64(v: UINT64): void; writeFloat(v: any): void; writeDouble(v: any): void; writeBlob(v: any): void; writeString(v: any): void; + append(stream: MemoryStream, offset: number, size: number): void; readSkip(v: any): void; space(): number; length(): number; readEOF(): boolean; done(): void; - getbuffer(v: any): ArrayBuffer; + getbuffer(): ArrayBuffer; + setbuffer(buffer: ArrayBuffer): void; + size(): number; + clear(): void; + reclaimObject(): void; } module MemoryStream { + const _objects: MemoryStream[]; class PackFloatXType { _unionData: ArrayBuffer; fv: Float32Array; @@ -116,12 +152,15 @@ declare namespace KBEngine { iv: Int32Array; constructor(); } + function createObject(): MemoryStream; } } declare namespace KBEngine { class Bundle { + static _objects: Bundle[]; + static createObject(): Bundle; constructor(); - memorystreams: Array; + memorystreams: Array; stream: MemoryStream; numMessage: number; messageLengthBuffer: Uint8Array; @@ -144,6 +183,8 @@ declare namespace KBEngine { writeDouble(v: any): void; writeString(v: any): void; writeBlob(v: any): void; + clear(): void; + reclaimObject(): void; } const reader: MemoryStream; interface IDataType2Id { @@ -154,13 +195,13 @@ declare namespace KBEngine { function bindWriter(writer: any, argType: number): any; function bindReader(argType: number): () => any; class Message { - constructor(id: any, name: any, length: any, argstype: any, args: any, handler: any); id: any; name: any; length: any; argsType: any; args: any; handler: any; + constructor(id: any, name: any, length: any, argsType: any, args: any, handler: any); createFromStream(msgstream: any): any; handleMessage(msgstream: any): void; } @@ -177,9 +218,9 @@ declare namespace KBEngine { } declare namespace KBEngine { class Vector2 { - constructor(x: number, y: number); x: number; y: number; + constructor(x: number, y: number); distance(pos: Vector2): number; add(vec2: Vector2): this; sub(vec2: Vector2): this; @@ -188,10 +229,10 @@ declare namespace KBEngine { neg(): this; } class Vector3 { - constructor(x: number, y: number, z: number); x: number; y: number; z: number; + constructor(x: number, y: number, z: number); distance(pos: Vector3): number; add(vec3: Vector3): this; sub(vec3: Vector3): this; @@ -199,15 +240,12 @@ declare namespace KBEngine { div(num: number): this; neg(): this; } - /** - * todo 这个类的第四个参数的没搞清楚,所有如果没有必要,不要用这个东西 - */ class Vector4 { - constructor(x: number, y: number, z: number, w: number); x: number; y: number; z: number; w: number; + constructor(x: number, y: number, z: number, w: number); distance(pos: Vector4): number; add(vec4: Vector4): this; sub(vec4: Vector4): this; @@ -216,12 +254,11 @@ declare namespace KBEngine { neg(): this; } function clampf(value: any, min_inclusive: any, max_inclusive: any): any; - function int82angle(angle: any, half: any): number; + function int82angle(angle: number, half: boolean): number; function angle2int8(v: number, half: boolean): number; } declare namespace KBEngine { - namespace Entities { - } + module Entities { } class Entity { constructor(); id: number; @@ -256,6 +293,7 @@ declare namespace KBEngine { onUpdateVolatileData(): void; set_direction(old: any): void; } + function registerEntity(name: string): (ctor: new () => Entity) => void; } declare namespace KBEngine { const ENTITYCALL_TYPE_CELL = 0; @@ -437,8 +475,6 @@ declare namespace KBEngine { const VECTOR3: DATATYPE_VECTOR3; const VECTOR4: DATATYPE_VECTOR4; const PYTHON: DATATYPE_PYTHON; - const PY_DICT: DATATYPE_PYTHON; - const PY_LIST: DATATYPE_PYTHON; const UNICODE: DATATYPE_UNICODE; const ENTITYCALL: DATATYPE_ENTITYCALL; const ENTITY_COMPONENT: DATATYPE_ENTITY_COMPONENT; @@ -451,17 +487,53 @@ declare namespace KBEngine { port: number; updateHZ: number; serverHeartbeatTick: number; - protocol: string; + isWss: boolean; + readonly protocol: string; forceBasePort: number; clientType: number; isOnInitCallPropertysSetMethods: boolean; } + const EventTypes: { + createAccount: string; + login: string; + logout: string; + reloginBaseapp: string; + bindAccountEmail: string; + newPassword: string; + onKicked: string; + onDisconnected: string; + onConnectionState: string; + onCreateAccountResult: string; + onVersionNotMatch: string; + onScriptVersionNotMatch: string; + onLoginFailed: string; + onLoginBaseapp: string; + onLoginBaseappFailed: string; + onReloginBaseapp: string; + onReloginBaseappSuccessfully: string; + onReloginBaseappFailed: string; + onEnterWorld: string; + onLeaveWorld: string; + onEnterSpace: string; + onLeaveSpace: string; + set_position: string; + set_direction: string; + updatePosition: string; + addSpaceGeometryMapping: string; + onSetSpaceData: string; + onDelSpaceData: string; + onControlled: string; + onLoseControlledEntity: string; + onStreamDataStarted: string; + onStreamDataRecv: string; + onStreamDataCompleted: string; + }; } declare namespace KBEngine { const moduledefs: {}; class KBEngineApp { - constructor(args: KBEngineArgs); args: KBEngineArgs; + constructor(args: KBEngineArgs); baseappIp: string; username: string; password: string; @@ -478,9 +550,16 @@ declare namespace KBEngine { baseappIP: string; baseappPort: number; baseappUdpPort: number; + currMsgID: number; + currMsgCount: number; + currMsgLen: number; + fragmentStream: any; + fragmentDatasFlag: number; + fragmentDatasRemain: number; socket: any; currserver: string; currstate: string; + currconnect: string; serverdatas: string; serverVersion: string; serverScriptVersion: string; @@ -502,6 +581,7 @@ declare namespace KBEngine { lastTickTime: number; lastTickCBTime: number; component: any; + msgStream: MemoryStream; resetSocket(): void; reset(): void; installEvents(): void; @@ -515,6 +595,8 @@ declare namespace KBEngine { onerror_before_onopen(evt: any): void; onerror_after_onopen(evt: any): void; onmessage(msg: any): void; + writeFragmentMessage(FragmentDataType: any, stream: MemoryStream, datasize: any): void; + mergeFragmentMessage(stream: MemoryStream): boolean | 0; onclose(): void; send(msg: any): void; close(): void; @@ -522,6 +604,7 @@ declare namespace KBEngine { Client_onAppActiveTickCB(): void; serverErr(id: any): string; Client_onImportServerErrorsDescr(stream: any): void; + Client_onImportClientSdk(stream: MemoryStream): void; onOpenLoginapp_login(): void; onOpenLoginapp_createAccount(): void; onImportClientMessagesCompleted(): void; @@ -531,11 +614,13 @@ declare namespace KBEngine { Client_onVersionNotMatch(stream: any): void; Client_onScriptVersionNotMatch(stream: any): void; onImportEntityDefCompleted(): void; + importClientMessages(stream: any): void; Client_onImportClientMessages(msg: any): void; createAccount(username: any, password: any, datas: any): void; createAccount_loginapp(noconnect: any): void; bindAccountEmail(emailAddress: any): void; newPassword(old_password: any, new_password: any): void; + logout(): void; login(username: any, password: any, datas: any): void; login_loginapp(noconnect: any): void; onOpenLoginapp_resetpassword(): void; @@ -605,7 +690,30 @@ declare namespace KBEngine { Client_onUpdateData_xyz_y(stream: any): void; Client_onUpdateData_xyz_p(stream: any): void; Client_onUpdateData_xyz_r(stream: any): void; - _updateVolatileData(entityID: any, x: any, y: any, z: any, yaw: any, pitch: any, roll: any, isOnGround: any): void; + Client_onUpdateData_ypr_optimized(stream: any): void; + Client_onUpdateData_yp_optimized(stream: any): void; + Client_onUpdateData_yr_optimized(stream: any): void; + Client_onUpdateData_pr_optimized(stream: any): void; + Client_onUpdateData_y_optimized(stream: any): void; + Client_onUpdateData_p_optimized(stream: any): void; + Client_onUpdateData_r_optimized(stream: any): void; + Client_onUpdateData_xz_optimized(stream: any): void; + Client_onUpdateData_xz_ypr_optimized(stream: any): void; + Client_onUpdateData_xz_yp_optimized(stream: any): void; + Client_onUpdateData_xz_yr_optimized(stream: any): void; + Client_onUpdateData_xz_pr_optimized(stream: any): void; + Client_onUpdateData_xz_y_optimized(stream: any): void; + Client_onUpdateData_xz_p_optimized(stream: any): void; + Client_onUpdateData_xz_r_optimized(stream: any): void; + Client_onUpdateData_xyz_optimized(stream: any): void; + Client_onUpdateData_xyz_ypr_optimized(stream: any): void; + Client_onUpdateData_xyz_yp_optimized(stream: any): void; + Client_onUpdateData_xyz_yr_optimized(stream: any): void; + Client_onUpdateData_xyz_pr_optimized(stream: any): void; + Client_onUpdateData_xyz_y_optimized(stream: any): void; + Client_onUpdateData_xyz_p_optimized(stream: any): void; + Client_onUpdateData_xyz_r_optimized(stream: any): void; + _updateVolatileData(entityID: any, x: any, y: any, z: any, yaw: any, pitch: any, roll: any, isOnGround: any, isOptimized?: boolean): void; Client_onStreamDataStarted(id: any, datasize: any, descr: any): void; Client_onStreamDataRecv(stream: any): void; Client_onStreamDataCompleted(id: any): void; @@ -618,6 +726,13 @@ declare namespace KBEngine { descr: string; id: number; } + const FragmentDataTypes: { + FRAGMENT_DATA_UNKNOW: number; + FRAGMENT_DATA_MESSAGE_ID: number; + FRAGMENT_DATA_MESSAGE_LENGTH: number; + FRAGMENT_DATA_MESSAGE_LENGTH1: number; + FRAGMENT_DATA_MESSAGE_BODY: number; + }; let app: KBEngineApp; function create(args: KBEngineArgs): void; function destroy(): void; diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index f3e7624..dfe4b76 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -1,7 +1,10 @@ var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -9,18 +12,23 @@ var __extends = (this && this.__extends) || (function () { }; })(); /** - * KBEngine的html5客户端扩展ts版 1.x版本 + * KBEngine的html5客户端扩展ts版 2.x版本 * cocos creator 环境下使用方法 - * 将bin/kbengine.js导入为插件,将bin/kbengine.d.ts放在项目根目录下,即可 + * 将bin/js导入为插件,将bin/d.ts放在项目根目录下,即可 * * todo 未完成内容 * 1、强类型匹配 * 2、代码注释 * * 注:(下面的是重点) - * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 KBEngine['Entities'] = KBEngine['Entities'] || {};KBEngine['Entities']['你的实体类名']=你的实体类名;将声明提升至全局 - * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; + * 1、实体声明的命名空间为Entities,与官方的KBEngine不同 + * 2、cocos creator环境下,实体类声明完成后,需要类声明时加上@registerEntity('你的类名'),用于将变量提升至全局,加入下方一段用于代码提示 + * declare global{ + namespace Entities{ + class 类名 extends 类{} + } + } + * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends Entity{}; * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ /*----------------------------------------------------------------------------------------- @@ -35,6 +43,8 @@ var KBEngine; KBEngine.PACKET_MAX_SIZE_UDP = 1472; KBEngine.MESSAGE_ID_LENGTH = 2; KBEngine.MESSAGE_LENGTH_LENGTH = 2; + KBEngine.MESSAGE_LENGTH1_LENGTH = 4; + KBEngine.MESSAGE_MAX_SIZE = 65535; KBEngine.CLIENT_NO_FLOAT = 0; KBEngine.KBE_FLT_MAX = 3.402823466e+38; })(KBEngine || (KBEngine = {})); @@ -42,6 +52,23 @@ var KBEngine; * 加上声明避免cocos creator编辑器报错 */ window['KBEngine'] = KBEngine; +if (!ArrayBuffer['transfer']) { + ArrayBuffer['transfer'] = function (source, length) { + var dest = new ArrayBuffer(length); + if (!(source instanceof ArrayBuffer) || !(dest instanceof ArrayBuffer)) { + throw new TypeError("ArrayBuffer.transfer, error: Source and destination must be ArrayBuffer instances"); + } + if (dest.byteLength >= source.byteLength) { + var buf = new Uint8Array(dest); + buf.set(new Uint8Array(source), 0); + } + else { + throw new RangeError("ArrayBuffer.transfer, error: destination has not enough space"); + } + return dest; + }; +} +; /*----------------------------------------------------------------------------------------- number64bits -----------------------------------------------------------------------------------------*/ @@ -218,15 +245,26 @@ window['KBEngine'] = KBEngine; (function (KBEngine) { var EventInfo = /** @class */ (function () { function EventInfo(classinst, callbackfn) { - this.callbackfn = callbackfn; this.classinst = classinst; + this.callbackfn = callbackfn; } return EventInfo; }()); KBEngine.EventInfo = EventInfo; + var FiredEvent = /** @class */ (function () { + function FiredEvent(evtName, evtInfo, ars) { + this.evtName = evtName; + this.evtInfo = evtInfo; + this.ars = ars; + } + return FiredEvent; + }()); + KBEngine.FiredEvent = FiredEvent; var Events = /** @class */ (function () { function Events() { this._events = {}; + this._isPause = false; + this._firedEvents = []; } Events.prototype.register = function (evtName, classinst, strCallback) { var callbackfn = classinst[strCallback]; @@ -242,22 +280,46 @@ window['KBEngine'] = KBEngine; var info = new EventInfo(classinst, callbackfn); evtlst.push(info); }; - Events.prototype.deregister = function (evtName, classinst) { + Events.prototype.deregisterAll = function (classinst) { for (var itemkey in this._events) { - var evtlst = this._events[itemkey]; - while (true) { - var found = false; - for (var i = 0; i < evtlst.length; i++) { - var info = evtlst[i]; - if (info.classinst == classinst) { - evtlst.splice(i, 1); - found = true; - break; - } + this.deregister(itemkey, classinst); + } + }; + Events.prototype.deregister = function (evtName, classinst) { + var evtlst = this._events[evtName]; + if (!evtlst) + return; + while (true) { + var found = false; + for (var i = 0; i < evtlst.length; i++) { + var info = evtlst[i]; + if (info.classinst == classinst) { + evtlst.splice(i, 1); + found = true; + break; } - if (!found) + } + if (!found) + break; + } + }; + Events.prototype.removeAllFiredEvent = function (classinst) { + this.removeFiredEvent("", classinst); + }; + Events.prototype.removeFiredEvent = function (evtName, classinst) { + var firedEvents = this._firedEvents; + while (true) { + var found = false; + for (var i = 0; i < firedEvents.length; i++) { + var evt = firedEvents[i]; + if ((evtName == "" || evt.evtName == evtName) && evt.evtInfo.classinst == classinst) { + firedEvents.splice(i, 1); + found = true; break; + } } + if (!found) + break; } }; Events.prototype.fire = function (evtName) { @@ -278,7 +340,13 @@ window['KBEngine'] = KBEngine; // ars.push(args[i]); for (var i = 0; i < evtlst.length; i++) { var info = evtlst[i]; - info.callbackfn.apply(info.classinst, args || []); + if (!this._isPause) { + info.callbackfn.apply(info.classinst, args || []); + } + else { + var eobj = new FiredEvent(evtName, info, args || []); + this._firedEvents.push(eobj); + } // if (args.length < 1) { // info.callbackfn.apply(info.classinst); // } @@ -287,6 +355,28 @@ window['KBEngine'] = KBEngine; // } } }; + Events.prototype.pasue = function () { + this._isPause = true; + }; + Events.prototype.resume = function () { + this._isPause = false; + var firedEvents = this._firedEvents; + while (firedEvents.length > 0) { + var evt = firedEvents.shift(); + var info = evt.evtInfo; + var ars = evt.ars; + if (ars.length < 1) { + info.callbackfn.apply(info.classinst); + } + else { + info.callbackfn.apply(info.classinst, ars); + } + } + }; + Events.prototype.clear = function () { + this._events = {}; + this._firedEvents.splice(0, this._firedEvents.length); + }; return Events; }()); KBEngine.Events = Events; @@ -296,6 +386,19 @@ window['KBEngine'] = KBEngine; memorystream -----------------------------------------------------------------------------------------*/ (function (KBEngine) { + var PackFloatXType = /** @class */ (function () { + function PackFloatXType() { + this._unionData = new ArrayBuffer(4); + this.fv = new Float32Array(this._unionData, 0, 1); + this.uv = new Uint32Array(this._unionData, 0, 1); + this.iv = new Int32Array(this._unionData, 0, 1); + } + return PackFloatXType; + }()); + KBEngine.PackFloatXType = PackFloatXType; + KBEngine._xPackData = new PackFloatXType(); + KBEngine._yPackData = new PackFloatXType(); + KBEngine._zPackData = new PackFloatXType(); var MemoryStream = /** @class */ (function () { function MemoryStream(size_or_buffer) { this.rpos = 0; @@ -328,7 +431,9 @@ window['KBEngine'] = KBEngine; return v; }; MemoryStream.prototype.readInt64 = function () { - return new KBEngine.INT64(this.readUint32(), this.readUint32()); + var lo = this.readUint32(); + var hi = this.readUint32(); + return new KBEngine.INT64(lo, hi); }; MemoryStream.prototype.readUint8 = function () { var buf = new Uint8Array(this.buffer, this.rpos, 1); @@ -346,7 +451,9 @@ window['KBEngine'] = KBEngine; return (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0]; }; MemoryStream.prototype.readUint64 = function () { - return new KBEngine.UINT64(this.readUint32(), this.readUint32()); + var lo = this.readUint32(); + var hi = this.readUint32(); + return new KBEngine.UINT64(lo, hi); }; MemoryStream.prototype.readFloat = function () { var buf; @@ -402,8 +509,8 @@ window['KBEngine'] = KBEngine; return new MemoryStream(buf); }; MemoryStream.prototype.readPackXZ = function () { - var xPackData = new MemoryStream.PackFloatXType(); - var zPackData = new MemoryStream.PackFloatXType(); + var xPackData = KBEngine._xPackData; + var zPackData = KBEngine._zPackData; xPackData.fv[0] = 0.0; zPackData.fv[0] = 0.0; xPackData.uv[0] = 0x40000000; @@ -428,7 +535,12 @@ window['KBEngine'] = KBEngine; }; MemoryStream.prototype.readPackY = function () { var v = this.readUint16(); - return v; + var yPackData = KBEngine._yPackData; + yPackData.uv[0] = 0x40000000; + yPackData.uv[0] |= (v & 0x7fff) << 12; + yPackData.fv[0] -= 2.0; + yPackData.uv[0] |= (v & 0x8000) << 16; + return yPackData.fv[0]; }; //--------------------------------------------------------------------------------- MemoryStream.prototype.writeInt8 = function (v) { @@ -526,6 +638,14 @@ window['KBEngine'] = KBEngine; buf[i++] = 0; this.wpos += i; }; + MemoryStream.prototype.append = function (stream, offset, size) { + if (size > this.space()) { + this.buffer = ArrayBuffer['transfer'](this.buffer, this.buffer.byteLength + size * 2); + } + var buf = new Uint8Array(this.buffer, this.wpos, size); + buf.set(new Uint8Array(stream.buffer, offset, size), 0); + this.wpos += size; + }; //--------------------------------------------------------------------------------- MemoryStream.prototype.readSkip = function (v) { this.rpos += v; @@ -547,13 +667,33 @@ window['KBEngine'] = KBEngine; this.rpos = this.wpos; }; //--------------------------------------------------------------------------------- - MemoryStream.prototype.getbuffer = function (v) { + MemoryStream.prototype.getbuffer = function () { return this.buffer.slice(this.rpos, this.wpos); }; + MemoryStream.prototype.setbuffer = function (buffer) { + this.clear(); + this.buffer = buffer; + }; + MemoryStream.prototype.size = function () { + return this.buffer.byteLength; + }; + MemoryStream.prototype.clear = function () { + this.rpos = this.wpos = 0; + if (this.buffer.byteLength > KBEngine.PACKET_MAX_SIZE) { + this.buffer = new ArrayBuffer(KBEngine.PACKET_MAX_SIZE); + } + }; + MemoryStream.prototype.reclaimObject = function () { + this.clear(); + if (MemoryStream._objects != undefined) { + MemoryStream._objects.push(this); + } + }; return MemoryStream; }()); KBEngine.MemoryStream = MemoryStream; (function (MemoryStream) { + MemoryStream._objects = []; var PackFloatXType = /** @class */ (function () { function PackFloatXType() { this._unionData = new ArrayBuffer(4); @@ -565,6 +705,10 @@ window['KBEngine'] = KBEngine; return PackFloatXType; }()); MemoryStream.PackFloatXType = PackFloatXType; + function createObject() { + return MemoryStream._objects.length > 0 ? MemoryStream._objects.pop() : new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); + } + MemoryStream.createObject = createObject; })(MemoryStream = KBEngine.MemoryStream || (KBEngine.MemoryStream = {})); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- @@ -578,8 +722,11 @@ window['KBEngine'] = KBEngine; this.messageLengthBuffer = null; this.msgtype = null; this.messageLength = 0; - this.stream = new KBEngine.MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); + this.stream = KBEngine.MemoryStream.createObject(); } + Bundle.createObject = function () { + return Bundle._objects.length > 0 ? Bundle._objects.pop() : new Bundle(); + }; //--------------------------------------------------------------------------------- Bundle.prototype.newMessage = function (msgtype) { this.fini(false); @@ -609,6 +756,7 @@ window['KBEngine'] = KBEngine; this.writeMsgLength(this.messageLength); if (this.stream) this.memorystreams.push(this.stream); + this.stream = KBEngine.MemoryStream.createObject(); } if (issend) { this.messageLengthBuffer = null; @@ -620,17 +768,16 @@ window['KBEngine'] = KBEngine; Bundle.prototype.send = function (network) { this.fini(true); for (var i = 0; i < this.memorystreams.length; i++) { - var stream = this.memorystreams[i]; - network.send(stream.getbuffer()); + var tmpStream = this.memorystreams[i]; + network.send(tmpStream.getbuffer()); } - this.memorystreams = new Array(); - this.stream = new KBEngine.MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); + this.reclaimObject(); }; //--------------------------------------------------------------------------------- Bundle.prototype.checkStream = function (v) { if (v > this.stream.space()) { this.memorystreams.push(this.stream); - this.stream = new KBEngine.MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); + this.stream = KBEngine.MemoryStream.createObject(); } this.messageLength += v; }; @@ -683,6 +830,27 @@ window['KBEngine'] = KBEngine; this.checkStream(v.length + 4); this.stream.writeBlob(v); }; + Bundle.prototype.clear = function () { + for (var i = 0; i < this.memorystreams.length; i++) { + if (this.stream != this.memorystreams[i]) + this.memorystreams[i].reclaimObject(); + } + if (this.stream) + this.stream.clear(); + else + this.stream = KBEngine.MemoryStream.createObject(); + this.memorystreams = new Array(); + this.numMessage = 0; + this.messageLengthBuffer = null; + this.messageLength = 0; + this.msgtype = null; + }; + Bundle.prototype.reclaimObject = function () { + this.clear(); + if (Bundle._objects != undefined) + Bundle._objects.push(this); + }; + Bundle._objects = []; return Bundle; }()); KBEngine.Bundle = Bundle; @@ -740,6 +908,7 @@ window['KBEngine'] = KBEngine; KBEngine.datatype2id["VECTOR4"] = 17; KBEngine.datatype2id["FIXED_DICT"] = 18; KBEngine.datatype2id["ARRAY"] = 19; + KBEngine.datatype2id["ENTITYCALL"] = 20; } KBEngine.mappingDataType = mappingDataType; mappingDataType(); @@ -782,16 +951,16 @@ window['KBEngine'] = KBEngine; } KBEngine.bindReader = bindReader; var Message = /** @class */ (function () { - function Message(id, name, length, argstype, args, handler) { + function Message(id, name, length, argsType, args, handler) { this.id = id; this.name = name; this.length = length; - this.argsType = argstype; + this.argsType = argsType; + this.args = args; + this.handler = handler; for (var i = 0; i < args.length; i++) { args[i] = bindReader(args[i]); } - this.args = args; - this.handler = handler; } Message.prototype.createFromStream = function (msgstream) { if (this.args.length <= 0) @@ -879,6 +1048,9 @@ window['KBEngine'] = KBEngine; this.x = x; this.y = y; this.z = z; + this.x = x; + this.y = y; + this.z = z; } Vector3.prototype.distance = function (pos) { var x = pos.x - this.x; @@ -924,15 +1096,16 @@ window['KBEngine'] = KBEngine; return Vector3; }()); KBEngine.Vector3 = Vector3; - /** - * todo 这个类的第四个参数的没搞清楚,所有如果没有必要,不要用这个东西 - */ var Vector4 = /** @class */ (function () { function Vector4(x, y, z, w) { this.x = x; this.y = y; this.z = z; this.w = w; + this.x = x; + this.y = y; + this.z = z; + this.w = w; } Vector4.prototype.distance = function (pos) { var x = pos.x - this.x; @@ -1206,6 +1379,13 @@ window['KBEngine'] = KBEngine; return Entity; }()); KBEngine.Entity = Entity; + function registerEntity(name) { + return function (ctor) { + KBEngine['Entities'] = KBEngine['Entities'] || {}; + KBEngine['Entities'][name] = ctor; + }; + } + KBEngine.registerEntity = registerEntity; })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- EntityCall @@ -1236,7 +1416,7 @@ window['KBEngine'] = KBEngine; }; EntityCall.prototype.newCall = function () { if (this.bundle == null) - this.bundle = new KBEngine.Bundle(); + this.bundle = KBEngine.Bundle.createObject(); if (this.type == KBEngine.ENTITYCALL_TYPE_CELL) this.bundle.newMessage(KBEngine.messages['Baseapp_onRemoteCallCellMethodFromClient']); else @@ -1513,10 +1693,14 @@ window['KBEngine'] = KBEngine; }; DATATYPE_VECTOR2.prototype.createFromStream = function (stream) { if (KBEngine.CLIENT_NO_FLOAT) { - return new KBEngine.Vector2(KBEngine.reader.readInt32.call(stream), KBEngine.reader.readInt32.call(stream)); + var x = KBEngine.reader.readInt32.call(stream); + var y = KBEngine.reader.readInt32.call(stream); + return new KBEngine.Vector2(x, y); } else { - return new KBEngine.Vector2(KBEngine.reader.readFloat.call(stream), KBEngine.reader.readFloat.call(stream)); + var x = KBEngine.reader.readFloat.call(stream); + var y = KBEngine.reader.readFloat.call(stream); + return new KBEngine.Vector2(x, y); } }; DATATYPE_VECTOR2.prototype.addToStream = function (stream, v) { @@ -1814,8 +1998,8 @@ window['KBEngine'] = KBEngine; datatypes.VECTOR3 = new DATATYPE_VECTOR3(); datatypes.VECTOR4 = new DATATYPE_VECTOR4(); datatypes.PYTHON = new DATATYPE_PYTHON(); - datatypes.PY_DICT = new DATATYPE_PYTHON(); - datatypes.PY_LIST = new DATATYPE_PYTHON(); + // export const PY_DICT = new DATATYPE_PYTHON(); + // export const PY_LIST = new DATATYPE_PYTHON(); datatypes.UNICODE = new DATATYPE_UNICODE(); datatypes.ENTITYCALL = new DATATYPE_ENTITYCALL(); datatypes.ENTITY_COMPONENT = new DATATYPE_ENTITY_COMPONENT(); @@ -1833,17 +2017,137 @@ window['KBEngine'] = KBEngine; this.port = 20013; this.updateHZ = 100; this.serverHeartbeatTick = 15; - //TODO wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 - this.protocol = "ws://"; + this.isWss = false; this.forceBasePort = 0; - // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types + // Reference: http://github.io/docs/programming/clientsdkprogramming.html, client types this.clientType = 5; // 在Entity初始化时是否触发属性的set_*事件(callPropertysSetMethods) this.isOnInitCallPropertysSetMethods = true; } + Object.defineProperty(KBEngineArgs.prototype, "protocol", { + //TODO wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 + get: function () { return this.isWss ? "wss://" : "ws://"; }, + enumerable: true, + configurable: true + }); return KBEngineArgs; }()); KBEngine.KBEngineArgs = KBEngineArgs; + KBEngine.EventTypes = { + // Create new account. + // param1(string): accountName + // param2(string): password + // param3(bytes): datas // Datas by user defined. Data will be recorded into the KBE account database, you can access the datas through the script layer. If you use third-party account system, datas will be submitted to the third-party system. + createAccount: "createAccount", + // Login to server. + // param1(string): accountName + // param2(string): password + // param3(bytes): datas // Datas by user defined. Data will be recorded into the KBE account database, you can access the datas through the script layer. If you use third-party account system, datas will be submitted to the third-party system. + login: "login", + // Logout to baseapp, called when exiting the client. + logout: "logout", + // Relogin to baseapp. + reloginBaseapp: "reloginBaseapp", + // Request server binding account Email. + // param1(string): emailAddress + bindAccountEmail: "bindAccountEmail", + // Request to set up a new password for the account. Note: account must be online. + // param1(string): old_password + // param2(string): new_password + newPassword: "newPassword", + // ------------------------------------连接相关------------------------------------ + // Kicked of the current server. + // param1(uint16): retcode. // server_errors + onKicked: "onKicked", + // Disconnected from the server. + onDisconnected: "onDisconnected", + // Status of connection server. + // param1(bool): success or fail + onConnectionState: "onConnectionState", + // ------------------------------------logon相关------------------------------------ + // Create account feedback results. + // param1(uint16): retcode. // server_errors + // param2(bytes): datas. // If you use third-party account system, the system may fill some of the third-party additional datas. + onCreateAccountResult: "onCreateAccountResult", + // Engine version mismatch. + // param1(string): clientVersion + // param2(string): serverVersion + onVersionNotMatch: "onVersionNotMatch", + // script version mismatch. + // param1(string): clientScriptVersion + // param2(string): serverScriptVersion + onScriptVersionNotMatch: "onScriptVersionNotMatch", + // Login failed. + // param1(uint16): retcode. // server_errors + onLoginFailed: "onLoginFailed", + // Login to baseapp. + onLoginBaseapp: "onLoginBaseapp", + // Login baseapp failed. + // param1(uint16): retcode. // server_errors + onLoginBaseappFailed: "onLoginBaseappFailed", + // Relogin to baseapp. + onReloginBaseapp: "onReloginBaseapp", + // Relogin baseapp success. + onReloginBaseappSuccessfully: "onReloginBaseappSuccessfully", + // Relogin baseapp failed. + // param1(uint16): retcode. // server_errors + onReloginBaseappFailed: "onReloginBaseappFailed", + // ------------------------------------实体cell相关事件------------------------------------ + // Entity enter the client-world. + // param1: Entity + onEnterWorld: "onEnterWorld", + // Entity leave the client-world. + // param1: Entity + onLeaveWorld: "onLeaveWorld", + // Player enter the new space. + // param1: Entity + onEnterSpace: "onEnterSpace", + // Player leave the space. + // param1: Entity + onLeaveSpace: "onLeaveSpace", + // Sets the current position of the entity. + // param1: Entity + set_position: "set_position", + // Sets the current direction of the entity. + // param1: Entity + set_direction: "set_direction", + // The entity position is updated, you can smooth the moving entity to new location. + // param1: Entity + updatePosition: "updatePosition", + // The current space is specified by the geometry mapping. + // Popular said is to load the specified Map Resources. + // param1(string): resPath + addSpaceGeometryMapping: "addSpaceGeometryMapping", + // Server spaceData set data. + // param1(int32): spaceID + // param2(string): key + // param3(string): value + onSetSpaceData: "onSetSpaceData", + // Start downloading data. + // param1(int32): rspaceID + // param2(string): key + onDelSpaceData: "onDelSpaceData", + // Triggered when the entity is controlled or out of control. + // param1: Entity + // param2(bool): isControlled + onControlled: "onControlled", + // Lose controlled entity. + // param1: Entity + onLoseControlledEntity: "onLoseControlledEntity", + // ------------------------------------数据下载相关------------------------------------ + // Start downloading data. + // param1(uint16): resouce id + // param2(uint32): data size + // param3(string): description + onStreamDataStarted: "onStreamDataStarted", + // Receive data. + // param1(uint16): resouce id + // param2(bytes): datas + onStreamDataRecv: "onStreamDataRecv", + // The downloaded data is completed. + // param1(uint16): resouce id + onStreamDataCompleted: "onStreamDataCompleted", + }; })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- KBEngine app @@ -1852,7 +2156,7 @@ window['KBEngine'] = KBEngine; KBEngine.moduledefs = {}; var KBEngineApp = /** @class */ (function () { function KBEngineApp(args) { - // console.assert(app == null || app == undefined, "Assertion of app not is null"); + this.args = args; this.username = "testhtml51"; this.password = "123456"; this.clientdatas = ""; @@ -1871,7 +2175,14 @@ window['KBEngine'] = KBEngine; this.baseappIP = ''; this.baseappPort = 0; this.baseappUdpPort = 0; + this.currMsgID = 0; + this.currMsgCount = 0; + this.currMsgLen = 0; + this.fragmentStream = null; + this.fragmentDatasFlag = KBEngine.FragmentDataTypes.FRAGMENT_DATA_UNKNOW; + this.fragmentDatasRemain = 0; this.currstate = "create"; + this.currconnect = 'loginapp'; // 扩展数据 this.serverdatas = ""; // 版本信息 @@ -1898,9 +2209,10 @@ window['KBEngine'] = KBEngine; this.isLoadedGeometry = false; this.lastTickTime = Date.now(); this.lastTickCBTime = Date.now(); + this.msgStream = new KBEngine.MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); this.entityclass = {}; + // console.assert(app == null || app == undefined, "Assertion of app not is null"); KBEngine.app = this; - this.args = args; } KBEngineApp.prototype.resetSocket = function () { try { @@ -1924,6 +2236,7 @@ window['KBEngine'] = KBEngine; KBEngine.app.resetSocket(); KBEngine.app.currserver = "loginapp"; KBEngine.app.currstate = "create"; + KBEngine.app.currconnect = 'loginapp'; // 扩展数据 KBEngine.app.serverdatas = ""; // 版本信息 @@ -1956,19 +2269,23 @@ window['KBEngine'] = KBEngine; KBEngine.app.component = "client"; }; KBEngineApp.prototype.installEvents = function () { - KBEngine.Event.register("createAccount", KBEngine.app, "createAccount"); - KBEngine.Event.register("login", KBEngine.app, "login"); - KBEngine.Event.register("reloginBaseapp", KBEngine.app, "reloginBaseapp"); - KBEngine.Event.register("bindAccountEmail", KBEngine.app, "bindAccountEmail"); - KBEngine.Event.register("newPassword", KBEngine.app, "newPassword"); + KBEngine.Event.register(KBEngine.EventTypes.createAccount, KBEngine.app, "createAccount"); + KBEngine.Event.register(KBEngine.EventTypes.login, KBEngine.app, "login"); + KBEngine.Event.register(KBEngine.EventTypes.logout, KBEngine.app, 'logout'); + KBEngine.Event.register(KBEngine.EventTypes.reloginBaseapp, KBEngine.app, "reloginBaseapp"); + KBEngine.Event.register(KBEngine.EventTypes.bindAccountEmail, KBEngine.app, "bindAccountEmail"); + KBEngine.Event.register(KBEngine.EventTypes.newPassword, KBEngine.app, "newPassword"); }; KBEngineApp.prototype.uninstallEvents = function () { - KBEngine.Event.deregister("reloginBaseapp", KBEngine.app); - KBEngine.Event.deregister("login", KBEngine.app); - KBEngine.Event.deregister("createAccount", KBEngine.app); + KBEngine.Event.deregister(KBEngine.EventTypes.createAccount, KBEngine.app); + KBEngine.Event.deregister(KBEngine.EventTypes.login, KBEngine.app); + KBEngine.Event.deregister(KBEngine.EventTypes.logout, KBEngine.app); + KBEngine.Event.deregister(KBEngine.EventTypes.reloginBaseapp, KBEngine.app); + KBEngine.Event.deregister(KBEngine.EventTypes.bindAccountEmail, KBEngine.app); + KBEngine.Event.deregister(KBEngine.EventTypes.newPassword, KBEngine.app); }; KBEngineApp.prototype.hello = function () { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); if (KBEngine.app.currserver == "loginapp") bundle.newMessage(KBEngine.messages['Loginapp_hello']); else @@ -1993,7 +2310,7 @@ window['KBEngine'] = KBEngine; } catch (e) { KBEngine.ERROR_MSG('WebSocket init error!'); - KBEngine.Event.fire("onConnectionState", false); + KBEngine.Event.fire(KBEngine.EventTypes.onConnectionState, false); return; } KBEngine.app.socket.binaryType = "arraybuffer"; @@ -2008,48 +2325,137 @@ window['KBEngine'] = KBEngine; KBEngineApp.prototype.onopen = function () { KBEngine.INFO_MSG('connect success!'); KBEngine.app.socket.onerror = KBEngine.app.onerror_after_onopen; - KBEngine.Event.fire("onConnectionState", true); + KBEngine.Event.fire(KBEngine.EventTypes.onConnectionState, true); }; KBEngineApp.prototype.onerror_before_onopen = function (evt) { KBEngine.ERROR_MSG('connect error:' + evt.data); KBEngine.app.resetSocket(); - KBEngine.Event.fire("onConnectionState", false); + KBEngine.Event.fire(KBEngine.EventTypes.onConnectionState, false); }; KBEngineApp.prototype.onerror_after_onopen = function (evt) { KBEngine.ERROR_MSG('connect error:' + evt.data); KBEngine.app.resetSocket(); - KBEngine.Event.fire("onDisconnected"); + KBEngine.Event.fire(KBEngine.EventTypes.onDisconnected); }; KBEngineApp.prototype.onmessage = function (msg) { - var stream = new KBEngine.MemoryStream(msg.data); + var stream = KBEngine.app.msgStream; + stream.setbuffer(msg.data); stream.wpos = msg.data.byteLength; - while (stream.rpos < stream.wpos) { - var msgid = stream.readUint16(); - var msgHandler = KBEngine.clientmessages[msgid]; - if (!msgHandler) { - KBEngine.ERROR_MSG("KBEngineApp::onmessage[" + KBEngine.app.currserver + "]: not found msg(" + msgid + ")!"); - } - else { + while (stream.length() > 0 || KBEngine.app.fragmentStream != null) { + if (KBEngine.app.fragmentDatasFlag == KBEngine.FragmentDataTypes.FRAGMENT_DATA_UNKNOW) { + if (KBEngine.app.currMsgID == 0) { + if (KBEngine.MESSAGE_ID_LENGTH > 1 && stream.length() < KBEngine.MESSAGE_ID_LENGTH) { + KBEngine.app.writeFragmentMessage(KBEngine.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_ID, stream, KBEngine.MESSAGE_ID_LENGTH); + break; + } + KBEngine.app.currMsgID = stream.readUint16(); + } + var msgHandler = KBEngine.clientmessages[KBEngine.app.currMsgID]; + if (!msgHandler) { + KBEngine.app.currMsgID = 0; + KBEngine.app.currMsgLen = 0; + KBEngine.ERROR_MSG("KBEngineApp::onmessage[" + KBEngine.app.currserver + "]: not found msg(" + KBEngine.app.currMsgID + ")!"); + break; + } var msglen = msgHandler.length; - if (msglen == -1) { - msglen = stream.readUint16(); - // 扩展长度 - if (msglen == 65535) - msglen = stream.readUint32(); + if (KBEngine.app.currMsgLen == 0) { + if (msglen == -1) { + if (stream.length() < KBEngine.MESSAGE_LENGTH_LENGTH) { + KBEngine.app.writeFragmentMessage(KBEngine.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH, stream, KBEngine.MESSAGE_LENGTH_LENGTH); + break; + } + else { + msglen = stream.readUint16(); + KBEngine.app.currMsgLen = msglen; + // 扩展长度 + if (msglen == KBEngine.MESSAGE_MAX_SIZE) { + if (stream.length() < KBEngine.MESSAGE_LENGTH1_LENGTH) { + KBEngine.app.writeFragmentMessage(KBEngine.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH1, stream, KBEngine.MESSAGE_LENGTH1_LENGTH); + break; + } + KBEngine.app.currMsgLen = stream.readUint32(); + } + } + } + else { + KBEngine.app.currMsgLen = msglen; + } } - var wpos = stream.wpos; - var rpos = stream.rpos + msglen; - stream.wpos = rpos; - msgHandler.handleMessage(stream); - stream.wpos = wpos; - stream.rpos = rpos; + if (KBEngine.app.fragmentStream != null && KBEngine.app.fragmentStream.length() >= KBEngine.app.currMsgLen) { + msgHandler.handleMessage(KBEngine.app.fragmentStream); + KBEngine.app.fragmentStream = null; + } + else if (stream.length() < KBEngine.app.currMsgLen && stream.length() > 0) { + KBEngine.app.writeFragmentMessage(KBEngine.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY, stream, KBEngine.app.currMsgLen); + break; + } + else { + var wpos = stream.wpos; + var rpos = stream.rpos + msglen; + stream.wpos = rpos; + msgHandler.handleMessage(stream); + stream.wpos = wpos; + stream.rpos = rpos; + } + KBEngine.app.currMsgID = 0; + KBEngine.app.currMsgLen = 0; + KBEngine.app.fragmentStream = null; + } + else { + if (KBEngine.app.mergeFragmentMessage(stream)) + break; } } }; + KBEngineApp.prototype.writeFragmentMessage = function (FragmentDataType, stream, datasize) { + var opsize = stream.length(); + KBEngine.app.fragmentDatasRemain = datasize - opsize; + KBEngine.app.fragmentDatasFlag = FragmentDataType; + KBEngine.app.fragmentStream = stream; + }; + KBEngineApp.prototype.mergeFragmentMessage = function (stream) { + var opsize = stream.length(); + if (opsize == 0) + return 0; + var fragmentStream = KBEngine.app.fragmentStream; + // console.assert(fragmentStream != null); + if (opsize >= KBEngine.app.fragmentDatasRemain) { + fragmentStream.append(stream, stream.rpos, KBEngine.app.fragmentDatasRemain); + switch (KBEngine.app.fragmentDatasFlag) { + case KBEngine.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_ID: + KBEngine.app.currMsgID = fragmentStream.readUint16(); + KBEngine.app.fragmentStream = null; + break; + case KBEngine.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH: + KBEngine.app.currMsgLen = fragmentStream.readUint16(); + KBEngine.app.fragmentStream = null; + break; + case KBEngine.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH1: + KBEngine.app.currMsgLen = fragmentStream.readUint32(); + KBEngine.app.fragmentStream = null; + break; + case KBEngine.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY: + default: + break; + } + stream.rpos += KBEngine.app.fragmentDatasRemain; + KBEngine.app.fragmentDatasFlag = KBEngine.FragmentDataTypes.FRAGMENT_DATA_UNKNOW; + KBEngine.app.fragmentDatasRemain = 0; + return false; + } + else { + fragmentStream.append(stream, stream.rpos, opsize); + KBEngine.app.fragmentDatasRemain -= opsize; + stream.done(); + return true; + } + }; KBEngineApp.prototype.onclose = function () { KBEngine.INFO_MSG('connect close:' + KBEngine.app.currserver); + if (KBEngine.app.currconnect != KBEngine.app.currstate) + return; KBEngine.app.resetSocket(); - KBEngine.Event.fire("onDisconnected"); + KBEngine.Event.fire(KBEngine.EventTypes.onDisconnected); //if(app.currserver != "loginapp") // app.reset(); }; @@ -2065,7 +2471,7 @@ window['KBEngine'] = KBEngine; if (KBEngine.app.socket == null) return; var dateObject = new Date(); - if ((dateObject.getTime() - KBEngine.app.lastTickTime) / 1000 > KBEngine.app.args.serverHeartbeatTick) { + if ((dateObject.getTime() - KBEngine.app.lastTickTime) / 1000 > KBEngine.app.args.serverHeartbeatTick / 2) { // 如果心跳回调接收时间小于心跳发送时间,说明没有收到回调 // 此时应该通知客户端掉线了 if (KBEngine.app.lastTickCBTime < KBEngine.app.lastTickTime) { @@ -2074,14 +2480,14 @@ window['KBEngine'] = KBEngine; } if (KBEngine.app.currserver == "loginapp") { if (KBEngine.messages['Loginapp_onClientActiveTick'] != undefined) { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Loginapp_onClientActiveTick']); bundle.send(KBEngine.app); } } else { if (KBEngine.messages['Baseapp_onClientActiveTick'] != undefined) { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Baseapp_onClientActiveTick']); bundle.send(KBEngine.app); } @@ -2091,8 +2497,8 @@ window['KBEngine'] = KBEngine; KBEngine.app.updatePlayerToServer(); }; KBEngineApp.prototype.Client_onAppActiveTickCB = function () { - var dateObject = new Date(); - KBEngine.app.lastTickCBTime = dateObject.getTime(); + // let dateObject = new Date(); + KBEngine.app.lastTickCBTime = Date.now(); //dateObject.getTime(); }; KBEngineApp.prototype.serverErr = function (id) { var e = KBEngine.app.serverErrs[id]; @@ -2113,13 +2519,20 @@ window['KBEngine'] = KBEngine; KBEngine.INFO_MSG("Client_onImportServerErrorsDescr: id=" + e.id + ", name=" + e.name + ", descr=" + e.descr); } }; + KBEngineApp.prototype.Client_onImportClientSdk = function (stream) { + var remainingFiles = stream.readInt32(); + var fileName = stream.readString(); + var fileSize = stream.readInt32(); + var fileDatas = stream.readBlob(); + KBEngine.Event.fire("onImportClientSDK", remainingFiles, fileName, fileSize, fileDatas); + }; KBEngineApp.prototype.onOpenLoginapp_login = function () { KBEngine.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"); - KBEngine.Event.fire("onConnectionState", true); + KBEngine.Event.fire(KBEngine.EventTypes.onConnectionState, true); KBEngine.app.currserver = "loginapp"; KBEngine.app.currstate = "login"; if (!KBEngine.app.loginappMessageImported) { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages.Loginapp_importClientMessages); bundle.send(KBEngine.app); KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; @@ -2136,7 +2549,7 @@ window['KBEngine'] = KBEngine; KBEngine.app.currserver = "loginapp"; KBEngine.app.currstate = "createAccount"; if (!KBEngine.app.loginappMessageImported) { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages.Loginapp_importClientMessages); bundle.send(KBEngine.app); KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; @@ -2155,7 +2568,7 @@ window['KBEngine'] = KBEngine; if (!KBEngine.app.serverErrorsDescrImported) { KBEngine.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"); KBEngine.app.serverErrorsDescrImported = true; - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Loginapp_importServerErrorsDescr']); bundle.send(KBEngine.app); } @@ -2171,7 +2584,7 @@ window['KBEngine'] = KBEngine; KBEngine.app.baseappMessageImported = true; if (!KBEngine.app.entitydefImported) { KBEngine.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ..."); - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages.Baseapp_importClientEntityDef); bundle.send(KBEngine.app); KBEngine.Event.fire("Baseapp_importClientEntityDef"); @@ -2238,7 +2651,7 @@ window['KBEngine'] = KBEngine; }; KBEngineApp.prototype.Client_onImportClientEntityDef = function (stream) { KBEngine.app.createDataTypeFromStreams(stream, true); - while (!stream.readEOF()) { + while (stream.length() > 0) { var scriptmodule_name = stream.readString(); var scriptUtype = stream.readUint16(); var propertysize = stream.readUint16(); @@ -2259,12 +2672,7 @@ window['KBEngine'] = KBEngine; var self_methods = currModuleDefs["methods"]; var self_base_methods = currModuleDefs["base_methods"]; var self_cell_methods = currModuleDefs["cell_methods"]; - try { - var Class = KBEngine['Entities'][scriptmodule_name]; - } - catch (e) { - var Class_1 = undefined; - } + var Class = KBEngine['Entities'][scriptmodule_name]; while (propertysize > 0) { propertysize--; var properUtype = stream.readUint16(); @@ -2385,64 +2793,87 @@ window['KBEngine'] = KBEngine; KBEngineApp.prototype.Client_onVersionNotMatch = function (stream) { KBEngine.app.serverVersion = stream.readString(); KBEngine.ERROR_MSG("Client_onVersionNotMatch: verInfo=" + KBEngine.app.clientVersion + " not match(server: " + KBEngine.app.serverVersion + ")"); - KBEngine.Event.fire("onVersionNotMatch", KBEngine.app.clientVersion, KBEngine.app.serverVersion); + KBEngine.Event.fire(KBEngine.EventTypes.onVersionNotMatch, KBEngine.app.clientVersion, KBEngine.app.serverVersion); }; KBEngineApp.prototype.Client_onScriptVersionNotMatch = function (stream) { KBEngine.app.serverScriptVersion = stream.readString(); KBEngine.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo=" + KBEngine.app.clientScriptVersion + " not match(server: " + KBEngine.app.serverScriptVersion + ")"); - KBEngine.Event.fire("onScriptVersionNotMatch", KBEngine.app.clientScriptVersion, KBEngine.app.serverScriptVersion); + KBEngine.Event.fire(KBEngine.EventTypes.onScriptVersionNotMatch, KBEngine.app.clientScriptVersion, KBEngine.app.serverScriptVersion); }; KBEngineApp.prototype.onImportEntityDefCompleted = function () { KBEngine.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"); KBEngine.app.entitydefImported = true; KBEngine.app.login_baseapp(false); }; - KBEngineApp.prototype.Client_onImportClientMessages = function (msg) { - var stream = new KBEngine.MemoryStream(msg.data); - var msgid = stream.readUint16(); - if (msgid == KBEngine.messages.onImportClientMessages.id) { - var msglen = stream.readUint16(); - var msgcount = stream.readUint16(); - KBEngine.INFO_MSG("KBEngineApp::onImportClientMessages: start(" + msgcount + ") ...!"); - while (msgcount > 0) { - msgcount--; - msgid = stream.readUint16(); - msglen = stream.readInt16(); - var msgname = stream.readString(); - var argtype = stream.readInt8(); - var argsize = stream.readUint8(); - var argstypes = new Array(argsize); - for (var i = 0; i < argsize; i++) { - argstypes[i] = stream.readUint8(); - } - var handler = null; - var isClientMethod = msgname.indexOf("Client_") >= 0; - if (isClientMethod) { - handler = KBEngine.app[msgname]; - if (handler == null || handler == undefined) { - KBEngine.WARNING_MSG("KBEngineApp::onImportClientMessages[" + KBEngine.app.currserver + "]: interface(" + msgname + "/" + msgid + ") no implement!"); - handler = null; - } - else { - KBEngine.INFO_MSG("KBEngineApp::onImportClientMessages: import(" + msgname + ") successfully!"); - } - } - if (msgname.length > 0) { - KBEngine.messages[msgname] = new KBEngine.Message(msgid, msgname, msglen, argtype, argstypes, handler); - if (isClientMethod) - KBEngine.clientmessages[msgid] = KBEngine.messages[msgname]; - else - KBEngine.messages[KBEngine.app.currserver][msgid] = KBEngine.messages[msgname]; + KBEngineApp.prototype.importClientMessages = function (stream) { + while (KBEngine.app.currMsgCount > 0) { + KBEngine.app.currMsgCount--; + var msgid = stream.readUint16(); + var msglen = stream.readInt16(); + var msgname = stream.readString(); + var argtype = stream.readInt8(); + var argsize = stream.readUint8(); + var argstypes = new Array(argsize); + for (var i = 0; i < argsize; i++) { + argstypes[i] = stream.readUint8(); + } + var handler = null; + var isClientMethod = msgname.indexOf("Client_") >= 0; + if (isClientMethod) { + handler = KBEngine.app[msgname]; + if (handler == null || handler == undefined) { + KBEngine.WARNING_MSG("KBEngineApp::onImportClientMessages[" + KBEngine.app.currserver + "]: interface(" + msgname + "/" + msgid + ") no implement!"); + handler = null; } else { - KBEngine.messages[KBEngine.app.currserver][msgid] = new KBEngine.Message(msgid, msgname, msglen, argtype, argstypes, handler); + KBEngine.INFO_MSG("KBEngineApp::onImportClientMessages: import(" + msgname + ") successfully!"); } } - ; - KBEngine.app.onImportClientMessagesCompleted(); + if (msgname.length > 0) { + KBEngine.messages[msgname] = new KBEngine.Message(msgid, msgname, msglen, argtype, argstypes, handler); + if (isClientMethod) + KBEngine.clientmessages[msgid] = KBEngine.messages[msgname]; + else + KBEngine.messages[KBEngine.app.currserver][msgid] = KBEngine.messages[msgname]; + } + else { + KBEngine.messages[KBEngine.app.currserver][msgid] = new KBEngine.Message(msgid, msgname, msglen, argtype, argstypes, handler); + } + } + ; + KBEngine.app.onImportClientMessagesCompleted(); + KBEngine.app.currMsgID = 0; + KBEngine.app.currMsgLen = 0; + KBEngine.app.currMsgCount = 0; + KBEngine.app.fragmentStream = null; + }; + KBEngineApp.prototype.Client_onImportClientMessages = function (msg) { + var stream = new KBEngine.MemoryStream(msg.data); + stream.wpos = msg.data.byteLength; + if (KBEngine.app.currMsgID == 0) { + KBEngine.app.currMsgID = stream.readUint16(); + } + if (KBEngine.app.currMsgID == KBEngine.messages.onImportClientMessages.id) { + if (KBEngine.app.currMsgLen == 0) { + KBEngine.app.currMsgLen = stream.readUint16(); + KBEngine.app.currMsgCount = stream.readUint16(); + } + if (stream.length() + 2 < KBEngine.app.currMsgLen && KBEngine.app.fragmentStream == null) { + KBEngine.app.writeFragmentMessage(KBEngine.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY, stream, KBEngine.app.currMsgLen - 2); + } + else if (KBEngine.app.fragmentStream != null) { + KBEngine.app.mergeFragmentMessage(stream); + if (KBEngine.app.fragmentStream.length() + 2 >= KBEngine.app.currMsgLen) { + KBEngine.app.importClientMessages(KBEngine.app.fragmentStream); + } + } + else { + KBEngine.app.importClientMessages(stream); + } + } + else { + KBEngine.ERROR_MSG("KBEngineApp::onmessage: not found msg(" + KBEngine.app.currMsgID + ")!"); } - else - KBEngine.ERROR_MSG("KBEngineApp::onmessage: not found msg(" + msgid + ")!"); }; KBEngineApp.prototype.createAccount = function (username, password, datas) { KBEngine.app.reset(); @@ -2454,11 +2885,12 @@ window['KBEngine'] = KBEngine; KBEngineApp.prototype.createAccount_loginapp = function (noconnect) { if (noconnect) { KBEngine.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + KBEngine.app.args.ip + ":" + KBEngine.app.args.port + "!"); + KBEngine.app.currconnect = "loginapp"; KBEngine.app.connect(KBEngine.app.args.ip, KBEngine.app.args.port); KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_createAccount; } else { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Loginapp_reqCreateAccount']); bundle.writeString(KBEngine.app.username); bundle.writeString(KBEngine.app.password); @@ -2467,7 +2899,7 @@ window['KBEngine'] = KBEngine; } }; KBEngineApp.prototype.bindAccountEmail = function (emailAddress) { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Baseapp_reqAccountBindEmail']); bundle.writeInt32(KBEngine.app.entity_id); bundle.writeString(KBEngine.app.password); @@ -2475,13 +2907,20 @@ window['KBEngine'] = KBEngine; bundle.send(KBEngine.app); }; KBEngineApp.prototype.newPassword = function (old_password, new_password) { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Baseapp_reqAccountNewPassword']); bundle.writeInt32(KBEngine.app.entity_id); bundle.writeString(old_password); bundle.writeString(new_password); bundle.send(KBEngine.app); }; + KBEngineApp.prototype.logout = function () { + var bundle = new KBEngine.Bundle(); + bundle.newMessage(KBEngine.messages['Baseapp_logoutBaseapp']); + bundle.writeUint64(KBEngine.app.entity_uuid); + bundle.writeInt32(KBEngine.app.entity_id); + bundle.send(KBEngine.app); + }; KBEngineApp.prototype.login = function (username, password, datas) { KBEngine.app.reset(); KBEngine.app.username = username; @@ -2492,11 +2931,12 @@ window['KBEngine'] = KBEngine; KBEngineApp.prototype.login_loginapp = function (noconnect) { if (noconnect) { KBEngine.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://" + KBEngine.app.args.ip + ":" + KBEngine.app.args.port + "!"); + KBEngine.app.currconnect = "loginapp"; KBEngine.app.connect(KBEngine.app.args.ip, KBEngine.app.args.port); KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_login; } else { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Loginapp_login']); bundle.writeInt8(KBEngine.app.args.clientType); // clientType bundle.writeBlob(KBEngine.app.clientdatas); @@ -2510,7 +2950,7 @@ window['KBEngine'] = KBEngine; KBEngine.app.currserver = "loginapp"; KBEngine.app.currstate = "resetpassword"; if (!KBEngine.app.loginappMessageImported) { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages.Loginapp_importClientMessages); bundle.send(KBEngine.app); KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; @@ -2528,11 +2968,12 @@ window['KBEngine'] = KBEngine; KBEngineApp.prototype.resetpassword_loginapp = function (noconnect) { if (noconnect) { KBEngine.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + KBEngine.app.args.ip + ":" + KBEngine.app.args.port + "!"); + KBEngine.app.currconnect = "loginapp"; KBEngine.app.connect(KBEngine.app.args.ip, KBEngine.app.args.port); KBEngine.app.socket.onopen = KBEngine.app.onOpenLoginapp_resetpassword; } else { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Loginapp_reqAccountResetPassword']); bundle.writeString(KBEngine.app.username); bundle.send(KBEngine.app); @@ -2542,7 +2983,7 @@ window['KBEngine'] = KBEngine; KBEngine.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"); KBEngine.app.currserver = "baseapp"; if (!KBEngine.app.baseappMessageImported) { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages.Baseapp_importClientMessages); bundle.send(KBEngine.app); KBEngine.app.socket.onmessage = KBEngine.app.Client_onImportClientMessages; @@ -2556,12 +2997,13 @@ window['KBEngine'] = KBEngine; if (noconnect) { KBEngine.Event.fire("onLoginBaseapp"); KBEngine.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "!"); + KBEngine.app.currconnect = "baseapp"; KBEngine.app.connect(KBEngine.app.baseappIp, KBEngine.app.baseappPort); if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) KBEngine.app.socket.onopen = KBEngine.app.onOpenBaseapp; } else { - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Baseapp_loginBaseapp']); bundle.writeString(KBEngine.app.username); bundle.writeString(KBEngine.app.password); @@ -2569,11 +3011,13 @@ window['KBEngine'] = KBEngine; } }; KBEngineApp.prototype.reloginBaseapp = function () { + KBEngine.app.lastTickCBTime = KBEngine.app.lastTickTime = Date.now(); if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) return; KBEngine.app.resetSocket(); - KBEngine.Event.fire("onReloginBaseapp"); + KBEngine.Event.fire(KBEngine.EventTypes.onReloginBaseapp); KBEngine.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://" + KBEngine.app.baseappIp + ":" + KBEngine.app.baseappPort + "!"); + KBEngine.app.currconnect = "baseapp"; KBEngine.app.connect(KBEngine.app.baseappIp, KBEngine.app.baseappPort); if (KBEngine.app.socket != undefined && KBEngine.app.socket != null) KBEngine.app.socket.onopen = KBEngine.app.onReOpenBaseapp; @@ -2581,7 +3025,7 @@ window['KBEngine'] = KBEngine; KBEngineApp.prototype.onReOpenBaseapp = function () { KBEngine.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"); KBEngine.app.currserver = "baseapp"; - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Baseapp_reloginBaseapp']); bundle.writeString(KBEngine.app.username); bundle.writeString(KBEngine.app.password); @@ -2623,16 +3067,16 @@ window['KBEngine'] = KBEngine; }; KBEngineApp.prototype.Client_onLoginBaseappFailed = function (failedcode) { KBEngine.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); - KBEngine.Event.fire("onLoginBaseappFailed", failedcode); + KBEngine.Event.fire(KBEngine.EventTypes.onLoginBaseappFailed, failedcode); }; KBEngineApp.prototype.Client_onReloginBaseappFailed = function (failedcode) { KBEngine.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); - KBEngine.Event.fire("onReloginBaseappFailed", failedcode); + KBEngine.Event.fire(KBEngine.EventTypes.onReloginBaseappFailed, failedcode); }; KBEngineApp.prototype.Client_onReloginBaseappSuccessfully = function (stream) { KBEngine.app.entity_uuid = stream.readUint64(); KBEngine.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: " + KBEngine.app.username); - KBEngine.Event.fire("onReloginBaseappSuccessfully"); + KBEngine.Event.fire(KBEngine.EventTypes.onReloginBaseappSuccessfully); }; KBEngineApp.prototype.getentityclass = function (entityType) { var runclass = KBEngine['Entities'][entityType]; @@ -2925,7 +3369,7 @@ window['KBEngine'] = KBEngine; }; KBEngineApp.prototype.Client_onKicked = function (failedcode) { KBEngine.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode(" + KBEngine.app.serverErrs[failedcode].name + ")!"); - KBEngine.Event.fire("onKicked", failedcode); + KBEngine.Event.fire(KBEngine.EventTypes.onKicked, failedcode); }; KBEngineApp.prototype.Client_onCreateAccountResult = function (stream) { var retcode = stream.readUint16(); @@ -2962,7 +3406,7 @@ window['KBEngine'] = KBEngine; entity.isControlled = isCont; try { entity.onControlled(isCont); - KBEngine.Event.fire("onControlled", entity, isCont); + KBEngine.Event.fire(KBEngine.EventTypes.onControlled, entity, isCont); } catch (e) { KBEngine.ERROR_MSG("KBEngine::Client_onControlEntity: entity id = '" + eid + "', is controlled = '" + isCont + "', error = '" + e + "'"); @@ -2980,7 +3424,7 @@ window['KBEngine'] = KBEngine; player.entityLastLocalDir.x = player.direction.x; player.entityLastLocalDir.y = player.direction.y; player.entityLastLocalDir.z = player.direction.z; - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Baseapp_onUpdateDataFromClient']); bundle.writeFloat(player.position.x); bundle.writeFloat(player.position.y); @@ -3002,7 +3446,7 @@ window['KBEngine'] = KBEngine; if (posHasChanged || dirHasChanged) { entity.entityLastLocalPos = position; entity.entityLastLocalDir = direction; - var bundle = new KBEngine.Bundle(); + var bundle = KBEngine.Bundle.createObject(); bundle.newMessage(KBEngine.messages['Baseapp_onUpdateDataFromClientForControlledEntity']); bundle.writeInt32(entity.id); bundle.writeFloat(position.x); @@ -3021,7 +3465,7 @@ window['KBEngine'] = KBEngine; KBEngine.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID(" + spaceID + "), respath(" + respath + ")!"); KBEngine.app.spaceID = spaceID; KBEngine.app.spaceResPath = respath; - KBEngine.Event.fire("addSpaceGeometryMapping", respath); + KBEngine.Event.fire(KBEngine.EventTypes.addSpaceGeometryMapping, respath); }; KBEngineApp.prototype.clearSpace = function (isAll) { KBEngine.app.entityIDAliasIDList = []; @@ -3122,161 +3566,329 @@ window['KBEngine'] = KBEngine; }; KBEngineApp.prototype.Client_onUpdateData_ypr = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); - var y = stream.readInt8(); - var p = stream.readInt8(); - var r = stream.readInt8(); + var y = stream.readFloat(); + var p = stream.readFloat(); + var r = stream.readFloat(); KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, p, r, -1); }; KBEngineApp.prototype.Client_onUpdateData_yp = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); - var y = stream.readInt8(); - var p = stream.readInt8(); + var y = stream.readFloat(); + var p = stream.readFloat(); KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, p, KBEngine.KBE_FLT_MAX, -1); }; KBEngineApp.prototype.Client_onUpdateData_yr = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); - var y = stream.readInt8(); - var r = stream.readInt8(); + var y = stream.readFloat(); + var r = stream.readFloat(); KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, KBEngine.KBE_FLT_MAX, r, -1); }; KBEngineApp.prototype.Client_onUpdateData_pr = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); - var p = stream.readInt8(); - var r = stream.readInt8(); + var p = stream.readFloat(); + var r = stream.readFloat(); KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, p, r, -1); }; KBEngineApp.prototype.Client_onUpdateData_y = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); - var y = stream.readInt8(); + var y = stream.readFloat(); KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, -1); }; KBEngineApp.prototype.Client_onUpdateData_p = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); - var p = stream.readInt8(); + var p = stream.readFloat(); KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, -1); }; KBEngineApp.prototype.Client_onUpdateData_r = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); - var r = stream.readInt8(); + var r = stream.readFloat(); KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, r, -1); }; KBEngineApp.prototype.Client_onUpdateData_xz = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); - var xz = stream.readPackXZ(); - KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 1); + // let x = stream.readFloat(); let z = stream.readFloat(); + var x = stream.readFloat(); + var z = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, KBEngine.KBE_FLT_MAX, z, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 1); }; KBEngineApp.prototype.Client_onUpdateData_xz_ypr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var y = stream.readFloat(); + var p = stream.readFloat(); + var r = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, KBEngine.KBE_FLT_MAX, z, y, p, r, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_yp = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var y = stream.readFloat(); + var p = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, KBEngine.KBE_FLT_MAX, z, y, p, KBEngine.KBE_FLT_MAX, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_yr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var y = stream.readFloat(); + var r = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, KBEngine.KBE_FLT_MAX, z, y, KBEngine.KBE_FLT_MAX, r, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_pr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var p = stream.readFloat(); + var r = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, KBEngine.KBE_FLT_MAX, z, KBEngine.KBE_FLT_MAX, p, r, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_y = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var y = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, KBEngine.KBE_FLT_MAX, z, y, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_p = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var p = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, x, KBEngine.KBE_FLT_MAX, z, KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_r = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, x, KBEngine.KBE_FLT_MAX, z, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, r, 1); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var y = stream.readFloat(); + var z = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, y, z, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_ypr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var y = stream.readFloat(); + var z = stream.readFloat(); + var yaw = stream.readFloat(); + var p = stream.readFloat(); + var r = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, y, z, yaw, p, r, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_yp = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var y = stream.readFloat(); + var yaw = stream.readFloat(); + var p = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, y, z, yaw, p, KBEngine.KBE_FLT_MAX, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_yr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var y = stream.readFloat(); + var yaw = stream.readFloat(); + var r = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, y, z, yaw, KBEngine.KBE_FLT_MAX, r, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_pr = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var y = stream.readFloat(); + var p = stream.readFloat(); + var r = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, y, z, KBEngine.KBE_FLT_MAX, p, r, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_y = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var y = stream.readFloat(); + var yaw = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, y, z, yaw, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_p = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var y = stream.readFloat(); + var p = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, y, z, KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_xyz_r = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var x = stream.readFloat(); + var z = stream.readFloat(); + var y = stream.readFloat(); + //todo 这个是自己加的,如果错误再修改 + var r = stream.readFloat(); + // let p = stream.readFloat(); + KBEngine.app._updateVolatileData(eid, x, y, z, r, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0); + }; + KBEngineApp.prototype.Client_onUpdateData_ypr_optimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var y = stream.readInt8(); + var p = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, p, r, -1, true); + }; + KBEngineApp.prototype.Client_onUpdateData_yp_optimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var y = stream.readInt8(); + var p = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, p, KBEngine.KBE_FLT_MAX, -1, true); + }; + KBEngineApp.prototype.Client_onUpdateData_yr_optimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var y = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, KBEngine.KBE_FLT_MAX, r, -1, true); + }; + KBEngineApp.prototype.Client_onUpdateData_pr_optimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var p = stream.readInt8(); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, p, r, -1, true); + }; + KBEngineApp.prototype.Client_onUpdateData_y_optimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var y = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, y, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, -1, true); + }; + KBEngineApp.prototype.Client_onUpdateData_p_optimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var p = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, -1, true); + }; + KBEngineApp.prototype.Client_onUpdateData_r_optimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var r = stream.readInt8(); + KBEngine.app._updateVolatileData(eid, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, r, -1, true); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_optimized = function (stream) { + var eid = KBEngine.app.getViewEntityIDFromStream(stream); + var xz = stream.readPackXZ(); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 1, true); + }; + KBEngineApp.prototype.Client_onUpdateData_xz_ypr_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readInt8(); var p = stream.readInt8(); var r = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, p, r, 1); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, p, r, 1, true); }; - KBEngineApp.prototype.Client_onUpdateData_xz_yp = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xz_yp_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readInt8(); var p = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, p, KBEngine.KBE_FLT_MAX, 1); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, p, KBEngine.KBE_FLT_MAX, 1, true); }; - KBEngineApp.prototype.Client_onUpdateData_xz_yr = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xz_yr_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readInt8(); var r = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, KBEngine.KBE_FLT_MAX, r, 1); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, KBEngine.KBE_FLT_MAX, r, 1, true); }; - KBEngineApp.prototype.Client_onUpdateData_xz_pr = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xz_pr_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var p = stream.readInt8(); var r = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, p, r, 1); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, p, r, 1, true); }; - KBEngineApp.prototype.Client_onUpdateData_xz_y = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xz_y_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 1); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], y, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 1, true); }; - KBEngineApp.prototype.Client_onUpdateData_xz_p = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xz_p_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var p = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, 1); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, 1, true); }; - KBEngineApp.prototype.Client_onUpdateData_xz_r = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xz_r_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var r = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, r, 1); + KBEngine.app._updateVolatileData(eid, xz[0], KBEngine.KBE_FLT_MAX, xz[1], KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, r, 1, true); }; - KBEngineApp.prototype.Client_onUpdateData_xyz = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xyz_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readPackY(); - KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0, true); }; - KBEngineApp.prototype.Client_onUpdateData_xyz_ypr = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xyz_ypr_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readPackY(); var yaw = stream.readInt8(); var p = stream.readInt8(); var r = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, r, 0); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, r, 0, true); }; - KBEngineApp.prototype.Client_onUpdateData_xyz_yp = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xyz_yp_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readPackY(); var yaw = stream.readInt8(); var p = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, KBEngine.KBE_FLT_MAX, 0); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, KBEngine.KBE_FLT_MAX, 0, true); }; - KBEngineApp.prototype.Client_onUpdateData_xyz_yr = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xyz_yr_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readPackY(); var yaw = stream.readInt8(); var r = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBEngine.KBE_FLT_MAX, r, 0); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBEngine.KBE_FLT_MAX, r, 0, true); }; - KBEngineApp.prototype.Client_onUpdateData_xyz_pr = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xyz_pr_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readPackY(); var p = stream.readInt8(); var r = stream.readInt8(); - KBEngine.ERROR_MSG('调用错误方法,无法找到x,z'); - //todo 这个是手动注释,如果错误再修改 - // app._updateVolatileData(eid, x, y, z, KBE_FLT_MAX, p, r, 0); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], KBEngine.KBE_FLT_MAX, p, r, 0, true); }; - KBEngineApp.prototype.Client_onUpdateData_xyz_y = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xyz_y_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readPackY(); var yaw = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0, true); }; - KBEngineApp.prototype.Client_onUpdateData_xyz_p = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xyz_p_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readPackY(); var p = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, 0); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], KBEngine.KBE_FLT_MAX, p, KBEngine.KBE_FLT_MAX, 0, true); }; - KBEngineApp.prototype.Client_onUpdateData_xyz_r = function (stream) { + KBEngineApp.prototype.Client_onUpdateData_xyz_r_optimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); var xz = stream.readPackXZ(); var y = stream.readPackY(); - //todo 这个是自己加的,如果错误再修改 var r = stream.readInt8(); - var p = stream.readInt8(); - KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], r, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0); + KBEngine.app._updateVolatileData(eid, xz[0], y, xz[1], r, KBEngine.KBE_FLT_MAX, KBEngine.KBE_FLT_MAX, 0, true); }; - KBEngineApp.prototype._updateVolatileData = function (entityID, x, y, z, yaw, pitch, roll, isOnGround) { + KBEngineApp.prototype._updateVolatileData = function (entityID, x, y, z, yaw, pitch, roll, isOnGround, isOptimized) { + if (isOptimized === void 0) { isOptimized = false; } var entity = KBEngine.app.entities[entityID]; if (entity == undefined) { // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 @@ -3317,9 +3929,16 @@ window['KBEngine'] = KBEngine; if (z == KBEngine.KBE_FLT_MAX) z = 0.0; if (positionChanged) { - entity.position.x = x + KBEngine.app.entityServerPos.x; - entity.position.y = y + KBEngine.app.entityServerPos.y; - entity.position.z = z + KBEngine.app.entityServerPos.z; + if (isOptimized) { + entity.position.x = x + KBEngine.app.entityServerPos.x; + entity.position.y = y + KBEngine.app.entityServerPos.y; + entity.position.z = z + KBEngine.app.entityServerPos.z; + } + else { + entity.position.x = x; + entity.position.y = y; + entity.position.z = z; + } done = true; KBEngine.Event.fire("updatePosition", entity); } @@ -3327,15 +3946,15 @@ window['KBEngine'] = KBEngine; entity.onUpdateVolatileData(); }; KBEngineApp.prototype.Client_onStreamDataStarted = function (id, datasize, descr) { - KBEngine.Event.fire("onStreamDataStarted", id, datasize, descr); + KBEngine.Event.fire(KBEngine.EventTypes.onStreamDataStarted, id, datasize, descr); }; KBEngineApp.prototype.Client_onStreamDataRecv = function (stream) { var id = stream.readUint16(); var data = stream.readBlob(); - KBEngine.Event.fire("onStreamDataRecv", id, data); + KBEngine.Event.fire(KBEngine.EventTypes.onStreamDataRecv, id, data); }; KBEngineApp.prototype.Client_onStreamDataCompleted = function (id) { - KBEngine.Event.fire("onStreamDataCompleted", id); + KBEngine.Event.fire(KBEngine.EventTypes.onStreamDataCompleted, id); }; KBEngineApp.prototype.Client_onReqAccountResetPasswordCB = function (failedcode) { if (failedcode != 0) { @@ -3371,14 +3990,17 @@ window['KBEngine'] = KBEngine; return ServerErr; }()); KBEngine.ServerErr = ServerErr; + KBEngine.FragmentDataTypes = { + FRAGMENT_DATA_UNKNOW: 0, + FRAGMENT_DATA_MESSAGE_ID: 1, + FRAGMENT_DATA_MESSAGE_LENGTH: 2, + FRAGMENT_DATA_MESSAGE_LENGTH1: 3, + FRAGMENT_DATA_MESSAGE_BODY: 4 + }; var idInterval; function create(args) { if (KBEngine.app != undefined) return; - if (args.constructor != KBEngine.KBEngineArgs) { - KBEngine.ERROR_MSG("create(): args(" + args + ") error! not is KBEngineArgs"); - return; - } new KBEngineApp(args); KBEngine.app.reset(); KBEngine.app.installEvents(); @@ -3393,6 +4015,7 @@ window['KBEngine'] = KBEngine; KBEngine.app.uninstallEvents(); KBEngine.app.reset(); KBEngine.app = undefined; + KBEngine.Event.clear(); } KBEngine.destroy = destroy; })(KBEngine || (KBEngine = {})); diff --git a/kbengine_ts/bin/kbengine.min.js b/kbengine_ts/bin/kbengine.min.js deleted file mode 100644 index b8c9c18..0000000 --- a/kbengine_ts/bin/kbengine.min.js +++ /dev/null @@ -1,3 +0,0 @@ -var __reflect=this&&this.__reflect||function(e,t,n){e.__class__=t,n?n.push(t):n=[t],e.__types__=e.__types__?n.concat(e.__types__):n},__extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);n.prototype=t.prototype,e.prototype=new n},KBEngine;!function(e){e.CLIENT_VERSION="1.1.8",e.CLIENT_SCRIPT_VERSION="0.1.0",e.PACKET_MAX_SIZE=1500,e.PACKET_MAX_SIZE_TCP=1460,e.PACKET_MAX_SIZE_UDP=1472,e.MESSAGE_ID_LENGTH=2,e.MESSAGE_LENGTH_LENGTH=2,e.CLIENT_NO_FLOAT=0,e.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,function(e){var t=function(){function e(e,t){this.sign=1,this.lo=e,this.hi=t,t>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return e.prototype.toString=function(){var e="";this.sign<0&&(e+="-");var t=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){e+=n;for(var r=8-t.length;r>0;--r)e+="0"}return e+=t},e}();e.INT64=t,__reflect(t.prototype,"KBEngine.INT64");var n=function(){function e(e,t){this.lo=e,this.hi=t}return e.prototype.toString=function(){var e=this.lo.toString(16),t=this.hi.toString(16),n="";if(this.hi>0){n+=t;for(var r=8-e.length;r>0;--r)n+="0"}return n+=e},e}();e.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(e){function t(){for(var e=[],t=0;tn;)switch(a=e[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(a);break;case 12:case 13:i=e[n++],t+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=e[n++],o=e[n++],t+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return t}function n(e){for(var t=[],n=0;nr?t.push(r):2048>r?t.push(192|r>>6,128|63&r):55296>r||r>=57344?t.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&e.charCodeAt(n)),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return t}e.utf8ArrayToString=t,e.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(e){var t=function(){function e(e,t){this.callbackfn=t,this.classinst=e}return e}();e.EventInfo=t,__reflect(t.prototype,"KBEngine.EventInfo");var n=function(){function n(){this._events={}}return n.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void e.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new t(r,i);o.push(p)},n.prototype.deregister=function(e,t){for(var n in this._events)for(var r=this._events[n];;){for(var a=!1,i=0;i=32768&&(e-=65536),e},t.prototype.readInt32=function(){var e=this.readUint32();return e>=2147483648&&(e-=4294967296),e},t.prototype.readInt64=function(){return new e.INT64(this.readUint32(),this.readUint32())},t.prototype.readUint8=function(){var e=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,e[0]},t.prototype.readUint16=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&e[1])<<8)+(255&e[0])},t.prototype.readUint32=function(){var e=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(e[3]<<24)+(e[2]<<16)+(e[1]<<8)+e[0]},t.prototype.readUint64=function(){return new e.UINT64(this.readUint32(),this.readUint32())},t.prototype.readFloat=function(){var e;try{e=new Float32Array(this.buffer,this.rpos,1)}catch(t){e=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,e[0]},t.prototype.readDouble=function(){var e;try{e=new Float64Array(this.buffer,this.rpos,1)}catch(t){e=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,e[0]},t.prototype.readString=function(){for(var e=new Uint8Array(this.buffer,this.rpos),t=0,n="";;){if(0==e[t]){t++;break}if(n+=String.fromCharCode(e[t]),t++,this.rpos+t>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+t)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=t,n},t.prototype.readBlob=function(){var e=this.readUint32(),t=new Uint8Array(this.buffer,this.rpos,e);return this.rpos+=e,t},t.prototype.readStream=function(){var e=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new t(e)},t.prototype.readPackXZ=function(){var e=new t.PackFloatXType,n=new t.PackFloatXType;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},t.prototype.readPackY=function(){var e=this.readUint16();return e},t.prototype.writeInt8=function(e){var t=new Int8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeInt16=function(e){this.writeInt8(255&e),this.writeInt8(e>>8&255)},t.prototype.writeInt32=function(e){for(var t=0;4>t;t++)this.writeInt8(e>>8*t&255)},t.prototype.writeInt64=function(e){this.writeInt32(e.lo),this.writeInt32(e.hi)},t.prototype.writeUint8=function(e){var t=new Uint8Array(this.buffer,this.wpos,1);t[0]=e,this.wpos+=1},t.prototype.writeUint16=function(e){this.writeUint8(255&e),this.writeUint8(e>>8&255)},t.prototype.writeUint32=function(e){for(var t=0;4>t;t++)this.writeUint8(e>>8*t&255)},t.prototype.writeUint64=function(e){this.writeUint32(e.lo),this.writeUint32(e.hi)},t.prototype.writeFloat=function(e){try{var t=new Float32Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float32Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=4},t.prototype.writeDouble=function(e){try{var t=new Float64Array(this.buffer,this.wpos,1);t[0]=e}catch(n){var t=new Float64Array(1);t[0]=e;var r=new Uint8Array(this.buffer),a=new Uint8Array(t.buffer);r.set(a,this.wpos)}this.wpos+=8},t.prototype.writeBlob=function(t){var n=t.length;if(n+4>this.space())return void e.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof t)for(var a=0;n>a;a++)r[a]=t.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=t[a];this.wpos+=n},t.prototype.writeString=function(t){if(t.length>this.space())return void e.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;a>8&255)},t.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream)),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},t.prototype.send=function(t){this.fini(!0);for(var n=0;nthis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=new e.MemoryStream(e.PACKET_MAX_SIZE_TCP)),this.messageLength+=t},t.prototype.writeInt8=function(e){this.checkStream(1),this.stream.writeInt8(e)},t.prototype.writeInt16=function(e){this.checkStream(2),this.stream.writeInt16(e)},t.prototype.writeInt32=function(e){this.checkStream(4),this.stream.writeInt32(e)},t.prototype.writeInt64=function(e){this.checkStream(8),this.stream.writeInt64(e)},t.prototype.writeUint8=function(e){this.checkStream(1),this.stream.writeUint8(e)},t.prototype.writeUint16=function(e){this.checkStream(2),this.stream.writeUint16(e)},t.prototype.writeUint32=function(e){this.checkStream(4),this.stream.writeUint32(e)},t.prototype.writeUint64=function(e){this.checkStream(8),this.stream.writeUint64(e)},t.prototype.writeFloat=function(e){this.checkStream(4),this.stream.writeFloat(e)},t.prototype.writeDouble=function(e){this.checkStream(8),this.stream.writeDouble(e)},t.prototype.writeString=function(e){this.checkStream(e.length+1),this.stream.writeString(e)},t.prototype.writeBlob=function(e){this.checkStream(e.length+4),this.stream.writeBlob(e)},t}();e.Bundle=a,__reflect(a.prototype,"KBEngine.Bundle"),e.reader=new e.MemoryStream(0),e.datatype2id={},e.mappingDataType=t,t(),e.bindWriter=n,e.bindReader=r;var i=function(){function t(e,t,n,a,i,o){this.id=e,this.name=t,this.length=n,this.argsType=a;for(var p=0;pn){var r=t;t=n,n=r}return t>e?t:n>e?e:n}function n(e,t){return e*(Math.PI/(t?254:128))}function r(e,n){var r=0;return r=n?t(Math.floor(254*e/Math.PI+.5),-128,127):Math.floor(128*e/Math.PI+.5)}var a=function(){function e(e,t){this.x=e,this.y=t}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y;return Math.sqrt(t*t+n*n)},e}();e.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function e(e,t,n){this.x=e,this.y=t,this.z=n}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function e(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}return e.prototype.distance=function(e){var t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.sqrt(t*t+n*n+r*r)},e}();e.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),e.clampf=t,e.int82angle=n,e.angle2int8=r}(KBEngine||(KBEngine={})),function(e){var t=function(){function t(){this.id=0,this.className="",this.position=new e.Vector3(0,0,0),this.direction=new e.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new e.Vector3(0,0,0),this.entityLastLocalDir=new e.Vector3(0,0,0),this.isOnGround=!1}return t.prototype.__init__=function(){},t.prototype.callPropertysSetMethods=function(){var t=e.moduledefs[this.className];for(var n in t.propertys){var r=t.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},t.prototype.onDestroy=function(){},t.prototype.onControlled=function(e){},t.prototype.isPlayer=function(){return this.id==e.app.entity_id},t.prototype.baseCall=function(t){for(var n=[],r=1;re||e>255?!1:!0},t}();e.DATATYPE_UINT8=n,__reflect(n.prototype,"KBEngine.DATATYPE_UINT8");var r=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint16.call(t)},t.prototype.addToStream=function(e,t){e.writeUint16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>65535?!1:!0},t}();e.DATATYPE_UINT16=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT16");var a=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint32.call(t)},t.prototype.addToStream=function(e,t){e.writeUint32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:0>e||e>4294967295?!1:!0},t}();e.DATATYPE_UINT32=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT32");var i=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readUint64.call(t)},t.prototype.addToStream=function(e,t){e.writeUint64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.UINT64},t}();e.DATATYPE_UINT64=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT64");var o=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt8.call(t)},t.prototype.addToStream=function(e,t){e.writeInt8(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-128>e||e>127?!1:!0},t}();e.DATATYPE_INT8=o,__reflect(o.prototype,"KBEngine.DATATYPE_INT8");var p=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt16.call(t)},t.prototype.addToStream=function(e,t){e.writeInt16(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-32768>e||e>32767?!1:!0},t}();e.DATATYPE_INT16=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT16");var s=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt32.call(t)},t.prototype.addToStream=function(e,t){e.writeInt32(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(e){return"number"!=typeof e?!1:-2147483648>e||e>2147483647?!1:!0},t}();e.DATATYPE_INT32=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT32");var l=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readInt64.call(t)},t.prototype.addToStream=function(e,t){e.writeInt64(t)},t.prototype.parseDefaultValStr=function(e){return parseInt(e)},t.prototype.isSameType=function(t){return t instanceof e.INT64},t}();e.DATATYPE_INT64=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT64");var c=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readFloat.call(t)},t.prototype.addToStream=function(e,t){e.writeFloat(t)},t.prototype.parseDefaultValStr=function(e){return parseFloat(e)},t.prototype.isSameType=function(e){return"number"==typeof e},t}();e.DATATYPE_FLOAT=c,__reflect(c.prototype,"KBEngine.DATATYPE_FLOAT");var d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),n.prototype.createFromStream=function(t){return e.reader.readDouble.call(t)},n.prototype.addToStream=function(e,t){e.writeDouble(t)},n}(c);e.DATATYPE_DOUBLE=d,__reflect(d.prototype,"KBEngine.DATATYPE_DOUBLE");var u=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.reader.readString.call(t)},t.prototype.addToStream=function(e,t){e.writeString(t)},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_STRING=u,__reflect(u.prototype,"KBEngine.DATATYPE_STRING");var y=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector2(e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector2(e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y)):(t.writeFloat(n.x),t.writeFloat(n.y))},t.prototype.parseDefaultValStr=function(t){return new e.Vector2(0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector2?!0:!1},t}();e.DATATYPE_VECTOR2=y,__reflect(y.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector3(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t)):new e.Vector3(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z))},t.prototype.parseDefaultValStr=function(t){return new e.Vector3(0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector3?!0:!1},t}();e.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var _=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.CLIENT_NO_FLOAT?new e.Vector4(e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readInt32.call(t),e.reader.readFloat.call(t)):new e.Vector4(e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t),e.reader.readFloat.call(t))},t.prototype.addToStream=function(t,n){e.CLIENT_NO_FLOAT?(t.writeInt32(n.x),t.writeInt32(n.y),t.writeInt32(n.z),t.writeInt32(n.w)):(t.writeFloat(n.x),t.writeFloat(n.y),t.writeFloat(n.z),t.writeFloat(n.w))},t.prototype.parseDefaultValStr=function(t){return new e.Vector4(0,0,0,0)},t.prototype.isSameType=function(t){return t instanceof e.Vector4?!0:!1},t}();e.DATATYPE_VECTOR4=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR4");var E=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_PYTHON=E,__reflect(E.prototype,"KBEngine.DATATYPE_PYTHON");var g=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return e.utf8ArrayToString(e.reader.readBlob.call(t))},t.prototype.addToStream=function(t,n){t.writeBlob(e.stringToUTF8Bytes(n))},t.prototype.parseDefaultValStr=function(e){return"string"==typeof e?e:""},t.prototype.isSameType=function(e){return"string"==typeof e},t}();e.DATATYPE_UNICODE=g,__reflect(g.prototype,"KBEngine.DATATYPE_UNICODE");var h=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){},e.prototype.addToStream=function(e,t){},e.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},e.prototype.isSameType=function(e){return!1},e}();e.DATATYPE_ENTITYCALL=h,__reflect(h.prototype,"KBEngine.DATATYPE_ENTITYCALL");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){var n=e.reader.readUint32.call(t),r=new Uint8Array(t.buffer,t.rpos,n);return t.rpos+=n,r},t.prototype.addToStream=function(e,t){e.writeBlob(t)},t.prototype.parseDefaultValStr=function(e){return new Uint8Array(0)},t.prototype.isSameType=function(e){return!0},t}();e.DATATYPE_BLOB=m,__reflect(m.prototype,"KBEngine.DATATYPE_BLOB");var v=function(){function e(){this.type=null}return e.prototype.bind=function(){"number"==typeof this.type&&(this.type=T[this.type])},e.prototype.createFromStream=function(e){for(var t=e.readUint32(),n=[];t>0;)t--,n.push(this.type.createFromStream(e));return n},e.prototype.addToStream=function(e,t){e.writeUint32(t.length);for(var n=0;ne.app.args.serverHeartbeatTick){if(e.app.lastTickCBTime0;){n-=1;var r=new a;r.id=t.readUint16(),r.name=e.utf8ArrayToString(t.readBlob()),r.descr=e.utf8ArrayToString(t.readBlob()),e.app.serverErrs[r.id]=r,e.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},t.prototype.onOpenLoginapp_login=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),e.Event.fire("onConnectionState",!0),e.app.currserver="loginapp",e.app.currstate="login",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onOpenLoginapp_createAccount=function(){if(e.Event.fire("onConnectionState",!0),e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),e.app.currserver="loginapp",e.app.currstate="createAccount",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),e.Event.fire("Loginapp_importClientMessages")}},t.prototype.onImportClientMessagesCompleted=function(){if(e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),e.app.socket.onmessage=e.app.onmessage,e.app.hello(),"loginapp"==e.app.currserver){if(!e.app.serverErrorsDescrImported){e.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),e.app.serverErrorsDescrImported=!0;var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importServerErrorsDescr),t.send(e.app)}"login"==e.app.currstate?e.app.login_loginapp(!1):"resetpassword"==e.app.currstate?e.app.resetpassword_loginapp(!1):e.app.createAccount_loginapp(!1),e.app.loginappMessageImported=!0}else if(e.app.baseappMessageImported=!0,e.app.entitydefImported)e.app.onImportEntityDefCompleted();else{e.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientEntityDef),t.send(e.app),e.Event.fire("Baseapp_importClientEntityDef")}},t.prototype.createDataTypeFromStreams=function(t,n){var r=t.readUint16();for(e.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,e.app.createDataTypeFromStream(t,n);for(var a in e.datatypes)void 0!=e.datatypes[a]&&e.datatypes[a].bind()},t.prototype.createDataTypeFromStream=function(t,n){var r,a=t.readUint16(),i=t.readString(),o=t.readString();if(0==o.length&&(r="Null_"+a),n&&e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new e.DATATYPE_FIXED_DICT,s=t.readUint8();for(p.implementedBy=t.readString();s>0;){s--;var l=t.readString(),c=t.readUint16();p.dicttype[l]=c}e.datatypes[o]=p}else if("ARRAY"==i){var d=t.readUint16(),p=new e.DATATYPE_ARRAY;p.type=d,e.datatypes[o]=p}else e.datatypes[o]=e.datatypes[i];e.datatypes[a]=e.datatypes[o],e.datatype2id[o]=a},t.prototype.Client_onImportClientEntityDef=function(t){for(e.app.createDataTypeFromStreams(t,!0);!t.readEOF();){var n=t.readString(),r=t.readUint16(),a=t.readUint16(),i=t.readUint16(),o=t.readUint16(),p=t.readUint16();e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),e.moduledefs[n]={};var s=e.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},e.moduledefs[r]=s;var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods;try{var y=e.Entities[n]}catch(f){}for(;a>0;){a--;var _=t.readUint16(),E=t.readUint32(),g=t.readInt16(),h=t.readString(),m=t.readString(),v=e.datatypes[t.readUint16()],S=null;void 0!=y&&(S=y.prototype["set_"+h],void 0==S&&(S=null));var T=[_,g,h,m,v,S,E];l[h]=T,-1!=g?(l[g]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+h+"/"+_+").")}for(;i>0;){i--;for(var I=t.readUint16(),g=t.readInt16(),w=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);var T=[I,g,w,C];c[w]=T,-1!=g?(c[g]=T,s.useMethodDescrAlias=!0):(c[I]=T,s.useMethodDescrAlias=!1),e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+w+").")}for(;o>0;){o--;for(var I=t.readUint16(),g=t.readInt16(),B=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);d[B]=[I,g,B,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+B+").")}for(;p>0;){p--;for(var I=t.readUint16(),g=t.readInt16(),D=t.readString(),A=t.readUint8(),C=[];A>0;)A--,C.push(e.datatypes[t.readUint16()]);u[D]=[I,g,D,C],e.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+D+").")}var M=void 0;try{M=e.Entities[n]}catch(f){e.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),M=void 0}for(var L in s.propertys){var F=s.propertys[L],_=F[0],g=F[1],R=F[2],m=F[3],v=F[4];void 0!=M&&(M.prototype[R]=v.parseDefaultValStr(m))}for(var K in s.methods){var F=s.methods[K],_=F[0],g=F[1],R=F[2],C=F[3];void 0!=M&&void 0==M.prototype[R]&&e.WARNING_MSG(n+":: method("+R+") no implement!")}}e.app.onImportEntityDefCompleted()},t.prototype.Client_onVersionNotMatch=function(t){e.app.serverVersion=t.readString(),e.ERROR_MSG("Client_onVersionNotMatch: verInfo="+e.app.clientVersion+" not match(server: "+e.app.serverVersion+")"),e.Event.fire("onVersionNotMatch",e.app.clientVersion,e.app.serverVersion)},t.prototype.Client_onScriptVersionNotMatch=function(t){e.app.serverScriptVersion=t.readString(),e.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+e.app.clientScriptVersion+" not match(server: "+e.app.serverScriptVersion+")"),e.Event.fire("onScriptVersionNotMatch",e.app.clientScriptVersion,e.app.serverScriptVersion)},t.prototype.onImportEntityDefCompleted=function(){e.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),e.app.entitydefImported=!0,e.app.login_baseapp(!1)},t.prototype.Client_onImportClientMessages=function(t){var n=new e.MemoryStream(t.data),r=n.readUint16();if(r==e.messages.onImportClientMessages.id){var a=n.readUint16(),i=n.readUint16();for(e.INFO_MSG("KBEngineApp::onImportClientMessages: start("+i+") ...!");i>0;){i--,r=n.readUint16(),a=n.readInt16();for(var o=n.readString(),p=n.readInt8(),s=n.readUint8(),l=new Array(s),c=0;s>c;c++)l[c]=n.readUint8();var d=null,u=o.indexOf("Client_")>=0;u&&(d=e.app[o],null==d||void 0==d?(e.WARNING_MSG("KBEngineApp::onImportClientMessages["+e.app.currserver+"]: interface("+o+"/"+r+") no implement!"),d=null):e.INFO_MSG("KBEngineApp::onImportClientMessages: import("+o+") successfully!")),o.length>0?(e.messages[o]=new e.Message(r,o,a,p,l,d),u?e.clientmessages[r]=e.messages[o]:e.messages[e.app.currserver][r]=e.messages[o]):e.messages[e.app.currserver][r]=new e.Message(r,o,a,p,l,d)}e.app.onImportClientMessagesCompleted()}else e.ERROR_MSG("KBEngineApp::onmessage: not found msg("+r+")!")},t.prototype.createAccount=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.createAccount_loginapp(!0)},t.prototype.createAccount_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_createAccount;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqCreateAccount),n.writeString(e.app.username),n.writeString(e.app.password),n.writeBlob(e.app.clientdatas),n.send(e.app)}},t.prototype.bindAccountEmail=function(t){var n=new e.Bundle;n.newMessage(e.messages.Baseapp_reqAccountBindEmail),n.writeInt32(e.app.entity_id),n.writeString(e.app.password),n.writeString(t),n.send(e.app)},t.prototype.newPassword=function(t,n){var r=new e.Bundle;r.newMessage(e.messages.Baseapp_reqAccountNewPassword),r.writeInt32(e.app.entity_id),r.writeString(t),r.writeString(n),r.send(e.app)},t.prototype.login=function(t,n,r){e.app.reset(),e.app.username=t,e.app.password=n,e.app.clientdatas=r,e.app.login_loginapp(!0)},t.prototype.login_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_login;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_login),n.writeInt8(e.app.args.clientType),n.writeBlob(e.app.clientdatas),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.onOpenLoginapp_resetpassword=function(){if(e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),e.app.currserver="loginapp",e.app.currstate="resetpassword",e.app.loginappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Loginapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},t.prototype.reset_password=function(t){e.app.reset(),e.app.username=t,e.app.resetpassword_loginapp(!0)},t.prototype.resetpassword_loginapp=function(t){if(t)e.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+e.app.args.ip+":"+e.app.args.port+"!"),e.app.connect(e.app.args.ip,e.app.args.port),e.app.socket.onopen=e.app.onOpenLoginapp_resetpassword;else{var n=new e.Bundle;n.newMessage(e.messages.Loginapp_reqAccountResetPassword),n.writeString(e.app.username),n.send(e.app)}},t.prototype.onOpenBaseapp=function(){if(e.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),e.app.currserver="baseapp",e.app.baseappMessageImported)e.app.onImportClientMessagesCompleted();else{var t=new e.Bundle;t.newMessage(e.messages.Baseapp_importClientMessages),t.send(e.app),e.app.socket.onmessage=e.app.Client_onImportClientMessages,e.Event.fire("Baseapp_importClientMessages")}},t.prototype.login_baseapp=function(t){if(t)e.Event.fire("onLoginBaseapp"),e.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onOpenBaseapp);else{var n=new e.Bundle;n.newMessage(e.messages.Baseapp_loginBaseapp),n.writeString(e.app.username),n.writeString(e.app.password),n.send(e.app)}},t.prototype.reloginBaseapp=function(){(void 0==e.app.socket||null==e.app.socket)&&(e.app.resetSocket(),e.Event.fire("onReloginBaseapp"),e.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+e.app.baseappIp+":"+e.app.baseappPort+"!"),e.app.connect(e.app.baseappIp,e.app.baseappPort),void 0!=e.app.socket&&null!=e.app.socket&&(e.app.socket.onopen=e.app.onReOpenBaseapp))},t.prototype.onReOpenBaseapp=function(){e.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),e.app.currserver="baseapp";var t=new e.Bundle;t.newMessage(e.messages.Baseapp_reloginBaseapp),t.writeString(e.app.username),t.writeString(e.app.password),t.writeUint64(e.app.entity_uuid),t.writeInt32(e.app.entity_id),t.send(e.app);var n=new Date;e.app.lastTickCBTime=n.getTime()},t.prototype.Client_onHelloCB=function(t){e.app.serverVersion=t.readString(),e.app.serverScriptVersion=t.readString(),e.app.serverProtocolMD5=t.readString(),e.app.serverEntityDefMD5=t.readString();var n=t.readInt32();e.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+e.app.serverVersion+"), scriptVerInfo("+e.app.serverScriptVersion+"), serverProtocolMD5("+e.app.serverProtocolMD5+"), serverEntityDefMD5("+e.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;e.app.lastTickCBTime=r.getTime()},t.prototype.Client_onLoginFailed=function(t){var n=t.readUint16();e.app.serverdatas=t.readBlob(),e.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+e.app.serverErrs[n].name+"), datas("+e.app.serverdatas.length+")!"),e.Event.fire("onLoginFailed",n)},t.prototype.Client_onLoginSuccessfully=function(t){var n=t.readString();e.app.username=n,e.app.baseappIp=t.readString(),e.app.baseappPort=t.readUint16(),e.app.serverdatas=t.readBlob(),e.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+e.app.baseappIp+":"+e.app.baseappPort+"), datas("+e.app.serverdatas.length+")!"),e.app.disconnect(),e.app.login_baseapp(!0)},t.prototype.Client_onLoginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onLoginBaseappFailed",t)},t.prototype.Client_onReloginBaseappFailed=function(t){e.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onReloginBaseappFailed",t)},t.prototype.Client_onReloginBaseappSuccessfully=function(t){e.app.entity_uuid=t.readUint64(),e.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+e.app.username),e.Event.fire("onReloginBaseappSuccessfully")},t.prototype.getentityclass=function(t){var n=e.Entities[t];return void 0==n?(e.ERROR_MSG("KBEngineApp::getentityclass: entityType("+t+") is error!"),n):n},t.prototype.Client_onCreatedProxies=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=e.app.entities[n];if(e.app.entity_uuid=t,e.app.entity_id=n,void 0==a){var i=e.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new e.EntityCall,o.base.id=n,o.base.className=r,o.base.type=e.ENTITYCALL_TYPE_BASE,e.app.entities[n]=o;var p=e.bufferedCreateEntityMessages[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessages[n]),o.__init__(),o.inited=!0,e.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=e.bufferedCreateEntityMessages[n];void 0!=p&&(e.app.Client_onUpdatePropertys(p),delete e.bufferedCreateEntityMessages[n])}},t.prototype.getViewEntityIDFromStream=function(t){var n=0;if(e.app.entityIDAliasIDList.length>255)n=t.readInt32();else{var r=t.readUint8();if(e.app.entityIDAliasIDList.length<=r)return 0;n=e.app.entityIDAliasIDList[r]}return n},t.prototype.onUpdatePropertys_=function(t,n){var r=e.app.entities[t];if(void 0==r){var a=e.bufferedCreateEntityMessages[t];if(void 0!=a)return void e.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+t+") not found!");var i=new e.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(e.bufferedCreateEntityMessages[t]=i)}for(var o=e.moduledefs[r.className],p=o.propertys;n.length()>0;){var s=0;s=o.usePropertyDescrAlias?n.readUint8():n.readUint16();var l=p[s],c=l[5],d=l[6],u=l[4].createFromStream(n),y=r[l[2]];e.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+t+" "+l[2]+", val="+u+")!"),r[l[2]]=u,null!=c&&(32==d||64==d?r.inited&&c.call(r,y):r.inWorld&&c.call(r,y))}},t.prototype.Client_onUpdatePropertysOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.onUpdatePropertys_(n,t)},t.prototype.Client_onUpdatePropertys=function(t){var n=t.readInt32();e.app.onUpdatePropertys_(n,t)},t.prototype.onRemoteMethodCall_=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+t+") not found!");var a=0;a=e.moduledefs[r.className].useMethodDescrAlias?n.readUint8():n.readUint16();for(var i=e.moduledefs[r.className].methods[a],o=[],p=i[3],s=0;s0&&n!=e.app.entity_id&&e.app.entityIDAliasIDList.push(n);var r;r=e.moduledefs.Length>255?t.readUint16():t.readUint8();var a=!0;t.length()>0&&(a=t.readInt8()),r=e.moduledefs[r].name,e.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+e.app.spaceID+"), isOnGround("+a+")!");var i=e.app.entities[n];if(void 0==i){var o=e.bufferedCreateEntityMessages[n];if(void 0==o)return void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=e.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new e.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entities[n]=s,e.app.Client_onUpdatePropertys(o),delete e.bufferedCreateEntityMessages[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new e.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=e.ENTITYCALL_TYPE_CELL,e.app.entityIDAliasIDList=[],e.app.entities={},e.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),e.app.entityServerPos.x=i.position.x,e.app.entityServerPos.y=i.position.y,e.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),e.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},t.prototype.Client_onEntityLeaveWorldOptimized=function(t){var n=e.app.getViewEntityIDFromStream(t);e.app.Client_onEntityLeaveWorld(n)},t.prototype.Client_onEntityLeaveWorld=function(t){var n=e.app.entities[t];if(void 0==n)return void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+t+") not found!");if(n.inWorld&&n.leaveWorld(),e.app.entity_id>0&&t!=e.app.entity_id){for(var r=[],a=0;a0&&(r=t.readInt8());var a=e.app.entities[n];return void 0==a?void e.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,e.app.entityServerPos.x=a.position.x,e.app.entityServerPos.y=a.position.y,e.app.entityServerPos.z=a.position.z,void a.enterSpace())},t.prototype.Client_onEntityLeaveSpace=function(t){var n=e.app.entities[t];return void 0==n?void e.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+t+") not found!"):(e.app.clearSpace(!1),void n.leaveSpace())},t.prototype.Client_onKicked=function(t){e.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+e.app.serverErrs[t].name+")!"),e.Event.fire("onKicked",t)},t.prototype.Client_onCreateAccountResult=function(t){var n=t.readUint16(),r=t.readBlob();return e.Event.fire("onCreateAccountResult",n,r),0!=n?void e.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is failed! code="+e.app.serverErrs[n].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+e.app.username+" create is successfully!")},t.prototype.Client_onControlEntity=function(t,n){var r=e.app.entities[t];if(void 0==r)return void e.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+t+") not found!");var a=0!=n;if(a)e.app.player().id!=r.id&&e.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||t.entityLastLocalDir.distance(t.direction)>.001){t.entityLastLocalPos.x=t.position.x,t.entityLastLocalPos.y=t.position.y,t.entityLastLocalPos.z=t.position.z,t.entityLastLocalDir.x=t.direction.x,t.entityLastLocalDir.y=t.direction.y,t.entityLastLocalDir.z=t.direction.z;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(t.position.x),n.writeFloat(t.position.y),n.writeFloat(t.position.z),n.writeFloat(t.direction.x),n.writeFloat(t.direction.y),n.writeFloat(t.direction.z),n.writeUint8(t.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}for(var r in e.app.controlledEntities){var a=e.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=new e.Bundle;n.newMessage(e.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(e.app.spaceID),n.send(e.app)}}}},t.prototype.addSpaceGeometryMapping=function(t,n){e.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+t+"), respath("+n+")!"),e.app.spaceID=t,e.app.spaceResPath=n,e.Event.fire("addSpaceGeometryMapping",n)},t.prototype.clearSpace=function(t){e.app.entityIDAliasIDList=[],e.app.spacedata={},e.app.clearEntities(t),e.app.isLoadedGeometry=!1,e.app.spaceID=0},t.prototype.clearEntities=function(t){if(e.app.controlledEntities=[],t){for(var n in e.app.entities)e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy();e.app.entities={}}else{var r=e.app.player();for(var n in e.app.entities)n!=r.id&&(e.app.entities[n].inWorld&&e.app.entities[n].leaveWorld(),e.app.entities[n].onDestroy());e.app.entities={},e.app.entities[r.id]=r}},t.prototype.Client_initSpaceData=function(t){for(e.app.clearSpace(!1),e.app.spaceID=t.readInt32();t.length()>0;){var n=t.readString(),r=t.readString();e.app.Client_setSpaceData(e.app.spaceID,n,r)}e.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+e.app.spaceID+"), datas("+e.app.spacedata+")!")},t.prototype.Client_setSpaceData=function(t,n,r){e.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+t+"), key("+n+"), value("+r+")!"),e.app.spacedata[n]=r,"_mapping"==n&&e.app.addSpaceGeometryMapping(t,r),e.Event.fire("onSetSpaceData",t,n,r)},t.prototype.Client_delSpaceData=function(t,n){e.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+t+"), key("+n+")!"),delete e.app.spacedata[n],e.Event.fire("onDelSpaceData",t,n)},t.prototype.Client_getSpaceData=function(t,n){return e.app.spacedata[n]},t.prototype.Client_onUpdateBasePos=function(t,n,r){e.app.entityServerPos.x=t,e.app.entityServerPos.y=n,e.app.entityServerPos.z=r},t.prototype.Client_onUpdateBasePosXZ=function(t,n){e.app.entityServerPos.x=t,e.app.entityServerPos.z=n},t.prototype.Client_onUpdateData=function(t){var n=e.app.getViewEntityIDFromStream(t),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},t.prototype.Client_onSetEntityPosAndDir=function(t){var n=t.readInt32(),r=e.app.entities[n];return void 0==r?void e.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=t.readFloat(),r.position.y=t.readFloat(),r.position.z=t.readFloat(),r.direction.x=t.readFloat(),r.direction.y=t.readFloat(),r.direction.z=t.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},t.prototype.Client_onUpdateData_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,i,-1)},t.prototype.Client_onUpdateData_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,a,-1)},t.prototype.Client_onUpdateData_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8(),a=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,a,-1)},t.prototype.Client_onUpdateData_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,e.KBE_FLT_MAX,-1)},t.prototype.Client_onUpdateData_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readInt8();e.app._updateVolatileData(n,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,r,-1)},t.prototype.Client_onUpdateData_xz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,o,1)},t.prototype.Client_onUpdateData_xz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,i,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,i,1)},t.prototype.Client_onUpdateData_xz_pr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8(),i=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,i,1)},t.prototype.Client_onUpdateData_xz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],a,e.KBE_FLT_MAX,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,a,e.KBE_FLT_MAX,1)},t.prototype.Client_onUpdateData_xz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readInt8();e.app._updateVolatileData(n,r[0],e.KBE_FLT_MAX,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,a,1)},t.prototype.Client_onUpdateData_xyz=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_ypr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8(),p=t.readInt8(); -e.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0)},t.prototype.Client_onUpdateData_xyz_yp=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,o,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_yr=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8(),o=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,o,0)},t.prototype.Client_onUpdateData_xyz_pr=function(t){e.app.getViewEntityIDFromStream(t),t.readPackXZ(),t.readPackY(),t.readInt8(),t.readInt8();e.ERROR_MSG("调用错误方法,无法找到x,z")},t.prototype.Client_onUpdateData_xyz_y=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_p=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],e.KBE_FLT_MAX,i,e.KBE_FLT_MAX,0)},t.prototype.Client_onUpdateData_xyz_r=function(t){var n=e.app.getViewEntityIDFromStream(t),r=t.readPackXZ(),a=t.readPackY(),i=t.readInt8();t.readInt8();e.app._updateVolatileData(n,r[0],a,r[1],i,e.KBE_FLT_MAX,e.KBE_FLT_MAX,0)},t.prototype._updateVolatileData=function(t,n,r,a,i,o,p,s){var l=e.app.entities[t];if(void 0==l)return void e.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+t+") not found!");s>=0&&(l.isOnGround=s>0);var c=!1;p!=e.KBE_FLT_MAX&&(c=!0,l.direction.x=e.int82angle(p,!1)),o!=e.KBE_FLT_MAX&&(c=!0,l.direction.y=e.int82angle(o,!1)),i!=e.KBE_FLT_MAX&&(c=!0,l.direction.z=e.int82angle(i,!1));var d=!1;1==c&&(e.Event.fire("set_direction",l),d=!0);var u=!1;(n!=e.KBE_FLT_MAX||r!=e.KBE_FLT_MAX||a!=e.KBE_FLT_MAX)&&(u=!0),n==e.KBE_FLT_MAX&&(n=0),r==e.KBE_FLT_MAX&&(r=0),a==e.KBE_FLT_MAX&&(a=0),u&&(l.position.x=n+e.app.entityServerPos.x,l.position.y=r+e.app.entityServerPos.y,l.position.z=a+e.app.entityServerPos.z,d=!0,e.Event.fire("updatePosition",l)),d&&l.onUpdateVolatileData()},t.prototype.Client_onStreamDataStarted=function(t,n,r){e.Event.fire("onStreamDataStarted",t,n,r)},t.prototype.Client_onStreamDataRecv=function(t){var n=t.readUint16(),r=t.readBlob();e.Event.fire("onStreamDataRecv",n,r)},t.prototype.Client_onStreamDataCompleted=function(t){e.Event.fire("onStreamDataCompleted",t)},t.prototype.Client_onReqAccountResetPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountBindEmailCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+e.app.username+" is successfully!")},t.prototype.Client_onReqAccountNewPasswordCB=function(t){return 0!=t?void e.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is failed! code="+e.app.serverErrs[t].name+"!"):void e.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+e.app.username+" is successfully!")},t}();e.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function e(){this.name="",this.descr="",this.id=0}return e}();e.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr");var i;e.create=t,e.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index 0339480..f4485b2 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -1,25 +1,31 @@ /** - * KBEngine的html5客户端扩展ts版 1.x版本 + * KBEngine的html5客户端扩展ts版 2.x版本 * cocos creator 环境下使用方法 - * 将bin/kbengine.js导入为插件,将bin/kbengine.d.ts放在项目根目录下,即可 - * - * todo 未完成内容 - * 1、强类型匹配 - * 2、代码注释 * * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要在脚本下方加入 KBEngine['Entities'] = KBEngine['Entities'] || {};KBEngine['Entities']['你的实体类名']=你的实体类名;将声明提升至全局 - * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends KBEngine.Entity{}; - * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 + * 2、cocos creator环境下,按下面方法声明实体 + * @KBEngine.registerEntity('Account') + export default class AccountEntity extends KBEngine.Entity { + __init__() { + console.log('创建account') + } + } + //这里加入声明用于vscode代码提示 + declare global { + namespace KBEngine.Entities { + class Account extends AccountEntity { } + } + } + * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ /*----------------------------------------------------------------------------------------- global -----------------------------------------------------------------------------------------*/ namespace KBEngine { - export const CLIENT_VERSION ='2.0.0'; - export const CLIENT_SCRIPT_VERSION ='0.1.0'; + export const CLIENT_VERSION = '2.0.0'; + export const CLIENT_SCRIPT_VERSION = '0.1.0'; export const PACKET_MAX_SIZE = 1500; export const PACKET_MAX_SIZE_TCP = 1460; @@ -27,6 +33,8 @@ namespace KBEngine { export const MESSAGE_ID_LENGTH = 2; export const MESSAGE_LENGTH_LENGTH = 2; + export const MESSAGE_LENGTH1_LENGTH = 4; + export const MESSAGE_MAX_SIZE = 65535; export const CLIENT_NO_FLOAT = 0; export const KBE_FLT_MAX = 3.402823466e+38; @@ -35,6 +43,27 @@ namespace KBEngine { * 加上声明避免cocos creator编辑器报错 */ window['KBEngine'] = KBEngine; + + +if (!ArrayBuffer['transfer']) { + ArrayBuffer['transfer'] = function (source: ArrayBuffer, length: number): ArrayBuffer { + let dest = new ArrayBuffer(length); + + if (!(source instanceof ArrayBuffer) || !(dest instanceof ArrayBuffer)) { + throw new TypeError("ArrayBuffer.transfer, error: Source and destination must be ArrayBuffer instances"); + } + + if (dest.byteLength >= source.byteLength) { + let buf = new Uint8Array(dest); + buf.set(new Uint8Array(source), 0); + } + else { + throw new RangeError("ArrayBuffer.transfer, error: destination has not enough space"); + } + + return dest; + }; +}; /*----------------------------------------------------------------------------------------- number64bits -----------------------------------------------------------------------------------------*/ @@ -196,12 +225,11 @@ namespace KBEngine { -----------------------------------------------------------------------------------------*/ namespace KBEngine { export class EventInfo { - constructor(classinst, callbackfn) { - this.callbackfn = callbackfn; - this.classinst = classinst; + constructor(public classinst, public callbackfn) { } - classinst; - callbackfn; + } + export class FiredEvent { + constructor(public evtName, public evtInfo, public ars) { } } export interface IEvents { [evtName: string]: EventInfo[]; @@ -211,6 +239,8 @@ namespace KBEngine { } _events: IEvents = {}; + _isPause = false; + _firedEvents: FiredEvent[] = [] register(evtName: string, classinst, strCallback: string) { let callbackfn = classinst[strCallback]; if (callbackfn == undefined) { @@ -227,23 +257,47 @@ namespace KBEngine { let info = new EventInfo(classinst, callbackfn); evtlst.push(info); } - deregister(evtName: string, classinst) { + deregisterAll(classinst) { for (let itemkey in this._events) { - let evtlst = this._events[itemkey]; - while (true) { - let found = false; - for (let i = 0; i < evtlst.length; i++) { - let info = evtlst[i]; - if (info.classinst == classinst) { - evtlst.splice(i, 1); - found = true; - break; - } + this.deregister(itemkey, classinst) + } + } + deregister(evtName: string, classinst) { + let evtlst = this._events[evtName]; + if (!evtlst) return; + while (true) { + let found = false; + for (let i = 0; i < evtlst.length; i++) { + let info = evtlst[i]; + if (info.classinst == classinst) { + evtlst.splice(i, 1); + found = true; + break; } + } - if (!found) + if (!found) + break; + } + } + removeAllFiredEvent(classinst) { + this.removeFiredEvent("", classinst); + } + removeFiredEvent(evtName: string, classinst) { + let firedEvents = this._firedEvents; + while (true) { + let found = false; + for (let i = 0; i < firedEvents.length; i++) { + let evt = firedEvents[i]; + if ((evtName == "" || evt.evtName == evtName) && evt.evtInfo.classinst == classinst) { + firedEvents.splice(i, 1); + found = true; break; + } } + + if (!found) + break; } } fire(evtName: string, ...args: any[]) { @@ -264,7 +318,12 @@ namespace KBEngine { for (let i = 0; i < evtlst.length; i++) { let info = evtlst[i]; - info.callbackfn.apply(info.classinst, args || []); + if (!this._isPause) { + info.callbackfn.apply(info.classinst, args || []); + } else { + let eobj = new FiredEvent(evtName, info, args || []); + this._firedEvents.push(eobj); + } // if (args.length < 1) { // info.callbackfn.apply(info.classinst); // } @@ -273,6 +332,30 @@ namespace KBEngine { // } } } + pasue() { + this._isPause = true; + } + resume() { + this._isPause = false; + + let firedEvents = this._firedEvents; + while (firedEvents.length > 0) { + let evt = firedEvents.shift(); + let info = evt.evtInfo; + let ars = evt.ars; + + if (ars.length < 1) { + info.callbackfn.apply(info.classinst); + } + else { + info.callbackfn.apply(info.classinst, ars); + } + } + } + clear() { + this._events = {}; + this._firedEvents.splice(0, this._firedEvents.length); + } } export const Event = new Events(); } @@ -280,8 +363,19 @@ namespace KBEngine { memorystream -----------------------------------------------------------------------------------------*/ namespace KBEngine { + export class PackFloatXType { + _unionData = new ArrayBuffer(4); + fv = new Float32Array(this._unionData, 0, 1); + uv = new Uint32Array(this._unionData, 0, 1); + iv = new Int32Array(this._unionData, 0, 1); + } + + export const _xPackData = new PackFloatXType(); + export const _yPackData = new PackFloatXType(); + export const _zPackData = new PackFloatXType(); + export class MemoryStream { - constructor(size_or_buffer) { + constructor(size_or_buffer: number | ArrayBuffer) { if (size_or_buffer instanceof ArrayBuffer) { this.buffer = size_or_buffer; } @@ -318,7 +412,9 @@ namespace KBEngine { } readInt64() { - return new INT64(this.readUint32(), this.readUint32()); + let lo = this.readUint32() + let hi = this.readUint32() + return new INT64(lo, hi); } readUint8() { @@ -340,7 +436,9 @@ namespace KBEngine { } readUint64() { - return new UINT64(this.readUint32(), this.readUint32()); + let lo = this.readUint32() + let hi = this.readUint32() + return new UINT64(lo, hi); } readFloat() { @@ -408,8 +506,8 @@ namespace KBEngine { } readPackXZ() { - let xPackData = new MemoryStream.PackFloatXType(); - let zPackData = new MemoryStream.PackFloatXType(); + let xPackData = _xPackData; + let zPackData = _zPackData; xPackData.fv[0] = 0.0; zPackData.fv[0] = 0.0; @@ -443,7 +541,13 @@ namespace KBEngine { readPackY() { let v = this.readUint16(); - return v; + + let yPackData = _yPackData; + yPackData.uv[0] = 0x40000000; + yPackData.uv[0] |= (v & 0x7fff) << 12; + yPackData.fv[0] -= 2.0; + yPackData.uv[0] |= (v & 0x8000) << 16; + return yPackData.fv[0]; } //--------------------------------------------------------------------------------- @@ -484,7 +588,7 @@ namespace KBEngine { this.writeUint8(v >> i * 8 & 0xff); } - writeUint64(v) { + writeUint64(v: UINT64) { this.writeUint32(v.lo); this.writeUint32(v.hi); } @@ -560,6 +664,15 @@ namespace KBEngine { buf[i++] = 0; this.wpos += i; } + append(stream: MemoryStream, offset: number, size: number) { + if (size > this.space()) { + this.buffer = ArrayBuffer['transfer'](this.buffer, this.buffer.byteLength + size * 2); + } + + let buf = new Uint8Array(this.buffer, this.wpos, size); + buf.set(new Uint8Array(stream.buffer, offset, size), 0); + this.wpos += size; + } //--------------------------------------------------------------------------------- readSkip(v) { @@ -587,11 +700,31 @@ namespace KBEngine { } //--------------------------------------------------------------------------------- - getbuffer(v) { + getbuffer() { return this.buffer.slice(this.rpos, this.wpos); } + setbuffer(buffer: ArrayBuffer) { + this.clear(); + this.buffer = buffer; + } + size() { + return this.buffer.byteLength; + } + clear() { + this.rpos = this.wpos = 0; + if (this.buffer.byteLength > PACKET_MAX_SIZE) { + this.buffer = new ArrayBuffer(PACKET_MAX_SIZE) + } + } + reclaimObject() { + this.clear() + if (MemoryStream._objects != undefined) { + MemoryStream._objects.push(this) + } + } } export module MemoryStream { + export const _objects: MemoryStream[] = [] export class PackFloatXType { _unionData: ArrayBuffer; fv: Float32Array; @@ -604,6 +737,9 @@ namespace KBEngine { this.iv = new Int32Array(this._unionData, 0, 1); }; } + export function createObject() { + return MemoryStream._objects.length > 0 ? MemoryStream._objects.pop() : new MemoryStream(PACKET_MAX_SIZE_TCP); + } } } /*----------------------------------------------------------------------------------------- @@ -611,10 +747,14 @@ namespace KBEngine { -----------------------------------------------------------------------------------------*/ namespace KBEngine { export class Bundle { + static _objects: Bundle[] = [] + static createObject() { + return Bundle._objects.length > 0 ? Bundle._objects.pop() : new Bundle(); + } constructor() { - this.stream = new MemoryStream(PACKET_MAX_SIZE_TCP); + this.stream = MemoryStream.createObject(); } - memorystreams: Array = new Array(); + memorystreams: Array = new Array(); stream: MemoryStream; numMessage: number = 0; messageLengthBuffer: Uint8Array = null; @@ -655,6 +795,8 @@ namespace KBEngine { this.writeMsgLength(this.messageLength); if (this.stream) this.memorystreams.push(this.stream); + + this.stream = MemoryStream.createObject(); } if (issend) { @@ -669,19 +811,18 @@ namespace KBEngine { this.fini(true); for (let i = 0; i < this.memorystreams.length; i++) { - let stream = this.memorystreams[i]; - network.send(stream.getbuffer()); + let tmpStream = this.memorystreams[i]; + network.send(tmpStream.getbuffer()); } - this.memorystreams = new Array(); - this.stream = new MemoryStream(PACKET_MAX_SIZE_TCP); + this.reclaimObject(); } //--------------------------------------------------------------------------------- checkStream(v) { if (v > this.stream.space()) { this.memorystreams.push(this.stream); - this.stream = new MemoryStream(PACKET_MAX_SIZE_TCP); + this.stream = MemoryStream.createObject(); } this.messageLength += v; @@ -747,6 +888,29 @@ namespace KBEngine { this.checkStream(v.length + 4); this.stream.writeBlob(v); } + clear() { + for (let i = 0; i < this.memorystreams.length; i++) { + if (this.stream != this.memorystreams[i]) + this.memorystreams[i].reclaimObject(); + } + + if (this.stream) + this.stream.clear(); + else + this.stream = MemoryStream.createObject(); + + this.memorystreams = new Array(); + this.numMessage = 0; + this.messageLengthBuffer = null; + this.messageLength = 0; + this.msgtype = null; + } + reclaimObject() { + this.clear(); + + if (Bundle._objects != undefined) + Bundle._objects.push(this); + } } export const reader = new MemoryStream(0); export interface IDataType2Id { @@ -824,6 +988,8 @@ namespace KBEngine { datatype2id["FIXED_DICT"] = 18; datatype2id["ARRAY"] = 19; + + datatype2id["ENTITYCALL"] = 20; } mappingDataType(); @@ -864,24 +1030,11 @@ namespace KBEngine { } } export class Message { - constructor(id, name, length, argstype, args, handler) { - this.id = id; - this.name = name; - this.length = length; - this.argsType = argstype; + constructor(public id, public name, public length, public argsType, public args, public handler) { for (let i = 0; i < args.length; i++) { args[i] = bindReader(args[i]); } - - this.args = args; - this.handler = handler; } - id; - name; - length; - argsType; - args; - handler; createFromStream(msgstream) { if (this.args.length <= 0) return msgstream; @@ -928,12 +1081,8 @@ namespace KBEngine { -----------------------------------------------------------------------------------------*/ namespace KBEngine { export class Vector2 { - constructor(x:number, y:number) { - this.x = x; - this.y = y; + constructor(public x: number, public y: number) { } - x: number; - y: number; distance(pos: Vector2) { let x = pos.x - this.x; let y = pos.y - this.y; @@ -970,14 +1119,11 @@ namespace KBEngine { } } export class Vector3 { - constructor(x:number, y:number, z:number) { + constructor(public x: number, public y: number, public z: number) { this.x = x; this.y = y; this.z = z; } - x: number; - y: number; - z: number; distance(pos: Vector3) { let x = pos.x - this.x; let y = pos.y - this.y; @@ -1025,29 +1171,22 @@ namespace KBEngine { return this; } } - /** - * todo 这个类的第四个参数的没搞清楚,所有如果没有必要,不要用这个东西 - */ export class Vector4 { - constructor(x:number, y:number, z:number, w:number) { + constructor(public x: number, public y: number, public z: number, public w: number) { this.x = x; this.y = y; this.z = z; this.w = w; } - x: number; - y: number; - z: number; - w: number; distance(pos: Vector4) { - var x = pos.x - this.x; - var y = pos.y - this.y; - var z = pos.z - this.z; - var w = pos.w - this.w; + let x = pos.x - this.x; + let y = pos.y - this.y; + let z = pos.z - this.z; + let w = pos.w - this.w; return Math.sqrt(x * x + y * y + z * z + w * w); } - add(vec4:Vector4) { + add(vec4: Vector4) { this.x += vec4.x; this.y += vec4.y; this.z += vec4.z; @@ -1055,7 +1194,7 @@ namespace KBEngine { return this; } - sub(vec4:Vector4) { + sub(vec4: Vector4) { this.x -= vec4.x; this.y -= vec4.y; this.z -= vec4.z; @@ -1063,14 +1202,14 @@ namespace KBEngine { return this; } - mul(num:number) { + mul(num: number) { this.x *= num; this.y *= num; this.z *= num; this.w *= num; return this; } - div(num:number) { + div(num: number) { this.x /= num; this.y /= num; this.z /= num; @@ -1094,7 +1233,7 @@ namespace KBEngine { } return value < min_inclusive ? min_inclusive : value < max_inclusive ? value : max_inclusive; } - export function int82angle(angle, half) { + export function int82angle(angle: number, half: boolean) { return angle * (Math.PI / (half ? 254.0 : 128.0)); } export function angle2int8(v: number, half: boolean) { @@ -1113,10 +1252,10 @@ namespace KBEngine { /*----------------------------------------------------------------------------------------- entity -----------------------------------------------------------------------------------------*/ + namespace KBEngine { - export namespace Entities { + export module Entities { } - } export class Entity { constructor() { @@ -1340,6 +1479,12 @@ namespace KBEngine { Event.fire("set_direction", this); } } + export function registerEntity(name: string) { + return (ctor: new () => Entity) => { + KBEngine['Entities'] = KBEngine['Entities'] || {} + KBEngine['Entities'][name] = ctor; + } + } } /*----------------------------------------------------------------------------------------- EntityCall @@ -1347,9 +1492,9 @@ namespace KBEngine { namespace KBEngine { export const ENTITYCALL_TYPE_CELL = 0; export const ENTITYCALL_TYPE_BASE = 1; - + //这个东西好像没有同步给客户端 - export class EntityComponent{ + export class EntityComponent { } @@ -1371,7 +1516,7 @@ namespace KBEngine { } newCall() { if (this.bundle == null) - this.bundle = new Bundle(); + this.bundle = Bundle.createObject(); if (this.type == ENTITYCALL_TYPE_CELL) this.bundle.newMessage(messages['Baseapp_onRemoteCallCellMethodFromClient']); @@ -1658,12 +1803,14 @@ namespace KBEngine { createFromStream(stream) { if (CLIENT_NO_FLOAT) { - return new Vector2(reader.readInt32.call(stream), - reader.readInt32.call(stream)); + let x = reader.readInt32.call(stream) + let y = reader.readInt32.call(stream) + return new Vector2(x, y); } else { - return new Vector2(reader.readFloat.call(stream), - reader.readFloat.call(stream)); + let x = reader.readFloat.call(stream) + let y = reader.readFloat.call(stream) + return new Vector2(x, y); } } @@ -1679,7 +1826,7 @@ namespace KBEngine { } parseDefaultValStr(v) { - return new KBEngine.Vector2(0.0, 0.0);; + return new Vector2(0.0, 0.0);; } isSameType(v) { @@ -1719,7 +1866,7 @@ namespace KBEngine { } parseDefaultValStr(v) { - return new KBEngine.Vector3(0.0, 0.0, 0.0); + return new Vector3(0.0, 0.0, 0.0); } isSameType(v) { @@ -1738,13 +1885,13 @@ namespace KBEngine { if (CLIENT_NO_FLOAT) { return new Vector4(reader.readInt32.call(stream), reader.readInt32.call(stream), - reader.readInt32.call(stream), + reader.readInt32.call(stream), reader.readInt32.call(stream)); } else { return new Vector4(reader.readFloat.call(stream), reader.readFloat.call(stream), - reader.readFloat.call(stream), + reader.readFloat.call(stream), reader.readFloat.call(stream)); } } @@ -1765,7 +1912,7 @@ namespace KBEngine { } parseDefaultValStr(v) { - return new KBEngine.Vector4(0.0, 0.0, 0.0, 0.0); + return new Vector4(0.0, 0.0, 0.0, 0.0); } isSameType(v) { @@ -1819,7 +1966,7 @@ namespace KBEngine { return typeof (v) == "string"; } } - export class DATATYPE_ENTITY_COMPONENT{ + export class DATATYPE_ENTITY_COMPONENT { bind() { } @@ -1981,8 +2128,8 @@ namespace KBEngine { export const VECTOR3 = new DATATYPE_VECTOR3(); export const VECTOR4 = new DATATYPE_VECTOR4(); export const PYTHON = new DATATYPE_PYTHON(); - export const PY_DICT = new DATATYPE_PYTHON(); - export const PY_LIST = new DATATYPE_PYTHON(); + // export const PY_DICT = new DATATYPE_PYTHON(); + // export const PY_LIST = new DATATYPE_PYTHON(); export const UNICODE = new DATATYPE_UNICODE(); export const ENTITYCALL = new DATATYPE_ENTITYCALL(); export const ENTITY_COMPONENT = new DATATYPE_ENTITY_COMPONENT(); @@ -1999,17 +2146,168 @@ namespace KBEngine { updateHZ = 100; serverHeartbeatTick = 15; - //TODO wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 - protocol: string = "ws://"; + isWss: boolean = false; + //TODO wss需要参数,因为服务器不支持wss,需要使用Nginx转发一次,在这里设置强制修改baseapp连接端口到Nginx端口 + get protocol(): string { return this.isWss ? "wss://" : "ws://" } forceBasePort: number = 0; - // Reference: http://www.org/docs/programming/clientsdkprogramming.html, client types + // Reference: http://github.io/docs/programming/clientsdkprogramming.html, client types clientType = 5; // 在Entity初始化时是否触发属性的set_*事件(callPropertysSetMethods) isOnInitCallPropertysSetMethods = true; } + export const EventTypes = { + // Create new account. + // param1(string): accountName + // param2(string): password + // param3(bytes): datas // Datas by user defined. Data will be recorded into the KBE account database, you can access the datas through the script layer. If you use third-party account system, datas will be submitted to the third-party system. + createAccount: "createAccount", + + // Login to server. + // param1(string): accountName + // param2(string): password + // param3(bytes): datas // Datas by user defined. Data will be recorded into the KBE account database, you can access the datas through the script layer. If you use third-party account system, datas will be submitted to the third-party system. + login: "login", + + // Logout to baseapp, called when exiting the client. + logout: "logout", + + // Relogin to baseapp. + reloginBaseapp: "reloginBaseapp", + + // Request server binding account Email. + // param1(string): emailAddress + bindAccountEmail: "bindAccountEmail", + + // Request to set up a new password for the account. Note: account must be online. + // param1(string): old_password + // param2(string): new_password + newPassword: "newPassword", + + // ------------------------------------连接相关------------------------------------ + + // Kicked of the current server. + // param1(uint16): retcode. // server_errors + onKicked: "onKicked", + + // Disconnected from the server. + onDisconnected: "onDisconnected", + + // Status of connection server. + // param1(bool): success or fail + onConnectionState: "onConnectionState", + + // ------------------------------------logon相关------------------------------------ + + // Create account feedback results. + // param1(uint16): retcode. // server_errors + // param2(bytes): datas. // If you use third-party account system, the system may fill some of the third-party additional datas. + onCreateAccountResult: "onCreateAccountResult", + + // Engine version mismatch. + // param1(string): clientVersion + // param2(string): serverVersion + onVersionNotMatch: "onVersionNotMatch", + + // script version mismatch. + // param1(string): clientScriptVersion + // param2(string): serverScriptVersion + onScriptVersionNotMatch: "onScriptVersionNotMatch", + + // Login failed. + // param1(uint16): retcode. // server_errors + onLoginFailed: "onLoginFailed", + + // Login to baseapp. + onLoginBaseapp: "onLoginBaseapp", + + // Login baseapp failed. + // param1(uint16): retcode. // server_errors + onLoginBaseappFailed: "onLoginBaseappFailed", + + // Relogin to baseapp. + onReloginBaseapp: "onReloginBaseapp", + + // Relogin baseapp success. + onReloginBaseappSuccessfully: "onReloginBaseappSuccessfully", + + // Relogin baseapp failed. + // param1(uint16): retcode. // server_errors + onReloginBaseappFailed: "onReloginBaseappFailed", + + // ------------------------------------实体cell相关事件------------------------------------ + + // Entity enter the client-world. + // param1: Entity + onEnterWorld: "onEnterWorld", + + // Entity leave the client-world. + // param1: Entity + onLeaveWorld: "onLeaveWorld", + + // Player enter the new space. + // param1: Entity + onEnterSpace: "onEnterSpace", + + // Player leave the space. + // param1: Entity + onLeaveSpace: "onLeaveSpace", + + // Sets the current position of the entity. + // param1: Entity + set_position: "set_position", + + // Sets the current direction of the entity. + // param1: Entity + set_direction: "set_direction", + + // The entity position is updated, you can smooth the moving entity to new location. + // param1: Entity + updatePosition: "updatePosition", + + // The current space is specified by the geometry mapping. + // Popular said is to load the specified Map Resources. + // param1(string): resPath + addSpaceGeometryMapping: "addSpaceGeometryMapping", + + // Server spaceData set data. + // param1(int32): spaceID + // param2(string): key + // param3(string): value + onSetSpaceData: "onSetSpaceData", + + // Start downloading data. + // param1(int32): rspaceID + // param2(string): key + onDelSpaceData: "onDelSpaceData", + + // Triggered when the entity is controlled or out of control. + // param1: Entity + // param2(bool): isControlled + onControlled: "onControlled", + // Lose controlled entity. + // param1: Entity + onLoseControlledEntity: "onLoseControlledEntity", + + // ------------------------------------数据下载相关------------------------------------ + + // Start downloading data. + // param1(uint16): resouce id + // param2(uint32): data size + // param3(string): description + onStreamDataStarted: "onStreamDataStarted", + + // Receive data. + // param1(uint16): resouce id + // param2(bytes): datas + onStreamDataRecv: "onStreamDataRecv", + + // The downloaded data is completed. + // param1(uint16): resouce id + onStreamDataCompleted: "onStreamDataCompleted", + } } /*----------------------------------------------------------------------------------------- KBEngine app @@ -2017,13 +2315,10 @@ namespace KBEngine { namespace KBEngine { export const moduledefs = {}; export class KBEngineApp { - constructor(args: KBEngineArgs) { + constructor(public args: KBEngineArgs) { // console.assert(app == null || app == undefined, "Assertion of app not is null"); - app = this; - this.args = args; } - args: KBEngineArgs; baseappIp: string; username = "testhtml51"; password = "123456"; @@ -2034,6 +2329,7 @@ namespace KBEngine { baseappMessageImported = false; serverErrorsDescrImported = false; entitydefImported = false; + // 这个参数的选择必须与kbengine_defs.xml::cellapp/aliasEntityID的参数保持一致 useAliasEntityID = true; serverErrs: { [err: string]: ServerErr } = {}; @@ -2047,9 +2343,18 @@ namespace KBEngine { baseappPort = 0; baseappUdpPort = 0; + currMsgID = 0; + currMsgCount = 0; + currMsgLen = 0; + + fragmentStream = null; + fragmentDatasFlag = FragmentDataTypes.FRAGMENT_DATA_UNKNOW; + fragmentDatasRemain = 0; + socket; currserver: string; currstate = "create"; + currconnect = 'loginapp'; // 扩展数据 serverdatas = ""; @@ -2084,6 +2389,8 @@ namespace KBEngine { lastTickTime = Date.now(); lastTickCBTime = Date.now(); component; + msgStream = new MemoryStream(PACKET_MAX_SIZE_TCP); + resetSocket() { try { if (app.socket != undefined && app.socket != null) { @@ -2109,6 +2416,7 @@ namespace KBEngine { app.currserver = "loginapp"; app.currstate = "create"; + app.currconnect = 'loginapp' // 扩展数据 app.serverdatas = ""; @@ -2150,19 +2458,23 @@ namespace KBEngine { app.component = "client"; } installEvents() { - Event.register("createAccount", app, "createAccount"); - Event.register("login", app, "login"); - Event.register("reloginBaseapp", app, "reloginBaseapp"); - Event.register("bindAccountEmail", app, "bindAccountEmail"); - Event.register("newPassword", app, "newPassword"); + Event.register(EventTypes.createAccount, app, "createAccount"); + Event.register(EventTypes.login, app, "login"); + Event.register(EventTypes.logout, app, 'logout') + Event.register(EventTypes.reloginBaseapp, app, "reloginBaseapp"); + Event.register(EventTypes.bindAccountEmail, app, "bindAccountEmail"); + Event.register(EventTypes.newPassword, app, "newPassword"); } uninstallEvents() { - Event.deregister("reloginBaseapp", app); - Event.deregister("login", app); - Event.deregister("createAccount", app); + Event.deregister(EventTypes.createAccount, app); + Event.deregister(EventTypes.login, app); + Event.deregister(EventTypes.logout, app) + Event.deregister(EventTypes.reloginBaseapp, app); + Event.deregister(EventTypes.bindAccountEmail, app); + Event.deregister(EventTypes.newPassword, app); } hello() { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); if (app.currserver == "loginapp") bundle.newMessage(messages['Loginapp_hello']); @@ -2189,7 +2501,7 @@ namespace KBEngine { } catch (e) { ERROR_MSG('WebSocket init error!'); - Event.fire("onConnectionState", false); + Event.fire(EventTypes.onConnectionState, false); return; } @@ -2205,52 +2517,156 @@ namespace KBEngine { onopen() { INFO_MSG('connect success!'); app.socket.onerror = app.onerror_after_onopen; - Event.fire("onConnectionState", true); + Event.fire(EventTypes.onConnectionState, true); } onerror_before_onopen(evt) { ERROR_MSG('connect error:' + evt.data); app.resetSocket(); - Event.fire("onConnectionState", false); + Event.fire(EventTypes.onConnectionState, false); } onerror_after_onopen(evt) { ERROR_MSG('connect error:' + evt.data); app.resetSocket(); - Event.fire("onDisconnected"); + Event.fire(EventTypes.onDisconnected); } onmessage(msg) { - let stream = new MemoryStream(msg.data); + let stream = app.msgStream; + stream.setbuffer(msg.data); stream.wpos = msg.data.byteLength; - while (stream.rpos < stream.wpos) { - let msgid = stream.readUint16(); - let msgHandler = clientmessages[msgid]; + while (stream.length() > 0 || app.fragmentStream != null) { + if (app.fragmentDatasFlag == FragmentDataTypes.FRAGMENT_DATA_UNKNOW) { + if (app.currMsgID == 0) { + if (MESSAGE_ID_LENGTH > 1 && stream.length() < MESSAGE_ID_LENGTH) { + app.writeFragmentMessage(FragmentDataTypes.FRAGMENT_DATA_MESSAGE_ID, stream, MESSAGE_ID_LENGTH); + break; + } + + app.currMsgID = stream.readUint16(); + } + + let msgHandler = clientmessages[app.currMsgID]; + + if (!msgHandler) { + app.currMsgID = 0; + app.currMsgLen = 0; + ERROR_MSG("KBEngineApp::onmessage[" + app.currserver + "]: not found msg(" + app.currMsgID + ")!"); + break; + } - if (!msgHandler) { - ERROR_MSG("KBEngineApp::onmessage[" + app.currserver + "]: not found msg(" + msgid + ")!"); - } - else { let msglen = msgHandler.length; - if (msglen == -1) { - msglen = stream.readUint16(); + if (app.currMsgLen == 0) { + if (msglen == -1) { + if (stream.length() < MESSAGE_LENGTH_LENGTH) { + app.writeFragmentMessage(FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH, stream, MESSAGE_LENGTH_LENGTH); + break; + } + else { + msglen = stream.readUint16(); + app.currMsgLen = msglen; + + // 扩展长度 + if (msglen == MESSAGE_MAX_SIZE) { + if (stream.length() < MESSAGE_LENGTH1_LENGTH) { + app.writeFragmentMessage(FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH1, stream, MESSAGE_LENGTH1_LENGTH); + break; + } + + app.currMsgLen = stream.readUint32(); + } + } + } + else { + app.currMsgLen = msglen; + } + } - // 扩展长度 - if (msglen == 65535) - msglen = stream.readUint32(); + if (app.fragmentStream != null && app.fragmentStream.length() >= app.currMsgLen) { + msgHandler.handleMessage(app.fragmentStream); + app.fragmentStream = null; + } + else if (stream.length() < app.currMsgLen && stream.length() > 0) { + app.writeFragmentMessage(FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY, stream, app.currMsgLen); + break; } + else { + let wpos = stream.wpos; + let rpos = stream.rpos + msglen; + stream.wpos = rpos; + msgHandler.handleMessage(stream); + stream.wpos = wpos; + stream.rpos = rpos; + } + + app.currMsgID = 0; + app.currMsgLen = 0; + app.fragmentStream = null; + } + else { + if (app.mergeFragmentMessage(stream)) + break; + } + } + } + writeFragmentMessage(FragmentDataType, stream: MemoryStream, datasize) { + let opsize = stream.length(); - let wpos = stream.wpos; - let rpos = stream.rpos + msglen; - stream.wpos = rpos; - msgHandler.handleMessage(stream); - stream.wpos = wpos; - stream.rpos = rpos; + app.fragmentDatasRemain = datasize - opsize; + app.fragmentDatasFlag = FragmentDataType; + app.fragmentStream = stream; + } + + mergeFragmentMessage(stream: MemoryStream) { + let opsize = stream.length(); + if (opsize == 0) + return 0; + + let fragmentStream = app.fragmentStream; + // console.assert(fragmentStream != null); + + if (opsize >= app.fragmentDatasRemain) { + fragmentStream.append(stream, stream.rpos, app.fragmentDatasRemain); + + switch (app.fragmentDatasFlag) { + case FragmentDataTypes.FRAGMENT_DATA_MESSAGE_ID: + app.currMsgID = fragmentStream.readUint16(); + app.fragmentStream = null; + break; + + case FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH: + app.currMsgLen = fragmentStream.readUint16(); + app.fragmentStream = null; + break; + + case FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH1: + app.currMsgLen = fragmentStream.readUint32(); + app.fragmentStream = null; + break; + + case FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY: + default: + break; } + + stream.rpos += app.fragmentDatasRemain; + app.fragmentDatasFlag = FragmentDataTypes.FRAGMENT_DATA_UNKNOW; + app.fragmentDatasRemain = 0; + return false; + } + else { + fragmentStream.append(stream, stream.rpos, opsize); + app.fragmentDatasRemain -= opsize; + stream.done(); + return true; } } onclose() { INFO_MSG('connect close:' + app.currserver); + + if (app.currconnect != app.currstate) return; + app.resetSocket(); - Event.fire("onDisconnected"); + Event.fire(EventTypes.onDisconnected); //if(app.currserver != "loginapp") // app.reset(); } @@ -2267,7 +2683,7 @@ namespace KBEngine { return; let dateObject = new Date(); - if ((dateObject.getTime() - app.lastTickTime) / 1000 > app.args.serverHeartbeatTick) { + if ((dateObject.getTime() - app.lastTickTime) / 1000 > app.args.serverHeartbeatTick / 2) { // 如果心跳回调接收时间小于心跳发送时间,说明没有收到回调 // 此时应该通知客户端掉线了 if (app.lastTickCBTime < app.lastTickTime) { @@ -2277,14 +2693,14 @@ namespace KBEngine { if (app.currserver == "loginapp") { if (messages['Loginapp_onClientActiveTick'] != undefined) { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Loginapp_onClientActiveTick']); bundle.send(app); } } else { if (messages['Baseapp_onClientActiveTick'] != undefined) { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Baseapp_onClientActiveTick']); bundle.send(app); } @@ -2296,8 +2712,8 @@ namespace KBEngine { app.updatePlayerToServer(); } Client_onAppActiveTickCB() { - let dateObject = new Date(); - app.lastTickCBTime = dateObject.getTime(); + // let dateObject = new Date(); + app.lastTickCBTime = Date.now() //dateObject.getTime(); } serverErr(id) { let e = app.serverErrs[id]; @@ -2308,6 +2724,7 @@ namespace KBEngine { return e.name + " [" + e.descr + "]"; } + Client_onImportServerErrorsDescr(stream) { let size = stream.readUint16(); while (size > 0) { @@ -2323,15 +2740,22 @@ namespace KBEngine { INFO_MSG("Client_onImportServerErrorsDescr: id=" + e.id + ", name=" + e.name + ", descr=" + e.descr); } } + Client_onImportClientSdk(stream: MemoryStream) { + let remainingFiles = stream.readInt32(); + let fileName = stream.readString(); + let fileSize = stream.readInt32(); + let fileDatas = stream.readBlob() + Event.fire("onImportClientSDK", remainingFiles, fileName, fileSize, fileDatas); + } onOpenLoginapp_login() { INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"); - Event.fire("onConnectionState", true); + Event.fire(EventTypes.onConnectionState, true); app.currserver = "loginapp"; app.currstate = "login"; if (!app.loginappMessageImported) { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages.Loginapp_importClientMessages); bundle.send(app); app.socket.onmessage = app.Client_onImportClientMessages; @@ -2342,6 +2766,7 @@ namespace KBEngine { app.onImportClientMessagesCompleted(); } } + onOpenLoginapp_createAccount() { Event.fire("onConnectionState", true); INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"); @@ -2349,7 +2774,7 @@ namespace KBEngine { app.currstate = "createAccount"; if (!app.loginappMessageImported) { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages.Loginapp_importClientMessages); bundle.send(app); app.socket.onmessage = app.Client_onImportClientMessages; @@ -2369,7 +2794,7 @@ namespace KBEngine { if (!app.serverErrorsDescrImported) { INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"); app.serverErrorsDescrImported = true; - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Loginapp_importServerErrorsDescr']); bundle.send(app); } @@ -2388,7 +2813,7 @@ namespace KBEngine { if (!app.entitydefImported) { INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ..."); - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages.Baseapp_importClientEntityDef); bundle.send(app); Event.fire("Baseapp_importClientEntityDef"); @@ -2463,7 +2888,7 @@ namespace KBEngine { Client_onImportClientEntityDef(stream) { app.createDataTypeFromStreams(stream, true); - while (!stream.readEOF()) { + while (stream.length() > 0) { let scriptmodule_name = stream.readString(); let scriptUtype = stream.readUint16(); let propertysize = stream.readUint16(); @@ -2488,12 +2913,7 @@ namespace KBEngine { let self_base_methods = currModuleDefs["base_methods"]; let self_cell_methods = currModuleDefs["cell_methods"]; - try { - var Class = KBEngine['Entities'][scriptmodule_name]; - } - catch (e) { - let Class = undefined; - } + let Class = KBEngine['Entities'][scriptmodule_name]; while (propertysize > 0) { propertysize--; @@ -2630,72 +3050,97 @@ namespace KBEngine { Client_onVersionNotMatch(stream) { app.serverVersion = stream.readString(); ERROR_MSG("Client_onVersionNotMatch: verInfo=" + app.clientVersion + " not match(server: " + app.serverVersion + ")"); - Event.fire("onVersionNotMatch", app.clientVersion, app.serverVersion); + Event.fire(EventTypes.onVersionNotMatch, app.clientVersion, app.serverVersion); } Client_onScriptVersionNotMatch(stream) { app.serverScriptVersion = stream.readString(); ERROR_MSG("Client_onScriptVersionNotMatch: verInfo=" + app.clientScriptVersion + " not match(server: " + app.serverScriptVersion + ")"); - Event.fire("onScriptVersionNotMatch", app.clientScriptVersion, app.serverScriptVersion); + Event.fire(EventTypes.onScriptVersionNotMatch, app.clientScriptVersion, app.serverScriptVersion); } onImportEntityDefCompleted() { INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"); app.entitydefImported = true; app.login_baseapp(false); } - Client_onImportClientMessages(msg) { - let stream = new MemoryStream(msg.data); - let msgid = stream.readUint16(); + importClientMessages(stream) { + while (app.currMsgCount > 0) { + app.currMsgCount--; + + let msgid = stream.readUint16(); + let msglen = stream.readInt16(); + let msgname = stream.readString(); + let argtype = stream.readInt8(); + let argsize = stream.readUint8(); + let argstypes = new Array(argsize); + + for (let i = 0; i < argsize; i++) { + argstypes[i] = stream.readUint8(); + } + + let handler = null; + let isClientMethod = msgname.indexOf("Client_") >= 0; + if (isClientMethod) { + handler = app[msgname]; + if (handler == null || handler == undefined) { + WARNING_MSG("KBEngineApp::onImportClientMessages[" + app.currserver + "]: interface(" + msgname + "/" + msgid + ") no implement!"); + handler = null; + } + else { + INFO_MSG("KBEngineApp::onImportClientMessages: import(" + msgname + ") successfully!"); + } + } - if (msgid == messages.onImportClientMessages.id) { - let msglen = stream.readUint16(); - let msgcount = stream.readUint16(); + if (msgname.length > 0) { + messages[msgname] = new Message(msgid, msgname, msglen, argtype, argstypes, handler); - INFO_MSG("KBEngineApp::onImportClientMessages: start(" + msgcount + ") ...!"); + if (isClientMethod) + clientmessages[msgid] = messages[msgname]; + else + messages[app.currserver][msgid] = messages[msgname]; + } + else { + messages[app.currserver][msgid] = new Message(msgid, msgname, msglen, argtype, argstypes, handler); + } + }; - while (msgcount > 0) { - msgcount--; + app.onImportClientMessagesCompleted(); + app.currMsgID = 0; + app.currMsgLen = 0; + app.currMsgCount = 0; + app.fragmentStream = null; + } - msgid = stream.readUint16(); - msglen = stream.readInt16(); - let msgname = stream.readString(); - let argtype = stream.readInt8(); - let argsize = stream.readUint8(); - let argstypes = new Array(argsize); + Client_onImportClientMessages(msg) { + let stream = new MemoryStream(msg.data); + stream.wpos = msg.data.byteLength; - for (let i = 0; i < argsize; i++) { - argstypes[i] = stream.readUint8(); - } + if (app.currMsgID == 0) { + app.currMsgID = stream.readUint16(); + } - let handler = null; - let isClientMethod = msgname.indexOf("Client_") >= 0; - if (isClientMethod) { - handler = app[msgname]; - if (handler == null || handler == undefined) { - WARNING_MSG("KBEngineApp::onImportClientMessages[" + app.currserver + "]: interface(" + msgname + "/" + msgid + ") no implement!"); - handler = null; - } - else { - INFO_MSG("KBEngineApp::onImportClientMessages: import(" + msgname + ") successfully!"); - } - } + if (app.currMsgID == messages.onImportClientMessages.id) { + if (app.currMsgLen == 0) { + app.currMsgLen = stream.readUint16(); + app.currMsgCount = stream.readUint16(); + } - if (msgname.length > 0) { - messages[msgname] = new Message(msgid, msgname, msglen, argtype, argstypes, handler); + if (stream.length() + 2 < app.currMsgLen && app.fragmentStream == null) { + app.writeFragmentMessage(FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY, stream, app.currMsgLen - 2); + } + else if (app.fragmentStream != null) { + app.mergeFragmentMessage(stream); - if (isClientMethod) - clientmessages[msgid] = messages[msgname]; - else - messages[app.currserver][msgid] = messages[msgname]; + if (app.fragmentStream.length() + 2 >= app.currMsgLen) { + app.importClientMessages(app.fragmentStream); } - else { - messages[app.currserver][msgid] = new Message(msgid, msgname, msglen, argtype, argstypes, handler); - } - }; - - app.onImportClientMessagesCompleted(); + } + else { + app.importClientMessages(stream); + } + } + else { + ERROR_MSG("KBEngineApp::onmessage: not found msg(" + app.currMsgID + ")!"); } - else - ERROR_MSG("KBEngineApp::onmessage: not found msg(" + msgid + ")!"); } createAccount(username, password, datas) { app.reset(); @@ -2708,11 +3153,12 @@ namespace KBEngine { createAccount_loginapp(noconnect) { if (noconnect) { INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + app.args.ip + ":" + app.args.port + "!"); + app.currconnect = "loginapp"; app.connect(app.args.ip, app.args.port); app.socket.onopen = app.onOpenLoginapp_createAccount; } else { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Loginapp_reqCreateAccount']); bundle.writeString(app.username); bundle.writeString(app.password); @@ -2721,7 +3167,7 @@ namespace KBEngine { } } bindAccountEmail(emailAddress) { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Baseapp_reqAccountBindEmail']); bundle.writeInt32(app.entity_id); bundle.writeString(app.password); @@ -2729,13 +3175,20 @@ namespace KBEngine { bundle.send(app); } newPassword(old_password, new_password) { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Baseapp_reqAccountNewPassword']); bundle.writeInt32(app.entity_id); bundle.writeString(old_password); bundle.writeString(new_password); bundle.send(app); } + logout() { + let bundle = new Bundle(); + bundle.newMessage(messages['Baseapp_logoutBaseapp']); + bundle.writeUint64(app.entity_uuid); + bundle.writeInt32(app.entity_id); + bundle.send(app); + } login(username, password, datas) { app.reset(); app.username = username; @@ -2747,11 +3200,12 @@ namespace KBEngine { login_loginapp(noconnect) { if (noconnect) { INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://" + app.args.ip + ":" + app.args.port + "!"); + app.currconnect = "loginapp"; app.connect(app.args.ip, app.args.port); app.socket.onopen = app.onOpenLoginapp_login; } else { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Loginapp_login']); bundle.writeInt8(app.args.clientType); // clientType bundle.writeBlob(app.clientdatas); @@ -2766,7 +3220,7 @@ namespace KBEngine { app.currstate = "resetpassword"; if (!app.loginappMessageImported) { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages.Loginapp_importClientMessages); bundle.send(app); app.socket.onmessage = app.Client_onImportClientMessages; @@ -2784,11 +3238,12 @@ namespace KBEngine { resetpassword_loginapp(noconnect) { if (noconnect) { INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://" + app.args.ip + ":" + app.args.port + "!"); + app.currconnect = "loginapp"; app.connect(app.args.ip, app.args.port); app.socket.onopen = app.onOpenLoginapp_resetpassword; } else { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Loginapp_reqAccountResetPassword']); bundle.writeString(app.username); bundle.send(app); @@ -2799,7 +3254,7 @@ namespace KBEngine { app.currserver = "baseapp"; if (!app.baseappMessageImported) { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages.Baseapp_importClientMessages); bundle.send(app); app.socket.onmessage = app.Client_onImportClientMessages; @@ -2809,17 +3264,19 @@ namespace KBEngine { app.onImportClientMessagesCompleted(); } } + login_baseapp(noconnect) { if (noconnect) { Event.fire("onLoginBaseapp"); INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://" + app.baseappIp + ":" + app.baseappPort + "!"); + app.currconnect = "baseapp"; app.connect(app.baseappIp, app.baseappPort); if (app.socket != undefined && app.socket != null) app.socket.onopen = app.onOpenBaseapp; } else { - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Baseapp_loginBaseapp']); bundle.writeString(app.username); bundle.writeString(app.password); @@ -2827,12 +3284,16 @@ namespace KBEngine { } } reloginBaseapp() { + app.lastTickCBTime = app.lastTickTime = Date.now(); + if (app.socket != undefined && app.socket != null) return; app.resetSocket(); - Event.fire("onReloginBaseapp"); + Event.fire(EventTypes.onReloginBaseapp); + INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://" + app.baseappIp + ":" + app.baseappPort + "!"); + app.currconnect = "baseapp"; app.connect(app.baseappIp, app.baseappPort); if (app.socket != undefined && app.socket != null) @@ -2842,7 +3303,7 @@ namespace KBEngine { INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"); app.currserver = "baseapp"; - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Baseapp_reloginBaseapp']); bundle.writeString(app.username); bundle.writeString(app.password); @@ -2890,16 +3351,16 @@ namespace KBEngine { } Client_onLoginBaseappFailed(failedcode) { ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode(" + app.serverErrs[failedcode].name + ")!"); - Event.fire("onLoginBaseappFailed", failedcode); + Event.fire(EventTypes.onLoginBaseappFailed, failedcode); } Client_onReloginBaseappFailed(failedcode) { ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode(" + app.serverErrs[failedcode].name + ")!"); - Event.fire("onReloginBaseappFailed", failedcode); + Event.fire(EventTypes.onReloginBaseappFailed, failedcode); } Client_onReloginBaseappSuccessfully(stream) { app.entity_uuid = stream.readUint64(); DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: " + app.username); - Event.fire("onReloginBaseappSuccessfully"); + Event.fire(EventTypes.onReloginBaseappSuccessfully); } entityclass = {}; getentityclass(entityType) { @@ -3250,7 +3711,7 @@ namespace KBEngine { } Client_onKicked(failedcode) { ERROR_MSG("KBEngineApp::Client_onKicked: failedcode(" + app.serverErrs[failedcode].name + ")!"); - Event.fire("onKicked", failedcode); + Event.fire(EventTypes.onKicked, failedcode); } Client_onCreateAccountResult(stream) { let retcode = stream.readUint16(); @@ -3295,7 +3756,7 @@ namespace KBEngine { try { entity.onControlled(isCont); - Event.fire("onControlled", entity, isCont); + Event.fire(EventTypes.onControlled, entity, isCont); } catch (e) { ERROR_MSG("KBEngine::Client_onControlEntity: entity id = '" + eid + "', is controlled = '" + isCont + "', error = '" + e + "'"); @@ -3315,7 +3776,7 @@ namespace KBEngine { player.entityLastLocalDir.y = player.direction.y; player.entityLastLocalDir.z = player.direction.z; - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Baseapp_onUpdateDataFromClient']); bundle.writeFloat(player.position.x); bundle.writeFloat(player.position.y); @@ -3341,7 +3802,7 @@ namespace KBEngine { entity.entityLastLocalPos = position; entity.entityLastLocalDir = direction; - let bundle = new Bundle(); + let bundle = Bundle.createObject(); bundle.newMessage(messages['Baseapp_onUpdateDataFromClientForControlledEntity']); bundle.writeInt32(entity.id); bundle.writeFloat(position.x); @@ -3362,7 +3823,7 @@ namespace KBEngine { app.spaceID = spaceID; app.spaceResPath = respath; - Event.fire("addSpaceGeometryMapping", respath); + Event.fire(EventTypes.addSpaceGeometryMapping, respath); } clearSpace(isAll) { app.entityIDAliasIDList = []; @@ -3480,76 +3941,308 @@ namespace KBEngine { Client_onUpdateData_ypr(stream) { let eid = app.getViewEntityIDFromStream(stream); - let y = stream.readInt8(); - let p = stream.readInt8(); - let r = stream.readInt8(); + let y = stream.readFloat(); + let p = stream.readFloat(); + let r = stream.readFloat(); app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, p, r, -1); } Client_onUpdateData_yp(stream) { let eid = app.getViewEntityIDFromStream(stream); - let y = stream.readInt8(); - let p = stream.readInt8(); + let y = stream.readFloat(); + let p = stream.readFloat(); app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, p, KBE_FLT_MAX, -1); } Client_onUpdateData_yr(stream) { let eid = app.getViewEntityIDFromStream(stream); - let y = stream.readInt8(); - let r = stream.readInt8(); + let y = stream.readFloat(); + let r = stream.readFloat(); app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, KBE_FLT_MAX, r, -1); } Client_onUpdateData_pr(stream) { let eid = app.getViewEntityIDFromStream(stream); - let p = stream.readInt8(); - let r = stream.readInt8(); + let p = stream.readFloat(); + let r = stream.readFloat(); app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, p, r, -1); } Client_onUpdateData_y(stream) { let eid = app.getViewEntityIDFromStream(stream); - let y = stream.readInt8(); + let y = stream.readFloat(); app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, KBE_FLT_MAX, KBE_FLT_MAX, -1); } Client_onUpdateData_p(stream) { let eid = app.getViewEntityIDFromStream(stream); - let p = stream.readInt8(); + let p = stream.readFloat(); app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, p, KBE_FLT_MAX, -1); } Client_onUpdateData_r(stream) { let eid = app.getViewEntityIDFromStream(stream); - let r = stream.readInt8(); + let r = stream.readFloat(); app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, r, -1); } Client_onUpdateData_xz(stream) { let eid = app.getViewEntityIDFromStream(stream); - let xz = stream.readPackXZ(); + // let x = stream.readFloat(); let z = stream.readFloat(); + let x = stream.readFloat(); + let z = stream.readFloat(); - app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, 1); + app._updateVolatileData(eid, x, KBE_FLT_MAX, z, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, 1); } Client_onUpdateData_xz_ypr(stream) { let eid = app.getViewEntityIDFromStream(stream); + let x = stream.readFloat(); + let z = stream.readFloat(); + + let y = stream.readFloat(); + let p = stream.readFloat(); + let r = stream.readFloat(); + + app._updateVolatileData(eid, x, KBE_FLT_MAX, z, y, p, r, 1); + } + Client_onUpdateData_xz_yp(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); + let z = stream.readFloat(); + + let y = stream.readFloat(); + let p = stream.readFloat(); + + app._updateVolatileData(eid, x, KBE_FLT_MAX, z, y, p, KBE_FLT_MAX, 1); + } + Client_onUpdateData_xz_yr(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); + let z = stream.readFloat(); + + let y = stream.readFloat(); + let r = stream.readFloat(); + + app._updateVolatileData(eid, x, KBE_FLT_MAX, z, y, KBE_FLT_MAX, r, 1); + } + Client_onUpdateData_xz_pr(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); + let z = stream.readFloat(); + + let p = stream.readFloat(); + let r = stream.readFloat(); + + app._updateVolatileData(eid, x, KBE_FLT_MAX, z, KBE_FLT_MAX, p, r, 1); + } + Client_onUpdateData_xz_y(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); + let z = stream.readFloat(); + let y = stream.readFloat(); + + app._updateVolatileData(eid, x, KBE_FLT_MAX, z, y, KBE_FLT_MAX, KBE_FLT_MAX, 1); + } + Client_onUpdateData_xz_p(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); + let z = stream.readFloat(); + let p = stream.readInt8(); + + app._updateVolatileData(eid, x, KBE_FLT_MAX, z, KBE_FLT_MAX, p, KBE_FLT_MAX, 1); + } + Client_onUpdateData_xz_r(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); + let z = stream.readFloat(); + + let r = stream.readInt8(); + + app._updateVolatileData(eid, x, KBE_FLT_MAX, z, KBE_FLT_MAX, KBE_FLT_MAX, r, 1); + } + Client_onUpdateData_xyz(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); + let y = stream.readFloat(); + let z = stream.readFloat(); + + app._updateVolatileData(eid, x, y, z, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, 0); + } + Client_onUpdateData_xyz_ypr(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); + let y = stream.readFloat(); + let z = stream.readFloat(); + + let yaw = stream.readFloat(); + let p = stream.readFloat(); + let r = stream.readFloat(); + + app._updateVolatileData(eid, x, y, z, yaw, p, r, 0); + } + Client_onUpdateData_xyz_yp(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); let z = stream.readFloat(); + let y = stream.readFloat(); + + let yaw = stream.readFloat(); + let p = stream.readFloat(); + + app._updateVolatileData(eid, x, y, z, yaw, p, KBE_FLT_MAX, 0); + } + Client_onUpdateData_xyz_yr(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); let z = stream.readFloat(); + let y = stream.readFloat(); + + let yaw = stream.readFloat(); + let r = stream.readFloat(); + + app._updateVolatileData(eid, x, y, z, yaw, KBE_FLT_MAX, r, 0); + } + Client_onUpdateData_xyz_pr(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); let z = stream.readFloat(); + let y = stream.readFloat(); + + let p = stream.readFloat(); + let r = stream.readFloat(); + + app._updateVolatileData(eid, x, y, z, KBE_FLT_MAX, p, r, 0); + } + Client_onUpdateData_xyz_y(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); let z = stream.readFloat(); + let y = stream.readFloat(); + + let yaw = stream.readFloat(); + + app._updateVolatileData(eid, x, y, z, yaw, KBE_FLT_MAX, KBE_FLT_MAX, 0); + } + Client_onUpdateData_xyz_p(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); let z = stream.readFloat(); + let y = stream.readFloat(); + + let p = stream.readFloat(); + + app._updateVolatileData(eid, x, y, z, KBE_FLT_MAX, p, KBE_FLT_MAX, 0); + } + Client_onUpdateData_xyz_r(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let x = stream.readFloat(); let z = stream.readFloat(); + let y = stream.readFloat(); + //todo 这个是自己加的,如果错误再修改 + let r = stream.readFloat(); + + // let p = stream.readFloat(); + + app._updateVolatileData(eid, x, y, z, r, KBE_FLT_MAX, KBE_FLT_MAX, 0); + } + Client_onUpdateData_ypr_optimized(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let y = stream.readInt8(); + let p = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, p, r, -1, true); + } + + Client_onUpdateData_yp_optimized(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let y = stream.readInt8(); + let p = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, p, KBE_FLT_MAX, -1, true); + } + + Client_onUpdateData_yr_optimized(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let y = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, KBE_FLT_MAX, r, -1, true); + } + + Client_onUpdateData_pr_optimized(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let p = stream.readInt8(); + let r = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, p, r, -1, true); + } + + Client_onUpdateData_y_optimized(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let y = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, y, KBE_FLT_MAX, KBE_FLT_MAX, -1, true); + } + + Client_onUpdateData_p_optimized(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let p = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, p, KBE_FLT_MAX, -1, true); + } + + Client_onUpdateData_r_optimized(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let r = stream.readInt8(); + + app._updateVolatileData(eid, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, r, -1, true); + } + + Client_onUpdateData_xz_optimized(stream) { + let eid = app.getViewEntityIDFromStream(stream); + + let xz = stream.readPackXZ(); + + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, 1, true); + } + + Client_onUpdateData_xz_ypr_optimized(stream) { + let eid = app.getViewEntityIDFromStream(stream); + let xz = stream.readPackXZ(); let y = stream.readInt8(); let p = stream.readInt8(); let r = stream.readInt8(); - app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, p, r, 1); + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, p, r, 1, true); } - Client_onUpdateData_xz_yp(stream) { + + Client_onUpdateData_xz_yp_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3557,9 +4250,10 @@ namespace KBEngine { let y = stream.readInt8(); let p = stream.readInt8(); - app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, p, KBE_FLT_MAX, 1); + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, p, KBE_FLT_MAX, 1, true); } - Client_onUpdateData_xz_yr(stream) { + + Client_onUpdateData_xz_yr_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3567,9 +4261,10 @@ namespace KBEngine { let y = stream.readInt8(); let r = stream.readInt8(); - app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, KBE_FLT_MAX, r, 1); + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, KBE_FLT_MAX, r, 1, true); } - Client_onUpdateData_xz_pr(stream) { + + Client_onUpdateData_xz_pr_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3577,44 +4272,49 @@ namespace KBEngine { let p = stream.readInt8(); let r = stream.readInt8(); - app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, p, r, 1); + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, p, r, 1, true); } - Client_onUpdateData_xz_y(stream) { + + Client_onUpdateData_xz_y_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); let y = stream.readInt8(); - app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, KBE_FLT_MAX, KBE_FLT_MAX, 1); + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], y, KBE_FLT_MAX, KBE_FLT_MAX, 1, true); } - Client_onUpdateData_xz_p(stream) { + + Client_onUpdateData_xz_p_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); let p = stream.readInt8(); - app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, p, KBE_FLT_MAX, 1); + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, p, KBE_FLT_MAX, 1, true); } - Client_onUpdateData_xz_r(stream) { + + Client_onUpdateData_xz_r_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); let r = stream.readInt8(); - app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, r, 1); + app._updateVolatileData(eid, xz[0], KBE_FLT_MAX, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, r, 1, true); } - Client_onUpdateData_xyz(stream) { + + Client_onUpdateData_xyz_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); let y = stream.readPackY(); - app._updateVolatileData(eid, xz[0], y, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, 0); + app._updateVolatileData(eid, xz[0], y, xz[1], KBE_FLT_MAX, KBE_FLT_MAX, KBE_FLT_MAX, 0, true); } - Client_onUpdateData_xyz_ypr(stream) { + + Client_onUpdateData_xyz_ypr_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3624,9 +4324,10 @@ namespace KBEngine { let p = stream.readInt8(); let r = stream.readInt8(); - app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, r, 0); + app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, r, 0, true); } - Client_onUpdateData_xyz_yp(stream) { + + Client_onUpdateData_xyz_yp_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3635,9 +4336,10 @@ namespace KBEngine { let yaw = stream.readInt8(); let p = stream.readInt8(); - app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, KBE_FLT_MAX, 0); + app._updateVolatileData(eid, xz[0], y, xz[1], yaw, p, KBE_FLT_MAX, 0, true); } - Client_onUpdateData_xyz_yr(stream) { + + Client_onUpdateData_xyz_yr_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3646,9 +4348,10 @@ namespace KBEngine { let yaw = stream.readInt8(); let r = stream.readInt8(); - app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBE_FLT_MAX, r, 0); + app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBE_FLT_MAX, r, 0, true); } - Client_onUpdateData_xyz_pr(stream) { + + Client_onUpdateData_xyz_pr_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3657,11 +4360,10 @@ namespace KBEngine { let p = stream.readInt8(); let r = stream.readInt8(); - ERROR_MSG('调用错误方法,无法找到x,z'); - //todo 这个是手动注释,如果错误再修改 - // app._updateVolatileData(eid, x, y, z, KBE_FLT_MAX, p, r, 0); + app._updateVolatileData(eid, xz[0], y, xz[1], KBE_FLT_MAX, p, r, 0, true); } - Client_onUpdateData_xyz_y(stream) { + + Client_onUpdateData_xyz_y_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3669,9 +4371,10 @@ namespace KBEngine { let yaw = stream.readInt8(); - app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBE_FLT_MAX, KBE_FLT_MAX, 0); + app._updateVolatileData(eid, xz[0], y, xz[1], yaw, KBE_FLT_MAX, KBE_FLT_MAX, 0, true); } - Client_onUpdateData_xyz_p(stream) { + + Client_onUpdateData_xyz_p_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); @@ -3679,21 +4382,20 @@ namespace KBEngine { let p = stream.readInt8(); - app._updateVolatileData(eid, xz[0], y, xz[1], KBE_FLT_MAX, p, KBE_FLT_MAX, 0); + app._updateVolatileData(eid, xz[0], y, xz[1], KBE_FLT_MAX, p, KBE_FLT_MAX, 0, true); } - Client_onUpdateData_xyz_r(stream) { + + Client_onUpdateData_xyz_r_optimized(stream) { let eid = app.getViewEntityIDFromStream(stream); let xz = stream.readPackXZ(); let y = stream.readPackY(); - //todo 这个是自己加的,如果错误再修改 - let r = stream.readInt8(); - let p = stream.readInt8(); + let r = stream.readInt8(); - app._updateVolatileData(eid, xz[0], y, xz[1], r, KBE_FLT_MAX, KBE_FLT_MAX, 0); + app._updateVolatileData(eid, xz[0], y, xz[1], r, KBE_FLT_MAX, KBE_FLT_MAX, 0, true); } - _updateVolatileData(entityID, x, y, z, yaw, pitch, roll, isOnGround) { + _updateVolatileData(entityID, x, y, z, yaw, pitch, roll, isOnGround, isOptimized: boolean = false) { let entity = app.entities[entityID]; if (entity == undefined) { // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 @@ -3740,10 +4442,16 @@ namespace KBEngine { if (z == KBE_FLT_MAX) z = 0.0; if (positionChanged) { - entity.position.x = x + app.entityServerPos.x; - entity.position.y = y + app.entityServerPos.y; - entity.position.z = z + app.entityServerPos.z; - + if (isOptimized) { + entity.position.x = x + KBEngine.app.entityServerPos.x; + entity.position.y = y + KBEngine.app.entityServerPos.y; + entity.position.z = z + KBEngine.app.entityServerPos.z; + } + else { + entity.position.x = x; + entity.position.y = y; + entity.position.z = z; + } done = true; Event.fire("updatePosition", entity); } @@ -3752,15 +4460,15 @@ namespace KBEngine { entity.onUpdateVolatileData(); } Client_onStreamDataStarted(id, datasize, descr) { - Event.fire("onStreamDataStarted", id, datasize, descr); + Event.fire(EventTypes.onStreamDataStarted, id, datasize, descr); } Client_onStreamDataRecv(stream) { let id = stream.readUint16(); let data = stream.readBlob(); - Event.fire("onStreamDataRecv", id, data); + Event.fire(EventTypes.onStreamDataRecv, id, data); } Client_onStreamDataCompleted(id) { - Event.fire("onStreamDataCompleted", id); + Event.fire(EventTypes.onStreamDataCompleted, id); } Client_onReqAccountResetPasswordCB(failedcode) { if (failedcode != 0) { @@ -3793,17 +4501,19 @@ namespace KBEngine { descr = ""; id = 0; } + export const FragmentDataTypes = { + FRAGMENT_DATA_UNKNOW: 0, + FRAGMENT_DATA_MESSAGE_ID: 1, + FRAGMENT_DATA_MESSAGE_LENGTH: 2, + FRAGMENT_DATA_MESSAGE_LENGTH1: 3, + FRAGMENT_DATA_MESSAGE_BODY: 4 + }; export let app: KBEngineApp; let idInterval; export function create(args: KBEngineArgs) { if (app != undefined) return; - if (args.constructor != KBEngineArgs) { - ERROR_MSG("create(): args(" + args + ") error! not is KBEngineArgs"); - return; - } - new KBEngineApp(args); app.reset(); @@ -3820,5 +4530,6 @@ namespace KBEngine { app.uninstallEvents(); app.reset(); app = undefined; + Event.clear(); } -} \ No newline at end of file +} diff --git a/kbengine_ts/sync.bat b/kbengine_ts/sync.bat new file mode 100644 index 0000000..e690d41 --- /dev/null +++ b/kbengine_ts/sync.bat @@ -0,0 +1,15 @@ +REM 将这个脚本放于项目之中,项目框架更新后双击执行即可 +REM 首次使用会问是文件或文件夹,一律选文件 +REM 如果不是cocos creator,需要改下路径 + +REM 这里需要设置kbengine_ts路径 +set kbengine=\ + +set libs=%cd%\assets\Libs +if not exist %libs% ( + mkdir %libs% +) + +xcopy /y /c /h /r %frame%\bin\kbengine.d.ts %cd%\kbengine.d.ts + +xcopy /y /c /h /r %frame%\bin\kbengine.js %libs%\kbengine.js diff --git a/kbengine_ts/tsconfig.json b/kbengine_ts/tsconfig.json index 51cd203..c56a267 100644 --- a/kbengine_ts/tsconfig.json +++ b/kbengine_ts/tsconfig.json @@ -4,10 +4,14 @@ "noImplicitAny": false, "sourceMap": false, "declaration": true, + "experimentalDecorators": true, "outFile": "bin/kbengine.js" }, "include": [ "libs", "src" + ], + "exclude": [ + "bin" ] } \ No newline at end of file From 6f2324d9fb0303b00469779f06d08fee6bc9760f Mon Sep 17 00:00:00 2001 From: oblivion <761458545@qq.com> Date: Sat, 11 May 2019 19:35:14 +0800 Subject: [PATCH 13/17] edit --- kbengine_ts/bin/kbengine.d.ts | 36 +++++++++------------ kbengine_ts/bin/kbengine.js | 61 ++++++++++++++++++----------------- kbengine_ts/src/KBEngine.ts | 48 +++++++++++++-------------- kbengine_ts/sync.bat | 15 --------- 4 files changed, 70 insertions(+), 90 deletions(-) delete mode 100644 kbengine_ts/sync.bat diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index d94b0a3..3360092 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -1,25 +1,28 @@ /** * KBEngine的html5客户端扩展ts版 2.x版本 * cocos creator 环境下使用方法 - * 将bin/js导入为插件,将bin/d.ts放在项目根目录下,即可 - * - * todo 未完成内容 - * 1、强类型匹配 - * 2、代码注释 * * 注:(下面的是重点) - * 1、实体声明的命名空间为Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要类声明时加上@registerEntity('你的类名'),用于将变量提升至全局,加入下方一段用于代码提示 - * declare global{ - namespace Entities{ - class 类名 extends 类{} + * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 + * 2、cocos creator环境下,按下面方法声明实体 + + @KBEngine.registerEntity('Account') /// <---这个Account对应服务器上实体 + export default class AccountEntity extends KBEngine.Entity { + __init__() { + console.log('创建account') + } + } + //这里加入声明用于vscode代码提示 + declare global { + namespace KBEngine.Entities { + class Account extends AccountEntity { } /// <---这个Account对应服务器上实体 } } - * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends Entity{}; - * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 + + * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ declare namespace KBEngine { - const CLIENT_VERSION = "2.0.0"; + const CLIENT_VERSION = "2.4.2"; const CLIENT_SCRIPT_VERSION = "0.1.0"; const PACKET_MAX_SIZE = 1500; const PACKET_MAX_SIZE_TCP = 1460; @@ -145,13 +148,6 @@ declare namespace KBEngine { } module MemoryStream { const _objects: MemoryStream[]; - class PackFloatXType { - _unionData: ArrayBuffer; - fv: Float32Array; - uv: Uint32Array; - iv: Int32Array; - constructor(); - } function createObject(): MemoryStream; } } diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index dfe4b76..b57f6d1 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -14,29 +14,32 @@ var __extends = (this && this.__extends) || (function () { /** * KBEngine的html5客户端扩展ts版 2.x版本 * cocos creator 环境下使用方法 - * 将bin/js导入为插件,将bin/d.ts放在项目根目录下,即可 - * - * todo 未完成内容 - * 1、强类型匹配 - * 2、代码注释 * * 注:(下面的是重点) - * 1、实体声明的命名空间为Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要类声明时加上@registerEntity('你的类名'),用于将变量提升至全局,加入下方一段用于代码提示 - * declare global{ - namespace Entities{ - class 类名 extends 类{} + * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 + * 2、cocos creator环境下,按下面方法声明实体 + + @KBEngine.registerEntity('Account') /// <---这个Account对应服务器上实体 + export default class AccountEntity extends KBEngine.Entity { + __init__() { + console.log('创建account') + } + } + //这里加入声明用于vscode代码提示 + declare global { + namespace KBEngine.Entities { + class Account extends AccountEntity { } /// <---这个Account对应服务器上实体 } } - * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends Entity{}; - * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 + + * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ /*----------------------------------------------------------------------------------------- global -----------------------------------------------------------------------------------------*/ var KBEngine; (function (KBEngine) { - KBEngine.CLIENT_VERSION = '2.0.0'; + KBEngine.CLIENT_VERSION = '2.4.2'; KBEngine.CLIENT_SCRIPT_VERSION = '0.1.0'; KBEngine.PACKET_MAX_SIZE = 1500; KBEngine.PACKET_MAX_SIZE_TCP = 1460; @@ -694,17 +697,6 @@ if (!ArrayBuffer['transfer']) { KBEngine.MemoryStream = MemoryStream; (function (MemoryStream) { MemoryStream._objects = []; - var PackFloatXType = /** @class */ (function () { - function PackFloatXType() { - this._unionData = new ArrayBuffer(4); - this.fv = new Float32Array(this._unionData, 0, 1); - this.uv = new Uint32Array(this._unionData, 0, 1); - this.iv = new Int32Array(this._unionData, 0, 1); - } - ; - return PackFloatXType; - }()); - MemoryStream.PackFloatXType = PackFloatXType; function createObject() { return MemoryStream._objects.length > 0 ? MemoryStream._objects.pop() : new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); } @@ -1265,6 +1257,7 @@ if (!ArrayBuffer['transfer']) { return; } this.base.newCall(); + this.base.bundle.writeUint16(0); this.base.bundle.writeUint16(methodID); try { for (var i = 0; i < params.length; i++) { @@ -1309,6 +1302,7 @@ if (!ArrayBuffer['transfer']) { return; } this.cell.newCall(); + this.cell.bundle.writeUint16(0); this.cell.bundle.writeUint16(methodID); try { for (var i = 0; i < args.length; i++) { @@ -3153,12 +3147,17 @@ if (!ArrayBuffer['transfer']) { } var currModule = KBEngine.moduledefs[entity.className]; var pdatas = currModule.propertys; + var componentUID; while (stream.length() > 0) { var utype = 0; - if (currModule.usePropertyDescrAlias) + if (currModule.usePropertyDescrAlias) { + componentUID = stream.readInt8(); utype = stream.readUint8(); - else + } + else { + componentUID = stream.readUint16(); utype = stream.readUint16(); + } var propertydata = pdatas[utype]; var setmethod = propertydata[5]; var flags = propertydata[6]; @@ -3193,11 +3192,15 @@ if (!ArrayBuffer['transfer']) { KBEngine.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); return; } - var methodUtype = 0; - if (KBEngine.moduledefs[entity.className].useMethodDescrAlias) + var methodUtype = 0, ComponentID = 0; + if (KBEngine.moduledefs[entity.className].useMethodDescrAlias) { + ComponentID = stream.readInt8(); methodUtype = stream.readUint8(); - else + } + else { + ComponentID = stream.readUint16(); methodUtype = stream.readUint16(); + } var methoddata = KBEngine.moduledefs[entity.className].methods[methodUtype]; var args = []; var argsdata = methoddata[3]; diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index f4485b2..5fe2c06 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -5,7 +5,8 @@ * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 * 2、cocos creator环境下,按下面方法声明实体 - * @KBEngine.registerEntity('Account') + + @KBEngine.registerEntity('Account') /// <---这个Account对应服务器上实体 export default class AccountEntity extends KBEngine.Entity { __init__() { console.log('创建account') @@ -14,7 +15,7 @@ //这里加入声明用于vscode代码提示 declare global { namespace KBEngine.Entities { - class Account extends AccountEntity { } + class Account extends AccountEntity { } /// <---这个Account对应服务器上实体 } } * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 @@ -24,7 +25,7 @@ global -----------------------------------------------------------------------------------------*/ namespace KBEngine { - export const CLIENT_VERSION = '2.0.0'; + export const CLIENT_VERSION = '2.5.0'; export const CLIENT_SCRIPT_VERSION = '0.1.0'; export const PACKET_MAX_SIZE = 1500; @@ -44,7 +45,6 @@ namespace KBEngine { */ window['KBEngine'] = KBEngine; - if (!ArrayBuffer['transfer']) { ArrayBuffer['transfer'] = function (source: ArrayBuffer, length: number): ArrayBuffer { let dest = new ArrayBuffer(length); @@ -725,18 +725,6 @@ namespace KBEngine { } export module MemoryStream { export const _objects: MemoryStream[] = [] - export class PackFloatXType { - _unionData: ArrayBuffer; - fv: Float32Array; - uv: Uint32Array; - iv: Int32Array; - constructor() { - this._unionData = new ArrayBuffer(4); - this.fv = new Float32Array(this._unionData, 0, 1); - this.uv = new Uint32Array(this._unionData, 0, 1); - this.iv = new Int32Array(this._unionData, 0, 1); - }; - } export function createObject() { return MemoryStream._objects.length > 0 ? MemoryStream._objects.pop() : new MemoryStream(PACKET_MAX_SIZE_TCP); } @@ -1353,6 +1341,7 @@ namespace KBEngine { } this.base.newCall(); + this.base.bundle.writeUint16(0); this.base.bundle.writeUint16(methodID); try { @@ -1400,7 +1389,8 @@ namespace KBEngine { return; } - this.cell.newCall(); + this.cell.newCall() + this.cell.bundle.writeUint16(0); this.cell.bundle.writeUint16(methodID); try { @@ -1462,7 +1452,7 @@ namespace KBEngine { } set_position() { - // DEBUG_MSG(this.className + "::set_position: " + old); + DEBUG_MSG(this.className + "::set_position: " + this.position); if (this.isPlayer()) { app.entityServerPos.x = this.position.x; app.entityServerPos.y = this.position.y; @@ -1475,7 +1465,7 @@ namespace KBEngine { } set_direction(old) { - // DEBUG_MSG(this.className + "::set_direction: " + old); + DEBUG_MSG(this.className + "::set_direction: " + this.direction); Event.fire("set_direction", this); } } @@ -3454,13 +3444,16 @@ namespace KBEngine { let currModule = moduledefs[entity.className]; let pdatas = currModule.propertys; + let componentUID; while (stream.length() > 0) { let utype = 0; - if (currModule.usePropertyDescrAlias) + if (currModule.usePropertyDescrAlias) { + componentUID = stream.readInt8(); utype = stream.readUint8(); - else + } else { + componentUID = stream.readUint16() utype = stream.readUint16(); - + } let propertydata = pdatas[utype]; let setmethod = propertydata[5]; let flags = propertydata[6]; @@ -3499,12 +3492,15 @@ namespace KBEngine { return; } - let methodUtype = 0; - if (moduledefs[entity.className].useMethodDescrAlias) + let methodUtype = 0, ComponentID = 0; + if (moduledefs[entity.className].useMethodDescrAlias) { + ComponentID = stream.readInt8() methodUtype = stream.readUint8(); - else + } + else { + ComponentID = stream.readUint16(); methodUtype = stream.readUint16(); - + } let methoddata = moduledefs[entity.className].methods[methodUtype]; let args = []; let argsdata = methoddata[3]; diff --git a/kbengine_ts/sync.bat b/kbengine_ts/sync.bat deleted file mode 100644 index e690d41..0000000 --- a/kbengine_ts/sync.bat +++ /dev/null @@ -1,15 +0,0 @@ -REM 将这个脚本放于项目之中,项目框架更新后双击执行即可 -REM 首次使用会问是文件或文件夹,一律选文件 -REM 如果不是cocos creator,需要改下路径 - -REM 这里需要设置kbengine_ts路径 -set kbengine=\ - -set libs=%cd%\assets\Libs -if not exist %libs% ( - mkdir %libs% -) - -xcopy /y /c /h /r %frame%\bin\kbengine.d.ts %cd%\kbengine.d.ts - -xcopy /y /c /h /r %frame%\bin\kbengine.js %libs%\kbengine.js From 1df2f0f6a1b2f627fe6141f8addd4c43f5990d6f Mon Sep 17 00:00:00 2001 From: zengmingnan Date: Mon, 13 May 2019 10:54:17 +0800 Subject: [PATCH 14/17] edit --- kbengine_ts/bin/kbengine.d.ts | 36 +++++++-------- kbengine_ts/bin/kbengine.js | 61 ++++++++++++++------------ kbengine_ts/{sync.bat => kbengine.bat} | 6 +-- kbengine_ts/src/KBEngine.ts | 49 ++++++++++----------- 4 files changed, 74 insertions(+), 78 deletions(-) rename kbengine_ts/{sync.bat => kbengine.bat} (61%) diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index d94b0a3..3360092 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -1,25 +1,28 @@ /** * KBEngine的html5客户端扩展ts版 2.x版本 * cocos creator 环境下使用方法 - * 将bin/js导入为插件,将bin/d.ts放在项目根目录下,即可 - * - * todo 未完成内容 - * 1、强类型匹配 - * 2、代码注释 * * 注:(下面的是重点) - * 1、实体声明的命名空间为Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要类声明时加上@registerEntity('你的类名'),用于将变量提升至全局,加入下方一段用于代码提示 - * declare global{ - namespace Entities{ - class 类名 extends 类{} + * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 + * 2、cocos creator环境下,按下面方法声明实体 + + @KBEngine.registerEntity('Account') /// <---这个Account对应服务器上实体 + export default class AccountEntity extends KBEngine.Entity { + __init__() { + console.log('创建account') + } + } + //这里加入声明用于vscode代码提示 + declare global { + namespace KBEngine.Entities { + class Account extends AccountEntity { } /// <---这个Account对应服务器上实体 } } - * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends Entity{}; - * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 + + * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ declare namespace KBEngine { - const CLIENT_VERSION = "2.0.0"; + const CLIENT_VERSION = "2.4.2"; const CLIENT_SCRIPT_VERSION = "0.1.0"; const PACKET_MAX_SIZE = 1500; const PACKET_MAX_SIZE_TCP = 1460; @@ -145,13 +148,6 @@ declare namespace KBEngine { } module MemoryStream { const _objects: MemoryStream[]; - class PackFloatXType { - _unionData: ArrayBuffer; - fv: Float32Array; - uv: Uint32Array; - iv: Int32Array; - constructor(); - } function createObject(): MemoryStream; } } diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index dfe4b76..b57f6d1 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -14,29 +14,32 @@ var __extends = (this && this.__extends) || (function () { /** * KBEngine的html5客户端扩展ts版 2.x版本 * cocos creator 环境下使用方法 - * 将bin/js导入为插件,将bin/d.ts放在项目根目录下,即可 - * - * todo 未完成内容 - * 1、强类型匹配 - * 2、代码注释 * * 注:(下面的是重点) - * 1、实体声明的命名空间为Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,实体类声明完成后,需要类声明时加上@registerEntity('你的类名'),用于将变量提升至全局,加入下方一段用于代码提示 - * declare global{ - namespace Entities{ - class 类名 extends 类{} + * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 + * 2、cocos creator环境下,按下面方法声明实体 + + @KBEngine.registerEntity('Account') /// <---这个Account对应服务器上实体 + export default class AccountEntity extends KBEngine.Entity { + __init__() { + console.log('创建account') + } + } + //这里加入声明用于vscode代码提示 + declare global { + namespace KBEngine.Entities { + class Account extends AccountEntity { } /// <---这个Account对应服务器上实体 } } - * 3、因为是ts,所以没有class.extends方法,需要声明时直接,class Account extends Entity{}; - * 4、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 + + * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ /*----------------------------------------------------------------------------------------- global -----------------------------------------------------------------------------------------*/ var KBEngine; (function (KBEngine) { - KBEngine.CLIENT_VERSION = '2.0.0'; + KBEngine.CLIENT_VERSION = '2.4.2'; KBEngine.CLIENT_SCRIPT_VERSION = '0.1.0'; KBEngine.PACKET_MAX_SIZE = 1500; KBEngine.PACKET_MAX_SIZE_TCP = 1460; @@ -694,17 +697,6 @@ if (!ArrayBuffer['transfer']) { KBEngine.MemoryStream = MemoryStream; (function (MemoryStream) { MemoryStream._objects = []; - var PackFloatXType = /** @class */ (function () { - function PackFloatXType() { - this._unionData = new ArrayBuffer(4); - this.fv = new Float32Array(this._unionData, 0, 1); - this.uv = new Uint32Array(this._unionData, 0, 1); - this.iv = new Int32Array(this._unionData, 0, 1); - } - ; - return PackFloatXType; - }()); - MemoryStream.PackFloatXType = PackFloatXType; function createObject() { return MemoryStream._objects.length > 0 ? MemoryStream._objects.pop() : new MemoryStream(KBEngine.PACKET_MAX_SIZE_TCP); } @@ -1265,6 +1257,7 @@ if (!ArrayBuffer['transfer']) { return; } this.base.newCall(); + this.base.bundle.writeUint16(0); this.base.bundle.writeUint16(methodID); try { for (var i = 0; i < params.length; i++) { @@ -1309,6 +1302,7 @@ if (!ArrayBuffer['transfer']) { return; } this.cell.newCall(); + this.cell.bundle.writeUint16(0); this.cell.bundle.writeUint16(methodID); try { for (var i = 0; i < args.length; i++) { @@ -3153,12 +3147,17 @@ if (!ArrayBuffer['transfer']) { } var currModule = KBEngine.moduledefs[entity.className]; var pdatas = currModule.propertys; + var componentUID; while (stream.length() > 0) { var utype = 0; - if (currModule.usePropertyDescrAlias) + if (currModule.usePropertyDescrAlias) { + componentUID = stream.readInt8(); utype = stream.readUint8(); - else + } + else { + componentUID = stream.readUint16(); utype = stream.readUint16(); + } var propertydata = pdatas[utype]; var setmethod = propertydata[5]; var flags = propertydata[6]; @@ -3193,11 +3192,15 @@ if (!ArrayBuffer['transfer']) { KBEngine.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); return; } - var methodUtype = 0; - if (KBEngine.moduledefs[entity.className].useMethodDescrAlias) + var methodUtype = 0, ComponentID = 0; + if (KBEngine.moduledefs[entity.className].useMethodDescrAlias) { + ComponentID = stream.readInt8(); methodUtype = stream.readUint8(); - else + } + else { + ComponentID = stream.readUint16(); methodUtype = stream.readUint16(); + } var methoddata = KBEngine.moduledefs[entity.className].methods[methodUtype]; var args = []; var argsdata = methoddata[3]; diff --git a/kbengine_ts/sync.bat b/kbengine_ts/kbengine.bat similarity index 61% rename from kbengine_ts/sync.bat rename to kbengine_ts/kbengine.bat index e690d41..b0e3be7 100644 --- a/kbengine_ts/sync.bat +++ b/kbengine_ts/kbengine.bat @@ -3,13 +3,13 @@ REM 首次使用会问是文件或文件夹,一律选文件 REM 如果不是cocos creator,需要改下路径 REM 这里需要设置kbengine_ts路径 -set kbengine=\ +set kbengine=%cd%\..\..\kbengine_js_plugins\kbengine_ts set libs=%cd%\assets\Libs if not exist %libs% ( mkdir %libs% ) -xcopy /y /c /h /r %frame%\bin\kbengine.d.ts %cd%\kbengine.d.ts +xcopy /y /c /h /r %kbengine%\bin\kbengine.d.ts %cd%\kbengine.d.ts -xcopy /y /c /h /r %frame%\bin\kbengine.js %libs%\kbengine.js +xcopy /y /c /h /r %kbengine%\bin\kbengine.js %libs%\kbengine.js diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index f4485b2..3eeee6f 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -5,7 +5,8 @@ * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 * 2、cocos creator环境下,按下面方法声明实体 - * @KBEngine.registerEntity('Account') + + @KBEngine.registerEntity('Account') /// <---这个Account对应服务器上实体 export default class AccountEntity extends KBEngine.Entity { __init__() { console.log('创建account') @@ -14,9 +15,10 @@ //这里加入声明用于vscode代码提示 declare global { namespace KBEngine.Entities { - class Account extends AccountEntity { } + class Account extends AccountEntity { } /// <---这个Account对应服务器上实体 } } + * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ @@ -24,7 +26,7 @@ global -----------------------------------------------------------------------------------------*/ namespace KBEngine { - export const CLIENT_VERSION = '2.0.0'; + export const CLIENT_VERSION = '2.4.2'; export const CLIENT_SCRIPT_VERSION = '0.1.0'; export const PACKET_MAX_SIZE = 1500; @@ -44,7 +46,6 @@ namespace KBEngine { */ window['KBEngine'] = KBEngine; - if (!ArrayBuffer['transfer']) { ArrayBuffer['transfer'] = function (source: ArrayBuffer, length: number): ArrayBuffer { let dest = new ArrayBuffer(length); @@ -725,18 +726,6 @@ namespace KBEngine { } export module MemoryStream { export const _objects: MemoryStream[] = [] - export class PackFloatXType { - _unionData: ArrayBuffer; - fv: Float32Array; - uv: Uint32Array; - iv: Int32Array; - constructor() { - this._unionData = new ArrayBuffer(4); - this.fv = new Float32Array(this._unionData, 0, 1); - this.uv = new Uint32Array(this._unionData, 0, 1); - this.iv = new Int32Array(this._unionData, 0, 1); - }; - } export function createObject() { return MemoryStream._objects.length > 0 ? MemoryStream._objects.pop() : new MemoryStream(PACKET_MAX_SIZE_TCP); } @@ -1353,6 +1342,7 @@ namespace KBEngine { } this.base.newCall(); + this.base.bundle.writeUint16(0); this.base.bundle.writeUint16(methodID); try { @@ -1400,7 +1390,8 @@ namespace KBEngine { return; } - this.cell.newCall(); + this.cell.newCall() + this.cell.bundle.writeUint16(0); this.cell.bundle.writeUint16(methodID); try { @@ -1462,7 +1453,7 @@ namespace KBEngine { } set_position() { - // DEBUG_MSG(this.className + "::set_position: " + old); + DEBUG_MSG(this.className + "::set_position: " + this.position); if (this.isPlayer()) { app.entityServerPos.x = this.position.x; app.entityServerPos.y = this.position.y; @@ -1475,7 +1466,7 @@ namespace KBEngine { } set_direction(old) { - // DEBUG_MSG(this.className + "::set_direction: " + old); + DEBUG_MSG(this.className + "::set_direction: " + this.direction); Event.fire("set_direction", this); } } @@ -3454,13 +3445,16 @@ namespace KBEngine { let currModule = moduledefs[entity.className]; let pdatas = currModule.propertys; + let componentUID; while (stream.length() > 0) { let utype = 0; - if (currModule.usePropertyDescrAlias) + if (currModule.usePropertyDescrAlias) { + componentUID = stream.readInt8(); utype = stream.readUint8(); - else + } else { + componentUID = stream.readUint16() utype = stream.readUint16(); - + } let propertydata = pdatas[utype]; let setmethod = propertydata[5]; let flags = propertydata[6]; @@ -3499,12 +3493,15 @@ namespace KBEngine { return; } - let methodUtype = 0; - if (moduledefs[entity.className].useMethodDescrAlias) + let methodUtype = 0, ComponentID = 0; + if (moduledefs[entity.className].useMethodDescrAlias) { + ComponentID = stream.readInt8() methodUtype = stream.readUint8(); - else + } + else { + ComponentID = stream.readUint16(); methodUtype = stream.readUint16(); - + } let methoddata = moduledefs[entity.className].methods[methodUtype]; let args = []; let argsdata = methoddata[3]; From ea970b4e3490499f934075f5f5eca99cf9bf6caf Mon Sep 17 00:00:00 2001 From: zengmingnan Date: Wed, 29 May 2019 11:55:48 +0800 Subject: [PATCH 15/17] edit --- kbengine_ts/bin/kbengine.d.ts | 5 +- kbengine_ts/bin/kbengine.js | 177 ++++++++++++++++++-------------- kbengine_ts/bin/kbengine.min.js | 3 + kbengine_ts/package.json | 2 +- kbengine_ts/src/KBEngine.ts | 32 ++---- 5 files changed, 114 insertions(+), 105 deletions(-) create mode 100644 kbengine_ts/bin/kbengine.min.js diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/bin/kbengine.d.ts index 3360092..9a8b0b6 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/bin/kbengine.d.ts @@ -22,7 +22,7 @@ * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 */ declare namespace KBEngine { - const CLIENT_VERSION = "2.4.2"; + const CLIENT_VERSION = "2.5.0"; const CLIENT_SCRIPT_VERSION = "0.1.0"; const PACKET_MAX_SIZE = 1500; const PACKET_MAX_SIZE_TCP = 1460; @@ -254,7 +254,8 @@ declare namespace KBEngine { function angle2int8(v: number, half: boolean): number; } declare namespace KBEngine { - module Entities { } + module Entities { + } class Entity { constructor(); id: number; diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/bin/kbengine.js index b57f6d1..3e36d75 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/bin/kbengine.js @@ -1,16 +1,13 @@ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); +var __reflect = (this && this.__reflect) || function (p, c, t) { + p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t; +}; +var __extends = this && this.__extends || function __extends(t, e) { + function r() { + this.constructor = t; +} +for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]); +r.prototype = e.prototype, t.prototype = new r(); +}; /** * KBEngine的html5客户端扩展ts版 2.x版本 * cocos creator 环境下使用方法 @@ -39,7 +36,7 @@ var __extends = (this && this.__extends) || (function () { -----------------------------------------------------------------------------------------*/ var KBEngine; (function (KBEngine) { - KBEngine.CLIENT_VERSION = '2.4.2'; + KBEngine.CLIENT_VERSION = '2.5.0'; KBEngine.CLIENT_SCRIPT_VERSION = '0.1.0'; KBEngine.PACKET_MAX_SIZE = 1500; KBEngine.PACKET_MAX_SIZE_TCP = 1460; @@ -76,7 +73,7 @@ if (!ArrayBuffer['transfer']) { number64bits -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var INT64 = /** @class */ (function () { + var INT64 = (function () { function INT64(lo, hi) { this.sign = 1; this.lo = lo; @@ -112,7 +109,8 @@ if (!ArrayBuffer['transfer']) { return INT64; }()); KBEngine.INT64 = INT64; - var UINT64 = /** @class */ (function () { + __reflect(INT64.prototype, "KBEngine.INT64"); + var UINT64 = (function () { function UINT64(lo, hi) { this.lo = lo; this.hi = hi; @@ -133,6 +131,7 @@ if (!ArrayBuffer['transfer']) { return UINT64; }()); KBEngine.UINT64 = UINT64; + __reflect(UINT64.prototype, "KBEngine.UINT64"); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- debug @@ -227,7 +226,6 @@ if (!ArrayBuffer['transfer']) { else if (charcode < 0xd800 || charcode >= 0xe000) { utf8.push(0xe0 | (charcode >> 12), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f)); } - // surrogate pair else { i++; // UTF-16 encodes 0x10000-0x10FFFF by @@ -246,7 +244,7 @@ if (!ArrayBuffer['transfer']) { event -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var EventInfo = /** @class */ (function () { + var EventInfo = (function () { function EventInfo(classinst, callbackfn) { this.classinst = classinst; this.callbackfn = callbackfn; @@ -254,7 +252,8 @@ if (!ArrayBuffer['transfer']) { return EventInfo; }()); KBEngine.EventInfo = EventInfo; - var FiredEvent = /** @class */ (function () { + __reflect(EventInfo.prototype, "KBEngine.EventInfo"); + var FiredEvent = (function () { function FiredEvent(evtName, evtInfo, ars) { this.evtName = evtName; this.evtInfo = evtInfo; @@ -263,7 +262,8 @@ if (!ArrayBuffer['transfer']) { return FiredEvent; }()); KBEngine.FiredEvent = FiredEvent; - var Events = /** @class */ (function () { + __reflect(FiredEvent.prototype, "KBEngine.FiredEvent"); + var Events = (function () { function Events() { this._events = {}; this._isPause = false; @@ -292,18 +292,11 @@ if (!ArrayBuffer['transfer']) { var evtlst = this._events[evtName]; if (!evtlst) return; - while (true) { - var found = false; - for (var i = 0; i < evtlst.length; i++) { - var info = evtlst[i]; - if (info.classinst == classinst) { - evtlst.splice(i, 1); - found = true; - break; - } + for (var i = evtlst.length - 1; i >= 0; i--) { + var info = evtlst[i]; + if (info.classinst == classinst) { + evtlst.splice(i, 1); } - if (!found) - break; } }; Events.prototype.removeAllFiredEvent = function (classinst) { @@ -311,18 +304,11 @@ if (!ArrayBuffer['transfer']) { }; Events.prototype.removeFiredEvent = function (evtName, classinst) { var firedEvents = this._firedEvents; - while (true) { - var found = false; - for (var i = 0; i < firedEvents.length; i++) { - var evt = firedEvents[i]; - if ((evtName == "" || evt.evtName == evtName) && evt.evtInfo.classinst == classinst) { - firedEvents.splice(i, 1); - found = true; - break; - } + for (var i = firedEvents.length - 1; i >= 0; i--) { + var evt = firedEvents[i]; + if ((evtName == "" || evt.evtName == evtName) && evt.evtInfo.classinst == classinst) { + firedEvents.splice(i, 1); } - if (!found) - break; } }; Events.prototype.fire = function (evtName) { @@ -383,13 +369,14 @@ if (!ArrayBuffer['transfer']) { return Events; }()); KBEngine.Events = Events; + __reflect(Events.prototype, "KBEngine.Events"); KBEngine.Event = new Events(); })(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- memorystream -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var PackFloatXType = /** @class */ (function () { + var PackFloatXType = (function () { function PackFloatXType() { this._unionData = new ArrayBuffer(4); this.fv = new Float32Array(this._unionData, 0, 1); @@ -399,10 +386,11 @@ if (!ArrayBuffer['transfer']) { return PackFloatXType; }()); KBEngine.PackFloatXType = PackFloatXType; + __reflect(PackFloatXType.prototype, "KBEngine.PackFloatXType"); KBEngine._xPackData = new PackFloatXType(); KBEngine._yPackData = new PackFloatXType(); KBEngine._zPackData = new PackFloatXType(); - var MemoryStream = /** @class */ (function () { + var MemoryStream = (function () { function MemoryStream(size_or_buffer) { this.rpos = 0; this.wpos = 0; @@ -695,6 +683,7 @@ if (!ArrayBuffer['transfer']) { return MemoryStream; }()); KBEngine.MemoryStream = MemoryStream; + __reflect(MemoryStream.prototype, "KBEngine.MemoryStream"); (function (MemoryStream) { MemoryStream._objects = []; function createObject() { @@ -707,7 +696,7 @@ if (!ArrayBuffer['transfer']) { bundle -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var Bundle = /** @class */ (function () { + var Bundle = (function () { function Bundle() { this.memorystreams = new Array(); this.numMessage = 0; @@ -846,6 +835,7 @@ if (!ArrayBuffer['transfer']) { return Bundle; }()); KBEngine.Bundle = Bundle; + __reflect(Bundle.prototype, "KBEngine.Bundle"); KBEngine.reader = new KBEngine.MemoryStream(0); KBEngine.datatype2id = {}; function mappingDataType() { @@ -942,7 +932,7 @@ if (!ArrayBuffer['transfer']) { } } KBEngine.bindReader = bindReader; - var Message = /** @class */ (function () { + var Message = (function () { function Message(id, name, length, argsType, args, handler) { this.id = id; this.name = name; @@ -981,6 +971,7 @@ if (!ArrayBuffer['transfer']) { return Message; }()); KBEngine.Message = Message; + __reflect(Message.prototype, "KBEngine.Message"); var messages; (function (messages) { messages.loginapp = {}; @@ -997,7 +988,7 @@ if (!ArrayBuffer['transfer']) { math -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var Vector2 = /** @class */ (function () { + var Vector2 = (function () { function Vector2(x, y) { this.x = x; this.y = y; @@ -1035,7 +1026,8 @@ if (!ArrayBuffer['transfer']) { return Vector2; }()); KBEngine.Vector2 = Vector2; - var Vector3 = /** @class */ (function () { + __reflect(Vector2.prototype, "KBEngine.Vector2"); + var Vector3 = (function () { function Vector3(x, y, z) { this.x = x; this.y = y; @@ -1088,7 +1080,8 @@ if (!ArrayBuffer['transfer']) { return Vector3; }()); KBEngine.Vector3 = Vector3; - var Vector4 = /** @class */ (function () { + __reflect(Vector3.prototype, "KBEngine.Vector3"); + var Vector4 = (function () { function Vector4(x, y, z, w) { this.x = x; this.y = y; @@ -1144,6 +1137,7 @@ if (!ArrayBuffer['transfer']) { return Vector4; }()); KBEngine.Vector4 = Vector4; + __reflect(Vector4.prototype, "KBEngine.Vector4"); function clampf(value, min_inclusive, max_inclusive) { if (min_inclusive > max_inclusive) { var temp = min_inclusive; @@ -1174,7 +1168,7 @@ if (!ArrayBuffer['transfer']) { entity -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var Entity = /** @class */ (function () { + var Entity = (function () { function Entity() { this.id = 0; this.className = ""; @@ -1356,7 +1350,7 @@ if (!ArrayBuffer['transfer']) { Entity.prototype.onLeaveSpace = function () { }; Entity.prototype.set_position = function () { - // DEBUG_MSG(this.className + "::set_position: " + old); + KBEngine.DEBUG_MSG(this.className + "::set_position: " + this.position); if (this.isPlayer()) { KBEngine.app.entityServerPos.x = this.position.x; KBEngine.app.entityServerPos.y = this.position.y; @@ -1367,12 +1361,13 @@ if (!ArrayBuffer['transfer']) { Entity.prototype.onUpdateVolatileData = function () { }; Entity.prototype.set_direction = function (old) { - // DEBUG_MSG(this.className + "::set_direction: " + old); + KBEngine.DEBUG_MSG(this.className + "::set_direction: " + this.direction); KBEngine.Event.fire("set_direction", this); }; return Entity; }()); KBEngine.Entity = Entity; + __reflect(Entity.prototype, "KBEngine.Entity"); function registerEntity(name) { return function (ctor) { KBEngine['Entities'] = KBEngine['Entities'] || {}; @@ -1388,13 +1383,14 @@ if (!ArrayBuffer['transfer']) { KBEngine.ENTITYCALL_TYPE_CELL = 0; KBEngine.ENTITYCALL_TYPE_BASE = 1; //这个东西好像没有同步给客户端 - var EntityComponent = /** @class */ (function () { + var EntityComponent = (function () { function EntityComponent() { } return EntityComponent; }()); KBEngine.EntityComponent = EntityComponent; - var EntityCall = /** @class */ (function () { + __reflect(EntityComponent.prototype, "KBEngine.EntityComponent"); + var EntityCall = (function () { function EntityCall() { this.id = 0; this.className = ''; @@ -1428,7 +1424,8 @@ if (!ArrayBuffer['transfer']) { return EntityCall; }()); KBEngine.EntityCall = EntityCall; - var DATATYPE_UINT8 = /** @class */ (function () { + __reflect(EntityCall.prototype, "KBEngine.EntityCall"); + var DATATYPE_UINT8 = (function () { function DATATYPE_UINT8() { } DATATYPE_UINT8.prototype.bind = function () { @@ -1454,7 +1451,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_UINT8; }()); KBEngine.DATATYPE_UINT8 = DATATYPE_UINT8; - var DATATYPE_UINT16 = /** @class */ (function () { + __reflect(DATATYPE_UINT8.prototype, "KBEngine.DATATYPE_UINT8"); + var DATATYPE_UINT16 = (function () { function DATATYPE_UINT16() { } DATATYPE_UINT16.prototype.bind = function () { @@ -1480,7 +1478,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_UINT16; }()); KBEngine.DATATYPE_UINT16 = DATATYPE_UINT16; - var DATATYPE_UINT32 = /** @class */ (function () { + __reflect(DATATYPE_UINT16.prototype, "KBEngine.DATATYPE_UINT16"); + var DATATYPE_UINT32 = (function () { function DATATYPE_UINT32() { } DATATYPE_UINT32.prototype.bind = function () { @@ -1506,7 +1505,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_UINT32; }()); KBEngine.DATATYPE_UINT32 = DATATYPE_UINT32; - var DATATYPE_UINT64 = /** @class */ (function () { + __reflect(DATATYPE_UINT32.prototype, "KBEngine.DATATYPE_UINT32"); + var DATATYPE_UINT64 = (function () { function DATATYPE_UINT64() { } DATATYPE_UINT64.prototype.bind = function () { @@ -1526,7 +1526,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_UINT64; }()); KBEngine.DATATYPE_UINT64 = DATATYPE_UINT64; - var DATATYPE_INT8 = /** @class */ (function () { + __reflect(DATATYPE_UINT64.prototype, "KBEngine.DATATYPE_UINT64"); + var DATATYPE_INT8 = (function () { function DATATYPE_INT8() { } DATATYPE_INT8.prototype.bind = function () { @@ -1552,7 +1553,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_INT8; }()); KBEngine.DATATYPE_INT8 = DATATYPE_INT8; - var DATATYPE_INT16 = /** @class */ (function () { + __reflect(DATATYPE_INT8.prototype, "KBEngine.DATATYPE_INT8"); + var DATATYPE_INT16 = (function () { function DATATYPE_INT16() { } DATATYPE_INT16.prototype.bind = function () { @@ -1578,7 +1580,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_INT16; }()); KBEngine.DATATYPE_INT16 = DATATYPE_INT16; - var DATATYPE_INT32 = /** @class */ (function () { + __reflect(DATATYPE_INT16.prototype, "KBEngine.DATATYPE_INT16"); + var DATATYPE_INT32 = (function () { function DATATYPE_INT32() { } DATATYPE_INT32.prototype.bind = function () { @@ -1604,7 +1607,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_INT32; }()); KBEngine.DATATYPE_INT32 = DATATYPE_INT32; - var DATATYPE_INT64 = /** @class */ (function () { + __reflect(DATATYPE_INT32.prototype, "KBEngine.DATATYPE_INT32"); + var DATATYPE_INT64 = (function () { function DATATYPE_INT64() { } DATATYPE_INT64.prototype.bind = function () { @@ -1624,7 +1628,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_INT64; }()); KBEngine.DATATYPE_INT64 = DATATYPE_INT64; - var DATATYPE_FLOAT = /** @class */ (function () { + __reflect(DATATYPE_INT64.prototype, "KBEngine.DATATYPE_INT64"); + var DATATYPE_FLOAT = (function () { function DATATYPE_FLOAT() { } DATATYPE_FLOAT.prototype.bind = function () { @@ -1644,7 +1649,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_FLOAT; }()); KBEngine.DATATYPE_FLOAT = DATATYPE_FLOAT; - var DATATYPE_DOUBLE = /** @class */ (function (_super) { + __reflect(DATATYPE_FLOAT.prototype, "KBEngine.DATATYPE_FLOAT"); + var DATATYPE_DOUBLE = (function (_super) { __extends(DATATYPE_DOUBLE, _super); function DATATYPE_DOUBLE() { return _super !== null && _super.apply(this, arguments) || this; @@ -1658,7 +1664,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_DOUBLE; }(DATATYPE_FLOAT)); KBEngine.DATATYPE_DOUBLE = DATATYPE_DOUBLE; - var DATATYPE_STRING = /** @class */ (function () { + __reflect(DATATYPE_DOUBLE.prototype, "KBEngine.DATATYPE_DOUBLE"); + var DATATYPE_STRING = (function () { function DATATYPE_STRING() { } DATATYPE_STRING.prototype.bind = function () { @@ -1680,7 +1687,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_STRING; }()); KBEngine.DATATYPE_STRING = DATATYPE_STRING; - var DATATYPE_VECTOR2 = /** @class */ (function () { + __reflect(DATATYPE_STRING.prototype, "KBEngine.DATATYPE_STRING"); + var DATATYPE_VECTOR2 = (function () { function DATATYPE_VECTOR2() { } DATATYPE_VECTOR2.prototype.bind = function () { @@ -1720,7 +1728,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_VECTOR2; }()); KBEngine.DATATYPE_VECTOR2 = DATATYPE_VECTOR2; - var DATATYPE_VECTOR3 = /** @class */ (function () { + __reflect(DATATYPE_VECTOR2.prototype, "KBEngine.DATATYPE_VECTOR2"); + var DATATYPE_VECTOR3 = (function () { function DATATYPE_VECTOR3() { } DATATYPE_VECTOR3.prototype.bind = function () { @@ -1757,7 +1766,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_VECTOR3; }()); KBEngine.DATATYPE_VECTOR3 = DATATYPE_VECTOR3; - var DATATYPE_VECTOR4 = /** @class */ (function () { + __reflect(DATATYPE_VECTOR3.prototype, "KBEngine.DATATYPE_VECTOR3"); + var DATATYPE_VECTOR4 = (function () { function DATATYPE_VECTOR4() { } DATATYPE_VECTOR4.prototype.bind = function () { @@ -1796,7 +1806,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_VECTOR4; }()); KBEngine.DATATYPE_VECTOR4 = DATATYPE_VECTOR4; - var DATATYPE_PYTHON = /** @class */ (function () { + __reflect(DATATYPE_VECTOR4.prototype, "KBEngine.DATATYPE_VECTOR4"); + var DATATYPE_PYTHON = (function () { function DATATYPE_PYTHON() { } DATATYPE_PYTHON.prototype.bind = function () { @@ -1816,7 +1827,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_PYTHON; }()); KBEngine.DATATYPE_PYTHON = DATATYPE_PYTHON; - var DATATYPE_UNICODE = /** @class */ (function () { + __reflect(DATATYPE_PYTHON.prototype, "KBEngine.DATATYPE_PYTHON"); + var DATATYPE_UNICODE = (function () { function DATATYPE_UNICODE() { } DATATYPE_UNICODE.prototype.bind = function () { @@ -1838,7 +1850,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_UNICODE; }()); KBEngine.DATATYPE_UNICODE = DATATYPE_UNICODE; - var DATATYPE_ENTITY_COMPONENT = /** @class */ (function () { + __reflect(DATATYPE_UNICODE.prototype, "KBEngine.DATATYPE_UNICODE"); + var DATATYPE_ENTITY_COMPONENT = (function () { function DATATYPE_ENTITY_COMPONENT() { } DATATYPE_ENTITY_COMPONENT.prototype.bind = function () { @@ -1857,7 +1870,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_ENTITY_COMPONENT; }()); KBEngine.DATATYPE_ENTITY_COMPONENT = DATATYPE_ENTITY_COMPONENT; - var DATATYPE_ENTITYCALL = /** @class */ (function () { + __reflect(DATATYPE_ENTITY_COMPONENT.prototype, "KBEngine.DATATYPE_ENTITY_COMPONENT"); + var DATATYPE_ENTITYCALL = (function () { function DATATYPE_ENTITYCALL() { } DATATYPE_ENTITYCALL.prototype.bind = function () { @@ -1876,7 +1890,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_ENTITYCALL; }()); KBEngine.DATATYPE_ENTITYCALL = DATATYPE_ENTITYCALL; - var DATATYPE_BLOB = /** @class */ (function () { + __reflect(DATATYPE_ENTITYCALL.prototype, "KBEngine.DATATYPE_ENTITYCALL"); + var DATATYPE_BLOB = (function () { function DATATYPE_BLOB() { } DATATYPE_BLOB.prototype.bind = function () { @@ -1899,7 +1914,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_BLOB; }()); KBEngine.DATATYPE_BLOB = DATATYPE_BLOB; - var DATATYPE_ARRAY = /** @class */ (function () { + __reflect(DATATYPE_BLOB.prototype, "KBEngine.DATATYPE_BLOB"); + var DATATYPE_ARRAY = (function () { function DATATYPE_ARRAY() { this.type = null; } @@ -1937,7 +1953,8 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_ARRAY; }()); KBEngine.DATATYPE_ARRAY = DATATYPE_ARRAY; - var DATATYPE_FIXED_DICT = /** @class */ (function () { + __reflect(DATATYPE_ARRAY.prototype, "KBEngine.DATATYPE_ARRAY"); + var DATATYPE_FIXED_DICT = (function () { function DATATYPE_FIXED_DICT() { this.dicttype = {}; this.implementedBy = null; @@ -1975,6 +1992,7 @@ if (!ArrayBuffer['transfer']) { return DATATYPE_FIXED_DICT; }()); KBEngine.DATATYPE_FIXED_DICT = DATATYPE_FIXED_DICT; + __reflect(DATATYPE_FIXED_DICT.prototype, "KBEngine.DATATYPE_FIXED_DICT"); var datatypes; (function (datatypes) { datatypes.UINT8 = new DATATYPE_UINT8(); @@ -2005,7 +2023,7 @@ if (!ArrayBuffer['transfer']) { KBEngine args -----------------------------------------------------------------------------------------*/ (function (KBEngine) { - var KBEngineArgs = /** @class */ (function () { + var KBEngineArgs = (function () { function KBEngineArgs() { this.ip = '127.0.0.1'; this.port = 20013; @@ -2027,6 +2045,7 @@ if (!ArrayBuffer['transfer']) { return KBEngineArgs; }()); KBEngine.KBEngineArgs = KBEngineArgs; + __reflect(KBEngineArgs.prototype, "KBEngine.KBEngineArgs"); KBEngine.EventTypes = { // Create new account. // param1(string): accountName @@ -2148,7 +2167,7 @@ if (!ArrayBuffer['transfer']) { -----------------------------------------------------------------------------------------*/ (function (KBEngine) { KBEngine.moduledefs = {}; - var KBEngineApp = /** @class */ (function () { + var KBEngineApp = (function () { function KBEngineApp(args) { this.args = args; this.username = "testhtml51"; @@ -3983,8 +4002,9 @@ if (!ArrayBuffer['transfer']) { return KBEngineApp; }()); KBEngine.KBEngineApp = KBEngineApp; + __reflect(KBEngineApp.prototype, "KBEngine.KBEngineApp"); // 描述服务端返回的错误信息 - var ServerErr = /** @class */ (function () { + var ServerErr = (function () { function ServerErr() { this.name = ""; this.descr = ""; @@ -3993,6 +4013,7 @@ if (!ArrayBuffer['transfer']) { return ServerErr; }()); KBEngine.ServerErr = ServerErr; + __reflect(ServerErr.prototype, "KBEngine.ServerErr"); KBEngine.FragmentDataTypes = { FRAGMENT_DATA_UNKNOW: 0, FRAGMENT_DATA_MESSAGE_ID: 1, diff --git a/kbengine_ts/bin/kbengine.min.js b/kbengine_ts/bin/kbengine.min.js new file mode 100644 index 0000000..43c9c80 --- /dev/null +++ b/kbengine_ts/bin/kbengine.min.js @@ -0,0 +1,3 @@ +var __reflect=this&&this.__reflect||function(t,e,n){t.__class__=e,n?n.push(e):n=[e],t.__types__=t.__types__?n.concat(t.__types__):n},__extends=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);n.prototype=e.prototype,t.prototype=new n},KBEngine;!function(t){t.CLIENT_VERSION="2.5.0",t.CLIENT_SCRIPT_VERSION="0.1.0",t.PACKET_MAX_SIZE=1500,t.PACKET_MAX_SIZE_TCP=1460,t.PACKET_MAX_SIZE_UDP=1472,t.MESSAGE_ID_LENGTH=2,t.MESSAGE_LENGTH_LENGTH=2,t.MESSAGE_LENGTH1_LENGTH=4,t.MESSAGE_MAX_SIZE=65535,t.CLIENT_NO_FLOAT=0,t.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,ArrayBuffer.transfer||(ArrayBuffer.transfer=function(t,e){var n=new ArrayBuffer(e);if(!(t instanceof ArrayBuffer&&n instanceof ArrayBuffer))throw new TypeError("ArrayBuffer.transfer, error: Source and destination must be ArrayBuffer instances");if(!(n.byteLength>=t.byteLength))throw new RangeError("ArrayBuffer.transfer, error: destination has not enough space");var r=new Uint8Array(n);return r.set(new Uint8Array(t),0),n}),function(t){var e=function(){function t(t,e){this.sign=1,this.lo=t,this.hi=e,e>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return t.prototype.toString=function(){var t="";this.sign<0&&(t+="-");var e=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){t+=n;for(var r=8-e.length;r>0;--r)t+="0"}return t+=e},t}();t.INT64=e,__reflect(e.prototype,"KBEngine.INT64");var n=function(){function t(t,e){this.lo=t,this.hi=e}return t.prototype.toString=function(){var t=this.lo.toString(16),e=this.hi.toString(16),n="";if(this.hi>0){n+=e;for(var r=8-t.length;r>0;--r)n+="0"}return n+=t},t}();t.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(t){function e(){for(var t=[],e=0;en;)switch(a=t[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:e+=String.fromCharCode(a);break;case 12:case 13:i=t[n++],e+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=t[n++],o=t[n++],e+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return e}function n(t){for(var e=[],n=0;nr?e.push(r):2048>r?e.push(192|r>>6,128|63&r):55296>r||r>=57344?e.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&t.charCodeAt(n)),e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return e}t.utf8ArrayToString=e,t.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(t){var e=function(){function t(t,e){this.classinst=t,this.callbackfn=e}return t}();t.EventInfo=e,__reflect(e.prototype,"KBEngine.EventInfo");var n=function(){function t(t,e,n){this.evtName=t,this.evtInfo=e,this.ars=n}return t}();t.FiredEvent=n,__reflect(n.prototype,"KBEngine.FiredEvent");var r=function(){function r(){this._events={},this._isPause=!1,this._firedEvents=[]}return r.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void t.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new e(r,i);o.push(p)},r.prototype.deregisterAll=function(t){for(var e in this._events)this.deregister(e,t)},r.prototype.deregister=function(t,e){var n=this._events[t];if(n)for(var r=n.length-1;r>=0;r--){var a=n[r];a.classinst==e&&n.splice(r,1)}},r.prototype.removeAllFiredEvent=function(t){this.removeFiredEvent("",t)},r.prototype.removeFiredEvent=function(t,e){for(var n=this._firedEvents,r=n.length-1;r>=0;r--){var a=n[r];""!=t&&a.evtName!=t||a.evtInfo.classinst!=e||n.splice(r,1)}},r.prototype.fire=function(e){for(var r=[],a=1;a0;){var e=t.shift(),n=e.evtInfo,r=e.ars;r.length<1?n.callbackfn.apply(n.classinst):n.callbackfn.apply(n.classinst,r)}},r.prototype.clear=function(){this._events={},this._firedEvents.splice(0,this._firedEvents.length)},r}();t.Events=r,__reflect(r.prototype,"KBEngine.Events"),t.Event=new r}(KBEngine||(KBEngine={})),function(t){var e=function(){function t(){this._unionData=new ArrayBuffer(4),this.fv=new Float32Array(this._unionData,0,1),this.uv=new Uint32Array(this._unionData,0,1),this.iv=new Int32Array(this._unionData,0,1)}return t}();t.PackFloatXType=e,__reflect(e.prototype,"KBEngine.PackFloatXType"),t._xPackData=new e,t._yPackData=new e,t._zPackData=new e;var n=function(){function e(t){this.rpos=0,this.wpos=0,t instanceof ArrayBuffer?this.buffer=t:this.buffer=new ArrayBuffer(t),this.rpos=0,this.wpos=0}return e.prototype.readInt8=function(){var t=new Int8Array(this.buffer,this.rpos,1);return this.rpos+=1,t[0]},e.prototype.readInt16=function(){var t=this.readUint16();return t>=32768&&(t-=65536),t},e.prototype.readInt32=function(){var t=this.readUint32();return t>=2147483648&&(t-=4294967296),t},e.prototype.readInt64=function(){var e=this.readUint32(),n=this.readUint32();return new t.INT64(e,n)},e.prototype.readUint8=function(){var t=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,t[0]},e.prototype.readUint16=function(){var t=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&t[1])<<8)+(255&t[0])},e.prototype.readUint32=function(){var t=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(t[3]<<24)+(t[2]<<16)+(t[1]<<8)+t[0]},e.prototype.readUint64=function(){var e=this.readUint32(),n=this.readUint32();return new t.UINT64(e,n)},e.prototype.readFloat=function(){var t;try{t=new Float32Array(this.buffer,this.rpos,1)}catch(e){t=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,t[0]},e.prototype.readDouble=function(){var t;try{t=new Float64Array(this.buffer,this.rpos,1)}catch(e){t=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,t[0]},e.prototype.readString=function(){for(var t=new Uint8Array(this.buffer,this.rpos),e=0,n="";;){if(0==t[e]){e++;break}if(n+=String.fromCharCode(t[e]),e++,this.rpos+e>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+e)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=e,n},e.prototype.readBlob=function(){var t=this.readUint32(),e=new Uint8Array(this.buffer,this.rpos,t);return this.rpos+=t,e},e.prototype.readStream=function(){var t=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new e(t)},e.prototype.readPackXZ=function(){var e=t._xPackData,n=t._zPackData;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},e.prototype.readPackY=function(){var e=this.readUint16(),n=t._yPackData;return n.uv[0]=1073741824,n.uv[0]|=(32767&e)<<12,n.fv[0]-=2,n.uv[0]|=(32768&e)<<16,n.fv[0]},e.prototype.writeInt8=function(t){var e=new Int8Array(this.buffer,this.wpos,1);e[0]=t,this.wpos+=1},e.prototype.writeInt16=function(t){this.writeInt8(255&t),this.writeInt8(t>>8&255)},e.prototype.writeInt32=function(t){for(var e=0;4>e;e++)this.writeInt8(t>>8*e&255)},e.prototype.writeInt64=function(t){this.writeInt32(t.lo),this.writeInt32(t.hi)},e.prototype.writeUint8=function(t){var e=new Uint8Array(this.buffer,this.wpos,1);e[0]=t,this.wpos+=1},e.prototype.writeUint16=function(t){this.writeUint8(255&t),this.writeUint8(t>>8&255)},e.prototype.writeUint32=function(t){for(var e=0;4>e;e++)this.writeUint8(t>>8*e&255)},e.prototype.writeUint64=function(t){this.writeUint32(t.lo),this.writeUint32(t.hi)},e.prototype.writeFloat=function(t){try{var e=new Float32Array(this.buffer,this.wpos,1);e[0]=t}catch(n){var e=new Float32Array(1);e[0]=t;var r=new Uint8Array(this.buffer),a=new Uint8Array(e.buffer);r.set(a,this.wpos)}this.wpos+=4},e.prototype.writeDouble=function(t){try{var e=new Float64Array(this.buffer,this.wpos,1);e[0]=t}catch(n){var e=new Float64Array(1);e[0]=t;var r=new Uint8Array(this.buffer),a=new Uint8Array(e.buffer);r.set(a,this.wpos)}this.wpos+=8},e.prototype.writeBlob=function(e){var n=e.length;if(n+4>this.space())return void t.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof e)for(var a=0;n>a;a++)r[a]=e.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=e[a];this.wpos+=n},e.prototype.writeString=function(e){if(e.length>this.space())return void t.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;athis.space()&&(this.buffer=ArrayBuffer.transfer(this.buffer,this.buffer.byteLength+2*n));var r=new Uint8Array(this.buffer,this.wpos,n);r.set(new Uint8Array(t.buffer,e,n),0),this.wpos+=n},e.prototype.readSkip=function(t){this.rpos+=t},e.prototype.space=function(){return this.buffer.byteLength-this.wpos},e.prototype.length=function(){return this.wpos-this.rpos},e.prototype.readEOF=function(){return this.buffer.byteLength-this.rpos<=0},e.prototype.done=function(){this.rpos=this.wpos},e.prototype.getbuffer=function(){return this.buffer.slice(this.rpos,this.wpos)},e.prototype.setbuffer=function(t){this.clear(),this.buffer=t},e.prototype.size=function(){return this.buffer.byteLength},e.prototype.clear=function(){this.rpos=this.wpos=0,this.buffer.byteLength>t.PACKET_MAX_SIZE&&(this.buffer=new ArrayBuffer(t.PACKET_MAX_SIZE))},e.prototype.reclaimObject=function(){this.clear(),void 0!=e._objects&&e._objects.push(this)},e}();t.MemoryStream=n,__reflect(n.prototype,"KBEngine.MemoryStream"),function(e){function n(){return e._objects.length>0?e._objects.pop():new e(t.PACKET_MAX_SIZE_TCP)}e._objects=[],e.createObject=n}(n=t.MemoryStream||(t.MemoryStream={}))}(KBEngine||(KBEngine={})),function(t){function e(){t.datatype2id={},t.datatype2id.STRING=1,t.datatype2id["STD::STRING"]=1,t.datatype2id.UINT8=2,t.datatype2id.BOOL=2,t.datatype2id.DATATYPE=2,t.datatype2id.CHAR=2,t.datatype2id.DETAIL_TYPE=2,t.datatype2id.ENTITYCALL_CALL_TYPE=2,t.datatype2id.UINT16=3,t.datatype2id["UNSIGNED SHORT"]=3,t.datatype2id.SERVER_ERROR_CODE=3,t.datatype2id.ENTITY_TYPE=3,t.datatype2id.ENTITY_PROPERTY_UID=3,t.datatype2id.ENTITY_METHOD_UID=3,t.datatype2id.ENTITY_SCRIPT_UID=3,t.datatype2id.DATATYPE_UID=3,t.datatype2id.UINT32=4,t.datatype2id.UINT=4,t.datatype2id["UNSIGNED INT"]=4,t.datatype2id.ARRAYSIZE=4,t.datatype2id.SPACE_ID=4,t.datatype2id.GAME_TIME=4,t.datatype2id.TIMER_ID=4,t.datatype2id.UINT64=5,t.datatype2id.DBID=5,t.datatype2id.COMPONENT_ID=5,t.datatype2id.INT8=6,t.datatype2id.COMPONENT_ORDER=6,t.datatype2id.INT16=7,t.datatype2id.SHORT=7,t.datatype2id.INT32=8,t.datatype2id.INT=8,t.datatype2id.ENTITY_ID=8,t.datatype2id.CALLBACK_ID=8,t.datatype2id.COMPONENT_TYPE=8,t.datatype2id.INT64=9,t.datatype2id.PYTHON=10,t.datatype2id.PY_DICT=10,t.datatype2id.PY_TUPLE=10,t.datatype2id.PY_LIST=10,t.datatype2id.ENTITYCALL=10,t.datatype2id.BLOB=11,t.datatype2id.UNICODE=12,t.datatype2id.FLOAT=13,t.datatype2id.DOUBLE=14,t.datatype2id.VECTOR2=15,t.datatype2id.VECTOR3=16,t.datatype2id.VECTOR4=17,t.datatype2id.FIXED_DICT=18,t.datatype2id.ARRAY=19,t.datatype2id.ENTITYCALL=20}function n(e,n){switch(n){case t.datatype2id.UINT8:return e.writeUint8;case t.datatype2id.UINT16:return e.writeUint16;case t.datatype2id.UINT32:return e.writeUint32;case t.datatype2id.UINT64:return e.writeUint64;case t.datatype2id.INT8:return e.writeInt8;case t.datatype2id.INT16:return e.writeInt16;case t.datatype2id.INT32:return e.writeInt32;case t.datatype2id.INT64:return e.writeInt64;case t.datatype2id.FLOAT:return e.writeFloat;case t.datatype2id.DOUBLE:return e.writeDouble;case t.datatype2id.STRING:return e.writeString;case t.datatype2id.FIXED_DICT:return e.writeStream;case t.datatype2id.ARRAY:return e.writeStream;default:return e.writeStream}}function r(e){switch(e){case t.datatype2id.UINT8:return t.reader.readUint8;case t.datatype2id.UINT16:return t.reader.readUint16;case t.datatype2id.UINT32:return t.reader.readUint32;case t.datatype2id.UINT64:return t.reader.readUint64;case t.datatype2id.INT8:return t.reader.readInt8;case t.datatype2id.INT16:return t.reader.readInt16;case t.datatype2id.INT32:return t.reader.readInt32;case t.datatype2id.INT64:return t.reader.readInt64;case t.datatype2id.FLOAT:return t.reader.readFloat;case t.datatype2id.DOUBLE:return t.reader.readDouble;case t.datatype2id.STRING:return t.reader.readString;case t.datatype2id.FIXED_DICT:return t.reader.readStream;case t.datatype2id.ARRAY:return t.reader.readStream;default:return t.reader.readStream}}var a=function(){function e(){this.memorystreams=new Array,this.numMessage=0,this.messageLengthBuffer=null,this.msgtype=null,this.messageLength=0,this.stream=t.MemoryStream.createObject()}return e.createObject=function(){return e._objects.length>0?e._objects.pop():new e},e.prototype.newMessage=function(e){this.fini(!1),this.msgtype=e,this.numMessage+=1,-1==this.msgtype.length&&(this.messageLengthBuffer=new Uint8Array(this.stream.buffer,this.stream.wpos+t.MESSAGE_ID_LENGTH,2)),this.writeUint16(e.id),this.messageLengthBuffer&&(this.writeUint16(0),this.messageLengthBuffer[0]=0,this.messageLengthBuffer[1]=0,this.messageLength=0)},e.prototype.writeMsgLength=function(t){this.messageLengthBuffer&&(this.messageLengthBuffer[0]=255&t,this.messageLengthBuffer[1]=t>>8&255)},e.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream),this.stream=t.MemoryStream.createObject()),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},e.prototype.send=function(t){this.fini(!0);for(var e=0;ethis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=t.MemoryStream.createObject()),this.messageLength+=e},e.prototype.writeInt8=function(t){this.checkStream(1),this.stream.writeInt8(t)},e.prototype.writeInt16=function(t){this.checkStream(2),this.stream.writeInt16(t)},e.prototype.writeInt32=function(t){this.checkStream(4),this.stream.writeInt32(t)},e.prototype.writeInt64=function(t){this.checkStream(8),this.stream.writeInt64(t)},e.prototype.writeUint8=function(t){this.checkStream(1),this.stream.writeUint8(t)},e.prototype.writeUint16=function(t){this.checkStream(2),this.stream.writeUint16(t)},e.prototype.writeUint32=function(t){this.checkStream(4),this.stream.writeUint32(t)},e.prototype.writeUint64=function(t){this.checkStream(8),this.stream.writeUint64(t)},e.prototype.writeFloat=function(t){this.checkStream(4),this.stream.writeFloat(t)},e.prototype.writeDouble=function(t){this.checkStream(8),this.stream.writeDouble(t)},e.prototype.writeString=function(t){this.checkStream(t.length+1),this.stream.writeString(t)},e.prototype.writeBlob=function(t){this.checkStream(t.length+4),this.stream.writeBlob(t)},e.prototype.clear=function(){for(var e=0;en){var r=e;e=n,n=r}return e>t?e:n>t?t:n}function n(t,e){return t*(Math.PI/(e?254:128))}function r(t,n){var r=0;return r=n?e(Math.floor(254*t/Math.PI+.5),-128,127):Math.floor(128*t/Math.PI+.5)}var a=function(){function t(t,e){this.x=t,this.y=e}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y;return Math.sqrt(e*e+n*n)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this},t}();t.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function t(t,e,n){this.x=t,this.y=e,this.z=n,this.x=t,this.y=e,this.z=n}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y,r=t.z-this.z;return Math.sqrt(e*e+n*n+r*r)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},t}();t.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function t(t,e,n,r){this.x=t,this.y=e,this.z=n,this.w=r,this.x=t,this.y=e,this.z=n,this.w=r}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y,r=t.z-this.z,a=t.w-this.w;return Math.sqrt(e*e+n*n+r*r+a*a)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this.w/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this},t}();t.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),t.clampf=e,t.int82angle=n,t.angle2int8=r}(KBEngine||(KBEngine={})),function(t){function e(e){return function(n){t.Entities=t.Entities||{},t.Entities[e]=n}}var n=function(){function e(){this.id=0,this.className="",this.position=new t.Vector3(0,0,0),this.direction=new t.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new t.Vector3(0,0,0),this.entityLastLocalDir=new t.Vector3(0,0,0),this.isOnGround=!1}return e.prototype.__init__=function(){},e.prototype.callPropertysSetMethods=function(){var e=t.moduledefs[this.className];for(var n in e.propertys){var r=e.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},e.prototype.onDestroy=function(){},e.prototype.onControlled=function(t){},e.prototype.isPlayer=function(){return this.id==t.app.entity_id},e.prototype.baseCall=function(e){for(var n=[],r=1;rt||t>255?!1:!0},e}();t.DATATYPE_UINT8=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT8");var a=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint16.call(e)},e.prototype.addToStream=function(t,e){t.writeUint16(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>65535?!1:!0},e}();t.DATATYPE_UINT16=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT16");var i=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint32.call(e)},e.prototype.addToStream=function(t,e){t.writeUint32(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>4294967295?!1:!0},e}();t.DATATYPE_UINT32=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT32");var o=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint64.call(e)},e.prototype.addToStream=function(t,e){t.writeUint64(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(e){return e instanceof t.UINT64},e}();t.DATATYPE_UINT64=o,__reflect(o.prototype,"KBEngine.DATATYPE_UINT64");var p=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt8.call(e)},e.prototype.addToStream=function(t,e){t.writeInt8(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-128>t||t>127?!1:!0},e}();t.DATATYPE_INT8=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT8");var s=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt16.call(e)},e.prototype.addToStream=function(t,e){t.writeInt16(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-32768>t||t>32767?!1:!0},e}();t.DATATYPE_INT16=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT16");var l=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt32.call(e)},e.prototype.addToStream=function(t,e){t.writeInt32(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-2147483648>t||t>2147483647?!1:!0},e}();t.DATATYPE_INT32=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT32");var c=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt64.call(e)},e.prototype.addToStream=function(t,e){t.writeInt64(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(e){return e instanceof t.INT64},e}();t.DATATYPE_INT64=c,__reflect(c.prototype,"KBEngine.DATATYPE_INT64");var d=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readFloat.call(e)},e.prototype.addToStream=function(t,e){t.writeFloat(e)},e.prototype.parseDefaultValStr=function(t){return parseFloat(t)},e.prototype.isSameType=function(t){return"number"==typeof t},e}();t.DATATYPE_FLOAT=d,__reflect(d.prototype,"KBEngine.DATATYPE_FLOAT");var u=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.createFromStream=function(e){return t.reader.readDouble.call(e)},n.prototype.addToStream=function(t,e){t.writeDouble(e)},n}(d);t.DATATYPE_DOUBLE=u,__reflect(u.prototype,"KBEngine.DATATYPE_DOUBLE");var y=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readString.call(e)},e.prototype.addToStream=function(t,e){t.writeString(e)},e.prototype.parseDefaultValStr=function(t){return"string"==typeof t?t:""},e.prototype.isSameType=function(t){return"string"==typeof t},e}();t.DATATYPE_STRING=y,__reflect(y.prototype,"KBEngine.DATATYPE_STRING");var _=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){if(t.CLIENT_NO_FLOAT){var n=t.reader.readInt32.call(e),r=t.reader.readInt32.call(e);return new t.Vector2(n,r)}var n=t.reader.readFloat.call(e),r=t.reader.readFloat.call(e);return new t.Vector2(n,r)},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y)):(e.writeFloat(n.x),e.writeFloat(n.y))},e.prototype.parseDefaultValStr=function(e){return new t.Vector2(0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector2?!0:!1},e}();t.DATATYPE_VECTOR2=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.CLIENT_NO_FLOAT?new t.Vector3(t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e)):new t.Vector3(t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e))},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z))},e.prototype.parseDefaultValStr=function(e){return new t.Vector3(0,0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector3?!0:!1},e}();t.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var E=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.CLIENT_NO_FLOAT?new t.Vector4(t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e)):new t.Vector4(t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e))},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z),e.writeInt32(n.w)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z),e.writeFloat(n.w))},e.prototype.parseDefaultValStr=function(e){return new t.Vector4(0,0,0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector4?!0:!1},e}();t.DATATYPE_VECTOR4=E,__reflect(E.prototype,"KBEngine.DATATYPE_VECTOR4");var g=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return t.readBlob()},t.prototype.addToStream=function(t,e){t.writeBlob(e)},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_PYTHON=g,__reflect(g.prototype,"KBEngine.DATATYPE_PYTHON");var m=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.utf8ArrayToString(t.reader.readBlob.call(e)) +},e.prototype.addToStream=function(e,n){e.writeBlob(t.stringToUTF8Bytes(n))},e.prototype.parseDefaultValStr=function(t){return"string"==typeof t?t:""},e.prototype.isSameType=function(t){return"string"==typeof t},e}();t.DATATYPE_UNICODE=m,__reflect(m.prototype,"KBEngine.DATATYPE_UNICODE");var h=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){},t.prototype.addToStream=function(t,e){},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_ENTITY_COMPONENT=h,__reflect(h.prototype,"KBEngine.DATATYPE_ENTITY_COMPONENT");var v=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){},t.prototype.addToStream=function(t,e){},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_ENTITYCALL=v,__reflect(v.prototype,"KBEngine.DATATYPE_ENTITYCALL");var T=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){var n=t.reader.readUint32.call(e),r=new Uint8Array(e.buffer,e.rpos,n);return e.rpos+=n,r},e.prototype.addToStream=function(t,e){t.writeBlob(e)},e.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},e.prototype.isSameType=function(t){return!0},e}();t.DATATYPE_BLOB=T,__reflect(T.prototype,"KBEngine.DATATYPE_BLOB");var S=function(){function t(){this.type=null}return t.prototype.bind=function(){"number"==typeof this.type&&(this.type=I[this.type])},t.prototype.createFromStream=function(t){for(var e=t.readUint32(),n=[];e>0;)e--,n.push(this.type.createFromStream(t));return n},t.prototype.addToStream=function(t,e){t.writeUint32(e.length);for(var n=0;n0||null!=t.app.fragmentStream;)if(t.app.fragmentDatasFlag==t.FragmentDataTypes.FRAGMENT_DATA_UNKNOW){if(0==t.app.currMsgID){if(t.MESSAGE_ID_LENGTH>1&&n.length()=t.app.currMsgLen)r.handleMessage(t.app.fragmentStream),t.app.fragmentStream=null;else{if(n.length()0){t.app.writeFragmentMessage(t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY,n,t.app.currMsgLen);break}var i=n.wpos,o=n.rpos+a;n.wpos=o,r.handleMessage(n),n.wpos=i,n.rpos=o}t.app.currMsgID=0,t.app.currMsgLen=0,t.app.fragmentStream=null}else if(t.app.mergeFragmentMessage(n))break},e.prototype.writeFragmentMessage=function(e,n,r){var a=n.length();t.app.fragmentDatasRemain=r-a,t.app.fragmentDatasFlag=e,t.app.fragmentStream=n},e.prototype.mergeFragmentMessage=function(e){var n=e.length();if(0==n)return 0;var r=t.app.fragmentStream;if(n>=t.app.fragmentDatasRemain){switch(r.append(e,e.rpos,t.app.fragmentDatasRemain),t.app.fragmentDatasFlag){case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_ID:t.app.currMsgID=r.readUint16(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH:t.app.currMsgLen=r.readUint16(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH1:t.app.currMsgLen=r.readUint32(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY:}return e.rpos+=t.app.fragmentDatasRemain,t.app.fragmentDatasFlag=t.FragmentDataTypes.FRAGMENT_DATA_UNKNOW,t.app.fragmentDatasRemain=0,!1}return r.append(e,e.rpos,n),t.app.fragmentDatasRemain-=n,e.done(),!0},e.prototype.onclose=function(){t.INFO_MSG("connect close:"+t.app.currserver),t.app.currconnect==t.app.currstate&&(t.app.resetSocket(),t.Event.fire(t.EventTypes.onDisconnected))},e.prototype.send=function(e){t.app.socket.send(e)},e.prototype.close=function(){t.INFO_MSG("KBEngine::close()"),t.app.socket.close(),t.app.reset()},e.prototype.update=function(){if(null!=t.app.socket){var e=new Date;if((e.getTime()-t.app.lastTickTime)/1e3>t.app.args.serverHeartbeatTick/2){if(t.app.lastTickCBTime0;){n-=1;var r=new a;r.id=e.readUint16(),r.name=t.utf8ArrayToString(e.readBlob()),r.descr=t.utf8ArrayToString(e.readBlob()),t.app.serverErrs[r.id]=r,t.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},e.prototype.Client_onImportClientSdk=function(e){var n=e.readInt32(),r=e.readString(),a=e.readInt32(),i=e.readBlob();t.Event.fire("onImportClientSDK",n,r,a,i)},e.prototype.onOpenLoginapp_login=function(){if(t.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),t.Event.fire(t.EventTypes.onConnectionState,!0),t.app.currserver="loginapp",t.app.currstate="login",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),t.Event.fire("Loginapp_importClientMessages")}},e.prototype.onOpenLoginapp_createAccount=function(){if(t.Event.fire("onConnectionState",!0),t.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),t.app.currserver="loginapp",t.app.currstate="createAccount",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),t.Event.fire("Loginapp_importClientMessages")}},e.prototype.onImportClientMessagesCompleted=function(){if(t.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),t.app.socket.onmessage=t.app.onmessage,t.app.hello(),"loginapp"==t.app.currserver){if(!t.app.serverErrorsDescrImported){t.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),t.app.serverErrorsDescrImported=!0;var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importServerErrorsDescr),e.send(t.app)}"login"==t.app.currstate?t.app.login_loginapp(!1):"resetpassword"==t.app.currstate?t.app.resetpassword_loginapp(!1):t.app.createAccount_loginapp(!1),t.app.loginappMessageImported=!0}else if(t.app.baseappMessageImported=!0,t.app.entitydefImported)t.app.onImportEntityDefCompleted();else{t.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_importClientEntityDef),e.send(t.app),t.Event.fire("Baseapp_importClientEntityDef")}},e.prototype.createDataTypeFromStreams=function(e,n){var r=e.readUint16();for(t.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,t.app.createDataTypeFromStream(e,n);for(var a in t.datatypes)void 0!=t.datatypes[a]&&t.datatypes[a].bind()},e.prototype.createDataTypeFromStream=function(e,n){var r,a=e.readUint16(),i=e.readString(),o=e.readString();if(0==o.length&&(r="Null_"+a),n&&t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new t.DATATYPE_FIXED_DICT,s=e.readUint8();for(p.implementedBy=e.readString();s>0;){s--;var l=e.readString(),c=e.readUint16();p.dicttype[l]=c}t.datatypes[o]=p}else if("ARRAY"==i){var d=e.readUint16(),p=new t.DATATYPE_ARRAY;p.type=d,t.datatypes[o]=p}else t.datatypes[o]=t.datatypes[i];t.datatypes[a]=t.datatypes[o],t.datatype2id[o]=a},e.prototype.Client_onImportClientEntityDef=function(e){for(t.app.createDataTypeFromStreams(e,!0);e.length()>0;){var n=e.readString(),r=e.readUint16(),a=e.readUint16(),i=e.readUint16(),o=e.readUint16(),p=e.readUint16();t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),t.moduledefs[n]={};var s=t.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},t.moduledefs[r]=s;for(var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods,y=t.Entities[n];a>0;){a--;var _=e.readUint16(),f=e.readUint32(),E=e.readInt16(),g=e.readString(),m=e.readString(),h=t.datatypes[e.readUint16()],v=null;void 0!=y&&(v=y.prototype["set_"+g],void 0==v&&(v=null));var T=[_,E,g,m,h,v,f];l[g]=T,-1!=E?(l[E]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+g+"/"+_+").")}for(;i>0;){i--;for(var S=e.readUint16(),E=e.readInt16(),A=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);var T=[S,E,A,D];c[A]=T,-1!=E?(c[E]=T,s.useMethodDescrAlias=!0):(c[S]=T,s.useMethodDescrAlias=!1),t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+A+").")}for(;o>0;){o--;for(var S=e.readUint16(),E=e.readInt16(),M=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);d[M]=[S,E,M,D],t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+M+").")}for(;p>0;){p--;for(var S=e.readUint16(),E=e.readInt16(),F=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);u[F]=[S,E,F,D],t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+F+").")}var w=void 0;try{w=t.Entities[n]}catch(B){t.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),w=void 0}for(var C in s.propertys){var L=s.propertys[C],_=L[0],E=L[1],K=L[2],m=L[3],h=L[4];void 0!=w&&(w.prototype[K]=h.parseDefaultValStr(m))}for(var N in s.methods){var L=s.methods[N],_=L[0],E=L[1],K=L[2],D=L[3];void 0!=w&&void 0==w.prototype[K]&&t.WARNING_MSG(n+":: method("+K+") no implement!")}}t.app.onImportEntityDefCompleted()},e.prototype.Client_onVersionNotMatch=function(e){t.app.serverVersion=e.readString(),t.ERROR_MSG("Client_onVersionNotMatch: verInfo="+t.app.clientVersion+" not match(server: "+t.app.serverVersion+")"),t.Event.fire(t.EventTypes.onVersionNotMatch,t.app.clientVersion,t.app.serverVersion)},e.prototype.Client_onScriptVersionNotMatch=function(e){t.app.serverScriptVersion=e.readString(),t.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+t.app.clientScriptVersion+" not match(server: "+t.app.serverScriptVersion+")"),t.Event.fire(t.EventTypes.onScriptVersionNotMatch,t.app.clientScriptVersion,t.app.serverScriptVersion)},e.prototype.onImportEntityDefCompleted=function(){t.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),t.app.entitydefImported=!0,t.app.login_baseapp(!1)},e.prototype.importClientMessages=function(e){for(;t.app.currMsgCount>0;){t.app.currMsgCount--;for(var n=e.readUint16(),r=e.readInt16(),a=e.readString(),i=e.readInt8(),o=e.readUint8(),p=new Array(o),s=0;o>s;s++)p[s]=e.readUint8();var l=null,c=a.indexOf("Client_")>=0;c&&(l=t.app[a],null==l||void 0==l?(t.WARNING_MSG("KBEngineApp::onImportClientMessages["+t.app.currserver+"]: interface("+a+"/"+n+") no implement!"),l=null):t.INFO_MSG("KBEngineApp::onImportClientMessages: import("+a+") successfully!")),a.length>0?(t.messages[a]=new t.Message(n,a,r,i,p,l),c?t.clientmessages[n]=t.messages[a]:t.messages[t.app.currserver][n]=t.messages[a]):t.messages[t.app.currserver][n]=new t.Message(n,a,r,i,p,l)}t.app.onImportClientMessagesCompleted(),t.app.currMsgID=0,t.app.currMsgLen=0,t.app.currMsgCount=0,t.app.fragmentStream=null},e.prototype.Client_onImportClientMessages=function(e){var n=new t.MemoryStream(e.data);n.wpos=e.data.byteLength,0==t.app.currMsgID&&(t.app.currMsgID=n.readUint16()),t.app.currMsgID==t.messages.onImportClientMessages.id?(0==t.app.currMsgLen&&(t.app.currMsgLen=n.readUint16(),t.app.currMsgCount=n.readUint16()),n.length()+2=t.app.currMsgLen&&t.app.importClientMessages(t.app.fragmentStream)):t.app.importClientMessages(n)):t.ERROR_MSG("KBEngineApp::onmessage: not found msg("+t.app.currMsgID+")!")},e.prototype.createAccount=function(e,n,r){t.app.reset(),t.app.username=e,t.app.password=n,t.app.clientdatas=r,t.app.createAccount_loginapp(!0)},e.prototype.createAccount_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_createAccount;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_reqCreateAccount),n.writeString(t.app.username),n.writeString(t.app.password),n.writeBlob(t.app.clientdatas),n.send(t.app)}},e.prototype.bindAccountEmail=function(e){var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_reqAccountBindEmail),n.writeInt32(t.app.entity_id),n.writeString(t.app.password),n.writeString(e),n.send(t.app)},e.prototype.newPassword=function(e,n){var r=t.Bundle.createObject();r.newMessage(t.messages.Baseapp_reqAccountNewPassword),r.writeInt32(t.app.entity_id),r.writeString(e),r.writeString(n),r.send(t.app)},e.prototype.logout=function(){var e=new t.Bundle;e.newMessage(t.messages.Baseapp_logoutBaseapp),e.writeUint64(t.app.entity_uuid),e.writeInt32(t.app.entity_id),e.send(t.app)},e.prototype.login=function(e,n,r){t.app.reset(),t.app.username=e,t.app.password=n,t.app.clientdatas=r,t.app.login_loginapp(!0)},e.prototype.login_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_login;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_login),n.writeInt8(t.app.args.clientType),n.writeBlob(t.app.clientdatas),n.writeString(t.app.username),n.writeString(t.app.password),n.send(t.app)}},e.prototype.onOpenLoginapp_resetpassword=function(){if(t.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),t.app.currserver="loginapp",t.app.currstate="resetpassword",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},e.prototype.reset_password=function(e){t.app.reset(),t.app.username=e,t.app.resetpassword_loginapp(!0)},e.prototype.resetpassword_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_resetpassword;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_reqAccountResetPassword),n.writeString(t.app.username),n.send(t.app)}},e.prototype.onOpenBaseapp=function(){if(t.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),t.app.currserver="baseapp",t.app.baseappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.Event.fire("Baseapp_importClientMessages")}},e.prototype.login_baseapp=function(e){if(e)t.Event.fire("onLoginBaseapp"),t.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+t.app.baseappIp+":"+t.app.baseappPort+"!"),t.app.currconnect="baseapp",t.app.connect(t.app.baseappIp,t.app.baseappPort),void 0!=t.app.socket&&null!=t.app.socket&&(t.app.socket.onopen=t.app.onOpenBaseapp);else{var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_loginBaseapp),n.writeString(t.app.username),n.writeString(t.app.password),n.send(t.app)}},e.prototype.reloginBaseapp=function(){t.app.lastTickCBTime=t.app.lastTickTime=Date.now(),(void 0==t.app.socket||null==t.app.socket)&&(t.app.resetSocket(),t.Event.fire(t.EventTypes.onReloginBaseapp),t.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+t.app.baseappIp+":"+t.app.baseappPort+"!"),t.app.currconnect="baseapp",t.app.connect(t.app.baseappIp,t.app.baseappPort),void 0!=t.app.socket&&null!=t.app.socket&&(t.app.socket.onopen=t.app.onReOpenBaseapp))},e.prototype.onReOpenBaseapp=function(){t.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),t.app.currserver="baseapp";var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_reloginBaseapp),e.writeString(t.app.username),e.writeString(t.app.password),e.writeUint64(t.app.entity_uuid),e.writeInt32(t.app.entity_id),e.send(t.app);var n=new Date;t.app.lastTickCBTime=n.getTime()},e.prototype.Client_onHelloCB=function(e){t.app.serverVersion=e.readString(),t.app.serverScriptVersion=e.readString(),t.app.serverProtocolMD5=e.readString(),t.app.serverEntityDefMD5=e.readString();var n=e.readInt32();t.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+t.app.serverVersion+"), scriptVerInfo("+t.app.serverScriptVersion+"), serverProtocolMD5("+t.app.serverProtocolMD5+"), serverEntityDefMD5("+t.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;t.app.lastTickCBTime=r.getTime()},e.prototype.Client_onLoginFailed=function(e){var n=e.readUint16();t.app.serverdatas=e.readBlob(),t.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+t.app.serverErrs[n].name+"), datas("+t.app.serverdatas.length+")!"),t.Event.fire("onLoginFailed",n)},e.prototype.Client_onLoginSuccessfully=function(e){var n=e.readString();t.app.username=n,t.app.baseappIp=e.readString(),t.app.baseappPort=e.readUint16(),t.app.baseappUdpPort=e.readUint16(),t.app.serverdatas=e.readBlob(),t.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+t.app.baseappIp+":"+t.app.baseappPort+"), datas("+t.app.serverdatas.length+")!"),t.app.disconnect(),t.app.login_baseapp(!0)},e.prototype.Client_onLoginBaseappFailed=function(e){t.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onLoginBaseappFailed,e)},e.prototype.Client_onReloginBaseappFailed=function(e){t.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onReloginBaseappFailed,e)},e.prototype.Client_onReloginBaseappSuccessfully=function(e){t.app.entity_uuid=e.readUint64(),t.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+t.app.username),t.Event.fire(t.EventTypes.onReloginBaseappSuccessfully)},e.prototype.getentityclass=function(e){var n=t.Entities[e];return void 0==n?(t.ERROR_MSG("KBEngineApp::getentityclass: entityType("+e+") is error!"),n):n},e.prototype.Client_onCreatedProxies=function(e,n,r){t.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=t.app.entities[n];if(t.app.entity_uuid=e,t.app.entity_id=n,void 0==a){var i=t.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new t.EntityCall,o.base.id=n,o.base.className=r,o.base.type=t.ENTITYCALL_TYPE_BASE,t.app.entities[n]=o;var p=t.bufferedCreateEntityMessages[n];void 0!=p&&(t.app.Client_onUpdatePropertys(p),delete t.bufferedCreateEntityMessages[n]),o.__init__(),o.inited=!0,t.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=t.bufferedCreateEntityMessages[n];void 0!=p&&(t.app.Client_onUpdatePropertys(p),delete t.bufferedCreateEntityMessages[n])}},e.prototype.getViewEntityIDFromStream=function(e){var n=0;if(t.app.entityIDAliasIDList.length>255)n=e.readInt32();else{var r=e.readUint8();if(t.app.entityIDAliasIDList.length<=r)return 0;n=t.app.entityIDAliasIDList[r]}return n},e.prototype.onUpdatePropertys_=function(e,n){var r=t.app.entities[e];if(void 0==r){var a=t.bufferedCreateEntityMessages[e];if(void 0!=a)return void t.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+e+") not found!");var i=new t.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(t.bufferedCreateEntityMessages[e]=i)}for(var o,p=t.moduledefs[r.className],s=p.propertys;n.length()>0;){var l=0;p.usePropertyDescrAlias?(o=n.readInt8(),l=n.readUint8()):(o=n.readUint16(),l=n.readUint16());var c=s[l],d=c[5],u=c[6],y=c[4].createFromStream(n),_=r[c[2]];t.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+e+" "+c[2]+", val="+y+")!"),r[c[2]]=y,null!=d&&(32==u||64==u?r.inited&&d.call(r,_):r.inWorld&&d.call(r,_))}},e.prototype.Client_onUpdatePropertysOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.onUpdatePropertys_(n,e)},e.prototype.Client_onUpdatePropertys=function(e){var n=e.readInt32();t.app.onUpdatePropertys_(n,e)},e.prototype.onRemoteMethodCall_=function(e,n){var r=t.app.entities[e];if(void 0==r)return void t.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+e+") not found!");var a=0,i=0;t.moduledefs[r.className].useMethodDescrAlias?(i=n.readInt8(),a=n.readUint8()):(i=n.readUint16(),a=n.readUint16());for(var o=t.moduledefs[r.className].methods[a],p=[],s=o[3],l=0;l0&&n!=t.app.entity_id&&t.app.entityIDAliasIDList.push(n);var r;r=t.moduledefs.Length>255?e.readUint16():e.readUint8();var a=!0;e.length()>0&&(a=e.readInt8()),r=t.moduledefs[r].name,t.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+t.app.spaceID+"), isOnGround("+a+")!");var i=t.app.entities[n];if(void 0==i){var o=t.bufferedCreateEntityMessages[n];if(void 0==o)return void t.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=t.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new t.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=t.ENTITYCALL_TYPE_CELL,t.app.entities[n]=s,t.app.Client_onUpdatePropertys(o),delete t.bufferedCreateEntityMessages[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),t.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new t.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=t.ENTITYCALL_TYPE_CELL,t.app.entityIDAliasIDList=[],t.app.entities={},t.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),t.app.entityServerPos.x=i.position.x,t.app.entityServerPos.y=i.position.y,t.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),t.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},e.prototype.Client_onEntityLeaveWorldOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.Client_onEntityLeaveWorld(n) +},e.prototype.Client_onEntityLeaveWorld=function(e){var n=t.app.entities[e];if(void 0==n)return void t.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+e+") not found!");if(n.inWorld&&n.leaveWorld(),t.app.entity_id>0&&e!=t.app.entity_id){for(var r=[],a=0;a0&&(r=e.readInt8());var a=t.app.entities[n];return void 0==a?void t.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,t.app.entityServerPos.x=a.position.x,t.app.entityServerPos.y=a.position.y,t.app.entityServerPos.z=a.position.z,void a.enterSpace())},e.prototype.Client_onEntityLeaveSpace=function(e){var n=t.app.entities[e];return void 0==n?void t.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+e+") not found!"):(t.app.clearSpace(!1),void n.leaveSpace())},e.prototype.Client_onKicked=function(e){t.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onKicked,e)},e.prototype.Client_onCreateAccountResult=function(e){var n=e.readUint16(),r=e.readBlob();return t.Event.fire("onCreateAccountResult",n,r),0!=n?void t.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+t.app.username+" create is failed! code="+t.app.serverErrs[n].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+t.app.username+" create is successfully!")},e.prototype.Client_onControlEntity=function(e,n){var r=t.app.entities[e];if(void 0==r)return void t.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+e+") not found!");var a=0!=n;if(a)t.app.player().id!=r.id&&t.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||e.entityLastLocalDir.distance(e.direction)>.001){e.entityLastLocalPos.x=e.position.x,e.entityLastLocalPos.y=e.position.y,e.entityLastLocalPos.z=e.position.z,e.entityLastLocalDir.x=e.direction.x,e.entityLastLocalDir.y=e.direction.y,e.entityLastLocalDir.z=e.direction.z;var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(e.position.x),n.writeFloat(e.position.y),n.writeFloat(e.position.z),n.writeFloat(e.direction.x),n.writeFloat(e.direction.y),n.writeFloat(e.direction.z),n.writeUint8(e.isOnGround),n.writeUint32(t.app.spaceID),n.send(t.app)}for(var r in t.app.controlledEntities){var a=t.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(t.app.spaceID),n.send(t.app)}}}},e.prototype.addSpaceGeometryMapping=function(e,n){t.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+e+"), respath("+n+")!"),t.app.spaceID=e,t.app.spaceResPath=n,t.Event.fire(t.EventTypes.addSpaceGeometryMapping,n)},e.prototype.clearSpace=function(e){t.app.entityIDAliasIDList=[],t.app.spacedata={},t.app.clearEntities(e),t.app.isLoadedGeometry=!1,t.app.spaceID=0},e.prototype.clearEntities=function(e){if(t.app.controlledEntities=[],e){for(var n in t.app.entities)t.app.entities[n].inWorld&&t.app.entities[n].leaveWorld(),t.app.entities[n].onDestroy();t.app.entities={}}else{var r=t.app.player();for(var n in t.app.entities)n!=r.id&&(t.app.entities[n].inWorld&&t.app.entities[n].leaveWorld(),t.app.entities[n].onDestroy());t.app.entities={},t.app.entities[r.id]=r}},e.prototype.Client_initSpaceData=function(e){for(t.app.clearSpace(!1),t.app.spaceID=e.readInt32();e.length()>0;){var n=e.readString(),r=e.readString();t.app.Client_setSpaceData(t.app.spaceID,n,r)}t.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+t.app.spaceID+"), datas("+t.app.spacedata+")!")},e.prototype.Client_setSpaceData=function(e,n,r){t.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+e+"), key("+n+"), value("+r+")!"),t.app.spacedata[n]=r,"_mapping"==n&&t.app.addSpaceGeometryMapping(e,r),t.Event.fire("onSetSpaceData",e,n,r)},e.prototype.Client_delSpaceData=function(e,n){t.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+e+"), key("+n+")!"),delete t.app.spacedata[n],t.Event.fire("onDelSpaceData",e,n)},e.prototype.Client_getSpaceData=function(e,n){return t.app.spacedata[n]},e.prototype.Client_onUpdateBasePos=function(e,n,r){t.app.entityServerPos.x=e,t.app.entityServerPos.y=n,t.app.entityServerPos.z=r},e.prototype.Client_onUpdateBasePosXZ=function(e,n){t.app.entityServerPos.x=e,t.app.entityServerPos.z=n},e.prototype.Client_onUpdateData=function(e){var n=t.app.getViewEntityIDFromStream(e),r=t.app.entities[n];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},e.prototype.Client_onSetEntityPosAndDir=function(e){var n=e.readInt32(),r=t.app.entities[n];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=e.readFloat(),r.position.y=e.readFloat(),r.position.z=e.readFloat(),r.direction.x=e.readFloat(),r.direction.y=e.readFloat(),r.direction.z=e.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},e.prototype.Client_onUpdateData_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,i,-1)},e.prototype.Client_onUpdateData_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,a,-1)},e.prototype.Client_onUpdateData_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,-1)},e.prototype.Client_onUpdateData_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,-1)},e.prototype.Client_onUpdateData_xz=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,o,p,1)},e.prototype.Client_onUpdateData_xz_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,o,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,t.KBE_FLT_MAX,o,1)},e.prototype.Client_onUpdateData_xz_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,i,o,1)},e.prototype.Client_onUpdateData_xz_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readInt8();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,i,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readInt8();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,i,1)},e.prototype.Client_onUpdateData_xyz=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,r,a,i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat(),s=e.readFloat();t.app._updateVolatileData(n,r,a,i,o,p,s,0)},e.prototype.Client_onUpdateData_xyz_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,p,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,p,0)},e.prototype.Client_onUpdateData_xyz_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,t.KBE_FLT_MAX,o,p,0)},e.prototype.Client_onUpdateData_xyz_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,t.KBE_FLT_MAX,o,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,i,-1,!0)},e.prototype.Client_onUpdateData_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,a,-1,!0)},e.prototype.Client_onUpdateData_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,-1,!0)},e.prototype.Client_onUpdateData_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,-1,!0)},e.prototype.Client_onUpdateData_xz_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,i,o,1,!0)},e.prototype.Client_onUpdateData_xz_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,i,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,t.KBE_FLT_MAX,i,1,!0)},e.prototype.Client_onUpdateData_xz_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,a,i,1,!0)},e.prototype.Client_onUpdateData_xz_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,a,1,!0)},e.prototype.Client_onUpdateData_xyz_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8(),p=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0,!0)},e.prototype.Client_onUpdateData_xyz_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,o,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,o,0,!0)},e.prototype.Client_onUpdateData_xyz_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,i,o,0,!0)},e.prototype.Client_onUpdateData_xyz_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,i,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype._updateVolatileData=function(e,n,r,a,i,o,p,s,l){void 0===l&&(l=!1);var c=t.app.entities[e];if(void 0==c)return void t.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+e+") not found!");s>=0&&(c.isOnGround=s>0);var d=!1;p!=t.KBE_FLT_MAX&&(d=!0,c.direction.x=t.int82angle(p,!1)),o!=t.KBE_FLT_MAX&&(d=!0,c.direction.y=t.int82angle(o,!1)),i!=t.KBE_FLT_MAX&&(d=!0,c.direction.z=t.int82angle(i,!1));var u=!1;1==d&&(t.Event.fire("set_direction",c),u=!0);var y=!1;(n!=t.KBE_FLT_MAX||r!=t.KBE_FLT_MAX||a!=t.KBE_FLT_MAX)&&(y=!0),n==t.KBE_FLT_MAX&&(n=0),r==t.KBE_FLT_MAX&&(r=0),a==t.KBE_FLT_MAX&&(a=0),y&&(l?(c.position.x=n+t.app.entityServerPos.x,c.position.y=r+t.app.entityServerPos.y,c.position.z=a+t.app.entityServerPos.z):(c.position.x=n,c.position.y=r,c.position.z=a),u=!0,t.Event.fire("updatePosition",c)),u&&c.onUpdateVolatileData()},e.prototype.Client_onStreamDataStarted=function(e,n,r){t.Event.fire(t.EventTypes.onStreamDataStarted,e,n,r)},e.prototype.Client_onStreamDataRecv=function(e){var n=e.readUint16(),r=e.readBlob();t.Event.fire(t.EventTypes.onStreamDataRecv,n,r)},e.prototype.Client_onStreamDataCompleted=function(e){t.Event.fire(t.EventTypes.onStreamDataCompleted,e)},e.prototype.Client_onReqAccountResetPasswordCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+t.app.username+" is successfully!")},e.prototype.Client_onReqAccountBindEmailCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+t.app.username+" is successfully!")},e.prototype.Client_onReqAccountNewPasswordCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+t.app.username+" is successfully!")},e}();t.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function t(){this.name="",this.descr="",this.id=0}return t}();t.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr"),t.FragmentDataTypes={FRAGMENT_DATA_UNKNOW:0,FRAGMENT_DATA_MESSAGE_ID:1,FRAGMENT_DATA_MESSAGE_LENGTH:2,FRAGMENT_DATA_MESSAGE_LENGTH1:3,FRAGMENT_DATA_MESSAGE_BODY:4};var i;t.create=e,t.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/package.json b/kbengine_ts/package.json index ff3dc69..d09e17c 100644 --- a/kbengine_ts/package.json +++ b/kbengine_ts/package.json @@ -1,4 +1,4 @@ { "name": "kbengine_ts", - "compilerVersion": "5.1.7" + "compilerVersion": "5.2.18" } \ No newline at end of file diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index 6ed2d3d..0f4b0ba 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -266,19 +266,11 @@ namespace KBEngine { deregister(evtName: string, classinst) { let evtlst = this._events[evtName]; if (!evtlst) return; - while (true) { - let found = false; - for (let i = 0; i < evtlst.length; i++) { - let info = evtlst[i]; - if (info.classinst == classinst) { - evtlst.splice(i, 1); - found = true; - break; - } + for (let i = evtlst.length - 1; i >= 0; i--) { + let info = evtlst[i]; + if (info.classinst == classinst) { + evtlst.splice(i, 1); } - - if (!found) - break; } } removeAllFiredEvent(classinst) { @@ -286,19 +278,11 @@ namespace KBEngine { } removeFiredEvent(evtName: string, classinst) { let firedEvents = this._firedEvents; - while (true) { - let found = false; - for (let i = 0; i < firedEvents.length; i++) { - let evt = firedEvents[i]; - if ((evtName == "" || evt.evtName == evtName) && evt.evtInfo.classinst == classinst) { - firedEvents.splice(i, 1); - found = true; - break; - } + for (let i = firedEvents.length - 1; i >= 0; i--) { + let evt = firedEvents[i]; + if ((evtName == "" || evt.evtName == evtName) && evt.evtInfo.classinst == classinst) { + firedEvents.splice(i, 1); } - - if (!found) - break; } } fire(evtName: string, ...args: any[]) { From 78a33cdcffa8042f357f727fea1d8a92c1b5f0be Mon Sep 17 00:00:00 2001 From: zengmingnan Date: Wed, 5 Jun 2019 18:00:10 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=E9=80=82=E9=85=8D2.x=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=20=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=90=8E=E8=B7=AF=E5=BE=84=EF=BC=8C=E9=80=82=E9=85=8D=E7=99=BD?= =?UTF-8?q?=E9=B9=AD=E7=9A=84=E7=AC=AC=E4=B8=89=E6=96=B9=E5=BA=93=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kbengine_ts/bin/kbengine.min.js | 3 - kbengine_ts/{bin => kbengine}/kbengine.d.ts | 63 +++-- kbengine_ts/{bin => kbengine}/kbengine.js | 284 +++++++++++++++----- kbengine_ts/kbengine/kbengine.min.js | 3 + kbengine_ts/src/KBEngine.ts | 278 ++++++++++++++----- kbengine_ts/tsconfig.json | 4 +- 6 files changed, 472 insertions(+), 163 deletions(-) delete mode 100644 kbengine_ts/bin/kbengine.min.js rename kbengine_ts/{bin => kbengine}/kbengine.d.ts (92%) rename kbengine_ts/{bin => kbengine}/kbengine.js (95%) create mode 100644 kbengine_ts/kbengine/kbengine.min.js diff --git a/kbengine_ts/bin/kbengine.min.js b/kbengine_ts/bin/kbengine.min.js deleted file mode 100644 index 43c9c80..0000000 --- a/kbengine_ts/bin/kbengine.min.js +++ /dev/null @@ -1,3 +0,0 @@ -var __reflect=this&&this.__reflect||function(t,e,n){t.__class__=e,n?n.push(e):n=[e],t.__types__=t.__types__?n.concat(t.__types__):n},__extends=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);n.prototype=e.prototype,t.prototype=new n},KBEngine;!function(t){t.CLIENT_VERSION="2.5.0",t.CLIENT_SCRIPT_VERSION="0.1.0",t.PACKET_MAX_SIZE=1500,t.PACKET_MAX_SIZE_TCP=1460,t.PACKET_MAX_SIZE_UDP=1472,t.MESSAGE_ID_LENGTH=2,t.MESSAGE_LENGTH_LENGTH=2,t.MESSAGE_LENGTH1_LENGTH=4,t.MESSAGE_MAX_SIZE=65535,t.CLIENT_NO_FLOAT=0,t.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,ArrayBuffer.transfer||(ArrayBuffer.transfer=function(t,e){var n=new ArrayBuffer(e);if(!(t instanceof ArrayBuffer&&n instanceof ArrayBuffer))throw new TypeError("ArrayBuffer.transfer, error: Source and destination must be ArrayBuffer instances");if(!(n.byteLength>=t.byteLength))throw new RangeError("ArrayBuffer.transfer, error: destination has not enough space");var r=new Uint8Array(n);return r.set(new Uint8Array(t),0),n}),function(t){var e=function(){function t(t,e){this.sign=1,this.lo=t,this.hi=e,e>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return t.prototype.toString=function(){var t="";this.sign<0&&(t+="-");var e=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){t+=n;for(var r=8-e.length;r>0;--r)t+="0"}return t+=e},t}();t.INT64=e,__reflect(e.prototype,"KBEngine.INT64");var n=function(){function t(t,e){this.lo=t,this.hi=e}return t.prototype.toString=function(){var t=this.lo.toString(16),e=this.hi.toString(16),n="";if(this.hi>0){n+=e;for(var r=8-t.length;r>0;--r)n+="0"}return n+=t},t}();t.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(t){function e(){for(var t=[],e=0;en;)switch(a=t[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:e+=String.fromCharCode(a);break;case 12:case 13:i=t[n++],e+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=t[n++],o=t[n++],e+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return e}function n(t){for(var e=[],n=0;nr?e.push(r):2048>r?e.push(192|r>>6,128|63&r):55296>r||r>=57344?e.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&t.charCodeAt(n)),e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return e}t.utf8ArrayToString=e,t.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(t){var e=function(){function t(t,e){this.classinst=t,this.callbackfn=e}return t}();t.EventInfo=e,__reflect(e.prototype,"KBEngine.EventInfo");var n=function(){function t(t,e,n){this.evtName=t,this.evtInfo=e,this.ars=n}return t}();t.FiredEvent=n,__reflect(n.prototype,"KBEngine.FiredEvent");var r=function(){function r(){this._events={},this._isPause=!1,this._firedEvents=[]}return r.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void t.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new e(r,i);o.push(p)},r.prototype.deregisterAll=function(t){for(var e in this._events)this.deregister(e,t)},r.prototype.deregister=function(t,e){var n=this._events[t];if(n)for(var r=n.length-1;r>=0;r--){var a=n[r];a.classinst==e&&n.splice(r,1)}},r.prototype.removeAllFiredEvent=function(t){this.removeFiredEvent("",t)},r.prototype.removeFiredEvent=function(t,e){for(var n=this._firedEvents,r=n.length-1;r>=0;r--){var a=n[r];""!=t&&a.evtName!=t||a.evtInfo.classinst!=e||n.splice(r,1)}},r.prototype.fire=function(e){for(var r=[],a=1;a0;){var e=t.shift(),n=e.evtInfo,r=e.ars;r.length<1?n.callbackfn.apply(n.classinst):n.callbackfn.apply(n.classinst,r)}},r.prototype.clear=function(){this._events={},this._firedEvents.splice(0,this._firedEvents.length)},r}();t.Events=r,__reflect(r.prototype,"KBEngine.Events"),t.Event=new r}(KBEngine||(KBEngine={})),function(t){var e=function(){function t(){this._unionData=new ArrayBuffer(4),this.fv=new Float32Array(this._unionData,0,1),this.uv=new Uint32Array(this._unionData,0,1),this.iv=new Int32Array(this._unionData,0,1)}return t}();t.PackFloatXType=e,__reflect(e.prototype,"KBEngine.PackFloatXType"),t._xPackData=new e,t._yPackData=new e,t._zPackData=new e;var n=function(){function e(t){this.rpos=0,this.wpos=0,t instanceof ArrayBuffer?this.buffer=t:this.buffer=new ArrayBuffer(t),this.rpos=0,this.wpos=0}return e.prototype.readInt8=function(){var t=new Int8Array(this.buffer,this.rpos,1);return this.rpos+=1,t[0]},e.prototype.readInt16=function(){var t=this.readUint16();return t>=32768&&(t-=65536),t},e.prototype.readInt32=function(){var t=this.readUint32();return t>=2147483648&&(t-=4294967296),t},e.prototype.readInt64=function(){var e=this.readUint32(),n=this.readUint32();return new t.INT64(e,n)},e.prototype.readUint8=function(){var t=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,t[0]},e.prototype.readUint16=function(){var t=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&t[1])<<8)+(255&t[0])},e.prototype.readUint32=function(){var t=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(t[3]<<24)+(t[2]<<16)+(t[1]<<8)+t[0]},e.prototype.readUint64=function(){var e=this.readUint32(),n=this.readUint32();return new t.UINT64(e,n)},e.prototype.readFloat=function(){var t;try{t=new Float32Array(this.buffer,this.rpos,1)}catch(e){t=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,t[0]},e.prototype.readDouble=function(){var t;try{t=new Float64Array(this.buffer,this.rpos,1)}catch(e){t=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,t[0]},e.prototype.readString=function(){for(var t=new Uint8Array(this.buffer,this.rpos),e=0,n="";;){if(0==t[e]){e++;break}if(n+=String.fromCharCode(t[e]),e++,this.rpos+e>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+e)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=e,n},e.prototype.readBlob=function(){var t=this.readUint32(),e=new Uint8Array(this.buffer,this.rpos,t);return this.rpos+=t,e},e.prototype.readStream=function(){var t=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new e(t)},e.prototype.readPackXZ=function(){var e=t._xPackData,n=t._zPackData;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},e.prototype.readPackY=function(){var e=this.readUint16(),n=t._yPackData;return n.uv[0]=1073741824,n.uv[0]|=(32767&e)<<12,n.fv[0]-=2,n.uv[0]|=(32768&e)<<16,n.fv[0]},e.prototype.writeInt8=function(t){var e=new Int8Array(this.buffer,this.wpos,1);e[0]=t,this.wpos+=1},e.prototype.writeInt16=function(t){this.writeInt8(255&t),this.writeInt8(t>>8&255)},e.prototype.writeInt32=function(t){for(var e=0;4>e;e++)this.writeInt8(t>>8*e&255)},e.prototype.writeInt64=function(t){this.writeInt32(t.lo),this.writeInt32(t.hi)},e.prototype.writeUint8=function(t){var e=new Uint8Array(this.buffer,this.wpos,1);e[0]=t,this.wpos+=1},e.prototype.writeUint16=function(t){this.writeUint8(255&t),this.writeUint8(t>>8&255)},e.prototype.writeUint32=function(t){for(var e=0;4>e;e++)this.writeUint8(t>>8*e&255)},e.prototype.writeUint64=function(t){this.writeUint32(t.lo),this.writeUint32(t.hi)},e.prototype.writeFloat=function(t){try{var e=new Float32Array(this.buffer,this.wpos,1);e[0]=t}catch(n){var e=new Float32Array(1);e[0]=t;var r=new Uint8Array(this.buffer),a=new Uint8Array(e.buffer);r.set(a,this.wpos)}this.wpos+=4},e.prototype.writeDouble=function(t){try{var e=new Float64Array(this.buffer,this.wpos,1);e[0]=t}catch(n){var e=new Float64Array(1);e[0]=t;var r=new Uint8Array(this.buffer),a=new Uint8Array(e.buffer);r.set(a,this.wpos)}this.wpos+=8},e.prototype.writeBlob=function(e){var n=e.length;if(n+4>this.space())return void t.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof e)for(var a=0;n>a;a++)r[a]=e.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=e[a];this.wpos+=n},e.prototype.writeString=function(e){if(e.length>this.space())return void t.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;athis.space()&&(this.buffer=ArrayBuffer.transfer(this.buffer,this.buffer.byteLength+2*n));var r=new Uint8Array(this.buffer,this.wpos,n);r.set(new Uint8Array(t.buffer,e,n),0),this.wpos+=n},e.prototype.readSkip=function(t){this.rpos+=t},e.prototype.space=function(){return this.buffer.byteLength-this.wpos},e.prototype.length=function(){return this.wpos-this.rpos},e.prototype.readEOF=function(){return this.buffer.byteLength-this.rpos<=0},e.prototype.done=function(){this.rpos=this.wpos},e.prototype.getbuffer=function(){return this.buffer.slice(this.rpos,this.wpos)},e.prototype.setbuffer=function(t){this.clear(),this.buffer=t},e.prototype.size=function(){return this.buffer.byteLength},e.prototype.clear=function(){this.rpos=this.wpos=0,this.buffer.byteLength>t.PACKET_MAX_SIZE&&(this.buffer=new ArrayBuffer(t.PACKET_MAX_SIZE))},e.prototype.reclaimObject=function(){this.clear(),void 0!=e._objects&&e._objects.push(this)},e}();t.MemoryStream=n,__reflect(n.prototype,"KBEngine.MemoryStream"),function(e){function n(){return e._objects.length>0?e._objects.pop():new e(t.PACKET_MAX_SIZE_TCP)}e._objects=[],e.createObject=n}(n=t.MemoryStream||(t.MemoryStream={}))}(KBEngine||(KBEngine={})),function(t){function e(){t.datatype2id={},t.datatype2id.STRING=1,t.datatype2id["STD::STRING"]=1,t.datatype2id.UINT8=2,t.datatype2id.BOOL=2,t.datatype2id.DATATYPE=2,t.datatype2id.CHAR=2,t.datatype2id.DETAIL_TYPE=2,t.datatype2id.ENTITYCALL_CALL_TYPE=2,t.datatype2id.UINT16=3,t.datatype2id["UNSIGNED SHORT"]=3,t.datatype2id.SERVER_ERROR_CODE=3,t.datatype2id.ENTITY_TYPE=3,t.datatype2id.ENTITY_PROPERTY_UID=3,t.datatype2id.ENTITY_METHOD_UID=3,t.datatype2id.ENTITY_SCRIPT_UID=3,t.datatype2id.DATATYPE_UID=3,t.datatype2id.UINT32=4,t.datatype2id.UINT=4,t.datatype2id["UNSIGNED INT"]=4,t.datatype2id.ARRAYSIZE=4,t.datatype2id.SPACE_ID=4,t.datatype2id.GAME_TIME=4,t.datatype2id.TIMER_ID=4,t.datatype2id.UINT64=5,t.datatype2id.DBID=5,t.datatype2id.COMPONENT_ID=5,t.datatype2id.INT8=6,t.datatype2id.COMPONENT_ORDER=6,t.datatype2id.INT16=7,t.datatype2id.SHORT=7,t.datatype2id.INT32=8,t.datatype2id.INT=8,t.datatype2id.ENTITY_ID=8,t.datatype2id.CALLBACK_ID=8,t.datatype2id.COMPONENT_TYPE=8,t.datatype2id.INT64=9,t.datatype2id.PYTHON=10,t.datatype2id.PY_DICT=10,t.datatype2id.PY_TUPLE=10,t.datatype2id.PY_LIST=10,t.datatype2id.ENTITYCALL=10,t.datatype2id.BLOB=11,t.datatype2id.UNICODE=12,t.datatype2id.FLOAT=13,t.datatype2id.DOUBLE=14,t.datatype2id.VECTOR2=15,t.datatype2id.VECTOR3=16,t.datatype2id.VECTOR4=17,t.datatype2id.FIXED_DICT=18,t.datatype2id.ARRAY=19,t.datatype2id.ENTITYCALL=20}function n(e,n){switch(n){case t.datatype2id.UINT8:return e.writeUint8;case t.datatype2id.UINT16:return e.writeUint16;case t.datatype2id.UINT32:return e.writeUint32;case t.datatype2id.UINT64:return e.writeUint64;case t.datatype2id.INT8:return e.writeInt8;case t.datatype2id.INT16:return e.writeInt16;case t.datatype2id.INT32:return e.writeInt32;case t.datatype2id.INT64:return e.writeInt64;case t.datatype2id.FLOAT:return e.writeFloat;case t.datatype2id.DOUBLE:return e.writeDouble;case t.datatype2id.STRING:return e.writeString;case t.datatype2id.FIXED_DICT:return e.writeStream;case t.datatype2id.ARRAY:return e.writeStream;default:return e.writeStream}}function r(e){switch(e){case t.datatype2id.UINT8:return t.reader.readUint8;case t.datatype2id.UINT16:return t.reader.readUint16;case t.datatype2id.UINT32:return t.reader.readUint32;case t.datatype2id.UINT64:return t.reader.readUint64;case t.datatype2id.INT8:return t.reader.readInt8;case t.datatype2id.INT16:return t.reader.readInt16;case t.datatype2id.INT32:return t.reader.readInt32;case t.datatype2id.INT64:return t.reader.readInt64;case t.datatype2id.FLOAT:return t.reader.readFloat;case t.datatype2id.DOUBLE:return t.reader.readDouble;case t.datatype2id.STRING:return t.reader.readString;case t.datatype2id.FIXED_DICT:return t.reader.readStream;case t.datatype2id.ARRAY:return t.reader.readStream;default:return t.reader.readStream}}var a=function(){function e(){this.memorystreams=new Array,this.numMessage=0,this.messageLengthBuffer=null,this.msgtype=null,this.messageLength=0,this.stream=t.MemoryStream.createObject()}return e.createObject=function(){return e._objects.length>0?e._objects.pop():new e},e.prototype.newMessage=function(e){this.fini(!1),this.msgtype=e,this.numMessage+=1,-1==this.msgtype.length&&(this.messageLengthBuffer=new Uint8Array(this.stream.buffer,this.stream.wpos+t.MESSAGE_ID_LENGTH,2)),this.writeUint16(e.id),this.messageLengthBuffer&&(this.writeUint16(0),this.messageLengthBuffer[0]=0,this.messageLengthBuffer[1]=0,this.messageLength=0)},e.prototype.writeMsgLength=function(t){this.messageLengthBuffer&&(this.messageLengthBuffer[0]=255&t,this.messageLengthBuffer[1]=t>>8&255)},e.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream),this.stream=t.MemoryStream.createObject()),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},e.prototype.send=function(t){this.fini(!0);for(var e=0;ethis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=t.MemoryStream.createObject()),this.messageLength+=e},e.prototype.writeInt8=function(t){this.checkStream(1),this.stream.writeInt8(t)},e.prototype.writeInt16=function(t){this.checkStream(2),this.stream.writeInt16(t)},e.prototype.writeInt32=function(t){this.checkStream(4),this.stream.writeInt32(t)},e.prototype.writeInt64=function(t){this.checkStream(8),this.stream.writeInt64(t)},e.prototype.writeUint8=function(t){this.checkStream(1),this.stream.writeUint8(t)},e.prototype.writeUint16=function(t){this.checkStream(2),this.stream.writeUint16(t)},e.prototype.writeUint32=function(t){this.checkStream(4),this.stream.writeUint32(t)},e.prototype.writeUint64=function(t){this.checkStream(8),this.stream.writeUint64(t)},e.prototype.writeFloat=function(t){this.checkStream(4),this.stream.writeFloat(t)},e.prototype.writeDouble=function(t){this.checkStream(8),this.stream.writeDouble(t)},e.prototype.writeString=function(t){this.checkStream(t.length+1),this.stream.writeString(t)},e.prototype.writeBlob=function(t){this.checkStream(t.length+4),this.stream.writeBlob(t)},e.prototype.clear=function(){for(var e=0;en){var r=e;e=n,n=r}return e>t?e:n>t?t:n}function n(t,e){return t*(Math.PI/(e?254:128))}function r(t,n){var r=0;return r=n?e(Math.floor(254*t/Math.PI+.5),-128,127):Math.floor(128*t/Math.PI+.5)}var a=function(){function t(t,e){this.x=t,this.y=e}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y;return Math.sqrt(e*e+n*n)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this},t}();t.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function t(t,e,n){this.x=t,this.y=e,this.z=n,this.x=t,this.y=e,this.z=n}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y,r=t.z-this.z;return Math.sqrt(e*e+n*n+r*r)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},t}();t.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function t(t,e,n,r){this.x=t,this.y=e,this.z=n,this.w=r,this.x=t,this.y=e,this.z=n,this.w=r}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y,r=t.z-this.z,a=t.w-this.w;return Math.sqrt(e*e+n*n+r*r+a*a)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this.w/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this},t}();t.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),t.clampf=e,t.int82angle=n,t.angle2int8=r}(KBEngine||(KBEngine={})),function(t){function e(e){return function(n){t.Entities=t.Entities||{},t.Entities[e]=n}}var n=function(){function e(){this.id=0,this.className="",this.position=new t.Vector3(0,0,0),this.direction=new t.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new t.Vector3(0,0,0),this.entityLastLocalDir=new t.Vector3(0,0,0),this.isOnGround=!1}return e.prototype.__init__=function(){},e.prototype.callPropertysSetMethods=function(){var e=t.moduledefs[this.className];for(var n in e.propertys){var r=e.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},e.prototype.onDestroy=function(){},e.prototype.onControlled=function(t){},e.prototype.isPlayer=function(){return this.id==t.app.entity_id},e.prototype.baseCall=function(e){for(var n=[],r=1;rt||t>255?!1:!0},e}();t.DATATYPE_UINT8=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT8");var a=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint16.call(e)},e.prototype.addToStream=function(t,e){t.writeUint16(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>65535?!1:!0},e}();t.DATATYPE_UINT16=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT16");var i=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint32.call(e)},e.prototype.addToStream=function(t,e){t.writeUint32(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>4294967295?!1:!0},e}();t.DATATYPE_UINT32=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT32");var o=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint64.call(e)},e.prototype.addToStream=function(t,e){t.writeUint64(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(e){return e instanceof t.UINT64},e}();t.DATATYPE_UINT64=o,__reflect(o.prototype,"KBEngine.DATATYPE_UINT64");var p=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt8.call(e)},e.prototype.addToStream=function(t,e){t.writeInt8(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-128>t||t>127?!1:!0},e}();t.DATATYPE_INT8=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT8");var s=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt16.call(e)},e.prototype.addToStream=function(t,e){t.writeInt16(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-32768>t||t>32767?!1:!0},e}();t.DATATYPE_INT16=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT16");var l=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt32.call(e)},e.prototype.addToStream=function(t,e){t.writeInt32(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-2147483648>t||t>2147483647?!1:!0},e}();t.DATATYPE_INT32=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT32");var c=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt64.call(e)},e.prototype.addToStream=function(t,e){t.writeInt64(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(e){return e instanceof t.INT64},e}();t.DATATYPE_INT64=c,__reflect(c.prototype,"KBEngine.DATATYPE_INT64");var d=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readFloat.call(e)},e.prototype.addToStream=function(t,e){t.writeFloat(e)},e.prototype.parseDefaultValStr=function(t){return parseFloat(t)},e.prototype.isSameType=function(t){return"number"==typeof t},e}();t.DATATYPE_FLOAT=d,__reflect(d.prototype,"KBEngine.DATATYPE_FLOAT");var u=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.createFromStream=function(e){return t.reader.readDouble.call(e)},n.prototype.addToStream=function(t,e){t.writeDouble(e)},n}(d);t.DATATYPE_DOUBLE=u,__reflect(u.prototype,"KBEngine.DATATYPE_DOUBLE");var y=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readString.call(e)},e.prototype.addToStream=function(t,e){t.writeString(e)},e.prototype.parseDefaultValStr=function(t){return"string"==typeof t?t:""},e.prototype.isSameType=function(t){return"string"==typeof t},e}();t.DATATYPE_STRING=y,__reflect(y.prototype,"KBEngine.DATATYPE_STRING");var _=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){if(t.CLIENT_NO_FLOAT){var n=t.reader.readInt32.call(e),r=t.reader.readInt32.call(e);return new t.Vector2(n,r)}var n=t.reader.readFloat.call(e),r=t.reader.readFloat.call(e);return new t.Vector2(n,r)},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y)):(e.writeFloat(n.x),e.writeFloat(n.y))},e.prototype.parseDefaultValStr=function(e){return new t.Vector2(0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector2?!0:!1},e}();t.DATATYPE_VECTOR2=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.CLIENT_NO_FLOAT?new t.Vector3(t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e)):new t.Vector3(t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e))},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z))},e.prototype.parseDefaultValStr=function(e){return new t.Vector3(0,0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector3?!0:!1},e}();t.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var E=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.CLIENT_NO_FLOAT?new t.Vector4(t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e)):new t.Vector4(t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e))},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z),e.writeInt32(n.w)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z),e.writeFloat(n.w))},e.prototype.parseDefaultValStr=function(e){return new t.Vector4(0,0,0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector4?!0:!1},e}();t.DATATYPE_VECTOR4=E,__reflect(E.prototype,"KBEngine.DATATYPE_VECTOR4");var g=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return t.readBlob()},t.prototype.addToStream=function(t,e){t.writeBlob(e)},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_PYTHON=g,__reflect(g.prototype,"KBEngine.DATATYPE_PYTHON");var m=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.utf8ArrayToString(t.reader.readBlob.call(e)) -},e.prototype.addToStream=function(e,n){e.writeBlob(t.stringToUTF8Bytes(n))},e.prototype.parseDefaultValStr=function(t){return"string"==typeof t?t:""},e.prototype.isSameType=function(t){return"string"==typeof t},e}();t.DATATYPE_UNICODE=m,__reflect(m.prototype,"KBEngine.DATATYPE_UNICODE");var h=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){},t.prototype.addToStream=function(t,e){},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_ENTITY_COMPONENT=h,__reflect(h.prototype,"KBEngine.DATATYPE_ENTITY_COMPONENT");var v=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){},t.prototype.addToStream=function(t,e){},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_ENTITYCALL=v,__reflect(v.prototype,"KBEngine.DATATYPE_ENTITYCALL");var T=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){var n=t.reader.readUint32.call(e),r=new Uint8Array(e.buffer,e.rpos,n);return e.rpos+=n,r},e.prototype.addToStream=function(t,e){t.writeBlob(e)},e.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},e.prototype.isSameType=function(t){return!0},e}();t.DATATYPE_BLOB=T,__reflect(T.prototype,"KBEngine.DATATYPE_BLOB");var S=function(){function t(){this.type=null}return t.prototype.bind=function(){"number"==typeof this.type&&(this.type=I[this.type])},t.prototype.createFromStream=function(t){for(var e=t.readUint32(),n=[];e>0;)e--,n.push(this.type.createFromStream(t));return n},t.prototype.addToStream=function(t,e){t.writeUint32(e.length);for(var n=0;n0||null!=t.app.fragmentStream;)if(t.app.fragmentDatasFlag==t.FragmentDataTypes.FRAGMENT_DATA_UNKNOW){if(0==t.app.currMsgID){if(t.MESSAGE_ID_LENGTH>1&&n.length()=t.app.currMsgLen)r.handleMessage(t.app.fragmentStream),t.app.fragmentStream=null;else{if(n.length()0){t.app.writeFragmentMessage(t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY,n,t.app.currMsgLen);break}var i=n.wpos,o=n.rpos+a;n.wpos=o,r.handleMessage(n),n.wpos=i,n.rpos=o}t.app.currMsgID=0,t.app.currMsgLen=0,t.app.fragmentStream=null}else if(t.app.mergeFragmentMessage(n))break},e.prototype.writeFragmentMessage=function(e,n,r){var a=n.length();t.app.fragmentDatasRemain=r-a,t.app.fragmentDatasFlag=e,t.app.fragmentStream=n},e.prototype.mergeFragmentMessage=function(e){var n=e.length();if(0==n)return 0;var r=t.app.fragmentStream;if(n>=t.app.fragmentDatasRemain){switch(r.append(e,e.rpos,t.app.fragmentDatasRemain),t.app.fragmentDatasFlag){case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_ID:t.app.currMsgID=r.readUint16(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH:t.app.currMsgLen=r.readUint16(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH1:t.app.currMsgLen=r.readUint32(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY:}return e.rpos+=t.app.fragmentDatasRemain,t.app.fragmentDatasFlag=t.FragmentDataTypes.FRAGMENT_DATA_UNKNOW,t.app.fragmentDatasRemain=0,!1}return r.append(e,e.rpos,n),t.app.fragmentDatasRemain-=n,e.done(),!0},e.prototype.onclose=function(){t.INFO_MSG("connect close:"+t.app.currserver),t.app.currconnect==t.app.currstate&&(t.app.resetSocket(),t.Event.fire(t.EventTypes.onDisconnected))},e.prototype.send=function(e){t.app.socket.send(e)},e.prototype.close=function(){t.INFO_MSG("KBEngine::close()"),t.app.socket.close(),t.app.reset()},e.prototype.update=function(){if(null!=t.app.socket){var e=new Date;if((e.getTime()-t.app.lastTickTime)/1e3>t.app.args.serverHeartbeatTick/2){if(t.app.lastTickCBTime0;){n-=1;var r=new a;r.id=e.readUint16(),r.name=t.utf8ArrayToString(e.readBlob()),r.descr=t.utf8ArrayToString(e.readBlob()),t.app.serverErrs[r.id]=r,t.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},e.prototype.Client_onImportClientSdk=function(e){var n=e.readInt32(),r=e.readString(),a=e.readInt32(),i=e.readBlob();t.Event.fire("onImportClientSDK",n,r,a,i)},e.prototype.onOpenLoginapp_login=function(){if(t.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),t.Event.fire(t.EventTypes.onConnectionState,!0),t.app.currserver="loginapp",t.app.currstate="login",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),t.Event.fire("Loginapp_importClientMessages")}},e.prototype.onOpenLoginapp_createAccount=function(){if(t.Event.fire("onConnectionState",!0),t.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),t.app.currserver="loginapp",t.app.currstate="createAccount",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),t.Event.fire("Loginapp_importClientMessages")}},e.prototype.onImportClientMessagesCompleted=function(){if(t.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),t.app.socket.onmessage=t.app.onmessage,t.app.hello(),"loginapp"==t.app.currserver){if(!t.app.serverErrorsDescrImported){t.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),t.app.serverErrorsDescrImported=!0;var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importServerErrorsDescr),e.send(t.app)}"login"==t.app.currstate?t.app.login_loginapp(!1):"resetpassword"==t.app.currstate?t.app.resetpassword_loginapp(!1):t.app.createAccount_loginapp(!1),t.app.loginappMessageImported=!0}else if(t.app.baseappMessageImported=!0,t.app.entitydefImported)t.app.onImportEntityDefCompleted();else{t.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_importClientEntityDef),e.send(t.app),t.Event.fire("Baseapp_importClientEntityDef")}},e.prototype.createDataTypeFromStreams=function(e,n){var r=e.readUint16();for(t.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,t.app.createDataTypeFromStream(e,n);for(var a in t.datatypes)void 0!=t.datatypes[a]&&t.datatypes[a].bind()},e.prototype.createDataTypeFromStream=function(e,n){var r,a=e.readUint16(),i=e.readString(),o=e.readString();if(0==o.length&&(r="Null_"+a),n&&t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new t.DATATYPE_FIXED_DICT,s=e.readUint8();for(p.implementedBy=e.readString();s>0;){s--;var l=e.readString(),c=e.readUint16();p.dicttype[l]=c}t.datatypes[o]=p}else if("ARRAY"==i){var d=e.readUint16(),p=new t.DATATYPE_ARRAY;p.type=d,t.datatypes[o]=p}else t.datatypes[o]=t.datatypes[i];t.datatypes[a]=t.datatypes[o],t.datatype2id[o]=a},e.prototype.Client_onImportClientEntityDef=function(e){for(t.app.createDataTypeFromStreams(e,!0);e.length()>0;){var n=e.readString(),r=e.readUint16(),a=e.readUint16(),i=e.readUint16(),o=e.readUint16(),p=e.readUint16();t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),t.moduledefs[n]={};var s=t.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},t.moduledefs[r]=s;for(var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods,y=t.Entities[n];a>0;){a--;var _=e.readUint16(),f=e.readUint32(),E=e.readInt16(),g=e.readString(),m=e.readString(),h=t.datatypes[e.readUint16()],v=null;void 0!=y&&(v=y.prototype["set_"+g],void 0==v&&(v=null));var T=[_,E,g,m,h,v,f];l[g]=T,-1!=E?(l[E]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+g+"/"+_+").")}for(;i>0;){i--;for(var S=e.readUint16(),E=e.readInt16(),A=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);var T=[S,E,A,D];c[A]=T,-1!=E?(c[E]=T,s.useMethodDescrAlias=!0):(c[S]=T,s.useMethodDescrAlias=!1),t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+A+").")}for(;o>0;){o--;for(var S=e.readUint16(),E=e.readInt16(),M=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);d[M]=[S,E,M,D],t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+M+").")}for(;p>0;){p--;for(var S=e.readUint16(),E=e.readInt16(),F=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);u[F]=[S,E,F,D],t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+F+").")}var w=void 0;try{w=t.Entities[n]}catch(B){t.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),w=void 0}for(var C in s.propertys){var L=s.propertys[C],_=L[0],E=L[1],K=L[2],m=L[3],h=L[4];void 0!=w&&(w.prototype[K]=h.parseDefaultValStr(m))}for(var N in s.methods){var L=s.methods[N],_=L[0],E=L[1],K=L[2],D=L[3];void 0!=w&&void 0==w.prototype[K]&&t.WARNING_MSG(n+":: method("+K+") no implement!")}}t.app.onImportEntityDefCompleted()},e.prototype.Client_onVersionNotMatch=function(e){t.app.serverVersion=e.readString(),t.ERROR_MSG("Client_onVersionNotMatch: verInfo="+t.app.clientVersion+" not match(server: "+t.app.serverVersion+")"),t.Event.fire(t.EventTypes.onVersionNotMatch,t.app.clientVersion,t.app.serverVersion)},e.prototype.Client_onScriptVersionNotMatch=function(e){t.app.serverScriptVersion=e.readString(),t.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+t.app.clientScriptVersion+" not match(server: "+t.app.serverScriptVersion+")"),t.Event.fire(t.EventTypes.onScriptVersionNotMatch,t.app.clientScriptVersion,t.app.serverScriptVersion)},e.prototype.onImportEntityDefCompleted=function(){t.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),t.app.entitydefImported=!0,t.app.login_baseapp(!1)},e.prototype.importClientMessages=function(e){for(;t.app.currMsgCount>0;){t.app.currMsgCount--;for(var n=e.readUint16(),r=e.readInt16(),a=e.readString(),i=e.readInt8(),o=e.readUint8(),p=new Array(o),s=0;o>s;s++)p[s]=e.readUint8();var l=null,c=a.indexOf("Client_")>=0;c&&(l=t.app[a],null==l||void 0==l?(t.WARNING_MSG("KBEngineApp::onImportClientMessages["+t.app.currserver+"]: interface("+a+"/"+n+") no implement!"),l=null):t.INFO_MSG("KBEngineApp::onImportClientMessages: import("+a+") successfully!")),a.length>0?(t.messages[a]=new t.Message(n,a,r,i,p,l),c?t.clientmessages[n]=t.messages[a]:t.messages[t.app.currserver][n]=t.messages[a]):t.messages[t.app.currserver][n]=new t.Message(n,a,r,i,p,l)}t.app.onImportClientMessagesCompleted(),t.app.currMsgID=0,t.app.currMsgLen=0,t.app.currMsgCount=0,t.app.fragmentStream=null},e.prototype.Client_onImportClientMessages=function(e){var n=new t.MemoryStream(e.data);n.wpos=e.data.byteLength,0==t.app.currMsgID&&(t.app.currMsgID=n.readUint16()),t.app.currMsgID==t.messages.onImportClientMessages.id?(0==t.app.currMsgLen&&(t.app.currMsgLen=n.readUint16(),t.app.currMsgCount=n.readUint16()),n.length()+2=t.app.currMsgLen&&t.app.importClientMessages(t.app.fragmentStream)):t.app.importClientMessages(n)):t.ERROR_MSG("KBEngineApp::onmessage: not found msg("+t.app.currMsgID+")!")},e.prototype.createAccount=function(e,n,r){t.app.reset(),t.app.username=e,t.app.password=n,t.app.clientdatas=r,t.app.createAccount_loginapp(!0)},e.prototype.createAccount_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_createAccount;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_reqCreateAccount),n.writeString(t.app.username),n.writeString(t.app.password),n.writeBlob(t.app.clientdatas),n.send(t.app)}},e.prototype.bindAccountEmail=function(e){var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_reqAccountBindEmail),n.writeInt32(t.app.entity_id),n.writeString(t.app.password),n.writeString(e),n.send(t.app)},e.prototype.newPassword=function(e,n){var r=t.Bundle.createObject();r.newMessage(t.messages.Baseapp_reqAccountNewPassword),r.writeInt32(t.app.entity_id),r.writeString(e),r.writeString(n),r.send(t.app)},e.prototype.logout=function(){var e=new t.Bundle;e.newMessage(t.messages.Baseapp_logoutBaseapp),e.writeUint64(t.app.entity_uuid),e.writeInt32(t.app.entity_id),e.send(t.app)},e.prototype.login=function(e,n,r){t.app.reset(),t.app.username=e,t.app.password=n,t.app.clientdatas=r,t.app.login_loginapp(!0)},e.prototype.login_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_login;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_login),n.writeInt8(t.app.args.clientType),n.writeBlob(t.app.clientdatas),n.writeString(t.app.username),n.writeString(t.app.password),n.send(t.app)}},e.prototype.onOpenLoginapp_resetpassword=function(){if(t.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),t.app.currserver="loginapp",t.app.currstate="resetpassword",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},e.prototype.reset_password=function(e){t.app.reset(),t.app.username=e,t.app.resetpassword_loginapp(!0)},e.prototype.resetpassword_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_resetpassword;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_reqAccountResetPassword),n.writeString(t.app.username),n.send(t.app)}},e.prototype.onOpenBaseapp=function(){if(t.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),t.app.currserver="baseapp",t.app.baseappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.Event.fire("Baseapp_importClientMessages")}},e.prototype.login_baseapp=function(e){if(e)t.Event.fire("onLoginBaseapp"),t.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+t.app.baseappIp+":"+t.app.baseappPort+"!"),t.app.currconnect="baseapp",t.app.connect(t.app.baseappIp,t.app.baseappPort),void 0!=t.app.socket&&null!=t.app.socket&&(t.app.socket.onopen=t.app.onOpenBaseapp);else{var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_loginBaseapp),n.writeString(t.app.username),n.writeString(t.app.password),n.send(t.app)}},e.prototype.reloginBaseapp=function(){t.app.lastTickCBTime=t.app.lastTickTime=Date.now(),(void 0==t.app.socket||null==t.app.socket)&&(t.app.resetSocket(),t.Event.fire(t.EventTypes.onReloginBaseapp),t.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+t.app.baseappIp+":"+t.app.baseappPort+"!"),t.app.currconnect="baseapp",t.app.connect(t.app.baseappIp,t.app.baseappPort),void 0!=t.app.socket&&null!=t.app.socket&&(t.app.socket.onopen=t.app.onReOpenBaseapp))},e.prototype.onReOpenBaseapp=function(){t.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),t.app.currserver="baseapp";var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_reloginBaseapp),e.writeString(t.app.username),e.writeString(t.app.password),e.writeUint64(t.app.entity_uuid),e.writeInt32(t.app.entity_id),e.send(t.app);var n=new Date;t.app.lastTickCBTime=n.getTime()},e.prototype.Client_onHelloCB=function(e){t.app.serverVersion=e.readString(),t.app.serverScriptVersion=e.readString(),t.app.serverProtocolMD5=e.readString(),t.app.serverEntityDefMD5=e.readString();var n=e.readInt32();t.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+t.app.serverVersion+"), scriptVerInfo("+t.app.serverScriptVersion+"), serverProtocolMD5("+t.app.serverProtocolMD5+"), serverEntityDefMD5("+t.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;t.app.lastTickCBTime=r.getTime()},e.prototype.Client_onLoginFailed=function(e){var n=e.readUint16();t.app.serverdatas=e.readBlob(),t.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+t.app.serverErrs[n].name+"), datas("+t.app.serverdatas.length+")!"),t.Event.fire("onLoginFailed",n)},e.prototype.Client_onLoginSuccessfully=function(e){var n=e.readString();t.app.username=n,t.app.baseappIp=e.readString(),t.app.baseappPort=e.readUint16(),t.app.baseappUdpPort=e.readUint16(),t.app.serverdatas=e.readBlob(),t.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+t.app.baseappIp+":"+t.app.baseappPort+"), datas("+t.app.serverdatas.length+")!"),t.app.disconnect(),t.app.login_baseapp(!0)},e.prototype.Client_onLoginBaseappFailed=function(e){t.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onLoginBaseappFailed,e)},e.prototype.Client_onReloginBaseappFailed=function(e){t.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onReloginBaseappFailed,e)},e.prototype.Client_onReloginBaseappSuccessfully=function(e){t.app.entity_uuid=e.readUint64(),t.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+t.app.username),t.Event.fire(t.EventTypes.onReloginBaseappSuccessfully)},e.prototype.getentityclass=function(e){var n=t.Entities[e];return void 0==n?(t.ERROR_MSG("KBEngineApp::getentityclass: entityType("+e+") is error!"),n):n},e.prototype.Client_onCreatedProxies=function(e,n,r){t.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=t.app.entities[n];if(t.app.entity_uuid=e,t.app.entity_id=n,void 0==a){var i=t.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new t.EntityCall,o.base.id=n,o.base.className=r,o.base.type=t.ENTITYCALL_TYPE_BASE,t.app.entities[n]=o;var p=t.bufferedCreateEntityMessages[n];void 0!=p&&(t.app.Client_onUpdatePropertys(p),delete t.bufferedCreateEntityMessages[n]),o.__init__(),o.inited=!0,t.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=t.bufferedCreateEntityMessages[n];void 0!=p&&(t.app.Client_onUpdatePropertys(p),delete t.bufferedCreateEntityMessages[n])}},e.prototype.getViewEntityIDFromStream=function(e){var n=0;if(t.app.entityIDAliasIDList.length>255)n=e.readInt32();else{var r=e.readUint8();if(t.app.entityIDAliasIDList.length<=r)return 0;n=t.app.entityIDAliasIDList[r]}return n},e.prototype.onUpdatePropertys_=function(e,n){var r=t.app.entities[e];if(void 0==r){var a=t.bufferedCreateEntityMessages[e];if(void 0!=a)return void t.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity("+e+") not found!");var i=new t.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(t.bufferedCreateEntityMessages[e]=i)}for(var o,p=t.moduledefs[r.className],s=p.propertys;n.length()>0;){var l=0;p.usePropertyDescrAlias?(o=n.readInt8(),l=n.readUint8()):(o=n.readUint16(),l=n.readUint16());var c=s[l],d=c[5],u=c[6],y=c[4].createFromStream(n),_=r[c[2]];t.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+r.className+"(id="+e+" "+c[2]+", val="+y+")!"),r[c[2]]=y,null!=d&&(32==u||64==u?r.inited&&d.call(r,_):r.inWorld&&d.call(r,_))}},e.prototype.Client_onUpdatePropertysOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.onUpdatePropertys_(n,e)},e.prototype.Client_onUpdatePropertys=function(e){var n=e.readInt32();t.app.onUpdatePropertys_(n,e)},e.prototype.onRemoteMethodCall_=function(e,n){var r=t.app.entities[e];if(void 0==r)return void t.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+e+") not found!");var a=0,i=0;t.moduledefs[r.className].useMethodDescrAlias?(i=n.readInt8(),a=n.readUint8()):(i=n.readUint16(),a=n.readUint16());for(var o=t.moduledefs[r.className].methods[a],p=[],s=o[3],l=0;l0&&n!=t.app.entity_id&&t.app.entityIDAliasIDList.push(n);var r;r=t.moduledefs.Length>255?e.readUint16():e.readUint8();var a=!0;e.length()>0&&(a=e.readInt8()),r=t.moduledefs[r].name,t.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+t.app.spaceID+"), isOnGround("+a+")!");var i=t.app.entities[n];if(void 0==i){var o=t.bufferedCreateEntityMessages[n];if(void 0==o)return void t.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=t.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new t.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=t.ENTITYCALL_TYPE_CELL,t.app.entities[n]=s,t.app.Client_onUpdatePropertys(o),delete t.bufferedCreateEntityMessages[n],s.isOnGround=a,s.__init__(),s.inited=!0,s.inWorld=!0,s.enterWorld(),t.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new t.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=t.ENTITYCALL_TYPE_CELL,t.app.entityIDAliasIDList=[],t.app.entities={},t.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),t.app.entityServerPos.x=i.position.x,t.app.entityServerPos.y=i.position.y,t.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),t.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},e.prototype.Client_onEntityLeaveWorldOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.Client_onEntityLeaveWorld(n) -},e.prototype.Client_onEntityLeaveWorld=function(e){var n=t.app.entities[e];if(void 0==n)return void t.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+e+") not found!");if(n.inWorld&&n.leaveWorld(),t.app.entity_id>0&&e!=t.app.entity_id){for(var r=[],a=0;a0&&(r=e.readInt8());var a=t.app.entities[n];return void 0==a?void t.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,t.app.entityServerPos.x=a.position.x,t.app.entityServerPos.y=a.position.y,t.app.entityServerPos.z=a.position.z,void a.enterSpace())},e.prototype.Client_onEntityLeaveSpace=function(e){var n=t.app.entities[e];return void 0==n?void t.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+e+") not found!"):(t.app.clearSpace(!1),void n.leaveSpace())},e.prototype.Client_onKicked=function(e){t.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onKicked,e)},e.prototype.Client_onCreateAccountResult=function(e){var n=e.readUint16(),r=e.readBlob();return t.Event.fire("onCreateAccountResult",n,r),0!=n?void t.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+t.app.username+" create is failed! code="+t.app.serverErrs[n].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+t.app.username+" create is successfully!")},e.prototype.Client_onControlEntity=function(e,n){var r=t.app.entities[e];if(void 0==r)return void t.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+e+") not found!");var a=0!=n;if(a)t.app.player().id!=r.id&&t.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||e.entityLastLocalDir.distance(e.direction)>.001){e.entityLastLocalPos.x=e.position.x,e.entityLastLocalPos.y=e.position.y,e.entityLastLocalPos.z=e.position.z,e.entityLastLocalDir.x=e.direction.x,e.entityLastLocalDir.y=e.direction.y,e.entityLastLocalDir.z=e.direction.z;var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(e.position.x),n.writeFloat(e.position.y),n.writeFloat(e.position.z),n.writeFloat(e.direction.x),n.writeFloat(e.direction.y),n.writeFloat(e.direction.z),n.writeUint8(e.isOnGround),n.writeUint32(t.app.spaceID),n.send(t.app)}for(var r in t.app.controlledEntities){var a=t.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(t.app.spaceID),n.send(t.app)}}}},e.prototype.addSpaceGeometryMapping=function(e,n){t.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+e+"), respath("+n+")!"),t.app.spaceID=e,t.app.spaceResPath=n,t.Event.fire(t.EventTypes.addSpaceGeometryMapping,n)},e.prototype.clearSpace=function(e){t.app.entityIDAliasIDList=[],t.app.spacedata={},t.app.clearEntities(e),t.app.isLoadedGeometry=!1,t.app.spaceID=0},e.prototype.clearEntities=function(e){if(t.app.controlledEntities=[],e){for(var n in t.app.entities)t.app.entities[n].inWorld&&t.app.entities[n].leaveWorld(),t.app.entities[n].onDestroy();t.app.entities={}}else{var r=t.app.player();for(var n in t.app.entities)n!=r.id&&(t.app.entities[n].inWorld&&t.app.entities[n].leaveWorld(),t.app.entities[n].onDestroy());t.app.entities={},t.app.entities[r.id]=r}},e.prototype.Client_initSpaceData=function(e){for(t.app.clearSpace(!1),t.app.spaceID=e.readInt32();e.length()>0;){var n=e.readString(),r=e.readString();t.app.Client_setSpaceData(t.app.spaceID,n,r)}t.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+t.app.spaceID+"), datas("+t.app.spacedata+")!")},e.prototype.Client_setSpaceData=function(e,n,r){t.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+e+"), key("+n+"), value("+r+")!"),t.app.spacedata[n]=r,"_mapping"==n&&t.app.addSpaceGeometryMapping(e,r),t.Event.fire("onSetSpaceData",e,n,r)},e.prototype.Client_delSpaceData=function(e,n){t.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+e+"), key("+n+")!"),delete t.app.spacedata[n],t.Event.fire("onDelSpaceData",e,n)},e.prototype.Client_getSpaceData=function(e,n){return t.app.spacedata[n]},e.prototype.Client_onUpdateBasePos=function(e,n,r){t.app.entityServerPos.x=e,t.app.entityServerPos.y=n,t.app.entityServerPos.z=r},e.prototype.Client_onUpdateBasePosXZ=function(e,n){t.app.entityServerPos.x=e,t.app.entityServerPos.z=n},e.prototype.Client_onUpdateData=function(e){var n=t.app.getViewEntityIDFromStream(e),r=t.app.entities[n];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},e.prototype.Client_onSetEntityPosAndDir=function(e){var n=e.readInt32(),r=t.app.entities[n];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=e.readFloat(),r.position.y=e.readFloat(),r.position.z=e.readFloat(),r.direction.x=e.readFloat(),r.direction.y=e.readFloat(),r.direction.z=e.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},e.prototype.Client_onUpdateData_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,i,-1)},e.prototype.Client_onUpdateData_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,a,-1)},e.prototype.Client_onUpdateData_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,-1)},e.prototype.Client_onUpdateData_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,-1)},e.prototype.Client_onUpdateData_xz=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,o,p,1)},e.prototype.Client_onUpdateData_xz_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,o,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,t.KBE_FLT_MAX,o,1)},e.prototype.Client_onUpdateData_xz_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,i,o,1)},e.prototype.Client_onUpdateData_xz_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readInt8();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,i,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readInt8();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,i,1)},e.prototype.Client_onUpdateData_xyz=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,r,a,i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat(),s=e.readFloat();t.app._updateVolatileData(n,r,a,i,o,p,s,0)},e.prototype.Client_onUpdateData_xyz_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,p,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,p,0)},e.prototype.Client_onUpdateData_xyz_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,t.KBE_FLT_MAX,o,p,0)},e.prototype.Client_onUpdateData_xyz_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,t.KBE_FLT_MAX,o,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,i,-1,!0)},e.prototype.Client_onUpdateData_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,a,-1,!0)},e.prototype.Client_onUpdateData_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,-1,!0)},e.prototype.Client_onUpdateData_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,-1,!0)},e.prototype.Client_onUpdateData_xz_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,i,o,1,!0)},e.prototype.Client_onUpdateData_xz_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,i,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,t.KBE_FLT_MAX,i,1,!0)},e.prototype.Client_onUpdateData_xz_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,a,i,1,!0)},e.prototype.Client_onUpdateData_xz_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,a,1,!0)},e.prototype.Client_onUpdateData_xyz_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8(),p=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0,!0)},e.prototype.Client_onUpdateData_xyz_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,o,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,o,0,!0)},e.prototype.Client_onUpdateData_xyz_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,i,o,0,!0)},e.prototype.Client_onUpdateData_xyz_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,i,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype._updateVolatileData=function(e,n,r,a,i,o,p,s,l){void 0===l&&(l=!1);var c=t.app.entities[e];if(void 0==c)return void t.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+e+") not found!");s>=0&&(c.isOnGround=s>0);var d=!1;p!=t.KBE_FLT_MAX&&(d=!0,c.direction.x=t.int82angle(p,!1)),o!=t.KBE_FLT_MAX&&(d=!0,c.direction.y=t.int82angle(o,!1)),i!=t.KBE_FLT_MAX&&(d=!0,c.direction.z=t.int82angle(i,!1));var u=!1;1==d&&(t.Event.fire("set_direction",c),u=!0);var y=!1;(n!=t.KBE_FLT_MAX||r!=t.KBE_FLT_MAX||a!=t.KBE_FLT_MAX)&&(y=!0),n==t.KBE_FLT_MAX&&(n=0),r==t.KBE_FLT_MAX&&(r=0),a==t.KBE_FLT_MAX&&(a=0),y&&(l?(c.position.x=n+t.app.entityServerPos.x,c.position.y=r+t.app.entityServerPos.y,c.position.z=a+t.app.entityServerPos.z):(c.position.x=n,c.position.y=r,c.position.z=a),u=!0,t.Event.fire("updatePosition",c)),u&&c.onUpdateVolatileData()},e.prototype.Client_onStreamDataStarted=function(e,n,r){t.Event.fire(t.EventTypes.onStreamDataStarted,e,n,r)},e.prototype.Client_onStreamDataRecv=function(e){var n=e.readUint16(),r=e.readBlob();t.Event.fire(t.EventTypes.onStreamDataRecv,n,r)},e.prototype.Client_onStreamDataCompleted=function(e){t.Event.fire(t.EventTypes.onStreamDataCompleted,e)},e.prototype.Client_onReqAccountResetPasswordCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+t.app.username+" is successfully!")},e.prototype.Client_onReqAccountBindEmailCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+t.app.username+" is successfully!")},e.prototype.Client_onReqAccountNewPasswordCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+t.app.username+" is successfully!")},e}();t.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function t(){this.name="",this.descr="",this.id=0}return t}();t.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr"),t.FragmentDataTypes={FRAGMENT_DATA_UNKNOW:0,FRAGMENT_DATA_MESSAGE_ID:1,FRAGMENT_DATA_MESSAGE_LENGTH:2,FRAGMENT_DATA_MESSAGE_LENGTH1:3,FRAGMENT_DATA_MESSAGE_BODY:4};var i;t.create=e,t.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/bin/kbengine.d.ts b/kbengine_ts/kbengine/kbengine.d.ts similarity index 92% rename from kbengine_ts/bin/kbengine.d.ts rename to kbengine_ts/kbengine/kbengine.d.ts index 9a8b0b6..880ed7e 100644 --- a/kbengine_ts/bin/kbengine.d.ts +++ b/kbengine_ts/kbengine/kbengine.d.ts @@ -4,22 +4,24 @@ * * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,按下面方法声明实体 - - @KBEngine.registerEntity('Account') /// <---这个Account对应服务器上实体 - export default class AccountEntity extends KBEngine.Entity { + * 2、 @KBEngine.registerEntity() /// TODO: <---组件使用@KBEngine.registerComponent() + export default class Account extends KBEngine.Entity { /// TODO: 组件继承自KBEngine.EntityComponent,类名等于服务器(实体/组件)名 + __comps__ = {组件名:组件类型} ///TODO: 因为组件类型不会从服务器同步,只能获取到EntityComponent,无法获取具体类型,所以需要在实体里进行手动设置,需要代码提示可以手动声明一下 __init__() { console.log('创建account') } } //这里加入声明用于vscode代码提示 declare global { - namespace KBEngine.Entities { - class Account extends AccountEntity { } /// <---这个Account对应服务器上实体 + namespace KBEngine { + interface IEntities{ + Account:new ()=>Account + } } } * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 + 4、因为下班了,组件的basecall和cellcall还未测试,改天再继续 */ declare namespace KBEngine { const CLIENT_VERSION = "2.5.0"; @@ -49,6 +51,9 @@ declare namespace KBEngine { toString(): string; } } +declare namespace KBEngine { + function getQualifiedClassName(value: any): any; +} declare namespace KBEngine { /** todo 调试输出模块,这里需要根据使用的引擎不同在这里加入判断条件 */ function INFO_MSG(...args: any[]): void; @@ -254,10 +259,14 @@ declare namespace KBEngine { function angle2int8(v: number, half: boolean): number; } declare namespace KBEngine { - module Entities { + interface IEntities { } + const Entities: IEntities; class Entity { constructor(); + protected __comps__: { + [compName: string]: new () => EntityComponent; + }; id: number; className: string; position: Vector3; @@ -272,6 +281,9 @@ declare namespace KBEngine { entityLastLocalDir: Vector3; isOnGround: boolean; __init__(): void; + attachComponents(): void; + getComponents(compName: string, all?: boolean): any; + detachComponents(): void; callPropertysSetMethods(): void; onDestroy(): void; onControlled(bIsControlled: any): void; @@ -279,6 +291,8 @@ declare namespace KBEngine { baseCall(type: string, ...params: any[]): void; cellCall(type: string, ...params: any[]): void; enterWorld(): void; + onComponentsEnterworld(): void; + onComponentsLeaveworld(): void; onEnterWorld(): void; leaveWorld(): void; onLeaveWorld(): void; @@ -288,15 +302,33 @@ declare namespace KBEngine { onLeaveSpace(): void; set_position(): void; onUpdateVolatileData(): void; + onUpdatePropertys(stream: MemoryStream): void; set_direction(old: any): void; } - function registerEntity(name: string): (ctor: new () => Entity) => void; + function registerEntity(): (ctor: new () => Entity) => void; +} +declare namespace KBEngine { + class EntityComponent { + id: number; + entityComponentPropertyID: number; + componentType: number; + ownerID: number; + owner: Entity; + name_: string; + base: EntityComponentCall; + cell: EntityComponentCall; + protected onAttached(owner: Entity): void; + protected onDetached(owner: Entity): void; + protected onEnterWorld(): void; + protected onLeaveWorld(): void; + onUpdatePropertys(propUtype: number, stream: MemoryStream, maxCount: number): void; + createFromStream(stream: MemoryStream): void; + } + function registerComponent(): (ctor: new () => EntityComponent) => void; } declare namespace KBEngine { const ENTITYCALL_TYPE_CELL = 0; const ENTITYCALL_TYPE_BASE = 1; - class EntityComponent { - } class EntityCall { constructor(); id: number; @@ -309,6 +341,9 @@ declare namespace KBEngine { newCall(): any; sendCall(bundle: any): void; } + class EntityComponentCall extends EntityCall { + constructor(ecpId: number, eid: number); + } class DATATYPE_UINT8 { bind(): void; createFromStream(stream: any): any; @@ -418,13 +453,6 @@ declare namespace KBEngine { parseDefaultValStr(v: any): string; isSameType(v: any): boolean; } - class DATATYPE_ENTITY_COMPONENT { - bind(): void; - createFromStream(stream: any): void; - addToStream(stream: any, v: any): void; - parseDefaultValStr(v: any): Uint8Array; - isSameType(v: any): boolean; - } class DATATYPE_ENTITYCALL { bind(): void; createFromStream(stream: any): void; @@ -474,7 +502,6 @@ declare namespace KBEngine { const PYTHON: DATATYPE_PYTHON; const UNICODE: DATATYPE_UNICODE; const ENTITYCALL: DATATYPE_ENTITYCALL; - const ENTITY_COMPONENT: DATATYPE_ENTITY_COMPONENT; const BLOB: DATATYPE_BLOB; } } diff --git a/kbengine_ts/bin/kbengine.js b/kbengine_ts/kbengine/kbengine.js similarity index 95% rename from kbengine_ts/bin/kbengine.js rename to kbengine_ts/kbengine/kbengine.js index 3e36d75..33d4345 100644 --- a/kbengine_ts/bin/kbengine.js +++ b/kbengine_ts/kbengine/kbengine.js @@ -14,22 +14,24 @@ r.prototype = e.prototype, t.prototype = new r(); * * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,按下面方法声明实体 - - @KBEngine.registerEntity('Account') /// <---这个Account对应服务器上实体 - export default class AccountEntity extends KBEngine.Entity { + * 2、 @KBEngine.registerEntity() /// TODO: <---组件使用@KBEngine.registerComponent() + export default class Account extends KBEngine.Entity { /// TODO: 组件继承自KBEngine.EntityComponent,类名等于服务器(实体/组件)名 + __comps__ = {组件名:组件类型} ///TODO: 因为组件类型不会从服务器同步,只能获取到EntityComponent,无法获取具体类型,所以需要在实体里进行手动设置,需要代码提示可以手动声明一下 __init__() { console.log('创建account') } } //这里加入声明用于vscode代码提示 declare global { - namespace KBEngine.Entities { - class Account extends AccountEntity { } /// <---这个Account对应服务器上实体 + namespace KBEngine { + interface IEntities{ + Account:new ()=>Account + } } } * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 + 4、因为下班了,组件的basecall和cellcall还未测试,改天再继续 */ /*----------------------------------------------------------------------------------------- global @@ -133,6 +135,29 @@ if (!ArrayBuffer['transfer']) { KBEngine.UINT64 = UINT64; __reflect(UINT64.prototype, "KBEngine.UINT64"); })(KBEngine || (KBEngine = {})); +(function (KBEngine) { + function getQualifiedClassName(value) { + var type = typeof value; + if (!value || (type != "object" && !value.prototype)) { + return type; + } + var prototype = value.prototype ? value.prototype : Object.getPrototypeOf(value); + if (prototype.hasOwnProperty("__class__")) { + return prototype["__class__"]; + } + var constructorString = prototype.constructor.toString().trim(); + var index = constructorString.indexOf("("); + var className = constructorString.substring(9, index); + var c = className.split('.'); + Object.defineProperty(prototype, "__class__", { + value: c[c.length - 1], + enumerable: false, + writable: true + }); + return c[c.length - 1]; + } + KBEngine.getQualifiedClassName = getQualifiedClassName; +})(KBEngine || (KBEngine = {})); /*----------------------------------------------------------------------------------------- debug -----------------------------------------------------------------------------------------*/ @@ -1168,8 +1193,10 @@ if (!ArrayBuffer['transfer']) { entity -----------------------------------------------------------------------------------------*/ (function (KBEngine) { + KBEngine.Entities = {}; var Entity = (function () { function Entity() { + this.__comps__ = {}; this.id = 0; this.className = ""; this.position = new KBEngine.Vector3(0, 0, 0); @@ -1187,9 +1214,35 @@ if (!ArrayBuffer['transfer']) { this.entityLastLocalDir = new KBEngine.Vector3(0.0, 0.0, 0.0); // 玩家是否在地面上 this.isOnGround = false; + for (var i in this.__comps__) { + this[i] = new this.__comps__[i](); + } } Entity.prototype.__init__ = function () { }; + Entity.prototype.attachComponents = function () { + for (var i in this.__comps__) { + this[i].onAttached(this); + } + }; + Entity.prototype.getComponents = function (compName, all) { + if (all === void 0) { all = false; } + var res = []; + for (var i in this.__comps__) { + if (KBEngine.getQualifiedClassName(this.__comps__[i]) === compName) { + if (!all) { + return this[i]; + } + res.push(this[i]); + } + } + return res; + }; + Entity.prototype.detachComponents = function () { + for (var i in this.__comps__) { + this[i].onDetached(this); + } + }; Entity.prototype.callPropertysSetMethods = function () { var currModule = KBEngine.moduledefs[this.className]; for (var name_1 in currModule.propertys) { @@ -1220,6 +1273,7 @@ if (!ArrayBuffer['transfer']) { ; }; Entity.prototype.onDestroy = function () { + this.detachComponents(); }; Entity.prototype.onControlled = function (bIsControlled) { }; @@ -1320,14 +1374,26 @@ if (!ArrayBuffer['transfer']) { KBEngine.INFO_MSG(this.className + '::enterWorld: ' + this.id); this.inWorld = true; this.onEnterWorld(); + this.onComponentsEnterworld(); KBEngine.Event.fire("onEnterWorld", this); }; + Entity.prototype.onComponentsEnterworld = function () { + for (var i in this.__comps__) { + this[i].onEnterWorld(); + } + }; + Entity.prototype.onComponentsLeaveworld = function () { + for (var i in this.__comps__) { + this[i].onLeaveWorld(); + } + }; Entity.prototype.onEnterWorld = function () { }; Entity.prototype.leaveWorld = function () { KBEngine.INFO_MSG(this.className + '::leaveWorld: ' + this.id); this.inWorld = false; this.onLeaveWorld(); + this.onComponentsLeaveworld(); KBEngine.Event.fire("onLeaveWorld", this); }; Entity.prototype.onLeaveWorld = function () { @@ -1360,6 +1426,51 @@ if (!ArrayBuffer['transfer']) { }; Entity.prototype.onUpdateVolatileData = function () { }; + Entity.prototype.onUpdatePropertys = function (stream) { + var currModule = KBEngine.moduledefs[KBEngine.getQualifiedClassName(this)]; + var pdatas = currModule.propertys; + while (stream.length() > 0) { + var utype = 0, cId = 0; + if (currModule.usePropertyDescrAlias) { + cId = stream.readUint8(); + utype = stream.readUint8(); + } + else { + cId = stream.readUint16(); + utype = stream.readUint16(); + } + if (cId !== 0) { + var comp = pdatas[cId]; + if (this[comp[2]]) { + this[comp[2]].onUpdatePropertys(utype, stream, -1); + } + continue; + } + var propertydata = pdatas[utype]; + var setmethod = propertydata[5]; + var flags = propertydata[6]; + if (!propertydata[4]) { + if (this[propertydata[2]] && typeof this[propertydata[2]].createFromStream === 'function') + this[propertydata[2]].createFromStream(stream); + continue; + } + var val = propertydata[4].createFromStream(stream); + var oldval = this[propertydata[2]]; + KBEngine.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: " + this.className + "(id=" + this.id + " " + propertydata[2] + ", val=" + val + ")!"); + this[propertydata[2]] = val; + if (setmethod != null) { + // base类属性或者进入世界后cell类属性会触发set_*方法 + if (flags == 0x00000020 || flags == 0x00000040) { + if (this.inited) + setmethod.call(this, oldval); + } + else { + if (this.inWorld) + setmethod.call(this, oldval); + } + } + } + }; Entity.prototype.set_direction = function (old) { KBEngine.DEBUG_MSG(this.className + "::set_direction: " + this.direction); KBEngine.Event.fire("set_direction", this); @@ -1368,28 +1479,101 @@ if (!ArrayBuffer['transfer']) { }()); KBEngine.Entity = Entity; __reflect(Entity.prototype, "KBEngine.Entity"); - function registerEntity(name) { + function registerEntity() { return function (ctor) { - KBEngine['Entities'] = KBEngine['Entities'] || {}; + var name = KBEngine.getQualifiedClassName(ctor); + // KBEngine['Entities'] = KBEngine['Entities'] || {} KBEngine['Entities'][name] = ctor; }; } KBEngine.registerEntity = registerEntity; })(KBEngine || (KBEngine = {})); -/*----------------------------------------------------------------------------------------- - EntityCall ------------------------------------------------------------------------------------------*/ (function (KBEngine) { - KBEngine.ENTITYCALL_TYPE_CELL = 0; - KBEngine.ENTITYCALL_TYPE_BASE = 1; - //这个东西好像没有同步给客户端 var EntityComponent = (function () { function EntityComponent() { + this.id = 0; + this.entityComponentPropertyID = 0; + this.componentType = 0; + this.ownerID = 0; + this.owner = null; + this.name_ = ''; + this.base = null; + this.cell = null; } + EntityComponent.prototype.onAttached = function (owner) { }; + EntityComponent.prototype.onDetached = function (owner) { }; + EntityComponent.prototype.onEnterWorld = function () { }; + EntityComponent.prototype.onLeaveWorld = function () { }; + EntityComponent.prototype.onUpdatePropertys = function (propUtype, stream, maxCount) { + var className = KBEngine.getQualifiedClassName(this); + var currModule = KBEngine.moduledefs[className]; + var pdatas = currModule.propertys; + while (stream.length() > 0 && maxCount-- != 0) { + var utype = propUtype, cId = 0; + if (utype === 0) { + if (currModule.usePropertyDescrAlias) { + cId = stream.readUint8(); + utype = stream.readUint8(); + } + else { + cId = stream.readUint16(); + utype = stream.readUint16(); + } + } + var propertydata = pdatas[utype]; + var setmethod = propertydata[5]; + var flags = propertydata[6]; + var val = propertydata[4].createFromStream(stream); + var oldval = this[propertydata[2]]; + KBEngine.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: " + className + "(id=" + this.id + " " + propertydata[2] + ", val=" + val + ")!"); + this[propertydata[2]] = val; + if (setmethod != null) { + // base类属性或者进入世界后cell类属性会触发set_*方法 + if (flags == 0x00000020 || flags == 0x00000040) { + if (this.owner.inited) + setmethod.call(this, oldval); + } + else { + if (this.owner.inWorld) + setmethod.call(this, oldval); + } + } + } + }; + EntityComponent.prototype.createFromStream = function (stream) { + this.componentType = stream.readInt32(); + this.ownerID = stream.readInt32(); + this.owner = KBEngine.app.entities[this.ownerID]; + //UInt16 ComponentDescrsType; + stream.readUint16(); + var count = stream.readUint16(); + if (count > 0) { + this.onUpdatePropertys(0, stream, count); + } + this.base = new KBEngine.EntityComponentCall(this.entityComponentPropertyID, this.ownerID); + this.base.type = KBEngine.ENTITYCALL_TYPE_BASE; + this.cell = new KBEngine.EntityComponentCall(this.entityComponentPropertyID, this.ownerID); + this.cell.type = KBEngine.ENTITYCALL_TYPE_CELL; + }; return EntityComponent; }()); KBEngine.EntityComponent = EntityComponent; __reflect(EntityComponent.prototype, "KBEngine.EntityComponent"); + function registerComponent() { + return function (ctor) { + var name = KBEngine.getQualifiedClassName(ctor); + // KBEngine['Entities'] = KBEngine['Entities'] || {} + KBEngine['Entities'][name] = ctor; + }; + } + KBEngine.registerComponent = registerComponent; +})(KBEngine || (KBEngine = {})); +/*----------------------------------------------------------------------------------------- + EntityCall +-----------------------------------------------------------------------------------------*/ +(function (KBEngine) { + KBEngine.ENTITYCALL_TYPE_CELL = 0; + KBEngine.ENTITYCALL_TYPE_BASE = 1; var EntityCall = (function () { function EntityCall() { this.id = 0; @@ -1425,6 +1609,18 @@ if (!ArrayBuffer['transfer']) { }()); KBEngine.EntityCall = EntityCall; __reflect(EntityCall.prototype, "KBEngine.EntityCall"); + var EntityComponentCall = (function (_super) { + __extends(EntityComponentCall, _super); + function EntityComponentCall(ecpId, eid) { + var _this = _super.call(this) || this; + _this.id = eid; + _this.className = KBEngine.getQualifiedClassName(_this); + return _this; + } + return EntityComponentCall; + }(EntityCall)); + KBEngine.EntityComponentCall = EntityComponentCall; + __reflect(EntityComponentCall.prototype, "KBEngine.EntityComponentCall"); var DATATYPE_UINT8 = (function () { function DATATYPE_UINT8() { } @@ -1851,26 +2047,6 @@ if (!ArrayBuffer['transfer']) { }()); KBEngine.DATATYPE_UNICODE = DATATYPE_UNICODE; __reflect(DATATYPE_UNICODE.prototype, "KBEngine.DATATYPE_UNICODE"); - var DATATYPE_ENTITY_COMPONENT = (function () { - function DATATYPE_ENTITY_COMPONENT() { - } - DATATYPE_ENTITY_COMPONENT.prototype.bind = function () { - }; - DATATYPE_ENTITY_COMPONENT.prototype.createFromStream = function (stream) { - }; - DATATYPE_ENTITY_COMPONENT.prototype.addToStream = function (stream, v) { - }; - DATATYPE_ENTITY_COMPONENT.prototype.parseDefaultValStr = function (v) { - return new Uint8Array(0); - ; - }; - DATATYPE_ENTITY_COMPONENT.prototype.isSameType = function (v) { - return false; - }; - return DATATYPE_ENTITY_COMPONENT; - }()); - KBEngine.DATATYPE_ENTITY_COMPONENT = DATATYPE_ENTITY_COMPONENT; - __reflect(DATATYPE_ENTITY_COMPONENT.prototype, "KBEngine.DATATYPE_ENTITY_COMPONENT"); var DATATYPE_ENTITYCALL = (function () { function DATATYPE_ENTITYCALL() { } @@ -2014,7 +2190,6 @@ if (!ArrayBuffer['transfer']) { // export const PY_LIST = new DATATYPE_PYTHON(); datatypes.UNICODE = new DATATYPE_UNICODE(); datatypes.ENTITYCALL = new DATATYPE_ENTITYCALL(); - datatypes.ENTITY_COMPONENT = new DATATYPE_ENTITY_COMPONENT(); datatypes.BLOB = new DATATYPE_BLOB(); })(datatypes = KBEngine.datatypes || (KBEngine.datatypes = {})); ; @@ -2785,7 +2960,7 @@ if (!ArrayBuffer['transfer']) { var n = infos[2]; var defaultValStr = infos[3]; var utype = infos[4]; - if (defmethod != undefined) + if (defmethod != undefined && utype) defmethod.prototype[n] = utype.parseDefaultValStr(defaultValStr); } ; @@ -3122,6 +3297,7 @@ if (!ArrayBuffer['transfer']) { delete KBEngine.bufferedCreateEntityMessages[eid]; } entity_1.__init__(); + entity_1.attachComponents(); entity_1.inited = true; if (KBEngine.app.args.isOnInitCallPropertysSetMethods) entity_1.callPropertysSetMethods(); @@ -3155,7 +3331,7 @@ if (!ArrayBuffer['transfer']) { if (entity == undefined) { var entityMessage = KBEngine.bufferedCreateEntityMessages[eid]; if (entityMessage != undefined) { - KBEngine.ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity(" + eid + ") not found!"); + KBEngine.ERROR_MSG("KBEngineApp::Client_onUpdEntityComponentatePropertys: entity(" + eid + ") not found!"); return; } var stream1 = new KBEngine.MemoryStream(stream.buffer); @@ -3164,38 +3340,7 @@ if (!ArrayBuffer['transfer']) { KBEngine.bufferedCreateEntityMessages[eid] = stream1; return; } - var currModule = KBEngine.moduledefs[entity.className]; - var pdatas = currModule.propertys; - var componentUID; - while (stream.length() > 0) { - var utype = 0; - if (currModule.usePropertyDescrAlias) { - componentUID = stream.readInt8(); - utype = stream.readUint8(); - } - else { - componentUID = stream.readUint16(); - utype = stream.readUint16(); - } - var propertydata = pdatas[utype]; - var setmethod = propertydata[5]; - var flags = propertydata[6]; - var val = propertydata[4].createFromStream(stream); - var oldval = entity[propertydata[2]]; - KBEngine.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: " + entity.className + "(id=" + eid + " " + propertydata[2] + ", val=" + val + ")!"); - entity[propertydata[2]] = val; - if (setmethod != null) { - // base类属性或者进入世界后cell类属性会触发set_*方法 - if (flags == 0x00000020 || flags == 0x00000040) { - if (entity.inited) - setmethod.call(entity, oldval); - } - else { - if (entity.inWorld) - setmethod.call(entity, oldval); - } - } - } + entity.onUpdatePropertys(stream); }; KBEngineApp.prototype.Client_onUpdatePropertysOptimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); @@ -3278,6 +3423,7 @@ if (!ArrayBuffer['transfer']) { // entity.isOnGround = isOnGround > 0; entity_2.isOnGround = isOnGround; entity_2.__init__(); + entity_2.attachComponents(); entity_2.inited = true; entity_2.inWorld = true; entity_2.enterWorld(); diff --git a/kbengine_ts/kbengine/kbengine.min.js b/kbengine_ts/kbengine/kbengine.min.js new file mode 100644 index 0000000..c82cf04 --- /dev/null +++ b/kbengine_ts/kbengine/kbengine.min.js @@ -0,0 +1,3 @@ +var __reflect=this&&this.__reflect||function(t,e,n){t.__class__=e,n?n.push(e):n=[e],t.__types__=t.__types__?n.concat(t.__types__):n},__extends=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);n.prototype=e.prototype,t.prototype=new n},KBEngine;!function(t){t.CLIENT_VERSION="2.5.0",t.CLIENT_SCRIPT_VERSION="0.1.0",t.PACKET_MAX_SIZE=1500,t.PACKET_MAX_SIZE_TCP=1460,t.PACKET_MAX_SIZE_UDP=1472,t.MESSAGE_ID_LENGTH=2,t.MESSAGE_LENGTH_LENGTH=2,t.MESSAGE_LENGTH1_LENGTH=4,t.MESSAGE_MAX_SIZE=65535,t.CLIENT_NO_FLOAT=0,t.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,ArrayBuffer.transfer||(ArrayBuffer.transfer=function(t,e){var n=new ArrayBuffer(e);if(!(t instanceof ArrayBuffer&&n instanceof ArrayBuffer))throw new TypeError("ArrayBuffer.transfer, error: Source and destination must be ArrayBuffer instances");if(!(n.byteLength>=t.byteLength))throw new RangeError("ArrayBuffer.transfer, error: destination has not enough space");var r=new Uint8Array(n);return r.set(new Uint8Array(t),0),n}),function(t){var e=function(){function t(t,e){this.sign=1,this.lo=t,this.hi=e,e>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return t.prototype.toString=function(){var t="";this.sign<0&&(t+="-");var e=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){t+=n;for(var r=8-e.length;r>0;--r)t+="0"}return t+=e},t}();t.INT64=e,__reflect(e.prototype,"KBEngine.INT64");var n=function(){function t(t,e){this.lo=t,this.hi=e}return t.prototype.toString=function(){var t=this.lo.toString(16),e=this.hi.toString(16),n="";if(this.hi>0){n+=e;for(var r=8-t.length;r>0;--r)n+="0"}return n+=t},t}();t.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(t){function e(t){var e=typeof t;if(!t||"object"!=e&&!t.prototype)return e;var n=t.prototype?t.prototype:Object.getPrototypeOf(t);if(n.hasOwnProperty("__class__"))return n.__class__;var r=n.constructor.toString().trim(),a=r.indexOf("("),i=r.substring(9,a),o=i.split(".");return Object.defineProperty(n,"__class__",{value:o[o.length-1],enumerable:!1,writable:!0}),o[o.length-1]}t.getQualifiedClassName=e}(KBEngine||(KBEngine={})),function(t){function e(){for(var t=[],e=0;en;)switch(a=t[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:e+=String.fromCharCode(a);break;case 12:case 13:i=t[n++],e+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=t[n++],o=t[n++],e+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return e}function n(t){for(var e=[],n=0;nr?e.push(r):2048>r?e.push(192|r>>6,128|63&r):55296>r||r>=57344?e.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&t.charCodeAt(n)),e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return e}t.utf8ArrayToString=e,t.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(t){var e=function(){function t(t,e){this.classinst=t,this.callbackfn=e}return t}();t.EventInfo=e,__reflect(e.prototype,"KBEngine.EventInfo");var n=function(){function t(t,e,n){this.evtName=t,this.evtInfo=e,this.ars=n}return t}();t.FiredEvent=n,__reflect(n.prototype,"KBEngine.FiredEvent");var r=function(){function r(){this._events={},this._isPause=!1,this._firedEvents=[]}return r.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void t.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new e(r,i);o.push(p)},r.prototype.deregisterAll=function(t){for(var e in this._events)this.deregister(e,t)},r.prototype.deregister=function(t,e){var n=this._events[t];if(n)for(var r=n.length-1;r>=0;r--){var a=n[r];a.classinst==e&&n.splice(r,1)}},r.prototype.removeAllFiredEvent=function(t){this.removeFiredEvent("",t)},r.prototype.removeFiredEvent=function(t,e){for(var n=this._firedEvents,r=n.length-1;r>=0;r--){var a=n[r];""!=t&&a.evtName!=t||a.evtInfo.classinst!=e||n.splice(r,1)}},r.prototype.fire=function(e){for(var r=[],a=1;a0;){var e=t.shift(),n=e.evtInfo,r=e.ars;r.length<1?n.callbackfn.apply(n.classinst):n.callbackfn.apply(n.classinst,r)}},r.prototype.clear=function(){this._events={},this._firedEvents.splice(0,this._firedEvents.length)},r}();t.Events=r,__reflect(r.prototype,"KBEngine.Events"),t.Event=new r}(KBEngine||(KBEngine={})),function(t){var e=function(){function t(){this._unionData=new ArrayBuffer(4),this.fv=new Float32Array(this._unionData,0,1),this.uv=new Uint32Array(this._unionData,0,1),this.iv=new Int32Array(this._unionData,0,1)}return t}();t.PackFloatXType=e,__reflect(e.prototype,"KBEngine.PackFloatXType"),t._xPackData=new e,t._yPackData=new e,t._zPackData=new e;var n=function(){function e(t){this.rpos=0,this.wpos=0,t instanceof ArrayBuffer?this.buffer=t:this.buffer=new ArrayBuffer(t),this.rpos=0,this.wpos=0}return e.prototype.readInt8=function(){var t=new Int8Array(this.buffer,this.rpos,1);return this.rpos+=1,t[0]},e.prototype.readInt16=function(){var t=this.readUint16();return t>=32768&&(t-=65536),t},e.prototype.readInt32=function(){var t=this.readUint32();return t>=2147483648&&(t-=4294967296),t},e.prototype.readInt64=function(){var e=this.readUint32(),n=this.readUint32();return new t.INT64(e,n)},e.prototype.readUint8=function(){var t=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,t[0]},e.prototype.readUint16=function(){var t=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&t[1])<<8)+(255&t[0])},e.prototype.readUint32=function(){var t=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(t[3]<<24)+(t[2]<<16)+(t[1]<<8)+t[0]},e.prototype.readUint64=function(){var e=this.readUint32(),n=this.readUint32();return new t.UINT64(e,n)},e.prototype.readFloat=function(){var t;try{t=new Float32Array(this.buffer,this.rpos,1)}catch(e){t=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,t[0]},e.prototype.readDouble=function(){var t;try{t=new Float64Array(this.buffer,this.rpos,1)}catch(e){t=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,t[0]},e.prototype.readString=function(){for(var t=new Uint8Array(this.buffer,this.rpos),e=0,n="";;){if(0==t[e]){e++;break}if(n+=String.fromCharCode(t[e]),e++,this.rpos+e>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+e)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=e,n},e.prototype.readBlob=function(){var t=this.readUint32(),e=new Uint8Array(this.buffer,this.rpos,t);return this.rpos+=t,e},e.prototype.readStream=function(){var t=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new e(t)},e.prototype.readPackXZ=function(){var e=t._xPackData,n=t._zPackData;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},e.prototype.readPackY=function(){var e=this.readUint16(),n=t._yPackData;return n.uv[0]=1073741824,n.uv[0]|=(32767&e)<<12,n.fv[0]-=2,n.uv[0]|=(32768&e)<<16,n.fv[0]},e.prototype.writeInt8=function(t){var e=new Int8Array(this.buffer,this.wpos,1);e[0]=t,this.wpos+=1},e.prototype.writeInt16=function(t){this.writeInt8(255&t),this.writeInt8(t>>8&255)},e.prototype.writeInt32=function(t){for(var e=0;4>e;e++)this.writeInt8(t>>8*e&255)},e.prototype.writeInt64=function(t){this.writeInt32(t.lo),this.writeInt32(t.hi)},e.prototype.writeUint8=function(t){var e=new Uint8Array(this.buffer,this.wpos,1);e[0]=t,this.wpos+=1},e.prototype.writeUint16=function(t){this.writeUint8(255&t),this.writeUint8(t>>8&255)},e.prototype.writeUint32=function(t){for(var e=0;4>e;e++)this.writeUint8(t>>8*e&255)},e.prototype.writeUint64=function(t){this.writeUint32(t.lo),this.writeUint32(t.hi)},e.prototype.writeFloat=function(t){try{var e=new Float32Array(this.buffer,this.wpos,1);e[0]=t}catch(n){var e=new Float32Array(1);e[0]=t;var r=new Uint8Array(this.buffer),a=new Uint8Array(e.buffer);r.set(a,this.wpos)}this.wpos+=4},e.prototype.writeDouble=function(t){try{var e=new Float64Array(this.buffer,this.wpos,1);e[0]=t}catch(n){var e=new Float64Array(1);e[0]=t;var r=new Uint8Array(this.buffer),a=new Uint8Array(e.buffer);r.set(a,this.wpos)}this.wpos+=8},e.prototype.writeBlob=function(e){var n=e.length;if(n+4>this.space())return void t.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof e)for(var a=0;n>a;a++)r[a]=e.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=e[a];this.wpos+=n},e.prototype.writeString=function(e){if(e.length>this.space())return void t.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;athis.space()&&(this.buffer=ArrayBuffer.transfer(this.buffer,this.buffer.byteLength+2*n));var r=new Uint8Array(this.buffer,this.wpos,n);r.set(new Uint8Array(t.buffer,e,n),0),this.wpos+=n},e.prototype.readSkip=function(t){this.rpos+=t},e.prototype.space=function(){return this.buffer.byteLength-this.wpos},e.prototype.length=function(){return this.wpos-this.rpos},e.prototype.readEOF=function(){return this.buffer.byteLength-this.rpos<=0},e.prototype.done=function(){this.rpos=this.wpos},e.prototype.getbuffer=function(){return this.buffer.slice(this.rpos,this.wpos)},e.prototype.setbuffer=function(t){this.clear(),this.buffer=t},e.prototype.size=function(){return this.buffer.byteLength},e.prototype.clear=function(){this.rpos=this.wpos=0,this.buffer.byteLength>t.PACKET_MAX_SIZE&&(this.buffer=new ArrayBuffer(t.PACKET_MAX_SIZE))},e.prototype.reclaimObject=function(){this.clear(),void 0!=e._objects&&e._objects.push(this)},e}();t.MemoryStream=n,__reflect(n.prototype,"KBEngine.MemoryStream"),function(e){function n(){return e._objects.length>0?e._objects.pop():new e(t.PACKET_MAX_SIZE_TCP)}e._objects=[],e.createObject=n}(n=t.MemoryStream||(t.MemoryStream={}))}(KBEngine||(KBEngine={})),function(t){function e(){t.datatype2id={},t.datatype2id.STRING=1,t.datatype2id["STD::STRING"]=1,t.datatype2id.UINT8=2,t.datatype2id.BOOL=2,t.datatype2id.DATATYPE=2,t.datatype2id.CHAR=2,t.datatype2id.DETAIL_TYPE=2,t.datatype2id.ENTITYCALL_CALL_TYPE=2,t.datatype2id.UINT16=3,t.datatype2id["UNSIGNED SHORT"]=3,t.datatype2id.SERVER_ERROR_CODE=3,t.datatype2id.ENTITY_TYPE=3,t.datatype2id.ENTITY_PROPERTY_UID=3,t.datatype2id.ENTITY_METHOD_UID=3,t.datatype2id.ENTITY_SCRIPT_UID=3,t.datatype2id.DATATYPE_UID=3,t.datatype2id.UINT32=4,t.datatype2id.UINT=4,t.datatype2id["UNSIGNED INT"]=4,t.datatype2id.ARRAYSIZE=4,t.datatype2id.SPACE_ID=4,t.datatype2id.GAME_TIME=4,t.datatype2id.TIMER_ID=4,t.datatype2id.UINT64=5,t.datatype2id.DBID=5,t.datatype2id.COMPONENT_ID=5,t.datatype2id.INT8=6,t.datatype2id.COMPONENT_ORDER=6,t.datatype2id.INT16=7,t.datatype2id.SHORT=7,t.datatype2id.INT32=8,t.datatype2id.INT=8,t.datatype2id.ENTITY_ID=8,t.datatype2id.CALLBACK_ID=8,t.datatype2id.COMPONENT_TYPE=8,t.datatype2id.INT64=9,t.datatype2id.PYTHON=10,t.datatype2id.PY_DICT=10,t.datatype2id.PY_TUPLE=10,t.datatype2id.PY_LIST=10,t.datatype2id.ENTITYCALL=10,t.datatype2id.BLOB=11,t.datatype2id.UNICODE=12,t.datatype2id.FLOAT=13,t.datatype2id.DOUBLE=14,t.datatype2id.VECTOR2=15,t.datatype2id.VECTOR3=16,t.datatype2id.VECTOR4=17,t.datatype2id.FIXED_DICT=18,t.datatype2id.ARRAY=19,t.datatype2id.ENTITYCALL=20}function n(e,n){switch(n){case t.datatype2id.UINT8:return e.writeUint8;case t.datatype2id.UINT16:return e.writeUint16;case t.datatype2id.UINT32:return e.writeUint32;case t.datatype2id.UINT64:return e.writeUint64;case t.datatype2id.INT8:return e.writeInt8;case t.datatype2id.INT16:return e.writeInt16;case t.datatype2id.INT32:return e.writeInt32;case t.datatype2id.INT64:return e.writeInt64;case t.datatype2id.FLOAT:return e.writeFloat;case t.datatype2id.DOUBLE:return e.writeDouble;case t.datatype2id.STRING:return e.writeString;case t.datatype2id.FIXED_DICT:return e.writeStream;case t.datatype2id.ARRAY:return e.writeStream;default:return e.writeStream}}function r(e){switch(e){case t.datatype2id.UINT8:return t.reader.readUint8;case t.datatype2id.UINT16:return t.reader.readUint16;case t.datatype2id.UINT32:return t.reader.readUint32;case t.datatype2id.UINT64:return t.reader.readUint64;case t.datatype2id.INT8:return t.reader.readInt8;case t.datatype2id.INT16:return t.reader.readInt16;case t.datatype2id.INT32:return t.reader.readInt32;case t.datatype2id.INT64:return t.reader.readInt64;case t.datatype2id.FLOAT:return t.reader.readFloat;case t.datatype2id.DOUBLE:return t.reader.readDouble;case t.datatype2id.STRING:return t.reader.readString;case t.datatype2id.FIXED_DICT:return t.reader.readStream;case t.datatype2id.ARRAY:return t.reader.readStream;default:return t.reader.readStream}}var a=function(){function e(){this.memorystreams=new Array,this.numMessage=0,this.messageLengthBuffer=null,this.msgtype=null,this.messageLength=0,this.stream=t.MemoryStream.createObject()}return e.createObject=function(){return e._objects.length>0?e._objects.pop():new e},e.prototype.newMessage=function(e){this.fini(!1),this.msgtype=e,this.numMessage+=1,-1==this.msgtype.length&&(this.messageLengthBuffer=new Uint8Array(this.stream.buffer,this.stream.wpos+t.MESSAGE_ID_LENGTH,2)),this.writeUint16(e.id),this.messageLengthBuffer&&(this.writeUint16(0),this.messageLengthBuffer[0]=0,this.messageLengthBuffer[1]=0,this.messageLength=0)},e.prototype.writeMsgLength=function(t){this.messageLengthBuffer&&(this.messageLengthBuffer[0]=255&t,this.messageLengthBuffer[1]=t>>8&255)},e.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream),this.stream=t.MemoryStream.createObject()),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},e.prototype.send=function(t){this.fini(!0);for(var e=0;ethis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=t.MemoryStream.createObject()),this.messageLength+=e},e.prototype.writeInt8=function(t){this.checkStream(1),this.stream.writeInt8(t)},e.prototype.writeInt16=function(t){this.checkStream(2),this.stream.writeInt16(t)},e.prototype.writeInt32=function(t){this.checkStream(4),this.stream.writeInt32(t)},e.prototype.writeInt64=function(t){this.checkStream(8),this.stream.writeInt64(t)},e.prototype.writeUint8=function(t){this.checkStream(1),this.stream.writeUint8(t)},e.prototype.writeUint16=function(t){this.checkStream(2),this.stream.writeUint16(t)},e.prototype.writeUint32=function(t){this.checkStream(4),this.stream.writeUint32(t)},e.prototype.writeUint64=function(t){this.checkStream(8),this.stream.writeUint64(t)},e.prototype.writeFloat=function(t){this.checkStream(4),this.stream.writeFloat(t)},e.prototype.writeDouble=function(t){this.checkStream(8),this.stream.writeDouble(t)},e.prototype.writeString=function(t){this.checkStream(t.length+1),this.stream.writeString(t)},e.prototype.writeBlob=function(t){this.checkStream(t.length+4),this.stream.writeBlob(t)},e.prototype.clear=function(){for(var e=0;en){var r=e;e=n,n=r}return e>t?e:n>t?t:n}function n(t,e){return t*(Math.PI/(e?254:128))}function r(t,n){var r=0;return r=n?e(Math.floor(254*t/Math.PI+.5),-128,127):Math.floor(128*t/Math.PI+.5)}var a=function(){function t(t,e){this.x=t,this.y=e}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y;return Math.sqrt(e*e+n*n)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this},t}();t.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function t(t,e,n){this.x=t,this.y=e,this.z=n,this.x=t,this.y=e,this.z=n}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y,r=t.z-this.z;return Math.sqrt(e*e+n*n+r*r)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},t}();t.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function t(t,e,n,r){this.x=t,this.y=e,this.z=n,this.w=r,this.x=t,this.y=e,this.z=n,this.w=r}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y,r=t.z-this.z,a=t.w-this.w;return Math.sqrt(e*e+n*n+r*r+a*a)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this.w/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this},t}();t.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),t.clampf=e,t.int82angle=n,t.angle2int8=r}(KBEngine||(KBEngine={})),function(t){function e(){return function(e){var n=t.getQualifiedClassName(e);t.Entities[n]=e}}t.Entities={};var n=function(){function e(){this.__comps__={},this.id=0,this.className="",this.position=new t.Vector3(0,0,0),this.direction=new t.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new t.Vector3(0,0,0),this.entityLastLocalDir=new t.Vector3(0,0,0),this.isOnGround=!1;for(var e in this.__comps__)this[e]=new this.__comps__[e]}return e.prototype.__init__=function(){},e.prototype.attachComponents=function(){for(var t in this.__comps__)this[t].onAttached(this)},e.prototype.getComponents=function(e,n){void 0===n&&(n=!1);var r=[];for(var a in this.__comps__)if(t.getQualifiedClassName(this.__comps__[a])===e){if(!n)return this[a];r.push(this[a])}return r},e.prototype.detachComponents=function(){for(var t in this.__comps__)this[t].onDetached(this)},e.prototype.callPropertysSetMethods=function(){var e=t.moduledefs[this.className];for(var n in e.propertys){var r=e.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},e.prototype.onDestroy=function(){this.detachComponents()},e.prototype.onControlled=function(t){},e.prototype.isPlayer=function(){return this.id==t.app.entity_id},e.prototype.baseCall=function(e){for(var n=[],r=1;r0;){var a=0,i=0;if(n.usePropertyDescrAlias?(i=e.readUint8(),a=e.readUint8()):(i=e.readUint16(),a=e.readUint16()),0===i){var o=r[a],p=o[5],s=o[6];if(o[4]){var l=o[4].createFromStream(e),c=this[o[2]];t.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+this.className+"(id="+this.id+" "+o[2]+", val="+l+")!"),this[o[2]]=l,null!=p&&(32==s||64==s?this.inited&&p.call(this,c):this.inWorld&&p.call(this,c))}else this[o[2]]&&"function"==typeof this[o[2]].createFromStream&&this[o[2]].createFromStream(e)}else{var d=r[i];this[d[2]]&&this[d[2]].onUpdatePropertys(a,e,-1)}}},e.prototype.set_direction=function(e){t.DEBUG_MSG(this.className+"::set_direction: "+this.direction),t.Event.fire("set_direction",this)},e}();t.Entity=n,__reflect(n.prototype,"KBEngine.Entity"),t.registerEntity=e}(KBEngine||(KBEngine={})),function(t){function e(){return function(e){var n=t.getQualifiedClassName(e);t.Entities[n]=e}}var n=function(){function e(){this.id=0,this.entityComponentPropertyID=0,this.componentType=0,this.ownerID=0,this.owner=null,this.name_="",this.base=null,this.cell=null}return e.prototype.onAttached=function(t){},e.prototype.onDetached=function(t){},e.prototype.onEnterWorld=function(){},e.prototype.onLeaveWorld=function(){},e.prototype.onUpdatePropertys=function(e,n,r){for(var a=t.getQualifiedClassName(this),i=t.moduledefs[a],o=i.propertys;n.length()>0&&0!=r--;){var p=e,s=0;0===p&&(i.usePropertyDescrAlias?(s=n.readUint8(),p=n.readUint8()):(s=n.readUint16(),p=n.readUint16()));var l=o[p],c=l[5],d=l[6],u=l[4].createFromStream(n),y=this[l[2]];t.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+a+"(id="+this.id+" "+l[2]+", val="+u+")!"),this[l[2]]=u,null!=c&&(32==d||64==d?this.owner.inited&&c.call(this,y):this.owner.inWorld&&c.call(this,y))}},e.prototype.createFromStream=function(e){this.componentType=e.readInt32(),this.ownerID=e.readInt32(),this.owner=t.app.entities[this.ownerID],e.readUint16();var n=e.readUint16();n>0&&this.onUpdatePropertys(0,e,n),this.base=new t.EntityComponentCall(this.entityComponentPropertyID,this.ownerID),this.base.type=t.ENTITYCALL_TYPE_BASE,this.cell=new t.EntityComponentCall(this.entityComponentPropertyID,this.ownerID),this.cell.type=t.ENTITYCALL_TYPE_CELL},e}();t.EntityComponent=n,__reflect(n.prototype,"KBEngine.EntityComponent"),t.registerComponent=e}(KBEngine||(KBEngine={})),function(t){t.ENTITYCALL_TYPE_CELL=0,t.ENTITYCALL_TYPE_BASE=1;var e=function(){function e(){this.id=0,this.className="",this.type=t.ENTITYCALL_TYPE_CELL,this.networkInterface=t.app,this.bundle=null}return e.prototype.isBase=function(){return this.type==t.ENTITYCALL_TYPE_BASE},e.prototype.isCell=function(){return this.type==t.ENTITYCALL_TYPE_CELL},e.prototype.newCall=function(){return null==this.bundle&&(this.bundle=t.Bundle.createObject()),this.type==t.ENTITYCALL_TYPE_CELL?this.bundle.newMessage(t.messages.Baseapp_onRemoteCallCellMethodFromClient):this.bundle.newMessage(t.messages.Entity_onRemoteMethodCall),this.bundle.writeInt32(this.id),this.bundle},e.prototype.sendCall=function(t){void 0==t&&(t=this.bundle),t.send(this.networkInterface),this.bundle==t&&(this.bundle=null)},e}();t.EntityCall=e,__reflect(e.prototype,"KBEngine.EntityCall");var n=function(e){function n(n,r){var a=e.call(this)||this;return a.id=r,a.className=t.getQualifiedClassName(a),a}return __extends(n,e),n}(e);t.EntityComponentCall=n,__reflect(n.prototype,"KBEngine.EntityComponentCall");var r=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint8.call(e)},e.prototype.addToStream=function(t,e){t.writeUint8(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>255?!1:!0},e}();t.DATATYPE_UINT8=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT8");var a=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint16.call(e)},e.prototype.addToStream=function(t,e){t.writeUint16(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>65535?!1:!0},e}();t.DATATYPE_UINT16=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT16");var i=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint32.call(e)},e.prototype.addToStream=function(t,e){t.writeUint32(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>4294967295?!1:!0},e}();t.DATATYPE_UINT32=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT32");var o=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint64.call(e)},e.prototype.addToStream=function(t,e){t.writeUint64(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(e){return e instanceof t.UINT64},e}();t.DATATYPE_UINT64=o,__reflect(o.prototype,"KBEngine.DATATYPE_UINT64");var p=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt8.call(e)},e.prototype.addToStream=function(t,e){t.writeInt8(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-128>t||t>127?!1:!0},e}();t.DATATYPE_INT8=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT8");var s=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt16.call(e)},e.prototype.addToStream=function(t,e){t.writeInt16(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-32768>t||t>32767?!1:!0},e}();t.DATATYPE_INT16=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT16");var l=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt32.call(e)},e.prototype.addToStream=function(t,e){t.writeInt32(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-2147483648>t||t>2147483647?!1:!0},e}();t.DATATYPE_INT32=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT32");var c=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt64.call(e)},e.prototype.addToStream=function(t,e){t.writeInt64(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(e){return e instanceof t.INT64},e}();t.DATATYPE_INT64=c,__reflect(c.prototype,"KBEngine.DATATYPE_INT64");var d=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readFloat.call(e)},e.prototype.addToStream=function(t,e){t.writeFloat(e)},e.prototype.parseDefaultValStr=function(t){return parseFloat(t) +},e.prototype.isSameType=function(t){return"number"==typeof t},e}();t.DATATYPE_FLOAT=d,__reflect(d.prototype,"KBEngine.DATATYPE_FLOAT");var u=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.createFromStream=function(e){return t.reader.readDouble.call(e)},n.prototype.addToStream=function(t,e){t.writeDouble(e)},n}(d);t.DATATYPE_DOUBLE=u,__reflect(u.prototype,"KBEngine.DATATYPE_DOUBLE");var y=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readString.call(e)},e.prototype.addToStream=function(t,e){t.writeString(e)},e.prototype.parseDefaultValStr=function(t){return"string"==typeof t?t:""},e.prototype.isSameType=function(t){return"string"==typeof t},e}();t.DATATYPE_STRING=y,__reflect(y.prototype,"KBEngine.DATATYPE_STRING");var _=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){if(t.CLIENT_NO_FLOAT){var n=t.reader.readInt32.call(e),r=t.reader.readInt32.call(e);return new t.Vector2(n,r)}var n=t.reader.readFloat.call(e),r=t.reader.readFloat.call(e);return new t.Vector2(n,r)},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y)):(e.writeFloat(n.x),e.writeFloat(n.y))},e.prototype.parseDefaultValStr=function(e){return new t.Vector2(0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector2?!0:!1},e}();t.DATATYPE_VECTOR2=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.CLIENT_NO_FLOAT?new t.Vector3(t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e)):new t.Vector3(t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e))},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z))},e.prototype.parseDefaultValStr=function(e){return new t.Vector3(0,0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector3?!0:!1},e}();t.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var E=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.CLIENT_NO_FLOAT?new t.Vector4(t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e)):new t.Vector4(t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e))},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z),e.writeInt32(n.w)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z),e.writeFloat(n.w))},e.prototype.parseDefaultValStr=function(e){return new t.Vector4(0,0,0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector4?!0:!1},e}();t.DATATYPE_VECTOR4=E,__reflect(E.prototype,"KBEngine.DATATYPE_VECTOR4");var h=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return t.readBlob()},t.prototype.addToStream=function(t,e){t.writeBlob(e)},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_PYTHON=h,__reflect(h.prototype,"KBEngine.DATATYPE_PYTHON");var g=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.utf8ArrayToString(t.reader.readBlob.call(e))},e.prototype.addToStream=function(e,n){e.writeBlob(t.stringToUTF8Bytes(n))},e.prototype.parseDefaultValStr=function(t){return"string"==typeof t?t:""},e.prototype.isSameType=function(t){return"string"==typeof t},e}();t.DATATYPE_UNICODE=g,__reflect(g.prototype,"KBEngine.DATATYPE_UNICODE");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){},t.prototype.addToStream=function(t,e){},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_ENTITYCALL=m,__reflect(m.prototype,"KBEngine.DATATYPE_ENTITYCALL");var v=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){var n=t.reader.readUint32.call(e),r=new Uint8Array(e.buffer,e.rpos,n);return e.rpos+=n,r},e.prototype.addToStream=function(t,e){t.writeBlob(e)},e.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},e.prototype.isSameType=function(t){return!0},e}();t.DATATYPE_BLOB=v,__reflect(v.prototype,"KBEngine.DATATYPE_BLOB");var T=function(){function t(){this.type=null}return t.prototype.bind=function(){"number"==typeof this.type&&(this.type=A[this.type])},t.prototype.createFromStream=function(t){for(var e=t.readUint32(),n=[];e>0;)e--,n.push(this.type.createFromStream(t));return n},t.prototype.addToStream=function(t,e){t.writeUint32(e.length);for(var n=0;n0||null!=t.app.fragmentStream;)if(t.app.fragmentDatasFlag==t.FragmentDataTypes.FRAGMENT_DATA_UNKNOW){if(0==t.app.currMsgID){if(t.MESSAGE_ID_LENGTH>1&&n.length()=t.app.currMsgLen)r.handleMessage(t.app.fragmentStream),t.app.fragmentStream=null;else{if(n.length()0){t.app.writeFragmentMessage(t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY,n,t.app.currMsgLen);break}var i=n.wpos,o=n.rpos+a;n.wpos=o,r.handleMessage(n),n.wpos=i,n.rpos=o}t.app.currMsgID=0,t.app.currMsgLen=0,t.app.fragmentStream=null}else if(t.app.mergeFragmentMessage(n))break},e.prototype.writeFragmentMessage=function(e,n,r){var a=n.length();t.app.fragmentDatasRemain=r-a,t.app.fragmentDatasFlag=e,t.app.fragmentStream=n},e.prototype.mergeFragmentMessage=function(e){var n=e.length();if(0==n)return 0;var r=t.app.fragmentStream;if(n>=t.app.fragmentDatasRemain){switch(r.append(e,e.rpos,t.app.fragmentDatasRemain),t.app.fragmentDatasFlag){case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_ID:t.app.currMsgID=r.readUint16(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH:t.app.currMsgLen=r.readUint16(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH1:t.app.currMsgLen=r.readUint32(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY:}return e.rpos+=t.app.fragmentDatasRemain,t.app.fragmentDatasFlag=t.FragmentDataTypes.FRAGMENT_DATA_UNKNOW,t.app.fragmentDatasRemain=0,!1}return r.append(e,e.rpos,n),t.app.fragmentDatasRemain-=n,e.done(),!0},e.prototype.onclose=function(){t.INFO_MSG("connect close:"+t.app.currserver),t.app.currconnect==t.app.currstate&&(t.app.resetSocket(),t.Event.fire(t.EventTypes.onDisconnected))},e.prototype.send=function(e){t.app.socket.send(e)},e.prototype.close=function(){t.INFO_MSG("KBEngine::close()"),t.app.socket.close(),t.app.reset()},e.prototype.update=function(){if(null!=t.app.socket){var e=new Date;if((e.getTime()-t.app.lastTickTime)/1e3>t.app.args.serverHeartbeatTick/2){if(t.app.lastTickCBTime0;){n-=1;var r=new a;r.id=e.readUint16(),r.name=t.utf8ArrayToString(e.readBlob()),r.descr=t.utf8ArrayToString(e.readBlob()),t.app.serverErrs[r.id]=r,t.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},e.prototype.Client_onImportClientSdk=function(e){var n=e.readInt32(),r=e.readString(),a=e.readInt32(),i=e.readBlob();t.Event.fire("onImportClientSDK",n,r,a,i)},e.prototype.onOpenLoginapp_login=function(){if(t.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),t.Event.fire(t.EventTypes.onConnectionState,!0),t.app.currserver="loginapp",t.app.currstate="login",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),t.Event.fire("Loginapp_importClientMessages")}},e.prototype.onOpenLoginapp_createAccount=function(){if(t.Event.fire("onConnectionState",!0),t.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),t.app.currserver="loginapp",t.app.currstate="createAccount",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),t.Event.fire("Loginapp_importClientMessages")}},e.prototype.onImportClientMessagesCompleted=function(){if(t.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),t.app.socket.onmessage=t.app.onmessage,t.app.hello(),"loginapp"==t.app.currserver){if(!t.app.serverErrorsDescrImported){t.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),t.app.serverErrorsDescrImported=!0;var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importServerErrorsDescr),e.send(t.app)}"login"==t.app.currstate?t.app.login_loginapp(!1):"resetpassword"==t.app.currstate?t.app.resetpassword_loginapp(!1):t.app.createAccount_loginapp(!1),t.app.loginappMessageImported=!0}else if(t.app.baseappMessageImported=!0,t.app.entitydefImported)t.app.onImportEntityDefCompleted();else{t.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_importClientEntityDef),e.send(t.app),t.Event.fire("Baseapp_importClientEntityDef")}},e.prototype.createDataTypeFromStreams=function(e,n){var r=e.readUint16();for(t.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,t.app.createDataTypeFromStream(e,n);for(var a in t.datatypes)void 0!=t.datatypes[a]&&t.datatypes[a].bind()},e.prototype.createDataTypeFromStream=function(e,n){var r,a=e.readUint16(),i=e.readString(),o=e.readString();if(0==o.length&&(r="Null_"+a),n&&t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new t.DATATYPE_FIXED_DICT,s=e.readUint8();for(p.implementedBy=e.readString();s>0;){s--;var l=e.readString(),c=e.readUint16();p.dicttype[l]=c}t.datatypes[o]=p}else if("ARRAY"==i){var d=e.readUint16(),p=new t.DATATYPE_ARRAY;p.type=d,t.datatypes[o]=p}else t.datatypes[o]=t.datatypes[i];t.datatypes[a]=t.datatypes[o],t.datatype2id[o]=a},e.prototype.Client_onImportClientEntityDef=function(e){for(t.app.createDataTypeFromStreams(e,!0);e.length()>0;){var n=e.readString(),r=e.readUint16(),a=e.readUint16(),i=e.readUint16(),o=e.readUint16(),p=e.readUint16();t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),t.moduledefs[n]={};var s=t.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},t.moduledefs[r]=s;for(var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods,y=t.Entities[n];a>0;){a--;var _=e.readUint16(),f=e.readUint32(),E=e.readInt16(),h=e.readString(),g=e.readString(),m=t.datatypes[e.readUint16()],v=null;void 0!=y&&(v=y.prototype["set_"+h],void 0==v&&(v=null));var T=[_,E,h,g,m,v,f];l[h]=T,-1!=E?(l[E]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+h+"/"+_+").")}for(;i>0;){i--;for(var S=e.readUint16(),E=e.readInt16(),A=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);var T=[S,E,A,D];c[A]=T,-1!=E?(c[E]=T,s.useMethodDescrAlias=!0):(c[S]=T,s.useMethodDescrAlias=!1),t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+A+").")}for(;o>0;){o--;for(var S=e.readUint16(),E=e.readInt16(),M=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);d[M]=[S,E,M,D],t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+M+").")}for(;p>0;){p--;for(var S=e.readUint16(),E=e.readInt16(),F=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);u[F]=[S,E,F,D],t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+F+").")}var w=void 0;try{w=t.Entities[n]}catch(B){t.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),w=void 0}for(var C in s.propertys){var L=s.propertys[C],_=L[0],E=L[1],K=L[2],g=L[3],m=L[4];void 0!=w&&m&&(w.prototype[K]=m.parseDefaultValStr(g))}for(var b in s.methods){var L=s.methods[b],_=L[0],E=L[1],K=L[2],D=L[3];void 0!=w&&void 0==w.prototype[K]&&t.WARNING_MSG(n+":: method("+K+") no implement!")}}t.app.onImportEntityDefCompleted()},e.prototype.Client_onVersionNotMatch=function(e){t.app.serverVersion=e.readString(),t.ERROR_MSG("Client_onVersionNotMatch: verInfo="+t.app.clientVersion+" not match(server: "+t.app.serverVersion+")"),t.Event.fire(t.EventTypes.onVersionNotMatch,t.app.clientVersion,t.app.serverVersion)},e.prototype.Client_onScriptVersionNotMatch=function(e){t.app.serverScriptVersion=e.readString(),t.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+t.app.clientScriptVersion+" not match(server: "+t.app.serverScriptVersion+")"),t.Event.fire(t.EventTypes.onScriptVersionNotMatch,t.app.clientScriptVersion,t.app.serverScriptVersion)},e.prototype.onImportEntityDefCompleted=function(){t.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),t.app.entitydefImported=!0,t.app.login_baseapp(!1)},e.prototype.importClientMessages=function(e){for(;t.app.currMsgCount>0;){t.app.currMsgCount--;for(var n=e.readUint16(),r=e.readInt16(),a=e.readString(),i=e.readInt8(),o=e.readUint8(),p=new Array(o),s=0;o>s;s++)p[s]=e.readUint8();var l=null,c=a.indexOf("Client_")>=0;c&&(l=t.app[a],null==l||void 0==l?(t.WARNING_MSG("KBEngineApp::onImportClientMessages["+t.app.currserver+"]: interface("+a+"/"+n+") no implement!"),l=null):t.INFO_MSG("KBEngineApp::onImportClientMessages: import("+a+") successfully!")),a.length>0?(t.messages[a]=new t.Message(n,a,r,i,p,l),c?t.clientmessages[n]=t.messages[a]:t.messages[t.app.currserver][n]=t.messages[a]):t.messages[t.app.currserver][n]=new t.Message(n,a,r,i,p,l)}t.app.onImportClientMessagesCompleted(),t.app.currMsgID=0,t.app.currMsgLen=0,t.app.currMsgCount=0,t.app.fragmentStream=null},e.prototype.Client_onImportClientMessages=function(e){var n=new t.MemoryStream(e.data);n.wpos=e.data.byteLength,0==t.app.currMsgID&&(t.app.currMsgID=n.readUint16()),t.app.currMsgID==t.messages.onImportClientMessages.id?(0==t.app.currMsgLen&&(t.app.currMsgLen=n.readUint16(),t.app.currMsgCount=n.readUint16()),n.length()+2=t.app.currMsgLen&&t.app.importClientMessages(t.app.fragmentStream)):t.app.importClientMessages(n)):t.ERROR_MSG("KBEngineApp::onmessage: not found msg("+t.app.currMsgID+")!")},e.prototype.createAccount=function(e,n,r){t.app.reset(),t.app.username=e,t.app.password=n,t.app.clientdatas=r,t.app.createAccount_loginapp(!0)},e.prototype.createAccount_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_createAccount;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_reqCreateAccount),n.writeString(t.app.username),n.writeString(t.app.password),n.writeBlob(t.app.clientdatas),n.send(t.app)}},e.prototype.bindAccountEmail=function(e){var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_reqAccountBindEmail),n.writeInt32(t.app.entity_id),n.writeString(t.app.password),n.writeString(e),n.send(t.app)},e.prototype.newPassword=function(e,n){var r=t.Bundle.createObject();r.newMessage(t.messages.Baseapp_reqAccountNewPassword),r.writeInt32(t.app.entity_id),r.writeString(e),r.writeString(n),r.send(t.app)},e.prototype.logout=function(){var e=new t.Bundle;e.newMessage(t.messages.Baseapp_logoutBaseapp),e.writeUint64(t.app.entity_uuid),e.writeInt32(t.app.entity_id),e.send(t.app)},e.prototype.login=function(e,n,r){t.app.reset(),t.app.username=e,t.app.password=n,t.app.clientdatas=r,t.app.login_loginapp(!0)},e.prototype.login_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_login;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_login),n.writeInt8(t.app.args.clientType),n.writeBlob(t.app.clientdatas),n.writeString(t.app.username),n.writeString(t.app.password),n.send(t.app)}},e.prototype.onOpenLoginapp_resetpassword=function(){if(t.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),t.app.currserver="loginapp",t.app.currstate="resetpassword",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},e.prototype.reset_password=function(e){t.app.reset(),t.app.username=e,t.app.resetpassword_loginapp(!0)},e.prototype.resetpassword_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_resetpassword;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_reqAccountResetPassword),n.writeString(t.app.username),n.send(t.app)}},e.prototype.onOpenBaseapp=function(){if(t.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),t.app.currserver="baseapp",t.app.baseappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.Event.fire("Baseapp_importClientMessages")}},e.prototype.login_baseapp=function(e){if(e)t.Event.fire("onLoginBaseapp"),t.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+t.app.baseappIp+":"+t.app.baseappPort+"!"),t.app.currconnect="baseapp",t.app.connect(t.app.baseappIp,t.app.baseappPort),void 0!=t.app.socket&&null!=t.app.socket&&(t.app.socket.onopen=t.app.onOpenBaseapp);else{var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_loginBaseapp),n.writeString(t.app.username),n.writeString(t.app.password),n.send(t.app)}},e.prototype.reloginBaseapp=function(){t.app.lastTickCBTime=t.app.lastTickTime=Date.now(),(void 0==t.app.socket||null==t.app.socket)&&(t.app.resetSocket(),t.Event.fire(t.EventTypes.onReloginBaseapp),t.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+t.app.baseappIp+":"+t.app.baseappPort+"!"),t.app.currconnect="baseapp",t.app.connect(t.app.baseappIp,t.app.baseappPort),void 0!=t.app.socket&&null!=t.app.socket&&(t.app.socket.onopen=t.app.onReOpenBaseapp))},e.prototype.onReOpenBaseapp=function(){t.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),t.app.currserver="baseapp";var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_reloginBaseapp),e.writeString(t.app.username),e.writeString(t.app.password),e.writeUint64(t.app.entity_uuid),e.writeInt32(t.app.entity_id),e.send(t.app);var n=new Date;t.app.lastTickCBTime=n.getTime()},e.prototype.Client_onHelloCB=function(e){t.app.serverVersion=e.readString(),t.app.serverScriptVersion=e.readString(),t.app.serverProtocolMD5=e.readString(),t.app.serverEntityDefMD5=e.readString();var n=e.readInt32();t.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+t.app.serverVersion+"), scriptVerInfo("+t.app.serverScriptVersion+"), serverProtocolMD5("+t.app.serverProtocolMD5+"), serverEntityDefMD5("+t.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;t.app.lastTickCBTime=r.getTime()},e.prototype.Client_onLoginFailed=function(e){var n=e.readUint16();t.app.serverdatas=e.readBlob(),t.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+t.app.serverErrs[n].name+"), datas("+t.app.serverdatas.length+")!"),t.Event.fire("onLoginFailed",n)},e.prototype.Client_onLoginSuccessfully=function(e){var n=e.readString();t.app.username=n,t.app.baseappIp=e.readString(),t.app.baseappPort=e.readUint16(),t.app.baseappUdpPort=e.readUint16(),t.app.serverdatas=e.readBlob(),t.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+t.app.baseappIp+":"+t.app.baseappPort+"), datas("+t.app.serverdatas.length+")!"),t.app.disconnect(),t.app.login_baseapp(!0)},e.prototype.Client_onLoginBaseappFailed=function(e){t.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onLoginBaseappFailed,e)},e.prototype.Client_onReloginBaseappFailed=function(e){t.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onReloginBaseappFailed,e)},e.prototype.Client_onReloginBaseappSuccessfully=function(e){t.app.entity_uuid=e.readUint64(),t.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+t.app.username),t.Event.fire(t.EventTypes.onReloginBaseappSuccessfully)},e.prototype.getentityclass=function(e){var n=t.Entities[e];return void 0==n?(t.ERROR_MSG("KBEngineApp::getentityclass: entityType("+e+") is error!"),n):n},e.prototype.Client_onCreatedProxies=function(e,n,r){t.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=t.app.entities[n];if(t.app.entity_uuid=e,t.app.entity_id=n,void 0==a){var i=t.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new t.EntityCall,o.base.id=n,o.base.className=r,o.base.type=t.ENTITYCALL_TYPE_BASE,t.app.entities[n]=o;var p=t.bufferedCreateEntityMessages[n];void 0!=p&&(t.app.Client_onUpdatePropertys(p),delete t.bufferedCreateEntityMessages[n]),o.__init__(),o.attachComponents(),o.inited=!0,t.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=t.bufferedCreateEntityMessages[n];void 0!=p&&(t.app.Client_onUpdatePropertys(p),delete t.bufferedCreateEntityMessages[n])}},e.prototype.getViewEntityIDFromStream=function(e){var n=0;if(t.app.entityIDAliasIDList.length>255)n=e.readInt32();else{var r=e.readUint8();if(t.app.entityIDAliasIDList.length<=r)return 0;n=t.app.entityIDAliasIDList[r]}return n},e.prototype.onUpdatePropertys_=function(e,n){var r=t.app.entities[e];if(void 0==r){var a=t.bufferedCreateEntityMessages[e];if(void 0!=a)return void t.ERROR_MSG("KBEngineApp::Client_onUpdEntityComponentatePropertys: entity("+e+") not found!"); +var i=new t.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(t.bufferedCreateEntityMessages[e]=i)}r.onUpdatePropertys(n)},e.prototype.Client_onUpdatePropertysOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.onUpdatePropertys_(n,e)},e.prototype.Client_onUpdatePropertys=function(e){var n=e.readInt32();t.app.onUpdatePropertys_(n,e)},e.prototype.onRemoteMethodCall_=function(e,n){var r=t.app.entities[e];if(void 0==r)return void t.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+e+") not found!");var a=0,i=0;t.moduledefs[r.className].useMethodDescrAlias?(i=n.readInt8(),a=n.readUint8()):(i=n.readUint16(),a=n.readUint16());for(var o=t.moduledefs[r.className].methods[a],p=[],s=o[3],l=0;l0&&n!=t.app.entity_id&&t.app.entityIDAliasIDList.push(n);var r;r=t.moduledefs.Length>255?e.readUint16():e.readUint8();var a=!0;e.length()>0&&(a=e.readInt8()),r=t.moduledefs[r].name,t.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+t.app.spaceID+"), isOnGround("+a+")!");var i=t.app.entities[n];if(void 0==i){var o=t.bufferedCreateEntityMessages[n];if(void 0==o)return void t.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=t.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new t.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=t.ENTITYCALL_TYPE_CELL,t.app.entities[n]=s,t.app.Client_onUpdatePropertys(o),delete t.bufferedCreateEntityMessages[n],s.isOnGround=a,s.__init__(),s.attachComponents(),s.inited=!0,s.inWorld=!0,s.enterWorld(),t.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new t.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=t.ENTITYCALL_TYPE_CELL,t.app.entityIDAliasIDList=[],t.app.entities={},t.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),t.app.entityServerPos.x=i.position.x,t.app.entityServerPos.y=i.position.y,t.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),t.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},e.prototype.Client_onEntityLeaveWorldOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.Client_onEntityLeaveWorld(n)},e.prototype.Client_onEntityLeaveWorld=function(e){var n=t.app.entities[e];if(void 0==n)return void t.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+e+") not found!");if(n.inWorld&&n.leaveWorld(),t.app.entity_id>0&&e!=t.app.entity_id){for(var r=[],a=0;a0&&(r=e.readInt8());var a=t.app.entities[n];return void 0==a?void t.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,t.app.entityServerPos.x=a.position.x,t.app.entityServerPos.y=a.position.y,t.app.entityServerPos.z=a.position.z,void a.enterSpace())},e.prototype.Client_onEntityLeaveSpace=function(e){var n=t.app.entities[e];return void 0==n?void t.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+e+") not found!"):(t.app.clearSpace(!1),void n.leaveSpace())},e.prototype.Client_onKicked=function(e){t.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onKicked,e)},e.prototype.Client_onCreateAccountResult=function(e){var n=e.readUint16(),r=e.readBlob();return t.Event.fire("onCreateAccountResult",n,r),0!=n?void t.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+t.app.username+" create is failed! code="+t.app.serverErrs[n].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+t.app.username+" create is successfully!")},e.prototype.Client_onControlEntity=function(e,n){var r=t.app.entities[e];if(void 0==r)return void t.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+e+") not found!");var a=0!=n;if(a)t.app.player().id!=r.id&&t.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||e.entityLastLocalDir.distance(e.direction)>.001){e.entityLastLocalPos.x=e.position.x,e.entityLastLocalPos.y=e.position.y,e.entityLastLocalPos.z=e.position.z,e.entityLastLocalDir.x=e.direction.x,e.entityLastLocalDir.y=e.direction.y,e.entityLastLocalDir.z=e.direction.z;var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(e.position.x),n.writeFloat(e.position.y),n.writeFloat(e.position.z),n.writeFloat(e.direction.x),n.writeFloat(e.direction.y),n.writeFloat(e.direction.z),n.writeUint8(e.isOnGround),n.writeUint32(t.app.spaceID),n.send(t.app)}for(var r in t.app.controlledEntities){var a=t.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(t.app.spaceID),n.send(t.app)}}}},e.prototype.addSpaceGeometryMapping=function(e,n){t.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+e+"), respath("+n+")!"),t.app.spaceID=e,t.app.spaceResPath=n,t.Event.fire(t.EventTypes.addSpaceGeometryMapping,n)},e.prototype.clearSpace=function(e){t.app.entityIDAliasIDList=[],t.app.spacedata={},t.app.clearEntities(e),t.app.isLoadedGeometry=!1,t.app.spaceID=0},e.prototype.clearEntities=function(e){if(t.app.controlledEntities=[],e){for(var n in t.app.entities)t.app.entities[n].inWorld&&t.app.entities[n].leaveWorld(),t.app.entities[n].onDestroy();t.app.entities={}}else{var r=t.app.player();for(var n in t.app.entities)n!=r.id&&(t.app.entities[n].inWorld&&t.app.entities[n].leaveWorld(),t.app.entities[n].onDestroy());t.app.entities={},t.app.entities[r.id]=r}},e.prototype.Client_initSpaceData=function(e){for(t.app.clearSpace(!1),t.app.spaceID=e.readInt32();e.length()>0;){var n=e.readString(),r=e.readString();t.app.Client_setSpaceData(t.app.spaceID,n,r)}t.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+t.app.spaceID+"), datas("+t.app.spacedata+")!")},e.prototype.Client_setSpaceData=function(e,n,r){t.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+e+"), key("+n+"), value("+r+")!"),t.app.spacedata[n]=r,"_mapping"==n&&t.app.addSpaceGeometryMapping(e,r),t.Event.fire("onSetSpaceData",e,n,r)},e.prototype.Client_delSpaceData=function(e,n){t.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+e+"), key("+n+")!"),delete t.app.spacedata[n],t.Event.fire("onDelSpaceData",e,n)},e.prototype.Client_getSpaceData=function(e,n){return t.app.spacedata[n]},e.prototype.Client_onUpdateBasePos=function(e,n,r){t.app.entityServerPos.x=e,t.app.entityServerPos.y=n,t.app.entityServerPos.z=r},e.prototype.Client_onUpdateBasePosXZ=function(e,n){t.app.entityServerPos.x=e,t.app.entityServerPos.z=n},e.prototype.Client_onUpdateData=function(e){var n=t.app.getViewEntityIDFromStream(e),r=t.app.entities[n];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},e.prototype.Client_onSetEntityPosAndDir=function(e){var n=e.readInt32(),r=t.app.entities[n];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=e.readFloat(),r.position.y=e.readFloat(),r.position.z=e.readFloat(),r.direction.x=e.readFloat(),r.direction.y=e.readFloat(),r.direction.z=e.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},e.prototype.Client_onUpdateData_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,i,-1)},e.prototype.Client_onUpdateData_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,a,-1)},e.prototype.Client_onUpdateData_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,-1)},e.prototype.Client_onUpdateData_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,-1)},e.prototype.Client_onUpdateData_xz=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,o,p,1)},e.prototype.Client_onUpdateData_xz_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,o,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,t.KBE_FLT_MAX,o,1)},e.prototype.Client_onUpdateData_xz_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,i,o,1)},e.prototype.Client_onUpdateData_xz_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readInt8();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,i,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readInt8();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,i,1)},e.prototype.Client_onUpdateData_xyz=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,r,a,i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat(),s=e.readFloat();t.app._updateVolatileData(n,r,a,i,o,p,s,0)},e.prototype.Client_onUpdateData_xyz_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,p,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,p,0)},e.prototype.Client_onUpdateData_xyz_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,t.KBE_FLT_MAX,o,p,0)},e.prototype.Client_onUpdateData_xyz_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,t.KBE_FLT_MAX,o,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,i,-1,!0)},e.prototype.Client_onUpdateData_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,a,-1,!0)},e.prototype.Client_onUpdateData_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,-1,!0)},e.prototype.Client_onUpdateData_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,-1,!0)},e.prototype.Client_onUpdateData_xz_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,i,o,1,!0)},e.prototype.Client_onUpdateData_xz_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,i,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,t.KBE_FLT_MAX,i,1,!0)},e.prototype.Client_onUpdateData_xz_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,a,i,1,!0)},e.prototype.Client_onUpdateData_xz_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,a,1,!0)},e.prototype.Client_onUpdateData_xyz_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8(),p=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0,!0)},e.prototype.Client_onUpdateData_xyz_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,o,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,o,0,!0)},e.prototype.Client_onUpdateData_xyz_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,i,o,0,!0)},e.prototype.Client_onUpdateData_xyz_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,i,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype._updateVolatileData=function(e,n,r,a,i,o,p,s,l){void 0===l&&(l=!1);var c=t.app.entities[e];if(void 0==c)return void t.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+e+") not found!");s>=0&&(c.isOnGround=s>0);var d=!1;p!=t.KBE_FLT_MAX&&(d=!0,c.direction.x=t.int82angle(p,!1)),o!=t.KBE_FLT_MAX&&(d=!0,c.direction.y=t.int82angle(o,!1)),i!=t.KBE_FLT_MAX&&(d=!0,c.direction.z=t.int82angle(i,!1));var u=!1;1==d&&(t.Event.fire("set_direction",c),u=!0);var y=!1;(n!=t.KBE_FLT_MAX||r!=t.KBE_FLT_MAX||a!=t.KBE_FLT_MAX)&&(y=!0),n==t.KBE_FLT_MAX&&(n=0),r==t.KBE_FLT_MAX&&(r=0),a==t.KBE_FLT_MAX&&(a=0),y&&(l?(c.position.x=n+t.app.entityServerPos.x,c.position.y=r+t.app.entityServerPos.y,c.position.z=a+t.app.entityServerPos.z):(c.position.x=n,c.position.y=r,c.position.z=a),u=!0,t.Event.fire("updatePosition",c)),u&&c.onUpdateVolatileData()},e.prototype.Client_onStreamDataStarted=function(e,n,r){t.Event.fire(t.EventTypes.onStreamDataStarted,e,n,r)},e.prototype.Client_onStreamDataRecv=function(e){var n=e.readUint16(),r=e.readBlob();t.Event.fire(t.EventTypes.onStreamDataRecv,n,r)},e.prototype.Client_onStreamDataCompleted=function(e){t.Event.fire(t.EventTypes.onStreamDataCompleted,e)},e.prototype.Client_onReqAccountResetPasswordCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+t.app.username+" is successfully!")},e.prototype.Client_onReqAccountBindEmailCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+t.app.username+" is successfully!")},e.prototype.Client_onReqAccountNewPasswordCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+t.app.username+" is successfully!")},e}();t.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function t(){this.name="",this.descr="",this.id=0}return t}();t.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr"),t.FragmentDataTypes={FRAGMENT_DATA_UNKNOW:0,FRAGMENT_DATA_MESSAGE_ID:1,FRAGMENT_DATA_MESSAGE_LENGTH:2,FRAGMENT_DATA_MESSAGE_LENGTH1:3,FRAGMENT_DATA_MESSAGE_BODY:4};var i;t.create=e,t.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index 0f4b0ba..ae9b46a 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -4,22 +4,24 @@ * * 注:(下面的是重点) * 1、实体声明的命名空间为KBEngine.Entities,与官方的KBEngine不同 - * 2、cocos creator环境下,按下面方法声明实体 - - @KBEngine.registerEntity('Account') /// <---这个Account对应服务器上实体 - export default class AccountEntity extends KBEngine.Entity { + * 2、 @KBEngine.registerEntity() /// TODO: <---组件使用@KBEngine.registerComponent() + export default class Account extends KBEngine.Entity { /// TODO: 组件继承自KBEngine.EntityComponent,类名等于服务器(实体/组件)名 + __comps__ = {组件名:组件类型} ///TODO: 因为组件类型不会从服务器同步,只能获取到EntityComponent,无法获取具体类型,所以需要在实体里进行手动设置,需要代码提示可以手动声明一下 __init__() { console.log('创建account') } } //这里加入声明用于vscode代码提示 declare global { - namespace KBEngine.Entities { - class Account extends AccountEntity { } /// <---这个Account对应服务器上实体 + namespace KBEngine { + interface IEntities{ + Account:new ()=>Account + } } } * 3、cocos creator编辑器下会出现KBEngine未找到的问题,不影响运行,如果想去掉,将允许编辑器加载勾选 + 4、因为下班了,组件的basecall和cellcall还未测试,改天再继续 */ /*----------------------------------------------------------------------------------------- @@ -133,6 +135,28 @@ namespace KBEngine { } } } +namespace KBEngine { + export function getQualifiedClassName(value) { + let type = typeof value; + if (!value || (type != "object" && !value.prototype)) { + return type; + } + let prototype = value.prototype ? value.prototype : Object.getPrototypeOf(value); + if (prototype.hasOwnProperty("__class__")) { + return prototype["__class__"]; + } + let constructorString = prototype.constructor.toString().trim(); + let index = constructorString.indexOf("("); + let className = constructorString.substring(9, index); + let c = className.split('.') + Object.defineProperty(prototype, "__class__", { + value: c[c.length - 1], + enumerable: false, + writable: true + }); + return c[c.length - 1]; + } +} /*----------------------------------------------------------------------------------------- debug -----------------------------------------------------------------------------------------*/ @@ -1227,12 +1251,16 @@ namespace KBEngine { -----------------------------------------------------------------------------------------*/ namespace KBEngine { - export module Entities { } + export interface IEntities { } + export const Entities: IEntities = {} export class Entity { constructor() { - + for (let i in this.__comps__) { + this[i] = new this.__comps__[i]() + } } + protected __comps__: { [compName: string]: new () => EntityComponent } = {} id: number = 0; className: string = ""; position: Vector3 = new Vector3(0, 0, 0); @@ -1259,6 +1287,28 @@ namespace KBEngine { __init__() { + } + attachComponents() { + for (let i in this.__comps__) { + this[i].onAttached(this) + } + } + getComponents(compName: string, all: boolean = false) { + let res = [] + for (let i in this.__comps__) { + if (getQualifiedClassName(this.__comps__[i]) === compName) { + if (!all) { + return this[i]; + } + res.push(this[i]) + } + } + return res; + } + detachComponents() { + for (let i in this.__comps__) { + this[i].onDetached(this) + } } callPropertysSetMethods() { let currModule = moduledefs[this.className]; @@ -1291,7 +1341,7 @@ namespace KBEngine { }; } onDestroy() { - + this.detachComponents() } onControlled(bIsControlled) { @@ -1401,9 +1451,19 @@ namespace KBEngine { INFO_MSG(this.className + '::enterWorld: ' + this.id); this.inWorld = true; this.onEnterWorld(); - + this.onComponentsEnterworld(); Event.fire("onEnterWorld", this); } + onComponentsEnterworld() { + for (let i in this.__comps__) { + this[i].onEnterWorld() + } + } + onComponentsLeaveworld() { + for (let i in this.__comps__) { + this[i].onLeaveWorld() + } + } onEnterWorld() { } @@ -1411,6 +1471,7 @@ namespace KBEngine { INFO_MSG(this.className + '::leaveWorld: ' + this.id); this.inWorld = false; this.onLeaveWorld(); + this.onComponentsLeaveworld() Event.fire("onLeaveWorld", this); } onLeaveWorld() { @@ -1448,15 +1509,137 @@ namespace KBEngine { } onUpdateVolatileData() { + } + onUpdatePropertys(stream: MemoryStream) { + let currModule = moduledefs[getQualifiedClassName(this)]; + let pdatas = currModule.propertys; + while (stream.length() > 0) { + let utype = 0, cId = 0; + if (currModule.usePropertyDescrAlias) { + cId = stream.readUint8() + utype = stream.readUint8() + } else { + cId = stream.readUint16() + utype = stream.readUint16() + } + if (cId !== 0) { + let comp = pdatas[cId]; + if (this[comp[2]]) { + this[comp[2]].onUpdatePropertys(utype, stream, -1) + } + continue; + } + let propertydata = pdatas[utype]; + let setmethod = propertydata[5]; + let flags = propertydata[6]; + if (!propertydata[4]) { + if (this[propertydata[2]] && typeof this[propertydata[2]].createFromStream === 'function') + this[propertydata[2]].createFromStream(stream) + continue; + } + let val = propertydata[4].createFromStream(stream); + let oldval = this[propertydata[2]]; + KBEngine.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: " + this.className + "(id=" + this.id + " " + propertydata[2] + ", val=" + val + ")!"); + this[propertydata[2]] = val; + if (setmethod != null) { + // base类属性或者进入世界后cell类属性会触发set_*方法 + if (flags == 0x00000020 || flags == 0x00000040) { + if (this.inited) + setmethod.call(this, oldval); + } + else { + if (this.inWorld) + setmethod.call(this, oldval); + } + } + } } set_direction(old) { DEBUG_MSG(this.className + "::set_direction: " + this.direction); Event.fire("set_direction", this); } } - export function registerEntity(name: string) { + export function registerEntity() { return (ctor: new () => Entity) => { - KBEngine['Entities'] = KBEngine['Entities'] || {} + let name = getQualifiedClassName(ctor); + // KBEngine['Entities'] = KBEngine['Entities'] || {} + KBEngine['Entities'][name] = ctor; + } + } +} +namespace KBEngine { + export class EntityComponent { + id = 0 + entityComponentPropertyID = 0; + componentType = 0; + ownerID = 0; + owner: Entity = null; + name_: string = '' + + base: EntityComponentCall = null; + cell: EntityComponentCall = null; + + protected onAttached(owner: Entity) { } + protected onDetached(owner: Entity) { } + protected onEnterWorld() { } + protected onLeaveWorld() { } + + onUpdatePropertys(propUtype: number, stream: MemoryStream, maxCount: number) { + let className = getQualifiedClassName(this) + let currModule = moduledefs[className]; + let pdatas = currModule.propertys; + while (stream.length() > 0 && maxCount-- != 0) { + let utype = propUtype, cId = 0; + if (utype === 0) { + if (currModule.usePropertyDescrAlias) { + cId = stream.readUint8() + utype = stream.readUint8() + } else { + cId = stream.readUint16() + utype = stream.readUint16() + } + } + let propertydata = pdatas[utype]; + let setmethod = propertydata[5]; + let flags = propertydata[6]; + let val = propertydata[4].createFromStream(stream); + let oldval = this[propertydata[2]]; + KBEngine.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: " + className + "(id=" + this.id + " " + propertydata[2] + ", val=" + val + ")!"); + this[propertydata[2]] = val; + if (setmethod != null) { + // base类属性或者进入世界后cell类属性会触发set_*方法 + if (flags == 0x00000020 || flags == 0x00000040) { + if (this.owner.inited) + setmethod.call(this, oldval); + } + else { + if (this.owner.inWorld) + setmethod.call(this, oldval); + } + } + } + } + createFromStream(stream: MemoryStream) { + this.componentType = stream.readInt32(); + this.ownerID = stream.readInt32() + this.owner = app.entities[this.ownerID]; + + //UInt16 ComponentDescrsType; + stream.readUint16(); + let count = stream.readUint16() + if (count > 0) { + this.onUpdatePropertys(0, stream, count) + } + this.base = new EntityComponentCall(this.entityComponentPropertyID, this.ownerID) + this.base.type = ENTITYCALL_TYPE_BASE + this.cell = new EntityComponentCall(this.entityComponentPropertyID, this.ownerID) + this.cell.type = ENTITYCALL_TYPE_CELL + } + } + export function registerComponent() { + return (ctor: new () => EntityComponent) => { + let name = getQualifiedClassName(ctor); + // KBEngine['Entities'] = KBEngine['Entities'] || {} KBEngine['Entities'][name] = ctor; } } @@ -1468,11 +1651,6 @@ namespace KBEngine { export const ENTITYCALL_TYPE_CELL = 0; export const ENTITYCALL_TYPE_BASE = 1; - //这个东西好像没有同步给客户端 - export class EntityComponent { - - } - export class EntityCall { constructor() { @@ -1512,6 +1690,13 @@ namespace KBEngine { this.bundle = null; } } + export class EntityComponentCall extends EntityCall { + constructor(ecpId: number, eid: number) { + super() + this.id = eid; + this.className = getQualifiedClassName(this); + } + } export class DATATYPE_UINT8 { bind() { @@ -1941,24 +2126,7 @@ namespace KBEngine { return typeof (v) == "string"; } } - export class DATATYPE_ENTITY_COMPONENT { - bind() { - } - - createFromStream(stream) { - } - - addToStream(stream, v) { - } - parseDefaultValStr(v) { - return new Uint8Array(0);; - } - - isSameType(v) { - return false; - } - } export class DATATYPE_ENTITYCALL { bind() { } @@ -2107,7 +2275,6 @@ namespace KBEngine { // export const PY_LIST = new DATATYPE_PYTHON(); export const UNICODE = new DATATYPE_UNICODE(); export const ENTITYCALL = new DATATYPE_ENTITYCALL(); - export const ENTITY_COMPONENT = new DATATYPE_ENTITY_COMPONENT(); export const BLOB = new DATATYPE_BLOB(); }; } @@ -3003,7 +3170,7 @@ namespace KBEngine { let defaultValStr = infos[3]; let utype = infos[4]; - if (defmethod != undefined) + if (defmethod != undefined && utype) defmethod.prototype[n] = utype.parseDefaultValStr(defaultValStr); }; @@ -3378,6 +3545,7 @@ namespace KBEngine { } entity.__init__(); + entity.attachComponents(); entity.inited = true; if (app.args.isOnInitCallPropertysSetMethods) @@ -3416,7 +3584,7 @@ namespace KBEngine { if (entity == undefined) { let entityMessage = bufferedCreateEntityMessages[eid]; if (entityMessage != undefined) { - ERROR_MSG("KBEngineApp::Client_onUpdatePropertys: entity(" + eid + ") not found!"); + ERROR_MSG("KBEngineApp::Client_onUpdEntityComponentatePropertys: entity(" + eid + ") not found!"); return; } @@ -3426,40 +3594,7 @@ namespace KBEngine { bufferedCreateEntityMessages[eid] = stream1; return; } - - let currModule = moduledefs[entity.className]; - let pdatas = currModule.propertys; - let componentUID; - while (stream.length() > 0) { - let utype = 0; - if (currModule.usePropertyDescrAlias) { - componentUID = stream.readInt8(); - utype = stream.readUint8(); - } else { - componentUID = stream.readUint16() - utype = stream.readUint16(); - } - let propertydata = pdatas[utype]; - let setmethod = propertydata[5]; - let flags = propertydata[6]; - let val = propertydata[4].createFromStream(stream); - let oldval = entity[propertydata[2]]; - - INFO_MSG("KBEngineApp::Client_onUpdatePropertys: " + entity.className + "(id=" + eid + " " + propertydata[2] + ", val=" + val + ")!"); - - entity[propertydata[2]] = val; - if (setmethod != null) { - // base类属性或者进入世界后cell类属性会触发set_*方法 - if (flags == 0x00000020 || flags == 0x00000040) { - if (entity.inited) - setmethod.call(entity, oldval); - } - else { - if (entity.inWorld) - setmethod.call(entity, oldval); - } - } - } + entity.onUpdatePropertys(stream) } Client_onUpdatePropertysOptimized(stream) { let eid = app.getViewEntityIDFromStream(stream); @@ -3556,6 +3691,7 @@ namespace KBEngine { // entity.isOnGround = isOnGround > 0; entity.isOnGround = isOnGround; entity.__init__(); + entity.attachComponents(); entity.inited = true; entity.inWorld = true; entity.enterWorld(); diff --git a/kbengine_ts/tsconfig.json b/kbengine_ts/tsconfig.json index c56a267..b2ccbcd 100644 --- a/kbengine_ts/tsconfig.json +++ b/kbengine_ts/tsconfig.json @@ -5,13 +5,13 @@ "sourceMap": false, "declaration": true, "experimentalDecorators": true, - "outFile": "bin/kbengine.js" + "outFile": "kbengine/kbengine.js" }, "include": [ "libs", "src" ], "exclude": [ - "bin" + "kbengine" ] } \ No newline at end of file From 1064bd4a3fa98db5ffc8d2758891f2307e7eda26 Mon Sep 17 00:00:00 2001 From: zengmingnan Date: Thu, 6 Jun 2019 09:54:39 +0800 Subject: [PATCH 17/17] =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84baseCall?= =?UTF-8?q?=E5=92=8CcellCall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kbengine_ts/kbengine/kbengine.d.ts | 13 +- kbengine_ts/kbengine/kbengine.js | 156 +++++++++++++++++++----- kbengine_ts/kbengine/kbengine.min.js | 6 +- kbengine_ts/src/KBEngine.ts | 170 ++++++++++++++++++++++----- 4 files changed, 279 insertions(+), 66 deletions(-) diff --git a/kbengine_ts/kbengine/kbengine.d.ts b/kbengine_ts/kbengine/kbengine.d.ts index 880ed7e..1d33cfe 100644 --- a/kbengine_ts/kbengine/kbengine.d.ts +++ b/kbengine_ts/kbengine/kbengine.d.ts @@ -304,6 +304,7 @@ declare namespace KBEngine { onUpdateVolatileData(): void; onUpdatePropertys(stream: MemoryStream): void; set_direction(old: any): void; + onRemoteMethodCall(stream: MemoryStream): void; } function registerEntity(): (ctor: new () => Entity) => void; } @@ -314,15 +315,18 @@ declare namespace KBEngine { componentType: number; ownerID: number; owner: Entity; - name_: string; + className: string; base: EntityComponentCall; cell: EntityComponentCall; protected onAttached(owner: Entity): void; protected onDetached(owner: Entity): void; protected onEnterWorld(): void; protected onLeaveWorld(): void; + baseCall(type: string, ...params: any[]): void; + cellCall(type: string, ...params: any[]): void; onUpdatePropertys(propUtype: number, stream: MemoryStream, maxCount: number): void; - createFromStream(stream: MemoryStream): void; + onRemoteMethodCall(propUtype: number, stream: MemoryStream): void; + createFromStream(stream: MemoryStream, ecpId: number): void; } function registerComponent(): (ctor: new () => EntityComponent) => void; } @@ -339,10 +343,11 @@ declare namespace KBEngine { isBase(): boolean; isCell(): boolean; newCall(): any; - sendCall(bundle: any): void; + sendCall(bundle?: Bundle): void; } class EntityComponentCall extends EntityCall { - constructor(ecpId: number, eid: number); + entityComponentPropertyID: number; + constructor(ecpId: number, eid: number, className: string); } class DATATYPE_UINT8 { bind(): void; diff --git a/kbengine_ts/kbengine/kbengine.js b/kbengine_ts/kbengine/kbengine.js index 33d4345..6e0be4b 100644 --- a/kbengine_ts/kbengine/kbengine.js +++ b/kbengine_ts/kbengine/kbengine.js @@ -1451,7 +1451,7 @@ if (!ArrayBuffer['transfer']) { var flags = propertydata[6]; if (!propertydata[4]) { if (this[propertydata[2]] && typeof this[propertydata[2]].createFromStream === 'function') - this[propertydata[2]].createFromStream(stream); + this[propertydata[2]].createFromStream(stream, propertydata[0]); continue; } var val = propertydata[4].createFromStream(stream); @@ -1475,6 +1475,29 @@ if (!ArrayBuffer['transfer']) { KBEngine.DEBUG_MSG(this.className + "::set_direction: " + this.direction); KBEngine.Event.fire("set_direction", this); }; + Entity.prototype.onRemoteMethodCall = function (stream) { + var sm = KBEngine.moduledefs[this.className]; + var ComponentID = sm.usePropertyDescrAlias ? stream.readUint8() : stream.readUint16(); + var methodUtype = sm.useMethodDescrAlias ? stream.readUint8() : stream.readUint16(); + if (ComponentID !== 0) { + var comp = this[sm.propertys[ComponentID][2]]; + if (comp) + comp.onRemoteMethodCall(methodUtype, stream); + return; + } + var methoddata = KBEngine.moduledefs[this.className].methods[methodUtype]; + var args = []; + var argsdata = methoddata[3]; + for (var i = 0; i < argsdata.length; i++) { + args.push(argsdata[i].createFromStream(stream)); + } + if (this[methoddata[2]] != undefined) { + this[methoddata[2]].apply(this, args); + } + else { + KBEngine.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + this.id + ") not found method(" + methoddata[2] + ")!"); + } + }; return Entity; }()); KBEngine.Entity = Entity; @@ -1496,7 +1519,7 @@ if (!ArrayBuffer['transfer']) { this.componentType = 0; this.ownerID = 0; this.owner = null; - this.name_ = ''; + this.className = ''; this.base = null; this.cell = null; } @@ -1504,6 +1527,90 @@ if (!ArrayBuffer['transfer']) { EntityComponent.prototype.onDetached = function (owner) { }; EntityComponent.prototype.onEnterWorld = function () { }; EntityComponent.prototype.onLeaveWorld = function () { }; + EntityComponent.prototype.baseCall = function (type) { + var params = []; + for (var _i = 1; _i < arguments.length; _i++) { + params[_i - 1] = arguments[_i]; + } + var className = this.className; + if (this.base == undefined) { + KBEngine.ERROR_MSG('Entity::baseCall: base is None!'); + return; + } + var method = KBEngine.moduledefs[className].base_methods[type]; + if (method == undefined) { + KBEngine.ERROR_MSG("Entity::baseCall: The server did not find the def_method(" + className + "." + type + ")!"); + return; + } + var methodID = method[0]; + var args = method[3]; + if (params.length != args.length) { + KBEngine.ERROR_MSG("Entity::baseCall: args(" + (params.length - 1) + "!= " + args.length + ") size is error!"); + return; + } + this.base.newCall(); + this.base.bundle.writeUint16(this.entityComponentPropertyID); + this.base.bundle.writeUint16(methodID); + try { + for (var i = 0; i < params.length; i++) { + if (args[i].isSameType(params[i])) { + args[i].addToStream(this.base.bundle, params[i]); + } + else { + throw new Error("Entity::baseCall: arg[" + i + "] is error!"); + } + } + } + catch (e) { + KBEngine.ERROR_MSG(e.toString()); + KBEngine.ERROR_MSG('Entity::baseCall: args is error!'); + this.base.bundle = null; + return; + } + this.base.sendCall(); + }; + EntityComponent.prototype.cellCall = function (type) { + var params = []; + for (var _i = 1; _i < arguments.length; _i++) { + params[_i - 1] = arguments[_i]; + } + var className = this.className; + if (this.cell == undefined) { + KBEngine.ERROR_MSG('Entity::cellCall: cell is None!'); + return; + } + var method = KBEngine.moduledefs[className].cell_methods[type]; + if (method == undefined) { + KBEngine.ERROR_MSG("Entity::cellCall: The server did not find the def_method(" + className + "." + type + ")!"); + return; + } + var methodID = method[0]; + var args = method[3]; + if (params.length != args.length) { + KBEngine.ERROR_MSG("Entity::cellCall: args(" + (params.length) + "!= " + args.length + ") size is error!"); + return; + } + this.cell.newCall(); + this.cell.bundle.writeUint16(this.entityComponentPropertyID); + this.cell.bundle.writeUint16(methodID); + try { + for (var i = 0; i < args.length; i++) { + if (args[i].isSameType(params[i])) { + args[i].addToStream(this.cell.bundle, params[i]); + } + else { + throw new Error("Entity::cellCall: arg[" + i + "] is error!"); + } + } + } + catch (e) { + KBEngine.ERROR_MSG(e.toString()); + KBEngine.ERROR_MSG('Entity::cellCall: args is error!'); + this.cell.bundle = null; + return; + } + this.cell.sendCall(); + }; EntityComponent.prototype.onUpdatePropertys = function (propUtype, stream, maxCount) { var className = KBEngine.getQualifiedClassName(this); var currModule = KBEngine.moduledefs[className]; @@ -1540,7 +1647,17 @@ if (!ArrayBuffer['transfer']) { } } }; - EntityComponent.prototype.createFromStream = function (stream) { + EntityComponent.prototype.onRemoteMethodCall = function (propUtype, stream) { + var sm = KBEngine.moduledefs[this.className].methods[propUtype]; + var args = []; + var argsdata = sm[3]; + for (var i = 0; i < argsdata.length; i++) { + args.push(argsdata[i].createFromStream(stream)); + } + typeof this[sm[2]] === 'function' && this[sm[2]].apply(this, args); + }; + EntityComponent.prototype.createFromStream = function (stream, ecpId) { + this.entityComponentPropertyID = ecpId; this.componentType = stream.readInt32(); this.ownerID = stream.readInt32(); this.owner = KBEngine.app.entities[this.ownerID]; @@ -1550,9 +1667,10 @@ if (!ArrayBuffer['transfer']) { if (count > 0) { this.onUpdatePropertys(0, stream, count); } - this.base = new KBEngine.EntityComponentCall(this.entityComponentPropertyID, this.ownerID); + this.className = KBEngine.getQualifiedClassName(this); + this.base = new KBEngine.EntityComponentCall(this.entityComponentPropertyID, this.ownerID, this.className); this.base.type = KBEngine.ENTITYCALL_TYPE_BASE; - this.cell = new KBEngine.EntityComponentCall(this.entityComponentPropertyID, this.ownerID); + this.cell = new KBEngine.EntityComponentCall(this.entityComponentPropertyID, this.ownerID, this.className); this.cell.type = KBEngine.ENTITYCALL_TYPE_CELL; }; return EntityComponent; @@ -1611,10 +1729,12 @@ if (!ArrayBuffer['transfer']) { __reflect(EntityCall.prototype, "KBEngine.EntityCall"); var EntityComponentCall = (function (_super) { __extends(EntityComponentCall, _super); - function EntityComponentCall(ecpId, eid) { + function EntityComponentCall(ecpId, eid, className) { var _this = _super.call(this) || this; + _this.entityComponentPropertyID = 0; + _this.entityComponentPropertyID = ecpId; _this.id = eid; - _this.className = KBEngine.getQualifiedClassName(_this); + _this.className = className; return _this; } return EntityComponentCall; @@ -3356,27 +3476,7 @@ if (!ArrayBuffer['transfer']) { KBEngine.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); return; } - var methodUtype = 0, ComponentID = 0; - if (KBEngine.moduledefs[entity.className].useMethodDescrAlias) { - ComponentID = stream.readInt8(); - methodUtype = stream.readUint8(); - } - else { - ComponentID = stream.readUint16(); - methodUtype = stream.readUint16(); - } - var methoddata = KBEngine.moduledefs[entity.className].methods[methodUtype]; - var args = []; - var argsdata = methoddata[3]; - for (var i = 0; i < argsdata.length; i++) { - args.push(argsdata[i].createFromStream(stream)); - } - if (entity[methoddata[2]] != undefined) { - entity[methoddata[2]].apply(entity, args); - } - else { - KBEngine.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found method(" + methoddata[2] + ")!"); - } + entity.onRemoteMethodCall(stream); }; KBEngineApp.prototype.Client_onRemoteMethodCallOptimized = function (stream) { var eid = KBEngine.app.getViewEntityIDFromStream(stream); diff --git a/kbengine_ts/kbengine/kbengine.min.js b/kbengine_ts/kbengine/kbengine.min.js index c82cf04..cb84a38 100644 --- a/kbengine_ts/kbengine/kbengine.min.js +++ b/kbengine_ts/kbengine/kbengine.min.js @@ -1,3 +1,3 @@ -var __reflect=this&&this.__reflect||function(t,e,n){t.__class__=e,n?n.push(e):n=[e],t.__types__=t.__types__?n.concat(t.__types__):n},__extends=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);n.prototype=e.prototype,t.prototype=new n},KBEngine;!function(t){t.CLIENT_VERSION="2.5.0",t.CLIENT_SCRIPT_VERSION="0.1.0",t.PACKET_MAX_SIZE=1500,t.PACKET_MAX_SIZE_TCP=1460,t.PACKET_MAX_SIZE_UDP=1472,t.MESSAGE_ID_LENGTH=2,t.MESSAGE_LENGTH_LENGTH=2,t.MESSAGE_LENGTH1_LENGTH=4,t.MESSAGE_MAX_SIZE=65535,t.CLIENT_NO_FLOAT=0,t.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,ArrayBuffer.transfer||(ArrayBuffer.transfer=function(t,e){var n=new ArrayBuffer(e);if(!(t instanceof ArrayBuffer&&n instanceof ArrayBuffer))throw new TypeError("ArrayBuffer.transfer, error: Source and destination must be ArrayBuffer instances");if(!(n.byteLength>=t.byteLength))throw new RangeError("ArrayBuffer.transfer, error: destination has not enough space");var r=new Uint8Array(n);return r.set(new Uint8Array(t),0),n}),function(t){var e=function(){function t(t,e){this.sign=1,this.lo=t,this.hi=e,e>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return t.prototype.toString=function(){var t="";this.sign<0&&(t+="-");var e=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){t+=n;for(var r=8-e.length;r>0;--r)t+="0"}return t+=e},t}();t.INT64=e,__reflect(e.prototype,"KBEngine.INT64");var n=function(){function t(t,e){this.lo=t,this.hi=e}return t.prototype.toString=function(){var t=this.lo.toString(16),e=this.hi.toString(16),n="";if(this.hi>0){n+=e;for(var r=8-t.length;r>0;--r)n+="0"}return n+=t},t}();t.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(t){function e(t){var e=typeof t;if(!t||"object"!=e&&!t.prototype)return e;var n=t.prototype?t.prototype:Object.getPrototypeOf(t);if(n.hasOwnProperty("__class__"))return n.__class__;var r=n.constructor.toString().trim(),a=r.indexOf("("),i=r.substring(9,a),o=i.split(".");return Object.defineProperty(n,"__class__",{value:o[o.length-1],enumerable:!1,writable:!0}),o[o.length-1]}t.getQualifiedClassName=e}(KBEngine||(KBEngine={})),function(t){function e(){for(var t=[],e=0;en;)switch(a=t[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:e+=String.fromCharCode(a);break;case 12:case 13:i=t[n++],e+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=t[n++],o=t[n++],e+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return e}function n(t){for(var e=[],n=0;nr?e.push(r):2048>r?e.push(192|r>>6,128|63&r):55296>r||r>=57344?e.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&t.charCodeAt(n)),e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return e}t.utf8ArrayToString=e,t.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(t){var e=function(){function t(t,e){this.classinst=t,this.callbackfn=e}return t}();t.EventInfo=e,__reflect(e.prototype,"KBEngine.EventInfo");var n=function(){function t(t,e,n){this.evtName=t,this.evtInfo=e,this.ars=n}return t}();t.FiredEvent=n,__reflect(n.prototype,"KBEngine.FiredEvent");var r=function(){function r(){this._events={},this._isPause=!1,this._firedEvents=[]}return r.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void t.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new e(r,i);o.push(p)},r.prototype.deregisterAll=function(t){for(var e in this._events)this.deregister(e,t)},r.prototype.deregister=function(t,e){var n=this._events[t];if(n)for(var r=n.length-1;r>=0;r--){var a=n[r];a.classinst==e&&n.splice(r,1)}},r.prototype.removeAllFiredEvent=function(t){this.removeFiredEvent("",t)},r.prototype.removeFiredEvent=function(t,e){for(var n=this._firedEvents,r=n.length-1;r>=0;r--){var a=n[r];""!=t&&a.evtName!=t||a.evtInfo.classinst!=e||n.splice(r,1)}},r.prototype.fire=function(e){for(var r=[],a=1;a0;){var e=t.shift(),n=e.evtInfo,r=e.ars;r.length<1?n.callbackfn.apply(n.classinst):n.callbackfn.apply(n.classinst,r)}},r.prototype.clear=function(){this._events={},this._firedEvents.splice(0,this._firedEvents.length)},r}();t.Events=r,__reflect(r.prototype,"KBEngine.Events"),t.Event=new r}(KBEngine||(KBEngine={})),function(t){var e=function(){function t(){this._unionData=new ArrayBuffer(4),this.fv=new Float32Array(this._unionData,0,1),this.uv=new Uint32Array(this._unionData,0,1),this.iv=new Int32Array(this._unionData,0,1)}return t}();t.PackFloatXType=e,__reflect(e.prototype,"KBEngine.PackFloatXType"),t._xPackData=new e,t._yPackData=new e,t._zPackData=new e;var n=function(){function e(t){this.rpos=0,this.wpos=0,t instanceof ArrayBuffer?this.buffer=t:this.buffer=new ArrayBuffer(t),this.rpos=0,this.wpos=0}return e.prototype.readInt8=function(){var t=new Int8Array(this.buffer,this.rpos,1);return this.rpos+=1,t[0]},e.prototype.readInt16=function(){var t=this.readUint16();return t>=32768&&(t-=65536),t},e.prototype.readInt32=function(){var t=this.readUint32();return t>=2147483648&&(t-=4294967296),t},e.prototype.readInt64=function(){var e=this.readUint32(),n=this.readUint32();return new t.INT64(e,n)},e.prototype.readUint8=function(){var t=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,t[0]},e.prototype.readUint16=function(){var t=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&t[1])<<8)+(255&t[0])},e.prototype.readUint32=function(){var t=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(t[3]<<24)+(t[2]<<16)+(t[1]<<8)+t[0]},e.prototype.readUint64=function(){var e=this.readUint32(),n=this.readUint32();return new t.UINT64(e,n)},e.prototype.readFloat=function(){var t;try{t=new Float32Array(this.buffer,this.rpos,1)}catch(e){t=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,t[0]},e.prototype.readDouble=function(){var t;try{t=new Float64Array(this.buffer,this.rpos,1)}catch(e){t=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,t[0]},e.prototype.readString=function(){for(var t=new Uint8Array(this.buffer,this.rpos),e=0,n="";;){if(0==t[e]){e++;break}if(n+=String.fromCharCode(t[e]),e++,this.rpos+e>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+e)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=e,n},e.prototype.readBlob=function(){var t=this.readUint32(),e=new Uint8Array(this.buffer,this.rpos,t);return this.rpos+=t,e},e.prototype.readStream=function(){var t=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new e(t)},e.prototype.readPackXZ=function(){var e=t._xPackData,n=t._zPackData;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},e.prototype.readPackY=function(){var e=this.readUint16(),n=t._yPackData;return n.uv[0]=1073741824,n.uv[0]|=(32767&e)<<12,n.fv[0]-=2,n.uv[0]|=(32768&e)<<16,n.fv[0]},e.prototype.writeInt8=function(t){var e=new Int8Array(this.buffer,this.wpos,1);e[0]=t,this.wpos+=1},e.prototype.writeInt16=function(t){this.writeInt8(255&t),this.writeInt8(t>>8&255)},e.prototype.writeInt32=function(t){for(var e=0;4>e;e++)this.writeInt8(t>>8*e&255)},e.prototype.writeInt64=function(t){this.writeInt32(t.lo),this.writeInt32(t.hi)},e.prototype.writeUint8=function(t){var e=new Uint8Array(this.buffer,this.wpos,1);e[0]=t,this.wpos+=1},e.prototype.writeUint16=function(t){this.writeUint8(255&t),this.writeUint8(t>>8&255)},e.prototype.writeUint32=function(t){for(var e=0;4>e;e++)this.writeUint8(t>>8*e&255)},e.prototype.writeUint64=function(t){this.writeUint32(t.lo),this.writeUint32(t.hi)},e.prototype.writeFloat=function(t){try{var e=new Float32Array(this.buffer,this.wpos,1);e[0]=t}catch(n){var e=new Float32Array(1);e[0]=t;var r=new Uint8Array(this.buffer),a=new Uint8Array(e.buffer);r.set(a,this.wpos)}this.wpos+=4},e.prototype.writeDouble=function(t){try{var e=new Float64Array(this.buffer,this.wpos,1);e[0]=t}catch(n){var e=new Float64Array(1);e[0]=t;var r=new Uint8Array(this.buffer),a=new Uint8Array(e.buffer);r.set(a,this.wpos)}this.wpos+=8},e.prototype.writeBlob=function(e){var n=e.length;if(n+4>this.space())return void t.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof e)for(var a=0;n>a;a++)r[a]=e.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=e[a];this.wpos+=n},e.prototype.writeString=function(e){if(e.length>this.space())return void t.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;athis.space()&&(this.buffer=ArrayBuffer.transfer(this.buffer,this.buffer.byteLength+2*n));var r=new Uint8Array(this.buffer,this.wpos,n);r.set(new Uint8Array(t.buffer,e,n),0),this.wpos+=n},e.prototype.readSkip=function(t){this.rpos+=t},e.prototype.space=function(){return this.buffer.byteLength-this.wpos},e.prototype.length=function(){return this.wpos-this.rpos},e.prototype.readEOF=function(){return this.buffer.byteLength-this.rpos<=0},e.prototype.done=function(){this.rpos=this.wpos},e.prototype.getbuffer=function(){return this.buffer.slice(this.rpos,this.wpos)},e.prototype.setbuffer=function(t){this.clear(),this.buffer=t},e.prototype.size=function(){return this.buffer.byteLength},e.prototype.clear=function(){this.rpos=this.wpos=0,this.buffer.byteLength>t.PACKET_MAX_SIZE&&(this.buffer=new ArrayBuffer(t.PACKET_MAX_SIZE))},e.prototype.reclaimObject=function(){this.clear(),void 0!=e._objects&&e._objects.push(this)},e}();t.MemoryStream=n,__reflect(n.prototype,"KBEngine.MemoryStream"),function(e){function n(){return e._objects.length>0?e._objects.pop():new e(t.PACKET_MAX_SIZE_TCP)}e._objects=[],e.createObject=n}(n=t.MemoryStream||(t.MemoryStream={}))}(KBEngine||(KBEngine={})),function(t){function e(){t.datatype2id={},t.datatype2id.STRING=1,t.datatype2id["STD::STRING"]=1,t.datatype2id.UINT8=2,t.datatype2id.BOOL=2,t.datatype2id.DATATYPE=2,t.datatype2id.CHAR=2,t.datatype2id.DETAIL_TYPE=2,t.datatype2id.ENTITYCALL_CALL_TYPE=2,t.datatype2id.UINT16=3,t.datatype2id["UNSIGNED SHORT"]=3,t.datatype2id.SERVER_ERROR_CODE=3,t.datatype2id.ENTITY_TYPE=3,t.datatype2id.ENTITY_PROPERTY_UID=3,t.datatype2id.ENTITY_METHOD_UID=3,t.datatype2id.ENTITY_SCRIPT_UID=3,t.datatype2id.DATATYPE_UID=3,t.datatype2id.UINT32=4,t.datatype2id.UINT=4,t.datatype2id["UNSIGNED INT"]=4,t.datatype2id.ARRAYSIZE=4,t.datatype2id.SPACE_ID=4,t.datatype2id.GAME_TIME=4,t.datatype2id.TIMER_ID=4,t.datatype2id.UINT64=5,t.datatype2id.DBID=5,t.datatype2id.COMPONENT_ID=5,t.datatype2id.INT8=6,t.datatype2id.COMPONENT_ORDER=6,t.datatype2id.INT16=7,t.datatype2id.SHORT=7,t.datatype2id.INT32=8,t.datatype2id.INT=8,t.datatype2id.ENTITY_ID=8,t.datatype2id.CALLBACK_ID=8,t.datatype2id.COMPONENT_TYPE=8,t.datatype2id.INT64=9,t.datatype2id.PYTHON=10,t.datatype2id.PY_DICT=10,t.datatype2id.PY_TUPLE=10,t.datatype2id.PY_LIST=10,t.datatype2id.ENTITYCALL=10,t.datatype2id.BLOB=11,t.datatype2id.UNICODE=12,t.datatype2id.FLOAT=13,t.datatype2id.DOUBLE=14,t.datatype2id.VECTOR2=15,t.datatype2id.VECTOR3=16,t.datatype2id.VECTOR4=17,t.datatype2id.FIXED_DICT=18,t.datatype2id.ARRAY=19,t.datatype2id.ENTITYCALL=20}function n(e,n){switch(n){case t.datatype2id.UINT8:return e.writeUint8;case t.datatype2id.UINT16:return e.writeUint16;case t.datatype2id.UINT32:return e.writeUint32;case t.datatype2id.UINT64:return e.writeUint64;case t.datatype2id.INT8:return e.writeInt8;case t.datatype2id.INT16:return e.writeInt16;case t.datatype2id.INT32:return e.writeInt32;case t.datatype2id.INT64:return e.writeInt64;case t.datatype2id.FLOAT:return e.writeFloat;case t.datatype2id.DOUBLE:return e.writeDouble;case t.datatype2id.STRING:return e.writeString;case t.datatype2id.FIXED_DICT:return e.writeStream;case t.datatype2id.ARRAY:return e.writeStream;default:return e.writeStream}}function r(e){switch(e){case t.datatype2id.UINT8:return t.reader.readUint8;case t.datatype2id.UINT16:return t.reader.readUint16;case t.datatype2id.UINT32:return t.reader.readUint32;case t.datatype2id.UINT64:return t.reader.readUint64;case t.datatype2id.INT8:return t.reader.readInt8;case t.datatype2id.INT16:return t.reader.readInt16;case t.datatype2id.INT32:return t.reader.readInt32;case t.datatype2id.INT64:return t.reader.readInt64;case t.datatype2id.FLOAT:return t.reader.readFloat;case t.datatype2id.DOUBLE:return t.reader.readDouble;case t.datatype2id.STRING:return t.reader.readString;case t.datatype2id.FIXED_DICT:return t.reader.readStream;case t.datatype2id.ARRAY:return t.reader.readStream;default:return t.reader.readStream}}var a=function(){function e(){this.memorystreams=new Array,this.numMessage=0,this.messageLengthBuffer=null,this.msgtype=null,this.messageLength=0,this.stream=t.MemoryStream.createObject()}return e.createObject=function(){return e._objects.length>0?e._objects.pop():new e},e.prototype.newMessage=function(e){this.fini(!1),this.msgtype=e,this.numMessage+=1,-1==this.msgtype.length&&(this.messageLengthBuffer=new Uint8Array(this.stream.buffer,this.stream.wpos+t.MESSAGE_ID_LENGTH,2)),this.writeUint16(e.id),this.messageLengthBuffer&&(this.writeUint16(0),this.messageLengthBuffer[0]=0,this.messageLengthBuffer[1]=0,this.messageLength=0)},e.prototype.writeMsgLength=function(t){this.messageLengthBuffer&&(this.messageLengthBuffer[0]=255&t,this.messageLengthBuffer[1]=t>>8&255)},e.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream),this.stream=t.MemoryStream.createObject()),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},e.prototype.send=function(t){this.fini(!0);for(var e=0;ethis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=t.MemoryStream.createObject()),this.messageLength+=e},e.prototype.writeInt8=function(t){this.checkStream(1),this.stream.writeInt8(t)},e.prototype.writeInt16=function(t){this.checkStream(2),this.stream.writeInt16(t)},e.prototype.writeInt32=function(t){this.checkStream(4),this.stream.writeInt32(t)},e.prototype.writeInt64=function(t){this.checkStream(8),this.stream.writeInt64(t)},e.prototype.writeUint8=function(t){this.checkStream(1),this.stream.writeUint8(t)},e.prototype.writeUint16=function(t){this.checkStream(2),this.stream.writeUint16(t)},e.prototype.writeUint32=function(t){this.checkStream(4),this.stream.writeUint32(t)},e.prototype.writeUint64=function(t){this.checkStream(8),this.stream.writeUint64(t)},e.prototype.writeFloat=function(t){this.checkStream(4),this.stream.writeFloat(t)},e.prototype.writeDouble=function(t){this.checkStream(8),this.stream.writeDouble(t)},e.prototype.writeString=function(t){this.checkStream(t.length+1),this.stream.writeString(t)},e.prototype.writeBlob=function(t){this.checkStream(t.length+4),this.stream.writeBlob(t)},e.prototype.clear=function(){for(var e=0;en){var r=e;e=n,n=r}return e>t?e:n>t?t:n}function n(t,e){return t*(Math.PI/(e?254:128))}function r(t,n){var r=0;return r=n?e(Math.floor(254*t/Math.PI+.5),-128,127):Math.floor(128*t/Math.PI+.5)}var a=function(){function t(t,e){this.x=t,this.y=e}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y;return Math.sqrt(e*e+n*n)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this},t}();t.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function t(t,e,n){this.x=t,this.y=e,this.z=n,this.x=t,this.y=e,this.z=n}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y,r=t.z-this.z;return Math.sqrt(e*e+n*n+r*r)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},t}();t.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function t(t,e,n,r){this.x=t,this.y=e,this.z=n,this.w=r,this.x=t,this.y=e,this.z=n,this.w=r}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y,r=t.z-this.z,a=t.w-this.w;return Math.sqrt(e*e+n*n+r*r+a*a)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this.w/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this},t}();t.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),t.clampf=e,t.int82angle=n,t.angle2int8=r}(KBEngine||(KBEngine={})),function(t){function e(){return function(e){var n=t.getQualifiedClassName(e);t.Entities[n]=e}}t.Entities={};var n=function(){function e(){this.__comps__={},this.id=0,this.className="",this.position=new t.Vector3(0,0,0),this.direction=new t.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new t.Vector3(0,0,0),this.entityLastLocalDir=new t.Vector3(0,0,0),this.isOnGround=!1;for(var e in this.__comps__)this[e]=new this.__comps__[e]}return e.prototype.__init__=function(){},e.prototype.attachComponents=function(){for(var t in this.__comps__)this[t].onAttached(this)},e.prototype.getComponents=function(e,n){void 0===n&&(n=!1);var r=[];for(var a in this.__comps__)if(t.getQualifiedClassName(this.__comps__[a])===e){if(!n)return this[a];r.push(this[a])}return r},e.prototype.detachComponents=function(){for(var t in this.__comps__)this[t].onDetached(this)},e.prototype.callPropertysSetMethods=function(){var e=t.moduledefs[this.className];for(var n in e.propertys){var r=e.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},e.prototype.onDestroy=function(){this.detachComponents()},e.prototype.onControlled=function(t){},e.prototype.isPlayer=function(){return this.id==t.app.entity_id},e.prototype.baseCall=function(e){for(var n=[],r=1;r0;){var a=0,i=0;if(n.usePropertyDescrAlias?(i=e.readUint8(),a=e.readUint8()):(i=e.readUint16(),a=e.readUint16()),0===i){var o=r[a],p=o[5],s=o[6];if(o[4]){var l=o[4].createFromStream(e),c=this[o[2]];t.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+this.className+"(id="+this.id+" "+o[2]+", val="+l+")!"),this[o[2]]=l,null!=p&&(32==s||64==s?this.inited&&p.call(this,c):this.inWorld&&p.call(this,c))}else this[o[2]]&&"function"==typeof this[o[2]].createFromStream&&this[o[2]].createFromStream(e)}else{var d=r[i];this[d[2]]&&this[d[2]].onUpdatePropertys(a,e,-1)}}},e.prototype.set_direction=function(e){t.DEBUG_MSG(this.className+"::set_direction: "+this.direction),t.Event.fire("set_direction",this)},e}();t.Entity=n,__reflect(n.prototype,"KBEngine.Entity"),t.registerEntity=e}(KBEngine||(KBEngine={})),function(t){function e(){return function(e){var n=t.getQualifiedClassName(e);t.Entities[n]=e}}var n=function(){function e(){this.id=0,this.entityComponentPropertyID=0,this.componentType=0,this.ownerID=0,this.owner=null,this.name_="",this.base=null,this.cell=null}return e.prototype.onAttached=function(t){},e.prototype.onDetached=function(t){},e.prototype.onEnterWorld=function(){},e.prototype.onLeaveWorld=function(){},e.prototype.onUpdatePropertys=function(e,n,r){for(var a=t.getQualifiedClassName(this),i=t.moduledefs[a],o=i.propertys;n.length()>0&&0!=r--;){var p=e,s=0;0===p&&(i.usePropertyDescrAlias?(s=n.readUint8(),p=n.readUint8()):(s=n.readUint16(),p=n.readUint16()));var l=o[p],c=l[5],d=l[6],u=l[4].createFromStream(n),y=this[l[2]];t.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+a+"(id="+this.id+" "+l[2]+", val="+u+")!"),this[l[2]]=u,null!=c&&(32==d||64==d?this.owner.inited&&c.call(this,y):this.owner.inWorld&&c.call(this,y))}},e.prototype.createFromStream=function(e){this.componentType=e.readInt32(),this.ownerID=e.readInt32(),this.owner=t.app.entities[this.ownerID],e.readUint16();var n=e.readUint16();n>0&&this.onUpdatePropertys(0,e,n),this.base=new t.EntityComponentCall(this.entityComponentPropertyID,this.ownerID),this.base.type=t.ENTITYCALL_TYPE_BASE,this.cell=new t.EntityComponentCall(this.entityComponentPropertyID,this.ownerID),this.cell.type=t.ENTITYCALL_TYPE_CELL},e}();t.EntityComponent=n,__reflect(n.prototype,"KBEngine.EntityComponent"),t.registerComponent=e}(KBEngine||(KBEngine={})),function(t){t.ENTITYCALL_TYPE_CELL=0,t.ENTITYCALL_TYPE_BASE=1;var e=function(){function e(){this.id=0,this.className="",this.type=t.ENTITYCALL_TYPE_CELL,this.networkInterface=t.app,this.bundle=null}return e.prototype.isBase=function(){return this.type==t.ENTITYCALL_TYPE_BASE},e.prototype.isCell=function(){return this.type==t.ENTITYCALL_TYPE_CELL},e.prototype.newCall=function(){return null==this.bundle&&(this.bundle=t.Bundle.createObject()),this.type==t.ENTITYCALL_TYPE_CELL?this.bundle.newMessage(t.messages.Baseapp_onRemoteCallCellMethodFromClient):this.bundle.newMessage(t.messages.Entity_onRemoteMethodCall),this.bundle.writeInt32(this.id),this.bundle},e.prototype.sendCall=function(t){void 0==t&&(t=this.bundle),t.send(this.networkInterface),this.bundle==t&&(this.bundle=null)},e}();t.EntityCall=e,__reflect(e.prototype,"KBEngine.EntityCall");var n=function(e){function n(n,r){var a=e.call(this)||this;return a.id=r,a.className=t.getQualifiedClassName(a),a}return __extends(n,e),n}(e);t.EntityComponentCall=n,__reflect(n.prototype,"KBEngine.EntityComponentCall");var r=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint8.call(e)},e.prototype.addToStream=function(t,e){t.writeUint8(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>255?!1:!0},e}();t.DATATYPE_UINT8=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT8");var a=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint16.call(e)},e.prototype.addToStream=function(t,e){t.writeUint16(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>65535?!1:!0},e}();t.DATATYPE_UINT16=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT16");var i=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint32.call(e)},e.prototype.addToStream=function(t,e){t.writeUint32(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>4294967295?!1:!0},e}();t.DATATYPE_UINT32=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT32");var o=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint64.call(e)},e.prototype.addToStream=function(t,e){t.writeUint64(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(e){return e instanceof t.UINT64},e}();t.DATATYPE_UINT64=o,__reflect(o.prototype,"KBEngine.DATATYPE_UINT64");var p=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt8.call(e)},e.prototype.addToStream=function(t,e){t.writeInt8(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-128>t||t>127?!1:!0},e}();t.DATATYPE_INT8=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT8");var s=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt16.call(e)},e.prototype.addToStream=function(t,e){t.writeInt16(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-32768>t||t>32767?!1:!0},e}();t.DATATYPE_INT16=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT16");var l=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt32.call(e)},e.prototype.addToStream=function(t,e){t.writeInt32(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-2147483648>t||t>2147483647?!1:!0},e}();t.DATATYPE_INT32=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT32");var c=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt64.call(e)},e.prototype.addToStream=function(t,e){t.writeInt64(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(e){return e instanceof t.INT64},e}();t.DATATYPE_INT64=c,__reflect(c.prototype,"KBEngine.DATATYPE_INT64");var d=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readFloat.call(e)},e.prototype.addToStream=function(t,e){t.writeFloat(e)},e.prototype.parseDefaultValStr=function(t){return parseFloat(t) -},e.prototype.isSameType=function(t){return"number"==typeof t},e}();t.DATATYPE_FLOAT=d,__reflect(d.prototype,"KBEngine.DATATYPE_FLOAT");var u=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.createFromStream=function(e){return t.reader.readDouble.call(e)},n.prototype.addToStream=function(t,e){t.writeDouble(e)},n}(d);t.DATATYPE_DOUBLE=u,__reflect(u.prototype,"KBEngine.DATATYPE_DOUBLE");var y=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readString.call(e)},e.prototype.addToStream=function(t,e){t.writeString(e)},e.prototype.parseDefaultValStr=function(t){return"string"==typeof t?t:""},e.prototype.isSameType=function(t){return"string"==typeof t},e}();t.DATATYPE_STRING=y,__reflect(y.prototype,"KBEngine.DATATYPE_STRING");var _=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){if(t.CLIENT_NO_FLOAT){var n=t.reader.readInt32.call(e),r=t.reader.readInt32.call(e);return new t.Vector2(n,r)}var n=t.reader.readFloat.call(e),r=t.reader.readFloat.call(e);return new t.Vector2(n,r)},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y)):(e.writeFloat(n.x),e.writeFloat(n.y))},e.prototype.parseDefaultValStr=function(e){return new t.Vector2(0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector2?!0:!1},e}();t.DATATYPE_VECTOR2=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.CLIENT_NO_FLOAT?new t.Vector3(t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e)):new t.Vector3(t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e))},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z))},e.prototype.parseDefaultValStr=function(e){return new t.Vector3(0,0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector3?!0:!1},e}();t.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var E=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.CLIENT_NO_FLOAT?new t.Vector4(t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e)):new t.Vector4(t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e))},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z),e.writeInt32(n.w)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z),e.writeFloat(n.w))},e.prototype.parseDefaultValStr=function(e){return new t.Vector4(0,0,0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector4?!0:!1},e}();t.DATATYPE_VECTOR4=E,__reflect(E.prototype,"KBEngine.DATATYPE_VECTOR4");var h=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return t.readBlob()},t.prototype.addToStream=function(t,e){t.writeBlob(e)},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_PYTHON=h,__reflect(h.prototype,"KBEngine.DATATYPE_PYTHON");var g=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.utf8ArrayToString(t.reader.readBlob.call(e))},e.prototype.addToStream=function(e,n){e.writeBlob(t.stringToUTF8Bytes(n))},e.prototype.parseDefaultValStr=function(t){return"string"==typeof t?t:""},e.prototype.isSameType=function(t){return"string"==typeof t},e}();t.DATATYPE_UNICODE=g,__reflect(g.prototype,"KBEngine.DATATYPE_UNICODE");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){},t.prototype.addToStream=function(t,e){},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_ENTITYCALL=m,__reflect(m.prototype,"KBEngine.DATATYPE_ENTITYCALL");var v=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){var n=t.reader.readUint32.call(e),r=new Uint8Array(e.buffer,e.rpos,n);return e.rpos+=n,r},e.prototype.addToStream=function(t,e){t.writeBlob(e)},e.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},e.prototype.isSameType=function(t){return!0},e}();t.DATATYPE_BLOB=v,__reflect(v.prototype,"KBEngine.DATATYPE_BLOB");var T=function(){function t(){this.type=null}return t.prototype.bind=function(){"number"==typeof this.type&&(this.type=A[this.type])},t.prototype.createFromStream=function(t){for(var e=t.readUint32(),n=[];e>0;)e--,n.push(this.type.createFromStream(t));return n},t.prototype.addToStream=function(t,e){t.writeUint32(e.length);for(var n=0;n0||null!=t.app.fragmentStream;)if(t.app.fragmentDatasFlag==t.FragmentDataTypes.FRAGMENT_DATA_UNKNOW){if(0==t.app.currMsgID){if(t.MESSAGE_ID_LENGTH>1&&n.length()=t.app.currMsgLen)r.handleMessage(t.app.fragmentStream),t.app.fragmentStream=null;else{if(n.length()0){t.app.writeFragmentMessage(t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY,n,t.app.currMsgLen);break}var i=n.wpos,o=n.rpos+a;n.wpos=o,r.handleMessage(n),n.wpos=i,n.rpos=o}t.app.currMsgID=0,t.app.currMsgLen=0,t.app.fragmentStream=null}else if(t.app.mergeFragmentMessage(n))break},e.prototype.writeFragmentMessage=function(e,n,r){var a=n.length();t.app.fragmentDatasRemain=r-a,t.app.fragmentDatasFlag=e,t.app.fragmentStream=n},e.prototype.mergeFragmentMessage=function(e){var n=e.length();if(0==n)return 0;var r=t.app.fragmentStream;if(n>=t.app.fragmentDatasRemain){switch(r.append(e,e.rpos,t.app.fragmentDatasRemain),t.app.fragmentDatasFlag){case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_ID:t.app.currMsgID=r.readUint16(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH:t.app.currMsgLen=r.readUint16(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH1:t.app.currMsgLen=r.readUint32(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY:}return e.rpos+=t.app.fragmentDatasRemain,t.app.fragmentDatasFlag=t.FragmentDataTypes.FRAGMENT_DATA_UNKNOW,t.app.fragmentDatasRemain=0,!1}return r.append(e,e.rpos,n),t.app.fragmentDatasRemain-=n,e.done(),!0},e.prototype.onclose=function(){t.INFO_MSG("connect close:"+t.app.currserver),t.app.currconnect==t.app.currstate&&(t.app.resetSocket(),t.Event.fire(t.EventTypes.onDisconnected))},e.prototype.send=function(e){t.app.socket.send(e)},e.prototype.close=function(){t.INFO_MSG("KBEngine::close()"),t.app.socket.close(),t.app.reset()},e.prototype.update=function(){if(null!=t.app.socket){var e=new Date;if((e.getTime()-t.app.lastTickTime)/1e3>t.app.args.serverHeartbeatTick/2){if(t.app.lastTickCBTime0;){n-=1;var r=new a;r.id=e.readUint16(),r.name=t.utf8ArrayToString(e.readBlob()),r.descr=t.utf8ArrayToString(e.readBlob()),t.app.serverErrs[r.id]=r,t.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},e.prototype.Client_onImportClientSdk=function(e){var n=e.readInt32(),r=e.readString(),a=e.readInt32(),i=e.readBlob();t.Event.fire("onImportClientSDK",n,r,a,i)},e.prototype.onOpenLoginapp_login=function(){if(t.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),t.Event.fire(t.EventTypes.onConnectionState,!0),t.app.currserver="loginapp",t.app.currstate="login",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),t.Event.fire("Loginapp_importClientMessages")}},e.prototype.onOpenLoginapp_createAccount=function(){if(t.Event.fire("onConnectionState",!0),t.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),t.app.currserver="loginapp",t.app.currstate="createAccount",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),t.Event.fire("Loginapp_importClientMessages")}},e.prototype.onImportClientMessagesCompleted=function(){if(t.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),t.app.socket.onmessage=t.app.onmessage,t.app.hello(),"loginapp"==t.app.currserver){if(!t.app.serverErrorsDescrImported){t.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),t.app.serverErrorsDescrImported=!0;var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importServerErrorsDescr),e.send(t.app)}"login"==t.app.currstate?t.app.login_loginapp(!1):"resetpassword"==t.app.currstate?t.app.resetpassword_loginapp(!1):t.app.createAccount_loginapp(!1),t.app.loginappMessageImported=!0}else if(t.app.baseappMessageImported=!0,t.app.entitydefImported)t.app.onImportEntityDefCompleted();else{t.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_importClientEntityDef),e.send(t.app),t.Event.fire("Baseapp_importClientEntityDef")}},e.prototype.createDataTypeFromStreams=function(e,n){var r=e.readUint16();for(t.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,t.app.createDataTypeFromStream(e,n);for(var a in t.datatypes)void 0!=t.datatypes[a]&&t.datatypes[a].bind()},e.prototype.createDataTypeFromStream=function(e,n){var r,a=e.readUint16(),i=e.readString(),o=e.readString();if(0==o.length&&(r="Null_"+a),n&&t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new t.DATATYPE_FIXED_DICT,s=e.readUint8();for(p.implementedBy=e.readString();s>0;){s--;var l=e.readString(),c=e.readUint16();p.dicttype[l]=c}t.datatypes[o]=p}else if("ARRAY"==i){var d=e.readUint16(),p=new t.DATATYPE_ARRAY;p.type=d,t.datatypes[o]=p}else t.datatypes[o]=t.datatypes[i];t.datatypes[a]=t.datatypes[o],t.datatype2id[o]=a},e.prototype.Client_onImportClientEntityDef=function(e){for(t.app.createDataTypeFromStreams(e,!0);e.length()>0;){var n=e.readString(),r=e.readUint16(),a=e.readUint16(),i=e.readUint16(),o=e.readUint16(),p=e.readUint16();t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),t.moduledefs[n]={};var s=t.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},t.moduledefs[r]=s;for(var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods,y=t.Entities[n];a>0;){a--;var _=e.readUint16(),f=e.readUint32(),E=e.readInt16(),h=e.readString(),g=e.readString(),m=t.datatypes[e.readUint16()],v=null;void 0!=y&&(v=y.prototype["set_"+h],void 0==v&&(v=null));var T=[_,E,h,g,m,v,f];l[h]=T,-1!=E?(l[E]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+h+"/"+_+").")}for(;i>0;){i--;for(var S=e.readUint16(),E=e.readInt16(),A=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);var T=[S,E,A,D];c[A]=T,-1!=E?(c[E]=T,s.useMethodDescrAlias=!0):(c[S]=T,s.useMethodDescrAlias=!1),t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+A+").")}for(;o>0;){o--;for(var S=e.readUint16(),E=e.readInt16(),M=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);d[M]=[S,E,M,D],t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+M+").")}for(;p>0;){p--;for(var S=e.readUint16(),E=e.readInt16(),F=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);u[F]=[S,E,F,D],t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+F+").")}var w=void 0;try{w=t.Entities[n]}catch(B){t.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),w=void 0}for(var C in s.propertys){var L=s.propertys[C],_=L[0],E=L[1],K=L[2],g=L[3],m=L[4];void 0!=w&&m&&(w.prototype[K]=m.parseDefaultValStr(g))}for(var b in s.methods){var L=s.methods[b],_=L[0],E=L[1],K=L[2],D=L[3];void 0!=w&&void 0==w.prototype[K]&&t.WARNING_MSG(n+":: method("+K+") no implement!")}}t.app.onImportEntityDefCompleted()},e.prototype.Client_onVersionNotMatch=function(e){t.app.serverVersion=e.readString(),t.ERROR_MSG("Client_onVersionNotMatch: verInfo="+t.app.clientVersion+" not match(server: "+t.app.serverVersion+")"),t.Event.fire(t.EventTypes.onVersionNotMatch,t.app.clientVersion,t.app.serverVersion)},e.prototype.Client_onScriptVersionNotMatch=function(e){t.app.serverScriptVersion=e.readString(),t.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+t.app.clientScriptVersion+" not match(server: "+t.app.serverScriptVersion+")"),t.Event.fire(t.EventTypes.onScriptVersionNotMatch,t.app.clientScriptVersion,t.app.serverScriptVersion)},e.prototype.onImportEntityDefCompleted=function(){t.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),t.app.entitydefImported=!0,t.app.login_baseapp(!1)},e.prototype.importClientMessages=function(e){for(;t.app.currMsgCount>0;){t.app.currMsgCount--;for(var n=e.readUint16(),r=e.readInt16(),a=e.readString(),i=e.readInt8(),o=e.readUint8(),p=new Array(o),s=0;o>s;s++)p[s]=e.readUint8();var l=null,c=a.indexOf("Client_")>=0;c&&(l=t.app[a],null==l||void 0==l?(t.WARNING_MSG("KBEngineApp::onImportClientMessages["+t.app.currserver+"]: interface("+a+"/"+n+") no implement!"),l=null):t.INFO_MSG("KBEngineApp::onImportClientMessages: import("+a+") successfully!")),a.length>0?(t.messages[a]=new t.Message(n,a,r,i,p,l),c?t.clientmessages[n]=t.messages[a]:t.messages[t.app.currserver][n]=t.messages[a]):t.messages[t.app.currserver][n]=new t.Message(n,a,r,i,p,l)}t.app.onImportClientMessagesCompleted(),t.app.currMsgID=0,t.app.currMsgLen=0,t.app.currMsgCount=0,t.app.fragmentStream=null},e.prototype.Client_onImportClientMessages=function(e){var n=new t.MemoryStream(e.data);n.wpos=e.data.byteLength,0==t.app.currMsgID&&(t.app.currMsgID=n.readUint16()),t.app.currMsgID==t.messages.onImportClientMessages.id?(0==t.app.currMsgLen&&(t.app.currMsgLen=n.readUint16(),t.app.currMsgCount=n.readUint16()),n.length()+2=t.app.currMsgLen&&t.app.importClientMessages(t.app.fragmentStream)):t.app.importClientMessages(n)):t.ERROR_MSG("KBEngineApp::onmessage: not found msg("+t.app.currMsgID+")!")},e.prototype.createAccount=function(e,n,r){t.app.reset(),t.app.username=e,t.app.password=n,t.app.clientdatas=r,t.app.createAccount_loginapp(!0)},e.prototype.createAccount_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_createAccount;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_reqCreateAccount),n.writeString(t.app.username),n.writeString(t.app.password),n.writeBlob(t.app.clientdatas),n.send(t.app)}},e.prototype.bindAccountEmail=function(e){var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_reqAccountBindEmail),n.writeInt32(t.app.entity_id),n.writeString(t.app.password),n.writeString(e),n.send(t.app)},e.prototype.newPassword=function(e,n){var r=t.Bundle.createObject();r.newMessage(t.messages.Baseapp_reqAccountNewPassword),r.writeInt32(t.app.entity_id),r.writeString(e),r.writeString(n),r.send(t.app)},e.prototype.logout=function(){var e=new t.Bundle;e.newMessage(t.messages.Baseapp_logoutBaseapp),e.writeUint64(t.app.entity_uuid),e.writeInt32(t.app.entity_id),e.send(t.app)},e.prototype.login=function(e,n,r){t.app.reset(),t.app.username=e,t.app.password=n,t.app.clientdatas=r,t.app.login_loginapp(!0)},e.prototype.login_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_login;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_login),n.writeInt8(t.app.args.clientType),n.writeBlob(t.app.clientdatas),n.writeString(t.app.username),n.writeString(t.app.password),n.send(t.app)}},e.prototype.onOpenLoginapp_resetpassword=function(){if(t.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),t.app.currserver="loginapp",t.app.currstate="resetpassword",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},e.prototype.reset_password=function(e){t.app.reset(),t.app.username=e,t.app.resetpassword_loginapp(!0)},e.prototype.resetpassword_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_resetpassword;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_reqAccountResetPassword),n.writeString(t.app.username),n.send(t.app)}},e.prototype.onOpenBaseapp=function(){if(t.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),t.app.currserver="baseapp",t.app.baseappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.Event.fire("Baseapp_importClientMessages")}},e.prototype.login_baseapp=function(e){if(e)t.Event.fire("onLoginBaseapp"),t.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+t.app.baseappIp+":"+t.app.baseappPort+"!"),t.app.currconnect="baseapp",t.app.connect(t.app.baseappIp,t.app.baseappPort),void 0!=t.app.socket&&null!=t.app.socket&&(t.app.socket.onopen=t.app.onOpenBaseapp);else{var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_loginBaseapp),n.writeString(t.app.username),n.writeString(t.app.password),n.send(t.app)}},e.prototype.reloginBaseapp=function(){t.app.lastTickCBTime=t.app.lastTickTime=Date.now(),(void 0==t.app.socket||null==t.app.socket)&&(t.app.resetSocket(),t.Event.fire(t.EventTypes.onReloginBaseapp),t.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+t.app.baseappIp+":"+t.app.baseappPort+"!"),t.app.currconnect="baseapp",t.app.connect(t.app.baseappIp,t.app.baseappPort),void 0!=t.app.socket&&null!=t.app.socket&&(t.app.socket.onopen=t.app.onReOpenBaseapp))},e.prototype.onReOpenBaseapp=function(){t.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),t.app.currserver="baseapp";var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_reloginBaseapp),e.writeString(t.app.username),e.writeString(t.app.password),e.writeUint64(t.app.entity_uuid),e.writeInt32(t.app.entity_id),e.send(t.app);var n=new Date;t.app.lastTickCBTime=n.getTime()},e.prototype.Client_onHelloCB=function(e){t.app.serverVersion=e.readString(),t.app.serverScriptVersion=e.readString(),t.app.serverProtocolMD5=e.readString(),t.app.serverEntityDefMD5=e.readString();var n=e.readInt32();t.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+t.app.serverVersion+"), scriptVerInfo("+t.app.serverScriptVersion+"), serverProtocolMD5("+t.app.serverProtocolMD5+"), serverEntityDefMD5("+t.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;t.app.lastTickCBTime=r.getTime()},e.prototype.Client_onLoginFailed=function(e){var n=e.readUint16();t.app.serverdatas=e.readBlob(),t.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+t.app.serverErrs[n].name+"), datas("+t.app.serverdatas.length+")!"),t.Event.fire("onLoginFailed",n)},e.prototype.Client_onLoginSuccessfully=function(e){var n=e.readString();t.app.username=n,t.app.baseappIp=e.readString(),t.app.baseappPort=e.readUint16(),t.app.baseappUdpPort=e.readUint16(),t.app.serverdatas=e.readBlob(),t.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+t.app.baseappIp+":"+t.app.baseappPort+"), datas("+t.app.serverdatas.length+")!"),t.app.disconnect(),t.app.login_baseapp(!0)},e.prototype.Client_onLoginBaseappFailed=function(e){t.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onLoginBaseappFailed,e)},e.prototype.Client_onReloginBaseappFailed=function(e){t.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onReloginBaseappFailed,e)},e.prototype.Client_onReloginBaseappSuccessfully=function(e){t.app.entity_uuid=e.readUint64(),t.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+t.app.username),t.Event.fire(t.EventTypes.onReloginBaseappSuccessfully)},e.prototype.getentityclass=function(e){var n=t.Entities[e];return void 0==n?(t.ERROR_MSG("KBEngineApp::getentityclass: entityType("+e+") is error!"),n):n},e.prototype.Client_onCreatedProxies=function(e,n,r){t.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=t.app.entities[n];if(t.app.entity_uuid=e,t.app.entity_id=n,void 0==a){var i=t.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new t.EntityCall,o.base.id=n,o.base.className=r,o.base.type=t.ENTITYCALL_TYPE_BASE,t.app.entities[n]=o;var p=t.bufferedCreateEntityMessages[n];void 0!=p&&(t.app.Client_onUpdatePropertys(p),delete t.bufferedCreateEntityMessages[n]),o.__init__(),o.attachComponents(),o.inited=!0,t.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=t.bufferedCreateEntityMessages[n];void 0!=p&&(t.app.Client_onUpdatePropertys(p),delete t.bufferedCreateEntityMessages[n])}},e.prototype.getViewEntityIDFromStream=function(e){var n=0;if(t.app.entityIDAliasIDList.length>255)n=e.readInt32();else{var r=e.readUint8();if(t.app.entityIDAliasIDList.length<=r)return 0;n=t.app.entityIDAliasIDList[r]}return n},e.prototype.onUpdatePropertys_=function(e,n){var r=t.app.entities[e];if(void 0==r){var a=t.bufferedCreateEntityMessages[e];if(void 0!=a)return void t.ERROR_MSG("KBEngineApp::Client_onUpdEntityComponentatePropertys: entity("+e+") not found!"); -var i=new t.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(t.bufferedCreateEntityMessages[e]=i)}r.onUpdatePropertys(n)},e.prototype.Client_onUpdatePropertysOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.onUpdatePropertys_(n,e)},e.prototype.Client_onUpdatePropertys=function(e){var n=e.readInt32();t.app.onUpdatePropertys_(n,e)},e.prototype.onRemoteMethodCall_=function(e,n){var r=t.app.entities[e];if(void 0==r)return void t.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+e+") not found!");var a=0,i=0;t.moduledefs[r.className].useMethodDescrAlias?(i=n.readInt8(),a=n.readUint8()):(i=n.readUint16(),a=n.readUint16());for(var o=t.moduledefs[r.className].methods[a],p=[],s=o[3],l=0;l0&&n!=t.app.entity_id&&t.app.entityIDAliasIDList.push(n);var r;r=t.moduledefs.Length>255?e.readUint16():e.readUint8();var a=!0;e.length()>0&&(a=e.readInt8()),r=t.moduledefs[r].name,t.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+t.app.spaceID+"), isOnGround("+a+")!");var i=t.app.entities[n];if(void 0==i){var o=t.bufferedCreateEntityMessages[n];if(void 0==o)return void t.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=t.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new t.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=t.ENTITYCALL_TYPE_CELL,t.app.entities[n]=s,t.app.Client_onUpdatePropertys(o),delete t.bufferedCreateEntityMessages[n],s.isOnGround=a,s.__init__(),s.attachComponents(),s.inited=!0,s.inWorld=!0,s.enterWorld(),t.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new t.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=t.ENTITYCALL_TYPE_CELL,t.app.entityIDAliasIDList=[],t.app.entities={},t.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),t.app.entityServerPos.x=i.position.x,t.app.entityServerPos.y=i.position.y,t.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),t.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},e.prototype.Client_onEntityLeaveWorldOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.Client_onEntityLeaveWorld(n)},e.prototype.Client_onEntityLeaveWorld=function(e){var n=t.app.entities[e];if(void 0==n)return void t.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+e+") not found!");if(n.inWorld&&n.leaveWorld(),t.app.entity_id>0&&e!=t.app.entity_id){for(var r=[],a=0;a0&&(r=e.readInt8());var a=t.app.entities[n];return void 0==a?void t.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,t.app.entityServerPos.x=a.position.x,t.app.entityServerPos.y=a.position.y,t.app.entityServerPos.z=a.position.z,void a.enterSpace())},e.prototype.Client_onEntityLeaveSpace=function(e){var n=t.app.entities[e];return void 0==n?void t.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+e+") not found!"):(t.app.clearSpace(!1),void n.leaveSpace())},e.prototype.Client_onKicked=function(e){t.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onKicked,e)},e.prototype.Client_onCreateAccountResult=function(e){var n=e.readUint16(),r=e.readBlob();return t.Event.fire("onCreateAccountResult",n,r),0!=n?void t.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+t.app.username+" create is failed! code="+t.app.serverErrs[n].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+t.app.username+" create is successfully!")},e.prototype.Client_onControlEntity=function(e,n){var r=t.app.entities[e];if(void 0==r)return void t.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+e+") not found!");var a=0!=n;if(a)t.app.player().id!=r.id&&t.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||e.entityLastLocalDir.distance(e.direction)>.001){e.entityLastLocalPos.x=e.position.x,e.entityLastLocalPos.y=e.position.y,e.entityLastLocalPos.z=e.position.z,e.entityLastLocalDir.x=e.direction.x,e.entityLastLocalDir.y=e.direction.y,e.entityLastLocalDir.z=e.direction.z;var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(e.position.x),n.writeFloat(e.position.y),n.writeFloat(e.position.z),n.writeFloat(e.direction.x),n.writeFloat(e.direction.y),n.writeFloat(e.direction.z),n.writeUint8(e.isOnGround),n.writeUint32(t.app.spaceID),n.send(t.app)}for(var r in t.app.controlledEntities){var a=t.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(t.app.spaceID),n.send(t.app)}}}},e.prototype.addSpaceGeometryMapping=function(e,n){t.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+e+"), respath("+n+")!"),t.app.spaceID=e,t.app.spaceResPath=n,t.Event.fire(t.EventTypes.addSpaceGeometryMapping,n)},e.prototype.clearSpace=function(e){t.app.entityIDAliasIDList=[],t.app.spacedata={},t.app.clearEntities(e),t.app.isLoadedGeometry=!1,t.app.spaceID=0},e.prototype.clearEntities=function(e){if(t.app.controlledEntities=[],e){for(var n in t.app.entities)t.app.entities[n].inWorld&&t.app.entities[n].leaveWorld(),t.app.entities[n].onDestroy();t.app.entities={}}else{var r=t.app.player();for(var n in t.app.entities)n!=r.id&&(t.app.entities[n].inWorld&&t.app.entities[n].leaveWorld(),t.app.entities[n].onDestroy());t.app.entities={},t.app.entities[r.id]=r}},e.prototype.Client_initSpaceData=function(e){for(t.app.clearSpace(!1),t.app.spaceID=e.readInt32();e.length()>0;){var n=e.readString(),r=e.readString();t.app.Client_setSpaceData(t.app.spaceID,n,r)}t.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+t.app.spaceID+"), datas("+t.app.spacedata+")!")},e.prototype.Client_setSpaceData=function(e,n,r){t.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+e+"), key("+n+"), value("+r+")!"),t.app.spacedata[n]=r,"_mapping"==n&&t.app.addSpaceGeometryMapping(e,r),t.Event.fire("onSetSpaceData",e,n,r)},e.prototype.Client_delSpaceData=function(e,n){t.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+e+"), key("+n+")!"),delete t.app.spacedata[n],t.Event.fire("onDelSpaceData",e,n)},e.prototype.Client_getSpaceData=function(e,n){return t.app.spacedata[n]},e.prototype.Client_onUpdateBasePos=function(e,n,r){t.app.entityServerPos.x=e,t.app.entityServerPos.y=n,t.app.entityServerPos.z=r},e.prototype.Client_onUpdateBasePosXZ=function(e,n){t.app.entityServerPos.x=e,t.app.entityServerPos.z=n},e.prototype.Client_onUpdateData=function(e){var n=t.app.getViewEntityIDFromStream(e),r=t.app.entities[n];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},e.prototype.Client_onSetEntityPosAndDir=function(e){var n=e.readInt32(),r=t.app.entities[n];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=e.readFloat(),r.position.y=e.readFloat(),r.position.z=e.readFloat(),r.direction.x=e.readFloat(),r.direction.y=e.readFloat(),r.direction.z=e.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},e.prototype.Client_onUpdateData_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,i,-1)},e.prototype.Client_onUpdateData_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,a,-1)},e.prototype.Client_onUpdateData_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,-1)},e.prototype.Client_onUpdateData_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,-1)},e.prototype.Client_onUpdateData_xz=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,o,p,1)},e.prototype.Client_onUpdateData_xz_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,o,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,t.KBE_FLT_MAX,o,1)},e.prototype.Client_onUpdateData_xz_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,i,o,1)},e.prototype.Client_onUpdateData_xz_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readInt8();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,i,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readInt8();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,i,1)},e.prototype.Client_onUpdateData_xyz=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,r,a,i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat(),s=e.readFloat();t.app._updateVolatileData(n,r,a,i,o,p,s,0)},e.prototype.Client_onUpdateData_xyz_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,p,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,p,0)},e.prototype.Client_onUpdateData_xyz_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,t.KBE_FLT_MAX,o,p,0)},e.prototype.Client_onUpdateData_xyz_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,t.KBE_FLT_MAX,o,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,i,-1,!0)},e.prototype.Client_onUpdateData_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,a,-1,!0)},e.prototype.Client_onUpdateData_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,-1,!0)},e.prototype.Client_onUpdateData_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,-1,!0)},e.prototype.Client_onUpdateData_xz_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,i,o,1,!0)},e.prototype.Client_onUpdateData_xz_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,i,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,t.KBE_FLT_MAX,i,1,!0)},e.prototype.Client_onUpdateData_xz_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,a,i,1,!0)},e.prototype.Client_onUpdateData_xz_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,a,1,!0)},e.prototype.Client_onUpdateData_xyz_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8(),p=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0,!0)},e.prototype.Client_onUpdateData_xyz_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,o,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,o,0,!0)},e.prototype.Client_onUpdateData_xyz_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,i,o,0,!0)},e.prototype.Client_onUpdateData_xyz_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,i,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype._updateVolatileData=function(e,n,r,a,i,o,p,s,l){void 0===l&&(l=!1);var c=t.app.entities[e];if(void 0==c)return void t.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+e+") not found!");s>=0&&(c.isOnGround=s>0);var d=!1;p!=t.KBE_FLT_MAX&&(d=!0,c.direction.x=t.int82angle(p,!1)),o!=t.KBE_FLT_MAX&&(d=!0,c.direction.y=t.int82angle(o,!1)),i!=t.KBE_FLT_MAX&&(d=!0,c.direction.z=t.int82angle(i,!1));var u=!1;1==d&&(t.Event.fire("set_direction",c),u=!0);var y=!1;(n!=t.KBE_FLT_MAX||r!=t.KBE_FLT_MAX||a!=t.KBE_FLT_MAX)&&(y=!0),n==t.KBE_FLT_MAX&&(n=0),r==t.KBE_FLT_MAX&&(r=0),a==t.KBE_FLT_MAX&&(a=0),y&&(l?(c.position.x=n+t.app.entityServerPos.x,c.position.y=r+t.app.entityServerPos.y,c.position.z=a+t.app.entityServerPos.z):(c.position.x=n,c.position.y=r,c.position.z=a),u=!0,t.Event.fire("updatePosition",c)),u&&c.onUpdateVolatileData()},e.prototype.Client_onStreamDataStarted=function(e,n,r){t.Event.fire(t.EventTypes.onStreamDataStarted,e,n,r)},e.prototype.Client_onStreamDataRecv=function(e){var n=e.readUint16(),r=e.readBlob();t.Event.fire(t.EventTypes.onStreamDataRecv,n,r)},e.prototype.Client_onStreamDataCompleted=function(e){t.Event.fire(t.EventTypes.onStreamDataCompleted,e)},e.prototype.Client_onReqAccountResetPasswordCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+t.app.username+" is successfully!")},e.prototype.Client_onReqAccountBindEmailCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+t.app.username+" is successfully!")},e.prototype.Client_onReqAccountNewPasswordCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+t.app.username+" is successfully!")},e}();t.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function t(){this.name="",this.descr="",this.id=0}return t}();t.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr"),t.FragmentDataTypes={FRAGMENT_DATA_UNKNOW:0,FRAGMENT_DATA_MESSAGE_ID:1,FRAGMENT_DATA_MESSAGE_LENGTH:2,FRAGMENT_DATA_MESSAGE_LENGTH1:3,FRAGMENT_DATA_MESSAGE_BODY:4};var i;t.create=e,t.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file +var __reflect=this&&this.__reflect||function(t,e,n){t.__class__=e,n?n.push(e):n=[e],t.__types__=t.__types__?n.concat(t.__types__):n},__extends=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);n.prototype=e.prototype,t.prototype=new n},KBEngine;!function(t){t.CLIENT_VERSION="2.5.0",t.CLIENT_SCRIPT_VERSION="0.1.0",t.PACKET_MAX_SIZE=1500,t.PACKET_MAX_SIZE_TCP=1460,t.PACKET_MAX_SIZE_UDP=1472,t.MESSAGE_ID_LENGTH=2,t.MESSAGE_LENGTH_LENGTH=2,t.MESSAGE_LENGTH1_LENGTH=4,t.MESSAGE_MAX_SIZE=65535,t.CLIENT_NO_FLOAT=0,t.KBE_FLT_MAX=3.402823466e38}(KBEngine||(KBEngine={})),window.KBEngine=KBEngine,ArrayBuffer.transfer||(ArrayBuffer.transfer=function(t,e){var n=new ArrayBuffer(e);if(!(t instanceof ArrayBuffer&&n instanceof ArrayBuffer))throw new TypeError("ArrayBuffer.transfer, error: Source and destination must be ArrayBuffer instances");if(!(n.byteLength>=t.byteLength))throw new RangeError("ArrayBuffer.transfer, error: destination has not enough space");var r=new Uint8Array(n);return r.set(new Uint8Array(t),0),n}),function(t){var e=function(){function t(t,e){this.sign=1,this.lo=t,this.hi=e,e>=2147483648&&(this.sign=-1,this.lo>0?(this.lo=4294967296-this.lo&4294967295,this.hi=4294967295-this.hi):(this.lo=4294967296-this.lo&4294967295,this.hi=4294967296-this.hi))}return t.prototype.toString=function(){var t="";this.sign<0&&(t+="-");var e=this.lo.toString(16),n=this.hi.toString(16);if(this.hi>0){t+=n;for(var r=8-e.length;r>0;--r)t+="0"}return t+=e},t}();t.INT64=e,__reflect(e.prototype,"KBEngine.INT64");var n=function(){function t(t,e){this.lo=t,this.hi=e}return t.prototype.toString=function(){var t=this.lo.toString(16),e=this.hi.toString(16),n="";if(this.hi>0){n+=e;for(var r=8-t.length;r>0;--r)n+="0"}return n+=t},t}();t.UINT64=n,__reflect(n.prototype,"KBEngine.UINT64")}(KBEngine||(KBEngine={})),function(t){function e(t){var e=typeof t;if(!t||"object"!=e&&!t.prototype)return e;var n=t.prototype?t.prototype:Object.getPrototypeOf(t);if(n.hasOwnProperty("__class__"))return n.__class__;var r=n.constructor.toString().trim(),a=r.indexOf("("),i=r.substring(9,a),o=i.split(".");return Object.defineProperty(n,"__class__",{value:o[o.length-1],enumerable:!1,writable:!0}),o[o.length-1]}t.getQualifiedClassName=e}(KBEngine||(KBEngine={})),function(t){function e(){for(var t=[],e=0;en;)switch(a=t[n++],a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:e+=String.fromCharCode(a);break;case 12:case 13:i=t[n++],e+=String.fromCharCode((31&a)<<6|63&i);break;case 14:i=t[n++],o=t[n++],e+=String.fromCharCode((15&a)<<12|(63&i)<<6|(63&o)<<0)}return e}function n(t){for(var e=[],n=0;nr?e.push(r):2048>r?e.push(192|r>>6,128|63&r):55296>r||r>=57344?e.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&t.charCodeAt(n)),e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return e}t.utf8ArrayToString=e,t.stringToUTF8Bytes=n}(KBEngine||(KBEngine={})),function(t){var e=function(){function t(t,e){this.classinst=t,this.callbackfn=e}return t}();t.EventInfo=e,__reflect(e.prototype,"KBEngine.EventInfo");var n=function(){function t(t,e,n){this.evtName=t,this.evtInfo=e,this.ars=n}return t}();t.FiredEvent=n,__reflect(n.prototype,"KBEngine.FiredEvent");var r=function(){function r(){this._events={},this._isPause=!1,this._firedEvents=[]}return r.prototype.register=function(n,r,a){var i=r[a];if(void 0==i)return void t.ERROR_MSG("export class Event::fire: not found strCallback("+r+")!"+a);var o=this._events[n];void 0==o&&(o=[],this._events[n]=o);var p=new e(r,i);o.push(p)},r.prototype.deregisterAll=function(t){for(var e in this._events)this.deregister(e,t)},r.prototype.deregister=function(t,e){var n=this._events[t];if(n)for(var r=n.length-1;r>=0;r--){var a=n[r];a.classinst==e&&n.splice(r,1)}},r.prototype.removeAllFiredEvent=function(t){this.removeFiredEvent("",t)},r.prototype.removeFiredEvent=function(t,e){for(var n=this._firedEvents,r=n.length-1;r>=0;r--){var a=n[r];""!=t&&a.evtName!=t||a.evtInfo.classinst!=e||n.splice(r,1)}},r.prototype.fire=function(e){for(var r=[],a=1;a0;){var e=t.shift(),n=e.evtInfo,r=e.ars;r.length<1?n.callbackfn.apply(n.classinst):n.callbackfn.apply(n.classinst,r)}},r.prototype.clear=function(){this._events={},this._firedEvents.splice(0,this._firedEvents.length)},r}();t.Events=r,__reflect(r.prototype,"KBEngine.Events"),t.Event=new r}(KBEngine||(KBEngine={})),function(t){var e=function(){function t(){this._unionData=new ArrayBuffer(4),this.fv=new Float32Array(this._unionData,0,1),this.uv=new Uint32Array(this._unionData,0,1),this.iv=new Int32Array(this._unionData,0,1)}return t}();t.PackFloatXType=e,__reflect(e.prototype,"KBEngine.PackFloatXType"),t._xPackData=new e,t._yPackData=new e,t._zPackData=new e;var n=function(){function e(t){this.rpos=0,this.wpos=0,t instanceof ArrayBuffer?this.buffer=t:this.buffer=new ArrayBuffer(t),this.rpos=0,this.wpos=0}return e.prototype.readInt8=function(){var t=new Int8Array(this.buffer,this.rpos,1);return this.rpos+=1,t[0]},e.prototype.readInt16=function(){var t=this.readUint16();return t>=32768&&(t-=65536),t},e.prototype.readInt32=function(){var t=this.readUint32();return t>=2147483648&&(t-=4294967296),t},e.prototype.readInt64=function(){var e=this.readUint32(),n=this.readUint32();return new t.INT64(e,n)},e.prototype.readUint8=function(){var t=new Uint8Array(this.buffer,this.rpos,1);return this.rpos+=1,t[0]},e.prototype.readUint16=function(){var t=new Uint8Array(this.buffer,this.rpos);return this.rpos+=2,((255&t[1])<<8)+(255&t[0])},e.prototype.readUint32=function(){var t=new Uint8Array(this.buffer,this.rpos);return this.rpos+=4,(t[3]<<24)+(t[2]<<16)+(t[1]<<8)+t[0]},e.prototype.readUint64=function(){var e=this.readUint32(),n=this.readUint32();return new t.UINT64(e,n)},e.prototype.readFloat=function(){var t;try{t=new Float32Array(this.buffer,this.rpos,1)}catch(e){t=new Float32Array(this.buffer.slice(this.rpos,this.rpos+4))}return this.rpos+=4,t[0]},e.prototype.readDouble=function(){var t;try{t=new Float64Array(this.buffer,this.rpos,1)}catch(e){t=new Float64Array(this.buffer.slice(this.rpos,this.rpos+8),0,1)}return this.rpos+=8,t[0]},e.prototype.readString=function(){for(var t=new Uint8Array(this.buffer,this.rpos),e=0,n="";;){if(0==t[e]){e++;break}if(n+=String.fromCharCode(t[e]),e++,this.rpos+e>=this.buffer.byteLength)throw new Error("export class MemoryStream::readString: rpos("+(this.rpos+e)+")>="+this.buffer.byteLength+" overflow!")}return this.rpos+=e,n},e.prototype.readBlob=function(){var t=this.readUint32(),e=new Uint8Array(this.buffer,this.rpos,t);return this.rpos+=t,e},e.prototype.readStream=function(){var t=new Uint8Array(this.buffer,this.rpos,this.buffer.byteLength-this.rpos);return this.rpos=this.buffer.byteLength,new e(t)},e.prototype.readPackXZ=function(){var e=t._xPackData,n=t._zPackData;e.fv[0]=0,n.fv[0]=0,e.uv[0]=1073741824,n.uv[0]=1073741824;var r=this.readUint8(),a=this.readUint8(),i=this.readUint8(),o=0;o|=r<<16,o|=a<<8,o|=i,e.uv[0]|=(8384512&o)<<3,n.uv[0]|=(2047&o)<<15,e.fv[0]-=2,n.fv[0]-=2,e.uv[0]|=(8388608&o)<<8,n.uv[0]|=(2048&o)<<20;var p=new Array(2);return p[0]=e.fv[0],p[1]=n.fv[0],p},e.prototype.readPackY=function(){var e=this.readUint16(),n=t._yPackData;return n.uv[0]=1073741824,n.uv[0]|=(32767&e)<<12,n.fv[0]-=2,n.uv[0]|=(32768&e)<<16,n.fv[0]},e.prototype.writeInt8=function(t){var e=new Int8Array(this.buffer,this.wpos,1);e[0]=t,this.wpos+=1},e.prototype.writeInt16=function(t){this.writeInt8(255&t),this.writeInt8(t>>8&255)},e.prototype.writeInt32=function(t){for(var e=0;4>e;e++)this.writeInt8(t>>8*e&255)},e.prototype.writeInt64=function(t){this.writeInt32(t.lo),this.writeInt32(t.hi)},e.prototype.writeUint8=function(t){var e=new Uint8Array(this.buffer,this.wpos,1);e[0]=t,this.wpos+=1},e.prototype.writeUint16=function(t){this.writeUint8(255&t),this.writeUint8(t>>8&255)},e.prototype.writeUint32=function(t){for(var e=0;4>e;e++)this.writeUint8(t>>8*e&255)},e.prototype.writeUint64=function(t){this.writeUint32(t.lo),this.writeUint32(t.hi)},e.prototype.writeFloat=function(t){try{var e=new Float32Array(this.buffer,this.wpos,1);e[0]=t}catch(n){var e=new Float32Array(1);e[0]=t;var r=new Uint8Array(this.buffer),a=new Uint8Array(e.buffer);r.set(a,this.wpos)}this.wpos+=4},e.prototype.writeDouble=function(t){try{var e=new Float64Array(this.buffer,this.wpos,1);e[0]=t}catch(n){var e=new Float64Array(1);e[0]=t;var r=new Uint8Array(this.buffer),a=new Uint8Array(e.buffer);r.set(a,this.wpos)}this.wpos+=8},e.prototype.writeBlob=function(e){var n=e.length;if(n+4>this.space())return void t.ERROR_MSG("memorystream::writeBlob: no free!");this.writeUint32(n);var r=new Uint8Array(this.buffer,this.wpos,n);if("string"==typeof e)for(var a=0;n>a;a++)r[a]=e.charCodeAt(a);else for(var a=0;n>a;a++)r[a]=e[a];this.wpos+=n},e.prototype.writeString=function(e){if(e.length>this.space())return void t.ERROR_MSG("memorystream::writeString: no free!");for(var n=new Uint8Array(this.buffer,this.wpos),r=0,a=0;athis.space()&&(this.buffer=ArrayBuffer.transfer(this.buffer,this.buffer.byteLength+2*n));var r=new Uint8Array(this.buffer,this.wpos,n);r.set(new Uint8Array(t.buffer,e,n),0),this.wpos+=n},e.prototype.readSkip=function(t){this.rpos+=t},e.prototype.space=function(){return this.buffer.byteLength-this.wpos},e.prototype.length=function(){return this.wpos-this.rpos},e.prototype.readEOF=function(){return this.buffer.byteLength-this.rpos<=0},e.prototype.done=function(){this.rpos=this.wpos},e.prototype.getbuffer=function(){return this.buffer.slice(this.rpos,this.wpos)},e.prototype.setbuffer=function(t){this.clear(),this.buffer=t},e.prototype.size=function(){return this.buffer.byteLength},e.prototype.clear=function(){this.rpos=this.wpos=0,this.buffer.byteLength>t.PACKET_MAX_SIZE&&(this.buffer=new ArrayBuffer(t.PACKET_MAX_SIZE))},e.prototype.reclaimObject=function(){this.clear(),void 0!=e._objects&&e._objects.push(this)},e}();t.MemoryStream=n,__reflect(n.prototype,"KBEngine.MemoryStream"),function(e){function n(){return e._objects.length>0?e._objects.pop():new e(t.PACKET_MAX_SIZE_TCP)}e._objects=[],e.createObject=n}(n=t.MemoryStream||(t.MemoryStream={}))}(KBEngine||(KBEngine={})),function(t){function e(){t.datatype2id={},t.datatype2id.STRING=1,t.datatype2id["STD::STRING"]=1,t.datatype2id.UINT8=2,t.datatype2id.BOOL=2,t.datatype2id.DATATYPE=2,t.datatype2id.CHAR=2,t.datatype2id.DETAIL_TYPE=2,t.datatype2id.ENTITYCALL_CALL_TYPE=2,t.datatype2id.UINT16=3,t.datatype2id["UNSIGNED SHORT"]=3,t.datatype2id.SERVER_ERROR_CODE=3,t.datatype2id.ENTITY_TYPE=3,t.datatype2id.ENTITY_PROPERTY_UID=3,t.datatype2id.ENTITY_METHOD_UID=3,t.datatype2id.ENTITY_SCRIPT_UID=3,t.datatype2id.DATATYPE_UID=3,t.datatype2id.UINT32=4,t.datatype2id.UINT=4,t.datatype2id["UNSIGNED INT"]=4,t.datatype2id.ARRAYSIZE=4,t.datatype2id.SPACE_ID=4,t.datatype2id.GAME_TIME=4,t.datatype2id.TIMER_ID=4,t.datatype2id.UINT64=5,t.datatype2id.DBID=5,t.datatype2id.COMPONENT_ID=5,t.datatype2id.INT8=6,t.datatype2id.COMPONENT_ORDER=6,t.datatype2id.INT16=7,t.datatype2id.SHORT=7,t.datatype2id.INT32=8,t.datatype2id.INT=8,t.datatype2id.ENTITY_ID=8,t.datatype2id.CALLBACK_ID=8,t.datatype2id.COMPONENT_TYPE=8,t.datatype2id.INT64=9,t.datatype2id.PYTHON=10,t.datatype2id.PY_DICT=10,t.datatype2id.PY_TUPLE=10,t.datatype2id.PY_LIST=10,t.datatype2id.ENTITYCALL=10,t.datatype2id.BLOB=11,t.datatype2id.UNICODE=12,t.datatype2id.FLOAT=13,t.datatype2id.DOUBLE=14,t.datatype2id.VECTOR2=15,t.datatype2id.VECTOR3=16,t.datatype2id.VECTOR4=17,t.datatype2id.FIXED_DICT=18,t.datatype2id.ARRAY=19,t.datatype2id.ENTITYCALL=20}function n(e,n){switch(n){case t.datatype2id.UINT8:return e.writeUint8;case t.datatype2id.UINT16:return e.writeUint16;case t.datatype2id.UINT32:return e.writeUint32;case t.datatype2id.UINT64:return e.writeUint64;case t.datatype2id.INT8:return e.writeInt8;case t.datatype2id.INT16:return e.writeInt16;case t.datatype2id.INT32:return e.writeInt32;case t.datatype2id.INT64:return e.writeInt64;case t.datatype2id.FLOAT:return e.writeFloat;case t.datatype2id.DOUBLE:return e.writeDouble;case t.datatype2id.STRING:return e.writeString;case t.datatype2id.FIXED_DICT:return e.writeStream;case t.datatype2id.ARRAY:return e.writeStream;default:return e.writeStream}}function r(e){switch(e){case t.datatype2id.UINT8:return t.reader.readUint8;case t.datatype2id.UINT16:return t.reader.readUint16;case t.datatype2id.UINT32:return t.reader.readUint32;case t.datatype2id.UINT64:return t.reader.readUint64;case t.datatype2id.INT8:return t.reader.readInt8;case t.datatype2id.INT16:return t.reader.readInt16;case t.datatype2id.INT32:return t.reader.readInt32;case t.datatype2id.INT64:return t.reader.readInt64;case t.datatype2id.FLOAT:return t.reader.readFloat;case t.datatype2id.DOUBLE:return t.reader.readDouble;case t.datatype2id.STRING:return t.reader.readString;case t.datatype2id.FIXED_DICT:return t.reader.readStream;case t.datatype2id.ARRAY:return t.reader.readStream;default:return t.reader.readStream}}var a=function(){function e(){this.memorystreams=new Array,this.numMessage=0,this.messageLengthBuffer=null,this.msgtype=null,this.messageLength=0,this.stream=t.MemoryStream.createObject()}return e.createObject=function(){return e._objects.length>0?e._objects.pop():new e},e.prototype.newMessage=function(e){this.fini(!1),this.msgtype=e,this.numMessage+=1,-1==this.msgtype.length&&(this.messageLengthBuffer=new Uint8Array(this.stream.buffer,this.stream.wpos+t.MESSAGE_ID_LENGTH,2)),this.writeUint16(e.id),this.messageLengthBuffer&&(this.writeUint16(0),this.messageLengthBuffer[0]=0,this.messageLengthBuffer[1]=0,this.messageLength=0)},e.prototype.writeMsgLength=function(t){this.messageLengthBuffer&&(this.messageLengthBuffer[0]=255&t,this.messageLengthBuffer[1]=t>>8&255)},e.prototype.fini=function(e){this.numMessage>0&&(this.writeMsgLength(this.messageLength),this.stream&&this.memorystreams.push(this.stream),this.stream=t.MemoryStream.createObject()),e&&(this.messageLengthBuffer=null,this.numMessage=0,this.msgtype=null)},e.prototype.send=function(t){this.fini(!0);for(var e=0;ethis.stream.space()&&(this.memorystreams.push(this.stream),this.stream=t.MemoryStream.createObject()),this.messageLength+=e},e.prototype.writeInt8=function(t){this.checkStream(1),this.stream.writeInt8(t)},e.prototype.writeInt16=function(t){this.checkStream(2),this.stream.writeInt16(t)},e.prototype.writeInt32=function(t){this.checkStream(4),this.stream.writeInt32(t)},e.prototype.writeInt64=function(t){this.checkStream(8),this.stream.writeInt64(t)},e.prototype.writeUint8=function(t){this.checkStream(1),this.stream.writeUint8(t)},e.prototype.writeUint16=function(t){this.checkStream(2),this.stream.writeUint16(t)},e.prototype.writeUint32=function(t){this.checkStream(4),this.stream.writeUint32(t)},e.prototype.writeUint64=function(t){this.checkStream(8),this.stream.writeUint64(t)},e.prototype.writeFloat=function(t){this.checkStream(4),this.stream.writeFloat(t)},e.prototype.writeDouble=function(t){this.checkStream(8),this.stream.writeDouble(t)},e.prototype.writeString=function(t){this.checkStream(t.length+1),this.stream.writeString(t)},e.prototype.writeBlob=function(t){this.checkStream(t.length+4),this.stream.writeBlob(t)},e.prototype.clear=function(){for(var e=0;en){var r=e;e=n,n=r}return e>t?e:n>t?t:n}function n(t,e){return t*(Math.PI/(e?254:128))}function r(t,n){var r=0;return r=n?e(Math.floor(254*t/Math.PI+.5),-128,127):Math.floor(128*t/Math.PI+.5)}var a=function(){function t(t,e){this.x=t,this.y=e}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y;return Math.sqrt(e*e+n*n)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this},t}();t.Vector2=a,__reflect(a.prototype,"KBEngine.Vector2");var i=function(){function t(t,e,n){this.x=t,this.y=e,this.z=n,this.x=t,this.y=e,this.z=n}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y,r=t.z-this.z;return Math.sqrt(e*e+n*n+r*r)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},t}();t.Vector3=i,__reflect(i.prototype,"KBEngine.Vector3");var o=function(){function t(t,e,n,r){this.x=t,this.y=e,this.z=n,this.w=r,this.x=t,this.y=e,this.z=n,this.w=r}return t.prototype.distance=function(t){var e=t.x-this.x,n=t.y-this.y,r=t.z-this.z,a=t.w-this.w;return Math.sqrt(e*e+n*n+r*r+a*a)},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.div=function(t){return this.x/=t,this.y/=t,this.z/=t,this.w/=t,this},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this},t}();t.Vector4=o,__reflect(o.prototype,"KBEngine.Vector4"),t.clampf=e,t.int82angle=n,t.angle2int8=r}(KBEngine||(KBEngine={})),function(t){function e(){return function(e){var n=t.getQualifiedClassName(e);t.Entities[n]=e}}t.Entities={};var n=function(){function e(){this.__comps__={},this.id=0,this.className="",this.position=new t.Vector3(0,0,0),this.direction=new t.Vector3(0,0,0),this.velocity=0,this.cell=null,this.base=null,this.inWorld=!1,this.inited=!1,this.isControlled=!1,this.entityLastLocalPos=new t.Vector3(0,0,0),this.entityLastLocalDir=new t.Vector3(0,0,0),this.isOnGround=!1;for(var e in this.__comps__)this[e]=new this.__comps__[e]}return e.prototype.__init__=function(){},e.prototype.attachComponents=function(){for(var t in this.__comps__)this[t].onAttached(this)},e.prototype.getComponents=function(e,n){void 0===n&&(n=!1);var r=[];for(var a in this.__comps__)if(t.getQualifiedClassName(this.__comps__[a])===e){if(!n)return this[a];r.push(this[a])}return r},e.prototype.detachComponents=function(){for(var t in this.__comps__)this[t].onDetached(this)},e.prototype.callPropertysSetMethods=function(){var e=t.moduledefs[this.className];for(var n in e.propertys){var r=e.propertys[n];r[0];n=r[2];var a=r[5],i=r[6],o=this[n];if(null!=a)if(32==i||64==i)this.inited&&!this.inWorld&&a.call(this,o);else if(this.inWorld){if((8==i||16==i)&&!this.isPlayer())continue;a.call(this,o)}}},e.prototype.onDestroy=function(){this.detachComponents()},e.prototype.onControlled=function(t){},e.prototype.isPlayer=function(){return this.id==t.app.entity_id},e.prototype.baseCall=function(e){for(var n=[],r=1;r0;){var a=0,i=0;if(n.usePropertyDescrAlias?(i=e.readUint8(),a=e.readUint8()):(i=e.readUint16(),a=e.readUint16()),0===i){var o=r[a],p=o[5],s=o[6];if(o[4]){var l=o[4].createFromStream(e),c=this[o[2]];t.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+this.className+"(id="+this.id+" "+o[2]+", val="+l+")!"),this[o[2]]=l,null!=p&&(32==s||64==s?this.inited&&p.call(this,c):this.inWorld&&p.call(this,c))}else this[o[2]]&&"function"==typeof this[o[2]].createFromStream&&this[o[2]].createFromStream(e,o[0])}else{var d=r[i];this[d[2]]&&this[d[2]].onUpdatePropertys(a,e,-1)}}},e.prototype.set_direction=function(e){t.DEBUG_MSG(this.className+"::set_direction: "+this.direction),t.Event.fire("set_direction",this)},e.prototype.onRemoteMethodCall=function(e){var n=t.moduledefs[this.className],r=n.usePropertyDescrAlias?e.readUint8():e.readUint16(),a=n.useMethodDescrAlias?e.readUint8():e.readUint16();if(0!==r){var i=this[n.propertys[r][2]];return void(i&&i.onRemoteMethodCall(a,e))}for(var o=t.moduledefs[this.className].methods[a],p=[],s=o[3],l=0;l0&&0!=r--;){var p=e,s=0;0===p&&(i.usePropertyDescrAlias?(s=n.readUint8(),p=n.readUint8()):(s=n.readUint16(),p=n.readUint16()));var l=o[p],c=l[5],d=l[6],u=l[4].createFromStream(n),y=this[l[2]];t.INFO_MSG("KBEngineApp::Client_onUpdatePropertys: "+a+"(id="+this.id+" "+l[2]+", val="+u+")!"),this[l[2]]=u,null!=c&&(32==d||64==d?this.owner.inited&&c.call(this,y):this.owner.inWorld&&c.call(this,y))}},e.prototype.onRemoteMethodCall=function(e,n){for(var r=t.moduledefs[this.className].methods[e],a=[],i=r[3],o=0;o0&&this.onUpdatePropertys(0,e,r),this.className=t.getQualifiedClassName(this),this.base=new t.EntityComponentCall(this.entityComponentPropertyID,this.ownerID,this.className),this.base.type=t.ENTITYCALL_TYPE_BASE,this.cell=new t.EntityComponentCall(this.entityComponentPropertyID,this.ownerID,this.className),this.cell.type=t.ENTITYCALL_TYPE_CELL},e}();t.EntityComponent=n,__reflect(n.prototype,"KBEngine.EntityComponent"),t.registerComponent=e}(KBEngine||(KBEngine={})),function(t){t.ENTITYCALL_TYPE_CELL=0,t.ENTITYCALL_TYPE_BASE=1;var e=function(){function e(){this.id=0,this.className="",this.type=t.ENTITYCALL_TYPE_CELL,this.networkInterface=t.app,this.bundle=null}return e.prototype.isBase=function(){return this.type==t.ENTITYCALL_TYPE_BASE},e.prototype.isCell=function(){return this.type==t.ENTITYCALL_TYPE_CELL},e.prototype.newCall=function(){return null==this.bundle&&(this.bundle=t.Bundle.createObject()),this.type==t.ENTITYCALL_TYPE_CELL?this.bundle.newMessage(t.messages.Baseapp_onRemoteCallCellMethodFromClient):this.bundle.newMessage(t.messages.Entity_onRemoteMethodCall),this.bundle.writeInt32(this.id),this.bundle},e.prototype.sendCall=function(t){void 0==t&&(t=this.bundle),t.send(this.networkInterface),this.bundle==t&&(this.bundle=null)},e}();t.EntityCall=e,__reflect(e.prototype,"KBEngine.EntityCall");var n=function(t){function e(e,n,r){var a=t.call(this)||this;return a.entityComponentPropertyID=0,a.entityComponentPropertyID=e,a.id=n,a.className=r,a}return __extends(e,t),e}(e);t.EntityComponentCall=n,__reflect(n.prototype,"KBEngine.EntityComponentCall");var r=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint8.call(e)},e.prototype.addToStream=function(t,e){t.writeUint8(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>255?!1:!0},e}();t.DATATYPE_UINT8=r,__reflect(r.prototype,"KBEngine.DATATYPE_UINT8");var a=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint16.call(e)},e.prototype.addToStream=function(t,e){t.writeUint16(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>65535?!1:!0},e}();t.DATATYPE_UINT16=a,__reflect(a.prototype,"KBEngine.DATATYPE_UINT16");var i=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint32.call(e) +},e.prototype.addToStream=function(t,e){t.writeUint32(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:0>t||t>4294967295?!1:!0},e}();t.DATATYPE_UINT32=i,__reflect(i.prototype,"KBEngine.DATATYPE_UINT32");var o=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readUint64.call(e)},e.prototype.addToStream=function(t,e){t.writeUint64(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(e){return e instanceof t.UINT64},e}();t.DATATYPE_UINT64=o,__reflect(o.prototype,"KBEngine.DATATYPE_UINT64");var p=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt8.call(e)},e.prototype.addToStream=function(t,e){t.writeInt8(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-128>t||t>127?!1:!0},e}();t.DATATYPE_INT8=p,__reflect(p.prototype,"KBEngine.DATATYPE_INT8");var s=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt16.call(e)},e.prototype.addToStream=function(t,e){t.writeInt16(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-32768>t||t>32767?!1:!0},e}();t.DATATYPE_INT16=s,__reflect(s.prototype,"KBEngine.DATATYPE_INT16");var l=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt32.call(e)},e.prototype.addToStream=function(t,e){t.writeInt32(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(t){return"number"!=typeof t?!1:-2147483648>t||t>2147483647?!1:!0},e}();t.DATATYPE_INT32=l,__reflect(l.prototype,"KBEngine.DATATYPE_INT32");var c=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readInt64.call(e)},e.prototype.addToStream=function(t,e){t.writeInt64(e)},e.prototype.parseDefaultValStr=function(t){return parseInt(t)},e.prototype.isSameType=function(e){return e instanceof t.INT64},e}();t.DATATYPE_INT64=c,__reflect(c.prototype,"KBEngine.DATATYPE_INT64");var d=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readFloat.call(e)},e.prototype.addToStream=function(t,e){t.writeFloat(e)},e.prototype.parseDefaultValStr=function(t){return parseFloat(t)},e.prototype.isSameType=function(t){return"number"==typeof t},e}();t.DATATYPE_FLOAT=d,__reflect(d.prototype,"KBEngine.DATATYPE_FLOAT");var u=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.createFromStream=function(e){return t.reader.readDouble.call(e)},n.prototype.addToStream=function(t,e){t.writeDouble(e)},n}(d);t.DATATYPE_DOUBLE=u,__reflect(u.prototype,"KBEngine.DATATYPE_DOUBLE");var y=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.reader.readString.call(e)},e.prototype.addToStream=function(t,e){t.writeString(e)},e.prototype.parseDefaultValStr=function(t){return"string"==typeof t?t:""},e.prototype.isSameType=function(t){return"string"==typeof t},e}();t.DATATYPE_STRING=y,__reflect(y.prototype,"KBEngine.DATATYPE_STRING");var _=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){if(t.CLIENT_NO_FLOAT){var n=t.reader.readInt32.call(e),r=t.reader.readInt32.call(e);return new t.Vector2(n,r)}var n=t.reader.readFloat.call(e),r=t.reader.readFloat.call(e);return new t.Vector2(n,r)},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y)):(e.writeFloat(n.x),e.writeFloat(n.y))},e.prototype.parseDefaultValStr=function(e){return new t.Vector2(0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector2?!0:!1},e}();t.DATATYPE_VECTOR2=_,__reflect(_.prototype,"KBEngine.DATATYPE_VECTOR2");var f=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.CLIENT_NO_FLOAT?new t.Vector3(t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e)):new t.Vector3(t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e))},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z))},e.prototype.parseDefaultValStr=function(e){return new t.Vector3(0,0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector3?!0:!1},e}();t.DATATYPE_VECTOR3=f,__reflect(f.prototype,"KBEngine.DATATYPE_VECTOR3");var h=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.CLIENT_NO_FLOAT?new t.Vector4(t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e),t.reader.readInt32.call(e)):new t.Vector4(t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e),t.reader.readFloat.call(e))},e.prototype.addToStream=function(e,n){t.CLIENT_NO_FLOAT?(e.writeInt32(n.x),e.writeInt32(n.y),e.writeInt32(n.z),e.writeInt32(n.w)):(e.writeFloat(n.x),e.writeFloat(n.y),e.writeFloat(n.z),e.writeFloat(n.w))},e.prototype.parseDefaultValStr=function(e){return new t.Vector4(0,0,0,0)},e.prototype.isSameType=function(e){return e instanceof t.Vector4?!0:!1},e}();t.DATATYPE_VECTOR4=h,__reflect(h.prototype,"KBEngine.DATATYPE_VECTOR4");var E=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){return t.readBlob()},t.prototype.addToStream=function(t,e){t.writeBlob(e)},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_PYTHON=E,__reflect(E.prototype,"KBEngine.DATATYPE_PYTHON");var g=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){return t.utf8ArrayToString(t.reader.readBlob.call(e))},e.prototype.addToStream=function(e,n){e.writeBlob(t.stringToUTF8Bytes(n))},e.prototype.parseDefaultValStr=function(t){return"string"==typeof t?t:""},e.prototype.isSameType=function(t){return"string"==typeof t},e}();t.DATATYPE_UNICODE=g,__reflect(g.prototype,"KBEngine.DATATYPE_UNICODE");var m=function(){function t(){}return t.prototype.bind=function(){},t.prototype.createFromStream=function(t){},t.prototype.addToStream=function(t,e){},t.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},t.prototype.isSameType=function(t){return!1},t}();t.DATATYPE_ENTITYCALL=m,__reflect(m.prototype,"KBEngine.DATATYPE_ENTITYCALL");var v=function(){function e(){}return e.prototype.bind=function(){},e.prototype.createFromStream=function(e){var n=t.reader.readUint32.call(e),r=new Uint8Array(e.buffer,e.rpos,n);return e.rpos+=n,r},e.prototype.addToStream=function(t,e){t.writeBlob(e)},e.prototype.parseDefaultValStr=function(t){return new Uint8Array(0)},e.prototype.isSameType=function(t){return!0},e}();t.DATATYPE_BLOB=v,__reflect(v.prototype,"KBEngine.DATATYPE_BLOB");var T=function(){function t(){this.type=null}return t.prototype.bind=function(){"number"==typeof this.type&&(this.type=A[this.type])},t.prototype.createFromStream=function(t){for(var e=t.readUint32(),n=[];e>0;)e--,n.push(this.type.createFromStream(t));return n},t.prototype.addToStream=function(t,e){t.writeUint32(e.length);for(var n=0;n0||null!=t.app.fragmentStream;)if(t.app.fragmentDatasFlag==t.FragmentDataTypes.FRAGMENT_DATA_UNKNOW){if(0==t.app.currMsgID){if(t.MESSAGE_ID_LENGTH>1&&n.length()=t.app.currMsgLen)r.handleMessage(t.app.fragmentStream),t.app.fragmentStream=null;else{if(n.length()0){t.app.writeFragmentMessage(t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY,n,t.app.currMsgLen);break}var i=n.wpos,o=n.rpos+a;n.wpos=o,r.handleMessage(n),n.wpos=i,n.rpos=o}t.app.currMsgID=0,t.app.currMsgLen=0,t.app.fragmentStream=null}else if(t.app.mergeFragmentMessage(n))break},e.prototype.writeFragmentMessage=function(e,n,r){var a=n.length();t.app.fragmentDatasRemain=r-a,t.app.fragmentDatasFlag=e,t.app.fragmentStream=n},e.prototype.mergeFragmentMessage=function(e){var n=e.length();if(0==n)return 0;var r=t.app.fragmentStream;if(n>=t.app.fragmentDatasRemain){switch(r.append(e,e.rpos,t.app.fragmentDatasRemain),t.app.fragmentDatasFlag){case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_ID:t.app.currMsgID=r.readUint16(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH:t.app.currMsgLen=r.readUint16(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_LENGTH1:t.app.currMsgLen=r.readUint32(),t.app.fragmentStream=null;break;case t.FragmentDataTypes.FRAGMENT_DATA_MESSAGE_BODY:}return e.rpos+=t.app.fragmentDatasRemain,t.app.fragmentDatasFlag=t.FragmentDataTypes.FRAGMENT_DATA_UNKNOW,t.app.fragmentDatasRemain=0,!1}return r.append(e,e.rpos,n),t.app.fragmentDatasRemain-=n,e.done(),!0},e.prototype.onclose=function(){t.INFO_MSG("connect close:"+t.app.currserver),t.app.currconnect==t.app.currstate&&(t.app.resetSocket(),t.Event.fire(t.EventTypes.onDisconnected))},e.prototype.send=function(e){t.app.socket.send(e)},e.prototype.close=function(){t.INFO_MSG("KBEngine::close()"),t.app.socket.close(),t.app.reset()},e.prototype.update=function(){if(null!=t.app.socket){var e=new Date;if((e.getTime()-t.app.lastTickTime)/1e3>t.app.args.serverHeartbeatTick/2){if(t.app.lastTickCBTime0;){n-=1;var r=new a;r.id=e.readUint16(),r.name=t.utf8ArrayToString(e.readBlob()),r.descr=t.utf8ArrayToString(e.readBlob()),t.app.serverErrs[r.id]=r,t.INFO_MSG("Client_onImportServerErrorsDescr: id="+r.id+", name="+r.name+", descr="+r.descr)}},e.prototype.Client_onImportClientSdk=function(e){var n=e.readInt32(),r=e.readString(),a=e.readInt32(),i=e.readBlob();t.Event.fire("onImportClientSDK",n,r,a,i)},e.prototype.onOpenLoginapp_login=function(){if(t.INFO_MSG("KBEngineApp::onOpenLoginapp_login: successfully!"),t.Event.fire(t.EventTypes.onConnectionState,!0),t.app.currserver="loginapp",t.app.currstate="login",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_login: start importClientMessages ..."),t.Event.fire("Loginapp_importClientMessages")}},e.prototype.onOpenLoginapp_createAccount=function(){if(t.Event.fire("onConnectionState",!0),t.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: successfully!"),t.app.currserver="loginapp",t.app.currstate="createAccount",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_createAccount: start importClientMessages ..."),t.Event.fire("Loginapp_importClientMessages")}},e.prototype.onImportClientMessagesCompleted=function(){if(t.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: successfully!"),t.app.socket.onmessage=t.app.onmessage,t.app.hello(),"loginapp"==t.app.currserver){if(!t.app.serverErrorsDescrImported){t.INFO_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"),t.app.serverErrorsDescrImported=!0;var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importServerErrorsDescr),e.send(t.app)}"login"==t.app.currstate?t.app.login_loginapp(!1):"resetpassword"==t.app.currstate?t.app.resetpassword_loginapp(!1):t.app.createAccount_loginapp(!1),t.app.loginappMessageImported=!0}else if(t.app.baseappMessageImported=!0,t.app.entitydefImported)t.app.onImportEntityDefCompleted();else{t.INFO_MSG("KBEngineApp::onImportClientMessagesCompleted: start importEntityDef ...");var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_importClientEntityDef),e.send(t.app),t.Event.fire("Baseapp_importClientEntityDef")}},e.prototype.createDataTypeFromStreams=function(e,n){var r=e.readUint16();for(t.INFO_MSG("KBEngineApp::createDataTypeFromStreams: importAlias(size="+r+")!");r>0;)r--,t.app.createDataTypeFromStream(e,n);for(var a in t.datatypes)void 0!=t.datatypes[a]&&t.datatypes[a].bind()},e.prototype.createDataTypeFromStream=function(e,n){var r,a=e.readUint16(),i=e.readString(),o=e.readString();if(0==o.length&&(r="Null_"+a),n&&t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: importAlias("+i+":"+o+")!"),"FIXED_DICT"==i){var p=new t.DATATYPE_FIXED_DICT,s=e.readUint8();for(p.implementedBy=e.readString();s>0;){s--;var l=e.readString(),c=e.readUint16();p.dicttype[l]=c}t.datatypes[o]=p}else if("ARRAY"==i){var d=e.readUint16(),p=new t.DATATYPE_ARRAY;p.type=d,t.datatypes[o]=p}else t.datatypes[o]=t.datatypes[i];t.datatypes[a]=t.datatypes[o],t.datatype2id[o]=a},e.prototype.Client_onImportClientEntityDef=function(e){for(t.app.createDataTypeFromStreams(e,!0);e.length()>0;){var n=e.readString(),r=e.readUint16(),a=e.readUint16(),i=e.readUint16(),o=e.readUint16(),p=e.readUint16();t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: import("+n+"), propertys("+a+"), clientMethods("+i+"), baseMethods("+o+"), cellMethods("+p+")!"),t.moduledefs[n]={};var s=t.moduledefs[n];s.name=n,s.propertys={},s.methods={},s.base_methods={},s.cell_methods={},t.moduledefs[r]=s;for(var l=s.propertys,c=s.methods,d=s.base_methods,u=s.cell_methods,y=t.Entities[n];a>0;){a--;var _=e.readUint16(),f=e.readUint32(),h=e.readInt16(),E=e.readString(),g=e.readString(),m=t.datatypes[e.readUint16()],v=null;void 0!=y&&(v=y.prototype["set_"+E],void 0==v&&(v=null));var T=[_,h,E,g,m,v,f];l[E]=T,-1!=h?(l[h]=T,s.usePropertyDescrAlias=!0):(l[_]=T,s.usePropertyDescrAlias=!1),t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), property("+E+"/"+_+").")}for(;i>0;){i--;for(var S=e.readUint16(),h=e.readInt16(),A=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);var T=[S,h,A,D];c[A]=T,-1!=h?(c[h]=T,s.useMethodDescrAlias=!0):(c[S]=T,s.useMethodDescrAlias=!1),t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), method("+A+").")}for(;o>0;){o--;for(var S=e.readUint16(),h=e.readInt16(),M=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);d[M]=[S,h,M,D],t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), base_method("+M+").")}for(;p>0;){p--;for(var S=e.readUint16(),h=e.readInt16(),w=e.readString(),I=e.readUint8(),D=[];I>0;)I--,D.push(t.datatypes[e.readUint16()]);u[w]=[S,h,w,D],t.INFO_MSG("KBEngineApp::Client_onImportClientEntityDef: add("+n+"), cell_method("+w+").")}var F=void 0;try{F=t.Entities[n]}catch(C){t.ERROR_MSG("KBEngineApp::Client_onImportClientEntityDef: module("+n+") not found!"),F=void 0}for(var B in s.propertys){var L=s.propertys[B],_=L[0],h=L[1],R=L[2],g=L[3],m=L[4];void 0!=F&&m&&(F.prototype[R]=m.parseDefaultValStr(g))}for(var b in s.methods){var L=s.methods[b],_=L[0],h=L[1],R=L[2],D=L[3];void 0!=F&&void 0==F.prototype[R]&&t.WARNING_MSG(n+":: method("+R+") no implement!")}}t.app.onImportEntityDefCompleted()},e.prototype.Client_onVersionNotMatch=function(e){t.app.serverVersion=e.readString(),t.ERROR_MSG("Client_onVersionNotMatch: verInfo="+t.app.clientVersion+" not match(server: "+t.app.serverVersion+")"),t.Event.fire(t.EventTypes.onVersionNotMatch,t.app.clientVersion,t.app.serverVersion)},e.prototype.Client_onScriptVersionNotMatch=function(e){t.app.serverScriptVersion=e.readString(),t.ERROR_MSG("Client_onScriptVersionNotMatch: verInfo="+t.app.clientScriptVersion+" not match(server: "+t.app.serverScriptVersion+")"),t.Event.fire(t.EventTypes.onScriptVersionNotMatch,t.app.clientScriptVersion,t.app.serverScriptVersion)},e.prototype.onImportEntityDefCompleted=function(){t.INFO_MSG("KBEngineApp::onImportEntityDefCompleted: successfully!"),t.app.entitydefImported=!0,t.app.login_baseapp(!1)},e.prototype.importClientMessages=function(e){for(;t.app.currMsgCount>0;){t.app.currMsgCount--;for(var n=e.readUint16(),r=e.readInt16(),a=e.readString(),i=e.readInt8(),o=e.readUint8(),p=new Array(o),s=0;o>s;s++)p[s]=e.readUint8();var l=null,c=a.indexOf("Client_")>=0;c&&(l=t.app[a],null==l||void 0==l?(t.WARNING_MSG("KBEngineApp::onImportClientMessages["+t.app.currserver+"]: interface("+a+"/"+n+") no implement!"),l=null):t.INFO_MSG("KBEngineApp::onImportClientMessages: import("+a+") successfully!")),a.length>0?(t.messages[a]=new t.Message(n,a,r,i,p,l),c?t.clientmessages[n]=t.messages[a]:t.messages[t.app.currserver][n]=t.messages[a]):t.messages[t.app.currserver][n]=new t.Message(n,a,r,i,p,l)}t.app.onImportClientMessagesCompleted(),t.app.currMsgID=0,t.app.currMsgLen=0,t.app.currMsgCount=0,t.app.fragmentStream=null},e.prototype.Client_onImportClientMessages=function(e){var n=new t.MemoryStream(e.data);n.wpos=e.data.byteLength,0==t.app.currMsgID&&(t.app.currMsgID=n.readUint16()),t.app.currMsgID==t.messages.onImportClientMessages.id?(0==t.app.currMsgLen&&(t.app.currMsgLen=n.readUint16(),t.app.currMsgCount=n.readUint16()),n.length()+2=t.app.currMsgLen&&t.app.importClientMessages(t.app.fragmentStream)):t.app.importClientMessages(n)):t.ERROR_MSG("KBEngineApp::onmessage: not found msg("+t.app.currMsgID+")!")},e.prototype.createAccount=function(e,n,r){t.app.reset(),t.app.username=e,t.app.password=n,t.app.clientdatas=r,t.app.createAccount_loginapp(!0)},e.prototype.createAccount_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_createAccount;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_reqCreateAccount),n.writeString(t.app.username),n.writeString(t.app.password),n.writeBlob(t.app.clientdatas),n.send(t.app)}},e.prototype.bindAccountEmail=function(e){var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_reqAccountBindEmail),n.writeInt32(t.app.entity_id),n.writeString(t.app.password),n.writeString(e),n.send(t.app)},e.prototype.newPassword=function(e,n){var r=t.Bundle.createObject();r.newMessage(t.messages.Baseapp_reqAccountNewPassword),r.writeInt32(t.app.entity_id),r.writeString(e),r.writeString(n),r.send(t.app)},e.prototype.logout=function(){var e=new t.Bundle;e.newMessage(t.messages.Baseapp_logoutBaseapp),e.writeUint64(t.app.entity_uuid),e.writeInt32(t.app.entity_id),e.send(t.app)},e.prototype.login=function(e,n,r){t.app.reset(),t.app.username=e,t.app.password=n,t.app.clientdatas=r,t.app.login_loginapp(!0)},e.prototype.login_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::login_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_login;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_login),n.writeInt8(t.app.args.clientType),n.writeBlob(t.app.clientdatas),n.writeString(t.app.username),n.writeString(t.app.password),n.send(t.app)}},e.prototype.onOpenLoginapp_resetpassword=function(){if(t.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: successfully!"),t.app.currserver="loginapp",t.app.currstate="resetpassword",t.app.loginappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Loginapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.INFO_MSG("KBEngineApp::onOpenLoginapp_resetpassword: start importClientMessages ...")}},e.prototype.reset_password=function(e){t.app.reset(),t.app.username=e,t.app.resetpassword_loginapp(!0)},e.prototype.resetpassword_loginapp=function(e){if(e)t.INFO_MSG("KBEngineApp::createAccount_loginapp: start connect to ws://"+t.app.args.ip+":"+t.app.args.port+"!"),t.app.currconnect="loginapp",t.app.connect(t.app.args.ip,t.app.args.port),t.app.socket.onopen=t.app.onOpenLoginapp_resetpassword;else{var n=t.Bundle.createObject();n.newMessage(t.messages.Loginapp_reqAccountResetPassword),n.writeString(t.app.username),n.send(t.app)}},e.prototype.onOpenBaseapp=function(){if(t.INFO_MSG("KBEngineApp::onOpenBaseapp: successfully!"),t.app.currserver="baseapp",t.app.baseappMessageImported)t.app.onImportClientMessagesCompleted();else{var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_importClientMessages),e.send(t.app),t.app.socket.onmessage=t.app.Client_onImportClientMessages,t.Event.fire("Baseapp_importClientMessages")}},e.prototype.login_baseapp=function(e){if(e)t.Event.fire("onLoginBaseapp"),t.INFO_MSG("KBEngineApp::login_baseapp: start connect to ws://"+t.app.baseappIp+":"+t.app.baseappPort+"!"),t.app.currconnect="baseapp",t.app.connect(t.app.baseappIp,t.app.baseappPort),void 0!=t.app.socket&&null!=t.app.socket&&(t.app.socket.onopen=t.app.onOpenBaseapp);else{var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_loginBaseapp),n.writeString(t.app.username),n.writeString(t.app.password),n.send(t.app)}},e.prototype.reloginBaseapp=function(){t.app.lastTickCBTime=t.app.lastTickTime=Date.now(),(void 0==t.app.socket||null==t.app.socket)&&(t.app.resetSocket(),t.Event.fire(t.EventTypes.onReloginBaseapp),t.INFO_MSG("KBEngineApp::reloginBaseapp: start connect to ws://"+t.app.baseappIp+":"+t.app.baseappPort+"!"),t.app.currconnect="baseapp",t.app.connect(t.app.baseappIp,t.app.baseappPort),void 0!=t.app.socket&&null!=t.app.socket&&(t.app.socket.onopen=t.app.onReOpenBaseapp))},e.prototype.onReOpenBaseapp=function(){t.INFO_MSG("KBEngineApp::onReOpenBaseapp: successfully!"),t.app.currserver="baseapp";var e=t.Bundle.createObject();e.newMessage(t.messages.Baseapp_reloginBaseapp),e.writeString(t.app.username),e.writeString(t.app.password),e.writeUint64(t.app.entity_uuid),e.writeInt32(t.app.entity_id),e.send(t.app);var n=new Date;t.app.lastTickCBTime=n.getTime()},e.prototype.Client_onHelloCB=function(e){t.app.serverVersion=e.readString(),t.app.serverScriptVersion=e.readString(),t.app.serverProtocolMD5=e.readString(),t.app.serverEntityDefMD5=e.readString();var n=e.readInt32();t.INFO_MSG("KBEngineApp::Client_onHelloCB: verInfo("+t.app.serverVersion+"), scriptVerInfo("+t.app.serverScriptVersion+"), serverProtocolMD5("+t.app.serverProtocolMD5+"), serverEntityDefMD5("+t.app.serverEntityDefMD5+"), ctype("+n+")!");var r=new Date;t.app.lastTickCBTime=r.getTime()},e.prototype.Client_onLoginFailed=function(e){var n=e.readUint16(); +t.app.serverdatas=e.readBlob(),t.ERROR_MSG("KBEngineApp::Client_onLoginFailed: failedcode("+t.app.serverErrs[n].name+"), datas("+t.app.serverdatas.length+")!"),t.Event.fire("onLoginFailed",n)},e.prototype.Client_onLoginSuccessfully=function(e){var n=e.readString();t.app.username=n,t.app.baseappIp=e.readString(),t.app.baseappPort=e.readUint16(),t.app.baseappUdpPort=e.readUint16(),t.app.serverdatas=e.readBlob(),t.INFO_MSG("KBEngineApp::Client_onLoginSuccessfully: accountName("+n+"), addr("+t.app.baseappIp+":"+t.app.baseappPort+"), datas("+t.app.serverdatas.length+")!"),t.app.disconnect(),t.app.login_baseapp(!0)},e.prototype.Client_onLoginBaseappFailed=function(e){t.ERROR_MSG("KBEngineApp::Client_onLoginBaseappFailed: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onLoginBaseappFailed,e)},e.prototype.Client_onReloginBaseappFailed=function(e){t.ERROR_MSG("KBEngineApp::Client_onReloginBaseappFailed: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onReloginBaseappFailed,e)},e.prototype.Client_onReloginBaseappSuccessfully=function(e){t.app.entity_uuid=e.readUint64(),t.DEBUG_MSG("KBEngineApp::Client_onReloginBaseappSuccessfully: "+t.app.username),t.Event.fire(t.EventTypes.onReloginBaseappSuccessfully)},e.prototype.getentityclass=function(e){var n=t.Entities[e];return void 0==n?(t.ERROR_MSG("KBEngineApp::getentityclass: entityType("+e+") is error!"),n):n},e.prototype.Client_onCreatedProxies=function(e,n,r){t.INFO_MSG("KBEngineApp::Client_onCreatedProxies: eid("+n+"), entityType("+r+")!");var a=t.app.entities[n];if(t.app.entity_uuid=e,t.app.entity_id=n,void 0==a){var i=t.app.getentityclass(r);if(void 0==i)return;var o=new i;o.id=n,o.className=r,o.base=new t.EntityCall,o.base.id=n,o.base.className=r,o.base.type=t.ENTITYCALL_TYPE_BASE,t.app.entities[n]=o;var p=t.bufferedCreateEntityMessages[n];void 0!=p&&(t.app.Client_onUpdatePropertys(p),delete t.bufferedCreateEntityMessages[n]),o.__init__(),o.attachComponents(),o.inited=!0,t.app.args.isOnInitCallPropertysSetMethods&&o.callPropertysSetMethods()}else{var p=t.bufferedCreateEntityMessages[n];void 0!=p&&(t.app.Client_onUpdatePropertys(p),delete t.bufferedCreateEntityMessages[n])}},e.prototype.getViewEntityIDFromStream=function(e){var n=0;if(t.app.entityIDAliasIDList.length>255)n=e.readInt32();else{var r=e.readUint8();if(t.app.entityIDAliasIDList.length<=r)return 0;n=t.app.entityIDAliasIDList[r]}return n},e.prototype.onUpdatePropertys_=function(e,n){var r=t.app.entities[e];if(void 0==r){var a=t.bufferedCreateEntityMessages[e];if(void 0!=a)return void t.ERROR_MSG("KBEngineApp::Client_onUpdEntityComponentatePropertys: entity("+e+") not found!");var i=new t.MemoryStream(n.buffer);return i.wpos=n.wpos,i.rpos=n.rpos-4,void(t.bufferedCreateEntityMessages[e]=i)}r.onUpdatePropertys(n)},e.prototype.Client_onUpdatePropertysOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.onUpdatePropertys_(n,e)},e.prototype.Client_onUpdatePropertys=function(e){var n=e.readInt32();t.app.onUpdatePropertys_(n,e)},e.prototype.onRemoteMethodCall_=function(e,n){var r=t.app.entities[e];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity("+e+") not found!"):void r.onRemoteMethodCall(n)},e.prototype.Client_onRemoteMethodCallOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.onRemoteMethodCall_(n,e)},e.prototype.Client_onRemoteMethodCall=function(e){var n=e.readInt32();t.app.onRemoteMethodCall_(n,e)},e.prototype.Client_onEntityEnterWorld=function(e){var n=e.readInt32();t.app.entity_id>0&&n!=t.app.entity_id&&t.app.entityIDAliasIDList.push(n);var r;r=t.moduledefs.Length>255?e.readUint16():e.readUint8();var a=!0;e.length()>0&&(a=e.readInt8()),r=t.moduledefs[r].name,t.INFO_MSG("KBEngineApp::Client_onEntityEnterWorld: "+r+"("+n+"), spaceID("+t.app.spaceID+"), isOnGround("+a+")!");var i=t.app.entities[n];if(void 0==i){var o=t.bufferedCreateEntityMessages[n];if(void 0==o)return void t.ERROR_MSG("KBEngineApp::Client_onEntityEnterWorld: entity("+n+") not found!");var p=t.app.getentityclass(r);if(void 0==p)return;var s=new p;s.id=n,s.className=r,s.cell=new t.EntityCall,s.cell.id=n,s.cell.className=r,s.cell.type=t.ENTITYCALL_TYPE_CELL,t.app.entities[n]=s,t.app.Client_onUpdatePropertys(o),delete t.bufferedCreateEntityMessages[n],s.isOnGround=a,s.__init__(),s.attachComponents(),s.inited=!0,s.inWorld=!0,s.enterWorld(),t.app.args.isOnInitCallPropertysSetMethods&&s.callPropertysSetMethods(),s.set_direction(s.direction),s.set_position(s.position)}else i.inWorld||(i.cell=new t.EntityCall,i.cell.id=n,i.cell.className=r,i.cell.type=t.ENTITYCALL_TYPE_CELL,t.app.entityIDAliasIDList=[],t.app.entities={},t.app.entities[i.id]=i,i.set_direction(i.direction),i.set_position(i.position),t.app.entityServerPos.x=i.position.x,t.app.entityServerPos.y=i.position.y,t.app.entityServerPos.z=i.position.z,i.isOnGround=a,i.inWorld=!0,i.enterWorld(),t.app.args.isOnInitCallPropertysSetMethods&&i.callPropertysSetMethods())},e.prototype.Client_onEntityLeaveWorldOptimized=function(e){var n=t.app.getViewEntityIDFromStream(e);t.app.Client_onEntityLeaveWorld(n)},e.prototype.Client_onEntityLeaveWorld=function(e){var n=t.app.entities[e];if(void 0==n)return void t.ERROR_MSG("KBEngineApp::Client_onEntityLeaveWorld: entity("+e+") not found!");if(n.inWorld&&n.leaveWorld(),t.app.entity_id>0&&e!=t.app.entity_id){for(var r=[],a=0;a0&&(r=e.readInt8());var a=t.app.entities[n];return void 0==a?void t.ERROR_MSG("KBEngineApp::Client_onEntityEnterSpace: entity("+n+") not found!"):(a.isOnGround=r,t.app.entityServerPos.x=a.position.x,t.app.entityServerPos.y=a.position.y,t.app.entityServerPos.z=a.position.z,void a.enterSpace())},e.prototype.Client_onEntityLeaveSpace=function(e){var n=t.app.entities[e];return void 0==n?void t.ERROR_MSG("KBEngineApp::Client_onEntityLeaveSpace: entity("+e+") not found!"):(t.app.clearSpace(!1),void n.leaveSpace())},e.prototype.Client_onKicked=function(e){t.ERROR_MSG("KBEngineApp::Client_onKicked: failedcode("+t.app.serverErrs[e].name+")!"),t.Event.fire(t.EventTypes.onKicked,e)},e.prototype.Client_onCreateAccountResult=function(e){var n=e.readUint16(),r=e.readBlob();return t.Event.fire("onCreateAccountResult",n,r),0!=n?void t.ERROR_MSG("KBEngineApp::Client_onCreateAccountResult: "+t.app.username+" create is failed! code="+t.app.serverErrs[n].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onCreateAccountResult: "+t.app.username+" create is successfully!")},e.prototype.Client_onControlEntity=function(e,n){var r=t.app.entities[e];if(void 0==r)return void t.ERROR_MSG("KBEngineApp::Client_onControlEntity: entity("+e+") not found!");var a=0!=n;if(a)t.app.player().id!=r.id&&t.app.controlledEntities.push(r);else{for(var i=[],o=0;o.001||e.entityLastLocalDir.distance(e.direction)>.001){e.entityLastLocalPos.x=e.position.x,e.entityLastLocalPos.y=e.position.y,e.entityLastLocalPos.z=e.position.z,e.entityLastLocalDir.x=e.direction.x,e.entityLastLocalDir.y=e.direction.y,e.entityLastLocalDir.z=e.direction.z;var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_onUpdateDataFromClient),n.writeFloat(e.position.x),n.writeFloat(e.position.y),n.writeFloat(e.position.z),n.writeFloat(e.direction.x),n.writeFloat(e.direction.y),n.writeFloat(e.direction.z),n.writeUint8(e.isOnGround),n.writeUint32(t.app.spaceID),n.send(t.app)}for(var r in t.app.controlledEntities){var a=t.app.controlledEntities[r],i=a.position,o=a.direction,p=a.entityLastLocalPos.distance(i)>.001,s=a.entityLastLocalDir.distance(o)>.001;if(p||s){a.entityLastLocalPos=i,a.entityLastLocalDir=o;var n=t.Bundle.createObject();n.newMessage(t.messages.Baseapp_onUpdateDataFromClientForControlledEntity),n.writeInt32(a.id),n.writeFloat(i.x),n.writeFloat(i.y),n.writeFloat(i.z),n.writeFloat(o.x),n.writeFloat(o.y),n.writeFloat(o.z),n.writeUint8(a.isOnGround),n.writeUint32(t.app.spaceID),n.send(t.app)}}}},e.prototype.addSpaceGeometryMapping=function(e,n){t.INFO_MSG("KBEngineApp::addSpaceGeometryMapping: spaceID("+e+"), respath("+n+")!"),t.app.spaceID=e,t.app.spaceResPath=n,t.Event.fire(t.EventTypes.addSpaceGeometryMapping,n)},e.prototype.clearSpace=function(e){t.app.entityIDAliasIDList=[],t.app.spacedata={},t.app.clearEntities(e),t.app.isLoadedGeometry=!1,t.app.spaceID=0},e.prototype.clearEntities=function(e){if(t.app.controlledEntities=[],e){for(var n in t.app.entities)t.app.entities[n].inWorld&&t.app.entities[n].leaveWorld(),t.app.entities[n].onDestroy();t.app.entities={}}else{var r=t.app.player();for(var n in t.app.entities)n!=r.id&&(t.app.entities[n].inWorld&&t.app.entities[n].leaveWorld(),t.app.entities[n].onDestroy());t.app.entities={},t.app.entities[r.id]=r}},e.prototype.Client_initSpaceData=function(e){for(t.app.clearSpace(!1),t.app.spaceID=e.readInt32();e.length()>0;){var n=e.readString(),r=e.readString();t.app.Client_setSpaceData(t.app.spaceID,n,r)}t.INFO_MSG("KBEngineApp::Client_initSpaceData: spaceID("+t.app.spaceID+"), datas("+t.app.spacedata+")!")},e.prototype.Client_setSpaceData=function(e,n,r){t.INFO_MSG("KBEngineApp::Client_setSpaceData: spaceID("+e+"), key("+n+"), value("+r+")!"),t.app.spacedata[n]=r,"_mapping"==n&&t.app.addSpaceGeometryMapping(e,r),t.Event.fire("onSetSpaceData",e,n,r)},e.prototype.Client_delSpaceData=function(e,n){t.INFO_MSG("KBEngineApp::Client_delSpaceData: spaceID("+e+"), key("+n+")!"),delete t.app.spacedata[n],t.Event.fire("onDelSpaceData",e,n)},e.prototype.Client_getSpaceData=function(e,n){return t.app.spacedata[n]},e.prototype.Client_onUpdateBasePos=function(e,n,r){t.app.entityServerPos.x=e,t.app.entityServerPos.y=n,t.app.entityServerPos.z=r},e.prototype.Client_onUpdateBasePosXZ=function(e,n){t.app.entityServerPos.x=e,t.app.entityServerPos.z=n},e.prototype.Client_onUpdateData=function(e){var n=t.app.getViewEntityIDFromStream(e),r=t.app.entities[n];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onUpdateData: entity("+n+") not found!"):void 0},e.prototype.Client_onSetEntityPosAndDir=function(e){var n=e.readInt32(),r=t.app.entities[n];return void 0==r?void t.ERROR_MSG("KBEngineApp::Client_onSetEntityPosAndDir: entity("+n+") not found!"):(r.position.x=e.readFloat(),r.position.y=e.readFloat(),r.position.z=e.readFloat(),r.direction.x=e.readFloat(),r.direction.y=e.readFloat(),r.direction.z=e.readFloat(),r.entityLastLocalPos.x=r.position.x,r.entityLastLocalPos.y=r.position.y,r.entityLastLocalPos.z=r.position.z,r.entityLastLocalDir.x=r.direction.x,r.entityLastLocalDir.y=r.direction.y,r.entityLastLocalDir.z=r.direction.z,r.set_direction(r.direction),void r.set_position(r.position))},e.prototype.Client_onUpdateData_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,i,-1)},e.prototype.Client_onUpdateData_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,a,-1)},e.prototype.Client_onUpdateData_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,-1)},e.prototype.Client_onUpdateData_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,-1)},e.prototype.Client_onUpdateData_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,-1)},e.prototype.Client_onUpdateData_xz=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,o,p,1)},e.prototype.Client_onUpdateData_xz_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,o,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,t.KBE_FLT_MAX,o,1)},e.prototype.Client_onUpdateData_xz_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,i,o,1)},e.prototype.Client_onUpdateData_xz_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readInt8();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,i,t.KBE_FLT_MAX,1)},e.prototype.Client_onUpdateData_xz_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readInt8();t.app._updateVolatileData(n,r,t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,i,1)},e.prototype.Client_onUpdateData_xyz=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat();t.app._updateVolatileData(n,r,a,i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_ypr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat(),s=e.readFloat();t.app._updateVolatileData(n,r,a,i,o,p,s,0)},e.prototype.Client_onUpdateData_xyz_yp=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,p,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_yr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,p,0)},e.prototype.Client_onUpdateData_xyz_pr=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat(),p=e.readFloat();t.app._updateVolatileData(n,r,i,a,t.KBE_FLT_MAX,o,p,0)},e.prototype.Client_onUpdateData_xyz_y=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_p=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,t.KBE_FLT_MAX,o,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_xyz_r=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readFloat(),a=e.readFloat(),i=e.readFloat(),o=e.readFloat();t.app._updateVolatileData(n,r,i,a,o,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0)},e.prototype.Client_onUpdateData_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,i,-1,!0)},e.prototype.Client_onUpdateData_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,a,-1,!0)},e.prototype.Client_onUpdateData_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8(),a=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,a,-1,!0)},e.prototype.Client_onUpdateData_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,t.KBE_FLT_MAX,-1,!0)},e.prototype.Client_onUpdateData_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readInt8();t.app._updateVolatileData(n,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,r,-1,!0)},e.prototype.Client_onUpdateData_xz_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,i,o,1,!0)},e.prototype.Client_onUpdateData_xz_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,i,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,t.KBE_FLT_MAX,i,1,!0)},e.prototype.Client_onUpdateData_xz_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8(),i=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,a,i,1,!0)},e.prototype.Client_onUpdateData_xz_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],a,t.KBE_FLT_MAX,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,a,t.KBE_FLT_MAX,1,!0)},e.prototype.Client_onUpdateData_xz_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readInt8();t.app._updateVolatileData(n,r[0],t.KBE_FLT_MAX,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,a,1,!0)},e.prototype.Client_onUpdateData_xyz_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_ypr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8(),p=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,o,p,0,!0)},e.prototype.Client_onUpdateData_xyz_yp_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,o,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_yr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,o,0,!0)},e.prototype.Client_onUpdateData_xyz_pr_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8(),o=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,i,o,0,!0)},e.prototype.Client_onUpdateData_xyz_y_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_p_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],t.KBE_FLT_MAX,i,t.KBE_FLT_MAX,0,!0)},e.prototype.Client_onUpdateData_xyz_r_optimized=function(e){var n=t.app.getViewEntityIDFromStream(e),r=e.readPackXZ(),a=e.readPackY(),i=e.readInt8();t.app._updateVolatileData(n,r[0],a,r[1],i,t.KBE_FLT_MAX,t.KBE_FLT_MAX,0,!0)},e.prototype._updateVolatileData=function(e,n,r,a,i,o,p,s,l){void 0===l&&(l=!1);var c=t.app.entities[e];if(void 0==c)return void t.ERROR_MSG("KBEngineApp::_updateVolatileData: entity("+e+") not found!");s>=0&&(c.isOnGround=s>0);var d=!1;p!=t.KBE_FLT_MAX&&(d=!0,c.direction.x=t.int82angle(p,!1)),o!=t.KBE_FLT_MAX&&(d=!0,c.direction.y=t.int82angle(o,!1)),i!=t.KBE_FLT_MAX&&(d=!0,c.direction.z=t.int82angle(i,!1));var u=!1;1==d&&(t.Event.fire("set_direction",c),u=!0);var y=!1;(n!=t.KBE_FLT_MAX||r!=t.KBE_FLT_MAX||a!=t.KBE_FLT_MAX)&&(y=!0),n==t.KBE_FLT_MAX&&(n=0),r==t.KBE_FLT_MAX&&(r=0),a==t.KBE_FLT_MAX&&(a=0),y&&(l?(c.position.x=n+t.app.entityServerPos.x,c.position.y=r+t.app.entityServerPos.y,c.position.z=a+t.app.entityServerPos.z):(c.position.x=n,c.position.y=r,c.position.z=a),u=!0,t.Event.fire("updatePosition",c)),u&&c.onUpdateVolatileData()},e.prototype.Client_onStreamDataStarted=function(e,n,r){t.Event.fire(t.EventTypes.onStreamDataStarted,e,n,r)},e.prototype.Client_onStreamDataRecv=function(e){var n=e.readUint16(),r=e.readBlob();t.Event.fire(t.EventTypes.onStreamDataRecv,n,r)},e.prototype.Client_onStreamDataCompleted=function(e){t.Event.fire(t.EventTypes.onStreamDataCompleted,e)},e.prototype.Client_onReqAccountResetPasswordCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountResetPasswordCB: "+t.app.username+" is successfully!")},e.prototype.Client_onReqAccountBindEmailCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountBindEmailCB: "+t.app.username+" is successfully!")},e.prototype.Client_onReqAccountNewPasswordCB=function(e){return 0!=e?void t.ERROR_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+t.app.username+" is failed! code="+t.app.serverErrs[e].name+"!"):void t.INFO_MSG("KBEngineApp::Client_onReqAccountNewPasswordCB: "+t.app.username+" is successfully!")},e}();t.KBEngineApp=r,__reflect(r.prototype,"KBEngine.KBEngineApp");var a=function(){function t(){this.name="",this.descr="",this.id=0}return t}();t.ServerErr=a,__reflect(a.prototype,"KBEngine.ServerErr"),t.FragmentDataTypes={FRAGMENT_DATA_UNKNOW:0,FRAGMENT_DATA_MESSAGE_ID:1,FRAGMENT_DATA_MESSAGE_LENGTH:2,FRAGMENT_DATA_MESSAGE_LENGTH1:3,FRAGMENT_DATA_MESSAGE_BODY:4};var i;t.create=e,t.destroy=n}(KBEngine||(KBEngine={})); \ No newline at end of file diff --git a/kbengine_ts/src/KBEngine.ts b/kbengine_ts/src/KBEngine.ts index ae9b46a..64a5ac5 100644 --- a/kbengine_ts/src/KBEngine.ts +++ b/kbengine_ts/src/KBEngine.ts @@ -1534,7 +1534,7 @@ namespace KBEngine { let flags = propertydata[6]; if (!propertydata[4]) { if (this[propertydata[2]] && typeof this[propertydata[2]].createFromStream === 'function') - this[propertydata[2]].createFromStream(stream) + this[propertydata[2]].createFromStream(stream, propertydata[0]) continue; } let val = propertydata[4].createFromStream(stream); @@ -1558,6 +1558,30 @@ namespace KBEngine { DEBUG_MSG(this.className + "::set_direction: " + this.direction); Event.fire("set_direction", this); } + onRemoteMethodCall(stream: MemoryStream) { + let sm = moduledefs[this.className] + let ComponentID = sm.usePropertyDescrAlias ? stream.readUint8() : stream.readUint16(); + let methodUtype = sm.useMethodDescrAlias ? stream.readUint8() : stream.readUint16(); + if (ComponentID !== 0) { + let comp = this[sm.propertys[ComponentID][2]]; + if (comp) comp.onRemoteMethodCall(methodUtype, stream) + return; + } + + let methoddata = moduledefs[this.className].methods[methodUtype]; + let args = []; + let argsdata = methoddata[3]; + for (let i = 0; i < argsdata.length; i++) { + args.push(argsdata[i].createFromStream(stream)); + } + + if (this[methoddata[2]] != undefined) { + this[methoddata[2]].apply(this, args); + } + else { + ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + this.id + ") not found method(" + methoddata[2] + ")!"); + } + } } export function registerEntity() { return (ctor: new () => Entity) => { @@ -1574,7 +1598,7 @@ namespace KBEngine { componentType = 0; ownerID = 0; owner: Entity = null; - name_: string = '' + className = ''; base: EntityComponentCall = null; cell: EntityComponentCall = null; @@ -1584,6 +1608,98 @@ namespace KBEngine { protected onEnterWorld() { } protected onLeaveWorld() { } + baseCall(type: string, ...params: any[]) { + let className = this.className + if (this.base == undefined) { + ERROR_MSG('Entity::baseCall: base is None!'); + return; + } + + let method = moduledefs[className].base_methods[type]; + + if (method == undefined) { + ERROR_MSG("Entity::baseCall: The server did not find the def_method(" + className + "." + type + ")!"); + return; + } + + let methodID = method[0]; + let args = method[3]; + + if (params.length != args.length) { + ERROR_MSG("Entity::baseCall: args(" + (params.length - 1) + "!= " + args.length + ") size is error!"); + return; + } + + this.base.newCall(); + this.base.bundle.writeUint16(this.entityComponentPropertyID); + this.base.bundle.writeUint16(methodID); + + try { + for (let i = 0; i < params.length; i++) { + if (args[i].isSameType(params[i])) { + args[i].addToStream(this.base.bundle, params[i]); + } + else { + throw new Error("Entity::baseCall: arg[" + i + "] is error!"); + } + } + } + catch (e) { + ERROR_MSG(e.toString()); + ERROR_MSG('Entity::baseCall: args is error!'); + this.base.bundle = null; + return; + } + + this.base.sendCall(); + } + cellCall(type: string, ...params: any[]) { + + let className = this.className + + if (this.cell == undefined) { + ERROR_MSG('Entity::cellCall: cell is None!'); + return; + } + + let method = moduledefs[className].cell_methods[type]; + + if (method == undefined) { + ERROR_MSG("Entity::cellCall: The server did not find the def_method(" + className + "." + type + ")!"); + return; + } + + let methodID = method[0]; + let args = method[3]; + + if (params.length != args.length) { + ERROR_MSG("Entity::cellCall: args(" + (params.length) + "!= " + args.length + ") size is error!"); + return; + } + + this.cell.newCall() + this.cell.bundle.writeUint16(this.entityComponentPropertyID); + this.cell.bundle.writeUint16(methodID); + + try { + for (let i = 0; i < args.length; i++) { + if (args[i].isSameType(params[i])) { + args[i].addToStream(this.cell.bundle, params[i]); + } + else { + throw new Error("Entity::cellCall: arg[" + i + "] is error!"); + } + } + } + catch (e) { + ERROR_MSG(e.toString()); + ERROR_MSG('Entity::cellCall: args is error!'); + this.cell.bundle = null; + return; + } + + this.cell.sendCall(); + } onUpdatePropertys(propUtype: number, stream: MemoryStream, maxCount: number) { let className = getQualifiedClassName(this) let currModule = moduledefs[className]; @@ -1619,7 +1735,18 @@ namespace KBEngine { } } } - createFromStream(stream: MemoryStream) { + onRemoteMethodCall(propUtype: number, stream: MemoryStream) { + let sm = moduledefs[this.className].methods[propUtype]; + + let args = []; + let argsdata = sm[3]; + for (let i = 0; i < argsdata.length; i++) { + args.push(argsdata[i].createFromStream(stream)); + } + typeof this[sm[2]] === 'function' && this[sm[2]].apply(this, args) + } + createFromStream(stream: MemoryStream, ecpId: number) { + this.entityComponentPropertyID = ecpId; this.componentType = stream.readInt32(); this.ownerID = stream.readInt32() this.owner = app.entities[this.ownerID]; @@ -1630,9 +1757,10 @@ namespace KBEngine { if (count > 0) { this.onUpdatePropertys(0, stream, count) } - this.base = new EntityComponentCall(this.entityComponentPropertyID, this.ownerID) + this.className = getQualifiedClassName(this) + this.base = new EntityComponentCall(this.entityComponentPropertyID, this.ownerID, this.className) this.base.type = ENTITYCALL_TYPE_BASE - this.cell = new EntityComponentCall(this.entityComponentPropertyID, this.ownerID) + this.cell = new EntityComponentCall(this.entityComponentPropertyID, this.ownerID, this.className) this.cell.type = ENTITYCALL_TYPE_CELL } } @@ -1680,7 +1808,7 @@ namespace KBEngine { return this.bundle; } - sendCall(bundle) { + sendCall(bundle?: Bundle) { if (bundle == undefined) bundle = this.bundle; @@ -1691,10 +1819,12 @@ namespace KBEngine { } } export class EntityComponentCall extends EntityCall { - constructor(ecpId: number, eid: number) { + entityComponentPropertyID = 0 + constructor(ecpId: number, eid: number, className: string) { super() + this.entityComponentPropertyID = ecpId; this.id = eid; - this.className = getQualifiedClassName(this); + this.className = className } } @@ -3611,29 +3741,7 @@ namespace KBEngine { ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); return; } - - let methodUtype = 0, ComponentID = 0; - if (moduledefs[entity.className].useMethodDescrAlias) { - ComponentID = stream.readInt8() - methodUtype = stream.readUint8(); - } - else { - ComponentID = stream.readUint16(); - methodUtype = stream.readUint16(); - } - let methoddata = moduledefs[entity.className].methods[methodUtype]; - let args = []; - let argsdata = methoddata[3]; - for (let i = 0; i < argsdata.length; i++) { - args.push(argsdata[i].createFromStream(stream)); - } - - if (entity[methoddata[2]] != undefined) { - entity[methoddata[2]].apply(entity, args); - } - else { - ERROR_MSG("KBEngineApp::Client_onRemoteMethodCall: entity(" + eid + ") not found method(" + methoddata[2] + ")!"); - } + entity.onRemoteMethodCall(stream) } Client_onRemoteMethodCallOptimized(stream) { let eid = app.getViewEntityIDFromStream(stream);