public void OnGridSpotClick(GridSpot spot) { if (selectedHandCard != null) { if (selectedHandCard.IsValidTarget(spot)) { CurrentMana = Mathf.Max(0, CurrentMana - selectedHandCard.ManaCost); selectedHandCard.Cast(spot); UpdateGridVisuals(); } } else { if (spot.gridEntity != selectedBoardFightCreature) { if (selectedFightCreatureMoveSet.GetElement(spot) != null) { selectedBoardFightCreature.GoTo(spot, selectedFightCreatureMoveSet); } else { SelectEntity(spot.gridEntity); } UpdateGridVisuals(); } } }
public void Cast(GridSpot spot) { switch (cardDefinition.cardCategory) { case CardCategory.Creature: FightManager.instance.SpawnCreature(this, true, spot); OnCardFinishedCasting(); break; case CardCategory.InstantSpell: switch (cardDefinition.cardType) { case CardDefinitionType.Fireball: castTarget = spot; GlobalGameManager.Instance.OnBusyElement(this); PlayGrid.Instance.gridFeedbackManager.FireProjectile(this, PlayGrid.Instance.mc, spot, OnFeedbackHit, OnCardFinishedCasting); break; default: Debug.LogError("Error: card type " + cardDefinition.cardType + " isn't handled in Cast method."); break; } break; } }
public void SpawnCreature(Card creatureCard, bool ally, GridSpot initialSpot = null) { if (creatureCard.cardDefinition.cardCategory != CardCategory.Creature) { Debug.LogError("Error: trying to spawn " + creatureCard.cardDefinition.cardType + " but it's not a creature."); return; } GridSpot spawnSpot = initialSpot; int remainingTries = 20; while ((spawnSpot == null || !creatureCard.IsValidTarget(spawnSpot)) && remainingTries > 0) { int x = UnityEngine.Random.Range(0, PlayGrid.size); int y = UnityEngine.Random.Range(0, PlayGrid.size); spawnSpot = grid.GetSpot(x, y); remainingTries--; } if (spawnSpot != null) { FightCreature newCreature = grid.SpawnFightCreature(creatureCard, spawnSpot, ally); if (ally) { allyCreatures.Add(newCreature); } else { enemyCreatures.Add(newCreature); } } }
public void Fill(GridSpot start, int maxDistance, PlayGrid grid) { Clear(); startSpot = start; elements.Add(new MoveSetElement(startSpot, null, 0)); Explore(elements[0], 0, maxDistance, grid); }
static SeatingLayout ParseInputAndCreateSeatingLayout(string input) { var rows = input.Split(new char[] { '\n' }).Select(e => e.Trim()).ToArray(); GridSpot[,] spots = new GridSpot[rows.Length, rows[0].Length]; for (int i = 0; i < rows.Length; i++) { for (int j = 0; j < rows[0].Length; j++) { GridSpot spot; if (rows[i][j] == '.') { spot = new Floor(i, j); } else if (rows[i][j] == 'L') { spot = new Seat(i, j); } else { throw new ArgumentException("Unrecognized character " + rows[i][j]); } spots[i, j] = spot; } } return(new SeatingLayout(spots)); }
public void Init(Card creatureCard, GridSpot initialSpot, bool ally) { health = creatureCard.Health; damage = creatureCard.Damage; range = creatureCard.Range; moves = creatureCard.Moves; creatureImage.sprite = creatureCard.cardDefinition.sprite; float spriteScale = creatureCard.cardDefinition.scale; if (spriteScale < 0.1f) spriteScale = 1f; creatureImage.transform.localScale = Vector3.one * creatureImage.transform.localScale.x * spriteScale; healthLabel.text = health.ToString(); attackLabel.text = damage.ToString(); isAlly = ally; isMC = creatureCard.cardDefinition.cardType == CardDefinitionType.MC; card = creatureCard; currentGridSpot = initialSpot; turnRemainingMoves = moves; }
public void FireProjectile(Card owner, FightCreature caster, GridSpot target, Action onHit, Action onEnd) { ProjectileFeedback newProjectile = Instantiate(projectileModel, projectileModel.transform.parent).GetComponent <ProjectileFeedback>(); newProjectile.gameObject.SetActive(true); newProjectile.FireProjectile(owner, caster, target, onHit, onEnd); }
void OnCardFinishedCasting() { if (castTarget != null && castTarget.gridEntity != null && castTarget.gridEntity is FightCreature) { (castTarget.gridEntity as FightCreature).ProcessHealth(); } castTarget = null; FightManager.instance.OnCardCastEnded(); }
public void OnNewGridCard(Card card, GridSpot spot) { GridCardUI newCardUI = Instantiate(gridCardUIModel.gameObject, gridCardUIModel.transform.parent).GetComponent <GridCardUI>(); newCardUI.gameObject.SetActive(true); newCardUI.Init(card, spot); newCardUI.transform.localPosition = spot.transform.localPosition; spot.OnEntityEnters(newCardUI); }
public GridSpot.GridSpotVisualState GetGridSpotVisualState(GridSpot spot) { switch (CurrentGameState) { case GameState.Fight: return(fightManager.GetGridSpotVisualState(spot)); } return(0); }
public void GoTo(GridSpot destination, PlayGrid.MoveSet moveSet) { if(moveSet.GetPath(destination, ref currentPath)) { turnRemainingMoves -= currentPath.Count; GlobalGameManager.Instance.OnBusyElement(this); StartPathStep(); } }
public void ResetGridPoint(int x, int y) { themeGrid[y, x] = new GridSpot { from = themeGrid[y, x].to, to = Utils.randm(2f), time = 0f, totalTime = Utils.randm(3f) + 1.2f }; }
private static List <pGridSpot> getNeighbors(GridSpot curr) { List <pGridSpot> toReturn = new List <pGridSpot>(); toReturn.Add(getNeigh(curr, new Vector3(0f, 1f, 0f))); //Up neighbor toReturn.Add(getNeigh(curr, new Vector3(0f, -1f, 0f))); //Down neighbor toReturn.Add(getNeigh(curr, new Vector3(1f, 0f, 0f))); //Right neighbor toReturn.Add(getNeigh(curr, new Vector3(-1f, 0f, 0f))); //Left neighbor return(toReturn); }
void populateMap() { for (int x = 0; x < columns; x++) { for (int y = 0; y < rows; y++) { GridSpot spot = map.getTile(x, y); Instantiate(spot.initSpot(), spot.Coord(), Quaternion.identity); } } }
public void PopulateWithCards() { List <Card> cards = new List <Card>(); cards.Add(GlobalGameManager.Instance.mcCard); cards.AddRange(GlobalGameManager.Instance.ownedCards); for (int i = 0; i < cards.Count && i < size * size; i++) { GridSpot spot = GetSpot(i % size, size - 1 - (i / size)); OnNewGridCard(cards[i], spot); } }
public void FireProjectile(Card owner, FightCreature caster, GridSpot target, Action onHit, Action onEnd) { onHitAction = onHit; onEndAction = onEnd; InitElements(owner.cardDefinition.cardType); transform.position = caster.transform.position; transform.localScale = Vector3.one * 0.0001f; startDate = Time.time; startLocalPosition = transform.localPosition; targetLocalPosition = transform.parent.InverseTransformPoint(target.transform.position); }
// If this wasn't a game jam, this function would definitely not be there public void OnGridSpotClick(GridSpot spot) { switch (CurrentGameState) { case GameState.Fight: fightManager.OnGridSpotClick(spot); break; case GameState.Deckbuilding: deckBuildingManager.OnGridSpotClick(spot); break; } }
private void maybeCreateVerLazer(float chance) { if (chance > Random.Range(0f, 1f)) { GridSpot toPut = getRandomAvailableSpot(7); GameObject lazer = Instantiate(verLazerOriginal); GridableObject script = lazer.GetComponent <GridableObject>(); script.setGridPosition(toPut.getY() + 1, toPut.getX()); grid[toPut.getY(), toPut.getX()] = true; temporaryObjs.Add(lazer); } }
private GridSpot getRandomAvailableSpot(int maxYTreshold) { while (true) { int x = Random.Range(0, ROWSIZE); int y = Random.Range(0, maxYTreshold); if (!grid[y, x]) { GridSpot toReturn = new GridSpot(x, y); return(toReturn); } } }
public bool Attack() { attackTargets.Clear(); for (int i = 1; i <= range; i++) { int passSpotsAmount = i * 2; for (int j = 0; j < 4; j++) { for (int k = 0; k < passSpotsAmount; k++) { int x = currentGridSpot.CoordX; int y = currentGridSpot.CoordY; switch (j) { case 0: x += k - i + 1; y += i; break; case 1: x += i; y -= k - i + 1; break; case 2: x -= k - i + 1; y -= i; break; case 3: x -= i; y += k - i + 1; break; } GridSpot spot = PlayGrid.Instance.GetSpot(x, y); if (spot != null && spot.gridEntity != null && spot.gridEntity is FightCreature && (spot.gridEntity as FightCreature).isAlly != isAlly) { attackTargets.Add(spot.gridEntity as FightCreature); } } } } if (attackTargets.Count > 0) { GlobalGameManager.Instance.OnBusyElement(this); StartNextAttack(); return true; } return false; }
public GridSpot.GridSpotVisualState GetGridSpotVisualState(GridSpot spot) { if (GlobalGameManager.Instance.IsBusy()) return 0; if (selectedFightCreatureMoveSet.GetElement(spot, false) != null) { return GridSpot.GridSpotVisualState.MoveDestination; } if (selectedHandCard != null && selectedHandCard.IsValidTarget(spot)) { return GridSpot.GridSpotVisualState.ValidTarget; } return 0; }
public bool IsValidTarget(GridSpot spot) { switch (cardDefinition.targettingType) { case TargettingType.AnySpot: return(true); case TargettingType.AnyFreeSpot: return(spot.IsFree()); default: Debug.Log("Asking IsValidTarget for unhandled targetting type " + cardDefinition.targettingType); return(false); } }
public MoveSetElement GetElement(GridSpot spot, bool ignoreInitialSpot = true) { if (ignoreInitialSpot && spot == startSpot) { return(null); } for (int s = 0; s < elements.Count; s++) { if (elements[s].spot == spot) { return(elements[s]); } } return(null); }
public void OnGridSpotClick(GridSpot spot) { selectedSpot = spot; if (spot.gridEntity != null) { cardBeingEdited = (spot.gridEntity as GridCardUI).card; editedCard.ShowCard(cardBeingEdited); deckbuildingUI.improvingCardUI.Show(cardBeingEdited); } else { editedCard.ShowUnknownCard(); isCreatingCard = true; deckbuildingUI.createCardUI.Show(); } }
public bool TryAndMoveAI(PlayGrid.MoveSet moveSet) { if (turnRemainingMoves > 0) { FightCreature target = FightManager.instance.GetClosestOpponentCreature(this); if (target != null) { GridSpot destination = moveSet.GetClosestSpot(target.currentGridSpot, turnRemainingMoves); if (destination != currentGridSpot) { GoTo(destination, moveSet); return true; } } } return false; }
public bool GetPath(GridSpot destination, ref List <GridSpot> path) { path.Clear(); MoveSetElement destinationElement = GetElement(destination); if (destinationElement != null) { path.Add(destination); while (destinationElement.previousElement.previousElement != null) { destinationElement = destinationElement.previousElement; path.Insert(0, destinationElement.spot); } return(true); } return(false); }
public void Init(Card _card, GridSpot spot) { card = _card; cardSprite.sprite = card.cardDefinition.sprite; if (card.cardDefinition.cardCategory == CardCategory.Creature) { creatureContainer.SetActive(true); creatureHealthLabel.text = card.Health.ToString(); creatureAttackLabel.text = card.Damage.ToString(); } else { creatureContainer.SetActive(false); } currentGridSpot = spot; }
private static List <GridSpot> waveExpansion(GridSpot curr, GridSpot end, List <GridSpot> path, int marker) { if (curr.Coord().Equals(end.Coord())) //Found endpoint { path.Add(curr); //End point return(path); } List <pGridSpot> neighbors = getNeighbors(curr); foreach (pGridSpot neighbor in neighbors) { if (neighbor == null) { } //No neighbor, collapse the branch else { neighbor.mark = marker; copyMap.addTile(neighbor); //Add marked tile to the temp map stack.Add(neighbor); //Add marked tile to the bottom of the stack } } while (stack.Count > 0) { marker += 1; pGridSpot next = stack[0]; stack.Remove(next); if (next.Coord().Equals(end.Coord())) { waveExpansion(next, end, path, marker); //Go one more time return(path); } else { waveExpansion(next, end, path, marker); } } return(path); }
MoveSetElement TryAndAddOrUpdate(GridSpot spot, MoveSetElement previousElement, int distance) { for (int s = 0; s < elements.Count; s++) { if (elements[s].spot == spot) { if (elements[s].distance > distance || (elements[s].distance == distance && (previousElement.spot.CoordX == spot.CoordX || previousElement.spot.CoordY == spot.CoordY))) { elements[s].Update(previousElement, distance); return(elements[s]); } return(null); } } MoveSetElement result = new MoveSetElement(spot, previousElement, distance); elements.Add(result); return(result); }
// Start is called before the first frame update void Start() { spots = new GridSpot[size][]; for (int i = 0; i < size; i++) { spots[i] = new GridSpot[size]; } float canvasSize = GetComponent <RectTransform>().rect.width /*.sizeDelta.x*/ - margin; GridSpot spotModel = GetComponentInChildren <GridSpot>(); float spotDefaultSize = spotModel.GetComponent <RectTransform>().sizeDelta.x; float spotScale = canvasSize / (size * spotDefaultSize); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { GridSpot spot = spotModel; if (i > 0 || j > 0) { spot = Instantiate(spotModel.gameObject, spotModel.transform.parent).GetComponent <GridSpot>(); } spot.transform.localPosition = new Vector3(i + 0.5f - size / 2f, j + 0.5f - size / 2f, 0f) * canvasSize / size; spot.transform.localScale = Vector3.one * spotScale; spots[i][j] = spot; spot.Init(i, j); } } fightCreatureModel = GetComponentInChildren <FightCreature>(); fightCreatureModel.transform.localScale = Vector3.one * spotScale; fightCreatureModel.gameObject.SetActive(false); gridCardUIModel = GetComponentInChildren <GridCardUI>(); gridCardUIModel.transform.localScale = Vector3.one * spotScale; gridCardUIModel.gameObject.SetActive(false); gridFeedbackManager.transform.localScale = Vector3.one * spotScale; }