2020-09-12 16:51:30 -04:00
|
|
|
package d2mapentity
|
2020-07-04 00:48:31 -04:00
|
|
|
|
|
|
|
import (
|
2020-07-06 20:12:53 -04:00
|
|
|
"math/rand"
|
|
|
|
|
2020-07-04 00:48:31 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Finds an init function for the given object
|
2020-07-26 14:52:54 -04:00
|
|
|
func initObject(ob *Object) (bool, error) {
|
|
|
|
funcs := map[int]func(*Object) error{
|
2020-07-04 00:48:31 -04:00
|
|
|
8: initTorch,
|
|
|
|
14: initTorch,
|
|
|
|
17: initWaypoint,
|
2020-07-06 20:12:53 -04:00
|
|
|
34: initTorchRnd,
|
2020-07-04 00:48:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fun, ok := funcs[ob.objectRecord.InitFn]
|
|
|
|
if !ok {
|
2020-07-26 14:52:54 -04:00
|
|
|
return false, nil
|
2020-07-04 00:48:31 -04:00
|
|
|
}
|
|
|
|
|
2020-07-26 14:52:54 -04:00
|
|
|
if err := fun(ob); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2020-07-04 00:48:31 -04:00
|
|
|
|
2020-07-26 14:52:54 -04:00
|
|
|
return true, nil
|
2020-07-04 00:48:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initializes torch/brazier type objects
|
2020-07-26 14:52:54 -04:00
|
|
|
func initTorch(ob *Object) error {
|
2020-07-09 23:12:28 -04:00
|
|
|
if ob.objectRecord.HasAnimationMode[d2enum.ObjectAnimationModeOpened] {
|
2020-07-26 14:52:54 -04:00
|
|
|
return ob.setMode(d2enum.ObjectAnimationModeOpened, 0, true)
|
2020-07-04 00:48:31 -04:00
|
|
|
}
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
return nil
|
2020-07-04 00:48:31 -04:00
|
|
|
}
|
|
|
|
|
2020-07-26 14:52:54 -04:00
|
|
|
func initWaypoint(ob *Object) error {
|
2020-07-04 00:48:31 -04:00
|
|
|
// Turn these on unconditionally for now, they look nice :)
|
2020-07-09 23:12:28 -04:00
|
|
|
if ob.objectRecord.HasAnimationMode[d2enum.ObjectAnimationModeOpened] {
|
2020-07-26 14:52:54 -04:00
|
|
|
return ob.setMode(d2enum.ObjectAnimationModeOpened, 0, true)
|
2020-07-06 20:12:53 -04:00
|
|
|
}
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
return nil
|
2020-07-06 20:12:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Randomly spawns in either NU or OP
|
2020-07-26 14:52:54 -04:00
|
|
|
func initTorchRnd(ob *Object) error {
|
2020-10-26 02:38:15 -04:00
|
|
|
const coinToss = 2
|
|
|
|
n := rand.Intn(coinToss) // nolint:gosec // not concerned with crypto-strong randomness
|
2020-07-06 20:12:53 -04:00
|
|
|
|
|
|
|
if n > 0 {
|
2020-07-26 14:52:54 -04:00
|
|
|
return ob.setMode(d2enum.ObjectAnimationModeNeutral, 0, true)
|
2020-07-04 00:48:31 -04:00
|
|
|
}
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
return ob.setMode(d2enum.ObjectAnimationModeOperating, 0, true)
|
2020-07-04 00:48:31 -04:00
|
|
|
}
|