mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-03-01 00:35:36 +08:00
整了个小活
This commit is contained in:
@@ -157,6 +157,12 @@ func (g *GameManager) PrivateChatReq(player *model.Player, payloadMsg pb.Message
|
|||||||
// 输入命令 会检测是否为命令的
|
// 输入命令 会检测是否为命令的
|
||||||
COMMAND_MANAGER.InputCommand(player, text)
|
COMMAND_MANAGER.InputCommand(player, text)
|
||||||
|
|
||||||
|
if text == "VPU" {
|
||||||
|
g.VideoPlayerUpdate(false)
|
||||||
|
} else if text == "VPUR" {
|
||||||
|
g.VideoPlayerUpdate(true)
|
||||||
|
}
|
||||||
|
|
||||||
case *proto.PrivateChatReq_Icon:
|
case *proto.PrivateChatReq_Icon:
|
||||||
icon := content.(*proto.PrivateChatReq_Icon).Icon
|
icon := content.(*proto.PrivateChatReq_Icon).Icon
|
||||||
|
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ func (g *GameManager) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.
|
|||||||
logger.Debug("EvtCreateGadgetNotify: %v", req)
|
logger.Debug("EvtCreateGadgetNotify: %v", req)
|
||||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||||
scene := world.GetSceneById(player.SceneId)
|
scene := world.GetSceneById(player.SceneId)
|
||||||
scene.ClientCreateEntityGadget(&model.Vector{
|
scene.CreateEntityGadgetClient(&model.Vector{
|
||||||
X: float64(req.InitPos.X),
|
X: float64(req.InitPos.X),
|
||||||
Y: float64(req.InitPos.Y),
|
Y: float64(req.InitPos.Y),
|
||||||
Z: float64(req.InitPos.Z),
|
Z: float64(req.InitPos.Z),
|
||||||
|
|||||||
@@ -61,18 +61,6 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u
|
|||||||
player.CombatInvokeHandler = model.NewInvokeHandler[proto.CombatInvokeEntry]()
|
player.CombatInvokeHandler = model.NewInvokeHandler[proto.CombatInvokeEntry]()
|
||||||
player.AbilityInvokeHandler = model.NewInvokeHandler[proto.AbilityInvokeEntry]()
|
player.AbilityInvokeHandler = model.NewInvokeHandler[proto.AbilityInvokeEntry]()
|
||||||
|
|
||||||
// // TODO 薄荷标记
|
|
||||||
// if world.IsBigWorld() {
|
|
||||||
// bigWorld := world.GetSceneById(3)
|
|
||||||
// for pos := range g.worldManager.worldStatic.terrain {
|
|
||||||
// bigWorld.CreateEntityGadget(&model.Vector{
|
|
||||||
// X: float64(pos.X),
|
|
||||||
// Y: float64(pos.Y),
|
|
||||||
// Z: float64(pos.Z),
|
|
||||||
// }, 3003009)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
g.LoginNotify(userId, player, clientSeq)
|
g.LoginNotify(userId, player, clientSeq)
|
||||||
|
|
||||||
player.SceneLoadState = model.SceneNone
|
player.SceneLoadState = model.SceneNone
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package game
|
package game
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -435,44 +436,55 @@ func (g *GameManager) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ENTITY_BATCH_SIZE = 1000
|
||||||
|
|
||||||
func (g *GameManager) AddSceneEntityNotify(player *model.Player, visionType proto.VisionType, entityIdList []uint32, broadcast bool, aec bool) {
|
func (g *GameManager) AddSceneEntityNotify(player *model.Player, visionType proto.VisionType, entityIdList []uint32, broadcast bool, aec bool) {
|
||||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||||
scene := world.GetSceneById(player.SceneId)
|
scene := world.GetSceneById(player.SceneId)
|
||||||
entityList := make([]*proto.SceneEntityInfo, 0)
|
// 如果总数量太多则分包发送
|
||||||
for _, entityId := range entityIdList {
|
times := int(math.Ceil(float64(len(entityIdList)) / float64(ENTITY_BATCH_SIZE)))
|
||||||
entity, ok := scene.entityMap[entityId]
|
for i := 0; i < times; i++ {
|
||||||
if !ok {
|
begin := ENTITY_BATCH_SIZE * i
|
||||||
// logger.Error("get entity is nil, entityId: %v", entityId)
|
end := ENTITY_BATCH_SIZE * (i + 1)
|
||||||
continue
|
if i == times-1 {
|
||||||
|
end = len(entityIdList)
|
||||||
}
|
}
|
||||||
switch entity.entityType {
|
entityList := make([]*proto.SceneEntityInfo, 0)
|
||||||
case uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_AVATAR):
|
for _, entityId := range entityIdList[begin:end] {
|
||||||
if visionType == proto.VisionType_VISION_TYPE_MEET && entity.avatarEntity.uid == player.PlayerID {
|
entity, ok := scene.entityMap[entityId]
|
||||||
|
if !ok {
|
||||||
|
// logger.Error("get entity is nil, entityId: %v", entityId)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
scenePlayer := USER_MANAGER.GetOnlineUser(entity.avatarEntity.uid)
|
switch entity.entityType {
|
||||||
if scenePlayer == nil {
|
case uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_AVATAR):
|
||||||
logger.Error("get scene player is nil, world id: %v, scene id: %v", world.id, scene.id)
|
if visionType == proto.VisionType_VISION_TYPE_MEET && entity.avatarEntity.uid == player.PlayerID {
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
|
scenePlayer := USER_MANAGER.GetOnlineUser(entity.avatarEntity.uid)
|
||||||
|
if scenePlayer == nil {
|
||||||
|
logger.Error("get scene player is nil, world id: %v, scene id: %v", world.id, scene.id)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if entity.avatarEntity.avatarId != world.GetPlayerActiveAvatarId(scenePlayer) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sceneEntityInfoAvatar := g.PacketSceneEntityInfoAvatar(scene, scenePlayer, world.GetPlayerActiveAvatarId(scenePlayer))
|
||||||
|
entityList = append(entityList, sceneEntityInfoAvatar)
|
||||||
|
case uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_WEAPON):
|
||||||
|
case uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_MONSTER):
|
||||||
|
sceneEntityInfoMonster := g.PacketSceneEntityInfoMonster(scene, entity.id)
|
||||||
|
entityList = append(entityList, sceneEntityInfoMonster)
|
||||||
|
case uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_GADGET):
|
||||||
|
sceneEntityInfoGadget := g.PacketSceneEntityInfoGadget(scene, entity.id)
|
||||||
|
entityList = append(entityList, sceneEntityInfoGadget)
|
||||||
}
|
}
|
||||||
if entity.avatarEntity.avatarId != world.GetPlayerActiveAvatarId(scenePlayer) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sceneEntityInfoAvatar := g.PacketSceneEntityInfoAvatar(scene, scenePlayer, world.GetPlayerActiveAvatarId(scenePlayer))
|
|
||||||
entityList = append(entityList, sceneEntityInfoAvatar)
|
|
||||||
case uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_WEAPON):
|
|
||||||
case uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_MONSTER):
|
|
||||||
sceneEntityInfoMonster := g.PacketSceneEntityInfoMonster(scene, entity.id)
|
|
||||||
entityList = append(entityList, sceneEntityInfoMonster)
|
|
||||||
case uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_GADGET):
|
|
||||||
sceneEntityInfoGadget := g.PacketSceneEntityInfoGadget(scene, entity.id)
|
|
||||||
entityList = append(entityList, sceneEntityInfoGadget)
|
|
||||||
}
|
}
|
||||||
}
|
if broadcast {
|
||||||
if broadcast {
|
g.AddSceneEntityNotifyBroadcast(player, scene, visionType, entityList, aec)
|
||||||
g.AddSceneEntityNotifyBroadcast(player, scene, visionType, entityList, aec)
|
} else {
|
||||||
} else {
|
g.AddSceneEntityNotifyToPlayer(player, visionType, entityList)
|
||||||
g.AddSceneEntityNotifyToPlayer(player, visionType, entityList)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -694,20 +706,22 @@ func (g *GameManager) PacketSceneEntityInfoGadget(scene *Scene, entityId uint32)
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
switch entity.gadgetEntity.gadgetType {
|
switch entity.gadgetEntity.gadgetType {
|
||||||
case GADGET_TYPE_CLIENT:
|
case GADGET_TYPE_NORMAL:
|
||||||
sceneEntityInfo.Entity = &proto.SceneEntityInfo_Gadget{
|
sceneEntityInfo.Entity = &proto.SceneEntityInfo_Gadget{
|
||||||
Gadget: g.PacketSceneGadgetInfoAbility(entity.gadgetEntity.gadgetClientEntity),
|
Gadget: g.PacketSceneGadgetInfoNormal(entity.gadgetEntity.gadgetId),
|
||||||
}
|
}
|
||||||
case GADGET_TYPE_GATHER:
|
case GADGET_TYPE_GATHER:
|
||||||
sceneEntityInfo.Entity = &proto.SceneEntityInfo_Gadget{
|
sceneEntityInfo.Entity = &proto.SceneEntityInfo_Gadget{
|
||||||
Gadget: g.PacketSceneGadgetInfoGather(entity.gadgetEntity.gadgetGatherEntity),
|
Gadget: g.PacketSceneGadgetInfoGather(entity.gadgetEntity.gadgetGatherEntity),
|
||||||
}
|
}
|
||||||
|
case GADGET_TYPE_CLIENT:
|
||||||
|
sceneEntityInfo.Entity = &proto.SceneEntityInfo_Gadget{
|
||||||
|
Gadget: g.PacketSceneGadgetInfoClient(entity.gadgetEntity.gadgetClientEntity),
|
||||||
|
}
|
||||||
case GADGET_TYPE_VEHICLE:
|
case GADGET_TYPE_VEHICLE:
|
||||||
sceneEntityInfo.Entity = &proto.SceneEntityInfo_Gadget{
|
sceneEntityInfo.Entity = &proto.SceneEntityInfo_Gadget{
|
||||||
Gadget: g.PacketSceneGadgetInfoVehicle(entity.gadgetEntity.gadgetVehicleEntity),
|
Gadget: g.PacketSceneGadgetInfoVehicle(entity.gadgetEntity.gadgetVehicleEntity),
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
return sceneEntityInfo
|
return sceneEntityInfo
|
||||||
}
|
}
|
||||||
@@ -760,18 +774,14 @@ func (g *GameManager) PacketSceneMonsterInfo() *proto.SceneMonsterInfo {
|
|||||||
return sceneMonsterInfo
|
return sceneMonsterInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) PacketSceneGadgetInfoVehicle(gadgetVehicleEntity *GadgetVehicleEntity) *proto.SceneGadgetInfo {
|
func (g *GameManager) PacketSceneGadgetInfoNormal(gadgetId uint32) *proto.SceneGadgetInfo {
|
||||||
sceneGadgetInfo := &proto.SceneGadgetInfo{
|
sceneGadgetInfo := &proto.SceneGadgetInfo{
|
||||||
GadgetId: gadgetVehicleEntity.vehicleId,
|
GadgetId: gadgetId,
|
||||||
AuthorityPeerId: WORLD_MANAGER.GetWorldByID(gadgetVehicleEntity.owner.WorldId).GetPlayerPeerId(gadgetVehicleEntity.owner),
|
GroupId: 133220271,
|
||||||
|
ConfigId: 271003,
|
||||||
|
GadgetState: 901,
|
||||||
IsEnableInteract: true,
|
IsEnableInteract: true,
|
||||||
Content: &proto.SceneGadgetInfo_VehicleInfo{
|
AuthorityPeerId: 1,
|
||||||
VehicleInfo: &proto.VehicleInfo{
|
|
||||||
MemberList: make([]*proto.VehicleMember, 0, len(gadgetVehicleEntity.memberMap)),
|
|
||||||
OwnerUid: gadgetVehicleEntity.owner.PlayerID,
|
|
||||||
CurStamina: gadgetVehicleEntity.curStamina,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
return sceneGadgetInfo
|
return sceneGadgetInfo
|
||||||
}
|
}
|
||||||
@@ -799,7 +809,7 @@ func (g *GameManager) PacketSceneGadgetInfoGather(gadgetGatherEntity *GadgetGath
|
|||||||
return sceneGadgetInfo
|
return sceneGadgetInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameManager) PacketSceneGadgetInfoAbility(gadgetClientEntity *GadgetClientEntity) *proto.SceneGadgetInfo {
|
func (g *GameManager) PacketSceneGadgetInfoClient(gadgetClientEntity *GadgetClientEntity) *proto.SceneGadgetInfo {
|
||||||
sceneGadgetInfo := &proto.SceneGadgetInfo{
|
sceneGadgetInfo := &proto.SceneGadgetInfo{
|
||||||
GadgetId: gadgetClientEntity.configId,
|
GadgetId: gadgetClientEntity.configId,
|
||||||
OwnerEntityId: gadgetClientEntity.ownerEntityId,
|
OwnerEntityId: gadgetClientEntity.ownerEntityId,
|
||||||
@@ -818,6 +828,22 @@ func (g *GameManager) PacketSceneGadgetInfoAbility(gadgetClientEntity *GadgetCli
|
|||||||
return sceneGadgetInfo
|
return sceneGadgetInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GameManager) PacketSceneGadgetInfoVehicle(gadgetVehicleEntity *GadgetVehicleEntity) *proto.SceneGadgetInfo {
|
||||||
|
sceneGadgetInfo := &proto.SceneGadgetInfo{
|
||||||
|
GadgetId: gadgetVehicleEntity.vehicleId,
|
||||||
|
AuthorityPeerId: WORLD_MANAGER.GetWorldByID(gadgetVehicleEntity.owner.WorldId).GetPlayerPeerId(gadgetVehicleEntity.owner),
|
||||||
|
IsEnableInteract: true,
|
||||||
|
Content: &proto.SceneGadgetInfo_VehicleInfo{
|
||||||
|
VehicleInfo: &proto.VehicleInfo{
|
||||||
|
MemberList: make([]*proto.VehicleMember, 0, len(gadgetVehicleEntity.memberMap)),
|
||||||
|
OwnerUid: gadgetVehicleEntity.owner.PlayerID,
|
||||||
|
CurStamina: gadgetVehicleEntity.curStamina,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return sceneGadgetInfo
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GameManager) PacketDelTeamEntityNotify(scene *Scene, player *model.Player) *proto.DelTeamEntityNotify {
|
func (g *GameManager) PacketDelTeamEntityNotify(scene *Scene, player *model.Player) *proto.DelTeamEntityNotify {
|
||||||
delTeamEntityNotify := &proto.DelTeamEntityNotify{
|
delTeamEntityNotify := &proto.DelTeamEntityNotify{
|
||||||
SceneId: player.SceneId,
|
SceneId: player.SceneId,
|
||||||
|
|||||||
256
gs/game/user_video_player.go
Normal file
256
gs/game/user_video_player.go
Normal file
@@ -0,0 +1,256 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"image/jpeg"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"hk4e/gs/model"
|
||||||
|
"hk4e/protocol/proto"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
SCREEN_WIDTH = 80
|
||||||
|
SCREEN_HEIGHT = 80
|
||||||
|
SCREEN_DPI = 0.5
|
||||||
|
)
|
||||||
|
const GADGET_ID = 70590015
|
||||||
|
|
||||||
|
var BASE_POS = &model.Vector{
|
||||||
|
X: 2700,
|
||||||
|
Y: 200,
|
||||||
|
Z: -1800,
|
||||||
|
}
|
||||||
|
var SCREEN_ENTITY_ID_LIST []uint32
|
||||||
|
var FRAME_COLOR [][]int
|
||||||
|
var FRAME [][]bool
|
||||||
|
|
||||||
|
const (
|
||||||
|
GADGET_RED = 70590016
|
||||||
|
GADGET_GREEN = 70590019
|
||||||
|
GADGET_BLUE = 70590017
|
||||||
|
GADGET_CYAN = 70590014
|
||||||
|
GADGET_YELLOW = 70590015
|
||||||
|
GADGET_CYAN_BLUE = 70590018
|
||||||
|
GADGET_PURPLE = 70590020
|
||||||
|
)
|
||||||
|
const (
|
||||||
|
RED_RGB = "C3764F"
|
||||||
|
GREEN_RGB = "559F30"
|
||||||
|
BLUE_RGB = "6293EA"
|
||||||
|
CYAN_RGB = "479094"
|
||||||
|
YELLOW_RGB = "DBB643"
|
||||||
|
CYAN_BLUE_RGB = "2B89C9"
|
||||||
|
PURPLE_RGB = "6E5BC5"
|
||||||
|
)
|
||||||
|
|
||||||
|
var COLOR_GADGET_MAP = map[string]int{
|
||||||
|
RED_RGB: GADGET_RED,
|
||||||
|
GREEN_RGB: GADGET_GREEN,
|
||||||
|
BLUE_RGB: GADGET_BLUE,
|
||||||
|
CYAN_RGB: GADGET_CYAN,
|
||||||
|
YELLOW_RGB: GADGET_YELLOW,
|
||||||
|
CYAN_BLUE_RGB: GADGET_CYAN_BLUE,
|
||||||
|
PURPLE_RGB: GADGET_PURPLE,
|
||||||
|
}
|
||||||
|
var ALL_COLOR = []string{RED_RGB, GREEN_RGB, BLUE_RGB, CYAN_RGB, YELLOW_RGB, CYAN_BLUE_RGB, PURPLE_RGB}
|
||||||
|
|
||||||
|
type ColorLight struct {
|
||||||
|
Color string
|
||||||
|
Light uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
type COLOR_LIGHT_LIST_SORT []*ColorLight
|
||||||
|
|
||||||
|
var COLOR_LIGHT_LIST COLOR_LIGHT_LIST_SORT
|
||||||
|
|
||||||
|
func (s COLOR_LIGHT_LIST_SORT) Len() int {
|
||||||
|
return len(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s COLOR_LIGHT_LIST_SORT) Less(i, j int) bool {
|
||||||
|
return s[i].Light < s[j].Light
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s COLOR_LIGHT_LIST_SORT) Swap(i, j int) {
|
||||||
|
s[i], s[j] = s[j], s[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
CalcColorLight()
|
||||||
|
}
|
||||||
|
|
||||||
|
func CalcColorLight() {
|
||||||
|
COLOR_LIGHT_LIST = make(COLOR_LIGHT_LIST_SORT, 0)
|
||||||
|
for _, c := range ALL_COLOR {
|
||||||
|
r, g, b := GetColorRGB(c)
|
||||||
|
gray := float32(r)*0.299 + float32(g)*0.587 + float32(b)*0.114
|
||||||
|
COLOR_LIGHT_LIST = append(COLOR_LIGHT_LIST, &ColorLight{
|
||||||
|
Color: c,
|
||||||
|
Light: uint8(gray),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
sort.Stable(COLOR_LIGHT_LIST)
|
||||||
|
total := len(COLOR_LIGHT_LIST)
|
||||||
|
div := 255.0 / float32(total)
|
||||||
|
for index, colorLight := range COLOR_LIGHT_LIST {
|
||||||
|
colorLight.Light = uint8(div * float32(index+1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetColorRGB(c string) (r, g, b uint8) {
|
||||||
|
if len(c) != 6 {
|
||||||
|
return 0, 0, 0
|
||||||
|
}
|
||||||
|
rr, err := strconv.ParseUint(c[0:2], 16, 8)
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, 0
|
||||||
|
}
|
||||||
|
r = uint8(rr)
|
||||||
|
gg, err := strconv.ParseUint(c[2:4], 16, 8)
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, 0
|
||||||
|
}
|
||||||
|
g = uint8(gg)
|
||||||
|
bb, err := strconv.ParseUint(c[4:6], 16, 8)
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, 0
|
||||||
|
}
|
||||||
|
b = uint8(bb)
|
||||||
|
return r, g, b
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadJpgFile(fileName string) image.Image {
|
||||||
|
file, err := os.Open(fileName)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = file.Close()
|
||||||
|
}()
|
||||||
|
img, err := jpeg.Decode(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteJpgFile(fileName string, jpg image.Image) {
|
||||||
|
file, err := os.Create(fileName)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = file.Close()
|
||||||
|
}()
|
||||||
|
err = jpeg.Encode(file, jpg, &jpeg.Options{
|
||||||
|
Quality: 100,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadVideoPlayerFile() error {
|
||||||
|
inImg := ReadJpgFile("./in.jpg")
|
||||||
|
if inImg == nil {
|
||||||
|
return errors.New("file not exist")
|
||||||
|
}
|
||||||
|
FRAME = make([][]bool, SCREEN_WIDTH)
|
||||||
|
for w := 0; w < SCREEN_WIDTH; w++ {
|
||||||
|
FRAME[w] = make([]bool, SCREEN_HEIGHT)
|
||||||
|
}
|
||||||
|
FRAME_COLOR = make([][]int, SCREEN_WIDTH)
|
||||||
|
for w := 0; w < SCREEN_WIDTH; w++ {
|
||||||
|
FRAME_COLOR[w] = make([]int, SCREEN_HEIGHT)
|
||||||
|
}
|
||||||
|
grayAvg := uint64(0)
|
||||||
|
grayImg := image.NewRGBA(image.Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||||
|
for w := 0; w < SCREEN_WIDTH; w++ {
|
||||||
|
for h := 0; h < SCREEN_HEIGHT; h++ {
|
||||||
|
pix := inImg.At(w, h)
|
||||||
|
r, g, b, _ := pix.RGBA()
|
||||||
|
gray := float32(r>>8)*0.299 + float32(g>>8)*0.587 + float32(b>>8)*0.114
|
||||||
|
grayImg.SetRGBA(w, h, color.RGBA{R: uint8(gray), G: uint8(gray), B: uint8(gray), A: 255})
|
||||||
|
grayAvg += uint64(gray)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WriteJpgFile("./gray.jpg", grayImg)
|
||||||
|
grayAvg /= SCREEN_WIDTH * SCREEN_HEIGHT
|
||||||
|
rgbImg := image.NewRGBA(image.Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||||
|
binImg := image.NewRGBA(image.Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||||
|
for w := 0; w < SCREEN_WIDTH; w++ {
|
||||||
|
for h := 0; h < SCREEN_HEIGHT; h++ {
|
||||||
|
pix := inImg.At(w, h)
|
||||||
|
r, g, b, _ := pix.RGBA()
|
||||||
|
gray := float32(r>>8)*0.299 + float32(g>>8)*0.587 + float32(b>>8)*0.114
|
||||||
|
c := ""
|
||||||
|
for _, colorLight := range COLOR_LIGHT_LIST {
|
||||||
|
if float32(colorLight.Light) > gray {
|
||||||
|
c = colorLight.Color
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if c == "" {
|
||||||
|
c = COLOR_LIGHT_LIST[len(COLOR_LIGHT_LIST)-1].Color
|
||||||
|
}
|
||||||
|
rr, gg, bb := GetColorRGB(c)
|
||||||
|
rgbImg.SetRGBA(w, h, color.RGBA{R: rr, G: gg, B: bb, A: 255})
|
||||||
|
FRAME_COLOR[w][h] = COLOR_GADGET_MAP[c]
|
||||||
|
if gray > float32(grayAvg) {
|
||||||
|
FRAME[w][h] = true
|
||||||
|
binImg.SetRGBA(w, h, color.RGBA{R: 255, G: 255, B: 255, A: 255})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WriteJpgFile("./rgb.jpg", rgbImg)
|
||||||
|
WriteJpgFile("./bin.jpg", binImg)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GameManager) VideoPlayerUpdate(rgb bool) {
|
||||||
|
err := LoadVideoPlayerFile()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
world := WORLD_MANAGER.GetBigWorld()
|
||||||
|
scene := world.GetSceneById(3)
|
||||||
|
for _, v := range SCREEN_ENTITY_ID_LIST {
|
||||||
|
scene.DestroyEntity(v)
|
||||||
|
}
|
||||||
|
GAME_MANAGER.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_TYPE_REMOVE, SCREEN_ENTITY_ID_LIST)
|
||||||
|
SCREEN_ENTITY_ID_LIST = make([]uint32, 0)
|
||||||
|
leftTopPos := &model.Vector{
|
||||||
|
X: BASE_POS.X + float64(float64(SCREEN_WIDTH)*SCREEN_DPI/2),
|
||||||
|
Y: BASE_POS.Y + float64(float64(SCREEN_HEIGHT)*SCREEN_DPI),
|
||||||
|
Z: BASE_POS.Z,
|
||||||
|
}
|
||||||
|
for w := 0; w < SCREEN_WIDTH; w++ {
|
||||||
|
for h := 0; h < SCREEN_HEIGHT; h++ {
|
||||||
|
// 创建像素点
|
||||||
|
if rgb {
|
||||||
|
entityId := scene.CreateEntityGadgetNormal(&model.Vector{
|
||||||
|
X: leftTopPos.X - float64(w)*SCREEN_DPI,
|
||||||
|
Y: leftTopPos.Y - float64(h)*SCREEN_DPI,
|
||||||
|
Z: leftTopPos.Z,
|
||||||
|
}, uint32(FRAME_COLOR[w][h]))
|
||||||
|
SCREEN_ENTITY_ID_LIST = append(SCREEN_ENTITY_ID_LIST, entityId)
|
||||||
|
} else {
|
||||||
|
if !FRAME[w][h] {
|
||||||
|
entityId := scene.CreateEntityGadgetNormal(&model.Vector{
|
||||||
|
X: leftTopPos.X - float64(w)*SCREEN_DPI,
|
||||||
|
Y: leftTopPos.Y - float64(h)*SCREEN_DPI,
|
||||||
|
Z: leftTopPos.Z,
|
||||||
|
}, uint32(GADGET_ID))
|
||||||
|
SCREEN_ENTITY_ID_LIST = append(SCREEN_ENTITY_ID_LIST, entityId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GAME_MANAGER.AddSceneEntityNotify(world.owner, proto.VisionType_VISION_TYPE_BORN, SCREEN_ENTITY_ID_LIST, true, false)
|
||||||
|
}
|
||||||
@@ -542,8 +542,9 @@ type MonsterEntity struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GADGET_TYPE_CLIENT = iota
|
GADGET_TYPE_NORMAL = iota
|
||||||
GADGET_TYPE_GATHER
|
GADGET_TYPE_GATHER
|
||||||
|
GADGET_TYPE_CLIENT
|
||||||
GADGET_TYPE_VEHICLE // 载具
|
GADGET_TYPE_VEHICLE // 载具
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -570,6 +571,7 @@ type GadgetVehicleEntity struct {
|
|||||||
|
|
||||||
type GadgetEntity struct {
|
type GadgetEntity struct {
|
||||||
gadgetType int
|
gadgetType int
|
||||||
|
gadgetId uint32
|
||||||
gadgetClientEntity *GadgetClientEntity
|
gadgetClientEntity *GadgetClientEntity
|
||||||
gadgetGatherEntity *GadgetGatherEntity
|
gadgetGatherEntity *GadgetGatherEntity
|
||||||
gadgetVehicleEntity *GadgetVehicleEntity
|
gadgetVehicleEntity *GadgetVehicleEntity
|
||||||
@@ -775,7 +777,65 @@ func (s *Scene) CreateEntityMonster(pos *model.Vector, level uint8, fightProp ma
|
|||||||
return entity.id
|
return entity.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scene) ClientCreateEntityGadget(pos, rot *model.Vector, entityId uint32, configId, campId, campType, ownerEntityId, targetEntityId, propOwnerEntityId uint32) {
|
func (s *Scene) CreateEntityGadgetNormal(pos *model.Vector, gadgetId uint32) uint32 {
|
||||||
|
entityId := s.world.GetNextWorldEntityId(constant.EntityIdTypeConst.GADGET)
|
||||||
|
entity := &Entity{
|
||||||
|
id: entityId,
|
||||||
|
scene: s,
|
||||||
|
lifeState: constant.LifeStateConst.LIFE_ALIVE,
|
||||||
|
pos: pos,
|
||||||
|
rot: new(model.Vector),
|
||||||
|
moveState: uint16(proto.MotionState_MOTION_STATE_NONE),
|
||||||
|
lastMoveSceneTimeMs: 0,
|
||||||
|
lastMoveReliableSeq: 0,
|
||||||
|
fightProp: map[uint32]float32{
|
||||||
|
uint32(constant.FightPropertyConst.FIGHT_PROP_CUR_HP): math.MaxFloat32,
|
||||||
|
uint32(constant.FightPropertyConst.FIGHT_PROP_MAX_HP): math.MaxFloat32,
|
||||||
|
uint32(constant.FightPropertyConst.FIGHT_PROP_BASE_HP): float32(1),
|
||||||
|
},
|
||||||
|
entityType: uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_GADGET),
|
||||||
|
level: 0,
|
||||||
|
gadgetEntity: &GadgetEntity{
|
||||||
|
gadgetId: gadgetId,
|
||||||
|
gadgetType: GADGET_TYPE_NORMAL,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
s.entityMap[entity.id] = entity
|
||||||
|
s.world.aoiManager.AddEntityIdToGridByPos(entity.id, float32(entity.pos.X), float32(entity.pos.Y), float32(entity.pos.Z))
|
||||||
|
return entity.id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Scene) CreateEntityGadgetGather(pos *model.Vector, gatherId uint32) uint32 {
|
||||||
|
entityId := s.world.GetNextWorldEntityId(constant.EntityIdTypeConst.GADGET)
|
||||||
|
entity := &Entity{
|
||||||
|
id: entityId,
|
||||||
|
scene: s,
|
||||||
|
lifeState: constant.LifeStateConst.LIFE_ALIVE,
|
||||||
|
pos: pos,
|
||||||
|
rot: new(model.Vector),
|
||||||
|
moveState: uint16(proto.MotionState_MOTION_STATE_NONE),
|
||||||
|
lastMoveSceneTimeMs: 0,
|
||||||
|
lastMoveReliableSeq: 0,
|
||||||
|
fightProp: map[uint32]float32{
|
||||||
|
uint32(constant.FightPropertyConst.FIGHT_PROP_CUR_HP): math.MaxFloat32,
|
||||||
|
uint32(constant.FightPropertyConst.FIGHT_PROP_MAX_HP): math.MaxFloat32,
|
||||||
|
uint32(constant.FightPropertyConst.FIGHT_PROP_BASE_HP): float32(1),
|
||||||
|
},
|
||||||
|
entityType: uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_GADGET),
|
||||||
|
level: 0,
|
||||||
|
gadgetEntity: &GadgetEntity{
|
||||||
|
gadgetType: GADGET_TYPE_GATHER,
|
||||||
|
gadgetGatherEntity: &GadgetGatherEntity{
|
||||||
|
gatherId: gatherId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
s.entityMap[entity.id] = entity
|
||||||
|
s.world.aoiManager.AddEntityIdToGridByPos(entity.id, float32(entity.pos.X), float32(entity.pos.Y), float32(entity.pos.Z))
|
||||||
|
return entity.id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Scene) CreateEntityGadgetClient(pos, rot *model.Vector, entityId uint32, configId, campId, campType, ownerEntityId, targetEntityId, propOwnerEntityId uint32) {
|
||||||
entity := &Entity{
|
entity := &Entity{
|
||||||
id: entityId,
|
id: entityId,
|
||||||
scene: s,
|
scene: s,
|
||||||
@@ -808,36 +868,6 @@ func (s *Scene) ClientCreateEntityGadget(pos, rot *model.Vector, entityId uint32
|
|||||||
s.world.aoiManager.AddEntityIdToGridByPos(entity.id, float32(entity.pos.X), float32(entity.pos.Y), float32(entity.pos.Z))
|
s.world.aoiManager.AddEntityIdToGridByPos(entity.id, float32(entity.pos.X), float32(entity.pos.Y), float32(entity.pos.Z))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scene) CreateEntityGadget(pos *model.Vector, gatherId uint32) uint32 {
|
|
||||||
entityId := s.world.GetNextWorldEntityId(constant.EntityIdTypeConst.GADGET)
|
|
||||||
entity := &Entity{
|
|
||||||
id: entityId,
|
|
||||||
scene: s,
|
|
||||||
lifeState: constant.LifeStateConst.LIFE_ALIVE,
|
|
||||||
pos: pos,
|
|
||||||
rot: new(model.Vector),
|
|
||||||
moveState: uint16(proto.MotionState_MOTION_STATE_NONE),
|
|
||||||
lastMoveSceneTimeMs: 0,
|
|
||||||
lastMoveReliableSeq: 0,
|
|
||||||
fightProp: map[uint32]float32{
|
|
||||||
uint32(constant.FightPropertyConst.FIGHT_PROP_CUR_HP): math.MaxFloat32,
|
|
||||||
uint32(constant.FightPropertyConst.FIGHT_PROP_MAX_HP): math.MaxFloat32,
|
|
||||||
uint32(constant.FightPropertyConst.FIGHT_PROP_BASE_HP): float32(1),
|
|
||||||
},
|
|
||||||
entityType: uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_GADGET),
|
|
||||||
level: 0,
|
|
||||||
gadgetEntity: &GadgetEntity{
|
|
||||||
gadgetType: GADGET_TYPE_GATHER,
|
|
||||||
gadgetGatherEntity: &GadgetGatherEntity{
|
|
||||||
gatherId: gatherId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
s.entityMap[entity.id] = entity
|
|
||||||
s.world.aoiManager.AddEntityIdToGridByPos(entity.id, float32(entity.pos.X), float32(entity.pos.Y), float32(entity.pos.Z))
|
|
||||||
return entity.id
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Scene) CreateEntityGadgetVehicle(uid uint32, pos, rot *model.Vector, vehicleId uint32) uint32 {
|
func (s *Scene) CreateEntityGadgetVehicle(uid uint32, pos, rot *model.Vector, vehicleId uint32) uint32 {
|
||||||
player := USER_MANAGER.GetOnlineUser(uid)
|
player := USER_MANAGER.GetOnlineUser(uid)
|
||||||
if player == nil {
|
if player == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user