feat(pet): 重构宠物属性计算与技能学习逻辑,优化代码结构
This commit is contained in:
@@ -84,8 +84,6 @@ func GenPetInfo(id int, dv, natureId, abilityTypeEnum, shinyid, level int) *PetI
|
||||
CatchTime: uint32(time.Now().Unix()),
|
||||
Level: uint32(level)} //等级
|
||||
|
||||
naxml := xmlres.NatureRootMap[int(p.Nature)]
|
||||
petxml := xmlres.PetMAP[int(id)]
|
||||
if shinyid != -1 {
|
||||
p.Shiny = uint32(shinyid)
|
||||
} else {
|
||||
@@ -127,89 +125,20 @@ func GenPetInfo(id int, dv, natureId, abilityTypeEnum, shinyid, level int) *PetI
|
||||
}
|
||||
|
||||
}
|
||||
tttt := make([]uint32, 0)
|
||||
for _, v := range petxml.LearnableMoves.Moves {
|
||||
if p.Level >= uint32(v.LearningLv) {
|
||||
tttt = append(tttt, uint32(v.ID))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
tttt = LastFourElements(tttt) //获取最后四个技能,如果不足,那就取全部技能
|
||||
tttt := LastFourElements(p.GetLevelRangeCanLearningSkills(0, p.Level)) //获取最后四个技能,如果不足,那就取全部技能
|
||||
for i := 0; i < len(tttt); i++ {
|
||||
p.SkillList[i].ID = tttt[i]
|
||||
p.SkillList[i].PP = uint32(xmlres.SkillMap[int(tttt[i])].MaxPP)
|
||||
|
||||
}
|
||||
p.SkillListLen = uint32(len(tttt))
|
||||
// 计算各项属性
|
||||
hp := p.CalculatePetHPPanelSize(
|
||||
uint32(petxml.HP),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvHp,
|
||||
)
|
||||
// * battle_lv: atk(0), def(1), sp_atk(2), sp_def(3), spd(4), accuracy(5)
|
||||
p.Prop[0] = p.CalculatePetPanelSize(
|
||||
uint32(petxml.Atk),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvAttack,
|
||||
naxml.AttackCorrect,
|
||||
)
|
||||
|
||||
p.Prop[1] = p.CalculatePetPanelSize(
|
||||
uint32(petxml.Def),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvDefence,
|
||||
naxml.DefenseCorrect,
|
||||
)
|
||||
|
||||
p.Prop[2] = p.CalculatePetPanelSize(
|
||||
uint32(petxml.SpAtk),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvSpecialAttack,
|
||||
naxml.SaCorrect,
|
||||
)
|
||||
|
||||
p.Prop[3] = p.CalculatePetPanelSize(
|
||||
uint32(petxml.SpDef),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvSpecialDefense,
|
||||
naxml.SdCorrect,
|
||||
)
|
||||
|
||||
p.Prop[4] = p.CalculatePetPanelSize(
|
||||
uint32(petxml.Spd),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvSpeed,
|
||||
naxml.SpeedCorrect,
|
||||
)
|
||||
|
||||
// 设置计算结果
|
||||
p.MaxHp = hp
|
||||
p.Hp = hp
|
||||
p.CalculatePetPane()
|
||||
p.Hp = p.MaxHp
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// 计算HP面板值(无性格修正)
|
||||
func (c *PetInfo) CalculatePetHPPanelSize(base, dv, level, ev uint32) uint32 {
|
||||
|
||||
return uint32((float64(base)*2+float64(ev)/4.0+float64(dv))*(float64(level)/100.0) + float64(level) + 10)
|
||||
}
|
||||
|
||||
// 计算其他属性面板值(带性格修正)
|
||||
func (c *PetInfo) CalculatePetPanelSize(base, dv, level, ev uint32, natureCorrect float64) uint32 {
|
||||
|
||||
base1 := float64((float64(base)*2+float64(ev)/4.0+float64(dv))*(float64(level)/100.0) + 5)
|
||||
return uint32(float64(base1) * natureCorrect)
|
||||
}
|
||||
|
||||
// PetInfo 精灵信息结构(合并后的优化版本)
|
||||
type PetInfo struct {
|
||||
|
||||
|
||||
86
modules/blazing/model/petinfo.go
Normal file
86
modules/blazing/model/petinfo.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package model
|
||||
|
||||
import "blazing/common/data/xmlres"
|
||||
|
||||
// 实现获取等级范围内可学习的技能
|
||||
func (p *PetInfo) GetLevelRangeCanLearningSkills(from, to uint32) []uint32 {
|
||||
|
||||
var skills []uint32
|
||||
|
||||
for _, skillIDs := range xmlres.PetMAP[int(p.ID)].LearnableMoves.Moves {
|
||||
|
||||
if skillIDs.LearningLv >= from && skillIDs.LearningLv <= to {
|
||||
skills = append(skills, skillIDs.ID)
|
||||
}
|
||||
}
|
||||
return skills
|
||||
}
|
||||
|
||||
// 计算HP面板值(无性格修正)
|
||||
func (c *PetInfo) calculatePetHPPanelSize(base, dv, level, ev uint32) uint32 {
|
||||
|
||||
return uint32((float64(base)*2+float64(ev)/4.0+float64(dv))*(float64(level)/100.0) + float64(level) + 10)
|
||||
}
|
||||
|
||||
// 计算其他属性面板值(带性格修正)
|
||||
func (c *PetInfo) calculatePetPanelSize(base, dv, level, ev uint32, natureCorrect float64) uint32 {
|
||||
|
||||
base1 := float64((float64(base)*2+float64(ev)/4.0+float64(dv))*(float64(level)/100.0) + 5)
|
||||
return uint32(float64(base1) * natureCorrect)
|
||||
}
|
||||
|
||||
// 计算生成面板
|
||||
func (p *PetInfo) CalculatePetPane() {
|
||||
naxml := xmlres.NatureRootMap[int(p.Nature)]
|
||||
petxml := xmlres.PetMAP[int(p.ID)]
|
||||
// 计算各项属性
|
||||
hp := p.calculatePetHPPanelSize(
|
||||
uint32(petxml.HP),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvHp,
|
||||
)
|
||||
// * battle_lv: atk(0), def(1), sp_atk(2), sp_def(3), spd(4), accuracy(5)
|
||||
p.Prop[0] = p.calculatePetPanelSize(
|
||||
uint32(petxml.Atk),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvAttack,
|
||||
naxml.AttackCorrect,
|
||||
)
|
||||
|
||||
p.Prop[1] = p.calculatePetPanelSize(
|
||||
uint32(petxml.Def),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvDefence,
|
||||
naxml.DefenseCorrect,
|
||||
)
|
||||
|
||||
p.Prop[2] = p.calculatePetPanelSize(
|
||||
uint32(petxml.SpAtk),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvSpecialAttack,
|
||||
naxml.SaCorrect,
|
||||
)
|
||||
|
||||
p.Prop[3] = p.calculatePetPanelSize(
|
||||
uint32(petxml.SpDef),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvSpecialDefense,
|
||||
naxml.SdCorrect,
|
||||
)
|
||||
|
||||
p.Prop[4] = p.calculatePetPanelSize(
|
||||
uint32(petxml.Spd),
|
||||
p.Dv,
|
||||
p.Level,
|
||||
p.EvSpeed,
|
||||
naxml.SpeedCorrect,
|
||||
)
|
||||
|
||||
// 设置计算结果
|
||||
p.MaxHp = hp
|
||||
}
|
||||
Reference in New Issue
Block a user