예제 #1
0
        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);
        }
예제 #2
0
        public NPCInstance(Fiber fiber, NPCModel npc, NPCSpawnModel npcSpawn, List <INPCBehaviour> behaviours, IReadOnlyDictionary <StatType, float> stats, MapData mapData)
        {
            NPCModel      = npc;
            NPCSpawnModel = npcSpawn;
            m_stats       = stats;
            m_fiber       = fiber;
            m_mapData     = mapData;

            m_behavioursByType = m_behaviours.ToDictionary(b => b.GetType());

            Position = new Vector2((float)npcSpawn.X, (float)npcSpawn.Y);
            ID       = IDGenerator.GetNextID();

            MaxHealth = Formulas.StaminaToHealth(GetStatValue(StatType.Stamina));
            Health    = MaxHealth;

            MaxPower = Formulas.LevelToPower(Level);
            Power    = MaxPower;

            m_introduction = new EntityIntroduction()
            {
                ID        = ID,
                Level     = (byte)NPCModel.Level,
                MaxHealth = MaxHealth,
                MaxPower  = MaxPower,
                Name      = Name,
                ModelID   = NPCModel.ModelID
            };

            m_stateUpdate = new EntityStateUpdate()
            {
                Rotation = Compression.RotationToByte(npcSpawn.Rotation),
                ID       = ID,
                Health   = Health,
                Power    = 100,
            };

            m_behaviours = behaviours;
        }