优化掉落系统

This commit is contained in:
flswld committed 2023-11-16 21:35:51 +08:00
1 parent e9cacf064a
commit c352746496
30 files changed
+350 -204

No files matched your search

+1 -4
View File
@@ -18,10 +18,7 @@ var (
func main() {
flag.Parse()
go func() {
err := statsviz_serve.Serve("0.0.0.0:7890")
if err != nil {
panic(err)
}
_ = statsviz_serve.Serve("0.0.0.0:7890")
}()
err := app.Run(context.TODO(), *config)
if err != nil {
+3 -3
View File
@@ -9,15 +9,15 @@ import (
)
func DispatchCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "dispatch",
Short: "dispatch server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+3 -3
View File
@@ -9,15 +9,15 @@ import (
)
func GateCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "gate",
Short: "gate server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+3 -3
View File
@@ -9,14 +9,14 @@ import (
)
func GMCmd() *cobra.Command {
var cfg string
var configFile string
c := &cobra.Command{
Use: "gm",
Short: "gm server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+3 -3
View File
@@ -9,15 +9,15 @@ import (
)
func GSCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "gs",
Short: "game server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+2
View File
@@ -28,6 +28,8 @@ func main() {
GSCmd(),
MultiCmd(),
GMCmd(),
RobotCmd(),
NatsCmd(),
)
if err := rootCmd.Execute(); err != nil {
+3 -3
View File
@@ -9,15 +9,15 @@ import (
)
func MultiCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "multi",
Short: "multi server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+80
View File
@@ -0,0 +1,80 @@
package main
import (
"errors"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"
cfg "hk4e/common/config"
"github.com/nats-io/nats-server/v2/server"
"github.com/spf13/cobra"
)
func NatsCmd() *cobra.Command {
var configFile string
c := &cobra.Command{
Use: "nats",
Short: "nats server",
RunE: func(cmd *cobra.Command, args []string) error {
return RunNatsServer(configFile)
},
}
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
func RunNatsServer(configFile string) error {
cfg.InitConfig(configFile)
natsAddr := strings.ReplaceAll(cfg.GetConfig().MQ.NatsUrl, "nats://", "")
if strings.Contains(natsAddr, ",") {
return errors.New("not support nats cluster")
}
split := strings.Split(natsAddr, ":")
if len(split) != 2 {
return errors.New("nats addr format error")
}
host := split[0]
port, err := strconv.Atoi(split[1])
if err != nil {
return err
}
opts := &server.Options{
Host: host,
Port: port,
NoLog: false,
NoSigs: true,
MaxControlLine: 4096,
DisableShortFirstPing: true,
Trace: true,
Debug: true,
}
natsServer, err := server.NewServer(opts)
if err != nil {
return err
}
natsServer.ConfigureLogger()
go natsServer.Start()
ok := natsServer.ReadyForConnections(time.Second * 5)
if !ok {
return errors.New("nats server start error")
}
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
return nil
case syscall.SIGHUP:
default:
return nil
}
}
}
+3 -3
View File
@@ -9,14 +9,14 @@ import (
)
func NodeCmd() *cobra.Command {
var cfg string
var configFile string
c := &cobra.Command{
Use: "node",
Short: "node server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+23
View File
@@ -0,0 +1,23 @@
package main
import (
"github.com/spf13/cobra"
"context"
"hk4e/robot/app"
)
func RobotCmd() *cobra.Command {
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "robot",
Short: "robot server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+1 -4
View File
@@ -18,10 +18,7 @@ var (
func main() {
flag.Parse()
go func() {
err := statsviz_serve.Serve("0.0.0.0:1234")
if err != nil {
panic(err)
}
_ = statsviz_serve.Serve("0.0.0.0:1234")
}()
err := app.Run(context.TODO(), *config)
if err != nil {
+21 -20
View File
@@ -11,32 +11,14 @@ var CONF *Config = nil
// Config 配置
type Config struct {
HttpPort int32 `toml:"http_port"`
Hk4e Hk4e `toml:"hk4e"`
Hk4eRobot Hk4eRobot `toml:"hk4e_robot"`
Logger Logger `toml:"logger"`
Database Database `toml:"database"`
Redis Redis `toml:"redis"`
Hk4e Hk4e `toml:"hk4e"`
Hk4eRobot Hk4eRobot `toml:"hk4e_robot"`
MQ MQ `toml:"mq"`
}
// Logger 日志
type Logger struct {
Level string `toml:"level"`
Mode string `toml:"mode"`
Track bool `toml:"track"`
MaxSize int32 `toml:"max_size"`
}
// Database 数据库配置
type Database struct {
Url string `toml:"url"`
}
type Redis struct {
Addr string `toml:"addr"`
Password string `toml:"password"`
}
// Hk4e 原神服务器
type Hk4e struct {
KcpAddr string `toml:"kcp_addr"` // kcp地址 该地址只用来注册到节点服务器 填网关的外网地址 网关本地监听为0.0.0.0
@@ -81,6 +63,25 @@ type Hk4eRobot struct {
ForwardChecksumClientVersion string `toml:"forward_checksum_client_version"` // 转发模式强制指定校验和客户端版本
}
// Logger 日志
type Logger struct {
Level string `toml:"level"`
Mode string `toml:"mode"`
Track bool `toml:"track"`
MaxSize int32 `toml:"max_size"`
}
// Database 数据库
type Database struct {
Url string `toml:"url"`
}
// Redis 缓存
type Redis struct {
Addr string `toml:"addr"`
Password string `toml:"password"`
}
// MQ 消息队列
type MQ struct {
NatsUrl string `toml:"nats_url"`
+2
View File
@@ -13,6 +13,8 @@ const (
ITEM_ID_WEAPON_UPGRADE_MAGIC = 104013 // 精锻用魔矿
ITEM_ID_WEAPON_UPGRADE_GOOD = 104012 // 精锻用良矿
ITEM_ID_WEAPON_UPGRADE_MOTLEY = 104011 // 精锻用杂矿
ITEM_ID_AVATAR_EXP = 101 // 角色经验
)
// 虚拟物品对应玩家的属性
+8 -8
View File
@@ -104,14 +104,14 @@ func ProtoDecode(kcpMsg *KcpMsg,
msg.PayloadMessage = protoMessage.message
protoMsgList = append(protoMsgList, msg)
}
for _, msg := range protoMsgList {
cmdName := "???"
if msg.PayloadMessage != nil {
cmdName = string(msg.PayloadMessage.ProtoReflect().Descriptor().FullName())
}
logger.Debug("[RECV UNION CMD] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v",
msg.CmdId, cmdName, msg.SessionId, msg.HeadMessage)
}
// for _, msg := range protoMsgList {
// cmdName := "???"
// if msg.PayloadMessage != nil {
// cmdName = string(msg.PayloadMessage.ProtoReflect().Descriptor().FullName())
// }
// logger.Debug("[RECV UNION CMD] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v",
// msg.CmdId, cmdName, msg.SessionId, msg.HeadMessage)
// }
} else {
protoMsg.PayloadMessage = protoMessageList[0].message
protoMsgList = append(protoMsgList, protoMsg)
+4 -1
View File
@@ -54,6 +54,7 @@ require github.com/pierrec/lz4/v4 v4.1.17
require github.com/gorilla/websocket v1.4.2
require (
github.com/nats-io/nats-server/v2 v2.9.7
github.com/stretchr/testify v1.8.3
golang.org/x/net v0.10.0
golang.org/x/sys v0.8.0
@@ -79,9 +80,10 @@ require (
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nats-io/nats-server/v2 v2.9.7 // indirect
github.com/nats-io/jwt/v2 v2.3.0 // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
@@ -99,5 +101,6 @@ require (
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+4
View File
@@ -74,6 +74,7 @@ github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNa
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -81,6 +82,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI=
github.com/nats-io/jwt/v2 v2.3.0/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k=
github.com/nats-io/nats-server/v2 v2.9.7 h1:VBlfq7xvv/72v0mzGZ2rgsDzUoVyX2Xhssl9XpKDue0=
github.com/nats-io/nats-server/v2 v2.9.7/go.mod h1:AB6hAnGZDlYfqb7CTAm66ZKMZy9DpfierY1/PbpvI2g=
github.com/nats-io/nats.go v1.19.0 h1:H6j8aBnTQFoVrTGB6Xjd903UMdE7jz6DS4YkmAqgZ9Q=
@@ -157,6 +159,7 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -172,6 +175,7 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y=
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+1 -1
View File
@@ -438,7 +438,7 @@ func (g *Game) SendError(cmdId uint16, player *model.Player, rsp pb.Message, ret
if !ok {
return
}
logger.Debug("send common error: %v", rsp)
logger.Error("send common error, rsp: %v, err: %v, uid: %v", rsp.ProtoReflect().Descriptor().FullName(), retCode[0].String(), player.PlayerId)
g.SendMsg(cmdId, player.PlayerId, player.ClientSeq, rsp)
}
-8
View File
@@ -395,14 +395,6 @@ func (c *CommandManager) ItemCommand(content *CommandContent) bool {
if itemDataConfig == nil {
return false
}
if itemDataConfig.Type == constant.ITEM_TYPE_WEAPON {
c.gmCmd.GMAddWeapon(content.AssignPlayer.PlayerId, uint32(itemId), 1, 1, 0, 0)
return true
}
if itemDataConfig.Type == constant.ITEM_TYPE_RELIQUARY {
c.gmCmd.GMAddReliquary(content.AssignPlayer.PlayerId, uint32(itemId), 1)
return true
}
c.gmCmd.GMAddItem(content.AssignPlayer.PlayerId, uint32(itemId), count)
content.SendSuccMessage(content.Executor, "已添加道具,指定UID:%v,道具ID:%v,数量:%v。", content.AssignPlayer.PlayerId, itemId, count)
case "clear":
+2 -2
View File
@@ -42,7 +42,7 @@ func (g *GMCmd) GMTeleportPlayer(userId, sceneId uint32, posX, posY, posZ float6
// GMAddItem 添加玩家道具
func (g *GMCmd) GMAddItem(userId, itemId, itemCount uint32) {
GAME.AddPlayerItem(userId, []*ChangeItem{{ItemId: itemId, ChangeCount: itemCount}}, true, 0)
GAME.AddPlayerItem(userId, []*ChangeItem{{ItemId: itemId, ChangeCount: itemCount}}, proto.ActionReasonType_ACTION_REASON_GM)
}
// GMCostItem 消耗玩家道具
@@ -137,7 +137,7 @@ func (g *GMCmd) GMAddAllItem(userId uint32) {
ChangeCount: 1,
})
}
GAME.AddPlayerItem(userId, itemList, false, 0)
GAME.AddPlayerItem(userId, itemList, proto.ActionReasonType_ACTION_REASON_GM)
}
// GMAddAllWeapon 添加玩家所有武器
+1 -1
View File
@@ -228,7 +228,7 @@ func (g *Game) AvatarPromoteGetRewardReq(player *model.Player, payloadMsg pb.Mes
ChangeCount: count,
})
}
g.AddPlayerItem(player.PlayerId, rewardItemList, false, 0)
g.AddPlayerItem(player.PlayerId, rewardItemList, proto.ActionReasonType_ACTION_REASON_AVATAR_PROMOTE)
avatarPromoteGetRewardRsp := &proto.AvatarPromoteGetRewardRsp{
RewardId: uint32(rewardConfig.RewardId),
+2 -2
View File
@@ -235,7 +235,7 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr
gadgetEntity := defEntity.GetGadgetEntity()
gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetEntity.GetGadgetId()))
if gadgetDataConfig == nil {
logger.Error("get gadget data config is nil, gadgetId: %v", gadgetEntity.GetGadgetId())
// logger.Error("get gadget data config is nil, gadgetId: %v", gadgetEntity.GetGadgetId())
return
}
logger.Debug("[EvtBeingHit] GadgetData: %+v, EntityId: %v, uid: %v", gadgetDataConfig, defEntity.GetId(), player.PlayerId)
@@ -1083,7 +1083,7 @@ func (g *Game) handleGadgetEntityAbilityLow(player *model.Player, entityId uint3
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_GM)
} else if strings.Contains(gadgetDataConfig.ServerLuaScript, "SubfieldDrop_Ore") {
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_GM)
g.CreateDropGadget(player, entity.GetPos(), 70900001, 233, 1)
g.CreateDropGadget(player, entity.GetPos(), 70600031, 104011, 1)
}
}
}
+7 -24
View File
@@ -266,45 +266,28 @@ func (g *Game) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
} else {
constellationItemId := itemId + 100
if g.GetPlayerItemCount(player.PlayerId, constellationItemId) < 6 {
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: constellationItemId, ChangeCount: 1}}, false, 0)
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: constellationItemId, ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_GACHA)
}
}
} else if itemId > 10000 && itemId < 20000 {
g.AddPlayerWeapon(player.PlayerId, itemId)
} else {
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: itemId, ChangeCount: 1}}, false, 0)
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: itemId, ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_GACHA)
}
// 计算星尘星辉
xc := uint32(random.GetRandomInt32(0, 10))
xh := uint32(random.GetRandomInt32(0, 10))
gachaItem := new(proto.GachaItem)
gachaItem.GachaItem = &proto.ItemParam{
ItemId: itemId,
Count: 1,
}
gachaItem.GachaItem = &proto.ItemParam{ItemId: itemId, Count: 1}
// 星尘
if xc != 0 {
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{
ItemId: 222,
ChangeCount: xc,
}}, false, 0)
gachaItem.TokenItemList = []*proto.ItemParam{{
ItemId: 222,
Count: xc,
}}
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: 222, ChangeCount: xc}}, proto.ActionReasonType_ACTION_REASON_GACHA)
gachaItem.TokenItemList = []*proto.ItemParam{{ItemId: 222, Count: xc}}
}
// 星辉
if xh != 0 {
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{
ItemId: 221,
ChangeCount: xh,
}}, false, 0)
gachaItem.TransferItems = []*proto.GachaTransferItem{{
Item: &proto.ItemParam{
ItemId: 221,
Count: xh,
},
}}
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: 221, ChangeCount: xh}}, proto.ActionReasonType_ACTION_REASON_GACHA)
gachaItem.TransferItems = []*proto.GachaTransferItem{{Item: &proto.ItemParam{ItemId: 221, Count: xh}}}
}
doGachaRsp.GachaItemList = append(doGachaRsp.GachaItemList, gachaItem)
}
+131 -73
View File
@@ -64,6 +64,7 @@ func (g *Game) UseItem(userId uint32, itemId uint32, targetParam ...uint64) {
for _, itemUse := range itemDataConfig.ItemUseList {
switch itemUse.UseOption {
case constant.ITEM_USE_GAIN_AVATAR:
// 获得角色
if len(itemUse.UseParam) != 1 {
continue
}
@@ -76,9 +77,10 @@ func (g *Game) UseItem(userId uint32, itemId uint32, targetParam ...uint64) {
if avatar == nil {
g.AddPlayerAvatar(userId, uint32(avatarId))
} else {
g.AddPlayerItem(userId, []*ChangeItem{{ItemId: itemId + 100, ChangeCount: 1}}, true, 0)
g.AddPlayerItem(userId, []*ChangeItem{{ItemId: itemId + 100, ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_ADD_AVATAR)
}
case constant.ITEM_USE_RELIVE_AVATAR:
// 复活角色
if len(targetParam) != 1 {
continue
}
@@ -91,6 +93,7 @@ func (g *Game) UseItem(userId uint32, itemId uint32, targetParam ...uint64) {
case constant.ITEM_USE_ADD_SERVER_BUFF:
// 草泥马回血要走ability
case constant.ITEM_USE_GAIN_FLYCLOAK:
// 获得风之翼
if len(itemUse.UseParam) != 1 {
continue
}
@@ -100,11 +103,13 @@ func (g *Game) UseItem(userId uint32, itemId uint32, targetParam ...uint64) {
}
g.AddPlayerFlycloak(userId, uint32(flyCloakId))
case constant.ITEM_USE_GAIN_NAME_CARD:
// 获得名片
if len(itemUse.UseParam) != 0 {
continue
}
g.AddPlayerNameCard(userId, itemId)
case constant.ITEM_USE_GAIN_COSTUME:
// 获得衣装
if len(itemUse.UseParam) != 1 {
continue
}
@@ -113,30 +118,73 @@ func (g *Game) UseItem(userId uint32, itemId uint32, targetParam ...uint64) {
continue
}
g.AddPlayerCostume(userId, uint32(costumeId))
case constant.ITEM_USE_ADD_ELEM_ENERGY:
// 添加元素能量
if len(itemUse.UseParam) != 3 {
continue
}
elementType, err := strconv.Atoi(itemUse.UseParam[0])
if err != nil {
continue
}
sameEnergy, err := strconv.Atoi(itemUse.UseParam[1])
if err != nil {
continue
}
otherEnergy, err := strconv.Atoi(itemUse.UseParam[2])
if err != nil {
continue
}
world := WORLD_MANAGER.GetWorldById(player.WorldId)
if world == nil {
continue
}
dbAvatar := player.GetDbAvatar()
activeAvatarId := world.GetPlayerActiveAvatarId(player)
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
addEnergy := float32(0.0)
if dbAvatar.GetAvatarElementType(worldAvatar.GetAvatarId()) == elementType {
addEnergy = float32(sameEnergy)
} else {
addEnergy = float32(otherEnergy)
}
if worldAvatar.GetAvatarId() != activeAvatarId {
addEnergy *= 0.6
}
g.AddPlayerAvatarEnergy(player.PlayerId, worldAvatar.GetAvatarId(), addEnergy, false)
}
case constant.ITEM_USE_ADD_ALL_ENERGY:
// 添加全体元素能量
if len(itemUse.UseParam) != 1 {
continue
}
addEnergy, err := strconv.Atoi(itemUse.UseParam[0])
if err != nil {
continue
}
world := WORLD_MANAGER.GetWorldById(player.WorldId)
if world == nil {
continue
}
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
g.AddPlayerAvatarEnergy(player.PlayerId, worldAvatar.GetAvatarId(), float32(addEnergy), false)
}
default:
logger.Error("use option not support, useOption: %v, uid: %v", itemUse.UseOption, userId)
}
}
}
type ChangeItem struct {
ItemId uint32
ChangeCount uint32
}
// GetAllItemDataConfig 获取所有物品数据配置表
func (g *Game) GetAllItemDataConfig() map[int32]*gdconf.ItemData {
allItemDataConfig := make(map[int32]*gdconf.ItemData)
for itemId, itemData := range gdconf.GetItemDataMap() {
if itemData.Type == constant.ITEM_TYPE_WEAPON {
// 排除武器
for itemId, itemDataConfig := range gdconf.GetItemDataMap() {
if itemDataConfig.Type != constant.ITEM_TYPE_VIRTUAL &&
itemDataConfig.Type != constant.ITEM_TYPE_MATERIAL &&
itemDataConfig.Type != constant.ITEM_TYPE_FURNITURE {
continue
}
if itemData.Type == constant.ITEM_TYPE_RELIQUARY {
// 排除圣遗物
continue
}
allItemDataConfig[itemId] = itemData
allItemDataConfig[itemId] = itemDataConfig
}
return allItemDataConfig
}
@@ -159,8 +207,13 @@ func (g *Game) GetPlayerItemCount(userId uint32, itemId uint32) uint32 {
}
}
type ChangeItem struct {
ItemId uint32
ChangeCount uint32
}
// AddPlayerItem 添加玩家物品
func (g *Game) AddPlayerItem(userId uint32, itemList []*ChangeItem, isHint bool, hintReason uint16) bool {
func (g *Game) AddPlayerItem(userId uint32, itemList []*ChangeItem, hintReason proto.ActionReasonType) bool {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.Error("player is nil, uid: %v", userId)
@@ -176,70 +229,65 @@ func (g *Game) AddPlayerItem(userId uint32, itemList []*ChangeItem, isHint bool,
StoreType: proto.StoreType_STORE_PACK,
ItemList: make([]*proto.Item, 0),
}
addHintNtf := &proto.ItemAddHintNotify{
Reason: uint32(hintReason),
ItemList: make([]*proto.ItemHint, 0),
}
for itemId, addCount := range itemMap {
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
if itemDataConfig == nil {
continue
}
if itemDataConfig.Type == constant.ITEM_TYPE_WEAPON {
continue
}
if itemDataConfig.Type == constant.ITEM_TYPE_RELIQUARY {
continue
}
if object.ConvInt64ToBool(int64(itemDataConfig.AutoUse)) {
continue
}
prop, exist := constant.VIRTUAL_ITEM_PROP[itemId]
if exist {
// 物品为虚拟物品 角色属性物品数量增加
player.PropMap[prop] += addCount
propList = append(propList, prop)
// 特殊属性变化处理函数
switch itemId {
case constant.ITEM_ID_PLAYER_EXP:
// 冒险阅历
g.HandlePlayerExpAdd(userId)
}
} else {
// 物品为普通物品 直接进背包
// 校验背包物品容量 目前物品包括材料和家具
if dbItem.GetItemMapLen() > constant.STORE_PACK_LIMIT_MATERIAL+constant.STORE_PACK_LIMIT_FURNITURE {
return false
}
dbItem.AddItem(player, itemId, addCount)
}
pbItem := &proto.Item{
pbItemHint := &proto.ItemHint{
ItemId: itemId,
Count: addCount,
Guid: dbItem.GetItemGuid(itemId),
Detail: &proto.Item_Material{
Material: &proto.Material{
Count: dbItem.GetItemCount(itemId),
},
},
}
changeNtf.ItemList = append(changeNtf.ItemList, pbItem)
addHintNtf.ItemList = append(addHintNtf.ItemList, pbItemHint)
switch itemDataConfig.Type {
case constant.ITEM_TYPE_WEAPON:
g.AddPlayerWeapon(player.PlayerId, itemId)
case constant.ITEM_TYPE_RELIQUARY:
g.AddPlayerReliquary(player.PlayerId, itemId)
case constant.ITEM_TYPE_VIRTUAL, constant.ITEM_TYPE_MATERIAL, constant.ITEM_TYPE_FURNITURE:
if object.ConvInt64ToBool(int64(itemDataConfig.AutoUse)) {
continue
}
prop, exist := constant.VIRTUAL_ITEM_PROP[itemId]
if exist {
// 物品为虚拟物品 角色属性物品数量增加
player.PropMap[prop] += addCount
propList = append(propList, prop)
} else {
// 物品为普通物品 直接进背包
// 校验背包物品容量 目前物品包括材料和家具
if dbItem.GetItemMapLen() > constant.STORE_PACK_LIMIT_MATERIAL+constant.STORE_PACK_LIMIT_FURNITURE {
return false
}
dbItem.AddItem(player, itemId, addCount)
}
pbItem := &proto.Item{
ItemId: itemId,
Guid: dbItem.GetItemGuid(itemId),
Detail: &proto.Item_Material{
Material: &proto.Material{
Count: dbItem.GetItemCount(itemId),
},
},
}
changeNtf.ItemList = append(changeNtf.ItemList, pbItem)
}
}
if len(propList) > 0 {
g.SendMsg(cmd.PlayerPropNotify, userId, player.ClientSeq, g.PacketPlayerPropNotify(player, propList...))
}
g.SendMsg(cmd.StoreItemChangeNotify, userId, player.ClientSeq, changeNtf)
if isHint {
if hintReason == 0 {
hintReason = uint16(proto.ActionReasonType_ACTION_REASON_SUBFIELD_DROP)
if len(changeNtf.ItemList) > 0 {
g.SendMsg(cmd.StoreItemChangeNotify, userId, player.ClientSeq, changeNtf)
}
if len(addHintNtf.ItemList) > 0 {
if hintReason != proto.ActionReasonType_ACTION_REASON_NONE {
g.SendMsg(cmd.ItemAddHintNotify, userId, player.ClientSeq, addHintNtf)
}
itemAddHintNotify := &proto.ItemAddHintNotify{
Reason: uint32(hintReason),
ItemList: make([]*proto.ItemHint, 0),
}
for _, changeItem := range itemList {
itemAddHintNotify.ItemList = append(itemAddHintNotify.ItemList, &proto.ItemHint{
ItemId: changeItem.ItemId,
Count: changeItem.ChangeCount,
IsNew: false,
})
}
g.SendMsg(cmd.ItemAddHintNotify, userId, player.ClientSeq, itemAddHintNotify)
}
for itemId, addCount := range itemMap {
g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_OBTAIN_ITEM, "", int32(itemId))
@@ -252,6 +300,20 @@ func (g *Game) AddPlayerItem(userId uint32, itemList []*ChangeItem, isHint bool,
g.UseItem(userId, itemId)
}
}
// 特殊属性变化处理函数
switch itemId {
case constant.ITEM_ID_PLAYER_EXP:
// 冒险阅历
g.HandlePlayerExpAdd(userId)
case constant.ITEM_ID_AVATAR_EXP:
// 角色经验
world := WORLD_MANAGER.GetWorldById(player.WorldId)
if world != nil {
activeAvatarId := world.GetPlayerActiveAvatarId(player)
dbAvatar := player.GetDbAvatar()
g.UpgradePlayerAvatar(player, dbAvatar.GetAvatarById(activeAvatarId), addCount)
}
}
}
return true
}
@@ -290,12 +352,6 @@ func (g *Game) CostPlayerItem(userId uint32, itemList []*ChangeItem) bool {
// 物品为虚拟物品 角色属性物品数量减少
player.PropMap[prop] -= costCount
propList = append(propList, prop)
// 特殊属性变化处理函数
switch itemId {
case constant.ITEM_ID_PLAYER_EXP:
// 冒险阅历应该也没人会去扣吧?
g.HandlePlayerExpAdd(userId)
}
} else {
// 物品为普通物品 直接扣除
dbItem.CostItem(player, itemId, costCount)
@@ -315,7 +371,9 @@ func (g *Game) CostPlayerItem(userId uint32, itemList []*ChangeItem) bool {
if len(propList) > 0 {
g.SendMsg(cmd.PlayerPropNotify, userId, player.ClientSeq, g.PacketPlayerPropNotify(player, propList...))
}
g.SendMsg(cmd.StoreItemChangeNotify, userId, player.ClientSeq, changeNtf)
if len(changeNtf.ItemList) > 0 {
g.SendMsg(cmd.StoreItemChangeNotify, userId, player.ClientSeq, changeNtf)
}
if len(delNtf.GuidList) > 0 {
g.SendMsg(cmd.StoreItemDelNotify, userId, player.ClientSeq, delNtf)
}
+4 -2
View File
@@ -174,13 +174,15 @@ func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) {
}
if canAccept {
if questData.QuestId == 35304 {
// TODO 任务异常的权柄释放元素爆发时没有能量
world := WORLD_MANAGER.GetWorldById(player.WorldId)
if world != nil {
g.AddPlayerAvatarEnergy(player.PlayerId, world.GetPlayerActiveAvatarId(player), 0.0, true)
}
}
if questData.QuestId == 35721 {
// TODO 由于第一次风龙任务进入秘境客户端会无限重连相关原因暂时屏蔽
// TODO 由于风龙任务进入秘境客户端会无限重连相关原因暂时屏蔽
// 直接福瑞
COMMAND_MANAGER.gmCmd.GMFreeMode(player.PlayerId)
continue
}
@@ -503,7 +505,7 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin
if len(questDataConfig.ItemIdList) != 0 {
for index, itemId := range questDataConfig.ItemIdList {
questItem := []*ChangeItem{{ItemId: uint32(itemId), ChangeCount: uint32(questDataConfig.ItemCountList[index])}}
g.AddPlayerItem(player.PlayerId, questItem, true, 0)
g.AddPlayerItem(player.PlayerId, questItem, proto.ActionReasonType_ACTION_REASON_QUEST_ITEM)
}
}
}
+5 -6
View File
@@ -1174,9 +1174,8 @@ func (g *Game) CreateMonster(player *model.Player, pos *model.Vector, monsterId
}
if pos == nil {
pos = g.GetPlayerPos(player)
pos.X += random.GetRandomFloat64(1.0, 10.0)
pos.Y = 0.0
pos.Z += random.GetRandomFloat64(1.0, 10.0)
pos.X += random.GetRandomFloat64(-5.0, 5.0)
pos.Z += random.GetRandomFloat64(-5.0, 5.0)
}
rot := new(model.Vector)
rot.Y = random.GetRandomFloat64(0.0, 360.0)
@@ -1214,8 +1213,8 @@ func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId ui
scene := world.GetSceneById(player.GetSceneId())
if pos == nil {
pos = g.GetPlayerPos(player)
pos.X += random.GetRandomFloat64(1.0, 10.0)
pos.Z += random.GetRandomFloat64(1.0, 10.0)
pos.X += random.GetRandomFloat64(-5.0, 5.0)
pos.Z += random.GetRandomFloat64(-5.0, 5.0)
}
rot := new(model.Vector)
rot.Y = random.GetRandomFloat64(0.0, 360.0)
@@ -1322,7 +1321,7 @@ func (g *Game) GetWeatherAreaClimate(weatherAreaId uint32) uint32 {
// 获取天气数据配置表
weatherConfig := gdconf.GetWeatherDataById(int32(weatherAreaId))
if weatherConfig == nil {
logger.Error("weather data config not exist, weatherId: %v", weatherAreaId)
// logger.Error("weather data config not exist, weatherId: %v", weatherAreaId)
return 0
}
// 如果指定了则使用指定的天气
+2 -8
View File
@@ -84,10 +84,7 @@ func (g *Game) BuyGoodsReq(player *model.Player, payloadMsg pb.Message) {
return
}
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{
ItemId: buyItemId,
ChangeCount: buyItemCount,
}}, true, uint16(proto.ActionReasonType_ACTION_REASON_SHOP))
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: buyItemId, ChangeCount: buyItemCount}}, proto.ActionReasonType_ACTION_REASON_SHOP)
req.Goods.BoughtNum = g.GetPlayerItemCount(player.PlayerId, buyItemId)
buyGoodsRsp := &proto.BuyGoodsRsp{
@@ -113,10 +110,7 @@ func (g *Game) McoinExchangeHcoinReq(player *model.Player, payloadMsg pb.Message
return
}
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{
ItemId: 201,
ChangeCount: count,
}}, false, 0)
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: 201, ChangeCount: count}}, proto.ActionReasonType_ACTION_REASON_SHOP)
mcoinExchangeHcoinRsp := &proto.McoinExchangeHcoinRsp{
Hcoin: req.Hcoin,
+1 -1
View File
@@ -406,7 +406,7 @@ func (g *Game) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Message) {
})
}
// 给予玩家返回的矿石
g.AddPlayerItem(player.PlayerId, addItemList, false, 0)
g.AddPlayerItem(player.PlayerId, addItemList, proto.ActionReasonType_ACTION_REASON_WEAPON_UPGRADE)
weaponUpgradeRsp := &proto.WeaponUpgradeRsp{
CurLevel: uint32(weapon.Level),
+14 -18
View File
@@ -429,28 +429,17 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) {
}
logger.Debug("[GadgetInteractReq] GadgetData: %+v, EntityId: %v, uid: %v", gadgetDataConfig, entity.GetId(), player.PlayerId)
switch gadgetDataConfig.Type {
case constant.GADGET_TYPE_GADGET, constant.GADGET_TYPE_EQUIP:
case constant.GADGET_TYPE_GADGET, constant.GADGET_TYPE_EQUIP, constant.GADGET_TYPE_ENERGY_BALL:
// 掉落物捡起
interactType = proto.InteractType_INTERACT_PICK_ITEM
gadgetNormalEntity := gadgetEntity.GetGadgetNormalEntity()
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{
ItemId: gadgetNormalEntity.GetItemId(),
ChangeCount: 1,
}}, true, 0)
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: gadgetNormalEntity.GetItemId(), ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_SUBFIELD_DROP)
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
case constant.GADGET_TYPE_ENERGY_BALL:
// TODO 元素能量球吸收
interactType = proto.InteractType_INTERACT_PICK_ITEM
activeAvatarId := world.GetPlayerActiveAvatarId(player)
g.AddPlayerAvatarEnergy(player.PlayerId, activeAvatarId, 10.0, false)
case constant.GADGET_TYPE_GATHER_OBJECT:
// 采集物摘取
interactType = proto.InteractType_INTERACT_GATHER
gadgetNormalEntity := gadgetEntity.GetGadgetNormalEntity()
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{
ItemId: gadgetNormalEntity.GetItemId(),
ChangeCount: 1,
}}, true, 0)
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: gadgetNormalEntity.GetItemId(), ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_GATHER)
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
case constant.GADGET_TYPE_CHEST:
// 宝箱开启
@@ -472,6 +461,7 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) {
logger.Error("not support gadget type: %v, uid: %v", gadgetDataConfig.Type, player.PlayerId)
}
case constant.ENTITY_TYPE_MONSTER:
// TODO 环境动物掉落道具
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
default:
logger.Error("not support entity type: %v, uid: %v", entity.GetEntityType(), player.PlayerId)
@@ -607,7 +597,7 @@ func (g *Game) monsterDrop(player *model.Player, monsterDropType int, hpDropId i
if itemDataConfig.GadgetId != 0 {
g.CreateDropGadget(player, entity.GetPos(), uint32(itemDataConfig.GadgetId), itemId, count)
} else {
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: itemId, ChangeCount: count}}, true, 0)
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: itemId, ChangeCount: count}}, proto.ActionReasonType_ACTION_REASON_SUBFIELD_DROP)
}
}
}
@@ -648,7 +638,7 @@ func (g *Game) chestDrop(player *model.Player, entity *Entity) {
if itemDataConfig.GadgetId != 0 {
g.CreateDropGadget(player, entity.GetPos(), uint32(itemDataConfig.GadgetId), itemId, count)
} else {
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: itemId, ChangeCount: count}}, true, 0)
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: itemId, ChangeCount: count}}, proto.ActionReasonType_ACTION_REASON_SUBFIELD_DROP)
}
}
}
@@ -704,7 +694,10 @@ func (g *Game) doRandDropOnce(dropDataConfig *gdconf.DropData) map[int32]int32 {
for _, subDrop := range dropDataConfig.SubDropList {
sumWeight += subDrop.Weight
if sumWeight > randNum {
dropMap[subDrop.Id] = random.GetRandomInt32(subDrop.CountRange[0], subDrop.CountRange[1])
count := random.GetRandomInt32(subDrop.CountRange[0], subDrop.CountRange[1])
if count > 0 {
dropMap[subDrop.Id] = count
}
break
}
}
@@ -713,7 +706,10 @@ func (g *Game) doRandDropOnce(dropDataConfig *gdconf.DropData) map[int32]int32 {
randNum := random.GetRandomInt32(0, gdconf.RandomTypeIndepWeight-1)
for _, subDrop := range dropDataConfig.SubDropList {
if subDrop.Weight > randNum {
dropMap[subDrop.Id] += random.GetRandomInt32(subDrop.CountRange[0], subDrop.CountRange[1])
count := random.GetRandomInt32(subDrop.CountRange[0], subDrop.CountRange[1])
if count > 0 {
dropMap[subDrop.Id] += count
}
}
}
}
+13
View File
@@ -228,3 +228,16 @@ func (a *DbAvatar) TakeOffWeapon(avatarId uint32, weapon *Weapon) {
weapon.AvatarId = 0
delete(avatar.EquipGuidMap, weapon.Guid)
}
func (a *DbAvatar) GetAvatarElementType(avatarId uint32) int {
avatar := a.AvatarMap[avatarId]
skillDepotDataConfig := gdconf.GetAvatarSkillDepotDataById(int32(avatar.SkillDepotId))
if skillDepotDataConfig == nil {
return 0
}
avatarSkillDataConfig := gdconf.GetAvatarSkillDataById(skillDepotDataConfig.EnergySkill)
if avatarSkillDataConfig == nil {
return 0
}
return int(avatarSkillDataConfig.CostElemType)
}
+3 -3
View File
@@ -37,7 +37,7 @@ func GetRandomByteHexStr(len int) string {
}
func GetRandomInt32(min int32, max int32) int32 {
if max <= min {
if max < min {
return 0
}
r := rand.Int31n(max-min+1) + min
@@ -45,7 +45,7 @@ func GetRandomInt32(min int32, max int32) int32 {
}
func GetRandomFloat32(min float32, max float32) float32 {
if max <= min {
if max < min {
return 0.0
}
r := rand.Float32()*(max-min) + min
@@ -53,7 +53,7 @@ func GetRandomFloat32(min float32, max float32) float32 {
}
func GetRandomFloat64(min float64, max float64) float64 {
if max <= min {
if max < min {
return 0.0
}
r := rand.Float64()*(max-min) + min