| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259 |
- package model
- import (
- "math/rand"
- "rocommon/util"
- "roserver/baseserver/model"
- "roserver/baseserver/set"
- "roserver/serverproto"
- "sort"
- "strings"
- )
- const (
- Max_Card_Slot_Num = 4 //最大卡槽数量
- Card_Slot_Index_1 = 0x1
- Card_Slot_Index_2 = 0x2
- Card_Slot_Index_3 = 0x4
- Card_Slot_Index_4 = 0x8
- )
- type RoleCard struct {
- SaveObject
- //部位卡槽解锁信息
- cardSlotList []int32
- cardList map[int32]*serverproto.CardData
- cardCollect map[int32]*serverproto.CardCollect
- //同品质卡片数量
- totalCardNumList []*serverproto.KeyValueType
- }
- func newRoleCard(r *Role) *RoleCard {
- roleCard := &RoleCard{
- SaveObject: SaveObject{
- role: r,
- },
- }
- roleCard.cardList = map[int32]*serverproto.CardData{}
- roleCard.cardCollect = map[int32]*serverproto.CardCollect{}
- return roleCard
- }
- func (this *RoleCard) Load(msg interface{}) bool {
- proRole := msg.(*serverproto.Role)
- if proRole.RoleCard != nil {
- //if !this.role.GetRoleBase().roleBase.RoleDelete5 {
- // m := map[int32]int{
- // 22100: 1, 22101: 1, 22102: 1, 22103: 1, 22104: 1, 22105: 1, 22106: 1, 22107: 1, 22108: 1, 22109: 1, 22110: 1, 22111: 1,
- // 22200: 1, 22201: 1, 22202: 1, 22203: 1, 22204: 1, 22205: 1, 22206: 1, 22207: 1, 22208: 1, 22209: 1, 22210: 1, 22211: 1,
- // 22300: 1, 22301: 1, 22302: 1, 22303: 1, 22304: 1, 22305: 1, 22306: 1, 22307: 1, 22308: 1, 22309: 1, 22310: 1, 22311: 1,
- // 22400: 1, 22401: 1, 22402: 1, 22403: 1, 22404: 1, 22405: 1, 22406: 1, 22407: 1, 22408: 1, 22409: 1, 22410: 1, 22411: 1,
- // 22500: 1, 22501: 1, 22502: 1, 22503: 1, 22504: 1, 22505: 1, 22506: 1, 22507: 1, 22508: 1, 22509: 1, 22510: 1, 22511: 1,
- // }
- // for _, data := range proRole.RoleCard.CardList {
- // _, ok := serverproto.CardCfgLoader[data.ConfigId]
- // if !ok || data.Num <= 0 {
- // continue
- // }
- // //噩梦bug删除红卡
- // if _, ok2 := m[data.ConfigId]; ok2 {
- // continue
- // }
- //
- // this.cardList[data.ConfigId] = data
- // }
- // this.role.GetRoleBase().roleBase.RoleDelete5 = true
- // this.role.GetRoleBase().SetDirty(true)
- // util.ErrorF("delete card uuid:%v", this.role.GetUUid())
- //} else {
- for _, data := range proRole.RoleCard.CardList {
- _, ok := serverproto.CardCfgLoader[data.ConfigId]
- if !ok || data.Num <= 0 {
- continue
- }
- this.cardList[data.ConfigId] = data
- }
- //}
- if len(proRole.RoleCard.CardSlotList) <= 0 {
- this.cardSlotList = make([]int32, Equip_Type_Max-1)
- this.SetDirty(true)
- } else {
- this.cardSlotList = proRole.RoleCard.CardSlotList
- }
- for _, data := range proRole.RoleCard.CardCollect {
- this.cardCollect[data.CardQuality] = data
- }
- this.totalCardNumList = proRole.RoleCard.TotalCardNumList
- this.SetDirty(true)
- }
- return true
- }
- func (this *RoleCard) Save() {
- this.SetDirty(false)
- //util.DebugF("uid=%v RoleCard save...", this.role.GetUUid())
- saveMsg := &serverproto.SSCardDataSaveReq{
- Card: &serverproto.RoleCard{
- TotalCardNumList: this.totalCardNumList,
- },
- }
- for _, data := range this.cardList {
- saveMsg.Card.CardList = append(saveMsg.Card.CardList, data)
- }
- saveMsg.Card.CardSlotList = this.cardSlotList
- for _, collect := range this.cardCollect {
- saveMsg.Card.CardCollect = append(saveMsg.Card.CardCollect, collect)
- }
- this.role.SendDb(saveMsg)
- }
- func (this *RoleCard) CopyData(data *serverproto.RoleCard) {
- data.CardSlotList = this.cardSlotList
- for _, cardData := range this.cardList {
- data.CardList = append(data.CardList, cardData)
- }
- }
- func (this *RoleCard) GetCardPileTotalNum() int {
- return len(this.cardList)
- }
- func (this *RoleCard) getCard(cardCfgId int32) *serverproto.CardData {
- cardData, ok := this.cardList[cardCfgId]
- if ok {
- return cardData
- }
- return nil
- }
- func (this *RoleCard) getCardCfgData(cardCfgId int32) *serverproto.CardCfg {
- cfgData, ok := serverproto.CardCfgLoader[cardCfgId]
- if ok {
- return cfgData
- }
- return nil
- }
- func (this *RoleCard) cardChangNtf(cardList set.Interface, ignore bool) {
- if len(cardList.List()) <= 0 {
- return
- }
- ntfMsg := &serverproto.SCCardChangeNtf{
- Ignore: ignore,
- }
- for _, data := range cardList.List() {
- cardConfigId := data.(int32)
- card := this.getCard(cardConfigId)
- if card != nil {
- ntfMsg.CardList = append(ntfMsg.CardList, &serverproto.CardData{
- ConfigId: cardConfigId,
- Num: card.Num,
- })
- } else {
- ntfMsg.CardList = append(ntfMsg.CardList, &serverproto.CardData{
- ConfigId: cardConfigId,
- Num: 0,
- })
- }
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- // 判断对应卡槽是否解锁
- func (this *RoleCard) isCardSlotUnlock(slotIndex, cardSlotIndex int32) bool {
- if slotIndex <= int32(len(this.cardSlotList)) && cardSlotIndex > 0 {
- return this.cardSlotList[slotIndex-1]&(1<<uint32(cardSlotIndex-1)) > 0
- }
- return false
- }
- func (this *RoleCard) AddCard(cardCfgId int32, count int32, notify bool, ignore bool, isNew bool) {
- cfgData, ok := serverproto.CardCfgLoader[cardCfgId]
- if !ok {
- return
- }
- var oldVal int32 = 0
- cardData := this.getCard(cardCfgId)
- if cardData != nil {
- oldVal = cardData.Num
- cardData.Num += count
- } else {
- cardData = &serverproto.CardData{
- ConfigId: cardCfgId,
- Num: count,
- }
- this.cardList[cardCfgId] = cardData
- }
- if isNew == true {
- TaskMagCheck(this.role, serverproto.TaskType_Get_Card_Count, count)
- //卡片成就
- this.AddCardCollect(cardCfgId)
- bFind := false
- for idx := 0; idx < len(this.totalCardNumList); idx++ {
- if this.totalCardNumList[idx].Key == cfgData.CardType {
- this.totalCardNumList[idx].Value += count
- bFind = true
- break
- }
- }
- if !bFind {
- this.totalCardNumList = append(this.totalCardNumList,
- &serverproto.KeyValueType{Key: cfgData.CardType, Value: count})
- }
- }
- this.SetDirty(true)
- if notify {
- changeNtf := &serverproto.SCCardChangeNtf{
- Ignore: ignore,
- }
- changeNtf.CardList = append(changeNtf.CardList, cardData)
- this.role.ReplayGate(changeNtf, true)
- }
- TaskMagCheck(this.role, serverproto.TaskType_Card_Quality_Num, 0)
- util.InfoF("uid=%v AddCard id=%v old=%v new=%v addval=%v add=%v, isNew=%v", this.role.GetUUid(), cardCfgId,
- oldVal, cardData.Num, count, true, isNew)
- }
- func (this *RoleCard) RemoveCard(cardCfgId int32) {
- delete(this.cardList, cardCfgId)
- }
- func (this *RoleCard) ReduceCard(cardCfgId, reduceNum int32, notify bool) {
- cardData := this.getCard(cardCfgId)
- if cardData != nil && reduceNum > 0 {
- cardData.Num -= reduceNum
- if cardData.Num <= 0 {
- cardData.Num = 0
- this.RemoveCard(cardCfgId)
- }
- this.SetDirty(true)
- }
- if notify {
- changeNtf := &serverproto.SCCardChangeNtf{}
- changeNtf.CardList = append(changeNtf.CardList, cardData)
- this.role.ReplayGate(changeNtf, true)
- }
- }
- // 装备对应槽位镶嵌卡片
- func (this *RoleCard) Mount(slotData *serverproto.SlotData, heroId, subSlotIndex, cardSlotIndex, cardCfgId int32, fightChange bool) serverproto.ErrorCode {
- if subSlotIndex <= 0 || cardSlotIndex <= 0 {
- return serverproto.ErrorCode_ERROR_CARD_SLOT_LOCK
- }
- cardData := this.getCard(cardCfgId)
- cardCfgData, ok := serverproto.CardCfgLoader[cardCfgId]
- if cardData == nil || !ok || cardData.Num <= 0 {
- util.DebugF("uid=%v Mount card not found cardCfgId=%v", this.role.GetUUid(), cardCfgId)
- return serverproto.ErrorCode_ERROR_CARD_NOT_FOUND
- }
- //card slot no unlock
- if !this.isCardSlotUnlock(subSlotIndex, cardSlotIndex) {
- util.DebugF("uid=%v Mount card slot lock subSlotIndex=%v cardSlotIndex=%v", this.role.GetUUid(), subSlotIndex, cardSlotIndex)
- return serverproto.ErrorCode_ERROR_CARD_SLOT_LOCK
- }
- //check card type and slot type
- slotType := this.role.GetRoleBase().GetSlotTypeByIndex(subSlotIndex)
- if slotType != cardCfgData.CardLocation {
- return serverproto.ErrorCode_ERROR_CARD_TYPE_NOT_MATCH
- }
- var changIdList = set.New(set.NonThreadSafe)
- slotDetail := slotData.SlotList[subSlotIndex-1]
- if slotDetail != nil && slotDetail.EquipId != 0 {
- //已经存在卡槽数据
- if cardSlotIndex <= int32(len(slotDetail.CardIdList)) {
- if slotDetail.CardIdList[cardSlotIndex-1] != 0 {
- changIdList.Add(slotDetail.CardIdList[cardSlotIndex-1])
- this.AddCard(slotDetail.CardIdList[cardSlotIndex-1], 1, false, false, false)
- }
- } else {
- //不存在卡槽数据
- for i := len(slotDetail.CardIdList); i < int(cardSlotIndex); i++ {
- slotDetail.CardIdList = append(slotDetail.CardIdList, 0)
- }
- }
- slotDetail.CardIdList[cardSlotIndex-1] = cardCfgId
- this.ReduceCard(cardCfgId, 1, false)
- changIdList.Add(cardCfgId)
- this.SetDirty(true)
- } else {
- return serverproto.ErrorCode_ERROR_EQUIP_SLOT_NO_EQUIP
- }
- util.DebugF("uid=%v Mount success heroId=%v subSlotIndex=%v cardSlotIndex=%v cardId=%v", this.role.GetUUid(),
- subSlotIndex, cardSlotIndex, cardCfgId)
- this.cardChangNtf(changIdList, true)
- this.onMount(heroId, subSlotIndex, fightChange)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleCard) onMount(heroId, subSlotIndex int32, fightChange bool) {
- if fightChange == true {
- //this.role.roleFightPower.CardAttrChange(heroId, subSlotIndex)
- }
- }
- func (this *RoleCard) CardDownAll(slotData *serverproto.SlotData, subSlotIndex, heroId int32, fightChange bool) serverproto.ErrorCode {
- if subSlotIndex > int32(len(slotData.SlotList)) || subSlotIndex <= 0 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- var changIdList = set.New(set.NonThreadSafe)
- slotDetail := slotData.SlotList[subSlotIndex-1]
- for i := range slotDetail.CardIdList {
- if slotDetail.CardIdList[i] != 0 {
- this.AddCard(slotDetail.CardIdList[i], 1, false, false, false)
- changIdList.Add(slotDetail.CardIdList[i])
- slotDetail.CardIdList[i] = 0
- }
- }
- if len(changIdList.List()) > 0 {
- this.cardChangNtf(changIdList, true)
- this.SetDirty(true)
- if fightChange == true {
- this.onCardDown(heroId)
- //this.role.GetRoleFightPower().AllCardAttrChange(heroId)
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- return serverproto.ErrorCode_ERROR_CARD_SLOT_HAS_NO_CARD
- }
- func (this *RoleCard) onCardDown(heroId int32) {
- this.role.roleBattleAttr.AttrChange(
- AttrChangeST{
- ChangeType: Attr_Change_Card,
- ChangeHeroData: this.role.GetRoleHero().GetHero(heroId),
- })
- }
- func (this *RoleCard) CardDown(slotData *serverproto.SlotData, subSlotIndex, cardSlotIndex, heroId int32) serverproto.ErrorCode {
- if subSlotIndex > int32(len(slotData.SlotList)) || subSlotIndex <= 0 || cardSlotIndex <= 0 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if cardSlotIndex > int32(len(slotData.SlotList[subSlotIndex-1].CardIdList)) {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- var changIdList = set.New(set.NonThreadSafe)
- slotDetail := slotData.SlotList[subSlotIndex-1]
- if slotDetail.CardIdList[cardSlotIndex-1] != 0 {
- this.AddCard(slotDetail.CardIdList[cardSlotIndex-1], 1, false, false, false)
- changIdList.Add(slotDetail.CardIdList[cardSlotIndex-1])
- slotDetail.CardIdList[cardSlotIndex-1] = 0
- this.cardChangNtf(changIdList, true)
- this.SetDirty(true)
- this.onCardDown(heroId)
- //this.role.roleFightPower.CardAttrChange(heroId, subSlotIndex)
- return serverproto.ErrorCode_ERROR_OK
- }
- return serverproto.ErrorCode_ERROR_FAIL
- }
- func (this *RoleCard) GetCardComposeWeight(cardType int32, cardLevel int32) (int32, int32, int32) {
- index := cardType*1000 + cardLevel
- weightCfg, ok := model.ConvertCardResetList[index]
- if !ok {
- return 0, 0, 0
- }
- return weightCfg.Normal, weightCfg.Mini, weightCfg.Boss
- }
- func (this *RoleCard) CardCompose(composeCardIdList []int32) (serverproto.ErrorCode, int32) {
- if len(composeCardIdList) < 3 {
- return serverproto.ErrorCode_ERROR_FAIL, 0
- }
- globalCfgData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Card_Compose_Cost)]
- if !ok {
- util.InfoF("uid=%v Global_Card_Compose_Cost data not found id=%v!!!", this.role.GetUUid(), serverproto.GlobalType_Global_Card_Compose_Cost)
- return serverproto.ErrorCode_ERROR_FAIL, 0
- }
- vipPetCompose := this.role.GetRoleBase().GetVipData(model.Vip_System_CardReset)
- //重置消耗资源
- var costItemList = map[int32]int32{}
- costStr := strings.Split(globalCfgData.SVal, ";")
- for index := range costStr {
- resType, resValue := model.Str2Res(costStr[index])
- costItemList[resType] = resValue
- }
- //不是VIP才需要检查银币数量
- if vipPetCompose <= 0 && !this.role.CheckResLitNum(costItemList) {
- return serverproto.ErrorCode_ERROR_RES_NOT_ENOUGH, 0
- }
- var normalWeight int32 = 0
- var miniWeight int32 = 0
- var mvpWeight int32 = 0
- var changIdList = set.New(set.NonThreadSafe)
- for _, data := range composeCardIdList {
- cfgData := this.getCardCfgData(data)
- cardData := this.getCard(data)
- if cfgData == nil || cardData == nil || cardData.Num <= 0 {
- return serverproto.ErrorCode_ERROR_CARD_NOT_FOUND, 0
- }
- normal, mini, mvp := this.GetCardComposeWeight(cfgData.CardType, cfgData.CardLevel)
- if normal == 0 && mini == 0 && mvp == 0 {
- util.ErrorF("uid=%v CardCompose config error=all weight are zero cardId=%v", this.role.GetUUid(), data)
- continue
- }
- normalWeight += normal
- miniWeight += mini
- mvpWeight += mvp
- this.ReduceCard(data, 1, false)
- changIdList.Add(data)
- }
- rand.Seed(int64(util.GetTimeMilliseconds()))
- miniWeight = normalWeight + miniWeight
- mvpWeight = miniWeight + mvpWeight
- randWeight := rand.Int31n(mvpWeight) //[0,mvpWeight)
- var randCardId int32 = 0
- if randWeight >= 0 && randWeight < normalWeight && normalWeight != 0 {
- //normal
- randCardId = this.randCardByType(model.Card_Type_Normal)
- } else if randWeight >= normalWeight && randWeight < miniWeight && miniWeight != 0 {
- //mini
- randCardId = this.randCardByType(model.Card_Type_Mini)
- } else if randWeight >= miniWeight && randWeight < mvpWeight && mvpWeight != 0 {
- //mvp
- randCardId = this.randCardByType(model.Card_Type_MVP)
- }
- if randCardId == 0 {
- //严重错误
- util.ErrorF("uid=%v CardCompose randCardId is invalid !!!", this.role.GetUUid())
- return serverproto.ErrorCode_ERROR_FAIL, 0
- }
- util.InfoF("uid=%v CardCompose weight=%v|%v|%v|%v ComposeCardId=%v", this.role.GetUUid(),
- normalWeight, miniWeight, mvpWeight, randWeight, randCardId)
- if vipPetCompose <= 0 {
- this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_Card_Decompose})
- }
- this.AddCard(randCardId, 1, false, false, true)
- changIdList.Add(randCardId)
- this.cardChangNtf(changIdList, true)
- TaskMagCheck(this.role, serverproto.TaskType_Card_Reset_Count, 1)
- return serverproto.ErrorCode_ERROR_OK, randCardId
- }
- func (this *RoleCard) CardDecompose(cardList []*serverproto.KeyValueType, cardType int32) serverproto.ErrorCode {
- var resList = map[int32]int32{}
- var changIdList = set.New(set.NonThreadSafe)
- //一键分解
- if len(cardList) <= 0 {
- for _, data := range this.cardList {
- cfgData, ok := serverproto.ItemCfgLoader[data.ConfigId]
- if !ok {
- continue
- }
- for i := range cfgData.Resolve {
- resType, resVal := model.Str2Res(cfgData.Resolve[i])
- if resType > 0 && resVal > 0 {
- resList[int32(resType)] += int32(resVal) * data.Num
- }
- }
- changIdList.Add(data.ConfigId)
- this.ReduceCard(data.ConfigId, data.Num, false)
- }
- } else {
- for _, data := range cardList {
- if data.Value <= 0 {
- continue
- }
- cardData := this.getCard(data.Key)
- if cardData == nil {
- continue
- }
- cfgData := serverproto.ItemCfgLoader[cardData.ConfigId]
- if cardData != nil && cfgData != nil && cardData.Num > 0 {
- resNum := cardData.Num
- if data.Value < cardData.Num {
- resNum = data.Value
- }
- for i := range cfgData.Resolve {
- resType, resVal := model.Str2Res(cfgData.Resolve[i])
- if resType > 0 && resVal > 0 {
- resList[int32(resType)] += int32(resVal) * resNum
- }
- }
- changIdList.Add(data.Key)
- this.ReduceCard(data.Key, resNum, false)
- }
- }
- }
- if ret := this.role.CanAddItemList(resList); ret != serverproto.ErrorCode_ERROR_OK {
- util.ErrorF("uid=%v CardDecompose ret=%v", this.role.GetUUid(), ret)
- }
- this.role.AddItemList(resList, AddFrom_Card_Decompose, true)
- //通知卡片数据变更
- this.cardChangNtf(changIdList, false)
- //客户端显示获得的资源
- ackMsg := &serverproto.SCCardDecomposeAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- }
- for itemType, itemCount := range resList {
- ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
- Key: itemType,
- Value: itemCount,
- })
- }
- this.role.ReplayGate(ackMsg, true)
- util.InfoF("uid=%v CardDecompose addResList=%v decomposeCardList=%v", this.role.GetUUid(), resList, changIdList.List())
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleCard) CheckUnLockState() serverproto.ErrorCode {
- ntfMsg := &serverproto.SCCardSlotChangeNtf{}
- for i := Equip_Type_Head; i < Equip_Type_Max; i++ {
- cardSlotData := this.cardSlotList[i-1]
- for j := 0; j < Max_Card_Slot_Num; j++ {
- //已经解锁
- if (cardSlotData & (1 << uint32(j))) != 0 {
- continue
- }
- cardSlotID := int32(i*100 + j + 1)
- cfgData, ok := model.ConvertCardUnlock[cardSlotID]
- if !ok {
- continue
- }
- mainHeroId := this.role.roleHero.GetMainHero().Id
- ret := this.role.GetRoleBase().checkUnLockState(mainHeroId, cfgData.ConditionList)
- if ret != serverproto.ErrorCode_ERROR_OK {
- continue
- }
- cardSlotData |= 1 << uint32(j)
- this.SetDirty(true)
- }
- if this.cardSlotList[i-1] != cardSlotData {
- this.cardSlotList[i-1] = cardSlotData
- ntfMsg.SlotList = append(ntfMsg.SlotList, &serverproto.KeyValueType{
- Key: int32(i),
- Value: cardSlotData,
- })
- }
- }
- if len(ntfMsg.SlotList) > 0 {
- this.role.ReplayGate(ntfMsg, true)
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleCard) randCardByType(cardType int32) int32 {
- var randWeight int32
- switch cardType {
- case model.Card_Type_Normal:
- randWeight = model.CardNormalCfgList[len(model.CardNormalCfgList)-1].Weight
- randWeight = rand.Int31n(randWeight) //[0,randWeight)
- return this.randCard(randWeight, &model.CardNormalCfgList)
- case model.Card_Type_Mini:
- randWeight = model.CardMiniCfgList[len(model.CardMiniCfgList)-1].Weight
- randWeight = rand.Int31n(randWeight) //[0,randWeight)
- return this.randCard(randWeight, &model.CardMiniCfgList)
- case model.Card_Type_MVP:
- randWeight = model.CardMvpCfgList[len(model.CardMvpCfgList)-1].Weight
- randWeight = rand.Int31n(randWeight) //[0,randWeight)
- return this.randCard(randWeight, &model.CardMvpCfgList)
- }
- return 0
- }
- func (this *RoleCard) randCard(randWeight int32, cardWeightList *[]*model.CardWeightDat) int32 {
- for _, data := range *cardWeightList {
- if randWeight < data.Weight {
- return data.CardCfgId
- }
- }
- return 0
- }
- func (this *RoleCard) BagCardUpGrade(msg *serverproto.CSCardUpGradeReq, ackMsg *serverproto.SCCardUpGradeAck) {
- if msg == nil || ackMsg == nil {
- return
- }
- var changIdList = set.New(set.NonThreadSafe)
- for _, data := range msg.ConfigIds {
- if data.Key <= 0 || data.Value <= 0 {
- continue
- }
- if bRet, newCfgId, cardCount := this.CardUpGrade(data.Key, data.Value); bRet == serverproto.ErrorCode_ERROR_OK {
- changIdList.Add(data.Key)
- changIdList.Add(newCfgId)
- ackMsg.ConfigIds = append(ackMsg.ConfigIds, &serverproto.KeyValueType{
- Key: newCfgId,
- Value: cardCount,
- })
- ackMsg.Error = int32(serverproto.ErrorCode_ERROR_OK)
- }
- }
- this.cardChangNtf(changIdList, true)
- }
- func (this *RoleCard) CardUpGrade(cardId int32, cardNum int32) (serverproto.ErrorCode, int32, int32) {
- //判定待合成卡片数量是否足够
- cardData := this.getCard(cardId)
- if cardData == nil || cardData.Num < Card_Up_Grade_Need_Num || cardData.Num < cardNum || cardNum < Card_Up_Grade_Need_Num {
- return serverproto.ErrorCode_ERROR_FAIL, 0, 0
- }
- oldCardCfg, ok := serverproto.CardCfgLoader[cardId]
- if !ok {
- return serverproto.ErrorCode_ERROR_CARD_NOT_FOUND_NEXT, 0, 0
- }
- upGradeNum := cardNum / Card_Up_Grade_Need_Num
- if upGradeNum <= 0 {
- return serverproto.ErrorCode_ERROR_FAIL, 0, 0
- }
- //检查银币是否足够
- //可合成卡片数量对应的银币消耗
- var costItemList = map[int32]int32{}
- costItemList[int32(serverproto.ResType_Res_Coin)] = oldCardCfg.UpCost * upGradeNum
- if !this.role.CheckResLitNum(costItemList) {
- return serverproto.ErrorCode_ERROR_MONEY_NOT_ENOUGH, 0, 0
- }
- //获取升级后的卡片ID
- //var newCardId int32
- //newCardId = cardId + 100
- newCardId := oldCardCfg.ToCardId
- _, ok = serverproto.CardCfgLoader[newCardId]
- if !ok {
- return serverproto.ErrorCode_ERROR_CARD_NOT_FOUND_NEXT, 0, 0
- }
- //处理合成
- this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_Card})
- this.ReduceCard(cardId, Card_Up_Grade_Need_Num*upGradeNum, false)
- this.AddCard(newCardId, Card_Up_Grade_Add_Num*upGradeNum, false, false, true)
- TaskMagCheck(this.role, serverproto.TaskType_Card_Composed_Count, upGradeNum)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Merge_Card, newCardId)
- return serverproto.ErrorCode_ERROR_OK, newCardId, upGradeNum
- }
- func (this *RoleCard) GetCardCount() int32 {
- var totalCount int32 = 0
- for _, data := range this.cardList {
- if data.Num > 0 {
- totalCount += data.Num
- }
- }
- for _, data := range this.role.GetRoleHero().heroList {
- if data.Slot != nil {
- for _, subData := range data.Slot.SlotList {
- if len(subData.CardIdList) > 0 {
- totalCount += int32(len(subData.CardIdList))
- }
- }
- }
- }
- return totalCount
- }
- func (this *RoleCard) CheckCardNum(cardCfgId, num int32) bool {
- card := this.getCard(cardCfgId)
- if card == nil {
- return false
- }
- if card.Num < num {
- return false
- }
- return true
- }
- func (this *RoleCard) GetCardNum(cardCfgId int32) int32 {
- card := this.getCard(cardCfgId)
- if card == nil {
- return 0
- }
- return card.Num
- }
- // 对槽位中的装备升级
- func (this *RoleCard) SlotCardLevelUp(cardCfgId int32, changeList set.Interface) (bool, int32) {
- // globalData, ok1 := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Card_Up_Grade_Resource)]
- cfgData, ok2 := serverproto.CardCfgLoader[cardCfgId]
- if !ok2 {
- return false, 0
- }
- _, okNext := serverproto.CardCfgLoader[cfgData.ToCardId]
- if !okNext {
- return false, 0
- }
- // _, moneyCost := model.Str2Res(globalData.SVal)
- moneyCost := cfgData.UpCost
- if this.role.GetMoney() < uint64(moneyCost) {
- return false, 0
- }
- curCardNum := this.GetCardNum(cardCfgId)
- //计算已经装备的装备
- cardDataNum := 1 + curCardNum
- var checkCost = moneyCost
- if cardDataNum < Card_Up_Grade_Need_Num {
- checkNum := (Card_Up_Grade_Need_Num - cardDataNum) * Card_Up_Grade_Need_Num //前一等级需要消耗的卡片数量
- if !this.checkCardNum(cfgData.FromCardId, checkNum, moneyCost, &checkCost) {
- util.DebugF("uid=%v slotEquipLevelUp num not enough cfgid=%v num=%v", this.role.GetUUid(), cfgData.CardId, cardDataNum)
- return false, 0
- } else {
- if this.role.GetRoleBase().GetMoney() < uint64(checkCost) {
- util.DebugF("uid=%v slotEquipLevelUp num not enough cfgid=%v num=%v", this.role.GetUUid(), cfgData.CardId, cardDataNum)
- return false, 0
- }
- this.consumeNeedCard(cfgData.FromCardId, checkNum, changeList)
- }
- }
- //消耗金钱
- this.role.DelItem(int32(serverproto.ResType_Res_Coin), checkCost, AddItemST{AddFrom: AddFrom_Card})
- //通知数据变化
- var afterNum int32 = 0
- card := this.getCard(cardCfgId)
- if card != nil {
- card.Num -= Card_Up_Grade_Need_Num - 1
- if card.Num <= 0 {
- card.Num = 0
- this.RemoveCard(cardCfgId)
- }
- afterNum = card.Num
- changeList.Add(cardCfgId)
- this.SetDirty(true)
- }
- util.InfoF("uid=%v equip num cardCfgId=%v old=%v new=%v", this.role.uuid, cardCfgId, afterNum, curCardNum)
- //任务处理
- TaskMagCheck(this.role, serverproto.TaskType_Card_Composed_Count, 1)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Merge_Card, cfgData.ToCardId)
- this.AddCardCollect(cfgData.ToCardId)
- return true, cfgData.ToCardId
- }
- func (this *RoleCard) checkCardNum(cardConfigId int32, checkNum int32, moneyCost int32, totalCost *int32) bool {
- cfgData, ok := serverproto.CardCfgLoader[cardConfigId]
- if !ok {
- return false
- }
- //检查钱够不够 checkNum/Card_Up_Grade_Need_Num 是当前等级需要合成的次数。
- *totalCost += (checkNum / Card_Up_Grade_Need_Num) * moneyCost
- if this.role.GetMoney() < uint64(*totalCost) {
- return false
- }
- var needNum int32
- cardNum := this.GetCardNum(cardConfigId)
- if cardNum > 0 {
- if cardNum >= checkNum {
- return true
- } else {
- needNum = (checkNum - cardNum) * Card_Up_Grade_Need_Num
- }
- } else {
- needNum = checkNum * Card_Up_Grade_Need_Num
- }
- //做保护处理
- if needNum > 0xffffff {
- return false
- }
- return this.checkCardNum(cfgData.FromCardId, needNum, moneyCost, totalCost)
- }
- func (this *RoleCard) consumeNeedCard(cardConfigId int32, checkNum int32, changeList set.Interface) bool {
- cfgData, ok := serverproto.CardCfgLoader[cardConfigId]
- if !ok {
- return false
- }
- var needNum int32
- cardNum := this.GetCardNum(cardConfigId)
- if cardNum > 0 {
- changeList.Add(cardConfigId)
- if cardNum >= checkNum {
- this.ReduceCard(cardConfigId, checkNum, false)
- return true
- } else {
- needNum = (checkNum - cardNum) * Card_Up_Grade_Need_Num
- this.ReduceCard(cardConfigId, cardNum, false)
- }
- } else {
- needNum = checkNum * Card_Up_Grade_Need_Num
- }
- //做保护处理
- if needNum > 0xffffff {
- return false
- }
- return this.consumeNeedCard(cfgData.FromCardId, needNum, changeList)
- }
- func (this *RoleCard) GetCardCollect(ackMsg *serverproto.SCCardCollectInfoAck) {
- if this.cardCollect == nil || len(this.cardCollect) <= 0 {
- return
- }
- for _, collect := range this.cardCollect {
- ackMsg.CardCollect = append(ackMsg.CardCollect, collect)
- }
- return
- }
- func (this *RoleCard) GetCollectReward(cardId, level int32, ackMsg *serverproto.SCCardCollectRewardAck) serverproto.ErrorCode {
- if level > 5 || level < 1 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- cardCfg, ok := serverproto.CardIdentificationLoader[cardId]
- if !ok {
- return serverproto.ErrorCode_ERROR_CARD_CONFIG_NOT_FOUND
- }
- if this.cardCollect[cardCfg.CardQuality] == nil || len(this.cardCollect[cardCfg.CardQuality].CardBook) <= 0 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- for _, data := range this.cardCollect[cardCfg.CardQuality].CardBook {
- if data.CardId == cardId { //ID存在,且等级够
- if data.CardLevel < level {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if (data.RewardRec & (1 << uint32(level-1))) > 0 {
- return serverproto.ErrorCode_ERROR_CARD_COLLECT_REWEARD_FALSE
- }
- //给道具奖励
- bRet := this.AddCardCollectReward(cardId, level, ackMsg)
- if bRet != serverproto.ErrorCode_ERROR_OK {
- return bRet
- }
- data.RewardRec |= 1 << uint32(level-1)
- this.SetDirty(true)
- var cardData []*serverproto.KeyValueType
- cardData = append(cardData, &serverproto.KeyValueType{
- Key: cardId,
- Value: cardCfg.CardQuality,
- })
- this.CardCollectChangeNtf(cardData)
- return serverproto.ErrorCode_ERROR_OK
- }
- }
- return serverproto.ErrorCode_ERROR_FAIL
- }
- func (this *RoleCard) AddCardCollectReward(cardId, level int32, ackMsg *serverproto.SCCardCollectRewardAck) serverproto.ErrorCode {
- data, ok := model.ConvertCardCollectReward[cardId]
- if !ok {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if len(data.CardReward) < int(level) || data.CardReward[level] == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- //查找奖励配置
- var addItemList = map[int32]int32{}
- var rewardList []*serverproto.KeyValueType
- cardReward, ok := data.CardReward[level]
- if ok == false {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- addItemList[cardReward.Key] = cardReward.Value
- rewardList = append(rewardList, &serverproto.KeyValueType{
- Key: cardReward.Key,
- Value: cardReward.Value,
- })
- //给奖励
- if ret := this.role.CanAddItemList(addItemList); ret != serverproto.ErrorCode_ERROR_OK {
- return ret
- }
- ackMsg.RewardList = rewardList
- this.role.AddItemList(addItemList, AddFrom_CardCollect, true)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleCard) AddCardCollect(cardCfgId int32) serverproto.ErrorCode {
- cardCfg, ok := serverproto.CardCfgLoader[cardCfgId]
- if !ok {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- level := cardCfg.CardLevel
- typeId := cardCfg.CardPicId
- collectCfg, ok2 := serverproto.CardIdentificationLoader[typeId]
- if !ok2 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- var bFind = false
- if this.cardCollect[collectCfg.CardQuality] != nil && len(this.cardCollect[collectCfg.CardQuality].CardBook) > 0 {
- for _, data := range this.cardCollect[collectCfg.CardQuality].CardBook {
- if data.CardId == typeId {
- if data.CardLevel >= level {
- return serverproto.ErrorCode_ERROR_FAIL
- } else {
- data.CardLevel = level
- bFind = true
- break
- }
- }
- }
- }
- //没有卡册,则创建卡册
- if this.cardCollect[collectCfg.CardQuality] == nil {
- this.cardCollect[collectCfg.CardQuality] = &serverproto.CardCollect{
- CardQuality: collectCfg.CardQuality,
- }
- }
- if bFind == false {
- var handBook serverproto.CardHandBook
- handBook.CardId = typeId
- handBook.CardLevel = level
- handBook.RewardRec = 0
- this.cardCollect[collectCfg.CardQuality].CardBook = append(this.cardCollect[collectCfg.CardQuality].CardBook, &handBook)
- }
- this.SetDirty(true)
- var cardData []*serverproto.KeyValueType
- cardData = append(cardData, &serverproto.KeyValueType{
- Key: typeId,
- Value: collectCfg.CardQuality,
- })
- this.CardCollectChangeNtf(cardData)
- //到达最大等级发送
- if level >= collectCfg.MaxLv {
- ntfMsg := &serverproto.SSCardCollectionChangeNtf{}
- ntfMsg.Uid = this.role.GetUUid()
- ntfMsg.CardLevel = level
- ntfMsg.CardId = typeId
- this.role.SendRank(ntfMsg)
- }
- return serverproto.ErrorCode_ERROR_FAIL
- }
- // key 卡片类型ID, value
- func (this *RoleCard) CardCollectChangeNtf(cardData []*serverproto.KeyValueType) {
- ntfMsg := &serverproto.SCCardCollectChangeNtf{}
- for _, changedCard := range cardData {
- for _, data := range this.cardCollect[changedCard.Value].CardBook {
- //找到对应的卡片
- if data.CardId == changedCard.Key {
- var bFind = false
- for _, ntfCollect := range ntfMsg.CardCollect {
- if ntfCollect.CardQuality == changedCard.Value {
- ntfCollect.CardBook = append(ntfCollect.CardBook, data)
- bFind = true
- break
- }
- }
- if bFind == false {
- var ntfCollect serverproto.CardCollect
- ntfCollect.CardQuality = changedCard.Value
- ntfCollect.CardBook = append(ntfCollect.CardBook, data)
- ntfMsg.CardCollect = append(ntfMsg.CardCollect, &ntfCollect)
- }
- break
- }
- }
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- // /Task
- func (this *RoleCard) GetQualityCardNum(quality int32) int32 {
- var retNum int32 = 0
- if quality <= 0 {
- for _, data := range this.totalCardNumList {
- retNum += data.Value
- }
- } else {
- for _, data := range this.totalCardNumList {
- if data.Key == quality {
- retNum += data.Value
- }
- }
- }
- return retNum
- }
- // 检查是否有过此类型卡片
- func (this *RoleCard) CheckNewCard(cardId int32) bool {
- cardCfg, ok := serverproto.CardCfgLoader[cardId]
- if !ok {
- return false
- }
- typeId := cardCfg.CardPicId
- collectCfg, ok2 := serverproto.CardIdentificationLoader[typeId]
- if !ok2 {
- return false
- }
- if this.cardCollect[collectCfg.CardQuality] != nil && len(this.cardCollect[collectCfg.CardQuality].CardBook) > 0 {
- for _, data := range this.cardCollect[collectCfg.CardQuality].CardBook {
- if data.CardId == typeId {
- return false
- }
- }
- }
- return true
- }
- // 卡片祝福属性
- func (this *RoleCard) GetCardSuitAttr(heroData *serverproto.HeroData, attrList map[serverproto.Attr]float32) {
- type tmpLevelNumSt struct {
- CardLevel int32
- CardNum int32
- CurCardNum int32
- }
- type tmpCardSt struct {
- CardLevelNum []tmpLevelNumSt //level num
- CardMaxLevel int
- }
- var cardTypeNumList = map[int32]*tmpCardSt{}
- for _, val := range heroData.Slot.SlotList {
- for idx := 0; idx < len(val.CardIdList); idx++ {
- cfgData := this.getCardCfgData(val.CardIdList[idx])
- if cfgData == nil {
- continue
- }
- data, ok := cardTypeNumList[cfgData.CardType]
- if !ok {
- data = &tmpCardSt{}
- cardTypeNumList[cfgData.CardType] = data
- }
- bFind := false
- for k := 0; k < len(data.CardLevelNum); k++ {
- if data.CardLevelNum[k].CardLevel == cfgData.CardLevel {
- data.CardLevelNum[k].CardNum++
- data.CardLevelNum[k].CurCardNum = data.CardLevelNum[k].CardNum
- bFind = true
- break
- }
- }
- if !bFind {
- data.CardLevelNum = append(data.CardLevelNum,
- tmpLevelNumSt{CardLevel: cfgData.CardLevel, CardNum: 1, CurCardNum: 1})
- }
- if data.CardMaxLevel < int(cfgData.CardLevel) {
- data.CardMaxLevel = int(cfgData.CardLevel)
- }
- }
- }
- for _, data := range cardTypeNumList {
- sort.Slice(data.CardLevelNum, func(i, j int) bool {
- return data.CardLevelNum[i].CardLevel < data.CardLevelNum[j].CardLevel
- })
- }
- for _, val := range model.ConvertCardSuit {
- bOk := true
- //reset data
- for _, v := range cardTypeNumList {
- for idx := 0; idx < len(v.CardLevelNum); idx++ {
- v.CardLevelNum[idx].CurCardNum = v.CardLevelNum[idx].CardNum
- }
- }
- conditionList := val.GetConditions()
- for idx := 0; idx < len(conditionList); idx++ {
- typeNumData, ok := cardTypeNumList[conditionList[idx].GetKey()]
- if !ok {
- bOk = false
- break
- }
- needNum := conditionList[idx].GetCnt()
- for levelIdx := 0; levelIdx < len(typeNumData.CardLevelNum); levelIdx++ {
- if typeNumData.CardLevelNum[levelIdx].CardLevel < conditionList[idx].GetLvl() {
- continue
- }
- if needNum > 0 {
- if typeNumData.CardLevelNum[levelIdx].CurCardNum >= needNum {
- typeNumData.CardLevelNum[levelIdx].CurCardNum -= needNum
- needNum = 0
- } else {
- needNum -= typeNumData.CardLevelNum[levelIdx].CurCardNum
- typeNumData.CardLevelNum[levelIdx].CurCardNum = 0
- }
- }
- if needNum <= 0 {
- break
- }
- }
- if needNum > 0 {
- bOk = false
- break
- }
- }
- if bOk {
- suitAttrList := val.GetSuits()
- for idx := 0; idx < len(suitAttrList); idx++ {
- attrList[serverproto.Attr(suitAttrList[idx].Key)] += float32(suitAttrList[idx].Value)
- }
- break
- }
- }
- //todo... 优化
- for key, value := range attrList {
- if key >= serverproto.Attr_STR_Percent && key <= serverproto.Attr_RealHurt_Percent {
- attrList[key] = value
- }
- }
- //for key, value := range attrList {
- // if key < serverproto.Attr_STR_Percent {
- // attrList[key] = value * (1 + attrList[key+30])
- // }
- //}
- //for key := range attrList {
- // if key >= serverproto.Attr_STR_Percent && key <= serverproto.Attr_RealHurt_Percent {
- // attrList[key] = 0
- // }
- //}
- }
- func (this *RoleCard) CardExchange(sourceCardId, targetCardId int32, ackMsg *serverproto.SCCardLevelExchangeAck) serverproto.ErrorCode {
- if ackMsg == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- //相同卡片不能置换
- if sourceCardId == targetCardId {
- return serverproto.ErrorCode_ERROR_CARD_EXCHANGE_SAME_CARD
- }
- //卡片配置找不到
- sourceCfgData := this.getCardCfgData(sourceCardId)
- targetCfgData := this.getCardCfgData(targetCardId)
- if sourceCfgData == nil || targetCfgData == nil {
- return serverproto.ErrorCode_ERROR_CARD_CONFIG_NOT_FOUND
- }
- //卡片等级相同
- if sourceCfgData.CardLevel == targetCfgData.CardLevel {
- return serverproto.ErrorCode_ERROR_CARD_EXCHANGE_LEVEL_EQUAL
- }
- if sourceCfgData.CardType != model.Card_Type_MVP || targetCfgData.CardType != model.Card_Type_MVP {
- return serverproto.ErrorCode_ERROR_CARD_EXCHANGE_NOT_MVP_CARD
- }
- //背包没有卡片
- sourceCard := this.getCard(sourceCardId)
- if sourceCard == nil {
- return serverproto.ErrorCode_ERROR_CARD_NOT_FOUND
- }
- targetCard := this.getCard(targetCardId)
- if targetCard == nil {
- return serverproto.ErrorCode_ERROR_CARD_NOT_FOUND
- }
- //卡片数量不够
- if sourceCard.Num <= 0 || targetCard.Num <= 0 {
- return serverproto.ErrorCode_ERROR_ITEM_NOT_FOUND
- }
- //有卡片不能进行转换
- sourceInitId := model.GetCardSource(sourceCardId)
- targetInitId := model.GetCardSource(targetCardId)
- if sourceInitId == 0 || targetInitId == 0 {
- return serverproto.ErrorCode_ERROR_CARD_EXCHANGE_INIT_CARD_NOT_FOUND
- }
- //两张卡片来源相同
- if sourceInitId == targetInitId {
- return serverproto.ErrorCode_ERROR_CARD_EXCHANGE_SAME_SOURCE
- }
- //合成目标卡片
- newSourceId := (sourceInitId/1000)*1000 + targetCfgData.CardLevel*100 + sourceInitId%100
- newTargetId := (targetInitId/1000)*1000 + sourceCfgData.CardLevel*100 + targetInitId%100
- newSourceCfgData := this.getCardCfgData(newSourceId)
- newTargetCfgData := this.getCardCfgData(newTargetId)
- if newSourceCfgData == nil || newTargetCfgData == nil {
- return serverproto.ErrorCode_ERROR_CARD_CONFIG_NOT_FOUND
- }
- //查看资源是否够
- var costItemList = map[int32]int32{}
- if targetCfgData.CardLevel > sourceCfgData.CardLevel {
- this.GetCardExchangeCost(sourceCfgData.CardLevel, targetCfgData.CardLevel, costItemList)
- } else {
- this.GetCardExchangeCost(targetCfgData.CardLevel, sourceCfgData.CardLevel, costItemList)
- }
- if len(costItemList) <= 0 {
- return serverproto.ErrorCode_ERROR_CARD_EXCHANGE_COST_CONFIG
- }
- if !this.role.CheckResLitNum(costItemList) {
- return serverproto.ErrorCode_ERROR_RES_NOT_ENOUGH
- }
- //删除两张老卡
- this.ReduceCard(sourceCardId, 1, true)
- this.ReduceCard(targetCardId, 1, true)
- //添加两张新卡
- this.AddCard(newSourceId, 1, true, true, true)
- this.AddCard(newTargetId, 1, true, true, true)
- //扣除道具
- this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_Card})
- ackMsg.SourceCardId = newSourceId
- ackMsg.TargetCardId = newTargetId
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleCard) GetCardExchangeCost(smallLevel, bigLevel int32, costItemList map[int32]int32) {
- if smallLevel == bigLevel {
- return
- }
- for key, data := range model.GlobalCardLevelExchange {
- if key-1 <= 0 {
- //打个Error日志
- continue
- }
- if smallLevel <= key-1 && bigLevel >= key {
- costItemList[data.Key] += data.Value
- }
- }
- }
|