role_pet_equip.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. package model
  2. import (
  3. "rocommon/util"
  4. "roserver/baseserver/model"
  5. "roserver/serverproto"
  6. )
  7. func (this *Role) PetEquipLevelUp(petEquipId uint32) {
  8. if this.rolePet != nil {
  9. ret := this.rolePet.PetEquipLevelUp(petEquipId)
  10. ackMsg := &serverproto.SCPetEquipLevelUpAck{
  11. Error: int32(ret),
  12. }
  13. this.ReplayGate(ackMsg, true)
  14. }
  15. }
  16. func (this *Role) PetEquipUp(petId uint32, slotIndexList []*serverproto.KeyValueType) {
  17. if this.rolePet != nil {
  18. ret := this.rolePet.PetEquipUp(petId, slotIndexList)
  19. ackMsg := &serverproto.SCPetEquipUPAck{
  20. Error: int32(ret),
  21. PetId: petId,
  22. SlotList: slotIndexList,
  23. }
  24. this.ReplayGate(ackMsg, true)
  25. }
  26. }
  27. func (this *Role) PetEquipDown(petId uint32, slotIndex int32) {
  28. if this.rolePet != nil {
  29. ret := this.rolePet.PetEquipDown(petId, slotIndex)
  30. ackMsg := &serverproto.SCPetEquipDownAck{
  31. Error: int32(ret),
  32. PetId: petId,
  33. SlotIndex: slotIndex,
  34. }
  35. this.ReplayGate(ackMsg, true)
  36. }
  37. }
  38. const PetEquipSlotNum = 6 //印记格子最大数量
  39. func (this *RolePet) GetPetEquip(petEquipId uint32) *serverproto.PetEquipData {
  40. petEquipData, ok := this.petEquipList[petEquipId]
  41. if ok {
  42. return petEquipData
  43. }
  44. return nil
  45. }
  46. func (this *RolePet) petEquipChangeNtf(changeData []*serverproto.PetEquipData, ignore bool) {
  47. ntfMsg := &serverproto.SCPetEquipDataNtf{
  48. PetEquipList: changeData,
  49. Ignore: ignore,
  50. }
  51. this.role.ReplayGate(ntfMsg, true)
  52. }
  53. //印记是否已经装备到宠物
  54. func (this *RolePet) isEquipUp(petEquipId uint32) bool {
  55. petEquipData := this.GetPetEquip(petEquipId)
  56. if petEquipData == nil {
  57. return false
  58. }
  59. return petEquipData.EquipPetId > 0
  60. }
  61. func (this *RolePet) AddPetEquip(petCfgEquipId, petEquipLevel int32, bNotify bool) *serverproto.PetEquipData {
  62. _, ok := model.ConvertPetEquip[petCfgEquipId]
  63. if !ok {
  64. util.ErrorF("uid=%v AddPetEquip equip data not find!!!", this.role.GetUUid(), petCfgEquipId)
  65. return nil
  66. }
  67. //id复用之前添加宠物字段
  68. this.maxPetId++
  69. petEquip := &serverproto.PetEquipData{
  70. Id: uint32(this.maxPetId),
  71. EquipCfgId: petCfgEquipId,
  72. Level: petEquipLevel, //默认一级
  73. }
  74. this.petEquipList[petEquip.Id] = petEquip
  75. this.dbChangePetEquipList.Add(petEquip.Id)
  76. this.SetDirty(true)
  77. util.InfoF("uid=%v AddPetEquip petEquipCfgId=%v id=%v", this.role.GetUUid(), petCfgEquipId, this.maxPetId)
  78. if bNotify {
  79. this.petEquipChangeNtf([]*serverproto.PetEquipData{petEquip}, false)
  80. }
  81. return petEquip
  82. }
  83. func (this *RolePet) AddPetEquipList(petCfgEquipId, count int32, petEquipLevel int32, ignore bool) {
  84. var ntfDataList []*serverproto.PetEquipData
  85. for idx := 0; idx < int(count); idx++ {
  86. petEquipData := this.AddPetEquip(petCfgEquipId, petEquipLevel, false)
  87. if petEquipData != nil {
  88. ntfDataList = append(ntfDataList, petEquipData)
  89. }
  90. }
  91. if len(ntfDataList) > 0 {
  92. this.petEquipChangeNtf(ntfDataList, ignore)
  93. }
  94. }
  95. func (this *RolePet) AddPetEquipByMapList(addList map[int32]int32, bNotify bool) {
  96. var ntfDataList []*serverproto.PetEquipData
  97. for key, val := range addList {
  98. for idx := 0; idx < int(val); idx++ {
  99. petEquipData := this.AddPetEquip(key, 1, false)
  100. if petEquipData != nil {
  101. ntfDataList = append(ntfDataList, petEquipData)
  102. }
  103. }
  104. }
  105. if len(ntfDataList) > 0 && bNotify {
  106. this.petEquipChangeNtf(ntfDataList, false)
  107. }
  108. }
  109. func (this *RolePet) PetEquipLevelUp(petEquipId uint32) serverproto.ErrorCode {
  110. petEquipData := this.GetPetEquip(petEquipId)
  111. if petEquipData == nil {
  112. return serverproto.ErrorCode_ERROR_PET_EQUIP_NOT_EXIST
  113. }
  114. cfgData, ok := model.ConvertPetEquip[petEquipData.EquipCfgId]
  115. if !ok {
  116. util.ErrorF("uid=%v EquipLevelUp equip data not find!!!", this.role.GetUUid(), petEquipId)
  117. return serverproto.ErrorCode_ERROR_PET_EQUIP_NOT_EXIST
  118. }
  119. if petEquipData.Level >= cfgData.MaxLevel {
  120. //进阶处理
  121. //advance
  122. if cfgData.AdvanceTargetEquip <= 0 {
  123. return serverproto.ErrorCode_ERROR_PET_EQUIP_MAX_LEVEL
  124. }
  125. if !this.role.GetRoleBag().CanDelItemList(cfgData.AdvanceCost) {
  126. return serverproto.ErrorCode_ERROR_PET_ADVANCE_COST
  127. }
  128. this.role.GetRoleBag().DelItemList(cfgData.AdvanceCost, AddItemST{AddFrom: AddFrom_PetEquip})
  129. petEquipData.Level = 1
  130. petEquipData.EquipCfgId = cfgData.AdvanceTargetEquip
  131. util.InfoF("uid=%v PetEquipLevelUp id=%v oldcfgId=%v newcfgId=%v", petEquipData.Id,
  132. cfgData.CfgId, cfgData.AdvanceTargetEquip)
  133. TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Battle_Quality_cnt, 1)
  134. } else {
  135. //levelup
  136. levelUpCfgData, ok := cfgData.LevelUpList[petEquipData.Level]
  137. if !ok {
  138. util.ErrorF("uid=%v EquipLevelUp equip data not find!!!", this.role.GetUUid(), petEquipId)
  139. return serverproto.ErrorCode_ERROR_PET_EQUIP_NOT_EXIST
  140. }
  141. if !this.role.GetRoleBag().CanDelItemList(levelUpCfgData.CostList) {
  142. return serverproto.ErrorCode_ERROR_PET_EQUIPLEVELUP_COST
  143. }
  144. this.role.GetRoleBag().DelItemList(levelUpCfgData.CostList, AddItemST{AddFrom: AddFrom_PetEquip})
  145. petEquipData.Level++
  146. }
  147. this.SetDirty(true)
  148. this.petEquipChangeNtf([]*serverproto.PetEquipData{petEquipData}, false)
  149. //属性计算 AttrChange
  150. if petEquipData.EquipPetId > 0 {
  151. petData := this.getPet(petEquipData.EquipPetId)
  152. //bFightChangeNotNotify := true
  153. //if petData != nil && petData.HeroId > 0 {
  154. // bFightChangeNotNotify = false
  155. //}
  156. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  157. IsPet: true,
  158. ChangeType: Attr_Change_Pet_Equip,
  159. ChangePetData: petData,
  160. //FightChangeNotNotify: bFightChangeNotNotify,
  161. })
  162. }
  163. //petData := this.getPet(petEquipData.EquipPetId)
  164. //if petData != nil && petData.HeroId != 0 {
  165. // heroData := this.role.GetRoleHero().GetHero(petData.HeroId)
  166. // if heroData != nil {
  167. // this.role.GetRoleFightPower().CalcPetEquipFightPower(heroData.Id, petData.Id, false)
  168. // }
  169. //
  170. //}
  171. petData := this.getPet(petEquipData.EquipPetId)
  172. if petData != nil {
  173. this.petChangeNtf([]*serverproto.PetData{petData}, nil, nil, false)
  174. }
  175. return serverproto.ErrorCode_ERROR_OK
  176. }
  177. func (this *RolePet) PetEquipUp(petId uint32, slotIndexList []*serverproto.KeyValueType) serverproto.ErrorCode {
  178. petData := this.getPet(petId)
  179. if petData == nil {
  180. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  181. }
  182. if len(slotIndexList) <= 0 {
  183. return serverproto.ErrorCode_ERROR_FAIL
  184. }
  185. var changePetEquipData []*serverproto.PetEquipData
  186. for idx := 0; idx < len(slotIndexList); idx++ {
  187. if slotIndexList[idx].Key <= 0 || slotIndexList[idx].Value <= 0 ||
  188. slotIndexList[idx].Key > PetEquipSlotNum {
  189. continue
  190. }
  191. petEquipData := this.GetPetEquip(uint32(slotIndexList[idx].Value))
  192. if petEquipData == nil {
  193. continue
  194. }
  195. cfgData, ok := model.ConvertPetEquip[petEquipData.EquipCfgId]
  196. if !ok {
  197. continue
  198. }
  199. if cfgData.Type != slotIndexList[idx].Key {
  200. continue
  201. }
  202. //当前印记已经装备
  203. if petEquipData.EquipPetId > 0 {
  204. continue
  205. }
  206. bFindSlotIdx := false
  207. for _, slot := range petData.SlotEquipList {
  208. if slot.Idx == slotIndexList[idx].Key {
  209. //已经装备的印记卸下
  210. if slot.EquipId > 0 {
  211. downEquip := this.petEquipDown(slot.EquipId)
  212. if downEquip != nil {
  213. changePetEquipData = append(changePetEquipData, downEquip)
  214. }
  215. slot.EquipId = 0
  216. }
  217. //装备新印记
  218. slot.EquipId = petEquipData.Id
  219. petEquipData.EquipPetId = petData.Id
  220. this.SetDirty(true)
  221. this.dbChangePetEquipList.Add(petEquipData.Id)
  222. changePetEquipData = append(changePetEquipData, petEquipData)
  223. bFindSlotIdx = true
  224. break
  225. }
  226. }
  227. //装备新印记
  228. if !bFindSlotIdx {
  229. petData.SlotEquipList = append(petData.SlotEquipList,
  230. &serverproto.PetSlotDetailData{
  231. Idx: slotIndexList[idx].Key,
  232. EquipId: petEquipData.Id,
  233. })
  234. petEquipData.EquipPetId = petData.Id
  235. this.SetDirty(true)
  236. this.dbChangePetEquipList.Add(petEquipData.Id)
  237. changePetEquipData = append(changePetEquipData, petEquipData)
  238. }
  239. }
  240. //equip ntf
  241. this.petEquipChangeNtf(changePetEquipData, false)
  242. if len(changePetEquipData) > 0 {
  243. this.dbChangePetList.Add(petData.Id)
  244. //slot ntf
  245. this.petChangeNtf([]*serverproto.PetData{petData}, nil, nil, false)
  246. ////属性计算 AttrChange
  247. //bFightChangeNotNotify := true
  248. //if petData.HeroId > 0 {
  249. // bFightChangeNotNotify = false
  250. //}
  251. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  252. IsPet: true,
  253. ChangeType: Attr_Change_Pet_Equip,
  254. ChangePetData: petData,
  255. //FightChangeNotNotify: bFightChangeNotNotify,
  256. })
  257. TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Battle_Quality_cnt, 1)
  258. }
  259. //if petData.HeroId != 0 {
  260. // heroData := this.role.GetRoleHero().GetHero(petData.HeroId)
  261. // if heroData != nil {
  262. // this.role.GetRoleFightPower().CalcPetEquipFightPower(heroData.Id, petData.Id, false)
  263. // }
  264. //}
  265. return serverproto.ErrorCode_ERROR_OK
  266. }
  267. func (this *RolePet) PetEquipDown(petId uint32, slotIndex int32) serverproto.ErrorCode {
  268. petData := this.getPet(petId)
  269. if petData == nil {
  270. return serverproto.ErrorCode_ERROR_PET_NOT_FOUND
  271. }
  272. if slotIndex > PetEquipSlotNum {
  273. return serverproto.ErrorCode_ERROR_OK
  274. }
  275. var changePetEquipData []*serverproto.PetEquipData
  276. //一键卸下
  277. if slotIndex <= 0 {
  278. for _, slotIdx := range petData.SlotEquipList {
  279. if slotIdx.EquipId > 0 {
  280. downEquip := this.petEquipDown(slotIdx.EquipId)
  281. if downEquip != nil {
  282. changePetEquipData = append(changePetEquipData, downEquip)
  283. }
  284. slotIdx.EquipId = 0
  285. this.SetDirty(true)
  286. }
  287. }
  288. if len(changePetEquipData) > 0 {
  289. this.dbChangePetList.Add(petData.Id)
  290. }
  291. } else {
  292. for _, slotIdx := range petData.SlotEquipList {
  293. if slotIdx.Idx != slotIndex {
  294. continue
  295. }
  296. if slotIdx.EquipId > 0 {
  297. downEquip := this.petEquipDown(slotIdx.EquipId)
  298. if downEquip != nil {
  299. changePetEquipData = append(changePetEquipData, downEquip)
  300. this.dbChangePetEquipList.Add(downEquip.Id)
  301. }
  302. slotIdx.EquipId = 0
  303. this.SetDirty(true)
  304. }
  305. break
  306. }
  307. }
  308. if len(changePetEquipData) > 0 {
  309. //equip ntf
  310. this.petEquipChangeNtf(changePetEquipData, false)
  311. //slot ntf
  312. this.petChangeNtf([]*serverproto.PetData{petData}, nil, nil, false)
  313. this.dbChangePetList.Add(petData.Id)
  314. //属性计算 AttrChange
  315. //bFightChangeNotNotify := true
  316. //if petData.HeroId > 0 {
  317. // bFightChangeNotNotify = false
  318. //}
  319. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  320. IsPet: true,
  321. ChangeType: Attr_Change_Pet_Equip,
  322. ChangePetData: petData,
  323. //FightChangeNotNotify: bFightChangeNotNotify,
  324. })
  325. TaskMagCheck(this.role, serverproto.TaskType_Eve_Pet_Battle_Quality_cnt, 1)
  326. }
  327. //if petData.HeroId != 0 {
  328. // heroData := this.role.GetRoleHero().GetHero(petData.HeroId)
  329. // if heroData != nil {
  330. // this.role.GetRoleFightPower().CalcPetEquipFightPower(heroData.Id, petData.Id, false)
  331. // }
  332. //}
  333. return serverproto.ErrorCode_ERROR_OK
  334. }
  335. func (this *RolePet) petEquipDown(petEquipId uint32) *serverproto.PetEquipData {
  336. petEquipData := this.GetPetEquip(petEquipId)
  337. if petEquipData == nil {
  338. return nil
  339. }
  340. petEquipData.EquipPetId = 0
  341. this.SetDirty(true)
  342. this.dbChangePetEquipList.Add(petEquipData.Id)
  343. return petEquipData
  344. }