Exemplo n.º 1
0
        public static void KillEntity(Entity entity, int killer_id)
        {
            DeathComponent death_component = entity.GetComponent(DeathComponent.ID) as DeathComponent;

            if (death_component != null)
            {
                death_component.KillOwner(killer_id);
            }
            else
            {
                //Player player = entity.GetOwnerPlayer();
                //Entity killer = entity.GetLogicWorld().GetEntityManager().GetObject(killer_id);
                //player.OnEntityBeKilled(killer, entity);
                //if (killer != null)
                //{
                //    Player killer_player = killer.GetOwnerPlayer();
                //    killer_player.OnKillEntity(killer, entity);
                //}

                //没有死亡组件的就从简了
                entity.SendSignal(SignalType.Die);
                entity.GetLogicWorld().AddSimpleRenderMessage(RenderMessageType.Die, entity.ID);
                entity.DeletePending = true;
                var schedeler = entity.GetLogicWorld().GetTaskScheduler();
                DeleteEntityTask delete_task = LogicTask.Create <DeleteEntityTask>();
                delete_task.Construct(entity.ID);
                schedeler.Schedule(delete_task, entity.GetCurrentTime(), ms_death_delay);
            }
        }
Exemplo n.º 2
0
        public void KillOwner(int killer_id)
        {
            //ZZWTODO Resurrect

            if (m_die_task != null)
            {
                m_die_task.Cancel();
            }
            LogicWorld logic_world = GetLogicWorld();

            Entity killer = logic_world.GetEntityManager().GetObject(killer_id);

            if (!DieSilently && killer_id != ParentObject.ID && m_killer_generator != null && killer != null)
            {
                EffectApplicationData app_data = RecyclableObject.Create <EffectApplicationData>();
                app_data.m_original_entity_id = ParentObject.ID;
                app_data.m_source_entity_id   = ParentObject.ID;
                m_killer_generator.Activate(app_data, killer);
                RecyclableObject.Recycle(app_data);
            }

            var schedeler = logic_world.GetTaskScheduler();

            if (DieSilently)
            {
                logic_world.AddSimpleRenderMessage(RenderMessageType.Hide, ParentObject.ID);
            }
            else
            {
                HideEntityTask hide_task = LogicTask.Create <HideEntityTask>();
                hide_task.Construct(ParentObject.ID);
                schedeler.Schedule(hide_task, GetCurrentTime(), m_hide_delay);
            }

            ParentObject.DeletePending = true;
            ParentObject.SendSignal(SignalType.Die);
            logic_world.AddSimpleRenderMessage(RenderMessageType.Die, ParentObject.ID);

            StateComponent state_component = ParentObject.GetComponent(StateComponent.ID) as StateComponent;

            if (state_component != null)
            {
                state_component.AddState(StateSystem.DEAD_STATE, 0);
            }

            if (!m_can_resurrect)
            {
                DeleteEntityTask delete_task = LogicTask.Create <DeleteEntityTask>();
                delete_task.Construct(ParentObject.ID);
                schedeler.Schedule(delete_task, GetCurrentTime(), m_delete_delay);
            }

            logic_world.OnKillEntity(killer, GetOwnerEntity());
        }