app.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package cherryApp
  2. import (
  3. cfacade "github.com/cherry-game/cherry/facade"
  4. "github.com/urfave/cli/v2"
  5. )
  6. var (
  7. _app cfacade.IApplication
  8. )
  9. var (
  10. isBattleValidation bool // 是否战斗验证
  11. )
  12. const (
  13. sourcePath = ".system"
  14. )
  15. func Init(app cfacade.IApplication) {
  16. _app = app
  17. // 服务器启动时,从配置文件中读取战斗验证开关
  18. isBattleValidation = app.Settings().GetBool("battle_validation", true)
  19. }
  20. func GetParameters(c *cli.Context) (path, node string) {
  21. path = c.String("path")
  22. node = c.String("node")
  23. return path, node
  24. }
  25. func GetFlag() []cli.Flag {
  26. return []cli.Flag{
  27. &cli.StringFlag{
  28. Name: "path,p",
  29. Usage: "profile file path",
  30. Required: false,
  31. Value: "./config",
  32. },
  33. &cli.StringFlag{
  34. Name: "node,n",
  35. Usage: "node id",
  36. Required: true,
  37. Value: "",
  38. },
  39. }
  40. }
  41. func App() cfacade.IApplication {
  42. return _app
  43. }
  44. func Serializer() cfacade.ISerializer {
  45. return _app.Serializer()
  46. }
  47. func Discovery() cfacade.IDiscovery {
  48. return _app.Discovery()
  49. }
  50. func ActorSystem() cfacade.IActorSystem {
  51. return _app.ActorSystem()
  52. }
  53. func GetNodeType(nodeID string) (string, bool) {
  54. member, found := _app.Discovery().GetMember(nodeID)
  55. if !found {
  56. return "", false
  57. }
  58. return member.GetNodeType(), true
  59. }
  60. func Call(target, funcName string, arg any) int32 {
  61. return ActorSystem().Call(sourcePath, target, funcName, arg)
  62. }
  63. func CallType(nodeType, actorID, funcName string, arg any) int32 {
  64. return ActorSystem().CallType(nodeType, actorID, funcName, arg)
  65. }
  66. func CallWait(target, funcName string, arg any, reply any) int32 {
  67. return ActorSystem().CallWait(sourcePath, target, funcName, arg, reply)
  68. }
  69. func PostEvent(data cfacade.IEventData) {
  70. ActorSystem().PostEvent(data)
  71. }
  72. func IsBattleValidation() bool {
  73. return isBattleValidation
  74. }
  75. // SetBattleValidation 探险PVE战斗验证开关
  76. func SetBattleValidation(value bool) {
  77. isBattleValidation = value
  78. }