package main import "fmt" // Identification Number // // Used to separate things into a unique thing type Id uint64 // An Id is considered valid so long as it's not 0 func (i Id) valid() bool { return i != 0 } // Render of an Id is simply prefixing it with # // // i.e. Id=5 .render() "#5" func (i Id) render() string { return fmt.Sprintf("#%d", i) } // Kind is used to separate a general Object into specific categories // // Players, Guilds, Rooms, Items, Creatures, Vehicles // // e.g. Players, Items, Creatures and Vehicles have a "health" (Items and Vehicles use the same name for their durability) // // But a Room won't use "health" (Despite it existing) type Kind uint8 // A Kind is valid so long as it's not 0 or None func (k Kind) valid() bool { return k != KNone } // Renders the Kind as a name // // i.e. Kind=Guild (2) .render() "Guild" func (k Kind) render() string { switch k { case KPlayer: return "Player" case KGuild: return "Guild" case KRoom: return "Room" case KItem: return "Item" case KCreature: return "Creature" case KVehicle: return "Vehicle" default: return "Unknown" } } const ( // An Invalid Kind KNone Kind = iota // A Creature, but controlled by a Human KPlayer // A Collection of 1 or more Players (Inventory is shared among Players, etc.) KGuild // A Room, which can hold Players, Items, Creatures, Vehicles and Containers KRoom // A Item, This is broad, but most Items should specify a specific thing (Weapon's for instance would have a "damage", Armor "defense", Gold on the other hand might have "value") KItem // A Entity that is controlled by either a Human's Logic (Scripted in some manner), or by the computer (Scripted internally) KCreature // A Entity / Room Hybrid, it behaves like both a Room and a Creature, Players and Creatures can enter a Vehicle, then where ever the Vehicle goes they are moved along with it KVehicle ) // A ValueRange is something which has a current Value and a Max // // Some ValueRanges are Health, Magic, and Build Points type ValueRange struct { Value uint64 Max uint64 } // ValueRanges are invalid when Max is 0, or Value is greater than Max func (v ValueRange) valid() bool { if v.Max == 0 { return false } return v.Value <= v.Max } // A 0 to 100 of the percentage the Range is at based on Value and Max // // This method will return 0 if the ValueRange is invalid func (v *ValueRange) Percent() uint8 { if IsInvalid(v) { return 0 } return uint8((float32(v.Value) / float32(v.Max)) * 100.0) } // Forms a good default for a ValueRange // // i.e. ValueRange{Value: 5, Max: 10} .render() "5/10" func (v ValueRange) render() string { if IsInvalid(v) { return "" } return fmt.Sprintf("%d/%d", v.Value, v.Max) }