199 lines
5.3 KiB
TypeScript
199 lines
5.3 KiB
TypeScript
import MsgAlert from "../game/msg/MsgAlert";
|
|
import AdoptPannel from "./AdoptPannel";
|
|
import Baby from "./Baby";
|
|
import BabyMgrPannel from "./BabyMgrPannel";
|
|
import CarePannel from "./CarePannel";
|
|
import DestinyPannel from "./DestinyPannel";
|
|
import NurtureHome from "./NurtureHome";
|
|
|
|
|
|
export default class BabyList {
|
|
SkillConfig = []
|
|
BabyList = []
|
|
BabyPracticeConfig: any
|
|
|
|
UpdateBabyPracticeConfig(data){
|
|
let config = JSON.parse(data.config)
|
|
this.BabyPracticeConfig = config
|
|
}
|
|
|
|
GetBabyPracticeConfig(type: number, index: number){
|
|
if(this.BabyPracticeConfig == null || this.BabyPracticeConfig.length == 0){
|
|
return null
|
|
}
|
|
let data = null
|
|
|
|
if (type == 0) {
|
|
data = this.BabyPracticeConfig["Learning"]
|
|
}
|
|
|
|
if(type == 1){
|
|
data = this.BabyPracticeConfig["Practice"]
|
|
}
|
|
|
|
if(type == 2){
|
|
data = this.BabyPracticeConfig["Enjoy"]
|
|
}
|
|
|
|
if(data == null) {
|
|
return false
|
|
}
|
|
|
|
if(index < 0 || index >= data.length) {
|
|
return false
|
|
}
|
|
|
|
return data[index]
|
|
}
|
|
|
|
UpdateBabyList(list: any){
|
|
if(list.length == 0) return
|
|
|
|
this.BabyList = []
|
|
for (let index = 0; index < list.length; index++) {
|
|
let data = list[index];
|
|
let baby = new Baby()
|
|
baby.UpdateData(data)
|
|
this.AddBaby(baby)
|
|
}
|
|
}
|
|
|
|
GetBabyByID(id):Baby {
|
|
for (let index = 0; index < this.BabyList.length; index++) {
|
|
let _baby = this.BabyList[index];
|
|
if (_baby.ID == id) {
|
|
return _baby
|
|
}
|
|
}
|
|
}
|
|
|
|
GetBattleBaby():Baby{
|
|
for (let index = 0; index < this.BabyList.length; index++) {
|
|
let baby = this.BabyList[index];
|
|
if (baby.Attr.battle == true){
|
|
return baby
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
|
|
AddBaby(baby: Baby){
|
|
for (let index = 0; index < this.BabyList.length; index++) {
|
|
let _baby = this.BabyList[index];
|
|
if (_baby.ID == baby.ID) {
|
|
return
|
|
}
|
|
}
|
|
this.BabyList.push(baby)
|
|
}
|
|
|
|
AdoptBaby(msg){
|
|
if (msg.ret == 0){
|
|
let data = JSON.parse(msg.baby)
|
|
let baby = new Baby()
|
|
baby.UpdateData(data)
|
|
this.AddBaby(baby)
|
|
MsgAlert.addMsg("恭喜, 領取寶寶成功!")
|
|
}
|
|
|
|
AdoptPannel.shared.hide()
|
|
}
|
|
|
|
BabyBattle(msg){
|
|
for (let index = 0; index < this.BabyList.length; index++) {
|
|
let baby = this.BabyList[index];
|
|
baby.Attr.battle = false
|
|
}
|
|
|
|
let data = JSON.parse(msg.baby)
|
|
let baby = this.GetBabyByID(data.id)
|
|
if (baby == null) {
|
|
baby = new Baby()
|
|
}
|
|
baby.UpdateData(data)
|
|
this.AddBaby(baby)
|
|
|
|
NurtureHome.shared.onBabyBattle(baby)
|
|
BabyMgrPannel.shared.onBabyBattle(baby)
|
|
}
|
|
|
|
BabySkillBless(data){
|
|
if (data.ret != 0) {
|
|
MsgAlert.addMsg("許願失敗,道具不足,無法許願!")
|
|
return
|
|
}
|
|
|
|
let skill = JSON.parse(data.skill)
|
|
let baby = this.GetBabyByID(data.id)
|
|
baby.Bless(skill)
|
|
DestinyPannel.shared.onBabyBless(skill)
|
|
}
|
|
|
|
BabySkillUpgrade(data){
|
|
if (data.ret != 0) {
|
|
if(data.ret == 1){
|
|
MsgAlert.addMsg("升級失敗,道具或銀幣不足,無法升級!")
|
|
}
|
|
if(data.ret == 2){
|
|
MsgAlert.addMsg("升級失敗,還沒對該技能許願,無法升級!")
|
|
}
|
|
if(data.ret == 3){
|
|
MsgAlert.addMsg("升級失敗,該技能已經達到滿級,無法升級!")
|
|
}
|
|
return
|
|
}
|
|
|
|
let skill = JSON.parse(data.skill)
|
|
let baby = this.GetBabyByID(data.id)
|
|
baby.UpgradeSkill(skill)
|
|
DestinyPannel.shared.onUpgradeSkill(skill)
|
|
}
|
|
|
|
BabySkillBattle(data){
|
|
if (data.ret != 0) {
|
|
MsgAlert.addMsg("抱歉,裝備技能失敗!")
|
|
return
|
|
}
|
|
|
|
let skill = JSON.parse(data.skill)
|
|
let baby = this.GetBabyByID(data.id)
|
|
baby.SkillBattle(skill)
|
|
DestinyPannel.shared.onSkillBattle(skill)
|
|
BabyMgrPannel.shared.onSkillBattle(skill)
|
|
}
|
|
|
|
//0 成功 1 失敗 2 疲勞已滿 3 屬性已加至最高
|
|
BabyPractice(msg){
|
|
if (msg.ret != 0) {
|
|
if(msg.ret == 1){
|
|
MsgAlert.addMsg("抱歉,培養寶寶失敗!")
|
|
}else if(msg.ret == 2){
|
|
MsgAlert.addMsg("抱歉,您的疲勞值已滿,帶寶寶去娛樂一下吧!")
|
|
}else if(msg.ret == 3){
|
|
MsgAlert.addMsg("抱歉,您當前要培養的屬性已加滿,請培養一下寶寶其它屬性吧!")
|
|
}else if(msg.ret == 4){
|
|
MsgAlert.addMsg("今日培養已達上限!")
|
|
}else{
|
|
MsgAlert.addMsg("抱歉,培養寶寶失敗!")
|
|
}
|
|
return
|
|
}
|
|
|
|
MsgAlert.addMsg("恭喜,培養寶寶成功!")
|
|
let data = JSON.parse(msg.baby)
|
|
let baby = this.GetBabyByID(data.id)
|
|
baby.UpdateData(data)
|
|
// this.AddBaby(baby)
|
|
|
|
CarePannel.shared.onBabyPractice(baby)
|
|
BabyMgrPannel.shared.resetAttrList()
|
|
}
|
|
|
|
GetBabyCount(){
|
|
return this.BabyList.length
|
|
}
|
|
|
|
SaveSkillConfig(data){
|
|
this.SkillConfig = data
|
|
}
|
|
} |