characters

package
v0.9.2-migration.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2025 License: GPL-3.0 Imports: 26 Imported by: 0

README

Characters

TODO: Flesh out more.

Stat Points

Players have statistics that naturally improve with experience levels based on their race.

These stat points can be further augmented by Buffs and by worn Equipment that provides stat mods.

Players also receive a stat point that they can manually assign as they please with each level.

Stat Point Definitions/Philosophy

  • Strength - Physical mass and power. Affects feats of strength and damage in combat (crit damage)
  • Speed - Affects hitting and being hit, ability to perform many actions, etc
  • Smarts - Raw intelligence. Memorization, effectiveness of spells, etc.
  • Vitality - Capability to take damage and keep functioning. affects HP
  • Mysticism - Magical capabiity - affects MP. Affects spell casting success and resistance to other spells.
  • Perception - Ability to see hidden things (i.e. hidden exits), understand complexities (i.e. lock picking), remain unseen (i.e. hiding), etc.

Stats that reach 105 get recalculated with anything over 100 applied as SQRT(overage)*2

So a stat of 150 would actually be calculated as 114

Documentation

Index

Constants

View Source
const (
	// MinMax alignment
	AlignmentMinimum int8 = -100
	AlignmentMaximum int8 = 100
	// Good
	AlignmentHoly     int8 = 80
	AlignmentGood     int8 = 60
	AlignmentVirtuous int8 = 40
	AlignmentLawful   int8 = 20
	// Neutral
	AlignmentNeutralHigh int8 = 19
	AlignmentNeutral     int8 = 0
	AlignmentNeutralLow  int8 = -19
	// Evil
	AlignmentMisguided int8 = -20
	AlignmentCorrupt   int8 = -40
	AlignmentEvil      int8 = -60
	AlignmentUnholy    int8 = -80
	// Threshold by which mobs will auto aggro
	AlignmentAggroThreshold int = 100 // Possible delta is 0 - 200

)
View Source
const (
	CharmPermanent      = -1 // Never expires due to time
	CharmExpiredDespawn = `emote bows and bids you farewell, disappearing into the scenery;despawn charmed mob expired`
	CharmExpiredRevert  = `emote reverts to its old ways`
)
View Source
const (
	StockTemporary = -1
	StockUnlimited = 0
)

Variables

View Source
var (
	StartingRoomId = -1
)

Functions

func AlignmentToString

func AlignmentToString(alignment int8) string

func AltsExists

func AltsExists(userId int) bool

func CompileAdjectiveSwaps

func CompileAdjectiveSwaps()

func GetAllSlotTypes

func GetAllSlotTypes() []string

func GetFormattedAdjective

func GetFormattedAdjective(adjName string) string

func GetFormattedAdjectives

func GetFormattedAdjectives(excludeShort bool) []string

func SaveAlts

func SaveAlts(userId int, alts []Character) bool

Types

type Aggro

type Aggro struct {
	Type          AggroType
	MobInstanceId int
	UserId        int
	SpellInfo     SpellAggroInfo // If Type is SpellCast, this is the spell info
	ExitName      string         // For example, firing a weapon in a direction
	RoundsWaiting int            // How many rounds must pass before this triggers
}

type AggroType

type AggroType int
const (
	// Enumerated Aggro Types
	DefaultAttack AggroType = iota // Regular H2H combat, everything can decay to this. Starts at zero
	Shooting
	BackStab
	SpellCast
	Flee
)

type Character

type Character struct {
	Name            string                         // The name of the character
	Description     string                         // A description of the character.
	Adjectives      []string                       `yaml:"adjectives,omitempty"` // Decorative text for the name of the character (e.g. "sleeping", "dead", "wounded")
	RoomId          int                            // The room id the character is in.
	Zone            string                         // The zone the character is in. The folder the room can be located in too.
	RaceId          int                            // Character race
	Stats           stats.Statistics               // Character stats
	Level           int                            // The level of the character
	Experience      int                            // The experience of the character
	TrainingPoints  int                            // The number of training points the character has
	StatPoints      int                            // The number of skill points the character has
	Health          int                            // The health of the character
	Mana            int                            // The mana of the character
	ActionPoints    int                            // The resevoir of action points the character has to spend on movement etc.
	Alignment       int8                           // The alignment of the character
	Gold            int                            // The gold the character is holding
	Bank            int                            // The gold the character has in the bank
	Shop            Shop                           `yaml:"shop,omitempty"`          // Definition of shop services/items this character stocks (or just has at the moment)
	SpellBook       map[string]int                 `yaml:"spellbook,omitempty"`     // The spells the character has learned
	Charmed         *CharmInfo                     `yaml:"-"`                       // If they are charmed, this is the info
	CharmedMobs     []int                          `yaml:"-"`                       // If they have charmed anyone, this is the list of mob instance ids
	Items           []items.Item                   `yaml:"items,omitempty"`         // The items the character is holding
	Buffs           buffs.Buffs                    `yaml:"buffs,omitempty"`         // The buffs the character has active
	Equipment       Worn                           `yaml:"equipment,omitempty"`     // The equipment the character is wearing
	TNLScale        float32                        `yaml:"-"`                       // The experience scale of the character. Don't write to yaml since is dynamically calculated.
	HealthMax       stats.StatInfo                 `yaml:"-"`                       // The maximum health of the character. Don't write to yaml since is dynamically calculated.
	ManaMax         stats.StatInfo                 `yaml:"-"`                       // The maximum mana of the character. Don't write to yaml since is dynamically calculated.
	ActionPointsMax stats.StatInfo                 `yaml:"-"`                       // The maximum actions of character. Don't write to yaml since is dynamically calculated.
	Aggro           *Aggro                         `yaml:"-"`                       // Dont' store this. If they leave they break their aggro
	Skills          map[string]int                 `yaml:"skills,omitempty"`        // The skills the character has, and what level they are at
	Cooldowns       Cooldowns                      `yaml:"cooldowns,omitempty"`     // How many rounds until it is cooled down
	Settings        map[string]string              `yaml:"settings,omitempty"`      // custom setting tracking, used for anything.
	QuestProgress   map[int]string                 `yaml:"questprogress,omitempty"` // quest progress tracking
	KeyRing         map[string]string              `yaml:"keyring,omitempty"`       // key is the lock id, value is the sequence
	KD              KDStats                        `yaml:"kd,omitempty"`            // Kill/Death stats
	MiscData        map[string]any                 `yaml:"miscdata,omitempty"`      // Any random other data that needs to be stored
	ExtraLives      int                            `yaml:"extralives,omitempty"`    // How many lives remain. If enabled, players can perma-die if they die at zero
	MobMastery      MobMasteries                   `yaml:"mobmastery,omitempty"`    // Tracks particular masteries around a given mob
	Pet             pets.Pet                       `yaml:"pet,omitempty"`           // Do they have a pet?
	Created         time.Time                      `yaml:"created"`                 // When this character was created
	Timers          map[string]gametime.RoundTimer `yaml:"timers,omitempty"`        // any special timers added to this character

	PlayerDamage     map[int]int `yaml:"-"` // key = who, value = how much
	LastPlayerDamage uint64      `yaml:"-"` // last round a player damaged this character
	// contains filtered or unexported fields
}

func LoadAlts

func LoadAlts(userId int) []Character

func New

func New() *Character

func (*Character) AddBuff

func (c *Character) AddBuff(buffId int, isPermanent bool) error

func (*Character) AlignmentName

func (c *Character) AlignmentName() string

func (*Character) ApplyHealthChange

func (c *Character) ApplyHealthChange(healthChange int) int

func (*Character) ApplyManaChange

func (c *Character) ApplyManaChange(manaChange int) int

func (*Character) AutoTrain

func (c *Character) AutoTrain()

AutoTrain() spends any training points for this character

func (*Character) BarterPrice

func (c *Character) BarterPrice(startPrice int) int

func (*Character) CacheDescription

func (c *Character) CacheDescription()

This should only be used for mobs. Not players

func (*Character) CanDualWield

func (c *Character) CanDualWield() bool

func (*Character) CancelBuffsWithFlag

func (c *Character) CancelBuffsWithFlag(buffFlag buffs.Flag) bool

func (*Character) CarryCapacity

func (c *Character) CarryCapacity() int

func (*Character) Charm

func (c *Character) Charm(userId int, rounds int, expireCommand string)

func (*Character) ClearQuestToken

func (c *Character) ClearQuestToken(questToken string)

func (*Character) DeductActionPoints

func (c *Character) DeductActionPoints(amount int) bool

func (*Character) DisableSpell

func (c *Character) DisableSpell(spellName string) bool

func (*Character) EnableSpell

func (c *Character) EnableSpell(spellName string) bool

func (*Character) EndAggro

func (c *Character) EndAggro()

func (*Character) FindInBackpack

func (c *Character) FindInBackpack(itemName string) (items.Item, bool)

func (*Character) FindKeyInBackpack

func (c *Character) FindKeyInBackpack(lockId string) (items.Item, bool)

func (*Character) FindOnBody

func (c *Character) FindOnBody(itemName string) (items.Item, bool)

func (*Character) GetAdjectives

func (c *Character) GetAdjectives() []string

func (*Character) GetAllBackpackItems

func (c *Character) GetAllBackpackItems() []items.Item

func (*Character) GetAllCooldowns

func (c *Character) GetAllCooldowns() map[string]int

func (*Character) GetAllSkillRanks

func (c *Character) GetAllSkillRanks() map[string]int

func (*Character) GetAllWornItems

func (c *Character) GetAllWornItems() []items.Item

func (*Character) GetBaseCastSuccessChance

func (c *Character) GetBaseCastSuccessChance(spellId string) int

All spells should have a 10% minimum chance of success.

func (*Character) GetBuffs

func (c *Character) GetBuffs(buffId ...int) []*buffs.Buff

func (*Character) GetCharmIds

func (c *Character) GetCharmIds() []int

func (*Character) GetCharmedUserId

func (c *Character) GetCharmedUserId() int

func (*Character) GetCooldown

func (c *Character) GetCooldown(trackingTag string) int

func (*Character) GetDefaultDiceRoll

func (c *Character) GetDefaultDiceRoll() (attacks int, dCount int, dSides int, bonus int, buffOnCrit []int)

func (*Character) GetDefense

func (c *Character) GetDefense() int

Returns an integer representing a % damage reduction

func (*Character) GetDescription

func (c *Character) GetDescription() string

returns description unless description is a hash which points to another description location.

func (*Character) GetGearValue

func (c *Character) GetGearValue() int

func (*Character) GetHealthAppearance

func (c *Character) GetHealthAppearance() string

USERNAME appears to be <BLANK>

func (*Character) GetKey

func (c *Character) GetKey(lockId string) string

func (*Character) GetMapSprawlCapacity

func (c *Character) GetMapSprawlCapacity() int

func (*Character) GetMaxCharmedCreatures

func (c *Character) GetMaxCharmedCreatures() int

func (*Character) GetMemoryCapacity

func (c *Character) GetMemoryCapacity() int

func (*Character) GetMiscData

func (c *Character) GetMiscData(key string) any

func (*Character) GetMiscDataKeys

func (c *Character) GetMiscDataKeys(prefixMatch ...string) []string

func (*Character) GetMobName

func (c *Character) GetMobName(viewingUserId int, renderFlags ...NameRenderFlag) FormattedName

func (*Character) GetPlayerName

func (c *Character) GetPlayerName(viewingUserId int, renderFlags ...NameRenderFlag) FormattedName

func (*Character) GetQuestProgress

func (c *Character) GetQuestProgress() map[int]string

func (*Character) GetRandomItem

func (c *Character) GetRandomItem() (items.Item, bool)

func (*Character) GetSetting

func (c *Character) GetSetting(settingName string) string

func (*Character) GetSkillLevel

func (c *Character) GetSkillLevel(skillName skills.SkillTag) int

Gets the current value of the skillname provided

func (*Character) GetSkillLevelCost

func (c *Character) GetSkillLevelCost(currentLevel int) int

func (*Character) GetSkills

func (c *Character) GetSkills() map[string]int

func (*Character) GetSpells

func (c *Character) GetSpells() map[string]int

func (*Character) GiveQuestToken

func (c *Character) GiveQuestToken(questToken string) bool

func (*Character) GrantXP

func (c *Character) GrantXP(xp int) (actualXP int, xpScale int)

func (*Character) HandsRequired

func (c *Character) HandsRequired(i items.Item) int

func (*Character) HasAdjective

func (c *Character) HasAdjective(adj string) bool

func (*Character) HasBuff

func (c *Character) HasBuff(buffId int) bool

func (*Character) HasBuffFlag

func (c *Character) HasBuffFlag(buffFlag buffs.Flag) bool

func (*Character) HasKey

func (c *Character) HasKey(lockId string, difficulty int) (hasKey bool, hasSequence bool)

func (*Character) HasQuest

func (c *Character) HasQuest(questToken string) bool

func (*Character) HasSpell

func (c *Character) HasSpell(spellName string) bool

func (*Character) Heal

func (c *Character) Heal(hp int, mana int) (int, int)

func (*Character) HealthPerRound

func (c *Character) HealthPerRound() int

func (*Character) IsAggro

func (c *Character) IsAggro(targetUserId int, targetMobInstanceId int) bool

func (*Character) IsCharmed

func (c *Character) IsCharmed(userId ...int) bool

func (*Character) IsDisabled

func (c *Character) IsDisabled() bool

func (*Character) IsQuestDone

func (c *Character) IsQuestDone(questToken string) bool

func (*Character) KeyCount

func (c *Character) KeyCount() int

func (*Character) KnowsFirstAid

func (c *Character) KnowsFirstAid() bool

func (*Character) LearnSpell

func (c *Character) LearnSpell(spellName string) bool

func (*Character) LevelUp

func (c *Character) LevelUp() (bool, stats.Statistics)

func (*Character) ManaPerRound

func (c *Character) ManaPerRound() int

func (*Character) MovementCost

func (c *Character) MovementCost() int

Where 1000 = a full round

func (*Character) PruneCooldowns

func (c *Character) PruneCooldowns()

func (*Character) Race

func (c *Character) Race() string

func (*Character) RecalculateStats

func (c *Character) RecalculateStats()

returns true if something has changed.

func (*Character) RememberRoom

func (c *Character) RememberRoom(roomId int)

Remember visiting a room. This may cause to forget an older room if the memory is full.

func (*Character) RemoveBuff

func (c *Character) RemoveBuff(buffId int)

func (*Character) RemoveCharm

func (c *Character) RemoveCharm() int

Returns userId of whoever had charmed them

func (*Character) RemoveFromBody

func (c *Character) RemoveFromBody(i items.Item) bool

func (*Character) RemoveItem

func (c *Character) RemoveItem(i items.Item) bool

func (*Character) SetAdjective

func (c *Character) SetAdjective(adj string, addToList bool)

func (*Character) SetAggro

func (c *Character) SetAggro(userId int, mobInstanceId int, aggroType AggroType, roundsWaitTime ...int)

func (*Character) SetAggroRemote

func (c *Character) SetAggroRemote(exitName string, userId int, mobInstanceId int, aggroType AggroType, roundsWaitTime ...int)

func (*Character) SetCast

func (c *Character) SetCast(roundsWaitTime int, sInfo SpellAggroInfo)

func (*Character) SetKey

func (c *Character) SetKey(lockId string, sequence string)

func (*Character) SetMiscData

func (c *Character) SetMiscData(key string, value any)

func (*Character) SetPermaBuffs

func (c *Character) SetPermaBuffs(buffIds []int)

Used with SpawnInfo to gift spawning mobs with permabuffs

func (*Character) SetSetting

func (c *Character) SetSetting(settingName string, settingValue string)

func (*Character) SetSkill

func (c *Character) SetSkill(skillName string, level int)

func (*Character) SetUserId

func (c *Character) SetUserId(userId int)

Sometimes it's useful for a character to know what user it belongs to.

func (*Character) StatMod

func (c *Character) StatMod(statName string) int

func (*Character) StoreItem

func (c *Character) StoreItem(i items.Item) bool

func (*Character) TimerExists

func (c *Character) TimerExists(name string) bool

func (*Character) TimerExpired

func (c *Character) TimerExpired(name string) bool

func (*Character) TimerSet

func (c *Character) TimerSet(name, period string)

func (*Character) TrackBuffStarted

func (c *Character) TrackBuffStarted(buffId int)

func (*Character) TrackCharmed

func (c *Character) TrackCharmed(mobId int, add bool)

func (*Character) TrackPlayerDamage

func (c *Character) TrackPlayerDamage(userId int, damageAmt int)

returns description unless description is a hash which points to another description location.

func (*Character) TrackSpellCast

func (c *Character) TrackSpellCast(spellName string) bool

func (*Character) TrainSkill

func (c *Character) TrainSkill(skillName string, targetLevel ...int) int

Increases the skill training counter and returns the new value

func (*Character) TryCooldown

func (c *Character) TryCooldown(trackingTag string, cooldownTime string) bool

func (*Character) Uncurse

func (c *Character) Uncurse() []items.Item

func (*Character) UpdateAlignment

func (c *Character) UpdateAlignment(amt int)

func (*Character) UpdateItem

func (c *Character) UpdateItem(originalItm items.Item, replacement items.Item) bool

Copies over an existing item with a new item Returns true if successfully replaces an item

func (*Character) UseItem

func (c *Character) UseItem(i items.Item) int

func (*Character) Validate

func (c *Character) Validate(recalcPermaBuffs ...bool) error

Returns whether a correction was in order

func (*Character) Wear

func (c *Character) Wear(i items.Item) (returnItems []items.Item, newItemWorn bool, failureReason string)

func (*Character) XPTL

func (c *Character) XPTL(lvl int) int

Amt TNL for a specific level

func (*Character) XPTNL

func (c *Character) XPTNL() int

func (*Character) XPTNLActual

func (c *Character) XPTNLActual() (xpPastCurrentLevel int, tnlXP int)

Returns the actual xp in regards to the current level/next level

type CharmInfo

type CharmInfo struct {
	UserId          int    // Charmed or serving a player?
	RoundsRemaining int    // If -1, never expires
	ExpiredCommand  string // Any valid mob commands such as `emote bows and waves farewell;despawn`
}

func NewCharm

func NewCharm(userId int, rounds int, expireCommand string) *CharmInfo

func (*CharmInfo) Expire

func (ch *CharmInfo) Expire()

type Cooldowns

type Cooldowns map[string]int

func (Cooldowns) Prune

func (cd Cooldowns) Prune()

func (Cooldowns) RoundTick

func (cd Cooldowns) RoundTick()

func (Cooldowns) Try

func (cd Cooldowns) Try(trackingTag string, cooldownPeriod string) bool

type FormattedName

type FormattedName struct {
	Name               string
	Type               string // mob/user
	Suffix             string // What ansi alias suffix to use (if any)
	Adjectives         []string
	UseShortAdjectives bool   // Whether to failover to short adjectives
	QuestAlert         bool   // Whether this mob is relevant to a current quest
	PetName            string // Name of pet (if any)
}

func (FormattedName) String

func (f FormattedName) String() string

type KDStats

type KDStats struct {
	TotalKills  int         `json:"totalkills,omitempty"`  // Quick tally of kills
	Kills       map[int]int `json:"kills,omitempty"`       // map of MobId to count
	TotalDeaths int         `json:"totaldeaths,omitempty"` // Quick tally of deaths

	TotalPvpKills  int            `json:"totalpvpkills,omitempty"`  // Quick tally of pvp kills
	PlayerKills    map[string]int `json:"playerkills,omitempty"`    // map of userid:username to count
	PlayerDeaths   map[string]int `json:"playerdeaths,omitempty"`   // map of userid:username to count
	TotalPvpDeaths int            `json:"totalpvpdeaths,omitempty"` // Quick tally of pvp deaths
}

func (*KDStats) AddMobDeath

func (kd *KDStats) AddMobDeath()

func (*KDStats) AddMobKill

func (kd *KDStats) AddMobKill(mobId int)

func (*KDStats) AddPlayerDeath

func (kd *KDStats) AddPlayerDeath(killedByUserId int, killedByCharName string)

func (*KDStats) AddPlayerKill

func (kd *KDStats) AddPlayerKill(killedUserId int, killedCharName string)

func (*KDStats) AddPvpDeath

func (kd *KDStats) AddPvpDeath()

func (*KDStats) GetMobDeaths

func (kd *KDStats) GetMobDeaths() int

func (*KDStats) GetMobKDRatio

func (kd *KDStats) GetMobKDRatio() float64

func (*KDStats) GetMobKills

func (kd *KDStats) GetMobKills(mobId ...int) int

func (*KDStats) GetPvpDeaths

func (kd *KDStats) GetPvpDeaths() int

func (*KDStats) GetPvpKDRatio

func (kd *KDStats) GetPvpKDRatio() float64

type MobMasteries

type MobMasteries struct {
	Tame map[int]int `json:"tame,omitempty"` // mobId to proficiency
}

func (*MobMasteries) GetAllTame

func (m *MobMasteries) GetAllTame() map[int]int

func (*MobMasteries) GetTame

func (m *MobMasteries) GetTame(mobId int) int

func (*MobMasteries) SetTame

func (m *MobMasteries) SetTame(mobId int, amt int)

type NameRenderFlag

type NameRenderFlag uint8
const (
	RenderHealth NameRenderFlag = iota
	RenderAggro
	RenderShortAdjectives
)

type Shop

type Shop []ShopItem

func (*Shop) Destock

func (s *Shop) Destock(si ShopItem) bool

func (*Shop) GetInstock

func (s *Shop) GetInstock() Shop

func (*Shop) Restock

func (s *Shop) Restock() bool

func (*Shop) StockItem

func (s *Shop) StockItem(itemId int) bool

type ShopItem

type ShopItem struct {
	MobId       int    `yaml:"mobid,omitempty"`       // Is it a mercenary for sale?
	ItemId      int    `yaml:"itemid,omitempty"`      // Is it an item for sale?
	BuffId      int    `yaml:"buffid,omitempty"`      // Does this shop keeper apply a buff if purchased?
	PetType     string `yaml:"pettype,omitempty"`     // Does this shop sell pets?
	Quantity    int    `yaml:"quantity,omitempty"`    // How many currently avilable
	QuantityMax int    `yaml:"quantitymax,omitempty"` // 0 for unlimited, or a maximum that can be stocked at one time
	Price       int    `yaml:"price,omitempty"`       // If a price is provided, use it
	TradeItemId int    `yaml:"tradeitemid,omitempty"` // ItemId required in trade
	RestockRate string `yaml:"restockrate,omitempty"` // 1 day, 1 week, 1 real month, etc
	// contains filtered or unexported fields
}

func (*ShopItem) Available

func (si *ShopItem) Available() bool

type SpellAggroInfo

type SpellAggroInfo struct {
	SpellId              string
	SpellRest            string
	TargetUserIds        []int
	TargetMobInstanceIds []int
}

type Worn

type Worn struct {
	Weapon  items.Item `yaml:"weapon,omitempty"`
	Offhand items.Item `yaml:"offhand,omitempty"`
	Head    items.Item `yaml:"head,omitempty"`
	Neck    items.Item `yaml:"neck,omitempty"`
	Body    items.Item `yaml:"body,omitempty"`
	Belt    items.Item `yaml:"belt,omitempty"`
	Gloves  items.Item `yaml:"gloves,omitempty"`
	Ring    items.Item `yaml:"ring,omitempty"`
	Legs    items.Item `yaml:"legs,omitempty"`
	Feet    items.Item `yaml:"feet,omitempty"`
}

func (*Worn) EnableAll

func (w *Worn) EnableAll()

func (*Worn) GetAllItems

func (w *Worn) GetAllItems() []items.Item

func (*Worn) StatMod

func (w *Worn) StatMod(stat ...string) int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL