modernize, improve entities. First pass
This commit is contained in:
parent
6df4b00201
commit
7ce87100e6
@ -1,167 +0,0 @@
|
||||
# Entity Package
|
||||
|
||||
The Entity package provides the core combat and magic systems for EverQuest II server emulation. It extends the base Spawn system with combat capabilities, spell effects, and character statistics management.
|
||||
|
||||
## Overview
|
||||
|
||||
The Entity system is built on three main components:
|
||||
|
||||
1. **InfoStruct** - Comprehensive character statistics and information
|
||||
2. **SpellEffectManager** - Manages all spell effects, buffs, debuffs, and bonuses
|
||||
3. **Entity** - Combat-capable spawn with spell casting and pet management
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
Spawn (base class)
|
||||
└── Entity (combat-capable)
|
||||
├── Player (player characters)
|
||||
└── NPC (non-player characters)
|
||||
```
|
||||
|
||||
## Core Components
|
||||
|
||||
### InfoStruct
|
||||
|
||||
Contains all character statistics including:
|
||||
- Primary attributes (STR, STA, AGI, WIS, INT)
|
||||
- Combat stats (attack, mitigation, avoidance)
|
||||
- Resistances (heat, cold, magic, mental, divine, disease, poison)
|
||||
- Experience points and currency
|
||||
- Equipment and weapon information
|
||||
- Group and encounter settings
|
||||
|
||||
**Thread Safety**: All access methods use RWMutex for safe concurrent access.
|
||||
|
||||
### SpellEffectManager
|
||||
|
||||
Manages four types of spell effects:
|
||||
|
||||
1. **Maintained Effects** - Buffs that consume concentration
|
||||
2. **Spell Effects** - Temporary buffs/debuffs with durations
|
||||
3. **Detrimental Effects** - Debuffs and harmful effects
|
||||
4. **Bonus Values** - Stat modifications from various sources
|
||||
|
||||
**Key Features**:
|
||||
- Automatic expiration handling
|
||||
- Control effect tracking (stun, root, mez, etc.)
|
||||
- Bonus calculations with class/race/faction requirements
|
||||
- Thread-safe effect management
|
||||
|
||||
### Entity
|
||||
|
||||
Combat-capable spawn that extends base Spawn functionality:
|
||||
|
||||
**Combat Systems**:
|
||||
- Health/Power/Savagery management
|
||||
- Combat state tracking (in combat, casting)
|
||||
- Damage resistance calculations
|
||||
- Speed and movement modifiers
|
||||
|
||||
**Magic Systems**:
|
||||
- Spell effect application and removal
|
||||
- Concentration-based maintained spells
|
||||
- Bonus stat calculations
|
||||
- Control effect immunity
|
||||
|
||||
**Pet Systems**:
|
||||
- Multiple pet types (summon, charm, deity, cosmetic)
|
||||
- Pet ownership and dismissal
|
||||
- Pet spell tracking
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### Creating an Entity
|
||||
|
||||
```go
|
||||
entity := NewEntity()
|
||||
entity.GetInfoStruct().SetName("TestEntity")
|
||||
entity.GetInfoStruct().SetLevel(50)
|
||||
entity.GetInfoStruct().SetStr(100.0)
|
||||
```
|
||||
|
||||
### Managing Spell Effects
|
||||
|
||||
```go
|
||||
// Add a maintained spell (buff)
|
||||
success := entity.AddMaintainedSpell("Heroic Strength", 12345, 300.0, 2)
|
||||
|
||||
// Add a temporary effect
|
||||
entity.AddSpellEffect(54321, casterID, 60.0)
|
||||
|
||||
// Add a detrimental effect
|
||||
entity.AddDetrimentalSpell(99999, attackerID, 30.0, 1)
|
||||
```
|
||||
|
||||
### Stat Calculations
|
||||
|
||||
```go
|
||||
// Get effective stats (base + bonuses)
|
||||
str := entity.GetStr()
|
||||
sta := entity.GetSta()
|
||||
primary := entity.GetPrimaryStat()
|
||||
|
||||
// Recalculate all bonuses
|
||||
entity.CalculateBonuses()
|
||||
```
|
||||
|
||||
### Pet Management
|
||||
|
||||
```go
|
||||
// Set a summon pet
|
||||
entity.SetPet(petEntity)
|
||||
|
||||
// Check pet status
|
||||
if entity.GetPet() != nil && !entity.IsPetDismissing() {
|
||||
// Pet is active
|
||||
}
|
||||
```
|
||||
|
||||
## Constants and Enums
|
||||
|
||||
### Pet Types
|
||||
- `PetTypeSummon` - Summoned pets
|
||||
- `PetTypeCharm` - Charmed creatures
|
||||
- `PetTypeDeity` - Deity pets
|
||||
- `PetTypeCosmetic` - Cosmetic pets
|
||||
|
||||
### Control Effects
|
||||
- `ControlEffectStun` - Cannot move or act
|
||||
- `ControlEffectRoot` - Cannot move
|
||||
- `ControlEffectMez` - Mesmerized
|
||||
- `ControlEffectDaze` - Dazed
|
||||
- `ControlEffectFear` - Feared
|
||||
- `ControlEffectSlow` - Movement slowed
|
||||
- `ControlEffectSnare` - Movement impaired
|
||||
- `ControlEffectCharm` - Mind controlled
|
||||
|
||||
## Thread Safety
|
||||
|
||||
All Entity operations are thread-safe using:
|
||||
- `sync.RWMutex` for read/write operations
|
||||
- `sync.atomic` for simple state flags
|
||||
- Separate mutexes for different subsystems to minimize lock contention
|
||||
|
||||
## Integration with Spawn System
|
||||
|
||||
The Entity extends the base Spawn class and requires:
|
||||
- `spawn.NewSpawn()` for initialization
|
||||
- Access to Spawn position and basic methods
|
||||
- Integration with zone update systems
|
||||
|
||||
## Future Extensions
|
||||
|
||||
Areas marked with TODO comments for future implementation:
|
||||
- Complete item and equipment systems
|
||||
- Combat calculation methods
|
||||
- Threat and hate management
|
||||
- Group combat mechanics
|
||||
- Spell casting systems
|
||||
- LUA script integration
|
||||
|
||||
## Files
|
||||
|
||||
- `entity.go` - Main Entity class implementation
|
||||
- `info_struct.go` - Character statistics and information
|
||||
- `spell_effects.go` - Spell effect management system
|
||||
- `README.md` - This documentation file
|
@ -503,4 +503,3 @@ func BenchmarkScalability(b *testing.B) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
41
internal/entity/doc.go
Normal file
41
internal/entity/doc.go
Normal file
@ -0,0 +1,41 @@
|
||||
// Package entity provides the core combat and magic systems for EverQuest II server emulation.
|
||||
// It extends the base Spawn system with combat capabilities, spell effects, and character statistics management.
|
||||
//
|
||||
// Basic Usage:
|
||||
//
|
||||
// entity := entity.NewEntity()
|
||||
// entity.GetInfoStruct().SetName("TestEntity")
|
||||
// entity.GetInfoStruct().SetLevel(50)
|
||||
// entity.GetInfoStruct().SetStr(100.0)
|
||||
//
|
||||
// Managing Spell Effects:
|
||||
//
|
||||
// // Add a maintained spell (buff)
|
||||
// success := entity.AddMaintainedSpell("Heroic Strength", 12345, 300.0, 2)
|
||||
//
|
||||
// // Add a temporary effect
|
||||
// entity.AddSpellEffect(54321, casterID, 60.0)
|
||||
//
|
||||
// // Add a detrimental effect
|
||||
// entity.AddDetrimentalSpell(99999, attackerID, 30.0, 1)
|
||||
//
|
||||
// Stat Calculations:
|
||||
//
|
||||
// // Get effective stats (base + bonuses)
|
||||
// str := entity.GetStr()
|
||||
// sta := entity.GetSta()
|
||||
// primary := entity.GetPrimaryStat()
|
||||
//
|
||||
// // Recalculate all bonuses
|
||||
// entity.CalculateBonuses()
|
||||
//
|
||||
// Pet Management:
|
||||
//
|
||||
// // Set a summon pet
|
||||
// entity.SetPet(petEntity)
|
||||
//
|
||||
// // Check pet status
|
||||
// if entity.GetPet() != nil && !entity.IsPetDismissing() {
|
||||
// // Pet is active
|
||||
// }
|
||||
package entity
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"eq2emu/internal/common"
|
||||
"eq2emu/internal/spawn"
|
||||
"eq2emu/internal/spells"
|
||||
)
|
||||
|
||||
// Combat and pet types
|
||||
@ -43,7 +44,7 @@ type Entity struct {
|
||||
regenPowerRate int16 // Power regeneration rate
|
||||
|
||||
// Spell and effect management
|
||||
spellEffectManager *SpellEffectManager
|
||||
spellEffectManager *spells.SpellEffectManager
|
||||
|
||||
// Pet system
|
||||
pet *Entity // Summon pet
|
||||
@ -106,7 +107,7 @@ func NewEntity() *Entity {
|
||||
lastHeading: -1,
|
||||
regenHpRate: 0,
|
||||
regenPowerRate: 0,
|
||||
spellEffectManager: NewSpellEffectManager(),
|
||||
spellEffectManager: spells.NewSpellEffectManager(),
|
||||
pet: nil,
|
||||
charmedPet: nil,
|
||||
deityPet: nil,
|
||||
@ -357,7 +358,7 @@ func (e *Entity) AddMaintainedSpell(name string, spellID int32, duration float32
|
||||
return false
|
||||
}
|
||||
|
||||
effect := NewMaintainedEffects(name, spellID, duration)
|
||||
effect := spells.NewMaintainedEffects(name, spellID, duration)
|
||||
effect.ConcUsed = concentration
|
||||
|
||||
e.maintainedMutex.Lock()
|
||||
@ -390,7 +391,7 @@ func (e *Entity) RemoveMaintainedSpell(spellID int32) bool {
|
||||
}
|
||||
|
||||
// GetMaintainedSpell retrieves a maintained spell effect
|
||||
func (e *Entity) GetMaintainedSpell(spellID int32) *MaintainedEffects {
|
||||
func (e *Entity) GetMaintainedSpell(spellID int32) *spells.MaintainedEffects {
|
||||
e.maintainedMutex.RLock()
|
||||
defer e.maintainedMutex.RUnlock()
|
||||
|
||||
@ -399,7 +400,7 @@ func (e *Entity) GetMaintainedSpell(spellID int32) *MaintainedEffects {
|
||||
|
||||
// AddSpellEffect adds a temporary spell effect
|
||||
func (e *Entity) AddSpellEffect(spellID int32, casterID int32, duration float32) bool {
|
||||
effect := NewSpellEffects(spellID, casterID, duration)
|
||||
effect := spells.NewSpellEffects(spellID, casterID, duration)
|
||||
|
||||
e.spellEffectMutex.Lock()
|
||||
defer e.spellEffectMutex.Unlock()
|
||||
@ -417,7 +418,7 @@ func (e *Entity) RemoveSpellEffect(spellID int32) bool {
|
||||
|
||||
// AddDetrimentalSpell adds a detrimental effect
|
||||
func (e *Entity) AddDetrimentalSpell(spellID int32, casterID int32, duration float32, detType int8) {
|
||||
effect := NewDetrimentalEffects(spellID, casterID, duration)
|
||||
effect := spells.NewDetrimentalEffects(spellID, casterID, duration)
|
||||
effect.DetType = detType
|
||||
|
||||
e.detrimentalMutex.Lock()
|
||||
@ -435,7 +436,7 @@ func (e *Entity) RemoveDetrimentalSpell(spellID int32, casterID int32) bool {
|
||||
}
|
||||
|
||||
// GetDetrimentalEffect retrieves a detrimental effect
|
||||
func (e *Entity) GetDetrimentalEffect(spellID int32, casterID int32) *DetrimentalEffects {
|
||||
func (e *Entity) GetDetrimentalEffect(spellID int32, casterID int32) *spells.DetrimentalEffects {
|
||||
e.detrimentalMutex.RLock()
|
||||
defer e.detrimentalMutex.RUnlock()
|
||||
|
||||
@ -451,13 +452,13 @@ func (e *Entity) HasControlEffect(controlType int8) bool {
|
||||
|
||||
// AddSkillBonus adds a skill-related bonus
|
||||
func (e *Entity) AddSkillBonus(spellID int32, skillID int32, value float32) {
|
||||
bonus := NewBonusValues(spellID, int16(skillID+100), value) // Skill bonuses use type 100+
|
||||
bonus := spells.NewBonusValues(spellID, int16(skillID+100), value) // Skill bonuses use type 100+
|
||||
e.spellEffectManager.AddBonus(bonus)
|
||||
}
|
||||
|
||||
// AddStatBonus adds a stat bonus
|
||||
func (e *Entity) AddStatBonus(spellID int32, statType int16, value float32) {
|
||||
bonus := NewBonusValues(spellID, statType, value)
|
||||
bonus := spells.NewBonusValues(spellID, statType, value)
|
||||
e.spellEffectManager.AddBonus(bonus)
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"eq2emu/internal/spells"
|
||||
)
|
||||
|
||||
func TestNewEntity(t *testing.T) {
|
||||
@ -628,7 +630,7 @@ func TestEntityControlEffects(t *testing.T) {
|
||||
|
||||
// Test has control effect - should work without panicking
|
||||
// The actual implementation depends on the spell effect manager
|
||||
hasStun := entity.HasControlEffect(ControlEffectStun)
|
||||
hasStun := entity.HasControlEffect(spells.ControlEffectStun)
|
||||
_ = hasStun // We can't easily test the actual value without setting up effects
|
||||
}
|
||||
|
||||
@ -651,7 +653,7 @@ func TestEntityConstants(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test control effect constants (re-exported from spells package)
|
||||
if ControlEffectStun == 0 && ControlEffectRoot == 0 {
|
||||
if spells.ControlEffectStun == 0 && spells.ControlEffectRoot == 0 {
|
||||
t.Error("Control effect constants should be non-zero")
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package entity
|
||||
|
||||
// DEPRECATED: This file now imports spell effect structures from the spells package.
|
||||
// The spell effect management has been moved to internal/spells for better organization.
|
||||
|
||||
import (
|
||||
"eq2emu/internal/spells"
|
||||
)
|
||||
|
||||
// Re-export spell effect types for backward compatibility
|
||||
// These will eventually be removed in favor of direct imports from spells package
|
||||
|
||||
type BonusValues = spells.BonusValues
|
||||
type MaintainedEffects = spells.MaintainedEffects
|
||||
type SpellEffects = spells.SpellEffects
|
||||
type DetrimentalEffects = spells.DetrimentalEffects
|
||||
type SpellEffectManager = spells.SpellEffectManager
|
||||
|
||||
// Re-export constructor functions
|
||||
var NewBonusValues = spells.NewBonusValues
|
||||
var NewMaintainedEffects = spells.NewMaintainedEffects
|
||||
var NewSpellEffects = spells.NewSpellEffects
|
||||
var NewDetrimentalEffects = spells.NewDetrimentalEffects
|
||||
var NewSpellEffectManager = spells.NewSpellEffectManager
|
||||
|
||||
// Re-export constants
|
||||
const (
|
||||
ControlEffectStun = spells.ControlEffectStun
|
||||
ControlEffectRoot = spells.ControlEffectRoot
|
||||
ControlEffectMez = spells.ControlEffectMez
|
||||
ControlEffectDaze = spells.ControlEffectDaze
|
||||
ControlEffectFear = spells.ControlEffectFear
|
||||
ControlEffectSlow = spells.ControlEffectSlow
|
||||
ControlEffectSnare = spells.ControlEffectSnare
|
||||
ControlEffectCharm = spells.ControlEffectCharm
|
||||
ControlMaxEffects = spells.ControlMaxEffects
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user