| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101 |
- package model
- import (
- "math/rand"
- "rocommon/util"
- "roserver/baseserver/model"
- "roserver/baseserver/set"
- "roserver/serverproto"
- "sort"
- "strconv"
- )
- type RoleEquip struct {
- SaveObject
- equipList map[int32]*serverproto.EquipData
- //部件对应的装备
- equipTypeList map[int32]set.Interface
- }
- func newRoleEquip(r *Role) *RoleEquip {
- roleEquip := &RoleEquip{
- SaveObject: SaveObject{
- role: r,
- },
- }
- roleEquip.equipList = make(map[int32]*serverproto.EquipData)
- roleEquip.equipTypeList = make(map[int32]set.Interface)
- return roleEquip
- }
- func (this *RoleEquip) CopyData(data *serverproto.RoleEquip) {
- for _, equip := range this.equipList {
- data.EquipList = append(data.EquipList, equip)
- }
- }
- func (this *RoleEquip) equipTypeListAdd(equipType int32, configId int32) {
- if _, ok := this.equipTypeList[equipType]; !ok {
- this.equipTypeList[equipType] = set.New(set.NonThreadSafe)
- }
- this.equipTypeList[equipType].Add(configId)
- }
- func (this *RoleEquip) equipTypeListRemove(equipType int32, configId int32) {
- if _, ok := this.equipTypeList[equipType]; ok {
- this.equipTypeList[equipType].Remove(configId)
- }
- }
- func (this *RoleEquip) Load(msg interface{}) bool {
- proRole := msg.(*serverproto.Role)
- if proRole.RoleEquip != nil {
- for _, data := range proRole.RoleEquip.EquipList {
- cfgData, ok := serverproto.EquipCfgLoader[data.ConfigId]
- if ok {
- this.equipList[data.ConfigId] = data
- this.equipTypeListAdd(cfgData.Type, data.ConfigId)
- if data.Num <= 0 {
- util.ErrorF("uid=%v online equip num<=0 cfgid=%v", this.role.GetUUid(), data.ConfigId)
- }
- }
- }
- }
- util.DebugF("uid=%v RoleEquip equipTypeListLen=%v", this.role.GetUUid(), len(this.equipTypeList))
- return true
- }
- func (this *RoleEquip) Save() {
- this.SetDirty(false)
- util.DebugF("uid=%v RoleEquip save...", this.role.GetUUid())
- if len(this.equipList) > 0 {
- //先整体做保存,后期做部分保存,提高效率
- saveMsg := &serverproto.SSEquipDataSaveReq{
- Equip: &serverproto.RoleEquip{},
- }
- //优化提升效率
- saveMsg.Equip.EquipList = make([]*serverproto.EquipData, 0, 32)
- for _, data := range this.equipList {
- if data.Num > 0 {
- saveMsg.Equip.EquipList = append(saveMsg.Equip.EquipList, data)
- }
- }
- this.role.SendDb(saveMsg)
- }
- }
- func (this *RoleEquip) ChangeNtf(equipIdList set.Interface, ignore bool) {
- ntfMsg := &serverproto.SCEquipChangeNtf{
- Ignore: ignore,
- }
- for _, data := range equipIdList.List() {
- equipConfigId := data.(int32)
- equip := this.GetEquip(equipConfigId)
- if equip != nil {
- if equip.Num < 0 {
- equip.Num = 0
- }
- ntfMsg.EquipList = append(ntfMsg.EquipList, &serverproto.EquipData{
- ConfigId: equipConfigId,
- Num: equip.Num,
- })
- } else {
- ntfMsg.EquipList = append(ntfMsg.EquipList, &serverproto.EquipData{
- ConfigId: equipConfigId,
- Num: 0,
- })
- }
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- func (this *RoleEquip) GetEquip(equipConfigId int32) *serverproto.EquipData {
- if equipData, ok := this.equipList[equipConfigId]; ok {
- if equipData.Num <= 0 {
- return nil
- }
- return equipData
- }
- return nil
- }
- func (this *RoleEquip) AddEquip(configId int32, num int32) (interface{}, bool) {
- cfgData, ok := serverproto.EquipCfgLoader[configId]
- if !ok || num <= 0 {
- util.DebugF("[AddEquip] load item config error, configId: %v ", configId)
- return nil, false
- }
- this.SetDirty(true)
- var oldNum int32 = 0
- equipData := this.GetEquip(configId)
- if equipData != nil {
- oldNum = equipData.Num
- equipData.Num += num
- TaskMagCheck(this.role, serverproto.TaskType_Equip_Quality_Num, 0)
- util.InfoF("uid=%v AddEquip configId=%v addNum=%v oldNum=%v curNum=%v", this.role.GetUUid(), configId, num, oldNum, equipData.Num)
- return equipData, false
- } else {
- this.equipList[configId] = &serverproto.EquipData{
- ConfigId: configId,
- Num: num,
- }
- this.equipTypeListAdd(cfgData.Type, configId)
- TaskMagCheck(this.role, serverproto.TaskType_Equip_Quality_Num, 0)
- util.InfoF("uid=%v AddEquip configId=%v addNum=%v oldNum=%v curNum=%v", this.role.GetUUid(), configId, num, oldNum, num)
- return this.equipList[configId], true
- }
- }
- func (this *RoleEquip) RemoveEquip(configId int32) {
- delete(this.equipList, configId)
- cfgData, ok := serverproto.EquipCfgLoader[configId]
- if !ok {
- this.equipTypeListRemove(cfgData.Type, configId)
- }
- }
- func (this *RoleEquip) ReduceEquipNum(configId int32, reduceNum int32, notify bool) {
- if reduceNum <= 0 {
- return
- }
- equipData := this.GetEquip(configId)
- if equipData != nil {
- oldNum := equipData.Num
- equipData.Num -= reduceNum
- if equipData.Num <= 0 {
- equipData.Num = 0
- util.InfoF("uid=%v ReduceEquipNum equip num configId=%v old=%v new=%v reducenum=%v", this.role.uuid, configId, oldNum, equipData.Num, reduceNum)
- this.RemoveEquip(configId)
- }
- if notify {
- changNtf := &serverproto.SCEquipChangeNtf{
- Ignore: true,
- }
- changNtf.EquipList = append(changNtf.EquipList, equipData)
- this.role.ReplayGate(changNtf, true)
- }
- util.InfoF("uid=%v ReduceEquipNum configId=%v reduceNum=%v oldNum=%v curNum=%v", this.role.GetUUid(), configId, reduceNum, oldNum, equipData.Num)
- }
- }
- func (this *RoleEquip) EquipForge(equipConfigId int32, once int32, equipType, subEquipType int32) {
- var ret = serverproto.ErrorCode_ERROR_OK
- //客户端显示使用
- ackMsg := &serverproto.SCEquipForgeAck{}
- //一键锻造
- if equipConfigId <= 0 {
- ret = this.equipForgeAll(equipType, subEquipType)
- } else {
- if once > 0 {
- ackMsg.Type = 1 //表示合成单件装备
- ret = this.equipSameForge(equipConfigId, once, ackMsg)
- if ret == serverproto.ErrorCode_ERROR_OK {
- this.role.BaseChangeNtf()
- this.SetDirty(true)
- }
- } else {
- ret = serverproto.ErrorCode_ERROR_FAIL
- }
- }
- ackMsg.Error = int32(ret)
- this.role.ReplayGate(ackMsg, true)
- }
- //合成该装备到下一个装备,根据给定limit是合成多次还是合成一次
- func (this *RoleEquip) equipSameForge(equipConfigId int32, limit int32, ackMsg *serverproto.SCEquipForgeAck) serverproto.ErrorCode {
- globalData, ok1 := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Equip_Forging_Num)]
- cfgData, ok2 := serverproto.EquipCfgLoader[equipConfigId]
- equipData, ok3 := this.equipList[cfgData.Id]
- //锻造的装备是否存在
- _, ok := serverproto.EquipCfgLoader[cfgData.Forge]
- if !ok {
- util.DebugF("EquipForging forge config data not found cfgid=%%v", cfgData.Forge)
- return serverproto.ErrorCode_ERROR_EQUIP_CONFIG_DATA_NOT_FOUND
- }
- if !ok1 || !ok2 || !ok3 {
- util.DebugF("EquipForging config data not found")
- return serverproto.ErrorCode_ERROR_EQUIP_CONFIG_DATA_NOT_FOUND
- }
- if equipData.Num < globalData.IVal {
- util.DebugF("uid=%v EquipForging num not enough cfgid=%v num=%v", this.role.GetUUid(), equipData.ConfigId, equipData.Num)
- return serverproto.ErrorCode_ERROR_EQUIP_FORGE_NUM_NOT_ENOUGH
- }
- if this.role.GetMoney() < uint64(cfgData.CostMoney) {
- util.DebugF("uid=%v EquipForging money not enough costmoney=%v", this.role.GetUUid(), cfgData.CostMoney)
- return serverproto.ErrorCode_ERROR_MONEY_NOT_ENOUGH
- }
- //同一个装备是否融合到不能融合为止
- addNum := equipData.Num / globalData.IVal
- costMoney := addNum * cfgData.CostMoney
- if this.role.GetMoney() < uint64(costMoney) {
- addNum = int32(this.role.GetMoney()) / cfgData.CostMoney
- costMoney = addNum * cfgData.CostMoney
- }
- if limit > addNum || limit <= 0 {
- limit = addNum
- }
- costMoney = limit * cfgData.CostMoney
- //消耗金钱
- this.role.AddMoney(AddItemST{ItemCount: costMoney}, false)
- //通知数据变化
- this.ReduceEquipNum(cfgData.Id, globalData.IVal*limit, true)
- addEquip, _ := this.AddEquip(cfgData.Forge, limit) //锻造成新的装备
- if addEquip != nil {
- changNtf := &serverproto.SCEquipChangeNtf{}
- changNtf.Ignore = false
- changNtf.EquipList = append(changNtf.EquipList, addEquip.(*serverproto.EquipData))
- this.role.ReplayGate(changNtf, true)
- }
- //任务条件处理
- TaskMagCheck(this.role, serverproto.TaskType_Equip_Forge_Count, limit)
- TaskMagCheck(this.role, serverproto.TaskType_Equip_Quality_Num, 0)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Merge_Equip, cfgData.Forge)
- return serverproto.ErrorCode_ERROR_OK
- }
- //根据装备部件进行锻造
- func (this *RoleEquip) equipForgeAll(equipType, subEquipType int32) serverproto.ErrorCode {
- if equipType <= Equip_Type_None || equipType >= Equip_Type_Max {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if equipType == Equip_Type_Weapon {
- if subEquipType <= Pro_Type_None || subEquipType >= Pro_Type_MAX {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- }
- globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Equip_Forging_Num)]
- if !ok {
- return serverproto.ErrorCode_ERROR_EQUIP_CONFIG_DATA_NOT_FOUND
- }
- var idList []int32
- this.getEquipListByType(equipType, subEquipType, &idList)
- //需要按照ID顺序执行(ID从高到底)
- sort.Slice(idList, func(i, j int) bool {
- return (idList)[i] > (idList)[j]
- })
- var changList = set.New(set.NonThreadSafe)
- for i := 0; i < len(idList); i++ {
- //合并同一个装备(查找可以合并的同部件装备,同职业)
- this.equipForgeEnd(idList[i], globalData.IVal, changList)
- }
- if len(changList.List()) > 0 {
- this.ChangeNtf(changList, false)
- this.role.BaseChangeNtf()
- this.SetDirty(true)
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleEquip) getEquipListByType(equipType, subEquipType int32, idList *[]int32) {
- typeSet, ok := this.equipTypeList[equipType]
- if !ok {
- return
- }
- subEquipTypeStr := strconv.Itoa(int(subEquipType))
- if equipType == Equip_Type_Weapon {
- for _, idData := range typeSet.List() {
- equipId := idData.(int32)
- cfgData, ok2 := serverproto.EquipCfgLoader[equipId]
- if !ok2 || cfgData.Type != equipType {
- continue
- }
- if len(cfgData.JobType) > 0 {
- bFind := false
- for i := 0; i < len(cfgData.JobType); i++ {
- if cfgData.JobType[i] == subEquipTypeStr {
- bFind = true
- }
- }
- if !bFind {
- continue
- }
- }
- *idList = append(*idList, equipId)
- }
- } else {
- for _, idData := range typeSet.List() {
- equipId := idData.(int32)
- *idList = append(*idList, equipId)
- }
- }
- }
- //不考虑消耗获得能够合成的最大装备ID
- func (this *RoleEquip) equipForgeEndCheck(equipConfigId int32, baseNum int32, checkData map[int32]int32, maxEquipCfgId *int32) {
- cfgData, ok := serverproto.EquipCfgLoader[equipConfigId]
- equipData := this.GetEquip(equipConfigId)
- if !ok || equipData == nil {
- return
- }
- //同一个装备融合到不能融合为止
- addNum := equipData.Num / baseNum
- //消耗不够合成新装备
- if addNum <= 0 {
- return
- }
- _, okData := checkData[equipConfigId]
- if okData {
- checkData[equipConfigId] -= baseNum * addNum
- }
- _, okNewData := checkData[cfgData.Forge]
- if okNewData {
- checkData[cfgData.Forge] += addNum
- } else {
- checkData[cfgData.Forge] = addNum
- }
- if *maxEquipCfgId < cfgData.Forge {
- *maxEquipCfgId = cfgData.Forge
- }
- this.equipForgeEndCheck(cfgData.Forge, baseNum, checkData, maxEquipCfgId)
- }
- //给定装备合成到不能合成为止
- func (this *RoleEquip) equipForgeEnd(equipConfigId int32, baseNum int32, changIdList set.Interface) {
- cfgData, ok := serverproto.EquipCfgLoader[equipConfigId]
- equipData := this.GetEquip(equipConfigId)
- if !ok || equipData == nil {
- return
- }
- //判斷合成的装备是否存在
- _, ok1 := serverproto.EquipCfgLoader[cfgData.Forge]
- if !ok1 {
- return
- }
- //同一个装备融合到不能融合为止
- addNum := equipData.Num / baseNum
- costMoney := cfgData.CostMoney
- if this.role.GetMoney() < uint64(costMoney) || addNum <= 0 {
- return
- }
- for i := 0; i < int(addNum); i++ {
- if this.role.GetMoney() < uint64(costMoney) || equipData.Num < baseNum {
- break
- }
- this.role.AddMoney(AddItemST{ItemCount: costMoney}, false)
- //通知数据变化
- this.ReduceEquipNum(cfgData.Id, baseNum, false)
- //锻造成新的装备
- addEquip, _ := this.AddEquip(cfgData.Forge, 1)
- this.SetDirty(true)
- changIdList.Add(cfgData.Id)
- if addEquip != nil {
- changIdList.Add(cfgData.Forge)
- }
- //任务条件处理
- TaskMagCheck(this.role, serverproto.TaskType_Equip_Forge_Count, 1)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Merge_Equip, cfgData.Forge)
- this.equipForgeEnd(cfgData.Forge, baseNum, changIdList)
- }
- TaskMagCheck(this.role, serverproto.TaskType_Equip_Quality_Num, 0)
- }
- //获得最高阶装备
- func (this *RoleEquip) GetBeastEquip(equipType int32, jobType int32, detail *serverproto.SlotDetailData) int32 {
- if jobType < 0 {
- return 0
- }
- var bEquipLevel int32 = 0
- detailData := serverproto.EquipCfgLoader[detail.EquipId]
- if detailData != nil {
- bEquipLevel = detailData.EquipLevel
- }
- var equipId int32 = 0
- jobTypeStr := strconv.Itoa(int(jobType))
- for _, data := range this.equipList {
- cfgData, ok := serverproto.EquipCfgLoader[data.ConfigId]
- if !ok || cfgData.Type != equipType {
- continue
- }
- if data.Num <= 0 {
- continue
- }
- //职业装备查找()
- if jobType == 0 && equipType != Equip_Type_Weapon {
- //无职业要求
- if cfgData.EquipLevel > bEquipLevel {
- bEquipLevel = cfgData.EquipLevel
- equipId = data.ConfigId
- } else if cfgData.EquipLevel == bEquipLevel {
- if data.ConfigId > equipId {
- bEquipLevel = cfgData.EquipLevel
- equipId = data.ConfigId
- }
- }
- } else {
- for _, str := range cfgData.JobType {
- if str == jobTypeStr {
- if cfgData.EquipLevel > bEquipLevel {
- bEquipLevel = cfgData.EquipLevel
- equipId = data.ConfigId
- } else if cfgData.EquipLevel == bEquipLevel {
- if data.ConfigId > equipId {
- bEquipLevel = cfgData.EquipLevel
- equipId = data.ConfigId
- }
- }
- break
- }
- }
- }
- }
- return equipId
- }
- //一键装备
- func (this *RoleEquip) EquipUpAll(heroId int32, slotData *serverproto.SlotData) {
- var changIdList = set.New(set.NonThreadSafe)
- for i := Equip_Type_None; i < Equip_Type_Jew; i++ {
- detail := slotData.SlotList[i]
- slotIndex := int32(i + 1)
- slotType := this.role.GetRoleBase().GetSlotTypeByIndex(slotIndex)
- slotJobType := this.role.GetRoleHero().GetHeroJobType(heroId)
- //查找最高阶装备
- equipId := this.GetBeastEquip(slotType, slotJobType, detail)
- if detail.EquipId != 0 && detail.EquipId == equipId {
- continue
- }
- if equipId != 0 {
- if detail.EquipId != 0 {
- this.AddEquip(detail.EquipId, 1)
- changIdList.Add(detail.EquipId)
- }
- detail.EquipId = equipId
- this.ReduceEquipNum(equipId, 1, false)
- changIdList.Add(equipId)
- }
- }
- if len(changIdList.List()) > 0 {
- this.ChangeNtf(changIdList, true)
- //slot数据变更通知
- ntfMsg := &serverproto.SCSlotDataNtf{
- HeroId: heroId,
- Slot: &serverproto.SlotData{},
- }
- *ntfMsg.Slot = *slotData
- this.role.ReplayGate(ntfMsg, true)
- this.SetDirty(true)
- this.role.GetRoleBase().SetDirty(true)
- this.role.GetRoleHero().addHeroChange(heroId)
- this.onEquipUpAll(heroId)
- }
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Battle_Role_Quality, 0)
- }
- func (this *RoleEquip) onEquipUpAll(heroId int32) {
- //this.role.roleFightPower.equipAttrChange(heroId)
- this.role.roleBattleAttr.AttrChange(
- AttrChangeST{
- ChangeType: Attr_Change_Equip,
- ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
- })
- }
- func (this *RoleEquip) EquipUp(heroId int32, slotData *serverproto.SlotData, equipId int32, slotIndex int32) serverproto.ErrorCode {
- detail := slotData.SlotList[slotIndex-1]
- if equipId != 0 {
- //判断类型是否一致
- equipCfgData, ok := serverproto.EquipCfgLoader[equipId]
- equipData := this.GetEquip(equipId)
- if !ok || equipData == nil {
- return serverproto.ErrorCode_ERROR_EQUIP_CONFIG_DATA_NOT_FOUND
- }
- typeIndex := this.role.GetRoleBase().GetSlotIndexByType(equipCfgData.Type)
- if typeIndex != slotIndex {
- return serverproto.ErrorCode_ERROR_EQUIP_TYPE_NOT_MATCH
- }
- bFind := false
- slotHeroJobType := this.role.GetRoleHero().GetHeroJobType(heroId)
- for idx := range equipCfgData.JobType {
- typeValue, _ := model.Str2Num(equipCfgData.JobType[idx])
- if int32(typeValue) == slotHeroJobType {
- bFind = true
- break
- }
- }
- if !bFind && equipCfgData.Type == Equip_Type_Weapon {
- return serverproto.ErrorCode_ERROR_EQUIP_TYPE_NOT_MATCH
- }
- var changIdList = set.New(set.NonThreadSafe)
- if detail.EquipId != 0 {
- //卸下之前的装备
- tmpEquipId := detail.EquipId
- detail.EquipId = 0
- this.AddEquip(tmpEquipId, 1)
- changIdList.Add(tmpEquipId)
- }
- if equipId != 0 {
- //替换新装备
- detail.EquipId = equipId
- this.ReduceEquipNum(equipId, 1, false)
- changIdList.Add(detail.EquipId)
- }
- //装备变化通知
- this.ChangeNtf(changIdList, true)
- //slot数据变更通知
- ntfMsg := &serverproto.SCSlotDataNtf{
- HeroId: heroId,
- Slot: &serverproto.SlotData{},
- }
- *ntfMsg.Slot = *slotData
- this.role.ReplayGate(ntfMsg, true)
- this.SetDirty(true)
- this.role.GetRoleBase().SetDirty(true)
- this.role.GetRoleHero().addHeroChange(heroId)
- }
- this.onEquipUp(heroId)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Battle_Role_Quality, 0)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleEquip) onEquipUp(heroId int32) {
- //this.role.roleFightPower.equipAttrChange(heroId)
- this.role.roleBattleAttr.AttrChange(
- AttrChangeST{
- ChangeType: Attr_Change_Equip,
- ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
- })
- }
- func (this *RoleEquip) EquipDown(heroId int32, slotData *serverproto.SlotData, subType int32) {
- detailNum := len(slotData.SlotList)
- var changIdList = set.New(set.NonThreadSafe)
- //一键卸下
- if subType == 0 {
- for i := 0; i < detailNum; i++ {
- detail := slotData.SlotList[i]
- if detail != nil && detail.EquipId != 0 {
- tmpEquipId := detail.EquipId
- detail.EquipId = 0
- this.AddEquip(tmpEquipId, 1)
- changIdList.Add(tmpEquipId)
- }
- }
- } else {
- if subType <= Equip_Type_None || subType >= Equip_Type_Max {
- return
- }
- subIndex := this.role.GetRoleBase().GetSlotIndexByType(subType)
- if slotData.SlotList == nil || int32(len(slotData.SlotList)) < subIndex {
- return
- }
- detail := slotData.SlotList[subIndex-1]
- if detail != nil && detail.EquipId != 0 {
- tmpEquipId := detail.EquipId
- detail.EquipId = 0
- this.AddEquip(tmpEquipId, 1)
- changIdList.Add(tmpEquipId)
- }
- }
- if len(changIdList.List()) > 0 {
- this.ChangeNtf(changIdList, true)
- //slot数据变更通知
- ntfMsg := &serverproto.SCSlotDataNtf{
- HeroId: heroId,
- Slot: &serverproto.SlotData{},
- }
- *ntfMsg.Slot = *slotData
- this.role.ReplayGate(ntfMsg, true)
- this.SetDirty(true)
- this.role.GetRoleHero().addHeroChange(heroId)
- }
- this.onEquipDown(heroId)
- }
- func (this *RoleEquip) onEquipDown(heroId int32) {
- //this.role.roleFightPower.equipAttrChange(heroId)
- this.role.roleBattleAttr.AttrChange(
- AttrChangeST{
- ChangeType: Attr_Change_Equip,
- ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
- })
- }
- func (this *RoleEquip) EquipLevelUpAll(heroId int32, slotData *serverproto.SlotData) bool {
- var changeEquipList = set.New(set.NonThreadSafe)
- bChange := false
- if this.role.GetRoleEquip().equipLevelUpAll(heroId, slotData, changeEquipList) {
- bChange = true
- }
- //合并到不能合并为止
- //for {
- // ret := this.role.GetRoleEquip().equipLevelUpAll(heroId, slotData, changeEquipList)
- // break
- // if ret {
- // bChange = true
- // } else {
- // break
- // }
- //}
- if bChange {
- //slot数据变更通知
- ntfMsg := &serverproto.SCSlotDataNtf{
- HeroId: heroId,
- Slot: &serverproto.SlotData{},
- }
- *ntfMsg.Slot = *slotData
- util.DebugF("uid=%v EquipLevelUpAll SlotData=%v", this.role.GetUUid(), *slotData)
- this.role.ReplayGate(ntfMsg, true)
- //装备数据变化通知
- this.ChangeNtf(changeEquipList, false)
- this.SetDirty(true)
- //资源变更通知
- if !this.role.GetRoleHero().addHeroChange(heroId) {
- this.role.BaseChangeNtf()
- }
- this.role.GetRoleEquip().onEquipLevelUpAll(heroId)
- return true
- } else {
- ackMsg := &serverproto.SCEquipLevelUpAllAck{
- Error: int32(serverproto.ErrorCode_ERROR_EQUIP_LEVEL_UP_ALL_NONE),
- }
- this.role.ReplayGate(ackMsg, true)
- return false
- }
- }
- func (this *RoleEquip) equipLevelUpAll(heroId int32, slotData *serverproto.SlotData, changeEquipList set.Interface) bool {
- bLevelUp := false
- var levelUpOrder = []int{
- Equip_Type_Weapon, Equip_Type_Body,
- Equip_Type_Jew, Equip_Type_Head,
- Equip_Type_Wrap, Equip_Type_Shoes}
- //获取最小等级,并升级
- var minListSet = set.New(set.NonThreadSafe)
- var minEquipLevel int32 = 0
- detailNum := len(slotData.SlotList)
- for i := 0; i < detailNum; i++ {
- detail := slotData.SlotList[i]
- if detail == nil || detail.EquipId == 0 {
- continue
- }
- if cfgData, ok := serverproto.EquipCfgLoader[detail.EquipId]; ok {
- minListSet.Add(cfgData.EquipLevel)
- if minEquipLevel == 0 {
- minEquipLevel = cfgData.EquipLevel
- } else if minEquipLevel > cfgData.EquipLevel {
- minEquipLevel = cfgData.EquipLevel
- }
- }
- }
- minLevelList := minListSet.List()
- sort.Slice(minLevelList, func(i, j int) bool {
- return minLevelList[i].(int32) < minLevelList[j].(int32)
- })
- //var changeEquipList = set.New(set.NonThreadSafe)
- var excludeSlotIdx = set.New(set.NonThreadSafe)
- bChange := false
- for {
- bLevelUp = false
- //升级当前minEquipLevel等级的所有槽位装备
- for i := 0; i < len(levelUpOrder); i++ {
- if levelUpOrder[i] > len(slotData.SlotList) || excludeSlotIdx.Has(i) {
- continue
- }
- detail := slotData.SlotList[levelUpOrder[i]-1]
- if detail == nil || detail.EquipId == 0 {
- continue
- }
- cfgData, ok := serverproto.EquipCfgLoader[detail.EquipId]
- if !ok || cfgData.EquipLevel != minEquipLevel {
- continue
- }
- var totalCostMoney uint64 = 0
- if this.slotEquipLevelUp(detail, changeEquipList, &totalCostMoney) {
- changeEquipList.Add(cfgData.Id)
- bLevelUp = true
- //消耗金钱
- this.role.DelItem(int32(serverproto.ResType_Res_Coin), int32(totalCostMoney), AddItemST{AddFrom: AddFrom_Equip})
- excludeSlotIdx.Add(i)
- }
- }
- minEquipLevel++
- if bLevelUp {
- bChange = true
- }
- bFind := false
- for _, data := range minLevelList {
- if minEquipLevel <= data.(int32) {
- minEquipLevel = data.(int32)
- bFind = true
- break
- }
- }
- if !bFind {
- break
- }
- }
- if bChange {
- return true
- }
- return false
- }
- func (this *RoleEquip) onEquipLevelUpAll(heroId int32) {
- //this.role.roleFightPower.equipAttrChange(heroId)
- this.role.roleBattleAttr.AttrChange(
- AttrChangeST{
- ChangeType: Attr_Change_Equip,
- ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
- })
- }
- //对应槽位进行升级
- func (this *RoleEquip) SlotLevelUp(slotData *serverproto.SlotData, heroId int32, subSlotIndex int32) serverproto.ErrorCode {
- if subSlotIndex > int32(len(slotData.SlotList)) || subSlotIndex <= 0 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- slotDetail := slotData.SlotList[subSlotIndex-1]
- if slotDetail.EquipId <= 0 {
- return serverproto.ErrorCode_ERROR_EQUIP_SLOT_NO_EQUIP
- }
- slotType := this.role.GetRoleBase().GetSlotTypeByIndex(subSlotIndex)
- cfgData, ok := serverproto.EquipRefineCfgLoader[slotDetail.Level+1]
- if !ok {
- return serverproto.ErrorCode_ERROR_EQUIP_REFINE_DATA_NOT_FOUND
- }
- //获取消耗
- ret := serverproto.ErrorCode_ERROR_OK
- var costZeny int32 = 0
- var costItemList = map[int32]int32{}
- slotTypeStr := strconv.Itoa(int(slotType))
- for index, _ := range cfgData.Place1 {
- if cfgData.Place1[index] == slotTypeStr {
- costZeny = cfgData.Costzeny1
- for index1, _ := range cfgData.Costitem1 {
- resType, resValue := model.Str2Res(cfgData.Costitem1[index1])
- costItemList[resType] = resValue
- }
- break
- }
- }
- if costZeny == 0 {
- for index, _ := range cfgData.Place2 {
- if cfgData.Place2[index] == slotTypeStr {
- costZeny = cfgData.Costzeny2
- for index1, _ := range cfgData.Costitem2 {
- resType, resValue := model.Str2Res(cfgData.Costitem2[index1])
- costItemList[resType] = resValue
- }
- break
- }
- }
- }
- if this.role.GetResNum(int32(serverproto.ResType_Res_Coin)) >= uint64(costZeny) &&
- this.role.CheckResLitNum(costItemList) {
- this.role.AddRes(int32(serverproto.ResType_Res_Coin), AddItemST{ItemCount: costZeny}, false)
- this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_Equip})
- //成功概率
- randNum := rand.Int31n(10000)
- if randNum <= cfgData.Rate {
- slotDetail.Level++
- //任务条件处理
- TaskMagCheck(this.role, serverproto.TaskType_Equip_Level_Num, 0)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Equip_Level_Role, 0)
- } else {
- ret = serverproto.ErrorCode_ERROR_EQUIP_REFINE_FAILED
- }
- //更新槽位信息
- ntfMsg := &serverproto.SCSlotDataNtf{
- HeroId: heroId,
- Slot: &serverproto.SlotData{},
- }
- *ntfMsg.Slot = *slotData
- this.role.ReplayGate(ntfMsg, true)
- this.SetDirty(true)
- if !this.role.GetRoleHero().addHeroChange(heroId) {
- this.role.GetRoleBase().BaseChangeNtf()
- }
- this.onSlotLevelUp(heroId)
- } else {
- ret = serverproto.ErrorCode_ERROR_RES_NOT_ENOUGH
- }
- return ret
- }
- func (this *RoleEquip) onSlotLevelUp(heroId int32) {
- //任务条件处理
- TaskMagCheck(this.role, serverproto.TaskType_Equip_Level_Count, 1)
- //this.role.roleFightPower.equipAttrChange(heroId)
- this.role.roleBattleAttr.AttrChange(
- AttrChangeST{
- ChangeType: Attr_Change_Equip,
- ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
- })
- }
- //对槽位中的装备升级
- func (this *RoleEquip) slotEquipLevelUp(detail *serverproto.SlotDetailData, changeList set.Interface, totalCostMoney *uint64) bool {
- globalData, ok1 := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Equip_Forging_Num)]
- cfgData, ok2 := serverproto.EquipCfgLoader[detail.EquipId]
- equipData, ok3 := this.equipList[cfgData.Id]
- if !ok1 || !ok2 {
- util.DebugF("slotEquipLevelUp config data not found id=%v", cfgData.Id)
- return false
- }
- //锻造的装备是否存在
- _, ok := serverproto.EquipCfgLoader[cfgData.Forge]
- if !ok {
- util.DebugF("slotEquipLevelUp forge config data not found id=%v forge=%v", cfgData.Forge)
- return false
- }
- if this.role.GetMoney() < *totalCostMoney+uint64(cfgData.CostMoney) {
- util.DebugF("uid=%v slotEquipLevelUp money not enough costmoney=%v", this.role.GetUUid(), cfgData.CostMoney)
- return false
- }
- //计算已经装备的装备
- var equipDataNum int32 = 1
- if ok3 {
- equipDataNum += equipData.Num
- }
- var tmpCheckCostMoney uint64 = 0
- if equipDataNum < globalData.IVal {
- checkNum := (globalData.IVal - equipDataNum) * globalData.IVal
- if !this.checkEquipNum(cfgData.Id, globalData.IVal-1, globalData.IVal, &tmpCheckCostMoney) {
- //if !this.checkEquipNum(cfgData.ForgeOld, checkNum, globalData.IVal, &tmpCheckCostMoney) {
- util.DebugF("uid=%v slotEquipLevelUp num not enough cfgid=%v num=%v", this.role.GetUUid(), cfgData.Id, equipDataNum)
- return false
- } else {
- *totalCostMoney += tmpCheckCostMoney
- if this.role.GetMoney() < *totalCostMoney+uint64(cfgData.CostMoney) {
- util.DebugF("uid=%v slotEquipLevelUp money not enough money=%v costmoney=%v", this.role.GetUUid(), this.role.GetMoney(), *totalCostMoney)
- return false
- }
- //可以升级并消耗装备
- this.consumeNeedEquip(cfgData.ForgeOld, checkNum, globalData.IVal, changeList)
- }
- }
- *totalCostMoney += uint64(cfgData.CostMoney)
- //消耗金钱
- //this.role.AddMoney(cfgData.CostMoney, false)
- //通知数据变化
- //this.ReduceEquipNum(cfgData.Id, globalData.IVal-1, false)
- if equipData != nil {
- oldNum := equipData.Num
- equipData.Num -= globalData.IVal - 1
- if equipData.Num <= 0 {
- equipData.Num = 0
- }
- util.InfoF("uid=%v equip num old=%v new=%v", this.role.uuid, oldNum, equipData.Num)
- }
- //部位装备高阶装备
- detail.EquipId = cfgData.Forge
- //任务处理
- TaskMagCheck(this.role, serverproto.TaskType_Equip_Forge_Count, 1)
- TaskMagCheck(this.role, serverproto.TaskType_Equip_Quality_Num, 0)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Merge_Equip, cfgData.Forge)
- return true
- }
- func (this *RoleEquip) checkEquipNum(equipConfigId int32, checkNum int32, baseNum int32, tmpCheckCostMoney *uint64) bool {
- cfgData, ok := serverproto.EquipCfgLoader[equipConfigId]
- if !ok {
- return false
- }
- var needNum int32
- equipData, ok := this.equipList[equipConfigId]
- if ok {
- if equipData.Num >= checkNum {
- return true
- } else {
- needNum = (checkNum - equipData.Num) * baseNum
- oldCfg, oldOk := serverproto.EquipCfgLoader[cfgData.ForgeOld]
- if oldOk {
- *tmpCheckCostMoney += uint64(oldCfg.CostMoney * (checkNum - equipData.Num))
- }
- }
- } else {
- needNum = checkNum * baseNum
- oldCfg, oldOk := serverproto.EquipCfgLoader[cfgData.ForgeOld]
- if oldOk {
- *tmpCheckCostMoney += uint64(oldCfg.CostMoney * checkNum)
- }
- }
- //做保护处理
- if needNum > 0xffffff {
- return false
- }
- return this.checkEquipNum(cfgData.ForgeOld, needNum, baseNum, tmpCheckCostMoney)
- }
- func (this *RoleEquip) consumeNeedEquip(equipConfigId int32, checkNum int32, baseNum int32, changList set.Interface) bool {
- cfgData, ok := serverproto.EquipCfgLoader[equipConfigId]
- if !ok {
- return false
- }
- var needNum int32
- equipData, ok := this.equipList[equipConfigId]
- if ok {
- if equipData.Num >= checkNum {
- this.ReduceEquipNum(equipConfigId, checkNum, false)
- changList.Add(equipConfigId)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Merge_Equip, cfgData.Forge)
- return true
- } else {
- needNum = (checkNum - equipData.Num) * baseNum
- this.ReduceEquipNum(equipConfigId, equipData.Num, false)
- changList.Add(equipConfigId)
- }
- } else {
- needNum = checkNum * baseNum
- }
- //做保护处理
- if needNum > 0xffffff {
- return false
- }
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Merge_Equip, cfgData.Forge)
- return this.consumeNeedEquip(cfgData.ForgeOld, needNum, baseNum, changList)
- }
- ///Task
- func (this *RoleEquip) GetQualityEquipNum(quality int32) int32 {
- var retNum int32 = 0
- if quality <= 0 {
- for _, data := range this.equipList {
- retNum += data.Num
- }
- } else {
- for _, data := range this.equipList {
- itemCfgData := GetItemCfg(data.ConfigId)
- if itemCfgData != nil && itemCfgData.Quality >= quality {
- retNum += data.Num
- }
- }
- }
- //玩家身上的装备
- retNum += this.role.GetRoleHero().GetQualityEquipNum(quality)
- return retNum
- }
- ///Task
- func (this *RoleEquip) GetQualityEquipNumAll(quality int32) bool {
- //var retNum int32 = 0
- //玩家身上的装备
- if this.role.GetRoleBase() == nil || this.role.GetRoleBase().RoleData().HeroData == nil {
- return false
- }
- slot := this.role.GetRoleBase().RoleData().HeroData.Slot
- for _, data := range slot.SlotList {
- if data.EquipId <= 0 {
- return false
- }
- itemCfgData := GetItemCfg(data.EquipId)
- if itemCfgData == nil {
- return false
- }
- if itemCfgData.Quality < quality {
- return false
- }
- }
- hero := this.role.GetRoleHero()
- if hero == nil {
- return false
- }
- for _, heroData := range hero.heroList {
- if heroData.Slot == nil {
- continue
- }
- for _, slotdata := range heroData.Slot.SlotList {
- if slotdata.EquipId <= 0 {
- return false
- }
- itemCfgData := GetItemCfg(slotdata.EquipId)
- if itemCfgData != nil {
- return false
- }
- if itemCfgData.Quality < quality {
- return false
- }
- }
- }
- return true
- }
|