Returns whether a correction was in order
(recalcPermaBuffs ...bool)
| 1580 | |
| 1581 | // Returns whether a correction was in order |
| 1582 | func (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 |
no test coverage detected