role_skill_equip.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. package model
  2. import (
  3. "math/rand"
  4. //"math/rand"
  5. "rocommon/util"
  6. "roserver/baseserver/model"
  7. "roserver/baseserver/set"
  8. "roserver/serverproto"
  9. )
  10. type RoleSkillEquip struct {
  11. SaveObject
  12. maxEquipId uint32
  13. // skillEquipId skillEquip
  14. skillEquipList map[uint32]*serverproto.SkillEquipData
  15. //skillEquipTypeList map[int32]set.Interface
  16. dbChangeSkillEquipList set.Interface
  17. }
  18. func newRoleSkillEquip(r *Role) *RoleSkillEquip {
  19. roleSkillEquip := &RoleSkillEquip{
  20. SaveObject: SaveObject{
  21. role: r,
  22. },
  23. }
  24. roleSkillEquip.skillEquipList = make(map[uint32]*serverproto.SkillEquipData)
  25. roleSkillEquip.dbChangeSkillEquipList = set.New(set.NonThreadSafe)
  26. return roleSkillEquip
  27. }
  28. func (this *RoleSkillEquip) CopyData(data *serverproto.RoleSkillEquip) {
  29. for _, equip := range this.skillEquipList {
  30. data.SkillEquipList = append(data.SkillEquipList, equip)
  31. }
  32. }
  33. func (this *RoleSkillEquip) Load(msg interface{}) bool {
  34. proRole := msg.(*serverproto.Role)
  35. if proRole.RoleSkillEquip != nil {
  36. this.maxEquipId = proRole.RoleSkillEquip.MaxSkillEquipId
  37. for _, data := range proRole.RoleSkillEquip.SkillEquipList {
  38. this.skillEquipList[data.Id] = data
  39. }
  40. }
  41. util.DebugF("uid=%v RoleSkillEquip ", this.role.GetUUid())
  42. return true
  43. }
  44. func (this *RoleSkillEquip) Save() {
  45. this.SetDirty(false)
  46. util.DebugF("uid=%v RoleSkillEquip save...", this.role.GetUUid())
  47. if this.dbChangeSkillEquipList.Size() > 0 {
  48. saveMsg := &serverproto.SSSkillEquipDataSaveReq{
  49. SkillEquip: &serverproto.RoleSkillEquip{},
  50. }
  51. changList := this.dbChangeSkillEquipList.List()
  52. for idx := 0; idx < len(changList); idx++ {
  53. skillEquipId := changList[idx].(uint32)
  54. skillEquip := this.GetSkillEquip(skillEquipId)
  55. if skillEquip == nil {
  56. saveMsg.SkillEquipDelList = append(saveMsg.SkillEquipDelList, skillEquipId)
  57. } else {
  58. saveMsg.SkillEquip.SkillEquipList = append(saveMsg.SkillEquip.SkillEquipList, skillEquip)
  59. }
  60. }
  61. this.dbChangeSkillEquipList.Clear()
  62. saveMsg.SkillEquip.MaxSkillEquipId = this.maxEquipId
  63. //for _, data := range this.skillEquipList {
  64. // saveMsg.SkillEquip.SkillEquipList = append(saveMsg.SkillEquip.SkillEquipList, data)
  65. //}
  66. this.role.SendDb(saveMsg)
  67. }
  68. }
  69. func (this *RoleSkillEquip) GetSkillEquipMaxId() uint32 {
  70. return this.maxEquipId
  71. }
  72. func (this *RoleSkillEquip) ChangeNtf(skillEquipIdList map[uint32]int32, ignore bool) {
  73. ntfMsg := &serverproto.SCSkillEquipChangeNtf{
  74. Ignore: ignore,
  75. }
  76. for id, cfgId := range skillEquipIdList {
  77. skillEquipId := id
  78. skillEquip := this.GetSkillEquip(skillEquipId)
  79. if skillEquip != nil {
  80. ntfMsg.SkillEquipChangeList = append(ntfMsg.SkillEquipChangeList, &serverproto.SkillEquipChangeData{
  81. SkillEquipData: &serverproto.SkillEquipData{
  82. Id: skillEquipId,
  83. ConfigId: cfgId,
  84. StarLevel: skillEquip.StarLevel},
  85. Add: true,
  86. },
  87. )
  88. } else {
  89. ntfMsg.SkillEquipChangeList = append(ntfMsg.SkillEquipChangeList, &serverproto.SkillEquipChangeData{
  90. SkillEquipData: &serverproto.SkillEquipData{
  91. Id: skillEquipId,
  92. ConfigId: cfgId,
  93. StarLevel: 0},
  94. Add: false,
  95. },
  96. )
  97. }
  98. }
  99. this.role.ReplayGate(ntfMsg, true)
  100. }
  101. func (this *RoleSkillEquip) GetSkillEquipPileTotalNum() int {
  102. return len(this.skillEquipList)
  103. }
  104. func (this *RoleSkillEquip) GetSkillEquip(equipId uint32) *serverproto.SkillEquipData {
  105. if skillEquip, ok := this.skillEquipList[equipId]; ok {
  106. return skillEquip
  107. }
  108. return nil
  109. }
  110. func (this *RoleSkillEquip) GetEquipByConfigId(equipConfigId int32) *serverproto.SkillEquipData {
  111. for _, skillEquip := range this.skillEquipList {
  112. if skillEquip.ConfigId == equipConfigId {
  113. return skillEquip
  114. }
  115. }
  116. return nil
  117. }
  118. func (this *RoleSkillEquip) AddSkillEquip(configId int32, starLevel int32) (interface{}, bool) {
  119. _, ok := serverproto.ArtifactCfgLoader[configId]
  120. if !ok {
  121. util.DebugF("[AddEquip] load item config error, configId: %v ", configId)
  122. return nil, false
  123. }
  124. this.SetDirty(true)
  125. this.maxEquipId++
  126. this.skillEquipList[this.maxEquipId] = &serverproto.SkillEquipData{
  127. Id: this.maxEquipId,
  128. ConfigId: configId,
  129. StarLevel: starLevel,
  130. }
  131. this.dbChangeSkillEquipList.Add(this.maxEquipId)
  132. util.InfoF("uid=%v [AddSkillEquip] skillEquipId=%v configId=%v startLevel=%v", this.role.GetUUid(), this.maxEquipId, configId, 0)
  133. return this.skillEquipList[this.maxEquipId], true
  134. }
  135. func (this *RoleSkillEquip) AddSkillEquipByInstance(skillEquipId uint32, configId int32, starLevel int32) (interface{}, bool) {
  136. skillEquip := this.GetSkillEquip(skillEquipId)
  137. if skillEquip != nil {
  138. util.ErrorF("uid=%v [AddSkillEquipByInstance] skillEquip had exist error skillEquipId=%v configId=%v startLevel=%v ",
  139. this.role.GetUUid(), skillEquip.Id, skillEquip.ConfigId, skillEquip.StarLevel)
  140. this.SetDirty(true)
  141. this.maxEquipId++
  142. this.skillEquipList[this.maxEquipId] = &serverproto.SkillEquipData{
  143. Id: this.maxEquipId,
  144. ConfigId: configId,
  145. StarLevel: starLevel,
  146. }
  147. this.dbChangeSkillEquipList.Add(this.maxEquipId)
  148. util.InfoF("uid=%v [AddSkillEquipByInstance] add new skillEquipId=%v configId=%v startLevel=%v",
  149. this.role.GetUUid(), this.maxEquipId, configId, starLevel)
  150. return this.skillEquipList, false
  151. } else {
  152. this.SetDirty(true)
  153. this.skillEquipList[skillEquipId] = &serverproto.SkillEquipData{
  154. Id: skillEquipId,
  155. ConfigId: configId,
  156. StarLevel: starLevel,
  157. }
  158. this.dbChangeSkillEquipList.Add(skillEquipId)
  159. util.InfoF("uid=%v [AddSkillEquipByInstance] skillEquipId=%v configId=%v startLevel=%v",
  160. this.role.GetUUid(), skillEquipId, configId, starLevel)
  161. }
  162. return this.skillEquipList, true
  163. }
  164. func (this *RoleSkillEquip) RemoveSkillEquip(skillEquipId uint32) {
  165. skillEquip := this.GetSkillEquip(skillEquipId)
  166. if skillEquip == nil {
  167. util.DebugF("uid=%v [RemoveSkillEquip] skillEquip had exist error skillEquipId=%v ",
  168. this.role.GetUUid(), skillEquip.Id)
  169. return
  170. }
  171. this.dbChangeSkillEquipList.Add(skillEquipId)
  172. util.InfoF("uid=%v [RemoveSkillEquip] skillEquipId=%v configId=%v startLevel=%v",
  173. this.role.GetUUid(), skillEquip.Id, skillEquip.ConfigId, skillEquip.StarLevel)
  174. delete(this.skillEquipList, skillEquipId)
  175. }
  176. // 解决兼容老数据问题,和属性计算放到一起
  177. //func (this *RoleSkillEquip) calcSlotDisplayAttrs(slotDetail *serverproto.SkillEquipSlotDetailData){
  178. // if slotDetail == nil {
  179. // return
  180. // }
  181. // convertData, ok := model.SkillEquipSlotAppendAttrContainer[slotDetail.SlotLevel]
  182. // var realHealHurt int32 = 0
  183. // if !ok {
  184. // util.ErrorF("uid=%v [CalcSlotAttrs] SlotLevel=%v ArtifactExpCfg can not find",
  185. // this.role.GetUUid(), slotDetail.SlotLevel)
  186. // return
  187. // }
  188. // if len(convertData) > 0 {
  189. // for key, value := range convertData {
  190. // if key == serverproto.Attr_RealHurt {
  191. // realHealHurt += int32(value)
  192. // }
  193. // }
  194. // }
  195. // slotDetail.SlotAttrs = []*serverproto.KeyValueType{&serverproto.KeyValueType{Key:int32(serverproto.Attr_RealHurt),Value: realHealHurt}}
  196. //}
  197. //神装佩戴
  198. func (this *RoleSkillEquip) SkillEquipUp(heroId int32, skillEquipSlotData *serverproto.SkillEquipSlotData, skillEquipId uint32, slotIndex int32) serverproto.ErrorCode {
  199. if skillEquipId == 0 ||
  200. slotIndex < -1 ||
  201. slotIndex >= int32(len(skillEquipSlotData.SlotList)) {
  202. return serverproto.ErrorCode_ERROR_FAIL
  203. }
  204. detail := skillEquipSlotData.SlotList[slotIndex]
  205. //判断神装是否正确
  206. skillEquipData := this.GetSkillEquip(skillEquipId)
  207. if skillEquipData == nil {
  208. util.DebugF("[SkillEquipUp] find equip error, skillEquipId: %v ", skillEquipId)
  209. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_EXIST
  210. }
  211. skillEquipCfgData, ok := serverproto.ArtifactCfgLoader[skillEquipData.ConfigId]
  212. if !ok || skillEquipCfgData == nil {
  213. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR
  214. }
  215. util.InfoF("uid=%v [SkillEquipUp] skillEquipId=%v configId=%v startLevel=%v soltIndex", this.role.GetUUid(), skillEquipData.Id, skillEquipData.ConfigId, skillEquipData.StarLevel, slotIndex)
  216. changIdList := map[uint32]int32{}
  217. if detail.SkillEquipId != 0 {
  218. //卸下之前的神器
  219. tmpSkillEquipId := detail.SkillEquipId
  220. tmpCfgId := detail.SkillEquipConfigId
  221. tmpStarLevel := detail.SkillEquipStarLevel
  222. detail.SkillEquipId = 0
  223. detail.SkillEquipConfigId = 0
  224. detail.SkillEquipStarLevel = 0
  225. //添加到神器背包
  226. this.AddSkillEquipByInstance(tmpSkillEquipId, tmpCfgId, tmpStarLevel)
  227. changIdList[tmpSkillEquipId] = tmpCfgId
  228. }
  229. //装上新装备
  230. detail.SkillEquipId = skillEquipData.Id
  231. detail.SkillEquipConfigId = skillEquipData.ConfigId
  232. detail.SkillEquipStarLevel = skillEquipData.StarLevel
  233. //从神器背包移除佩戴的神器
  234. this.RemoveSkillEquip(skillEquipId)
  235. //神器背包变更数据
  236. changIdList[detail.SkillEquipId] = detail.SkillEquipConfigId
  237. this.ChangeNtf(changIdList, true)
  238. //this.calcSlotDisplayAttrs(detail)
  239. //神器槽位变更数据
  240. ntfMsg := &serverproto.SCSkillEquipSlotDataNtf{
  241. HeroId: heroId,
  242. Slot: &serverproto.SkillEquipSlotData{},
  243. }
  244. *ntfMsg.Slot = *skillEquipSlotData
  245. this.role.ReplayGate(ntfMsg, true)
  246. this.SetDirty(true)
  247. this.onSkillEquipUp(heroId)
  248. this.role.GetRoleHero().addHeroChange(heroId)
  249. TaskMagCheck(this.role, serverproto.TaskType_Eve_Five_Artifact_Activate, 1)
  250. return serverproto.ErrorCode_ERROR_OK
  251. }
  252. func (this *RoleSkillEquip) onSkillEquipUp(heroId int32) {
  253. this.role.roleBattleAttr.AttrChange(
  254. AttrChangeST{
  255. ChangeType: Attr_Change_Skill_Equip_Slot,
  256. ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
  257. })
  258. }
  259. // 卸下神器
  260. func (this *RoleSkillEquip) SkillEquipDown(heroId int32, skillSlotData *serverproto.SkillEquipSlotData, subIndex int32) serverproto.ErrorCode {
  261. if skillSlotData.SlotList == nil ||
  262. int32(len(skillSlotData.SlotList)) <= subIndex {
  263. return serverproto.ErrorCode_ERROR_FAIL
  264. }
  265. detailNum := len(skillSlotData.SlotList)
  266. var changIdList = map[uint32]int32{}
  267. //一键卸下所有槽位
  268. if subIndex == -1 {
  269. for i := 0; i < detailNum; i++ {
  270. detail := skillSlotData.SlotList[i]
  271. if detail != nil && detail.SkillEquipId != 0 {
  272. util.InfoF("uid=%v [SkillEquipDown] begin skillEquipId=%v configId=%v startLevel=%v soltIndex=%v",
  273. this.role.GetUUid(), detail.SkillEquipId, detail.SkillEquipConfigId, detail.SkillEquipStarLevel, subIndex)
  274. tmpEquipId := detail.SkillEquipId
  275. tmpEquipCfgId := detail.SkillEquipConfigId
  276. tmpEquipStarLevel := detail.SkillEquipStarLevel
  277. detail.SkillEquipId = 0
  278. detail.SkillEquipConfigId = 0
  279. detail.SkillEquipStarLevel = 0
  280. this.AddSkillEquipByInstance(tmpEquipId, tmpEquipCfgId, tmpEquipStarLevel)
  281. changIdList[tmpEquipId] = tmpEquipCfgId
  282. util.InfoF("uid=%v [SkillEquipDown] end skillEquipId=%v configId=%v startLevel=%v soltIndex=%v",
  283. this.role.GetUUid(), detail.SkillEquipId, detail.SkillEquipConfigId, detail.SkillEquipStarLevel, subIndex)
  284. }
  285. //this.calcSlotDisplayAttrs(detail)
  286. }
  287. } else {
  288. //卸下当前槽位
  289. detail := skillSlotData.SlotList[subIndex]
  290. if detail == nil || detail.SkillEquipId == 0 {
  291. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_SOLT_NULL
  292. }
  293. tmpEquipId := detail.SkillEquipId
  294. tmpEquipCfgId := detail.SkillEquipConfigId
  295. tmpEquipStarLevel := detail.SkillEquipStarLevel
  296. util.InfoF("uid=%v [SkillEquipDown] begin skillEquipId=%v configId=%v startLevel=%v soltIndex=%v",
  297. this.role.GetUUid(), detail.SkillEquipId, detail.SkillEquipConfigId, detail.SkillEquipStarLevel, subIndex)
  298. detail.SkillEquipId = 0
  299. detail.SkillEquipConfigId = 0
  300. detail.SkillEquipStarLevel = 0
  301. this.AddSkillEquipByInstance(tmpEquipId, tmpEquipCfgId, tmpEquipStarLevel)
  302. changIdList[tmpEquipId] = tmpEquipCfgId
  303. util.InfoF("uid=%v [SkillEquipDown] end skillEquipId=%v configId=%v startLevel=%v soltIndex=%v",
  304. this.role.GetUUid(), detail.SkillEquipId, detail.SkillEquipConfigId, detail.SkillEquipStarLevel, subIndex)
  305. //this.calcSlotDisplayAttrs(detail)
  306. }
  307. if len(changIdList) > 0 {
  308. this.ChangeNtf(changIdList, true)
  309. //slot数据变更通知
  310. ntfMsg := &serverproto.SCSkillEquipSlotDataNtf{
  311. HeroId: heroId,
  312. Slot: &serverproto.SkillEquipSlotData{},
  313. }
  314. *ntfMsg.Slot = *skillSlotData
  315. this.role.ReplayGate(ntfMsg, true)
  316. this.SetDirty(true)
  317. this.onSkillEquipDown(heroId)
  318. this.role.GetRoleHero().addHeroChange(heroId)
  319. }
  320. return serverproto.ErrorCode_ERROR_OK
  321. }
  322. func (this *RoleSkillEquip) onSkillEquipDown(heroId int32) {
  323. this.role.roleBattleAttr.AttrChange(
  324. AttrChangeST{
  325. ChangeType: Attr_Change_Skill_Equip_Slot,
  326. ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
  327. })
  328. }
  329. // 神器转移
  330. func (this *RoleSkillEquip) SkillEquipShift(srcId, dstId uint32) serverproto.ErrorCode {
  331. srcData := this.GetSkillEquip(srcId)
  332. dstData := this.GetSkillEquip(dstId)
  333. if srcData == nil || dstData == nil {
  334. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_BAG
  335. }
  336. if srcData.ConfigId == dstData.ConfigId {
  337. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFGID_EQUA
  338. }
  339. if srcData.StarLevel == dstData.StarLevel {
  340. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_STAR_EQUA
  341. }
  342. srdDb, ok := serverproto.ArtifactCfgLoader[srcData.ConfigId]
  343. dstdDb, ok1 := serverproto.ArtifactCfgLoader[dstData.ConfigId]
  344. if !ok || !ok1 {
  345. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_DB_NOT
  346. }
  347. if srdDb.ArtifactMaxLevel != dstdDb.ArtifactMaxLevel {
  348. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_STAR_NOT
  349. }
  350. cost, ok := model.GlobalSkillEquipShiftCost[srdDb.ArtifactMaxLevel]
  351. if !ok {
  352. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_STAR_MIN
  353. }
  354. if !this.role.GetRoleBag().CanDelItem(cost.Key, cost.Value) {
  355. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH
  356. }
  357. this.role.DelItem(cost.Key, cost.Value, AddItemST{AddFrom: AddFrom_SkillEquipShift})
  358. srcStar := srcData.StarLevel
  359. srcData.StarLevel = dstData.StarLevel
  360. dstData.StarLevel = srcStar
  361. this.ChangeNtf(map[uint32]int32{srcId: srcData.ConfigId, dstId: dstData.ConfigId}, true)
  362. this.onSkillEquipStarLevelUp(this.role.GetRoleHero().GetMainHero().Id)
  363. this.dbChangeSkillEquipList.Add(srcData.Id, dstData.Id)
  364. this.SetDirty(true)
  365. return serverproto.ErrorCode_ERROR_OK
  366. }
  367. // 任务 获得指定星级的神器数量
  368. func (this *RoleSkillEquip) GetSkillEquipCntByStar(star int32) int32 {
  369. if this.role == nil || this.role.base == nil || this.role.GetRoleHero() == nil {
  370. return 0
  371. }
  372. roleHero := this.role.GetRoleHero()
  373. slotData := this.role.base.getSkillEquipSlotData(roleHero.GetMainHero().Id)
  374. if slotData == nil {
  375. return 0
  376. }
  377. ret := int32(0)
  378. for _, data := range slotData.SlotList {
  379. if data.SkillEquipStarLevel < star {
  380. continue
  381. }
  382. ret += 1
  383. }
  384. for _, hero := range roleHero.heroList {
  385. slotData := this.role.base.getSkillEquipSlotData(hero.Id)
  386. if slotData == nil {
  387. continue
  388. }
  389. for _, data := range slotData.SlotList {
  390. if data.SkillEquipStarLevel < star {
  391. continue
  392. }
  393. ret += 1
  394. }
  395. }
  396. return ret
  397. }
  398. // 神器升星
  399. func (this *RoleSkillEquip) SkillEquipStarLevelUp(heroId int32, skillSlotData *serverproto.SkillEquipSlotData, skillEquipId uint32, select_cost []uint32) serverproto.ErrorCode {
  400. detailNum := len(skillSlotData.SlotList)
  401. bFind := false
  402. slotIndex := 0
  403. var detailSolt *serverproto.SkillEquipSlotDetailData
  404. for i := 0; i < detailNum; i++ {
  405. detailSolt = skillSlotData.SlotList[i]
  406. if detailSolt != nil &&
  407. detailSolt.SkillEquipId == skillEquipId {
  408. bFind = true
  409. slotIndex = i
  410. break
  411. }
  412. }
  413. if !bFind {
  414. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_EXIST
  415. }
  416. // 神器最大星级判断
  417. skillEquipCfg := serverproto.ArtifactCfgLoader[detailSolt.SkillEquipConfigId]
  418. if skillEquipCfg == nil {
  419. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR
  420. }
  421. if detailSolt.SkillEquipStarLevel >= skillEquipCfg.ArtifactMaxLevel {
  422. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_STAR_LEVEL_MAX
  423. }
  424. //查找消耗
  425. costsCfg, ok := model.SkillEquipStarLevelUpCostContainer[detailSolt.SkillEquipConfigId]
  426. if !ok {
  427. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR
  428. }
  429. curCostCfg, ok1 := costsCfg[detailSolt.SkillEquipStarLevel]
  430. if !ok1 {
  431. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR
  432. }
  433. skillEquipCfgCostData := map[int32]int32{}
  434. otherCfgCostData := map[int32]int32{}
  435. selectCostByConfigId := map[int32]int32{}
  436. // 分离消耗类型
  437. for k, v := range curCostCfg {
  438. itemCfg, ok2 := serverproto.ItemCfgLoader[k]
  439. if ok2 && serverproto.ResType(itemCfg.ResType) == serverproto.ResType_Res_Skill_Equip {
  440. skillEquipCfgCostData[k] = v
  441. } else {
  442. otherCfgCostData[k] = v
  443. }
  444. }
  445. changeIdList := map[uint32]int32{}
  446. // 检查其它条件
  447. if !this.role.CheckResLitNum(otherCfgCostData) {
  448. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH
  449. }
  450. for _, v := range select_cost {
  451. skill_equip, ok3 := this.skillEquipList[v]
  452. if !ok3 {
  453. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_EXIST
  454. }
  455. _, ok4 := serverproto.ArtifactCfgLoader[skill_equip.ConfigId]
  456. if !ok4 {
  457. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR
  458. }
  459. _, ok5 := skillEquipCfgCostData[skill_equip.ConfigId]
  460. if !ok5 {
  461. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_EXIST
  462. }
  463. _, ok6 := selectCostByConfigId[skill_equip.ConfigId]
  464. if !ok6 {
  465. selectCostByConfigId[skill_equip.ConfigId] = 1
  466. } else {
  467. selectCostByConfigId[skill_equip.ConfigId] += 1
  468. }
  469. }
  470. for k, v := range skillEquipCfgCostData {
  471. count, ok7 := selectCostByConfigId[k]
  472. if !ok7 {
  473. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH
  474. } else if v != count {
  475. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH
  476. } else {
  477. delete(selectCostByConfigId, k)
  478. }
  479. }
  480. if len(selectCostByConfigId) != 0 {
  481. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH
  482. }
  483. util.InfoF("uid=%v [SkillEquipStarLevelUp] begin skillEquipId=%v configId=%v startLevel=%v slotIndex=%v",
  484. this.role.GetUUid(), detailSolt.SkillEquipId, detailSolt.SkillEquipConfigId, detailSolt.SkillEquipStarLevel, slotIndex)
  485. this.role.DelItemList(otherCfgCostData, AddItemST{AddFrom: AddFrom_SkillEquipStarLevel})
  486. for _, v := range select_cost {
  487. skillEquip := this.GetSkillEquip(v)
  488. //util.InfoF("uid=%v SkillEquipStarLevelUp RemoveSkillEquip Id=%v SkillEqipId=%v ConfigId=%v", this.role.uuid, v, skillEquip.ConfigId)
  489. this.RemoveSkillEquip(v)
  490. changeIdList[v] = skillEquip.ConfigId
  491. }
  492. this.ChangeNtf(changeIdList, true)
  493. detailSolt.SkillEquipStarLevel += 1
  494. //神器槽位变更数据
  495. ntfMsg := &serverproto.SCSkillEquipSlotDataNtf{
  496. HeroId: heroId,
  497. Slot: &serverproto.SkillEquipSlotData{},
  498. }
  499. *ntfMsg.Slot = *skillSlotData
  500. this.role.ReplayGate(ntfMsg, true)
  501. this.SetDirty(true)
  502. this.role.GetRoleHero().addHeroChange(heroId)
  503. util.InfoF("uid=%v [SkillEquipStarLevelUp] end skillEquipId=%v configId=%v startLevel=%v slotIndex=%v",
  504. this.role.GetUUid(), detailSolt.SkillEquipId, detailSolt.SkillEquipConfigId, detailSolt.SkillEquipStarLevel, slotIndex)
  505. this.onSkillEquipStarLevelUp(heroId)
  506. TaskMagCheck(this.role, serverproto.TaskType_Eve_Five_Artifact_Activate, 1)
  507. return serverproto.ErrorCode_ERROR_OK
  508. }
  509. func (this *RoleSkillEquip) onSkillEquipStarLevelUp(heroId int32) {
  510. this.role.roleBattleAttr.AttrChange(
  511. AttrChangeST{
  512. ChangeType: Attr_Change_Skill_Equip,
  513. ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
  514. })
  515. }
  516. // 神器分解
  517. func (this *RoleSkillEquip) SkillEquipDecompose(skillEquipIds []uint32) (map[int32]int32, serverproto.ErrorCode) {
  518. changeIdList := map[uint32]int32{}
  519. curAwards := map[int32]int32{}
  520. var equipsCfgId []int32
  521. var equipsStarLevel []int32
  522. for _, v := range skillEquipIds {
  523. skillEquip := this.GetSkillEquip(v)
  524. if skillEquip == nil {
  525. return curAwards, serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_EXIST
  526. }
  527. cfgAwards := model.SkillEquipDecomposeReturnContainer[skillEquip.ConfigId]
  528. if cfgAwards == nil {
  529. return curAwards, serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR
  530. }
  531. cfgAward := cfgAwards[skillEquip.StarLevel]
  532. if cfgAward == nil || len(cfgAward) < 1 {
  533. return curAwards, serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR
  534. }
  535. for k1, v1 := range cfgAward {
  536. _, ok := curAwards[k1]
  537. if !ok {
  538. curAwards[k1] = v1
  539. } else {
  540. curAwards[k1] += v1
  541. }
  542. }
  543. equipsCfgId = append(equipsCfgId, skillEquip.ConfigId)
  544. equipsStarLevel = append(equipsStarLevel, skillEquip.StarLevel)
  545. changeIdList[v] = skillEquip.ConfigId
  546. }
  547. util.InfoF("uid=%v [SkillEquipDecompose] skillEquipId=%v configId=%v startLevel=%v", this.role.GetUUid(), skillEquipIds, equipsCfgId, equipsStarLevel)
  548. for _, v := range skillEquipIds {
  549. this.RemoveSkillEquip(v)
  550. }
  551. this.role.AddItemList(curAwards, AddFrom_SkillEquipDecompose, true)
  552. this.SetDirty(true)
  553. if len(changeIdList) > 0 {
  554. this.ChangeNtf(changeIdList, true)
  555. }
  556. return curAwards, serverproto.ErrorCode_ERROR_OK
  557. }
  558. // 槽位升级
  559. func (this *RoleSkillEquip) SkillEquipSlotLevelUp(skillEquipSlotData *serverproto.SkillEquipSlotData, heroId int32, slotIndex int32) serverproto.ErrorCode {
  560. if slotIndex >= int32(len(skillEquipSlotData.SlotList)) ||
  561. slotIndex < 0 {
  562. return serverproto.ErrorCode_ERROR_FAIL
  563. }
  564. slotDetail := skillEquipSlotData.SlotList[slotIndex]
  565. if slotDetail == nil || slotDetail.SkillEquipId == 0 {
  566. return serverproto.ErrorCode_ERROR_FAIL
  567. }
  568. cost := model.SkillEquipSlotLevelUpCostContainer[slotDetail.SlotLevel]
  569. if cost == nil || len(cost) < 1 {
  570. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR
  571. }
  572. if this.role.CheckResLitNum(cost) {
  573. util.InfoF("uid=%v [SkillEquipSlotLevelUp] begin skillEquipId=%v configId=%v startLevel=%v slotIndex=%v slotLevel=%v",
  574. this.role.GetUUid(), slotDetail.SkillEquipId, slotDetail.SkillEquipConfigId, slotDetail.SkillEquipStarLevel, slotIndex, slotDetail.SlotLevel)
  575. this.role.DelItemList(cost, AddItemST{AddFrom: AddFrom_SkillEquipSoltLevel})
  576. slotDetail.SlotLevel += 1
  577. //this.calcSlotDisplayAttrs(slotDetail)
  578. //神器槽位变更数据
  579. ntfMsg := &serverproto.SCSkillEquipSlotDataNtf{
  580. HeroId: heroId,
  581. Slot: &serverproto.SkillEquipSlotData{},
  582. }
  583. *ntfMsg.Slot = *skillEquipSlotData
  584. this.role.ReplayGate(ntfMsg, true)
  585. this.SetDirty(true)
  586. this.role.GetRoleHero().addHeroChange(heroId)
  587. } else {
  588. return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH
  589. }
  590. util.InfoF("uid=%v [SkillEquipSlotLevelUp] end skillEquipId=%v configId=%v startLevel=%v slotIndex=%v slotLevel=%v",
  591. this.role.GetUUid(), slotDetail.SkillEquipId, slotDetail.SkillEquipConfigId, slotDetail.SkillEquipStarLevel, slotIndex, slotDetail.SlotLevel)
  592. this.onSkillEquipSlotLevelUp(heroId, slotIndex)
  593. return serverproto.ErrorCode_ERROR_OK
  594. }
  595. func (this *RoleSkillEquip) onSkillEquipSlotLevelUp(heroId int32, slotIndex int32) {
  596. this.role.roleBattleAttr.AttrChange(
  597. AttrChangeST{
  598. ChangeType: Attr_Change_Skill_Equip_Slot,
  599. ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
  600. })
  601. }
  602. func (this *RoleSkillEquip) CheckReforgeCost(costData *model.RemakeCost, configId int32) serverproto.ErrorCode {
  603. if costData == nil {
  604. return serverproto.ErrorCode_ERROR_FAIL
  605. }
  606. bRet := this.role.CheckResLitNum(costData.CostMap)
  607. if !bRet {
  608. util.InfoF("uid=%v [CheckReforgeCost] refroge skillequip item check fail, configId:%v", this.role.GetUUid(), configId)
  609. return serverproto.ErrorCode_ERROR_FAIL
  610. }
  611. return serverproto.ErrorCode_ERROR_OK
  612. }
  613. func (this *RoleSkillEquip) GetNewCfgIdFromPool(skillConfigId int32) int32 {
  614. curForgePool := model.GetCurForgePool()
  615. if curForgePool == nil {
  616. return 0
  617. }
  618. randomPool := map[int32]int32{}
  619. i := int32(0)
  620. for _, configId := range curForgePool.RealPool {
  621. if configId != skillConfigId {
  622. i++
  623. randomPool[i] = configId
  624. }
  625. }
  626. poolSize := len(randomPool)
  627. if poolSize <= 0 {
  628. util.ErrorF("[GetNewCfgIdFromPool] pool size error, configId: %v ", skillConfigId)
  629. return 0
  630. }
  631. randNum := rand.Int31n(int32(poolSize))
  632. configId, ok := randomPool[randNum+1]
  633. if !ok {
  634. return 0
  635. }
  636. return configId
  637. }
  638. func (this *RoleSkillEquip) SkillEquipReforge(skillEquipId uint32) (serverproto.ErrorCode, uint32) {
  639. skillEquip := this.GetSkillEquip(skillEquipId)
  640. if skillEquip == nil {
  641. return serverproto.ErrorCode_ERROR_FAIL, 0
  642. }
  643. skillEquipCfg, ok := serverproto.ArtifactCfgLoader[skillEquip.ConfigId]
  644. if !ok {
  645. util.DebugF("[AddEquip] load item config error, configId: %v ", skillEquip.ConfigId)
  646. return serverproto.ErrorCode_ERROR_FAIL, 0
  647. }
  648. if skillEquipCfg.Quality < 3 {
  649. return serverproto.ErrorCode_ERROR_FAIL, 0
  650. }
  651. if skillEquipCfg.ArtifactMaxLevel < model.GlobalSkillEquipReforgeMinStart {
  652. return serverproto.ErrorCode_ERROR_FAIL, 0
  653. }
  654. //随机一个configId
  655. newConfigId := this.GetNewCfgIdFromPool(skillEquip.ConfigId)
  656. if newConfigId == 0 {
  657. return serverproto.ErrorCode_ERROR_FAIL, 0
  658. }
  659. costData := model.SkillEquipRemakeCostContainer[skillEquip.ConfigId]
  660. if costData == nil {
  661. return serverproto.ErrorCode_ERROR_FAIL, 0
  662. }
  663. //检查消耗
  664. bRet := this.CheckReforgeCost(costData, skillEquip.ConfigId)
  665. if bRet != serverproto.ErrorCode_ERROR_OK {
  666. return bRet, 0
  667. }
  668. //添加神器
  669. changeIdList := map[uint32]int32{}
  670. addSkillEquip, _ := this.AddSkillEquip(newConfigId, skillEquip.StarLevel)
  671. detail, ok := addSkillEquip.(*serverproto.SkillEquipData)
  672. if !ok {
  673. return serverproto.ErrorCode_ERROR_FAIL, 0
  674. }
  675. this.role.DelItemList(costData.CostMap, AddItemST{AddFrom: AddFrom_SkillEquipRefroge})
  676. changeIdList[detail.Id] = detail.ConfigId
  677. //刪除
  678. this.RemoveSkillEquip(skillEquipId)
  679. changeIdList[skillEquip.Id] = skillEquip.ConfigId
  680. this.ChangeNtf(changeIdList, true)
  681. util.InfoF("uid=%v [CheckAddRemoveRefrogeCost] refroge success, oldId:%v, oldCfgId:%v, newId:%v newCfgId:%v ",
  682. this.role.GetUUid(), skillEquipId, skillEquip.ConfigId, detail.Id, detail.ConfigId)
  683. return serverproto.ErrorCode_ERROR_OK, detail.Id
  684. }
  685. func (this *RoleSkillEquip) GetSkillEquipPool(ackMsg *serverproto.SCSkillEquipPoolAck) serverproto.ErrorCode {
  686. if ackMsg == nil {
  687. return serverproto.ErrorCode_ERROR_FAIL
  688. }
  689. curForgePool := model.GetCurForgePool()
  690. if curForgePool == nil {
  691. return serverproto.ErrorCode_ERROR_FAIL
  692. }
  693. ackMsg.CurId = curForgePool.Id
  694. for _, data := range curForgePool.CurForgePool {
  695. ackMsg.PoolIdList = append(ackMsg.PoolIdList, data)
  696. }
  697. for _, data := range curForgePool.NextForgePool {
  698. ackMsg.NextPool = append(ackMsg.NextPool, data)
  699. }
  700. ackMsg.NextBegin = curForgePool.NextBegin
  701. return serverproto.ErrorCode_ERROR_OK
  702. }