ChatCommand.h 2.0 KB

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