Пример #1
0
        public BLIntVector3 GetRandomPosition(BLIntVector3 born_point)
        {
            int offset_x = Random.Range(1, 1);
            int offset_y = Random.Range(-1, 1);

            return(new BLIntVector3(born_point.x + offset_x * 1000, born_point.y, born_point.z + offset_y * 1000));
        }
Пример #2
0
    public BL.BLIntVector3 Grid2BLPosition(int grid_x, int grid_y)
    {
        int half_step = (int)(map_data.map_step * 500);

        BL.BLIntVector3 world_positin = new BL.BLIntVector3(grid_x * (int)map_data.map_step * 1000 + half_step, 0, grid_y * (int)map_data.map_step * 1000 + half_step);

        return(world_positin);
    }
Пример #3
0
        // 做线性差值,total 是总共分成多少段,offset是距离起始点偏移了多少段
        public static BLIntVector3 Lerp(BLIntVector3 a, BLIntVector3 b, int offset, int total)
        {
            BLIntVector3 result = a;

            result.x += (b.x - a.x) * offset / total;
            result.y += (b.y - a.y) * offset / total;
            result.z += (b.z - a.z) * offset / total;

            return(result);
        }
Пример #4
0
        public void InitBase()
        {
            BLIntVector3 born_point1 = BattleField.battle_field.born_point[1];
            BLIntVector3 born_point2 = BattleField.battle_field.born_point[2];

//			BLUnitHero hero1 = CreateHeroUnit("rocket_car", GetRandomPosition(born_point1), 0);
//			BLUnitHero hero2 = CreateHeroUnit("rocket_car", GetRandomPosition(born_point2), 1);

            CreateBuildingUnit(GetBaseID(1), "base", born_point1, 1);
            CreateBuildingUnit(GetBaseID(2), "base", born_point2, 2);
        }
Пример #5
0
        public BLUnitHero CreateHeroUnit(int unit_id, string gds_name, BLIntVector3 pos, int team_id)
        {
            GDSKit.unit unit_gds = GDSKit.unit.GetInstance(gds_name);

            BLUnitHero hero_unit = new BLUnitHero();

            // 属性相关设置
            hero_unit.gds_name         = gds_name;
            hero_unit.unit_type        = UnitType.Hero;
            hero_unit.unit_id          = unit_id;
            hero_unit.revive_cool_down = unit_gds.revive_cd;
            hero_unit.move_speed       = unit_gds.move_speed;
            hero_unit.attack_range     = unit_gds.attack_range;
            hero_unit.vision           = unit_gds.attack_vision;
            hero_unit.attack_speed     = unit_gds.attack_speed;
            hero_unit.attack_power     = unit_gds.unit_attack;
            hero_unit.hp     = unit_gds.unit_hp;
            hero_unit.max_hp = unit_gds.unit_hp;

            hero_unit.is_move_attack    = unit_gds.is_move_attack;
            hero_unit.is_fly            = unit_gds.is_fly;
            hero_unit.can_attack_fly    = unit_gds.can_attack_fly;
            hero_unit.can_attack_ground = unit_gds.can_attack_ground;
            hero_unit.can_pursue        = unit_gds.can_pursue;
            hero_unit.aoe_radius        = unit_gds.aoe_radius;
            hero_unit.bullet_speed      = unit_gds.bullet_speed;

            hero_unit.position = pos;
            hero_unit.team_id  = team_id;

            if (all_unit_list.ContainsKey(hero_unit.unit_id))
            {
                Debug.LogError("相同名字的unit已经在管理器里了 id : " + hero_unit.unit_id);
                return(null);
            }

            all_unit_list.Add(hero_unit.unit_id, hero_unit);
            hero_unit_list.Add(hero_unit.unit_id, hero_unit);

            hero_unit.OnInit();

            // 表现层
            HeroUnit unit_renderer = UnitManager.Instance().CreateHeroUnit(hero_unit.gds_name, hero_unit.unit_id, hero_unit.position.Vector3Value());

            // 表现层需要显示迷雾,攻击范围,所以需要这些数据
            unit_renderer.attack_vision = hero_unit.vision * 0.001f;
            unit_renderer.team_id       = hero_unit.team_id;
            unit_renderer.attack_range  = (hero_unit.attack_range * 0.001f);

            unit_renderer.OnInit();

            return(hero_unit);
        }
Пример #6
0
        // 距离要可以打到,并且攻击类型符合
        public bool IsCanAttack(BLUnitBase enemy_unit)
        {
            if (!IsCanAttackByAttackType(enemy_unit))
            {
                return(false);
            }

            BLIntVector3 distance = (enemy_unit.position - position);

            float distance_square = distance.SqrMagnitude();

            return(attack_range_sqr_ >= distance_square);
        }
Пример #7
0
        public void Start(BLIntVector3 start_pos, BLIntVector3 end_pos, HitEndCallback call_back)
        {
            start_postion = start_pos;
            end_position  = end_pos;

            remain_frames = (int)((end_position - start_postion).Magnitude() / bullet_speed / BLTimelineController.MS_PER_FRAME);
            end_call_back = call_back;
            total_frames  = remain_frames;

            pre_position = start_pos;
            now_position = start_pos;

            // 发送创建表现层子弹的事件
            EventManager.Instance().PostEvent(EventConfig.EVENT_L2R_BULLET_START, new object[] { bullet_id });
        }
Пример #8
0
    public bool BLPosition2Grid(BL.BLIntVector3 position, out int grid_x, out int grid_y)
    {
        int x = (int)(position.x / map_data.map_step / 1000);
        int y = (int)(position.z / map_data.map_step / 1000);

        if (x >= 0 && x < map_data.map_width && y >= 0 && y < map_data.map_height)
        {
            grid_x = x;
            grid_y = y;
            return(true);
        }

        grid_x = -1;
        grid_y = -1;

        return(false);
    }
Пример #9
0
        public override bool Tick()
        {
            //Debug.Log("current_frame " + current_frame + " current_node_index " + current_node_index + " pre_node_index " + pre_node_index);

            if (final_path_node == null || final_path_node.Count == 0)
            {
                return(true);
            }

            if (current_frame == frame_at_node[current_node_index])
            {
                ++current_node_index;
                ++pre_node_index;
            }

            // 已经到最后一个陆经点
            if (current_node_index == final_path_node.Count)
            {
                return(true);
            }

            BLIntVector3 next_position = final_path_node[current_node_index];
            BLIntVector3 pre_position  = final_path_node[pre_node_index];

            int frame_span          = frame_at_node[current_node_index] - frame_at_node[pre_node_index];
            int frame_from_pre_node = current_frame - frame_at_node[pre_node_index];

            BLIntVector3 now_position = BLIntVector3.Lerp(pre_position, next_position, frame_from_pre_node, frame_span);

            //Debug.Log("pre_position " + pre_position + " next_position " + next_position + " now_position " + now_position);

            hero_unit.pre_position = hero_unit.position;
            hero_unit.position     = now_position;

            current_dir = (next_position - pre_position).Vector3Value();

            hero_unit.dir = current_dir;

            ++current_frame;

            return(false);
        }
Пример #10
0
        public BLUnitBuilding CreateBuildingUnit(int unit_id, string gds_name, BLIntVector3 pos, int team_id)
        {
            GDSKit.building unit_gds = GDSKit.building.GetInstance(gds_name);

            BLUnitBuilding building_unit = new BLUnitBuilding();

            // 属性相关设置
            building_unit.gds_name        = gds_name;
            building_unit.unit_type       = UnitType.Building;
            building_unit.unit_id         = unit_id;
            building_unit.vision          = unit_gds.vision;
            building_unit.hp              = unit_gds.building_hp;
            building_unit.max_hp          = unit_gds.building_hp;
            building_unit.can_revive_hero = unit_gds.can_revive_hero;

            building_unit.position = pos;

            building_unit.team_id = team_id;


            if (all_unit_list.ContainsKey(building_unit.unit_id))
            {
                Debug.LogError("相同名字的unit已经在管理器里了 id : " + building_unit.unit_id);
                return(null);
            }

            all_unit_list.Add(building_unit.unit_id, building_unit);
            buiding_unit_list.Add(building_unit.unit_id, building_unit);

            building_unit.OnInit();

            // 表现层
            BuildingUnit unit_renderer = UnitManager.Instance().CreateBuildingUnit(building_unit.gds_name, building_unit.unit_id, building_unit.position.Vector3Value());

            unit_renderer.attack_vision = building_unit.vision * 0.001f;
            unit_renderer.team_id       = team_id;

            unit_renderer.OnInit();

            return(building_unit);
        }
Пример #11
0
    public List <BL.BLIntVector3> SearchPath(BL.BLIntVector3 start_pos, BL.BLIntVector3 dest_pos)
    {
        int x_start;
        int y_start;

        int x_end;
        int y_end;

        BLPosition2Grid(start_pos, out x_start, out y_start);
        BLPosition2Grid(dest_pos, out x_end, out y_end);

        List <AStarNode> path = FindPath(x_start, y_start, x_end, y_end);

        List <BL.BLIntVector3> bl_path = new List <BL.BLIntVector3>();

        if (path != null)
        {
            for (int i = 0; i < path.Count; ++i)
            {
                if (i == 0)
                {
                    bl_path.Add(start_pos);
                }
                else if (i == path.Count - 1)
                {
                    bl_path.Add(dest_pos);
                }
                else
                {
                    BL.BLIntVector3 bl_position = Grid2BLPosition(path[i]._x, path[i]._y);
                    bl_path.Add(bl_position);
                }
            }
        }

        return(bl_path);
    }
Пример #12
0
        public bool Tick()
        {
            if (remain_frames <= 0)
            {
                EventManager.Instance().PostEvent(EventConfig.EVENT_L2R_BULLET_END, new object[] { bullet_id });

                // 发送销毁子弹粒子的事件
                if (end_call_back != null)
                {
                    end_call_back.Invoke(this);
                }

                return(true);
            }
            else
            {
                pre_position = now_position;
                now_position = BLIntVector3.Lerp(start_postion, end_position, total_frames - remain_frames, total_frames);

                remain_frames--;
            }

            return(false);
        }
Пример #13
0
        public BLCommandMove2Position CreateMove2PositionCommand(int cast_id, int cast_frame, BLIntVector3 dest_position)
        {
            BLCommandMove2Position move_command = new BLCommandMove2Position();

            move_command.cast_frame    = cast_frame;
            move_command.cast_unit_id  = cast_id;
            move_command.dest_position = dest_position;

            return(move_command);
        }
Пример #14
0
        public override void OnInit()
        {
            base.OnInit();

            hero_unit = cast_unit as BLUnitHero;

            command_type = TickCommandType.Move;

            start_position = hero_unit.position;

            // 准备数据
            List <BLIntVector3> path_node = null;

            if (hero_unit.is_fly)
            {
                path_node = BattleField.battle_field.SearchFlyPath(start_position, dest_position);
            }
            else
            {
                path_node = BattleField.battle_field.SearchPath(start_position, dest_position);
            }


            frame_at_node.Clear();
            final_path_node.Clear();

            if (path_node != null && path_node.Count > 0)
            {
                BLIntVector3 pre_node = path_node[0];

                int frame = 0;
                frame_at_node.Add(frame);
                final_path_node.Add(pre_node);

                for (int i = 1; i < path_node.Count; ++i)
                {
                    BLIntVector3 current_node = path_node[i];

                    int magnitude  = (current_node - pre_node).Magnitude();
                    int need_frame = (int)(magnitude / hero_unit.move_speed / BLTimelineController.MS_PER_FRAME);

                    if (need_frame > 0)
                    {
                        frame += need_frame;

                        frame_at_node.Add(frame);

                        final_path_node.Add(path_node[i]);

                        //Debug.Log("frame at node i " + i + " frame " + frame);
                    }

                    pre_node = current_node;
                }
            }

            pre_node_index     = 0;
            current_node_index = 1;
            current_frame      = 0;


            hero_unit.pre_position = start_position;

            current_dir = (hero_unit.position - hero_unit.pre_position).Vector3Value();

            EventManager.Instance().PostEvent(EventConfig.EVENT_L2R_START_MOVE, new object[] { hero_unit.unit_id });
        }
Пример #15
0
        public static int DistanceSqr(BLIntVector3 a, BLIntVector3 b)
        {
            BLIntVector3 tmp = a - b;

            return(tmp.x * tmp.x + tmp.y * tmp.y + tmp.z * tmp.z);
        }