예제 #1
0
        private void BuildAndSendWorldStateUpdate()
        {
            m_worldState.CurrentServerTime = Environment.TickCount;
            m_worldState.Health            = Health;
            m_worldState.Power             = Power;

            List <EntityStateUpdate> entityStates = new List <EntityStateUpdate>();

            m_worldState.EntityIntroductions = null;

            BoundingBox    range        = new BoundingBox(Position - RELEVANCE_RANGE, Position + RELEVANCE_RANGE);
            List <IEntity> nearEntities = CurrentZone.GatherEntitiesInRange(range);

            for (int i = 0; i < nearEntities.Count; i++)
            {
                IEntity           entity = nearEntities[i];
                EntityStateUpdate esu    = entity.GetStateUpdate();
                if (entity.ID != ID && esu != null && !entity.IsDead)
                {
                    entityStates.Add(entity.GetStateUpdate());

                    EntityIntroduction introduction = entity.GetIntroduction();
                    if (!m_introducedEntities.ContainsKey(esu.ID) || m_introducedEntities[esu.ID] != introduction)
                    {
                        if (m_worldState.EntityIntroductions == null)
                        {
                            m_worldState.EntityIntroductions = new List <EntityIntroduction>();
                        }

                        m_worldState.EntityIntroductions.Add(introduction);
                        m_introducedEntities[esu.ID] = introduction;
                    }
                }
            }

            m_worldState.EntityStates = entityStates;
            m_nearEntities            = nearEntities;

            Send(m_worldState);
        }
예제 #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;
        }
예제 #3
0
        private void Update()
        {
            if (IsAuthenticated)
            {
                m_latestStateUpdate = new EntityStateUpdate()
                {
                    ID            = ID,
                    Health        = (ushort)Health,
                    Power         = (ushort)Power,
                    Rotation      = Rotation,
                    TargetID      = TargetID,
                    Timestamp     = TimeOnClient,
                    VelX          = m_compressedVelX,
                    VelY          = m_compressedVelY,
                    X             = m_compressedX,
                    Y             = m_compressedY,
                    CastingEffect = m_lastAbility.State == AbilityState.Casting ? (ushort)m_lastAbility.Ability.AbilityID : (ushort)0
                };

                if (CurrentZone != null)
                {
                    BuildAndSendWorldStateUpdate();
                }
                if (Environment.TickCount - m_lastSaveTime > SAVE_INTERVAL_MS)
                {
                    Save(SaveFlags.General);
                }
            }

            if (Environment.TickCount - m_lastActivity > PING_TIMEOUT)
            {
                Send(new Ping());
                m_lastActivity = Environment.TickCount;
            }

            Fiber.Schedule(Update, TimeSpan.FromMilliseconds(TARGET_UPDATE_TIME_MS));
        }