Add persistent destructible world structures and building kits
This commit is contained in:
@@ -90,6 +90,11 @@ func (w *World) combatTargets(player bool, effect string) []p.Entity {
|
||||
out = append(out, p.Entity{ID: "boss", Position: w.terrain.Position(0, 0), HP: w.BossHP})
|
||||
}
|
||||
}
|
||||
if effect == "damage" {
|
||||
for _, id := range w.structureIDs() {
|
||||
out = append(out, w.Structures[id].Entity)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
func (w *World) terrainHit(a, b p.Vec3) (p.Vec3, bool) {
|
||||
@@ -129,13 +134,16 @@ func (w *World) attack(c *Character, target string) error {
|
||||
}
|
||||
from, to := body(c.View.Entity.Position), body(e.Position)
|
||||
extra := float64(0)
|
||||
if e.Kind == "structure" {
|
||||
extra = math.Max(*e.Width, *e.Depth) / 2
|
||||
}
|
||||
if target == "boss" {
|
||||
extra = 4
|
||||
}
|
||||
if length3(from, to) > a.Range+extra {
|
||||
return errors.New("target out of reach")
|
||||
}
|
||||
if _, blocked := w.terrainHit(from, to); blocked {
|
||||
if _, blocked := w.combatLine(from, to, target); blocked {
|
||||
return errors.New("terrain blocks the attack")
|
||||
}
|
||||
if a.Delivery == "projectile" && len(w.Projectiles) >= w.Balance.CombatRules.MaxProjectiles {
|
||||
@@ -206,7 +214,7 @@ func (w *World) areaPulse(shot Projectile) {
|
||||
if length3(body(e.Position), shot.Position) > shot.Attack.Radius {
|
||||
continue
|
||||
}
|
||||
if _, blocked := w.terrainHit(shot.Position, body(e.Position)); blocked {
|
||||
if _, blocked := w.combatLine(shot.Position, body(e.Position), e.ID); blocked {
|
||||
continue
|
||||
}
|
||||
w.combatHit(shot, e.ID)
|
||||
@@ -218,6 +226,12 @@ func (w *World) combatHit(shot Projectile, target string) {
|
||||
return
|
||||
}
|
||||
healing := shot.Attack.Effect == "heal"
|
||||
if w.Structures[target] != nil {
|
||||
if !healing {
|
||||
w.damageStructure(target, shot.Power)
|
||||
}
|
||||
return
|
||||
}
|
||||
if c := w.Characters[target]; c != nil {
|
||||
if c.View.Entity.State != "alive" || !c.Online || c.Sheltered {
|
||||
return
|
||||
@@ -301,7 +315,17 @@ func (w *World) updateCombat(dt float64) {
|
||||
}
|
||||
hit := ""
|
||||
hitPoint := obstacle
|
||||
for _, id := range w.structureIDs() {
|
||||
if f, ok := boxFraction(shot.Position, end, w.Structures[id].Entity, 0, 0); ok && f*length3(shot.Position, end) < best {
|
||||
best = f * length3(shot.Position, end)
|
||||
hit = id
|
||||
hitPoint = lerp3(shot.Position, end, f)
|
||||
}
|
||||
}
|
||||
for _, e := range w.combatTargets(shot.Player, shot.Attack.Effect) {
|
||||
if e.Kind == "structure" {
|
||||
continue
|
||||
}
|
||||
if e.ID == shot.Source && shot.Target != shot.Source {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user