mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-03-01 00:35:36 +08:00
1.MongoDB、Redis兼容集群模式
2.离线数据接口化访问
This commit is contained in:
@@ -10,7 +10,7 @@ max_size = 10485760
|
|||||||
url = "mongodb://mongo:27017"
|
url = "mongodb://mongo:27017"
|
||||||
|
|
||||||
[redis]
|
[redis]
|
||||||
addr = "redis:6379"
|
addr = "redis://redis:6379"
|
||||||
password = ""
|
password = ""
|
||||||
|
|
||||||
[mq]
|
[mq]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ max_size = 10485760
|
|||||||
url = "mongodb://mongo:27017"
|
url = "mongodb://mongo:27017"
|
||||||
|
|
||||||
[redis]
|
[redis]
|
||||||
addr = "redis:6379"
|
addr = "redis://redis:6379"
|
||||||
password = ""
|
password = ""
|
||||||
|
|
||||||
[mq]
|
[mq]
|
||||||
|
|||||||
@@ -137,7 +137,6 @@ func (c *Controller) registerRouter() {
|
|||||||
}
|
}
|
||||||
engine.Use(c.authorize())
|
engine.Use(c.authorize())
|
||||||
engine.POST("/gate/token/verify", c.gateTokenVerify)
|
engine.POST("/gate/token/verify", c.gateTokenVerify)
|
||||||
engine.POST("/gate/token/reset", c.gateTokenReset)
|
|
||||||
port := config.GetConfig().HttpPort
|
port := config.GetConfig().HttpPort
|
||||||
addr := ":" + strconv.Itoa(int(port))
|
addr := ":" + strconv.Itoa(int(port))
|
||||||
err := engine.Run(addr)
|
err := engine.Run(addr)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
|
|
||||||
@@ -51,12 +52,7 @@ func (c *Controller) gateTokenVerify(context *gin.Context) {
|
|||||||
verifyFail(account.PlayerID)
|
verifyFail(account.PlayerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if account.ComboTokenUsed {
|
if time.Now().UnixMilli()-int64(account.ComboTokenCreateTime) > time.Minute.Milliseconds()*5 {
|
||||||
verifyFail(account.PlayerID)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "ComboTokenUsed", true)
|
|
||||||
if err != nil {
|
|
||||||
verifyFail(account.PlayerID)
|
verifyFail(account.PlayerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -67,32 +63,3 @@ func (c *Controller) gateTokenVerify(context *gin.Context) {
|
|||||||
PlayerID: account.PlayerID,
|
PlayerID: account.PlayerID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type TokenResetReq struct {
|
|
||||||
PlayerId uint32 `json:"playerId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TokenResetRsp struct {
|
|
||||||
Result bool `json:"result"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Controller) gateTokenReset(context *gin.Context) {
|
|
||||||
req := new(TokenResetReq)
|
|
||||||
err := context.ShouldBindJSON(req)
|
|
||||||
if err != nil {
|
|
||||||
context.JSON(http.StatusOK, &TokenResetRsp{
|
|
||||||
Result: false,
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = c.dao.UpdateAccountFieldByFieldName("PlayerID", req.PlayerId, "ComboTokenUsed", false)
|
|
||||||
if err != nil {
|
|
||||||
context.JSON(http.StatusOK, &TokenResetRsp{
|
|
||||||
Result: false,
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
context.JSON(http.StatusOK, &TokenResetRsp{
|
|
||||||
Result: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
|||||||
// 自动注册
|
// 自动注册
|
||||||
accountId, err := c.dao.GetNextAccountId()
|
accountId, err := c.dao.GetNextAccountId()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("get next account id error: %v", err)
|
||||||
responseData.Retcode = -201
|
responseData.Retcode = -201
|
||||||
responseData.Message = "服务器内部错误:-1"
|
responseData.Message = "服务器内部错误:-1"
|
||||||
context.JSON(http.StatusOK, responseData)
|
context.JSON(http.StatusOK, responseData)
|
||||||
@@ -108,6 +109,7 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
|||||||
}
|
}
|
||||||
playerID, err := c.dao.GetNextYuanShenUid()
|
playerID, err := c.dao.GetNextYuanShenUid()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("get next player id error: %v", err)
|
||||||
responseData.Retcode = -201
|
responseData.Retcode = -201
|
||||||
responseData.Message = "服务器内部错误:-2"
|
responseData.Message = "服务器内部错误:-2"
|
||||||
context.JSON(http.StatusOK, responseData)
|
context.JSON(http.StatusOK, responseData)
|
||||||
@@ -125,6 +127,7 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
|||||||
}
|
}
|
||||||
_, err = c.dao.InsertAccount(regAccount)
|
_, err = c.dao.InsertAccount(regAccount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("insert account error: %v", err)
|
||||||
responseData.Retcode = -201
|
responseData.Retcode = -201
|
||||||
responseData.Message = "服务器内部错误:-3"
|
responseData.Message = "服务器内部错误:-3"
|
||||||
context.JSON(http.StatusOK, responseData)
|
context.JSON(http.StatusOK, responseData)
|
||||||
@@ -142,6 +145,7 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
|||||||
account.Token = base64.StdEncoding.EncodeToString(random.GetRandomByte(24))
|
account.Token = base64.StdEncoding.EncodeToString(random.GetRandomByte(24))
|
||||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "Token", account.Token)
|
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "Token", account.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("update account token error: %v", err)
|
||||||
responseData.Retcode = -201
|
responseData.Retcode = -201
|
||||||
responseData.Message = "服务器内部错误:-4"
|
responseData.Message = "服务器内部错误:-4"
|
||||||
context.JSON(http.StatusOK, responseData)
|
context.JSON(http.StatusOK, responseData)
|
||||||
@@ -149,6 +153,7 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
|||||||
}
|
}
|
||||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "TokenCreateTime", time.Now().UnixMilli())
|
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "TokenCreateTime", time.Now().UnixMilli())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("update account token time error: %v", err)
|
||||||
responseData.Retcode = -201
|
responseData.Retcode = -201
|
||||||
responseData.Message = "服务器内部错误:-5"
|
responseData.Message = "服务器内部错误:-5"
|
||||||
context.JSON(http.StatusOK, responseData)
|
context.JSON(http.StatusOK, responseData)
|
||||||
@@ -233,13 +238,15 @@ func (c *Controller) v2Login(context *gin.Context) {
|
|||||||
account.ComboToken = random.GetRandomByteHexStr(20)
|
account.ComboToken = random.GetRandomByteHexStr(20)
|
||||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "ComboToken", account.ComboToken)
|
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "ComboToken", account.ComboToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("update combo token error: %v", err)
|
||||||
responseData.Retcode = -201
|
responseData.Retcode = -201
|
||||||
responseData.Message = "服务器内部错误:-1"
|
responseData.Message = "服务器内部错误:-1"
|
||||||
context.JSON(http.StatusOK, responseData)
|
context.JSON(http.StatusOK, responseData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "ComboTokenUsed", false)
|
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "ComboTokenCreateTime", time.Now().UnixMilli())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("update combo token time error: %v", err)
|
||||||
responseData.Retcode = -201
|
responseData.Retcode = -201
|
||||||
responseData.Message = "服务器内部错误:-2"
|
responseData.Message = "服务器内部错误:-2"
|
||||||
context.JSON(http.StatusOK, responseData)
|
context.JSON(http.StatusOK, responseData)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (d *Dao) InsertAccount(account *model.Account) (primitive.ObjectID, error)
|
|||||||
|
|
||||||
func (d *Dao) UpdateAccountFieldByFieldName(fieldName string, fieldValue any, fieldUpdateName string, fieldUpdateValue any) (int64, error) {
|
func (d *Dao) UpdateAccountFieldByFieldName(fieldName string, fieldValue any, fieldUpdateName string, fieldUpdateValue any) (int64, error) {
|
||||||
db := d.db.Collection("account")
|
db := d.db.Collection("account")
|
||||||
updateCount, err := db.UpdateOne(
|
updateCount, err := db.UpdateMany(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
bson.D{
|
bson.D{
|
||||||
{fieldName, fieldValue},
|
{fieldName, fieldValue},
|
||||||
|
|||||||
@@ -22,7 +22,13 @@ func (d *Dao) GetNextYuanShenUid() (uint32, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) redisInc(keyName string) (uint32, error) {
|
func (d *Dao) redisInc(keyName string) (uint32, error) {
|
||||||
exist, err := d.redis.Exists(context.TODO(), keyName).Result()
|
var exist int64 = 0
|
||||||
|
var err error = nil
|
||||||
|
if d.redisCluster != nil {
|
||||||
|
exist, err = d.redisCluster.Exists(context.TODO(), keyName).Result()
|
||||||
|
} else {
|
||||||
|
exist, err = d.redis.Exists(context.TODO(), keyName).Result()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@@ -33,12 +39,22 @@ func (d *Dao) redisInc(keyName string) (uint32, error) {
|
|||||||
} else if keyName == RedisPlayerKeyPrefix+":"+YuanShenUidRedisKey {
|
} else if keyName == RedisPlayerKeyPrefix+":"+YuanShenUidRedisKey {
|
||||||
value = YuanShenUidBegin
|
value = YuanShenUidBegin
|
||||||
}
|
}
|
||||||
err := d.redis.Set(context.TODO(), keyName, value, 0).Err()
|
var err error = nil
|
||||||
|
if d.redisCluster != nil {
|
||||||
|
err = d.redisCluster.Set(context.TODO(), keyName, value, 0).Err()
|
||||||
|
} else {
|
||||||
|
err = d.redis.Set(context.TODO(), keyName, value, 0).Err()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id, err := d.redis.Incr(context.TODO(), keyName).Result()
|
var id int64 = 0
|
||||||
|
if d.redisCluster != nil {
|
||||||
|
id, err = d.redisCluster.Incr(context.TODO(), keyName).Result()
|
||||||
|
} else {
|
||||||
|
id, err = d.redis.Incr(context.TODO(), keyName).Result()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package dao
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"hk4e/common/config"
|
"hk4e/common/config"
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
@@ -13,13 +14,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Dao struct {
|
type Dao struct {
|
||||||
mongo *mongo.Client
|
mongo *mongo.Client
|
||||||
db *mongo.Database
|
db *mongo.Database
|
||||||
redis *redis.Client
|
redis *redis.Client
|
||||||
|
redisCluster *redis.ClusterClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDao() (r *Dao) {
|
func NewDao() (r *Dao) {
|
||||||
r = new(Dao)
|
r = new(Dao)
|
||||||
|
|
||||||
clientOptions := options.Client().ApplyURI(config.GetConfig().Database.Url).SetMinPoolSize(10).SetMaxPoolSize(100)
|
clientOptions := options.Client().ApplyURI(config.GetConfig().Database.Url).SetMinPoolSize(10).SetMaxPoolSize(100)
|
||||||
client, err := mongo.Connect(context.TODO(), clientOptions)
|
client, err := mongo.Connect(context.TODO(), clientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -33,18 +36,37 @@ func NewDao() (r *Dao) {
|
|||||||
}
|
}
|
||||||
r.mongo = client
|
r.mongo = client
|
||||||
r.db = client.Database("dispatch_hk4e")
|
r.db = client.Database("dispatch_hk4e")
|
||||||
r.redis = redis.NewClient(&redis.Options{
|
|
||||||
Addr: config.GetConfig().Redis.Addr,
|
r.redis = nil
|
||||||
Password: config.GetConfig().Redis.Password,
|
r.redisCluster = nil
|
||||||
DB: 0,
|
redisAddr := strings.ReplaceAll(config.GetConfig().Redis.Addr, "redis://", "")
|
||||||
PoolSize: 10,
|
if strings.Contains(redisAddr, ",") {
|
||||||
MinIdleConns: 1,
|
redisAddrList := strings.Split(redisAddr, ",")
|
||||||
})
|
r.redisCluster = redis.NewClusterClient(&redis.ClusterOptions{
|
||||||
err = r.redis.Ping(context.TODO()).Err()
|
Addrs: redisAddrList,
|
||||||
|
Password: config.GetConfig().Redis.Password,
|
||||||
|
PoolSize: 10,
|
||||||
|
MinIdleConns: 1,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
r.redis = redis.NewClient(&redis.Options{
|
||||||
|
Addr: redisAddr,
|
||||||
|
Password: config.GetConfig().Redis.Password,
|
||||||
|
DB: 0,
|
||||||
|
PoolSize: 10,
|
||||||
|
MinIdleConns: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if r.redisCluster != nil {
|
||||||
|
err = r.redisCluster.Ping(context.TODO()).Err()
|
||||||
|
} else {
|
||||||
|
err = r.redis.Ping(context.TODO()).Err()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("redis ping error: %v", err)
|
logger.Error("redis ping error: %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +75,11 @@ func (d *Dao) CloseDao() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("mongo close error: %v", err)
|
logger.Error("mongo close error: %v", err)
|
||||||
}
|
}
|
||||||
err = d.redis.Close()
|
if d.redisCluster != nil {
|
||||||
|
err = d.redisCluster.Close()
|
||||||
|
} else {
|
||||||
|
err = d.redis.Close()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("redis close error: %v", err)
|
logger.Error("redis close error: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,15 @@ package model
|
|||||||
import "go.mongodb.org/mongo-driver/bson/primitive"
|
import "go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||||
AccountID uint32 `bson:"AccountID"`
|
AccountID uint32 `bson:"AccountID"`
|
||||||
PlayerID uint32 `bson:"PlayerID"`
|
PlayerID uint32 `bson:"PlayerID"`
|
||||||
Username string `bson:"Username"`
|
Username string `bson:"Username"`
|
||||||
Password string `bson:"Password"`
|
Password string `bson:"Password"`
|
||||||
Token string `bson:"Token"`
|
Token string `bson:"Token"`
|
||||||
TokenCreateTime uint64 `bson:"TokenCreateTime"` // 毫秒时间戳
|
TokenCreateTime uint64 `bson:"TokenCreateTime"` // 毫秒时间戳
|
||||||
ComboToken string `bson:"ComboToken"`
|
ComboToken string `bson:"ComboToken"`
|
||||||
ComboTokenUsed bool `bson:"ComboTokenUsed"`
|
ComboTokenCreateTime uint64 `bson:"ComboTokenCreateTime"` // 毫秒时间戳
|
||||||
Forbid bool `bson:"Forbid"`
|
Forbid bool `bson:"Forbid"`
|
||||||
ForbidEndTime uint32 `bson:"ForbidEndTime"` // 秒时间戳
|
ForbidEndTime uint32 `bson:"ForbidEndTime"` // 秒时间戳
|
||||||
}
|
}
|
||||||
|
|||||||
47
docker/3rd/mongo/mongo_cluster/create_cluster.sh
Executable file
47
docker/3rd/mongo/mongo_cluster/create_cluster.sh
Executable file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# shard1
|
||||||
|
mongo --host 192.168.199.233 --port 27118 <<EOF
|
||||||
|
rs.initiate({_id: "shard1", members: [{_id: 0, host: "mongo_shard1:27018"}]})
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# shard2
|
||||||
|
mongo --host 192.168.199.233 --port 27218 <<EOF
|
||||||
|
rs.initiate({_id: "shard2", members: [{_id: 0, host: "mongo_shard2:27018"}]})
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# shard3
|
||||||
|
mongo --host 192.168.199.233 --port 27318 <<EOF
|
||||||
|
rs.initiate({_id: "shard3", members: [{_id: 0, host: "mongo_shard3:27018"}]})
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# config1
|
||||||
|
mongo --host 192.168.199.233 --port 27119 <<EOF
|
||||||
|
rs.initiate({_id: "config", configsvr: true, members: [{_id: 0, host: "mongo_config1:27019"}, {_id: 1, host: "mongo_config2:27019"}, {_id: 2, host: "mongo_config3:27019"}]})
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
# mongos1
|
||||||
|
mongo --host 192.168.199.233 --port 27117 <<EOF
|
||||||
|
sh.addShard("shard1/mongo_shard1:27018")
|
||||||
|
sh.addShard("shard2/mongo_shard2:27018")
|
||||||
|
sh.addShard("shard3/mongo_shard3:27018")
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
mongo --host 192.168.199.233 --port 27117 <<EOF
|
||||||
|
sh.enableSharding("dispatch_hk4e")
|
||||||
|
sh.shardCollection("dispatch_hk4e.account", {"AccountID": "hashed"})
|
||||||
|
sh.enableBalancing("dispatch_hk4e.account")
|
||||||
|
sh.shardCollection("dispatch_hk4e.client_log", {"_id": "hashed"})
|
||||||
|
sh.enableBalancing("dispatch_hk4e.client_log")
|
||||||
|
sh.enableSharding("gs_hk4e")
|
||||||
|
sh.shardCollection("gs_hk4e.player", {"PlayerID": "hashed"})
|
||||||
|
sh.enableBalancing("gs_hk4e.player")
|
||||||
|
sh.shardCollection("gs_hk4e.chat_msg", {"Uid": "hashed"})
|
||||||
|
sh.enableBalancing("gs_hk4e.chat_msg")
|
||||||
|
sh.startBalancer()
|
||||||
|
db.adminCommand("flushRouterConfig")
|
||||||
|
EOF
|
||||||
196
docker/3rd/mongo/mongo_cluster/docker-compose.yaml
Normal file
196
docker/3rd/mongo/mongo_cluster/docker-compose.yaml
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
mongo_shard1:
|
||||||
|
restart: always
|
||||||
|
image: mongo:5.0.5
|
||||||
|
container_name: mongo_shard1
|
||||||
|
ports:
|
||||||
|
- "27118:27018/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./data/shard1:/data/db
|
||||||
|
command: mongod --shardsvr --replSet shard1
|
||||||
|
privileged: true
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '4.00'
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
mongo_shard2:
|
||||||
|
restart: always
|
||||||
|
image: mongo:5.0.5
|
||||||
|
container_name: mongo_shard2
|
||||||
|
ports:
|
||||||
|
- "27218:27018/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./data/shard2:/data/db
|
||||||
|
command: mongod --shardsvr --replSet shard2
|
||||||
|
privileged: true
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '4.00'
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
mongo_shard3:
|
||||||
|
restart: always
|
||||||
|
image: mongo:5.0.5
|
||||||
|
container_name: mongo_shard3
|
||||||
|
ports:
|
||||||
|
- "27318:27018/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./data/shard3:/data/db
|
||||||
|
command: mongod --shardsvr --replSet shard3
|
||||||
|
privileged: true
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '4.00'
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
mongo_config1:
|
||||||
|
restart: always
|
||||||
|
image: mongo:5.0.5
|
||||||
|
container_name: mongo_config1
|
||||||
|
ports:
|
||||||
|
- "27119:27019/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./data/config1:/data/configdb
|
||||||
|
command: mongod --configsvr --replSet config
|
||||||
|
depends_on:
|
||||||
|
- mongo_shard1
|
||||||
|
- mongo_shard2
|
||||||
|
- mongo_shard3
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 256M
|
||||||
|
|
||||||
|
mongo_config2:
|
||||||
|
restart: always
|
||||||
|
image: mongo:5.0.5
|
||||||
|
container_name: mongo_config2
|
||||||
|
ports:
|
||||||
|
- "27219:27019/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./data/config2:/data/configdb
|
||||||
|
command: mongod --configsvr --replSet config
|
||||||
|
depends_on:
|
||||||
|
- mongo_shard1
|
||||||
|
- mongo_shard2
|
||||||
|
- mongo_shard3
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 256M
|
||||||
|
|
||||||
|
mongo_config3:
|
||||||
|
restart: always
|
||||||
|
image: mongo:5.0.5
|
||||||
|
container_name: mongo_config3
|
||||||
|
ports:
|
||||||
|
- "27319:27019/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./data/config3:/data/configdb
|
||||||
|
command: mongod --configsvr --replSet config
|
||||||
|
depends_on:
|
||||||
|
- mongo_shard1
|
||||||
|
- mongo_shard2
|
||||||
|
- mongo_shard3
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 256M
|
||||||
|
|
||||||
|
mongo_mongos1:
|
||||||
|
restart: always
|
||||||
|
image: mongo:5.0.5
|
||||||
|
container_name: mongo_mongos1
|
||||||
|
ports:
|
||||||
|
- "27117:27017/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
command: mongos --bind_ip_all --configdb config/mongo_config1:27019,mongo_config2:27019,mongo_config3:27019
|
||||||
|
depends_on:
|
||||||
|
- mongo_config1
|
||||||
|
- mongo_config2
|
||||||
|
- mongo_config3
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '2.00'
|
||||||
|
memory: 128M
|
||||||
|
|
||||||
|
mongo_mongos2:
|
||||||
|
restart: always
|
||||||
|
image: mongo:5.0.5
|
||||||
|
container_name: mongo_mongos2
|
||||||
|
ports:
|
||||||
|
- "27217:27017/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
command: mongos --bind_ip_all --configdb config/mongo_config1:27019,mongo_config2:27019,mongo_config3:27019
|
||||||
|
depends_on:
|
||||||
|
- mongo_config1
|
||||||
|
- mongo_config2
|
||||||
|
- mongo_config3
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '2.00'
|
||||||
|
memory: 128M
|
||||||
|
|
||||||
|
mongo_mongos3:
|
||||||
|
restart: always
|
||||||
|
image: mongo:5.0.5
|
||||||
|
container_name: mongo_mongos3
|
||||||
|
ports:
|
||||||
|
- "27317:27017/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
command: mongos --bind_ip_all --configdb config/mongo_config1:27019,mongo_config2:27019,mongo_config3:27019
|
||||||
|
depends_on:
|
||||||
|
- mongo_config1
|
||||||
|
- mongo_config2
|
||||||
|
- mongo_config3
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '2.00'
|
||||||
|
memory: 128M
|
||||||
19
docker/3rd/mongo/mongo_strndalone/docker-compose.yaml
Normal file
19
docker/3rd/mongo/mongo_strndalone/docker-compose.yaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
mongo:
|
||||||
|
restart: always
|
||||||
|
image: mongo:5.0.5
|
||||||
|
container_name: mongo
|
||||||
|
ports:
|
||||||
|
- "27017:27017/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./data:/data/db
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '4.00'
|
||||||
|
memory: 512M
|
||||||
23
docker/3rd/nats/nats_cluster/conf/nats1/nats-server.conf
Normal file
23
docker/3rd/nats/nats_cluster/conf/nats1/nats-server.conf
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
http: 8222
|
||||||
|
|
||||||
|
server_name: nats1
|
||||||
|
listen: 4222
|
||||||
|
|
||||||
|
max_payload: 5120KB
|
||||||
|
|
||||||
|
cluster {
|
||||||
|
name: nats-cluster
|
||||||
|
listen: 6222
|
||||||
|
routes: [
|
||||||
|
nats-route://nats2:6222
|
||||||
|
nats-route://nats3:6222
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
jetstream: enable
|
||||||
|
|
||||||
|
jetstream {
|
||||||
|
store_dir: /nats/storage
|
||||||
|
max_mem: 1G
|
||||||
|
max_file: 10G
|
||||||
|
}
|
||||||
23
docker/3rd/nats/nats_cluster/conf/nats2/nats-server.conf
Normal file
23
docker/3rd/nats/nats_cluster/conf/nats2/nats-server.conf
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
http: 8222
|
||||||
|
|
||||||
|
server_name: nats2
|
||||||
|
listen: 4222
|
||||||
|
|
||||||
|
max_payload: 5120KB
|
||||||
|
|
||||||
|
cluster {
|
||||||
|
name: nats-cluster
|
||||||
|
listen: 6222
|
||||||
|
routes: [
|
||||||
|
nats-route://nats1:6222
|
||||||
|
nats-route://nats3:6222
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
jetstream: enable
|
||||||
|
|
||||||
|
jetstream {
|
||||||
|
store_dir: /nats/storage
|
||||||
|
max_mem: 1G
|
||||||
|
max_file: 10G
|
||||||
|
}
|
||||||
23
docker/3rd/nats/nats_cluster/conf/nats3/nats-server.conf
Normal file
23
docker/3rd/nats/nats_cluster/conf/nats3/nats-server.conf
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
http: 8222
|
||||||
|
|
||||||
|
server_name: nats3
|
||||||
|
listen: 4222
|
||||||
|
|
||||||
|
max_payload: 5120KB
|
||||||
|
|
||||||
|
cluster {
|
||||||
|
name: nats-cluster
|
||||||
|
listen: 6222
|
||||||
|
routes: [
|
||||||
|
nats-route://nats1:6222
|
||||||
|
nats-route://nats2:6222
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
jetstream: enable
|
||||||
|
|
||||||
|
jetstream {
|
||||||
|
store_dir: /nats/storage
|
||||||
|
max_mem: 1G
|
||||||
|
max_file: 10G
|
||||||
|
}
|
||||||
61
docker/3rd/nats/nats_cluster/docker-compose.yaml
Normal file
61
docker/3rd/nats/nats_cluster/docker-compose.yaml
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
nats1:
|
||||||
|
restart: always
|
||||||
|
image: nats:2.7.3
|
||||||
|
container_name: nats1
|
||||||
|
ports:
|
||||||
|
- "4222:4222/tcp"
|
||||||
|
- "8222:8222/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./conf/nats1/nats-server.conf:/nats-server.conf
|
||||||
|
- ./data/nats1:/nats/storage
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
nats2:
|
||||||
|
restart: always
|
||||||
|
image: nats:2.7.3
|
||||||
|
container_name: nats2
|
||||||
|
ports:
|
||||||
|
- "4223:4222/tcp"
|
||||||
|
- "8223:8222/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./conf/nats2/nats-server.conf:/nats-server.conf
|
||||||
|
- ./data/nats2:/nats/storage
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
nats3:
|
||||||
|
restart: always
|
||||||
|
image: nats:2.7.3
|
||||||
|
container_name: nats3
|
||||||
|
ports:
|
||||||
|
- "4224:4222/tcp"
|
||||||
|
- "8224:8222/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./conf/nats3/nats-server.conf:/nats-server.conf
|
||||||
|
- ./data/nats3:/nats/storage
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
13
docker/3rd/nats/nats_strndalone/conf/nats-server.conf
Normal file
13
docker/3rd/nats/nats_strndalone/conf/nats-server.conf
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
http: 8222
|
||||||
|
|
||||||
|
server_name: nats
|
||||||
|
listen: 4222
|
||||||
|
|
||||||
|
max_payload: 5120KB
|
||||||
|
|
||||||
|
cluster {
|
||||||
|
name: nats-cluster
|
||||||
|
listen: 6222
|
||||||
|
routes: [
|
||||||
|
]
|
||||||
|
}
|
||||||
21
docker/3rd/nats/nats_strndalone/docker-compose.yaml
Normal file
21
docker/3rd/nats/nats_strndalone/docker-compose.yaml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
nats:
|
||||||
|
restart: always
|
||||||
|
image: nats:2.7.3
|
||||||
|
container_name: nats
|
||||||
|
ports:
|
||||||
|
- "4224:4222/tcp"
|
||||||
|
- "8224:8222/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./conf/nats-server.conf:/nats-server.conf
|
||||||
|
- ./data:/nats/storage
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
12
docker/3rd/redis/redis_cluster/conf/redis1/redis.conf
Normal file
12
docker/3rd/redis/redis_cluster/conf/redis1/redis.conf
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
port 6371
|
||||||
|
requirepass 123456
|
||||||
|
masterauth 123456
|
||||||
|
protected-mode no
|
||||||
|
daemonize no
|
||||||
|
appendonly yes
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file nodes.conf
|
||||||
|
cluster-node-timeout 15000
|
||||||
|
cluster-announce-ip 192.168.199.233
|
||||||
|
cluster-announce-port 6371
|
||||||
|
cluster-announce-bus-port 16371
|
||||||
12
docker/3rd/redis/redis_cluster/conf/redis2/redis.conf
Normal file
12
docker/3rd/redis/redis_cluster/conf/redis2/redis.conf
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
port 6372
|
||||||
|
requirepass 123456
|
||||||
|
masterauth 123456
|
||||||
|
protected-mode no
|
||||||
|
daemonize no
|
||||||
|
appendonly yes
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file nodes.conf
|
||||||
|
cluster-node-timeout 15000
|
||||||
|
cluster-announce-ip 192.168.199.233
|
||||||
|
cluster-announce-port 6372
|
||||||
|
cluster-announce-bus-port 16372
|
||||||
12
docker/3rd/redis/redis_cluster/conf/redis3/redis.conf
Normal file
12
docker/3rd/redis/redis_cluster/conf/redis3/redis.conf
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
port 6373
|
||||||
|
requirepass 123456
|
||||||
|
masterauth 123456
|
||||||
|
protected-mode no
|
||||||
|
daemonize no
|
||||||
|
appendonly yes
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file nodes.conf
|
||||||
|
cluster-node-timeout 15000
|
||||||
|
cluster-announce-ip 192.168.199.233
|
||||||
|
cluster-announce-port 6373
|
||||||
|
cluster-announce-bus-port 16373
|
||||||
12
docker/3rd/redis/redis_cluster/conf/redis4/redis.conf
Normal file
12
docker/3rd/redis/redis_cluster/conf/redis4/redis.conf
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
port 6374
|
||||||
|
requirepass 123456
|
||||||
|
masterauth 123456
|
||||||
|
protected-mode no
|
||||||
|
daemonize no
|
||||||
|
appendonly yes
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file nodes.conf
|
||||||
|
cluster-node-timeout 15000
|
||||||
|
cluster-announce-ip 192.168.199.233
|
||||||
|
cluster-announce-port 6374
|
||||||
|
cluster-announce-bus-port 16374
|
||||||
12
docker/3rd/redis/redis_cluster/conf/redis5/redis.conf
Normal file
12
docker/3rd/redis/redis_cluster/conf/redis5/redis.conf
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
port 6375
|
||||||
|
requirepass 123456
|
||||||
|
masterauth 123456
|
||||||
|
protected-mode no
|
||||||
|
daemonize no
|
||||||
|
appendonly yes
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file nodes.conf
|
||||||
|
cluster-node-timeout 15000
|
||||||
|
cluster-announce-ip 192.168.199.233
|
||||||
|
cluster-announce-port 6375
|
||||||
|
cluster-announce-bus-port 16375
|
||||||
12
docker/3rd/redis/redis_cluster/conf/redis6/redis.conf
Normal file
12
docker/3rd/redis/redis_cluster/conf/redis6/redis.conf
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
port 6376
|
||||||
|
requirepass 123456
|
||||||
|
masterauth 123456
|
||||||
|
protected-mode no
|
||||||
|
daemonize no
|
||||||
|
appendonly yes
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file nodes.conf
|
||||||
|
cluster-node-timeout 15000
|
||||||
|
cluster-announce-ip 192.168.199.233
|
||||||
|
cluster-announce-port 6376
|
||||||
|
cluster-announce-bus-port 16376
|
||||||
10
docker/3rd/redis/redis_cluster/create_cluster.sh
Executable file
10
docker/3rd/redis/redis_cluster/create_cluster.sh
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
redis-cli -a 123456 --cluster create \
|
||||||
|
192.168.199.233:6371 \
|
||||||
|
192.168.199.233:6372 \
|
||||||
|
192.168.199.233:6373 \
|
||||||
|
192.168.199.233:6374 \
|
||||||
|
192.168.199.233:6375 \
|
||||||
|
192.168.199.233:6376 \
|
||||||
|
--cluster-replicas 1
|
||||||
127
docker/3rd/redis/redis_cluster/docker-compose.yaml
Normal file
127
docker/3rd/redis/redis_cluster/docker-compose.yaml
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
redis1:
|
||||||
|
restart: always
|
||||||
|
image: redis:4
|
||||||
|
container_name: redis1
|
||||||
|
ports:
|
||||||
|
- "6371:6371/tcp"
|
||||||
|
- "16371:16371/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./conf/redis1/redis.conf:/redis/redis.conf
|
||||||
|
- ./data/redis1:/data
|
||||||
|
command: redis-server /redis/redis.conf
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
redis2:
|
||||||
|
restart: always
|
||||||
|
image: redis:4
|
||||||
|
container_name: redis2
|
||||||
|
ports:
|
||||||
|
- "6372:6372/tcp"
|
||||||
|
- "16372:16372/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./conf/redis2/redis.conf:/redis/redis.conf
|
||||||
|
- ./data/redis2:/data
|
||||||
|
command: redis-server /redis/redis.conf
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
redis3:
|
||||||
|
restart: always
|
||||||
|
image: redis:4
|
||||||
|
container_name: redis3
|
||||||
|
ports:
|
||||||
|
- "6373:6373/tcp"
|
||||||
|
- "16373:16373/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./conf/redis3/redis.conf:/redis/redis.conf
|
||||||
|
- ./data/redis3:/data
|
||||||
|
command: redis-server /redis/redis.conf
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
redis4:
|
||||||
|
restart: always
|
||||||
|
image: redis:4
|
||||||
|
container_name: redis4
|
||||||
|
ports:
|
||||||
|
- "6374:6374/tcp"
|
||||||
|
- "16374:16374/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./conf/redis4/redis.conf:/redis/redis.conf
|
||||||
|
- ./data/redis4:/data
|
||||||
|
command: redis-server /redis/redis.conf
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
redis5:
|
||||||
|
restart: always
|
||||||
|
image: redis:4
|
||||||
|
container_name: redis5
|
||||||
|
ports:
|
||||||
|
- "6375:6375/tcp"
|
||||||
|
- "16375:16375/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./conf/redis5/redis.conf:/redis/redis.conf
|
||||||
|
- ./data/redis5:/data
|
||||||
|
command: redis-server /redis/redis.conf
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
redis6:
|
||||||
|
restart: always
|
||||||
|
image: redis:4
|
||||||
|
container_name: redis6
|
||||||
|
ports:
|
||||||
|
- "6376:6376/tcp"
|
||||||
|
- "16376:16376/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./conf/redis6/redis.conf:/redis/redis.conf
|
||||||
|
- ./data/redis6:/data
|
||||||
|
command: redis-server /redis/redis.conf
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
20
docker/3rd/redis/redis_strndalone/docker-compose.yaml
Normal file
20
docker/3rd/redis/redis_strndalone/docker-compose.yaml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
redis:
|
||||||
|
restart: always
|
||||||
|
image: redis:4
|
||||||
|
container_name: redis
|
||||||
|
ports:
|
||||||
|
- "6379:6379/tcp"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime
|
||||||
|
- /etc/timezone:/etc/timezone
|
||||||
|
- ./data:/data
|
||||||
|
command: redis-server --requirepass "123456" --save 60 1
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '1.00'
|
||||||
|
memory: 512M
|
||||||
@@ -189,30 +189,6 @@ func (k *KcpConnectManager) sendMsgHandle() {
|
|||||||
EventId: mq.ServerAppidBindNotify,
|
EventId: mq.ServerAppidBindNotify,
|
||||||
ServerMsg: serverMsg,
|
ServerMsg: serverMsg,
|
||||||
})
|
})
|
||||||
} else if protoMsg.CmdId == cmd.ClientReconnectNotify {
|
|
||||||
tokenResetRsp, err := httpclient.PostJson[controller.TokenResetRsp](
|
|
||||||
config.GetConfig().Hk4e.LoginSdkUrl+"/gate/token/reset?key=flswld",
|
|
||||||
&controller.TokenResetReq{
|
|
||||||
PlayerId: session.userId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logger.Error("reset token error: %v", err)
|
|
||||||
k.kcpEventInput <- &KcpEvent{
|
|
||||||
ConvId: protoMsg.ConvId,
|
|
||||||
EventId: KcpConnForceClose,
|
|
||||||
EventMessage: uint32(kcp.EnetServerKick),
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !tokenResetRsp.Result {
|
|
||||||
logger.Error("reset token fail")
|
|
||||||
k.kcpEventInput <- &KcpEvent{
|
|
||||||
ConvId: protoMsg.ConvId,
|
|
||||||
EventId: KcpConnForceClose,
|
|
||||||
EventMessage: uint32(kcp.EnetServerKick),
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
kcpRawSendChan <- protoMsg
|
kcpRawSendChan <- protoMsg
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package dao
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"hk4e/common/config"
|
"hk4e/common/config"
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
@@ -13,13 +14,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Dao struct {
|
type Dao struct {
|
||||||
mongo *mongo.Client
|
mongo *mongo.Client
|
||||||
db *mongo.Database
|
db *mongo.Database
|
||||||
redis *redis.Client
|
redis *redis.Client
|
||||||
|
redisCluster *redis.ClusterClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDao() (r *Dao, err error) {
|
func NewDao() (r *Dao, err error) {
|
||||||
r = new(Dao)
|
r = new(Dao)
|
||||||
|
|
||||||
clientOptions := options.Client().ApplyURI(config.GetConfig().Database.Url).SetMinPoolSize(1).SetMaxPoolSize(10)
|
clientOptions := options.Client().ApplyURI(config.GetConfig().Database.Url).SetMinPoolSize(1).SetMaxPoolSize(10)
|
||||||
client, err := mongo.Connect(context.TODO(), clientOptions)
|
client, err := mongo.Connect(context.TODO(), clientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -33,18 +36,37 @@ func NewDao() (r *Dao, err error) {
|
|||||||
}
|
}
|
||||||
r.mongo = client
|
r.mongo = client
|
||||||
r.db = client.Database("gs_hk4e")
|
r.db = client.Database("gs_hk4e")
|
||||||
r.redis = redis.NewClient(&redis.Options{
|
|
||||||
Addr: config.GetConfig().Redis.Addr,
|
r.redis = nil
|
||||||
Password: config.GetConfig().Redis.Password,
|
r.redisCluster = nil
|
||||||
DB: 0,
|
redisAddr := strings.ReplaceAll(config.GetConfig().Redis.Addr, "redis://", "")
|
||||||
PoolSize: 10,
|
if strings.Contains(redisAddr, ",") {
|
||||||
MinIdleConns: 1,
|
redisAddrList := strings.Split(redisAddr, ",")
|
||||||
})
|
r.redisCluster = redis.NewClusterClient(&redis.ClusterOptions{
|
||||||
err = r.redis.Ping(context.TODO()).Err()
|
Addrs: redisAddrList,
|
||||||
|
Password: config.GetConfig().Redis.Password,
|
||||||
|
PoolSize: 10,
|
||||||
|
MinIdleConns: 1,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
r.redis = redis.NewClient(&redis.Options{
|
||||||
|
Addr: redisAddr,
|
||||||
|
Password: config.GetConfig().Redis.Password,
|
||||||
|
DB: 0,
|
||||||
|
PoolSize: 10,
|
||||||
|
MinIdleConns: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if r.redisCluster != nil {
|
||||||
|
err = r.redisCluster.Ping(context.TODO()).Err()
|
||||||
|
} else {
|
||||||
|
err = r.redis.Ping(context.TODO()).Err()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("redis ping error: %v", err)
|
logger.Error("redis ping error: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +75,11 @@ func (d *Dao) CloseDao() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("mongo close error: %v", err)
|
logger.Error("mongo close error: %v", err)
|
||||||
}
|
}
|
||||||
err = d.redis.Close()
|
if d.redisCluster != nil {
|
||||||
|
err = d.redisCluster.Close()
|
||||||
|
} else {
|
||||||
|
err = d.redis.Close()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("redis close error: %v", err)
|
logger.Error("redis close error: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ func (d *Dao) DeleteChatMsgList(idList []primitive.ObjectID) error {
|
|||||||
|
|
||||||
func (d *Dao) UpdatePlayer(player *model.Player) error {
|
func (d *Dao) UpdatePlayer(player *model.Player) error {
|
||||||
db := d.db.Collection("player")
|
db := d.db.Collection("player")
|
||||||
_, err := db.UpdateOne(
|
_, err := db.UpdateMany(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
bson.D{{"PlayerID", player.PlayerID}},
|
bson.D{{"PlayerID", player.PlayerID}},
|
||||||
bson.D{{"$set", player}},
|
bson.D{{"$set", player}},
|
||||||
@@ -129,7 +129,7 @@ func (d *Dao) UpdatePlayer(player *model.Player) error {
|
|||||||
|
|
||||||
func (d *Dao) UpdateChatMsg(chatMsg *model.ChatMsg) error {
|
func (d *Dao) UpdateChatMsg(chatMsg *model.ChatMsg) error {
|
||||||
db := d.db.Collection("chat_msg")
|
db := d.db.Collection("chat_msg")
|
||||||
_, err := db.UpdateOne(
|
_, err := db.UpdateMany(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
bson.D{{"_id", chatMsg.ID}},
|
bson.D{{"_id", chatMsg.ID}},
|
||||||
bson.D{{"$set", chatMsg}},
|
bson.D{{"$set", chatMsg}},
|
||||||
@@ -147,7 +147,7 @@ func (d *Dao) UpdatePlayerList(playerList []*model.Player) error {
|
|||||||
db := d.db.Collection("player")
|
db := d.db.Collection("player")
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
modelOperateList := make([]mongo.WriteModel, 0)
|
||||||
for _, player := range playerList {
|
for _, player := range playerList {
|
||||||
modelOperate := mongo.NewUpdateOneModel().SetFilter(bson.D{{"PlayerID", player.PlayerID}}).SetUpdate(bson.D{{"$set", player}})
|
modelOperate := mongo.NewUpdateManyModel().SetFilter(bson.D{{"PlayerID", player.PlayerID}}).SetUpdate(bson.D{{"$set", player}})
|
||||||
modelOperateList = append(modelOperateList, modelOperate)
|
modelOperateList = append(modelOperateList, modelOperate)
|
||||||
}
|
}
|
||||||
_, err := db.BulkWrite(context.TODO(), modelOperateList)
|
_, err := db.BulkWrite(context.TODO(), modelOperateList)
|
||||||
@@ -164,7 +164,7 @@ func (d *Dao) UpdateChatMsgList(chatMsgList []*model.ChatMsg) error {
|
|||||||
db := d.db.Collection("chat_msg")
|
db := d.db.Collection("chat_msg")
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
modelOperateList := make([]mongo.WriteModel, 0)
|
||||||
for _, chatMsg := range chatMsgList {
|
for _, chatMsg := range chatMsgList {
|
||||||
modelOperate := mongo.NewUpdateOneModel().SetFilter(bson.D{{"_id", chatMsg.ID}}).SetUpdate(bson.D{{"$set", chatMsg}})
|
modelOperate := mongo.NewUpdateManyModel().SetFilter(bson.D{{"_id", chatMsg.ID}}).SetUpdate(bson.D{{"$set", chatMsg}})
|
||||||
modelOperateList = append(modelOperateList, modelOperate)
|
modelOperateList = append(modelOperateList, modelOperate)
|
||||||
}
|
}
|
||||||
_, err := db.BulkWrite(context.TODO(), modelOperateList)
|
_, err := db.BulkWrite(context.TODO(), modelOperateList)
|
||||||
|
|||||||
@@ -30,7 +30,13 @@ func (d *Dao) GetRedisPlayerLockKey(userId uint32) string {
|
|||||||
// GetRedisPlayer 获取玩家数据
|
// GetRedisPlayer 获取玩家数据
|
||||||
func (d *Dao) GetRedisPlayer(userId uint32) *model.Player {
|
func (d *Dao) GetRedisPlayer(userId uint32) *model.Player {
|
||||||
startTime := time.Now().UnixNano()
|
startTime := time.Now().UnixNano()
|
||||||
playerDataLz4, err := d.redis.Get(context.TODO(), d.GetRedisPlayerKey(userId)).Result()
|
var playerDataLz4 = ""
|
||||||
|
var err error = nil
|
||||||
|
if d.redisCluster != nil {
|
||||||
|
playerDataLz4, err = d.redisCluster.Get(context.TODO(), d.GetRedisPlayerKey(userId)).Result()
|
||||||
|
} else {
|
||||||
|
playerDataLz4, err = d.redis.Get(context.TODO(), d.GetRedisPlayerKey(userId)).Result()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("get player from redis error: %v", err)
|
logger.Error("get player from redis error: %v", err)
|
||||||
return nil
|
return nil
|
||||||
@@ -90,7 +96,11 @@ func (d *Dao) SetRedisPlayer(player *model.Player) {
|
|||||||
logger.Debug("lz4 encode cost time: %v ns, before len: %v, after len: %v, ratio lz4/raw: %v",
|
logger.Debug("lz4 encode cost time: %v ns, before len: %v, after len: %v, ratio lz4/raw: %v",
|
||||||
costTime, len(playerData), len(playerDataLz4), float64(len(playerDataLz4))/float64(len(playerData)))
|
costTime, len(playerData), len(playerDataLz4), float64(len(playerDataLz4))/float64(len(playerData)))
|
||||||
startTime = time.Now().UnixNano()
|
startTime = time.Now().UnixNano()
|
||||||
err = d.redis.Set(context.TODO(), d.GetRedisPlayerKey(player.PlayerID), playerDataLz4, time.Hour*24*30).Err()
|
if d.redisCluster != nil {
|
||||||
|
err = d.redisCluster.Set(context.TODO(), d.GetRedisPlayerKey(player.PlayerID), playerDataLz4, time.Hour*24*30).Err()
|
||||||
|
} else {
|
||||||
|
err = d.redis.Set(context.TODO(), d.GetRedisPlayerKey(player.PlayerID), playerDataLz4, time.Hour*24*30).Err()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("set player to redis error: %v", err)
|
logger.Error("set player to redis error: %v", err)
|
||||||
return
|
return
|
||||||
@@ -118,10 +128,19 @@ const (
|
|||||||
|
|
||||||
// DistLock 加锁并返回是否成功
|
// DistLock 加锁并返回是否成功
|
||||||
func (d *Dao) DistLock(userId uint32) bool {
|
func (d *Dao) DistLock(userId uint32) bool {
|
||||||
result, err := d.redis.SetNX(context.TODO(),
|
var result = false
|
||||||
d.GetRedisPlayerLockKey(userId),
|
var err error = nil
|
||||||
time.Now().UnixMilli(),
|
if d.redisCluster != nil {
|
||||||
time.Millisecond*time.Duration(MaxLockAliveTime)).Result()
|
result, err = d.redisCluster.SetNX(context.TODO(),
|
||||||
|
d.GetRedisPlayerLockKey(userId),
|
||||||
|
time.Now().UnixMilli(),
|
||||||
|
time.Millisecond*time.Duration(MaxLockAliveTime)).Result()
|
||||||
|
} else {
|
||||||
|
result, err = d.redis.SetNX(context.TODO(),
|
||||||
|
d.GetRedisPlayerLockKey(userId),
|
||||||
|
time.Now().UnixMilli(),
|
||||||
|
time.Millisecond*time.Duration(MaxLockAliveTime)).Result()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("redis lock setnx error: %v", err)
|
logger.Error("redis lock setnx error: %v", err)
|
||||||
return false
|
return false
|
||||||
@@ -132,10 +151,19 @@ func (d *Dao) DistLock(userId uint32) bool {
|
|||||||
// DistLockSync 加锁同步阻塞直到成功或超时
|
// DistLockSync 加锁同步阻塞直到成功或超时
|
||||||
func (d *Dao) DistLockSync(userId uint32) bool {
|
func (d *Dao) DistLockSync(userId uint32) bool {
|
||||||
for i := 0; i < MaxLockRetryTimes; i++ {
|
for i := 0; i < MaxLockRetryTimes; i++ {
|
||||||
result, err := d.redis.SetNX(context.TODO(),
|
var result = false
|
||||||
d.GetRedisPlayerLockKey(userId),
|
var err error = nil
|
||||||
time.Now().UnixMilli(),
|
if d.redisCluster != nil {
|
||||||
time.Millisecond*time.Duration(MaxLockAliveTime)).Result()
|
result, err = d.redisCluster.SetNX(context.TODO(),
|
||||||
|
d.GetRedisPlayerLockKey(userId),
|
||||||
|
time.Now().UnixMilli(),
|
||||||
|
time.Millisecond*time.Duration(MaxLockAliveTime)).Result()
|
||||||
|
} else {
|
||||||
|
result, err = d.redis.SetNX(context.TODO(),
|
||||||
|
d.GetRedisPlayerLockKey(userId),
|
||||||
|
time.Now().UnixMilli(),
|
||||||
|
time.Millisecond*time.Duration(MaxLockAliveTime)).Result()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("redis lock setnx error: %v", err)
|
logger.Error("redis lock setnx error: %v", err)
|
||||||
return false
|
return false
|
||||||
@@ -150,7 +178,13 @@ func (d *Dao) DistLockSync(userId uint32) bool {
|
|||||||
|
|
||||||
// DistUnlock 解锁
|
// DistUnlock 解锁
|
||||||
func (d *Dao) DistUnlock(userId uint32) {
|
func (d *Dao) DistUnlock(userId uint32) {
|
||||||
result, err := d.redis.Del(context.TODO(), d.GetRedisPlayerLockKey(userId)).Result()
|
var result int64 = 0
|
||||||
|
var err error = nil
|
||||||
|
if d.redisCluster != nil {
|
||||||
|
result, err = d.redisCluster.Del(context.TODO(), d.GetRedisPlayerLockKey(userId)).Result()
|
||||||
|
} else {
|
||||||
|
result, err = d.redis.Del(context.TODO(), d.GetRedisPlayerLockKey(userId)).Result()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("redis lock del error: %v", err)
|
logger.Error("redis lock del error: %v", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func (c *CommandManager) GMTeleportPlayer(userId, sceneId uint32, posX, posY, po
|
|||||||
|
|
||||||
// GMAddUserItem 给予玩家物品
|
// GMAddUserItem 给予玩家物品
|
||||||
func (c *CommandManager) GMAddUserItem(userId, itemId, itemCount uint32) {
|
func (c *CommandManager) GMAddUserItem(userId, itemId, itemCount uint32) {
|
||||||
GAME_MANAGER.AddUserItem(userId, []*UserItem{
|
GAME_MANAGER.AddUserItem(userId, []*ChangeItem{
|
||||||
{
|
{
|
||||||
ItemId: itemId,
|
ItemId: itemId,
|
||||||
ChangeCount: itemCount,
|
ChangeCount: itemCount,
|
||||||
@@ -75,9 +75,9 @@ func (c *CommandManager) GMAddUserAllItem(userId, itemCount uint32) {
|
|||||||
// for itemId := range GAME_MANAGER.GetAllItemDataConfig() {
|
// for itemId := range GAME_MANAGER.GetAllItemDataConfig() {
|
||||||
// c.GMAddUserItem(userId, uint32(itemId), itemCount)
|
// c.GMAddUserItem(userId, uint32(itemId), itemCount)
|
||||||
// }
|
// }
|
||||||
itemList := make([]*UserItem, 0)
|
itemList := make([]*ChangeItem, 0)
|
||||||
for itemId := range GAME_MANAGER.GetAllItemDataConfig() {
|
for itemId := range GAME_MANAGER.GetAllItemDataConfig() {
|
||||||
itemList = append(itemList, &UserItem{
|
itemList = append(itemList, &ChangeItem{
|
||||||
ItemId: uint32(itemId),
|
ItemId: uint32(itemId),
|
||||||
ChangeCount: itemCount,
|
ChangeCount: itemCount,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -108,10 +108,11 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs
|
|||||||
}
|
}
|
||||||
robot := r.CreateRobot(uid, random.GetRandomStr(8), random.GetRandomStr(10))
|
robot := r.CreateRobot(uid, random.GetRandomStr(8), random.GetRandomStr(10))
|
||||||
r.AddUserAvatar(uid, avatarId)
|
r.AddUserAvatar(uid, avatarId)
|
||||||
|
dbAvatar := robot.GetDbAvatar()
|
||||||
r.SetUpAvatarTeamReq(robot, &proto.SetUpAvatarTeamReq{
|
r.SetUpAvatarTeamReq(robot, &proto.SetUpAvatarTeamReq{
|
||||||
TeamId: 1,
|
TeamId: 1,
|
||||||
AvatarTeamGuidList: []uint64{robot.AvatarMap[avatarId].Guid},
|
AvatarTeamGuidList: []uint64{dbAvatar.AvatarMap[avatarId].Guid},
|
||||||
CurAvatarGuid: robot.AvatarMap[avatarId].Guid,
|
CurAvatarGuid: dbAvatar.AvatarMap[avatarId].Guid,
|
||||||
})
|
})
|
||||||
robot.Pos.X -= random.GetRandomFloat64(25.0, 35.0)
|
robot.Pos.X -= random.GetRandomFloat64(25.0, 35.0)
|
||||||
robot.Pos.Y += 1.0
|
robot.Pos.Y += 1.0
|
||||||
@@ -160,7 +161,7 @@ func (g *GameManager) run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) gameMainLoopD() {
|
func (g *GameManager) gameMainLoopD() {
|
||||||
for times := 1; times <= 100000; times++ {
|
for times := 1; times <= 10000; times++ {
|
||||||
logger.Warn("start game main loop, times: %v", times)
|
logger.Warn("start game main loop, times: %v", times)
|
||||||
g.gameMainLoop()
|
g.gameMainLoop()
|
||||||
logger.Warn("game main loop stop")
|
logger.Warn("game main loop stop")
|
||||||
|
|||||||
@@ -41,12 +41,13 @@ func (g *GameManager) AddUserAvatar(userId uint32, avatarId uint32) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 判断玩家是否已有该角色
|
// 判断玩家是否已有该角色
|
||||||
_, ok := player.AvatarMap[avatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
_, ok := dbAvatar.AvatarMap[avatarId]
|
||||||
if ok {
|
if ok {
|
||||||
// TODO 如果已有转换命座材料
|
// TODO 如果已有转换命座材料
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
player.AddAvatar(avatarId)
|
dbAvatar.AddAvatar(player, avatarId)
|
||||||
|
|
||||||
// 添加初始武器
|
// 添加初始武器
|
||||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatarId))
|
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatarId))
|
||||||
@@ -62,7 +63,7 @@ func (g *GameManager) AddUserAvatar(userId uint32, avatarId uint32) {
|
|||||||
g.UpdateUserAvatarFightProp(player.PlayerID, avatarId)
|
g.UpdateUserAvatarFightProp(player.PlayerID, avatarId)
|
||||||
|
|
||||||
avatarAddNotify := &proto.AvatarAddNotify{
|
avatarAddNotify := &proto.AvatarAddNotify{
|
||||||
Avatar: g.PacketAvatarInfo(player.AvatarMap[avatarId]),
|
Avatar: g.PacketAvatarInfo(dbAvatar.AvatarMap[avatarId]),
|
||||||
IsInTeam: false,
|
IsInTeam: false,
|
||||||
}
|
}
|
||||||
g.SendMsg(cmd.AvatarAddNotify, userId, player.ClientSeq, avatarAddNotify)
|
g.SendMsg(cmd.AvatarAddNotify, userId, player.ClientSeq, avatarAddNotify)
|
||||||
@@ -102,9 +103,9 @@ func (g *GameManager) AvatarPromoteGetRewardReq(player *model.Player, payloadMsg
|
|||||||
// 设置该奖励为已被获取状态
|
// 设置该奖励为已被获取状态
|
||||||
avatar.PromoteRewardMap[req.PromoteLevel] = true
|
avatar.PromoteRewardMap[req.PromoteLevel] = true
|
||||||
// 给予突破奖励
|
// 给予突破奖励
|
||||||
rewardItemList := make([]*UserItem, 0, len(rewardConfig.RewardItemMap))
|
rewardItemList := make([]*ChangeItem, 0, len(rewardConfig.RewardItemMap))
|
||||||
for itemId, count := range rewardConfig.RewardItemMap {
|
for itemId, count := range rewardConfig.RewardItemMap {
|
||||||
rewardItemList = append(rewardItemList, &UserItem{
|
rewardItemList = append(rewardItemList, &ChangeItem{
|
||||||
ItemId: itemId,
|
ItemId: itemId,
|
||||||
ChangeCount: count,
|
ChangeCount: count,
|
||||||
})
|
})
|
||||||
@@ -158,22 +159,23 @@ func (g *GameManager) AvatarPromoteReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 将被消耗的物品列表
|
// 将被消耗的物品列表
|
||||||
costItemList := make([]*UserItem, 0, len(avatarPromoteConfig.CostItemMap)+1)
|
costItemList := make([]*ChangeItem, 0, len(avatarPromoteConfig.CostItemMap)+1)
|
||||||
// 突破材料是否足够并添加到消耗物品列表
|
// 突破材料是否足够并添加到消耗物品列表
|
||||||
for itemId, count := range avatarPromoteConfig.CostItemMap {
|
for itemId, count := range avatarPromoteConfig.CostItemMap {
|
||||||
costItemList = append(costItemList, &UserItem{
|
costItemList = append(costItemList, &ChangeItem{
|
||||||
ItemId: itemId,
|
ItemId: itemId,
|
||||||
ChangeCount: count,
|
ChangeCount: count,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 消耗列表添加摩拉的消耗
|
// 消耗列表添加摩拉的消耗
|
||||||
costItemList = append(costItemList, &UserItem{
|
costItemList = append(costItemList, &ChangeItem{
|
||||||
ItemId: constant.ITEM_ID_SCOIN,
|
ItemId: constant.ITEM_ID_SCOIN,
|
||||||
ChangeCount: uint32(avatarPromoteConfig.CostCoin),
|
ChangeCount: uint32(avatarPromoteConfig.CostCoin),
|
||||||
})
|
})
|
||||||
// 突破材料以及摩拉是否足够
|
// 突破材料以及摩拉是否足够
|
||||||
|
dbItem := player.GetDbItem()
|
||||||
for _, item := range costItemList {
|
for _, item := range costItemList {
|
||||||
if player.GetItemCount(item.ItemId) < item.ChangeCount {
|
if dbItem.GetItemCount(player, item.ItemId) < item.ChangeCount {
|
||||||
logger.Error("item count not enough, itemId: %v", item.ItemId)
|
logger.Error("item count not enough, itemId: %v", item.ItemId)
|
||||||
// 摩拉的错误提示与材料不同
|
// 摩拉的错误提示与材料不同
|
||||||
if item.ItemId == constant.ITEM_ID_SCOIN {
|
if item.ItemId == constant.ITEM_ID_SCOIN {
|
||||||
@@ -217,7 +219,8 @@ func (g *GameManager) AvatarUpgradeReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 经验书数量是否足够
|
// 经验书数量是否足够
|
||||||
if player.GetItemCount(req.ItemId) < req.Count {
|
dbItem := player.GetDbItem()
|
||||||
|
if dbItem.GetItemCount(player, req.ItemId) < req.Count {
|
||||||
logger.Error("item count not enough, itemId: %v", req.ItemId)
|
logger.Error("item count not enough, itemId: %v", req.ItemId)
|
||||||
g.SendError(cmd.AvatarUpgradeRsp, player, &proto.AvatarUpgradeRsp{}, proto.Retcode_RET_ITEM_COUNT_NOT_ENOUGH)
|
g.SendError(cmd.AvatarUpgradeRsp, player, &proto.AvatarUpgradeRsp{}, proto.Retcode_RET_ITEM_COUNT_NOT_ENOUGH)
|
||||||
return
|
return
|
||||||
@@ -239,7 +242,7 @@ func (g *GameManager) AvatarUpgradeReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
// 角色获得的经验
|
// 角色获得的经验
|
||||||
expCount := uint32(itemParam) * req.Count
|
expCount := uint32(itemParam) * req.Count
|
||||||
// 摩拉数量是否足够
|
// 摩拉数量是否足够
|
||||||
if player.GetItemCount(constant.ITEM_ID_SCOIN) < expCount/5 {
|
if dbItem.GetItemCount(player, constant.ITEM_ID_SCOIN) < expCount/5 {
|
||||||
logger.Error("item count not enough, itemId: %v", constant.ITEM_ID_SCOIN)
|
logger.Error("item count not enough, itemId: %v", constant.ITEM_ID_SCOIN)
|
||||||
g.SendError(cmd.AvatarUpgradeRsp, player, &proto.AvatarUpgradeRsp{}, proto.Retcode_RET_SCOIN_NOT_ENOUGH)
|
g.SendError(cmd.AvatarUpgradeRsp, player, &proto.AvatarUpgradeRsp{}, proto.Retcode_RET_SCOIN_NOT_ENOUGH)
|
||||||
return
|
return
|
||||||
@@ -265,7 +268,7 @@ func (g *GameManager) AvatarUpgradeReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 消耗升级材料以及摩拉
|
// 消耗升级材料以及摩拉
|
||||||
g.CostUserItem(player.PlayerID, []*UserItem{
|
g.CostUserItem(player.PlayerID, []*ChangeItem{
|
||||||
{
|
{
|
||||||
ItemId: req.ItemId,
|
ItemId: req.ItemId,
|
||||||
ChangeCount: req.Count,
|
ChangeCount: req.Count,
|
||||||
@@ -365,13 +368,14 @@ func (g *GameManager) UpdateUserAvatarFightProp(userId uint32, avatarId uint32)
|
|||||||
logger.Error("player is nil, uid: %v", userId)
|
logger.Error("player is nil, uid: %v", userId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
avatar, ok := player.AvatarMap[avatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar, ok := dbAvatar.AvatarMap[avatarId]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("avatar is nil, avatarId: %v", avatar)
|
logger.Error("avatar is nil, avatarId: %v", avatar)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 角色初始化面板
|
// 角色初始化面板
|
||||||
player.InitAvatarFightProp(avatar)
|
dbAvatar.InitAvatarFightProp(avatar)
|
||||||
|
|
||||||
avatarFightPropNotify := &proto.AvatarFightPropNotify{
|
avatarFightPropNotify := &proto.AvatarFightPropNotify{
|
||||||
AvatarGuid: avatar.Guid,
|
AvatarGuid: avatar.Guid,
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ func (g *GameManager) TakeoffEquipReq(player *model.Player, payloadMsg pb.Messag
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 卸下圣遗物
|
// 卸下圣遗物
|
||||||
player.TakeOffReliquary(avatar.AvatarId, reliquary.ReliquaryId)
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
dbAvatar.TakeOffReliquary(avatar.AvatarId, reliquary)
|
||||||
// 角色更新面板
|
// 角色更新面板
|
||||||
g.UpdateUserAvatarFightProp(player.PlayerID, avatar.AvatarId)
|
g.UpdateUserAvatarFightProp(player.PlayerID, avatar.AvatarId)
|
||||||
// 更新玩家装备
|
// 更新玩家装备
|
||||||
@@ -147,12 +148,14 @@ func (g *GameManager) WearUserAvatarReliquary(userId uint32, avatarId uint32, re
|
|||||||
logger.Error("player is nil, uid: %v", userId)
|
logger.Error("player is nil, uid: %v", userId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
avatar, ok := player.AvatarMap[avatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar, ok := dbAvatar.AvatarMap[avatarId]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("avatar error, avatarId: %v", avatarId)
|
logger.Error("avatar error, avatarId: %v", avatarId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
reliquary, ok := player.ReliquaryMap[reliquaryId]
|
dbReliquary := player.GetDbReliquary()
|
||||||
|
reliquary, ok := dbReliquary.ReliquaryMap[reliquaryId]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("reliquary error, reliquaryId: %v", reliquaryId)
|
logger.Error("reliquary error, reliquaryId: %v", reliquaryId)
|
||||||
return
|
return
|
||||||
@@ -167,7 +170,7 @@ func (g *GameManager) WearUserAvatarReliquary(userId uint32, avatarId uint32, re
|
|||||||
avatarCurReliquary := avatar.EquipReliquaryMap[uint8(reliquaryConfig.ReliquaryType)]
|
avatarCurReliquary := avatar.EquipReliquaryMap[uint8(reliquaryConfig.ReliquaryType)]
|
||||||
if reliquary.AvatarId != 0 {
|
if reliquary.AvatarId != 0 {
|
||||||
// 圣遗物在别的角色身上
|
// 圣遗物在别的角色身上
|
||||||
targetReliquaryAvatar, ok := player.AvatarMap[reliquary.AvatarId]
|
targetReliquaryAvatar, ok := dbAvatar.AvatarMap[reliquary.AvatarId]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("avatar error, avatarId: %v", reliquary.AvatarId)
|
logger.Error("avatar error, avatarId: %v", reliquary.AvatarId)
|
||||||
return
|
return
|
||||||
@@ -175,22 +178,22 @@ func (g *GameManager) WearUserAvatarReliquary(userId uint32, avatarId uint32, re
|
|||||||
// 确保目前角色已装备圣遗物
|
// 确保目前角色已装备圣遗物
|
||||||
if avatarCurReliquary != nil {
|
if avatarCurReliquary != nil {
|
||||||
// 卸下角色已装备的圣遗物
|
// 卸下角色已装备的圣遗物
|
||||||
player.TakeOffReliquary(avatarId, avatarCurReliquary.ReliquaryId)
|
dbAvatar.TakeOffReliquary(avatarId, avatarCurReliquary)
|
||||||
// 将目标圣遗物的角色装备当前角色曾装备的圣遗物
|
// 将目标圣遗物的角色装备当前角色曾装备的圣遗物
|
||||||
player.WearReliquary(targetReliquaryAvatar.AvatarId, avatarCurReliquary.ReliquaryId)
|
dbAvatar.WearReliquary(targetReliquaryAvatar.AvatarId, avatarCurReliquary)
|
||||||
}
|
}
|
||||||
// 将目标圣遗物的角色卸下圣遗物
|
// 将目标圣遗物的角色卸下圣遗物
|
||||||
player.TakeOffReliquary(targetReliquaryAvatar.AvatarId, reliquary.ReliquaryId)
|
dbAvatar.TakeOffReliquary(targetReliquaryAvatar.AvatarId, reliquary)
|
||||||
|
|
||||||
// 更新目标圣遗物角色的装备
|
// 更新目标圣遗物角色的装备
|
||||||
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(targetReliquaryAvatar, uint8(reliquaryConfig.ReliquaryType))
|
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(targetReliquaryAvatar, uint8(reliquaryConfig.ReliquaryType))
|
||||||
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
|
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
|
||||||
} else if avatarCurReliquary != nil {
|
} else if avatarCurReliquary != nil {
|
||||||
// 角色当前有圣遗物则卸下
|
// 角色当前有圣遗物则卸下
|
||||||
player.TakeOffReliquary(avatarId, avatarCurReliquary.ReliquaryId)
|
dbAvatar.TakeOffReliquary(avatarId, avatarCurReliquary)
|
||||||
}
|
}
|
||||||
// 角色装备圣遗物
|
// 角色装备圣遗物
|
||||||
player.WearReliquary(avatarId, reliquaryId)
|
dbAvatar.WearReliquary(avatarId, reliquary)
|
||||||
|
|
||||||
// 更新角色装备
|
// 更新角色装备
|
||||||
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(avatar, uint8(reliquaryConfig.ReliquaryType))
|
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(avatar, uint8(reliquaryConfig.ReliquaryType))
|
||||||
@@ -204,12 +207,14 @@ func (g *GameManager) WearUserAvatarWeapon(userId uint32, avatarId uint32, weapo
|
|||||||
logger.Error("player is nil, uid: %v", userId)
|
logger.Error("player is nil, uid: %v", userId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
avatar, ok := player.AvatarMap[avatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar, ok := dbAvatar.AvatarMap[avatarId]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("avatar error, avatarId: %v", avatarId)
|
logger.Error("avatar error, avatarId: %v", avatarId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
weapon, ok := player.WeaponMap[weaponId]
|
dbWeapon := player.GetDbWeapon()
|
||||||
|
weapon, ok := dbWeapon.WeaponMap[weaponId]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("weapon error, weaponId: %v", weaponId)
|
logger.Error("weapon error, weaponId: %v", weaponId)
|
||||||
return
|
return
|
||||||
@@ -225,18 +230,18 @@ func (g *GameManager) WearUserAvatarWeapon(userId uint32, avatarId uint32, weapo
|
|||||||
if avatarCurWeapon != nil {
|
if avatarCurWeapon != nil {
|
||||||
if weapon.AvatarId != 0 {
|
if weapon.AvatarId != 0 {
|
||||||
// 武器在别的角色身上
|
// 武器在别的角色身上
|
||||||
targetWeaponAvatar, ok := player.AvatarMap[weapon.AvatarId]
|
targetWeaponAvatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("avatar error, avatarId: %v", weapon.AvatarId)
|
logger.Error("avatar error, avatarId: %v", weapon.AvatarId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 卸下角色已装备的武器
|
// 卸下角色已装备的武器
|
||||||
player.TakeOffWeapon(avatarId, avatarCurWeapon.WeaponId)
|
dbAvatar.TakeOffWeapon(avatarId, avatarCurWeapon)
|
||||||
|
|
||||||
// 将目标武器的角色卸下武器
|
// 将目标武器的角色卸下武器
|
||||||
player.TakeOffWeapon(targetWeaponAvatar.AvatarId, weapon.WeaponId)
|
dbAvatar.TakeOffWeapon(targetWeaponAvatar.AvatarId, weapon)
|
||||||
// 将目标武器的角色装备当前角色曾装备的武器
|
// 将目标武器的角色装备当前角色曾装备的武器
|
||||||
player.WearWeapon(targetWeaponAvatar.AvatarId, avatarCurWeapon.WeaponId)
|
dbAvatar.WearWeapon(targetWeaponAvatar.AvatarId, avatarCurWeapon)
|
||||||
|
|
||||||
// 更新目标武器角色的装备
|
// 更新目标武器角色的装备
|
||||||
weaponEntityId := uint32(0)
|
weaponEntityId := uint32(0)
|
||||||
@@ -248,11 +253,11 @@ func (g *GameManager) WearUserAvatarWeapon(userId uint32, avatarId uint32, weapo
|
|||||||
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
|
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
|
||||||
} else {
|
} else {
|
||||||
// 角色当前有武器则卸下
|
// 角色当前有武器则卸下
|
||||||
player.TakeOffWeapon(avatarId, avatarCurWeapon.WeaponId)
|
dbAvatar.TakeOffWeapon(avatarId, avatarCurWeapon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 角色装备武器
|
// 角色装备武器
|
||||||
player.WearWeapon(avatarId, weaponId)
|
dbAvatar.WearWeapon(avatarId, weapon)
|
||||||
|
|
||||||
// 更新角色装备
|
// 更新角色装备
|
||||||
weaponEntityId := uint32(0)
|
weaponEntityId := uint32(0)
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ func (g *GameManager) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 先扣掉粉球或蓝球再进行抽卡
|
// 先扣掉粉球或蓝球再进行抽卡
|
||||||
g.CostUserItem(player.PlayerID, []*UserItem{
|
g.CostUserItem(player.PlayerID, []*ChangeItem{
|
||||||
{
|
{
|
||||||
ItemId: costItemId,
|
ItemId: costItemId,
|
||||||
ChangeCount: gachaTimes,
|
ChangeCount: gachaTimes,
|
||||||
@@ -268,19 +268,21 @@ func (g *GameManager) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
|
|||||||
// 添加抽卡获得的道具
|
// 添加抽卡获得的道具
|
||||||
if itemId > 1000 && itemId < 2000 {
|
if itemId > 1000 && itemId < 2000 {
|
||||||
avatarId := (itemId % 1000) + 10000000
|
avatarId := (itemId % 1000) + 10000000
|
||||||
_, exist := player.AvatarMap[avatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
_, exist := dbAvatar.AvatarMap[avatarId]
|
||||||
if !exist {
|
if !exist {
|
||||||
g.AddUserAvatar(player.PlayerID, avatarId)
|
g.AddUserAvatar(player.PlayerID, avatarId)
|
||||||
} else {
|
} else {
|
||||||
constellationItemId := itemId + 100
|
constellationItemId := itemId + 100
|
||||||
if player.GetItemCount(constellationItemId) < 6 {
|
dbItem := player.GetDbItem()
|
||||||
g.AddUserItem(player.PlayerID, []*UserItem{{ItemId: constellationItemId, ChangeCount: 1}}, false, 0)
|
if dbItem.GetItemCount(player, constellationItemId) < 6 {
|
||||||
|
g.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: constellationItemId, ChangeCount: 1}}, false, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if itemId > 10000 && itemId < 20000 {
|
} else if itemId > 10000 && itemId < 20000 {
|
||||||
g.AddUserWeapon(player.PlayerID, itemId)
|
g.AddUserWeapon(player.PlayerID, itemId)
|
||||||
} else {
|
} else {
|
||||||
g.AddUserItem(player.PlayerID, []*UserItem{{ItemId: itemId, ChangeCount: 1}}, false, 0)
|
g.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: itemId, ChangeCount: 1}}, false, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算星尘星辉
|
// 计算星尘星辉
|
||||||
@@ -294,7 +296,7 @@ func (g *GameManager) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
|
|||||||
}
|
}
|
||||||
// 星尘
|
// 星尘
|
||||||
if xc != 0 {
|
if xc != 0 {
|
||||||
g.AddUserItem(player.PlayerID, []*UserItem{{
|
g.AddUserItem(player.PlayerID, []*ChangeItem{{
|
||||||
ItemId: 222,
|
ItemId: 222,
|
||||||
ChangeCount: xc,
|
ChangeCount: xc,
|
||||||
}}, false, 0)
|
}}, false, 0)
|
||||||
@@ -305,7 +307,7 @@ func (g *GameManager) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
|
|||||||
}
|
}
|
||||||
// 星辉
|
// 星辉
|
||||||
if xh != 0 {
|
if xh != 0 {
|
||||||
g.AddUserItem(player.PlayerID, []*UserItem{{
|
g.AddUserItem(player.PlayerID, []*ChangeItem{{
|
||||||
ItemId: 221,
|
ItemId: 221,
|
||||||
ChangeCount: xh,
|
ChangeCount: xh,
|
||||||
}}, false, 0)
|
}}, false, 0)
|
||||||
@@ -392,7 +394,8 @@ func (g *GameManager) doGachaOnce(userId uint32, gachaType uint32, mustGetUpEnab
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户的卡池保底信息
|
// 获取用户的卡池保底信息
|
||||||
gachaPoolInfo := player.DropInfo.GachaPoolInfo[gachaType]
|
dbGacha := player.GetDbGacha()
|
||||||
|
gachaPoolInfo := dbGacha.GachaPoolInfo[gachaType]
|
||||||
if gachaPoolInfo == nil {
|
if gachaPoolInfo == nil {
|
||||||
logger.Error("user gacha pool info not found, gacha type: %v", gachaType)
|
logger.Error("user gacha pool info not found, gacha type: %v", gachaType)
|
||||||
return false, 0
|
return false, 0
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ func (g *GameManager) GCGAskDuelReq(player *model.Player, payloadMsg pb.Message)
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
// 玩家信息列表
|
// 玩家信息列表
|
||||||
|
dbAvatar := player.GetDbAvatar()
|
||||||
for _, controller := range game.controllerMap {
|
for _, controller := range game.controllerMap {
|
||||||
gcgControllerShowInfo := &proto.GCGControllerShowInfo{
|
gcgControllerShowInfo := &proto.GCGControllerShowInfo{
|
||||||
ControllerId: controller.controllerId,
|
ControllerId: controller.controllerId,
|
||||||
@@ -177,7 +178,7 @@ func (g *GameManager) GCGAskDuelReq(player *model.Player, payloadMsg pb.Message)
|
|||||||
// 如果为玩家则更改为玩家信息
|
// 如果为玩家则更改为玩家信息
|
||||||
if controller.controllerType == ControllerType_Player {
|
if controller.controllerType == ControllerType_Player {
|
||||||
gcgControllerShowInfo.ProfilePicture.AvatarId = player.HeadImage
|
gcgControllerShowInfo.ProfilePicture.AvatarId = player.HeadImage
|
||||||
gcgControllerShowInfo.ProfilePicture.AvatarId = player.AvatarMap[player.HeadImage].Costume
|
gcgControllerShowInfo.ProfilePicture.AvatarId = dbAvatar.AvatarMap[player.HeadImage].Costume
|
||||||
}
|
}
|
||||||
gcgAskDuelRsp.Duel.ShowInfoList = append(gcgAskDuelRsp.Duel.ShowInfoList)
|
gcgAskDuelRsp.Duel.ShowInfoList = append(gcgAskDuelRsp.Duel.ShowInfoList)
|
||||||
}
|
}
|
||||||
@@ -481,6 +482,8 @@ func (g *GameManager) PacketGCGGameBriefDataNotify(player *model.Player, busines
|
|||||||
},
|
},
|
||||||
IsNewGame: true, // TODO 根据游戏修改
|
IsNewGame: true, // TODO 根据游戏修改
|
||||||
}
|
}
|
||||||
|
dbTeam := player.GetDbTeam()
|
||||||
|
dbAvatar := player.GetDbAvatar()
|
||||||
for _, controller := range game.controllerMap {
|
for _, controller := range game.controllerMap {
|
||||||
gcgPlayerBriefData := &proto.GCGPlayerBriefData{
|
gcgPlayerBriefData := &proto.GCGPlayerBriefData{
|
||||||
ControllerId: controller.controllerId,
|
ControllerId: controller.controllerId,
|
||||||
@@ -494,8 +497,8 @@ func (g *GameManager) PacketGCGGameBriefDataNotify(player *model.Player, busines
|
|||||||
// 玩家信息
|
// 玩家信息
|
||||||
if controller.player != nil {
|
if controller.player != nil {
|
||||||
gcgPlayerBriefData.Uid = player.PlayerID
|
gcgPlayerBriefData.Uid = player.PlayerID
|
||||||
gcgPlayerBriefData.ProfilePicture.AvatarId = player.TeamConfig.GetActiveAvatarId()
|
gcgPlayerBriefData.ProfilePicture.AvatarId = dbTeam.GetActiveAvatarId()
|
||||||
gcgPlayerBriefData.ProfilePicture.CostumeId = player.AvatarMap[player.TeamConfig.GetActiveAvatarId()].Costume
|
gcgPlayerBriefData.ProfilePicture.CostumeId = dbAvatar.AvatarMap[dbTeam.GetActiveAvatarId()].Costume
|
||||||
gcgPlayerBriefData.NickName = player.NickName
|
gcgPlayerBriefData.NickName = player.NickName
|
||||||
}
|
}
|
||||||
gcgGameBriefDataNotify.GcgBriefData.PlayerBriefList = append(gcgGameBriefDataNotify.GcgBriefData.PlayerBriefList)
|
gcgGameBriefDataNotify.GcgBriefData.PlayerBriefList = append(gcgGameBriefDataNotify.GcgBriefData.PlayerBriefList)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"hk4e/protocol/proto"
|
"hk4e/protocol/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserItem struct {
|
type ChangeItem struct {
|
||||||
ItemId uint32
|
ItemId uint32
|
||||||
ChangeCount uint32
|
ChangeCount uint32
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ func (g *GameManager) GetAllItemDataConfig() map[int32]*gdconf.ItemData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddUserItem 玩家添加物品
|
// AddUserItem 玩家添加物品
|
||||||
func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bool, hintReason uint16) {
|
func (g *GameManager) AddUserItem(userId uint32, itemList []*ChangeItem, isHint bool, hintReason uint16) {
|
||||||
player := USER_MANAGER.GetOnlineUser(userId)
|
player := USER_MANAGER.GetOnlineUser(userId)
|
||||||
if player == nil {
|
if player == nil {
|
||||||
logger.Error("player is nil, uid: %v", userId)
|
logger.Error("player is nil, uid: %v", userId)
|
||||||
@@ -58,6 +58,7 @@ func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bo
|
|||||||
playerPropNotify := &proto.PlayerPropNotify{
|
playerPropNotify := &proto.PlayerPropNotify{
|
||||||
PropMap: make(map[uint32]*proto.PropValue),
|
PropMap: make(map[uint32]*proto.PropValue),
|
||||||
}
|
}
|
||||||
|
dbItem := player.GetDbItem()
|
||||||
for _, userItem := range itemList {
|
for _, userItem := range itemList {
|
||||||
// 物品为虚拟物品则另外处理
|
// 物品为虚拟物品则另外处理
|
||||||
switch userItem.ItemId {
|
switch userItem.ItemId {
|
||||||
@@ -83,7 +84,7 @@ func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bo
|
|||||||
g.AddUserPlayerExp(userId, userItem.ChangeCount)
|
g.AddUserPlayerExp(userId, userItem.ChangeCount)
|
||||||
default:
|
default:
|
||||||
// 普通物品直接进背包
|
// 普通物品直接进背包
|
||||||
player.AddItem(userItem.ItemId, userItem.ChangeCount)
|
dbItem.AddItem(player, userItem.ItemId, userItem.ChangeCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(playerPropNotify.PropMap) > 0 {
|
if len(playerPropNotify.PropMap) > 0 {
|
||||||
@@ -97,10 +98,10 @@ func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bo
|
|||||||
for _, userItem := range itemList {
|
for _, userItem := range itemList {
|
||||||
pbItem := &proto.Item{
|
pbItem := &proto.Item{
|
||||||
ItemId: userItem.ItemId,
|
ItemId: userItem.ItemId,
|
||||||
Guid: player.GetItemGuid(userItem.ItemId),
|
Guid: dbItem.GetItemGuid(userItem.ItemId),
|
||||||
Detail: &proto.Item_Material{
|
Detail: &proto.Item_Material{
|
||||||
Material: &proto.Material{
|
Material: &proto.Material{
|
||||||
Count: player.GetItemCount(userItem.ItemId),
|
Count: dbItem.GetItemCount(player, userItem.ItemId),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -127,7 +128,7 @@ func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
|
func (g *GameManager) CostUserItem(userId uint32, itemList []*ChangeItem) {
|
||||||
player := USER_MANAGER.GetOnlineUser(userId)
|
player := USER_MANAGER.GetOnlineUser(userId)
|
||||||
if player == nil {
|
if player == nil {
|
||||||
logger.Error("player is nil, uid: %v", userId)
|
logger.Error("player is nil, uid: %v", userId)
|
||||||
@@ -136,6 +137,7 @@ func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
|
|||||||
playerPropNotify := &proto.PlayerPropNotify{
|
playerPropNotify := &proto.PlayerPropNotify{
|
||||||
PropMap: make(map[uint32]*proto.PropValue),
|
PropMap: make(map[uint32]*proto.PropValue),
|
||||||
}
|
}
|
||||||
|
dbItem := player.GetDbItem()
|
||||||
for _, userItem := range itemList {
|
for _, userItem := range itemList {
|
||||||
// 物品为虚拟物品则另外处理
|
// 物品为虚拟物品则另外处理
|
||||||
switch userItem.ItemId {
|
switch userItem.ItemId {
|
||||||
@@ -164,7 +166,7 @@ func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
|
|||||||
// 冒险阅历应该也没人会去扣吧?
|
// 冒险阅历应该也没人会去扣吧?
|
||||||
default:
|
default:
|
||||||
// 普通物品直接扣除
|
// 普通物品直接扣除
|
||||||
player.CostItem(userItem.ItemId, userItem.ChangeCount)
|
dbItem.CostItem(player, userItem.ItemId, userItem.ChangeCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(playerPropNotify.PropMap) > 0 {
|
if len(playerPropNotify.PropMap) > 0 {
|
||||||
@@ -176,13 +178,13 @@ func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
|
|||||||
ItemList: make([]*proto.Item, 0),
|
ItemList: make([]*proto.Item, 0),
|
||||||
}
|
}
|
||||||
for _, userItem := range itemList {
|
for _, userItem := range itemList {
|
||||||
count := player.GetItemCount(userItem.ItemId)
|
count := dbItem.GetItemCount(player, userItem.ItemId)
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pbItem := &proto.Item{
|
pbItem := &proto.Item{
|
||||||
ItemId: userItem.ItemId,
|
ItemId: userItem.ItemId,
|
||||||
Guid: player.GetItemGuid(userItem.ItemId),
|
Guid: dbItem.GetItemGuid(userItem.ItemId),
|
||||||
Detail: &proto.Item_Material{
|
Detail: &proto.Item_Material{
|
||||||
Material: &proto.Material{
|
Material: &proto.Material{
|
||||||
Count: count,
|
Count: count,
|
||||||
@@ -200,11 +202,11 @@ func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
|
|||||||
GuidList: make([]uint64, 0),
|
GuidList: make([]uint64, 0),
|
||||||
}
|
}
|
||||||
for _, userItem := range itemList {
|
for _, userItem := range itemList {
|
||||||
count := player.GetItemCount(userItem.ItemId)
|
count := dbItem.GetItemCount(player, userItem.ItemId)
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
storeItemDelNotify.GuidList = append(storeItemDelNotify.GuidList, player.GetItemGuid(userItem.ItemId))
|
storeItemDelNotify.GuidList = append(storeItemDelNotify.GuidList, dbItem.GetItemGuid(userItem.ItemId))
|
||||||
}
|
}
|
||||||
if len(storeItemDelNotify.GuidList) > 0 {
|
if len(storeItemDelNotify.GuidList) > 0 {
|
||||||
g.SendMsg(cmd.StoreItemDelNotify, userId, player.ClientSeq, storeItemDelNotify)
|
g.SendMsg(cmd.StoreItemDelNotify, userId, player.ClientSeq, storeItemDelNotify)
|
||||||
|
|||||||
@@ -56,7 +56,15 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u
|
|||||||
player.GateAppId = gateAppId
|
player.GateAppId = gateAppId
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
player.InitAll()
|
player.InitOnlineData()
|
||||||
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
dbAvatar.InitAllAvatar(player)
|
||||||
|
dbReliquary := player.GetDbReliquary()
|
||||||
|
dbReliquary.InitAllReliquary(player)
|
||||||
|
dbWeapon := player.GetDbWeapon()
|
||||||
|
dbWeapon.InitAllWeapon(player)
|
||||||
|
dbItem := player.GetDbItem()
|
||||||
|
dbItem.InitAllItem(player)
|
||||||
|
|
||||||
// 确保玩家位置安全
|
// 确保玩家位置安全
|
||||||
player.Pos.X = player.SafePos.X
|
player.Pos.X = player.SafePos.X
|
||||||
@@ -68,9 +76,6 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u
|
|||||||
player.Rot = &model.Vector{X: 0, Y: 307, Z: 0}
|
player.Rot = &model.Vector{X: 0, Y: 307, Z: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.CombatInvokeHandler = model.NewInvokeHandler[proto.CombatInvokeEntry]()
|
|
||||||
player.AbilityInvokeHandler = model.NewInvokeHandler[proto.AbilityInvokeEntry]()
|
|
||||||
|
|
||||||
if userId < PlayerBaseUid {
|
if userId < PlayerBaseUid {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -196,12 +201,15 @@ func (g *GameManager) PacketStoreWeightLimitNotify() *proto.StoreWeightLimitNoti
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreNotify {
|
func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreNotify {
|
||||||
|
dbItem := player.GetDbItem()
|
||||||
|
dbWeapon := player.GetDbWeapon()
|
||||||
|
dbReliquary := player.GetDbReliquary()
|
||||||
playerStoreNotify := &proto.PlayerStoreNotify{
|
playerStoreNotify := &proto.PlayerStoreNotify{
|
||||||
StoreType: proto.StoreType_STORE_PACK,
|
StoreType: proto.StoreType_STORE_PACK,
|
||||||
WeightLimit: constant.STORE_PACK_LIMIT_WEIGHT,
|
WeightLimit: constant.STORE_PACK_LIMIT_WEIGHT,
|
||||||
ItemList: make([]*proto.Item, 0, len(player.WeaponMap)+len(player.ReliquaryMap)+len(player.ItemMap)),
|
ItemList: make([]*proto.Item, 0, len(dbItem.ItemMap)+len(dbWeapon.WeaponMap)+len(dbReliquary.ReliquaryMap)),
|
||||||
}
|
}
|
||||||
for _, weapon := range player.WeaponMap {
|
for _, weapon := range dbWeapon.WeaponMap {
|
||||||
itemDataConfig := gdconf.GetItemDataById(int32(weapon.ItemId))
|
itemDataConfig := gdconf.GetItemDataById(int32(weapon.ItemId))
|
||||||
if itemDataConfig == nil {
|
if itemDataConfig == nil {
|
||||||
logger.Error("get item data config is nil, itemId: %v", weapon.ItemId)
|
logger.Error("get item data config is nil, itemId: %v", weapon.ItemId)
|
||||||
@@ -233,7 +241,7 @@ func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.Playe
|
|||||||
}
|
}
|
||||||
playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem)
|
playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem)
|
||||||
}
|
}
|
||||||
for _, reliquary := range player.ReliquaryMap {
|
for _, reliquary := range dbReliquary.ReliquaryMap {
|
||||||
itemDataConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
itemDataConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
||||||
if itemDataConfig == nil {
|
if itemDataConfig == nil {
|
||||||
logger.Error("get item data config is nil, itemId: %v", reliquary.ItemId)
|
logger.Error("get item data config is nil, itemId: %v", reliquary.ItemId)
|
||||||
@@ -262,7 +270,7 @@ func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.Playe
|
|||||||
}
|
}
|
||||||
playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem)
|
playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem)
|
||||||
}
|
}
|
||||||
for _, item := range player.ItemMap {
|
for _, item := range dbItem.ItemMap {
|
||||||
itemDataConfig := gdconf.GetItemDataById(int32(item.ItemId))
|
itemDataConfig := gdconf.GetItemDataById(int32(item.ItemId))
|
||||||
if itemDataConfig == nil {
|
if itemDataConfig == nil {
|
||||||
logger.Error("get item data config is nil, itemId: %v", item.ItemId)
|
logger.Error("get item data config is nil, itemId: %v", item.ItemId)
|
||||||
@@ -293,24 +301,25 @@ func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.Playe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) PacketAvatarDataNotify(player *model.Player) *proto.AvatarDataNotify {
|
func (g *GameManager) PacketAvatarDataNotify(player *model.Player) *proto.AvatarDataNotify {
|
||||||
chooseAvatarId := player.MainCharAvatarId
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
dbTeam := player.GetDbTeam()
|
||||||
avatarDataNotify := &proto.AvatarDataNotify{
|
avatarDataNotify := &proto.AvatarDataNotify{
|
||||||
CurAvatarTeamId: uint32(player.TeamConfig.GetActiveTeamId()),
|
CurAvatarTeamId: uint32(dbTeam.GetActiveTeamId()),
|
||||||
ChooseAvatarGuid: player.AvatarMap[chooseAvatarId].Guid,
|
ChooseAvatarGuid: dbAvatar.AvatarMap[dbAvatar.MainCharAvatarId].Guid,
|
||||||
OwnedFlycloakList: player.FlyCloakList,
|
OwnedFlycloakList: player.FlyCloakList,
|
||||||
// 角色衣装
|
// 角色衣装
|
||||||
OwnedCostumeList: player.CostumeList,
|
OwnedCostumeList: player.CostumeList,
|
||||||
AvatarList: make([]*proto.AvatarInfo, 0),
|
AvatarList: make([]*proto.AvatarInfo, 0),
|
||||||
AvatarTeamMap: make(map[uint32]*proto.AvatarTeam),
|
AvatarTeamMap: make(map[uint32]*proto.AvatarTeam),
|
||||||
}
|
}
|
||||||
for _, avatar := range player.AvatarMap {
|
for _, avatar := range dbAvatar.AvatarMap {
|
||||||
pbAvatar := g.PacketAvatarInfo(avatar)
|
pbAvatar := g.PacketAvatarInfo(avatar)
|
||||||
avatarDataNotify.AvatarList = append(avatarDataNotify.AvatarList, pbAvatar)
|
avatarDataNotify.AvatarList = append(avatarDataNotify.AvatarList, pbAvatar)
|
||||||
}
|
}
|
||||||
for teamIndex, team := range player.TeamConfig.TeamList {
|
for teamIndex, team := range dbTeam.TeamList {
|
||||||
var teamAvatarGuidList []uint64 = nil
|
var teamAvatarGuidList []uint64 = nil
|
||||||
for _, avatarId := range team.GetAvatarIdList() {
|
for _, avatarId := range team.GetAvatarIdList() {
|
||||||
teamAvatarGuidList = append(teamAvatarGuidList, player.AvatarMap[avatarId].Guid)
|
teamAvatarGuidList = append(teamAvatarGuidList, dbAvatar.AvatarMap[avatarId].Guid)
|
||||||
}
|
}
|
||||||
avatarDataNotify.AvatarTeamMap[uint32(teamIndex)+1] = &proto.AvatarTeam{
|
avatarDataNotify.AvatarTeamMap[uint32(teamIndex)+1] = &proto.AvatarTeam{
|
||||||
AvatarGuidList: teamAvatarGuidList,
|
AvatarGuidList: teamAvatarGuidList,
|
||||||
@@ -336,7 +345,6 @@ func (g *GameManager) CreatePlayer(userId uint32, nickName string, mainCharAvata
|
|||||||
player.PlayerID = userId
|
player.PlayerID = userId
|
||||||
player.NickName = nickName
|
player.NickName = nickName
|
||||||
player.Signature = ""
|
player.Signature = ""
|
||||||
player.MainCharAvatarId = mainCharAvatarId
|
|
||||||
player.HeadImage = mainCharAvatarId
|
player.HeadImage = mainCharAvatarId
|
||||||
player.Birthday = []uint8{0, 0}
|
player.Birthday = []uint8{0, 0}
|
||||||
player.NameCard = 210001
|
player.NameCard = 210001
|
||||||
@@ -368,29 +376,28 @@ func (g *GameManager) CreatePlayer(userId uint32, nickName string, mainCharAvata
|
|||||||
player.Pos = &model.Vector{X: 2747, Y: 194, Z: -1719}
|
player.Pos = &model.Vector{X: 2747, Y: 194, Z: -1719}
|
||||||
player.Rot = &model.Vector{X: 0, Y: 307, Z: 0}
|
player.Rot = &model.Vector{X: 0, Y: 307, Z: 0}
|
||||||
|
|
||||||
player.ItemMap = make(map[uint32]*model.Item)
|
dbAvatar := player.GetDbAvatar()
|
||||||
player.WeaponMap = make(map[uint64]*model.Weapon)
|
dbAvatar.MainCharAvatarId = mainCharAvatarId
|
||||||
player.ReliquaryMap = make(map[uint64]*model.Reliquary)
|
|
||||||
player.AvatarMap = make(map[uint32]*model.Avatar)
|
|
||||||
player.GameObjectGuidMap = make(map[uint64]model.GameObject)
|
player.GameObjectGuidMap = make(map[uint64]model.GameObject)
|
||||||
player.DropInfo = model.NewDropInfo()
|
|
||||||
player.GCGInfo = model.NewGCGInfo()
|
player.GCGInfo = model.NewGCGInfo()
|
||||||
|
|
||||||
// 添加选定的主角
|
// 添加选定的主角
|
||||||
player.AddAvatar(mainCharAvatarId)
|
dbAvatar.AddAvatar(player, mainCharAvatarId)
|
||||||
// 添加初始武器
|
// 添加主角初始武器
|
||||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(mainCharAvatarId))
|
avatarDataConfig := gdconf.GetAvatarDataById(int32(mainCharAvatarId))
|
||||||
if avatarDataConfig == nil {
|
if avatarDataConfig == nil {
|
||||||
logger.Error("config is nil, mainCharAvatarId: %v", mainCharAvatarId)
|
logger.Error("config is nil, mainCharAvatarId: %v", mainCharAvatarId)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
weaponId := uint64(g.snowflake.GenId())
|
weaponId := uint64(g.snowflake.GenId())
|
||||||
player.AddWeapon(uint32(avatarDataConfig.InitialWeapon), weaponId)
|
dbWeapon := player.GetDbWeapon()
|
||||||
// 角色装上初始武器
|
dbWeapon.AddWeapon(player, uint32(avatarDataConfig.InitialWeapon), weaponId)
|
||||||
player.WearWeapon(mainCharAvatarId, weaponId)
|
weapon := dbWeapon.WeaponMap[weaponId]
|
||||||
|
dbAvatar.WearWeapon(mainCharAvatarId, weapon)
|
||||||
|
|
||||||
player.TeamConfig = model.NewTeamInfo()
|
dbTeam := player.GetDbTeam()
|
||||||
player.TeamConfig.GetActiveTeam().SetAvatarIdList([]uint32{mainCharAvatarId})
|
dbTeam.GetActiveTeam().SetAvatarIdList([]uint32{mainCharAvatarId})
|
||||||
|
|
||||||
player.ChatMsgMap = make(map[uint32][]*model.ChatMsg)
|
player.ChatMsgMap = make(map[uint32][]*model.ChatMsg)
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,9 @@ func (g *GameManager) AddUserReliquary(userId uint32, itemId uint32) uint64 {
|
|||||||
// 圣遗物主属性
|
// 圣遗物主属性
|
||||||
mainPropId := uint32(reliquaryMainConfig.MainPropId)
|
mainPropId := uint32(reliquaryMainConfig.MainPropId)
|
||||||
// 玩家添加圣遗物
|
// 玩家添加圣遗物
|
||||||
player.AddReliquary(itemId, reliquaryId, mainPropId)
|
dbReliquary := player.GetDbReliquary()
|
||||||
reliquary := player.GetReliquary(reliquaryId)
|
dbReliquary.AddReliquary(player, itemId, reliquaryId, mainPropId)
|
||||||
|
reliquary := dbReliquary.GetReliquary(reliquaryId)
|
||||||
if reliquary == nil {
|
if reliquary == nil {
|
||||||
logger.Error("reliquary is nil, itemId: %v, reliquaryId: %v", itemId, reliquaryId)
|
logger.Error("reliquary is nil, itemId: %v, reliquaryId: %v", itemId, reliquaryId)
|
||||||
return 0
|
return 0
|
||||||
@@ -108,8 +109,9 @@ func (g *GameManager) CostUserReliquary(userId uint32, reliquaryIdList []uint64)
|
|||||||
GuidList: make([]uint64, 0, len(reliquaryIdList)),
|
GuidList: make([]uint64, 0, len(reliquaryIdList)),
|
||||||
StoreType: proto.StoreType_STORE_PACK,
|
StoreType: proto.StoreType_STORE_PACK,
|
||||||
}
|
}
|
||||||
|
dbReliquary := player.GetDbReliquary()
|
||||||
for _, reliquaryId := range reliquaryIdList {
|
for _, reliquaryId := range reliquaryIdList {
|
||||||
reliquaryGuid := player.CostReliquary(reliquaryId)
|
reliquaryGuid := dbReliquary.CostReliquary(player, reliquaryId)
|
||||||
if reliquaryGuid == 0 {
|
if reliquaryGuid == 0 {
|
||||||
logger.Error("reliquary cost error, reliquaryId: %v", reliquaryId)
|
logger.Error("reliquary cost error, reliquaryId: %v", reliquaryId)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -148,8 +148,9 @@ func (g *GameManager) SceneInitFinishReq(player *model.Player, payloadMsg pb.Mes
|
|||||||
},
|
},
|
||||||
AvatarEnterInfo: make([]*proto.AvatarEnterSceneInfo, 0),
|
AvatarEnterInfo: make([]*proto.AvatarEnterSceneInfo, 0),
|
||||||
}
|
}
|
||||||
|
dbAvatar := player.GetDbAvatar()
|
||||||
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
|
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
|
||||||
avatar := player.AvatarMap[worldAvatar.GetAvatarId()]
|
avatar := dbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
|
||||||
avatarEnterSceneInfo := &proto.AvatarEnterSceneInfo{
|
avatarEnterSceneInfo := &proto.AvatarEnterSceneInfo{
|
||||||
AvatarGuid: avatar.Guid,
|
AvatarGuid: avatar.Guid,
|
||||||
AvatarEntityId: world.GetPlayerWorldAvatarEntityId(player, worldAvatar.GetAvatarId()),
|
AvatarEntityId: world.GetPlayerWorldAvatarEntityId(player, worldAvatar.GetAvatarId()),
|
||||||
@@ -652,7 +653,8 @@ func (g *GameManager) PacketSceneEntityInfoAvatar(scene *Scene, player *model.Pl
|
|||||||
Z: float32(entity.GetPos().Z),
|
Z: float32(entity.GetPos().Z),
|
||||||
}
|
}
|
||||||
worldAvatar := scene.GetWorld().GetWorldAvatarByEntityId(entity.GetId())
|
worldAvatar := scene.GetWorld().GetWorldAvatarByEntityId(entity.GetId())
|
||||||
avatar, ok := player.AvatarMap[worldAvatar.GetAvatarId()]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar, ok := dbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("avatar error, avatarId: %v", worldAvatar.GetAvatarId())
|
logger.Error("avatar error, avatarId: %v", worldAvatar.GetAvatarId())
|
||||||
return new(proto.SceneEntityInfo)
|
return new(proto.SceneEntityInfo)
|
||||||
@@ -897,7 +899,8 @@ func (g *GameManager) PacketSceneEntityInfoGadget(scene *Scene, entityId uint32)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) PacketSceneAvatarInfo(scene *Scene, player *model.Player, avatarId uint32) *proto.SceneAvatarInfo {
|
func (g *GameManager) PacketSceneAvatarInfo(scene *Scene, player *model.Player, avatarId uint32) *proto.SceneAvatarInfo {
|
||||||
avatar, ok := player.AvatarMap[avatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar, ok := dbAvatar.AvatarMap[avatarId]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("avatar error, avatarId: %v", avatarId)
|
logger.Error("avatar error, avatarId: %v", avatarId)
|
||||||
return new(proto.SceneAvatarInfo)
|
return new(proto.SceneAvatarInfo)
|
||||||
|
|||||||
@@ -80,19 +80,20 @@ func (g *GameManager) BuyGoodsReq(player *model.Player, payloadMsg pb.Message) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if player.GetItemCount(201) < costHcoinCount {
|
dbItem := player.GetDbItem()
|
||||||
|
if dbItem.GetItemCount(player, 201) < costHcoinCount {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
g.CostUserItem(player.PlayerID, []*UserItem{{
|
g.CostUserItem(player.PlayerID, []*ChangeItem{{
|
||||||
ItemId: 201,
|
ItemId: 201,
|
||||||
ChangeCount: costHcoinCount,
|
ChangeCount: costHcoinCount,
|
||||||
}})
|
}})
|
||||||
|
|
||||||
g.AddUserItem(player.PlayerID, []*UserItem{{
|
g.AddUserItem(player.PlayerID, []*ChangeItem{{
|
||||||
ItemId: buyItemId,
|
ItemId: buyItemId,
|
||||||
ChangeCount: buyItemCount,
|
ChangeCount: buyItemCount,
|
||||||
}}, true, constant.ActionReasonShop)
|
}}, true, constant.ActionReasonShop)
|
||||||
req.Goods.BoughtNum = player.GetItemCount(buyItemId)
|
req.Goods.BoughtNum = dbItem.GetItemCount(player, buyItemId)
|
||||||
|
|
||||||
buyGoodsRsp := &proto.BuyGoodsRsp{
|
buyGoodsRsp := &proto.BuyGoodsRsp{
|
||||||
ShopType: req.ShopType,
|
ShopType: req.ShopType,
|
||||||
@@ -110,15 +111,16 @@ func (g *GameManager) McoinExchangeHcoinReq(player *model.Player, payloadMsg pb.
|
|||||||
}
|
}
|
||||||
count := req.Hcoin
|
count := req.Hcoin
|
||||||
|
|
||||||
if player.GetItemCount(203) < count {
|
dbItem := player.GetDbItem()
|
||||||
|
if dbItem.GetItemCount(player, 203) < count {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
g.CostUserItem(player.PlayerID, []*UserItem{{
|
g.CostUserItem(player.PlayerID, []*ChangeItem{{
|
||||||
ItemId: 203,
|
ItemId: 203,
|
||||||
ChangeCount: count,
|
ChangeCount: count,
|
||||||
}})
|
}})
|
||||||
|
|
||||||
g.AddUserItem(player.PlayerID, []*UserItem{{
|
g.AddUserItem(player.PlayerID, []*ChangeItem{{
|
||||||
ItemId: 201,
|
ItemId: 201,
|
||||||
ChangeCount: count,
|
ChangeCount: count,
|
||||||
}}, false, 0)
|
}}, false, 0)
|
||||||
|
|||||||
@@ -127,7 +127,8 @@ func (g *GameManager) SetPlayerHeadImageReq(player *model.Player, payloadMsg pb.
|
|||||||
logger.Debug("user change head image, uid: %v", player.PlayerID)
|
logger.Debug("user change head image, uid: %v", player.PlayerID)
|
||||||
req := payloadMsg.(*proto.SetPlayerHeadImageReq)
|
req := payloadMsg.(*proto.SetPlayerHeadImageReq)
|
||||||
avatarId := req.AvatarId
|
avatarId := req.AvatarId
|
||||||
_, exist := player.AvatarMap[avatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
_, exist := dbAvatar.AvatarMap[avatarId]
|
||||||
if !exist {
|
if !exist {
|
||||||
logger.Error("the head img of the avatar not exist, uid: %v", player.PlayerID)
|
logger.Error("the head img of the avatar not exist, uid: %v", player.PlayerID)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ func (g *GameManager) ChangeAvatarReq(player *model.Player, payloadMsg pb.Messag
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !world.GetMultiplayer() {
|
if !world.GetMultiplayer() {
|
||||||
player.TeamConfig.CurrAvatarIndex = uint8(newAvatarIndex)
|
dbTeam := player.GetDbTeam()
|
||||||
|
dbTeam.CurrAvatarIndex = uint8(newAvatarIndex)
|
||||||
}
|
}
|
||||||
world.SetPlayerAvatarIndex(player, newAvatarIndex)
|
world.SetPlayerAvatarIndex(player, newAvatarIndex)
|
||||||
oldAvatarEntityId := world.GetPlayerWorldAvatarEntityId(player, oldAvatarId)
|
oldAvatarEntityId := world.GetPlayerWorldAvatarEntityId(player, oldAvatarId)
|
||||||
@@ -89,31 +90,33 @@ func (g *GameManager) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Mes
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
avatarGuidList := req.AvatarTeamGuidList
|
avatarGuidList := req.AvatarTeamGuidList
|
||||||
selfTeam := teamId == uint32(player.TeamConfig.GetActiveTeamId())
|
dbTeam := player.GetDbTeam()
|
||||||
|
selfTeam := teamId == uint32(dbTeam.GetActiveTeamId())
|
||||||
if (selfTeam && len(avatarGuidList) == 0) || len(avatarGuidList) > 4 {
|
if (selfTeam && len(avatarGuidList) == 0) || len(avatarGuidList) > 4 {
|
||||||
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
|
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
avatarIdList := make([]uint32, 0)
|
avatarIdList := make([]uint32, 0)
|
||||||
|
dbAvatar := player.GetDbAvatar()
|
||||||
for _, avatarGuid := range avatarGuidList {
|
for _, avatarGuid := range avatarGuidList {
|
||||||
for avatarId, avatar := range player.AvatarMap {
|
for avatarId, avatar := range dbAvatar.AvatarMap {
|
||||||
if avatarGuid == avatar.Guid {
|
if avatarGuid == avatar.Guid {
|
||||||
avatarIdList = append(avatarIdList, avatarId)
|
avatarIdList = append(avatarIdList, avatarId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.TeamConfig.GetTeamByIndex(uint8(teamId - 1)).SetAvatarIdList(avatarIdList)
|
dbTeam.GetTeamByIndex(uint8(teamId - 1)).SetAvatarIdList(avatarIdList)
|
||||||
|
|
||||||
avatarTeamUpdateNotify := &proto.AvatarTeamUpdateNotify{
|
avatarTeamUpdateNotify := &proto.AvatarTeamUpdateNotify{
|
||||||
AvatarTeamMap: make(map[uint32]*proto.AvatarTeam),
|
AvatarTeamMap: make(map[uint32]*proto.AvatarTeam),
|
||||||
}
|
}
|
||||||
for teamIndex, team := range player.TeamConfig.TeamList {
|
for teamIndex, team := range dbTeam.TeamList {
|
||||||
avatarTeam := &proto.AvatarTeam{
|
avatarTeam := &proto.AvatarTeam{
|
||||||
TeamName: team.Name,
|
TeamName: team.Name,
|
||||||
AvatarGuidList: make([]uint64, 0),
|
AvatarGuidList: make([]uint64, 0),
|
||||||
}
|
}
|
||||||
for _, avatarId := range team.GetAvatarIdList() {
|
for _, avatarId := range team.GetAvatarIdList() {
|
||||||
avatarTeam.AvatarGuidList = append(avatarTeam.AvatarGuidList, player.AvatarMap[avatarId].Guid)
|
avatarTeam.AvatarGuidList = append(avatarTeam.AvatarGuidList, dbAvatar.AvatarMap[avatarId].Guid)
|
||||||
}
|
}
|
||||||
avatarTeamUpdateNotify.AvatarTeamMap[uint32(teamIndex)+1] = avatarTeam
|
avatarTeamUpdateNotify.AvatarTeamMap[uint32(teamIndex)+1] = avatarTeam
|
||||||
}
|
}
|
||||||
@@ -133,7 +136,7 @@ func (g *GameManager) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Mes
|
|||||||
}
|
}
|
||||||
currAvatarId := currAvatar.AvatarId
|
currAvatarId := currAvatar.AvatarId
|
||||||
currAvatarIndex := world.GetPlayerAvatarIndexByAvatarId(player, currAvatarId)
|
currAvatarIndex := world.GetPlayerAvatarIndexByAvatarId(player, currAvatarId)
|
||||||
player.TeamConfig.CurrAvatarIndex = uint8(currAvatarIndex)
|
dbTeam.CurrAvatarIndex = uint8(currAvatarIndex)
|
||||||
world.SetPlayerAvatarIndex(player, currAvatarIndex)
|
world.SetPlayerAvatarIndex(player, currAvatarIndex)
|
||||||
|
|
||||||
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world)
|
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world)
|
||||||
@@ -157,12 +160,13 @@ func (g *GameManager) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb
|
|||||||
g.SendError(cmd.ChooseCurAvatarTeamRsp, player, &proto.ChooseCurAvatarTeamRsp{})
|
g.SendError(cmd.ChooseCurAvatarTeamRsp, player, &proto.ChooseCurAvatarTeamRsp{})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
team := player.TeamConfig.GetTeamByIndex(uint8(teamId) - 1)
|
dbTeam := player.GetDbTeam()
|
||||||
|
team := dbTeam.GetTeamByIndex(uint8(teamId) - 1)
|
||||||
if team == nil || len(team.GetAvatarIdList()) == 0 {
|
if team == nil || len(team.GetAvatarIdList()) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
player.TeamConfig.CurrTeamIndex = uint8(teamId) - 1
|
dbTeam.CurrTeamIndex = uint8(teamId) - 1
|
||||||
player.TeamConfig.CurrAvatarIndex = 0
|
dbTeam.CurrAvatarIndex = 0
|
||||||
// player.TeamConfig.UpdateTeam()
|
// player.TeamConfig.UpdateTeam()
|
||||||
world.SetPlayerAvatarIndex(player, 0)
|
world.SetPlayerAvatarIndex(player, 0)
|
||||||
world.SetPlayerLocalTeam(player, team.GetAvatarIdList())
|
world.SetPlayerLocalTeam(player, team.GetAvatarIdList())
|
||||||
@@ -239,7 +243,8 @@ func (g *GameManager) PacketSceneTeamUpdateNotify(world *World) *proto.SceneTeam
|
|||||||
logger.Error("scene is nil, sceneId: %v", worldPlayer.SceneId)
|
logger.Error("scene is nil, sceneId: %v", worldPlayer.SceneId)
|
||||||
return new(proto.SceneTeamUpdateNotify)
|
return new(proto.SceneTeamUpdateNotify)
|
||||||
}
|
}
|
||||||
worldPlayerAvatar := worldPlayer.AvatarMap[worldAvatar.GetAvatarId()]
|
worldPlayerDbAvatar := worldPlayer.GetDbAvatar()
|
||||||
|
worldPlayerAvatar := worldPlayerDbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
|
||||||
equipIdList := make([]uint32, 0)
|
equipIdList := make([]uint32, 0)
|
||||||
weapon := worldPlayerAvatar.EquipWeapon
|
weapon := worldPlayerAvatar.EquipWeapon
|
||||||
equipIdList = append(equipIdList, weapon.ItemId)
|
equipIdList = append(equipIdList, weapon.ItemId)
|
||||||
|
|||||||
@@ -114,7 +114,9 @@ func (g *GameManager) DestroyVehicleEntity(player *model.Player, scene *Scene, v
|
|||||||
// 如果玩家正在载具中
|
// 如果玩家正在载具中
|
||||||
if g.IsPlayerInVehicle(player, gadgetEntity.GetGadgetVehicleEntity()) {
|
if g.IsPlayerInVehicle(player, gadgetEntity.GetGadgetVehicleEntity()) {
|
||||||
// 离开载具
|
// 离开载具
|
||||||
g.ExitVehicle(player, entity, player.AvatarMap[player.TeamConfig.GetActiveAvatarId()].Guid)
|
dbTeam := player.GetDbTeam()
|
||||||
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
g.ExitVehicle(player, entity, dbAvatar.AvatarMap[dbTeam.GetActiveAvatarId()].Guid)
|
||||||
}
|
}
|
||||||
// 删除已创建的载具
|
// 删除已创建的载具
|
||||||
scene.DestroyEntity(entity.GetId())
|
scene.DestroyEntity(entity.GetId())
|
||||||
@@ -220,7 +222,9 @@ func (g *GameManager) VehicleInteractReq(player *model.Player, payloadMsg pb.Mes
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
avatarGuid := player.AvatarMap[player.TeamConfig.GetActiveAvatarId()].Guid
|
dbTeam := player.GetDbTeam()
|
||||||
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatarGuid := dbAvatar.AvatarMap[dbTeam.GetActiveAvatarId()].Guid
|
||||||
|
|
||||||
switch req.InteractType {
|
switch req.InteractType {
|
||||||
case proto.VehicleInteractType_VEHICLE_INTERACT_IN:
|
case proto.VehicleInteractType_VEHICLE_INTERACT_IN:
|
||||||
|
|||||||
@@ -50,8 +50,9 @@ func (g *GameManager) AddUserWeapon(userId uint32, itemId uint32) uint64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
weaponId := uint64(g.snowflake.GenId())
|
weaponId := uint64(g.snowflake.GenId())
|
||||||
player.AddWeapon(itemId, weaponId)
|
dbWeapon := player.GetDbWeapon()
|
||||||
weapon := player.GetWeapon(weaponId)
|
dbWeapon.AddWeapon(player, itemId, weaponId)
|
||||||
|
weapon := dbWeapon.GetWeapon(weaponId)
|
||||||
if weapon == nil {
|
if weapon == nil {
|
||||||
logger.Error("weapon is nil, itemId: %v, weaponId: %v", itemId, weaponId)
|
logger.Error("weapon is nil, itemId: %v, weaponId: %v", itemId, weaponId)
|
||||||
return 0
|
return 0
|
||||||
@@ -70,8 +71,9 @@ func (g *GameManager) CostUserWeapon(userId uint32, weaponIdList []uint64) {
|
|||||||
GuidList: make([]uint64, 0, len(weaponIdList)),
|
GuidList: make([]uint64, 0, len(weaponIdList)),
|
||||||
StoreType: proto.StoreType_STORE_PACK,
|
StoreType: proto.StoreType_STORE_PACK,
|
||||||
}
|
}
|
||||||
|
dbWeapon := player.GetDbWeapon()
|
||||||
for _, weaponId := range weaponIdList {
|
for _, weaponId := range weaponIdList {
|
||||||
weaponGuid := player.CostWeapon(weaponId)
|
weaponGuid := dbWeapon.CostWeapon(player, weaponId)
|
||||||
if weaponGuid == 0 {
|
if weaponGuid == 0 {
|
||||||
logger.Error("weapon cost error, weaponId: %v", weaponId)
|
logger.Error("weapon cost error, weaponId: %v", weaponId)
|
||||||
return
|
return
|
||||||
@@ -142,7 +144,8 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 摩拉数量是否足够
|
// 摩拉数量是否足够
|
||||||
if player.GetItemCount(constant.ITEM_ID_SCOIN) < weaponConfig.AwakenCoinCostList[weapon.Refinement] {
|
dbItem := player.GetDbItem()
|
||||||
|
if dbItem.GetItemCount(player, constant.ITEM_ID_SCOIN) < weaponConfig.AwakenCoinCostList[weapon.Refinement] {
|
||||||
logger.Error("item count not enough, itemId: %v", constant.ITEM_ID_SCOIN)
|
logger.Error("item count not enough, itemId: %v", constant.ITEM_ID_SCOIN)
|
||||||
g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_SCOIN_NOT_ENOUGH)
|
g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_SCOIN_NOT_ENOUGH)
|
||||||
return
|
return
|
||||||
@@ -224,7 +227,7 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 消耗作为精炼材料的道具
|
// 消耗作为精炼材料的道具
|
||||||
g.CostUserItem(player.PlayerID, []*UserItem{
|
g.CostUserItem(player.PlayerID, []*ChangeItem{
|
||||||
{
|
{
|
||||||
ItemId: item.ItemId,
|
ItemId: item.ItemId,
|
||||||
ChangeCount: 1,
|
ChangeCount: 1,
|
||||||
@@ -236,7 +239,7 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 消耗摩拉
|
// 消耗摩拉
|
||||||
g.CostUserItem(player.PlayerID, []*UserItem{
|
g.CostUserItem(player.PlayerID, []*ChangeItem{
|
||||||
{
|
{
|
||||||
ItemId: constant.ITEM_ID_SCOIN,
|
ItemId: constant.ITEM_ID_SCOIN,
|
||||||
ChangeCount: weaponConfig.AwakenCoinCostList[weapon.Refinement],
|
ChangeCount: weaponConfig.AwakenCoinCostList[weapon.Refinement],
|
||||||
@@ -260,7 +263,8 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
|
|||||||
// 更新武器的物品数据
|
// 更新武器的物品数据
|
||||||
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerID, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
|
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerID, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
|
||||||
// 获取持有该武器的角色
|
// 获取持有该武器的角色
|
||||||
avatar, ok := player.AvatarMap[weapon.AvatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||||
// 武器可能没被任何角色装备 仅在被装备时更新面板
|
// 武器可能没被任何角色装备 仅在被装备时更新面板
|
||||||
if ok {
|
if ok {
|
||||||
weaponAwakenRsp.AvatarGuid = avatar.Guid
|
weaponAwakenRsp.AvatarGuid = avatar.Guid
|
||||||
@@ -315,22 +319,23 @@ func (g *GameManager) WeaponPromoteReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 将被消耗的物品列表
|
// 将被消耗的物品列表
|
||||||
costItemList := make([]*UserItem, 0, len(weaponPromoteConfig.CostItemMap)+1)
|
costItemList := make([]*ChangeItem, 0, len(weaponPromoteConfig.CostItemMap)+1)
|
||||||
// 突破材料是否足够并添加到消耗物品列表
|
// 突破材料是否足够并添加到消耗物品列表
|
||||||
for itemId, count := range weaponPromoteConfig.CostItemMap {
|
for itemId, count := range weaponPromoteConfig.CostItemMap {
|
||||||
costItemList = append(costItemList, &UserItem{
|
costItemList = append(costItemList, &ChangeItem{
|
||||||
ItemId: itemId,
|
ItemId: itemId,
|
||||||
ChangeCount: count,
|
ChangeCount: count,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 消耗列表添加摩拉的消耗
|
// 消耗列表添加摩拉的消耗
|
||||||
costItemList = append(costItemList, &UserItem{
|
costItemList = append(costItemList, &ChangeItem{
|
||||||
ItemId: constant.ITEM_ID_SCOIN,
|
ItemId: constant.ITEM_ID_SCOIN,
|
||||||
ChangeCount: uint32(weaponPromoteConfig.CostCoin),
|
ChangeCount: uint32(weaponPromoteConfig.CostCoin),
|
||||||
})
|
})
|
||||||
// 突破材料以及摩拉是否足够
|
// 突破材料以及摩拉是否足够
|
||||||
|
dbItem := player.GetDbItem()
|
||||||
for _, item := range costItemList {
|
for _, item := range costItemList {
|
||||||
if player.GetItemCount(item.ItemId) < item.ChangeCount {
|
if dbItem.GetItemCount(player, item.ItemId) < item.ChangeCount {
|
||||||
logger.Error("item count not enough, itemId: %v", item.ItemId)
|
logger.Error("item count not enough, itemId: %v", item.ItemId)
|
||||||
// 摩拉的错误提示与材料不同
|
// 摩拉的错误提示与材料不同
|
||||||
if item.ItemId == constant.ITEM_ID_SCOIN {
|
if item.ItemId == constant.ITEM_ID_SCOIN {
|
||||||
@@ -357,7 +362,8 @@ func (g *GameManager) WeaponPromoteReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
// 更新武器的物品数据
|
// 更新武器的物品数据
|
||||||
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerID, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
|
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerID, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
|
||||||
// 获取持有该武器的角色
|
// 获取持有该武器的角色
|
||||||
avatar, ok := player.AvatarMap[weapon.AvatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||||
// 武器可能没被任何角色装备 仅在被装备时更新面板
|
// 武器可能没被任何角色装备 仅在被装备时更新面板
|
||||||
if ok {
|
if ok {
|
||||||
// 角色更新面板
|
// 角色更新面板
|
||||||
@@ -576,10 +582,10 @@ func (g *GameManager) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 将被消耗的物品列表
|
// 将被消耗的物品列表
|
||||||
costItemList := make([]*UserItem, 0, len(req.ItemParamList)+1)
|
costItemList := make([]*ChangeItem, 0, len(req.ItemParamList)+1)
|
||||||
// 突破材料是否足够并添加到消耗物品列表
|
// 突破材料是否足够并添加到消耗物品列表
|
||||||
for _, itemParam := range req.ItemParamList {
|
for _, itemParam := range req.ItemParamList {
|
||||||
costItemList = append(costItemList, &UserItem{
|
costItemList = append(costItemList, &ChangeItem{
|
||||||
ItemId: itemParam.ItemId,
|
ItemId: itemParam.ItemId,
|
||||||
ChangeCount: itemParam.Count,
|
ChangeCount: itemParam.Count,
|
||||||
})
|
})
|
||||||
@@ -592,13 +598,14 @@ func (g *GameManager) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 消耗列表添加摩拉的消耗
|
// 消耗列表添加摩拉的消耗
|
||||||
costItemList = append(costItemList, &UserItem{
|
costItemList = append(costItemList, &ChangeItem{
|
||||||
ItemId: constant.ITEM_ID_SCOIN,
|
ItemId: constant.ITEM_ID_SCOIN,
|
||||||
ChangeCount: coinCost,
|
ChangeCount: coinCost,
|
||||||
})
|
})
|
||||||
// 校验物品是否足够
|
// 校验物品是否足够
|
||||||
|
dbItem := player.GetDbItem()
|
||||||
for _, item := range costItemList {
|
for _, item := range costItemList {
|
||||||
if player.GetItemCount(item.ItemId) < item.ChangeCount {
|
if dbItem.GetItemCount(player, item.ItemId) < item.ChangeCount {
|
||||||
logger.Error("item count not enough, itemId: %v", item.ItemId)
|
logger.Error("item count not enough, itemId: %v", item.ItemId)
|
||||||
// 摩拉的错误提示与材料不同
|
// 摩拉的错误提示与材料不同
|
||||||
if item.ItemId == constant.ITEM_ID_SCOIN {
|
if item.ItemId == constant.ITEM_ID_SCOIN {
|
||||||
@@ -652,7 +659,8 @@ func (g *GameManager) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerID, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
|
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerID, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
|
||||||
|
|
||||||
// 获取持有该武器的角色
|
// 获取持有该武器的角色
|
||||||
avatar, ok := player.AvatarMap[weapon.AvatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||||
// 武器可能没被任何角色装备 仅在被装备时更新面板
|
// 武器可能没被任何角色装备 仅在被装备时更新面板
|
||||||
if ok {
|
if ok {
|
||||||
// 角色更新面板
|
// 角色更新面板
|
||||||
@@ -660,9 +668,9 @@ func (g *GameManager) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 将给予的材料列表
|
// 将给予的材料列表
|
||||||
addItemList := make([]*UserItem, 0, len(returnItemList))
|
addItemList := make([]*ChangeItem, 0, len(returnItemList))
|
||||||
for _, param := range returnItemList {
|
for _, param := range returnItemList {
|
||||||
addItemList = append(addItemList, &UserItem{
|
addItemList = append(addItemList, &ChangeItem{
|
||||||
ItemId: param.ItemId,
|
ItemId: param.ItemId,
|
||||||
ChangeCount: param.Count,
|
ChangeCount: param.Count,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -194,19 +194,19 @@ func (t *TickManager) onTickMinute(now int64) {
|
|||||||
i := int32(0)
|
i := int32(0)
|
||||||
for itemId := range allItemDataConfig {
|
for itemId := range allItemDataConfig {
|
||||||
num := random.GetRandomInt32(1, 9)
|
num := random.GetRandomInt32(1, 9)
|
||||||
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: uint32(itemId), ChangeCount: uint32(num)}}, true, 0)
|
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: uint32(itemId), ChangeCount: uint32(num)}}, true, 0)
|
||||||
i++
|
i++
|
||||||
if i > count {
|
if i > count {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 102, ChangeCount: 30}}, true, 0)
|
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 102, ChangeCount: 30}}, true, 0)
|
||||||
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 201, ChangeCount: 10}}, true, 0)
|
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 201, ChangeCount: 10}}, true, 0)
|
||||||
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 202, ChangeCount: 100}}, true, 0)
|
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 202, ChangeCount: 100}}, true, 0)
|
||||||
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 203, ChangeCount: 10}}, true, 0)
|
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 203, ChangeCount: 10}}, true, 0)
|
||||||
// 蓝球粉球
|
// 蓝球粉球
|
||||||
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 223, ChangeCount: 1}}, true, 0)
|
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 223, ChangeCount: 1}}, true, 0)
|
||||||
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 224, ChangeCount: 1}}, true, 0)
|
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 224, ChangeCount: 1}}, true, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -309,11 +309,12 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) {
|
|||||||
w.peerList = append(w.peerList, player)
|
w.peerList = append(w.peerList, player)
|
||||||
w.playerMap[player.PlayerID] = player
|
w.playerMap[player.PlayerID] = player
|
||||||
// 将玩家自身当前的队伍角色信息复制到世界的玩家本地队伍
|
// 将玩家自身当前的队伍角色信息复制到世界的玩家本地队伍
|
||||||
team := player.TeamConfig.GetActiveTeam()
|
dbTeam := player.GetDbTeam()
|
||||||
|
team := dbTeam.GetActiveTeam()
|
||||||
if player.PlayerID == w.owner.PlayerID {
|
if player.PlayerID == w.owner.PlayerID {
|
||||||
w.SetPlayerLocalTeam(player, team.GetAvatarIdList())
|
w.SetPlayerLocalTeam(player, team.GetAvatarIdList())
|
||||||
} else {
|
} else {
|
||||||
activeAvatarId := player.TeamConfig.GetActiveAvatarId()
|
activeAvatarId := dbTeam.GetActiveAvatarId()
|
||||||
w.SetPlayerLocalTeam(player, []uint32{activeAvatarId})
|
w.SetPlayerLocalTeam(player, []uint32{activeAvatarId})
|
||||||
}
|
}
|
||||||
playerNum := w.GetWorldPlayerNum()
|
playerNum := w.GetWorldPlayerNum()
|
||||||
@@ -328,7 +329,8 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) {
|
|||||||
for _, worldPlayer := range w.playerMap {
|
for _, worldPlayer := range w.playerMap {
|
||||||
list := w.GetPlayerWorldAvatarList(worldPlayer)
|
list := w.GetPlayerWorldAvatarList(worldPlayer)
|
||||||
maxIndex := len(list) - 1
|
maxIndex := len(list) - 1
|
||||||
index := int(worldPlayer.TeamConfig.CurrAvatarIndex)
|
worldPlayerDbTeam := worldPlayer.GetDbTeam()
|
||||||
|
index := int(worldPlayerDbTeam.CurrAvatarIndex)
|
||||||
if index > maxIndex {
|
if index > maxIndex {
|
||||||
w.SetPlayerAvatarIndex(worldPlayer, 0)
|
w.SetPlayerAvatarIndex(worldPlayer, 0)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ func (s *Scene) SetEntityLifeState(entity *Entity, lifeState uint16, dieType pro
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 获取角色
|
// 获取角色
|
||||||
avatar, ok := player.AvatarMap[entity.avatarEntity.avatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar, ok := dbAvatar.AvatarMap[entity.avatarEntity.avatarId]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("avatar is nil, avatarId: %v", avatar)
|
logger.Error("avatar is nil, avatarId: %v", avatar)
|
||||||
return
|
return
|
||||||
@@ -139,7 +140,8 @@ func (s *Scene) SetEntityLifeState(entity *Entity, lifeState uint16, dieType pro
|
|||||||
|
|
||||||
func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32 {
|
func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32 {
|
||||||
entityId := s.world.GetNextWorldEntityId(constant.ENTITY_ID_TYPE_AVATAR)
|
entityId := s.world.GetNextWorldEntityId(constant.ENTITY_ID_TYPE_AVATAR)
|
||||||
avatar, ok := player.AvatarMap[avatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar, ok := dbAvatar.AvatarMap[avatarId]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("avatar error, avatarId: %v", avatar)
|
logger.Error("avatar error, avatarId: %v", avatar)
|
||||||
return 0
|
return 0
|
||||||
@@ -153,7 +155,7 @@ func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32
|
|||||||
moveState: uint16(proto.MotionState_MOTION_NONE),
|
moveState: uint16(proto.MotionState_MOTION_NONE),
|
||||||
lastMoveSceneTimeMs: 0,
|
lastMoveSceneTimeMs: 0,
|
||||||
lastMoveReliableSeq: 0,
|
lastMoveReliableSeq: 0,
|
||||||
fightProp: player.AvatarMap[avatarId].FightPropMap, // 使用角色结构的数据
|
fightProp: dbAvatar.AvatarMap[avatarId].FightPropMap, // 使用角色结构的数据
|
||||||
entityType: uint32(proto.ProtEntityType_PROT_ENTITY_AVATAR),
|
entityType: uint32(proto.ProtEntityType_PROT_ENTITY_AVATAR),
|
||||||
avatarEntity: &AvatarEntity{
|
avatarEntity: &AvatarEntity{
|
||||||
uid: player.PlayerID,
|
uid: player.PlayerID,
|
||||||
@@ -169,7 +171,7 @@ func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32
|
|||||||
EntityId: entity.id,
|
EntityId: entity.id,
|
||||||
FightPropMap: entity.fightProp,
|
FightPropMap: entity.fightProp,
|
||||||
Uid: entity.avatarEntity.uid,
|
Uid: entity.avatarEntity.uid,
|
||||||
AvatarGuid: player.AvatarMap[avatarId].Guid,
|
AvatarGuid: dbAvatar.AvatarMap[avatarId].Guid,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return entity.id
|
return entity.id
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ type ChatMsg struct {
|
|||||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||||
Sequence uint32 `bson:"-"`
|
Sequence uint32 `bson:"-"`
|
||||||
Time uint32 `bson:"Time"`
|
Time uint32 `bson:"Time"`
|
||||||
ToUid uint32 `bson:"ToUid"`
|
|
||||||
Uid uint32 `bson:"Uid"`
|
Uid uint32 `bson:"Uid"`
|
||||||
|
ToUid uint32 `bson:"ToUid"`
|
||||||
IsRead bool `bson:"IsRead"`
|
IsRead bool `bson:"IsRead"`
|
||||||
MsgType uint8 `bson:"MsgType"`
|
MsgType uint8 `bson:"MsgType"`
|
||||||
Text string `bson:"Text"`
|
Text string `bson:"Text"`
|
||||||
@@ -8,6 +8,20 @@ import (
|
|||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type DbAvatar struct {
|
||||||
|
AvatarMap map[uint32]*Avatar // 角色列表
|
||||||
|
MainCharAvatarId uint32 // 主角id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) GetDbAvatar() *DbAvatar {
|
||||||
|
if p.DbAvatar == nil {
|
||||||
|
p.DbAvatar = &DbAvatar{
|
||||||
|
AvatarMap: make(map[uint32]*Avatar),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p.DbAvatar
|
||||||
|
}
|
||||||
|
|
||||||
type Avatar struct {
|
type Avatar struct {
|
||||||
AvatarId uint32 // 角色id
|
AvatarId uint32 // 角色id
|
||||||
LifeState uint16 // 存活状态
|
LifeState uint16 // 存活状态
|
||||||
@@ -35,26 +49,26 @@ type Avatar struct {
|
|||||||
ExtraAbilityEmbryos map[string]bool `bson:"-" msgpack:"-"`
|
ExtraAbilityEmbryos map[string]bool `bson:"-" msgpack:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) InitAllAvatar() {
|
func (a *DbAvatar) InitAllAvatar(player *Player) {
|
||||||
for _, avatar := range p.AvatarMap {
|
for _, avatar := range a.AvatarMap {
|
||||||
p.InitAvatar(avatar)
|
a.InitAvatar(player, avatar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) InitAvatar(avatar *Avatar) {
|
func (a *DbAvatar) InitAvatar(player *Player, avatar *Avatar) {
|
||||||
// 角色战斗属性
|
// 角色战斗属性
|
||||||
p.InitAvatarFightProp(avatar)
|
a.InitAvatarFightProp(avatar)
|
||||||
// guid
|
// guid
|
||||||
avatar.Guid = p.GetNextGameObjectGuid()
|
avatar.Guid = player.GetNextGameObjectGuid()
|
||||||
p.GameObjectGuidMap[avatar.Guid] = GameObject(avatar)
|
player.GameObjectGuidMap[avatar.Guid] = GameObject(avatar)
|
||||||
avatar.EquipGuidMap = make(map[uint64]uint64)
|
avatar.EquipGuidMap = make(map[uint64]uint64)
|
||||||
avatar.EquipReliquaryMap = make(map[uint8]*Reliquary)
|
avatar.EquipReliquaryMap = make(map[uint8]*Reliquary)
|
||||||
p.AvatarMap[avatar.AvatarId] = avatar
|
a.AvatarMap[avatar.AvatarId] = avatar
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitAvatarFightProp 初始化角色面板
|
// InitAvatarFightProp 初始化角色面板
|
||||||
func (p *Player) InitAvatarFightProp(avatar *Avatar) {
|
func (a *DbAvatar) InitAvatarFightProp(avatar *Avatar) {
|
||||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatar.AvatarId))
|
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatar.AvatarId))
|
||||||
if avatarDataConfig == nil {
|
if avatarDataConfig == nil {
|
||||||
logger.Error("avatarDataConfig error, avatarId: %v", avatar.AvatarId)
|
logger.Error("avatarDataConfig error, avatarId: %v", avatar.AvatarId)
|
||||||
@@ -77,10 +91,10 @@ func (p *Player) InitAvatarFightProp(avatar *Avatar) {
|
|||||||
avatar.FightPropMap[uint32(constant.FIGHT_PROP_CRITICAL_HURT)] = float32(avatarDataConfig.CriticalHurt)
|
avatar.FightPropMap[uint32(constant.FIGHT_PROP_CRITICAL_HURT)] = float32(avatarDataConfig.CriticalHurt)
|
||||||
// 元素充能
|
// 元素充能
|
||||||
avatar.FightPropMap[uint32(constant.FIGHT_PROP_CHARGE_EFFICIENCY)] = 1.0
|
avatar.FightPropMap[uint32(constant.FIGHT_PROP_CHARGE_EFFICIENCY)] = 1.0
|
||||||
p.SetCurrEnergy(avatar, avatar.CurrEnergy, true)
|
a.SetCurrEnergy(avatar, avatar.CurrEnergy, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) AddAvatar(avatarId uint32) {
|
func (a *DbAvatar) AddAvatar(player *Player, avatarId uint32) {
|
||||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatarId))
|
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatarId))
|
||||||
if avatarDataConfig == nil {
|
if avatarDataConfig == nil {
|
||||||
logger.Error("avatar data config is nil, avatarId: %v", avatarId)
|
logger.Error("avatar data config is nil, avatarId: %v", avatarId)
|
||||||
@@ -140,11 +154,11 @@ func (p *Player) AddAvatar(avatarId uint32) {
|
|||||||
avatar.PromoteRewardMap[promoteLevel] = false
|
avatar.PromoteRewardMap[promoteLevel] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
p.InitAvatar(avatar)
|
a.InitAvatar(player, avatar)
|
||||||
p.AvatarMap[avatarId] = avatar
|
a.AvatarMap[avatarId] = avatar
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) SetCurrEnergy(avatar *Avatar, value float64, max bool) {
|
func (a *DbAvatar) SetCurrEnergy(avatar *Avatar, value float64, max bool) {
|
||||||
var avatarSkillDataConfig *gdconf.AvatarSkillData = nil
|
var avatarSkillDataConfig *gdconf.AvatarSkillData = nil
|
||||||
if avatar.AvatarId == 10000005 || avatar.AvatarId == 10000007 {
|
if avatar.AvatarId == 10000005 || avatar.AvatarId == 10000007 {
|
||||||
avatarSkillDepotDataConfig := gdconf.GetAvatarSkillDepotDataById(int32(avatar.SkillDepotId))
|
avatarSkillDepotDataConfig := gdconf.GetAvatarSkillDepotDataById(int32(avatar.SkillDepotId))
|
||||||
@@ -175,9 +189,8 @@ func (p *Player) SetCurrEnergy(avatar *Avatar, value float64, max bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) WearReliquary(avatarId uint32, reliquaryId uint64) {
|
func (a *DbAvatar) WearReliquary(avatarId uint32, reliquary *Reliquary) {
|
||||||
avatar := p.AvatarMap[avatarId]
|
avatar := a.AvatarMap[avatarId]
|
||||||
reliquary := p.ReliquaryMap[reliquaryId]
|
|
||||||
reliquaryConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
reliquaryConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
||||||
if reliquaryConfig == nil {
|
if reliquaryConfig == nil {
|
||||||
logger.Error("reliquary config error, itemId: %v", reliquary.ItemId)
|
logger.Error("reliquary config error, itemId: %v", reliquary.ItemId)
|
||||||
@@ -188,9 +201,8 @@ func (p *Player) WearReliquary(avatarId uint32, reliquaryId uint64) {
|
|||||||
avatar.EquipGuidMap[reliquary.Guid] = reliquary.Guid
|
avatar.EquipGuidMap[reliquary.Guid] = reliquary.Guid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) TakeOffReliquary(avatarId uint32, reliquaryId uint64) {
|
func (a *DbAvatar) TakeOffReliquary(avatarId uint32, reliquary *Reliquary) {
|
||||||
avatar := p.AvatarMap[avatarId]
|
avatar := a.AvatarMap[avatarId]
|
||||||
reliquary := p.ReliquaryMap[reliquaryId]
|
|
||||||
reliquaryConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
reliquaryConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
||||||
if reliquaryConfig == nil {
|
if reliquaryConfig == nil {
|
||||||
logger.Error("reliquary config error, itemId: %v", reliquary.ItemId)
|
logger.Error("reliquary config error, itemId: %v", reliquary.ItemId)
|
||||||
@@ -201,17 +213,15 @@ func (p *Player) TakeOffReliquary(avatarId uint32, reliquaryId uint64) {
|
|||||||
delete(avatar.EquipGuidMap, reliquary.Guid)
|
delete(avatar.EquipGuidMap, reliquary.Guid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) WearWeapon(avatarId uint32, weaponId uint64) {
|
func (a *DbAvatar) WearWeapon(avatarId uint32, weapon *Weapon) {
|
||||||
avatar := p.AvatarMap[avatarId]
|
avatar := a.AvatarMap[avatarId]
|
||||||
weapon := p.WeaponMap[weaponId]
|
|
||||||
avatar.EquipWeapon = weapon
|
avatar.EquipWeapon = weapon
|
||||||
weapon.AvatarId = avatarId
|
weapon.AvatarId = avatarId
|
||||||
avatar.EquipGuidMap[weapon.Guid] = weapon.Guid
|
avatar.EquipGuidMap[weapon.Guid] = weapon.Guid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) TakeOffWeapon(avatarId uint32, weaponId uint64) {
|
func (a *DbAvatar) TakeOffWeapon(avatarId uint32, weapon *Weapon) {
|
||||||
avatar := p.AvatarMap[avatarId]
|
avatar := a.AvatarMap[avatarId]
|
||||||
weapon := p.WeaponMap[weaponId]
|
|
||||||
avatar.EquipWeapon = nil
|
avatar.EquipWeapon = nil
|
||||||
weapon.AvatarId = 0
|
weapon.AvatarId = 0
|
||||||
delete(avatar.EquipGuidMap, weapon.Guid)
|
delete(avatar.EquipGuidMap, weapon.Guid)
|
||||||
@@ -8,12 +8,19 @@ type GachaPoolInfo struct {
|
|||||||
MustGetUpPurple bool // 是否4星大保底
|
MustGetUpPurple bool // 是否4星大保底
|
||||||
}
|
}
|
||||||
|
|
||||||
type DropInfo struct {
|
type DbGacha struct {
|
||||||
GachaPoolInfo map[uint32]*GachaPoolInfo
|
GachaPoolInfo map[uint32]*GachaPoolInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDropInfo() (r *DropInfo) {
|
func (p *Player) GetDbGacha() *DbGacha {
|
||||||
r = new(DropInfo)
|
if p.DbGacha == nil {
|
||||||
|
p.DbGacha = NewDbGacha()
|
||||||
|
}
|
||||||
|
return p.DbGacha
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDbGacha() (r *DbGacha) {
|
||||||
|
r = new(DbGacha)
|
||||||
r.GachaPoolInfo = make(map[uint32]*GachaPoolInfo)
|
r.GachaPoolInfo = make(map[uint32]*GachaPoolInfo)
|
||||||
r.GachaPoolInfo[300] = &GachaPoolInfo{
|
r.GachaPoolInfo[300] = &GachaPoolInfo{
|
||||||
// 温迪
|
// 温迪
|
||||||
89
gs/model/db_item.go
Normal file
89
gs/model/db_item.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "hk4e/common/constant"
|
||||||
|
|
||||||
|
type DbItem struct {
|
||||||
|
ItemMap map[uint32]*Item // 道具仓库
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) GetDbItem() *DbItem {
|
||||||
|
if p.DbItem == nil {
|
||||||
|
p.DbItem = &DbItem{
|
||||||
|
ItemMap: make(map[uint32]*Item),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p.DbItem
|
||||||
|
}
|
||||||
|
|
||||||
|
type Item struct {
|
||||||
|
ItemId uint32 // 道具id
|
||||||
|
Count uint32 // 道具数量
|
||||||
|
Guid uint64 `bson:"-" msgpack:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *DbItem) InitAllItem(player *Player) {
|
||||||
|
for itemId, item := range i.ItemMap {
|
||||||
|
item.Guid = player.GetNextGameObjectGuid()
|
||||||
|
player.GameObjectGuidMap[item.Guid] = GameObject(item)
|
||||||
|
i.ItemMap[itemId] = item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *DbItem) GetItemGuid(itemId uint32) uint64 {
|
||||||
|
itemInfo := i.ItemMap[itemId]
|
||||||
|
if itemInfo == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return itemInfo.Guid
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *DbItem) GetItemCount(player *Player, itemId uint32) uint32 {
|
||||||
|
prop, ok := constant.VIRTUAL_ITEM_PROP[itemId]
|
||||||
|
if ok {
|
||||||
|
value := player.PropertiesMap[prop]
|
||||||
|
return value
|
||||||
|
} else {
|
||||||
|
itemInfo := i.ItemMap[itemId]
|
||||||
|
if itemInfo == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return itemInfo.Count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *DbItem) AddItem(player *Player, itemId uint32, count uint32) {
|
||||||
|
itemInfo := i.ItemMap[itemId]
|
||||||
|
if itemInfo == nil {
|
||||||
|
// 该物品为新物品时校验背包物品容量
|
||||||
|
// 目前物品包括材料和家具
|
||||||
|
if len(i.ItemMap) > constant.STORE_PACK_LIMIT_MATERIAL+constant.STORE_PACK_LIMIT_FURNITURE {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
itemInfo = &Item{
|
||||||
|
ItemId: itemId,
|
||||||
|
Count: 0,
|
||||||
|
Guid: player.GetNextGameObjectGuid(),
|
||||||
|
}
|
||||||
|
player.GameObjectGuidMap[itemInfo.Guid] = GameObject(itemInfo)
|
||||||
|
}
|
||||||
|
itemInfo.Count += count
|
||||||
|
i.ItemMap[itemId] = itemInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *DbItem) CostItem(player *Player, itemId uint32, count uint32) {
|
||||||
|
itemInfo := i.ItemMap[itemId]
|
||||||
|
if itemInfo == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if itemInfo.Count < count {
|
||||||
|
itemInfo.Count = 0
|
||||||
|
} else {
|
||||||
|
itemInfo.Count -= count
|
||||||
|
}
|
||||||
|
if itemInfo.Count == 0 {
|
||||||
|
delete(i.ItemMap, itemId)
|
||||||
|
delete(player.GameObjectGuidMap, itemInfo.Guid)
|
||||||
|
} else {
|
||||||
|
i.ItemMap[itemId] = itemInfo
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,19 @@ import (
|
|||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type DbReliquary struct {
|
||||||
|
ReliquaryMap map[uint64]*Reliquary // 圣遗物背包
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) GetDbReliquary() *DbReliquary {
|
||||||
|
if p.DbReliquary == nil {
|
||||||
|
p.DbReliquary = &DbReliquary{
|
||||||
|
ReliquaryMap: make(map[uint64]*Reliquary),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p.DbReliquary
|
||||||
|
}
|
||||||
|
|
||||||
type Reliquary struct {
|
type Reliquary struct {
|
||||||
ReliquaryId uint64 // 圣遗物的唯一id
|
ReliquaryId uint64 // 圣遗物的唯一id
|
||||||
ItemId uint32 // 圣遗物的道具id
|
ItemId uint32 // 圣遗物的道具id
|
||||||
@@ -19,44 +32,45 @@ type Reliquary struct {
|
|||||||
Guid uint64 `bson:"-" msgpack:"-"`
|
Guid uint64 `bson:"-" msgpack:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) InitReliquary(reliquary *Reliquary) {
|
func (r *DbReliquary) InitAllReliquary(player *Player) {
|
||||||
|
for _, reliquary := range r.ReliquaryMap {
|
||||||
|
r.InitReliquary(player, reliquary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *DbReliquary) InitReliquary(player *Player, reliquary *Reliquary) {
|
||||||
// 获取圣遗物配置表
|
// 获取圣遗物配置表
|
||||||
reliquaryConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
reliquaryConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
||||||
if reliquaryConfig == nil {
|
if reliquaryConfig == nil {
|
||||||
logger.Error("reliquary config error, itemId: %v", reliquary.ItemId)
|
logger.Error("reliquary config error, itemId: %v", reliquary.ItemId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
reliquary.Guid = p.GetNextGameObjectGuid()
|
reliquary.Guid = player.GetNextGameObjectGuid()
|
||||||
p.GameObjectGuidMap[reliquary.Guid] = GameObject(reliquary)
|
player.GameObjectGuidMap[reliquary.Guid] = GameObject(reliquary)
|
||||||
p.ReliquaryMap[reliquary.ReliquaryId] = reliquary
|
r.ReliquaryMap[reliquary.ReliquaryId] = reliquary
|
||||||
if reliquary.AvatarId != 0 {
|
if reliquary.AvatarId != 0 {
|
||||||
avatar := p.AvatarMap[reliquary.AvatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar := dbAvatar.AvatarMap[reliquary.AvatarId]
|
||||||
avatar.EquipGuidMap[reliquary.Guid] = reliquary.Guid
|
avatar.EquipGuidMap[reliquary.Guid] = reliquary.Guid
|
||||||
avatar.EquipReliquaryMap[uint8(reliquaryConfig.ReliquaryType)] = reliquary
|
avatar.EquipReliquaryMap[uint8(reliquaryConfig.ReliquaryType)] = reliquary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) InitAllReliquary() {
|
func (r *DbReliquary) GetReliquaryGuid(reliquaryId uint64) uint64 {
|
||||||
for _, reliquary := range p.ReliquaryMap {
|
reliquaryInfo := r.ReliquaryMap[reliquaryId]
|
||||||
p.InitReliquary(reliquary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) GetReliquaryGuid(reliquaryId uint64) uint64 {
|
|
||||||
reliquaryInfo := p.ReliquaryMap[reliquaryId]
|
|
||||||
if reliquaryInfo == nil {
|
if reliquaryInfo == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return reliquaryInfo.Guid
|
return reliquaryInfo.Guid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) GetReliquary(reliquaryId uint64) *Reliquary {
|
func (r *DbReliquary) GetReliquary(reliquaryId uint64) *Reliquary {
|
||||||
return p.ReliquaryMap[reliquaryId]
|
return r.ReliquaryMap[reliquaryId]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) AddReliquary(itemId uint32, reliquaryId uint64, mainPropId uint32) {
|
func (r *DbReliquary) AddReliquary(player *Player, itemId uint32, reliquaryId uint64, mainPropId uint32) {
|
||||||
// 校验背包圣遗物容量
|
// 校验背包圣遗物容量
|
||||||
if len(p.ReliquaryMap) > constant.STORE_PACK_LIMIT_RELIQUARY {
|
if len(r.ReliquaryMap) > constant.STORE_PACK_LIMIT_RELIQUARY {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
|
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
|
||||||
@@ -76,16 +90,16 @@ func (p *Player) AddReliquary(itemId uint32, reliquaryId uint64, mainPropId uint
|
|||||||
AvatarId: 0,
|
AvatarId: 0,
|
||||||
Guid: 0,
|
Guid: 0,
|
||||||
}
|
}
|
||||||
p.InitReliquary(reliquary)
|
r.InitReliquary(player, reliquary)
|
||||||
p.ReliquaryMap[reliquaryId] = reliquary
|
r.ReliquaryMap[reliquaryId] = reliquary
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) CostReliquary(reliquaryId uint64) uint64 {
|
func (r *DbReliquary) CostReliquary(player *Player, reliquaryId uint64) uint64 {
|
||||||
reliquary := p.ReliquaryMap[reliquaryId]
|
reliquary := r.ReliquaryMap[reliquaryId]
|
||||||
if reliquary == nil {
|
if reliquary == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
delete(p.ReliquaryMap, reliquaryId)
|
delete(r.ReliquaryMap, reliquaryId)
|
||||||
delete(p.GameObjectGuidMap, reliquary.Guid)
|
delete(player.GameObjectGuidMap, reliquary.Guid)
|
||||||
return reliquary.Guid
|
return reliquary.Guid
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func (t *Team) SetAvatarIdList(avatarIdList []uint32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type TeamInfo struct {
|
type DbTeam struct {
|
||||||
TeamList []*Team
|
TeamList []*Team
|
||||||
CurrTeamIndex uint8
|
CurrTeamIndex uint8
|
||||||
CurrAvatarIndex uint8
|
CurrAvatarIndex uint8
|
||||||
@@ -40,8 +40,15 @@ type TeamInfo struct {
|
|||||||
TeamResonancesConfig map[int32]bool `bson:"-" msgpack:"-"`
|
TeamResonancesConfig map[int32]bool `bson:"-" msgpack:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTeamInfo() (r *TeamInfo) {
|
func (p *Player) GetDbTeam() *DbTeam {
|
||||||
r = &TeamInfo{
|
if p.DbTeam == nil {
|
||||||
|
p.DbTeam = NewDbTeam()
|
||||||
|
}
|
||||||
|
return p.DbTeam
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDbTeam() (r *DbTeam) {
|
||||||
|
r = &DbTeam{
|
||||||
TeamList: []*Team{
|
TeamList: []*Team{
|
||||||
{Name: "冒险", AvatarIdList: make([]uint32, 4)},
|
{Name: "冒险", AvatarIdList: make([]uint32, 4)},
|
||||||
{Name: "委托", AvatarIdList: make([]uint32, 4)},
|
{Name: "委托", AvatarIdList: make([]uint32, 4)},
|
||||||
@@ -54,7 +61,7 @@ func NewTeamInfo() (r *TeamInfo) {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TeamInfo) UpdateTeam() {
|
func (t *DbTeam) UpdateTeam() {
|
||||||
activeTeam := t.GetActiveTeam()
|
activeTeam := t.GetActiveTeam()
|
||||||
// TODO 队伍元素共鸣
|
// TODO 队伍元素共鸣
|
||||||
t.TeamResonances = make(map[uint16]bool)
|
t.TeamResonances = make(map[uint16]bool)
|
||||||
@@ -88,11 +95,11 @@ func (t *TeamInfo) UpdateTeam() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TeamInfo) GetActiveTeamId() uint8 {
|
func (t *DbTeam) GetActiveTeamId() uint8 {
|
||||||
return t.CurrTeamIndex + 1
|
return t.CurrTeamIndex + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TeamInfo) GetTeamByIndex(teamIndex uint8) *Team {
|
func (t *DbTeam) GetTeamByIndex(teamIndex uint8) *Team {
|
||||||
if t.TeamList == nil {
|
if t.TeamList == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -103,11 +110,11 @@ func (t *TeamInfo) GetTeamByIndex(teamIndex uint8) *Team {
|
|||||||
return activeTeam
|
return activeTeam
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TeamInfo) GetActiveTeam() *Team {
|
func (t *DbTeam) GetActiveTeam() *Team {
|
||||||
return t.GetTeamByIndex(t.CurrTeamIndex)
|
return t.GetTeamByIndex(t.CurrTeamIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TeamInfo) GetActiveAvatarId() uint32 {
|
func (t *DbTeam) GetActiveAvatarId() uint32 {
|
||||||
team := t.GetActiveTeam()
|
team := t.GetActiveTeam()
|
||||||
if team == nil {
|
if team == nil {
|
||||||
return 0
|
return 0
|
||||||
@@ -6,6 +6,19 @@ import (
|
|||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type DbWeapon struct {
|
||||||
|
WeaponMap map[uint64]*Weapon // 武器背包
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) GetDbWeapon() *DbWeapon {
|
||||||
|
if p.DbWeapon == nil {
|
||||||
|
p.DbWeapon = &DbWeapon{
|
||||||
|
WeaponMap: make(map[uint64]*Weapon),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p.DbWeapon
|
||||||
|
}
|
||||||
|
|
||||||
type Weapon struct {
|
type Weapon struct {
|
||||||
WeaponId uint64 // 武器的唯一id
|
WeaponId uint64 // 武器的唯一id
|
||||||
ItemId uint32 // 武器的道具id
|
ItemId uint32 // 武器的道具id
|
||||||
@@ -19,38 +32,39 @@ type Weapon struct {
|
|||||||
Guid uint64 `bson:"-" msgpack:"-"`
|
Guid uint64 `bson:"-" msgpack:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) InitWeapon(weapon *Weapon) {
|
func (w *DbWeapon) InitAllWeapon(player *Player) {
|
||||||
weapon.Guid = p.GetNextGameObjectGuid()
|
for _, weapon := range w.WeaponMap {
|
||||||
p.GameObjectGuidMap[weapon.Guid] = GameObject(weapon)
|
w.InitWeapon(player, weapon)
|
||||||
p.WeaponMap[weapon.WeaponId] = weapon
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *DbWeapon) InitWeapon(player *Player, weapon *Weapon) {
|
||||||
|
weapon.Guid = player.GetNextGameObjectGuid()
|
||||||
|
player.GameObjectGuidMap[weapon.Guid] = GameObject(weapon)
|
||||||
|
w.WeaponMap[weapon.WeaponId] = weapon
|
||||||
if weapon.AvatarId != 0 {
|
if weapon.AvatarId != 0 {
|
||||||
avatar := p.AvatarMap[weapon.AvatarId]
|
dbAvatar := player.GetDbAvatar()
|
||||||
|
avatar := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||||
avatar.EquipGuidMap[weapon.Guid] = weapon.Guid
|
avatar.EquipGuidMap[weapon.Guid] = weapon.Guid
|
||||||
avatar.EquipWeapon = weapon
|
avatar.EquipWeapon = weapon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) InitAllWeapon() {
|
func (w *DbWeapon) GetWeaponGuid(weaponId uint64) uint64 {
|
||||||
for _, weapon := range p.WeaponMap {
|
weaponInfo := w.WeaponMap[weaponId]
|
||||||
p.InitWeapon(weapon)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) GetWeaponGuid(weaponId uint64) uint64 {
|
|
||||||
weaponInfo := p.WeaponMap[weaponId]
|
|
||||||
if weaponInfo == nil {
|
if weaponInfo == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return weaponInfo.Guid
|
return weaponInfo.Guid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) GetWeapon(weaponId uint64) *Weapon {
|
func (w *DbWeapon) GetWeapon(weaponId uint64) *Weapon {
|
||||||
return p.WeaponMap[weaponId]
|
return w.WeaponMap[weaponId]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) AddWeapon(itemId uint32, weaponId uint64) {
|
func (w *DbWeapon) AddWeapon(player *Player, itemId uint32, weaponId uint64) {
|
||||||
// 校验背包武器容量
|
// 校验背包武器容量
|
||||||
if len(p.WeaponMap) > constant.STORE_PACK_LIMIT_WEAPON {
|
if len(w.WeaponMap) > constant.STORE_PACK_LIMIT_WEAPON {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
|
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
|
||||||
@@ -72,16 +86,16 @@ func (p *Player) AddWeapon(itemId uint32, weaponId uint64) {
|
|||||||
for _, skillAffix := range itemDataConfig.SkillAffix {
|
for _, skillAffix := range itemDataConfig.SkillAffix {
|
||||||
weapon.AffixIdList = append(weapon.AffixIdList, uint32(skillAffix))
|
weapon.AffixIdList = append(weapon.AffixIdList, uint32(skillAffix))
|
||||||
}
|
}
|
||||||
p.InitWeapon(weapon)
|
w.InitWeapon(player, weapon)
|
||||||
p.WeaponMap[weaponId] = weapon
|
w.WeaponMap[weaponId] = weapon
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) CostWeapon(weaponId uint64) uint64 {
|
func (w *DbWeapon) CostWeapon(player *Player, weaponId uint64) uint64 {
|
||||||
weapon := p.WeaponMap[weaponId]
|
weapon := w.WeaponMap[weaponId]
|
||||||
if weapon == nil {
|
if weapon == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
delete(p.WeaponMap, weaponId)
|
delete(w.WeaponMap, weaponId)
|
||||||
delete(p.GameObjectGuidMap, weapon.Guid)
|
delete(player.GameObjectGuidMap, weapon.Guid)
|
||||||
return weapon.Guid
|
return weapon.Guid
|
||||||
}
|
}
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import "hk4e/common/constant"
|
|
||||||
|
|
||||||
type Item struct {
|
|
||||||
ItemId uint32 // 道具id
|
|
||||||
Count uint32 // 道具数量
|
|
||||||
Guid uint64 `bson:"-" msgpack:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) InitAllItem() {
|
|
||||||
for itemId, item := range p.ItemMap {
|
|
||||||
item.Guid = p.GetNextGameObjectGuid()
|
|
||||||
p.GameObjectGuidMap[item.Guid] = GameObject(item)
|
|
||||||
p.ItemMap[itemId] = item
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) GetItemGuid(itemId uint32) uint64 {
|
|
||||||
itemInfo := p.ItemMap[itemId]
|
|
||||||
if itemInfo == nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return itemInfo.Guid
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) GetItemCount(itemId uint32) uint32 {
|
|
||||||
prop, ok := constant.VIRTUAL_ITEM_PROP[itemId]
|
|
||||||
if ok {
|
|
||||||
value := p.PropertiesMap[prop]
|
|
||||||
return value
|
|
||||||
} else {
|
|
||||||
itemInfo := p.ItemMap[itemId]
|
|
||||||
if itemInfo == nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return itemInfo.Count
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) AddItem(itemId uint32, count uint32) {
|
|
||||||
itemInfo := p.ItemMap[itemId]
|
|
||||||
if itemInfo == nil {
|
|
||||||
// 该物品为新物品时校验背包物品容量
|
|
||||||
// 目前物品包括材料和家具
|
|
||||||
if len(p.ItemMap) > constant.STORE_PACK_LIMIT_MATERIAL+constant.STORE_PACK_LIMIT_FURNITURE {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
itemInfo = &Item{
|
|
||||||
ItemId: itemId,
|
|
||||||
Count: 0,
|
|
||||||
Guid: p.GetNextGameObjectGuid(),
|
|
||||||
}
|
|
||||||
p.GameObjectGuidMap[itemInfo.Guid] = GameObject(itemInfo)
|
|
||||||
}
|
|
||||||
itemInfo.Count += count
|
|
||||||
p.ItemMap[itemId] = itemInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) CostItem(itemId uint32, count uint32) {
|
|
||||||
itemInfo := p.ItemMap[itemId]
|
|
||||||
if itemInfo == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if itemInfo.Count < count {
|
|
||||||
itemInfo.Count = 0
|
|
||||||
} else {
|
|
||||||
itemInfo.Count -= count
|
|
||||||
}
|
|
||||||
if itemInfo.Count == 0 {
|
|
||||||
delete(p.ItemMap, itemId)
|
|
||||||
delete(p.GameObjectGuidMap, itemInfo.Guid)
|
|
||||||
} else {
|
|
||||||
p.ItemMap[itemId] = itemInfo
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,45 +25,43 @@ type GameObject interface {
|
|||||||
|
|
||||||
type Player struct {
|
type Player struct {
|
||||||
// 离线数据 请尽量不要定义接口等复杂数据结构
|
// 离线数据 请尽量不要定义接口等复杂数据结构
|
||||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||||
PlayerID uint32 `bson:"PlayerID"` // 玩家uid
|
PlayerID uint32 `bson:"PlayerID"` // 玩家uid
|
||||||
NickName string // 玩家昵称
|
NickName string // 昵称
|
||||||
Signature string // 玩家签名
|
Signature string // 签名
|
||||||
HeadImage uint32 // 玩家头像
|
HeadImage uint32 // 头像
|
||||||
Birthday []uint8 // 生日
|
Birthday []uint8 // 生日
|
||||||
NameCard uint32 // 当前名片
|
NameCard uint32 // 当前名片
|
||||||
NameCardList []uint32 // 已解锁名片列表
|
NameCardList []uint32 // 已解锁名片列表
|
||||||
FriendList map[uint32]bool // 好友uid列表
|
FriendList map[uint32]bool // 好友uid列表
|
||||||
FriendApplyList map[uint32]bool // 好友申请uid列表
|
FriendApplyList map[uint32]bool // 好友申请uid列表
|
||||||
OfflineTime uint32 // 离线时间点
|
OfflineTime uint32 // 离线时间点
|
||||||
OnlineTime uint32 // 上线时间点
|
OnlineTime uint32 // 上线时间点
|
||||||
TotalOnlineTime uint32 // 玩家累计在线时长
|
TotalOnlineTime uint32 // 累计在线时长
|
||||||
PropertiesMap map[uint16]uint32 // 玩家自身相关的一些属性
|
PropertiesMap map[uint16]uint32 // 玩家自身相关的一些属性
|
||||||
FlyCloakList []uint32 // 风之翼列表
|
FlyCloakList []uint32 // 风之翼列表
|
||||||
CostumeList []uint32 // 角色衣装列表
|
CostumeList []uint32 // 角色衣装列表
|
||||||
SceneId uint32 // 场景
|
SceneId uint32 // 场景
|
||||||
SafePos *Vector // 玩家在陆地时的坐标
|
IsGM uint8 // 管理员权限等级
|
||||||
Pos *Vector // 玩家坐标
|
SafePos *Vector // 在陆地时的坐标
|
||||||
Rot *Vector // 玩家朝向
|
Pos *Vector // 坐标
|
||||||
ItemMap map[uint32]*Item // 玩家统一大背包仓库
|
Rot *Vector // 朝向
|
||||||
WeaponMap map[uint64]*Weapon // 玩家武器背包
|
DbItem *DbItem // 道具
|
||||||
ReliquaryMap map[uint64]*Reliquary // 玩家圣遗物背包
|
DbWeapon *DbWeapon // 武器
|
||||||
TeamConfig *TeamInfo // 队伍配置
|
DbReliquary *DbReliquary // 圣遗物
|
||||||
AvatarMap map[uint32]*Avatar // 角色信息
|
DbTeam *DbTeam // 队伍
|
||||||
DropInfo *DropInfo // 掉落信息
|
DbAvatar *DbAvatar // 角色
|
||||||
MainCharAvatarId uint32 // 主角id
|
DbGacha *DbGacha // 卡池
|
||||||
GCGInfo *GCGInfo // 七圣召唤信息
|
DbQuest *DbQuest // 任务
|
||||||
IsGM uint8 // 管理员权限等级
|
|
||||||
DbQuest *DbQuest // 任务
|
|
||||||
// 在线数据 请随意 记得加忽略字段的tag
|
// 在线数据 请随意 记得加忽略字段的tag
|
||||||
LastSaveTime uint32 `bson:"-" msgpack:"-"` // 上一次保存时间
|
LastSaveTime uint32 `bson:"-" msgpack:"-"` // 上一次保存时间
|
||||||
EnterSceneToken uint32 `bson:"-" msgpack:"-"` // 玩家的世界进入令牌
|
EnterSceneToken uint32 `bson:"-" msgpack:"-"` // 世界进入令牌
|
||||||
DbState int `bson:"-" msgpack:"-"` // 数据库存档状态
|
DbState int `bson:"-" msgpack:"-"` // 数据库存档状态
|
||||||
WorldId uint32 `bson:"-" msgpack:"-"` // 所在的世界id
|
WorldId uint32 `bson:"-" msgpack:"-"` // 所在的世界id
|
||||||
GameObjectGuidCounter uint64 `bson:"-" msgpack:"-"` // 游戏对象guid计数器
|
GameObjectGuidCounter uint64 `bson:"-" msgpack:"-"` // 游戏对象guid计数器
|
||||||
LastKeepaliveTime uint32 `bson:"-" msgpack:"-"` // 上一次保持活跃时间
|
LastKeepaliveTime uint32 `bson:"-" msgpack:"-"` // 上一次保持活跃时间
|
||||||
ClientTime uint32 `bson:"-" msgpack:"-"` // 玩家客户端的本地时钟
|
ClientTime uint32 `bson:"-" msgpack:"-"` // 客户端的本地时钟
|
||||||
ClientRTT uint32 `bson:"-" msgpack:"-"` // 玩家客户端往返时延
|
ClientRTT uint32 `bson:"-" msgpack:"-"` // 客户端往返时延
|
||||||
GameObjectGuidMap map[uint64]GameObject `bson:"-" msgpack:"-"` // 游戏对象guid映射表
|
GameObjectGuidMap map[uint64]GameObject `bson:"-" msgpack:"-"` // 游戏对象guid映射表
|
||||||
Online bool `bson:"-" msgpack:"-"` // 在线状态
|
Online bool `bson:"-" msgpack:"-"` // 在线状态
|
||||||
Pause bool `bson:"-" msgpack:"-"` // 暂停状态
|
Pause bool `bson:"-" msgpack:"-"` // 暂停状态
|
||||||
@@ -78,6 +76,7 @@ type Player struct {
|
|||||||
GateAppId string `bson:"-" msgpack:"-"` // 网关服务器的appid
|
GateAppId string `bson:"-" msgpack:"-"` // 网关服务器的appid
|
||||||
FightAppId string `bson:"-" msgpack:"-"` // 战斗服务器的appid
|
FightAppId string `bson:"-" msgpack:"-"` // 战斗服务器的appid
|
||||||
GCGCurGameGuid uint32 `bson:"-" msgpack:"-"` // GCG玩家所在的游戏guid
|
GCGCurGameGuid uint32 `bson:"-" msgpack:"-"` // GCG玩家所在的游戏guid
|
||||||
|
GCGInfo *GCGInfo `bson:"-" msgpack:"-"` // 七圣召唤信息
|
||||||
// 特殊数据
|
// 特殊数据
|
||||||
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis
|
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis
|
||||||
}
|
}
|
||||||
@@ -87,17 +86,15 @@ func (p *Player) GetNextGameObjectGuid() uint64 {
|
|||||||
return uint64(p.PlayerID)<<32 + p.GameObjectGuidCounter
|
return uint64(p.PlayerID)<<32 + p.GameObjectGuidCounter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) InitAll() {
|
func (p *Player) InitOnlineData() {
|
||||||
|
// 在线数据初始化
|
||||||
p.GameObjectGuidMap = make(map[uint64]GameObject)
|
p.GameObjectGuidMap = make(map[uint64]GameObject)
|
||||||
p.CoopApplyMap = make(map[uint32]int64)
|
p.CoopApplyMap = make(map[uint32]int64)
|
||||||
p.StaminaInfo = new(StaminaInfo)
|
p.StaminaInfo = NewStaminaInfo()
|
||||||
p.VehicleInfo = new(VehicleInfo)
|
p.VehicleInfo = NewVehicleInfo()
|
||||||
p.VehicleInfo.LastCreateEntityIdMap = make(map[uint32]uint32)
|
p.CombatInvokeHandler = NewInvokeHandler[proto.CombatInvokeEntry]()
|
||||||
|
p.AbilityInvokeHandler = NewInvokeHandler[proto.AbilityInvokeEntry]()
|
||||||
p.GCGInfo = NewGCGInfo() // 临时测试用数据
|
p.GCGInfo = NewGCGInfo() // 临时测试用数据
|
||||||
p.InitAllAvatar()
|
|
||||||
p.InitAllWeapon()
|
|
||||||
p.InitAllItem()
|
|
||||||
p.InitAllReliquary()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 多人世界网络同步包转发器
|
// 多人世界网络同步包转发器
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ type StaminaInfo struct {
|
|||||||
DrownBackDelay uint8 // 溺水返回安全点延时
|
DrownBackDelay uint8 // 溺水返回安全点延时
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewStaminaInfo() *StaminaInfo {
|
||||||
|
return new(StaminaInfo)
|
||||||
|
}
|
||||||
|
|
||||||
// SetStaminaCost 设置动作需要消耗的耐力
|
// SetStaminaCost 设置动作需要消耗的耐力
|
||||||
func (s *StaminaInfo) SetStaminaCost(state proto.MotionState) {
|
func (s *StaminaInfo) SetStaminaCost(state proto.MotionState) {
|
||||||
// 根据状态决定要修改的耐力
|
// 根据状态决定要修改的耐力
|
||||||
|
|||||||
@@ -6,3 +6,11 @@ type VehicleInfo struct {
|
|||||||
// TODO 玩家可以在其他世界创建载具 需要额外处理
|
// TODO 玩家可以在其他世界创建载具 需要额外处理
|
||||||
LastCreateEntityIdMap map[uint32]uint32 // 最后一次创建载具的实体Id map[vehicleId]EntityId
|
LastCreateEntityIdMap map[uint32]uint32 // 最后一次创建载具的实体Id map[vehicleId]EntityId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewVehicleInfo() *VehicleInfo {
|
||||||
|
return &VehicleInfo{
|
||||||
|
InVehicleEntityId: 0,
|
||||||
|
LastCreateTime: 0,
|
||||||
|
LastCreateEntityIdMap: make(map[uint32]uint32),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user