Exemple #1
0
        bool HandleEntityMove(EntityMoveCommand cmd)
        {
            Entity entity = m_logic_world.GetEntityManager().GetObject(cmd.m_entity_id);

            if (entity == null)
            {
                return(false);
            }
            LocomotorComponent locomotor_component = entity.GetComponent(LocomotorComponent.ID) as LocomotorComponent;

            if (locomotor_component == null)
            {
                return(false);
            }
            if (cmd.m_move_type != EntityMoveCommand.StopMoving)
            {
                TargetingComponent targeting_component = entity.GetComponent(TargetingComponent.ID) as TargetingComponent;
                if (targeting_component != null)
                {
                    targeting_component.StopTargeting();
                }
            }
            if (cmd.m_move_type == EntityMoveCommand.DestinationType)
            {
                PathFindingComponent pathfinding_component = entity.GetComponent(PathFindingComponent.ID) as PathFindingComponent;
                if (pathfinding_component != null)
                {
                    return(pathfinding_component.FindPath(cmd.m_vector));
                }
                else
                {
                    PositionComponent position_component = entity.GetComponent(PositionComponent.ID) as PositionComponent;
                    List <Vector3FP>  path = new List <Vector3FP>();
                    path.Add(position_component.CurrentPosition);
                    path.Add(cmd.m_vector);
                    locomotor_component.MoveAlongPath(path, true);
                }
            }
            else if (cmd.m_move_type == EntityMoveCommand.DirectionType)
            {
                locomotor_component.MoveByDirection(cmd.m_vector);
            }
            else if (cmd.m_move_type == EntityMoveCommand.StopMoving)
            {
                locomotor_component.StopMoving(true);
            }
            return(true);
        }
Exemple #2
0
        void SpawnOneObject()
        {
            Vector2FP random_position = new Vector2FP();

            if (!RandomPosition(ref random_position))
            {
                return;
            }

            Player            player         = GetOwnerPlayer();
            LogicWorld        logic_world    = GetLogicWorld();
            EntityManager     entity_manager = logic_world.GetEntityManager();
            IConfigProvider   config         = logic_world.GetConfigProvider();
            BirthPositionInfo birth_info     = new BirthPositionInfo(random_position.x, new FixPoint(0), random_position.z, new FixPoint(90));

            ObjectCreationContext object_context = new ObjectCreationContext();

            object_context.m_object_proxy_id = player.ProxyID;
            object_context.m_object_type_id  = m_object_type_id;
            object_context.m_object_proto_id = m_object_proto_id;
            object_context.m_birth_info      = birth_info;
            object_context.m_type_data       = config.GetObjectTypeData(object_context.m_object_type_id);
            object_context.m_proto_data      = config.GetObjectProtoData(object_context.m_object_proto_id);
            object_context.m_logic_world     = logic_world;
            object_context.m_owner_id        = ParentObject.ID;
            object_context.m_is_ai           = true;
            object_context.m_is_local        = player.IsLocal;
            Entity obj = entity_manager.CreateObject(object_context);

            m_current_objects[obj.ID] = random_position;
            obj.AddListener(SignalType.Die, m_listener_context);
        }
Exemple #3
0
        public void Deactivate()
        {
            if (m_effect2entity.Count == 0)
            {
                return;
            }

            LogicWorld    logic_world    = m_generator.GetLogicWorld();
            EntityManager entity_manager = logic_world.GetEntityManager();

            SortedDictionary <int, int> temp = m_effect2entity;

            m_effect2entity = null;
            var enumerator = temp.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Entity         entity   = entity_manager.GetObject(enumerator.Current.Value);
                EffectRegistry registry = EntityUtil.GetEffectRegistry(entity);
                if (registry != null)
                {
                    registry.RemoveEffect(enumerator.Current.Key);
                }
            }

            temp.Clear();
            m_effect2entity = temp;
        }
        void ProcessRenderMessage_CreateEntity(int entity_id)
        {
            Entity entity = m_logic_world.GetEntityManager().GetObject(entity_id);

            if (entity == null)
            {
                return;
            }
            m_render_entity_manager.CreateObject(entity.GetCreationContext());
        }
Exemple #5
0
 public Entity GetEntity(LogicWorld logic_world)
 {
     if (m_target_type == TargetType.EntityType)
     {
         return(logic_world.GetEntityManager().GetObject(m_object_id));
     }
     else
     {
         return(null);
     }
 }
        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());
        }
Exemple #7
0
 public Vector3FP GetPosition(LogicWorld logic_world)
 {
     if (m_target_type == TargetType.EntityType)
     {
         Entity entity = logic_world.GetEntityManager().GetObject(m_object_id);
         if (entity == null)
         {
             return(new Vector3FP(FixPoint.Zero, FixPoint.Zero, FixPoint.Zero));
         }
         else
         {
             return((entity.GetComponent(PositionComponent.ID) as PositionComponent).CurrentPosition);
         }
     }
     else
     {
         return(m_position);
     }
 }
Exemple #8
0
        void GatherTargetsAndActivate(EffectApplicationData app_data)
        {
            LogicWorld logic_world   = m_generator.GetLogicWorld();
            Entity     source_entity = logic_world.GetEntityManager().GetObject(app_data.m_source_entity_id);

            if (source_entity == null)
            {
                return;
            }
            if (m_targets == null)
            {
                m_targets = new List <Target>();
            }
            m_generator.GetLogicWorld().GetTargetGatheringManager().BuildTargetList(source_entity, m_data.m_target_gathering_param, m_targets);
            for (int i = 0; i < m_targets.Count; ++i)
            {
                Entity entity = m_targets[i].GetEntity(logic_world);
                if (entity != null)
                {
                    ActivateOnOneTatget(app_data, entity);
                }
            }
            ClearTargets();
        }
Exemple #9
0
        public static Entity CreateEntityForSkillAndEffect(Component caller_component, Entity owner_entity, Target projectile_target, Vector3FP position_offset, FixPoint angle_offset, int object_type_id, int object_proto_id, FixPoint object_life_time, EffectGenerator attached_generator)
        {
            LogicWorld      logic_world = owner_entity.GetLogicWorld();
            IConfigProvider config      = logic_world.GetConfigProvider();
            ObjectTypeData  type_data   = config.GetObjectTypeData(object_type_id);

            if (type_data == null)
            {
                return(null);
            }

            PositionComponent owner_position_cmp = owner_entity.GetComponent(PositionComponent.ID) as PositionComponent;
            Vector3FP         source_pos         = owner_position_cmp.CurrentPosition;

            Vector2FP xz_facing;
            FixPoint  angle;
            Vector3FP facing;

            if (projectile_target == null)
            {
                xz_facing = owner_position_cmp.Facing2D;
                angle     = owner_position_cmp.FacingAngle;
                facing.x  = xz_facing.x;
                facing.y  = FixPoint.Zero;
                facing.z  = xz_facing.z;
            }
            else
            {
                Vector3FP target_pos = projectile_target.GetPosition(logic_world);
                xz_facing.x = target_pos.x - source_pos.x;
                xz_facing.z = target_pos.z - source_pos.z;
                xz_facing.Normalize();
                angle  = xz_facing.ToDegree();
                facing = target_pos - source_pos;
                facing.Normalize();
            }
            Vector2FP side      = xz_facing.Perpendicular();
            Vector2FP xz_offset = xz_facing * position_offset.z + side * position_offset.x;

            if (angle_offset != FixPoint.Zero)
            {
                angle += angle_offset;
                FixPoint radian = FixPoint.Degree2Radian(-angle);
                facing.x = FixPoint.Cos(radian);
                facing.z = FixPoint.Sin(radian);
            }

            Vector3FP         birth_position = new Vector3FP(source_pos.x + xz_offset.x, source_pos.y + position_offset.y, source_pos.z + xz_offset.z);
            BirthPositionInfo birth_info     = new BirthPositionInfo(birth_position.x, birth_position.y, birth_position.z, angle, owner_position_cmp.GetCurrentSceneSpace());

            ProjectileComponent owner_entity_projectile_component = owner_entity.GetComponent(ProjectileComponent.ID) as ProjectileComponent;

            if (owner_entity_projectile_component != null)
            {
                Entity original_owner = logic_world.GetEntityManager().GetObject(owner_entity_projectile_component.SourceEntityID);
                if (original_owner != null)
                {
                    owner_entity = original_owner;
                }
            }

            Player owner_player = owner_entity.GetOwnerPlayer();
            ObjectCreationContext object_context = new ObjectCreationContext();

            object_context.m_object_proxy_id = owner_player.ProxyID;
            object_context.m_object_type_id  = object_type_id;
            object_context.m_object_proto_id = object_proto_id;
            object_context.m_birth_info      = birth_info;
            object_context.m_type_data       = type_data;
            object_context.m_proto_data      = config.GetObjectProtoData(object_proto_id);
            object_context.m_logic_world     = logic_world;
            object_context.m_owner_id        = owner_player.ID;
            object_context.m_is_ai           = true;
            object_context.m_is_local        = owner_player.IsLocal;

            Entity created_entity = logic_world.GetEntityManager().CreateObject(object_context);

            DeathComponent death_component = created_entity.GetComponent(DeathComponent.ID) as DeathComponent;

            if (death_component != null && object_life_time > FixPoint.Zero)
            {
                death_component.SetLifeTime(object_life_time);
            }

            SummonedEntityComponent summoned_component = created_entity.GetComponent(SummonedEntityComponent.ID) as SummonedEntityComponent;

            if (summoned_component != null)
            {
                summoned_component.SetMaster(owner_entity);
            }

            ProjectileComponent projectile_component = created_entity.GetComponent(ProjectileComponent.ID) as ProjectileComponent;

            if (projectile_component != null)
            {
                ProjectileParameters param = RecyclableObject.Create <ProjectileParameters>();
                param.m_start_time       = logic_world.GetCurrentTime();
                param.m_life_time        = object_life_time;
                param.m_source_entity_id = owner_entity.ID;
                param.m_start_position   = birth_position;
                param.m_fixed_facing     = facing;
                if (projectile_target != null)
                {
                    param.m_target_entity_id = projectile_target.GetEntityID();
                    param.m_target_position  = projectile_target.GetPosition(logic_world);
                }
                else
                {
                    Skill          owner_skill     = null;
                    SkillComponent skill_componnet = caller_component as SkillComponent;
                    if (skill_componnet != null)
                    {
                        owner_skill = skill_componnet.GetOwnerSkill();
                    }
                    if (owner_skill != null && owner_skill.GetDefinitionComponent().ExternalDataType == SkillDefinitionComponent.NeedExternalTarget)
                    {
                        param.m_target_entity_id = 0;
                        FixPoint range = owner_skill.GetDefinitionComponent().MaxRange;
                        if (range <= 0)
                        {
                            range = FixPoint.Ten;  //ZZWTODO
                        }
                        if (projectile_component.Speed > FixPoint.Zero)
                        {
                            param.m_life_time = range / projectile_component.Speed;
                        }
                        param.m_target_position = param.m_start_position + param.m_fixed_facing * range;
                    }
                }
                param.m_generator_id = attached_generator == null ? 0 : attached_generator.ID;
                projectile_component.InitParam(param);
            }
            else if (attached_generator != null)
            {
                EffectApplicationData app_data = RecyclableObject.Create <EffectApplicationData>();
                app_data.m_original_entity_id = owner_entity.ID;
                app_data.m_source_entity_id   = owner_entity.ID;
                attached_generator.Activate(app_data, created_entity);
                RecyclableObject.Recycle(app_data);
            }
            return(created_entity);
        }
Exemple #10
0
 public TargetGatheringManager(LogicWorld logic_world)
 {
     m_logic_world    = logic_world;
     m_entity_manager = m_logic_world.GetEntityManager();
 }
Exemple #11
0
        public ISignalListener GetListener(LogicWorld logic_world)
        {
            switch (m_context_type)
            {
            case SignalListenerContextType.PlayerComponent:
            {
                Player player = logic_world.GetPlayerManager().GetObject(m_object_id);
                if (player == null)
                {
                    return(null);
                }
                Component component = player.GetComponent(m_component_type_id);
                if (component == null)
                {
                    return(null);
                }
                return(component as ISignalListener);
            }

            case SignalListenerContextType.EntityComponent:
            {
                Entity entity = logic_world.GetEntityManager().GetObject(m_object_id);
                if (entity == null)
                {
                    return(null);
                }
                Component component = entity.GetComponent(m_component_type_id);
                if (component == null)
                {
                    return(null);
                }
                return(component as ISignalListener);
            }

            case SignalListenerContextType.EffectComponent:
            {
                Effect effect = logic_world.GetEffectManager().GetObject(m_object_id);
                if (effect == null)
                {
                    return(null);
                }
                Component component = effect.GetComponent(m_component_type_id);
                if (component == null)
                {
                    return(null);
                }
                return(component as ISignalListener);
            }

            case SignalListenerContextType.BehaviorTree:
            {
                BehaviorTree tree = logic_world.GetBehaviorTree(m_object_id);
                if (tree == null)
                {
                    return(null);
                }
                return(tree);
            }

            default:
                return(null);
            }
        }