咸鱼的反击
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
xianyudefanji/assets/Scripts/Manager/ZaoCanManager.ts

330 lines
12 KiB

// Learn TypeScript:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
import { ryw_Event } from "../../FrameWork/Event/EventEnum"
import EventMgr from "../../FrameWork/Event/EventMgr"
import User from "../../FrameWork/User/User"
import Common5 from "../../Platform/th/Common5"
import BagManager from "./BagManager"
import JieDaoManager from "./JieDaoManager"
// let zaocanConfig = [
// { id: 0, zaocan: ['馒头', '肉包', '烧卖', '红薯'], needLevel: [1, 5, 10, 20], initPrice: 100, jiacheng: [1, 2, 3, 4] },
// { id: 0, zaocan: ['馒头', '肉包', '烧卖', '红薯'], needLevel: [1, 5, 10, 20], initPrice: 100, jiacheng: [1, 2, 3, 4] },
// { id: 1, zaocan: ['鸡蛋', '茶叶蛋', '玉米', '西兰花'], needLevel: [1, 5, 10, 20], initPrice: 100, jiacheng: [1, 2, 3, 4] },
// { id: 2, zaocan: ['饺子', '韭菜盒子', '鸡蛋饼', '牛排'], needLevel: [1, 5, 10, 20], initPrice: 100, jiacheng: [1, 2, 3, 4] },
// { id: 3, zaocan: ['油条', '麻球', '油饼', '鸡腿'], needLevel: [1, 5, 10, 20], initPrice: 100, jiacheng: [1, 2, 3, 4] },
// { id: 4, zaocan: ['豆浆', '小米粥', '燕麦', '咖啡机'], needLevel: [1, 5, 10, 20], initPrice: 100, jiacheng: [1, 2, 3, 4] },
// ]
let zaocanConfig = [
{ id: 0, type: 0, zaocan: '馒头', needLevel: 1, jiacheng: 1 },
{ id: 1, type: 1, zaocan: '鸡蛋', needLevel: 1, jiacheng: 1 },
{ id: 3, type: 2, zaocan: '煎鸡蛋', needLevel: 1, jiacheng: 1 },
{ id: 3, type: 3, zaocan: '油条', needLevel: 1, jiacheng: 1 },
{ id: 4, type: 4, zaocan: '豆浆', needLevel: 1, jiacheng: 1 },
{ id: 5, type: 0, zaocan: '肉包', needLevel: 230, jiacheng: 0.1 },
{ id: 6, type: 1, zaocan: '茶叶蛋', needLevel: 250, jiacheng: 0.15 },
{ id: 7, type: 2, zaocan: '韭菜盒子', needLevel: 280, jiacheng: 0.2 },
{ id: 8, type: 3, zaocan: '麻球', needLevel: 300, jiacheng: 0.3 },
{ id: 9, type: 4, zaocan: '小米粥', needLevel: 330, jiacheng: 0.5 },
{ id: 10, type: 0, zaocan: '烧卖', needLevel: 350, jiacheng: 0.7 },
{ id: 11, type: 1, zaocan: '玉米', needLevel: 380, jiacheng: 1 },
{ id: 12, type: 2, zaocan: '葱油饼', needLevel: 400, jiacheng: 1.5 },
{ id: 13, type: 3, zaocan: '油饼', needLevel: 430, jiacheng: 2 },
{ id: 14, type: 4, zaocan: '燕麦粥', needLevel: 450, jiacheng: 3 },
{ id: 15, type: 0, zaocan: '红薯', needLevel: 500, jiacheng: 4 },
{ id: 16, type: 1, zaocan: '西兰花', needLevel: 650, jiacheng: 5 },
{ id: 17, type: 2, zaocan: '牛排', needLevel: 800, jiacheng: 6 },
{ id: 18, type: 3, zaocan: '鸡腿', needLevel: 900, jiacheng: 7 },
{ id: 19, type: 4, zaocan: '咖啡', needLevel: 1000, jiacheng: 10 },
]
let levelUpUnLockTanWei = [
{ level: 0, unlock: '油条' },
{ level: 50, unlock: '鸡蛋' },
{ level: 100, unlock: '饺子' },
{ level: 150, unlock: '豆浆' },
{ level: 200, unlock: '馒头' },
]
//食谱
export default class ZaoCanManager {
public static initManager() {
let array = User.getzaoCanArray()
if (array.length == 0) {
//插入数据
let tempArray = []
for (let i = 0; i < zaocanConfig.length; i++) {
let obj = { id: 0, isLock: true }
obj.id = zaocanConfig[i].id
obj.isLock = true
//最开始0-4的五个默认早餐默认已解锁
if (obj.id <= 4) {
obj.isLock = false
}
tempArray[tempArray.length] = obj
}
User.setzaoCanArray(tempArray)
} else {
}
}
public static getManagerConfigDate() {
return zaocanConfig
}
/**
* 剔除初始的5个早餐
* @returns
*/
public static getManagerConfigDateHaveJiaCheng() {
let configs = []
for (let i = 5; i < zaocanConfig.length; i++) {
configs.push(Common5.deepClone(zaocanConfig[i]))
}
return configs
}
/**
* 获取所有已解锁的早餐加成 剔除初始的5个早餐
*/
public static getAllZaoCanJiaCheng() {
let jiacheng = 0
let getzaoCanArray = User.getzaoCanArray()
for (let i = 5; i < getzaoCanArray.length; i++) {
let obj = getzaoCanArray[i];
if (!obj.isLock) {
//已解锁
jiacheng += zaocanConfig[i].jiacheng
}
}
// 没有加成就是1倍加成
if (jiacheng == 0) {
jiacheng = 1
}
return jiacheng + 1
}
/**
* 根据id获取解锁状态,0是未解锁,1是待解锁,2是已解锁
*/
public static getIsLockById(id) {
let lockType = 0
let level = User.getMyLevel()
let getzaoCanArray = User.getzaoCanArray()
for (let i = 0; i < getzaoCanArray.length; i++) {
let obj = getzaoCanArray[i];
if (obj.id == id && !obj.isLock) {
lockType = 2
break
} else if (obj.id == id && obj.isLock) {
if (level >= zaocanConfig[i].needLevel) {
lockType = 1
} else {
lockType = 0
}
break
}
}
return lockType
}
public static getIsHaveUnLock() {
let isHave = false
let getzaoCanArray = User.getzaoCanArray()
for (let i = 5; i < getzaoCanArray.length; i++) {
if (this.getIsLockById(i) == 1) {
isHave = true
break
}
}
return isHave
}
/**
* 解锁
*/
public static setUnLock(id) {
let lockType = this.getIsLockById(id)
//是不是等待解锁的状态
if (lockType == 1) {
let getzaoCanArray = User.getzaoCanArray()
for (let i = 0; i < getzaoCanArray.length; i++) {
let obj = getzaoCanArray[i];
if (id == obj.id) {
obj.isLock = false
break
}
}
User.setzaoCanArray(getzaoCanArray)
}
}
public static getDanJia() {
let level = User.getMyLevel()
let price = Math.ceil(200 * Math.pow(1.02, level - 1))
let jiedaoJiacheng = JieDaoManager.getJieDaoBeiShu()
return Math.ceil(price * jiedaoJiacheng)
// return price
}
public static getLastDanJia() {
let level = User.getMyLevel() - 1
let price = Math.ceil(35 * Math.pow(1.025, level - 1))
// let jiedaoJiacheng = JieDaoManager.getJieDaoBeiShu()
// return Math.ceil(level * jiedaoJiacheng)
return price
}
public static getCurNameByType(type) {
let name
let getzaoCanArray = User.getzaoCanArray()
for (let i = 0; i < getzaoCanArray.length; i++) {
let obj = getzaoCanArray[i];
if (zaocanConfig[i].type == type && !obj.isLock) {
name = zaocanConfig[i].zaocan
}
}
return name
}
public static getEffectUrlByType(type) {
let name
let getzaoCanArray = User.getzaoCanArray()
let effectUrls = ['sound/蒸笼/放饺子', 'sound/煮锅/煮东西', 'sound/煎锅/煎东西', 'sound/油锅/油炸', 'sound/豆浆桶/豆浆桶抛物线']
for (let i = 0; i < getzaoCanArray.length; i++) {
if (zaocanConfig[i].type == type) {
name = effectUrls[i]
break
}
}
return name
}
public static getUnlockTanWei() {
let level = User.getMyLevel()
let unlocks = []
for (let i = 0; i < levelUpUnLockTanWei.length; i++) {
if (level >= levelUpUnLockTanWei[i].level) {
unlocks.push(levelUpUnLockTanWei[i].unlock)
}
}
return unlocks
}
// public static getCurPriceById(id) {
// let config = zaocanConfig[id]
// let level = User.getMyLevel()
// let price = config.initPrice + level
// return price
// }
// public static getNextPriceById(id) {
// let config = zaocanConfig[id]
// let level = User.getMyLevel() + 1
// let price = config.initPrice + level
// return price
// }
// public static isCanLevelUpById(id) {
// let config = zaocanConfig[id]
// let level = User.getMyLevel() + 1
// let isCan = false
// for (let i = 0; i < config.needLevel.length; i++) {
// let _needLevel = config.needLevel[i];
// if (level == _needLevel) {
// isCan = true
// }
// }
// return isCan
// }
// /**
// * 获取所有已解锁的早餐加成
// */
// public static getAllZaoCanJiaCheng() {
// let jiacheng = 0
// let level = User.getMyLevel()
// for (let i = 0; i < zaocanConfig.length; i++) {
// let _needLevel = zaocanConfig[i].needLevel
// for (let j = 0; j < _needLevel.length; j++) {
// if (level >= _needLevel[j]) {
// jiacheng += zaocanConfig[i].jiacheng[j]
// }
// }
// }
// // 没有加成就是1倍加成
// if (jiacheng == 0) {
// jiacheng = 1
// }
// return jiacheng
// }
// /**
// * 获取所有需要解锁的早餐,初始的早餐不计入
// */
// public static getAllZaoCan() {
// let all = []
// for (let i = 0; i < zaocanConfig.length; i++) {
// let _zaocan = zaocanConfig[i].zaocan
// // 初始的早餐不计入
// for (let j = 1; j < _zaocan.length; j++) {
// all.push({ name: zaocanConfig[i].zaocan[j], addPercent: zaocanConfig[i].jiacheng[j] })
// }
// }
// return all
// }
// /**
// * 获取早餐是否解锁
// */
// public static isUnLockByName(name) {
// let level = User.getMyLevel()
// let lockState = false
// for (let i = 0; i < zaocanConfig.length; i++) {
// let _zaocan = zaocanConfig[i].zaocan
// let _needLevel = zaocanConfig[i].needLevel
// for (let j = 0; j < _zaocan.length; j++) {
// //是当前早餐并且等级已经到了自动解锁
// if (name == _zaocan[j] && level >= _needLevel[j]) {
// lockState = true
// break
// }
// }
// }
// return lockState
// }
// /**
// * 获取早餐解锁等级要求
// */
// public static getZaoCanNeedLevelByName(name) {
// let needLevel = 0
// for (let i = 0; i < zaocanConfig.length; i++) {
// let _zaocan = zaocanConfig[i].zaocan
// let _needLevel = zaocanConfig[i].needLevel
// for (let j = 0; j < _zaocan.length; j++) {
// //是当前早餐
// if (name == _zaocan[j]) {
// needLevel = _needLevel[j]
// break
// }
// }
// }
// return needLevel
// }
}