| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699 |
- package model
- import (
- "math/rand"
- "rocommon/util"
- "roserver/baseserver/model"
- "roserver/baseserver/set"
- "roserver/serverproto"
- )
- //宠物升级
- func (this *Role) PetLevelUp(petId uint32) {
- if this.rolePet != nil {
- ret := this.rolePet.LevelUp(petId)
- ackMsg := &serverproto.SCPetLevelUpAck{
- Error: int32(ret),
- PetId: petId,
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- //宠物进阶
- func (this *Role) PetAdvance(petId uint32, petList []uint32) {
- if this.rolePet != nil {
- ret := this.rolePet.Advance(petId, petList)
- ackMsg := &serverproto.SCPetAdvanceAck{
- Error: int32(ret),
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- //宠物图鉴奖励获取
- func (this *Role) PetManualReward(petCfgId, petId, advLevel int32) {
- if this.rolePet != nil {
- var rewardList []*serverproto.KeyValueType
- ret := this.rolePet.PetManualReward(petCfgId, petId, advLevel, &rewardList)
- ackMsg := &serverproto.SCPetManualRewardAck{
- Error: int32(ret),
- RewardList: rewardList,
- PetCfgId: petCfgId,
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- //宠物技能升级(领悟)
- func (this *Role) PetSkillLevelUp(petId uint32, costPetId uint32) {
- if this.rolePet != nil {
- ret, skillCfgId := this.rolePet.PetSkillLevelUp(petId, costPetId)
- ackMsg := &serverproto.SCPetSkillLevelUpAck{
- Error: int32(ret),
- PetId: petId,
- SkillId: skillCfgId,
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- //宠物分解
- func (this *Role) PetDecompose(petIdList []uint32) {
- if this.rolePet != nil {
- ackMsg := &serverproto.SCPetDecomposeAck{}
- ret := this.rolePet.PetDecompose(petIdList, ackMsg)
- ackMsg.Error = int32(ret)
- this.ReplayGate(ackMsg, true)
- }
- }
- //宠物上阵/下阵
- func (this *Role) PetBattle(battleList []*serverproto.KeyValueType) {
- if this.rolePet != nil {
- ret := this.rolePet.PetBattle(battleList)
- ackMsg := &serverproto.SCPetBattleAck{
- Error: int32(ret),
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- //宠物援助设置
- func (this *Role) PetAssist(petIdList []uint32) {
- if this.rolePet != nil {
- ret := this.rolePet.PetAssist(petIdList)
- ackMsg := &serverproto.SCPetAssistAck{
- Error: int32(ret),
- AssistList: this.rolePet.assistList,
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- //获取羁绊列表数据
- func (this *Role) PetBondListGet() {
- if this.rolePet != nil {
- ackMsg := &serverproto.SCPetBondListAck{}
- ret := this.rolePet.PetBondListGet(ackMsg)
- if ret == serverproto.ErrorCode_ERROR_OK {
- ackMsg.Error = int32(ret)
- this.ReplayGate(ackMsg, true)
- }
- }
- }
- //获取激活羁绊所需的宠物列表(援助列表)
- func (this *Role) PetBondAssistListGet(bondCfgId int32) {
- if this.rolePet != nil {
- ret := this.rolePet.PetBondAssistListGet(bondCfgId)
- if !ret {
- ackMsg := &serverproto.SCPetBondAssistListAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- BondCfgId: bondCfgId,
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- }
- //宠物羁绊激活
- func (this *Role) PetBondActive(bondData []*serverproto.PetBondData) {
- if this.rolePet != nil {
- ret := this.rolePet.PetBondActive(bondData)
- if ret != serverproto.ErrorCode_ERROR_OK {
- ackMsg := &serverproto.SCPetBondActiveAck{
- Error: int32(ret),
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- }
- //最早收集到宠物最高进阶等级获取
- func (this *Role) PetAdvAchievement(petCfgId int32) {
- if this.rolePet != nil {
- ssReqMsg := &serverproto.SSPetAdvAchievementReq{
- PetCfgId: petCfgId,
- }
- this.SendDb(ssReqMsg)
- }
- }
- //宠物系统优化
- //背包界面只下发必要数据,后续通过打开宠物界面主动获取
- func (this *Role) PetGetPetDetailInfo(petIdList []uint32) {
- if this.GetRolePet() != nil {
- ackMsg := &serverproto.SCPetDetailInfoAck{}
- //limit petIdList len
- if len(petIdList) <= 10 {
- for idx := 0; idx < len(petIdList); idx++ {
- petInfo := this.GetRolePet().getPet(petIdList[idx])
- if petInfo != nil {
- ackMsg.PetInfoList = append(ackMsg.PetInfoList, petInfo)
- }
- }
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- ////宠物觉醒
- func (this *Role) PetQiyueUnlock(heroId int32) {
- if this.roleHero == nil || this.rolePet == nil {
- return
- }
- errCode := this.rolePet.PetQiyueUnlock(heroId)
- ackMsg := &serverproto.SCPetQiyueSlotUnlockAck{
- Error: int32(errCode),
- HeroId: heroId,
- }
- this.ReplayGate(ackMsg, true)
- }
- func (this *Role) PetQiyueSlotIn(heroId, slotIdx int32, petId uint32) {
- if this.roleHero == nil || this.rolePet == nil {
- return
- }
- errCode := this.rolePet.PetQiyueSlotIn(heroId, slotIdx, petId)
- ackMsg := &serverproto.SCPetQiyueSlotInAck{
- Error: int32(errCode),
- HeroId: heroId,
- SlotIdx: slotIdx,
- }
- this.ReplayGate(ackMsg, true)
- }
- func (this *Role) PetQiyueSlotOut(heroId, slotIdx int32) {
- if this.roleHero == nil || this.rolePet == nil {
- return
- }
- errCode := this.rolePet.PetQiyueSlotOut(heroId, slotIdx)
- ackMsg := &serverproto.SCPetQiyueSlotOutAck{
- Error: int32(errCode),
- HeroId: heroId,
- SlotIdx: slotIdx,
- }
- this.ReplayGate(ackMsg, true)
- }
- func (this *Role) PetQiyueBattlePetAttr() {
- if this.roleHero == nil || this.rolePet == nil {
- return
- }
- errCode := this.rolePet.PetQiyueBattlePetAttr()
- if errCode != serverproto.ErrorCode_ERROR_OK {
- ackMsg := &serverproto.SCPetQiyueBattlePetAttrAck{
- Error: int32(errCode),
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- const Max_Assist_Num = 6
- type RolePet struct {
- SaveObject
- maxPetId int32
- //petManualList []*serverproto.KeyValueType //宠物图鉴
- petManualRewardList map[int32]*serverproto.PetManualST //宠物图鉴
- petList map[uint32]*serverproto.PetData //宠物列表
- bondList map[int32]*serverproto.PetBondData //羁绊(只填充固定字段数据)
- assistList []*serverproto.AssistIdxData //援助宠物列表
- petEquipList map[uint32]*serverproto.PetEquipData //宠物印记
- dbChangePetList set.Interface
- dbBondChangeList set.Interface
- dbChangePetEquipList set.Interface
- refreshBondListTime uint64 //刷新羁绊列表数据
- queryAssistList map[uint64]*serverproto.AssistData // 其他已经放置
- tmpBondAssistList map[int32][]*serverproto.AssistData //获取其他玩家援助列表(好友,公会)暂存信息
- rushPet *serverproto.RushPet
- }
- func newRolePet(r *Role) *RolePet {
- pet := &RolePet{
- SaveObject: SaveObject{
- role: r,
- },
- }
- pet.petList = map[uint32]*serverproto.PetData{}
- pet.bondList = map[int32]*serverproto.PetBondData{}
- pet.dbChangePetList = set.New(set.NonThreadSafe)
- pet.dbBondChangeList = set.New(set.NonThreadSafe)
- pet.dbChangePetEquipList = set.New(set.NonThreadSafe)
- pet.queryAssistList = map[uint64]*serverproto.AssistData{}
- pet.tmpBondAssistList = map[int32][]*serverproto.AssistData{}
- pet.petManualRewardList = map[int32]*serverproto.PetManualST{}
- pet.petEquipList = map[uint32]*serverproto.PetEquipData{}
- return pet
- }
- func (this *RolePet) Load(msg interface{}) bool {
- return true
- }
- //收到多个,数据量大时
- func (this *RolePet) LoadOther(msg interface{}) bool {
- petInfoMsg := msg.(*serverproto.SSLoadPetNtf)
- petInfo := petInfoMsg.Pet
- if petInfo == nil {
- return true
- }
- if petInfo.MaxPetId != 0 {
- this.maxPetId = petInfo.MaxPetId
- }
- for idx := 0; idx < len(petInfo.PetList); idx++ {
- this.petList[petInfo.PetList[idx].Id] = petInfo.PetList[idx]
- if len(this.petManualRewardList) > 0 {
- if val, ok := this.petManualRewardList[petInfo.PetList[idx].ConfigId-800]; ok {
- if val.AdvLevel < petInfo.PetList[idx].AdvanceLevel {
- val.AdvLevel = petInfo.PetList[idx].AdvanceLevel
- }
- }
- }
- }
- for idx := 0; idx < len(petInfo.BondList); idx++ {
- this.bondList[petInfo.BondList[idx].BondCfgId] = petInfo.BondList[idx]
- }
- if petInfo.AssistList != nil {
- this.assistList = petInfo.AssistList
- }
- for idx := 0; idx < len(petInfo.PetManualRewardList); idx++ {
- this.petManualRewardList[petInfo.PetManualRewardList[idx].PetCfgId] = petInfo.PetManualRewardList[idx]
- }
- //新老数据转换
- if petInfo.PetManualList != nil {
- for idx := 0; idx < len(petInfo.PetManualList); idx++ {
- if item, ok := this.petManualRewardList[petInfo.PetManualList[idx].Key]; ok {
- item.RewardState = petInfo.PetManualList[idx].Value
- for k := 0; k < 10; k++ {
- if petInfo.PetManualList[idx].Value&(1<<uint32(k)) > 0 {
- if item.AdvLevel < uint32(k) {
- item.AdvLevel = uint32(k)
- }
- }
- }
- for _, v := range this.petList {
- if v.ConfigId-800 == petInfo.PetManualList[idx].Key {
- if v.AdvanceLevel > item.AdvLevel {
- item.AdvLevel = v.AdvanceLevel
- }
- break
- }
- }
- } else {
- item := &serverproto.PetManualST{
- PetCfgId: petInfo.PetManualList[idx].Key,
- RewardState: petInfo.PetManualList[idx].Value,
- }
- for k := 0; k < 10; k++ {
- if petInfo.PetManualList[idx].Value&(1<<uint32(k)) > 0 {
- if item.AdvLevel < uint32(k) {
- item.AdvLevel = uint32(k)
- }
- }
- }
- for _, v := range this.petList {
- if v.ConfigId-800 == petInfo.PetManualList[idx].Key {
- if v.AdvanceLevel > item.AdvLevel {
- item.AdvLevel = v.AdvanceLevel
- }
- break
- }
- }
- this.petManualRewardList[item.PetCfgId] = item
- }
- }
- petInfo.PetManualList = nil
- this.SetDirty(true)
- }
- if petInfo.RushPet != nil {
- this.rushPet = petInfo.RushPet
- }
- //宠物印记
- for idx := 0; idx < len(petInfo.PetEquipList); idx++ {
- this.petEquipList[petInfo.PetEquipList[idx].Id] = petInfo.PetEquipList[idx]
- }
- if len(this.assistList) <= 0 {
- for idx := 0; idx < Max_Assist_Num; idx++ {
- this.assistList = append(this.assistList, &serverproto.AssistIdxData{})
- }
- }
- //有多个通知协议导致,宠物没有接受完成就进行判断
- if petInfoMsg.LoadEnd {
- this.refreshPetBond(false)
- }
- return true
- }
- func (this *RolePet) Save() {
- this.SetDirty(false)
- util.DebugF("uid=%v RolePet save...", this.role.GetUUid())
- saveMsg := &serverproto.SSPetDataSaveReq{
- RolePet: &serverproto.RolePet{},
- }
- saveMsg.RolePet.MaxPetId = this.maxPetId
- saveMsg.RolePet.AssistList = this.assistList
- for _, v := range this.petManualRewardList {
- saveMsg.RolePet.PetManualRewardList = append(saveMsg.RolePet.PetManualRewardList, v)
- }
- //pet
- changList := this.dbChangePetList.List()
- for idx := 0; idx < len(changList); idx++ {
- petId := changList[idx].(uint32)
- pet := this.getPet(petId)
- if pet == nil {
- saveMsg.PetDelList = append(saveMsg.PetDelList, petId)
- } else {
- saveMsg.RolePet.PetList = append(saveMsg.RolePet.PetList, pet)
- }
- }
- this.dbChangePetList.Clear()
- //羁绊数据
- bondChangList := this.dbBondChangeList.List()
- for idx := 0; idx < len(bondChangList); idx++ {
- bondCfgId := bondChangList[idx].(int32)
- bond := this.getBond(bondCfgId)
- if bond == nil {
- saveMsg.BondDelList = append(saveMsg.BondDelList, bondCfgId)
- } else {
- saveMsg.RolePet.BondList = append(saveMsg.RolePet.BondList, bond)
- }
- }
- this.dbBondChangeList.Clear()
- saveMsg.RolePet.RushPet = this.rushPet
- //宠物印记数据
- for _, val := range this.petEquipList {
- saveMsg.RolePet.PetEquipList = append(saveMsg.RolePet.PetEquipList, val)
- }
- this.dbChangePetEquipList.Clear()
- this.role.SendDb(saveMsg)
- }
- func (this *RolePet) StartupNtf() {
- petNtf := &serverproto.SCStartupInfoPetNtf{
- RolePetInfo: &serverproto.RolePet{},
- }
- for _, v := range this.petManualRewardList {
- petNtf.RolePetInfo.PetManualRewardList = append(petNtf.RolePetInfo.PetManualRewardList, v)
- }
- petNtf.RolePetInfo.AssistList = this.assistList
- petNtf.RolePetInfo.MaxPetId = this.maxPetId
- for _, val := range this.bondList {
- petNtf.RolePetInfo.BondList = append(petNtf.RolePetInfo.BondList, val)
- }
- for _, val := range this.petEquipList {
- petNtf.RolePetInfo.PetEquipList = append(petNtf.RolePetInfo.PetEquipList, val)
- }
- tmpCount := 0
- //数据量大不能直接发送全部
- for _, val := range this.petList {
- //petNtf.RolePetInfo.PetList = append(petNtf.RolePetInfo.PetList, val)
- tmpPetInfo := &serverproto.PetData{
- Id: val.Id,
- Level: val.Level,
- ConfigId: val.ConfigId,
- AdvanceLevel: val.AdvanceLevel,
- HeroId: val.HeroId,
- Param: val.Param,
- PetFightPower: val.PetFightPower,
- SkillList: val.SkillList,
- QiyueHeroId: val.QiyueHeroId,
- }
- petNtf.RolePetInfo.PetList = append(petNtf.RolePetInfo.PetList, tmpPetInfo)
- tmpCount++
- if tmpCount >= 50 {
- util.DebugF("uid=%v StartupProto petlen=%v ", this.role.GetUUid(), tmpCount)
- this.role.ReplayGate(petNtf, true)
- petNtf = &serverproto.SCStartupInfoPetNtf{
- RolePetInfo: &serverproto.RolePet{},
- }
- tmpCount = 0
- }
- }
- if tmpCount >= 0 {
- sendLen := this.role.ReplayGate(petNtf, true)
- util.DebugF("uid=%v StartupProto ntfMsgLen=%v petlen=%v totalNum=%v", this.role.GetUUid(), sendLen, tmpCount, len(this.petList))
- }
- }
- func (this *RolePet) GetPetePileTotalNum() int {
- return len(this.petList)
- }
- func (this *RolePet) petChangeNtf(petData []*serverproto.PetData, delPetList []uint32, manualList []*serverproto.PetManualST, bAssist bool) {
- ntfMsg := &serverproto.SCPetChangeNtf{}
- if petData != nil {
- ntfMsg.PetList = append(ntfMsg.PetList, petData...)
- }
- if len(delPetList) > 0 {
- ntfMsg.DelPetList = delPetList
- }
- if len(manualList) > 0 {
- ntfMsg.PetManualList = manualList
- }
- if bAssist {
- ntfMsg.AssistPetList = this.assistList
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- func (this *RolePet) LevelUp(petId uint32) serverproto.ErrorCode {
- pet := this.getPet(petId)
- if pet == nil {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- petCfgData, ok := model.ConvertPet[pet.ConfigId]
- if !ok {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- //获取等级上限
- levelUpLimit := this.getLevelUpLimit(int(pet.AdvanceLevel))
- if pet.Level >= levelUpLimit {
- return serverproto.ErrorCode_ERROR_PET_LEVEL_LIMIT
- }
- //升级消耗(经验,zeny)
- if this.levelUp(petCfgData.Quality, levelUpLimit, pet) {
- this.petChangeNtf([]*serverproto.PetData{pet}, nil, nil, false)
- //db save
- this.dbChangePetList.Add(petId)
- bFightChangeNotNotify := true
- if this.isBattle(pet) || pet.QiyueHeroId > 0 {
- //this.role.GetRoleFightPower().OnBattlePetChanged(pet.HeroId, true)
- this.OnRushPetScoreChange()
- bFightChangeNotNotify = false
- }
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- IsPet: true,
- ChangePetData: pet,
- ChangeType: Attr_Change_Pet_Base,
- FightChangeNotNotify: bFightChangeNotNotify,
- })
- return serverproto.ErrorCode_ERROR_OK
- }
- return serverproto.ErrorCode_ERROR_PET_MONEY_ENOUGH
- }
- func (this *RolePet) Advance(petId uint32, petList []uint32) serverproto.ErrorCode {
- pet := this.getPet(petId)
- if pet == nil {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- _, ok := model.ConvertPet[pet.ConfigId]
- if !ok {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- advCfgData, ok := model.ConvertPetProgress[pet.ConfigId]
- if !ok {
- return serverproto.ErrorCode_ERROR_PET_ADVANCE_DATA_NOT_FOUND
- }
- if pet.AdvanceLevel >= uint32(len(advCfgData.ProgressList)) {
- return serverproto.ErrorCode_ERROR_PET_ADVANCE_LIMIT
- }
- //pet.AdvanceLevel -> pet.AdvanceLevel+1
- var costZeny int32 = 0
- vipPetAdvance := this.role.GetRoleBase().GetVipData(model.Vip_System_PetAdvance)
- if vipPetAdvance <= 0 {
- costZeny = advCfgData.ProgressList[pet.AdvanceLevel].CostZeny
- if this.role.GetMoney() < uint64(costZeny) {
- return serverproto.ErrorCode_ERROR_PET_MONEY_ENOUGH
- }
- }
- bAssistChange := false
- condition1Set := set.New(set.NonThreadSafe)
- condition2Set := set.New(set.NonThreadSafe)
- for idx := 0; idx < len(petList); idx++ {
- if petList[idx] == petId {
- continue
- }
- tmpPet := this.getPet(petList[idx])
- //上阵/契约宠物无法作为进阶材料
- if tmpPet == nil || this.isBattle(tmpPet) || tmpPet.QiyueHeroId > 0 {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- tmpPetCfgData, ok := model.ConvertPet[tmpPet.ConfigId]
- if !ok {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- if this.isInAssist(tmpPet.Id, true) {
- bAssistChange = true
- }
- //ConditionPet1
- bNum := 0
- conditionList := advCfgData.ProgressList[pet.AdvanceLevel].ConditionPet1
- for k := 0; k < len(conditionList); k++ {
- switch (serverproto.EPetAssistType)(conditionList[k].Key) {
- case serverproto.EPetAssistType_EPetAssistType_Quality:
- if tmpPetCfgData.Quality >= conditionList[k].Value {
- bNum++
- }
- case serverproto.EPetAssistType_EPetAssistType_AdvLevel:
- if tmpPet.AdvanceLevel >= uint32(conditionList[k].Value) {
- bNum++
- }
- case serverproto.EPetAssistType_EPetAssistType_Nature:
- if tmpPetCfgData.NatureType == conditionList[k].Value {
- bNum++
- //return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
- }
- default:
- return serverproto.ErrorCode_ERROR_FAIL
- }
- }
- if bNum == len(conditionList) {
- //列表中有相同宠物ID
- if condition1Set.Has(petList[idx]) {
- return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
- }
- condition1Set.Add(petList[idx])
- }
- //ConditionPet2
- bNum = 0
- conditionList = advCfgData.ProgressList[pet.AdvanceLevel].ConditionPet2
- for k := 0; k < len(conditionList); k++ {
- switch (serverproto.EPetAssistType)(conditionList[k].Key) {
- case serverproto.EPetAssistType_EPetAssistType_Quality:
- if tmpPetCfgData.Quality >= conditionList[k].Value {
- bNum++
- }
- case serverproto.EPetAssistType_EPetAssistType_AdvLevel:
- if tmpPet.AdvanceLevel >= uint32(conditionList[k].Value) {
- bNum++
- }
- case serverproto.EPetAssistType_EPetAssistType_Nature:
- if tmpPetCfgData.NatureType == conditionList[k].Value {
- bNum++
- //return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
- }
- default:
- return serverproto.ErrorCode_ERROR_FAIL
- }
- }
- if bNum == len(conditionList) {
- //列表中有相同宠物ID
- if condition2Set.Has(petList[idx]) {
- return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
- }
- condition2Set.Add(petList[idx])
- }
- }
- conditionNum := 0
- if len(advCfgData.ProgressList[pet.AdvanceLevel].ConditionPet1) > 0 {
- conditionNum++
- if condition1Set.Size() <= 0 {
- return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
- }
- }
- if len(advCfgData.ProgressList[pet.AdvanceLevel].ConditionPet2) > 0 {
- conditionNum++
- if condition2Set.Size() <= 0 {
- return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
- }
- }
- //条件个数和宠物个数不匹配
- for _, data := range condition2Set.List() {
- condition1Set.Add(data.(uint32))
- }
- if condition1Set.Size() < conditionNum || len(petList) < conditionNum {
- return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
- }
- //消耗资源
- this.role.DelItem(int32(serverproto.ResType_Res_Coin), costZeny, AddItemST{AddFrom: AddFrom_Pet})
- pet.AdvanceLevel++
- this.delPetList(petList)
- for idx := 0; idx < len(petList); idx++ {
- this.dbChangePetList.Add(petList[idx])
- }
- this.dbChangePetList.Add(petId)
- if !bAssistChange && this.isInAssist(petId, false) {
- bAssistChange = true
- }
- //宠物图鉴
- manualItem, ok := this.petManualRewardList[pet.ConfigId-800]
- if !ok {
- manualItem := &serverproto.PetManualST{
- PetCfgId: pet.ConfigId - 800,
- AdvLevel: pet.AdvanceLevel,
- }
- this.petManualRewardList[manualItem.PetCfgId] = manualItem
- } else {
- manualItem.AdvLevel = pet.AdvanceLevel
- }
- this.petChangeNtf([]*serverproto.PetData{pet}, petList, []*serverproto.PetManualST{manualItem}, bAssistChange)
- this.SetDirty(true)
- if bAssistChange {
- this.saveAssist()
- }
- //最早收集到宠物最高进阶等级获取
- if pet.AdvanceLevel == uint32(len(advCfgData.ProgressList)) {
- ssMsg := &serverproto.SSPetAdvAchievementSetNtf{
- PetCfgId: pet.ConfigId,
- AdvLevel: int32(pet.AdvanceLevel),
- }
- this.role.SendDb(ssMsg)
- }
- //attr
- bFightChangeNotNotify := true
- if this.isBattle(pet) || pet.QiyueHeroId > 0 {
- //this.role.GetRoleFightPower().OnBattlePetChanged(pet.HeroId, true)
- this.OnRushPetScoreChange()
- bFightChangeNotNotify = false
- }
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- IsPet: true,
- ChangePetData: pet,
- ChangeType: Attr_Change_Pet_Base,
- FightChangeNotNotify: bFightChangeNotNotify,
- })
- //刷新羁绊列表中玩家自身的宠物数据(分解,消耗造成的移除操作)
- if this.refreshPetBond(true) {
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- IsPet: true,
- ChangeType: Attr_Change_Pet_Bond,
- FightChangeNotNotify: bFightChangeNotNotify,
- })
- }
- util.InfoF("uid=%v PetAdvance petid=%v advlevel=%v", this.role.GetUUid(), pet.Id, pet.AdvanceLevel)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RolePet) PetManualReward(petCfgId, petId, petAdvLevel int32, rewardList *[]*serverproto.KeyValueType) serverproto.ErrorCode {
- if petCfgId < 800 || petAdvLevel < 0 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- tmpPetCfgId := petCfgId - 800
- manualItem, ok := this.petManualRewardList[tmpPetCfgId]
- if !ok {
- return serverproto.ErrorCode_ERROR_PET_MANUAL_NOT_FOUND
- }
- petCfgData, ok := model.ConvertPet[petCfgId]
- if !ok {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- if manualItem.AdvLevel < uint32(petAdvLevel) {
- return serverproto.ErrorCode_ERROR_PET_MANUAL_NOT_FOUND
- }
- //进阶奖励是否存在
- advReward, ok := petCfgData.ManualRewardList[petAdvLevel]
- if !ok {
- return serverproto.ErrorCode_ERROR_PET_MANUAL_NOT_FOUND
- }
- if manualItem.RewardState&(1<<uint32(petAdvLevel)) > 0 {
- return serverproto.ErrorCode_ERROR_PET_MANUAL_REWARD
- }
- addItemList := map[int32]int32{}
- addItemList[advReward.Key] = advReward.Value
- ret := this.role.CanAddItemList(addItemList)
- if ret == serverproto.ErrorCode_ERROR_OK {
- manualItem.RewardState |= 1 << uint32(petAdvLevel)
- this.SetDirty(true)
- this.role.AddItemList(addItemList, AddFrom_Pet, true)
- *rewardList = append(*rewardList, advReward)
- this.petChangeNtf(nil, nil, []*serverproto.PetManualST{manualItem}, false)
- util.InfoF("uid=%v PetManualReward reward=%v", this.role.GetUUid(), rewardList)
- }
- return ret
- }
- func (this *RolePet) PetSkillLevelUp(petId uint32, costPetId uint32) (serverproto.ErrorCode, int32) {
- pet := this.getPet(petId)
- costPet := this.getPet(costPetId)
- if pet == nil || costPet == nil || petId == costPetId || this.isBattle(costPet) || costPet.QiyueHeroId > 0 {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND, 0
- }
- petCfgData, ok := model.ConvertPet[pet.ConfigId]
- if !ok {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND, 0
- }
- if len(pet.SkillList) <= 0 {
- util.InfoF("uid=%v PetSkillLevelUp pet skill empty", this.role.GetUUid())
- return serverproto.ErrorCode_ERROR_FAIL, 0
- }
- if this.role.GetMoney() < uint64(model.GlobalPetSkillUpConsume) {
- return serverproto.ErrorCode_ERROR_MONEY_NOT_ENOUGH, 0
- }
- //材料检查
- if pet.ConfigId == costPet.ConfigId || costPet.ConfigId == model.GlobalPetSkillUpCost {
- var randSkillIdList []int
- for idx := 0; idx < len(pet.SkillList); idx++ {
- petSkill := pet.SkillList[idx]
- bFind := false
- for k := 0; k < len(petCfgData.SkillList); k++ {
- if petSkill.ConfigId == petCfgData.SkillList[k].SkillId {
- bFind = true
- if petSkill.Level >= petCfgData.SkillList[k].MaxSkillLevel {
- bFind = false
- }
- }
- }
- if bFind {
- randSkillIdList = append(randSkillIdList, idx)
- }
- }
- skillLen := len(randSkillIdList)
- if skillLen <= 0 {
- return serverproto.ErrorCode_ERROR_PET_SKILLUP_NONE, 0
- }
- randNum := rand.Int31n(int32(skillLen))
- randSkill := pet.SkillList[randSkillIdList[randNum]]
- randSkill.Level++
- randSkill.Rate = petCfgData.GetSkillRate(randSkill.ConfigId, randSkill.Level)
- this.delPet(costPetId)
- if this.isInAssist(costPetId, true) || this.isInAssist(petId, false) {
- this.saveAssist()
- }
- this.dbChangePetList.Add(pet.Id)
- this.dbChangePetList.Add(costPetId)
- this.role.DelItem(int32(serverproto.ResType_Res_Coin), model.GlobalPetSkillUpConsume, AddItemST{AddFrom: AddFrom_Pet})
- this.petChangeNtf([]*serverproto.PetData{pet}, []uint32{costPetId}, nil, true)
- this.SetDirty(true)
- //如果是上阵的宠物//通知战力变化
- bFightChangeNotNotify := true
- if this.isBattle(pet) || pet.QiyueHeroId > 0 {
- //this.role.GetRoleFightPower().OnBattlePetChanged(pet.HeroId, false)
- bFightChangeNotNotify = false
- }
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- IsPet: true,
- ChangePetData: pet,
- ChangeType: Attr_Change_Pet_Skill,
- FightChangeNotNotify: bFightChangeNotNotify,
- })
- this.OnRushPetScoreChange()
- return serverproto.ErrorCode_ERROR_OK, randSkill.ConfigId
- }
- return serverproto.ErrorCode_ERROR_PET_SKILLUP_TYPE, 0
- }
- func (this *RolePet) GetPetTotalSkillLevel(pet *serverproto.PetData) int32 {
- if pet == nil || len(pet.SkillList) <= 0 {
- return 0
- }
- var totalSkillLevel int32 = 0
- for _, data := range pet.SkillList {
- if data.Level > 1 {
- totalSkillLevel += data.Level - 1
- }
- }
- return totalSkillLevel
- }
- func (this *RolePet) PetDecompose(petIdList []uint32, ackMsg *serverproto.SCPetDecomposeAck) serverproto.ErrorCode {
- bAssistChange := false
- var delPetLIst []uint32
- var addItemList = map[int32]int32{}
- var ntfDataList []*serverproto.PetEquipData
- for idx := 0; idx < len(petIdList); idx++ {
- pet := this.getPet(petIdList[idx])
- //宠物上阵/契约无法进行分解
- if pet == nil || pet.HeroId != 0 || pet.QiyueHeroId > 0 {
- continue
- }
- petCfgData, ok := model.ConvertPet[pet.ConfigId]
- if !ok {
- continue
- }
- retPercent := (float32)(model.GlobalNormalPetDecompose * 1.0)
- vipPetDecompose := this.role.GetRoleBase().GetVipData(model.Vip_System_PetDesolve)
- if vipPetDecompose > 0 {
- retPercent = (float32)(model.GlobalVipPetDecompose)
- }
- retPercent = retPercent / 100
- var addExp int32 = 0
- var addZeny int32 = 0
- sumSkillLevel := this.GetPetTotalSkillLevel(pet)
- if len(model.GlobalPet1LevelDecompose) >= 3 {
- switch petCfgData.Quality {
- case model.Pet_Type_Normal:
- addResItem := model.GlobalPet1LevelDecompose[0]
- addExp = addResItem.Key
- addZeny = addResItem.Value
- tmpKV := model.GlobalPetDecomposeNormal[pet.AdvanceLevel]
- if tmpKV != nil {
- realCont := tmpKV.Value
- //计算技能相关
- tmp := model.GlobalPetDecomposeItemList[model.Pet_Type_Normal]
- if tmp != nil {
- realCont += sumSkillLevel * tmp.Value
- }
- addItemList[tmpKV.Key] += int32(float32(realCont) * retPercent)
- }
- case model.Pet_Type_Mini:
- addResItem := model.GlobalPet1LevelDecompose[1]
- addExp = addResItem.Key
- addZeny = addResItem.Value
- tmpKV := model.GlobalPetDecomposeMin[pet.AdvanceLevel]
- if tmpKV != nil {
- realCont := tmpKV.Value
- //计算技能相关
- tmp := model.GlobalPetDecomposeItemList[model.Pet_Type_Mini]
- if tmp != nil {
- realCont += sumSkillLevel * tmp.Value
- }
- addItemList[tmpKV.Key] += int32(float32(realCont) * retPercent)
- }
- case model.Pet_Type_MVP:
- addResItem := model.GlobalPet1LevelDecompose[2]
- addExp = addResItem.Key
- addZeny = addResItem.Value
- tmpKV := model.GlobalPetDecomposeMvp[pet.AdvanceLevel]
- if tmpKV != nil {
- realCont := tmpKV.Value
- //计算技能相关
- tmp := model.GlobalPetDecomposeItemList[model.Pet_Type_MVP]
- if tmp != nil {
- realCont += sumSkillLevel * tmp.Value
- }
- addItemList[tmpKV.Key] += int32(float32(realCont) * retPercent)
- }
- }
- }
- expData, ok := model.ConvertPetExp[pet.Level-1]
- if ok {
- if petCfgData.Quality == model.Pet_Type_Normal {
- addExp += expData.NormalAccuExp
- addZeny += expData.NormalAccuZeny
- } else if petCfgData.Quality == model.Pet_Type_Mini {
- addExp += expData.MiniAccuExp
- addZeny += expData.MiniAccuZeny
- } else if petCfgData.Quality == model.Pet_Type_MVP {
- addExp += expData.MvpAccuExp
- addZeny += expData.MvpAccuZeny
- }
- }
- addItemList[int32(serverproto.ResType_Res_PetExp)] += int32(float32(addExp) * retPercent)
- addItemList[int32(serverproto.ResType_Res_Coin)] += int32(float32(addZeny) * retPercent)
- this.dbChangePetList.Add(pet.Id)
- delPetLIst = append(delPetLIst, pet.Id)
- delete(this.petList, pet.Id)
- this.SetDirty(true)
- if this.isInAssist(petIdList[idx], true) {
- bAssistChange = true
- }
- //this.isInPetBondList(petIdList[idx], this.role.GetUUid(), true)
- //宠物印记卸下
- for _, slotEquip := range pet.SlotEquipList {
- if slotEquip.EquipId > 0 {
- petEquipData := this.petEquipDown(slotEquip.EquipId)
- ntfDataList = append(ntfDataList, petEquipData)
- }
- }
- }
- if len(ntfDataList) > 0 {
- this.role.rolePet.petEquipChangeNtf(ntfDataList, false)
- }
- if len(addItemList) > 0 {
- this.role.GetRoleBag().AddItemList(addItemList, AddItemST{AddFrom: AddFrom_Pet, Notify: true})
- for key, val := range addItemList {
- if key <= 0 || val <= 0 {
- continue
- }
- ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{Key: key, Value: val})
- }
- }
- if len(delPetLIst) > 0 {
- this.petChangeNtf(nil, delPetLIst, nil, bAssistChange)
- }
- if bAssistChange {
- this.saveAssist()
- }
- //刷新羁绊列表中玩家自身的宠物数据(分解,消耗造成的移除操作)
- if this.refreshPetBond(true) {
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- IsPet: true,
- ChangeType: Attr_Change_Pet_Bond,
- })
- }
- //判断是否激活,增加属性,战斗力
- //this.role.GetRoleFightPower().ClearPetBondFightPower()
- //for _, data := range this.bondList {
- // this.role.GetRoleFightPower().CalcAndResetPetBondFightPower(data.BondCfgId)
- //}
- //this.role.GetRoleFightPower().AfterBondFightPowerChange()
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RolePet) PetBondListGet(msg *serverproto.SCPetBondListAck) serverproto.ErrorCode {
- if !this.PetBondListAssistQuery(true) {
- this.petBondListQuery(msg)
- return serverproto.ErrorCode_ERROR_OK
- }
- return serverproto.ErrorCode_ERROR_FAIL
- }
- func (this *RolePet) PetBondListAssistQuery(notify bool) bool {
- nowTime := util.GetTimeMilliseconds()
- if this.refreshBondListTime == 0 || nowTime-this.refreshBondListTime > 5*1000 {
- this.refreshBondListTime = nowTime
- queryMsg := &serverproto.SSPetQueryAssistInfoReq{
- Notify: notify,
- }
- var assistDataList = map[uint64]*serverproto.AssistData{}
- for _, val := range this.bondList {
- for idx := 0; idx < len(val.BondList); idx++ {
- if val.BondList[idx].OwnerUid == 0 {
- continue
- }
- assistData, ok := assistDataList[val.BondList[idx].OwnerUid]
- if !ok {
- assistData = &serverproto.AssistData{
- OwnerUid: val.BondList[idx].OwnerUid,
- }
- queryMsg.QueryAssistList = append(queryMsg.QueryAssistList, assistData)
- assistDataList[assistData.OwnerUid] = assistData
- }
- bFind := false
- for k := 0; k < len(assistData.PetInfoList); k++ {
- if assistData.PetInfoList[k].Id == val.BondList[idx].PetId {
- bFind = true
- break
- }
- }
- if !bFind {
- assistData.PetInfoList = append(assistData.PetInfoList, &serverproto.PetData{
- Id: val.BondList[idx].PetId, //选择的援助宠物ID
- })
- }
- }
- }
- if len(assistDataList) > 0 {
- queryMsg.UidList = append(queryMsg.UidList, this.role.GetRoleSocial().GetFriendList()...)
- queryMsg.GuildId = uint64(this.role.GetRoleGuildId())
- this.role.SendDb(queryMsg)
- return true
- }
- }
- return false
- }
- func (this *RolePet) OnPetBondListAssistQuery(ackMsg *serverproto.SSPetQueryAssistInfoAck) {
- this.queryAssistList = map[uint64]*serverproto.AssistData{}
- for idx := 0; idx < len(ackMsg.QueryAssistList); idx++ {
- this.queryAssistList[ackMsg.QueryAssistList[idx].OwnerUid] = ackMsg.QueryAssistList[idx]
- }
- sendMsg := &serverproto.SCPetBondListAck{}
- this.petBondListQuery(sendMsg)
- if ackMsg.Notify {
- this.role.ReplayGate(sendMsg, true)
- }
- }
- func (this *RolePet) petBondListQuery(msg *serverproto.SCPetBondListAck) serverproto.ErrorCode {
- //表示当前羁绊属性被修改需求重新计算
- var uniqueUidList = set.New(set.NonThreadSafe)
- for _, val := range this.bondList {
- for idx := 0; idx < len(val.BondList); idx++ {
- bondPosData := val.BondList[idx]
- if bondPosData.PetId == 0 {
- val.BondList[idx].PetCfgId = 0
- val.BondList[idx].AdvanceLevel = 0
- val.BondList[idx].OwnerUid = 0
- continue
- }
- //当前设置羁绊的宠物为自己
- if bondPosData.OwnerUid == 0 {
- if bondPosData.PetId > 0 {
- tmpPet := this.getPet(bondPosData.PetId)
- if tmpPet == nil {
- val.BondList[idx].PetId = 0
- val.BondList[idx].PetCfgId = 0
- val.BondList[idx].AdvanceLevel = 0
- val.BondList[idx].OwnerUid = 0
- this.dbBondChangeList.Add(val.BondCfgId)
- } else {
- val.BondList[idx].AdvanceLevel = tmpPet.AdvanceLevel
- val.BondList[idx].PetCfgId = tmpPet.ConfigId
- }
- }
- continue
- }
- //当前设置羁绊的宠物为其他玩家所有
- assistVal, ok := this.queryAssistList[bondPosData.OwnerUid]
- if !ok {
- val.BondList[idx].PetId = 0
- val.BondList[idx].OwnerUid = 0
- val.BondList[idx].AdvanceLevel = 0
- val.BondList[idx].PetCfgId = 0
- this.dbBondChangeList.Add(val.BondCfgId)
- continue
- }
- bFind := false
- for i := 0; i < len(assistVal.PetInfoList); i++ {
- if assistVal.PetInfoList[i].Id == bondPosData.PetId && assistVal.PetInfoList[i].Param > 0 { //Param>0表示玩家存在该宠物
- //添加唯一玩家名称
- if !uniqueUidList.Has(val.BondList[idx].OwnerUid) {
- uniqueUidList.Add(val.BondList[idx])
- msg.UidNameList = append(msg.UidNameList, &serverproto.KeyValueType64Str{
- Key: assistVal.OwnerUid,
- StrVal: assistVal.OwnerNickName,
- })
- }
- val.BondList[idx].AdvanceLevel = assistVal.PetInfoList[i].AdvanceLevel
- val.BondList[idx].PetCfgId = assistVal.PetInfoList[i].ConfigId
- //之前设置的援助玩家宠物合法
- bFind = true
- break
- }
- }
- if !bFind {
- val.BondList[idx].PetId = 0
- val.BondList[idx].OwnerUid = 0
- val.BondList[idx].AdvanceLevel = 0
- val.BondList[idx].PetCfgId = 0
- this.dbBondChangeList.Add(val.BondCfgId)
- }
- }
- msg.BondList = append(msg.BondList, val)
- }
- if this.refreshPetBond(false) {
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- IsPet: true,
- ChangeType: Attr_Change_Pet_Bond,
- })
- }
- ////todo...
- //// 战力没有初始化前,需要先初始化一次
- //
- //if this.dbBondChangeList.Size() > 0 {
- // this.SetDirty(true)
- //
- // //todo...
- // // 重新计算变更后的战斗力处理
- // this.checkBondCondition(this.dbBondChangeList.List())
- //}
- return serverproto.ErrorCode_ERROR_OK
- }
- // Task 获得指定上阵宠物数量 印记达到指定品质
- func (this *RolePet) GetPetBattleCntByQuality(quality int32) int32 {
- var cnt int32 = 0
- mainHero := this.role.GetRoleBase().RoleData().HeroData
- if mainHero != nil && mainHero.BattlePetId > 0 {
- Battle := this.getPet(mainHero.BattlePetId)
- if Battle != nil {
- meet := false
- for i := 0; i < PetEquipSlotNum; i++ {
- meet = false
- if len(Battle.SlotEquipList) < i+1 {
- break
- }
- pet := Battle.SlotEquipList[i]
- if pet.EquipId <= 0 {
- break
- }
- EquipData := this.GetPetEquip(pet.EquipId)
- if EquipData == nil {
- continue
- }
- cfg, ok := model.ConvertPetEquip[int32(EquipData.EquipCfgId)]
- if !ok || cfg == nil {
- continue
- }
- if cfg.Quality < quality {
- break
- }
- meet = true
- }
- if meet {
- cnt++
- }
- }
- }
- for _, hero := range this.role.GetRoleHero().heroList {
- if hero.BattlePetId <= 0 {
- continue
- }
- Battle := this.getPet(hero.BattlePetId)
- if Battle == nil {
- continue
- }
- meet := false
- for i := 0; i < PetEquipSlotNum; i++ {
- meet = false
- if len(Battle.SlotEquipList) < i+1 {
- break
- }
- pet := Battle.SlotEquipList[i]
- if pet.EquipId <= 0 {
- break
- }
- EquipData := this.GetPetEquip(pet.EquipId)
- if EquipData == nil {
- continue
- }
- cfg, ok := model.ConvertPetEquip[EquipData.EquipCfgId]
- if !ok || cfg == nil {
- continue
- }
- if cfg.Quality < quality {
- break
- }
- meet = true
- }
- if meet {
- cnt++
- }
- }
- return cnt
- }
- func (this *RolePet) PetBattle(battleList []*serverproto.KeyValueType) serverproto.ErrorCode {
- var tmpChangeList = set.New(set.NonThreadSafe)
- //判断是否上阵相同宠物
- for idx := 0; idx < len(battleList); idx++ {
- petId := uint32(battleList[idx].Value)
- if petId <= 0 {
- continue
- }
- pet := this.getPet(uint32(petId))
- if pet == nil {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- if tmpChangeList.Has(pet.ConfigId) {
- return serverproto.ErrorCode_ERROR_PET_BATTLE_REPEATED
- }
- tmpChangeList.Add(pet.ConfigId)
- }
- tmpChangeList.Clear()
- for idx := 0; idx < len(battleList); idx++ {
- heroId := battleList[idx].Key
- petId := uint32(battleList[idx].Value)
- heroData := this.role.GetRoleHero().GetHero(heroId)
- if heroData == nil {
- continue
- }
- //下阵
- if petId == 0 {
- tmpPetId := heroData.BattlePetId
- if tmpPetId > 0 && this.role.GetRoleHero().PetBattle(0, heroId) {
- tmpPet := this.getPet(tmpPetId)
- if tmpPet != nil {
- tmpPet.HeroId = 0
- this.dbChangePetList.Add(tmpPetId)
- this.SetDirty(true)
- tmpChangeList.Add(tmpPetId)
- }
- }
- } else {
- //上阵
- pet := this.getPet(uint32(petId))
- if pet == nil {
- continue
- }
- if pet.HeroId == heroId {
- continue
- }
- //当成契约材料宠物无法上阵
- if pet.QiyueHeroId != 0 {
- continue
- }
- //当前petid对应宠物正在上阵,先下阵
- if pet.HeroId != 0 {
- this.role.GetRoleHero().PetBattle(0, pet.HeroId)
- }
- //当前玩家身上的宠物下阵
- if heroData.BattlePetId > 0 {
- tmpPet := this.getPet(heroData.BattlePetId)
- if tmpPet != nil {
- tmpPet.HeroId = 0
- this.dbChangePetList.Add(heroData.BattlePetId)
- tmpChangeList.Add(heroData.BattlePetId)
- }
- }
- pet.HeroId = heroId
- this.role.GetRoleHero().PetBattle(uint32(petId), heroId)
- this.SetDirty(true)
- this.dbChangePetList.Add(petId)
- tmpChangeList.Add(uint32(petId))
- }
- }
- if tmpChangeList.Size() > 0 {
- //不进行任何计算只做战力通知(AttrChangeST结构不做任何赋值)
- this.role.roleBattleAttr.AttrChange(AttrChangeST{})
- tmpList := tmpChangeList.List()
- var tmpPetList []*serverproto.PetData
- for idx := 0; idx < len(tmpList); idx++ {
- pet := this.getPet(tmpList[idx].(uint32))
- if pet == nil {
- continue
- }
- tmpPetList = append(tmpPetList, pet)
- }
- this.petChangeNtf(tmpPetList, nil, nil, false)
- this.OnRushPetScoreChange()
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Battle_Quality_cnt, 1)
- return serverproto.ErrorCode_ERROR_OK
- }
- return serverproto.ErrorCode_ERROR_FAIL
- }
- func (this *RolePet) PetAssist(petIdList []uint32) serverproto.ErrorCode {
- if len(petIdList) != Max_Assist_Num {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if len(this.assistList) <= 0 {
- for idx := 0; idx < Max_Assist_Num; idx++ {
- this.assistList = append(this.assistList, &serverproto.AssistIdxData{})
- }
- }
- bChange := false
- nowTime := util.GetTimeMilliseconds()
- hasList := set.New(set.NonThreadSafe)
- for idx := 0; idx < len(petIdList); idx++ {
- if petIdList[idx] == 0 {
- //下援助设置CD
- if this.assistList[idx].PetId > 0 {
- this.assistList[idx].PetId = 0
- this.assistList[idx].EndCdTime = nowTime + uint64(model.GlobalPetAssistCD*1000)
- this.SetDirty(true)
- bChange = true
- }
- continue
- }
- pet := this.getPet(petIdList[idx])
- if pet == nil {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- if hasList.Has(petIdList[idx]) {
- return serverproto.ErrorCode_ERROR_PET_ASSIST_REPEATED
- }
- if this.assistList[idx].EndCdTime < nowTime {
- //判断CD
- hasList.Add(petIdList[idx])
- this.assistList[idx].PetId = pet.Id
- this.SetDirty(true)
- bChange = true
- }
- }
- if bChange {
- this.petChangeNtf(nil, nil, nil, bChange)
- this.saveAssist()
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RolePet) saveAssist() {
- ssMsg := &serverproto.SSPetSetAssistNtf{}
- for idx := 0; idx < len(this.assistList); idx++ {
- pet := this.getPet(this.assistList[idx].PetId)
- if pet == nil {
- continue
- }
- ssMsg.AssistList = append(ssMsg.AssistList, &serverproto.AssistSaveData{
- PetId: pet.Id,
- PetCfgId: pet.ConfigId,
- AdvLevel: pet.AdvanceLevel,
- })
- }
- this.role.SendDb(ssMsg)
- }
- func (this *RolePet) PetBondAssistListGet(bondCfgId int32) bool {
- bFind := false
- for idx := 0; idx < len(model.ConvertBond); idx++ {
- if model.ConvertBond[idx].BondId == bondCfgId {
- ssMsg := &serverproto.SSPetBondAssistListReq{
- BondCfgId: bondCfgId,
- Condition1List: model.ConvertBond[idx].ConditionList1,
- Condition2List: model.ConvertBond[idx].ConditionList2,
- Condition3List: model.ConvertBond[idx].ConditionList3,
- }
- ssMsg.UidList = append(ssMsg.UidList, this.role.GetRoleSocial().GetFriendList()...)
- ssMsg.GuildId = uint64(this.role.GetRoleGuildId())
- if len(ssMsg.UidList) <= 0 && ssMsg.GuildId <= 0 {
- break
- }
- this.role.SendDb(ssMsg)
- bFind = true
- break
- }
- }
- if !bFind {
- return false
- }
- return true
- }
- func (this *RolePet) OnPetBondAssistListGet(msg *serverproto.SSPetBondAssistListAck) {
- this.tmpBondAssistList[msg.BondCfgId] = msg.AssistList
- //排除已经设置的对应玩家宠物ID(客户端显示时做处理)
- ackMsg := &serverproto.SCPetBondAssistListAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- BondPetList: msg.AssistList,
- BondCfgId: msg.BondCfgId,
- }
- this.role.ReplayGate(ackMsg, true)
- }
- func (this *RolePet) PetBondActive(bondData []*serverproto.PetBondData) serverproto.ErrorCode {
- //是否有重复宠物ID
- var multiplePetList = map[uint32][]uint64{} //[petId,uid]
- for k := 0; k < len(bondData); k++ {
- if len(bondData[k].BondList) > 3 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- for idx := 0; idx < len(bondData[k].BondList); idx++ {
- if bondData[k].BondList[idx].PetId == 0 {
- continue
- }
- if valList, ok := multiplePetList[bondData[k].BondList[idx].PetId]; ok {
- for i := 0; i < len(valList); i++ {
- if valList[i] == bondData[k].BondList[idx].OwnerUid {
- return serverproto.ErrorCode_ERROR_PET_ACTIVE_MULTI
- }
- }
- }
- multiplePetList[bondData[k].BondList[idx].PetId] = append(
- multiplePetList[bondData[k].BondList[idx].PetId], bondData[k].BondList[idx].OwnerUid)
- }
- }
- //未改变的羁绊列表中是否有重复的宠物id
- for _, val := range this.bondList {
- bFind := false
- for idx := 0; idx < len(bondData); idx++ {
- if bondData[idx].BondCfgId == val.BondCfgId {
- bFind = true
- break
- }
- }
- if !bFind {
- for idx := 0; idx < len(val.BondList); idx++ {
- if val.BondList[idx].PetId == 0 {
- continue
- }
- if valList, ok := multiplePetList[val.BondList[idx].PetId]; ok {
- for i := 0; i < len(valList); i++ {
- if valList[i] == val.BondList[idx].OwnerUid {
- return serverproto.ErrorCode_ERROR_PET_ACTIVE_MULTI
- }
- }
- }
- multiplePetList[val.BondList[idx].PetId] = append(
- multiplePetList[val.BondList[idx].PetId], val.BondList[idx].OwnerUid)
- }
- }
- }
- var uidNameList []*serverproto.KeyValueType64Str
- //判断设置的宠物ID是否合法
- for k := 0; k < len(bondData); k++ {
- ret := this.petBondActive(bondData[k], &uidNameList)
- if ret != serverproto.ErrorCode_ERROR_OK {
- return ret
- }
- }
- for k := 0; k < len(bondData); k++ {
- this.bondList[bondData[k].BondCfgId] = bondData[k]
- this.dbBondChangeList.Add(bondData[k].BondCfgId)
- }
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Id_Cnt, 1)
- this.SetDirty(true)
- ackMsg := &serverproto.SCPetBondActiveAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- BondDataList: bondData,
- UidNameList: uidNameList,
- }
- this.role.ReplayGate(ackMsg, true)
- //判断是否激活,增加属性,战斗力
- //this.checkBondCondition(this.dbBondChangeList.List())
- //attr
- this.onPetBondActiveAttr(bondData)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RolePet) GetBondPetCntByCfgId(cfgId int32) int32 {
- var cnt int32 = 0
- for _, data := range this.bondList {
- if len(data.BondList) <= 0 {
- continue
- }
- for _, pet := range data.BondList {
- if pet.PetCfgId != cfgId {
- continue
- }
- cnt++
- }
- }
- return cnt
- }
- func (this *RolePet) onPetBondActiveAttr(bondData []*serverproto.PetBondData) {
- //attr
- bResetAttr := false
- for k := 0; k < len(bondData); k++ {
- if len(bondData[k].BondList) < 3 {
- continue
- }
- bOk := true
- for idx := 0; idx < len(bondData[k].BondList); idx++ {
- if bondData[k].BondList[idx].PetCfgId <= 0 {
- bOk = false
- break
- }
- }
- if bOk {
- bResetAttr = true
- break
- }
- }
- if bResetAttr {
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- IsPet: true,
- ChangeType: Attr_Change_Pet_Bond,
- })
- }
- }
- func (this *RolePet) petBondActive(bondData *serverproto.PetBondData, uidNameList *[]*serverproto.KeyValueType64Str) serverproto.ErrorCode {
- for idx := 0; idx < len(bondData.BondList); idx++ {
- if bondData.BondList[idx].PetId <= 0 {
- bondData.BondList[idx].OwnerUid = 0
- bondData.BondList[idx].AdvanceLevel = 0
- continue
- }
- //当前宠物自己
- if bondData.BondList[idx].OwnerUid == 0 {
- petData := this.getPet(bondData.BondList[idx].PetId)
- if petData == nil {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- bondData.BondList[idx].AdvanceLevel = petData.AdvanceLevel
- bondData.BondList[idx].PetCfgId = petData.ConfigId
- } else {
- assistData, ok := this.tmpBondAssistList[bondData.BondCfgId]
- if !ok {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- bFind := false
- for i := 0; i < len(assistData); i++ {
- if assistData[i].OwnerUid != bondData.BondList[idx].OwnerUid {
- continue
- }
- for j := 0; j < len(assistData[i].PetInfoList); j++ {
- if assistData[i].PetInfoList[j].Id == bondData.BondList[idx].PetId &&
- assistData[i].PetInfoList[j].Param > 0 {
- *uidNameList = append(*uidNameList, &serverproto.KeyValueType64Str{
- Key: assistData[i].OwnerUid,
- StrVal: assistData[i].OwnerNickName,
- })
- bondData.BondList[idx].AdvanceLevel = assistData[i].PetInfoList[j].AdvanceLevel
- bondData.BondList[idx].PetCfgId = assistData[i].PetInfoList[j].ConfigId
- bFind = true
- break
- }
- }
- if bFind {
- break
- }
- }
- if !bFind {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- }
- }
- bondData.PetBondLevel = this.CheckBondLevel(bondData)
- return serverproto.ErrorCode_ERROR_OK
- }
- //刷新羁绊列表中玩家自身的宠物数据(分解,消耗造成的移除操作)
- func (this *RolePet) refreshPetBond(bNotify bool) bool {
- bChange := false
- ntfMsg := &serverproto.SCPetBondListNtf{}
- for _, bondData := range this.bondList {
- bFind := false
- for idx := 0; idx < len(bondData.BondList); idx++ {
- if bondData.BondList[idx].PetId <= 0 {
- bondData.BondList[idx].PetCfgId = 0
- bondData.BondList[idx].OwnerUid = 0
- bondData.BondList[idx].AdvanceLevel = 0
- continue
- } //当前宠物自己
- if bondData.BondList[idx].OwnerUid == 0 {
- petData := this.getPet(bondData.BondList[idx].PetId)
- if petData == nil {
- //宠物已经被移除(消耗,分解玩家操作)
- bondData.BondList[idx].PetId = 0
- bondData.BondList[idx].PetCfgId = 0
- bondData.BondList[idx].OwnerUid = 0
- bondData.BondList[idx].AdvanceLevel = 0
- this.SetDirty(true)
- this.dbBondChangeList.Add(bondData.BondCfgId)
- bFind = true
- } else {
- if petData.AdvanceLevel > bondData.BondList[idx].AdvanceLevel {
- bondData.BondList[idx].AdvanceLevel = petData.AdvanceLevel
- bFind = true
- this.SetDirty(true)
- this.dbBondChangeList.Add(bondData.BondCfgId)
- }
- }
- }
- }
- //bNotify=false表示load阶段
- if bFind || !bNotify {
- retBondLevel := this.CheckBondLevel(bondData)
- if bondData.PetBondLevel != retBondLevel {
- bondData.PetBondLevel = retBondLevel
- bChange = true
- this.SetDirty(true)
- }
- ntfMsg.BondList = append(ntfMsg.BondList, bondData)
- }
- }
- util.InfoF("uid=%v refreshPetBond bondList=%v", this.role.GetUUid(), this.bondList)
- if len(ntfMsg.BondList) > 0 && bNotify {
- this.role.ReplayGate(ntfMsg, true)
- }
- return bChange
- }
- func (this *RolePet) AddPet(petCfgId int32) (serverproto.ErrorCode, *serverproto.PetData) {
- petCfgData, ok := model.ConvertPet[petCfgId]
- if !ok {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND, nil
- }
- this.maxPetId++
- pet := &serverproto.PetData{
- Id: uint32(this.maxPetId),
- ConfigId: petCfgId,
- Level: 1,
- }
- for idx := 0; idx < len(petCfgData.SkillList); idx++ {
- petSkill := &serverproto.PetSkillData{
- ConfigId: petCfgData.SkillList[idx].SkillId,
- Level: 1,
- Rate: petCfgData.SkillList[idx].RateList[0],
- }
- pet.SkillList = append(pet.SkillList, petSkill)
- }
- this.petList[pet.Id] = pet
- this.dbChangePetList.Add(pet.Id)
- manualItem := this.addPetManual(uint32(petCfgId))
- util.InfoF("uid=%v AddPet petcfgid=%v", this.role.GetUUid(), petCfgId)
- this.SetDirty(true)
- if manualItem != nil {
- this.petChangeNtf([]*serverproto.PetData{pet}, nil, []*serverproto.PetManualST{manualItem}, false)
- } else {
- this.petChangeNtf([]*serverproto.PetData{pet}, nil, nil, false)
- }
- this.onAddPet(pet)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Id_Cnt, petCfgId)
- return serverproto.ErrorCode_ERROR_OK, pet
- }
- func (this *RolePet) onAddPet(petData *serverproto.PetData) {
- TaskMagCheck(this.role, serverproto.TaskType_Pet_Quality_Num, 0)
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- IsPet: true,
- ChangePetData: petData,
- ChangeType: Attr_Change_Pet_Base,
- FightChangeNotNotify: true,
- })
- }
- func (this *RolePet) addPetManual(petCfgId uint32) *serverproto.PetManualST {
- if petCfgId < 800 {
- return nil
- }
- petCfgId -= 800
- var manualItem *serverproto.PetManualST = nil
- manualItem, ok := this.petManualRewardList[int32(petCfgId)]
- if !ok {
- manualItem = &serverproto.PetManualST{
- PetCfgId: int32(petCfgId),
- }
- petData := this.getPet(petCfgId)
- if petData != nil {
- manualItem.AdvLevel = petData.AdvanceLevel
- }
- this.petManualRewardList[int32(petCfgId)] = manualItem
- this.SetDirty(true)
- return manualItem
- } else {
- petData := this.getPet(petCfgId)
- if petData != nil && manualItem.AdvLevel < petData.AdvanceLevel {
- this.SetDirty(true)
- return manualItem
- }
- }
- return nil
- }
- func (this *RolePet) getPet(petId uint32) *serverproto.PetData {
- if val, ok := this.petList[petId]; ok {
- return val
- }
- return nil
- }
- func (this *RolePet) delPet(petId uint32) {
- var ntfDataList []*serverproto.PetEquipData
- petData := this.getPet(petId)
- if petData == nil {
- delete(this.petList, petId)
- return
- }
- //宠物印记卸下
- for _, slotEquip := range petData.SlotEquipList {
- if slotEquip.EquipId > 0 {
- petEquipData := this.petEquipDown(slotEquip.EquipId)
- ntfDataList = append(ntfDataList, petEquipData)
- }
- }
- delete(this.petList, petId)
- if len(ntfDataList) > 0 {
- this.role.rolePet.petEquipChangeNtf(ntfDataList, false)
- }
- }
- func (this *RolePet) delPetList(petIdList []uint32) {
- var ntfDataList []*serverproto.PetEquipData
- for idx := 0; idx < len(petIdList); idx++ {
- petData := this.getPet(petIdList[idx])
- if petData == nil {
- continue
- }
- //宠物印记卸下
- for _, slotEquip := range petData.SlotEquipList {
- if slotEquip.EquipId > 0 {
- petEquipData := this.petEquipDown(slotEquip.EquipId)
- ntfDataList = append(ntfDataList, petEquipData)
- }
- }
- delete(this.petList, petIdList[idx])
- }
- if len(ntfDataList) > 0 {
- this.role.rolePet.petEquipChangeNtf(ntfDataList, false)
- }
- }
- func (this *RolePet) getLevelUpLimit(advanceLevel int) int32 {
- if advanceLevel > len(model.GlobalPetAdvanceLimit) || advanceLevel < 0 {
- return 0
- }
- return model.GlobalPetAdvanceLimit[advanceLevel]
- }
- func (this *RolePet) getLevelUpCost(quality int32, level int32) (serverproto.ErrorCode, int32, int32) {
- convertData, ok1 := model.ConvertPetExp[level]
- if !ok1 {
- return serverproto.ErrorCode_ERROR_PET_LEVEL_LIMIT, 0, 0
- }
- if quality == model.Pet_Type_Normal {
- return serverproto.ErrorCode_ERROR_OK, convertData.NormalZeny, convertData.NormalExp
- } else if quality == model.Pet_Type_Mini {
- return serverproto.ErrorCode_ERROR_OK, convertData.MiniZeny, convertData.MiniExp
- } else if quality == model.Pet_Type_MVP {
- return serverproto.ErrorCode_ERROR_OK, convertData.MvpZeny, convertData.MvpExp
- }
- return serverproto.ErrorCode_ERROR_PET_LEVEL_LIMIT, 0, 0
- }
- func (this *RolePet) levelUp(quality int32, levelUpLimit int32, pet *serverproto.PetData) bool {
- bRet := false
- if pet.Level >= levelUpLimit {
- return bRet
- }
- ret, needZeny, needExp := this.getLevelUpCost(quality, pet.Level)
- if ret != serverproto.ErrorCode_ERROR_OK {
- return bRet
- }
- //消耗异常
- if needZeny == 0 || needExp == 0 {
- return bRet
- }
- var delItemList = map[int32]int32{}
- delItemList[int32(serverproto.ResType_Res_Coin)] = needZeny
- delItemList[int32(serverproto.ResType_Res_PetExp)] = int32(needExp)
- if !this.role.GetRoleBag().CanDelItemList(delItemList) {
- return bRet
- }
- pet.Level++
- this.role.DelItemList(delItemList, AddItemST{AddFrom: AddFrom_Pet})
- this.SetDirty(true)
- bRet = true
- return bRet
- }
- func (this *RolePet) isBattle(pet *serverproto.PetData) bool {
- if pet.HeroId != 0 && this.role.GetRoleHero().IsPetBattle(pet.HeroId) == pet.Id {
- return true
- }
- return false
- }
- func (this *RolePet) getBond(bondCfgId int32) *serverproto.PetBondData {
- if data, ok := this.bondList[bondCfgId]; ok {
- return data
- }
- return nil
- }
- func (this *RolePet) isInAssist(petId uint32, del bool) bool {
- for idx := 0; idx < len(this.assistList); idx++ {
- if this.assistList[idx].PetId == petId {
- if del {
- nowTime := util.GetTimeMilliseconds()
- this.assistList[idx].PetId = 0
- this.assistList[idx].EndCdTime = nowTime + uint64(model.GlobalPetAssistCD*1000)
- this.SetDirty(true)
- }
- return true
- }
- }
- return false
- }
- //self
- func (this *RolePet) isInPetBondList(petId uint32, ownerUid uint64, del bool) bool {
- for _, val := range this.bondList {
- for idx := 0; idx < len(val.BondList); idx++ {
- //self
- if val.BondList[idx].PetId == petId && val.BondList[idx].OwnerUid == 0 {
- if del {
- val.BondList[idx].PetId = 0
- val.BondList[idx].OwnerUid = 0
- val.BondList[idx].PetCfgId = 0
- val.BondList[idx].AdvanceLevel = 0
- this.SetDirty(true)
- this.dbBondChangeList.Add(val.BondCfgId)
- }
- break
- }
- }
- }
- return false
- }
- func (this *RolePet) checkBondCondition(bondCfgId []interface{}) serverproto.ErrorCode {
- //for idx := 0; idx < len(bondCfgId); idx++ {
- // //cfgId := bondCfgId[idx].(int32)
- // this.role.GetRoleFightPower().CalcAndResetPetBondFightPower(bondCfgId[idx].(int32))
- //}
- //
- //this.role.GetRoleFightPower().AfterBondFightPowerChange()
- return serverproto.ErrorCode_ERROR_FAIL
- }
- ///Task
- func (this *RolePet) GetQualityPetNum(quality int32) int32 {
- var retNum int32 = 0
- if quality <= 0 {
- retNum = int32(len(this.petList))
- } else {
- for _, val := range this.petList {
- petCfgData, ok := model.ConvertPet[val.ConfigId]
- if !ok {
- continue
- }
- if petCfgData.Quality == quality {
- retNum++
- }
- }
- }
- return retNum
- }
- ///Task
- func (this *RolePet) GetPetNumByCfgId(cfgId int32) int32 {
- var retNum int32 = 0
- if cfgId <= 0 {
- return 0
- }
- for _, val := range this.petList {
- if val.ConfigId != cfgId {
- continue
- }
- retNum++
- }
- return retNum
- }
- func (this *RolePet) GetBondLevel(bond *serverproto.PetBondData) int32 {
- if bond == nil {
- return -1
- }
- var advanceLevel int32 = -1
- for _, data := range model.ConvertBond {
- if data.BondId == bond.BondCfgId {
- //条件1查看是否满足
- var count1 int32 = 0
- for _, petData := range data.ConditionList1 {
- for _, ownPet := range bond.BondList {
- if petData.Key == ownPet.PetCfgId {
- if ownPet.AdvanceLevel >= uint32(petData.Value) {
- count1++
- }
- break
- }
- }
- }
- if count1 >= int32(len(data.ConditionList1)) {
- advanceLevel = 0
- }
- var count2 int32 = 0
- for _, petData := range data.ConditionList2 {
- for _, ownPet := range bond.BondList {
- if petData.Key == ownPet.PetCfgId {
- if ownPet.AdvanceLevel >= uint32(petData.Value) {
- count2++
- }
- break
- }
- }
- }
- if count2 >= int32(len(data.ConditionList2)) {
- advanceLevel = 1
- }
- var count3 int32 = 0
- for _, petData := range data.ConditionList3 {
- for _, ownPet := range bond.BondList {
- if petData.Key == ownPet.PetCfgId {
- if ownPet.AdvanceLevel >= uint32(petData.Value) {
- count3++
- }
- break
- }
- }
- }
- if count3 >= int32(len(data.ConditionList3)) {
- advanceLevel = 2
- }
- break
- }
- }
- return advanceLevel
- }
- func (this *RolePet) CheckBondLevel(bond *serverproto.PetBondData) int32 {
- var advanceLevel int32 = 0
- if bond == nil {
- return advanceLevel
- }
- for _, data := range model.ConvertBond {
- if data.BondId == bond.BondCfgId {
- //条件1查看是否满足
- if this.checkBondLevel(bond, data.ConditionList1) {
- advanceLevel = 1
- }
- if this.checkBondLevel(bond, data.ConditionList2) {
- advanceLevel = 2
- }
- if this.checkBondLevel(bond, data.ConditionList3) {
- advanceLevel = 3
- }
- break
- }
- }
- return advanceLevel
- }
- func (this *RolePet) checkBondLevel(bond *serverproto.PetBondData, conditionList []*serverproto.KeyValueType) bool {
- if len(conditionList) > len(bond.BondList) || len(conditionList) <= 0 {
- return false
- }
- for _, petCfgData := range conditionList {
- bFind := false
- for _, bondPet := range bond.BondList {
- if petCfgData.Key == bondPet.PetCfgId {
- if bondPet.AdvanceLevel >= uint32(petCfgData.Value) {
- bFind = true
- }
- break
- }
- }
- if !bFind {
- return false
- }
- }
- return true
- }
- ///GM
- func (this *RolePet) GMClearPet() {
- var delPetList []uint32
- for _, item := range this.petList {
- delPetList = append(delPetList, item.Id)
- this.dbChangePetList.Add(item.Id)
- }
- this.petList = map[uint32]*serverproto.PetData{}
- this.SetDirty(true)
- this.petChangeNtf(nil, delPetList, nil, false)
- }
- func (this *RolePet) GMPetLevel(petId uint32, petLevel, petAdvLevel int32) {
- petData := this.getPet(petId)
- if petData != nil {
- petData.Level = petLevel
- advCfgData, ok := model.ConvertPetProgress[petData.ConfigId]
- if !ok {
- return
- }
- if petAdvLevel > int32(len(advCfgData.ProgressList)) {
- petAdvLevel = int32(len(advCfgData.ProgressList))
- }
- levelUpLimit := this.getLevelUpLimit(int(petAdvLevel))
- if petLevel >= levelUpLimit {
- petLevel = levelUpLimit
- }
- petData.Level = petLevel
- petData.AdvanceLevel = uint32(petAdvLevel)
- this.SetDirty(true)
- this.dbChangePetList.Add(petId)
- this.petChangeNtf([]*serverproto.PetData{petData}, nil, nil, false)
- }
- }
- func (this *RolePet) GMPetSkillLevel(petId uint32, skillCfgId, skillLevel int32) {
- petData := this.getPet(petId)
- if petData != nil {
- for idx := 0; idx < len(petData.SkillList); idx++ {
- if petData.SkillList[idx].ConfigId == skillCfgId {
- petCfgData, ok := model.ConvertPet[petData.ConfigId]
- if !ok {
- break
- }
- petData.SkillList[idx].Level = skillLevel
- petData.SkillList[idx].Rate = petCfgData.GetSkillRate(skillCfgId, skillLevel)
- this.SetDirty(true)
- this.dbChangePetList.Add(petId)
- this.petChangeNtf([]*serverproto.PetData{petData}, nil, nil, false)
- break
- }
- }
- }
- }
- func (this *RolePet) CheckNewPet(petCfgId int32) bool {
- if petCfgId < 800 {
- return false
- }
- tmpPetID := petCfgId - 800
- if _, ok := this.petManualRewardList[tmpPetID]; ok {
- return false
- }
- return true
- }
- //================================== 宠物冲榜功能 ==================================
- func (this *RolePet) OnlineGetRushPetBaseReward(rewardRound int32) {
- if this.rushPet == nil || rewardRound <= 0 {
- return
- }
- if this.rushPet.ScoreRewardFlag < rewardRound {
- var addItemList = map[int32]int32{}
- model.GetRushActivityBaseReward(this.rushPet.RushRound, model.Rush_Type_Pet, int32(this.rushPet.TotalScore), addItemList)
- if len(addItemList) > 0 {
- this.role.AddMail(model.GlobalMailRushPetBaseReward, serverproto.MailType_MailType_RushPet,
- addItemList, []int32{int32(this.rushPet.TotalScore)}, "", "")
- }
- this.rushPet.ScoreRewardFlag = rewardRound
- this.rushPet.TotalScore = 0
- this.SetDirty(true)
- } else {
- this.rushPet.TotalScore = 0
- this.SetDirty(true)
- }
- }
- func (this *RolePet) OnlineProcess() {
- if this.rushPet == nil {
- return
- }
- /*
- if this.rushPet.RushRound != 0 {
- if rankRound == 0 || (rankRound != 0 && rankRound != this.rushPet.RushRound) {
- if this.rushPet.ScoreRewardFlag == 0 { //参与了SSRushPetInfoChangeNtf
- var addItemList = map[int32]int32{}
- model.GetRushActivityBaseReward(this.rushPet.RushRound, model.Rush_Type_Pet, int32(this.rushPet.TotalScore), addItemList)
- if len(addItemList) > 0 {
- this.role.AddMail(model.GlobalMailRushPetBaseReward, serverproto.MailType_MailType_RushPet,
- addItemList, []int32{int32(this.rushPet.TotalScore)}, "", "")
- }
- }
- this.rushPet.RushRound = rankRound
- this.rushPet.TotalScore = 0
- this.rushPet.ScoreRewardFlag = 0
- this.SetDirty(true)
- }
- }
- */
- //上线处理下,有可能这个人没有参加过。
- this.OnRushPetScoreChange()
- // 上线请求下冲榜是否有历史奖励可以领取
- if this.rushPet != nil {
- if this.rushPet.RushRound != 0 && this.rushPet.RushRound > this.rushPet.ScoreRewardFlag {
- reqMsg := &serverproto.SSGetRushBaseRewardReq{}
- reqMsg.Uid = this.role.GetUUid()
- reqMsg.RushType = model.Rush_Type_Pet
- reqMsg.RushRound = this.rushPet.RushRound
- this.role.SendRank(reqMsg)
- }
- /*
- reqMsg := &serverproto.SSGetRushRankReq{
- Uid: this.role.GetUUid(),
- RushType: model.Rush_Type_Pet,
- RushRound: this.rushPet.RankReward,
- }
- this.role.SendRank(reqMsg)
- */
- }
- }
- //发送到rank服务器验证
- func (this *RolePet) OnRushPetScoreChange() {
- reqMsg := &serverproto.SSRushDataChangeReq{}
- reqMsg.Uid = this.role.GetUUid()
- reqMsg.RushType = model.Rush_Type_Pet
- this.role.SendRank(reqMsg)
- }
- func (this *RolePet) AddRushPetScore(curRound int32) {
- if this.rushPet == nil {
- this.rushPet = &serverproto.RushPet{}
- this.SetDirty(true)
- }
- if curRound == 0 {
- return
- }
- if curRound != this.rushPet.RushRound {
- this.rushPet.RushRound = curRound
- this.rushPet.TotalScore = 0
- }
- //发送到rank
- reqMsg := &serverproto.SSRushPetInfoChangeNtf{}
- if this.role.GetRoleHero() != nil {
- this.role.GetRoleHero().PackHeroRushPetInfo(reqMsg)
- }
- if 0 == reqMsg.TotalScore {
- return
- }
- if uint32(reqMsg.TotalScore) >= this.rushPet.TotalScore {
- this.rushPet.TotalScore = uint32(reqMsg.TotalScore)
- reqMsg.Uid = this.role.GetUUid()
- this.role.SendRank(reqMsg)
- }
- this.SetDirty(true)
- }
- func (this *RolePet) GetBaseScoreReward(ackMsg *serverproto.SCRushActivityRewardAck, rushRound int32) serverproto.ErrorCode {
- if ackMsg == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if this.rushPet == nil {
- this.rushPet = &serverproto.RushPet{}
- this.SetDirty(true)
- }
- if this.rushPet.ScoreRewardFlag >= rushRound {
- return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH
- }
- var addItemList = map[int32]int32{}
- model.GetRushActivityBaseReward(this.rushPet.RushRound, model.Rush_Type_Pet, int32(this.rushPet.TotalScore), addItemList)
- if len(addItemList) <= 0 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- for key, value := range addItemList {
- ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
- Key: key,
- Value: value,
- })
- }
- this.role.AddItemList(addItemList, AddFrom_RushPet, true)
- this.rushPet.ScoreRewardFlag = rushRound
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RolePet) GetRushPetRankReward(ssAck *serverproto.SSGetRushRewardAck) serverproto.ErrorCode {
- if ssAck == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if this.rushPet == nil {
- this.rushPet = &serverproto.RushPet{}
- this.SetDirty(true)
- }
- if this.rushPet.RankReward >= ssAck.RushRound {
- return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH
- }
- var addItemList = map[int32]int32{}
- for _, data := range ssAck.ItemList {
- addItemList[data.Key] += data.Value
- }
- this.role.AddItemList(addItemList, AddFrom_RushPet, true)
- this.rushPet.RankReward = ssAck.RushRound
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RolePet) GetRushPetInfo(ackMsg *serverproto.SCPetActivityAck, curRound int32) {
- if ackMsg == nil {
- return
- }
- if this.rushPet == nil {
- this.rushPet = &serverproto.RushPet{}
- this.SetDirty(true)
- }
- // ackMsg.SelfScore = this.rushPet.TotalScore
- ackMsg.RankReward = false
- if this.rushPet.RankReward == curRound {
- ackMsg.RankReward = true
- }
- ackMsg.ChallengReward = false
- if this.rushPet.ScoreRewardFlag >= curRound {
- ackMsg.ChallengReward = true
- }
- }
- func (this *RolePet) CheckRankReward(finishRound int32) serverproto.ErrorCode {
- if this.rushPet == nil {
- this.rushPet = &serverproto.RushPet{}
- this.SetDirty(true)
- }
- if this.rushPet.RankReward >= finishRound {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RolePet) SetRankReward(finishRound int32) {
- if this.rushPet == nil {
- this.rushPet = &serverproto.RushPet{}
- this.SetDirty(true)
- }
- this.rushPet.RankReward = finishRound
- this.SetDirty(true)
- }
- func (this *RolePet) GetFightCountMailReward(rushRound int32) {
- if this.rushPet == nil {
- this.rushPet = &serverproto.RushPet{}
- this.SetDirty(true)
- }
- if this.rushPet.ScoreRewardFlag < rushRound {
- var addItemList = map[int32]int32{}
- model.GetRushActivityBaseReward(this.rushPet.RushRound, model.Rush_Type_Pet, int32(this.rushPet.TotalScore), addItemList)
- if len(addItemList) > 0 {
- this.role.AddMail(model.GlobalMailRushPetBaseReward, serverproto.MailType_MailType_RushPet,
- addItemList, []int32{int32(this.rushPet.TotalScore)}, "", "")
- }
- this.rushPet.ScoreRewardFlag = rushRound
- this.rushPet.TotalScore = 0
- this.SetDirty(true)
- }
- }
- func (this *RolePet) GetPetJobType(petId uint32) int32 {
- petData := this.getPet(petId)
- if petData == nil {
- return -1
- }
- petCfgData, ok := model.ConvertPet[petData.ConfigId]
- if !ok {
- return -1
- }
- return petCfgData.JobType
- }
- func (this *RolePet) BattleAttrChange(petData *serverproto.PetData,
- attrType *serverproto.ActorAttrType, petFightPower uint64) {
- petData.BattleAttrList = attrType.AttrList
- oldPetFightPower := petData.PetFightPower
- petData.PetFightPower = uint32(petFightPower / 10)
- this.SetDirty(true)
- //db save
- this.dbChangePetList.Add(petData.Id)
- util.InfoF("uid=%v petId=%v oldPetFightPower=%v newCalFightPower=%v",
- this.role.GetUUid(), petData.Id, oldPetFightPower, petFightPower/10)
- //if petData.HeroId <= 0 {
- if oldPetFightPower != petData.PetFightPower {
- //通知单位战力变更
- ntfMsg := &serverproto.SCFightPowerChagneNtf{
- Data: &serverproto.FightPowerData{},
- }
- slotFightPower := &serverproto.SlotFightPower{
- HeroId: int32(petData.Id),
- PetFightPower: uint64(petData.PetFightPower),
- }
- ntfMsg.Data.ActorFightpower = append(ntfMsg.Data.ActorFightpower, slotFightPower)
- this.role.ReplayGate(ntfMsg, true)
- }
- //}
- }
- func (this *RolePet) petJuexingDataChangeNtf(heroData *serverproto.HeroData) {
- this.role.GetRoleHero().addHeroChange(heroData.Id)
- ntfMsg := &serverproto.SCPetQiyueDataNtf{
- HeroId: heroData.Id,
- QiyueInfo: heroData.PetQiyueData,
- }
- this.role.ReplayGate(ntfMsg, true)
- //觉醒导致属性变更处理
- changePetData := this.getPet(heroData.BattlePetId)
- if changePetData != nil && heroData.PetQiyueData != nil && len(heroData.PetQiyueData.QiyueSlotList) > 0 {
- this.role.roleBattleAttr.AttrChange(AttrChangeST{
- IsPet: true,
- ChangePetData: changePetData,
- ChangeType: Attr_Change_Pet_Qiyue,
- })
- }
- }
- func (this *RolePet) petQiyueUnlockCost(slotIdx int32) serverproto.KeyValueType {
- if slotIdx <= 0 {
- util.FatalF("uid=%v petQiyueUnlockCost slotIdx Failed slotIdx=%v", this.role.GetUUid(), slotIdx)
- return serverproto.KeyValueType{}
- }
- costLen := len(model.GlobalPetQiyueUnlockCost)
- if costLen >= int(slotIdx) {
- return model.GlobalPetQiyueUnlockCost[slotIdx-1]
- } else {
- costLen := len(model.GlobalPetQiyueUnlockCost)
- if costLen > 0 {
- return model.GlobalPetQiyueUnlockCost[costLen-1]
- }
- }
- util.FatalF("uid=%v petQiyueUnlockCost GlobalPetQiyueUnlockCost empty slotIdx=%v", this.role.GetUUid(), slotIdx)
- return serverproto.KeyValueType{}
- }
- func (this *RolePet) PetQiyueUnlock(heroId int32) serverproto.ErrorCode {
- heroData := this.role.GetRoleHero().GetHero(heroId)
- if heroData == nil {
- return serverproto.ErrorCode_ERROR_HERO_NO_FOUND
- }
- var unlockCost serverproto.KeyValueType
- if heroData.PetQiyueData == nil {
- //解锁第一个槽位
- //判断资源消耗
- unlockCost = this.petQiyueUnlockCost(1)
- if !this.role.GetRoleBag().CanDelItem(unlockCost.Key, unlockCost.Value) {
- return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_UNLOCK_RES
- }
- heroData.PetQiyueData = &serverproto.PetQiyueInfo{
- PetId: heroData.BattlePetId,
- }
- } else {
- //解锁槽位数量已达上限
- if len(heroData.PetQiyueData.QiyueSlotList) >= model.GlobalPetQiyueMaxSlotNum {
- return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_UNLOCK_NUM_LIMIT
- }
- //判断资源消耗
- unlockCost = this.petQiyueUnlockCost(int32(len(heroData.PetQiyueData.QiyueSlotList) + 1))
- if !this.role.GetRoleBag().CanDelItem(unlockCost.Key, unlockCost.Value) {
- return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_UNLOCK_RES
- }
- }
- this.role.GetRoleBag().DelItem(unlockCost.Key, unlockCost.Value, AddItemST{
- AddFrom: AddFrom_PetJuexing,
- Notify: true,
- })
- heroData.PetQiyueData.QiyueSlotList = append(heroData.PetQiyueData.QiyueSlotList,
- &serverproto.PetQiyueSlotInfo{
- SlotIdx: int32(len(heroData.PetQiyueData.QiyueSlotList) + 1),
- })
- this.SetDirty(true)
- this.petJuexingDataChangeNtf(heroData)
- util.InfoF("uid=%v PetQiyueUnlock heroid=%v slotIdx=%v", this.role.GetUUid(),
- heroId, len(heroData.PetQiyueData.QiyueSlotList)-1)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RolePet) getQiyueSlotInfoBySlot(heroData *serverproto.HeroData, slotIdx int32) *serverproto.PetQiyueSlotInfo {
- for idx := 0; idx < len(heroData.PetQiyueData.QiyueSlotList); idx++ {
- if heroData.PetQiyueData.QiyueSlotList[idx].SlotIdx == slotIdx {
- return heroData.PetQiyueData.QiyueSlotList[idx]
- }
- }
- return nil
- }
- func (this *RolePet) getQiyueSlotInfoByPetID(heroData *serverproto.HeroData, petId uint32) *serverproto.PetQiyueSlotInfo {
- for idx := 0; idx < len(heroData.PetQiyueData.QiyueSlotList); idx++ {
- if heroData.PetQiyueData.QiyueSlotList[idx].PetId == petId {
- return heroData.PetQiyueData.QiyueSlotList[idx]
- }
- }
- return nil
- }
- func (this *RolePet) PetQiyueSlotIn(heroId, slotIdx int32, petId uint32) serverproto.ErrorCode {
- heroData := this.role.GetRoleHero().GetHero(heroId)
- if heroData == nil {
- return serverproto.ErrorCode_ERROR_HERO_NO_FOUND
- }
- if heroData.PetQiyueData == nil {
- return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_INVALID
- }
- //判断槽位是否存在
- if len(heroData.PetQiyueData.QiyueSlotList) < int(slotIdx) {
- return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_INVALID
- }
- petData := this.getPet(petId)
- if petData == nil {
- return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
- }
- //出阵宠物无法放入觉醒槽位
- if petData.HeroId > 0 {
- return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_PET_INVALID
- }
- if petData.QiyueHeroId > 0 {
- //在同一个上阵宠物上
- if petData.QiyueHeroId == heroId {
- slotIdxInfo := this.getQiyueSlotInfoByPetID(heroData, petId)
- if slotIdxInfo != nil {
- //判断是否在同一个槽位
- if slotIdxInfo.SlotIdx == slotIdx {
- util.InfoF("uid=%v PetQiyueSlotIn slot put same pet")
- return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_PET_INVALID
- }
- slotIdxInfo.PetId = 0
- slotIdxInfo.PetCfgId = 0
- petData.QiyueHeroId = 0
- this.dbChangePetList.Add(petId)
- this.SetDirty(true)
- }
- } else {
- //先下阵
- oldHeroData := this.role.GetRoleHero().GetHero(petData.QiyueHeroId)
- if oldHeroData != nil {
- slotIdxInfo := this.getQiyueSlotInfoByPetID(oldHeroData, petId)
- if slotIdxInfo != nil {
- slotIdxInfo.PetId = 0
- slotIdxInfo.PetCfgId = 0
- this.SetDirty(true)
- util.InfoF("uid=%v PetQiyueSlotIn out old heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(),
- oldHeroData.Id, slotIdxInfo.SlotIdx, petId)
- this.petJuexingDataChangeNtf(oldHeroData)
- }
- }
- petData.QiyueHeroId = 0
- this.dbChangePetList.Add(petId)
- this.SetDirty(true)
- }
- }
- slotIdxInfo := this.getQiyueSlotInfoBySlot(heroData, slotIdx)
- if slotIdxInfo != nil {
- var changPetDataList []*serverproto.PetData
- //当前位置上已经有宠物,下阵
- if slotIdxInfo.PetId > 0 {
- slotPetData := this.getPet(slotIdxInfo.PetId)
- if slotPetData != nil {
- util.InfoF("uid=%v PetQiyueSlotIn out old heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(),
- heroData.Id, slotIdx, slotIdxInfo.PetId)
- slotPetData.QiyueHeroId = 0
- this.dbChangePetList.Add(slotIdxInfo.PetId)
- this.SetDirty(true)
- changPetDataList = append(changPetDataList, slotPetData)
- }
- }
- slotIdxInfo.PetId = petData.Id
- slotIdxInfo.PetCfgId = petData.ConfigId
- petData.QiyueHeroId = heroData.Id
- this.dbChangePetList.Add(petId)
- this.SetDirty(true)
- changPetDataList = append(changPetDataList, petData)
- util.InfoF("uid=%v PetQiyueSlotIn in heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(),
- heroData.Id, slotIdx, slotIdxInfo.PetId)
- this.petChangeNtf(changPetDataList, nil, nil, false)
- this.petJuexingDataChangeNtf(heroData)
- return serverproto.ErrorCode_ERROR_OK
- } else {
- return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_INVALID
- }
- }
- func (this *RolePet) PetQiyueSlotOut(heroId, slotIdx int32) serverproto.ErrorCode {
- heroData := this.role.GetRoleHero().GetHero(heroId)
- if heroData == nil {
- return serverproto.ErrorCode_ERROR_HERO_NO_FOUND
- }
- if heroData.PetQiyueData == nil {
- return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_INVALID
- }
- //操作具体的槽位
- if slotIdx > 0 {
- bFind := false
- for idx := 0; idx < len(heroData.PetQiyueData.QiyueSlotList); idx++ {
- if heroData.PetQiyueData.QiyueSlotList[idx].SlotIdx == slotIdx {
- if heroData.PetQiyueData.QiyueSlotList[idx].PetId <= 0 {
- break
- }
- tmpPetId := heroData.PetQiyueData.QiyueSlotList[idx].PetId
- heroData.PetQiyueData.QiyueSlotList[idx].PetId = 0
- heroData.PetQiyueData.QiyueSlotList[idx].PetCfgId = 0
- tmpPetData := this.getPet(tmpPetId)
- if tmpPetData != nil {
- util.InfoF("uid=%v PetQiyueSlotOut in heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(),
- heroId, slotIdx, tmpPetId)
- tmpPetData.QiyueHeroId = 0
- this.dbChangePetList.Add(tmpPetId)
- this.petChangeNtf([]*serverproto.PetData{tmpPetData}, nil, nil, false)
- }
- this.SetDirty(true)
- bFind = true
- util.InfoF("uid=%v PetQiyueSlotOut heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(), heroId, slotIdx, tmpPetId)
- break
- }
- }
- if !bFind {
- return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_INVALID
- }
- this.petJuexingDataChangeNtf(heroData)
- } else {
- //一键卸下做为觉醒材料的宠物
- var ntfPetDataList []*serverproto.PetData
- for idx := 0; idx < len(heroData.PetQiyueData.QiyueSlotList); idx++ {
- tmpPetId := heroData.PetQiyueData.QiyueSlotList[idx].PetId
- if tmpPetId <= 0 {
- continue
- }
- heroData.PetQiyueData.QiyueSlotList[idx].PetId = 0
- heroData.PetQiyueData.QiyueSlotList[idx].PetCfgId = 0
- tmpPetData := this.getPet(tmpPetId)
- if tmpPetData != nil {
- tmpPetData.QiyueHeroId = 0
- this.dbChangePetList.Add(tmpPetId)
- ntfPetDataList = append(ntfPetDataList, tmpPetData)
- }
- this.SetDirty(true)
- util.InfoF("uid=%v PetQiyueSlotOut heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(), heroId,
- heroData.PetQiyueData.QiyueSlotList[idx].SlotIdx, tmpPetId)
- }
- if len(ntfPetDataList) > 0 {
- this.petChangeNtf(ntfPetDataList, nil, nil, false)
- this.petJuexingDataChangeNtf(heroData)
- }
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- //当前宠物是否在宠物契约槽内
- func (this *RolePet) IsPetInQiyueSlot(petId uint32) (uint32, bool) {
- petData := this.getPet(petId)
- if petData != nil && petData.QiyueHeroId > 0 {
- if petData.HeroId > 0 {
- util.ErrorF("uid=%v IsPetInQiyueSlot pet in battle heroid=%v", petData.HeroId)
- return 0, false
- }
- heroData := this.role.GetRoleHero().GetHero(petData.QiyueHeroId)
- if heroData != nil {
- return heroData.BattlePetId, true
- }
- return 0, false
- }
- return 0, false
- }
- func (this *RolePet) PetQiyueBattlePetAttr() serverproto.ErrorCode {
- var attrTypeList []*serverproto.ActorAttrType
- var battlePetList []*serverproto.PetData
- this.role.GetRoleHero().GetBattlePetList(&battlePetList)
- for idx := 0; idx < len(battlePetList); idx++ {
- attrTypeList = append(attrTypeList,
- &serverproto.ActorAttrType{
- ActorId: battlePetList[idx].Id,
- })
- }
- this.role.roleBattleAttr.GetActorQiyueAttr(attrTypeList)
- ackMsg := &serverproto.SCPetQiyueBattlePetAttrAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- ActorList: attrTypeList,
- }
- this.role.ReplayGate(ackMsg, true)
- return serverproto.ErrorCode_ERROR_OK
- }
|