ChatCommand.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include <ReferenceCounter.h>
  3. #include <Text.h>
  4. #include "Entity.h"
  5. class ChatCommandParameter;
  6. class ChatCommand : public Framework::ConsoleCommand
  7. {
  8. private:
  9. Framework::Text description;
  10. int securityLevel;
  11. Framework::RCArray<ChatCommandParameter> params;
  12. public:
  13. ChatCommand(
  14. Framework::Text name, Framework::Text description, int securityLevel);
  15. protected:
  16. void addParam(ChatCommandParameter* param);
  17. public:
  18. virtual bool execute(
  19. Framework::RCArray<Framework::Text>& params, Entity* zActor) const
  20. = 0;
  21. bool execute(Framework::RCArray<Framework::Text>& params) const override;
  22. void addAutocompletePossibilities(
  23. const Framework::RCArray<Framework::Text>& args,
  24. bool appendToLast,
  25. Framework::RCArray<Framework::Text>& possibilities) const override;
  26. const Framework::RCArray<ChatCommandParameter>& getParams() const;
  27. Framework::Text getHelp() const;
  28. virtual int getSecurityLevel(
  29. Framework::RCArray<Framework::Text> params) const;
  30. };
  31. class ChatCommandParameter : public virtual Framework::ReferenceCounter
  32. {
  33. private:
  34. Framework::Text name;
  35. Framework::Text description;
  36. bool optional;
  37. public:
  38. ChatCommandParameter(
  39. Framework::Text name, Framework::Text description, bool optional);
  40. virtual bool isLegalValue(Framework::Text value) const;
  41. virtual Framework::Text getDefaultValue(Entity* zActor) const;
  42. Framework::Text getName() const;
  43. Framework::Text getDescription() const;
  44. bool isOptional() const;
  45. virtual Framework::RCArray<Framework::Text> getAutocompleteValues(
  46. const Framework::Text& current) const;
  47. };
  48. class PlayerNameParameter : public ChatCommandParameter
  49. {
  50. public:
  51. PlayerNameParameter();
  52. bool isLegalValue(Framework::Text value) const override;
  53. Framework::Text getDefaultValue(Entity* zActor) const override;
  54. Framework::RCArray<Framework::Text> getAutocompleteValues(
  55. const Framework::Text& current) const override;
  56. };
  57. class IntegerParameter : public ChatCommandParameter
  58. {
  59. private:
  60. std::function<int(Entity* zEntity)> calculateDefault;
  61. public:
  62. IntegerParameter(Framework::Text name,
  63. Framework::Text description,
  64. bool optional,
  65. std::function<int(Entity* zEntity)> calculateDefault);
  66. bool isLegalValue(Framework::Text value) const override;
  67. Framework::Text getDefaultValue(Entity* zActor) const override;
  68. };