Esempio n. 1
0
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()
		}
	}()
}