You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.7 KiB
Go
88 lines
3.7 KiB
Go
package model
|
|
|
|
type EnemyType string
|
|
|
|
const (
|
|
EnemyWolf EnemyType = "wolf"
|
|
EnemyBoar EnemyType = "boar"
|
|
EnemyZombie EnemyType = "zombie"
|
|
EnemySpider EnemyType = "spider"
|
|
EnemyOrc EnemyType = "orc"
|
|
EnemySkeletonArcher EnemyType = "skeleton_archer"
|
|
EnemyBattleLizard EnemyType = "battle_lizard"
|
|
EnemyFireDemon EnemyType = "fire_demon"
|
|
EnemyIceGuardian EnemyType = "ice_guardian"
|
|
EnemySkeletonKing EnemyType = "skeleton_king"
|
|
EnemyWaterElement EnemyType = "water_element"
|
|
EnemyForestWarden EnemyType = "forest_warden"
|
|
EnemyLightningTitan EnemyType = "lightning_titan"
|
|
)
|
|
|
|
type SpecialAbility string
|
|
|
|
const (
|
|
AbilityBurn SpecialAbility = "burn" // DoT fire damage
|
|
AbilitySlow SpecialAbility = "slow" // -40% movement speed (Water Element)
|
|
AbilityCritical SpecialAbility = "critical" // chance for double damage
|
|
AbilityPoison SpecialAbility = "poison" // DoT poison damage
|
|
AbilityFreeze SpecialAbility = "freeze" // -50% attack speed (generic)
|
|
AbilityIceSlow SpecialAbility = "ice_slow" // -20% attack speed (Ice Guardian per spec)
|
|
AbilityStun SpecialAbility = "stun" // no attacks for 2 sec
|
|
AbilityDodge SpecialAbility = "dodge" // chance to avoid incoming damage
|
|
AbilityRegen SpecialAbility = "regen" // regenerate HP over time
|
|
AbilityBurst SpecialAbility = "burst" // every Nth attack deals multiplied damage
|
|
AbilityChainLightning SpecialAbility = "chain_lightning" // 3x damage after 5 attacks
|
|
AbilitySummon SpecialAbility = "summon" // summons minions
|
|
)
|
|
|
|
type Enemy struct {
|
|
ID int64 `json:"id"`
|
|
Type EnemyType `json:"type"`
|
|
Name string `json:"name"`
|
|
HP int `json:"hp"`
|
|
MaxHP int `json:"maxHp"`
|
|
Attack int `json:"attack"`
|
|
Defense int `json:"defense"`
|
|
Speed float64 `json:"speed"` // attacks per second
|
|
CritChance float64 `json:"critChance"` // 0.0 to 1.0
|
|
MinLevel int `json:"minLevel"`
|
|
MaxLevel int `json:"maxLevel"`
|
|
BaseLevel int `json:"baseLevel"`
|
|
LevelVariance float64 `json:"levelVariance"` // 0.30 => +/-30%
|
|
MaxHeroLevelDiff int `json:"maxHeroLevelDiff"`
|
|
HPPerLevel float64 `json:"hpPerLevel"`
|
|
AttackPerLevel float64 `json:"attackPerLevel"`
|
|
DefensePerLevel float64 `json:"defensePerLevel"`
|
|
XPPerLevel float64 `json:"xpPerLevel"`
|
|
GoldPerLevel float64 `json:"goldPerLevel"`
|
|
Level int `json:"level,omitempty"` // runtime instance level
|
|
XPReward int64 `json:"xpReward"`
|
|
GoldReward int64 `json:"goldReward"`
|
|
SpecialAbilities []SpecialAbility `json:"specialAbilities,omitempty"`
|
|
IsElite bool `json:"isElite"`
|
|
AttackCount int `json:"-"` // tracks attacks for burst/chain abilities
|
|
}
|
|
|
|
// IsAlive returns true if the enemy has HP remaining.
|
|
func (e *Enemy) IsAlive() bool {
|
|
return e.HP > 0
|
|
}
|
|
|
|
// HasAbility checks if the enemy possesses a given special ability.
|
|
func (e *Enemy) HasAbility(a SpecialAbility) bool {
|
|
for _, ab := range e.SpecialAbilities {
|
|
if ab == a {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// EnemyTemplates is loaded from DB at startup/reload.
|
|
// It intentionally has no hardcoded fallback templates in code.
|
|
var EnemyTemplates = map[EnemyType]Enemy{}
|
|
|
|
func SetEnemyTemplates(next map[EnemyType]Enemy) {
|
|
EnemyTemplates = next
|
|
}
|