예제 #1
0
    public bool AddMechaComponentToBag(MechaComponentInfo mci, GridPos.Orientation orientation, List <GridPos> realGridPoses, out BagItem bagItem)
    {
        bool suc = BagPanel.TryAddItem(mci, orientation, realGridPoses, out bagItem);

        if (suc)
        {
            mechaComponentInfosInBag.Add(mci);
        }

        return(suc);
    }
예제 #2
0
    private void AddItem(MechaComponentInfo mci, GridPos.Orientation orientation, List <GridPos> realOccupiedGPs, out BagItem bagItem)
    {
        IntRect realSpace = GetSizeFromGridPositions(realOccupiedGPs);
        GridPos GridPos   = new GridPos(realSpace.x, realSpace.z, orientation);

        bagItem = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.BagItem].AllocateGameObject <BagItem>(ItemContainer);
        bagItem.Initialize(mci, realSpace.width, realSpace.height, GridPos, realOccupiedGPs, false);
        bagItems.Add(bagItem);

        foreach (GridPos gp in realOccupiedGPs)
        {
            bagGridMatrix[gp.x, gp.z].State = BagGrid.States.Unavailable;
        }
    }
예제 #3
0
    private bool FindSpaceToPutItem(MechaComponentInfo mci, out GridPos.Orientation orientation, out List <GridPos> realOccupiedGPs)
    {
        realOccupiedGPs = new List <GridPos>();
        orientation     = GridPos.Orientation.Up;
        foreach (string s in Enum.GetNames(typeof(GridPos.Orientation)))
        {
            orientation = (GridPos.Orientation)Enum.Parse(typeof(GridPos.Orientation), s);
            if (FindSpaceToPutRotatedItem(mci, orientation, realOccupiedGPs))
            {
                return(true);
            }
        }

        return(false);
    }
예제 #4
0
    public bool TryAddItem(MechaComponentInfo mci, GridPos.Orientation orientation, List <GridPos> realGridPoses, out BagItem bagItem)
    {
        bool placeFound = CheckSpaceAvailable(realGridPoses);

        if (placeFound)
        {
            AddItem(mci, orientation, realGridPoses, out bagItem);
            return(true);
        }
        else
        {
            bagItem = null;
            return(false);
        }
    }
예제 #5
0
    private bool FindSpaceToPutRotatedItem(MechaComponentInfo mci, GridPos.Orientation orientation, List <GridPos> realOccupiedGPs)
    {
        List <GridPos> occupiedGridPositions = BagManager.Instance.MechaComponentOccupiedGridPosDict[mci.MechaComponentType];
        IntRect        space = GetSizeFromGridPositions(occupiedGridPositions);

        bool heightWidthSwap = orientation == GridPos.Orientation.Right || orientation == GridPos.Orientation.Left;

        GridPos temp        = new GridPos(space.x, space.z);
        GridPos temp_rot    = GridPos.RotateGridPos(temp, orientation);
        int     xStart_temp = temp_rot.x;
        int     zStart_temp = temp_rot.z;

        for (int i = 0 - zStart_temp; i <= 10 - (heightWidthSwap ? space.width : space.height) - zStart_temp; i++)
        {
            for (int j = 0 - xStart_temp; j <= 10 - (heightWidthSwap ? space.height : space.width) - xStart_temp; j++)
            {
                bool canHold = true;
                foreach (GridPos gp in occupiedGridPositions)
                {
                    GridPos rot_gp = GridPos.RotateGridPos(gp, orientation);
                    int     col    = j + rot_gp.x;
                    int     row    = i + rot_gp.z;
                    if (col < 0 || col >= 10 || row < 0 || col >= 10)
                    {
                        canHold = false;
                        break;
                    }

                    if (!bagGridMatrix[col, row].Available)
                    {
                        canHold = false;
                        break;
                    }

                    realOccupiedGPs.Add(new GridPos(col, row, GridPos.Orientation.Up));
                }

                if (canHold)
                {
                    return(true);
                }

                realOccupiedGPs.Clear();
            }
        }

        return(false);
    }
예제 #6
0
    private void Rotate()
    {
        GridPos.Orientation newOrientation = GridPos.orientation == GridPos.Orientation.Up ? GridPos.Orientation.Right : GridPos.Orientation.Up;

        List <GridPos> newRealPositions = new List <GridPos>();

        foreach (GridPos gp in RealPositionsInBagPanel)
        {
            GridPos newLocalGrid = GridPos.RotateGridPos(gp - GridPos, GridPos.orientation == GridPos.Orientation.Up ? GridPos.Orientation.Right : GridPos.Orientation.Left);
            GridPos newRealGrid  = newLocalGrid + GridPos;
            newRealPositions.Add(newRealGrid);
        }

        RealPositionsInBagPanel.Clear();
        RealPositionsInBagPanel = newRealPositions;

        //todo edit RealPositionsInBagPanel and change in bagpanel
        Initialize(MechaComponentInfo, Height, Width, new GridPos(GridPos.x, GridPos.z, newOrientation), newRealPositions, true);
    }
 public void Initialize()
 {
     Orientation = GridPos.GetGridPosByLocalTrans(transform, GameManager.GridSize).orientation;
 }