| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- //AI类型枚举
- var taskEnumType = cc.Enum({
- //游戏开始,即开场
- GameStart: -1,
- //建造房子(住宅)
- BuildAHouse: -1,
- //增加一颗果树(环境)
- IncreaseFruitTrees: -1,
- //铺设道路
- PavedRoads: -1,
- //招聘员工
- RecruitStaff: -1,
- //分享
- Share: -1
- });
- cc.Class({
- extends: cc.Component,
- properties: {
- MainCamera: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- //类型
- taskEnum: {
- default: taskEnumType.GameStart,
- type: cc.Enum(taskEnumType),
- },
- //工人管理节点
- manageWorker: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- },
- onLoad() {
- // 开启碰撞检测系统,未开启时无法检测
- // cc.director.getCollisionManager().enabled = true;
- GlobalD.ManageTask = this;
- this._uiCamera = cc.find("Canvas/UICamera");
- this.managerControl = this._uiCamera.getComponent('ManagerControl');
- //初始化人物对话
- dialogmanager.InitDialgue();
- },
- onStart() {
- // onStartTask()
- },
- /**
- * 调用任务
- */
- onStartTask(){
- //初始化任务
- switch (this.taskEnum) {
- case taskEnumType.GameStart:
- this.onInitGameStartTask();
- break;
- case taskEnumType.BuildAHouse:
- this.onInitBuildAHouse();
- break;
- case taskEnumType.IncreaseFruitTrees:
- this.onInitBuildAHouse();
- break;
- case taskEnumType.PavedRoads:
- this.onInitPavedRoads();
- break;
- case taskEnumType.RecruitStaff:
- this.onInitRecruitStaff();
- break;
- case taskEnumType.Share:
- this.onInitShare();
- break;
- // default:
- // break;
- }
- },
- InitTask(BFirstLoadGame) {
- // return;
- // todo 新手教学 初始化
-
- if (0 === BFirstLoadGame) {
- console.log("***首次初始化任务", BFirstLoadGame);
- //首次初始化
- task.taskOnLoad();
- //创建员工
- // this.manageWorker.getComponent('ManageWorker').onRecruit();
- // this.manageWorker.getComponent('ManageWorker').onRecruit();
- this.onStartTask();
- } else {
- console.log("***初始化任务", BFirstLoadGame);
- // this.onStartTask();
- // console.log('task.TaskIconCountClick =====',task.TaskIconCountClick);
- task._init();
- task.addSeneceTaskIcon(() => {
- task.taskOnLoadno();
- //直接吊起记录的任务
- task.taskCallBack();
- });
- }
- },
- onInitGameStartTask() {
- //初始化的时候设置一个值
- task.TaskIconCountClick = -1;
- task._setTaskCount(0);
- setTimeout(() => {
- task.taskCallBack();
- }, 500);
- },
- //移动到工人位置
- onMoveCamera() {
- if (this.MainCamera == null) return;
- // let targetWorldPos = this.target.parent.convertToWorldSpaceAR(this.target.getPosition());
- // let moveToSpacePos = this.node.parent.convertToNodeSpaceAR(targetWorldPos);
- // cc.log('Node移动的位置:', moveToSpacePos);
- // 创建一个移动动作
- var action = cc.moveTo(0.5, cc.v2(0, 0));
- // 执行动作
- this.MainCamera.runAction(
- cc.sequence(
- cc.callFunc(this._startUpdateMap.bind(this)),
- action,
- cc.callFunc(this._endUpdateMap.bind(this))
- ));
- },
- onInitBuildAHouse() {
- task._setTaskCount(3);
- task.addSeneceTaskIcon();
- },
- //移动到游客在农田购买的位置
- onMovePayFarmland() {
- if (this.MainCamera == null) return;
- // 创建一个移动动作
- var action = cc.moveTo(0.5, cc.v2(0, -100));
- // 执行动作
- this.MainCamera.runAction(
- cc.sequence(
- cc.callFunc(this._startUpdateMap.bind(this)),
- action,
- cc.callFunc(this._endUpdateMap.bind(this))
- ));
- },
- //初始化铺路
- onInitPavedRoads() {
- task._setTaskIconCountClick(10);
- task.addSeneceTaskIcon();
- task.taskCallBack();
- },
- //初始化招聘员工
- onInitRecruitStaff() {
- task._setTaskIconCountClick(1);
- task.addSeneceTaskIcon();
- },
- //初始化游戏分享
- onInitShare() {
- task._setTaskIconCountClick(12);
- task.addSeneceTaskIcon();
- },
- /**
- * 初始相机到对应的tiled 位置
- * @method onMoveToTiledTile
- * @param {int} x
- * @param {int} y
- */
- onMoveToTiledTile(x, y) {
- if (this.MainCamera == null) return;
- let endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(x, y));
- // 创建一个移动动作
- var action = cc.moveTo(0.5, endPos);
- // 执行动作
- this.MainCamera.runAction(
- cc.sequence(
- cc.callFunc(this._startUpdateMap.bind(this)),
- action,
- cc.callFunc(this._endUpdateMap.bind(this))
- ));
- },
- _startUpdateMap() {
- this.updateCallback = function () {
- //更新地图边界外的物体
- this.managerControl._deteItem();
- }
- this.schedule(this.updateCallback, 0.3);
- },
- _endUpdateMap() {
- this.unschedule(this.updateCallback);
- //更新地图边界外的物体
- this.managerControl._deteItem();
- },
- });
|