role_bag.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. package model
  2. import (
  3. "math"
  4. "rocommon/util"
  5. "roserver/baseserver/model"
  6. "roserver/baseserver/set"
  7. "roserver/serverproto"
  8. "strings"
  9. )
  10. type AddFromType int32
  11. const (
  12. AddFrom_System AddFromType = iota
  13. AddFrom_Battle
  14. AddFrom_Task
  15. AddFrom_Card_Decompose
  16. AddFrom_Battle_Box //4 寻宝
  17. AddFrom_Quick_Battle //5 快速战斗
  18. AddFrom_Mail //6 邮件
  19. AddFrom_Fashion //7 时装
  20. AddFrom_Shop_Buy //8 杂货店
  21. AddFrom_Arena //9 arena
  22. AddFrom_Package //10 来自礼包
  23. AddFrom_SignUp //11 签到
  24. AddFrom_WorldBoss //12 世界boss rand点奖励
  25. AddFrom_Evil //13 恶魔协会
  26. AddFrom_Tower //14 爬塔奖励
  27. AddFrom_ResetSkill //15 重置技能
  28. AddFrom_CardCollect //16 卡片收集奖励
  29. AddFrom_Pet //17 宠物
  30. AddFrom_GuildBoss //18 公会boss奖励
  31. AddFrom_Expedition //19 远征之门
  32. AddFrom_Activities //20 精彩活动
  33. AddFrom_Invitation //21 invitation
  34. AddFrom_Pay //22 pay
  35. AddFrom_Draw //23 抽取获得
  36. AddFrom_Rune //24 卢恩商会
  37. AddFrom_Shop_Arane //25 荣誉商店
  38. AddFrom_Shop_Dark //26 黑市商店
  39. AddFrom_Shop_Guild //27 公会商店
  40. AddFrom_Shop_Pet //28 宠物商店
  41. AddFrom_HeadFrame //29 头像处理
  42. AddFrom_Guild //30 公会
  43. AddFrom_Competition //31 赛季系统
  44. AddFrom_Card //32 卡片系统
  45. AddFrom_Equip //33 装备系统
  46. AddFrom_Hero //34 伙伴系统
  47. AddFrom_Skill //35 技能系统
  48. AddFrom_Expire //36 过期数据
  49. AddFrom_RushTower //37 爬塔冲榜
  50. AddFrom_RushArena //38 英灵殿冲榜
  51. AddFrom_DaoChang100 //39 百人道场
  52. AddFrom_DrawCard //40 卡片召唤
  53. AddFrom_DrawPet //41 宠物召唤
  54. AddFrom_GiftCode //42 礼包码
  55. AddFrom_QuestionReward //43 问卷调查奖励
  56. AddFrom_RushMap //44 地图冲榜
  57. AddFrom_ReplaceJob //45 职业更换
  58. AddFrom_KeepSake //46 信物(藏品)
  59. AddFrom_GuildBattle //47 公会战
  60. AddFrom_DaoChang100Wheel //48 百人道场转盘
  61. AddFrom_OnlineReward //49 在线时间累计奖励
  62. AddFrom_RedBagShop //50 红包商店
  63. AddFrom_RedBagExchange //51 红包商店兑换
  64. AddFrom_qualityPoint //52 素质点
  65. AddFrom_RushPet //53 爬塔冲榜
  66. AddFrom_PetEquip //54 宠物印记
  67. AddFrom_JobChange //55 转职
  68. AddFrom_Divine //56 占卜
  69. AddFrom_SkillExpConver //57 技能经验兑换
  70. AddFrom_DrawingResolve //58 时装图纸分解
  71. AddFrom_RushSkill //59 技能冲榜
  72. AddFrom_CrossYuanHangTrial //60跨服远航试炼
  73. AddFrom_SkillEquipStarLevel //61 神器升星
  74. AddFrom_SkillEquipSoltLevel //62 神器槽位升级
  75. AddFrom_SkillEquipDecompose //63 神器分解
  76. AddFrom_DrawSkillEquip //64
  77. AddFrom_CrossTopTower //65 跨服巅峰之塔
  78. AddFrom_HeadActivate //66 称号激活消耗
  79. AddFrom_GuildDemon //67 公会魔王
  80. AddFrom_SkillEquipRefroge //68 神器重铸
  81. AddFrom_ActivitySummon //69 活动召唤
  82. AddFrom_ActivitySignIn //70 活动签到
  83. AddFrom_SkillEquipShift //71 神器转移
  84. AddFrom_IdolSeason //72 偶像季
  85. AddFrom_WishBox //73 许愿宝箱解锁
  86. AddFrom_WishBoxSpeed //74 许愿宝箱加速
  87. AddFrom_WishBoxUse //75 许愿使用
  88. AddFrom_PetJuexing //76 宠物觉醒
  89. AddFrom_CreditRecharge // 77 充值钱包
  90. AddFrom_SpecialPrivilege // 78 特权卡商店
  91. AddFrom_BT_Boli // 79 bt boli
  92. AddFrom_CreateRole // 80
  93. AddFrom_ActivitySmashEggs // 81 砸蛋金蛋
  94. AddFrom_ActivitySmashEggsSpeical // 82 彩蛋
  95. AddFrom_BT_Recharge // 83 bt超值首充&百元大礼包
  96. )
  97. type RoleBag struct {
  98. SaveObject
  99. itemList map[uint64]*serverproto.ItemData
  100. maxBagSize int32
  101. itemAction *ItemAction
  102. bCheck bool
  103. }
  104. func newRoleBag(r *Role) *RoleBag {
  105. roleBag := &RoleBag{
  106. SaveObject: SaveObject{
  107. role: r,
  108. },
  109. maxBagSize: 999,
  110. }
  111. roleBag.itemAction = newItemAction(roleBag)
  112. roleBag.itemList = make(map[uint64]*serverproto.ItemData)
  113. return roleBag
  114. }
  115. func (this *RoleBag) Load(msg interface{}) bool {
  116. proRole := msg.(*serverproto.Role)
  117. if proRole.RoleBag == nil {
  118. proRole.RoleBag = &serverproto.RoleBag{}
  119. } else {
  120. for _, itemData := range proRole.RoleBag.ItemList {
  121. this.itemList[itemData.Id] = itemData
  122. }
  123. }
  124. return true
  125. }
  126. func (this *RoleBag) Save() {
  127. this.SetDirty(false)
  128. //util.DebugF("uid=%v RoleBag save...", this.role.GetUUid())
  129. saveMsg := &serverproto.SSBagDataSaveReq{
  130. Bag: &serverproto.RoleBag{},
  131. }
  132. //优化提升效率 growslice
  133. saveMsg.Bag.ItemList = make([]*serverproto.ItemData, 0, 32)
  134. for _, data := range this.itemList {
  135. saveMsg.Bag.ItemList = append(saveMsg.Bag.ItemList, data)
  136. }
  137. this.role.SendDb(saveMsg)
  138. }
  139. func (this *RoleBag) CopyData(bag *serverproto.RoleBag) {
  140. for _, data := range this.itemList {
  141. bag.ItemList = append(bag.ItemList, data)
  142. }
  143. }
  144. func (this *RoleBag) GetRole() *Role {
  145. return this.role
  146. }
  147. func (this *RoleBag) checkValid() {
  148. if this.bCheck {
  149. return
  150. }
  151. this.bCheck = true
  152. for _, itemData := range this.itemList {
  153. if itemData.Num <= 0 {
  154. delete(this.itemList, itemData.Id)
  155. this.SetDirty(true)
  156. continue
  157. }
  158. _, ok := serverproto.ItemCfgLoader[itemData.ConfigId]
  159. if !ok {
  160. util.WarnF("uid=%v RoleBag Load load item error id=%v", this.role.GetUUid(), itemData.ConfigId)
  161. delete(this.itemList, itemData.Id)
  162. this.SetDirty(true)
  163. continue
  164. }
  165. }
  166. }
  167. func (this *RoleBag) emptyPosNum() uint32 {
  168. itemLen := int32(len(this.itemList))
  169. if this.maxBagSize < itemLen {
  170. return 0
  171. } else {
  172. return uint32(this.maxBagSize - itemLen)
  173. }
  174. }
  175. //获取物品堆叠上限
  176. func (this *RoleBag) canAddCnt(itemCfgId int32, itemPileNum uint32) uint64 {
  177. //itemPileNum := this.getItemPileNum(itemCfgId)
  178. //itemCfg := GetItemCfg(itemCfgId)
  179. var count uint64 = 0
  180. for _, item := range this.itemList {
  181. if item != nil && item.ConfigId == itemCfgId && item.Num < itemPileNum {
  182. left := itemPileNum - item.Num
  183. count += uint64(left)
  184. }
  185. }
  186. currCount := count + uint64(this.emptyPosNum()*itemPileNum)
  187. return currCount
  188. }
  189. //根据动态ID获取道具
  190. func (this *RoleBag) getItemById(id uint64) *serverproto.ItemData {
  191. item, ok := this.itemList[id]
  192. if ok {
  193. return item
  194. }
  195. return nil
  196. }
  197. func (this *RoleBag) getItemPileNum(itemCfgId int32) uint32 {
  198. cfgData, ok := serverproto.ItemCfgLoader[itemCfgId]
  199. if ok {
  200. return uint32(cfgData.Composition)
  201. } else {
  202. util.InfoF("uid=%v getItemPileNum item data not found id=%v", this.role.GetUUid(), itemCfgId)
  203. return 0
  204. }
  205. }
  206. func (this *RoleBag) getItemNum(itemConfigId int32) uint32 {
  207. var count uint32 = 0
  208. if itemConfigId > 0 {
  209. for _, item := range this.itemList {
  210. if item.ConfigId == itemConfigId {
  211. count += item.Num
  212. }
  213. }
  214. }
  215. return count
  216. }
  217. func (this *RoleBag) addItem(cfgData *serverproto.ItemCfg, count int32, st AddItemST) (bBaseChange bool) {
  218. itemCfgId := cfgData.Id
  219. bBaseChange = false
  220. ignore := st.Ignore
  221. st.ItemCfgId = cfgData.Id
  222. st.ItemCount = count
  223. switch serverproto.ResType(cfgData.ResType) {
  224. case serverproto.ResType_Res_Coin:
  225. fallthrough
  226. case serverproto.ResType_Res_RoleBaseExp:
  227. fallthrough
  228. case serverproto.ResType_Res_RoleJobExp:
  229. fallthrough
  230. case serverproto.ResType_Res_HeroBaseExp:
  231. fallthrough
  232. case serverproto.ResType_Res_Rmb:
  233. fallthrough
  234. case serverproto.ResType_Res_Cruise:
  235. fallthrough
  236. case serverproto.ResType_Res_Sprite:
  237. fallthrough
  238. case serverproto.ResType_Res_Reslove:
  239. fallthrough
  240. case serverproto.ResType_Res_EvilExp:
  241. fallthrough
  242. case serverproto.ResType_Res_PetExp:
  243. fallthrough
  244. case serverproto.ResType_Res_Guild:
  245. fallthrough
  246. case serverproto.ResType_Res_DaoChang100:
  247. fallthrough
  248. case serverproto.ResType_Res_VipExp:
  249. fallthrough
  250. case serverproto.ResType_Res_Guild_Battle:
  251. fallthrough
  252. case serverproto.ResType_Res_PetCoin:
  253. fallthrough
  254. case serverproto.ResType_Res_HightSkillExp:
  255. fallthrough
  256. case serverproto.ResType_Res_PetLevelUP_Exp:
  257. fallthrough
  258. case serverproto.ResType_Res_CreditRecharge:
  259. fallthrough
  260. case serverproto.ResType_Res_ROCoin:
  261. fallthrough
  262. case serverproto.ResType_Res_BoliShopExp:
  263. if DoCheck(this.role, cfgData, count) != int32(serverproto.ErrorCode_ERROR_OK) {
  264. util.InfoF("uid=%v AddItem effect not found restype=%v", this.role.GetUUid(), cfgData.ResType)
  265. return
  266. }
  267. DoUse(this.role, cfgData, st, true)
  268. if serverproto.ResType(cfgData.ResType) != serverproto.ResType_Res_VipExp {
  269. bBaseChange = true
  270. }
  271. case serverproto.ResType_Res_Item:
  272. fallthrough
  273. case serverproto.ResType_Res_SkillBook:
  274. fallthrough
  275. case serverproto.ResType_Res_Gift:
  276. fallthrough
  277. case serverproto.ResType_Res_QuickBattle:
  278. fallthrough
  279. case serverproto.ResType_Res_ItemCompose:
  280. fallthrough
  281. case serverproto.ResType_Res_HeadFrame:
  282. fallthrough
  283. case serverproto.ResType_Res_CashTicket:
  284. fallthrough
  285. case serverproto.ResType_Res_Month_Car_Item:
  286. fallthrough
  287. case serverproto.ResType_Res_Rune_Unlock_Award:
  288. fallthrough
  289. case serverproto.ResType_Res_Head_Item:
  290. fallthrough
  291. case serverproto.ResType_Res_WishBox:
  292. fallthrough
  293. case serverproto.ResType_Res_WishBox_Select:
  294. fallthrough
  295. case serverproto.ResType_Res_Gift_Unique:
  296. if this.itemAction.add(itemCfgId, count) {
  297. this.SetDirty(true)
  298. }
  299. case serverproto.ResType_Res_Fashion:
  300. //添加时判断性别
  301. cfgFashionPaper, ok1 := serverproto.FashionPaperCfgLoader[itemCfgId]
  302. if ok1 {
  303. cfgFashion, ok2 := serverproto.FashionCfgLoader[cfgFashionPaper.FashionId]
  304. if ok2 && cfgFashion.FashionSex == this.role.GetRoleBase().GetRoleSex() || cfgFashion.FashionSex == 0 {
  305. if this.itemAction.add(itemCfgId, count) {
  306. //this.itemAction.doAction(notify, false)
  307. this.SetDirty(true)
  308. }
  309. }
  310. }
  311. case serverproto.ResType_Res_Equip:
  312. this.role.AddEquip(cfgData.Id, count, st.Notify, ignore)
  313. case serverproto.ResType_Res_Skill_Equip:
  314. this.role.AddSkillEquip(cfgData.Id, count, st.Notify, ignore)
  315. case serverproto.ResType_Res_Chip:
  316. this.role.GetRoleChip().AddChip(itemCfgId, count, true)
  317. if st.Notify {
  318. this.role.GetRoleChip().ChipChangeNtf([]int32{int32(itemCfgId)})
  319. }
  320. case serverproto.ResType_Res_Card:
  321. this.role.GetRoleCard().AddCard(itemCfgId, count, st.Notify, ignore, true)
  322. case serverproto.ResType_Res_Hero:
  323. if cfgData.AutoUse > 0 {
  324. this.role.GetRoleHero().AddHeroByList(cfgData.ComposeItem)
  325. } else {
  326. if this.itemAction.add(itemCfgId, count) {
  327. //this.itemAction.doAction(notify, ignore)
  328. this.SetDirty(true)
  329. }
  330. }
  331. case serverproto.ResType_Res_Pet:
  332. for idx := 0; idx < int(count); idx++ {
  333. this.role.GetRolePet().AddPet(itemCfgId)
  334. }
  335. case serverproto.ResType_Res_KeepSake:
  336. this.role.GetRoleKeepSake().AddKeepSakeMaterial(cfgData, count)
  337. case serverproto.ResType_Res_DaoChang100_Guild:
  338. //百人道场公会贡献点
  339. ssUpdateMsg := &serverproto.SSDaoChang100GuildRankUpdateNtf{
  340. Uid: this.role.GetUUid(),
  341. GuildId: uint64(this.role.GetRoleGuildId()),
  342. Score: uint32(count),
  343. }
  344. this.role.SendGuild(ssUpdateMsg)
  345. case serverproto.ResType_Res_Explor_Exp:
  346. if rune := this.role.GetRoleRune(); rune != nil {
  347. rune.AddGoldExp(count)
  348. }
  349. case serverproto.ResType_Res_DaoChang100_Score:
  350. this.role.GetRoleCompetition().CompetitionAddScoreDuoBao(count)
  351. case serverproto.ResType_Res_RushMap:
  352. this.role.GetRoleBattle().OnRushMapScoreChange(count, 0)
  353. case serverproto.ResType_Res_Virtual_RMB:
  354. this.role.GMPay(float32(count))
  355. case serverproto.ResType_Res_PetEquip:
  356. this.role.GetRolePet().AddPetEquipList(itemCfgId, count, 1, ignore)
  357. case serverproto.ResType_Res_IdolSeason:
  358. this.role.GetRoleCompetition().UseIdolSeasonItem(itemCfgId, count)
  359. default:
  360. util.WarnF("uid=%v res type no exist!!! restype=%v", this.role.GetUUid(), cfgData.ResType)
  361. }
  362. //稀有道具获得消息提示
  363. //邮件方式获取稀有道具不做提醒
  364. if st.AddFrom == AddFrom_WorldBoss ||
  365. st.AddFrom == AddFrom_DrawCard ||
  366. st.AddFrom == AddFrom_DrawPet ||
  367. st.AddFrom == AddFrom_Package ||
  368. st.AddFrom == AddFrom_Shop_Arane ||
  369. st.AddFrom == AddFrom_Shop_Guild ||
  370. st.AddFrom == AddFrom_DrawSkillEquip ||
  371. st.AddFrom == AddFrom_ActivitySummon ||
  372. st.AddFrom == AddFrom_ActivitySmashEggs ||
  373. st.AddFrom == AddFrom_ActivitySmashEggsSpeical {
  374. if _, ok := model.GlobalSystemMsgItemList[cfgData.Id]; ok {
  375. if cfgData.ResType == int32(serverproto.ResType_Res_Card) ||
  376. cfgData.ResType == int32(serverproto.ResType_Res_Pet) ||
  377. cfgData.ResType == int32(serverproto.ResType_Res_Skill_Equip) {
  378. //514老旧相册,世界boss,商店购买,抽卡
  379. if (st.UseItemCfgId > 0 && st.UseItemCfgId == 514 && st.AddFrom == AddFrom_Package) ||
  380. st.AddFrom == AddFrom_DrawCard ||
  381. st.AddFrom == AddFrom_DrawPet ||
  382. st.AddFrom == AddFrom_WorldBoss ||
  383. st.AddFrom == AddFrom_Shop_Arane ||
  384. st.AddFrom == AddFrom_Shop_Guild ||
  385. st.AddFrom == AddFrom_DrawSkillEquip ||
  386. st.AddFrom == AddFrom_ActivitySummon ||
  387. st.AddFrom == AddFrom_ActivitySmashEggs ||
  388. st.AddFrom == AddFrom_ActivitySmashEggsSpeical {
  389. this.GetRole().AddSystemMessage(SystemMessageType_Item,
  390. AddSystemMsg{ParamId: cfgData.Id, ParamCount: int32(count), AddFromType: int32(st.AddFrom), UseItemCfgId: st.UseItemCfgId})
  391. }
  392. } else {
  393. this.GetRole().AddSystemMessage(SystemMessageType_Item,
  394. AddSystemMsg{ParamId: cfgData.Id, ParamCount: int32(count), AddFromType: int32(st.AddFrom), UseItemCfgId: st.UseItemCfgId})
  395. }
  396. }
  397. }
  398. return
  399. }
  400. func (this *RoleBag) AddItem(itemCfgId, count int32, st AddItemST) {
  401. this.checkValid()
  402. if count <= 0 {
  403. return
  404. }
  405. cfgData, ok := serverproto.ItemCfgLoader[itemCfgId]
  406. if !ok {
  407. util.ErrorF("uid=%v AddItem item cfg data not found id=%v", this.role.GetUUid(), itemCfgId)
  408. return
  409. }
  410. //自动使用
  411. if cfgData.AutoUse > 0 {
  412. this.autoUseItem(itemCfgId, uint32(count), true, nil, 0)
  413. return
  414. }
  415. util.InfoF("uid=%v AddItem id=%v count=%v from=%v", this.role.GetUUid(), itemCfgId, count, st.AddFrom)
  416. ignore := false
  417. addFrom := st.AddFrom
  418. if addFrom == AddFrom_Battle ||
  419. addFrom == AddFrom_Task ||
  420. addFrom == AddFrom_Quick_Battle ||
  421. addFrom == AddFrom_SignUp ||
  422. addFrom == AddFrom_Tower ||
  423. addFrom == AddFrom_Mail ||
  424. addFrom == AddFrom_Package ||
  425. addFrom == AddFrom_ResetSkill ||
  426. addFrom == AddFrom_WorldBoss ||
  427. addFrom == AddFrom_GuildBoss ||
  428. addFrom == AddFrom_Expedition ||
  429. addFrom == AddFrom_Shop_Buy ||
  430. addFrom == AddFrom_Draw ||
  431. addFrom == AddFrom_Rune ||
  432. addFrom == AddFrom_Shop_Arane ||
  433. addFrom == AddFrom_Shop_Dark ||
  434. addFrom == AddFrom_Shop_Guild ||
  435. addFrom == AddFrom_Shop_Pet ||
  436. addFrom == AddFrom_RushTower ||
  437. addFrom == AddFrom_RushArena ||
  438. addFrom == AddFrom_Activities ||
  439. addFrom == AddFrom_Pay ||
  440. addFrom == AddFrom_DrawCard ||
  441. addFrom == AddFrom_GiftCode ||
  442. addFrom == AddFrom_RushMap ||
  443. addFrom == AddFrom_KeepSake ||
  444. addFrom == AddFrom_DrawPet ||
  445. addFrom == AddFrom_DaoChang100Wheel ||
  446. addFrom == AddFrom_DaoChang100 ||
  447. addFrom == AddFrom_RushPet ||
  448. addFrom == AddFrom_DrawingResolve ||
  449. addFrom == AddFrom_RushSkill ||
  450. addFrom == AddFrom_RedBagShop ||
  451. addFrom == AddFrom_CrossYuanHangTrial ||
  452. addFrom == AddFrom_WishBox ||
  453. addFrom == AddFrom_BT_Boli ||
  454. addFrom == AddFrom_BT_Recharge {
  455. ignore = true
  456. }
  457. st.Ignore = ignore
  458. bBaseChange := this.addItem(cfgData, count, st)
  459. this.itemAction.doAction(st.Notify, st.Ignore)
  460. if bBaseChange {
  461. this.role.GetRoleBase().BaseChangeNtf()
  462. }
  463. if cfgData.ResType == int32(serverproto.ResType_Res_KeepSake) {
  464. this.role.GetRoleKeepSake().OnKeepSakeChangeNtf()
  465. }
  466. if cfgData.ResType == int32(serverproto.ResType_Res_Head_Item) {
  467. TaskMagCheck(this.role, serverproto.TaskType_Eve_Item_Count, int32(cfgData.Id))
  468. }
  469. }
  470. type AddItemST struct {
  471. ItemCfgId int32
  472. ItemCount int32
  473. AddFrom AddFromType
  474. UseItemCfgId int32 //来自使用物品的ID
  475. Notify bool
  476. Ignore bool
  477. ReasonParam int32 //触发该消耗或者添加操作的对应系统道具参数
  478. ReasonParam2 int32 //触发该消耗或者添加操作的对应系统道具参数2
  479. }
  480. func (this *RoleBag) AddItemList(addItemList map[int32]int32, st AddItemST) {
  481. addFrom := st.AddFrom
  482. notify := st.Notify
  483. this.checkValid()
  484. ignore := false
  485. if addFrom == AddFrom_Battle ||
  486. addFrom == AddFrom_Task ||
  487. addFrom == AddFrom_Quick_Battle ||
  488. addFrom == AddFrom_SignUp ||
  489. addFrom == AddFrom_Tower ||
  490. addFrom == AddFrom_Mail ||
  491. addFrom == AddFrom_Package ||
  492. addFrom == AddFrom_ResetSkill ||
  493. addFrom == AddFrom_WorldBoss ||
  494. addFrom == AddFrom_GuildBoss ||
  495. addFrom == AddFrom_Expedition ||
  496. addFrom == AddFrom_Shop_Buy ||
  497. addFrom == AddFrom_Draw ||
  498. addFrom == AddFrom_Rune ||
  499. addFrom == AddFrom_Shop_Arane ||
  500. addFrom == AddFrom_Shop_Dark ||
  501. addFrom == AddFrom_Shop_Guild ||
  502. addFrom == AddFrom_Shop_Pet ||
  503. addFrom == AddFrom_RushTower ||
  504. addFrom == AddFrom_RushArena ||
  505. addFrom == AddFrom_Activities ||
  506. addFrom == AddFrom_Pay ||
  507. addFrom == AddFrom_DrawCard ||
  508. addFrom == AddFrom_GiftCode ||
  509. addFrom == AddFrom_RushMap ||
  510. addFrom == AddFrom_KeepSake ||
  511. addFrom == AddFrom_DrawPet ||
  512. addFrom == AddFrom_DaoChang100Wheel ||
  513. addFrom == AddFrom_DaoChang100 ||
  514. addFrom == AddFrom_RushPet ||
  515. addFrom == AddFrom_DrawingResolve ||
  516. addFrom == AddFrom_RushSkill ||
  517. addFrom == AddFrom_RedBagShop ||
  518. addFrom == AddFrom_CrossYuanHangTrial ||
  519. addFrom == AddFrom_SkillEquipStarLevel ||
  520. addFrom == AddFrom_SkillEquipSoltLevel ||
  521. addFrom == AddFrom_SkillEquipDecompose ||
  522. addFrom == AddFrom_DrawSkillEquip ||
  523. addFrom == AddFrom_CrossTopTower ||
  524. addFrom == AddFrom_ActivitySummon ||
  525. addFrom == AddFrom_ActivitySignIn ||
  526. addFrom == AddFrom_CreateRole ||
  527. addFrom == AddFrom_ActivitySmashEggs ||
  528. addFrom == AddFrom_ActivitySmashEggsSpeical {
  529. ignore = true
  530. }
  531. st.Ignore = ignore
  532. util.InfoF("uid=%v AddItem itemlist=%v from=%v", this.role.GetUUid(), addItemList, st.AddFrom)
  533. bBaseChange := false
  534. bKeepSakeItem := false
  535. for itemCfgId, count := range addItemList {
  536. cfgData, ok := serverproto.ItemCfgLoader[itemCfgId]
  537. if !ok {
  538. util.ErrorF("uid=%v item cfg data not found id=%v", this.role.GetUUid(), itemCfgId)
  539. continue
  540. }
  541. if cfgData.AutoUse > 0 {
  542. ret := this.autoUseItem(itemCfgId, uint32(count), notify, nil, 0)
  543. if ret == serverproto.ErrorCode_ERROR_OK {
  544. delete(addItemList, itemCfgId)
  545. }
  546. continue
  547. }
  548. if this.addItem(cfgData, count, st) {
  549. bBaseChange = true
  550. }
  551. if cfgData.ResType == int32(serverproto.ResType_Res_KeepSake) {
  552. bKeepSakeItem = true
  553. }
  554. }
  555. this.itemAction.doAction(notify, st.Ignore)
  556. if bBaseChange {
  557. this.role.GetRoleBase().BaseChangeNtf()
  558. }
  559. if bKeepSakeItem { //如果有信物相关变化
  560. this.role.GetRoleKeepSake().OnKeepSakeChangeNtf()
  561. }
  562. for itemCfgId, _ := range addItemList {
  563. cfgData, ok := serverproto.ItemCfgLoader[itemCfgId]
  564. if !ok {
  565. continue
  566. }
  567. if cfgData.ResType == int32(serverproto.ResType_Res_Head_Item) {
  568. TaskMagCheck(this.role, serverproto.TaskType_Eve_Item_Count, int32(itemCfgId))
  569. }
  570. }
  571. }
  572. func (this *RoleBag) delItem(itemCfgId int32, st AddItemST, notify bool) (bBaseChange bool) {
  573. cfgData, ok := serverproto.ItemCfgLoader[itemCfgId]
  574. if !ok {
  575. util.ErrorF("uid=%v delItem item cfg data not found itemCfgId=%v", this.role.GetUUid(), itemCfgId)
  576. return
  577. }
  578. count := st.ItemCount
  579. bBaseChange = false
  580. switch serverproto.ResType(cfgData.ResType) {
  581. case serverproto.ResType_Res_Coin:
  582. fallthrough
  583. case serverproto.ResType_Res_RoleBaseExp:
  584. fallthrough
  585. case serverproto.ResType_Res_RoleJobExp:
  586. fallthrough
  587. case serverproto.ResType_Res_HeroBaseExp:
  588. fallthrough
  589. case serverproto.ResType_Res_Rmb:
  590. fallthrough
  591. case serverproto.ResType_Res_Cruise:
  592. fallthrough
  593. case serverproto.ResType_Res_Sprite:
  594. fallthrough
  595. case serverproto.ResType_Res_Reslove:
  596. fallthrough
  597. case serverproto.ResType_Res_EvilExp:
  598. fallthrough
  599. case serverproto.ResType_Res_PetExp:
  600. fallthrough
  601. case serverproto.ResType_Res_Guild:
  602. fallthrough
  603. case serverproto.ResType_Res_DaoChang100:
  604. fallthrough
  605. case serverproto.ResType_Res_VipExp:
  606. fallthrough
  607. case serverproto.ResType_Res_Guild_Battle:
  608. fallthrough
  609. case serverproto.ResType_Res_PetCoin:
  610. fallthrough
  611. case serverproto.ResType_Res_HightSkillExp:
  612. fallthrough
  613. case serverproto.ResType_Res_PetLevelUP_Exp:
  614. fallthrough
  615. case serverproto.ResType_Res_CreditRecharge:
  616. fallthrough
  617. case serverproto.ResType_Res_ROCoin:
  618. fallthrough
  619. case serverproto.ResType_Res_BoliShopExp:
  620. if DoCheck(this.role, cfgData, count) != int32(serverproto.ErrorCode_ERROR_OK) {
  621. util.ErrorF("uid=%v effect not found itemCfgId=%v", this.role.GetUUid(), itemCfgId)
  622. return
  623. }
  624. DoUse(this.role, cfgData, st, false)
  625. bBaseChange = true
  626. case serverproto.ResType_Res_Item:
  627. fallthrough
  628. case serverproto.ResType_Res_HeadFrame:
  629. fallthrough
  630. case serverproto.ResType_Res_SkillBook:
  631. fallthrough
  632. case serverproto.ResType_Res_Fashion:
  633. fallthrough
  634. case serverproto.ResType_Res_Gift:
  635. fallthrough
  636. case serverproto.ResType_Res_QuickBattle:
  637. fallthrough
  638. case serverproto.ResType_Res_ItemCompose:
  639. fallthrough
  640. case serverproto.ResType_Res_CashTicket:
  641. fallthrough
  642. case serverproto.ResType_Res_Head_Item:
  643. fallthrough
  644. case serverproto.ResType_Res_WishBox_Select:
  645. fallthrough
  646. case serverproto.ResType_Res_WishBox:
  647. fallthrough
  648. case serverproto.ResType_Res_Gift_Unique, serverproto.ResType_Res_Month_Car_Item, serverproto.ResType_Res_Rune_Unlock_Award:
  649. if this.itemAction.del(itemCfgId, count) {
  650. this.SetDirty(true)
  651. }
  652. case serverproto.ResType_Res_Chip:
  653. this.GetRole().roleChip.DelChip(itemCfgId, count)
  654. case serverproto.ResType_Res_Equip:
  655. fallthrough
  656. case serverproto.ResType_Res_Card:
  657. fallthrough
  658. case serverproto.ResType_Res_PetEquip:
  659. util.WarnF("uid=%v PetEquip can't be del ", this.role.GetUUid())
  660. default:
  661. util.WarnF("uid=%v resType no exist!!! restype=%v ", this.role.GetUUid(), cfgData.ResType)
  662. }
  663. return
  664. }
  665. func (this *RoleBag) DelItemList(delItemList map[int32]int32, delFrom AddItemST) {
  666. this.checkValid()
  667. bBaseChange := false
  668. for itemCfgId, count := range delItemList {
  669. if itemCfgId <= 0 {
  670. continue
  671. }
  672. delFrom.ItemCfgId = itemCfgId
  673. delFrom.ItemCount = count
  674. if this.delItem(itemCfgId, delFrom, false) {
  675. bBaseChange = true
  676. }
  677. }
  678. util.InfoF("uid=%v DelItem itemList=%v delFrom=%v", this.role.GetUUid(), delItemList, delFrom)
  679. this.itemAction.doAction(true, false)
  680. if bBaseChange {
  681. this.role.GetRoleBase().BaseChangeNtf()
  682. }
  683. }
  684. func (this *RoleBag) DelItem(configId, count int32, delFrom AddItemST) {
  685. bBaseChange := false
  686. delFrom.ItemCfgId = configId
  687. delFrom.ItemCount = count
  688. if this.delItem(configId, delFrom, false) {
  689. bBaseChange = true
  690. }
  691. util.InfoF("uid=%v DelItem id=%v count=%v delFrom=%v", this.role.GetUUid(), configId, count, delFrom)
  692. this.itemAction.doAction(true, false)
  693. if bBaseChange {
  694. this.role.GetRoleBase().BaseChangeNtf()
  695. }
  696. }
  697. //该结构只删除背包中的道具(在背包中显示的道具)
  698. func (this *RoleBag) DelItemById(id uint64, count int32, delFrom AddFromType) {
  699. if this.itemAction.delByID(id, count) {
  700. this.SetDirty(true)
  701. this.itemAction.doAction(true, false)
  702. util.InfoF("uid=%v DelItemById id=%v count=%v delFrom=%v", this.role.GetUUid(), id, count, delFrom)
  703. }
  704. }
  705. func (this *RoleBag) UseHeadFrameItem(itemId uint64, itemNum uint32) (serverproto.ErrorCode, []*serverproto.KeyValueType) {
  706. if itemNum <= 0 {
  707. return serverproto.ErrorCode_ERROR_FAIL, nil
  708. }
  709. item := this.getItemById(itemId)
  710. if item == nil || item.Num < itemNum {
  711. return serverproto.ErrorCode_ERROR_RENAME_ITEM_NOT_ENOUGH, nil
  712. }
  713. cfgData, ok := serverproto.ItemCfgLoader[item.ConfigId]
  714. if !ok {
  715. util.InfoF("uid=%v item cfg data not found itemCfgId=%v", this.role.GetUUid(), item.ConfigId)
  716. return serverproto.ErrorCode_ERROR_ITEM_NOT_FOUND, nil
  717. }
  718. frameList := strings.Split(cfgData.ComposeItem[0], ":")
  719. if len(frameList) >= 2 {
  720. frameId, _ := model.Str2Num(frameList[0])
  721. frameTime, _ := model.Str2Num(frameList[1])
  722. //校验头像框
  723. headFrameCfg, headFrameOk := serverproto.HeadFrameCfgLoader[int32(frameId)]
  724. if headFrameOk == false {
  725. return serverproto.ErrorCode_ERROR_ITEM_NOT_FOUND, nil
  726. }
  727. //头像框流程
  728. bRet := this.role.GetRoleBase().AddHeadFrame(int32(frameId), int32(frameTime), int32(itemNum))
  729. this.DelItem(item.ConfigId, int32(itemNum), AddItemST{AddFrom: AddFrom_HeadFrame})
  730. if bRet == serverproto.ErrorCode_ERROR_HEAD_FRAME_EXCHANGE_ITEM {
  731. var retMList = map[int32]int32{}
  732. var retKList []*serverproto.KeyValueType
  733. resList := strings.Split(headFrameCfg.ResolveItem[0], ":")
  734. if len(frameList) >= 2 {
  735. resId, _ := model.Str2Num(resList[0])
  736. resNum, _ := model.Str2Num(resList[1])
  737. retMList[int32(resId)] = int32(resNum) * int32(itemNum)
  738. retKList = append(retKList, &serverproto.KeyValueType{
  739. Key: int32(resId),
  740. Value: int32(resNum) * int32(itemNum),
  741. })
  742. }
  743. this.AddItemList(retMList, AddItemST{AddFrom: AddFrom_Package, Notify: true})
  744. return serverproto.ErrorCode_ERROR_HEAD_FRAME_EXCHANGE_ITEM, retKList
  745. }
  746. return serverproto.ErrorCode_ERROR_OK, nil
  747. }
  748. return serverproto.ErrorCode_ERROR_FAIL, nil
  749. }
  750. func (this *RoleBag) UseItem(id uint64, count uint32, itemIdxList []int32, bForceItemId bool) serverproto.ErrorCode {
  751. item := this.getItemById(id)
  752. if item == nil || item.Num < count {
  753. return serverproto.ErrorCode_ERROR_ITEM_NOT_FOUND
  754. }
  755. util.InfoF("uid=%v UseItem id=%v cfgId=%v count=%v", this.role.GetUUid(), id, item.ConfigId, count)
  756. if bForceItemId {
  757. return this.autoUseItem(item.ConfigId, count, true, itemIdxList, id)
  758. } else {
  759. return this.autoUseItem(item.ConfigId, count, true, itemIdxList, 0)
  760. }
  761. }
  762. func (this *RoleBag) autoUseItem(itemCfgId int32, count uint32, notify bool, itemIdxList []int32, itemId uint64) serverproto.ErrorCode {
  763. this.checkValid()
  764. cfgData, ok := serverproto.ItemCfgLoader[itemCfgId]
  765. if !ok {
  766. util.InfoF("uid=%v item cfg data not found itemCfgId=%v", this.role.GetUUid(), itemCfgId)
  767. return serverproto.ErrorCode_ERROR_ITEM_NOT_FOUND
  768. }
  769. if cfgData.NeedLevel != 0 && cfgData.NeedLevel > this.role.GetRoleLevel() {
  770. return serverproto.ErrorCode_ERROR_USEITEM_ROLE_LEVEL_NOT_ENOUGH
  771. }
  772. if itemId > 0 {
  773. item := this.getItemById(itemId)
  774. //判断是否是达到对应时间可使用道具
  775. if cfgData.ItemTime == Item_Time_Type_TimeUse {
  776. if int64(item.TimeStamp+uint32(cfgData.ItemTimeCd)) > util.GetTimeSeconds() {
  777. return serverproto.ErrorCode_ERROR_ITEM_NOT_IN_USE_TIME
  778. }
  779. }
  780. }
  781. //获取使用消耗
  782. var consumeItemLIst = map[int32]int32{}
  783. for idx := 0; idx < len(cfgData.Costitem); idx++ {
  784. key, val := model.Str2Res(cfgData.Costitem[idx])
  785. if key <= 0 || val <= 0 {
  786. continue
  787. }
  788. if !this.CanDelItem(key, val*int32(count)) {
  789. return serverproto.ErrorCode_ERROR_RES_NOT_ENOUGH
  790. }
  791. consumeItemLIst[key] += val * int32(count)
  792. }
  793. //获取礼包内容
  794. var addItemList = map[int32]int32{}
  795. for i := 0; i < int(count); i++ {
  796. switch serverproto.ResType(cfgData.ResType) {
  797. case serverproto.ResType_Res_Hero:
  798. this.role.GetRoleHero().AddHeroByList(cfgData.ComposeItem)
  799. case serverproto.ResType_Res_Gift:
  800. //掉落处理//根据配置需要按照职业/性别给箱子
  801. job := false
  802. if cfgData.Job == 1 {
  803. job = true
  804. }
  805. //先区分性别
  806. if SEX_FEMALE == this.role.GetRoleBase().GetRoleSex() {
  807. this.openPackage(cfgData.ComposeItem, addItemList, job)
  808. } else {
  809. this.openPackage(cfgData.Resolve, addItemList, job)
  810. }
  811. case serverproto.ResType_Res_ItemCompose:
  812. //先区分性别
  813. if SEX_FEMALE == this.role.GetRoleBase().GetRoleSex() {
  814. this.openPackage(cfgData.ComposeItem, addItemList, false)
  815. } else {
  816. this.openPackage(cfgData.Resolve, addItemList, false)
  817. }
  818. case serverproto.ResType_Res_Head_Item:
  819. for _, data := range cfgData.ComposeItem {
  820. itemList := strings.Split(data, ":")
  821. if len(itemList) < 2 {
  822. continue
  823. }
  824. itemId, _ := model.Str2Num(itemList[0])
  825. cnt, _ := model.Str2Num(itemList[1])
  826. addItemList[int32(itemId)] += int32(cnt)
  827. }
  828. case serverproto.ResType_Res_QuickBattle:
  829. for _, data := range cfgData.ComposeItem {
  830. itemList := strings.Split(data, ":")
  831. if len(itemList) < 2 {
  832. continue
  833. }
  834. itemId, _ := model.Str2Num(itemList[0])
  835. hours, _ := model.Str2Num(itemList[1])
  836. var itemNum int32 = 0
  837. levelCfg, ok := serverproto.LevelCfgLoader[this.role.GetRoleBattle().GetLevelId()]
  838. if !ok {
  839. continue
  840. }
  841. if itemId == int(serverproto.ResType_Res_RoleBaseExp) {
  842. itemNum = levelCfg.BaseExpOl
  843. } else if itemId == int(serverproto.ResType_Res_HeroBaseExp) {
  844. itemNum = levelCfg.ParterOl
  845. } else if itemId == int(serverproto.ResType_Res_Coin) {
  846. itemNum = levelCfg.ZenyOl
  847. } else if itemId == int(serverproto.ResType_Res_Cruise) {
  848. itemNum = levelCfg.CruiseOl
  849. } else {
  850. continue
  851. }
  852. tmpAddNum := uint64(itemNum) * (uint64(hours) / uint64(model.GlobalIncomeTime))
  853. tmpNum := uint64(addItemList[int32(itemId)]) + tmpAddNum
  854. if tmpNum > math.MaxInt32 {
  855. util.ErrorF("uid=%v useItem limit configid=%v count=%v", this.role.GetUUid(), itemCfgId, count)
  856. return serverproto.ErrorCode_ERROR_SERVER_USE_FAILED_LIMIT
  857. }
  858. addItemList[int32(itemId)] += int32(tmpAddNum)
  859. }
  860. case serverproto.ResType_Res_Gift_Unique:
  861. //只能使用一个
  862. if i > 1 || len(itemIdxList) <= 0 {
  863. break
  864. }
  865. hasList := set.New(set.NonThreadSafe)
  866. for idx := 0; idx < len(itemIdxList); idx++ {
  867. if int(itemIdxList[idx]) >= len(cfgData.ComposeItem) || itemIdxList[idx] < 0 {
  868. break
  869. }
  870. if hasList.Has(itemIdxList[idx]) {
  871. continue
  872. }
  873. hasList.Add(itemIdxList[idx])
  874. itemId, ItemNum := model.Str2Res(cfgData.ComposeItem[itemIdxList[idx]])
  875. if itemId > 0 && ItemNum > 0 {
  876. addItemList[itemId] += ItemNum
  877. }
  878. }
  879. case serverproto.ResType_Res_Month_Car_Item:
  880. if len(cfgData.ComposeItem) > 0 {
  881. if id, err := model.Str2Num(cfgData.ComposeItem[0]); err == nil {
  882. this.role.GetRoleRune().AddMonthCardItem(int32(id), 1)
  883. }
  884. }
  885. case serverproto.ResType_Res_Rune_Unlock_Award:
  886. rune := this.role.GetRoleRune()
  887. if rune != nil && rune.runeExplore != nil {
  888. if !RuneShopMag.IsOpen() {
  889. return serverproto.ErrorCode_ERROR_RUNE_NO_OPEN
  890. }
  891. if rune.runeExplore.BUnlock {
  892. return serverproto.ErrorCode_ERROR_RUNE_HIGHTER_UNLOCK
  893. }
  894. this.role.GetRoleRune().RuneUnlock()
  895. }
  896. }
  897. }
  898. //消耗资源并获得礼包内容
  899. switch serverproto.ResType(cfgData.ResType) {
  900. case serverproto.ResType_Res_Hero:
  901. if itemId > 0 {
  902. this.DelItemById(itemId, int32(count), AddFrom_Package)
  903. } else {
  904. this.DelItem(itemCfgId, int32(count), AddItemST{AddFrom: AddFrom_Package})
  905. }
  906. case serverproto.ResType_Res_Month_Car_Item, serverproto.ResType_Res_Rune_Unlock_Award:
  907. if itemId > 0 {
  908. this.DelItemById(itemId, int32(count), AddFrom_Package)
  909. } else {
  910. this.DelItem(itemCfgId, int32(count), AddItemST{AddFrom: AddFrom_Package})
  911. }
  912. return serverproto.ErrorCode_ERROR_OK
  913. case serverproto.ResType_Res_ItemCompose:
  914. this.DelItemList(consumeItemLIst, AddItemST{AddFrom: AddFrom_Package})
  915. this.AddItemList(addItemList, AddItemST{AddFrom: AddFrom_Package, Notify: notify, UseItemCfgId: itemCfgId})
  916. default:
  917. if cfgData.ResType == int32(serverproto.ResType_Res_Gift) {
  918. // 特殊处理使用道具添加战斗倍数时间
  919. for idx := 0; idx < len(model.GlobalFastBattleTime); idx++ {
  920. if model.GlobalFastBattleTime[idx].Key == itemCfgId {
  921. this.role.GetRoleBattle().FastBattleTimeAdd(model.GlobalFastBattleTime[idx].Value * int32(count))
  922. //消耗资源
  923. if itemId > 0 {
  924. this.DelItemById(itemId, int32(count), AddFrom_Package)
  925. } else {
  926. consumeItemLIst[itemCfgId] += int32(count)
  927. }
  928. this.DelItemList(consumeItemLIst, AddItemST{AddFrom: AddFrom_Package})
  929. break
  930. }
  931. }
  932. }
  933. if len(addItemList) > 0 {
  934. ret := this.CanAddItemList(addItemList)
  935. if ret == serverproto.ErrorCode_ERROR_OK {
  936. this.AddItemList(addItemList, AddItemST{AddFrom: AddFrom_Package, Notify: notify, UseItemCfgId: itemCfgId})
  937. //消耗资源
  938. if itemId > 0 {
  939. this.DelItemById(itemId, int32(count), AddFrom_Package)
  940. } else {
  941. consumeItemLIst[itemCfgId] += int32(count)
  942. }
  943. this.DelItemList(consumeItemLIst, AddItemST{AddFrom: AddFrom_Package})
  944. } else {
  945. return ret
  946. }
  947. }
  948. }
  949. ackMsg := &serverproto.SCUseItemAck{
  950. Error: int32(serverproto.ErrorCode_ERROR_OK),
  951. }
  952. if len(addItemList) <= 0 {
  953. //ackMsg.Error = int32(serverproto.ErrorCode_ERROR_FAIL)
  954. } else {
  955. for key, value := range addItemList {
  956. ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
  957. Key: key,
  958. Value: value,
  959. })
  960. }
  961. }
  962. this.role.ReplayGate(ackMsg, true)
  963. return serverproto.ErrorCode_ERROR_OK
  964. }
  965. //是否能添加该列表物品(整体添加)
  966. func (this *RoleBag) CanAddItemList(addItemList map[int32]int32) serverproto.ErrorCode {
  967. for key, value := range addItemList {
  968. ret := this.CanAddItem(key, value)
  969. if ret != serverproto.ErrorCode_ERROR_OK {
  970. return ret
  971. }
  972. }
  973. return serverproto.ErrorCode_ERROR_OK
  974. }
  975. func (this *RoleBag) CanAddItem(configId int32, count int32) serverproto.ErrorCode {
  976. if count <= 0 {
  977. return serverproto.ErrorCode_ERROR_FAIL
  978. }
  979. cfgData, ok := serverproto.ItemCfgLoader[configId]
  980. if !ok {
  981. util.InfoF("uid=%v item cfg data not found itemCfgId=%v", this.role.GetUUid(), configId)
  982. return serverproto.ErrorCode_ERROR_ITEM_NOT_FOUND
  983. }
  984. switch serverproto.ResType(cfgData.ResType) {
  985. case serverproto.ResType_Res_Item:
  986. fallthrough
  987. case serverproto.ResType_Res_HeadFrame:
  988. fallthrough
  989. case serverproto.ResType_Res_SkillBook:
  990. fallthrough
  991. case serverproto.ResType_Res_Card:
  992. fallthrough
  993. case serverproto.ResType_Res_Pet:
  994. fallthrough
  995. case serverproto.ResType_Res_QuickBattle:
  996. fallthrough
  997. case serverproto.ResType_Res_Fashion: //只添加图纸
  998. if cfgData.Composition <= 0 {
  999. //if this.role.roleBag.getItemPileNum(configId) <= 0 {
  1000. util.InfoF("uid=%v CanAddItem max count can not add or cfg not found itemCfgId=%v", this.role.GetUUid(), configId)
  1001. return serverproto.ErrorCode_ERROR_BAG_ITEM_PILE
  1002. }
  1003. if uint64(count) > this.canAddCnt(configId, uint32(cfgData.Composition)) {
  1004. util.InfoF("uid=%v CanAddItem limit count itemCfgId=%v", this.role.GetUUid(), configId)
  1005. return serverproto.ErrorCode_ERROR_BAG_FULL
  1006. }
  1007. }
  1008. return serverproto.ErrorCode_ERROR_OK
  1009. }
  1010. func (this *RoleBag) CanDelItemList(delItemList map[int32]int32) bool {
  1011. for key, value := range delItemList {
  1012. if !this.CanDelItem(key, value) {
  1013. return false
  1014. }
  1015. }
  1016. return true
  1017. }
  1018. func (this *RoleBag) CanDelItem(configId int32, count int32) bool {
  1019. if count <= 0 {
  1020. return false
  1021. }
  1022. if configId > 100 {
  1023. if this.role.GetItemNum(configId) < uint32(count) {
  1024. return false
  1025. }
  1026. } else {
  1027. if this.role.GetResNum(configId) < uint64(count) {
  1028. util.InfoF("uid=%v del item num not enough itemCfgId=%v", this.role.GetUUid(), configId)
  1029. return false
  1030. }
  1031. }
  1032. return true
  1033. }
  1034. //打开礼包
  1035. func (this *RoleBag) openPackage(dropIdList []string, addItemList map[int32]int32, job bool) {
  1036. roleJobType := this.role.GetRoleBase().GetRoleJobType()
  1037. for idx := 0; idx < len(dropIdList); idx++ {
  1038. if !job { //不按照job给箱子
  1039. dropId, _ := model.Str2Num(dropIdList[idx])
  1040. if dropId <= 0 {
  1041. continue
  1042. }
  1043. this.role.GetRoleBattle().DropProcess(addItemList, int32(dropId))
  1044. } else { //按照job给箱子
  1045. jobType, dropId := model.Str2Res(dropIdList[idx])
  1046. if (dropId <= 0) || (jobType != roleJobType) {
  1047. continue
  1048. }
  1049. this.role.GetRoleBattle().DropProcess(addItemList, int32(dropId))
  1050. }
  1051. }
  1052. }
  1053. //GM process
  1054. func (this *RoleBag) GMClearBag() {
  1055. for _, data := range this.itemList {
  1056. cfgData, ok := serverproto.ItemCfgLoader[data.ConfigId]
  1057. if !ok {
  1058. util.InfoF("uid=%v item cfg data not found itemCfgId=%v", this.role.GetUUid(), data.ConfigId)
  1059. break
  1060. }
  1061. switch serverproto.ResType(cfgData.ResType) {
  1062. case serverproto.ResType_Res_SkillBook:
  1063. case serverproto.ResType_Res_Gift:
  1064. case serverproto.ResType_Res_QuickBattle:
  1065. case serverproto.ResType_Res_HeadFrame:
  1066. fallthrough
  1067. case serverproto.ResType_Res_Item:
  1068. this.itemAction.del(data.ConfigId, int32(data.Num))
  1069. this.SetDirty(true)
  1070. }
  1071. }
  1072. this.itemAction.doAction(true, false)
  1073. }