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.
213 lines
6.8 KiB
213 lines
6.8 KiB
import User from "../../FrameWork/User/User";
|
|
import Common5 from "../../Platform/th/Common5";
|
|
import TaskManager, { MainTaskIdEnum } from "../JuQingChat/TaskManager";
|
|
|
|
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
|
|
}
|
|
|
|
public static randomNeedShowMounting2(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)
|
|
}
|
|
|
|
let mainTaskInfo:any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.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()
|
|
if(leftMounting.length <= 0){
|
|
topArr = this.randomNeedShowMounting2("高",2)
|
|
midArr = this.randomNeedShowMounting("中",3)
|
|
bottomArr = this.randomNeedShowMounting("低",3)
|
|
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 getKanTanMineralsConfig(){
|
|
//随机得到产出的矿石id
|
|
let mineralsIdArr = null
|
|
let mineralsRateArr = null
|
|
|
|
mineralsIdArr = this.curMountingConfig.getMineralsIdArr
|
|
|
|
mineralsRateArr = this.curMountingConfig.getMineralsRateArr
|
|
let randomIndex = Math.floor(Math.random()*100)
|
|
let sum = 0
|
|
let selectId = 0
|
|
|
|
for(var i=0;i<mineralsRateArr.length;i++){
|
|
sum += mineralsRateArr[i]
|
|
if(randomIndex < sum){
|
|
selectId = mineralsIdArr[i]
|
|
break
|
|
}
|
|
}
|
|
|
|
//获取矿石的配置
|
|
let mainTaskInfo:any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.Id
|
|
if(mainId == MainTaskIdEnum.MainTask_535 && Common5.kaiKuangVDIndex>=1){
|
|
Common5.kaiKuangVDIndex = 0
|
|
return null
|
|
}
|
|
|
|
let allMineralsConfig = this.getAllMineralsConfig()
|
|
for(var i=0;i<allMineralsConfig.length;i++){
|
|
if(selectId == allMineralsConfig[i].id){
|
|
|
|
console.log(allMineralsConfig[i], '1111111111111')
|
|
|
|
return allMineralsConfig[i]
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
|
|
|
|
|
|
|
|
public static clearAllRecord(){
|
|
User.setCurDayMountingArr([])
|
|
}
|
|
} |