role_bag.go 36 KB

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