1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package main
- import "fmt"
- type Object struct {
- // Required
- Id Id
- Kind Kind
- Name string
- // Optional (Based on Kind)
- Description string
- Password string
- Location Id
- Owner Id
- Health ValueRange
- Magic ValueRange
- BuildPoints ValueRange
- Level uint16
- Experience ValueRange
- Inventory map[Id]uint64
- Exits map[string]Id
- Motd string
- CoOwner Id
- SeniorOfficers []Id
- Officers []Id
- Members []Id
- }
- func (o *Object) valid() bool {
- if o.Kind == KPlayer && len(o.Password) == 0 {
- return false
- }
- return IsValid(o.Id) && IsValid(o.Kind) && len(o.Name) != 0
- }
- func (o *Object) render() string {
- var out string = ""
- switch o.Kind {
- case KPlayer, KCreature:
- out += fmt.Sprintf("%s the %s (%s)", o.Name, o.Kind.render(), o.Id.render())
- out += "\n"
- if len(o.Description) != 0 {
- out += fmt.Sprintf("%s", o.Description)
- out += "\n"
- }
- if IsValid(o.Location) {
- out += fmt.Sprintf("Located at %s", o.Location.render())
- out += "\n"
- }
- if IsValid(o.Owner) {
- out += fmt.Sprintf("Owned by %s", o.Owner.render())
- out += "\n"
- }
- if IsValid(o.Health) {
- out += fmt.Sprintf("%s Health", o.Health.render())
- out += "\n"
- }
- if IsValid(o.Magic) {
- out += fmt.Sprintf("%s Magic Points", o.Magic.render())
- out += "\n"
- }
- if IsValid(o.BuildPoints) {
- out += fmt.Sprintf("%s Build Points", o.BuildPoints.render())
- out += "\n"
- }
- if o.Level != 0 && o.Experience.Max != 0 {
- out += fmt.Sprintf("Level %d and %s Experience Points", o.Level, o.Experience.render())
- out += "\n"
- }
- default:
- return "Object.render() >> Unknown/Unsupported Kind"
- }
- return out
- }
|