Add biome revisions readable content and visible projectile outcomes

This commit is contained in:
dingo
2026-09-09 08:27:32 -04:00
parent 4a7979e32f
commit 70d08b0d32
24 changed files with 703 additions and 128 deletions
+31 -2
View File
@@ -27,12 +27,22 @@ type CombatArea struct {
}
func protocolAttack(a content.CombatAttack) p.CombatAttack {
return p.CombatAttack{ID: a.ID, Name: a.Name, Description: a.Description, Delivery: a.Delivery, Effect: a.Effect, Stat: a.Stat, Multiplier: a.Multiplier, Range: a.Range, Cooldown: a.Cooldown, Stamina: a.Stamina, Speed: a.Speed, Radius: a.Radius, Duration: a.Duration, Interval: a.Interval}
return p.CombatAttack{ID: a.ID, Name: a.Name, Description: a.Description, Delivery: a.Delivery, Effect: a.Effect, Stat: a.Stat, Multiplier: a.Multiplier, Range: a.Range, Cooldown: a.Cooldown, Stamina: a.Stamina, Speed: a.Speed, DexteritySpeed: &a.DexteritySpeed, StrengthSpeed: &a.StrengthSpeed, Radius: a.Radius, Duration: a.Duration, Interval: a.Interval}
}
func (w *World) playerAttack(c *Character) p.CombatAttack {
for _, i := range c.View.Items {
if i.ID == c.View.Equipment["weapon"] && i.Attack != nil {
return *i.Attack
a := *i.Attack
if a.Delivery == "projectile" {
if a.DexteritySpeed != nil {
a.Speed += c.View.Stats["dexterity"].Final * *a.DexteritySpeed
}
if a.StrengthSpeed != nil {
a.Speed += c.View.Stats["strength"].Final * *a.StrengthSpeed
}
a.Speed = math.Max(1, math.Min(100, a.Speed))
}
return a
}
}
return p.CombatAttack{ID: "basic_melee", Name: "Melee attack", Delivery: "melee", Effect: "damage", Stat: "meleeDamage", Multiplier: 1, Range: w.Balance.AttackRange, Cooldown: w.Balance.AttackCooldown, Speed: 1, Interval: 1}
@@ -137,6 +147,7 @@ func (w *World) attack(c *Character, target string) error {
shot := Projectile{ID: w.combatID("projectile"), Source: c.View.Entity.ID, Player: true, Target: target, Position: from, Destination: to, Attack: a, Power: power}
if a.Delivery == "projectile" {
w.Projectiles[shot.ID] = &shot
w.projectileVisual(shot, "launch", "")
} else {
shot.Position = to
w.impact(shot, target)
@@ -254,6 +265,7 @@ func (w *World) updateCombat(dt float64) {
for _, id := range ids {
shot := w.Projectiles[id]
if !w.sourceActive(shot.Source, shot.Player) {
w.projectileVisual(*shot, "impact", "cancelled")
delete(w.Projectiles, id)
w.dirty = true
continue
@@ -302,6 +314,13 @@ func (w *World) updateCombat(dt float64) {
copy.Position = hitPoint
}
delete(w.Projectiles, id)
outcome := "miss"
if hit != "" {
outcome = "hit"
} else if blocked {
outcome = "terrain"
}
w.projectileVisual(copy, "impact", outcome)
w.impact(copy, hit)
} else {
shot.Position = end
@@ -326,6 +345,16 @@ func (w *World) updateCombat(dt float64) {
}
}
}
// Short, bounded event history lets a launch and impact survive between network
// snapshots. This is presentation data; damage is resolved only by updateCombat.
func (w *World) projectileVisual(shot Projectile, phase, outcome string) {
w.ProjectileVisuals = append(w.ProjectileVisuals, p.ProjectileVisual{ID: w.combatID("visual"), ProjectileID: shot.ID, Phase: phase, Position: shot.Position, Destination: shot.Destination, Speed: shot.Attack.Speed, Outcome: outcome, At: w.Age()})
if len(w.ProjectileVisuals) > 1024 {
w.ProjectileVisuals = w.ProjectileVisuals[len(w.ProjectileVisuals)-1024:]
}
w.dirty = true
}
func (w *World) mobKilled(c *Character, m *Mob) {
if m.Entity.State == "dead" {
return