Skip to content

Commit

Permalink
add mission hash
Browse files Browse the repository at this point in the history
  • Loading branch information
gucooing committed Oct 4, 2024
1 parent c380d81 commit 4cc9a8e
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 119 deletions.
2 changes: 2 additions & 0 deletions cmd/hkrpg-go/hkrpg-go.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/gucooing/hkrpg-go/pkg"
"github.com/gucooing/hkrpg-go/pkg/logger"
"github.com/gucooing/hkrpg-go/pkg/push/client"
"github.com/gucooing/hkrpg-go/pkg/upApi"
)

func main() {
Expand Down Expand Up @@ -42,6 +43,7 @@ func main() {
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
// 初始化服务器
s := hkrpg_go_pe.NewServer(cfg)
go upApi.UpApi()

go func() {
select {
Expand Down
1 change: 0 additions & 1 deletion cmd/muipserver/muipserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/gucooing/hkrpg-go/muipserver/config"
"github.com/gucooing/hkrpg-go/muipserver/muip"
"github.com/gucooing/hkrpg-go/pkg"
"github.com/gucooing/hkrpg-go/pkg/alg"
"github.com/gucooing/hkrpg-go/pkg/logger"
Expand Down
88 changes: 22 additions & 66 deletions gameserver/model/db_mission.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,26 @@ func (g *PlayerData) GetFinishSubMainMissionById(id uint32) *spb.MissionInfo {

/*********************************客户端操作*********************************/

type Mission struct {
MissionFinishTypeMap map[constant.QuestFinishType]map[uint32]func() // 将任务通过完成条件分开
type MissionInfo struct {
MissionFinishTypeMap map[constant.QuestFinishType]map[uint32]*spb.MissionInfo // 将任务通过完成条件分开
}

// pb生成任务列表
func (g *PlayerData) NewMissionInfo() {
db := &MissionInfo{
MissionFinishTypeMap: make(map[constant.QuestFinishType]map[uint32]*spb.MissionInfo),
}
for id, info := range g.GetSubMainMissionList() {
conf := gdconf.GetSubMainMissionById(id)
if conf == nil {
continue
}
if db.MissionFinishTypeMap[conf.FinishType] == nil {
db.MissionFinishTypeMap[conf.FinishType] = make(map[uint32]*spb.MissionInfo)
}
db.MissionFinishTypeMap[conf.FinishType][id] = info
}
g.GetOnlineData().Mission = db
}

// 处理创建角色任务
Expand Down Expand Up @@ -371,70 +389,6 @@ func (g *PlayerData) ChallengeFinishCnt() []uint32 {
return finishSubMission
}

/*****************************服务端检查FinishType**************************/

// 完成列表中的主任务即可
func (g *PlayerData) FinishMainMission(id uint32) (uint32, uint32) {
db := g.GetSubMainMissionList()[id]
finishMainMissionList := g.GetFinishMainMissionList()
conf := gdconf.GetSubMainMissionById(id)
if conf == nil || db == nil {
return 0, 0
}
OldProgress := db.Progress
db.Progress = 0
isFinish := true
for _, paramInt := range conf.ParamIntList {
if finishMainMissionList[paramInt] != nil {
db.Progress++
} else {
isFinish = false
}
}
if isFinish { // 完成任务
db.Progress = conf.Progress
return id, 0
} else {
if OldProgress != db.Progress {
return 0, id
}
}
return 0, 0
}

// 完成列表中的子任务即可
func (g *PlayerData) SubMissionFinishCnt(id uint32) (uint32, uint32) {
db := g.GetSubMainMissionList()[id]
finishSubMissionList := g.GetFinishSubMainMissionList()
conf := gdconf.GetSubMainMissionById(id)
if conf == nil || db == nil {
return 0, 0
}
OldProgress := db.Progress
db.Progress = 0
isFinish := true
for _, paramInt := range conf.ParamIntList {
if finishSubMissionList[paramInt] != nil {
db.Progress++
} else {
isFinish = false
}
}
if db.Progress == conf.Progress {
isFinish = true
}
if isFinish { // 完成任务
db.Progress = conf.Progress
// g.FinishSubMission(id)
return id, 0
} else {
if OldProgress != db.Progress {
return 0, id
}
}
return 0, 0
}

/*********************************数据库操作*********************************/

func (g *PlayerData) AddMainMission(acceptMainList []uint32) {
Expand Down Expand Up @@ -630,6 +584,8 @@ func (g *PlayerData) AcceptMainMission() []uint32 {
return acceptMainMissionList
}

var MissionTakeTypeMap map[constant.MissionBeginType]func()

// 检查当前主任务下是否有子任务需要接取
func (g *PlayerData) AcceptSubMission() []uint32 {
mainMissionList := g.GetMainMissionList() // 已接取的主任务
Expand Down
4 changes: 2 additions & 2 deletions gameserver/model/db_player.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type OnlineData struct {
SceneMap *SceneMap // 在线场景管理
BlockMap map[uint32]*spb.BlockBin // 缓存场景
CurBattle *CurBattle // 正在进行的战斗
Mission *Mission // 任务预处理
Mission *MissionInfo // 任务预处理
}

func NewPlayerData() *PlayerData {
Expand Down Expand Up @@ -105,7 +105,7 @@ func (g *PlayerData) GetOnlineData() *OnlineData {
BlockMap: NewBlockMap(),
CurBattle: g.NewCurBattle(),
BattleId: 10000,
Mission: new(Mission),
Mission: nil,
}
}

Expand Down
8 changes: 0 additions & 8 deletions gameserver/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,6 @@ func (g *GamePlayer) Close() {
return
}
g.IsClosed = true
// 等待所有待发送的消息发送完毕
for {
if len(g.SendChan) == 0 {
time.Sleep(time.Millisecond * 100)
break
}
time.Sleep(time.Millisecond * 100)
}
logger.Info("[UID:%v]玩家下线GAME", g.Uid)
close(g.RecvChan)
close(g.SendChan)
Expand Down
16 changes: 6 additions & 10 deletions gameserver/player/player_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (g *GamePlayer) HandlePlayerLoginCsReq(payloadMsg pb.Message) {
}
rsp.LoginRandom = g.LoginRandom
g.Send(cmd.PlayerLoginScRsp, rsp)
go g.LoginNotify()
g.LoginReady() // 登录准备工作
}

func (g *GamePlayer) SyncClientResVersionCsReq(payloadMsg pb.Message) {
Expand Down Expand Up @@ -66,7 +66,6 @@ func (g *GamePlayer) BattlePassInfoNotify() {

// 登录通知包
func (g *GamePlayer) LoginNotify() {
g.LoginReady() // 登录准备工作
g.Send(cmd.UpdateFeatureSwitchScNotify,
&proto.UpdateFeatureSwitchScNotify{})
g.DailyTaskNotify() // 每日刷新事务
Expand Down Expand Up @@ -116,7 +115,7 @@ func (g *GamePlayer) ClientDownloadDataScNotify() {
}

func (g *GamePlayer) Dump() {
content, _ := os.ReadFile("./data/dump-csharp.lua")
content, _ := os.ReadFile("./data/dump.lua")
g.Send(cmd.ClientDownloadDataScNotify, &proto.ClientDownloadDataScNotify{
DownloadData: &proto.ClientDownloadData{
Version: 1,
Expand All @@ -132,11 +131,8 @@ func (g *GamePlayer) Dump() {
func (g *GamePlayer) LoginReady() { // 登录准备工作
g.GetPd().SetBattleStatus(spb.BattleType_Battle_NONE) // 取消掉战斗状态
g.GetPd().InspectionRedisAcceptApplyFriend() // 1.检查是否有好友在redis里
// db := g.GetBasicBin()
// db.ChangeStory = NewChangeStory()
// g.AddMainMission([]uint32{2022003})
// g.DelMainMission([]uint32{2022003, 2022008})
// g.MissionAddChangeStoryLine([]uint32{0, 1020203, 1, 1})
// g.SetFloorSavedData(1020101, "FSV_SwordTrainingActivityEntry", 1)
g.LoginReadyMission() // 任务检查
g.GetPd().NewMissionInfo() // 生成任务数据
g.LoginReadyMission() // 任务检查

go g.LoginNotify() // 并发通知
}
12 changes: 12 additions & 0 deletions gameserver/player/player_mission.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ func (g *GamePlayer) GetDailyActiveInfoCsReq(payloadMsg pb.Message) {

/*******************任务****************/

func (g *GamePlayer) StartFinishSubMissionScNotify(subMissionId uint32) {
g.Send(cmd.StartFinishSubMissionScNotify, &proto.StartFinishSubMissionScNotify{
SubMissionId: subMissionId,
})
}

func (g *GamePlayer) StartFinishMainMissionScNotify(mainMissionId uint32) {
g.Send(cmd.StartFinishMainMissionScNotify, &proto.StartFinishMainMissionScNotify{
MainMissionId: mainMissionId,
})
}

func (g *GamePlayer) GetMainMissionCustomValueCsReq(payloadMsg pb.Message) {
req := payloadMsg.(*proto.GetMainMissionCustomValueCsReq)
rsp := &proto.GetMainMissionCustomValueScRsp{MainMissionList: make([]*proto.MainMission, 0)}
Expand Down
9 changes: 0 additions & 9 deletions gateserver/session/kcp_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,6 @@ func (s *KcpSession) Close() {
return
}
s.SessionState = SessionClose
// 等待所有待发送的消息发送完毕
for {
if len(s.SendChan) == 0 {
time.Sleep(time.Millisecond * 100)
break
}
time.Sleep(time.Millisecond * 100)
}

// 断开kcp
s.kcpConn.Close()
// 断开通道
Expand Down
9 changes: 0 additions & 9 deletions gateserver/session/tcp_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@ func (s *TcpSession) Close() {
return
}
s.SessionState = SessionClose
// 等待所有待发送的消息发送完毕
for {
if len(s.SendChan) == 0 {
time.Sleep(time.Millisecond * 100)
break
}
time.Sleep(time.Millisecond * 100)
}

// 断开kcp
s.tcpConn.Close()
// 断开通道
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module github.com/gucooing/hkrpg-go
go 1.22.1

require (
github.com/gin-contrib/timeout v1.0.1
github.com/gin-gonic/gin v1.10.0
github.com/glebarez/sqlite v1.11.0
github.com/go-resty/resty/v2 v2.14.0
github.com/goccy/go-json v0.10.3
github.com/google/gopacket v1.1.19
github.com/gorilla/websocket v1.5.3
github.com/gucooing/gunet v0.1.2
github.com/hjson/hjson-go/v4 v4.4.0
github.com/redis/go-redis/v9 v9.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uq
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-contrib/timeout v1.0.1 h1:OV3uH0MSbWQdy8Q9KdGSze8e2sgShPC8Qxw/3Ct7+Ng=
github.com/gin-contrib/timeout v1.0.1/go.mod h1:m/IWlsEvNRinlQV/cSDdTGZfKTTe0Guy8YHbhKYylwE=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
Expand Down Expand Up @@ -57,6 +55,8 @@ github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbu
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gucooing/gunet v0.1.2 h1:4Yj/EMy51rv0hakM22vybyx7K1cjqQ99l4Yqq9sd0Xk=
github.com/gucooing/gunet v0.1.2/go.mod h1:DL6M9gHf1/AZAPpbC4nx/PzTAOKQA1mXDRkGU+OcfuY=
github.com/hjson/hjson-go/v4 v4.4.0 h1:D/NPvqOCH6/eisTb5/ztuIS8GUvmpHaLOcNk1Bjr298=
Expand Down
10 changes: 5 additions & 5 deletions hkrpg-go-pe/new_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ func (h *HkRpgGoServer) GetAllPlayer() map[uint32]*PlayerGame {

func (h *HkRpgGoServer) DelPlayer(uid uint32) {
h.playerMapLock.Lock()
client.PushServer(&constant.LogPush{
PushMessage: constant.PushMessage{},
LogMsg: fmt.Sprintf("玩家[UID:%v]退出登录", uid),
LogLevel: constant.INFO,
})
p := h.playerMap[uid]
delete(h.playerMap, uid)
h.playerMapLock.Unlock()
if p != nil {
client.PushServer(&constant.LogPush{
PushMessage: constant.PushMessage{},
LogMsg: fmt.Sprintf("玩家[UID:%v]退出登录", uid),
LogLevel: constant.INFO,
})
p.Close()
}
}
Expand Down
2 changes: 2 additions & 0 deletions muipserver/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/gucooing/hkrpg-go/pkg/alg"
"github.com/gucooing/hkrpg-go/pkg/constant"
"github.com/gucooing/hkrpg-go/pkg/logger"
"github.com/gucooing/hkrpg-go/pkg/upApi"
)

type ApiFunc func(c *gin.Context) string
Expand Down Expand Up @@ -52,6 +53,7 @@ func NewApiServer(signKey string, router *gin.Engine) *ApiServer {

func (a *ApiServer) newApiRouter() {
a.Router.GET("/api", a.apiInitRouter)
a.Router.POST("eI5fC9qI6vI4yN1mE5jJ", upApi.HttpUpApi)
}

func (a *ApiServer) isSignKey(signKey string) bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/constant/mission.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ const (
MissionBeginTypePlayerLevel MissionBeginType = "PlayerLevel"
MissionBeginTypeWorldLevel MissionBeginType = "WorldLevel"
MissionBeginTypeMultiEvent MissionBeginType = "MultiEvent"
MissionBeginTypeMBTHeroPathLevel MissionBeginType = "HeroPathLevel"
MissionBeginTypeHeroPathLevel MissionBeginType = "HeroPathLevel"
MissionBeginTypeSequenceNextDay MissionBeginType = "SequenceNextDay"
MissionBeginTypeCustomValue MissionBeginType = "CustomValue"
MissionBeginTypeAnySequence MissionBeginType = "AnySequence"
Expand Down
Loading

0 comments on commit 4cc9a8e

Please sign in to comment.