Skip to content

Commit

Permalink
fix SummonUnitTriggers
Browse files Browse the repository at this point in the history
  • Loading branch information
gucooing committed Aug 21, 2024
1 parent 5627a99 commit 59c3376
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 56 deletions.
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM golang:1.23-alpine as builder
LABEL authors="gucooing"

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk add --no-cache gcc musl-dev linux-headers
WORKDIR /usr/hkrpg
ADD go.mod .
ADD go.sum .
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,direct
ENV CGO_ENABLED=1
RUN go mod download && go mod verify
COPY . .
RUN go build -tags netgo -o /usr/hkrpg/hkrpg-go hkrpg-go-pe.go

FROM alpine:latest
WORKDIR /usr/hkrpg
COPY --from=builder /usr/hkrpg/hkrpg-go /usr/hkrpg/hkrpg-go
COPY --from=builder /usr/hkrpg/data/ /usr/hkrpg/data/
EXPOSE 8080/tcp 20041/udp
ENTRYPOINT ["./hkrpg-go"]
16 changes: 16 additions & 0 deletions gameserver/model/db_battle.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ func (g *PlayerData) GetSceneMonsterWaveByStageID(stageID, worldLevel, waveId ui
func (g *PlayerData) GetBattleBuff(avatarMap map[uint32]*BattleAvatar) []*proto.BattleBuff {
buffList := make([]*proto.BattleBuff, 0)
mazeBufflist := g.GetMazeBuffList()
summonUnitInfo := g.GetSummonUnitInfo()
// var targetIndex = 0
for _, buff := range mazeBufflist {
if buff.AvatarId != 0 { // add avatarBuff
Expand All @@ -790,6 +791,21 @@ func (g *PlayerData) GetBattleBuff(avatarMap map[uint32]*BattleAvatar) []*proto.
continue
}
}
// add SummonUnitBuff
var waveFlagMap = make(map[uint32]uint32)
for _, avatarInfo := range avatarMap {
if avatarInfo.AvatarId == summonUnitInfo.AvatarId {
for _, buff := range summonUnitInfo.BuffList {
waveFlagMap[buff.BuffId]++
buffList = append(buffList, &proto.BattleBuff{
Id: buff.BuffId,
Level: 1,
OwnerIndex: avatarInfo.Index,
WaveFlag: waveFlagMap[buff.BuffId],
})
}
}
}

// 默认buff
// buffList = append(buffList, &proto.BattleBuff{
Expand Down
86 changes: 52 additions & 34 deletions gameserver/model/db_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ type EntityAll interface {
}

type SceneMap struct {
LoadedGroup map[uint32]*GroupInfo // 已加载场景
NoLoadedGroup map[uint32]*GroupInfo // 未加载场景
LoadedGroup map[uint32]*GroupInfo // 已加载场景
NoLoadedGroup map[uint32]*GroupInfo // 未加载场景
SummonUnitInfo *SummonUnitInfo // 领域
}

type SummonUnitInfo struct {
EntityId uint32
AvatarId uint32
AttachEntityId uint32
SummonUnitId uint32
Pos *proto.Vector
BuffList []*OnBuffMap
}

type GroupInfo struct {
Expand Down Expand Up @@ -84,6 +94,14 @@ func (g *PlayerData) GetSceneMap() *SceneMap {
return db.SceneMap
}

func (g *PlayerData) GetSummonUnitInfo() *SummonUnitInfo {
db := g.GetSceneMap()
if db.SummonUnitInfo == nil {
db.SummonUnitInfo = new(SummonUnitInfo)
}
return db.SummonUnitInfo
}

func (g *PlayerData) GetLoadedGroup() map[uint32]*GroupInfo {
db := g.GetSceneMap()
if db.LoadedGroup == nil {
Expand Down Expand Up @@ -1368,38 +1386,6 @@ func (g *PlayerData) GetAddAvatarSceneEntityRefreshInfo(lineUp *spb.Line, pos, r
return sceneEntityRefreshInfo
}

// 添加Buff
func (g *PlayerData) GetAddBuffSceneEntityRefreshInfo(casterEntityId, summonId uint32, pos *proto.Vector) []*proto.GroupRefreshInfo {
groupRefreshInfo := make([]*proto.GroupRefreshInfo, 0)
sceneGroupRefreshInfo := &proto.GroupRefreshInfo{
RefreshEntity: make([]*proto.SceneEntityRefreshInfo, 0),
}
sceneEntityRefreshInfo := &proto.SceneEntityRefreshInfo{
Refresh: &proto.SceneEntityRefreshInfo_AddEntity{
AddEntity: &proto.SceneEntityInfo{
Motion: &proto.MotionInfo{
Pos: pos,
Rot: &proto.Vector{Y: 139439},
},
EntityId: g.GetNextGameObjectGuid(),
EntityOneofCase: &proto.SceneEntityInfo_SummonUnit{
SummonUnit: &proto.SceneSummonUnitInfo{
CasterEntityId: casterEntityId,
AttachEntityId: casterEntityId,
SummonUnitId: summonId,
CreateTimeMs: uint64(time.Now().UnixMilli()),
TriggerNameList: make([]string, 0),
LifeTimeMs: -1,
},
},
},
},
}
sceneGroupRefreshInfo.RefreshEntity = append(sceneGroupRefreshInfo.RefreshEntity, sceneEntityRefreshInfo)
groupRefreshInfo = append(groupRefreshInfo, sceneGroupRefreshInfo)
return groupRefreshInfo
}

func (g *PlayerData) GetSceneGroupRefreshInfoByLineUP(lineUp *spb.Line, pos, rot *proto.Vector) []*proto.GroupRefreshInfo {
groupRefreshInfo := make([]*proto.GroupRefreshInfo, 0)
sceneGroupRefreshInfo := &proto.GroupRefreshInfo{
Expand Down Expand Up @@ -1442,6 +1428,38 @@ func (g *PlayerData) GetSceneGroupRefreshInfoByLineUP(lineUp *spb.Line, pos, rot
return groupRefreshInfo
}

// 添加领域
func (g *PlayerData) GetAddBuffSceneEntityRefreshInfo(casterEntityId, summonId, entityId uint32, pos *proto.Vector) []*proto.GroupRefreshInfo {
groupRefreshInfo := make([]*proto.GroupRefreshInfo, 0)
sceneGroupRefreshInfo := &proto.GroupRefreshInfo{
RefreshEntity: make([]*proto.SceneEntityRefreshInfo, 0),
}
sceneEntityRefreshInfo := &proto.SceneEntityRefreshInfo{
Refresh: &proto.SceneEntityRefreshInfo_AddEntity{
AddEntity: &proto.SceneEntityInfo{
Motion: &proto.MotionInfo{
Pos: pos,
Rot: &proto.Vector{Y: 139439},
},
EntityId: entityId,
EntityOneofCase: &proto.SceneEntityInfo_SummonUnit{
SummonUnit: &proto.SceneSummonUnitInfo{
CasterEntityId: casterEntityId,
AttachEntityId: casterEntityId,
SummonUnitId: summonId,
CreateTimeMs: uint64(time.Now().UnixMilli()),
TriggerNameList: make([]string, 0),
LifeTimeMs: -1,
},
},
},
},
}
sceneGroupRefreshInfo.RefreshEntity = append(sceneGroupRefreshInfo.RefreshEntity, sceneEntityRefreshInfo)
groupRefreshInfo = append(groupRefreshInfo, sceneGroupRefreshInfo)
return groupRefreshInfo
}

func (g *PlayerData) GetSpringRecoverConfig() *proto.SpringRecoverConfig {
info := &proto.SpringRecoverConfig{
DefaultHp: 10000,
Expand Down
2 changes: 1 addition & 1 deletion gameserver/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
pb "google.golang.org/protobuf/proto"
)

var LogMsgPlayer uint32 = 5
var LogMsgPlayer uint32 = 2

type GamePlayer struct {
Uid uint32
Expand Down
46 changes: 42 additions & 4 deletions gameserver/player/player_battle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strconv"

"github.com/gucooing/hkrpg-go/gameserver/model"
"github.com/gucooing/hkrpg-go/pkg/constant"
"github.com/gucooing/hkrpg-go/pkg/gdconf"
"github.com/gucooing/hkrpg-go/pkg/logger"
"github.com/gucooing/hkrpg-go/protocol/cmd"
Expand Down Expand Up @@ -148,10 +149,13 @@ func (g *GamePlayer) SceneCastSkillCsReq(payloadMsg pb.Message) {
g.GetPd().SceneCastSkill(battleBackup, skill, req)
// summonun
if battleBackup.SummonUnitId != 0 {
g.Send(cmd.SceneGroupRefreshScNotify, &proto.SceneGroupRefreshScNotify{
GroupRefreshList: g.GetPd().GetAddBuffSceneEntityRefreshInfo(
battleBackup.Sce.AvatarEntityId, battleBackup.SummonUnitId, req.TargetMotion.Rot),
})
db := g.GetPd().GetSummonUnitInfo()
db.AvatarId = battleBackup.Sce.AvatarId
db.AttachEntityId = battleBackup.Sce.AvatarEntityId
db.EntityId = g.GetPd().GetNextGameObjectGuid()
db.SummonUnitId = battleBackup.SummonUnitId
db.Pos = req.TargetMotion.Pos
g.AddSummonUnitSceneGroupRefreshScNotify()
}
if len(battleBackup.Sce.EvenIdList) == 0 || !battleBackup.IsBattle { // 是否满足战斗条件
g.Send(cmd.SceneCastSkillScRsp, rsp)
Expand Down Expand Up @@ -351,6 +355,40 @@ func (g *GamePlayer) ActivateFarmElementCsReq(payloadMsg pb.Message) {
g.Send(cmd.ActivateFarmElementScRsp, rsp)
}

func (g *GamePlayer) RefreshTriggerByClientCsReq(payloadMsg pb.Message) {
req := payloadMsg.(*proto.RefreshTriggerByClientCsReq)
db := g.GetPd().GetSummonUnitInfo()
if db.EntityId == req.TriggerEntityId {
conf := gdconf.GetSummonUnitMazeSkillAction(db.SummonUnitId, req.TriggerName)
if conf != nil {
for _, action := range conf {
if action.Type == constant.AddMazeBuff {
if db.BuffList == nil {
db.BuffList = make([]*model.OnBuffMap, 0)
}
db.BuffList = append(db.BuffList, &model.OnBuffMap{
AvatarId: 0,
BuffId: action.Id,
Level: 1,
Count: 0,
LifeCount: 0,
AddTime: 0,
LifeTime: 0,
})
}
}
}
}

rsp := &proto.RefreshTriggerByClientScRsp{
RefreshTrigger: true,
Retcode: 0,
TriggerName: req.TriggerName,
TriggerEntityId: req.TriggerEntityId,
}
g.Send(cmd.RefreshTriggerByClientScRsp, rsp)
}

/***********************************物品破坏处理***********************************/

func (g *GamePlayer) SceneCastSkillProp(sce *model.SceneCastEntity) {
Expand Down
21 changes: 11 additions & 10 deletions gameserver/player/player_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ func (r *RouteManager) initRoute(g *GamePlayer) {
cmd.StartWolfBroGameCsReq: g.StartWolfBroGameCsReq, // 变身
cmd.SetGroupCustomSaveDataCsReq: g.SetGroupCustomSaveDataCsReq,
// 战斗
cmd.SceneCastSkillCostMpCsReq: g.SceneCastSkillCostMpCsReq, // 技能使用
cmd.SceneCastSkillCsReq: g.SceneCastSkillCsReq, // 场景开启战斗
cmd.SetTurnFoodSwitchCsReq: g.SetTurnFoodSwitchCsReq, // 使用消耗品buff
cmd.PVEBattleResultCsReq: g.PVEBattleResultCsReq, // PVE战斗结算
cmd.StartCocoonStageCsReq: g.StartCocoonStageCsReq, // 副本/周本等
cmd.ActivateFarmElementCsReq: g.ActivateFarmElementCsReq, // 虚影战斗
cmd.SceneEnterStageCsReq: g.SceneEnterStageCsReq, // 场景直接发起战斗
cmd.GetRaidInfoCsReq: g.GetRaidInfoCsReq, // 获取raid
cmd.StartRaidCsReq: g.StartRaidCsReq, // 拓境探游
cmd.LeaveRaidCsReq: g.LeaveRaidCsReq, // 退出拓境探游
cmd.SceneCastSkillCostMpCsReq: g.SceneCastSkillCostMpCsReq, // 技能使用
cmd.SceneCastSkillCsReq: g.SceneCastSkillCsReq, // 场景开启战斗
cmd.SetTurnFoodSwitchCsReq: g.SetTurnFoodSwitchCsReq, // 使用消耗品buff
cmd.RefreshTriggerByClientCsReq: g.RefreshTriggerByClientCsReq, // 领域buff
cmd.PVEBattleResultCsReq: g.PVEBattleResultCsReq, // PVE战斗结算
cmd.StartCocoonStageCsReq: g.StartCocoonStageCsReq, // 副本/周本等
cmd.ActivateFarmElementCsReq: g.ActivateFarmElementCsReq, // 虚影战斗
cmd.SceneEnterStageCsReq: g.SceneEnterStageCsReq, // 场景直接发起战斗
cmd.GetRaidInfoCsReq: g.GetRaidInfoCsReq, // 获取raid
cmd.StartRaidCsReq: g.StartRaidCsReq, // 拓境探游
cmd.LeaveRaidCsReq: g.LeaveRaidCsReq, // 退出拓境探游
// 模拟宇宙
cmd.GetRogueHandbookDataCsReq: g.GetRogueHandbookDataCsReq, // 模拟宇宙图鉴
cmd.GetRogueScoreRewardInfoCsReq: g.GetRogueScoreRewardInfoCsReq, // 获取模拟宇宙排期
Expand Down
35 changes: 30 additions & 5 deletions gameserver/player/player_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package player

import (
"strings"
"time"

"github.com/gucooing/hkrpg-go/gameserver/model"
"github.com/gucooing/hkrpg-go/pkg/alg"
Expand Down Expand Up @@ -313,8 +314,8 @@ func (g *GamePlayer) InteractPropCsReq(payloadMsg pb.Message) {
g.GetPd().AddItem(pileItem, allSync)
g.AllPlayerSyncScNotify(allSync)
g.AllScenePlaneEventScNotify(pileItem)
g.PropSceneGroupRefreshScNotify(propEntityIdList, blockBin) // 通知状态更改
finishSubMission := g.GetPd().UpInteractSubMission(blockBin) // 检查交互任务
g.PropSceneGroupRefreshScNotify(propEntityIdList, blockBin) // 通知状态更改
finishSubMission := g.GetPd().UpInteractSubMission(blockBin) // 检查交互任务
if len(finishSubMission) != 0 {
g.InspectMission(finishSubMission)
}
Expand Down Expand Up @@ -539,9 +540,9 @@ func (g *GamePlayer) UpSceneGroupRefreshScNotify(uninstallGroup, loadedGroupList
for _, entify := range groupInfo.EntityMap {
groupRefreshInfo.RefreshEntity = append(groupRefreshInfo.RefreshEntity,
&proto.SceneEntityRefreshInfo{
Refresh: &proto.SceneEntityRefreshInfo_DeleteEntity{
DeleteEntity: g.GetPd().GetEntryId(entify)},
})
Refresh: &proto.SceneEntityRefreshInfo_DeleteEntity{
DeleteEntity: g.GetPd().GetEntryId(entify)},
})
}

notify.GroupRefreshList = append(notify.GroupRefreshList, groupRefreshInfo)
Expand Down Expand Up @@ -628,3 +629,27 @@ func (g *GamePlayer) SetFloorSavedValue(conf *gdconf.SubMission, finishAction *g
g.PropSceneGroupRefreshScNotify([]uint32{enep.EntityId}, db)
}
}

/****************************************************领域管理***************************************************/

func (g *GamePlayer) AddSummonUnitSceneGroupRefreshScNotify() {
db := g.GetPd().GetSummonUnitInfo()
g.Send(cmd.SceneGroupRefreshScNotify, &proto.SceneGroupRefreshScNotify{
GroupRefreshList: g.GetPd().GetAddBuffSceneEntityRefreshInfo(
db.AttachEntityId, db.SummonUnitId, db.EntityId, db.Pos),
})
go func() {
time.Sleep(20 * time.Second)
g.Send(cmd.SceneGroupRefreshScNotify, &proto.SceneGroupRefreshScNotify{
GroupRefreshList: []*proto.GroupRefreshInfo{{
RefreshType: proto.SceneGroupRefreshType_SCENE_GROUP_REFRESH_TYPE_UNLOAD,
RefreshEntity: []*proto.SceneEntityRefreshInfo{{
Refresh: &proto.SceneEntityRefreshInfo_DeleteEntity{
DeleteEntity: db.EntityId,
},
}},
}},
})
db = new(model.SummonUnitInfo)
}()
}
36 changes: 34 additions & 2 deletions pkg/gdconf/summon_unit_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package gdconf
import (
"fmt"
"os"
"strings"

"github.com/gucooing/hkrpg-go/pkg/constant"
"github.com/gucooing/hkrpg-go/pkg/logger"
"github.com/hjson/hjson-go/v4"
)
Expand All @@ -25,8 +27,9 @@ type SummonUnitData struct {
}

type SummonUnitDataJson struct {
AttachPoint string `json:"AttachPoint"`
TriggerConfig *SummonUnitTriggers `json:"TriggerConfig"`
AttachPoint string `json:"AttachPoint"`
TriggerConfig *SummonUnitTriggers `json:"TriggerConfig"`
Actions map[string][]*MazeSkillAction `json:"-"`
}

type SummonUnitTriggers struct {
Expand Down Expand Up @@ -68,6 +71,12 @@ func (g *GameDataConfig) loadSummonUnitData() {
logger.Error("parse file error: %v", err)
continue
}
jsonData.Actions = make(map[string][]*MazeSkillAction)
if jsonData.TriggerConfig != nil && jsonData.TriggerConfig.CustomTriggers != nil {
for _, customTrigger := range jsonData.TriggerConfig.CustomTriggers {
jsonData.Actions[customTrigger.TriggerName] = BuildSummonUnitMazeSkillActions(customTrigger)
}
}
g.SummonUnitDataInfo.SummonUnitDataJsonMap[v.ID] = jsonData
g.SummonUnitDataInfo.SummonUnitDataMap[v.ID] = v
}
Expand All @@ -79,3 +88,26 @@ func (g *GameDataConfig) loadSummonUnitData() {
func GetSummonUnitData(summonId uint32) *SummonUnitData {
return CONF.SummonUnitDataInfo.SummonUnitDataMap[summonId]
}

func BuildSummonUnitMazeSkillActions(customTriggers *SummonUnitCustomTrigger) []*MazeSkillAction {
actionList := make([]*MazeSkillAction, 0)
for _, task := range customTriggers.OnTriggerEnter {
if strings.Contains(task.Type, "AddMazeBuff") {
actionList = append(actionList, &MazeSkillAction{
Type: constant.AddMazeBuff,
Id: task.ID,
})
} else if strings.Contains(task.Type, "TriggerHitProp") {

}
}
return actionList
}

func GetSummonUnitMazeSkillAction(summonId uint32, triggerName string) []*MazeSkillAction {
if CONF.SummonUnitDataInfo.SummonUnitDataJsonMap[summonId] == nil ||
CONF.SummonUnitDataInfo.SummonUnitDataJsonMap[summonId].Actions == nil {
return nil
}
return CONF.SummonUnitDataInfo.SummonUnitDataJsonMap[summonId].Actions[triggerName]
}

0 comments on commit 59c3376

Please sign in to comment.