//===================================================== private static void ClearCurrentAction() { _currentPlayerAction = ePlayerAction.NULL; _currentInteractiveObject = null; if (GuiManager.Instance != null) { GuiManager.Instance.OnPlayerActionAvailable(_currentPlayerAction); } }
//===================================================== // Store available playerAction and gameObject // - action checked and activated when player uses Action button (see OnPerformActionEvent) e.g. open door public static void OnActionOk(ePlayerAction playerAction, IPlayerInteraction interactiveObject = null, Transform spawnPoint = null) { if (playerAction != ePlayerAction.NULL) { _currentPlayerAction = playerAction; _currentInteractiveObject = interactiveObject; _currentSpawnPoint = spawnPoint; if (GuiManager.Instance != null) { GuiManager.Instance.OnPlayerActionAvailable(_currentPlayerAction); } } else { ClearCurrentAction(); } }
void Update() { float previous = verticalRaw; horizontal = Input.GetAxis("Horizontal"); horizontalRaw = Input.GetAxisRaw("Horizontal"); verticalRaw = Input.GetAxisRaw("Vertical"); if (isGrounded) { dash = Input.GetButton("Dash"); } if (!upKeyDown) { upKeyDown = previous <= 0 && verticalRaw > 0; } if (!downKeyDown) { downKeyDown = previous >= 0 && verticalRaw < 0; } interaction = Input.GetButtonDown("Interaction"); if (Input.GetButtonDown("Jump")) { jump = true; } if (!GetItemRay() && lastDropItem != null) { lastDropItem.HighlightSwitch(false); lastDropItem = null; } if (lastDropItem != null && interaction) { lastDropItem.Apply(); lastDropItem = null; } }
public void TakeTurn(IPlayerInteraction playerInteraction) { int actionsLeft = 1; int buysLeft = 1; Draw(); playerInteraction.DisplayHand(Hand); var endTurn = false; while (actionsLeft + buysLeft > 0 && !endTurn) { int actionChoice = playerInteraction.PromptPlayerForTurnChoice(); switch (actionChoice) { case 1: //Play a Card ChoseAndPlayCard(playerInteraction); actionsLeft--; break; case 2: //Buy a Card BuyCard(playerInteraction); buysLeft--; break; case 3: endTurn = true; break; } } playerInteraction.DisplayHand(Hand); playerInteraction.DisplayBattleField(Battlefield); Gems++; }
private void BuyCard(IPlayerInteraction playerInteraction) { int buyChoice = playerInteraction.PromptPlayerForBuyChoice(); switch (buyChoice) { case 1: Hand.Add(new Card(CardType.Item, true)); Gems = Gems - 5; break; case 2: Hand.Add(new Card(CardType.Spell, true)); Gems = Gems - 5; break; case 3: Hand.Add(new Card(CardType.Action, true)); Gems = Gems - 5; break; } }
private void ChoseAndPlayCard(IPlayerInteraction playerInteraction) { Card chosenCard = playerInteraction.PromptPlayerForCardToPlay(Hand); PlaceCard(chosenCard); }
// This will get sent from an IPlayerInteractable public void ReceivePlayerInteraction(IPlayerInteraction interaction) { _CurrentEquipable?.Unequip(this, interaction); }
bool GetItemRay() { RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, itemLayer); RaycastHit2D[] hits; hits = Physics2D.BoxCastAll(transform.position, new Vector2(Player.X, boxHeight), 0, Vector2.down, Player.Y / 2f, itemLayer); if (hits.Length > 0) //if no object was found there is no minimum { float min = hits[0].distance; //lets assume that the minimum is at the 0th place int minIndex = 0; //store the index of the minimum because thats hoow we can find our object for (int i = 1; i < hits.Length; ++i)// iterate from the 1st element to the last.(Note that we ignore the 0th element) { if (hits[i].transform != gameObject.transform && hits[i].distance < min) //if we found smaller distance and its not the player we got a new minimum { min = hits[i].distance; //refresh the minimum distance value minIndex = i; //refresh the distance } } IPlayerInteraction temp = hits[minIndex].collider.GetComponent <IPlayerInteraction>(); if (lastDropItem != null) { lastDropItem.HighlightSwitch(false); } if (temp != null) { temp.HighlightSwitch(true); } lastDropItem = temp; } else { hit = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, portalLayer); if (hit.collider != null) { IPlayerInteraction temp = hit.collider.GetComponent <IPlayerInteraction>(); if (lastDropItem != null) { lastDropItem.HighlightSwitch(false); } if (temp != null) { temp.HighlightSwitch(true); } lastDropItem = temp; } } return(hit.collider != null || hits.Length > 0); }