Esempio n. 1
0
    /// <summary>
    /// 获取离自身最近的墙对象(炸弹人用)
    /// </summary>
    /// <param name="self"></param>
    /// <returns></returns>
    public TileEntity GetWallEntityNearest(TileEntity self)
    {
        var allEntities = IsoMap.Instance.GetAllEntitiesByOwner(self.GetTargetOwner());

        int        selfx   = self.GetTilePos().x;
        int        selfy   = self.GetTilePos().y;
        int        mindiff = 999999;
        TileEntity target  = null;

        foreach (var entity in allEntities)
        {
            if (entity.IsDead())
            {
                continue;
            }

            if (entity.entityType == EntityType.Wall)
            {
                Vector2 c    = entity.GetCurrentPositionCenter();
                int     x    = (int)c.x;
                int     y    = (int)c.y;
                int     diff = Math.Abs(selfx - x) + Math.Abs(selfy - y);
                if (diff <= mindiff)
                {
                    mindiff = diff;
                    target  = entity;
                }
            }
        }

        return(target);
    }
Esempio n. 2
0
    /// <summary>
    /// 获取建筑小屋门的位置  REMARK:这里门的位置假设定义在右下边的中心(邻近不可通行区域)
    /// </summary>
    /// <returns></returns>
    private TilePoint GetDoorOfTheWorkerHouse()
    {
        int blocking = _workerHouse.blockingRange;

        Assert.Should(blocking > 0, "invalid blockingRange...");

        int doorX = _workerHouse.GetTilePos().x + (int)(_workerHouse.width * 0.5f);
        int doorY = _workerHouse.GetTilePos().y + (int)((_workerHouse.height + 1 - blocking) / 2) - 1;

        return(new TilePoint(doorX, doorY));
    }
Esempio n. 3
0
 public void SelectBuilding(TileEntity building) //临时去掉占地数据,记录原始位置,添加选择状态
 {
     building.OnSelected();
     oldX            = building.GetTilePos().x;
     oldY            = building.GetTilePos().y;
     currentBuilding = building;
     IsoMap.Instance.BeginMoveEntity(building);
     buildableView.Init(building.width);
     buildArrow.Init(building.width);
     buildArrow.gameObject.SetActive(true);
     buildArrow.transform.position = IsoHelper.GridToPosition(building.GetTilePos());
 }
Esempio n. 4
0
 public void UnselectBuilding(TileEntity building) //恢复或者变更占地数据,去掉选择状态
 {
     if (!IsoMap.Instance.CanPlaceBuilding(building.GetTilePos().x, building.GetTilePos().y,
                                           building.width, building.height))
     {
         DraggingBuildingTo(oldX, oldY);
     }
     building.OnUnselected();
     currentBuilding = null;
     IsoMap.Instance.EndMoveEntity(building);
     buildableView.gameObject.SetActive(false);
     buildArrow.gameObject.SetActive(false);
 }
Esempio n. 5
0
    /// <summary>
    /// 初始化军营
    /// </summary>
    private bool InitCamp()
    {
        if (m_camp == null)
        {
            m_camp = FindCampEntity();
            if (m_camp == null)
            {
                return(false);
            }

            //  军营区域
            RefreshCampGridData(m_camp.GetTilePos());
            return(true);
        }
        else
        {
            //  位置变更了(拖拽等)
            TilePoint campPos = m_camp.GetTilePos();
            if (m_campTilePos != campPos)
            {
                RefreshCampGridData(campPos);
            }
            return(true);
        }
    }
Esempio n. 6
0
    public override com.pureland.proto.ReqWrapper Execute()
    {
        var buildTime  = entity.model.buildTime;
        var buildingVO = new BuildingVO();

        buildingVO.buildingStatus = buildTime == 0 ? BuildingVO.BuildingStatus.On : BuildingVO.BuildingStatus.Construct;
        buildingVO.cid            = entity.model.baseId;
        buildingVO.sid            = DataCenter.Instance.CreateNextItemSid();
        buildingVO.endTime        = ServerTime.Instance.GetTimestamp(buildTime);
        buildingVO.x = entity.GetTilePos().x;
        buildingVO.y = entity.GetTilePos().y;

        if (EntityTypeUtil.IsGatherResourceBuilding(entity.model))
        {
            buildingVO.resourceBuildingVO = new ResourceBuildingVO()
            {
                lastGatherTime = buildingVO.endTime
            };                                                                                               //建造完成开始计算产量
        }
        //替换为有建筑动画的对象
        var newEntity = entity.ReplaceWith(entity.model, buildingVO);

        IsoMap.Instance.ForceAddEntity(newEntity);

        if (buildTime != 0)
        {
            //占用工人数量
            DataCenter.Instance.FreeWorker -= 1;
        }
        //添加到建筑vo,方便计数等
        DataCenter.Instance.AddBuilding(buildingVO);
        //消耗资源
        DataCenter.Instance.AddResource(new ResourceVO()
        {
            resourceType = entity.model.costResourceType, resourceCount = -entity.model.costResourceCount
        });


        var buildingConsReq = new BuildingConsReq();

        buildingConsReq.buildingVO   = buildingVO;
        buildingConsReq.resourceType = resourceType;
        return(new ReqWrapper()
        {
            requestType = ReqWrapper.RequestType.BuildingCons, buildingConsReq = buildingConsReq
        });
    }
Esempio n. 7
0
    /// <summary>
    /// 填充地表建筑数据(0为清除)
    /// </summary>
    /// <param name="entity"></param>
    /// <param name="value"></param>
    private void FillBuildingMapData(TileEntity entity, int entity_id)
    {
        if (!EntityTypeUtil.IsCostMapGrid(entity.entityType))
        {
            return;
        }
        int x = entity.GetTilePos().x;
        int y = entity.GetTilePos().y;
        //  填充建筑全部区域
        int w = entity.width;
        int h = entity.height;

        for (int i = x; i < x + w; ++i)
        {
            for (int j = y; j < y + h; ++j)
            {
                m_buildingMap[i, j] = entity_id;
            }
        }

        //  填充建筑不可通行区域(blockingRange最大值为边数减1,所以不会导致建筑边上的entity_id重合。)
        int blocking = entity.blockingRange;

        if (blocking > 0)
        {
            int offset_x = (int)((w + 1 - blocking) / 2);
            int offset_y = (int)((h + 1 - blocking) / 2);
            Assert.Should(offset_x >= 1 && offset_y >= 1, "Entity的blockingRange不正确...");
            for (int i = x + offset_x; i < x + offset_x + blocking; ++i)
            {
                for (int j = y + offset_y; j < y + offset_y + blocking; ++j)
                {
                    m_routeMap[i, j].EntityID = entity_id;
                }
            }
        }

        //  更新墙之间的连接器 并 刷新墙的方向(显示用)
        if (entity.entityType == EntityType.Wall)
        {
            RefreshWallLinkerAndDirection(entity, entity_id);
        }
    }
Esempio n. 8
0
    public LinkedList <IMoveGrid> SearchDijkstraNearestWall(TileEntity attacker, Dictionary <TilePoint, IsoGridTarget> gridTargets)
    {
        LinkedList <IMoveGrid> path = m_dijkstra.SearchNearestWall(attacker.GetTilePos().x, attacker.GetTilePos().y, gridTargets, new AStarUserContext(this, attacker));

        //  DEBUG
        if (path != null)
        {
            m_dbgLastRoute = new LinkedList <IMoveGrid>();
            foreach (var v in path)
            {
                m_dbgLastRoute.AddFirst(v);
            }
        }
        else
        {
            m_dbgLastRoute = null;
        }

        return(path);
    }
Esempio n. 9
0
    /// <summary>
    /// 获取建造格子区域
    /// </summary>
    private void RefreshBuildGridArea()
    {
        TilePoint currPos = _buildTargeter.GetTilePos();

        if (currPos != _buildindLastTilePos)
        {
            _buildindLastTilePos = currPos;
            _buildArea.Clear();

            int x = currPos.x;
            int y = currPos.y;
            int w = _buildTargeter.width;
            int h = _buildTargeter.height;

            //  不可通行区域
            int blkBgnX, blkEndX, blkBgnY, blkEndY;
            int blocking = _buildTargeter.blockingRange;
            Assert.Should(blocking > 0, "invalid blockingRange...");

            int offset_x = (int)((w + 1 - blocking) / 2);
            int offset_y = (int)((h + 1 - blocking) / 2);
            blkBgnX = x + offset_x;
            blkEndX = blkBgnX + blocking - 1;
            blkBgnY = y + offset_y;
            blkEndY = blkBgnY + blocking - 1;

            //  获取建造区域(不可通行区域的左下右下两边)
            //  *           *
            //     *     *
            //        *
            for (int i = blkBgnX - 1; i <= blkEndX; i++)
            {
                _buildArea.Add(new TilePoint(i, blkBgnY - 1));
            }
            for (int j = blkBgnY; j <= blkEndY; j++)
            {
                _buildArea.Add(new TilePoint(blkBgnX - 1, j));
            }
        }
    }
Esempio n. 10
0
 /// <summary>
 /// 建造 确认 or 取消
 /// </summary>
 /// <param name="confirm"></param>
 private void OnBuildConfirm(bool confirm)
 {
     if (confirm)
     {
         if (!IsoMap.Instance.CanPlaceBuilding(currentBuilding.GetTilePos().x, currentBuilding.GetTilePos().y,
                                               currentBuilding.width, currentBuilding.height))
         {
             return;//TODO alert sound
         }
         //send to server
         GameManager.Instance.RequestBuyBuilding(currentBuilding);
         if (isConstructMulti)
         {
             TilePoint?suggestPoint = null;
             if (lastPoint != null)
             {
                 var delta = currentBuilding.GetTilePos() - lastPoint.Value;
                 if (Mathf.Abs(delta.x) + Mathf.Abs(delta.y) == currentBuilding.width) //只有在挨着的时候才处理
                 {
                     var newPoint = currentBuilding.GetTilePos() + delta;
                     if (IsoMap.Instance.CanPlaceBuilding(newPoint.x, newPoint.y, currentBuilding.width,
                                                          currentBuilding.height))
                     {
                         suggestPoint = newPoint;
                     }
                 }
             }
             if (suggestPoint == null && currentBuilding.model.entityType == EntityType.Wall)
             {
                 //判断当前建筑四周是否有墙
                 var currPoint = currentBuilding.GetTilePos();
                 if (IsoMap.Instance.IsWallStrict(currPoint.x - 2, currPoint.y))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(2, 0));
                 }
                 else if (IsoMap.Instance.IsWallStrict(currPoint.x + 2, currPoint.y))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(-2, 0));
                 }
                 else if (IsoMap.Instance.IsWallStrict(currPoint.x, currPoint.y - 2))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(0, 2));
                 }
                 else if (IsoMap.Instance.IsWallStrict(currPoint.x, currPoint.y + 2))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(0, -2));
                 }
             }
             if (suggestPoint == null)
             {
                 suggestPoint = SuggestPosition(currentBuilding.GetTilePos());
             }
             lastPoint = currentBuilding.GetTilePos();
             var tileEntity = TileEntity.Create(OwnerType.Defender, currentBuilding.model);
             tileEntity.Init();
             BuildCompleteCleanUp();//清除上一次的建造
             SetBuildingObject(tileEntity, isConstructMulti, suggestPoint);
         }
         else
         {
             lastPoint = currentBuilding.GetTilePos();
             BuildCompleteCleanUp();
         }
     }
     else
     {
         currentBuilding.Destroy();
         BuildCompleteCleanUp();
     }
 }
Esempio n. 11
0
 public RetvGridTargetInfo SearchDijkstra(TileEntity attacker, Dictionary <TilePoint, IsoGridTarget> gridTargets)
 {
     return(m_dijkstra.Search(attacker.GetTilePos().x, attacker.GetTilePos().y, gridTargets, new AStarUserContext(this, attacker)));
 }