zhengtao 9 mesi fa
parent
commit
ace30e5336

+ 8 - 8
game/game_cluster/internal/mdb/models/player.go

@@ -536,15 +536,9 @@ func (p *Player) SetInviteReward() {
 	key1 := fmt.Sprintf("%v:%v:%v", constant.InviteKey, InvitePlayer, p.UserName)
 	key2 := fmt.Sprintf("%v:%v:%v", constant.InviteKey, InviteVipPlayer, p.UserName)
 
-	freeNum, err := mdb.RDB.Get(context.Background(), key1).Int()
-	if err != nil {
-		return
-	}
+	freeNum, _ := mdb.RDB.Get(context.Background(), key1).Int()
 
-	VipNum, err := mdb.RDB.Get(context.Background(), key2).Int()
-	if err != nil {
-		return
-	}
+	VipNum, _ := mdb.RDB.Get(context.Background(), key2).Int()
 
 	for i := 0; i < freeNum; i++ {
 		addItem = append(addItem, ret2.Reward...)
@@ -553,6 +547,7 @@ func (p *Player) SetInviteReward() {
 			addItem = append(addItem, ret.Reward...)
 			p.SetPlayerRewardLog(SourceInvite, InvitePlayerByLeader, []data.ItemReward{}, []data.ItemReward{}, 2)
 		}
+		mdb.RDB.DecrBy(context.Background(), key1, 1)
 	}
 
 	for i := 0; i < VipNum; i++ {
@@ -562,6 +557,11 @@ func (p *Player) SetInviteReward() {
 			addItem = append(addItem, ret.Reward...)
 			p.SetPlayerRewardLog(SourceInvite, InvitePlayerByLeader, []data.ItemReward{}, []data.ItemReward{}, 2)
 		}
+		mdb.RDB.DecrBy(context.Background(), key2, 1)
+	}
+
+	if (freeNum + VipNum) > 0 {
+		SetRank(constant.RankSourceInvite, p.IsRobot, p.UserName, freeNum+VipNum)
 	}
 
 	if p.InviteReward.IsClaim == 2 {

+ 5 - 0
game/game_cluster/internal/param/param.go

@@ -102,6 +102,11 @@ type GetLevelResp struct {
 	NowInvite  int `json:"nowInvite"`
 }
 
+type ClaimReq struct {
+	Tp int `json:"tp"` //类型 1榜单奖励 2邀请奖励 3成就奖励 4日常奖励
+	Id int `json:"id"`
+}
+
 type PlayerBase struct {
 	UserName      string            `json:"userName"`
 	OpenId        string            `json:"openId"`

+ 6 - 0
game/game_cluster/nodes/center/center/center.go

@@ -3,7 +3,9 @@ package center
 import (
 	"github.com/mhaya"
 	mhayaCron "github.com/mhaya/components/cron"
+	mhayaMongo "github.com/mhaya/components/mongo"
 	"github.com/mhaya/game/game_cluster/internal/data"
+	"github.com/mhaya/game/game_cluster/internal/mdb"
 	"github.com/mhaya/game/game_cluster/nodes/center/module/account"
 	"github.com/mhaya/game/game_cluster/nodes/center/module/ops"
 )
@@ -18,9 +20,13 @@ func Run(profileFilePath, nodeId string) {
 
 	app.Register(mhayaCron.New())
 	app.Register(data.New())
+	// 注册db组件
+	app.Register(mhayaMongo.NewComponent())
+
 	app.AddActors(
 		&account.ActorAccount{},
 		&ops.ActorOps{},
+		&mdb.ActorDB{},
 	)
 
 	app.Startup()

+ 4 - 2
game/game_cluster/nodes/game/game/game.go

@@ -4,12 +4,13 @@ import (
 	"github.com/mhaya"
 	mhayaCron "github.com/mhaya/components/cron"
 	mhayaGops "github.com/mhaya/components/gops"
+	mhayaMongo "github.com/mhaya/components/mongo"
 	mhayaSnowflake "github.com/mhaya/extend/snowflake"
 	cstring "github.com/mhaya/extend/string"
 	mhayaUtils "github.com/mhaya/extend/utils"
 	checkCenter "github.com/mhaya/game/game_cluster/internal/component/check_center"
 	"github.com/mhaya/game/game_cluster/internal/data"
-	"github.com/mhaya/game/game_cluster/nodes/game/db"
+	"github.com/mhaya/game/game_cluster/internal/mdb"
 	"github.com/mhaya/game/game_cluster/nodes/game/module/player"
 )
 
@@ -34,10 +35,11 @@ func Run(profileFilePath, nodeId string) {
 	// 注册检测中心节点组件,确认中心节点启动后,再启动当前节点
 	app.Register(checkCenter.New())
 	// 注册db组件
-	app.Register(db.New())
+	app.Register(mhayaMongo.NewComponent())
 
 	app.AddActors(
 		&player.ActorPlayers{},
+		&mdb.ActorDB{},
 	)
 
 	app.Startup()

+ 21 - 0
game/game_cluster/nodes/game/module/player/claim.go

@@ -0,0 +1,21 @@
+package player
+
+import (
+	"github.com/mhaya/game/game_cluster/internal/code"
+	"github.com/mhaya/game/game_cluster/internal/param"
+)
+
+func (p *actorPlayer) claim(req *param.ClaimReq) (*param.ChangeData, int32) {
+	if !p.isOnline {
+		return nil, code.PlayerNotLogin
+	}
+	var resp param.ChangeData
+	switch req.Tp {
+	case 1:
+	case 2:
+	case 3:
+	case 4:
+	}
+
+	return &resp, code.OK
+}

+ 7 - 0
game/game_cluster/nodes/web/web/web.go

@@ -5,8 +5,10 @@ import (
 	"github.com/mhaya"
 	mhayaCron "github.com/mhaya/components/cron"
 	mhayaGin "github.com/mhaya/components/gin"
+	mhayaMongo "github.com/mhaya/components/mongo"
 	checkCenter "github.com/mhaya/game/game_cluster/internal/component/check_center"
 	"github.com/mhaya/game/game_cluster/internal/data"
+	"github.com/mhaya/game/game_cluster/internal/mdb"
 	"github.com/mhaya/game/game_cluster/nodes/web/controller"
 	"github.com/mhaya/game/game_cluster/nodes/web/sdk"
 )
@@ -26,7 +28,12 @@ func Run(profileFilePath, nodeId string) {
 
 	// 加载http server组件
 	app.Register(httpServerComponent(app.Address()))
+	// 注册db组件
+	app.Register(mhayaMongo.NewComponent())
 
+	app.AddActors(
+		&mdb.ActorDB{},
+	)
 	// 加载sdk逻辑
 	sdk.Init(app)