public NPCInstance CreateNPC(Fiber fiber, NPCSpawnModel spawn, MapData mapData) { NPCModel npc = m_npcRepository.GetNPCByID(spawn.NPCID); List <INPCBehaviour> behaviours = new List <INPCBehaviour>(); foreach (NPCBehaviourModel behaviourModel in m_npcRepository.GetNPCBehavioursByNPCID(spawn.NPCID).OrderBy(b => b.ExecutionOrder)) { INPCBehaviour behaviour = (INPCBehaviour)Activator.CreateInstance(m_behaviourTypes[behaviourModel.NPCBehaviourID]); IReadOnlyDictionary <string, string> behaviourVars = m_npcRepository.GetNPCBehaviourVarsByNPCBehaviourID(behaviourModel.NPCBehaviourID); behaviour.Initialise(behaviourVars); behaviours.Add(behaviour); } IReadOnlyDictionary <StatType, float> stats = m_npcRepository.GetNPCStatsByNPCID(spawn.NPCID).ToDictionary(kvp => (StatType)kvp.Key, kvp => kvp.Value); NPCInstance npcInstance = new NPCInstance(fiber, npc, spawn, behaviours, stats, mapData); return(npcInstance); }
private static void Main(string[] args) { GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency; ServerConfiguration config = (ServerConfiguration)ConfigurationManager.GetSection("server"); s_log.Info("Creating repositories..."); UnityContainer repositoryResolver = new UnityContainer(); repositoryResolver.LoadConfiguration(); IAccountRepository accountRepository = repositoryResolver.Resolve <IAccountRepository>(); INPCRepository npcRepository = repositoryResolver.Resolve <INPCRepository>(); IPlayerRepository playerRepository = repositoryResolver.Resolve <IPlayerRepository>(); IAbilityRepository abilityRepository = repositoryResolver.Resolve <IAbilityRepository>(); IServerStatsRepository statsRepository = new NullServerStatsRepository(); try { statsRepository = repositoryResolver.Resolve <IServerStatsRepository>(); } catch { s_log.Warn("Failed to create stats repository. Stats will be disabled."); } s_log.Info("Precaching NPCs..."); var npcs = npcRepository.GetNPCs(); s_log.Info("Precaching NPC Spawns..."); npcRepository.GetNPCSpawns(); s_log.Info("Precaching NPC Behaviours..."); var npcBehaviours = npcRepository.GetNPCBehaviours(); foreach (NPCModel npc in npcs) { npcRepository.GetNPCBehavioursByNPCID(npc.NPCID); } s_log.Info("Precaching NPC Behaviour Vars..."); npcRepository.GetNPCBehaviourVars(); foreach (NPCBehaviourModel npcBehaviour in npcBehaviours) { npcRepository.GetNPCBehaviourVarsByNPCBehaviourID(npcBehaviour.NPCBehaviourID); } s_log.Info("Precaching NPC Stats..."); npcRepository.GetNPCStats(); foreach (NPCModel npc in npcs) { npcRepository.GetNPCStatsByNPCID(npc.NPCID); } s_log.Info("Precaching abilities..."); abilityRepository.GetAbilities(); s_log.Info("Initialising serializer..."); ProtocolUtility.InitialiseSerializer(); s_log.Info("Creating world..."); using (World world = new World(accountRepository, npcRepository, playerRepository, statsRepository, abilityRepository)) { TcpListener listener = new TcpListener(IPAddress.Any, config.Port); listener.Start(); s_log.Info("Listening for connections on " + listener.LocalEndpoint.ToString()); while (true) { Socket socket = listener.AcceptSocket(); world.AcceptSocket(socket); } } }