示例#1
0
        internal void OnInteract(Entity entity, MessageSession session, InteractMsg msg)
        {
            if (entity.Has <Fightable>())
            {
                var template = DataCenter.Instance.GetDatum <InteractTemplate>(msg.InteractId);
                if (template == null)
                {
                    Logger.Write("Request a invalid interact[{0}]", msg.InteractId);
                    return;
                }

                EffectSystem.Affect(entity, template);
            }
            else
            {
                PositionSystem.Global.Interact(entity, targets =>
                {
                    // default interaction - remove removables
                    foreach (var target in targets.Where(target => target.Has <Removable>() && target.Get <Removable>().Action))
                    {
                        // despawn target
                        PositionSystem.Global.Disappear(target);
                        EntityBinder.Instance.Remove(target);
                        EntityManager.Instance.Remove(target.Id);
                    }
                });
            }
        }
示例#2
0
文件: Tick.cs 项目: 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);
            }
        }