func specificSpawnerMenu(s *Session, spawner types.Spawner) { utils.ExecMenu(fmt.Sprintf("%s - %s", "Spawner", spawner.GetName()), s, func(menu *utils.Menu) { menu.AddAction("r", "Rename", func() bool { newName := s.getRawUserInput("New name: ") if newName != "" { spawner.SetName(newName) } return true }) menu.AddAction("c", fmt.Sprintf("Count - %v", spawner.GetCount()), func() bool { count, valid := s.getInt("New count: ", 0, 1000) if valid { spawner.SetCount(count) } return true }) menu.AddAction("h", fmt.Sprintf("Health - %v", spawner.GetHealth()), func() bool { health, valid := s.getInt("New hitpoint count: ", 0, 1000) if valid { spawner.SetHealth(health) } return true }) }) }
func manageSpawner(spawner types.Spawner) { throttler := utils.NewThrottler(5 * time.Second) go func() { for { rooms := model.GetAreaRooms(spawner.GetAreaId()) if len(rooms) > 0 { npcs := model.GetSpawnerNpcs(spawner.GetId()) diff := spawner.GetCount() - len(npcs) for diff > 0 && len(rooms) > 0 { room := rooms[utils.Random(0, len(rooms)-1)] npc := model.CreateNpc(spawner.GetName(), room.GetId(), spawner.GetId()) npc.SetHealth(spawner.GetHealth()) manageNpc(npc) diff-- } } throttler.Sync() } }() }