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

Method Validate

internal/characters/character.go:1582–1717  ·  view source on GitHub ↗

Returns whether a correction was in order

(recalcPermaBuffs ...bool)

Source from the content-addressed store, hash-verified

1580
1581// Returns whether a correction was in order
1582func (c *Character) Validate(recalcPermaBuffs ...bool) error {
1583
1584 if len(c.Description) == 0 {
1585 c.Description = "They seem thoroughly uninteresting."
1586 }
1587
1588 if race := races.GetRace(c.RaceId); race == nil {
1589 c.RaceId = 1
1590 }
1591
1592 if c.Created.IsZero() {
1593 c.Created = time.Now()
1594 }
1595
1596 if c.Pet.Exists() {
1597 c.Pet.Validate()
1598 }
1599
1600 if c.SpellBook == nil {
1601 c.SpellBook = make(map[string]int)
1602 }
1603
1604 if c.Zone == "" {
1605 c.Zone = startingZone
1606 }
1607
1608 if c.Name == "" {
1609 c.Name = defaultName
1610 }
1611 if c.Level < 1 {
1612 c.Level = 1
1613 }
1614 if c.Experience < 1 {
1615 c.Experience = 1
1616 }
1617
1618 c.Buffs.Validate()
1619
1620 // Do a stats recalc based on equipment, race, level, etc.
1621 c.RecalculateStats()
1622
1623 // Recalculate health and mana
1624
1625 if c.Mana > c.ManaMax.Value {
1626 c.Mana = c.ManaMax.Value
1627 }
1628 if c.Health > c.HealthMax.Value {
1629 c.Health = c.HealthMax.Value
1630 }
1631
1632 if c.Health < -10 {
1633 c.Health = -10
1634 }
1635
1636 if c.Mana < 0 {
1637 c.Mana = 0
1638 }
1639

Callers 7

CancelBuffsWithFlagMethod · 0.95
AddBuffMethod · 0.95
RemoveBuffMethod · 0.95
LevelUpMethod · 0.95
AutoTrainMethod · 0.95
ApplyFormChangeMethod · 0.95
RevertFormChangeMethod · 0.95

Calls 15

RecalculateStatsMethod · 0.95
GetRaceIdMethod · 0.95
IsDisabledMethod · 0.95
StoreItemMethod · 0.95
NameMethod · 0.95
HandsRequiredMethod · 0.95
reapplyPermabuffsMethod · 0.95
GetRaceFunction · 0.92
ItemTypeTypeAlias · 0.92
DebugFunction · 0.92
AllSlotsFunction · 0.85
EnableAllMethod · 0.80

Tested by

no test coverage detected