113 lines
3.1 KiB
Go
113 lines
3.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/data/xmlres"
|
|
"blazing/common/socket/errorcode"
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/pet"
|
|
"blazing/logic/service/player"
|
|
playermodel "blazing/modules/player/model"
|
|
)
|
|
|
|
func petSetExpLimit(currentPet *playermodel.PetInfo) int64 {
|
|
if currentPet == nil || currentPet.Level >= 100 {
|
|
return 0
|
|
}
|
|
|
|
simulatedPet := *currentPet
|
|
allowedExp := simulatedPet.NextLvExp - simulatedPet.Exp
|
|
if allowedExp < 0 {
|
|
allowedExp = 0
|
|
}
|
|
|
|
for simulatedPet.Level < 100 && simulatedPet.NextLvExp > 0 {
|
|
simulatedPet.Level++
|
|
simulatedPet.Update(true)
|
|
if simulatedPet.Level >= 100 {
|
|
break
|
|
}
|
|
allowedExp += simulatedPet.NextLvExp
|
|
}
|
|
|
|
return allowedExp
|
|
}
|
|
|
|
func minInt64(a, b int64) int64 {
|
|
if a < b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|
|
|
|
// PetReleaseToWarehouse 将精灵从仓库包中放生
|
|
func (h Controller) PetReleaseToWarehouse(
|
|
data *PET_ROWEI, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
_, _, inBag := player.FindPet(data.CatchTime)
|
|
_, _, inBackup := player.FindBackupPet(data.CatchTime)
|
|
freeForbidden := xmlres.PetMAP[int(data.ID)].FreeForbidden
|
|
if inBag || inBackup || freeForbidden == 1 {
|
|
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
|
}
|
|
|
|
if !player.Service.Pet.UpdateFree(data.CatchTime, 1) {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
|
|
return nil, 0
|
|
}
|
|
|
|
// PetOneCure 单体治疗
|
|
func (h Controller) PetOneCure(
|
|
data *PetOneCureInboundInfo, player *player.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) {
|
|
if player.IsArenaHealLocked() {
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
|
|
}
|
|
|
|
if slot, ok := player.FindPetBagSlot(data.CatchTime); ok {
|
|
currentPet := slot.PetInfoPtr()
|
|
if currentPet != nil {
|
|
defer currentPet.Cure()
|
|
}
|
|
}
|
|
|
|
return &pet.PetOneCureOutboundInfo{
|
|
CatchTime: data.CatchTime,
|
|
}, 0
|
|
}
|
|
|
|
// PetFirst 精灵首发
|
|
func (h Controller) PetFirst(
|
|
data *PetDefaultInboundInfo, player *player.Player) (result *pet.PetDefaultOutboundInfo, err errorcode.ErrorCode) {
|
|
if player.IsArenaSwitchLocked() {
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
|
}
|
|
|
|
result = &pet.PetDefaultOutboundInfo{}
|
|
index, _, ok := player.FindPet(data.CatchTime)
|
|
if ok && index != 0 {
|
|
player.Info.PetList[index], player.Info.PetList[0] = player.Info.PetList[0], player.Info.PetList[index]
|
|
result.IsDefault = 1
|
|
}
|
|
|
|
return result, 0
|
|
}
|
|
|
|
// SetPetExp 设置宠物经验
|
|
func (h Controller) SetPetExp(
|
|
data *PetSetExpInboundInfo,
|
|
player *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
|
slot, found := player.FindPetBagSlot(data.CatchTime)
|
|
currentPet := slot.PetInfoPtr()
|
|
if !found || currentPet == nil || currentPet.Level >= 100 {
|
|
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
|
|
allowedExp := petSetExpLimit(currentPet)
|
|
if allowedExp <= 0 {
|
|
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
|
|
player.AddPetExp(currentPet, minInt64(data.Exp, allowedExp))
|
|
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, 0
|
|
}
|