1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-16 04:25:23 +00:00
OpenDiablo2/d2core/d2map/d2mapentity/cast_overlay.go
presiyan-ivanov 88326b5278
Initial cast overlay implementation. Fix HeroSkill deserialization & map entities processing crashing for remote client. (#766)
* Casting a skill now plays the corresponding overlay(if any).

* Prevent a crash caused by nil pointer in HeroSkill deserialization, happening when
unmarshalling HeroSkill from packets as a remote client.

* Add PlayerAnimationModeNone to handle some of the Skills(e.g.
Paladin auras) having "" as animation mode.

* Joining a game as remote client now waits for map generation to finish
before rendering map or processing map entities. This is temporary hack to prevent the game from
crashing due to concurrent map read & write exception.

* Send CastSkill packet to other clients.

Co-authored-by: Presiyan Ivanov <presiyan-ivanov@users.noreply.github.com>
2020-10-10 18:47:51 -04:00

58 lines
1.6 KiB
Go

package d2mapentity
import (
"math"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
)
// CastOverlay is an animated entity representing a projectile that is a result of a skill cast.
type CastOverlay struct {
*AnimatedEntity
record *d2records.OverlayRecord
playLoop bool
onDoneFunc func()
}
// ID returns the overlay uuid
func (co *CastOverlay) ID() string {
return co.AnimatedEntity.uuid
}
// GetPosition returns the position of the overlay
func (co *CastOverlay) GetPosition() d2vector.Position {
return co.AnimatedEntity.Position
}
// GetVelocity returns the velocity vector of the overlay
func (co *CastOverlay) GetVelocity() d2vector.Vector {
return co.AnimatedEntity.velocity
}
// SetRadians adjusts the entity target based on it's range, rotating it's
// current destination by the value of angle in radians.
func (co *CastOverlay) SetRadians(angle float64, done func()) {
rads := float64(co.record.Height2) // TODO:
x := co.Position.X() + (rads * math.Cos(angle))
y := co.Position.Y() + (rads * math.Sin(angle))
co.setTarget(d2vector.NewPosition(x, y), done)
}
// SetOnDoneFunc changes the handler func that gets called when the overlay finishes playing.
func (co *CastOverlay) SetOnDoneFunc(onDoneFunc func()) {
co.onDoneFunc = onDoneFunc
}
// Advance is called once per frame and processes a single game tick.
func (co *CastOverlay) Advance(tickTime float64) {
co.Step(tickTime)
co.AnimatedEntity.Advance(tickTime)
if !co.playLoop && co.AnimatedEntity.animation.GetPlayedCount() >= 1 {
co.onDoneFunc()
}
}