Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
6f61a5102a
@ -54,18 +54,21 @@ func (this *apiComp) Useitem(session comm.IUserSession, req *pb.ItemsUseItemReq)
|
|||||||
code = pb.ErrorCode_ItemsUseNotSupported
|
code = pb.ErrorCode_ItemsUseNotSupported
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
item.Amount = item.Amount - req.Amount
|
if code = this.module.AddItemforGrid(&comm.ModuleCallSource{}, session, req.GridId, -1*int32(req.Amount), true); code != pb.ErrorCode_Success {
|
||||||
if item.Amount == 0 {
|
return
|
||||||
if err = this.module.modelItems.DelUserPack(session.GetUserId(), item.GridId); err != nil {
|
|
||||||
code = pb.ErrorCode_DBError
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err = this.module.modelItems.UpdateUserPack(session.GetUserId(), item); err != nil {
|
|
||||||
code = pb.ErrorCode_DBError
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// item.Amount = item.Amount - req.Amount
|
||||||
|
// if item.Amount == 0 {
|
||||||
|
// if err = this.module.modelItems.DelUserPack(session.GetUserId(), item.GridId); err != nil {
|
||||||
|
// code = pb.ErrorCode_DBError
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// if err = this.module.modelItems.UpdateUserPack(session.GetUserId(), item); err != nil {
|
||||||
|
// code = pb.ErrorCode_DBError
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// }
|
||||||
session.SendMsg(string(this.module.GetType()), "useitem", &pb.ItemsUseItemResp{GridId: req.GridId, Amount: req.Amount, Issucc: true})
|
session.SendMsg(string(this.module.GetType()), "useitem", &pb.ItemsUseItemResp{GridId: req.GridId, Amount: req.Amount, Issucc: true})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -207,32 +207,28 @@ func (this *ModelItemsComp) AddItemsToUserPack(uId string, items map[int32]int32
|
|||||||
}
|
}
|
||||||
|
|
||||||
///修改指定格子的物品数量
|
///修改指定格子的物品数量
|
||||||
func (this *ModelItemsComp) AddItemToUserPackByGrid(uId string, gridid string, itemId int32, addnum int32) (err error) {
|
func (this *ModelItemsComp) AddItemToUserPackByGrid(uId string, gridid string, addnum int32) (change []*pb.DB_UserItemData, err error) {
|
||||||
var (
|
var (
|
||||||
conf *cfg.Game_itemData
|
conf *cfg.Game_itemData
|
||||||
itme *pb.DB_UserItemData
|
itme *pb.DB_UserItemData
|
||||||
grid *pb.DB_UserItemData
|
|
||||||
num int64
|
num int64
|
||||||
amount int64
|
amount int64
|
||||||
)
|
)
|
||||||
if addnum == 0 {
|
if addnum == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if conf, err = this.module.configure.GetItemConfigure(itemId); err != nil {
|
|
||||||
this.module.Errorf("err:%v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if itme, err = this.QueryUserPackByGridId(uId, gridid); err != nil {
|
if itme, err = this.QueryUserPackByGridId(uId, gridid); err != nil {
|
||||||
this.module.Errorf("err:%v", err)
|
this.module.Errorf("err:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
amount = int64(itme.Amount)
|
|
||||||
if grid.ItemId != itemId {
|
if conf, err = this.module.configure.GetItemConfigure(itme.ItemId); err != nil {
|
||||||
err = fmt.Errorf("target grid itemid:%d no is %d ", grid.ItemId, itemId)
|
this.module.Errorf("err:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
amount = int64(itme.Amount)
|
||||||
num = amount + int64(addnum)
|
num = amount + int64(addnum)
|
||||||
|
change = make([]*pb.DB_UserItemData, 0)
|
||||||
if num < 0 {
|
if num < 0 {
|
||||||
err = ItemNotEnoughError
|
err = ItemNotEnoughError
|
||||||
} else {
|
} else {
|
||||||
@ -242,6 +238,7 @@ func (this *ModelItemsComp) AddItemToUserPackByGrid(uId string, gridid string, i
|
|||||||
} else {
|
} else {
|
||||||
itme.Amount = uint32(num)
|
itme.Amount = uint32(num)
|
||||||
this.UpdateUserPack(uId, itme)
|
this.UpdateUserPack(uId, itme)
|
||||||
|
change = append(change, itme)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -61,6 +61,30 @@ func (this *Items) QueryItemsAmount(source *comm.ModuleCallSource, uId string, i
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Items) AddItemforGrid(source *comm.ModuleCallSource, session comm.IUserSession, gridid string, addnum int32, bPush bool) (code pb.ErrorCode) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
change []*pb.DB_UserItemData
|
||||||
|
)
|
||||||
|
defer this.Debugf("给用户添加物品 uId:%s gridid:%d addnum:%d issucc:%v", session.GetUserId(), gridid, addnum, err == nil)
|
||||||
|
if change, err = this.modelItems.AddItemToUserPackByGrid(session.GetUserId(), gridid, addnum); err != nil {
|
||||||
|
this.Errorf("给用户添加物品 uId:%s gridid:%d addnum:%d err:%v", session.GetUserId(), gridid, addnum, err)
|
||||||
|
if err == ItemNotEnoughError {
|
||||||
|
code = pb.ErrorCode_ItemsNoEnough
|
||||||
|
} else if err == PackGridNumUpper {
|
||||||
|
code = pb.ErrorCode_ItemsGridNumUpper
|
||||||
|
} else {
|
||||||
|
code = pb.ErrorCode_Unknown
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if bPush {
|
||||||
|
this.itemsChangePush(session, change) //推送道具背包变化
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
///添加单个物品到背包 (可以加物品和减物品)
|
///添加单个物品到背包 (可以加物品和减物品)
|
||||||
func (this *Items) AddItem(source *comm.ModuleCallSource, session comm.IUserSession, itemid, addnum int32, bPush bool) (code pb.ErrorCode) {
|
func (this *Items) AddItem(source *comm.ModuleCallSource, session comm.IUserSession, itemid, addnum int32, bPush bool) (code pb.ErrorCode) {
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user