1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-05 09:47:18 -05:00
OpenDiablo2/d2core/d2object/init_function.go
Intyre 9e58b134e5
Refactored d2enum (#567)
* Refactored animation mode enum

* More d2enum changes

* Refactored tile enum

* Refactored weapon class enum

* Refactored more enums

* Refactored item event enum

* Fixed init_functions animation mode

* Removed string2enum from MonsterAnimationMode

* Refactored ItemStatCost description

* Last enum lint errors

* Regenerated monster stringer file
2020-07-09 23:12:28 -04:00

52 lines
1.0 KiB
Go

package d2object
import (
"math/rand"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
)
// Finds an init function for the given object
func initObject(ob *Object) bool {
funcs := map[int]func(*Object){
8: initTorch,
14: initTorch,
17: initWaypoint,
34: initTorchRnd,
}
fun, ok := funcs[ob.objectRecord.InitFn]
if !ok {
return false
}
fun(ob)
return true
}
// Initializes torch/brazier type objects
func initTorch(ob *Object) {
if ob.objectRecord.HasAnimationMode[d2enum.ObjectAnimationModeOpened] {
ob.setMode(d2enum.ObjectAnimationModeOpened, 0, true)
}
}
func initWaypoint(ob *Object) {
// Turn these on unconditionally for now, they look nice :)
if ob.objectRecord.HasAnimationMode[d2enum.ObjectAnimationModeOpened] {
ob.setMode(d2enum.ObjectAnimationModeOpened, 0, true)
}
}
// Randomly spawns in either NU or OP
func initTorchRnd(ob *Object) {
n := rand.Intn(2)
if n > 0 {
ob.setMode(d2enum.ObjectAnimationModeNeutral, 0, true)
} else {
ob.setMode(d2enum.ObjectAnimationModeOperating, 0, true)
}
}