role_pet.go 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699
  1. package model
  2. import (
  3. "math/rand"
  4. "rocommon/util"
  5. "roserver/baseserver/model"
  6. "roserver/baseserver/set"
  7. "roserver/serverproto"
  8. )
  9. //宠物升级
  10. func (this *Role) PetLevelUp(petId uint32) {
  11. if this.rolePet != nil {
  12. ret := this.rolePet.LevelUp(petId)
  13. ackMsg := &serverproto.SCPetLevelUpAck{
  14. Error: int32(ret),
  15. PetId: petId,
  16. }
  17. this.ReplayGate(ackMsg, true)
  18. }
  19. }
  20. //宠物进阶
  21. func (this *Role) PetAdvance(petId uint32, petList []uint32) {
  22. if this.rolePet != nil {
  23. ret := this.rolePet.Advance(petId, petList)
  24. ackMsg := &serverproto.SCPetAdvanceAck{
  25. Error: int32(ret),
  26. }
  27. this.ReplayGate(ackMsg, true)
  28. }
  29. }
  30. //宠物图鉴奖励获取
  31. func (this *Role) PetManualReward(petCfgId, petId, advLevel int32) {
  32. if this.rolePet != nil {
  33. var rewardList []*serverproto.KeyValueType
  34. ret := this.rolePet.PetManualReward(petCfgId, petId, advLevel, &rewardList)
  35. ackMsg := &serverproto.SCPetManualRewardAck{
  36. Error: int32(ret),
  37. RewardList: rewardList,
  38. PetCfgId: petCfgId,
  39. }
  40. this.ReplayGate(ackMsg, true)
  41. }
  42. }
  43. //宠物技能升级(领悟)
  44. func (this *Role) PetSkillLevelUp(petId uint32, costPetId uint32) {
  45. if this.rolePet != nil {
  46. ret, skillCfgId := this.rolePet.PetSkillLevelUp(petId, costPetId)
  47. ackMsg := &serverproto.SCPetSkillLevelUpAck{
  48. Error: int32(ret),
  49. PetId: petId,
  50. SkillId: skillCfgId,
  51. }
  52. this.ReplayGate(ackMsg, true)
  53. }
  54. }
  55. //宠物分解
  56. func (this *Role) PetDecompose(petIdList []uint32) {
  57. if this.rolePet != nil {
  58. ackMsg := &serverproto.SCPetDecomposeAck{}
  59. ret := this.rolePet.PetDecompose(petIdList, ackMsg)
  60. ackMsg.Error = int32(ret)
  61. this.ReplayGate(ackMsg, true)
  62. }
  63. }
  64. //宠物上阵/下阵
  65. func (this *Role) PetBattle(battleList []*serverproto.KeyValueType) {
  66. if this.rolePet != nil {
  67. ret := this.rolePet.PetBattle(battleList)
  68. ackMsg := &serverproto.SCPetBattleAck{
  69. Error: int32(ret),
  70. }
  71. this.ReplayGate(ackMsg, true)
  72. }
  73. }
  74. //宠物援助设置
  75. func (this *Role) PetAssist(petIdList []uint32) {
  76. if this.rolePet != nil {
  77. ret := this.rolePet.PetAssist(petIdList)
  78. ackMsg := &serverproto.SCPetAssistAck{
  79. Error: int32(ret),
  80. AssistList: this.rolePet.assistList,
  81. }
  82. this.ReplayGate(ackMsg, true)
  83. }
  84. }
  85. //获取羁绊列表数据
  86. func (this *Role) PetBondListGet() {
  87. if this.rolePet != nil {
  88. ackMsg := &serverproto.SCPetBondListAck{}
  89. ret := this.rolePet.PetBondListGet(ackMsg)
  90. if ret == serverproto.ErrorCode_ERROR_OK {
  91. ackMsg.Error = int32(ret)
  92. this.ReplayGate(ackMsg, true)
  93. }
  94. }
  95. }
  96. //获取激活羁绊所需的宠物列表(援助列表)
  97. func (this *Role) PetBondAssistListGet(bondCfgId int32) {
  98. if this.rolePet != nil {
  99. ret := this.rolePet.PetBondAssistListGet(bondCfgId)
  100. if !ret {
  101. ackMsg := &serverproto.SCPetBondAssistListAck{
  102. Error: int32(serverproto.ErrorCode_ERROR_OK),
  103. BondCfgId: bondCfgId,
  104. }
  105. this.ReplayGate(ackMsg, true)
  106. }
  107. }
  108. }
  109. //宠物羁绊激活
  110. func (this *Role) PetBondActive(bondData []*serverproto.PetBondData) {
  111. if this.rolePet != nil {
  112. ret := this.rolePet.PetBondActive(bondData)
  113. if ret != serverproto.ErrorCode_ERROR_OK {
  114. ackMsg := &serverproto.SCPetBondActiveAck{
  115. Error: int32(ret),
  116. }
  117. this.ReplayGate(ackMsg, true)
  118. }
  119. }
  120. }
  121. //最早收集到宠物最高进阶等级获取
  122. func (this *Role) PetAdvAchievement(petCfgId int32) {
  123. if this.rolePet != nil {
  124. ssReqMsg := &serverproto.SSPetAdvAchievementReq{
  125. PetCfgId: petCfgId,
  126. }
  127. this.SendDb(ssReqMsg)
  128. }
  129. }
  130. //宠物系统优化
  131. //背包界面只下发必要数据,后续通过打开宠物界面主动获取
  132. func (this *Role) PetGetPetDetailInfo(petIdList []uint32) {
  133. if this.GetRolePet() != nil {
  134. ackMsg := &serverproto.SCPetDetailInfoAck{}
  135. //limit petIdList len
  136. if len(petIdList) <= 10 {
  137. for idx := 0; idx < len(petIdList); idx++ {
  138. petInfo := this.GetRolePet().getPet(petIdList[idx])
  139. if petInfo != nil {
  140. ackMsg.PetInfoList = append(ackMsg.PetInfoList, petInfo)
  141. }
  142. }
  143. }
  144. this.ReplayGate(ackMsg, true)
  145. }
  146. }
  147. ////宠物觉醒
  148. func (this *Role) PetQiyueUnlock(heroId int32) {
  149. if this.roleHero == nil || this.rolePet == nil {
  150. return
  151. }
  152. errCode := this.rolePet.PetQiyueUnlock(heroId)
  153. ackMsg := &serverproto.SCPetQiyueSlotUnlockAck{
  154. Error: int32(errCode),
  155. HeroId: heroId,
  156. }
  157. this.ReplayGate(ackMsg, true)
  158. }
  159. func (this *Role) PetQiyueSlotIn(heroId, slotIdx int32, petId uint32) {
  160. if this.roleHero == nil || this.rolePet == nil {
  161. return
  162. }
  163. errCode := this.rolePet.PetQiyueSlotIn(heroId, slotIdx, petId)
  164. ackMsg := &serverproto.SCPetQiyueSlotInAck{
  165. Error: int32(errCode),
  166. HeroId: heroId,
  167. SlotIdx: slotIdx,
  168. }
  169. this.ReplayGate(ackMsg, true)
  170. }
  171. func (this *Role) PetQiyueSlotOut(heroId, slotIdx int32) {
  172. if this.roleHero == nil || this.rolePet == nil {
  173. return
  174. }
  175. errCode := this.rolePet.PetQiyueSlotOut(heroId, slotIdx)
  176. ackMsg := &serverproto.SCPetQiyueSlotOutAck{
  177. Error: int32(errCode),
  178. HeroId: heroId,
  179. SlotIdx: slotIdx,
  180. }
  181. this.ReplayGate(ackMsg, true)
  182. }
  183. func (this *Role) PetQiyueBattlePetAttr() {
  184. if this.roleHero == nil || this.rolePet == nil {
  185. return
  186. }
  187. errCode := this.rolePet.PetQiyueBattlePetAttr()
  188. if errCode != serverproto.ErrorCode_ERROR_OK {
  189. ackMsg := &serverproto.SCPetQiyueBattlePetAttrAck{
  190. Error: int32(errCode),
  191. }
  192. this.ReplayGate(ackMsg, true)
  193. }
  194. }
  195. const Max_Assist_Num = 6
  196. type RolePet struct {
  197. SaveObject
  198. maxPetId int32
  199. //petManualList []*serverproto.KeyValueType //宠物图鉴
  200. petManualRewardList map[int32]*serverproto.PetManualST //宠物图鉴
  201. petList map[uint32]*serverproto.PetData //宠物列表
  202. bondList map[int32]*serverproto.PetBondData //羁绊(只填充固定字段数据)
  203. assistList []*serverproto.AssistIdxData //援助宠物列表
  204. petEquipList map[uint32]*serverproto.PetEquipData //宠物印记
  205. dbChangePetList set.Interface
  206. dbBondChangeList set.Interface
  207. dbChangePetEquipList set.Interface
  208. refreshBondListTime uint64 //刷新羁绊列表数据
  209. queryAssistList map[uint64]*serverproto.AssistData // 其他已经放置
  210. tmpBondAssistList map[int32][]*serverproto.AssistData //获取其他玩家援助列表(好友,公会)暂存信息
  211. rushPet *serverproto.RushPet
  212. }
  213. func newRolePet(r *Role) *RolePet {
  214. pet := &RolePet{
  215. SaveObject: SaveObject{
  216. role: r,
  217. },
  218. }
  219. pet.petList = map[uint32]*serverproto.PetData{}
  220. pet.bondList = map[int32]*serverproto.PetBondData{}
  221. pet.dbChangePetList = set.New(set.NonThreadSafe)
  222. pet.dbBondChangeList = set.New(set.NonThreadSafe)
  223. pet.dbChangePetEquipList = set.New(set.NonThreadSafe)
  224. pet.queryAssistList = map[uint64]*serverproto.AssistData{}
  225. pet.tmpBondAssistList = map[int32][]*serverproto.AssistData{}
  226. pet.petManualRewardList = map[int32]*serverproto.PetManualST{}
  227. pet.petEquipList = map[uint32]*serverproto.PetEquipData{}
  228. return pet
  229. }
  230. func (this *RolePet) Load(msg interface{}) bool {
  231. return true
  232. }
  233. //收到多个,数据量大时
  234. func (this *RolePet) LoadOther(msg interface{}) bool {
  235. petInfoMsg := msg.(*serverproto.SSLoadPetNtf)
  236. petInfo := petInfoMsg.Pet
  237. if petInfo == nil {
  238. return true
  239. }
  240. if petInfo.MaxPetId != 0 {
  241. this.maxPetId = petInfo.MaxPetId
  242. }
  243. for idx := 0; idx < len(petInfo.PetList); idx++ {
  244. this.petList[petInfo.PetList[idx].Id] = petInfo.PetList[idx]
  245. if len(this.petManualRewardList) > 0 {
  246. if val, ok := this.petManualRewardList[petInfo.PetList[idx].ConfigId-800]; ok {
  247. if val.AdvLevel < petInfo.PetList[idx].AdvanceLevel {
  248. val.AdvLevel = petInfo.PetList[idx].AdvanceLevel
  249. }
  250. }
  251. }
  252. }
  253. for idx := 0; idx < len(petInfo.BondList); idx++ {
  254. this.bondList[petInfo.BondList[idx].BondCfgId] = petInfo.BondList[idx]
  255. }
  256. if petInfo.AssistList != nil {
  257. this.assistList = petInfo.AssistList
  258. }
  259. for idx := 0; idx < len(petInfo.PetManualRewardList); idx++ {
  260. this.petManualRewardList[petInfo.PetManualRewardList[idx].PetCfgId] = petInfo.PetManualRewardList[idx]
  261. }
  262. //新老数据转换
  263. if petInfo.PetManualList != nil {
  264. for idx := 0; idx < len(petInfo.PetManualList); idx++ {
  265. if item, ok := this.petManualRewardList[petInfo.PetManualList[idx].Key]; ok {
  266. item.RewardState = petInfo.PetManualList[idx].Value
  267. for k := 0; k < 10; k++ {
  268. if petInfo.PetManualList[idx].Value&(1<<uint32(k)) > 0 {
  269. if item.AdvLevel < uint32(k) {
  270. item.AdvLevel = uint32(k)
  271. }
  272. }
  273. }
  274. for _, v := range this.petList {
  275. if v.ConfigId-800 == petInfo.PetManualList[idx].Key {
  276. if v.AdvanceLevel > item.AdvLevel {
  277. item.AdvLevel = v.AdvanceLevel
  278. }
  279. break
  280. }
  281. }
  282. } else {
  283. item := &serverproto.PetManualST{
  284. PetCfgId: petInfo.PetManualList[idx].Key,
  285. RewardState: petInfo.PetManualList[idx].Value,
  286. }
  287. for k := 0; k < 10; k++ {
  288. if petInfo.PetManualList[idx].Value&(1<<uint32(k)) > 0 {
  289. if item.AdvLevel < uint32(k) {
  290. item.AdvLevel = uint32(k)
  291. }
  292. }
  293. }
  294. for _, v := range this.petList {
  295. if v.ConfigId-800 == petInfo.PetManualList[idx].Key {
  296. if v.AdvanceLevel > item.AdvLevel {
  297. item.AdvLevel = v.AdvanceLevel
  298. }
  299. break
  300. }
  301. }
  302. this.petManualRewardList[item.PetCfgId] = item
  303. }
  304. }
  305. petInfo.PetManualList = nil
  306. this.SetDirty(true)
  307. }
  308. if petInfo.RushPet != nil {
  309. this.rushPet = petInfo.RushPet
  310. }
  311. //宠物印记
  312. for idx := 0; idx < len(petInfo.PetEquipList); idx++ {
  313. this.petEquipList[petInfo.PetEquipList[idx].Id] = petInfo.PetEquipList[idx]
  314. }
  315. if len(this.assistList) <= 0 {
  316. for idx := 0; idx < Max_Assist_Num; idx++ {
  317. this.assistList = append(this.assistList, &serverproto.AssistIdxData{})
  318. }
  319. }
  320. //有多个通知协议导致,宠物没有接受完成就进行判断
  321. if petInfoMsg.LoadEnd {
  322. this.refreshPetBond(false)
  323. }
  324. return true
  325. }
  326. func (this *RolePet) Save() {
  327. this.SetDirty(false)
  328. util.DebugF("uid=%v RolePet save...", this.role.GetUUid())
  329. saveMsg := &serverproto.SSPetDataSaveReq{
  330. RolePet: &serverproto.RolePet{},
  331. }
  332. saveMsg.RolePet.MaxPetId = this.maxPetId
  333. saveMsg.RolePet.AssistList = this.assistList
  334. for _, v := range this.petManualRewardList {
  335. saveMsg.RolePet.PetManualRewardList = append(saveMsg.RolePet.PetManualRewardList, v)
  336. }
  337. //pet
  338. changList := this.dbChangePetList.List()
  339. for idx := 0; idx < len(changList); idx++ {
  340. petId := changList[idx].(uint32)
  341. pet := this.getPet(petId)
  342. if pet == nil {
  343. saveMsg.PetDelList = append(saveMsg.PetDelList, petId)
  344. } else {
  345. saveMsg.RolePet.PetList = append(saveMsg.RolePet.PetList, pet)
  346. }
  347. }
  348. this.dbChangePetList.Clear()
  349. //羁绊数据
  350. bondChangList := this.dbBondChangeList.List()
  351. for idx := 0; idx < len(bondChangList); idx++ {
  352. bondCfgId := bondChangList[idx].(int32)
  353. bond := this.getBond(bondCfgId)
  354. if bond == nil {
  355. saveMsg.BondDelList = append(saveMsg.BondDelList, bondCfgId)
  356. } else {
  357. saveMsg.RolePet.BondList = append(saveMsg.RolePet.BondList, bond)
  358. }
  359. }
  360. this.dbBondChangeList.Clear()
  361. saveMsg.RolePet.RushPet = this.rushPet
  362. //宠物印记数据
  363. for _, val := range this.petEquipList {
  364. saveMsg.RolePet.PetEquipList = append(saveMsg.RolePet.PetEquipList, val)
  365. }
  366. this.dbChangePetEquipList.Clear()
  367. this.role.SendDb(saveMsg)
  368. }
  369. func (this *RolePet) StartupNtf() {
  370. petNtf := &serverproto.SCStartupInfoPetNtf{
  371. RolePetInfo: &serverproto.RolePet{},
  372. }
  373. for _, v := range this.petManualRewardList {
  374. petNtf.RolePetInfo.PetManualRewardList = append(petNtf.RolePetInfo.PetManualRewardList, v)
  375. }
  376. petNtf.RolePetInfo.AssistList = this.assistList
  377. petNtf.RolePetInfo.MaxPetId = this.maxPetId
  378. for _, val := range this.bondList {
  379. petNtf.RolePetInfo.BondList = append(petNtf.RolePetInfo.BondList, val)
  380. }
  381. for _, val := range this.petEquipList {
  382. petNtf.RolePetInfo.PetEquipList = append(petNtf.RolePetInfo.PetEquipList, val)
  383. }
  384. tmpCount := 0
  385. //数据量大不能直接发送全部
  386. for _, val := range this.petList {
  387. //petNtf.RolePetInfo.PetList = append(petNtf.RolePetInfo.PetList, val)
  388. tmpPetInfo := &serverproto.PetData{
  389. Id: val.Id,
  390. Level: val.Level,
  391. ConfigId: val.ConfigId,
  392. AdvanceLevel: val.AdvanceLevel,
  393. HeroId: val.HeroId,
  394. Param: val.Param,
  395. PetFightPower: val.PetFightPower,
  396. SkillList: val.SkillList,
  397. QiyueHeroId: val.QiyueHeroId,
  398. }
  399. petNtf.RolePetInfo.PetList = append(petNtf.RolePetInfo.PetList, tmpPetInfo)
  400. tmpCount++
  401. if tmpCount >= 50 {
  402. util.DebugF("uid=%v StartupProto petlen=%v ", this.role.GetUUid(), tmpCount)
  403. this.role.ReplayGate(petNtf, true)
  404. petNtf = &serverproto.SCStartupInfoPetNtf{
  405. RolePetInfo: &serverproto.RolePet{},
  406. }
  407. tmpCount = 0
  408. }
  409. }
  410. if tmpCount >= 0 {
  411. sendLen := this.role.ReplayGate(petNtf, true)
  412. util.DebugF("uid=%v StartupProto ntfMsgLen=%v petlen=%v totalNum=%v", this.role.GetUUid(), sendLen, tmpCount, len(this.petList))
  413. }
  414. }
  415. func (this *RolePet) GetPetePileTotalNum() int {
  416. return len(this.petList)
  417. }
  418. func (this *RolePet) petChangeNtf(petData []*serverproto.PetData, delPetList []uint32, manualList []*serverproto.PetManualST, bAssist bool) {
  419. ntfMsg := &serverproto.SCPetChangeNtf{}
  420. if petData != nil {
  421. ntfMsg.PetList = append(ntfMsg.PetList, petData...)
  422. }
  423. if len(delPetList) > 0 {
  424. ntfMsg.DelPetList = delPetList
  425. }
  426. if len(manualList) > 0 {
  427. ntfMsg.PetManualList = manualList
  428. }
  429. if bAssist {
  430. ntfMsg.AssistPetList = this.assistList
  431. }
  432. this.role.ReplayGate(ntfMsg, true)
  433. }
  434. func (this *RolePet) LevelUp(petId uint32) serverproto.ErrorCode {
  435. pet := this.getPet(petId)
  436. if pet == nil {
  437. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  438. }
  439. petCfgData, ok := model.ConvertPet[pet.ConfigId]
  440. if !ok {
  441. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  442. }
  443. //获取等级上限
  444. levelUpLimit := this.getLevelUpLimit(int(pet.AdvanceLevel))
  445. if pet.Level >= levelUpLimit {
  446. return serverproto.ErrorCode_ERROR_PET_LEVEL_LIMIT
  447. }
  448. //升级消耗(经验,zeny)
  449. if this.levelUp(petCfgData.Quality, levelUpLimit, pet) {
  450. this.petChangeNtf([]*serverproto.PetData{pet}, nil, nil, false)
  451. //db save
  452. this.dbChangePetList.Add(petId)
  453. bFightChangeNotNotify := true
  454. if this.isBattle(pet) || pet.QiyueHeroId > 0 {
  455. //this.role.GetRoleFightPower().OnBattlePetChanged(pet.HeroId, true)
  456. this.OnRushPetScoreChange()
  457. bFightChangeNotNotify = false
  458. }
  459. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  460. IsPet: true,
  461. ChangePetData: pet,
  462. ChangeType: Attr_Change_Pet_Base,
  463. FightChangeNotNotify: bFightChangeNotNotify,
  464. })
  465. return serverproto.ErrorCode_ERROR_OK
  466. }
  467. return serverproto.ErrorCode_ERROR_PET_MONEY_ENOUGH
  468. }
  469. func (this *RolePet) Advance(petId uint32, petList []uint32) serverproto.ErrorCode {
  470. pet := this.getPet(petId)
  471. if pet == nil {
  472. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  473. }
  474. _, ok := model.ConvertPet[pet.ConfigId]
  475. if !ok {
  476. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  477. }
  478. advCfgData, ok := model.ConvertPetProgress[pet.ConfigId]
  479. if !ok {
  480. return serverproto.ErrorCode_ERROR_PET_ADVANCE_DATA_NOT_FOUND
  481. }
  482. if pet.AdvanceLevel >= uint32(len(advCfgData.ProgressList)) {
  483. return serverproto.ErrorCode_ERROR_PET_ADVANCE_LIMIT
  484. }
  485. //pet.AdvanceLevel -> pet.AdvanceLevel+1
  486. var costZeny int32 = 0
  487. vipPetAdvance := this.role.GetRoleBase().GetVipData(model.Vip_System_PetAdvance)
  488. if vipPetAdvance <= 0 {
  489. costZeny = advCfgData.ProgressList[pet.AdvanceLevel].CostZeny
  490. if this.role.GetMoney() < uint64(costZeny) {
  491. return serverproto.ErrorCode_ERROR_PET_MONEY_ENOUGH
  492. }
  493. }
  494. bAssistChange := false
  495. condition1Set := set.New(set.NonThreadSafe)
  496. condition2Set := set.New(set.NonThreadSafe)
  497. for idx := 0; idx < len(petList); idx++ {
  498. if petList[idx] == petId {
  499. continue
  500. }
  501. tmpPet := this.getPet(petList[idx])
  502. //上阵/契约宠物无法作为进阶材料
  503. if tmpPet == nil || this.isBattle(tmpPet) || tmpPet.QiyueHeroId > 0 {
  504. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  505. }
  506. tmpPetCfgData, ok := model.ConvertPet[tmpPet.ConfigId]
  507. if !ok {
  508. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  509. }
  510. if this.isInAssist(tmpPet.Id, true) {
  511. bAssistChange = true
  512. }
  513. //ConditionPet1
  514. bNum := 0
  515. conditionList := advCfgData.ProgressList[pet.AdvanceLevel].ConditionPet1
  516. for k := 0; k < len(conditionList); k++ {
  517. switch (serverproto.EPetAssistType)(conditionList[k].Key) {
  518. case serverproto.EPetAssistType_EPetAssistType_Quality:
  519. if tmpPetCfgData.Quality >= conditionList[k].Value {
  520. bNum++
  521. }
  522. case serverproto.EPetAssistType_EPetAssistType_AdvLevel:
  523. if tmpPet.AdvanceLevel >= uint32(conditionList[k].Value) {
  524. bNum++
  525. }
  526. case serverproto.EPetAssistType_EPetAssistType_Nature:
  527. if tmpPetCfgData.NatureType == conditionList[k].Value {
  528. bNum++
  529. //return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
  530. }
  531. default:
  532. return serverproto.ErrorCode_ERROR_FAIL
  533. }
  534. }
  535. if bNum == len(conditionList) {
  536. //列表中有相同宠物ID
  537. if condition1Set.Has(petList[idx]) {
  538. return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
  539. }
  540. condition1Set.Add(petList[idx])
  541. }
  542. //ConditionPet2
  543. bNum = 0
  544. conditionList = advCfgData.ProgressList[pet.AdvanceLevel].ConditionPet2
  545. for k := 0; k < len(conditionList); k++ {
  546. switch (serverproto.EPetAssistType)(conditionList[k].Key) {
  547. case serverproto.EPetAssistType_EPetAssistType_Quality:
  548. if tmpPetCfgData.Quality >= conditionList[k].Value {
  549. bNum++
  550. }
  551. case serverproto.EPetAssistType_EPetAssistType_AdvLevel:
  552. if tmpPet.AdvanceLevel >= uint32(conditionList[k].Value) {
  553. bNum++
  554. }
  555. case serverproto.EPetAssistType_EPetAssistType_Nature:
  556. if tmpPetCfgData.NatureType == conditionList[k].Value {
  557. bNum++
  558. //return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
  559. }
  560. default:
  561. return serverproto.ErrorCode_ERROR_FAIL
  562. }
  563. }
  564. if bNum == len(conditionList) {
  565. //列表中有相同宠物ID
  566. if condition2Set.Has(petList[idx]) {
  567. return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
  568. }
  569. condition2Set.Add(petList[idx])
  570. }
  571. }
  572. conditionNum := 0
  573. if len(advCfgData.ProgressList[pet.AdvanceLevel].ConditionPet1) > 0 {
  574. conditionNum++
  575. if condition1Set.Size() <= 0 {
  576. return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
  577. }
  578. }
  579. if len(advCfgData.ProgressList[pet.AdvanceLevel].ConditionPet2) > 0 {
  580. conditionNum++
  581. if condition2Set.Size() <= 0 {
  582. return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
  583. }
  584. }
  585. //条件个数和宠物个数不匹配
  586. for _, data := range condition2Set.List() {
  587. condition1Set.Add(data.(uint32))
  588. }
  589. if condition1Set.Size() < conditionNum || len(petList) < conditionNum {
  590. return serverproto.ErrorCode_ERROR_PET_ADVANCE_TYPE
  591. }
  592. //消耗资源
  593. this.role.DelItem(int32(serverproto.ResType_Res_Coin), costZeny, AddItemST{AddFrom: AddFrom_Pet})
  594. pet.AdvanceLevel++
  595. this.delPetList(petList)
  596. for idx := 0; idx < len(petList); idx++ {
  597. this.dbChangePetList.Add(petList[idx])
  598. }
  599. this.dbChangePetList.Add(petId)
  600. if !bAssistChange && this.isInAssist(petId, false) {
  601. bAssistChange = true
  602. }
  603. //宠物图鉴
  604. manualItem, ok := this.petManualRewardList[pet.ConfigId-800]
  605. if !ok {
  606. manualItem := &serverproto.PetManualST{
  607. PetCfgId: pet.ConfigId - 800,
  608. AdvLevel: pet.AdvanceLevel,
  609. }
  610. this.petManualRewardList[manualItem.PetCfgId] = manualItem
  611. } else {
  612. manualItem.AdvLevel = pet.AdvanceLevel
  613. }
  614. this.petChangeNtf([]*serverproto.PetData{pet}, petList, []*serverproto.PetManualST{manualItem}, bAssistChange)
  615. this.SetDirty(true)
  616. if bAssistChange {
  617. this.saveAssist()
  618. }
  619. //最早收集到宠物最高进阶等级获取
  620. if pet.AdvanceLevel == uint32(len(advCfgData.ProgressList)) {
  621. ssMsg := &serverproto.SSPetAdvAchievementSetNtf{
  622. PetCfgId: pet.ConfigId,
  623. AdvLevel: int32(pet.AdvanceLevel),
  624. }
  625. this.role.SendDb(ssMsg)
  626. }
  627. //attr
  628. bFightChangeNotNotify := true
  629. if this.isBattle(pet) || pet.QiyueHeroId > 0 {
  630. //this.role.GetRoleFightPower().OnBattlePetChanged(pet.HeroId, true)
  631. this.OnRushPetScoreChange()
  632. bFightChangeNotNotify = false
  633. }
  634. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  635. IsPet: true,
  636. ChangePetData: pet,
  637. ChangeType: Attr_Change_Pet_Base,
  638. FightChangeNotNotify: bFightChangeNotNotify,
  639. })
  640. //刷新羁绊列表中玩家自身的宠物数据(分解,消耗造成的移除操作)
  641. if this.refreshPetBond(true) {
  642. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  643. IsPet: true,
  644. ChangeType: Attr_Change_Pet_Bond,
  645. FightChangeNotNotify: bFightChangeNotNotify,
  646. })
  647. }
  648. util.InfoF("uid=%v PetAdvance petid=%v advlevel=%v", this.role.GetUUid(), pet.Id, pet.AdvanceLevel)
  649. return serverproto.ErrorCode_ERROR_OK
  650. }
  651. func (this *RolePet) PetManualReward(petCfgId, petId, petAdvLevel int32, rewardList *[]*serverproto.KeyValueType) serverproto.ErrorCode {
  652. if petCfgId < 800 || petAdvLevel < 0 {
  653. return serverproto.ErrorCode_ERROR_FAIL
  654. }
  655. tmpPetCfgId := petCfgId - 800
  656. manualItem, ok := this.petManualRewardList[tmpPetCfgId]
  657. if !ok {
  658. return serverproto.ErrorCode_ERROR_PET_MANUAL_NOT_FOUND
  659. }
  660. petCfgData, ok := model.ConvertPet[petCfgId]
  661. if !ok {
  662. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  663. }
  664. if manualItem.AdvLevel < uint32(petAdvLevel) {
  665. return serverproto.ErrorCode_ERROR_PET_MANUAL_NOT_FOUND
  666. }
  667. //进阶奖励是否存在
  668. advReward, ok := petCfgData.ManualRewardList[petAdvLevel]
  669. if !ok {
  670. return serverproto.ErrorCode_ERROR_PET_MANUAL_NOT_FOUND
  671. }
  672. if manualItem.RewardState&(1<<uint32(petAdvLevel)) > 0 {
  673. return serverproto.ErrorCode_ERROR_PET_MANUAL_REWARD
  674. }
  675. addItemList := map[int32]int32{}
  676. addItemList[advReward.Key] = advReward.Value
  677. ret := this.role.CanAddItemList(addItemList)
  678. if ret == serverproto.ErrorCode_ERROR_OK {
  679. manualItem.RewardState |= 1 << uint32(petAdvLevel)
  680. this.SetDirty(true)
  681. this.role.AddItemList(addItemList, AddFrom_Pet, true)
  682. *rewardList = append(*rewardList, advReward)
  683. this.petChangeNtf(nil, nil, []*serverproto.PetManualST{manualItem}, false)
  684. util.InfoF("uid=%v PetManualReward reward=%v", this.role.GetUUid(), rewardList)
  685. }
  686. return ret
  687. }
  688. func (this *RolePet) PetSkillLevelUp(petId uint32, costPetId uint32) (serverproto.ErrorCode, int32) {
  689. pet := this.getPet(petId)
  690. costPet := this.getPet(costPetId)
  691. if pet == nil || costPet == nil || petId == costPetId || this.isBattle(costPet) || costPet.QiyueHeroId > 0 {
  692. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND, 0
  693. }
  694. petCfgData, ok := model.ConvertPet[pet.ConfigId]
  695. if !ok {
  696. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND, 0
  697. }
  698. if len(pet.SkillList) <= 0 {
  699. util.InfoF("uid=%v PetSkillLevelUp pet skill empty", this.role.GetUUid())
  700. return serverproto.ErrorCode_ERROR_FAIL, 0
  701. }
  702. if this.role.GetMoney() < uint64(model.GlobalPetSkillUpConsume) {
  703. return serverproto.ErrorCode_ERROR_MONEY_NOT_ENOUGH, 0
  704. }
  705. //材料检查
  706. if pet.ConfigId == costPet.ConfigId || costPet.ConfigId == model.GlobalPetSkillUpCost {
  707. var randSkillIdList []int
  708. for idx := 0; idx < len(pet.SkillList); idx++ {
  709. petSkill := pet.SkillList[idx]
  710. bFind := false
  711. for k := 0; k < len(petCfgData.SkillList); k++ {
  712. if petSkill.ConfigId == petCfgData.SkillList[k].SkillId {
  713. bFind = true
  714. if petSkill.Level >= petCfgData.SkillList[k].MaxSkillLevel {
  715. bFind = false
  716. }
  717. }
  718. }
  719. if bFind {
  720. randSkillIdList = append(randSkillIdList, idx)
  721. }
  722. }
  723. skillLen := len(randSkillIdList)
  724. if skillLen <= 0 {
  725. return serverproto.ErrorCode_ERROR_PET_SKILLUP_NONE, 0
  726. }
  727. randNum := rand.Int31n(int32(skillLen))
  728. randSkill := pet.SkillList[randSkillIdList[randNum]]
  729. randSkill.Level++
  730. randSkill.Rate = petCfgData.GetSkillRate(randSkill.ConfigId, randSkill.Level)
  731. this.delPet(costPetId)
  732. if this.isInAssist(costPetId, true) || this.isInAssist(petId, false) {
  733. this.saveAssist()
  734. }
  735. this.dbChangePetList.Add(pet.Id)
  736. this.dbChangePetList.Add(costPetId)
  737. this.role.DelItem(int32(serverproto.ResType_Res_Coin), model.GlobalPetSkillUpConsume, AddItemST{AddFrom: AddFrom_Pet})
  738. this.petChangeNtf([]*serverproto.PetData{pet}, []uint32{costPetId}, nil, true)
  739. this.SetDirty(true)
  740. //如果是上阵的宠物//通知战力变化
  741. bFightChangeNotNotify := true
  742. if this.isBattle(pet) || pet.QiyueHeroId > 0 {
  743. //this.role.GetRoleFightPower().OnBattlePetChanged(pet.HeroId, false)
  744. bFightChangeNotNotify = false
  745. }
  746. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  747. IsPet: true,
  748. ChangePetData: pet,
  749. ChangeType: Attr_Change_Pet_Skill,
  750. FightChangeNotNotify: bFightChangeNotNotify,
  751. })
  752. this.OnRushPetScoreChange()
  753. return serverproto.ErrorCode_ERROR_OK, randSkill.ConfigId
  754. }
  755. return serverproto.ErrorCode_ERROR_PET_SKILLUP_TYPE, 0
  756. }
  757. func (this *RolePet) GetPetTotalSkillLevel(pet *serverproto.PetData) int32 {
  758. if pet == nil || len(pet.SkillList) <= 0 {
  759. return 0
  760. }
  761. var totalSkillLevel int32 = 0
  762. for _, data := range pet.SkillList {
  763. if data.Level > 1 {
  764. totalSkillLevel += data.Level - 1
  765. }
  766. }
  767. return totalSkillLevel
  768. }
  769. func (this *RolePet) PetDecompose(petIdList []uint32, ackMsg *serverproto.SCPetDecomposeAck) serverproto.ErrorCode {
  770. bAssistChange := false
  771. var delPetLIst []uint32
  772. var addItemList = map[int32]int32{}
  773. var ntfDataList []*serverproto.PetEquipData
  774. for idx := 0; idx < len(petIdList); idx++ {
  775. pet := this.getPet(petIdList[idx])
  776. //宠物上阵/契约无法进行分解
  777. if pet == nil || pet.HeroId != 0 || pet.QiyueHeroId > 0 {
  778. continue
  779. }
  780. petCfgData, ok := model.ConvertPet[pet.ConfigId]
  781. if !ok {
  782. continue
  783. }
  784. retPercent := (float32)(model.GlobalNormalPetDecompose * 1.0)
  785. vipPetDecompose := this.role.GetRoleBase().GetVipData(model.Vip_System_PetDesolve)
  786. if vipPetDecompose > 0 {
  787. retPercent = (float32)(model.GlobalVipPetDecompose)
  788. }
  789. retPercent = retPercent / 100
  790. var addExp int32 = 0
  791. var addZeny int32 = 0
  792. sumSkillLevel := this.GetPetTotalSkillLevel(pet)
  793. if len(model.GlobalPet1LevelDecompose) >= 3 {
  794. switch petCfgData.Quality {
  795. case model.Pet_Type_Normal:
  796. addResItem := model.GlobalPet1LevelDecompose[0]
  797. addExp = addResItem.Key
  798. addZeny = addResItem.Value
  799. tmpKV := model.GlobalPetDecomposeNormal[pet.AdvanceLevel]
  800. if tmpKV != nil {
  801. realCont := tmpKV.Value
  802. //计算技能相关
  803. tmp := model.GlobalPetDecomposeItemList[model.Pet_Type_Normal]
  804. if tmp != nil {
  805. realCont += sumSkillLevel * tmp.Value
  806. }
  807. addItemList[tmpKV.Key] += int32(float32(realCont) * retPercent)
  808. }
  809. case model.Pet_Type_Mini:
  810. addResItem := model.GlobalPet1LevelDecompose[1]
  811. addExp = addResItem.Key
  812. addZeny = addResItem.Value
  813. tmpKV := model.GlobalPetDecomposeMin[pet.AdvanceLevel]
  814. if tmpKV != nil {
  815. realCont := tmpKV.Value
  816. //计算技能相关
  817. tmp := model.GlobalPetDecomposeItemList[model.Pet_Type_Mini]
  818. if tmp != nil {
  819. realCont += sumSkillLevel * tmp.Value
  820. }
  821. addItemList[tmpKV.Key] += int32(float32(realCont) * retPercent)
  822. }
  823. case model.Pet_Type_MVP:
  824. addResItem := model.GlobalPet1LevelDecompose[2]
  825. addExp = addResItem.Key
  826. addZeny = addResItem.Value
  827. tmpKV := model.GlobalPetDecomposeMvp[pet.AdvanceLevel]
  828. if tmpKV != nil {
  829. realCont := tmpKV.Value
  830. //计算技能相关
  831. tmp := model.GlobalPetDecomposeItemList[model.Pet_Type_MVP]
  832. if tmp != nil {
  833. realCont += sumSkillLevel * tmp.Value
  834. }
  835. addItemList[tmpKV.Key] += int32(float32(realCont) * retPercent)
  836. }
  837. }
  838. }
  839. expData, ok := model.ConvertPetExp[pet.Level-1]
  840. if ok {
  841. if petCfgData.Quality == model.Pet_Type_Normal {
  842. addExp += expData.NormalAccuExp
  843. addZeny += expData.NormalAccuZeny
  844. } else if petCfgData.Quality == model.Pet_Type_Mini {
  845. addExp += expData.MiniAccuExp
  846. addZeny += expData.MiniAccuZeny
  847. } else if petCfgData.Quality == model.Pet_Type_MVP {
  848. addExp += expData.MvpAccuExp
  849. addZeny += expData.MvpAccuZeny
  850. }
  851. }
  852. addItemList[int32(serverproto.ResType_Res_PetExp)] += int32(float32(addExp) * retPercent)
  853. addItemList[int32(serverproto.ResType_Res_Coin)] += int32(float32(addZeny) * retPercent)
  854. this.dbChangePetList.Add(pet.Id)
  855. delPetLIst = append(delPetLIst, pet.Id)
  856. delete(this.petList, pet.Id)
  857. this.SetDirty(true)
  858. if this.isInAssist(petIdList[idx], true) {
  859. bAssistChange = true
  860. }
  861. //this.isInPetBondList(petIdList[idx], this.role.GetUUid(), true)
  862. //宠物印记卸下
  863. for _, slotEquip := range pet.SlotEquipList {
  864. if slotEquip.EquipId > 0 {
  865. petEquipData := this.petEquipDown(slotEquip.EquipId)
  866. ntfDataList = append(ntfDataList, petEquipData)
  867. }
  868. }
  869. }
  870. if len(ntfDataList) > 0 {
  871. this.role.rolePet.petEquipChangeNtf(ntfDataList, false)
  872. }
  873. if len(addItemList) > 0 {
  874. this.role.GetRoleBag().AddItemList(addItemList, AddItemST{AddFrom: AddFrom_Pet, Notify: true})
  875. for key, val := range addItemList {
  876. if key <= 0 || val <= 0 {
  877. continue
  878. }
  879. ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{Key: key, Value: val})
  880. }
  881. }
  882. if len(delPetLIst) > 0 {
  883. this.petChangeNtf(nil, delPetLIst, nil, bAssistChange)
  884. }
  885. if bAssistChange {
  886. this.saveAssist()
  887. }
  888. //刷新羁绊列表中玩家自身的宠物数据(分解,消耗造成的移除操作)
  889. if this.refreshPetBond(true) {
  890. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  891. IsPet: true,
  892. ChangeType: Attr_Change_Pet_Bond,
  893. })
  894. }
  895. //判断是否激活,增加属性,战斗力
  896. //this.role.GetRoleFightPower().ClearPetBondFightPower()
  897. //for _, data := range this.bondList {
  898. // this.role.GetRoleFightPower().CalcAndResetPetBondFightPower(data.BondCfgId)
  899. //}
  900. //this.role.GetRoleFightPower().AfterBondFightPowerChange()
  901. return serverproto.ErrorCode_ERROR_OK
  902. }
  903. func (this *RolePet) PetBondListGet(msg *serverproto.SCPetBondListAck) serverproto.ErrorCode {
  904. if !this.PetBondListAssistQuery(true) {
  905. this.petBondListQuery(msg)
  906. return serverproto.ErrorCode_ERROR_OK
  907. }
  908. return serverproto.ErrorCode_ERROR_FAIL
  909. }
  910. func (this *RolePet) PetBondListAssistQuery(notify bool) bool {
  911. nowTime := util.GetTimeMilliseconds()
  912. if this.refreshBondListTime == 0 || nowTime-this.refreshBondListTime > 5*1000 {
  913. this.refreshBondListTime = nowTime
  914. queryMsg := &serverproto.SSPetQueryAssistInfoReq{
  915. Notify: notify,
  916. }
  917. var assistDataList = map[uint64]*serverproto.AssistData{}
  918. for _, val := range this.bondList {
  919. for idx := 0; idx < len(val.BondList); idx++ {
  920. if val.BondList[idx].OwnerUid == 0 {
  921. continue
  922. }
  923. assistData, ok := assistDataList[val.BondList[idx].OwnerUid]
  924. if !ok {
  925. assistData = &serverproto.AssistData{
  926. OwnerUid: val.BondList[idx].OwnerUid,
  927. }
  928. queryMsg.QueryAssistList = append(queryMsg.QueryAssistList, assistData)
  929. assistDataList[assistData.OwnerUid] = assistData
  930. }
  931. bFind := false
  932. for k := 0; k < len(assistData.PetInfoList); k++ {
  933. if assistData.PetInfoList[k].Id == val.BondList[idx].PetId {
  934. bFind = true
  935. break
  936. }
  937. }
  938. if !bFind {
  939. assistData.PetInfoList = append(assistData.PetInfoList, &serverproto.PetData{
  940. Id: val.BondList[idx].PetId, //选择的援助宠物ID
  941. })
  942. }
  943. }
  944. }
  945. if len(assistDataList) > 0 {
  946. queryMsg.UidList = append(queryMsg.UidList, this.role.GetRoleSocial().GetFriendList()...)
  947. queryMsg.GuildId = uint64(this.role.GetRoleGuildId())
  948. this.role.SendDb(queryMsg)
  949. return true
  950. }
  951. }
  952. return false
  953. }
  954. func (this *RolePet) OnPetBondListAssistQuery(ackMsg *serverproto.SSPetQueryAssistInfoAck) {
  955. this.queryAssistList = map[uint64]*serverproto.AssistData{}
  956. for idx := 0; idx < len(ackMsg.QueryAssistList); idx++ {
  957. this.queryAssistList[ackMsg.QueryAssistList[idx].OwnerUid] = ackMsg.QueryAssistList[idx]
  958. }
  959. sendMsg := &serverproto.SCPetBondListAck{}
  960. this.petBondListQuery(sendMsg)
  961. if ackMsg.Notify {
  962. this.role.ReplayGate(sendMsg, true)
  963. }
  964. }
  965. func (this *RolePet) petBondListQuery(msg *serverproto.SCPetBondListAck) serverproto.ErrorCode {
  966. //表示当前羁绊属性被修改需求重新计算
  967. var uniqueUidList = set.New(set.NonThreadSafe)
  968. for _, val := range this.bondList {
  969. for idx := 0; idx < len(val.BondList); idx++ {
  970. bondPosData := val.BondList[idx]
  971. if bondPosData.PetId == 0 {
  972. val.BondList[idx].PetCfgId = 0
  973. val.BondList[idx].AdvanceLevel = 0
  974. val.BondList[idx].OwnerUid = 0
  975. continue
  976. }
  977. //当前设置羁绊的宠物为自己
  978. if bondPosData.OwnerUid == 0 {
  979. if bondPosData.PetId > 0 {
  980. tmpPet := this.getPet(bondPosData.PetId)
  981. if tmpPet == nil {
  982. val.BondList[idx].PetId = 0
  983. val.BondList[idx].PetCfgId = 0
  984. val.BondList[idx].AdvanceLevel = 0
  985. val.BondList[idx].OwnerUid = 0
  986. this.dbBondChangeList.Add(val.BondCfgId)
  987. } else {
  988. val.BondList[idx].AdvanceLevel = tmpPet.AdvanceLevel
  989. val.BondList[idx].PetCfgId = tmpPet.ConfigId
  990. }
  991. }
  992. continue
  993. }
  994. //当前设置羁绊的宠物为其他玩家所有
  995. assistVal, ok := this.queryAssistList[bondPosData.OwnerUid]
  996. if !ok {
  997. val.BondList[idx].PetId = 0
  998. val.BondList[idx].OwnerUid = 0
  999. val.BondList[idx].AdvanceLevel = 0
  1000. val.BondList[idx].PetCfgId = 0
  1001. this.dbBondChangeList.Add(val.BondCfgId)
  1002. continue
  1003. }
  1004. bFind := false
  1005. for i := 0; i < len(assistVal.PetInfoList); i++ {
  1006. if assistVal.PetInfoList[i].Id == bondPosData.PetId && assistVal.PetInfoList[i].Param > 0 { //Param>0表示玩家存在该宠物
  1007. //添加唯一玩家名称
  1008. if !uniqueUidList.Has(val.BondList[idx].OwnerUid) {
  1009. uniqueUidList.Add(val.BondList[idx])
  1010. msg.UidNameList = append(msg.UidNameList, &serverproto.KeyValueType64Str{
  1011. Key: assistVal.OwnerUid,
  1012. StrVal: assistVal.OwnerNickName,
  1013. })
  1014. }
  1015. val.BondList[idx].AdvanceLevel = assistVal.PetInfoList[i].AdvanceLevel
  1016. val.BondList[idx].PetCfgId = assistVal.PetInfoList[i].ConfigId
  1017. //之前设置的援助玩家宠物合法
  1018. bFind = true
  1019. break
  1020. }
  1021. }
  1022. if !bFind {
  1023. val.BondList[idx].PetId = 0
  1024. val.BondList[idx].OwnerUid = 0
  1025. val.BondList[idx].AdvanceLevel = 0
  1026. val.BondList[idx].PetCfgId = 0
  1027. this.dbBondChangeList.Add(val.BondCfgId)
  1028. }
  1029. }
  1030. msg.BondList = append(msg.BondList, val)
  1031. }
  1032. if this.refreshPetBond(false) {
  1033. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  1034. IsPet: true,
  1035. ChangeType: Attr_Change_Pet_Bond,
  1036. })
  1037. }
  1038. ////todo...
  1039. //// 战力没有初始化前,需要先初始化一次
  1040. //
  1041. //if this.dbBondChangeList.Size() > 0 {
  1042. // this.SetDirty(true)
  1043. //
  1044. // //todo...
  1045. // // 重新计算变更后的战斗力处理
  1046. // this.checkBondCondition(this.dbBondChangeList.List())
  1047. //}
  1048. return serverproto.ErrorCode_ERROR_OK
  1049. }
  1050. // Task 获得指定上阵宠物数量 印记达到指定品质
  1051. func (this *RolePet) GetPetBattleCntByQuality(quality int32) int32 {
  1052. var cnt int32 = 0
  1053. mainHero := this.role.GetRoleBase().RoleData().HeroData
  1054. if mainHero != nil && mainHero.BattlePetId > 0 {
  1055. Battle := this.getPet(mainHero.BattlePetId)
  1056. if Battle != nil {
  1057. meet := false
  1058. for i := 0; i < PetEquipSlotNum; i++ {
  1059. meet = false
  1060. if len(Battle.SlotEquipList) < i+1 {
  1061. break
  1062. }
  1063. pet := Battle.SlotEquipList[i]
  1064. if pet.EquipId <= 0 {
  1065. break
  1066. }
  1067. EquipData := this.GetPetEquip(pet.EquipId)
  1068. if EquipData == nil {
  1069. continue
  1070. }
  1071. cfg, ok := model.ConvertPetEquip[int32(EquipData.EquipCfgId)]
  1072. if !ok || cfg == nil {
  1073. continue
  1074. }
  1075. if cfg.Quality < quality {
  1076. break
  1077. }
  1078. meet = true
  1079. }
  1080. if meet {
  1081. cnt++
  1082. }
  1083. }
  1084. }
  1085. for _, hero := range this.role.GetRoleHero().heroList {
  1086. if hero.BattlePetId <= 0 {
  1087. continue
  1088. }
  1089. Battle := this.getPet(hero.BattlePetId)
  1090. if Battle == nil {
  1091. continue
  1092. }
  1093. meet := false
  1094. for i := 0; i < PetEquipSlotNum; i++ {
  1095. meet = false
  1096. if len(Battle.SlotEquipList) < i+1 {
  1097. break
  1098. }
  1099. pet := Battle.SlotEquipList[i]
  1100. if pet.EquipId <= 0 {
  1101. break
  1102. }
  1103. EquipData := this.GetPetEquip(pet.EquipId)
  1104. if EquipData == nil {
  1105. continue
  1106. }
  1107. cfg, ok := model.ConvertPetEquip[EquipData.EquipCfgId]
  1108. if !ok || cfg == nil {
  1109. continue
  1110. }
  1111. if cfg.Quality < quality {
  1112. break
  1113. }
  1114. meet = true
  1115. }
  1116. if meet {
  1117. cnt++
  1118. }
  1119. }
  1120. return cnt
  1121. }
  1122. func (this *RolePet) PetBattle(battleList []*serverproto.KeyValueType) serverproto.ErrorCode {
  1123. var tmpChangeList = set.New(set.NonThreadSafe)
  1124. //判断是否上阵相同宠物
  1125. for idx := 0; idx < len(battleList); idx++ {
  1126. petId := uint32(battleList[idx].Value)
  1127. if petId <= 0 {
  1128. continue
  1129. }
  1130. pet := this.getPet(uint32(petId))
  1131. if pet == nil {
  1132. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  1133. }
  1134. if tmpChangeList.Has(pet.ConfigId) {
  1135. return serverproto.ErrorCode_ERROR_PET_BATTLE_REPEATED
  1136. }
  1137. tmpChangeList.Add(pet.ConfigId)
  1138. }
  1139. tmpChangeList.Clear()
  1140. for idx := 0; idx < len(battleList); idx++ {
  1141. heroId := battleList[idx].Key
  1142. petId := uint32(battleList[idx].Value)
  1143. heroData := this.role.GetRoleHero().GetHero(heroId)
  1144. if heroData == nil {
  1145. continue
  1146. }
  1147. //下阵
  1148. if petId == 0 {
  1149. tmpPetId := heroData.BattlePetId
  1150. if tmpPetId > 0 && this.role.GetRoleHero().PetBattle(0, heroId) {
  1151. tmpPet := this.getPet(tmpPetId)
  1152. if tmpPet != nil {
  1153. tmpPet.HeroId = 0
  1154. this.dbChangePetList.Add(tmpPetId)
  1155. this.SetDirty(true)
  1156. tmpChangeList.Add(tmpPetId)
  1157. }
  1158. }
  1159. } else {
  1160. //上阵
  1161. pet := this.getPet(uint32(petId))
  1162. if pet == nil {
  1163. continue
  1164. }
  1165. if pet.HeroId == heroId {
  1166. continue
  1167. }
  1168. //当成契约材料宠物无法上阵
  1169. if pet.QiyueHeroId != 0 {
  1170. continue
  1171. }
  1172. //当前petid对应宠物正在上阵,先下阵
  1173. if pet.HeroId != 0 {
  1174. this.role.GetRoleHero().PetBattle(0, pet.HeroId)
  1175. }
  1176. //当前玩家身上的宠物下阵
  1177. if heroData.BattlePetId > 0 {
  1178. tmpPet := this.getPet(heroData.BattlePetId)
  1179. if tmpPet != nil {
  1180. tmpPet.HeroId = 0
  1181. this.dbChangePetList.Add(heroData.BattlePetId)
  1182. tmpChangeList.Add(heroData.BattlePetId)
  1183. }
  1184. }
  1185. pet.HeroId = heroId
  1186. this.role.GetRoleHero().PetBattle(uint32(petId), heroId)
  1187. this.SetDirty(true)
  1188. this.dbChangePetList.Add(petId)
  1189. tmpChangeList.Add(uint32(petId))
  1190. }
  1191. }
  1192. if tmpChangeList.Size() > 0 {
  1193. //不进行任何计算只做战力通知(AttrChangeST结构不做任何赋值)
  1194. this.role.roleBattleAttr.AttrChange(AttrChangeST{})
  1195. tmpList := tmpChangeList.List()
  1196. var tmpPetList []*serverproto.PetData
  1197. for idx := 0; idx < len(tmpList); idx++ {
  1198. pet := this.getPet(tmpList[idx].(uint32))
  1199. if pet == nil {
  1200. continue
  1201. }
  1202. tmpPetList = append(tmpPetList, pet)
  1203. }
  1204. this.petChangeNtf(tmpPetList, nil, nil, false)
  1205. this.OnRushPetScoreChange()
  1206. TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Battle_Quality_cnt, 1)
  1207. return serverproto.ErrorCode_ERROR_OK
  1208. }
  1209. return serverproto.ErrorCode_ERROR_FAIL
  1210. }
  1211. func (this *RolePet) PetAssist(petIdList []uint32) serverproto.ErrorCode {
  1212. if len(petIdList) != Max_Assist_Num {
  1213. return serverproto.ErrorCode_ERROR_FAIL
  1214. }
  1215. if len(this.assistList) <= 0 {
  1216. for idx := 0; idx < Max_Assist_Num; idx++ {
  1217. this.assistList = append(this.assistList, &serverproto.AssistIdxData{})
  1218. }
  1219. }
  1220. bChange := false
  1221. nowTime := util.GetTimeMilliseconds()
  1222. hasList := set.New(set.NonThreadSafe)
  1223. for idx := 0; idx < len(petIdList); idx++ {
  1224. if petIdList[idx] == 0 {
  1225. //下援助设置CD
  1226. if this.assistList[idx].PetId > 0 {
  1227. this.assistList[idx].PetId = 0
  1228. this.assistList[idx].EndCdTime = nowTime + uint64(model.GlobalPetAssistCD*1000)
  1229. this.SetDirty(true)
  1230. bChange = true
  1231. }
  1232. continue
  1233. }
  1234. pet := this.getPet(petIdList[idx])
  1235. if pet == nil {
  1236. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  1237. }
  1238. if hasList.Has(petIdList[idx]) {
  1239. return serverproto.ErrorCode_ERROR_PET_ASSIST_REPEATED
  1240. }
  1241. if this.assistList[idx].EndCdTime < nowTime {
  1242. //判断CD
  1243. hasList.Add(petIdList[idx])
  1244. this.assistList[idx].PetId = pet.Id
  1245. this.SetDirty(true)
  1246. bChange = true
  1247. }
  1248. }
  1249. if bChange {
  1250. this.petChangeNtf(nil, nil, nil, bChange)
  1251. this.saveAssist()
  1252. }
  1253. return serverproto.ErrorCode_ERROR_OK
  1254. }
  1255. func (this *RolePet) saveAssist() {
  1256. ssMsg := &serverproto.SSPetSetAssistNtf{}
  1257. for idx := 0; idx < len(this.assistList); idx++ {
  1258. pet := this.getPet(this.assistList[idx].PetId)
  1259. if pet == nil {
  1260. continue
  1261. }
  1262. ssMsg.AssistList = append(ssMsg.AssistList, &serverproto.AssistSaveData{
  1263. PetId: pet.Id,
  1264. PetCfgId: pet.ConfigId,
  1265. AdvLevel: pet.AdvanceLevel,
  1266. })
  1267. }
  1268. this.role.SendDb(ssMsg)
  1269. }
  1270. func (this *RolePet) PetBondAssistListGet(bondCfgId int32) bool {
  1271. bFind := false
  1272. for idx := 0; idx < len(model.ConvertBond); idx++ {
  1273. if model.ConvertBond[idx].BondId == bondCfgId {
  1274. ssMsg := &serverproto.SSPetBondAssistListReq{
  1275. BondCfgId: bondCfgId,
  1276. Condition1List: model.ConvertBond[idx].ConditionList1,
  1277. Condition2List: model.ConvertBond[idx].ConditionList2,
  1278. Condition3List: model.ConvertBond[idx].ConditionList3,
  1279. }
  1280. ssMsg.UidList = append(ssMsg.UidList, this.role.GetRoleSocial().GetFriendList()...)
  1281. ssMsg.GuildId = uint64(this.role.GetRoleGuildId())
  1282. if len(ssMsg.UidList) <= 0 && ssMsg.GuildId <= 0 {
  1283. break
  1284. }
  1285. this.role.SendDb(ssMsg)
  1286. bFind = true
  1287. break
  1288. }
  1289. }
  1290. if !bFind {
  1291. return false
  1292. }
  1293. return true
  1294. }
  1295. func (this *RolePet) OnPetBondAssistListGet(msg *serverproto.SSPetBondAssistListAck) {
  1296. this.tmpBondAssistList[msg.BondCfgId] = msg.AssistList
  1297. //排除已经设置的对应玩家宠物ID(客户端显示时做处理)
  1298. ackMsg := &serverproto.SCPetBondAssistListAck{
  1299. Error: int32(serverproto.ErrorCode_ERROR_OK),
  1300. BondPetList: msg.AssistList,
  1301. BondCfgId: msg.BondCfgId,
  1302. }
  1303. this.role.ReplayGate(ackMsg, true)
  1304. }
  1305. func (this *RolePet) PetBondActive(bondData []*serverproto.PetBondData) serverproto.ErrorCode {
  1306. //是否有重复宠物ID
  1307. var multiplePetList = map[uint32][]uint64{} //[petId,uid]
  1308. for k := 0; k < len(bondData); k++ {
  1309. if len(bondData[k].BondList) > 3 {
  1310. return serverproto.ErrorCode_ERROR_FAIL
  1311. }
  1312. for idx := 0; idx < len(bondData[k].BondList); idx++ {
  1313. if bondData[k].BondList[idx].PetId == 0 {
  1314. continue
  1315. }
  1316. if valList, ok := multiplePetList[bondData[k].BondList[idx].PetId]; ok {
  1317. for i := 0; i < len(valList); i++ {
  1318. if valList[i] == bondData[k].BondList[idx].OwnerUid {
  1319. return serverproto.ErrorCode_ERROR_PET_ACTIVE_MULTI
  1320. }
  1321. }
  1322. }
  1323. multiplePetList[bondData[k].BondList[idx].PetId] = append(
  1324. multiplePetList[bondData[k].BondList[idx].PetId], bondData[k].BondList[idx].OwnerUid)
  1325. }
  1326. }
  1327. //未改变的羁绊列表中是否有重复的宠物id
  1328. for _, val := range this.bondList {
  1329. bFind := false
  1330. for idx := 0; idx < len(bondData); idx++ {
  1331. if bondData[idx].BondCfgId == val.BondCfgId {
  1332. bFind = true
  1333. break
  1334. }
  1335. }
  1336. if !bFind {
  1337. for idx := 0; idx < len(val.BondList); idx++ {
  1338. if val.BondList[idx].PetId == 0 {
  1339. continue
  1340. }
  1341. if valList, ok := multiplePetList[val.BondList[idx].PetId]; ok {
  1342. for i := 0; i < len(valList); i++ {
  1343. if valList[i] == val.BondList[idx].OwnerUid {
  1344. return serverproto.ErrorCode_ERROR_PET_ACTIVE_MULTI
  1345. }
  1346. }
  1347. }
  1348. multiplePetList[val.BondList[idx].PetId] = append(
  1349. multiplePetList[val.BondList[idx].PetId], val.BondList[idx].OwnerUid)
  1350. }
  1351. }
  1352. }
  1353. var uidNameList []*serverproto.KeyValueType64Str
  1354. //判断设置的宠物ID是否合法
  1355. for k := 0; k < len(bondData); k++ {
  1356. ret := this.petBondActive(bondData[k], &uidNameList)
  1357. if ret != serverproto.ErrorCode_ERROR_OK {
  1358. return ret
  1359. }
  1360. }
  1361. for k := 0; k < len(bondData); k++ {
  1362. this.bondList[bondData[k].BondCfgId] = bondData[k]
  1363. this.dbBondChangeList.Add(bondData[k].BondCfgId)
  1364. }
  1365. TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Id_Cnt, 1)
  1366. this.SetDirty(true)
  1367. ackMsg := &serverproto.SCPetBondActiveAck{
  1368. Error: int32(serverproto.ErrorCode_ERROR_OK),
  1369. BondDataList: bondData,
  1370. UidNameList: uidNameList,
  1371. }
  1372. this.role.ReplayGate(ackMsg, true)
  1373. //判断是否激活,增加属性,战斗力
  1374. //this.checkBondCondition(this.dbBondChangeList.List())
  1375. //attr
  1376. this.onPetBondActiveAttr(bondData)
  1377. return serverproto.ErrorCode_ERROR_OK
  1378. }
  1379. func (this *RolePet) GetBondPetCntByCfgId(cfgId int32) int32 {
  1380. var cnt int32 = 0
  1381. for _, data := range this.bondList {
  1382. if len(data.BondList) <= 0 {
  1383. continue
  1384. }
  1385. for _, pet := range data.BondList {
  1386. if pet.PetCfgId != cfgId {
  1387. continue
  1388. }
  1389. cnt++
  1390. }
  1391. }
  1392. return cnt
  1393. }
  1394. func (this *RolePet) onPetBondActiveAttr(bondData []*serverproto.PetBondData) {
  1395. //attr
  1396. bResetAttr := false
  1397. for k := 0; k < len(bondData); k++ {
  1398. if len(bondData[k].BondList) < 3 {
  1399. continue
  1400. }
  1401. bOk := true
  1402. for idx := 0; idx < len(bondData[k].BondList); idx++ {
  1403. if bondData[k].BondList[idx].PetCfgId <= 0 {
  1404. bOk = false
  1405. break
  1406. }
  1407. }
  1408. if bOk {
  1409. bResetAttr = true
  1410. break
  1411. }
  1412. }
  1413. if bResetAttr {
  1414. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  1415. IsPet: true,
  1416. ChangeType: Attr_Change_Pet_Bond,
  1417. })
  1418. }
  1419. }
  1420. func (this *RolePet) petBondActive(bondData *serverproto.PetBondData, uidNameList *[]*serverproto.KeyValueType64Str) serverproto.ErrorCode {
  1421. for idx := 0; idx < len(bondData.BondList); idx++ {
  1422. if bondData.BondList[idx].PetId <= 0 {
  1423. bondData.BondList[idx].OwnerUid = 0
  1424. bondData.BondList[idx].AdvanceLevel = 0
  1425. continue
  1426. }
  1427. //当前宠物自己
  1428. if bondData.BondList[idx].OwnerUid == 0 {
  1429. petData := this.getPet(bondData.BondList[idx].PetId)
  1430. if petData == nil {
  1431. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  1432. }
  1433. bondData.BondList[idx].AdvanceLevel = petData.AdvanceLevel
  1434. bondData.BondList[idx].PetCfgId = petData.ConfigId
  1435. } else {
  1436. assistData, ok := this.tmpBondAssistList[bondData.BondCfgId]
  1437. if !ok {
  1438. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  1439. }
  1440. bFind := false
  1441. for i := 0; i < len(assistData); i++ {
  1442. if assistData[i].OwnerUid != bondData.BondList[idx].OwnerUid {
  1443. continue
  1444. }
  1445. for j := 0; j < len(assistData[i].PetInfoList); j++ {
  1446. if assistData[i].PetInfoList[j].Id == bondData.BondList[idx].PetId &&
  1447. assistData[i].PetInfoList[j].Param > 0 {
  1448. *uidNameList = append(*uidNameList, &serverproto.KeyValueType64Str{
  1449. Key: assistData[i].OwnerUid,
  1450. StrVal: assistData[i].OwnerNickName,
  1451. })
  1452. bondData.BondList[idx].AdvanceLevel = assistData[i].PetInfoList[j].AdvanceLevel
  1453. bondData.BondList[idx].PetCfgId = assistData[i].PetInfoList[j].ConfigId
  1454. bFind = true
  1455. break
  1456. }
  1457. }
  1458. if bFind {
  1459. break
  1460. }
  1461. }
  1462. if !bFind {
  1463. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  1464. }
  1465. }
  1466. }
  1467. bondData.PetBondLevel = this.CheckBondLevel(bondData)
  1468. return serverproto.ErrorCode_ERROR_OK
  1469. }
  1470. //刷新羁绊列表中玩家自身的宠物数据(分解,消耗造成的移除操作)
  1471. func (this *RolePet) refreshPetBond(bNotify bool) bool {
  1472. bChange := false
  1473. ntfMsg := &serverproto.SCPetBondListNtf{}
  1474. for _, bondData := range this.bondList {
  1475. bFind := false
  1476. for idx := 0; idx < len(bondData.BondList); idx++ {
  1477. if bondData.BondList[idx].PetId <= 0 {
  1478. bondData.BondList[idx].PetCfgId = 0
  1479. bondData.BondList[idx].OwnerUid = 0
  1480. bondData.BondList[idx].AdvanceLevel = 0
  1481. continue
  1482. } //当前宠物自己
  1483. if bondData.BondList[idx].OwnerUid == 0 {
  1484. petData := this.getPet(bondData.BondList[idx].PetId)
  1485. if petData == nil {
  1486. //宠物已经被移除(消耗,分解玩家操作)
  1487. bondData.BondList[idx].PetId = 0
  1488. bondData.BondList[idx].PetCfgId = 0
  1489. bondData.BondList[idx].OwnerUid = 0
  1490. bondData.BondList[idx].AdvanceLevel = 0
  1491. this.SetDirty(true)
  1492. this.dbBondChangeList.Add(bondData.BondCfgId)
  1493. bFind = true
  1494. } else {
  1495. if petData.AdvanceLevel > bondData.BondList[idx].AdvanceLevel {
  1496. bondData.BondList[idx].AdvanceLevel = petData.AdvanceLevel
  1497. bFind = true
  1498. this.SetDirty(true)
  1499. this.dbBondChangeList.Add(bondData.BondCfgId)
  1500. }
  1501. }
  1502. }
  1503. }
  1504. //bNotify=false表示load阶段
  1505. if bFind || !bNotify {
  1506. retBondLevel := this.CheckBondLevel(bondData)
  1507. if bondData.PetBondLevel != retBondLevel {
  1508. bondData.PetBondLevel = retBondLevel
  1509. bChange = true
  1510. this.SetDirty(true)
  1511. }
  1512. ntfMsg.BondList = append(ntfMsg.BondList, bondData)
  1513. }
  1514. }
  1515. util.InfoF("uid=%v refreshPetBond bondList=%v", this.role.GetUUid(), this.bondList)
  1516. if len(ntfMsg.BondList) > 0 && bNotify {
  1517. this.role.ReplayGate(ntfMsg, true)
  1518. }
  1519. return bChange
  1520. }
  1521. func (this *RolePet) AddPet(petCfgId int32) (serverproto.ErrorCode, *serverproto.PetData) {
  1522. petCfgData, ok := model.ConvertPet[petCfgId]
  1523. if !ok {
  1524. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND, nil
  1525. }
  1526. this.maxPetId++
  1527. pet := &serverproto.PetData{
  1528. Id: uint32(this.maxPetId),
  1529. ConfigId: petCfgId,
  1530. Level: 1,
  1531. }
  1532. for idx := 0; idx < len(petCfgData.SkillList); idx++ {
  1533. petSkill := &serverproto.PetSkillData{
  1534. ConfigId: petCfgData.SkillList[idx].SkillId,
  1535. Level: 1,
  1536. Rate: petCfgData.SkillList[idx].RateList[0],
  1537. }
  1538. pet.SkillList = append(pet.SkillList, petSkill)
  1539. }
  1540. this.petList[pet.Id] = pet
  1541. this.dbChangePetList.Add(pet.Id)
  1542. manualItem := this.addPetManual(uint32(petCfgId))
  1543. util.InfoF("uid=%v AddPet petcfgid=%v", this.role.GetUUid(), petCfgId)
  1544. this.SetDirty(true)
  1545. if manualItem != nil {
  1546. this.petChangeNtf([]*serverproto.PetData{pet}, nil, []*serverproto.PetManualST{manualItem}, false)
  1547. } else {
  1548. this.petChangeNtf([]*serverproto.PetData{pet}, nil, nil, false)
  1549. }
  1550. this.onAddPet(pet)
  1551. TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Id_Cnt, petCfgId)
  1552. return serverproto.ErrorCode_ERROR_OK, pet
  1553. }
  1554. func (this *RolePet) onAddPet(petData *serverproto.PetData) {
  1555. TaskMagCheck(this.role, serverproto.TaskType_Pet_Quality_Num, 0)
  1556. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  1557. IsPet: true,
  1558. ChangePetData: petData,
  1559. ChangeType: Attr_Change_Pet_Base,
  1560. FightChangeNotNotify: true,
  1561. })
  1562. }
  1563. func (this *RolePet) addPetManual(petCfgId uint32) *serverproto.PetManualST {
  1564. if petCfgId < 800 {
  1565. return nil
  1566. }
  1567. petCfgId -= 800
  1568. var manualItem *serverproto.PetManualST = nil
  1569. manualItem, ok := this.petManualRewardList[int32(petCfgId)]
  1570. if !ok {
  1571. manualItem = &serverproto.PetManualST{
  1572. PetCfgId: int32(petCfgId),
  1573. }
  1574. petData := this.getPet(petCfgId)
  1575. if petData != nil {
  1576. manualItem.AdvLevel = petData.AdvanceLevel
  1577. }
  1578. this.petManualRewardList[int32(petCfgId)] = manualItem
  1579. this.SetDirty(true)
  1580. return manualItem
  1581. } else {
  1582. petData := this.getPet(petCfgId)
  1583. if petData != nil && manualItem.AdvLevel < petData.AdvanceLevel {
  1584. this.SetDirty(true)
  1585. return manualItem
  1586. }
  1587. }
  1588. return nil
  1589. }
  1590. func (this *RolePet) getPet(petId uint32) *serverproto.PetData {
  1591. if val, ok := this.petList[petId]; ok {
  1592. return val
  1593. }
  1594. return nil
  1595. }
  1596. func (this *RolePet) delPet(petId uint32) {
  1597. var ntfDataList []*serverproto.PetEquipData
  1598. petData := this.getPet(petId)
  1599. if petData == nil {
  1600. delete(this.petList, petId)
  1601. return
  1602. }
  1603. //宠物印记卸下
  1604. for _, slotEquip := range petData.SlotEquipList {
  1605. if slotEquip.EquipId > 0 {
  1606. petEquipData := this.petEquipDown(slotEquip.EquipId)
  1607. ntfDataList = append(ntfDataList, petEquipData)
  1608. }
  1609. }
  1610. delete(this.petList, petId)
  1611. if len(ntfDataList) > 0 {
  1612. this.role.rolePet.petEquipChangeNtf(ntfDataList, false)
  1613. }
  1614. }
  1615. func (this *RolePet) delPetList(petIdList []uint32) {
  1616. var ntfDataList []*serverproto.PetEquipData
  1617. for idx := 0; idx < len(petIdList); idx++ {
  1618. petData := this.getPet(petIdList[idx])
  1619. if petData == nil {
  1620. continue
  1621. }
  1622. //宠物印记卸下
  1623. for _, slotEquip := range petData.SlotEquipList {
  1624. if slotEquip.EquipId > 0 {
  1625. petEquipData := this.petEquipDown(slotEquip.EquipId)
  1626. ntfDataList = append(ntfDataList, petEquipData)
  1627. }
  1628. }
  1629. delete(this.petList, petIdList[idx])
  1630. }
  1631. if len(ntfDataList) > 0 {
  1632. this.role.rolePet.petEquipChangeNtf(ntfDataList, false)
  1633. }
  1634. }
  1635. func (this *RolePet) getLevelUpLimit(advanceLevel int) int32 {
  1636. if advanceLevel > len(model.GlobalPetAdvanceLimit) || advanceLevel < 0 {
  1637. return 0
  1638. }
  1639. return model.GlobalPetAdvanceLimit[advanceLevel]
  1640. }
  1641. func (this *RolePet) getLevelUpCost(quality int32, level int32) (serverproto.ErrorCode, int32, int32) {
  1642. convertData, ok1 := model.ConvertPetExp[level]
  1643. if !ok1 {
  1644. return serverproto.ErrorCode_ERROR_PET_LEVEL_LIMIT, 0, 0
  1645. }
  1646. if quality == model.Pet_Type_Normal {
  1647. return serverproto.ErrorCode_ERROR_OK, convertData.NormalZeny, convertData.NormalExp
  1648. } else if quality == model.Pet_Type_Mini {
  1649. return serverproto.ErrorCode_ERROR_OK, convertData.MiniZeny, convertData.MiniExp
  1650. } else if quality == model.Pet_Type_MVP {
  1651. return serverproto.ErrorCode_ERROR_OK, convertData.MvpZeny, convertData.MvpExp
  1652. }
  1653. return serverproto.ErrorCode_ERROR_PET_LEVEL_LIMIT, 0, 0
  1654. }
  1655. func (this *RolePet) levelUp(quality int32, levelUpLimit int32, pet *serverproto.PetData) bool {
  1656. bRet := false
  1657. if pet.Level >= levelUpLimit {
  1658. return bRet
  1659. }
  1660. ret, needZeny, needExp := this.getLevelUpCost(quality, pet.Level)
  1661. if ret != serverproto.ErrorCode_ERROR_OK {
  1662. return bRet
  1663. }
  1664. //消耗异常
  1665. if needZeny == 0 || needExp == 0 {
  1666. return bRet
  1667. }
  1668. var delItemList = map[int32]int32{}
  1669. delItemList[int32(serverproto.ResType_Res_Coin)] = needZeny
  1670. delItemList[int32(serverproto.ResType_Res_PetExp)] = int32(needExp)
  1671. if !this.role.GetRoleBag().CanDelItemList(delItemList) {
  1672. return bRet
  1673. }
  1674. pet.Level++
  1675. this.role.DelItemList(delItemList, AddItemST{AddFrom: AddFrom_Pet})
  1676. this.SetDirty(true)
  1677. bRet = true
  1678. return bRet
  1679. }
  1680. func (this *RolePet) isBattle(pet *serverproto.PetData) bool {
  1681. if pet.HeroId != 0 && this.role.GetRoleHero().IsPetBattle(pet.HeroId) == pet.Id {
  1682. return true
  1683. }
  1684. return false
  1685. }
  1686. func (this *RolePet) getBond(bondCfgId int32) *serverproto.PetBondData {
  1687. if data, ok := this.bondList[bondCfgId]; ok {
  1688. return data
  1689. }
  1690. return nil
  1691. }
  1692. func (this *RolePet) isInAssist(petId uint32, del bool) bool {
  1693. for idx := 0; idx < len(this.assistList); idx++ {
  1694. if this.assistList[idx].PetId == petId {
  1695. if del {
  1696. nowTime := util.GetTimeMilliseconds()
  1697. this.assistList[idx].PetId = 0
  1698. this.assistList[idx].EndCdTime = nowTime + uint64(model.GlobalPetAssistCD*1000)
  1699. this.SetDirty(true)
  1700. }
  1701. return true
  1702. }
  1703. }
  1704. return false
  1705. }
  1706. //self
  1707. func (this *RolePet) isInPetBondList(petId uint32, ownerUid uint64, del bool) bool {
  1708. for _, val := range this.bondList {
  1709. for idx := 0; idx < len(val.BondList); idx++ {
  1710. //self
  1711. if val.BondList[idx].PetId == petId && val.BondList[idx].OwnerUid == 0 {
  1712. if del {
  1713. val.BondList[idx].PetId = 0
  1714. val.BondList[idx].OwnerUid = 0
  1715. val.BondList[idx].PetCfgId = 0
  1716. val.BondList[idx].AdvanceLevel = 0
  1717. this.SetDirty(true)
  1718. this.dbBondChangeList.Add(val.BondCfgId)
  1719. }
  1720. break
  1721. }
  1722. }
  1723. }
  1724. return false
  1725. }
  1726. func (this *RolePet) checkBondCondition(bondCfgId []interface{}) serverproto.ErrorCode {
  1727. //for idx := 0; idx < len(bondCfgId); idx++ {
  1728. // //cfgId := bondCfgId[idx].(int32)
  1729. // this.role.GetRoleFightPower().CalcAndResetPetBondFightPower(bondCfgId[idx].(int32))
  1730. //}
  1731. //
  1732. //this.role.GetRoleFightPower().AfterBondFightPowerChange()
  1733. return serverproto.ErrorCode_ERROR_FAIL
  1734. }
  1735. ///Task
  1736. func (this *RolePet) GetQualityPetNum(quality int32) int32 {
  1737. var retNum int32 = 0
  1738. if quality <= 0 {
  1739. retNum = int32(len(this.petList))
  1740. } else {
  1741. for _, val := range this.petList {
  1742. petCfgData, ok := model.ConvertPet[val.ConfigId]
  1743. if !ok {
  1744. continue
  1745. }
  1746. if petCfgData.Quality == quality {
  1747. retNum++
  1748. }
  1749. }
  1750. }
  1751. return retNum
  1752. }
  1753. ///Task
  1754. func (this *RolePet) GetPetNumByCfgId(cfgId int32) int32 {
  1755. var retNum int32 = 0
  1756. if cfgId <= 0 {
  1757. return 0
  1758. }
  1759. for _, val := range this.petList {
  1760. if val.ConfigId != cfgId {
  1761. continue
  1762. }
  1763. retNum++
  1764. }
  1765. return retNum
  1766. }
  1767. func (this *RolePet) GetBondLevel(bond *serverproto.PetBondData) int32 {
  1768. if bond == nil {
  1769. return -1
  1770. }
  1771. var advanceLevel int32 = -1
  1772. for _, data := range model.ConvertBond {
  1773. if data.BondId == bond.BondCfgId {
  1774. //条件1查看是否满足
  1775. var count1 int32 = 0
  1776. for _, petData := range data.ConditionList1 {
  1777. for _, ownPet := range bond.BondList {
  1778. if petData.Key == ownPet.PetCfgId {
  1779. if ownPet.AdvanceLevel >= uint32(petData.Value) {
  1780. count1++
  1781. }
  1782. break
  1783. }
  1784. }
  1785. }
  1786. if count1 >= int32(len(data.ConditionList1)) {
  1787. advanceLevel = 0
  1788. }
  1789. var count2 int32 = 0
  1790. for _, petData := range data.ConditionList2 {
  1791. for _, ownPet := range bond.BondList {
  1792. if petData.Key == ownPet.PetCfgId {
  1793. if ownPet.AdvanceLevel >= uint32(petData.Value) {
  1794. count2++
  1795. }
  1796. break
  1797. }
  1798. }
  1799. }
  1800. if count2 >= int32(len(data.ConditionList2)) {
  1801. advanceLevel = 1
  1802. }
  1803. var count3 int32 = 0
  1804. for _, petData := range data.ConditionList3 {
  1805. for _, ownPet := range bond.BondList {
  1806. if petData.Key == ownPet.PetCfgId {
  1807. if ownPet.AdvanceLevel >= uint32(petData.Value) {
  1808. count3++
  1809. }
  1810. break
  1811. }
  1812. }
  1813. }
  1814. if count3 >= int32(len(data.ConditionList3)) {
  1815. advanceLevel = 2
  1816. }
  1817. break
  1818. }
  1819. }
  1820. return advanceLevel
  1821. }
  1822. func (this *RolePet) CheckBondLevel(bond *serverproto.PetBondData) int32 {
  1823. var advanceLevel int32 = 0
  1824. if bond == nil {
  1825. return advanceLevel
  1826. }
  1827. for _, data := range model.ConvertBond {
  1828. if data.BondId == bond.BondCfgId {
  1829. //条件1查看是否满足
  1830. if this.checkBondLevel(bond, data.ConditionList1) {
  1831. advanceLevel = 1
  1832. }
  1833. if this.checkBondLevel(bond, data.ConditionList2) {
  1834. advanceLevel = 2
  1835. }
  1836. if this.checkBondLevel(bond, data.ConditionList3) {
  1837. advanceLevel = 3
  1838. }
  1839. break
  1840. }
  1841. }
  1842. return advanceLevel
  1843. }
  1844. func (this *RolePet) checkBondLevel(bond *serverproto.PetBondData, conditionList []*serverproto.KeyValueType) bool {
  1845. if len(conditionList) > len(bond.BondList) || len(conditionList) <= 0 {
  1846. return false
  1847. }
  1848. for _, petCfgData := range conditionList {
  1849. bFind := false
  1850. for _, bondPet := range bond.BondList {
  1851. if petCfgData.Key == bondPet.PetCfgId {
  1852. if bondPet.AdvanceLevel >= uint32(petCfgData.Value) {
  1853. bFind = true
  1854. }
  1855. break
  1856. }
  1857. }
  1858. if !bFind {
  1859. return false
  1860. }
  1861. }
  1862. return true
  1863. }
  1864. ///GM
  1865. func (this *RolePet) GMClearPet() {
  1866. var delPetList []uint32
  1867. for _, item := range this.petList {
  1868. delPetList = append(delPetList, item.Id)
  1869. this.dbChangePetList.Add(item.Id)
  1870. }
  1871. this.petList = map[uint32]*serverproto.PetData{}
  1872. this.SetDirty(true)
  1873. this.petChangeNtf(nil, delPetList, nil, false)
  1874. }
  1875. func (this *RolePet) GMPetLevel(petId uint32, petLevel, petAdvLevel int32) {
  1876. petData := this.getPet(petId)
  1877. if petData != nil {
  1878. petData.Level = petLevel
  1879. advCfgData, ok := model.ConvertPetProgress[petData.ConfigId]
  1880. if !ok {
  1881. return
  1882. }
  1883. if petAdvLevel > int32(len(advCfgData.ProgressList)) {
  1884. petAdvLevel = int32(len(advCfgData.ProgressList))
  1885. }
  1886. levelUpLimit := this.getLevelUpLimit(int(petAdvLevel))
  1887. if petLevel >= levelUpLimit {
  1888. petLevel = levelUpLimit
  1889. }
  1890. petData.Level = petLevel
  1891. petData.AdvanceLevel = uint32(petAdvLevel)
  1892. this.SetDirty(true)
  1893. this.dbChangePetList.Add(petId)
  1894. this.petChangeNtf([]*serverproto.PetData{petData}, nil, nil, false)
  1895. }
  1896. }
  1897. func (this *RolePet) GMPetSkillLevel(petId uint32, skillCfgId, skillLevel int32) {
  1898. petData := this.getPet(petId)
  1899. if petData != nil {
  1900. for idx := 0; idx < len(petData.SkillList); idx++ {
  1901. if petData.SkillList[idx].ConfigId == skillCfgId {
  1902. petCfgData, ok := model.ConvertPet[petData.ConfigId]
  1903. if !ok {
  1904. break
  1905. }
  1906. petData.SkillList[idx].Level = skillLevel
  1907. petData.SkillList[idx].Rate = petCfgData.GetSkillRate(skillCfgId, skillLevel)
  1908. this.SetDirty(true)
  1909. this.dbChangePetList.Add(petId)
  1910. this.petChangeNtf([]*serverproto.PetData{petData}, nil, nil, false)
  1911. break
  1912. }
  1913. }
  1914. }
  1915. }
  1916. func (this *RolePet) CheckNewPet(petCfgId int32) bool {
  1917. if petCfgId < 800 {
  1918. return false
  1919. }
  1920. tmpPetID := petCfgId - 800
  1921. if _, ok := this.petManualRewardList[tmpPetID]; ok {
  1922. return false
  1923. }
  1924. return true
  1925. }
  1926. //================================== 宠物冲榜功能 ==================================
  1927. func (this *RolePet) OnlineGetRushPetBaseReward(rewardRound int32) {
  1928. if this.rushPet == nil || rewardRound <= 0 {
  1929. return
  1930. }
  1931. if this.rushPet.ScoreRewardFlag < rewardRound {
  1932. var addItemList = map[int32]int32{}
  1933. model.GetRushActivityBaseReward(this.rushPet.RushRound, model.Rush_Type_Pet, int32(this.rushPet.TotalScore), addItemList)
  1934. if len(addItemList) > 0 {
  1935. this.role.AddMail(model.GlobalMailRushPetBaseReward, serverproto.MailType_MailType_RushPet,
  1936. addItemList, []int32{int32(this.rushPet.TotalScore)}, "", "")
  1937. }
  1938. this.rushPet.ScoreRewardFlag = rewardRound
  1939. this.rushPet.TotalScore = 0
  1940. this.SetDirty(true)
  1941. } else {
  1942. this.rushPet.TotalScore = 0
  1943. this.SetDirty(true)
  1944. }
  1945. }
  1946. func (this *RolePet) OnlineProcess() {
  1947. if this.rushPet == nil {
  1948. return
  1949. }
  1950. /*
  1951. if this.rushPet.RushRound != 0 {
  1952. if rankRound == 0 || (rankRound != 0 && rankRound != this.rushPet.RushRound) {
  1953. if this.rushPet.ScoreRewardFlag == 0 { //参与了SSRushPetInfoChangeNtf
  1954. var addItemList = map[int32]int32{}
  1955. model.GetRushActivityBaseReward(this.rushPet.RushRound, model.Rush_Type_Pet, int32(this.rushPet.TotalScore), addItemList)
  1956. if len(addItemList) > 0 {
  1957. this.role.AddMail(model.GlobalMailRushPetBaseReward, serverproto.MailType_MailType_RushPet,
  1958. addItemList, []int32{int32(this.rushPet.TotalScore)}, "", "")
  1959. }
  1960. }
  1961. this.rushPet.RushRound = rankRound
  1962. this.rushPet.TotalScore = 0
  1963. this.rushPet.ScoreRewardFlag = 0
  1964. this.SetDirty(true)
  1965. }
  1966. }
  1967. */
  1968. //上线处理下,有可能这个人没有参加过。
  1969. this.OnRushPetScoreChange()
  1970. // 上线请求下冲榜是否有历史奖励可以领取
  1971. if this.rushPet != nil {
  1972. if this.rushPet.RushRound != 0 && this.rushPet.RushRound > this.rushPet.ScoreRewardFlag {
  1973. reqMsg := &serverproto.SSGetRushBaseRewardReq{}
  1974. reqMsg.Uid = this.role.GetUUid()
  1975. reqMsg.RushType = model.Rush_Type_Pet
  1976. reqMsg.RushRound = this.rushPet.RushRound
  1977. this.role.SendRank(reqMsg)
  1978. }
  1979. /*
  1980. reqMsg := &serverproto.SSGetRushRankReq{
  1981. Uid: this.role.GetUUid(),
  1982. RushType: model.Rush_Type_Pet,
  1983. RushRound: this.rushPet.RankReward,
  1984. }
  1985. this.role.SendRank(reqMsg)
  1986. */
  1987. }
  1988. }
  1989. //发送到rank服务器验证
  1990. func (this *RolePet) OnRushPetScoreChange() {
  1991. reqMsg := &serverproto.SSRushDataChangeReq{}
  1992. reqMsg.Uid = this.role.GetUUid()
  1993. reqMsg.RushType = model.Rush_Type_Pet
  1994. this.role.SendRank(reqMsg)
  1995. }
  1996. func (this *RolePet) AddRushPetScore(curRound int32) {
  1997. if this.rushPet == nil {
  1998. this.rushPet = &serverproto.RushPet{}
  1999. this.SetDirty(true)
  2000. }
  2001. if curRound == 0 {
  2002. return
  2003. }
  2004. if curRound != this.rushPet.RushRound {
  2005. this.rushPet.RushRound = curRound
  2006. this.rushPet.TotalScore = 0
  2007. }
  2008. //发送到rank
  2009. reqMsg := &serverproto.SSRushPetInfoChangeNtf{}
  2010. if this.role.GetRoleHero() != nil {
  2011. this.role.GetRoleHero().PackHeroRushPetInfo(reqMsg)
  2012. }
  2013. if 0 == reqMsg.TotalScore {
  2014. return
  2015. }
  2016. if uint32(reqMsg.TotalScore) >= this.rushPet.TotalScore {
  2017. this.rushPet.TotalScore = uint32(reqMsg.TotalScore)
  2018. reqMsg.Uid = this.role.GetUUid()
  2019. this.role.SendRank(reqMsg)
  2020. }
  2021. this.SetDirty(true)
  2022. }
  2023. func (this *RolePet) GetBaseScoreReward(ackMsg *serverproto.SCRushActivityRewardAck, rushRound int32) serverproto.ErrorCode {
  2024. if ackMsg == nil {
  2025. return serverproto.ErrorCode_ERROR_FAIL
  2026. }
  2027. if this.rushPet == nil {
  2028. this.rushPet = &serverproto.RushPet{}
  2029. this.SetDirty(true)
  2030. }
  2031. if this.rushPet.ScoreRewardFlag >= rushRound {
  2032. return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH
  2033. }
  2034. var addItemList = map[int32]int32{}
  2035. model.GetRushActivityBaseReward(this.rushPet.RushRound, model.Rush_Type_Pet, int32(this.rushPet.TotalScore), addItemList)
  2036. if len(addItemList) <= 0 {
  2037. return serverproto.ErrorCode_ERROR_FAIL
  2038. }
  2039. for key, value := range addItemList {
  2040. ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
  2041. Key: key,
  2042. Value: value,
  2043. })
  2044. }
  2045. this.role.AddItemList(addItemList, AddFrom_RushPet, true)
  2046. this.rushPet.ScoreRewardFlag = rushRound
  2047. this.SetDirty(true)
  2048. return serverproto.ErrorCode_ERROR_OK
  2049. }
  2050. func (this *RolePet) GetRushPetRankReward(ssAck *serverproto.SSGetRushRewardAck) serverproto.ErrorCode {
  2051. if ssAck == nil {
  2052. return serverproto.ErrorCode_ERROR_FAIL
  2053. }
  2054. if this.rushPet == nil {
  2055. this.rushPet = &serverproto.RushPet{}
  2056. this.SetDirty(true)
  2057. }
  2058. if this.rushPet.RankReward >= ssAck.RushRound {
  2059. return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH
  2060. }
  2061. var addItemList = map[int32]int32{}
  2062. for _, data := range ssAck.ItemList {
  2063. addItemList[data.Key] += data.Value
  2064. }
  2065. this.role.AddItemList(addItemList, AddFrom_RushPet, true)
  2066. this.rushPet.RankReward = ssAck.RushRound
  2067. this.SetDirty(true)
  2068. return serverproto.ErrorCode_ERROR_OK
  2069. }
  2070. func (this *RolePet) GetRushPetInfo(ackMsg *serverproto.SCPetActivityAck, curRound int32) {
  2071. if ackMsg == nil {
  2072. return
  2073. }
  2074. if this.rushPet == nil {
  2075. this.rushPet = &serverproto.RushPet{}
  2076. this.SetDirty(true)
  2077. }
  2078. // ackMsg.SelfScore = this.rushPet.TotalScore
  2079. ackMsg.RankReward = false
  2080. if this.rushPet.RankReward == curRound {
  2081. ackMsg.RankReward = true
  2082. }
  2083. ackMsg.ChallengReward = false
  2084. if this.rushPet.ScoreRewardFlag >= curRound {
  2085. ackMsg.ChallengReward = true
  2086. }
  2087. }
  2088. func (this *RolePet) CheckRankReward(finishRound int32) serverproto.ErrorCode {
  2089. if this.rushPet == nil {
  2090. this.rushPet = &serverproto.RushPet{}
  2091. this.SetDirty(true)
  2092. }
  2093. if this.rushPet.RankReward >= finishRound {
  2094. return serverproto.ErrorCode_ERROR_FAIL
  2095. }
  2096. return serverproto.ErrorCode_ERROR_OK
  2097. }
  2098. func (this *RolePet) SetRankReward(finishRound int32) {
  2099. if this.rushPet == nil {
  2100. this.rushPet = &serverproto.RushPet{}
  2101. this.SetDirty(true)
  2102. }
  2103. this.rushPet.RankReward = finishRound
  2104. this.SetDirty(true)
  2105. }
  2106. func (this *RolePet) GetFightCountMailReward(rushRound int32) {
  2107. if this.rushPet == nil {
  2108. this.rushPet = &serverproto.RushPet{}
  2109. this.SetDirty(true)
  2110. }
  2111. if this.rushPet.ScoreRewardFlag < rushRound {
  2112. var addItemList = map[int32]int32{}
  2113. model.GetRushActivityBaseReward(this.rushPet.RushRound, model.Rush_Type_Pet, int32(this.rushPet.TotalScore), addItemList)
  2114. if len(addItemList) > 0 {
  2115. this.role.AddMail(model.GlobalMailRushPetBaseReward, serverproto.MailType_MailType_RushPet,
  2116. addItemList, []int32{int32(this.rushPet.TotalScore)}, "", "")
  2117. }
  2118. this.rushPet.ScoreRewardFlag = rushRound
  2119. this.rushPet.TotalScore = 0
  2120. this.SetDirty(true)
  2121. }
  2122. }
  2123. func (this *RolePet) GetPetJobType(petId uint32) int32 {
  2124. petData := this.getPet(petId)
  2125. if petData == nil {
  2126. return -1
  2127. }
  2128. petCfgData, ok := model.ConvertPet[petData.ConfigId]
  2129. if !ok {
  2130. return -1
  2131. }
  2132. return petCfgData.JobType
  2133. }
  2134. func (this *RolePet) BattleAttrChange(petData *serverproto.PetData,
  2135. attrType *serverproto.ActorAttrType, petFightPower uint64) {
  2136. petData.BattleAttrList = attrType.AttrList
  2137. oldPetFightPower := petData.PetFightPower
  2138. petData.PetFightPower = uint32(petFightPower / 10)
  2139. this.SetDirty(true)
  2140. //db save
  2141. this.dbChangePetList.Add(petData.Id)
  2142. util.InfoF("uid=%v petId=%v oldPetFightPower=%v newCalFightPower=%v",
  2143. this.role.GetUUid(), petData.Id, oldPetFightPower, petFightPower/10)
  2144. //if petData.HeroId <= 0 {
  2145. if oldPetFightPower != petData.PetFightPower {
  2146. //通知单位战力变更
  2147. ntfMsg := &serverproto.SCFightPowerChagneNtf{
  2148. Data: &serverproto.FightPowerData{},
  2149. }
  2150. slotFightPower := &serverproto.SlotFightPower{
  2151. HeroId: int32(petData.Id),
  2152. PetFightPower: uint64(petData.PetFightPower),
  2153. }
  2154. ntfMsg.Data.ActorFightpower = append(ntfMsg.Data.ActorFightpower, slotFightPower)
  2155. this.role.ReplayGate(ntfMsg, true)
  2156. }
  2157. //}
  2158. }
  2159. func (this *RolePet) petJuexingDataChangeNtf(heroData *serverproto.HeroData) {
  2160. this.role.GetRoleHero().addHeroChange(heroData.Id)
  2161. ntfMsg := &serverproto.SCPetQiyueDataNtf{
  2162. HeroId: heroData.Id,
  2163. QiyueInfo: heroData.PetQiyueData,
  2164. }
  2165. this.role.ReplayGate(ntfMsg, true)
  2166. //觉醒导致属性变更处理
  2167. changePetData := this.getPet(heroData.BattlePetId)
  2168. if changePetData != nil && heroData.PetQiyueData != nil && len(heroData.PetQiyueData.QiyueSlotList) > 0 {
  2169. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  2170. IsPet: true,
  2171. ChangePetData: changePetData,
  2172. ChangeType: Attr_Change_Pet_Qiyue,
  2173. })
  2174. }
  2175. }
  2176. func (this *RolePet) petQiyueUnlockCost(slotIdx int32) serverproto.KeyValueType {
  2177. if slotIdx <= 0 {
  2178. util.FatalF("uid=%v petQiyueUnlockCost slotIdx Failed slotIdx=%v", this.role.GetUUid(), slotIdx)
  2179. return serverproto.KeyValueType{}
  2180. }
  2181. costLen := len(model.GlobalPetQiyueUnlockCost)
  2182. if costLen >= int(slotIdx) {
  2183. return model.GlobalPetQiyueUnlockCost[slotIdx-1]
  2184. } else {
  2185. costLen := len(model.GlobalPetQiyueUnlockCost)
  2186. if costLen > 0 {
  2187. return model.GlobalPetQiyueUnlockCost[costLen-1]
  2188. }
  2189. }
  2190. util.FatalF("uid=%v petQiyueUnlockCost GlobalPetQiyueUnlockCost empty slotIdx=%v", this.role.GetUUid(), slotIdx)
  2191. return serverproto.KeyValueType{}
  2192. }
  2193. func (this *RolePet) PetQiyueUnlock(heroId int32) serverproto.ErrorCode {
  2194. heroData := this.role.GetRoleHero().GetHero(heroId)
  2195. if heroData == nil {
  2196. return serverproto.ErrorCode_ERROR_HERO_NO_FOUND
  2197. }
  2198. var unlockCost serverproto.KeyValueType
  2199. if heroData.PetQiyueData == nil {
  2200. //解锁第一个槽位
  2201. //判断资源消耗
  2202. unlockCost = this.petQiyueUnlockCost(1)
  2203. if !this.role.GetRoleBag().CanDelItem(unlockCost.Key, unlockCost.Value) {
  2204. return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_UNLOCK_RES
  2205. }
  2206. heroData.PetQiyueData = &serverproto.PetQiyueInfo{
  2207. PetId: heroData.BattlePetId,
  2208. }
  2209. } else {
  2210. //解锁槽位数量已达上限
  2211. if len(heroData.PetQiyueData.QiyueSlotList) >= model.GlobalPetQiyueMaxSlotNum {
  2212. return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_UNLOCK_NUM_LIMIT
  2213. }
  2214. //判断资源消耗
  2215. unlockCost = this.petQiyueUnlockCost(int32(len(heroData.PetQiyueData.QiyueSlotList) + 1))
  2216. if !this.role.GetRoleBag().CanDelItem(unlockCost.Key, unlockCost.Value) {
  2217. return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_UNLOCK_RES
  2218. }
  2219. }
  2220. this.role.GetRoleBag().DelItem(unlockCost.Key, unlockCost.Value, AddItemST{
  2221. AddFrom: AddFrom_PetJuexing,
  2222. Notify: true,
  2223. })
  2224. heroData.PetQiyueData.QiyueSlotList = append(heroData.PetQiyueData.QiyueSlotList,
  2225. &serverproto.PetQiyueSlotInfo{
  2226. SlotIdx: int32(len(heroData.PetQiyueData.QiyueSlotList) + 1),
  2227. })
  2228. this.SetDirty(true)
  2229. this.petJuexingDataChangeNtf(heroData)
  2230. util.InfoF("uid=%v PetQiyueUnlock heroid=%v slotIdx=%v", this.role.GetUUid(),
  2231. heroId, len(heroData.PetQiyueData.QiyueSlotList)-1)
  2232. return serverproto.ErrorCode_ERROR_OK
  2233. }
  2234. func (this *RolePet) getQiyueSlotInfoBySlot(heroData *serverproto.HeroData, slotIdx int32) *serverproto.PetQiyueSlotInfo {
  2235. for idx := 0; idx < len(heroData.PetQiyueData.QiyueSlotList); idx++ {
  2236. if heroData.PetQiyueData.QiyueSlotList[idx].SlotIdx == slotIdx {
  2237. return heroData.PetQiyueData.QiyueSlotList[idx]
  2238. }
  2239. }
  2240. return nil
  2241. }
  2242. func (this *RolePet) getQiyueSlotInfoByPetID(heroData *serverproto.HeroData, petId uint32) *serverproto.PetQiyueSlotInfo {
  2243. for idx := 0; idx < len(heroData.PetQiyueData.QiyueSlotList); idx++ {
  2244. if heroData.PetQiyueData.QiyueSlotList[idx].PetId == petId {
  2245. return heroData.PetQiyueData.QiyueSlotList[idx]
  2246. }
  2247. }
  2248. return nil
  2249. }
  2250. func (this *RolePet) PetQiyueSlotIn(heroId, slotIdx int32, petId uint32) serverproto.ErrorCode {
  2251. heroData := this.role.GetRoleHero().GetHero(heroId)
  2252. if heroData == nil {
  2253. return serverproto.ErrorCode_ERROR_HERO_NO_FOUND
  2254. }
  2255. if heroData.PetQiyueData == nil {
  2256. return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_INVALID
  2257. }
  2258. //判断槽位是否存在
  2259. if len(heroData.PetQiyueData.QiyueSlotList) < int(slotIdx) {
  2260. return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_INVALID
  2261. }
  2262. petData := this.getPet(petId)
  2263. if petData == nil {
  2264. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  2265. }
  2266. //出阵宠物无法放入觉醒槽位
  2267. if petData.HeroId > 0 {
  2268. return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_PET_INVALID
  2269. }
  2270. if petData.QiyueHeroId > 0 {
  2271. //在同一个上阵宠物上
  2272. if petData.QiyueHeroId == heroId {
  2273. slotIdxInfo := this.getQiyueSlotInfoByPetID(heroData, petId)
  2274. if slotIdxInfo != nil {
  2275. //判断是否在同一个槽位
  2276. if slotIdxInfo.SlotIdx == slotIdx {
  2277. util.InfoF("uid=%v PetQiyueSlotIn slot put same pet")
  2278. return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_PET_INVALID
  2279. }
  2280. slotIdxInfo.PetId = 0
  2281. slotIdxInfo.PetCfgId = 0
  2282. petData.QiyueHeroId = 0
  2283. this.dbChangePetList.Add(petId)
  2284. this.SetDirty(true)
  2285. }
  2286. } else {
  2287. //先下阵
  2288. oldHeroData := this.role.GetRoleHero().GetHero(petData.QiyueHeroId)
  2289. if oldHeroData != nil {
  2290. slotIdxInfo := this.getQiyueSlotInfoByPetID(oldHeroData, petId)
  2291. if slotIdxInfo != nil {
  2292. slotIdxInfo.PetId = 0
  2293. slotIdxInfo.PetCfgId = 0
  2294. this.SetDirty(true)
  2295. util.InfoF("uid=%v PetQiyueSlotIn out old heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(),
  2296. oldHeroData.Id, slotIdxInfo.SlotIdx, petId)
  2297. this.petJuexingDataChangeNtf(oldHeroData)
  2298. }
  2299. }
  2300. petData.QiyueHeroId = 0
  2301. this.dbChangePetList.Add(petId)
  2302. this.SetDirty(true)
  2303. }
  2304. }
  2305. slotIdxInfo := this.getQiyueSlotInfoBySlot(heroData, slotIdx)
  2306. if slotIdxInfo != nil {
  2307. var changPetDataList []*serverproto.PetData
  2308. //当前位置上已经有宠物,下阵
  2309. if slotIdxInfo.PetId > 0 {
  2310. slotPetData := this.getPet(slotIdxInfo.PetId)
  2311. if slotPetData != nil {
  2312. util.InfoF("uid=%v PetQiyueSlotIn out old heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(),
  2313. heroData.Id, slotIdx, slotIdxInfo.PetId)
  2314. slotPetData.QiyueHeroId = 0
  2315. this.dbChangePetList.Add(slotIdxInfo.PetId)
  2316. this.SetDirty(true)
  2317. changPetDataList = append(changPetDataList, slotPetData)
  2318. }
  2319. }
  2320. slotIdxInfo.PetId = petData.Id
  2321. slotIdxInfo.PetCfgId = petData.ConfigId
  2322. petData.QiyueHeroId = heroData.Id
  2323. this.dbChangePetList.Add(petId)
  2324. this.SetDirty(true)
  2325. changPetDataList = append(changPetDataList, petData)
  2326. util.InfoF("uid=%v PetQiyueSlotIn in heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(),
  2327. heroData.Id, slotIdx, slotIdxInfo.PetId)
  2328. this.petChangeNtf(changPetDataList, nil, nil, false)
  2329. this.petJuexingDataChangeNtf(heroData)
  2330. return serverproto.ErrorCode_ERROR_OK
  2331. } else {
  2332. return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_INVALID
  2333. }
  2334. }
  2335. func (this *RolePet) PetQiyueSlotOut(heroId, slotIdx int32) serverproto.ErrorCode {
  2336. heroData := this.role.GetRoleHero().GetHero(heroId)
  2337. if heroData == nil {
  2338. return serverproto.ErrorCode_ERROR_HERO_NO_FOUND
  2339. }
  2340. if heroData.PetQiyueData == nil {
  2341. return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_INVALID
  2342. }
  2343. //操作具体的槽位
  2344. if slotIdx > 0 {
  2345. bFind := false
  2346. for idx := 0; idx < len(heroData.PetQiyueData.QiyueSlotList); idx++ {
  2347. if heroData.PetQiyueData.QiyueSlotList[idx].SlotIdx == slotIdx {
  2348. if heroData.PetQiyueData.QiyueSlotList[idx].PetId <= 0 {
  2349. break
  2350. }
  2351. tmpPetId := heroData.PetQiyueData.QiyueSlotList[idx].PetId
  2352. heroData.PetQiyueData.QiyueSlotList[idx].PetId = 0
  2353. heroData.PetQiyueData.QiyueSlotList[idx].PetCfgId = 0
  2354. tmpPetData := this.getPet(tmpPetId)
  2355. if tmpPetData != nil {
  2356. util.InfoF("uid=%v PetQiyueSlotOut in heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(),
  2357. heroId, slotIdx, tmpPetId)
  2358. tmpPetData.QiyueHeroId = 0
  2359. this.dbChangePetList.Add(tmpPetId)
  2360. this.petChangeNtf([]*serverproto.PetData{tmpPetData}, nil, nil, false)
  2361. }
  2362. this.SetDirty(true)
  2363. bFind = true
  2364. util.InfoF("uid=%v PetQiyueSlotOut heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(), heroId, slotIdx, tmpPetId)
  2365. break
  2366. }
  2367. }
  2368. if !bFind {
  2369. return serverproto.ErrorCode_ERROR_PET_QIYUE_SLOT_INVALID
  2370. }
  2371. this.petJuexingDataChangeNtf(heroData)
  2372. } else {
  2373. //一键卸下做为觉醒材料的宠物
  2374. var ntfPetDataList []*serverproto.PetData
  2375. for idx := 0; idx < len(heroData.PetQiyueData.QiyueSlotList); idx++ {
  2376. tmpPetId := heroData.PetQiyueData.QiyueSlotList[idx].PetId
  2377. if tmpPetId <= 0 {
  2378. continue
  2379. }
  2380. heroData.PetQiyueData.QiyueSlotList[idx].PetId = 0
  2381. heroData.PetQiyueData.QiyueSlotList[idx].PetCfgId = 0
  2382. tmpPetData := this.getPet(tmpPetId)
  2383. if tmpPetData != nil {
  2384. tmpPetData.QiyueHeroId = 0
  2385. this.dbChangePetList.Add(tmpPetId)
  2386. ntfPetDataList = append(ntfPetDataList, tmpPetData)
  2387. }
  2388. this.SetDirty(true)
  2389. util.InfoF("uid=%v PetQiyueSlotOut heroId=%v slotIdx=%v petId=%v", this.role.GetUUid(), heroId,
  2390. heroData.PetQiyueData.QiyueSlotList[idx].SlotIdx, tmpPetId)
  2391. }
  2392. if len(ntfPetDataList) > 0 {
  2393. this.petChangeNtf(ntfPetDataList, nil, nil, false)
  2394. this.petJuexingDataChangeNtf(heroData)
  2395. }
  2396. }
  2397. return serverproto.ErrorCode_ERROR_OK
  2398. }
  2399. //当前宠物是否在宠物契约槽内
  2400. func (this *RolePet) IsPetInQiyueSlot(petId uint32) (uint32, bool) {
  2401. petData := this.getPet(petId)
  2402. if petData != nil && petData.QiyueHeroId > 0 {
  2403. if petData.HeroId > 0 {
  2404. util.ErrorF("uid=%v IsPetInQiyueSlot pet in battle heroid=%v", petData.HeroId)
  2405. return 0, false
  2406. }
  2407. heroData := this.role.GetRoleHero().GetHero(petData.QiyueHeroId)
  2408. if heroData != nil {
  2409. return heroData.BattlePetId, true
  2410. }
  2411. return 0, false
  2412. }
  2413. return 0, false
  2414. }
  2415. func (this *RolePet) PetQiyueBattlePetAttr() serverproto.ErrorCode {
  2416. var attrTypeList []*serverproto.ActorAttrType
  2417. var battlePetList []*serverproto.PetData
  2418. this.role.GetRoleHero().GetBattlePetList(&battlePetList)
  2419. for idx := 0; idx < len(battlePetList); idx++ {
  2420. attrTypeList = append(attrTypeList,
  2421. &serverproto.ActorAttrType{
  2422. ActorId: battlePetList[idx].Id,
  2423. })
  2424. }
  2425. this.role.roleBattleAttr.GetActorQiyueAttr(attrTypeList)
  2426. ackMsg := &serverproto.SCPetQiyueBattlePetAttrAck{
  2427. Error: int32(serverproto.ErrorCode_ERROR_OK),
  2428. ActorList: attrTypeList,
  2429. }
  2430. this.role.ReplayGate(ackMsg, true)
  2431. return serverproto.ErrorCode_ERROR_OK
  2432. }