觉醒时刻
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.
 
 
 
juexingshike/assets/Scripts/Manager/KaiKuangDataManage.ts

210 lines
7.8 KiB

import User from "../../FrameWork/User/User";
import Common5 from "../../Platform/th/Common5";
import TaskManager from "../JuQingChat/TaskManager";
import BagManager from "./BagManager";
const { ccclass, property } = cc._decorator;
@ccclass
export default class KaiKuangDataManage {
public static curMountingConfig = null
public static setCurMountingConfig(config) {
this.curMountingConfig = config
}
public static getCurMountingConfig() {
return this.curMountingConfig
}
public static curMountingPrice = null
public static setCurMountingPrice(price) {
this.curMountingPrice = price
}
public static getCurMountingPrice() {
return this.curMountingPrice
}
//所有山峰配置
public static getAllMountingConfig() {
return Common5.AllMountingConfig
}
//根据价格类型获取山峰
public static getMountingConfigByType(typeStr) {
let allMountingConfig = this.getAllMountingConfig()
let tempArr = []
for (var i = 0; i < allMountingConfig.length; i++) {
if (typeStr == allMountingConfig[i].priceType) {
tempArr.push(allMountingConfig[i])
}
}
return tempArr
}
//根据id获取山峰
public static getMountingConfigById(id) {
let allMountingConfig = this.getAllMountingConfig()
for (var i = 0; i < allMountingConfig.length; i++) {
if (id == allMountingConfig[i].id) {
return allMountingConfig[i]
}
}
}
//随机出需要显示的山峰(类型,数量)
public static randomNeedShowMounting(typeStr, count) {
let topMountingArr = this.getMountingConfigByType(typeStr)
let tempIndexArr = this.getNumberFromArray(0, topMountingArr.length, count)
let tempArr = []
for (var i = 0; i < tempIndexArr.length; i++) {
tempArr.push(topMountingArr[tempIndexArr[i]].id)
}
return tempArr
}
//从min到max中随机取出n个值
public static getNumberFromArray(min, max, count) {
//原数组
var arr = [];
for (var i = min; i < max; i++) {
arr.push(i)
}
//输出数组
let temp = []
let length = arr.length
while (count > 0) {
var index = Math.floor(Math.random() * length)
temp.push(arr[index])
arr.splice(index, 1)
length--
count--
}
// console.log("temp==",temp)
return temp
}
//获取显示山峰
public static getShowMounting() {
let topArr = []
let midArr = []
let bottomArr = []
let leftMounting = User.getCurDayMountingArr()
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
let mainId = mainTaskInfo.Id
let configData = TaskManager.getTaskConfigById(mainId)
if (leftMounting.length <= 0) {
topArr = this.randomNeedShowMounting("高", 2)
midArr = this.randomNeedShowMounting("中", 3)
bottomArr = this.randomNeedShowMounting("低", 3)
let KuangShanID = configData.KuangShanID
if ((KuangShanID || KuangShanID == 0)) {
let CurTaskKaiKuangID = User.getCurTaskKaiKuangID()
if ((CurTaskKaiKuangID[0] || CurTaskKaiKuangID[0] == 0) && CurTaskKaiKuangID[1] < configData.KuangShanNum) {
let arr
if (this.getMountingConfigById(KuangShanID).priceType == "高") {
arr = topArr
} else if (this.getMountingConfigById(KuangShanID).priceType == "中") {
arr = midArr
} else if (this.getMountingConfigById(KuangShanID).priceType == "低") {
arr = bottomArr
}
if (arr.indexOf(KuangShanID) == -1) {
arr[Common5.getRandomNum(0, 2)] = KuangShanID
}
}
}
for (var i = 0; i < topArr.length; i++) {
this.saveDataToStorage(topArr[i], false)
}
for (var i = 0; i < midArr.length; i++) {
this.saveDataToStorage(midArr[i], false)
}
for (var i = 0; i < bottomArr.length; i++) {
this.saveDataToStorage(bottomArr[i], false)
}
console.log("内存中没有剩余山峰")
}
return leftMounting
}
//保存至内存
public static saveDataToStorage(id, isFinish) {
let mountingArr = User.getCurDayMountingArr()
let arr = { id: id, isFinish: isFinish }
for (var i = 0; i < mountingArr.length; i++) {
if (mountingArr[i].id == id) {
mountingArr[i] = arr
return
}
}
mountingArr.push(arr)
User.setCurDayMountingArr(mountingArr)
}
//获取分类后的山峰信息
public static getMountingInfo() {
let leftMounting = this.getShowMounting()
let topArr = []
let midArr = []
let bottomArr = []
for (var i = 0; i < leftMounting.length; i++) {
let mountingConfig = KaiKuangDataManage.getMountingConfigById(leftMounting[i].id)
if (mountingConfig.priceType == "高") {
topArr.push({ id: leftMounting[i].id, isFinish: leftMounting[i].isFinish })
} else if (mountingConfig.priceType == "中") {
midArr.push({ id: leftMounting[i].id, isFinish: leftMounting[i].isFinish })
} else if (mountingConfig.priceType == "低") {
bottomArr.push({ id: leftMounting[i].id, isFinish: leftMounting[i].isFinish })
}
}
return { "高": topArr, "中": midArr, "低": bottomArr }
}
//所有矿石配置
public static getAllMineralsConfig() {
return Common5.AllMineralsConfig
}
//所有矿石配置
public static getMineralsConfigById(id) {
let allMineralsConfig = this.getAllMineralsConfig()
for (var i = 0; i < allMineralsConfig.length; i++) {
if (id == allMineralsConfig[i].id) {
return allMineralsConfig[i]
}
}
}
//随机得到勘探出的矿石
public static getKanTanMineralsNum() {
//随机得到产出的矿石id
let mineralsNumArr = null
let mineralsRateArr = null
// if(Common5.GMDATA_KS){
// mineralsNum = this.curMountingConfig.GMgetMineralsIdArr
// mineralsRateArr = this.curMountingConfig.GMgetMineralsRateArr
// }else{
// if(Common5.kuangshanChange.countNum>0){
// Common5.kuangshanChange.countNum--
// mineralsNum = this.curMountingConfig.QQgetMineralsIdArr
// mineralsRateArr = this.curMountingConfig.QQgetMineralsIdArr
// }else{
mineralsNumArr = this.curMountingConfig.getMineralsNum
mineralsRateArr = this.curMountingConfig.getMineralsRateArr
// }
// }
let randomIndex = Math.floor(Math.random() * 100)
let sum = 0
let selectIdNum = 0
for (var i = 0; i < mineralsRateArr.length; i++) {
sum += mineralsRateArr[i]
if (randomIndex < sum) {
selectIdNum = mineralsNumArr[i]
break
}
}
// //获取矿石的配置
// let allMineralsConfig = this.getAllMineralsConfig()
// for(var i=0;i<allMineralsConfig.length;i++){
// if(selectId == allMineralsConfig[i].id){
// return allMineralsConfig[i]
// }
// }
console.log('随机得到勘探出的矿石==', mineralsNumArr, mineralsRateArr, selectIdNum)
return selectIdNum
}
public static clearAllRecord() {
User.setCurDayMountingArr([])
}
}