389 lines
11 KiB
Go

package model
import (
"rocommon/util"
"roserver/baseserver/model"
"roserver/serverproto"
)
func (this *Role) PetEquipLevelUp(petEquipId uint32) {
if this.rolePet != nil {
ret := this.rolePet.PetEquipLevelUp(petEquipId)
ackMsg := &serverproto.SCPetEquipLevelUpAck{
Error: int32(ret),
}
this.ReplayGate(ackMsg, true)
}
}
func (this *Role) PetEquipUp(petId uint32, slotIndexList []*serverproto.KeyValueType) {
if this.rolePet != nil {
ret := this.rolePet.PetEquipUp(petId, slotIndexList)
ackMsg := &serverproto.SCPetEquipUPAck{
Error: int32(ret),
PetId: petId,
SlotList: slotIndexList,
}
this.ReplayGate(ackMsg, true)
}
}
func (this *Role) PetEquipDown(petId uint32, slotIndex int32) {
if this.rolePet != nil {
ret := this.rolePet.PetEquipDown(petId, slotIndex)
ackMsg := &serverproto.SCPetEquipDownAck{
Error: int32(ret),
PetId: petId,
SlotIndex: slotIndex,
}
this.ReplayGate(ackMsg, true)
}
}
const PetEquipSlotNum = 6 //印记格子最大数量
func (this *RolePet) GetPetEquip(petEquipId uint32) *serverproto.PetEquipData {
petEquipData, ok := this.petEquipList[petEquipId]
if ok {
return petEquipData
}
return nil
}
func (this *RolePet) petEquipChangeNtf(changeData []*serverproto.PetEquipData, ignore bool) {
ntfMsg := &serverproto.SCPetEquipDataNtf{
PetEquipList: changeData,
Ignore: ignore,
}
this.role.ReplayGate(ntfMsg, true)
}
//印记是否已经装备到宠物
func (this *RolePet) isEquipUp(petEquipId uint32) bool {
petEquipData := this.GetPetEquip(petEquipId)
if petEquipData == nil {
return false
}
return petEquipData.EquipPetId > 0
}
func (this *RolePet) AddPetEquip(petCfgEquipId, petEquipLevel int32, bNotify bool) *serverproto.PetEquipData {
_, ok := model.ConvertPetEquip[petCfgEquipId]
if !ok {
util.ErrorF("uid=%v AddPetEquip equip data not find!!!", this.role.GetUUid(), petCfgEquipId)
return nil
}
//id复用之前添加宠物字段
this.maxPetId++
petEquip := &serverproto.PetEquipData{
Id: uint32(this.maxPetId),
EquipCfgId: petCfgEquipId,
Level: petEquipLevel, //默认一级
}
this.petEquipList[petEquip.Id] = petEquip
this.dbChangePetEquipList.Add(petEquip.Id)
this.SetDirty(true)
util.InfoF("uid=%v AddPetEquip petEquipCfgId=%v id=%v", this.role.GetUUid(), petCfgEquipId, this.maxPetId)
if bNotify {
this.petEquipChangeNtf([]*serverproto.PetEquipData{petEquip}, false)
}
return petEquip
}
func (this *RolePet) AddPetEquipList(petCfgEquipId, count int32, petEquipLevel int32, ignore bool) {
var ntfDataList []*serverproto.PetEquipData
for idx := 0; idx < int(count); idx++ {
petEquipData := this.AddPetEquip(petCfgEquipId, petEquipLevel, false)
if petEquipData != nil {
ntfDataList = append(ntfDataList, petEquipData)
}
}
if len(ntfDataList) > 0 {
this.petEquipChangeNtf(ntfDataList, ignore)
}
}
func (this *RolePet) AddPetEquipByMapList(addList map[int32]int32, bNotify bool) {
var ntfDataList []*serverproto.PetEquipData
for key, val := range addList {
for idx := 0; idx < int(val); idx++ {
petEquipData := this.AddPetEquip(key, 1, false)
if petEquipData != nil {
ntfDataList = append(ntfDataList, petEquipData)
}
}
}
if len(ntfDataList) > 0 && bNotify {
this.petEquipChangeNtf(ntfDataList, false)
}
}
func (this *RolePet) PetEquipLevelUp(petEquipId uint32) serverproto.ErrorCode {
petEquipData := this.GetPetEquip(petEquipId)
if petEquipData == nil {
return serverproto.ErrorCode_ERROR_PET_EQUIP_NOT_EXIST
}
cfgData, ok := model.ConvertPetEquip[petEquipData.EquipCfgId]
if !ok {
util.ErrorF("uid=%v EquipLevelUp equip data not find!!!", this.role.GetUUid(), petEquipId)
return serverproto.ErrorCode_ERROR_PET_EQUIP_NOT_EXIST
}
if petEquipData.Level >= cfgData.MaxLevel {
//进阶处理
//advance
if cfgData.AdvanceTargetEquip <= 0 {
return serverproto.ErrorCode_ERROR_PET_EQUIP_MAX_LEVEL
}
if !this.role.GetRoleBag().CanDelItemList(cfgData.AdvanceCost) {
return serverproto.ErrorCode_ERROR_PET_ADVANCE_COST
}
this.role.GetRoleBag().DelItemList(cfgData.AdvanceCost, AddItemST{AddFrom: AddFrom_PetEquip})
petEquipData.Level = 1
petEquipData.EquipCfgId = cfgData.AdvanceTargetEquip
util.InfoF("uid=%v PetEquipLevelUp id=%v oldcfgId=%v newcfgId=%v", petEquipData.Id,
cfgData.CfgId, cfgData.AdvanceTargetEquip)
TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Battle_Quality_cnt, 1)
} else {
//levelup
levelUpCfgData, ok := cfgData.LevelUpList[petEquipData.Level]
if !ok {
util.ErrorF("uid=%v EquipLevelUp equip data not find!!!", this.role.GetUUid(), petEquipId)
return serverproto.ErrorCode_ERROR_PET_EQUIP_NOT_EXIST
}
if !this.role.GetRoleBag().CanDelItemList(levelUpCfgData.CostList) {
return serverproto.ErrorCode_ERROR_PET_EQUIPLEVELUP_COST
}
this.role.GetRoleBag().DelItemList(levelUpCfgData.CostList, AddItemST{AddFrom: AddFrom_PetEquip})
petEquipData.Level++
}
this.SetDirty(true)
this.petEquipChangeNtf([]*serverproto.PetEquipData{petEquipData}, false)
//属性计算 AttrChange
if petEquipData.EquipPetId > 0 {
petData := this.getPet(petEquipData.EquipPetId)
//bFightChangeNotNotify := true
//if petData != nil && petData.HeroId > 0 {
// bFightChangeNotNotify = false
//}
this.role.roleBattleAttr.AttrChange(AttrChangeST{
IsPet: true,
ChangeType: Attr_Change_Pet_Equip,
ChangePetData: petData,
//FightChangeNotNotify: bFightChangeNotNotify,
})
}
//petData := this.getPet(petEquipData.EquipPetId)
//if petData != nil && petData.HeroId != 0 {
// heroData := this.role.GetRoleHero().GetHero(petData.HeroId)
// if heroData != nil {
// this.role.GetRoleFightPower().CalcPetEquipFightPower(heroData.Id, petData.Id, false)
// }
//
//}
petData := this.getPet(petEquipData.EquipPetId)
if petData != nil {
this.petChangeNtf([]*serverproto.PetData{petData}, nil, nil, false)
}
return serverproto.ErrorCode_ERROR_OK
}
func (this *RolePet) PetEquipUp(petId uint32, slotIndexList []*serverproto.KeyValueType) serverproto.ErrorCode {
petData := this.getPet(petId)
if petData == nil {
return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
}
if len(slotIndexList) <= 0 {
return serverproto.ErrorCode_ERROR_FAIL
}
var changePetEquipData []*serverproto.PetEquipData
for idx := 0; idx < len(slotIndexList); idx++ {
if slotIndexList[idx].Key <= 0 || slotIndexList[idx].Value <= 0 ||
slotIndexList[idx].Key > PetEquipSlotNum {
continue
}
petEquipData := this.GetPetEquip(uint32(slotIndexList[idx].Value))
if petEquipData == nil {
continue
}
cfgData, ok := model.ConvertPetEquip[petEquipData.EquipCfgId]
if !ok {
continue
}
if cfgData.Type != slotIndexList[idx].Key {
continue
}
//当前印记已经装备
if petEquipData.EquipPetId > 0 {
continue
}
bFindSlotIdx := false
for _, slot := range petData.SlotEquipList {
if slot.Idx == slotIndexList[idx].Key {
//已经装备的印记卸下
if slot.EquipId > 0 {
downEquip := this.petEquipDown(slot.EquipId)
if downEquip != nil {
changePetEquipData = append(changePetEquipData, downEquip)
}
slot.EquipId = 0
}
//装备新印记
slot.EquipId = petEquipData.Id
petEquipData.EquipPetId = petData.Id
this.SetDirty(true)
this.dbChangePetEquipList.Add(petEquipData.Id)
changePetEquipData = append(changePetEquipData, petEquipData)
bFindSlotIdx = true
break
}
}
//装备新印记
if !bFindSlotIdx {
petData.SlotEquipList = append(petData.SlotEquipList,
&serverproto.PetSlotDetailData{
Idx: slotIndexList[idx].Key,
EquipId: petEquipData.Id,
})
petEquipData.EquipPetId = petData.Id
this.SetDirty(true)
this.dbChangePetEquipList.Add(petEquipData.Id)
changePetEquipData = append(changePetEquipData, petEquipData)
}
}
//equip ntf
this.petEquipChangeNtf(changePetEquipData, false)
if len(changePetEquipData) > 0 {
this.dbChangePetList.Add(petData.Id)
//slot ntf
this.petChangeNtf([]*serverproto.PetData{petData}, nil, nil, false)
////属性计算 AttrChange
//bFightChangeNotNotify := true
//if petData.HeroId > 0 {
// bFightChangeNotNotify = false
//}
this.role.roleBattleAttr.AttrChange(AttrChangeST{
IsPet: true,
ChangeType: Attr_Change_Pet_Equip,
ChangePetData: petData,
//FightChangeNotNotify: bFightChangeNotNotify,
})
TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Battle_Quality_cnt, 1)
}
//if petData.HeroId != 0 {
// heroData := this.role.GetRoleHero().GetHero(petData.HeroId)
// if heroData != nil {
// this.role.GetRoleFightPower().CalcPetEquipFightPower(heroData.Id, petData.Id, false)
// }
//}
return serverproto.ErrorCode_ERROR_OK
}
func (this *RolePet) PetEquipDown(petId uint32, slotIndex int32) serverproto.ErrorCode {
petData := this.getPet(petId)
if petData == nil {
return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
}
if slotIndex > PetEquipSlotNum {
return serverproto.ErrorCode_ERROR_OK
}
var changePetEquipData []*serverproto.PetEquipData
//一键卸下
if slotIndex <= 0 {
for _, slotIdx := range petData.SlotEquipList {
if slotIdx.EquipId > 0 {
downEquip := this.petEquipDown(slotIdx.EquipId)
if downEquip != nil {
changePetEquipData = append(changePetEquipData, downEquip)
}
slotIdx.EquipId = 0
this.SetDirty(true)
}
}
if len(changePetEquipData) > 0 {
this.dbChangePetList.Add(petData.Id)
}
} else {
for _, slotIdx := range petData.SlotEquipList {
if slotIdx.Idx != slotIndex {
continue
}
if slotIdx.EquipId > 0 {
downEquip := this.petEquipDown(slotIdx.EquipId)
if downEquip != nil {
changePetEquipData = append(changePetEquipData, downEquip)
this.dbChangePetEquipList.Add(downEquip.Id)
}
slotIdx.EquipId = 0
this.SetDirty(true)
}
break
}
}
if len(changePetEquipData) > 0 {
//equip ntf
this.petEquipChangeNtf(changePetEquipData, false)
//slot ntf
this.petChangeNtf([]*serverproto.PetData{petData}, nil, nil, false)
this.dbChangePetList.Add(petData.Id)
//属性计算 AttrChange
//bFightChangeNotNotify := true
//if petData.HeroId > 0 {
// bFightChangeNotNotify = false
//}
this.role.roleBattleAttr.AttrChange(AttrChangeST{
IsPet: true,
ChangeType: Attr_Change_Pet_Equip,
ChangePetData: petData,
//FightChangeNotNotify: bFightChangeNotNotify,
})
TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Battle_Quality_cnt, 1)
}
//if petData.HeroId != 0 {
// heroData := this.role.GetRoleHero().GetHero(petData.HeroId)
// if heroData != nil {
// this.role.GetRoleFightPower().CalcPetEquipFightPower(heroData.Id, petData.Id, false)
// }
//}
return serverproto.ErrorCode_ERROR_OK
}
func (this *RolePet) petEquipDown(petEquipId uint32) *serverproto.PetEquipData {
petEquipData := this.GetPetEquip(petEquipId)
if petEquipData == nil {
return nil
}
petEquipData.EquipPetId = 0
this.SetDirty(true)
this.dbChangePetEquipList.Add(petEquipData.Id)
return petEquipData
}