Beispiel #1
0
 public void RpcChangeModeMonster(int aIdSpawn)
 {
     if (!isServer)
     {
         MonsterController monster = MatchController.instance.monstersInGame[MatchController.instance.GetIndexMonsterInGameListWithSpawn(aIdSpawn)];
         monster.ChangeNextMonsterMode();
     }
 }
Beispiel #2
0
    private void Update()
    {
        if (isLocalPlayer)
        {
            if (MatchController.instance.playerPlaying != playerNumber && monsterSelected != null)
            {
                BoardController.instance.DeselectFloorMonsterSelected(monsterSelected.idFloor);
                monsterSelected = null;
            }
            if (!MatchController.instance.activatingCard)
            {
                if (monsterSelected != null)
                {
                    BoardController.instance.SelectFloorMonsterSelected(monsterSelected.idFloor);
                    if (monsterSelected.canMove)
                    {
                        BoardController.instance.ShowFloorCanMove(monsterSelected.idFloor, monsterSelected.playerOwner, monsterSelected.remainingVelocity);
                        if (BoardController.instance.floorOver != null && BoardController.instance.IsInPosibleFloors(BoardController.instance.floorOver))
                        {
                            Vector2 hotSpot = new Vector2(MatchController.instance.cursorTextures[2].width / 2, MatchController.instance.cursorTextures[1].height / 2);
                            Cursor.SetCursor(MatchController.instance.cursorTextures[2], hotSpot, CursorMode.Auto);
                        }
                        else
                        {
                            Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
                        }
                    }
                    else
                    {
                        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
                        BoardController.instance.ClearListPosibleFloors();
                    }
                    if (monsterSelected.canMove && !monsterSelected.frozen && monsterSelected.canMove && monsterSelected.GetState() == 0 && Input.GetMouseButtonDown(0) && BoardController.instance.floorOver != null)
                    {
                        if (BoardController.instance.IsInPosibleFloors(BoardController.instance.floorOver))
                        {
                            BoardController.instance.DeselectFloorMonsterSelected(monsterSelected.idFloor);
                            monsterSelected.SetFloorToMove(BoardController.instance.floorOver.idFloor);
                            if (isServer)
                            {
                                RpcMoveMonster(monsterSelected.idSpawn, BoardController.instance.floorOver.idFloor);
                            }
                            else
                            {
                                CmdMoveMonster(monsterSelected.idSpawn, BoardController.instance.floorOver.idFloor);
                            }
                        }
                    }
                }
                else
                {
                    if (idFloorMonsterSelected != -1)
                    {
                        BoardController.instance.DeselectFloorMonsterSelected(idFloorMonsterSelected);
                        idFloorMonsterSelected = -1;
                    }
                    Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
                    BoardController.instance.ClearListPosibleFloors();
                }

                if (BoardController.instance.floorOver != null)
                {
                    Floor floorOver = BoardController.instance.floorOver;
                    if (MatchController.instance.playerPlaying == playerNumber)
                    {
                        if (floorOver.isOcupateByMonster)
                        {
                            MonsterController monsterInFloor = MatchController.instance.monstersInGame[MatchController.instance.GetIndexMonsterInGameListWithFloor(BoardController.instance.floorOver.idFloor)];
                            if (monsterInFloor.playerOwner != playerNumber)
                            {
                                if (monsterSelected != null && !monsterSelected.frozen && monsterSelected.canAttack && monsterSelected.monsterMode == 1 && monsterSelected.GetState() == 0)
                                {
                                    List <MonsterController> monstersCanAttack = BoardController.instance.GetMonstersCanAttack(monsterSelected.idFloor, playerNumber, monsterSelected.typeAttack);
                                    for (int i = 0; i < monstersCanAttack.Count; i++)
                                    {
                                        if (monstersCanAttack[i].gameObject == monsterInFloor.gameObject)
                                        {
                                            //si puedo atacar al monstruo seteo el cursor a la espada
                                            Vector2 hotSpot = new Vector2(MatchController.instance.cursorTextures[1].width / 2, MatchController.instance.cursorTextures[1].height / 2);
                                            Cursor.SetCursor(MatchController.instance.cursorTextures[1], hotSpot, CursorMode.Auto);

                                            if (Input.GetMouseButtonDown(0))
                                            {
                                                Debug.Log("Presione sobre un monstruo enemigo");
                                                MatchController.instance.monstersInGame[MatchController.instance.GetIndexMonsterInGameListWithSpawn(monsterSelected.idSpawn)].canAttack = false;
                                                //ataco y dependiendo si soy el servidor o cliente notifico con cmd o rpc
                                                HitMonster(MatchController.instance.GetIndexMonsterInGameListWithSpawn(monsterSelected.idSpawn), MatchController.instance.GetIndexMonsterInGameListWithSpawn(monsterInFloor.idSpawn), monsterSelected.attack);
                                                monsterSelected.AlreadyAttack();
                                                monsterSelected.IHitEnemy(monsterInFloor.idSpawn);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //si no puedo atacar al monstruo seteo el cursor a default
                                    Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
                                }
                            }
                            else
                            {
                                //si no puedo atacar al monstruo seteo el cursor a default
                                Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
                            }
                            if (Input.GetMouseButtonDown(0) && monsterInFloor.playerOwner == playerNumber && !monsterInFloor.king)
                            {
                                Debug.Log("Presione sobre un monstruo propio");
                                if (monsterSelected != null && monsterInFloor.gameObject == monsterSelected.gameObject)
                                {
                                    BoardController.instance.DeselectFloorMonsterSelected(monsterSelected.idFloor);
                                    monsterSelected = null;
                                    BoardController.instance.ClearListPosibleFloors();
                                }
                                else if (monsterSelected != null && monsterInFloor.gameObject != monsterSelected.gameObject)
                                {
                                    BoardController.instance.DeselectFloorMonsterSelected(monsterSelected.idFloor);
                                    monsterSelected        = monsterInFloor;
                                    idFloorMonsterSelected = monsterInFloor.idFloor;
                                }
                                else if (monsterSelected == null)
                                {
                                    monsterSelected        = monsterInFloor;
                                    idFloorMonsterSelected = monsterInFloor.idFloor;
                                }
                            }

                            if (Input.GetMouseButtonDown(1) && monsterInFloor.canChangeMode && !monsterInFloor.frozen && monsterInFloor.playerOwner == playerNumber && !monsterInFloor.king)
                            {
                                Debug.Log("Presione click derecho sobre un monstruo propio");
                                monsterInFloor.ChangeNextMonsterMode();
                                if (!isServer)
                                {
                                    CmdChangeModeMonster(monsterInFloor.idSpawn);
                                }
                                else
                                {
                                    RpcChangeModeMonster(monsterInFloor.idSpawn);
                                }
                            }
                        }
                    }

                    //muestra la carta sobre la que tengo el mouse

                    if (floorOver.isOcupateByMonster || floorOver.haveTrap)
                    {
                        if (!MatchController.instance.draggingCard)
                        {
                            timerMouseOnMonster += Time.deltaTime;

                            if (timerMouseOnMonster > 0.5f && !showingCard)
                            {
                                //los typecard al igual que la variables que se repiten con id spawn playerowner, etc, pasarlas a una clase en comun a los monstruos y el resto de las cartas

                                if (floorOver.isOcupateByMonster)
                                {
                                    DestroyCardShow();
                                    cardShowing = Instantiate(prefabCard[0], HandController.instance.transform.position, Quaternion.identity);
                                    cardShowing.GetComponent <CardController>().card = cards[MatchController.instance.monstersInGame[MatchController.instance.GetIndexMonsterInGameListWithFloor(floorOver.idFloor)].idCard];
                                    cardShowing.GetComponent <CardController>().DontDestroyCard();
                                    cardShowing.GetComponent <Dragg>().enabled = false;
                                }
                                if (floorOver.haveTrap && MatchController.instance.trapsInGame[MatchController.instance.GetIndexTrapsInGameListWithFloor(floorOver.idFloor)].playerOwner == playerNumber)
                                {
                                    if (floorOver.isOcupateByMonster)
                                    {
                                        DestroyCardShow2();
                                        cardShowing2 = Instantiate(prefabCard[1], HandController.instance.transform.position, Quaternion.identity);
                                        cardShowing2.GetComponent <CardController>().card = cards[MatchController.instance.trapsInGame[MatchController.instance.GetIndexTrapsInGameListWithFloor(floorOver.idFloor)].idCard];
                                        cardShowing2.GetComponent <CardController>().DontDestroyCard();
                                        cardShowing2.GetComponent <Dragg>().enabled = false;
                                    }
                                    else
                                    {
                                        DestroyCardShow();
                                        cardShowing = Instantiate(prefabCard[1], HandController.instance.transform.position, Quaternion.identity);
                                        cardShowing.GetComponent <CardController>().card = cards[MatchController.instance.trapsInGame[MatchController.instance.GetIndexTrapsInGameListWithFloor(floorOver.idFloor)].idCard];
                                        cardShowing.GetComponent <CardController>().DontDestroyCard();
                                        cardShowing.GetComponent <Dragg>().enabled = false;
                                    }
                                }
                                if (cardShowing != null)
                                {
                                    cardShowing.transform.SetParent(CMainCanvas.Inst.transform);

                                    cardShowing.transform.localScale = new Vector3(1, 1, 1);

                                    Vector2 ViewportPosition           = Camera.main.WorldToViewportPoint(floorOver.transform.position);
                                    Vector2 WorldObject_ScreenPosition = new Vector2(
                                        ((ViewportPosition.x * CMainCanvas.Inst.GetCanvas().transform.RT().sizeDelta.x) - (CMainCanvas.Inst.GetCanvas().transform.RT().sizeDelta.x *0.5f)),
                                        ((ViewportPosition.y * CMainCanvas.Inst.GetCanvas().transform.RT().sizeDelta.y) - (CMainCanvas.Inst.GetCanvas().transform.RT().sizeDelta.y *0.5f)));
                                    cardShowing.transform.localRotation = Quaternion.Euler(0, 0, 0);
                                    WorldObject_ScreenPosition.x       += 100;
                                    WorldObject_ScreenPosition.y       += 50;
                                    cardShowing.transform.RT().anchoredPosition = WorldObject_ScreenPosition;
                                }


                                if (cardShowing2 != null)
                                {
                                    cardShowing2.transform.SetParent(CMainCanvas.Inst.transform);

                                    cardShowing2.transform.localScale = new Vector3(1, 1, 1);
                                    Vector2 ViewportPosition           = Camera.main.WorldToViewportPoint(floorOver.transform.position);
                                    Vector2 WorldObject_ScreenPosition = new Vector2(
                                        ((ViewportPosition.x * CMainCanvas.Inst.GetCanvas().transform.RT().sizeDelta.x) - (CMainCanvas.Inst.GetCanvas().transform.RT().sizeDelta.x *0.5f)),
                                        ((ViewportPosition.y * CMainCanvas.Inst.GetCanvas().transform.RT().sizeDelta.y) - (CMainCanvas.Inst.GetCanvas().transform.RT().sizeDelta.y *0.5f)));
                                    cardShowing2.transform.localRotation = Quaternion.Euler(0, 0, 0);
                                    WorldObject_ScreenPosition.x        += 250;
                                    WorldObject_ScreenPosition.y        += 50;
                                    cardShowing2.transform.RT().anchoredPosition = WorldObject_ScreenPosition;
                                }



                                showingCard = true;
                            }
                        }
                    }
                    else
                    {
                        ResetShowCard();
                    }
                }
                else
                {
                    ResetShowCard();
                }
                if (Input.GetMouseButtonDown(1) && !MatchController.instance.activatingCard && (BoardController.instance.floorOver == null || !BoardController.instance.floorOver.isOcupateByMonster || MatchController.instance.monstersInGame[MatchController.instance.GetIndexMonsterInGameListWithFloor(BoardController.instance.floorOver.idFloor)].playerOwner != playerNumber))
                {
                    if (monsterSelected != null)
                    {
                        BoardController.instance.DeselectFloorMonsterSelected(monsterSelected.idFloor);
                        monsterSelected = null;
                        BoardController.instance.ClearListPosibleFloors();
                        Debug.Log("Deseleccione mi monstruo");
                    }
                }
            }
        }
    }