import SKDataUtil from "../gear/SKDataUtil"; import Baby from "./Baby"; export default class BabyMgr { BabyList: Baby[] = [] ToJson(): string { let list = [] for (let index = 0; index < this.BabyList.length; index++) { let baby = this.BabyList[index]; list.push(baby.GetObject()) } if (list.length == 0) { return "[]" } return SKDataUtil.toJson(list, "[]") } GetBattleBaby(): Baby { for (let index = 0; index < this.BabyList.length; index++) { let baby = this.BabyList[index] if(baby != null && baby.Attr.battle == true){ return baby } } return null } GetBabyByID(id: number) { for (let index = 0; index < this.BabyList.length; index++) { let baby = this.BabyList[index]; if (baby.ID == id) { return baby } } return null } GetBabySkill(id: number, skillId: number):any{ let baby = this.GetBabyByID(id) if(baby == null) { return null } return baby.GetSkillByID(skillId) } setDB(data: string) { let result = SKDataUtil.jsonBy(data) if (result == null || result.length == 0) { return } this.BabyList = [] for (let index = 0; index < result.length; index++) { let babyData = result[index]; let baby = new Baby() baby.UpdateData(babyData) this.BabyList.push(baby) } } //养育 AdoptBaby(sex: number) { if (this.BabyList.length >= 3) { //todo max baby number return null } let baby = new Baby() baby.ID = this.BabyList.length baby.Attr.sex = sex baby.Attr.foodFull = 1000 this.BabyList.push(baby) return baby } //出战 SetBattle(id: number) { let battleBaby = this.GetBabyByID(id) if (battleBaby != null) { for (let index = 0; index < this.BabyList.length; index++) { let baby = this.BabyList[index]; if (baby.ID != id) { baby.Attr.battle = false } else { baby.Attr.battle = true } } } return battleBaby } //许愿 Bless(id: number): any { let baby = this.GetBabyByID(id) if (baby != null) { return baby.Bless() } return null } //升级 Upgrade(babyId: number, skillId: number): number { let baby = this.GetBabyByID(babyId) if (baby != null) { return baby.Upgrade(skillId) } return 1 } //技能出战 SkillBattle(babyId: number, skillId: number): any { let baby = this.GetBabyByID(babyId) if (baby != null) { return baby.SkillBattle(skillId) } return null } //培养 Practice(babyId: number, type: number, index: number): number { let baby = this.GetBabyByID(babyId) if (baby != null) { return baby.Practice(type, index) } return 1 } //吃糖果 EatCandy(babyId: number): number { let baby = this.GetBabyByID(babyId) if (baby != null) { return baby.EatCandy() ? 0 : 3 } return 1 } //江湖宝典 ReadingBook(babyId: number): number { let baby = this.GetBabyByID(babyId) if (baby != null) { return baby.ReadingBook() ? 0 : 3 } return 1 } }