refactor: 优化代码结构和逻辑
This commit is contained in:
@@ -18,34 +18,34 @@ func (h Controller) PetELV(data *C2S_PET_EVOLVTION, c *player.Player) (result *f
|
||||
return nil, errorcode.ErrorCodes.Err10401
|
||||
}
|
||||
|
||||
flag := xmlres.PetMAP[int(currentPet.ID)].EvolvFlag
|
||||
|
||||
if flag == 0 {
|
||||
petCfg, ok := xmlres.PetMAP[int(currentPet.ID)]
|
||||
if !ok || petCfg.EvolvFlag == 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotEvolveReady
|
||||
}
|
||||
if xmlres.PetMAP[int(currentPet.ID)].EvolvingLv > int(currentPet.Level) {
|
||||
if petCfg.EvolvingLv > int(currentPet.Level) {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotEvolveReady
|
||||
}
|
||||
evinfo := xmlres.EVOLVMAP[flag].Branches[data.Index-1]
|
||||
|
||||
if c.Service.Item.CheakItem(uint32(evinfo.EvolvItem)) < int64(evinfo.EvolvItemCount) {
|
||||
evolveCfg, ok := xmlres.EVOLVMAP[petCfg.EvolvFlag]
|
||||
if !ok || data.Index == 0 || int(data.Index) > len(evolveCfg.Branches) {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotEvolveReady
|
||||
}
|
||||
|
||||
branch := evolveCfg.Branches[data.Index-1]
|
||||
if branch.EvolvItem != 0 && c.Service.Item.CheakItem(uint32(branch.EvolvItem)) < int64(branch.EvolvItemCount) {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItemsMulti
|
||||
}
|
||||
if evinfo.EvolvItem != 0 {
|
||||
c.Service.Item.UPDATE(uint32(evinfo.EvolvItem), -evinfo.EvolvItemCount)
|
||||
if branch.EvolvItem != 0 {
|
||||
c.Service.Item.UPDATE(uint32(branch.EvolvItem), -branch.EvolvItemCount)
|
||||
}
|
||||
|
||||
currentPet.ID = uint32(xmlres.EVOLVMAP[flag].Branches[data.Index-1].MonTo)
|
||||
currentPet.ID = uint32(branch.MonTo)
|
||||
currentPet.Update(true)
|
||||
currentPet.CalculatePetPane(100)
|
||||
|
||||
currentPet.Update(true)
|
||||
updateOutbound := &info.PetUpdateOutboundInfo{}
|
||||
|
||||
var petUpdateInfo info.UpdatePropInfo
|
||||
|
||||
copier.Copy(&petUpdateInfo, currentPet)
|
||||
|
||||
updateOutbound.Data = append(updateOutbound.Data, petUpdateInfo)
|
||||
c.SendPackCmd(2508, updateOutbound) //准备包由各自发,因为协议不一样
|
||||
return nil, -1
|
||||
|
||||
Reference in New Issue
Block a user