コード例 #1
0
 public void PlacePortal(NetworkedGridElement newPortalLoc)
 {
     if (portalElement)
     {
         portalElement.portal      = false;
         portalElement.portalOwner = PlayerEnum.none;
         portalElement.ChangeColor(NetworkedMenu.defaultColor);
     }
     portalElement = newPortalLoc;
     // Check to make sure enemy portal isn't there
     if (portalElement.portal && portalElement.owner != owner.GetComponent <NetworkedPlayer>().identity)
     {
         // if there is one, destory it
         portalElement.portal      = false;
         portalElement.portalOwner = PlayerEnum.none;
         return;
     }
     portalElement.portal      = true;
     portalElement.portalOwner = owner.GetComponent <NetworkedPlayer>().identity;
 }
コード例 #2
0
 private void DisplayPusherInfluenceWest(bool shouldHighlight, bool immediateNeighbor)
 {
     if (!westWall && westNeighbor && westNeighbor.GetComponent <NetworkedGridElement>().piece&&
         (westNeighbor.GetComponent <NetworkedGridElement>().piece.GetComponent <NetworkedGamePiece>() is NetworkedUnit ||
          westNeighbor.GetComponent <NetworkedGridElement>().piece.GetComponent <NetworkedGamePiece>() is NetworkedTrap))
     {
         NetworkedGridElement west = westNeighbor.GetComponent <NetworkedGridElement>();
         west.isHighlighted = shouldHighlight;
         if (shouldHighlight)
         {
             west.ChangeColor(NetworkedGridMenu.pushColor);
             if (!immediateNeighbor)
             {
                 west.ChangeColor(NetworkedGridMenu.pushColor + new Color(0.4F, 0.4F, 0.4F));
             }
         }
         else
         {
             west.ChangeColor(NetworkedMenu.defaultColor);
         }
         west.DisplayPusherInfluenceWest(shouldHighlight, false);
     }
 }
コード例 #3
0
 public void ActivateElementAction()
 {
     if (activeGO == null)
     {
         NetworkedGridElement selectedGE = selectedGO.GetComponent <NetworkedGridElement>();
         activeGO = selectedGO;
         if (selectedGE.piece && selectedGE.piece.GetComponent <NetworkedGamePiece>() is NetworkedUnit)
         {
             selectedPiece = selectedGE.piece;
             if (selectedPiece.GetComponent <NetworkedGamePiece>() is NetworkedUnit)
             {
                 if (!selectedPiece.GetComponent <NetworkedUnit>().DisplayActionGrid())
                 {
                     activeGO = null;
                 }
             }
         }
         else
         {
             activeGO = null;
         }
     }
 }
コード例 #4
0
 private void DisplayPusherInfluenceSouth(bool shouldHighlight, bool immediateNeighbor)
 {
     if (!southWall && southNeighbor && southNeighbor.GetComponent <NetworkedGridElement>().piece&&
         (southNeighbor.GetComponent <NetworkedGridElement>().piece.GetComponent <NetworkedGamePiece>() is NetworkedUnit ||
          southNeighbor.GetComponent <NetworkedGridElement>().piece.GetComponent <NetworkedGamePiece>() is NetworkedTrap))
     {
         NetworkedGridElement south = southNeighbor.GetComponent <NetworkedGridElement>();
         south.isHighlighted = shouldHighlight;
         if (shouldHighlight)
         {
             south.ChangeColor(NetworkedGridMenu.pushColor);
             if (!immediateNeighbor)
             {
                 south.ChangeColor(NetworkedGridMenu.pushColor + new Color(0.4F, 0.4F, 0.4F));
             }
         }
         else
         {
             south.ChangeColor(NetworkedMenu.defaultColor);
         }
         south.DisplayPusherInfluenceSouth(shouldHighlight, false);
     }
 }
コード例 #5
0
 private void DisplayPullerInfluenceWest(int distance, bool shouldHighlight)
 {
     if (!westWall && westNeighbor && distance > 0)
     {
         NetworkedGridElement west = westNeighbor.GetComponent <NetworkedGridElement>();
         if (shouldHighlight)
         {
             west.ChangeColor(NetworkedGridMenu.pullColor);
             if (west.piece && (west.piece.GetComponent <NetworkedGamePiece>() is NetworkedUnit || west.piece.GetComponent <NetworkedGamePiece>() is NetworkedTrap))
             {
                 west.isHighlighted = shouldHighlight;
             }
             else
             {
                 west.GetComponent <Image>().color += new Color(0.2F, 0.2F, 0.2F);
             }
         }
         else
         {
             west.ChangeColor(NetworkedMenu.defaultColor);
         }
         west.DisplayPullerInfluenceWest(distance - 1, shouldHighlight);
     }
 }
コード例 #6
0
 private void DisplayPullerInfluenceSouth(int distance, bool shouldHighlight)
 {
     if (!southWall && southNeighbor && distance > 0)
     {
         NetworkedGridElement south = southNeighbor.GetComponent <NetworkedGridElement>();
         if (shouldHighlight)
         {
             south.ChangeColor(NetworkedGridMenu.pullColor);
             if (south.piece && (south.piece.GetComponent <NetworkedGamePiece>() is NetworkedUnit || south.piece.GetComponent <NetworkedGamePiece>() is NetworkedTrap))
             {
                 south.isHighlighted = shouldHighlight;
             }
             else
             {
                 south.GetComponent <Image>().color += new Color(0.2F, 0.2F, 0.2F);
             }
         }
         else
         {
             south.ChangeColor(NetworkedMenu.defaultColor);
         }
         south.DisplayPullerInfluenceSouth(distance - 1, shouldHighlight);
     }
 }
コード例 #7
0
    public void SetLocation(GameObject newLoc)
    {
        transform.position = newLoc.transform.TransformPoint(Vector3.zero) + Vector3.forward * gameObject.transform.position.z;
        if (flag)
        {
            flag.transform.position = newLoc.transform.TransformPoint(Vector3.zero) + Vector3.forward * flag.transform.position.z;
            flag.GetComponent <NetworkedGamePiece>().gridElement = newLoc.GetComponent <NetworkedGridElement>();
            if (newLoc.GetComponent <NetworkedGridElement>().goal)
            {
                owner.GetComponent <NetworkedPlayer>().CmdEndLevel(owner.GetComponent <NetworkedPlayer>().identity);
                //grid.gameMan.EndLevel(owner.GetComponent<NetworkedPlayer>().identity);
            }
        }
        // Check if gridElement has been assigned (this is for spawning)
        if (!gridElement)
        {
            if (!FindGridElement())
            {
                Debug.Log(gridElement.piece);
            }
        }
        // Handle Collisions; We're assuming newLoc always has a GridElement
        NetworkedGridElement otherGE = newLoc.GetComponent <NetworkedGridElement>();

        if (otherGE && otherGE.piece && otherGE.piece != gameObject)
        {
            //Debug.Log("Collided with: " + otherGE.piece.name);
            // Check to make sure we're working with a unit
            if (otherGE.piece.GetComponent <NetworkedGamePiece>() is NetworkedUnit)
            {
                NetworkedUnit otherUnit = otherGE.piece.GetComponent <NetworkedUnit>();
                otherUnit.owner.GetComponent <NetworkedPlayer>().CmdReturnUnit(otherGE.piece);
                if (otherUnit.unitType == UnitType.Portalist)
                {
                    otherUnit.GetComponent <NetworkedPortalPlacer>().PlacePortal(otherGE);
                }
                otherGE.piece = null;
                // check to see if the other piece has the flag
                if (otherUnit.flag)
                {
                    otherGE.piece = otherUnit.flag;
                    flag          = null;
                }
                // make sure you don't have the flag
                if (flag)
                {
                    otherGE.piece = flag;
                    flag.GetComponent <NetworkedGamePiece>().gridElement = otherGE;
                    flag = null;
                }
                // Don't forget to kill yourself
                owner.GetComponent <NetworkedPlayer>().CmdReturnUnit(gameObject);
                if (unitType == UnitType.Portalist)
                {
                    GetComponent <NetworkedPortalPlacer>().PlacePortal(otherGE);
                }
                gridElement.piece = null;
                return;
            }
            else
            {
                // Check for flag
                if (otherGE.piece.GetComponent <NetworkedGamePiece>() is NetworkedFlag)
                {
                    flag           = otherGE.piece;
                    canAct         = false;
                    remainingMoves = 0;
                }
                else if (otherGE.piece.GetComponent <NetworkedGamePiece>() is NetworkedTrap)
                {
                    if (unitType == UnitType.Portalist)
                    {
                        this.GetComponent <NetworkedPortalPlacer>().PlacePortal(otherGE);
                    }
                    if (gridElement.piece == gameObject)
                    {
                        gridElement.piece = null;
                    }
                    if (!grid)
                    {
                        grid = FindObjectOfType <NetworkedGridMenu>();
                    }
                    owner.GetComponent <NetworkedPlayer>().CmdReturnUnit(gameObject);
                    if (flag)   // flags will destroy traps; currently no piece can destroy traps,
                                // so if a flag lands on one, it must either destroy the trap or the game is unwinnable
                                // it may be better to have traps pull/pushable, while the flag remains aloof. This would
                                // prevent the need to destroy the trap
                    {
                        Destroy(otherGE.piece);
                        otherGE.piece = flag;
                        flag.GetComponent <NetworkedGamePiece>().gridElement = otherGE;
                        flag = null;
                    }
                    return;
                }
            }
        }
        gridElement.piece = null;
        gridElement       = newLoc.GetComponent <NetworkedGridElement>();
        gridElement.piece = gameObject;

        if (flag)
        {
            flag.GetComponent <NetworkedGamePiece>().gridElement = gridElement;
            if (gridElement.goal)
            {
                // Player has moved the flag into the goal!
                // Someone should probably contact the gamemanager
                owner.GetComponent <NetworkedPlayer>().CmdEndLevel(owner.GetComponent <NetworkedPlayer>().identity);
                //grid.gameMan.EndLevel();
            }
        }

        if (grid == null)
        {
            grid = FindObjectOfType <NetworkedGridMenu>();
        }
        grid.UpdateDescription();
    }
コード例 #8
0
    void ActivateElement()
    {
        // ASSUMING NOTHING HAS BEEN SELECTED...
        // Check to see if there's a piece above the selected tile
        //      If there is, activate this tile and open that piece's context menu
        //      If that piece wants to move, it should call what this used to do but is now in a public function
        //          This should use the Unit script's numMoves as a parameter for showing movement
        //      If there is not, do nothing
        if (activeGO == null)
        {
            NetworkedGridElement selectedGE = selectedGO.GetComponent <NetworkedGridElement>();
            activeGO = selectedGO;
            if (selectedGE.piece && selectedGE.piece.GetComponent <NetworkedGamePiece>() is NetworkedUnit)
            {
                if (selectedGE.piece.GetComponent <NetworkedUnit>().owner.GetComponent <NetworkedPlayer>() != activePlayer)
                {
                    activeGO = null;
                    return;
                }
                selectedPiece = selectedGE.piece;
                selectedPiece.GetComponent <NetworkedUnit>().DisplayMoveGrid();
                //canPressButtons = false;
            }
            else if (!(selectedGE.piece && selectedGE.piece.GetComponent <NetworkedGamePiece>() is NetworkedTrap) &&
                     ((selectedGE.spawnable && selectedGE.owner == activePlayer.GetComponent <NetworkedPlayer>().identity) ||
                      (selectedGE.portal && selectedGE.portalOwner == activePlayer.GetComponent <NetworkedPlayer>().identity)))
            {
                // Display a ContextMenu with all the pieces that can be spawned
                contextMenu.ShowContextMenu(this);
                // Move the canvas to SelectedGO's location
                contextMenu.menuCanvas.transform.position = selectedGO.transform.position + contextMenu.menuCanvas.transform.position.z * Vector3.forward;
                canPressButtons = false;
                // Long term, this must be dynamic, but we can settle for short term for now
            }
            else
            {
                activeGO = null;
            }
        }

        // ASSUMING SOMETHING *HAS* BEEN SELECTED (that is, we're already displaying a movement grid
        // Check to see if this element is a valid movement target for the piece
        //      If it is, turn off the movement grid and move the piece here
        //      If it isn't, cancel the move action? Do nothing? Do nothing for now
        else
        {
            // don't do anything if we reselect the active game object
            if (selectedGO == activeGO)
            {
                return;
            }
            else if (selectedPiece != null)
            {
                if (selectedGO.GetComponent <NetworkedGridElement>().isHighlighted)
                {
                    selectedPiece.GetComponent <NetworkedUnit>().PerformAction(selectedGO);
                    SetElementColor(selectedGO, selectedColor, defaultColor);
                    activeGO      = null;
                    selectedPiece = null;
                }
            }
        }
    }
コード例 #9
0
    public static void UpdateWallSprite(GameObject GO)
    {
        NetworkedGridMenu    grid    = FindObjectOfType <NetworkedGridMenu>();
        NetworkedGridElement element = GO.GetComponent <NetworkedGridElement>();

        if (element.northWall && element.eastWall && element.southWall && element.westWall)
        {
            GO.GetComponent <Image>().sprite = grid.FourWalls;
        }
        else if (element.northWall && element.eastWall && element.southWall)
        {
            GO.GetComponent <Image>().sprite = grid.ThreeWalls;
            GO.transform.rotation            = Quaternion.Euler(0, 0, -90);
        }
        else if (element.northWall && element.eastWall && element.westWall)
        {
            GO.GetComponent <Image>().sprite = grid.ThreeWalls;
        }
        else if (element.northWall && element.southWall && element.westWall)
        {
            GO.GetComponent <Image>().sprite = grid.ThreeWalls;
            GO.transform.rotation            = Quaternion.Euler(0, 0, 90);
        }
        else if (element.eastWall && element.southWall && element.westWall)
        {
            GO.GetComponent <Image>().sprite = grid.ThreeWalls;
            GO.transform.rotation            = Quaternion.Euler(0, 0, 180);
        }
        else if (element.northWall && element.eastWall)
        {
            GO.GetComponent <Image>().sprite = grid.TwoWallsL;
            GO.transform.rotation            = Quaternion.Euler(0, 0, -90);
        }
        else if (element.northWall && element.southWall)
        {
            GO.GetComponent <Image>().sprite = grid.TwoWallsHall;
            GO.transform.rotation            = Quaternion.Euler(0, 0, 90);
        }
        else if (element.northWall && element.westWall)
        {
            GO.GetComponent <Image>().sprite = grid.TwoWallsL;
        }
        else if (element.eastWall && element.southWall)
        {
            GO.GetComponent <Image>().sprite = grid.TwoWallsL;
            GO.transform.rotation            = Quaternion.Euler(0, 0, 180);
        }
        else if (element.eastWall && element.westWall)
        {
            GO.GetComponent <Image>().sprite = grid.TwoWallsHall;
        }
        else if (element.southWall && element.westWall)
        {
            GO.GetComponent <Image>().sprite = grid.TwoWallsL;
            GO.transform.rotation            = Quaternion.Euler(0, 0, 90);
        }
        else if (element.northWall)
        {
            GO.GetComponent <Image>().sprite = grid.OneWall;
            GO.transform.rotation            = Quaternion.Euler(0, 0, -90);
        }
        else if (element.eastWall)
        {
            GO.GetComponent <Image>().sprite = grid.OneWall;
            GO.transform.rotation            = Quaternion.Euler(0, 0, 180);
        }
        else if (element.southWall)
        {
            GO.GetComponent <Image>().sprite = grid.OneWall;
            GO.transform.rotation            = Quaternion.Euler(0, 0, 90);
        }
        else if (element.westWall)
        {
            GO.GetComponent <Image>().sprite = grid.OneWall;
        }
        else
        {
            GO.GetComponent <Image>().sprite = grid.NoWalls;
            GO.transform.rotation            = Quaternion.identity;
        }
    }
コード例 #10
0
    private void UpdateGridAttributes()
    {
        NetworkedGridElement north     = gridElement.northNeighbor.GetComponent <NetworkedGridElement>();
        NetworkedGridElement east      = gridElement.eastNeighbor.GetComponent <NetworkedGridElement>();
        NetworkedGridElement south     = gridElement.southNeighbor.GetComponent <NetworkedGridElement>();
        NetworkedGridElement west      = gridElement.westNeighbor.GetComponent <NetworkedGridElement>();
        NetworkedGridElement northeast = gridElement.eastNeighbor.GetComponent <NetworkedGridElement>().northNeighbor.GetComponent <NetworkedGridElement>();
        NetworkedGridElement southeast = gridElement.southNeighbor.GetComponent <NetworkedGridElement>().eastNeighbor.GetComponent <NetworkedGridElement>();
        NetworkedGridElement northwest = gridElement.northNeighbor.GetComponent <NetworkedGridElement>().westNeighbor.GetComponent <NetworkedGridElement>();
        NetworkedGridElement southwest = gridElement.westNeighbor.GetComponent <NetworkedGridElement>().southNeighbor.GetComponent <NetworkedGridElement>();
        bool       temp   = north.spawnable;
        bool       temp2  = west.spawnable;
        bool       temp3  = north.goal;
        bool       temp4  = west.goal;
        bool       temp5  = northeast.spawnable;
        bool       temp6  = northwest.spawnable;
        bool       temp7  = northeast.goal;
        bool       temp8  = northwest.goal;
        PlayerEnum temp9  = north.owner;
        PlayerEnum temp10 = west.owner;
        PlayerEnum temp11 = northeast.owner;
        PlayerEnum temp12 = northwest.owner;

        if (north.owner != PlayerEnum.none)
        {
            west.owner  = north.owner;
            north.owner = PlayerEnum.none;
        }
        if (east.owner != PlayerEnum.none)
        {
            north.owner = east.owner;
            east.owner  = PlayerEnum.none;
        }
        if (south.owner != PlayerEnum.none)
        {
            east.owner  = south.owner;
            south.owner = PlayerEnum.none;
        }
        if (temp10 != PlayerEnum.none)
        {
            south.owner = temp10;
            if (temp9 == PlayerEnum.none)
            {
                west.owner = PlayerEnum.none;
            }
        }
        if (northeast.owner != PlayerEnum.none)
        {
            northwest.owner = northeast.owner;
            northeast.owner = PlayerEnum.none;
        }
        if (southeast.owner != PlayerEnum.none)
        {
            northeast.owner = southeast.owner;
            southeast.owner = PlayerEnum.none;
        }
        if (southwest.owner != PlayerEnum.none)
        {
            southeast.owner = southwest.owner;
            southwest.owner = PlayerEnum.none;
        }
        if (temp12 != PlayerEnum.none)
        {
            southwest.owner = temp12;
            if (temp11 == PlayerEnum.none)
            {
                northwest.owner = PlayerEnum.none;
            }
        }
        if (north.spawnable)
        {
            west.spawnable  = true;
            north.spawnable = false;
        }
        if (east.spawnable)
        {
            north.spawnable = true;
            east.spawnable  = false;
        }
        if (south.spawnable)
        {
            east.spawnable  = true;
            south.spawnable = false;
        }
        if (temp2)
        {
            south.spawnable = true;
            if (!temp)
            {
                west.spawnable = false;
            }
        }
        if (northeast.spawnable)
        {
            northwest.spawnable = true;
            northeast.spawnable = false;
        }
        if (southeast.spawnable)
        {
            northeast.spawnable = true;
            southeast.spawnable = false;
        }
        if (southwest.spawnable)
        {
            southeast.spawnable = true;
            southwest.spawnable = false;
        }
        if (temp6)
        {
            southwest.spawnable = true;
            if (!temp5)
            {
                northwest.spawnable = false;
            }
        }
        if (north.goal)
        {
            west.goal  = true;
            north.goal = false;
        }
        if (east.goal)
        {
            north.goal = true;
            east.goal  = false;
        }
        if (south.goal)
        {
            east.goal  = true;
            south.goal = false;
        }
        if (temp4)
        {
            south.goal = true;
            if (!temp3)
            {
                west.goal = false;
            }
        }
        if (northeast.goal)
        {
            northwest.goal = true;
            northeast.goal = false;
        }
        if (southeast.goal)
        {
            northeast.goal = true;
            southeast.goal = false;
        }
        if (southwest.goal)
        {
            southeast.goal = true;
            southwest.goal = false;
        }
        if (temp8)
        {
            southwest.goal = true;
            if (!temp7)
            {
                northwest.goal = false;
            }
        }
        grid.SetElementColor(north.gameObject, Menu.defaultColor);
        grid.SetElementColor(east.gameObject, Menu.defaultColor);
        grid.SetElementColor(south.gameObject, Menu.defaultColor);
        grid.SetElementColor(west.gameObject, Menu.defaultColor);
        grid.SetElementColor(northeast.gameObject, Menu.defaultColor);
        grid.SetElementColor(northwest.gameObject, Menu.defaultColor);
        grid.SetElementColor(southeast.gameObject, Menu.defaultColor);
        grid.SetElementColor(southwest.gameObject, Menu.defaultColor);
    }