package model import ( "math/rand" //"math/rand" "rocommon/util" "roserver/baseserver/model" "roserver/baseserver/set" "roserver/serverproto" ) type RoleSkillEquip struct { SaveObject maxEquipId uint32 // skillEquipId skillEquip skillEquipList map[uint32]*serverproto.SkillEquipData //skillEquipTypeList map[int32]set.Interface dbChangeSkillEquipList set.Interface } func newRoleSkillEquip(r *Role) *RoleSkillEquip { roleSkillEquip := &RoleSkillEquip{ SaveObject: SaveObject{ role: r, }, } roleSkillEquip.skillEquipList = make(map[uint32]*serverproto.SkillEquipData) roleSkillEquip.dbChangeSkillEquipList = set.New(set.NonThreadSafe) return roleSkillEquip } func (this *RoleSkillEquip) CopyData(data *serverproto.RoleSkillEquip) { for _, equip := range this.skillEquipList { data.SkillEquipList = append(data.SkillEquipList, equip) } } func (this *RoleSkillEquip) Load(msg interface{}) bool { proRole := msg.(*serverproto.Role) if proRole.RoleSkillEquip != nil { this.maxEquipId = proRole.RoleSkillEquip.MaxSkillEquipId for _, data := range proRole.RoleSkillEquip.SkillEquipList { this.skillEquipList[data.Id] = data } } util.DebugF("uid=%v RoleSkillEquip ", this.role.GetUUid()) return true } func (this *RoleSkillEquip) Save() { this.SetDirty(false) util.DebugF("uid=%v RoleSkillEquip save...", this.role.GetUUid()) if this.dbChangeSkillEquipList.Size() > 0 { saveMsg := &serverproto.SSSkillEquipDataSaveReq{ SkillEquip: &serverproto.RoleSkillEquip{}, } changList := this.dbChangeSkillEquipList.List() for idx := 0; idx < len(changList); idx++ { skillEquipId := changList[idx].(uint32) skillEquip := this.GetSkillEquip(skillEquipId) if skillEquip == nil { saveMsg.SkillEquipDelList = append(saveMsg.SkillEquipDelList, skillEquipId) } else { saveMsg.SkillEquip.SkillEquipList = append(saveMsg.SkillEquip.SkillEquipList, skillEquip) } } this.dbChangeSkillEquipList.Clear() saveMsg.SkillEquip.MaxSkillEquipId = this.maxEquipId //for _, data := range this.skillEquipList { // saveMsg.SkillEquip.SkillEquipList = append(saveMsg.SkillEquip.SkillEquipList, data) //} this.role.SendDb(saveMsg) } } func (this *RoleSkillEquip) GetSkillEquipMaxId() uint32 { return this.maxEquipId } func (this *RoleSkillEquip) ChangeNtf(skillEquipIdList map[uint32]int32, ignore bool) { ntfMsg := &serverproto.SCSkillEquipChangeNtf{ Ignore: ignore, } for id, cfgId := range skillEquipIdList { skillEquipId := id skillEquip := this.GetSkillEquip(skillEquipId) if skillEquip != nil { ntfMsg.SkillEquipChangeList = append(ntfMsg.SkillEquipChangeList, &serverproto.SkillEquipChangeData{ SkillEquipData: &serverproto.SkillEquipData{ Id: skillEquipId, ConfigId: cfgId, StarLevel: skillEquip.StarLevel}, Add: true, }, ) } else { ntfMsg.SkillEquipChangeList = append(ntfMsg.SkillEquipChangeList, &serverproto.SkillEquipChangeData{ SkillEquipData: &serverproto.SkillEquipData{ Id: skillEquipId, ConfigId: cfgId, StarLevel: 0}, Add: false, }, ) } } this.role.ReplayGate(ntfMsg, true) } func (this *RoleSkillEquip) GetSkillEquipPileTotalNum() int { return len(this.skillEquipList) } func (this *RoleSkillEquip) GetSkillEquip(equipId uint32) *serverproto.SkillEquipData { if skillEquip, ok := this.skillEquipList[equipId]; ok { return skillEquip } return nil } func (this *RoleSkillEquip) GetEquipByConfigId(equipConfigId int32) *serverproto.SkillEquipData { for _, skillEquip := range this.skillEquipList { if skillEquip.ConfigId == equipConfigId { return skillEquip } } return nil } func (this *RoleSkillEquip) AddSkillEquip(configId int32, starLevel int32) (interface{}, bool) { _, ok := serverproto.ArtifactCfgLoader[configId] if !ok { util.DebugF("[AddEquip] load item config error, configId: %v ", configId) return nil, false } this.SetDirty(true) this.maxEquipId++ this.skillEquipList[this.maxEquipId] = &serverproto.SkillEquipData{ Id: this.maxEquipId, ConfigId: configId, StarLevel: starLevel, } this.dbChangeSkillEquipList.Add(this.maxEquipId) util.InfoF("uid=%v [AddSkillEquip] skillEquipId=%v configId=%v startLevel=%v", this.role.GetUUid(), this.maxEquipId, configId, 0) return this.skillEquipList[this.maxEquipId], true } func (this *RoleSkillEquip) AddSkillEquipByInstance(skillEquipId uint32, configId int32, starLevel int32) (interface{}, bool) { skillEquip := this.GetSkillEquip(skillEquipId) if skillEquip != nil { util.ErrorF("uid=%v [AddSkillEquipByInstance] skillEquip had exist error skillEquipId=%v configId=%v startLevel=%v ", this.role.GetUUid(), skillEquip.Id, skillEquip.ConfigId, skillEquip.StarLevel) this.SetDirty(true) this.maxEquipId++ this.skillEquipList[this.maxEquipId] = &serverproto.SkillEquipData{ Id: this.maxEquipId, ConfigId: configId, StarLevel: starLevel, } this.dbChangeSkillEquipList.Add(this.maxEquipId) util.InfoF("uid=%v [AddSkillEquipByInstance] add new skillEquipId=%v configId=%v startLevel=%v", this.role.GetUUid(), this.maxEquipId, configId, starLevel) return this.skillEquipList, false } else { this.SetDirty(true) this.skillEquipList[skillEquipId] = &serverproto.SkillEquipData{ Id: skillEquipId, ConfigId: configId, StarLevel: starLevel, } this.dbChangeSkillEquipList.Add(skillEquipId) util.InfoF("uid=%v [AddSkillEquipByInstance] skillEquipId=%v configId=%v startLevel=%v", this.role.GetUUid(), skillEquipId, configId, starLevel) } return this.skillEquipList, true } func (this *RoleSkillEquip) RemoveSkillEquip(skillEquipId uint32) { skillEquip := this.GetSkillEquip(skillEquipId) if skillEquip == nil { util.DebugF("uid=%v [RemoveSkillEquip] skillEquip had exist error skillEquipId=%v ", this.role.GetUUid(), skillEquip.Id) return } this.dbChangeSkillEquipList.Add(skillEquipId) util.InfoF("uid=%v [RemoveSkillEquip] skillEquipId=%v configId=%v startLevel=%v", this.role.GetUUid(), skillEquip.Id, skillEquip.ConfigId, skillEquip.StarLevel) delete(this.skillEquipList, skillEquipId) } // 解决兼容老数据问题,和属性计算放到一起 //func (this *RoleSkillEquip) calcSlotDisplayAttrs(slotDetail *serverproto.SkillEquipSlotDetailData){ // if slotDetail == nil { // return // } // convertData, ok := model.SkillEquipSlotAppendAttrContainer[slotDetail.SlotLevel] // var realHealHurt int32 = 0 // if !ok { // util.ErrorF("uid=%v [CalcSlotAttrs] SlotLevel=%v ArtifactExpCfg can not find", // this.role.GetUUid(), slotDetail.SlotLevel) // return // } // if len(convertData) > 0 { // for key, value := range convertData { // if key == serverproto.Attr_RealHurt { // realHealHurt += int32(value) // } // } // } // slotDetail.SlotAttrs = []*serverproto.KeyValueType{&serverproto.KeyValueType{Key:int32(serverproto.Attr_RealHurt),Value: realHealHurt}} //} //神装佩戴 func (this *RoleSkillEquip) SkillEquipUp(heroId int32, skillEquipSlotData *serverproto.SkillEquipSlotData, skillEquipId uint32, slotIndex int32) serverproto.ErrorCode { if skillEquipId == 0 || slotIndex < -1 || slotIndex >= int32(len(skillEquipSlotData.SlotList)) { return serverproto.ErrorCode_ERROR_FAIL } detail := skillEquipSlotData.SlotList[slotIndex] //判断神装是否正确 skillEquipData := this.GetSkillEquip(skillEquipId) if skillEquipData == nil { util.DebugF("[SkillEquipUp] find equip error, skillEquipId: %v ", skillEquipId) return serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_EXIST } skillEquipCfgData, ok := serverproto.ArtifactCfgLoader[skillEquipData.ConfigId] if !ok || skillEquipCfgData == nil { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR } util.InfoF("uid=%v [SkillEquipUp] skillEquipId=%v configId=%v startLevel=%v soltIndex", this.role.GetUUid(), skillEquipData.Id, skillEquipData.ConfigId, skillEquipData.StarLevel, slotIndex) changIdList := map[uint32]int32{} if detail.SkillEquipId != 0 { //卸下之前的神器 tmpSkillEquipId := detail.SkillEquipId tmpCfgId := detail.SkillEquipConfigId tmpStarLevel := detail.SkillEquipStarLevel detail.SkillEquipId = 0 detail.SkillEquipConfigId = 0 detail.SkillEquipStarLevel = 0 //添加到神器背包 this.AddSkillEquipByInstance(tmpSkillEquipId, tmpCfgId, tmpStarLevel) changIdList[tmpSkillEquipId] = tmpCfgId } //装上新装备 detail.SkillEquipId = skillEquipData.Id detail.SkillEquipConfigId = skillEquipData.ConfigId detail.SkillEquipStarLevel = skillEquipData.StarLevel //从神器背包移除佩戴的神器 this.RemoveSkillEquip(skillEquipId) //神器背包变更数据 changIdList[detail.SkillEquipId] = detail.SkillEquipConfigId this.ChangeNtf(changIdList, true) //this.calcSlotDisplayAttrs(detail) //神器槽位变更数据 ntfMsg := &serverproto.SCSkillEquipSlotDataNtf{ HeroId: heroId, Slot: &serverproto.SkillEquipSlotData{}, } *ntfMsg.Slot = *skillEquipSlotData this.role.ReplayGate(ntfMsg, true) this.SetDirty(true) this.onSkillEquipUp(heroId) this.role.GetRoleHero().addHeroChange(heroId) TaskMagCheck(this.role, serverproto.TaskType_Eve_Five_Artifact_Activate, 1) return serverproto.ErrorCode_ERROR_OK } func (this *RoleSkillEquip) onSkillEquipUp(heroId int32) { this.role.roleBattleAttr.AttrChange( AttrChangeST{ ChangeType: Attr_Change_Skill_Equip_Slot, ChangeHeroData: this.role.GetRoleHero().GetHero(heroId), }) } // 卸下神器 func (this *RoleSkillEquip) SkillEquipDown(heroId int32, skillSlotData *serverproto.SkillEquipSlotData, subIndex int32) serverproto.ErrorCode { if skillSlotData.SlotList == nil || int32(len(skillSlotData.SlotList)) <= subIndex { return serverproto.ErrorCode_ERROR_FAIL } detailNum := len(skillSlotData.SlotList) var changIdList = map[uint32]int32{} //一键卸下所有槽位 if subIndex == -1 { for i := 0; i < detailNum; i++ { detail := skillSlotData.SlotList[i] if detail != nil && detail.SkillEquipId != 0 { util.InfoF("uid=%v [SkillEquipDown] begin skillEquipId=%v configId=%v startLevel=%v soltIndex=%v", this.role.GetUUid(), detail.SkillEquipId, detail.SkillEquipConfigId, detail.SkillEquipStarLevel, subIndex) tmpEquipId := detail.SkillEquipId tmpEquipCfgId := detail.SkillEquipConfigId tmpEquipStarLevel := detail.SkillEquipStarLevel detail.SkillEquipId = 0 detail.SkillEquipConfigId = 0 detail.SkillEquipStarLevel = 0 this.AddSkillEquipByInstance(tmpEquipId, tmpEquipCfgId, tmpEquipStarLevel) changIdList[tmpEquipId] = tmpEquipCfgId util.InfoF("uid=%v [SkillEquipDown] end skillEquipId=%v configId=%v startLevel=%v soltIndex=%v", this.role.GetUUid(), detail.SkillEquipId, detail.SkillEquipConfigId, detail.SkillEquipStarLevel, subIndex) } //this.calcSlotDisplayAttrs(detail) } } else { //卸下当前槽位 detail := skillSlotData.SlotList[subIndex] if detail == nil || detail.SkillEquipId == 0 { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_SOLT_NULL } tmpEquipId := detail.SkillEquipId tmpEquipCfgId := detail.SkillEquipConfigId tmpEquipStarLevel := detail.SkillEquipStarLevel util.InfoF("uid=%v [SkillEquipDown] begin skillEquipId=%v configId=%v startLevel=%v soltIndex=%v", this.role.GetUUid(), detail.SkillEquipId, detail.SkillEquipConfigId, detail.SkillEquipStarLevel, subIndex) detail.SkillEquipId = 0 detail.SkillEquipConfigId = 0 detail.SkillEquipStarLevel = 0 this.AddSkillEquipByInstance(tmpEquipId, tmpEquipCfgId, tmpEquipStarLevel) changIdList[tmpEquipId] = tmpEquipCfgId util.InfoF("uid=%v [SkillEquipDown] end skillEquipId=%v configId=%v startLevel=%v soltIndex=%v", this.role.GetUUid(), detail.SkillEquipId, detail.SkillEquipConfigId, detail.SkillEquipStarLevel, subIndex) //this.calcSlotDisplayAttrs(detail) } if len(changIdList) > 0 { this.ChangeNtf(changIdList, true) //slot数据变更通知 ntfMsg := &serverproto.SCSkillEquipSlotDataNtf{ HeroId: heroId, Slot: &serverproto.SkillEquipSlotData{}, } *ntfMsg.Slot = *skillSlotData this.role.ReplayGate(ntfMsg, true) this.SetDirty(true) this.onSkillEquipDown(heroId) this.role.GetRoleHero().addHeroChange(heroId) } return serverproto.ErrorCode_ERROR_OK } func (this *RoleSkillEquip) onSkillEquipDown(heroId int32) { this.role.roleBattleAttr.AttrChange( AttrChangeST{ ChangeType: Attr_Change_Skill_Equip_Slot, ChangeHeroData: this.role.GetRoleHero().GetHero(heroId), }) } // 神器转移 func (this *RoleSkillEquip) SkillEquipShift(srcId, dstId uint32) serverproto.ErrorCode { srcData := this.GetSkillEquip(srcId) dstData := this.GetSkillEquip(dstId) if srcData == nil || dstData == nil { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_BAG } if srcData.ConfigId == dstData.ConfigId { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFGID_EQUA } if srcData.StarLevel == dstData.StarLevel { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_STAR_EQUA } srdDb, ok := serverproto.ArtifactCfgLoader[srcData.ConfigId] dstdDb, ok1 := serverproto.ArtifactCfgLoader[dstData.ConfigId] if !ok || !ok1 { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_DB_NOT } if srdDb.ArtifactMaxLevel != dstdDb.ArtifactMaxLevel { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_STAR_NOT } cost, ok := model.GlobalSkillEquipShiftCost[srdDb.ArtifactMaxLevel] if !ok { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_STAR_MIN } if !this.role.GetRoleBag().CanDelItem(cost.Key, cost.Value) { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH } this.role.DelItem(cost.Key, cost.Value, AddItemST{AddFrom: AddFrom_SkillEquipShift}) srcStar := srcData.StarLevel srcData.StarLevel = dstData.StarLevel dstData.StarLevel = srcStar this.ChangeNtf(map[uint32]int32{srcId: srcData.ConfigId, dstId: dstData.ConfigId}, true) this.onSkillEquipStarLevelUp(this.role.GetRoleHero().GetMainHero().Id) this.dbChangeSkillEquipList.Add(srcData.Id, dstData.Id) this.SetDirty(true) return serverproto.ErrorCode_ERROR_OK } // 任务 获得指定星级的神器数量 func (this *RoleSkillEquip) GetSkillEquipCntByStar(star int32) int32 { if this.role == nil || this.role.base == nil || this.role.GetRoleHero() == nil { return 0 } roleHero := this.role.GetRoleHero() slotData := this.role.base.getSkillEquipSlotData(roleHero.GetMainHero().Id) if slotData == nil { return 0 } ret := int32(0) for _, data := range slotData.SlotList { if data.SkillEquipStarLevel < star { continue } ret += 1 } for _, hero := range roleHero.heroList { slotData := this.role.base.getSkillEquipSlotData(hero.Id) if slotData == nil { continue } for _, data := range slotData.SlotList { if data.SkillEquipStarLevel < star { continue } ret += 1 } } return ret } // 神器升星 func (this *RoleSkillEquip) SkillEquipStarLevelUp(heroId int32, skillSlotData *serverproto.SkillEquipSlotData, skillEquipId uint32, select_cost []uint32) serverproto.ErrorCode { detailNum := len(skillSlotData.SlotList) bFind := false slotIndex := 0 var detailSolt *serverproto.SkillEquipSlotDetailData for i := 0; i < detailNum; i++ { detailSolt = skillSlotData.SlotList[i] if detailSolt != nil && detailSolt.SkillEquipId == skillEquipId { bFind = true slotIndex = i break } } if !bFind { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_EXIST } // 神器最大星级判断 skillEquipCfg := serverproto.ArtifactCfgLoader[detailSolt.SkillEquipConfigId] if skillEquipCfg == nil { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR } if detailSolt.SkillEquipStarLevel >= skillEquipCfg.ArtifactMaxLevel { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_STAR_LEVEL_MAX } //查找消耗 costsCfg, ok := model.SkillEquipStarLevelUpCostContainer[detailSolt.SkillEquipConfigId] if !ok { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR } curCostCfg, ok1 := costsCfg[detailSolt.SkillEquipStarLevel] if !ok1 { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR } skillEquipCfgCostData := map[int32]int32{} otherCfgCostData := map[int32]int32{} selectCostByConfigId := map[int32]int32{} // 分离消耗类型 for k, v := range curCostCfg { itemCfg, ok2 := serverproto.ItemCfgLoader[k] if ok2 && serverproto.ResType(itemCfg.ResType) == serverproto.ResType_Res_Skill_Equip { skillEquipCfgCostData[k] = v } else { otherCfgCostData[k] = v } } changeIdList := map[uint32]int32{} // 检查其它条件 if !this.role.CheckResLitNum(otherCfgCostData) { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH } for _, v := range select_cost { skill_equip, ok3 := this.skillEquipList[v] if !ok3 { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_EXIST } _, ok4 := serverproto.ArtifactCfgLoader[skill_equip.ConfigId] if !ok4 { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR } _, ok5 := skillEquipCfgCostData[skill_equip.ConfigId] if !ok5 { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_EXIST } _, ok6 := selectCostByConfigId[skill_equip.ConfigId] if !ok6 { selectCostByConfigId[skill_equip.ConfigId] = 1 } else { selectCostByConfigId[skill_equip.ConfigId] += 1 } } for k, v := range skillEquipCfgCostData { count, ok7 := selectCostByConfigId[k] if !ok7 { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH } else if v != count { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH } else { delete(selectCostByConfigId, k) } } if len(selectCostByConfigId) != 0 { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH } util.InfoF("uid=%v [SkillEquipStarLevelUp] begin skillEquipId=%v configId=%v startLevel=%v slotIndex=%v", this.role.GetUUid(), detailSolt.SkillEquipId, detailSolt.SkillEquipConfigId, detailSolt.SkillEquipStarLevel, slotIndex) this.role.DelItemList(otherCfgCostData, AddItemST{AddFrom: AddFrom_SkillEquipStarLevel}) for _, v := range select_cost { skillEquip := this.GetSkillEquip(v) //util.InfoF("uid=%v SkillEquipStarLevelUp RemoveSkillEquip Id=%v SkillEqipId=%v ConfigId=%v", this.role.uuid, v, skillEquip.ConfigId) this.RemoveSkillEquip(v) changeIdList[v] = skillEquip.ConfigId } this.ChangeNtf(changeIdList, true) detailSolt.SkillEquipStarLevel += 1 //神器槽位变更数据 ntfMsg := &serverproto.SCSkillEquipSlotDataNtf{ HeroId: heroId, Slot: &serverproto.SkillEquipSlotData{}, } *ntfMsg.Slot = *skillSlotData this.role.ReplayGate(ntfMsg, true) this.SetDirty(true) this.role.GetRoleHero().addHeroChange(heroId) util.InfoF("uid=%v [SkillEquipStarLevelUp] end skillEquipId=%v configId=%v startLevel=%v slotIndex=%v", this.role.GetUUid(), detailSolt.SkillEquipId, detailSolt.SkillEquipConfigId, detailSolt.SkillEquipStarLevel, slotIndex) this.onSkillEquipStarLevelUp(heroId) TaskMagCheck(this.role, serverproto.TaskType_Eve_Five_Artifact_Activate, 1) return serverproto.ErrorCode_ERROR_OK } func (this *RoleSkillEquip) onSkillEquipStarLevelUp(heroId int32) { this.role.roleBattleAttr.AttrChange( AttrChangeST{ ChangeType: Attr_Change_Skill_Equip, ChangeHeroData: this.role.GetRoleHero().GetHero(heroId), }) } // 神器分解 func (this *RoleSkillEquip) SkillEquipDecompose(skillEquipIds []uint32) (map[int32]int32, serverproto.ErrorCode) { changeIdList := map[uint32]int32{} curAwards := map[int32]int32{} var equipsCfgId []int32 var equipsStarLevel []int32 for _, v := range skillEquipIds { skillEquip := this.GetSkillEquip(v) if skillEquip == nil { return curAwards, serverproto.ErrorCode_ERROR_SKILL_EQUIP_NOT_EXIST } cfgAwards := model.SkillEquipDecomposeReturnContainer[skillEquip.ConfigId] if cfgAwards == nil { return curAwards, serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR } cfgAward := cfgAwards[skillEquip.StarLevel] if cfgAward == nil || len(cfgAward) < 1 { return curAwards, serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR } for k1, v1 := range cfgAward { _, ok := curAwards[k1] if !ok { curAwards[k1] = v1 } else { curAwards[k1] += v1 } } equipsCfgId = append(equipsCfgId, skillEquip.ConfigId) equipsStarLevel = append(equipsStarLevel, skillEquip.StarLevel) changeIdList[v] = skillEquip.ConfigId } util.InfoF("uid=%v [SkillEquipDecompose] skillEquipId=%v configId=%v startLevel=%v", this.role.GetUUid(), skillEquipIds, equipsCfgId, equipsStarLevel) for _, v := range skillEquipIds { this.RemoveSkillEquip(v) } this.role.AddItemList(curAwards, AddFrom_SkillEquipDecompose, true) this.SetDirty(true) if len(changeIdList) > 0 { this.ChangeNtf(changeIdList, true) } return curAwards, serverproto.ErrorCode_ERROR_OK } // 槽位升级 func (this *RoleSkillEquip) SkillEquipSlotLevelUp(skillEquipSlotData *serverproto.SkillEquipSlotData, heroId int32, slotIndex int32) serverproto.ErrorCode { if slotIndex >= int32(len(skillEquipSlotData.SlotList)) || slotIndex < 0 { return serverproto.ErrorCode_ERROR_FAIL } slotDetail := skillEquipSlotData.SlotList[slotIndex] if slotDetail == nil || slotDetail.SkillEquipId == 0 { return serverproto.ErrorCode_ERROR_FAIL } cost := model.SkillEquipSlotLevelUpCostContainer[slotDetail.SlotLevel] if cost == nil || len(cost) < 1 { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_CFG_ERR } if this.role.CheckResLitNum(cost) { util.InfoF("uid=%v [SkillEquipSlotLevelUp] begin skillEquipId=%v configId=%v startLevel=%v slotIndex=%v slotLevel=%v", this.role.GetUUid(), slotDetail.SkillEquipId, slotDetail.SkillEquipConfigId, slotDetail.SkillEquipStarLevel, slotIndex, slotDetail.SlotLevel) this.role.DelItemList(cost, AddItemST{AddFrom: AddFrom_SkillEquipSoltLevel}) slotDetail.SlotLevel += 1 //this.calcSlotDisplayAttrs(slotDetail) //神器槽位变更数据 ntfMsg := &serverproto.SCSkillEquipSlotDataNtf{ HeroId: heroId, Slot: &serverproto.SkillEquipSlotData{}, } *ntfMsg.Slot = *skillEquipSlotData this.role.ReplayGate(ntfMsg, true) this.SetDirty(true) this.role.GetRoleHero().addHeroChange(heroId) } else { return serverproto.ErrorCode_ERROR_SKILL_EQUIP_RES_NOT_ENOUGH } util.InfoF("uid=%v [SkillEquipSlotLevelUp] end skillEquipId=%v configId=%v startLevel=%v slotIndex=%v slotLevel=%v", this.role.GetUUid(), slotDetail.SkillEquipId, slotDetail.SkillEquipConfigId, slotDetail.SkillEquipStarLevel, slotIndex, slotDetail.SlotLevel) this.onSkillEquipSlotLevelUp(heroId, slotIndex) return serverproto.ErrorCode_ERROR_OK } func (this *RoleSkillEquip) onSkillEquipSlotLevelUp(heroId int32, slotIndex int32) { this.role.roleBattleAttr.AttrChange( AttrChangeST{ ChangeType: Attr_Change_Skill_Equip_Slot, ChangeHeroData: this.role.GetRoleHero().GetHero(heroId), }) } func (this *RoleSkillEquip) CheckReforgeCost(costData *model.RemakeCost, configId int32) serverproto.ErrorCode { if costData == nil { return serverproto.ErrorCode_ERROR_FAIL } bRet := this.role.CheckResLitNum(costData.CostMap) if !bRet { util.InfoF("uid=%v [CheckReforgeCost] refroge skillequip item check fail, configId:%v", this.role.GetUUid(), configId) return serverproto.ErrorCode_ERROR_FAIL } return serverproto.ErrorCode_ERROR_OK } func (this *RoleSkillEquip) GetNewCfgIdFromPool(skillConfigId int32) int32 { curForgePool := model.GetCurForgePool() if curForgePool == nil { return 0 } randomPool := map[int32]int32{} i := int32(0) for _, configId := range curForgePool.RealPool { if configId != skillConfigId { i++ randomPool[i] = configId } } poolSize := len(randomPool) if poolSize <= 0 { util.ErrorF("[GetNewCfgIdFromPool] pool size error, configId: %v ", skillConfigId) return 0 } randNum := rand.Int31n(int32(poolSize)) configId, ok := randomPool[randNum+1] if !ok { return 0 } return configId } func (this *RoleSkillEquip) SkillEquipReforge(skillEquipId uint32) (serverproto.ErrorCode, uint32) { skillEquip := this.GetSkillEquip(skillEquipId) if skillEquip == nil { return serverproto.ErrorCode_ERROR_FAIL, 0 } skillEquipCfg, ok := serverproto.ArtifactCfgLoader[skillEquip.ConfigId] if !ok { util.DebugF("[AddEquip] load item config error, configId: %v ", skillEquip.ConfigId) return serverproto.ErrorCode_ERROR_FAIL, 0 } if skillEquipCfg.Quality < 3 { return serverproto.ErrorCode_ERROR_FAIL, 0 } if skillEquipCfg.ArtifactMaxLevel < model.GlobalSkillEquipReforgeMinStart { return serverproto.ErrorCode_ERROR_FAIL, 0 } //随机一个configId newConfigId := this.GetNewCfgIdFromPool(skillEquip.ConfigId) if newConfigId == 0 { return serverproto.ErrorCode_ERROR_FAIL, 0 } costData := model.SkillEquipRemakeCostContainer[skillEquip.ConfigId] if costData == nil { return serverproto.ErrorCode_ERROR_FAIL, 0 } //检查消耗 bRet := this.CheckReforgeCost(costData, skillEquip.ConfigId) if bRet != serverproto.ErrorCode_ERROR_OK { return bRet, 0 } //添加神器 changeIdList := map[uint32]int32{} addSkillEquip, _ := this.AddSkillEquip(newConfigId, skillEquip.StarLevel) detail, ok := addSkillEquip.(*serverproto.SkillEquipData) if !ok { return serverproto.ErrorCode_ERROR_FAIL, 0 } this.role.DelItemList(costData.CostMap, AddItemST{AddFrom: AddFrom_SkillEquipRefroge}) changeIdList[detail.Id] = detail.ConfigId //刪除 this.RemoveSkillEquip(skillEquipId) changeIdList[skillEquip.Id] = skillEquip.ConfigId this.ChangeNtf(changeIdList, true) util.InfoF("uid=%v [CheckAddRemoveRefrogeCost] refroge success, oldId:%v, oldCfgId:%v, newId:%v newCfgId:%v ", this.role.GetUUid(), skillEquipId, skillEquip.ConfigId, detail.Id, detail.ConfigId) return serverproto.ErrorCode_ERROR_OK, detail.Id } func (this *RoleSkillEquip) GetSkillEquipPool(ackMsg *serverproto.SCSkillEquipPoolAck) serverproto.ErrorCode { if ackMsg == nil { return serverproto.ErrorCode_ERROR_FAIL } curForgePool := model.GetCurForgePool() if curForgePool == nil { return serverproto.ErrorCode_ERROR_FAIL } ackMsg.CurId = curForgePool.Id for _, data := range curForgePool.CurForgePool { ackMsg.PoolIdList = append(ackMsg.PoolIdList, data) } for _, data := range curForgePool.NextForgePool { ackMsg.NextPool = append(ackMsg.NextPool, data) } ackMsg.NextBegin = curForgePool.NextBegin return serverproto.ErrorCode_ERROR_OK }