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)
|
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
|
// heroId 英雄ID
|
||||||
GetHeroByObjID(uid, heroId string) (*pb.DBHero, pb.ErrorCode)
|
GetHeroByObjID(uid, heroId string) (*pb.DBHero, pb.ErrorCode)
|
||||||
@ -64,6 +64,8 @@ type (
|
|||||||
QueryAttributeValue(uid string, attr string) (value int32)
|
QueryAttributeValue(uid string, attr string) (value int32)
|
||||||
//添加/减少属性值 第四个参数控制是否推送给前端
|
//添加/减少属性值 第四个参数控制是否推送给前端
|
||||||
AddAttributeValue(session IUserSession, attr string, add int32, bPush bool) (code pb.ErrorCode)
|
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)
|
EventUserChanged(session IUserSession)
|
||||||
//获取用户expand
|
//获取用户expand
|
||||||
|
@ -112,6 +112,7 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int
|
|||||||
hero = this.initHero(uid, heroCfgId)
|
hero = this.initHero(uid, heroCfgId)
|
||||||
if hero != nil {
|
if hero != nil {
|
||||||
// 添加图鉴
|
// 添加图鉴
|
||||||
|
go func(uid, heroCfgId string) { // 携程处理 图鉴数据
|
||||||
if result, err1 := this.moduleHero.ModuleUser.GetUserExpand(uid); err1 == nil {
|
if result, err1 := this.moduleHero.ModuleUser.GetUserExpand(uid); err1 == nil {
|
||||||
sz := make(map[string]bool, 0)
|
sz := make(map[string]bool, 0)
|
||||||
for k := range result.GetTujian() {
|
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)
|
this.moduleHero.ModuleUser.ChangeUserExpand(uid, initUpdate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}(uid, heroCfgId)
|
||||||
|
|
||||||
hero.SameCount = count
|
hero.SameCount = count
|
||||||
if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil {
|
if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil {
|
||||||
this.moduleHero.Errorf("%v", err)
|
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) {
|
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 items {
|
for heroCfgId, num := range heros {
|
||||||
_, err := this.modelHero.createHeroOverlying(session.GetUserId(), heroCfgId, num)
|
if num == 0 { // 数量为0 不做处理
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
hero, err := this.modelHero.createHeroOverlying(session.GetUserId(), heroCfgId, num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
code = pb.ErrorCode_HeroCreate
|
code = pb.ErrorCode_HeroCreate
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
changeHero = append(changeHero, hero)
|
||||||
|
}
|
||||||
|
|
||||||
|
if bPush && len(changeHero) > 0 { //推送
|
||||||
|
session.SendMsg("hero", "change", &pb.HeroChangePush{List: changeHero})
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -47,7 +47,7 @@ func (this *apiComp) GetUserMailAttachment(session comm.IUserSession, req *pb.Ma
|
|||||||
if code == pb.ErrorCode_Success {
|
if code == pb.ErrorCode_Success {
|
||||||
// 修改状态
|
// 修改状态
|
||||||
this.module.modelMail.MailUpdateMailAttachmentState(req.ObjID)
|
this.module.modelMail.MailUpdateMailAttachmentState(req.ObjID)
|
||||||
mail.Reward = true
|
//mail.Reward = true
|
||||||
//return
|
//return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ func (this *apiComp) ReadMail(session comm.IUserSession, req *pb.MailReadMailReq
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.module.Debugf("read mail %v", mail)
|
this.module.Debugf("read mail %v", mail)
|
||||||
mail.Check = true
|
|
||||||
session.SendMsg(string(this.module.GetType()), "readmail", &pb.MailReadMailResp{Mail: mail})
|
session.SendMsg(string(this.module.GetType()), "readmail", &pb.MailReadMailResp{Mail: mail})
|
||||||
return
|
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) {
|
func (this *ModuleBase) ConsumeRes(session comm.IUserSession, res []*cfg.Game_atn, bPush bool) (code pb.ErrorCode) {
|
||||||
var (
|
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{
|
source := &comm.ModuleCallSource{
|
||||||
Module: string(this.module.GetType()),
|
Module: string(this.module.GetType()),
|
||||||
FuncName: "CheckConsumeRes",
|
FuncName: "CheckConsumeRes",
|
||||||
Describe: "消耗资源",
|
Describe: "消耗资源",
|
||||||
}
|
}
|
||||||
//校验消费资源是否充足
|
// 校验数量
|
||||||
for _, v := range res {
|
for k, v := range attrs {
|
||||||
if v.A == comm.AttrType { //用户属性资源
|
if this.ModuleUser.QueryAttributeValue(session.GetUserId(), k) < -v { // -v 负负得正
|
||||||
if amount = this.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T); amount < v.N {
|
|
||||||
code = pb.ErrorCode_ResNoEnough
|
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.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)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else if v.A == comm.HeroType { //卡片资源
|
for k, v := range items {
|
||||||
// if resID, err = strconv.Atoi(v.T); err != nil {
|
if int32(this.ModuleItems.QueryItemAmount(source, session.GetUserId(), k)) < -v {
|
||||||
// code = pb.ErrorCode_ConfigurationException
|
code = pb.ErrorCode_ResNoEnough
|
||||||
// return
|
this.Errorf("道具不足: A: item, T:%s, N:%d", k, v)
|
||||||
// }
|
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 _, 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)
|
if len(attrs) > 0 {
|
||||||
// this.ModuleHero.ConsumeCard(uid, int32(resID), -1*v.N)
|
code = this.ModuleUser.AddAttributeValues(session, attrs, bPush)
|
||||||
// }
|
if code != pb.ErrorCode_Success {
|
||||||
// } else if v.A == comm.EquipmentType {
|
return
|
||||||
// resID, _ = strconv.Atoi(v.T)
|
}
|
||||||
// equipment.AddNewEquipments(source, uid, resID, -1*v.N)
|
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
|
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) {
|
func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Game_atn, bPush bool) (code pb.ErrorCode) {
|
||||||
var (
|
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{
|
source := &comm.ModuleCallSource{
|
||||||
Module: string(this.module.GetType()),
|
Module: string(this.module.GetType()),
|
||||||
FuncName: "DispenseRes",
|
FuncName: "DispenseRes",
|
||||||
Describe: "发放资源",
|
Describe: "发放资源",
|
||||||
}
|
}
|
||||||
for _, v := range res {
|
for _, v := range res {
|
||||||
this.Debugf("发放资源 DispenseRes:A = %s, T:%s, N:%d", v.A, v.T, v.N)
|
switch v.A {
|
||||||
if v.A == comm.AttrType { //用户属性资源
|
case comm.AttrType:
|
||||||
code = this.ModuleUser.AddAttributeValue(session, v.T, v.N, bPush)
|
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 { //道具资源
|
if len(attrs) > 0 { //用户属性资源
|
||||||
// resID = cast.ToInt(v.T)
|
code = this.ModuleUser.AddAttributeValues(session, attrs, bPush)
|
||||||
// resID, _ = strconv.Atoi(v.T)
|
this.Debugf("发放用户资源: %v", attrs)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
hero = append(hero, _hero)
|
if len(items) > 0 { //道具资源
|
||||||
} else if v.A == comm.EquipmentType {
|
code = this.ModuleItems.AddItems(source, session, items, bPush)
|
||||||
//resID, _ = strconv.Atoi(v.T)
|
this.Debugf("发放道具资源: %v", items)
|
||||||
code = this.ModuleEquipment.AddNewEquipments(source, session, map[string]uint32{v.T: uint32(v.N)}, bPush)
|
|
||||||
}
|
}
|
||||||
|
if len(heros) > 0 { //卡片资源
|
||||||
|
code = this.ModuleHero.CreateRepeatHeros(session, heros, bPush)
|
||||||
|
this.Debugf("发放英雄资源: %v", heros)
|
||||||
}
|
}
|
||||||
if len(hero) > 0 {
|
if len(equips) > 0 {
|
||||||
session.SendMsg("hero", "change", &pb.HeroChangePush{List: hero})
|
code = this.ModuleEquipment.AddNewEquipments(source, session, equips, bPush)
|
||||||
|
this.Debugf("发放装备资源: %v", equips)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -161,6 +161,74 @@ func (this *User) AddAttributeValue(session comm.IUserSession, attr string, add
|
|||||||
return
|
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) {
|
func (this *User) EventUserChanged(session comm.IUserSession) {
|
||||||
ul := new(UserListen)
|
ul := new(UserListen)
|
||||||
|
Loading…
Reference in New Issue
Block a user