修复动态调整天气相关的错误,修复命令管理器相关的错误,添加帮助命令分页功能
This commit is contained in:
1 parent
8356aad4d6
commit
6594d214f6
11 files changed
+229
-134
No files matched your search
@@ -73,6 +73,7 @@ type GameDataConfig struct {
|
||||
VehicleDataMap map[int32]*VehicleData // 载具
|
||||
OpenStateDataMap map[int32]*OpenStateData // 开放状态
|
||||
WeatherDataMap map[int32]*WeatherData // 天气
|
||||
WeatherDataJsonMap map[int32]map[int32]*WeatherData // 天气 json的天气区域id格式
|
||||
WeatherTemplateMap map[string]map[int32]*WeatherTemplate // 天气模版
|
||||
SceneWeatherAreaMap map[int32]map[int32]*SceneWeatherArea // 天气区域
|
||||
PubgWorldGadgetDataMap map[int32]*PubgWorldGadgetData // pubg世界物件
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gdconf
|
||||
|
||||
import (
|
||||
"hk4e/pkg/alg"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
@@ -13,6 +14,8 @@ import (
|
||||
type SceneWeatherArea struct {
|
||||
AreaId int32 `json:"area_id"` // 天气区域id
|
||||
Points []*AreaPoint `json:"points"` // 多边形平面顶点数组
|
||||
|
||||
VectorPoints []*alg.Vector2 `json:"-"` // 多边形平面顶点二维向量数组
|
||||
}
|
||||
|
||||
type AreaPoint struct {
|
||||
@@ -42,6 +45,14 @@ func (g *GameDataConfig) loadSceneWeatherArea() {
|
||||
}
|
||||
// 记录每个天气区域
|
||||
for _, area := range sceneWeatherAreaList {
|
||||
area.VectorPoints = make([]*alg.Vector2, 0, len(area.Points))
|
||||
// 多边形平面顶点数组转换
|
||||
for _, point := range area.Points {
|
||||
area.VectorPoints = append(area.VectorPoints, &alg.Vector2{
|
||||
X: point.X,
|
||||
Z: point.Y,
|
||||
})
|
||||
}
|
||||
_, exist := g.SceneWeatherAreaMap[sceneId]
|
||||
if !exist {
|
||||
g.SceneWeatherAreaMap[sceneId] = make(map[int32]*SceneWeatherArea, len(area.Points))
|
||||
|
||||
+29
-5
@@ -6,8 +6,9 @@ import (
|
||||
|
||||
// WeatherData 天气配置表
|
||||
type WeatherData struct {
|
||||
WeatherId int32 `csv:"ID"`
|
||||
WeatherAreaId int32 `csv:"JSON天气区域ID,omitempty"`
|
||||
WeatherAreaId int32 `csv:"ID"`
|
||||
JsonWeatherAreaId int32 `csv:"JSON天气区域ID,omitempty"`
|
||||
MaxHeight int32 `csv:"最大高度,omitempty"`
|
||||
GadgetID int32 `csv:"GadgetID,omitempty"`
|
||||
DefaultOpen int32 `csv:"默认是否开启,omitempty"`
|
||||
TemplateName string `csv:"TemplateName,omitempty"`
|
||||
@@ -19,18 +20,41 @@ type WeatherData struct {
|
||||
|
||||
func (g *GameDataConfig) loadWeatherData() {
|
||||
g.WeatherDataMap = make(map[int32]*WeatherData)
|
||||
g.WeatherDataJsonMap = make(map[int32]map[int32]*WeatherData)
|
||||
weatherDataList := make([]*WeatherData, 0)
|
||||
readTable[WeatherData](g.txtPrefix+"WeatherData.txt", &weatherDataList)
|
||||
for _, weatherData := range weatherDataList {
|
||||
g.WeatherDataMap[weatherData.WeatherId] = weatherData
|
||||
g.WeatherDataMap[weatherData.WeatherAreaId] = weatherData
|
||||
// json的天气区域id格式
|
||||
_, exist := g.WeatherDataJsonMap[weatherData.JsonWeatherAreaId]
|
||||
if !exist {
|
||||
g.WeatherDataJsonMap[weatherData.JsonWeatherAreaId] = make(map[int32]*WeatherData)
|
||||
}
|
||||
g.WeatherDataJsonMap[weatherData.JsonWeatherAreaId][weatherData.WeatherAreaId] = weatherData
|
||||
}
|
||||
logger.Info("WeatherData count: %v", len(g.WeatherDataMap))
|
||||
}
|
||||
|
||||
func GetWeatherDataById(weatherId int32) *WeatherData {
|
||||
return CONF.WeatherDataMap[weatherId]
|
||||
func GetWeatherDataMapByJsonWeatherAreaId(jsonWeatherAreaId int32) map[int32]*WeatherData {
|
||||
value, exist := CONF.WeatherDataJsonMap[jsonWeatherAreaId]
|
||||
if !exist {
|
||||
return nil
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func GetWeatherDataByWeatherAreaId(weatherAreaId int32) *WeatherData {
|
||||
value, exist := CONF.WeatherDataMap[weatherAreaId]
|
||||
if !exist {
|
||||
return nil
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func GetWeatherDataMap() map[int32]*WeatherData {
|
||||
return CONF.WeatherDataMap
|
||||
}
|
||||
|
||||
func GetWeatherDataJsonMap() map[int32]map[int32]*WeatherData {
|
||||
return CONF.WeatherDataJsonMap
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -87,7 +88,8 @@ func (c *CommandManager) NewHelpCommandController() *CommandController {
|
||||
Description: "<color=#FFFFCC>{alias}</color> <color=#FFCC99>帮助</color>",
|
||||
UsageList: []string{
|
||||
"{alias} 查看简要帮助信息",
|
||||
"{alias} <序号/命令别名> 查看详细帮助信息",
|
||||
"{alias} <页数> 查看指定页数的帮助信息",
|
||||
"{alias} <命令别名> 查看详细帮助信息",
|
||||
},
|
||||
Perm: CommandPermNormal,
|
||||
Func: c.HelpCommand,
|
||||
@@ -95,55 +97,91 @@ func (c *CommandManager) NewHelpCommandController() *CommandController {
|
||||
}
|
||||
|
||||
func (c *CommandManager) HelpCommand(content *CommandContent) bool {
|
||||
var controller *CommandController // 命令控制器
|
||||
var mode = "page" // 模式
|
||||
var page uint32 = 1 // 页数
|
||||
var alias string // 别名
|
||||
var controller *CommandController // 命令控制器
|
||||
|
||||
return content.Option("string", func(param any) bool {
|
||||
value := param.(string)
|
||||
// 数字的话就是页面
|
||||
parseUint, err := strconv.ParseUint(value, 10, 32)
|
||||
if err == nil {
|
||||
page = uint32(parseUint)
|
||||
mode = "page"
|
||||
return true
|
||||
}
|
||||
// 通过别名获取
|
||||
controller = c.commandControllerMap[value]
|
||||
if controller == nil {
|
||||
return false
|
||||
}
|
||||
alias = value
|
||||
mode = "alias"
|
||||
return true
|
||||
}).Execute(func() bool {
|
||||
if alias == "" {
|
||||
switch mode {
|
||||
case "page":
|
||||
// 显示简要帮助信息
|
||||
helpText := "<color=#66B2FF>================</color><color=#CCE5FF>/ 帮 助 /</color><color=#66B2FF>================</color>\n"
|
||||
commandCount := 0 // 权限足够的命令
|
||||
for _, controller := range c.commandControllerList {
|
||||
// 获取玩家权限足够的命令列表
|
||||
playerCommandControllerList := make([]*CommandController, 0)
|
||||
for _, commandController := range c.commandControllerList {
|
||||
// 权限不足跳过
|
||||
if content.Executor.CmdPerm < uint8(controller.Perm) {
|
||||
if content.Executor.CmdPerm < uint8(commandController.Perm) {
|
||||
continue
|
||||
}
|
||||
commandCount++
|
||||
playerCommandControllerList = append(playerCommandControllerList, commandController)
|
||||
}
|
||||
// 每页显示的命令数量
|
||||
const commandsPerPage = 10
|
||||
// 最大页数
|
||||
maxPages := uint32(math.Ceil(float64(len(playerCommandControllerList)) / float64(commandsPerPage)))
|
||||
// 页数超出范围
|
||||
if page > maxPages {
|
||||
content.SendFailMessage(content.AssignPlayer, "超出命令帮助页数范围,最大页数:%v", maxPages)
|
||||
return true
|
||||
}
|
||||
// 获取页数索引
|
||||
startIndex := int((page - 1) * commandsPerPage)
|
||||
endIndex := startIndex + commandsPerPage
|
||||
if endIndex > len(playerCommandControllerList) {
|
||||
endIndex = len(playerCommandControllerList)
|
||||
}
|
||||
// 添加帮助文本
|
||||
for i, commandController := range playerCommandControllerList[startIndex:endIndex] {
|
||||
// 计算命令在整个列表中的索引
|
||||
commandIndex := startIndex + i + 1
|
||||
// GM命令和普通命令区分颜色
|
||||
var permColor string
|
||||
switch controller.Perm {
|
||||
switch commandController.Perm {
|
||||
case CommandPermNormal:
|
||||
permColor = "#CCFFCC"
|
||||
case CommandPermGM:
|
||||
permColor = "#FF9999"
|
||||
}
|
||||
helpText += fmt.Sprintf("<color=%v>%v. %v</color> <color=#FFE5CC>-</color> %v\n", permColor, commandCount, controller.Name, strings.ReplaceAll(controller.Description, "{alias}", controller.AliasList[0]))
|
||||
helpText += fmt.Sprintf("<color=%v>%v. %v</color> <color=#FFE5CC>-</color> %v\n", permColor, commandIndex, commandController.Name, strings.ReplaceAll(commandController.Description, "{alias}", commandController.AliasList[0]))
|
||||
}
|
||||
helpText += fmt.Sprintf("\n<color=#CCE5FF>当前第 %v 页,共 %v 页~</color>", page, maxPages)
|
||||
// 发送帮助文本
|
||||
content.SendMessage(content.Executor, helpText)
|
||||
return true
|
||||
}
|
||||
// 命令详细用法
|
||||
usage := "命令用法:\n"
|
||||
for i, s := range controller.UsageList {
|
||||
s = strings.ReplaceAll(s, "{alias}", alias)
|
||||
usage += fmt.Sprintf("%v. %v", i+1, s)
|
||||
// 换行
|
||||
if i != len(controller.UsageList)-1 {
|
||||
usage += "\n"
|
||||
case "alias":
|
||||
// 命令详细用法
|
||||
usage := "命令用法:\n"
|
||||
for i, s := range controller.UsageList {
|
||||
s = strings.ReplaceAll(s, "{alias}", alias)
|
||||
usage += fmt.Sprintf("%v. %v", i+1, s)
|
||||
// 换行
|
||||
if i != len(controller.UsageList)-1 {
|
||||
usage += "\n"
|
||||
}
|
||||
}
|
||||
text := fmt.Sprintf("<color=#FFFFCC>%v</color><color=#CCCCFF> 命令详细帮助:</color>\n\n%v\n\n<color=#CCE5FF>所有别名:</color><color=#E0E0E0>%v</color>", controller.Name, usage, controller.AliasList)
|
||||
content.SendMessage(content.Executor, text)
|
||||
return true
|
||||
}
|
||||
text := fmt.Sprintf("<color=#FFFFCC>%v</color><color=#CCCCFF> 命令详细帮助:</color>\n\n%v\n\n<color=#CCE5FF>所有别名:</color><color=#E0E0E0>%v</color>", controller.Name, usage, controller.AliasList)
|
||||
content.SendMessage(content.Executor, text)
|
||||
return true
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
@@ -744,7 +782,7 @@ func (c *CommandManager) WeatherCommand(content *CommandContent) bool {
|
||||
var climateType uint32 // 气象类型
|
||||
|
||||
return content.Option("uint32", func(param any) bool {
|
||||
// 天气id
|
||||
// 天气区域id
|
||||
weatherAreaId = param.(uint32)
|
||||
return true
|
||||
}).Dynamic("uint32", func(param any) bool {
|
||||
|
||||
@@ -233,7 +233,11 @@ func (c *CommandContent) Execute(thenFunc func() bool) bool {
|
||||
}
|
||||
// 可选参数可执行的数量
|
||||
optionExecCount := optionStepCount - excludeParamCount
|
||||
// 可选参数可执行的数量小于0代表肯定有个必填参数缺少
|
||||
// 如果不能执行的参数数量为负数代表可执行的可选参数为0
|
||||
if excludeParamCount < 0 {
|
||||
optionExecCount = 0
|
||||
}
|
||||
// 可选参数可执行的数量为负数代表肯定有个必填参数缺少
|
||||
if optionExecCount < 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -236,25 +236,16 @@ func (g *Game) PlayerTimeNotify(world *World) {
|
||||
}
|
||||
|
||||
func (g *Game) PlayerGameTimeNotify(world *World) {
|
||||
for _, player := range world.GetAllPlayer() {
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if scene == nil {
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
for _, scene := range world.sceneMap {
|
||||
for _, scenePlayer := range scene.GetAllPlayer() {
|
||||
playerGameTimeNotify := &proto.PlayerGameTimeNotify{
|
||||
GameTime: scene.GetGameTime(),
|
||||
Uid: scenePlayer.PlayerId,
|
||||
}
|
||||
g.SendMsg(cmd.PlayerGameTimeNotify, scenePlayer.PlayerId, 0, playerGameTimeNotify)
|
||||
// 设置玩家天气
|
||||
climateType := GAME.GetWeatherAreaClimate(player.WeatherInfo.WeatherAreaId)
|
||||
// 跳过相同的天气
|
||||
if climateType == player.WeatherInfo.ClimateType {
|
||||
return
|
||||
}
|
||||
GAME.SetPlayerWeather(player, player.WeatherInfo.WeatherAreaId, climateType)
|
||||
|
||||
// 天气气象随机
|
||||
g.WeatherClimateRandom(scenePlayer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+90
-62
@@ -1,6 +1,7 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"hk4e/pkg/alg"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -274,13 +275,15 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
|
||||
playerEnterSceneInfoNotify.AvatarEnterInfo = append(playerEnterSceneInfoNotify.AvatarEnterInfo, avatarEnterSceneInfo)
|
||||
}
|
||||
g.SendMsg(cmd.PlayerEnterSceneInfoNotify, player.PlayerId, player.ClientSeq, playerEnterSceneInfoNotify)
|
||||
}
|
||||
|
||||
// 设置玩家天气
|
||||
weatherAreaId := g.GetPlayerInWeatherAreaId(player, player.GetPos())
|
||||
if weatherAreaId != 0 {
|
||||
climateType := GAME.GetWeatherAreaClimate(weatherAreaId)
|
||||
GAME.SetPlayerWeather(player, weatherAreaId, climateType)
|
||||
}
|
||||
// 设置玩家天气
|
||||
weatherAreaId := g.GetPlayerInWeatherAreaId(player, player.GetPos())
|
||||
if weatherAreaId != 0 {
|
||||
climateType := g.GetWeatherAreaClimate(weatherAreaId)
|
||||
g.SetPlayerWeather(player, weatherAreaId, climateType)
|
||||
} else {
|
||||
logger.Error("weather area id error, weatherAreaId: %v", weatherAreaId)
|
||||
}
|
||||
|
||||
g.UpdateWorldScenePlayerInfo(player, world)
|
||||
@@ -1377,10 +1380,10 @@ func (g *Game) SceneGroupCreateEntity(player *model.Player, groupId uint32, conf
|
||||
switch entityType {
|
||||
case constant.ENTITY_TYPE_MONSTER:
|
||||
// 怪物创建触发器检测
|
||||
GAME.MonsterCreateTriggerCheck(player, group, configId)
|
||||
g.MonsterCreateTriggerCheck(player, group, configId)
|
||||
case constant.ENTITY_TYPE_GADGET:
|
||||
// 物件创建触发器检测
|
||||
GAME.GadgetCreateTriggerCheck(player, group, configId)
|
||||
g.GadgetCreateTriggerCheck(player, group, configId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1460,58 +1463,72 @@ func (g *Game) CreateDropGadget(player *model.Player, pos *model.Vector, gadgetI
|
||||
}
|
||||
|
||||
// GetPosIsInWeatherArea 获取坐标是否在指定的天气区域
|
||||
func (g *Game) GetPosIsInWeatherArea(posX, posZ float64, sceneId, weatherAreaId uint32) bool {
|
||||
func (g *Game) GetPosIsInWeatherArea(posX, posZ float64, sceneId, jsonWeatherAreaId uint32) bool {
|
||||
// 获取场景天气区域配置表
|
||||
weatherAreaConfig := gdconf.GetSceneWeatherAreaMapBySceneIdAndWeatherAreaId(int32(sceneId), int32(weatherAreaId))
|
||||
if weatherAreaConfig == nil {
|
||||
sceneWeatherAreaData := gdconf.GetSceneWeatherAreaMapBySceneIdAndWeatherAreaId(int32(sceneId), int32(jsonWeatherAreaId))
|
||||
if sceneWeatherAreaData == nil {
|
||||
logger.Error("scene weather area data config not exist, sceneId: %v, jsonWeatherAreaId: %v", sceneId, jsonWeatherAreaId)
|
||||
return false
|
||||
}
|
||||
// 寻找玩家所在范围内的天气区域
|
||||
polygon := weatherAreaConfig.Points
|
||||
isInside := false
|
||||
for i, j := 0, len(polygon)-1; i < len(polygon); i++ {
|
||||
if (polygon[i].Y > float32(posZ)) != (polygon[j].Y > float32(posZ)) &&
|
||||
float32(posX) < (polygon[j].X-polygon[i].X)*(float32(posZ)-polygon[i].Y)/(polygon[j].Y-polygon[i].Y)+polygon[i].X {
|
||||
isInside = !isInside
|
||||
}
|
||||
j = i
|
||||
// 判断坐标是否在指定的天气区域
|
||||
pos := &alg.Vector2{
|
||||
X: float32(posX),
|
||||
Z: float32(posZ),
|
||||
}
|
||||
if isInside {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return alg.Region2DPolygonContainPos(sceneWeatherAreaData.VectorPoints, pos)
|
||||
}
|
||||
|
||||
// GetPlayerInWeatherAreaId 获取玩家所在的天气区域id
|
||||
func (g *Game) GetPlayerInWeatherAreaId(player *model.Player, newPos *model.Vector) uint32 {
|
||||
func (g *Game) GetPlayerInWeatherAreaId(player *model.Player, newPos *model.Vector) (weatherAreaId uint32) {
|
||||
// 获取场景天气区域配置表
|
||||
sceneWeatherAreaMap := gdconf.GetSceneWeatherAreaMap()[int32(player.GetSceneId())]
|
||||
if sceneWeatherAreaMap == nil {
|
||||
return 0
|
||||
sceneWeatherAreaDataMap := gdconf.GetSceneWeatherAreaMap()[int32(player.GetSceneId())]
|
||||
if sceneWeatherAreaDataMap == nil {
|
||||
logger.Error("scene weather area data config not exist, sceneId: %v", player.GetSceneId())
|
||||
return
|
||||
}
|
||||
// 寻找玩家所在范围内的天气区域
|
||||
var weatherAreaId uint32
|
||||
var priority int32
|
||||
// 玩家所在的天气区域
|
||||
for _, area := range sceneWeatherAreaMap {
|
||||
isInside := g.GetPosIsInWeatherArea(newPos.X, newPos.Z, player.GetSceneId(), uint32(area.AreaId))
|
||||
for _, area := range sceneWeatherAreaDataMap {
|
||||
// 获取天气数据配置表
|
||||
weatherConfig := gdconf.GetWeatherDataById(area.AreaId)
|
||||
if weatherConfig == nil {
|
||||
weatherDataMap := gdconf.GetWeatherDataMapByJsonWeatherAreaId(area.AreaId)
|
||||
if weatherDataMap == nil {
|
||||
// 有些天气不在配置表内
|
||||
// logger.Error("weather data config not exist, weatherId: %v", area.AreaId)
|
||||
logger.Error("weather data config not exist, weatherAreaId: %v", area.AreaId)
|
||||
continue
|
||||
}
|
||||
// 确保默认自动开启
|
||||
if weatherConfig.DefaultOpen != 1 {
|
||||
continue
|
||||
}
|
||||
if isInside && weatherConfig.Priority > priority {
|
||||
weatherAreaId = uint32(area.AreaId)
|
||||
priority = weatherConfig.Priority
|
||||
for _, weatherData := range weatherDataMap {
|
||||
// 确保高度不超过
|
||||
if weatherData.MaxHeight != 0 && player.GetPos().Y > float64(weatherData.MaxHeight) {
|
||||
continue
|
||||
}
|
||||
// 确保默认自动开启
|
||||
if weatherData.DefaultOpen != 1 {
|
||||
continue
|
||||
}
|
||||
// 确保处于天气区域内
|
||||
if !g.GetPosIsInWeatherArea(newPos.X, newPos.Z, player.GetSceneId(), uint32(weatherData.JsonWeatherAreaId)) {
|
||||
continue
|
||||
}
|
||||
// 优先级比较
|
||||
if weatherData.Priority > priority {
|
||||
weatherAreaId = uint32(weatherData.WeatherAreaId)
|
||||
priority = weatherData.Priority
|
||||
}
|
||||
}
|
||||
}
|
||||
return weatherAreaId
|
||||
return
|
||||
}
|
||||
|
||||
// WeatherClimateRandom 随机天气气象
|
||||
func (g *Game) WeatherClimateRandom(player *model.Player) {
|
||||
// 设置玩家天气
|
||||
climateType := g.GetWeatherAreaClimate(player.WeatherInfo.WeatherAreaId)
|
||||
// 跳过相同的天气
|
||||
if climateType == player.WeatherInfo.ClimateType {
|
||||
return
|
||||
}
|
||||
g.SetPlayerWeather(player, player.WeatherInfo.WeatherAreaId, climateType)
|
||||
}
|
||||
|
||||
// SceneWeatherAreaCheck 场景天气区域变更检测
|
||||
@@ -1521,12 +1538,13 @@ func (g *Game) SceneWeatherAreaCheck(player *model.Player, oldPos *model.Vector,
|
||||
return
|
||||
}
|
||||
// 如果玩家还在历史区域内就不获取当前所在区域
|
||||
if g.GetPosIsInWeatherArea(newPos.X, newPos.Z, player.GetSceneId(), player.WeatherInfo.WeatherAreaId) {
|
||||
if g.GetPosIsInWeatherArea(newPos.X, newPos.Z, player.GetSceneId(), player.WeatherInfo.JsonWeatherAreaId) {
|
||||
return
|
||||
}
|
||||
// 获取当前所在的天气区域
|
||||
weatherAreaId := g.GetPlayerInWeatherAreaId(player, newPos)
|
||||
if weatherAreaId == 0 {
|
||||
logger.Error("weather area id error, weatherAreaId: %v", weatherAreaId)
|
||||
return
|
||||
}
|
||||
// 判断天气区域是否变更
|
||||
@@ -1534,29 +1552,29 @@ func (g *Game) SceneWeatherAreaCheck(player *model.Player, oldPos *model.Vector,
|
||||
return
|
||||
}
|
||||
// 设置玩家天气
|
||||
climateType := GAME.GetWeatherAreaClimate(weatherAreaId)
|
||||
GAME.SetPlayerWeather(player, weatherAreaId, climateType)
|
||||
climateType := g.GetWeatherAreaClimate(weatherAreaId)
|
||||
g.SetPlayerWeather(player, weatherAreaId, climateType)
|
||||
}
|
||||
|
||||
// GetWeatherAreaClimate 获取天气区域气象
|
||||
// GetWeatherAreaClimate 获取天气气象
|
||||
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)
|
||||
weatherData := gdconf.GetWeatherDataByWeatherAreaId(int32(weatherAreaId))
|
||||
if weatherData == nil {
|
||||
logger.Error("weather data config not exist, weatherAreaId: %v", weatherAreaId)
|
||||
return 0
|
||||
}
|
||||
// 如果指定了则使用指定的天气
|
||||
var weatherTemplateConfig *gdconf.WeatherTemplate
|
||||
var weather int32
|
||||
if weatherConfig.UseDefaultWeather == 1 && weatherConfig.DefaultWeather != 0 {
|
||||
weather = weatherConfig.DefaultWeather
|
||||
weatherTemplateConfig = gdconf.GetWeatherTemplateByTemplateNameAndWeather(weatherConfig.TemplateName, weather)
|
||||
if weatherData.UseDefaultWeather == 1 && weatherData.DefaultWeather != 0 {
|
||||
weather = weatherData.DefaultWeather
|
||||
weatherTemplateConfig = gdconf.GetWeatherTemplateByTemplateNameAndWeather(weatherData.TemplateName, weather)
|
||||
} else {
|
||||
// 随机取个天气类型
|
||||
weatherTemplateMap := gdconf.GetWeatherTemplateMap()[weatherConfig.TemplateName]
|
||||
weatherTemplateMap := gdconf.GetWeatherTemplateMap()[weatherData.TemplateName]
|
||||
if weatherTemplateMap == nil {
|
||||
logger.Error("weather template map not exist, templateName: %v", weatherConfig.TemplateName)
|
||||
logger.Error("weather template map not exist, templateName: %v", weatherData.TemplateName)
|
||||
return 0
|
||||
}
|
||||
weatherTemplateList := make([]int32, 0, len(weatherTemplateMap))
|
||||
@@ -1568,11 +1586,10 @@ func (g *Game) GetWeatherAreaClimate(weatherAreaId uint32) uint32 {
|
||||
}
|
||||
// 确保指定的天气模版存在
|
||||
if weatherTemplateConfig == nil {
|
||||
logger.Error("weather template config not exist, templateName: %v, weather: %v", weatherConfig.TemplateName, weather)
|
||||
logger.Error("weather template config not exist, templateName: %v, weather: %v", weatherData.TemplateName, weather)
|
||||
return 0
|
||||
}
|
||||
// 随机气象 轮盘赌选择法RWS
|
||||
var climateType uint32
|
||||
climateWeightMap := map[uint32]int32{
|
||||
constant.CLIMATE_TYPE_SUNNY: weatherTemplateConfig.Sunny,
|
||||
constant.CLIMATE_TYPE_CLOUDY: weatherTemplateConfig.Cloudy,
|
||||
@@ -1582,25 +1599,36 @@ func (g *Game) GetWeatherAreaClimate(weatherAreaId uint32) uint32 {
|
||||
constant.CLIMATE_TYPE_MIST: weatherTemplateConfig.Mist,
|
||||
constant.CLIMATE_TYPE_DESERT: weatherTemplateConfig.Desert,
|
||||
}
|
||||
logger.Debug("climate weight: %v", climateWeightMap)
|
||||
randNum := random.GetRandomInt32(0, 100-1)
|
||||
var weightAll int32
|
||||
for _, weight := range climateWeightMap {
|
||||
weightAll += weight
|
||||
}
|
||||
// logger.Debug("weather climate weightMap: %v, weightAll: %v", climateWeightMap, weightAll)
|
||||
randNum := random.GetRandomInt32(0, weightAll-1)
|
||||
sumWeight := int32(0)
|
||||
for climate, weight := range climateWeightMap {
|
||||
sumWeight += weight
|
||||
if sumWeight > randNum {
|
||||
climateType = climate
|
||||
break
|
||||
return climate
|
||||
}
|
||||
}
|
||||
return climateType
|
||||
return 0
|
||||
}
|
||||
|
||||
// SetPlayerWeather 设置玩家天气
|
||||
func (g *Game) SetPlayerWeather(player *model.Player, weatherAreaId uint32, climateType uint32) {
|
||||
logger.Debug("weather climateType: %v, weatherAreaId: %v", climateType, weatherAreaId)
|
||||
// 获取天气数据配置表
|
||||
weatherData := gdconf.GetWeatherDataByWeatherAreaId(int32(weatherAreaId))
|
||||
if weatherData == nil {
|
||||
logger.Error("weather data config not exist, weatherAreaId: %v", weatherAreaId)
|
||||
return
|
||||
}
|
||||
|
||||
logger.Debug("weather climateType: %v, weatherAreaId: %v, jsonWeatherAreaId: %v, uid: %v", climateType, weatherAreaId, weatherData.JsonWeatherAreaId, player.PlayerId)
|
||||
|
||||
// 记录数据
|
||||
player.WeatherInfo.WeatherAreaId = weatherAreaId
|
||||
player.WeatherInfo.JsonWeatherAreaId = uint32(weatherData.JsonWeatherAreaId)
|
||||
player.WeatherInfo.ClimateType = climateType
|
||||
|
||||
sceneAreaWeatherNotify := &proto.SceneAreaWeatherNotify{
|
||||
|
||||
@@ -284,12 +284,8 @@ func (g *Game) ChangeGameTimeReq(player *model.Player, payloadMsg pb.Message) {
|
||||
logger.Debug("change game time, gameTime: %v, uid: %v", gameTime, player.PlayerId)
|
||||
g.ChangeGameTime(scene, gameTime)
|
||||
|
||||
// 设置玩家天气
|
||||
climateType := GAME.GetWeatherAreaClimate(player.WeatherInfo.WeatherAreaId)
|
||||
// 跳过相同的天气
|
||||
if climateType != player.WeatherInfo.ClimateType {
|
||||
g.SetPlayerWeather(player, player.WeatherInfo.WeatherAreaId, climateType)
|
||||
}
|
||||
// 天气气象随机
|
||||
g.WeatherClimateRandom(player)
|
||||
|
||||
rsp := &proto.ChangeGameTimeRsp{
|
||||
CurGameTime: scene.GetGameTime(),
|
||||
|
||||
+6
-4
@@ -1,13 +1,15 @@
|
||||
package model
|
||||
|
||||
type WeatherInfo struct {
|
||||
WeatherAreaId uint32 // 天气区域id
|
||||
ClimateType uint32 // 气候类型
|
||||
WeatherAreaId uint32 // 天气区域id
|
||||
JsonWeatherAreaId uint32 // 天气区域id json场景天气区域的id
|
||||
ClimateType uint32 // 气候类型
|
||||
}
|
||||
|
||||
func NewWeatherInfo() *WeatherInfo {
|
||||
return &WeatherInfo{
|
||||
WeatherAreaId: 0,
|
||||
ClimateType: 0,
|
||||
WeatherAreaId: 0,
|
||||
JsonWeatherAreaId: 0,
|
||||
ClimateType: 0,
|
||||
}
|
||||
}
|
||||
+18
-18
@@ -113,25 +113,25 @@ func (s *Shape) Contain(pos *Vector3) bool {
|
||||
switch shape.(type) {
|
||||
case *RegionCubic:
|
||||
cubic := shape.(*RegionCubic)
|
||||
contain := regionCubicContainPos(cubic, pos)
|
||||
contain := RegionCubicContainPos(cubic, pos)
|
||||
if contain {
|
||||
return true
|
||||
}
|
||||
case *RegionSphere:
|
||||
sphere := shape.(*RegionSphere)
|
||||
contain := regionSphereContainPos(sphere, pos)
|
||||
contain := RegionSphereContainPos(sphere, pos)
|
||||
if contain {
|
||||
return true
|
||||
}
|
||||
case *RegionCylinder:
|
||||
cylinder := shape.(*RegionCylinder)
|
||||
contain := regionCylinderContainPos(cylinder, pos)
|
||||
contain := RegionCylinderContainPos(cylinder, pos)
|
||||
if contain {
|
||||
return true
|
||||
}
|
||||
case *RegionPolygon:
|
||||
polygon := shape.(*RegionPolygon)
|
||||
contain := regionPolygonContainPos(polygon, pos)
|
||||
contain := RegionPolygonContainPos(polygon, pos)
|
||||
if contain {
|
||||
return true
|
||||
}
|
||||
@@ -142,8 +142,8 @@ func (s *Shape) Contain(pos *Vector3) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// 检测一个点是否在立方体内
|
||||
func regionCubicContainPos(cubic *RegionCubic, pos *Vector3) bool {
|
||||
// RegionCubicContainPos 检测一个点是否在立方体内
|
||||
func RegionCubicContainPos(cubic *RegionCubic, pos *Vector3) bool {
|
||||
cubicMinX := cubic.pos.X - cubic.size.X
|
||||
cubicMinY := cubic.pos.Y - cubic.size.Y
|
||||
cubicMinZ := cubic.pos.Z - cubic.size.Z
|
||||
@@ -159,8 +159,8 @@ func regionCubicContainPos(cubic *RegionCubic, pos *Vector3) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// 检测一个点是否在球体内
|
||||
func regionSphereContainPos(sphere *RegionSphere, pos *Vector3) bool {
|
||||
// RegionSphereContainPos 检测一个点是否在球体内
|
||||
func RegionSphereContainPos(sphere *RegionSphere, pos *Vector3) bool {
|
||||
distance3D := math.Sqrt(
|
||||
float64(sphere.pos.X-pos.X)*float64(sphere.pos.X-pos.X) +
|
||||
float64(sphere.pos.Y-pos.Y)*float64(sphere.pos.Y-pos.Y) +
|
||||
@@ -173,8 +173,8 @@ func regionSphereContainPos(sphere *RegionSphere, pos *Vector3) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// 检测一个点是否在圆柱体内
|
||||
func regionCylinderContainPos(cylinder *RegionCylinder, pos *Vector3) bool {
|
||||
// RegionCylinderContainPos 检测一个点是否在圆柱体内
|
||||
func RegionCylinderContainPos(cylinder *RegionCylinder, pos *Vector3) bool {
|
||||
distance2D := math.Sqrt(
|
||||
float64(cylinder.pos.X-pos.X)*float64(cylinder.pos.X-pos.X) +
|
||||
float64(cylinder.pos.Z-pos.Z)*float64(cylinder.pos.Z-pos.Z),
|
||||
@@ -191,9 +191,9 @@ func regionCylinderContainPos(cylinder *RegionCylinder, pos *Vector3) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// 检测一个点是否在空间多边形内
|
||||
func regionPolygonContainPos(polygon *RegionPolygon, pos *Vector3) bool {
|
||||
contain := region2DPolygonContainPos(polygon.pointArray, &Vector2{X: pos.X, Z: pos.Z})
|
||||
// RegionPolygonContainPos 检测一个点是否在空间多边形内
|
||||
func RegionPolygonContainPos(polygon *RegionPolygon, pos *Vector3) bool {
|
||||
contain := Region2DPolygonContainPos(polygon.pointArray, &Vector2{X: pos.X, Z: pos.Z})
|
||||
if !contain {
|
||||
return false
|
||||
}
|
||||
@@ -206,13 +206,13 @@ func regionPolygonContainPos(polygon *RegionPolygon, pos *Vector3) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// 检测一个点是否在平面多边形内
|
||||
func region2DPolygonContainPos(pointArray []*Vector2, pos *Vector2) bool {
|
||||
// Region2DPolygonContainPos 检测一个点是否在平面多边形内
|
||||
func Region2DPolygonContainPos(pointArray []*Vector2, pos *Vector2) bool {
|
||||
convexPolygonList := make([][]*Vector2, 0)
|
||||
// TODO 凹多边形分割为多个凸多边形
|
||||
convexPolygonList = append(convexPolygonList, pointArray)
|
||||
for _, convexPolygon := range convexPolygonList {
|
||||
contain := region2DConvexPolygonContainPos(convexPolygon, pos)
|
||||
contain := Region2DConvexPolygonContainPos(convexPolygon, pos)
|
||||
if contain {
|
||||
return true
|
||||
}
|
||||
@@ -220,8 +220,8 @@ func region2DPolygonContainPos(pointArray []*Vector2, pos *Vector2) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// 检测一个点是否在平面凸多边形内
|
||||
func region2DConvexPolygonContainPos(pointArray []*Vector2, pos *Vector2) bool {
|
||||
// Region2DConvexPolygonContainPos 检测一个点是否在平面凸多边形内
|
||||
func Region2DConvexPolygonContainPos(pointArray []*Vector2, pos *Vector2) bool {
|
||||
// 凸多边形分割为多个三角形
|
||||
for index := range pointArray {
|
||||
if index < 2 {
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
)
|
||||
|
||||
func TestLogger(t *testing.T) {
|
||||
config.CONF = &config.Config{Logger: config.Logger{Level: "DEBUG", Mode: "CONSOLE", Track: true}}
|
||||
config.CONF = &config.Config{Logger: config.Logger{Level: "DEBUG", TrackLine: true, TrackThread: true, EnableJson: true}}
|
||||
|
||||
logger.InitLogger("logger_test")
|
||||
defer logger.CloseLogger()
|
||||
logger.Warn("logger test ...")
|
||||
for i := 0; i < 100; i++ {
|
||||
go func(x int) { logger.Info("%d", x) }(i)
|
||||
for i := 0; i < 10000; i++ {
|
||||
logger.Info("%v", i)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user