Example #1
0
File: Tick.cs Project: ktj007/mmo
        internal void OnTick(Entity entity, TickMessage tick)
        {
            // 로그아웃 한 상태에서 Tickable이 남아있는 유저는 Tick을 수행하지 않도록 한다.
            if (entity.Has<Player>() && !entity.Get<Player>().Logged)
            {
                entity.Detach<Tickable>();
                return;
            }

            if (entity.Has<Fightable>())
            {
                var fightable = entity.Get<Fightable>();
                if (fightable.IsAlive)
                {
                    if (++fightable.RecoveryCurrentTick >= fightable.RecoveryTickCount)
                    {
                        var recovery = DataCenter.Instance.GetDatum<InteractTemplate>((int)InteractTemplate.Ids.Recovery);
                        EffectSystem.Affect(entity, recovery);

                        fightable.RecoveryCurrentTick = 0;
                    }
                }
            }

            if (entity.Has<Eatable>())
            {
            }

            if (entity.Has<EntityGenerate>())
            {
                var entityGenerate = entity.Get<EntityGenerate>();
                if (entityGenerate.IsGeneratable)
                {
                    if (entityGenerate.Resource >= entityGenerate.NeededResourceToGen)
                    {
                        // generate!

                        entityGenerate.Resource -= entityGenerate.NeededResourceToGen;
                    }

                    entityGenerate.Resource += entityGenerate.IncResource;
                }
            }

            // 다음 Tick을 요청한다.
            if (entity.Has<Tickable>())
            {
                var nextMsg = new TickMessage {Id = entity.Id};
                nextMsg.ExecuteDelayed(entity, entity.Get<Tickable>().Interval);
            }
        }
        private void AddIfMatch(Entity entity)
        {
            if (!_entities.ContainsKey(entity))
            {
                if (_components.Keys.Any(componentClass => !entity.Has(componentClass)))
                {
                    return;
                }

                var node = _nodePool.Get();
                node.Entity = entity;
                foreach (var componentClass in _components.Keys)
                {
                    node.SetProperty(_components[componentClass], entity.Get(componentClass));
                }
                _entities.Add(entity, node);
                _nodes.Add(node);
            }
        }