combat

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignmentChange

func AlignmentChange(killerAlignment int8, killedAlignment int8) int

AlignmentChange returns the alignment delta for a killer after slaying a target.

func ChanceToTame

func ChanceToTame(s *users.UserRecord, t *mobs.Mob) int

ChanceToTame returns the probability that a user successfully tames a mob.

func CombatOdds added in v0.9.8

func CombatOdds(atkChar characters.Character, defChar characters.Character) float64

CombatOdds returns the ratio of rounds-for-attacker-to-kill-defender to rounds-for-defender-to-kill-attacker. Values above 1.0 favor the attacker.

func Crits

func Crits(sourceChar characters.Character, targetChar characters.Character) bool

Crits rolls whether an attack is a critical hit.

func Dodges added in v0.9.8

func Dodges(defPerc, atkPerc int) bool

Dodges returns true when the defender successfully dodges an attack.

func FormatArmorRankings added in v0.9.8

func FormatArmorRankings() string

FormatArmorRankings returns a human-readable table of all three ranking views, suitable for logging or printing to a terminal.

func FormatMobRankings added in v0.9.8

func FormatMobRankings() string

FormatMobRankings returns a human-readable table of all three ranking views.

func FormatPetRankings added in v0.9.8

func FormatPetRankings() string

FormatPetRankings returns a human-readable table of all three ranking views, suitable for logging or printing to a terminal.

func FormatWeaponRankings added in v0.9.8

func FormatWeaponRankings() string

FormatWeaponRankings returns a human-readable table of all three ranking views, suitable for logging or printing to a terminal.

func Hits

func Hits(atkSpd, defSpd, hitModifier int) bool

Hits returns whether an attack connects, incorporating an optional modifier. equal stats will result in 0% of max

Types

type ArmorRank added in v0.9.8

type ArmorRank struct {
	ItemId int
	Name   string
	Slot   string
	Cursed bool

	// Defense is the raw DamageReduction value from the item spec.
	Defense int

	// AdjDefense is Defense adjusted for the slot's inherent multiplier.
	// Offhand items with DamageReduction > 0 (shields) receive a ×1.5
	// multiplier inside Character.GetDefense(), so we reflect that here.
	AdjDefense float64

	// StatBonus is the sum of all raw stat mod values on the item (signed).
	StatBonus int

	// BuffCount is the number of WornBuffIds on the item (passive while equipped).
	BuffCount int

	// BuffValue is the aggregate GetValue() of all WornBuffIds.
	BuffValue int

	// Score is the unified eHP-equivalent ranking number.
	//
	// It is computed as:
	//
	//   defenseEHP + statValue + buffValue/10
	//
	// where:
	//   defenseEHP  = (AdjDefense / 200) * armorBaseHP
	//                 Expected HP-equivalent from damage reduction.
	//                 applyDefenseReduction draws uniform [0, DamageReduction),
	//                 so the expected fractional reduction per hit is
	//                 DamageReduction/200. Multiplied by the baseline HP pool
	//                 this gives how many effective extra HP the piece provides.
	//
	//   statValue   = per-stat weighted sum using weights derived from the
	//                 combat engine's own range constants:
	//                   strength   (DamageBonusMax-DamageBonusMin)/100  – damage output
	//                   speed      (ToHitMax-ToHitMin)/100              – hit chance
	//                   perception (CritMultMax-CritMultMin)/100 * base – crit/dodge
	//                   smarts     (CritChanceMax-CritChanceMin)/100    – crit chance
	//                   vitality / healthmax / manamax / healthrecovery / manarecovery: 1.0
	//                   damage (flat per-hit bonus): 1.0
	//                   attacks (extra attack/round): avgWeaponDPS proxy = 3.0
	//                   everything else: 1.0
	//
	//   buffValue/10 = aggregate buff GetValue() scaled down to the same order
	//                 of magnitude as the other components.
	Score float64
}

ArmorRank holds the computed metrics for a single armor item spec.

func RankArmor added in v0.9.8

func RankArmor() (byDefense, byAdjDefense, byScore []ArmorRank)

RankArmor computes ranking metrics for every loaded armor/wearable spec and returns slices sorted by three different criteria:

  • byDefense – raw DamageReduction value
  • byAdjDefense – DamageReduction adjusted for slot multiplier
  • byScore – unified eHP-equivalent score (defense + stats + buffs)

All three slices contain the same entries; only the order differs.

type AttackResult

type AttackResult struct {
	Hit                     bool  // defaults false
	Crit                    bool  // defaults false
	BuffSource              []int // defaults 0
	BuffTarget              []int // defaults 0
	DamageToTarget          int   // defaults 0
	DamageToTargetReduction int   // defaults 0
	DamageToSource          int   // defaults 0
	DamageToSourceReduction int   // defaults 0
	MessagesToSource        []string
	MessagesToTarget        []string
	MessagesToSourceRoom    []string
	MessagesToTargetRoom    []string
	MessagesToRoomOld       []string
}

func AttackMobVsMob

func AttackMobVsMob(mobAtk *mobs.Mob, mobDef *mobs.Mob) AttackResult

Performs a combat round from a mob to a mob

func AttackMobVsPlayer

func AttackMobVsPlayer(mob *mobs.Mob, user *users.UserRecord) AttackResult

Performs a combat round from a mob to a player

func AttackPlayerVsMob

func AttackPlayerVsMob(user *users.UserRecord, mob *mobs.Mob) AttackResult

Performs a combat round from a player to a mob

func AttackPlayerVsPlayer

func AttackPlayerVsPlayer(userAtk *users.UserRecord, userDef *users.UserRecord) AttackResult

Performs a combat round from a player to a player

func GetWaitMessages

func GetWaitMessages(stepType items.Intensity, sourceChar *characters.Character, targetChar *characters.Character, sourceType SourceTarget, targetType SourceTarget) AttackResult

func (*AttackResult) SendToRoomOld

func (a *AttackResult) SendToRoomOld(msg string)

func (*AttackResult) SendToSource

func (a *AttackResult) SendToSource(msg string)

func (*AttackResult) SendToSourceRoom

func (a *AttackResult) SendToSourceRoom(msg string)

func (*AttackResult) SendToTarget

func (a *AttackResult) SendToTarget(msg string)

func (*AttackResult) SendToTargetRoom

func (a *AttackResult) SendToTargetRoom(msg string)

type MobRank added in v0.9.8

type MobRank struct {
	MobId   int
	Name    string
	Zone    string
	Level   int
	Hostile bool

	// Combat metrics at the mob's effective level.
	DiceRoll string
	DPS      float64
	MaxDmg   int
	HP       int
	Defense  int
	// EHP is raw HP divided by the fraction of damage that gets through:
	// EHP = HP / (1 - min(Defense/200, 0.95))
	EHP    float64
	Threat float64 // DPS * EHP

	// Loot fields from the raw spec (level-independent).
	Gold           int
	ItemCount      int
	ItemDropChance int
	ItemValue      int
	// LootScore = Gold + (ItemDropChance/100 * ItemValue)
	// ItemValue includes carried items and worn items (excluding CanNeverBeRemoved).
	LootScore float64

	// Aggregate scores used for tab sorting.
	ThreatScore  float64 // = Threat
	DefenseScore float64 // = EHP
	OffenseScore float64 // = DPS
}

MobRank holds the computed metrics for a single mob spec, evaluated at the mob's effective level against a level-matched baseline opponent.

func RankMobs added in v0.9.8

func RankMobs() (byThreat, byLoot, byDefense []MobRank)

RankMobs computes ranking metrics for every loaded mob spec at each mob's effective level and returns slices sorted by three criteria:

  • byThreat – DPS × eHP
  • byLoot – expected loot value per kill
  • byDefense – effective HP

type PetLevelSnapshot added in v0.9.8

type PetLevelSnapshot struct {
	Level        int
	CombatChance int
	DiceRoll     string
	AvgDmg       float64
	MaxDmg       int
	DPS          float64 // avgDmg * combatChance/100
	StatMods     map[string]int
	StatTotal    int
	BuffCount    int
	BuffValue    int
	BuffNames    []string
	Capacity     int
}

PetLevelSnapshot captures a pet's effective ability at a given level.

type PetRank added in v0.9.8

type PetRank struct {
	Type string
	Name string

	// Per-level ability snapshots (index 0 = level 1, etc.)
	Levels []PetLevelSnapshot

	// Peak values across all levels
	PeakDPS       float64
	PeakMaxDmg    int
	PeakStatTotal int
	PeakCapacity  int
	PeakBuffCount int
	PeakBuffValue int

	// Aggregate scores
	CombatScore  float64 // weighted combat effectiveness across levels
	UtilityScore float64 // stat mods + buffs + capacity across levels
	OverallScore float64 // combined
}

PetRank holds the computed metrics for a single pet type across all levels.

func RankPets added in v0.9.8

func RankPets() (byCombat, byUtility, byOverall []PetRank)

RankPets computes ranking metrics for every loaded pet type and returns slices sorted by three criteria:

  • byCombat – weighted combat effectiveness across all levels
  • byUtility – stat mods + buffs + capacity value across all levels
  • byOverall – combined score

type SimResult added in v0.9.8

type SimResult struct {
	Winner           string
	WinnerSide       int // 0=draw, 1=A won, 2=B won
	Rounds           int
	DamageByA        int
	DamageByB        int
	HealthRemainingA int
	HealthRemainingB int
	NameA            string
	NameB            string
	LevelA           int
	LevelB           int
	Log              []string
}

func SimulateCombat added in v0.9.8

func SimulateCombat(mobIdA, mobIdB mobs.MobId, levelA, levelB int, maxRounds int) (SimResult, error)

SimulateCombat runs an instant fight between two mobs identified by their template IDs. levelA/levelB override the template level when > 0. maxRounds caps the fight length (defaults to 100 if <= 0).

func (SimResult) String added in v0.9.8

func (r SimResult) String() string

type SourceTarget

type SourceTarget string
const (
	User SourceTarget = "user"
	Mob  SourceTarget = "mob"
)

type WeaponRank added in v0.9.8

type WeaponRank struct {
	ItemId   int
	Name     string
	Subtype  items.ItemSubType
	Hands    int
	DiceRoll string

	// Raw dice metrics (weapon only, no character stat bonuses)
	AvgDmg float64
	MaxDmg int

	// DPR is the average damage that would land per round if every attack
	// connected with no misses, dodges, or defense reduction. It is the
	// raw per-round ceiling: avgDmgPerHit × attackCount.
	DPR float64

	// AdjDPR applies the same two-handed and wait-round opportunity-cost
	// penalties as AdjDPS, but to the raw DPR rather than the
	// combat-engine DPS.
	AdjDPR float64

	// expectedDPS from the combat engine against a neutral opponent
	// at equal stats (no character advantage either way).
	DPS float64

	// DPS adjusted for opportunity cost: two-handed weapons and
	// weapons with wait rounds give up something (offhand slot /
	// attack frequency), so we penalise them proportionally.
	// WaitRounds > 0 means the weapon skips that many rounds
	// between attacks; Hands == 2 means no offhand.
	AdjDPS float64

	WaitRounds int

	// BuffCount is the number of WornBuffIds on the weapon (passive while equipped).
	BuffCount int

	// BuffValue is the aggregate GetValue() of all WornBuffIds.
	BuffValue int
}

WeaponRank holds the computed metrics for a single weapon spec.

func RankWeapons added in v0.9.8

func RankWeapons() (byDPS, byAdjDPS, byMaxDmg []WeaponRank)

RankWeapons computes ranking metrics for every loaded weapon spec and returns slices sorted by three different criteria:

  • byDPS – raw expected DPS against an equal-stat opponent
  • byAdjDPS – DPS penalised for two-handed / wait-round cost
  • byMaxDmg – theoretical maximum single-hit damage

All three slices contain the same entries; only the order differs.

The function is intended for design-time balance analysis and is not called during normal gameplay.

Jump to

Keyboard shortcuts

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