| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- var reGameStates = require('GameStates');
- import gameToast from "../Network/gameToast";
- // const { values } = require('../Network/runtime');
- cc.Class({
- extends: cc.Component,
- properties: {
- seedType: {
- default: reGameStates.SeedType.Normal,
- type: cc.Enum(reGameStates.SeedType),
- },
- seedName: {
- default: ''
- },
- _EndPosition: {
- default: new cc.Vec2(),
- serializable: false,
- visible: false,
- },
- labelTip: {
- default: null,
- type: cc.Label,
- },
- labelTipString: {
- default: '移动可拆除对应建筑',
- },
- //记录节点
- targetBuildingsInfo: { default: null, visible: false },
- //移除的提示预制
- removeTipPrefab: { default: null, type: cc.Prefab },
- //记录要删除的节点
- selectedTarget: { default: [], type: cc.Node, visible: false },
- //记录选中的index
- selectedTargetIndex: { default: [], type: cc.Integer, visible: false },
- isMoveState: { default: true, visible: false },
- MoveStartNode: cc.Node,
- MoveEndNode: cc.Node,
- //content_seed 传递过来
- goodsSeedInfo: {
- default: null,
- tooltip: '设定一个背包种子信息',
- },
- //content_seed 设置
- seedSprite: {
- default: null,
- type: cc.Sprite,
- tooltip: "当前生出工具的提示"
- },
- fruitSpriteFrame: {
- default: null,
- type: cc.SpriteFrame,
- tooltip: "成熟的图片展示"
- },
- upTarget: {
- default: null,
- type: cc.Node,
- tooltip: "把当前操作的ui按钮传进来"
- },
- mallType: {
- default: 0,
- tooltip: "类型,默认0是种子"
- }
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start() {
- let self = this;
- GlobalD.game._ManageUIScript.onBottomMenuView(false);
- //初始化时候设置一下位置
- let startTiledPos = GlobalD.TiledMap._tilePosFromLocation(self.node.getPosition());
- let startEndPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(startTiledPos);
- self.node.setPosition(startEndPos);
- self._EndPosition = startTiledPos;
- if(0 === self.mallType){
- let startIndex = GlobalD.TiledMap.getIndex(startTiledPos);
- let _targetBuildingsInfo = GlobalD.game.onGetBuildingsTiledMapUnitFromIndex(startIndex);
- if (_targetBuildingsInfo) {
- self.labelTip.string = '播种到' + _targetBuildingsInfo.buildInfo.id + "号" + _targetBuildingsInfo.buildInfo.buildingName + '上';
- self.targetBuildingsInfo = _targetBuildingsInfo;
- }
- else {
- self.labelTip.string = "请移动到农田上!";
- self.targetBuildingsInfo = null;
- }
- }else{
- let startIndex = GlobalD.TiledMap.getIndex(startTiledPos);
- let _targetBuildingsInfo = GlobalD.game.onGetBuildingsTiledMapUnitFromIndex(startIndex);
- if (_targetBuildingsInfo) {
- self.labelTip.string = "养殖在" + _targetBuildingsInfo.buildInfo.buildingName + '上';
- self.targetBuildingsInfo = _targetBuildingsInfo;
- }
- else {
- self.labelTip.string = "请移动到对应的养殖场上!";
- self.targetBuildingsInfo = null;
- }
- }
-
- self.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
- // cc.log( "isUICameraMove:", GlobalD.GameControl.isUICameraMove);
- GlobalD.GameControl._isBuildingMove = true;
- GlobalD.GameControl.isUICameraMove = false;
- var delta = event.touch.getDelta();
- self._touchPosition.x += delta.x / GlobalD.game.MainCamera.zoomRatio;
- self._touchPosition.y += delta.y / GlobalD.game.MainCamera.zoomRatio;
- let tiledPos = GlobalD.TiledMap._tilePosFromLocation(self._touchPosition);
- // //不相等的时候才绘制
- if (tiledPos.sub(self._EndPosition).mag() != 0) {
- self._EndPosition = tiledPos;
- self._SelectHighwayTiled(tiledPos);
- }
- }, self.node);
- self.node.on(cc.Node.EventType.TOUCH_START, function (event) {
- // console.log("self.TOUCH_START:", GlobalD.GameControl.isUICameraMove);
- self.isMoving = true;
- self._touchPosition = self.node.getPosition();
- GlobalD.GameControl._isBuildingMove = false;
- GlobalD.GameControl.isUICameraMove = false;
- }, self.node);
- self.node.on(cc.Node.EventType.TOUCH_END, function (event) {
- // console.log("self._EndPosition:", self._EndPosition);
- //起始触摸位置
- GlobalD.GameControl._isBuildingMove = false;
- GlobalD.GameControl.isUICameraMove = false;
- let buildIndex = GlobalD.TiledMap.getIndex(self._EndPosition);
- let _targetBuildingsInfo = GlobalD.game.onGetBuildingsTiledMapUnitFromIndex(buildIndex);
- if (_targetBuildingsInfo) {
- if(0 === self.mallType){
- if (_targetBuildingsInfo.buildInfo.buildType == reGameStates.BuildType.HolyFarmland) {
- self.labelTip.string = '播种到' + _targetBuildingsInfo.buildInfo.id + "号" + _targetBuildingsInfo.buildInfo.buildingName + '上';
- self.targetBuildingsInfo = _targetBuildingsInfo;
- } else {
- self.labelTip.string = '请移动到农田上!';
- self.targetBuildingsInfo = null;
- }
- }else{
- if (_targetBuildingsInfo.buildInfo.buildType == reGameStates.BuildType.HolyAnimal) {
- self.labelTip.string = "养殖在" + _targetBuildingsInfo.buildInfo.buildingName + '上';
- self.targetBuildingsInfo = _targetBuildingsInfo;
- } else {
- self.labelTip.string = '请移动到对应的养殖场上!';
- self.targetBuildingsInfo = null;
- }
- }
-
- }
- else {
- self.labelTip.string = self.labelTipString;
- self.targetBuildingsInfo = null;
- }
- }, self.node);
- self.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
- //起始触摸位置
- GlobalD.GameControl._isBuildingMove = false;
- GlobalD.GameControl.isUICameraMove = false;
- // console.log("self.TOUCH_CANCEL:");
- }, self.node);
- },
- onCancleSelf() {
- //只要是编辑状态下。设为true
- GlobalD.GameControl._isBuildingCanEdit = false;
- GlobalD.game._ManageUIScript.onBottomMenuView(true);
- this.node.destroy();
- },
- /**
- *
- * 处理播种逻辑,记录数据库
- * @returns
- */
- onSowOnTheGround() {
- //调用土地相关
- if (!this.targetBuildingsInfo) return;
- // 种植土地的信息
- let _leaselandInfoScript = null;
- if (0 === this.mallType) {
- // 种植土地的信息
- _leaselandInfoScript = this.targetBuildingsInfo.getComponent("LeaseFarmlandInfo");
- } else {
- //养殖场的信息
- _leaselandInfoScript = this.targetBuildingsInfo.getComponent("LeaseAnimalInfo");
- }
- // console.log("_leaselandInfoScript:",_leaselandInfoScript);
- if(!_leaselandInfoScript){
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "种子(幼苗)类型不对!", 2);
- return;
- }
- let leaseLandInfo = _leaselandInfoScript.leaseLandInfo;
- if (leaseLandInfo == null) {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), 0 === this.mallType ? "请先租赁土地!" : "请先租赁养殖场", 2);
- //隐藏种子和显示UI
- this.node.active = false;
- GlobalD.game._ManageUIScript.onBottomMenuView(true);
- return;
- }
- let data = { landId: leaseLandInfo.configLandId, seedId: this.goodsSeedInfo.id, amount: 1 };
- GlobalD.GameData.onPlant(data, (value) => {
- //面板种子消耗减少1
- if (0 === value.code) {
- console.log('种子减少的类型名字', this.seedName);
- console.log(value);
- var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView").getComponent("BuildingView");
- BuildingView.onUpdateList();
- //把种子的信息存储到当前的土地 plantInfo 上;
- _leaselandInfoScript.setLeaseLandInfo(value.data, true);
- //刷新当前灾难ui
- GlobalD.game._ManageUIScript.onShowDisater();
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "已成功种植!", 1);
- } else if (706 === value.code) {
- //土地到期,没有更新刷新的处理刷新
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
- //重置锁定状态显示
- _leaselandInfoScript.onLockLand();
- } else {
- //土地已经种植了
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
- }
- });
- //隐藏种子和显示UI
- this.node.active = false;
- GlobalD.game._ManageUIScript.onBottomMenuView(true);
- },
- _SelectHighwayTiled(tiledPos) {
- let endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(tiledPos);
- this.node.setPosition(endPos);
- }
- });
|