(function () {
    'use strict';

    class GameConfig {
        constructor() { }
        static init() {
            var reg = Laya.ClassUtils.regClass;
        }
    }
    GameConfig.width = 640;
    GameConfig.height = 1136;
    GameConfig.scaleMode = "fixedwidth";
    GameConfig.screenMode = "none";
    GameConfig.alignV = "top";
    GameConfig.alignH = "left";
    GameConfig.startScene = "";
    GameConfig.sceneRoot = "";
    GameConfig.debug = false;
    GameConfig.stat = false;
    GameConfig.physicsDebug = false;
    GameConfig.exportSceneToJson = true;
    GameConfig.init();

    class ResDic {
        constructor() {
            this._container = {};
            this._length = 0;
        }
        get container() {
            return this._container;
        }
        get size() {
            return this._length;
        }
        set(key, value) {
            if (!this._container.hasOwnProperty(key)) {
                this._length++;
            }
            this._container[key] = value;
        }
        has(key) {
            return this._container.hasOwnProperty(key) ? true : false;
        }
        get(key) {
            if (this._container.hasOwnProperty(key)) {
                return this._container[key];
            }
            else {
                return undefined;
            }
        }
        delete(key) {
            if (this._container.hasOwnProperty(key)) {
                delete this._container[key];
                this._length--;
            }
        }
        clear() {
            this._container = {};
            this._length = 0;
        }
    }

    var EventState;
    (function (EventState) {
        EventState[EventState["LoadComplete"] = 0] = "LoadComplete";
        EventState[EventState["SceneInit"] = 1] = "SceneInit";
        EventState[EventState["StageInit"] = 2] = "StageInit";
        EventState[EventState["StageCreateComplete"] = 3] = "StageCreateComplete";
        EventState[EventState["AnimatorEnd"] = 4] = "AnimatorEnd";
    })(EventState || (EventState = {}));
    var StageState;
    (function (StageState) {
        StageState[StageState["Win"] = 0] = "Win";
        StageState[StageState["Lose"] = 1] = "Lose";
        StageState[StageState["Start"] = 2] = "Start";
        StageState[StageState["StageCreateComPlete"] = 3] = "StageCreateComPlete";
        StageState[StageState["Over"] = 4] = "Over";
    })(StageState || (StageState = {}));
    class EventManager {
        static EventOn(_mode, caller, fun, args = []) {
            EventManager.instance.on(EventState[_mode], caller, fun, args);
        }
        static EventOff(_mode, caller, fun, args = []) {
            EventManager.instance.off(EventState[_mode], caller, fun);
        }
        static EventTrigger(_mode, args = []) {
            EventManager.instance.event(EventState[_mode], args);
        }
        static StageOn(_mode, caller, fun, args = []) {
            EventManager.instance.on(StageState[_mode], caller, fun, args);
        }
        static StageOff(_mode, caller, fun, args = []) {
            EventManager.instance.off(StageState[_mode], caller, fun);
        }
        static StageTrigger(_mode, args = []) {
            EventManager.instance.event(StageState[_mode], args);
        }
    }
    EventManager.instance = new Laya.EventDispatcher();

    class AssetManager {
        constructor() {
            this.Player = new ResDic();
            this.Enemy = new ResDic();
            this.Horse = new ResDic();
            this.Prop = new ResDic();
            AssetManager.ins = this;
            EventManager.EventOn(EventState.LoadComplete, this, this.Init);
        }
        static get Instance() {
            if (AssetManager.ins) {
                return AssetManager.ins;
            }
            else {
                return new AssetManager();
            }
        }
        Init() {
            this.maincamera = this.mainscene.getChildByName("Main Camera");
            this.Plane = this.mainscene.getChildByName("Plane");
            EventManager.EventTrigger(EventState.SceneInit);
        }
    }
    class ResourcesPath {
    }
    ResourcesPath.MainScene = "Game/res/MainScene/LayaScene_Mainscene/Conventional/Mainscene.ls";
    ResourcesPath.Horse = [
        "Game/res/Role/LayaScene_Role/Conventional/Horse.lh"
    ];
    ResourcesPath.Player = [
        "Game/res/Role/LayaScene_Role/Conventional/player.lh"
    ];
    ResourcesPath.Enemy = [
        "Game/res/Role/LayaScene_Role/Conventional/enemy.lh"
    ];

    var Sprite3D = Laya.Sprite3D;
    var Vector3 = Laya.Vector3;
    class modelConfig {
        constructor(model) {
            this.modelcur = model;
            this.modelPos = model.transform.position.clone();
            this.modelRot = model.transform.rotation.clone();
            this.modelSca = model.transform.scale.clone();
        }
    }
    class GamePool {
        constructor() {
            this.modelpool = {};
            this.maxAcount = 30;
            GamePool.Ins = this;
        }
        static get Instance() {
            if (GamePool.Ins) {
                return GamePool.Ins;
            }
            else {
                return new GamePool();
            }
        }
        GetModel(_model, title) {
            var poolname = title + _model.name;
            if (this.modelpool[poolname] != null && this.modelpool[poolname] != undefined) {
                if (this.modelpool[poolname].length > 0) {
                    var model1 = this.modelpool[poolname][0];
                    this.modelpool[poolname].splice(0, 1);
                    if (model1.modelcur.destroyed) {
                        model1.modelcur = Sprite3D.instantiate(_model);
                        if (!model1.modelcur.active) {
                            model1.modelcur.active = true;
                        }
                    }
                    model1.modelcur.active = true;
                    model1.modelcur.transform.position = _model.transform.position.clone();
                    model1.modelcur.transform.rotation = _model.transform.rotation.clone();
                    model1.modelcur.transform.scale = _model.transform.scale.clone();
                    return model1.modelcur;
                }
                else {
                    var model = Sprite3D.instantiate(_model);
                    model.active = true;
                    return model;
                }
            }
            else {
                var model = Sprite3D.instantiate(_model);
                model.active = true;
                return model;
            }
        }
        RecoveryModel(model, title = "", modelstate = false) {
            if (model.destroyed) {
                return;
            }
            if (!modelstate && model.active == false) {
                return;
            }
            var poolname = title + model.name;
            if (this.modelpool[poolname] != null && this.modelpool[poolname] != undefined) {
                var modelnum = this.modelpool[poolname];
                if (modelnum.length > this.maxAcount) {
                    model.destroy();
                    return;
                }
                else {
                    modelnum.push(new modelConfig(model));
                }
            }
            else {
                modelnum = [];
                modelnum.push(new modelConfig(model));
                this.modelpool[poolname] = modelnum;
            }
            model.transform.position = new Vector3(0, 0, -10000);
            model.removeSelf();
            model.active = false;
        }
        ResetsModelPool() {
            for (var Key in this.modelpool) {
                var model = this.modelpool[Key];
                for (var i = 0; i < model.length; i++) {
                    model[i].modelcur.destroy();
                }
            }
            this.modelpool = {};
        }
    }

    class GameTools {
        constructor() {
            GameTools.ins = this;
        }
        static get Instance() {
            if (GameTools.ins) {
                return GameTools.ins;
            }
            else {
                return new GameTools();
            }
        }
        lerp(form, to, t) {
            if (t <= 0) {
                return form;
            }
            else if (t >= 1) {
                return to;
            }
            var a = t * to + (1 - t) * form;
            return a;
        }
        SetCollider(setNode, CollisionGroup) {
            var numchild = setNode.numChildren;
            for (var i = 0; i < setNode.numChildren; i++) {
                var numchild2 = setNode.getChildAt(i).numChildren;
                if (numchild2 > 1) {
                    this.SetCollider(setNode.getChildAt(i), CollisionGroup);
                }
                var physicsCollider = setNode.getChildAt(i).getComponent(Laya.PhysicsCollider);
                if (physicsCollider) {
                    physicsCollider.collisionGroup = CollisionGroup;
                }
            }
        }
        static RandomNumber(from, to) {
            if (from >= to) {
                return 0;
            }
            var size = to - from;
            var curNumber = Math.random() * size + from;
            return curNumber;
        }
        static RandomANumber(from, to) {
            if (from >= to) {
                return 0;
            }
            var size = to - from;
            var curNumber = Math.random() * size + from;
            return Math.floor(curNumber);
        }
        static GetMoney(_num, _pos = null, _completeHandle = null) {
            if (_num == 0)
                return;
            var fafaafsfa = new Laya.Box;
            fafaafsfa.width = 400;
            fafaafsfa.height = 100;
            fafaafsfa.pivotX = fafaafsfa.width / 2;
            fafaafsfa.pivotY = fafaafsfa.height / 2;
            if (_pos == null) {
                _pos = new Laya.Vector2(Laya.stage.width / 2, Laya.stage.height / 2);
            }
            fafaafsfa.pos(_pos.x, _pos.y);
            var aafafaffa = new Laya.Image;
            aafafaffa.skin = "game/qiandao_1_7.png";
            aafafaffa.width = 60;
            aafafaffa.height = 60;
            aafafaffa.left = 50;
            aafafaffa.y = 10;
            fafaafsfa.addChild(aafafaffa);
            var faasfafsafs = new Laya.Text;
            faasfafsafs.width = 300;
            faasfafsafs.height = 50;
            faasfafsafs.align = "center";
            faasfafsafs.valign = "middle";
            faasfafsafs.font = "Microsoft YaHei";
            faasfafsafs.fontSize = 40;
            faasfafsafs.color = "#FFFFFF";
            faasfafsafs.bold = true;
            faasfafsafs.font = "Microsoft YaHei";
            faasfafsafs.text = "金币 +" + _num;
            faasfafsafs.x = 60;
            faasfafsafs.y = 10;
            fafaafsfa.addChild(faasfafsafs);
            Laya.stage.addChild(fafaafsfa);
            var faasfsaf = Laya.Tween.to(fafaafsfa, { y: fafaafsfa.y - 200 }, 1500, Laya.Ease.expoInOut, Laya.Handler.create(this, () => {
                faasfsaf.clear();
                fafaafsfa.destroy();
                if (_completeHandle) {
                    _completeHandle.run();
                }
            }), 100);
        }
        static TweenText(faafssfafsa, _hight, _completeHandle = null, hide = true, _duration = 500) {
            var afasafsafsfa = new Laya.Text();
            afasafsafsfa.width = faafssfafsa.size.x;
            afasafsafsfa.height = faafssfafsa.size.y;
            afasafsafsfa.align = "center";
            afasafsafsfa.valign = "middle";
            afasafsafsfa.font = "Microsoft YaHei";
            afasafsafsfa.fontSize = faafssfafsa.fontSize;
            afasafsafsfa.pivotX = afasafsafsfa.width / 2;
            afasafsafsfa.pivotY = afasafsafsfa.height / 2;
            afasafsafsfa.color = "#5ad122";
            afasafsafsfa.bold = true;
            afasafsafsfa.stroke = 5;
            afasafsafsfa.strokeColor = "#ffffff";
            if (faafssfafsa.color) {
                faafssfafsa.color = faafssfafsa.color;
            }
            afasafsafsfa.text = faafssfafsa.message;
            afasafsafsfa.zOrder = 1;
            Laya.stage.addChildAt(afasafsafsfa, Laya.stage.numChildren - 1);
            afasafsafsfa.pos(faafssfafsa.pos.x, faafssfafsa.pos.y);
            var tween = Laya.Tween.to(afasafsafsfa, { y: afasafsafsfa.y - _hight, update: new Laya.Handler(this, function () {
                }) }, _duration, Laya.Ease.expoInOut, Laya.Handler.create(this, function () {
                tween.clear();
                if (hide) {
                    afasafsafsfa.destroy();
                }
                if (_completeHandle) {
                    _completeHandle.run();
                }
            }));
            if (hide) {
                Laya.Tween.to(afasafsafsfa, { alpha: 0.4 }, 500);
            }
            return afasafsafsfa;
        }
        static StationTweenText(faafssfafsa, _hight, _completeHandle = null, hide = true, _duration = 500) {
            var afasafsafsfa = new Laya.Text();
            afasafsafsfa.width = faafssfafsa.size.x;
            afasafsafsfa.height = faafssfafsa.size.y;
            afasafsafsfa.align = "center";
            afasafsafsfa.valign = "middle";
            afasafsafsfa.font = "Microsoft YaHei";
            afasafsafsfa.fontSize = 50;
            afasafsafsfa.pivotX = afasafsafsfa.width / 2;
            afasafsafsfa.pivotY = afasafsafsfa.height / 2;
            afasafsafsfa.color = "#5ad122";
            afasafsafsfa.bold = true;
            afasafsafsfa.stroke = 5;
            afasafsafsfa.strokeColor = "#ffffff";
            if (faafssfafsa.color) {
                faafssfafsa.color = faafssfafsa.color;
            }
            afasafsafsfa.text = faafssfafsa.message;
            afasafsafsfa.zOrder = 1;
            Laya.stage.addChildAt(afasafsafsfa, Laya.stage.numChildren - 1);
            afasafsafsfa.pos(faafssfafsa.pos.x, faafssfafsa.pos.y);
            var tween = Laya.Tween.to(afasafsafsfa, { y: afasafsafsfa.y - _hight, update: new Laya.Handler(this, function () {
                }) }, _duration, Laya.Ease.expoInOut, Laya.Handler.create(this, function () {
                tween.clear();
                if (hide) {
                    afasafsafsfa.destroy();
                }
                if (_completeHandle) {
                    _completeHandle.run();
                }
            }));
            if (hide) {
                Laya.Tween.to(afasafsafsfa, { alpha: 0.4 }, 10000);
            }
            return afasafsafsfa;
        }
        static tweenMove(transform, targPos, delay, ease, complete) {
            let curPos = transform.position.clone();
            return Laya.Tween.to(curPos, {
                x: targPos.x,
                y: targPos.y,
                z: targPos.z,
                update: new Laya.Handler(this, () => {
                    transform.position = curPos.clone();
                })
            }, delay, ease, complete);
        }
        static tweenRotate(transform, targEuler, delay, ease, complete) {
            let curEuler = transform.rotationEuler.clone();
            return Laya.Tween.to(curEuler, {
                x: targEuler.x,
                y: targEuler.y,
                z: targEuler.z,
                update: new Laya.Handler(this, () => {
                    transform.rotationEuler = curEuler.clone();
                })
            }, delay, ease, complete);
        }
    }

    var Vector2 = Laya.Vector2;
    var Vector3$1 = Laya.Vector3;
    class PlayerControl {
        constructor() {
            this.mousepos = new Vector2(0, 0);
            this.offx = 0;
            this.curtouchsmoothness = 0.02;
            this.poschazhi = new Vector3$1();
            this.gengsuipos = new Vector3$1();
            this.lllpos = new Vector3$1();
            this.hights = 0;
            this.wights = 0;
            PlayerControl.ins = this;
        }
        static get Instance() {
            if (PlayerControl.ins) {
                return PlayerControl.ins;
            }
            else {
                return new PlayerControl();
            }
        }
        Init(_player) {
            this.Player = _player;
            this.Player.transform.position = new Vector3$1();
            this.Camera = AssetManager.Instance.maincamera;
            this.Camera.transform.position = new Vector3$1(0, 15, -10);
            this.Camera.transform.localRotationEuler = new Vector3$1(-25, 0, 0);
            this.MouseListen();
            this.CameraFollow();
        }
        MouseListen() {
            Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.OnTouchEnter);
            Laya.stage.on(Laya.Event.MOUSE_UP, this, this.OnTouchOut);
            Laya.stage.on(Laya.Event.MOUSE_OUT, this, this.OnTouchOut);
        }
        OnTouchEnter() {
            this.mousepos = new Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
            Laya.timer.clear(this, this.OnTouchMove);
            Laya.timer.frameLoop(1, this, this.OnTouchMove);
        }
        OnTouchOut() {
            Laya.timer.clear(this, this.OnTouchMove);
        }
        OnTouchMove() {
            var MousePos = new Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
            var offestX = MousePos.x - this.mousepos.x;
            this.offx = GameTools.Instance.lerp(this.offx, offestX, this.curtouchsmoothness);
            var movespeed = this.offx * 0.07;
            this.Player.transform.translate(new Vector3$1(-movespeed, 0, 0));
            this.Player.transform.position = this.Player.transform.position.x < -4.5 ? new Vector3$1(-4.5, this.Player.transform.position.y, this.Player.transform.position.z) : this.Player.transform.position;
            this.Player.transform.position = this.Player.transform.position.x > 4.5 ? new Vector3$1(4.5, this.Player.transform.position.y, this.Player.transform.position.z) : this.Player.transform.position;
            var dir = new Vector3$1(-offestX * 0.001, 0, 0);
            this.mousepos = MousePos;
        }
        CameraFollow() {
            this.hights = 0;
            this.wights = 0;
            Vector3$1.subtract(this.Player.transform.position, this.Camera.transform.position, this.poschazhi);
            Laya.timer.frameLoop(1, this, this.GenSui);
        }
        GenSui() {
            Vector3$1.subtract(this.Player.transform.position, this.poschazhi, this.gengsuipos);
            this.hights = GameTools.Instance.lerp(this.hights, 1.0, 0.03);
            this.wights = GameTools.Instance.lerp(this.wights, 0.8, 0.02);
            this.gengsuipos = new Vector3$1(this.gengsuipos.x, this.gengsuipos.y, this.gengsuipos.z - this.wights);
            Vector3$1.lerp(this.Camera.transform.position, this.gengsuipos, 0.25, this.lllpos);
            this.lllpos = new Vector3$1(this.gengsuipos.x, this.gengsuipos.y, this.lllpos.z);
            this.lllpos = new Vector3$1(this.gengsuipos.x, this.lllpos.y, this.lllpos.z);
            this.Camera.transform.position = this.lllpos;
            var qqqwe = new Laya.Quaternion();
            var eyePos = new Vector3$1(this.gengsuipos.x, this.gengsuipos.y - 0.8, this.gengsuipos.z);
            Laya.Quaternion.lookAt(eyePos, this.Player.transform.position, new Vector3$1(0, 1, 0), qqqwe);
            qqqwe.invert(qqqwe);
            Laya.Quaternion.slerp(this.Camera.transform.rotation, qqqwe, 0.1, qqqwe);
            this.Camera.transform.rotation = qqqwe;
        }
    }

    class GameManager {
        constructor() {
            this.EnemyArray = [];
            GameManager.ins = this;
            EventManager.EventOn(EventState.SceneInit, this, this.Init);
        }
        static get Instance() {
            if (GameManager.ins) {
                return GameManager.ins;
            }
            else {
                return new GameManager();
            }
        }
        Init() {
            this.CreatCharacter();
            this.mainscene = AssetManager.Instance.mainscene;
            Laya.stage.addChildAt(this.mainscene, 0);
        }
        CreatCharacter() {
            this.CreatPlayer();
            this.CreatEnemy();
        }
        CreatPlayer() {
            var playermodel = GamePool.Instance.GetModel(AssetManager.Instance.Player.get(1), "");
            var horsemodel = GamePool.Instance.GetModel(AssetManager.Instance.Horse.get(1), "");
            playermodel.addChild(horsemodel);
            playermodel.transform.position = new Laya.Vector3(0, 0, 0);
            horsemodel.transform.localScale = new Laya.Vector3(1, 1, 1);
            horsemodel.transform.localPosition = new Laya.Vector3(0, 0, 0);
            PlayerControl.Instance.Init(playermodel);
            AssetManager.Instance.mainscene.addChild(playermodel);
        }
        CreatEnemy() {
        }
    }

    class LoadView {
        constructor() {
            LoadView.ins = this;
            this.Init();
        }
        static get Instance() {
            if (LoadView.ins) {
                return LoadView.ins;
            }
            else {
                return new LoadView();
            }
        }
        Init() {
            new GameManager();
            this.LoadScene();
        }
        LoadComplete() {
            console.log("加载完毕--");
            EventManager.EventTrigger(EventState.LoadComplete);
        }
        LoadScene() {
            Laya.Scene3D.load(ResourcesPath.MainScene, Laya.Handler.create(this, (scene) => {
                this.scene = scene;
                AssetManager.Instance.mainscene = this.scene;
                console.log("场景加载完毕");
                this.LoadEnemy();
            }));
        }
        LoadEnemy() {
            var path = [];
            for (let i = 0; i < ResourcesPath.Enemy.length; i++) {
                path.push(ResourcesPath.Enemy[i]);
            }
            Laya.loader.create(path, Laya.Handler.create(this, () => {
                for (let i = 0; i < ResourcesPath.Enemy.length; i++) {
                    var model = Laya.loader.getRes(ResourcesPath.Enemy[i]);
                    AssetManager.Instance.Enemy.set(i + 1, model);
                    Laya.loader.clearRes(ResourcesPath.Enemy[i]);
                }
                console.log("敌人模型资源加载完毕---");
                this.LoadPlayer();
            }));
        }
        LoadPlayer() {
            var path = [];
            for (let i = 0; i < ResourcesPath.Player.length; i++) {
                path.push(ResourcesPath.Player[i]);
            }
            Laya.loader.create(path, Laya.Handler.create(this, () => {
                for (let i = 0; i < ResourcesPath.Player.length; i++) {
                    var model = Laya.loader.getRes(ResourcesPath.Player[i]);
                    AssetManager.Instance.Player.set(i + 1, model);
                    Laya.loader.clearRes(ResourcesPath.Player[i]);
                }
                console.log("玩家模型资源加载完毕---");
                this.LoadHorse();
            }));
        }
        LoadHorse() {
            var path = [];
            for (let i = 0; i < ResourcesPath.Horse.length; i++) {
                path.push(ResourcesPath.Horse[i]);
            }
            Laya.loader.create(path, Laya.Handler.create(this, () => {
                for (let i = 0; i < ResourcesPath.Horse.length; i++) {
                    var model = Laya.loader.getRes(ResourcesPath.Horse[i]);
                    AssetManager.Instance.Horse.set(i + 1, model);
                    Laya.loader.clearRes(ResourcesPath.Horse[i]);
                }
                console.log("马模型资源加载完毕---");
                this.LoadComplete();
            }));
        }
    }

    class Main {
        constructor() {
            if (window["Laya3D"])
                Laya3D.init(GameConfig.width, GameConfig.height);
            else
                Laya.init(GameConfig.width, GameConfig.height, Laya["WebGL"]);
            Laya["Physics"] && Laya["Physics"].enable();
            Laya["DebugPanel"] && Laya["DebugPanel"].enable();
            Laya.stage.scaleMode = GameConfig.scaleMode;
            Laya.stage.screenMode = GameConfig.screenMode;
            Laya.stage.alignV = GameConfig.alignV;
            Laya.stage.alignH = GameConfig.alignH;
            Laya.URL.exportSceneToJson = GameConfig.exportSceneToJson;
            if (GameConfig.debug || Laya.Utils.getQueryString("debug") == "true")
                Laya.enableDebugPanel();
            if (GameConfig.physicsDebug && Laya["PhysicsDebugDraw"])
                Laya["PhysicsDebugDraw"].enable();
            if (GameConfig.stat)
                Laya.Stat.show();
            Laya.alertGlobalError = true;
            Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.onVersionLoaded), Laya.ResourceVersion.FILENAME_VERSION);
        }
        onVersionLoaded() {
            Laya.AtlasInfoManager.enable("fileconfig.json", Laya.Handler.create(this, this.onConfigLoaded));
        }
        onConfigLoaded() {
            new LoadView();
        }
    }
    new Main();

}());
//# sourceMappingURL=bundle.js.map
