Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
ba619a1c08
@ -40,7 +40,7 @@ type (
|
||||
//创建指定数量
|
||||
CreateRepeatHero(uid string, heroCfgId string, num int32) (*pb.DBHero, error)
|
||||
// 批量创建英雄
|
||||
CreateRepeatHeros(session IUserSession, items map[string]int32, bPush bool) (code pb.ErrorCode)
|
||||
CreateRepeatHeros(session IUserSession, heros map[string]int32, bPush bool) (code pb.ErrorCode)
|
||||
// 获取英雄
|
||||
// heroId 英雄ID
|
||||
GetHeroByObjID(uid, heroId string) (*pb.DBHero, pb.ErrorCode)
|
||||
@ -64,6 +64,8 @@ type (
|
||||
QueryAttributeValue(uid string, attr string) (value int32)
|
||||
//添加/减少属性值 第四个参数控制是否推送给前端
|
||||
AddAttributeValue(session IUserSession, attr string, add int32, bPush bool) (code pb.ErrorCode)
|
||||
// 批量处理
|
||||
AddAttributeValues(session IUserSession, attrs map[string]int32, bPush bool) (code pb.ErrorCode)
|
||||
//用户改变事件
|
||||
EventUserChanged(session IUserSession)
|
||||
//获取用户expand
|
||||
|
@ -112,6 +112,7 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int
|
||||
hero = this.initHero(uid, heroCfgId)
|
||||
if hero != nil {
|
||||
// 添加图鉴
|
||||
go func(uid, heroCfgId string) { // 携程处理 图鉴数据
|
||||
if result, err1 := this.moduleHero.ModuleUser.GetUserExpand(uid); err1 == nil {
|
||||
sz := make(map[string]bool, 0)
|
||||
for k := range result.GetTujian() {
|
||||
@ -126,6 +127,8 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int
|
||||
this.moduleHero.ModuleUser.ChangeUserExpand(uid, initUpdate)
|
||||
}
|
||||
}
|
||||
}(uid, heroCfgId)
|
||||
|
||||
hero.SameCount = count
|
||||
if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil {
|
||||
this.moduleHero.Errorf("%v", err)
|
||||
|
@ -159,14 +159,22 @@ func (this *Hero) EventUserOffline(session comm.IUserSession) {
|
||||
}
|
||||
|
||||
// 批量创建多个英雄
|
||||
func (this *Hero) CreateRepeatHeros(session comm.IUserSession, items map[string]int32, bPush bool) (code pb.ErrorCode) {
|
||||
|
||||
for heroCfgId, num := range items {
|
||||
_, err := this.modelHero.createHeroOverlying(session.GetUserId(), heroCfgId, num)
|
||||
func (this *Hero) CreateRepeatHeros(session comm.IUserSession, heros map[string]int32, bPush bool) (code pb.ErrorCode) {
|
||||
changeHero := make([]*pb.DBHero, 0)
|
||||
for heroCfgId, num := range heros {
|
||||
if num == 0 { // 数量为0 不做处理
|
||||
continue
|
||||
}
|
||||
hero, err := this.modelHero.createHeroOverlying(session.GetUserId(), heroCfgId, num)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_HeroCreate
|
||||
break
|
||||
return
|
||||
}
|
||||
changeHero = append(changeHero, hero)
|
||||
}
|
||||
|
||||
if bPush && len(changeHero) > 0 { //推送
|
||||
session.SendMsg("hero", "change", &pb.HeroChangePush{List: changeHero})
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -47,7 +47,7 @@ func (this *apiComp) GetUserMailAttachment(session comm.IUserSession, req *pb.Ma
|
||||
if code == pb.ErrorCode_Success {
|
||||
// 修改状态
|
||||
this.module.modelMail.MailUpdateMailAttachmentState(req.ObjID)
|
||||
mail.Reward = true
|
||||
//mail.Reward = true
|
||||
//return
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func (this *apiComp) ReadMail(session comm.IUserSession, req *pb.MailReadMailReq
|
||||
return
|
||||
}
|
||||
this.module.Debugf("read mail %v", mail)
|
||||
mail.Check = true
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), "readmail", &pb.MailReadMailResp{Mail: mail})
|
||||
return
|
||||
}
|
||||
|
@ -178,71 +178,56 @@ func (this *ModuleBase) CheckRes(session comm.IUserSession, res []*cfg.Game_atn)
|
||||
//消耗资源
|
||||
func (this *ModuleBase) ConsumeRes(session comm.IUserSession, res []*cfg.Game_atn, bPush bool) (code pb.ErrorCode) {
|
||||
var (
|
||||
amount int32
|
||||
items map[string]int32 // 道具背包 批量处理
|
||||
attrs map[string]int32 // 属性
|
||||
)
|
||||
items = make(map[string]int32, 0)
|
||||
attrs = make(map[string]int32, 0)
|
||||
|
||||
for _, v := range res {
|
||||
switch v.A {
|
||||
case comm.AttrType:
|
||||
attrs[v.T] -= v.N
|
||||
case comm.ItemType:
|
||||
items[v.T] -= v.N
|
||||
default:
|
||||
this.Errorf("not found res type") // 找不到资源类型
|
||||
}
|
||||
}
|
||||
source := &comm.ModuleCallSource{
|
||||
Module: string(this.module.GetType()),
|
||||
FuncName: "CheckConsumeRes",
|
||||
Describe: "消耗资源",
|
||||
}
|
||||
//校验消费资源是否充足
|
||||
for _, v := range res {
|
||||
if v.A == comm.AttrType { //用户属性资源
|
||||
if amount = this.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T); amount < v.N {
|
||||
// 校验数量
|
||||
for k, v := range attrs {
|
||||
if this.ModuleUser.QueryAttributeValue(session.GetUserId(), k) < -v { // -v 负负得正
|
||||
code = pb.ErrorCode_ResNoEnough
|
||||
this.Errorf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N)
|
||||
return
|
||||
}
|
||||
} else if v.A == comm.ItemType { //道具资源
|
||||
// if resID, err = strconv.Atoi(v.T); err != nil {
|
||||
// code = pb.ErrorCode_ConfigurationException
|
||||
// return
|
||||
// }
|
||||
if amount = int32(this.ModuleItems.QueryItemAmount(source, session.GetUserId(), v.T)); amount < v.N {
|
||||
code = pb.ErrorCode_ResNoEnough
|
||||
this.Errorf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N)
|
||||
this.Errorf("资源不足: A: attr, T: %s, N: %d", k, v)
|
||||
return
|
||||
}
|
||||
}
|
||||
// else if v.A == comm.HeroType { //卡片资源
|
||||
// if resID, err = strconv.Atoi(v.T); err != nil {
|
||||
// code = pb.ErrorCode_ConfigurationException
|
||||
// return
|
||||
// }
|
||||
// if amount = int32(this.ModuleHero.QueryHeroAmount(uid, int32(resID))); amount < v.N {
|
||||
// code = pb.ErrorCode_ResNoEnough
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
//不存在消耗武器的情况
|
||||
// } else if v.A == comm.EquipmentType {
|
||||
// if resID, err = strconv.Atoi(v.T); err != nil {
|
||||
// code = pb.ErrorCode_ConfigurationException
|
||||
// return
|
||||
// }
|
||||
// if amount = int32(equipment.QueryEquipmentAmount(source, uid, int32(resID))); amount < v.N {
|
||||
// code = pb.ErrorCode_ResNoEnough
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
for k, v := range items {
|
||||
if int32(this.ModuleItems.QueryItemAmount(source, session.GetUserId(), k)) < -v {
|
||||
code = pb.ErrorCode_ResNoEnough
|
||||
this.Errorf("道具不足: A: item, T:%s, N:%d", k, v)
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range res {
|
||||
if v.A == comm.AttrType { //用户属性资源
|
||||
this.ModuleUser.AddAttributeValue(session, v.T, -1*v.N, bPush)
|
||||
} else if v.A == comm.ItemType { //道具资源
|
||||
//resID, _ = strconv.Atoi(v.T)
|
||||
this.ModuleItems.AddItem(source, session, v.T, -1*v.N, bPush)
|
||||
}
|
||||
// else if v.A == comm.HeroType { //卡片资源
|
||||
// resID, _ = strconv.Atoi(v.T)
|
||||
// this.ModuleHero.ConsumeCard(uid, int32(resID), -1*v.N)
|
||||
// }
|
||||
// } else if v.A == comm.EquipmentType {
|
||||
// resID, _ = strconv.Atoi(v.T)
|
||||
// equipment.AddNewEquipments(source, uid, resID, -1*v.N)
|
||||
// }
|
||||
// 真正消耗
|
||||
if len(attrs) > 0 {
|
||||
code = this.ModuleUser.AddAttributeValues(session, attrs, bPush)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
this.Debugf("消耗玩家资源: %v", attrs)
|
||||
}
|
||||
if len(items) > 0 {
|
||||
code = this.ModuleItems.AddItems(source, session, items, bPush)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
this.Debugf("消耗道具资源: %v", items)
|
||||
}
|
||||
|
||||
return
|
||||
@ -251,37 +236,53 @@ func (this *ModuleBase) ConsumeRes(session comm.IUserSession, res []*cfg.Game_at
|
||||
//发放资源
|
||||
func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Game_atn, bPush bool) (code pb.ErrorCode) {
|
||||
var (
|
||||
hero []*pb.DBHero
|
||||
items map[string]int32 // 道具背包 批量处理
|
||||
heros map[string]int32 // 英雄
|
||||
attrs map[string]int32 // 属性
|
||||
equips map[string]uint32 // 装备
|
||||
)
|
||||
items = make(map[string]int32, 0)
|
||||
heros = make(map[string]int32, 0)
|
||||
attrs = make(map[string]int32, 0)
|
||||
equips = make(map[string]uint32, 0)
|
||||
|
||||
source := &comm.ModuleCallSource{
|
||||
Module: string(this.module.GetType()),
|
||||
FuncName: "DispenseRes",
|
||||
Describe: "发放资源",
|
||||
}
|
||||
for _, v := range res {
|
||||
this.Debugf("发放资源 DispenseRes:A = %s, T:%s, N:%d", v.A, v.T, v.N)
|
||||
if v.A == comm.AttrType { //用户属性资源
|
||||
code = this.ModuleUser.AddAttributeValue(session, v.T, v.N, bPush)
|
||||
switch v.A {
|
||||
case comm.AttrType:
|
||||
attrs[v.T] += v.N
|
||||
case comm.ItemType:
|
||||
items[v.T] += v.N
|
||||
case comm.HeroType:
|
||||
heros[v.T] += v.N
|
||||
case comm.EquipmentType:
|
||||
if v.N > 0 { // 不允许减少装备
|
||||
equips[v.T] += uint32(v.N)
|
||||
}
|
||||
default:
|
||||
this.Errorf("not found res type") // 找不到资源类型
|
||||
}
|
||||
}
|
||||
|
||||
} else if v.A == comm.ItemType { //道具资源
|
||||
// resID = cast.ToInt(v.T)
|
||||
// resID, _ = strconv.Atoi(v.T)
|
||||
code = this.ModuleItems.AddItem(source, session, v.T, v.N, bPush)
|
||||
} else if v.A == comm.HeroType { //卡片资源
|
||||
//resID, _ = strconv.Atoi(v.T)
|
||||
_hero, err := this.ModuleHero.CreateRepeatHero(session.GetUserId(), v.T, v.N)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_HeroMaxCount
|
||||
return
|
||||
if len(attrs) > 0 { //用户属性资源
|
||||
code = this.ModuleUser.AddAttributeValues(session, attrs, bPush)
|
||||
this.Debugf("发放用户资源: %v", attrs)
|
||||
}
|
||||
hero = append(hero, _hero)
|
||||
} else if v.A == comm.EquipmentType {
|
||||
//resID, _ = strconv.Atoi(v.T)
|
||||
code = this.ModuleEquipment.AddNewEquipments(source, session, map[string]uint32{v.T: uint32(v.N)}, bPush)
|
||||
if len(items) > 0 { //道具资源
|
||||
code = this.ModuleItems.AddItems(source, session, items, bPush)
|
||||
this.Debugf("发放道具资源: %v", items)
|
||||
}
|
||||
if len(heros) > 0 { //卡片资源
|
||||
code = this.ModuleHero.CreateRepeatHeros(session, heros, bPush)
|
||||
this.Debugf("发放英雄资源: %v", heros)
|
||||
}
|
||||
if len(hero) > 0 {
|
||||
session.SendMsg("hero", "change", &pb.HeroChangePush{List: hero})
|
||||
if len(equips) > 0 {
|
||||
code = this.ModuleEquipment.AddNewEquipments(source, session, equips, bPush)
|
||||
this.Debugf("发放装备资源: %v", equips)
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -161,6 +161,74 @@ func (this *User) AddAttributeValue(session comm.IUserSession, attr string, add
|
||||
return
|
||||
}
|
||||
|
||||
//用户资源
|
||||
func (this *User) AddAttributeValues(session comm.IUserSession, attrs map[string]int32, bPush bool) (code pb.ErrorCode) {
|
||||
user := this.GetUser(session.GetUserId())
|
||||
if user == nil {
|
||||
code = pb.ErrorCode_UserSessionNobeing
|
||||
return
|
||||
}
|
||||
_change := &pb.UserResChangePush{
|
||||
Gold: user.Gold,
|
||||
Exp: user.Exp,
|
||||
Lv: user.Lv,
|
||||
Vip: user.Vip,
|
||||
Diamond: user.Diamond,
|
||||
}
|
||||
update := make(map[string]interface{})
|
||||
for key, add := range attrs {
|
||||
if add == 0 {
|
||||
log.Errorf("attr no changed,uid: %s attr: %s add: %d", session.GetUserId(), key, add)
|
||||
continue
|
||||
}
|
||||
switch key {
|
||||
case comm.ResGold:
|
||||
if add < 0 {
|
||||
if user.Gold+add < 0 {
|
||||
code = pb.ErrorCode_GoldNoEnough
|
||||
return
|
||||
}
|
||||
}
|
||||
_change.Gold += add
|
||||
update[comm.ResGold] = user.Gold + add
|
||||
case comm.ResExp:
|
||||
if add < 0 {
|
||||
if user.Exp+add < 0 {
|
||||
code = pb.ErrorCode_ResNoEnough
|
||||
return
|
||||
}
|
||||
}
|
||||
_change.Exp += add
|
||||
update[comm.ResExp] = user.Exp + add
|
||||
case comm.ResDiamond:
|
||||
if add < 0 {
|
||||
if user.Diamond+add < 0 {
|
||||
code = pb.ErrorCode_ResNoEnough
|
||||
return
|
||||
}
|
||||
}
|
||||
_change.Diamond += add
|
||||
update[comm.ResDiamond] = user.Diamond + add
|
||||
default:
|
||||
code = pb.ErrorCode_Unknown
|
||||
}
|
||||
}
|
||||
|
||||
if len(update) == 0 {
|
||||
log.Warn("AddAttributeValue param is empty")
|
||||
return
|
||||
}
|
||||
if err := this.modelUser.updateUserAttr(session.GetUserId(), update); err != nil {
|
||||
log.Errorf("AddAttributeValue err:%v", err)
|
||||
code = pb.ErrorCode_DBError
|
||||
}
|
||||
|
||||
if bPush { //推送玩家账号信息变化消息
|
||||
session.SendMsg(string(this.GetType()), "reschange", _change)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 用户事件变化
|
||||
func (this *User) EventUserChanged(session comm.IUserSession) {
|
||||
ul := new(UserListen)
|
||||
|
Loading…
Reference in New Issue
Block a user