diff options
Diffstat (limited to 'internal/world/mob.go')
| -rw-r--r-- | internal/world/mob.go | 100 |
1 files changed, 31 insertions, 69 deletions
diff --git a/internal/world/mob.go b/internal/world/mob.go index ebf97cf..9dfec59 100644 --- a/internal/world/mob.go +++ b/internal/world/mob.go @@ -8,24 +8,20 @@ import ( "strings" "sync" + "thirdcollapse/internal/action" "gopkg.in/yaml.v3" ) -type LootEntry struct { - ItemID string `yaml:"item_id"` - Weight int `yaml:"weight"` - Quantity int `yaml:"quantity"` -} - type DropTable struct { - Remains string `yaml:"remains"` - Loot []LootEntry `yaml:"loot"` + Remains string `yaml:"remains"` + Loot []action.DropEntry `yaml:"loot"` } type MobDef struct { ID string `yaml:"id"` Name string `yaml:"name"` Description string `yaml:"description"` + BehaviorID string `yaml:"behavior"` IdleDescriptions []string `yaml:"idle_descriptions"` CombatDescriptions []string `yaml:"combat_descriptions"` Attack int `yaml:"attack"` @@ -37,33 +33,32 @@ type MobDef struct { Protected bool `yaml:"protected"` Unique bool `yaml:"unique"` RespawnTicks int `yaml:"respawn_ticks"` - Wander int `yaml:"wander"` - WanderTick int `yaml:"wander_tick"` - WanderChance float64 `yaml:"wander_chance"` + WanderRooms []int `yaml:"wander_rooms"` + WanderInterval int `yaml:"wander_interval"` Drops DropTable `yaml:"drops"` } type MobInstance struct { - InstanceID string - DefID string - Name string - HP int - MaxHP int - Attack int - Strength int - Defense int - Speed int - Aggressive bool - Protected bool - Unique bool - RespawnTicks int - RoomID int - HomeRoomID int - Drops DropTable - IdleDescription string - Wander int - WanderTick int - WanderChance float64 + InstanceID string + DefID string + Name string + BehaviorID string + HP int + MaxHP int + Attack int + Strength int + Defense int + Speed int + Aggressive bool + Protected bool + Unique bool + RespawnTicks int + RoomID int + HomeRoomID int + Drops DropTable + IdleDescription string + WanderRooms []int + WanderInterval int WanderTickCounter int regenerateTick int } @@ -147,44 +142,12 @@ func (s *MobStore) LoadDef(id string) (*MobDef, error) { return &def, nil } -func (s *MobStore) SpawnMob(defID string, roomID int, instanceID string) (*MobInstance, error) { - def, err := s.LoadDef(defID) - if err != nil { - return nil, err - } - s.mu.Lock() - defer s.mu.Unlock() - inst := &MobInstance{ - InstanceID: instanceID, - DefID: defID, - Name: def.Name, - HP: def.HP, - MaxHP: def.HP, - Attack: def.Attack, - Strength: def.Strength, - Defense: def.Defense, - Speed: def.Speed, - Aggressive: def.Aggressive, - RespawnTicks: def.RespawnTicks, - RoomID: roomID, - Drops: def.Drops, - } - s.instances[instanceID] = inst - return inst, nil -} - func (s *MobStore) GetInstance(id string) *MobInstance { s.mu.Lock() defer s.mu.Unlock() return s.instances[id] } -func (s *MobStore) RemoveInstance(id string) { - s.mu.Lock() - defer s.mu.Unlock() - delete(s.instances, id) -} - func (s *MobStore) AllInstances() []*MobInstance { s.mu.Lock() defer s.mu.Unlock() @@ -235,9 +198,8 @@ func (s *MobStore) RollIdleDescription(inst *MobInstance) { return } inst.IdleDescription = pickIdleDescription(def.IdleDescriptions) - inst.Wander = def.Wander - inst.WanderTick = def.WanderTick - inst.WanderChance = def.WanderChance + inst.WanderRooms = def.WanderRooms + inst.WanderInterval = def.WanderInterval inst.WanderTickCounter = 0 } @@ -269,6 +231,7 @@ func (s *MobStore) SeedMobs(roomID int, mobIDs []string) { InstanceID: instID, DefID: defID, Name: dw.def.Name, + BehaviorID: dw.def.BehaviorID, HP: dw.def.HP, MaxHP: dw.def.HP, Attack: dw.def.Attack, @@ -279,9 +242,8 @@ func (s *MobStore) SeedMobs(roomID int, mobIDs []string) { Protected: dw.def.Protected, Unique: dw.def.Unique, RespawnTicks: dw.def.RespawnTicks, - Wander: dw.def.Wander, - WanderTick: dw.def.WanderTick, - WanderChance: dw.def.WanderChance, + WanderRooms: dw.def.WanderRooms, + WanderInterval: dw.def.WanderInterval, RoomID: roomID, HomeRoomID: roomID, Drops: dw.def.Drops, |
