0.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package pb
  2. import cstring "github.com/cherry-game/cherry/extend/string"
  3. func (m *StrStrList) Add(key string, value any) {
  4. m.List = append(m.List, &StrStr{
  5. Key: key,
  6. Value: cstring.ToString(value),
  7. })
  8. }
  9. func (m *OrderDeliver) GetExtraI32(key string) (int32, bool) {
  10. value, found := m.Extra[key]
  11. if !found {
  12. return 0, false
  13. }
  14. return cstring.ToInt32(value, 0)
  15. }
  16. func (m *MapData) PointToTileID(x, y int32) (int32, bool) {
  17. if m.IsPointOutOfBound(x, y) {
  18. return 0, false
  19. }
  20. tileID := (y * m.MapInfo.Width) + x
  21. return tileID, true
  22. }
  23. func (m *MapData) TileIDToPoint(tileID int32) (int32, int32) {
  24. x := tileID % m.MapInfo.Width
  25. y := tileID / m.MapInfo.Width
  26. return x, y
  27. }
  28. func (m *MapData) IsTileBlock(tileID int32) bool {
  29. tile := m.Tiles[tileID]
  30. return tile == nil || tile.BlockType == MapWalkableTag_mwt_disable
  31. }
  32. func (m *MapData) IsPointBlock(x, y int32) bool {
  33. tileID, ok := m.PointToTileID(x, y)
  34. if !ok {
  35. return true
  36. }
  37. return m.IsTileBlock(tileID)
  38. }
  39. func (m *MapData) IsPointOutOfBound(x int32, y int32) bool {
  40. return x < 0 || x >= m.MapInfo.Width || y < 0 || y >= m.MapInfo.Height
  41. }
  42. // 获取坐标点所在的州省县
  43. func (m *MapData) GetTileLocateInfo(tileID int32) (state, province, county int32) {
  44. tile := m.Tiles[tileID]
  45. if tile == nil {
  46. return 0, 0, 0
  47. }
  48. // 最高位是州ID
  49. state = tile.CountyId / 1_000_000
  50. // 中间三位是省ID
  51. province = (tile.CountyId % 1_000_000) / 1_000
  52. // 最低三位是县ID
  53. county = tile.CountyId % 1_000
  54. return
  55. }
  56. func (p *TileData) IsBlock() bool {
  57. return p.BlockType == MapWalkableTag_mwt_disable
  58. }