objects.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package main
  2. import "fmt"
  3. type Object struct {
  4. // Required
  5. Id Id
  6. Kind Kind
  7. Name string
  8. // Optional (Based on Kind)
  9. Description string
  10. Password string
  11. Location Id
  12. Owner Id
  13. Health ValueRange
  14. Magic ValueRange
  15. BuildPoints ValueRange
  16. Level uint16
  17. Experience ValueRange
  18. Inventory map[Id]uint64
  19. Exits map[string]Id
  20. Motd string
  21. CoOwner Id
  22. SeniorOfficers []Id
  23. Officers []Id
  24. Members []Id
  25. }
  26. func (o *Object) valid() bool {
  27. if o.Kind == KPlayer && len(o.Password) == 0 {
  28. return false
  29. }
  30. return IsValid(o.Id) && IsValid(o.Kind) && len(o.Name) != 0
  31. }
  32. func (o *Object) render() string {
  33. var out string = ""
  34. switch o.Kind {
  35. case KPlayer, KCreature:
  36. out += fmt.Sprintf("%s the %s (%s)", o.Name, o.Kind.render(), o.Id.render())
  37. out += "\n"
  38. if len(o.Description) != 0 {
  39. out += fmt.Sprintf("%s", o.Description)
  40. out += "\n"
  41. }
  42. if IsValid(o.Location) {
  43. out += fmt.Sprintf("Located at %s", o.Location.render())
  44. out += "\n"
  45. }
  46. if IsValid(o.Owner) {
  47. out += fmt.Sprintf("Owned by %s", o.Owner.render())
  48. out += "\n"
  49. }
  50. if IsValid(o.Health) {
  51. out += fmt.Sprintf("%s Health", o.Health.render())
  52. out += "\n"
  53. }
  54. if IsValid(o.Magic) {
  55. out += fmt.Sprintf("%s Magic Points", o.Magic.render())
  56. out += "\n"
  57. }
  58. if IsValid(o.BuildPoints) {
  59. out += fmt.Sprintf("%s Build Points", o.BuildPoints.render())
  60. out += "\n"
  61. }
  62. if o.Level != 0 && o.Experience.Max != 0 {
  63. out += fmt.Sprintf("Level %d and %s Experience Points", o.Level, o.Experience.render())
  64. out += "\n"
  65. }
  66. default:
  67. return "Object.render() >> Unknown/Unsupported Kind"
  68. }
  69. return out
  70. }