Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        bool RandomPosition(ref Vector2FP random_position)
        {
            //ZZWTODO 随机分布,分成grid,随机选一个然后标志占用
            RandomGeneratorFP random_generator_fp = GetLogicWorld().GetRandomGeneratorFP();

            for (int i = 0; i < 50; ++i)
            {
                random_position.x = random_generator_fp.RandBetween(m_min_x, m_max_x);
                random_position.z = random_generator_fp.RandBetween(m_min_z, m_max_z);
                bool overlap    = false;
                var  enumerator = m_current_objects.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.Value.FastDistance(ref random_position) < m_object_distance)
                    {
                        overlap = true;
                        break;
                    }
                }
                if (!overlap)
                {
                    return(true);
                }
            }
            return(false);
        }
        public List <PositionComponent> CollectEntity_ForwardSector(Vector3FP position, Vector2FP facing, FixPoint radius, FixPoint degree, int exclude_id)
        {
            FixPoint cos = FixPoint.Cos(FixPoint.Degree2Radian(degree >> 1));

            m_collection.Clear();
            Vector2FP         source = new Vector2FP(position.x, position.z);
            Vector2FP         target = new Vector2FP();
            PositionComponent cmp;

            for (int i = 0; i < m_entities.Count; ++i)
            {
                cmp = m_entities[i];
                if (cmp.GetOwnerEntityID() == exclude_id)
                {
                    continue;
                }
                target.x = cmp.CurrentPosition.x;
                target.z = cmp.CurrentPosition.z;
                Vector2FP to_target = target - source;
                FixPoint  distance  = to_target.FastNormalize();
                if (distance > radius + cmp.Radius)
                {
                    continue;
                }
                if (to_target.Dot(ref facing) < cos)
                {
                    continue;
                }
                m_collection.Add(cmp);
            }
            return(m_collection);
        }
 public void Construct(IRegionCallback callback, ISpacePartition partition, Vector3FP fixed_position, Vector2FP fixed_facing)
 {
     m_callback       = callback;
     m_binding_object = null;
     m_partition      = partition;
     m_fixed_position = fixed_position;
     m_fixed_facing   = fixed_facing;
 }
Ejemplo n.º 5
0
 void ComputeAreaXZ(Vector2FP pos1, Vector2FP pos2)
 {
     pos1.x -= m_left_bottom_position.x;
     pos1.z -= m_left_bottom_position.z;
     pos2.x -= m_left_bottom_position.x;
     pos2.z -= m_left_bottom_position.z;
     if (pos1.x < pos2.x)
     {
         pos1.x -= MAX_ENTITY_RADIUS;
         pos2.x += MAX_ENTITY_RADIUS;
         m_min_x = (int)(pos1.x / CELL_SIZE);
         m_max_x = (int)(pos2.x / CELL_SIZE);
     }
     else
     {
         pos2.x -= MAX_ENTITY_RADIUS;
         pos1.x += MAX_ENTITY_RADIUS;
         m_min_x = (int)(pos2.x / CELL_SIZE);
         m_max_x = (int)(pos1.x / CELL_SIZE);
     }
     if (pos1.z < pos2.z)
     {
         pos1.z -= MAX_ENTITY_RADIUS;
         pos2.z += MAX_ENTITY_RADIUS;
         m_min_z = (int)(pos1.z / CELL_SIZE);
         m_max_z = (int)(pos2.z / CELL_SIZE);
     }
     else
     {
         pos2.z -= MAX_ENTITY_RADIUS;
         pos1.z += MAX_ENTITY_RADIUS;
         m_min_z = (int)(pos2.z / CELL_SIZE);
         m_max_z = (int)(pos1.z / CELL_SIZE);
     }
     if (m_min_x < 0)
     {
         m_min_x = 0;
     }
     if (m_max_x > MAX_X_INDEX)
     {
         m_max_x = MAX_X_INDEX;
     }
     if (m_min_z < 0)
     {
         m_min_z = 0;
     }
     if (m_max_z > MAX_Z_INDEX)
     {
         m_max_z = MAX_Z_INDEX;
     }
 }
Ejemplo n.º 6
0
        public List <PositionComponent> CollectEntity_ForwardRectangle(Vector3FP position, Vector2FP direction, FixPoint length, FixPoint width, int exclude_id)
        {
            m_collection.Clear();
            Vector2FP start_position = new Vector2FP(position);
            Vector2FP end_position   = start_position + direction * length;

            ComputeAreaXZ(start_position, end_position);
            Vector2FP side = direction.Perpendicular();

            width = width >> 1;
            Cell cell;
            PositionComponent cmp;
            Vector2FP         offset;

            for (int x = m_min_x; x <= m_max_x; ++x)
            {
                for (int z = m_min_z; z <= m_max_z; ++z)
                {
                    cell = m_cells[x, z];
                    for (int i = 0; i < cell.m_entities.Count; ++i)
                    {
                        cmp = cell.m_entities[i];
                        if (cmp.GetOwnerEntityID() == exclude_id)
                        {
                            continue;
                        }
                        offset.x = cmp.CurrentPosition.x - position.x;
                        offset.z = cmp.CurrentPosition.z - position.z;
                        FixPoint component = offset.Dot(ref direction);
                        FixPoint radius    = cmp.Radius;
                        if (component < -radius || component > length + radius)
                        {
                            continue;
                        }
                        component = offset.Dot(ref side);
                        if (component < FixPoint.Zero)
                        {
                            component = -component;
                        }
                        if (component > width + radius)
                        {
                            continue;
                        }
                        m_collection.Add(cmp);
                    }
                }
            }
            return(m_collection);
        }
Ejemplo n.º 7
0
        public List <PositionComponent> CollectEntity_ForwardSector(Vector3FP position, Vector2FP facing, FixPoint radius, FixPoint degree, int exclude_id)
        {
            FixPoint cos = FixPoint.Cos(FixPoint.Degree2Radian(degree >> 1));

            m_collection.Clear();
            Vector2FP start_position = new Vector2FP(position.x - radius, position.z - radius);
            Vector2FP end_position   = new Vector2FP(position.x + radius, position.z + radius);

            ComputeAreaXZ(start_position, end_position);
            Cell              cell;
            Vector2FP         source = new Vector2FP(position.x, position.z);
            Vector2FP         target = new Vector2FP();
            PositionComponent cmp;

            for (int x = m_min_x; x <= m_max_x; ++x)
            {
                for (int z = m_min_z; z <= m_max_z; ++z)
                {
                    cell = m_cells[x, z];
                    for (int i = 0; i < cell.m_entities.Count; ++i)
                    {
                        cmp = cell.m_entities[i];
                        if (cmp.GetOwnerEntityID() == exclude_id)
                        {
                            continue;
                        }
                        target.x = cmp.CurrentPosition.x;
                        target.z = cmp.CurrentPosition.z;
                        Vector2FP to_target = target - source;
                        FixPoint  distance  = to_target.FastNormalize();
                        if (distance > radius + cmp.Radius)
                        {
                            continue;
                        }
                        if (to_target.Dot(ref facing) < cos)
                        {
                            continue;
                        }
                        m_collection.Add(cmp);
                    }
                }
            }
            return(m_collection);
        }
Ejemplo n.º 8
0
        public List <PositionComponent> CollectEntity_SurroundingRing(Vector3FP position, FixPoint outer_radius, FixPoint inner_radius, int exclude_id)
        {
            m_collection.Clear();
            Vector2FP start_position = new Vector2FP(position.x - outer_radius, position.z - outer_radius);
            Vector2FP end_position   = new Vector2FP(position.x + outer_radius, position.z + outer_radius);

            ComputeAreaXZ(start_position, end_position);
            Cell cell;
            PositionComponent cmp;

            for (int x = m_min_x; x <= m_max_x; ++x)
            {
                for (int z = m_min_z; z <= m_max_z; ++z)
                {
                    cell = m_cells[x, z];
                    for (int i = 0; i < cell.m_entities.Count; ++i)
                    {
                        cmp = cell.m_entities[i];
                        if (cmp.GetOwnerEntityID() == exclude_id)
                        {
                            continue;
                        }
                        Vector3FP offset   = position - cmp.CurrentPosition;
                        FixPoint  distance = FixPoint.FastDistance(offset.x, offset.z);
                        if (distance >= (outer_radius + cmp.Radius))
                        {
                            continue;
                        }
                        if (inner_radius > FixPoint.Zero && distance <= (inner_radius - cmp.Radius))
                        {
                            continue;
                        }
                        m_collection.Add(cmp);
                    }
                }
            }
            return(m_collection);
        }
        public List <PositionComponent> CollectEntity_ForwardRectangle(Vector3FP position, Vector2FP direction, FixPoint length, FixPoint width, int exclude_id)
        {
            m_collection.Clear();
            Vector2FP side = direction.Perpendicular();

            width = width >> 1;
            PositionComponent cmp;
            Vector2FP         offset;

            for (int i = 0; i < m_entities.Count; ++i)
            {
                cmp = m_entities[i];
                if (cmp.GetOwnerEntityID() == exclude_id)
                {
                    continue;
                }
                offset.x = cmp.CurrentPosition.x - position.x;
                offset.z = cmp.CurrentPosition.z - position.z;
                FixPoint component = offset.Dot(ref direction);
                FixPoint radius    = cmp.Radius;
                if (component < -radius || component > length + radius)
                {
                    continue;
                }
                component = offset.Dot(ref side);
                if (component < FixPoint.Zero)
                {
                    component = -component;
                }
                if (component > width + radius)
                {
                    continue;
                }
                m_collection.Add(cmp);
            }
            return(m_collection);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
 public Vector3FP(Vector2FP v2)
 {
     x = v2.x;
     y = FixPoint.Zero;
     z = v2.z;
 }
Ejemplo n.º 12
0
        void GatherGeneral(ISpacePartition partition, Player player, Vector3FP position, Vector2FP facing, TargetGatheringParam param, List <Entity> targets)
        {
            if (partition == null)
            {
                return;
            }

            List <PositionComponent> list = null;
            int gathering_type            = param.m_type;

            if (gathering_type == TargetGatheringType.ForwardRectangle)
            {
                list = partition.CollectEntity_ForwardRectangle(position, facing, param.m_param1, param.m_param2);
            }
            else if (gathering_type == TargetGatheringType.SurroundingRing)
            {
                list = partition.CollectEntity_SurroundingRing(position, param.m_param1, param.m_param2);
            }
            else if (gathering_type == TargetGatheringType.ForwardSector)
            {
                list = partition.CollectEntity_ForwardSector(position, facing, param.m_param1, param.m_param2);
            }
            else if (gathering_type == TargetGatheringType.All)
            {
                list = partition.CollectEntity_All();
            }
            if (list == null)
            {
                return;
            }

            for (int i = 0; i < list.Count; ++i)
            {
                PositionComponent position_component = list[i];
                Entity            entity             = position_component.GetOwnerEntity();
                if (param.m_category != 0)
                {
                    EntityDefinitionComponent definition_component = entity.GetComponent(EntityDefinitionComponent.ID) as EntityDefinitionComponent;
                    if (definition_component == null)
                    {
                        continue;
                    }
                    if (!definition_component.IsCategory(param.m_category))
                    {
                        continue;
                    }
                }
                if (player != null && !FactionRelation.IsFactionSatisfied(player.GetFaction(entity.GetOwnerPlayerID()), param.m_faction))
                {
                    continue;
                }
                targets.Add(entity);
            }
        }
Ejemplo n.º 13
0
 public void BuildTargetList(ISpacePartition partition, Player player, Vector3FP position, Vector2FP facing, TargetGatheringParam param, List <int> targets)
 {
     m_temp_targets.Clear();
     GatherGeneral(partition, player, position, facing, param, m_temp_targets);
     for (int i = 0; i < m_temp_targets.Count; ++i)
     {
         targets.Add(m_temp_targets[i].ID);
     }
     m_temp_targets.Clear();
 }
Ejemplo n.º 14
0
 public void BuildTargetList(ISpacePartition partition, Player player, Vector3FP position, Vector2FP facing, TargetGatheringParam param, List <Target> targets)
 {
     m_temp_targets.Clear();
     GatherGeneral(partition, player, position, facing, param, m_temp_targets);
     for (int i = 0; i < m_temp_targets.Count; ++i)
     {
         Target target = RecyclableObject.Create <Target>();
         target.Construct();
         target.SetEntityTarget(m_temp_targets[i]);
         targets.Add(target);
     }
     m_temp_targets.Clear();
 }