MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / ValidateSpec

Function ValidateSpec

internal/mutators/admin.go:36–76  ·  view source on GitHub ↗
(spec *MutatorSpec)

Source from the content-addressed store, hash-verified

34}
35
36func ValidateSpec(spec *MutatorSpec) error {
37 if err := ValidateMutatorId(spec.MutatorId); err != nil {
38 return err
39 }
40
41 if spec.LightMod < -2 || spec.LightMod > 2 {
42 return fmt.Errorf("lightmod must be between -2 and 2, got %d", spec.LightMod)
43 }
44
45 if err := ValidateBuffIds(spec.PlayerBuffIds); err != nil {
46 return fmt.Errorf("playerbuffids: %w", err)
47 }
48 if err := ValidateBuffIds(spec.MobBuffIds); err != nil {
49 return fmt.Errorf("mobbuffids: %w", err)
50 }
51 if err := ValidateBuffIds(spec.NativeBuffIds); err != nil {
52 return fmt.Errorf("nativebuffids: %w", err)
53 }
54
55 if spec.DecayIntoId != "" {
56 if err := ValidateMutatorId(spec.DecayIntoId); err != nil {
57 return fmt.Errorf("decayintoid: %w", err)
58 }
59 }
60
61 if spec.NameModifier != nil && spec.NameModifier.Behavior != "" && !spec.NameModifier.Behavior.IsValid() {
62 return fmt.Errorf("namemodifier behavior is invalid: %q", spec.NameModifier.Behavior)
63 }
64 if spec.DescriptionModifier != nil && spec.DescriptionModifier.Behavior != "" && !spec.DescriptionModifier.Behavior.IsValid() {
65 return fmt.Errorf("descriptionmodifier behavior is invalid: %q", spec.DescriptionModifier.Behavior)
66 }
67 if spec.AlertModifier != nil && spec.AlertModifier.Behavior != "" && !spec.AlertModifier.Behavior.IsValid() {
68 return fmt.Errorf("alertmodifier behavior is invalid: %q", spec.AlertModifier.Behavior)
69 }
70
71 if spec.Pvp.Enabled && spec.Pvp.Disabled {
72 return fmt.Errorf("pvp cannot be both enabled and disabled")
73 }
74
75 return spec.Validate()
76}
77
78func CreateNewMutatorSpec(spec MutatorSpec) (string, error) {
79 spec.MutatorId = strings.ToLower(strings.TrimSpace(spec.MutatorId))

Callers 2

CreateNewMutatorSpecFunction · 0.85
SaveMutatorSpecFunction · 0.85

Calls 4

ValidateMutatorIdFunction · 0.85
ValidateBuffIdsFunction · 0.85
ValidateMethod · 0.65
IsValidMethod · 0.45

Tested by

no test coverage detected