Commit 22c0a3ab authored by haiyoucuv's avatar haiyoucuv

初始化土地信息,更新土地信息

parent 0bb2e710
This diff is collapsed.
{
"success": true,
"code": "1111",
"data": {}
}
\ No newline at end of file
{
"success": true,
"data": {
"index": 2,
"plant": true,
"level": 1,
"plantType": "CASHEWNUT",
"waterTime": "",
"waterRestCount": 0
}
}
{
"success": true,
"data": {
"index": 2,
"plant": true,
"level": 1,
"plantType": "CASHEWNUT",
"waterTime": "",
"waterRestCount": 0
}
}
...@@ -10,27 +10,30 @@ ...@@ -10,27 +10,30 @@
"plants": [ "plants": [
{ {
"index": 1, "index": 1,
"plant": false, "plant": true,
"level": "", "level": 3,
"plantType": "", "plantType": "PEANUT",
"waterTime": "", "waterTime": 1591790173326,
"waterRestCount": "" "totalTime": 30000000,
"waterRestCount": 0
}, },
{ {
"index": 2, "index": 2,
"plant": true, "plant": true,
"level": 1, "level": 1,
"plantType": "CASHEWNUT", "plantType": "CASHEWNUT",
"waterTime": "", "waterTime": 0,
"totalTime": 3000,
"waterRestCount": 0 "waterRestCount": 0
}, },
{ {
"index": 3, "index": 3,
"plant": false, "plant": true,
"level": "", "level": 1,
"plantType": "", "plantType": "PECAN",
"waterTime": "", "waterTime": 2,
"waterRestCount": "" "totalTime": 3000,
"waterRestCount": 0
}, },
{ {
"index": 4, "index": 4,
...@@ -38,6 +41,7 @@ ...@@ -38,6 +41,7 @@
"level": "", "level": "",
"plantType": "", "plantType": "",
"waterTime": "", "waterTime": "",
"totalTime": "",
"waterRestCount": "" "waterRestCount": ""
} }
] ]
......
{
"success": true,
"code": "1111",
"data": "1.哈哈哈哈哈\n2.哈哈哈哈哈\n3.哈哈哈哈哈\n4.哈哈哈哈哈\n5.哈哈哈哈哈\n6.哈哈哈哈哈\n7.哈哈哈哈哈\n8.哈哈哈哈哈\n9.哈哈哈哈哈\n10.哈哈哈哈哈\n11.哈哈哈哈哈\n12.哈哈哈哈哈\n13.哈哈哈哈哈\n14.哈哈哈哈哈\n15.哈哈哈哈哈\n16.哈哈哈哈哈\n17.哈哈哈哈哈\n18.哈哈哈哈哈\n19.哈哈哈哈哈\n20.哈哈哈哈哈\n21.哈哈哈哈哈\n"
}
...@@ -2,6 +2,7 @@ import { showToast, wait, clearWait } from "../module/ctrls"; ...@@ -2,6 +2,7 @@ import { showToast, wait, clearWait } from "../module/ctrls";
export const activityId = 111; export const activityId = 111;
export const sellerId = 742982950;
//接口枚举,包括需要调用淘宝的api,用是否含有兑吧区分,或者单独区分 //接口枚举,包括需要调用淘宝的api,用是否含有兑吧区分,或者单独区分
export enum TbNetName { export enum TbNetName {
......
...@@ -7,7 +7,7 @@ import { PLANT_STATE, PLANT_TYPE, s_PlantData } from "../../const/staticData"; ...@@ -7,7 +7,7 @@ import { PLANT_STATE, PLANT_TYPE, s_PlantData } from "../../const/staticData";
import { Tool } from "../../Tools"; import { Tool } from "../../Tools";
import { layers } from "../../../module/views/layers"; import { layers } from "../../../module/views/layers";
import { G_wareHouseEffect } from "../UI/UILayer"; import { G_wareHouseEffect } from "../UI/UILayer";
import { getTbData, TbNetName } from "../../TaoBaoNet"; import { activityId, getTbData, sendTbNet, TbNetName } from "../../TaoBaoNet";
/** /**
...@@ -38,31 +38,11 @@ export default class GameLayer extends Container { ...@@ -38,31 +38,11 @@ export default class GameLayer extends Container {
this.initLand(); this.initLand();
const gameInfo = getTbData(TbNetName.gameInfo).data;
// 种植列表 // 种植列表
this.plantList = this.addChild(new PlantList()); this.plantList = this.addChild(new PlantList());
const initData = [ const gameInfo = getTbData(TbNetName.gameInfo).data;
{ this.initPlant(gameInfo.plants);
type: PLANT_TYPE.PISTACHIONUT,
state: PLANT_STATE.STATE1,
},
{
type: PLANT_TYPE.NONE,
state: 0,
},
{
type: PLANT_TYPE.MELON,
state: PLANT_STATE.STATE2,
},
{
type: PLANT_TYPE.PEANUT,
state: PLANT_STATE.STATE3,
},
];
this.initPlant(initData);
} }
/** /**
...@@ -71,7 +51,7 @@ export default class GameLayer extends Container { ...@@ -71,7 +51,7 @@ export default class GameLayer extends Container {
* @param {PLANT_TYPE} type 植物类型 * @param {PLANT_TYPE} type 植物类型
*/ */
public addPlant(landId: number, type: PLANT_TYPE) { public addPlant(landId: number, type: PLANT_TYPE) {
this.landList[landId - 1].addPlant(type); /// TODO 看后端从几号开始 this.landList[landId].addPlant(type); /// TODO 看后端从几号开始
} }
/** /**
...@@ -79,8 +59,26 @@ export default class GameLayer extends Container { ...@@ -79,8 +59,26 @@ export default class GameLayer extends Container {
* @param {number} landId * @param {number} landId
* @param {PLANT_STATE} state * @param {PLANT_STATE} state
*/ */
public updatePlant(landId: number, state: PLANT_STATE) { public upPlant(landId: number, state: PLANT_STATE) {
this.landList[landId - 1].updatePlant(state); this.landList[landId].upPlant(state);
}
/**
* 更新植物信息
* @param {number} landId
* @param {PLANT_STATE} state
*/
public updatePlant(landId: number) {
sendTbNet(TbNetName.gameInfo, {
activityId: activityId
}, (success, res) => {
for (let i = 0; i < res.data.plants.length; i++) {
if (res.data.plants[i].index == landId) {
this.landList[landId].updatePlant(res.data.plants[i]);
break;
}
}
});
} }
/** /**
...@@ -88,7 +86,7 @@ export default class GameLayer extends Container { ...@@ -88,7 +86,7 @@ export default class GameLayer extends Container {
* @param {number} landId * @param {number} landId
*/ */
public clearPlant(landId: number) { public clearPlant(landId: number) {
this.landList[landId - 1].clearPlant(); this.landList[landId].clearPlant();
} }
/** /**
...@@ -96,15 +94,22 @@ export default class GameLayer extends Container { ...@@ -96,15 +94,22 @@ export default class GameLayer extends Container {
* @param initData * @param initData
*/ */
public initPlant(initData) { public initPlant(initData) {
this.landList.forEach((land: Land, index: number) => { initData.forEach((data) => {
land.initPlant(initData[index].type, initData[index].state); if (!data.plant) return;
this.landList[data.index].initPlant({
type: data.plantType,
state: data.level,
time: data.waterTime,
totalTime: data.totalTime,
waterRestCount: data.waterRestCount
});
}); });
} }
public getEffect(type: PLANT_TYPE, id: number) { public getEffect(type: PLANT_TYPE, id: number) {
let getEffect = this.addChild(Tool.getSprite(`种植框_${s_PlantData[type].name}.png`)); let getEffect = this.addChild(Tool.getSprite(`种植框_${s_PlantData[type].name}.png`));
getEffect.mouseEnable = false; getEffect.mouseEnable = false;
getEffect.position.set(this.landList[id - 1].x + 185, this.landList[id - 1].y + 55); getEffect.position.set(this.landList[id].x + 185, this.landList[id].y + 55);
let _x = 375 - getEffect.width / 2; let _x = 375 - getEffect.width / 2;
let _y = layers.stageHeight - layers.stageOffsetY - 205; let _y = layers.stageHeight - layers.stageOffsetY - 205;
let __y = getEffect.y; let __y = getEffect.y;
...@@ -146,7 +151,8 @@ export default class GameLayer extends Container { ...@@ -146,7 +151,8 @@ export default class GameLayer extends Container {
let newLand = this.addChild(new Land()); let newLand = this.addChild(new Land());
newLand.position.set(v[0], v[1]); newLand.position.set(v[0], v[1]);
newLand.id = index + 1; /// TODO 看后端从几号开始 newLand.id = index + 1; /// TODO 看后端从几号开始
this.landList.push(newLand); this.landList[index + 1] = newLand;
// this.landList.push(newLand);
}); });
} }
} }
...@@ -2,6 +2,8 @@ import Container = FYGE.Container; ...@@ -2,6 +2,8 @@ import Container = FYGE.Container;
import Sprite = FYGE.Sprite; import Sprite = FYGE.Sprite;
import DisplayObject = FYGE.DisplayObject; import DisplayObject = FYGE.DisplayObject;
import MouseEvent = FYGE.MouseEvent; import MouseEvent = FYGE.MouseEvent;
import Event = FYGE.Event;
import MovieClip = FYGE.MovieClip;
import { RES } from "../../../module/RES"; import { RES } from "../../../module/RES";
import GameLayer from "./GameLayer"; import GameLayer from "./GameLayer";
import OptionPool from "../../const/OptionPool"; import OptionPool from "../../const/OptionPool";
...@@ -10,8 +12,6 @@ import { OPTION_TYPE, PLANT_STATE, PLANT_TYPE } from "../../const/staticData"; ...@@ -10,8 +12,6 @@ import { OPTION_TYPE, PLANT_STATE, PLANT_TYPE } from "../../const/staticData";
import Plant from "./Plant"; import Plant from "./Plant";
import ProgressBar from "./ProgressBar"; import ProgressBar from "./ProgressBar";
import { Tool } from "../../Tools"; import { Tool } from "../../Tools";
import Event = FYGE.Event;
import MovieClip = FYGE.MovieClip;
export enum LAND_STATE { export enum LAND_STATE {
DEFAULT = 'default', DEFAULT = 'default',
...@@ -39,6 +39,8 @@ export class Land extends Container { ...@@ -39,6 +39,8 @@ export class Land extends Container {
private option: OptionEffect = null; // 当前显示的 OptionEffect private option: OptionEffect = null; // 当前显示的 OptionEffect
private waterRestCount: number;
// id // id
private _id: number; private _id: number;
public set id(id: number) { public set id(id: number) {
...@@ -104,8 +106,8 @@ export class Land extends Container { ...@@ -104,8 +106,8 @@ export class Land extends Container {
* 升级植物 * 升级植物
* @param {PLANT_STATE} state * @param {PLANT_STATE} state
*/ */
public updatePlant(state: PLANT_STATE) { public upPlant(state: PLANT_STATE) {
this.plant.updatePlant(state); this.plant.upPlant(state);
this.progressBar.setData({ this.progressBar.setData({
type: this.plant.type, type: this.plant.type,
timestamp: Date.now(), timestamp: Date.now(),
...@@ -114,23 +116,61 @@ export class Land extends Container { ...@@ -114,23 +116,61 @@ export class Land extends Container {
this.progressBar.show(); this.progressBar.show();
} }
/**
* 更新土地信息
* @param data
*/
public updatePlant(data) {
console.log(data);
this.plant.updatePlant(data);
this.waterRestCount = +data.waterRestCount;
// 收获和浇水?
if (this.waterRestCount <= 0 && data.waterTime <= 0) {
this.addOption(this.plant.state == PLANT_STATE.STATE3
? OPTION_TYPE.GET
: OPTION_TYPE.WATER
);
return;
}
this.progressBar.setData({
type: data.plantType,
timestamp: +data.waterTime,
fullTime: +data.totalTime,
});
}
/** /**
* 初始化一个植物,比如刚进游戏当时候 * 初始化一个植物,比如刚进游戏当时候
* @param {PLANT_TYPE} type
* @param {PLANT_STATE} state
*/ */
public initPlant(type: PLANT_TYPE, state: PLANT_STATE) { public initPlant(data) {
if (type === PLANT_TYPE.NONE) { if (data.type === PLANT_TYPE.NONE) {
return; return;
} }
this.plant.initPlant(type, state); this.plant.initPlant(data.type, data.state);
this.changeState(LAND_STATE.PLANT); this.changeState(LAND_STATE.PLANT);
this.waterRestCount = +data.waterRestCount;
// 收获和浇水?
if (this.waterRestCount <= 0 && data.time <= 0) {
this.addOption(this.plant.state == PLANT_STATE.STATE3
? OPTION_TYPE.GET
: OPTION_TYPE.WATER
);
return;
}
this.progressBar.setData({ this.progressBar.setData({
type: type, type: data.type,
timestamp: Date.now(), timestamp: +data.time,
fullTime: 3, fullTime: +data.totalTime,
}); });
this.progressBar.show(); this.progressBar.show();
} }
/** /**
...@@ -182,7 +222,7 @@ export class Land extends Container { ...@@ -182,7 +222,7 @@ export class Land extends Container {
mv.addEventListener(Event.END_FRAME, () => { mv.addEventListener(Event.END_FRAME, () => {
mv.stop(); mv.stop();
this.removeChild(mv); this.removeChild(mv);
this.updatePlant(this.plant.state + 1); this.upPlant(this.plant.state + 1);
}); });
mv.gotoAndPlay(0, true); mv.gotoAndPlay(0, true);
}); });
...@@ -256,7 +296,7 @@ export class Land extends Container { ...@@ -256,7 +296,7 @@ export class Land extends Container {
private endTime() { private endTime() {
console.log(this.id, '倒计时结束'); console.log(this.id, '倒计时结束');
this.addOption(Math.random() > 0.5 ? OPTION_TYPE.WATER : OPTION_TYPE.GET); GameLayer.ins.updatePlant(this.id);
} }
/** /**
......
...@@ -120,7 +120,7 @@ export default class Plant extends Container { ...@@ -120,7 +120,7 @@ export default class Plant extends Container {
* 更新一下植物(升级) * 更新一下植物(升级)
* @param {PLANT_STATE} state * @param {PLANT_STATE} state
*/ */
public updatePlant(state: PLANT_STATE) { public upPlant(state: PLANT_STATE) {
const type = this.type; const type = this.type;
if (state < PLANT_STATE.STATE1 || state > PLANT_STATE.STATE3) { if (state < PLANT_STATE.STATE1 || state > PLANT_STATE.STATE3) {
...@@ -152,6 +152,18 @@ export default class Plant extends Container { ...@@ -152,6 +152,18 @@ export default class Plant extends Container {
}); });
} }
/**
* 更新植物信息
* @param data
*/
public updatePlant(data) {
if (this.type != data.plantType) {
this.initPlant(data.plantType, +data.level);
} else if (this.state != +data.level) {
this.upPlant(data.level);
}
}
/** /**
* 收获植物,清除植物 * 收获植物,清除植物
*/ */
......
...@@ -62,10 +62,14 @@ export default class ProgressBar extends Container { ...@@ -62,10 +62,14 @@ export default class ProgressBar extends Container {
this.visible = false; this.visible = false;
return; return;
} }
if(data.timestamp <= 0){
this.dispatchEvent('endTime');
return;
}
this.nameLabel.text = s_PlantData[data.type].name; this.nameLabel.text = s_PlantData[data.type].name;
this.nameLabel.position.set(80 + (56 - this.nameLabel.textWidth) / 2, 139); this.nameLabel.position.set(80 + (56 - this.nameLabel.textWidth) / 2, 139);
this.fullTime = data.fullTime; this.fullTime = data.fullTime / 1000;
this.cutTime = (data.timestamp - Date.now()) / 1000 + 3; this.cutTime = (data.timestamp - Date.now()) / 1000 + 3;
if (this.cutTime <= 3) { if (this.cutTime <= 3) {
......
import { Scene } from "../../module/views/Scene"; import { Scene } from "../../module/views/Scene";
import { Tool } from "../Tools"; import { Tool } from "../Tools";
import { activityId, sendTbNet, setTbData, TbNetName } from "../TaoBaoNet"; import { activityId, sellerId, sendTbNet, setTbData, TbNetName } from "../TaoBaoNet";
import { getAdjustTopHeight } from "../const/myLab"; import { getAdjustTopHeight } from "../const/myLab";
import SceneCtrl from "../../module/ctrls/sceneCtrl"; import SceneCtrl from "../../module/ctrls/sceneCtrl";
import { GameScene } from "./GameScene"; import { GameScene } from "./GameScene";
...@@ -15,7 +15,6 @@ import Ease = FYGE.Ease; ...@@ -15,7 +15,6 @@ import Ease = FYGE.Ease;
import Graphics = FYGE.Graphics; import Graphics = FYGE.Graphics;
import TextField = FYGE.TextField; import TextField = FYGE.TextField;
import { checkShopFavoredStatus, getAuthUserInfo } from "../utils"; import { checkShopFavoredStatus, getAuthUserInfo } from "../utils";
import { ancestorWhere } from "tslint";
export class LoadingScene extends Scene { export class LoadingScene extends Scene {
...@@ -47,7 +46,7 @@ export class LoadingScene extends Scene { ...@@ -47,7 +46,7 @@ export class LoadingScene extends Scene {
}); });
// 是否关注店铺 // 是否关注店铺
await checkShopFavoredStatus(111).then(async (isFollow) => { await checkShopFavoredStatus(sellerId).then(async (isFollow) => {
console.log('isFollow', isFollow); console.log('isFollow', isFollow);
setTbData(TbNetName.isFollow, { setTbData(TbNetName.isFollow, {
data: isFollow data: isFollow
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment