165 lines
4.7 KiB
Go
165 lines
4.7 KiB
Go
package gameserver
|
|
|
|
import (
|
|
"gac-hkrpg-go/internal/common"
|
|
goproto "gac-hkrpg-go/protocol/proto"
|
|
)
|
|
|
|
func commonToLineupAvatars(f *common.FreesrData) []*goproto.LineupAvatar {
|
|
return common.ToLineupAvatars(f)
|
|
}
|
|
|
|
func init() {
|
|
handle("GetAllLineupData", func(s *Session, req *goproto.GetAllLineupDataCsReq, rsp *goproto.GetAllLineupDataScRsp) error {
|
|
player := s.JSON()
|
|
if player == nil {
|
|
return nil
|
|
}
|
|
rsp.LineupList = append(rsp.LineupList, &goproto.LineupInfo{
|
|
ExtraLineupType: goproto.ExtraLineupType_ExtraLineupType_LineupNone,
|
|
Name: "Squad 1",
|
|
Mp: 5,
|
|
MaxMp: 5,
|
|
AvatarList: commonToLineupAvatars(player),
|
|
})
|
|
return nil
|
|
})
|
|
|
|
handle("GetCurLineupData", func(s *Session, req *goproto.GetCurLineupDataCsReq, rsp *goproto.GetCurLineupDataScRsp) error {
|
|
player := s.JSON()
|
|
if player == nil {
|
|
return nil
|
|
}
|
|
rsp.Lineup = &goproto.LineupInfo{
|
|
ExtraLineupType: goproto.ExtraLineupType_ExtraLineupType_LineupNone,
|
|
Name: "Squad 1",
|
|
Mp: 5,
|
|
MaxMp: 5,
|
|
AvatarList: commonToLineupAvatars(player),
|
|
}
|
|
return nil
|
|
})
|
|
|
|
handle("JoinLineup", func(s *Session, req *goproto.JoinLineupCsReq, rsp *goproto.JoinLineupScRsp) error {
|
|
player := s.JSON()
|
|
if player == nil {
|
|
return nil
|
|
}
|
|
player.Lineups[req.Slot] = req.BaseAvatarId
|
|
player.SavePersistent()
|
|
return refreshLineup(s)
|
|
})
|
|
|
|
handle("ReplaceLineup", func(s *Session, req *goproto.ReplaceLineupCsReq, rsp *goproto.ReplaceLineupScRsp) error {
|
|
player := s.JSON()
|
|
if player == nil {
|
|
return nil
|
|
}
|
|
for _, item := range req.LineupSlotList {
|
|
player.Lineups[item.Slot] = item.Id
|
|
}
|
|
player.SavePersistent()
|
|
return refreshLineup(s)
|
|
})
|
|
|
|
handle("SwapLineup", func(s *Session, req *goproto.SwapLineupCsReq, rsp *goproto.SwapLineupScRsp) error {
|
|
player := s.JSON()
|
|
if player == nil {
|
|
return nil
|
|
}
|
|
// MPIEGFCNBEN / ENBIBCPPLDC are the obfuscated src/dst slots; the swap
|
|
// is symmetric so the mapping direction doesn't matter.
|
|
srcSlot, dstSlot := req.MPIEGFCNBEN, req.ENBIBCPPLDC
|
|
srcAvatar := player.Lineups[srcSlot]
|
|
dstAvatar := player.Lineups[dstSlot]
|
|
player.Lineups[srcSlot] = dstAvatar
|
|
player.Lineups[dstSlot] = srcAvatar
|
|
player.SavePersistent()
|
|
return refreshLineup(s)
|
|
})
|
|
|
|
handle("SwitchLineupIndex", func(s *Session, req *goproto.SwitchLineupIndexCsReq, rsp *goproto.SwitchLineupIndexScRsp) error {
|
|
return refreshLineup(s)
|
|
})
|
|
|
|
handle("GetLineupAvatarData", func(s *Session, req *goproto.GetLineupAvatarDataCsReq, rsp *goproto.GetLineupAvatarDataScRsp) error {
|
|
player := s.JSON()
|
|
if player != nil {
|
|
for _, slot := range player.SortedLineupKeys() {
|
|
avatarID := player.Lineups[slot]
|
|
if avatarID == 0 {
|
|
continue
|
|
}
|
|
rsp.AvatarDataList = append(rsp.AvatarDataList, &goproto.LineupAvatarData{
|
|
AvatarType: goproto.AvatarType_AVATAR_FORMAL_TYPE,
|
|
Hp: 10000,
|
|
Id: avatarID,
|
|
})
|
|
}
|
|
}
|
|
rsp.Retcode = 0
|
|
return nil
|
|
})
|
|
|
|
handle("QuitLineup", func(s *Session, req *goproto.QuitLineupCsReq, rsp *goproto.QuitLineupScRsp) error {
|
|
return nil
|
|
})
|
|
|
|
handle("ChangeLineupLeader", func(s *Session, req *goproto.ChangeLineupLeaderCsReq, rsp *goproto.ChangeLineupLeaderScRsp) error {
|
|
rsp.Slot = req.Slot
|
|
return nil
|
|
})
|
|
}
|
|
|
|
// refreshLineup mirrors refresh_lineup: SceneGroupRefreshScNotify + SyncLineupNotify.
|
|
func refreshLineup(s *Session) error {
|
|
player := s.JSON()
|
|
if player == nil {
|
|
return nil
|
|
}
|
|
|
|
lineup := &goproto.LineupInfo{
|
|
ExtraLineupType: goproto.ExtraLineupType_ExtraLineupType_LineupNone,
|
|
Name: "Squad 1",
|
|
AvatarList: commonToLineupAvatars(player),
|
|
MaxMp: 5,
|
|
Mp: 5,
|
|
}
|
|
|
|
notify := &goproto.SceneGroupRefreshScNotify{
|
|
FloorId: player.Scene.FloorID,
|
|
DimensionId: 0,
|
|
}
|
|
group := &goproto.SceneGroupRefreshInfo{
|
|
GroupId: 0,
|
|
State: 0,
|
|
GroupRefreshType: goproto.SceneGroupRefreshType_SCENE_GROUP_REFRESH_TYPE_LOADED,
|
|
}
|
|
for _, slot := range player.SortedLineupKeys() {
|
|
avatarID := player.Lineups[slot]
|
|
group.RefreshEntity = append(group.RefreshEntity, &goproto.SceneEntityRefreshInfo{
|
|
RefreshType: &goproto.SceneEntityRefreshInfo_AddEntity{
|
|
AddEntity: &goproto.SceneEntityInfo{
|
|
EntityId: slot + 1,
|
|
GroupId: 0,
|
|
InstId: 0,
|
|
Entity: &goproto.SceneEntityInfo_Actor{
|
|
Actor: &goproto.SceneActorInfo{
|
|
AvatarType: goproto.AvatarType_AVATAR_FORMAL_TYPE,
|
|
BaseAvatarId: avatarID,
|
|
MapLayer: 0,
|
|
Uid: 25,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
notify.GroupRefreshInfo = append(notify.GroupRefreshInfo, group)
|
|
|
|
if err := s.Send(notify); err != nil {
|
|
return err
|
|
}
|
|
return s.Send(&goproto.SyncLineupNotify{Lineup: lineup})
|
|
}
|