|
|
@@ -1,5 +1,6 @@
|
|
|
import { PLAYERPROP } from "../../data/GameDefinition";
|
|
|
import GameController from "../../GameController";
|
|
|
+import MainUI from "../main/MainUI";
|
|
|
|
|
|
/**
|
|
|
* 获取粮草界面逻辑
|
|
|
@@ -11,28 +12,41 @@ export default class GetLiangCaoModel {
|
|
|
* - 跨天重置
|
|
|
*/
|
|
|
rest_vedio_times: 0,
|
|
|
- /** 可以获得的粮草数量 */
|
|
|
- food_count: 4999,
|
|
|
}
|
|
|
+ /** 可以获得的粮草数量 */
|
|
|
+ public static food_count: number = 0
|
|
|
/** 今日最多可看视频次数
|
|
|
* - 走配置,需要配置
|
|
|
*/
|
|
|
- public static max_vedio_times: number = 40;
|
|
|
+ public static max_vedio_times: number = 0;
|
|
|
/** 保存数据 */
|
|
|
public static saveData() {
|
|
|
let temp_str_model_data = JSON.stringify(this.model_data);
|
|
|
- GameController.gameData.updatePropNoCheck(PLAYERPROP.GET_FOOD_DATA, temp_str_model_data);// 任务条数据
|
|
|
+ GameController.gameData.updatePropNoCheck(PLAYERPROP.GET_FOOD_DATA, temp_str_model_data);
|
|
|
}
|
|
|
/** 重置数据 */
|
|
|
public static resetData() {
|
|
|
this.model_data.rest_vedio_times = this.max_vedio_times;
|
|
|
this.saveData();
|
|
|
}
|
|
|
+ /** 初始化数据 */
|
|
|
+ public static initData() {
|
|
|
+ if (!this.max_vedio_times) this.max_vedio_times = GameController.gameData.serverConfig_data.videofoodtime || 0;
|
|
|
+
|
|
|
+ let list_data = GameController.gameData.player.getProp(PLAYERPROP.GET_FOOD_DATA);
|
|
|
+ if (list_data) {
|
|
|
+ let temp_str_list_data = JSON.parse(list_data)
|
|
|
+ if (temp_str_list_data) this.model_data = temp_str_list_data;
|
|
|
+ } else {
|
|
|
+ // 没有数据
|
|
|
+ this.resetData();
|
|
|
+ }
|
|
|
+ }
|
|
|
/** 更新可以获得的粮草数量
|
|
|
* 每关刷新
|
|
|
*/
|
|
|
public static updateFoodCount(mission_id) {
|
|
|
- this.model_data.food_count = GameController.gameData.getMissionByID(mission_id).videofood;
|
|
|
+ this.food_count = GameController.gameData.getMissionByID(mission_id).videofood;
|
|
|
}
|
|
|
/** 预计可训练次数
|
|
|
* - 实时计算得到
|
|
|
@@ -42,7 +56,7 @@ export default class GetLiangCaoModel {
|
|
|
public static canExpUpTimes(): number {
|
|
|
let can_expUp_times = 0;
|
|
|
|
|
|
- let cur_food = this.model_data.food_count;
|
|
|
+ let cur_food = this.food_count;
|
|
|
let consume_food = GameController.gameData.player.getProp(PLAYERPROP.FOODCONSUME);
|
|
|
can_expUp_times = Math.floor(cur_food / consume_food);
|
|
|
return can_expUp_times;
|
|
|
@@ -65,4 +79,38 @@ export default class GetLiangCaoModel {
|
|
|
need_after_time = Math.ceil(need_food / food_recover);
|
|
|
return need_after_time;
|
|
|
}
|
|
|
+ /** 看视频领取粮草的逻辑 */
|
|
|
+ public static receiveTVFood() {
|
|
|
+ if (this.model_data.rest_vedio_times <= 0) {
|
|
|
+ GameController.uiM.showToast('剩余次数不足');
|
|
|
+ } else {
|
|
|
+ this.model_data.rest_vedio_times--;
|
|
|
+ this.saveData();
|
|
|
+ GameController.gameData.player.setProp(PLAYERPROP.FOOD, this.food_count, true);
|
|
|
+ this.flyRedBagToMain();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /** 主界面组件,动画用 */
|
|
|
+ private static comp_main: MainUI = null!;
|
|
|
+ /** 飞粮草效果 */
|
|
|
+ private static flyRedBagToMain() {
|
|
|
+ if (!this.comp_main) this.comp_main = GameController.uiM.getUI(MainUI);
|
|
|
+ let start_world_pos = this.comp_main.btn_3.node.parent.convertToWorldSpaceAR(this.comp_main.btn_3.node.getPosition());
|
|
|
+ start_world_pos.y += this.comp_main.btn_3.node.height;
|
|
|
+ let start_node_pos = this.comp_main.node.convertToNodeSpaceAR(start_world_pos);
|
|
|
+
|
|
|
+ let end_world_pos = this.comp_main.node_lc.node.parent.convertToWorldSpaceAR(this.comp_main.node_lc.node.getPosition());
|
|
|
+ let end_node_pos = this.comp_main.node.convertToNodeSpaceAR(end_world_pos);
|
|
|
+ let fly_data = {
|
|
|
+ node_p: this.comp_main.node,
|
|
|
+ item_count: 10,
|
|
|
+ item_scale: [1, 2],
|
|
|
+ item_sf: this.comp_main.node_lc.spriteFrame,
|
|
|
+ start_pos: start_node_pos,
|
|
|
+ end_pos: end_node_pos,
|
|
|
+ complete_call: null,
|
|
|
+ }
|
|
|
+ // 发起飞item事件
|
|
|
+ this.comp_main.node.emit('ui-fly-node', fly_data);
|
|
|
+ }
|
|
|
}
|