/// <summary> /// Executes random actions with the next pieces over the state of node /// </summary> /// <param name="node"></param> /// <returns></returns> protected virtual float Rollout(MCTSNode node) { TetrisState newState = node.state.CloneState(); int nPieces = 0; float totalScore = node.state.GetScore(); float weight = 1f; float totalWeight = weight; //node.height identifies the height of the node in the MCTreeSearch, but also identifies the index of the piece inside the history of all the pieces played //So, if that node.height plus the number of pieces played in the rollout are bigger than the number of known pieces, then the rollout must stop. //Also it stops if an action has caused a game over while ((node.height + nPieces) < pieces.Count && !newState.IsTerminal()) { weight *= rolloutScoreWeightReduction; totalWeight += weight; PieceModel piece; piece = new PieceModel(pieces[node.height + nPieces]); newState.DoAction(piece, newState.GetRandomAction(piece)); nPieces++; totalScore += newState.GetScore() * weight; } float score = totalScore / totalWeight; rollouts++; return(score); }
public PreviewPiece(Board board, Color color, PieceModel model, int rotationIndex) : base(color, model, rotationIndex, Defaults.Board.PreviewBlockSize) { Board = board; SetPiecePosition(); UpdateBlocksPositions(board.PreviewPanel.Bounds.Location); }
// Vector3 touchPosWorld; // TouchPhase touchPhase = TouchPhase.Began; public bool testWin() { int rows = board.GetLength(0); int cols = board.GetLength(1); int i; int j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { PieceModel p = board[i, j]; if (p == null) { continue; } if (p.color == player) { return(false); } } } return(true); }
public void Move(MoveModel move, ref PieceModel [,] board) { board[move.y, move.x] = this; board[y, x] = null; x = move.x; y = move.y; // next steps here if (move.isCapture()) { PieceModel piece = board[move.capture.removeY, move.capture.removeX]; piece.doRemove(ref board); OnJump(); } else { OnMove(); } //doMove(); if (type == PieceType.KING) { return; } doKinging(ref board); }
/// <summary> /// Uses also the budget in order to make a fair calculation: if the budget is consumed checking the Tetris, then it stops /// </summary> /// <param name="nextPiece"></param> /// <param name="currentTetrisState"></param> /// <param name="possibleActions"></param> /// <param name="budget"></param> /// <returns></returns> protected IEnumerator CheckTetris(PieceModel nextPiece, TetrisState currentTetrisState, List <PieceAction> possibleActions, float budget) { int i = 0; while (t0 < budget && i < possibleActions.Count) { if (!TBController.pausedGame) { t0 += Time.deltaTime; PieceAction action = possibleActions[i]; if (action.rotationIndex == 0) //The I piece is horizontal, not vertical, so it can't be a Tetris { i++; continue; } TetrisState newState = currentTetrisState.CloneState(); newState.DoAction(nextPiece, action); nextPiece.ResetCoordinates(); if (newState.IsTetris()) { bestAction = action; } i++; } yield return(null); } }
public int height; //Identifies in which height of the tree search is public MCTSNode(int id, MCTSNode parent, TetrisState state, PieceAction action, PieceModel currentPiece) { this.id = id; this.parent = parent; this.state = state; this.action = action; this.currentPiece = currentPiece; children = new List <MCTSNode>(); if (parent != null) { height = parent.height + 1; } else { height = 0; } MCTreeSearch.nNodes++; if (height > MCTreeSearch.currentHeight) { MCTreeSearch.currentHeight = height; } }
public void SetGame(GameViewModel model) { GameRoom gameRoom = db.GameRooms.FirstOrDefault(e => e.Id == model.RoomId); List <PieceModel> fark = new List <PieceModel>(); gameRoom.Pieces.ToList().ForEach(g => { PieceModel aPiece = model.Pieces.FirstOrDefault(e => e.Id == g.Id && (e.Row != g.Row || e.Col != g.Col || e.Name != g.Name || e.Status != g.Status)); if (aPiece != null) { fark.Add(aPiece); } }); fark.ForEach(e => { var aPiece = gameRoom.Pieces.Single(k => k.Id == e.Id); if (e.Col == 0 && e.Row == 0) { db.Entry(aPiece).State = EntityState.Deleted; db.SaveChanges(); } else { aPiece.Col = e.Col; aPiece.Row = e.Row; aPiece.Name = e.Name; aPiece.Status = e.Status; aPiece.Symbol = e.Symbol; } }); gameRoom.GameStatus = model.GameStatus; gameRoom.Turn = model.Turn; db.Entry(gameRoom).State = EntityState.Modified; db.SaveChanges(); }
private PieceModel StringToPiece(string p) { PieceModel piece = new PieceModel(); switch (p[0]) { case 'w': piece.Color = Color.White; break; case 'b': piece.Color = Color.Black; break; default: throw new ArgumentException(); } switch (p[1]) { case 'k': piece.Type = PieceType.King; break; case 'q': piece.Type = PieceType.Queen; break; case 'b': piece.Type = PieceType.Bishop; break; case 'r': piece.Type = PieceType.Rook; break; case 'n': piece.Type = PieceType.Knight; break; case 'p': piece.Type = PieceType.Pawn; break; default: throw new ArgumentException(); } return(piece); }
private static string PieceToString(PieceModel p) { string pos = ""; pos += p.Color == Color.White ? "w" : "b"; pos += Utils.GetStringRep(p.Type).ToLower(); return(pos); }
internal void init(PlayerResourcesModel playerResources, PieceModel piece) { abilityButton.onClick.AddListener(() => onClick()); abilityButton.interactable = false; buttonText = abilityButton.GetComponentInChildren<TextMeshProUGUI>(); this.playerResources = playerResources; this.piece = piece; }
public Response AddPieceToSet(int setIndex, string setPlayerName, bool right, PieceModel piece, string playerName) { var(response, game) = _rummyEngine.AddPieceToSet(Game, setIndex, setPlayerName, right, piece, playerName); Game = game; OnDropSetOnTable.Invoke(); return(response); }
static PieceModel ClonePiece(PieceModel piece) { return(new PieceModel() { Type = piece.Type, Color = piece.Color }); }
void AddPiece(Vector3 position, int pieceIndex, int positionalIndex) { if (fetchedPieces.ContainsKey(pieceIndex)) { return; } GameObject pieceCopy = Instantiate(piecePrefab) as GameObject; pieceCopy.transform.position = position; PieceModel pieceModel = pieceCopy.GetComponent <PieceModel>(); pieceModel.pieceIndex = pieceIndex; pieceModel.ToggleFace(faceUp); switch (pieceIndex / 26) { case (0): pieceModel.color = "Red"; break; case (1): pieceModel.color = "Black"; break; case (2): pieceModel.color = "Green"; break; case (3): pieceModel.color = "Yellow"; break; default: pieceModel.color = "Joker"; break; } if (pieceModel.color == "Joker") { pieceModel.value = 20; } else { pieceModel.value = ((pieceIndex / 2) % 13) + 1; if (pieceModel.value == 0) { pieceModel.value = 13; } } SpriteRenderer spriteRenderer = pieceCopy.GetComponent <SpriteRenderer>(); spriteRenderer.sortingOrder = positionalIndex; fetchedPieces.Add(pieceIndex, pieceCopy); }
public static Piece buildPiece(PieceModel pieceModel, GameObject parentObject, GameObject prefab) { GameObject go = GameObject.Instantiate(prefab); Piece p = go.GetComponent <Piece>(); p.setup(pieceModel); p.transform.SetParent(parentObject.transform, false); return(p); }
private bool CanIAnyMoveHelper(GameViewModel model, PieceModel aPiece, Cell cellto, Cell cellfrom) { if (IsCellCorrect(model, cellfrom, cellto)) { if (!model.Pieces.Any(e => e.Col == _cellTo.Col && e.Row == _cellTo.Row && e.Color == aPiece.Color)) { // şah çekilmişse hamle sonrası tehdit kalkıyorsa true Cell cellto1 = cellto; Cell cellFrom1 = new Cell() { Row = cellfrom.Row, Col = cellfrom.Col }; PieceModel yenecek = model.Pieces.Find(e => e.Col == cellto1.Col && e.Row == cellto1.Row); if (yenecek != null) { yenecek.Row = 0; yenecek.Col = 0; } PieceModel oynanacak = model.Pieces.Find(e => e.Col == cellFrom1.Col && e.Row == cellFrom1.Row); oynanacak.Row = cellto1.Row; oynanacak.Col = cellto1.Col; if (IsCheck(model, true)) { if (yenecek != null) { yenecek.Row = cellto1.Row; yenecek.Col = cellto1.Col; } oynanacak.Row = cellFrom1.Row; oynanacak.Col = cellFrom1.Col; return(false); } else { if (yenecek != null) { yenecek.Row = cellto1.Row; yenecek.Col = cellto1.Col; } oynanacak.Row = cellFrom1.Row; oynanacak.Col = cellFrom1.Col; Debug.WriteLine(oynanacak.Color.ToString() + " " + oynanacak.Name); Debug.WriteLine(cellto.Row + "-" + cellto.Col); return(true); } } } return(false); }
private List <Move> GetMovesMan(ref PieceModel[,] board) { // next steps here List <Move> moves = new List <Move>(2); int[] moveX = new int[] { -1, 1 }; int moveY = -1; if (color == PieceColor.BLACK) { moveY = 1; } foreach (int mX in moveX) { int nextX = x + mX; int nextY = y + moveY; if (!IsMoveInBounds(nextX, nextY, ref board)) { continue; } PieceModel p = board[nextY, nextX]; if (p != null && p.color == color) { continue; } MoveModel m = new MoveModel(); m.piece = this; if (p == null) { m.x = nextX; m.y = nextY; } else { int hopX = nextX + mX; int hopY = nextY + moveY; Debug.Log(hopX + " " + hopY); if (!IsMoveInBounds(hopX, hopY, ref board)) { continue; } if (board[hopY, hopX] != null) { continue; } m.x = hopX; m.y = hopY; m.capture = new Capture(nextX, nextY); } moves.Add(m); } return(moves); }
public Response DropPieceOnTable(PieceModel source, string playerName) { var(response, game) = _rummyEngine.AddPieceOnTable(Game, source, playerName); Game = game; OnDropPieceOnTable.Invoke(); if (game.GameEnded) { OnGameEnd.Invoke(); } return(response); }
private List <Move> GetMovesKing(ref PieceModel[,] board) { // next steps here List <Move> moves = new List <Move>(); int[] moveX = new int[] { -1, 1 }; int[] moveY = new int[] { -1, 1 }; foreach (int mY in moveY) { foreach (int mX in moveX) { int nowX = x + mX; int nowY = y + mY; if (IsMoveInBounds(nowX, nowY, ref board)) { PieceModel p = board[nowY, nowX]; if (p != null && p.color == color) { break; } MoveModel m = new MoveModel(); m.piece = this; if (p == null) { m.x = nowX; m.y = nowY; } else { int hopX = nowX + mX; int hopY = nowY + mY; if (!IsMoveInBounds(hopX, hopY, ref board)) { break; } if (board[hopY, hopX] != null) { continue; } m.x = hopX; m.y = hopY; m.capture = new Capture(nowX, nowY); } moves.Add(m); nowX += mX; nowY += mY; } } } return(moves); }
protected PieceBase(Color color, PieceModel model, int rotationIndex, Rectangle blockSize) { Color = color; Model = model; RotationIndex = 0; if (rotationIndex >= 0 && rotationIndex < model.Length) { RotationIndex = rotationIndex; } BlockSize = blockSize; CreateBlocks(Model[RotationIndex]); }
internal static PolyPlayedPiece Create(PositionValue position, PieceModel piece, int index = 0) { var images = piece.Def.GetImages(piece.Player); return(new PolyPlayedPiece { Player = piece.Player.Value, Piece = piece.Piece.Value, Position = position.Value, Flags = piece.AttributeLookup == null ? null : piece.AttributeLookup.Where(a => a.Value == BoolValue.True).Select(a => a.Key).Join(" "), Image = images[index % images.Count].Value, }); }
public void PlacePiece(PieceModel newPiece) { foreach (BlockTileModel block in newPiece.MyTiles) { //Debug.Log("Cordinate" + (newPiece.position.x + block.local.x)); //WorldModel.TheWorld[newPiece.position.x + block.local.x, newPiece.position.y + block.local.y, newPiece.position.z + block.local.z] = block; // so origin block will have local position of 0,0 but the other ones will add there local XY values to origin. } if (PiecePlacedEvent != null) { PiecePlacedEvent.Invoke(newPiece); } }
/*public void removePiece(int x,int y) * { * gameBoard.map[m.y,m.x].currentPiece = null; * Destroy(board[move.removeY, move.removeX]); * board[move.removeY, move.removeX] = null; * }*/ private void PlacePiece(int x, int y) { // your own transformations // according to space placements Vector3 pos = new Vector3(); pos.x = (float)x; pos.y = -(float)y; PieceModel piece = new PieceModel(x, y, player); board[y, x] = piece; //gameBoard.map[y,x].currentPiece = piece; }
public void AddNewPiece(PointModel pointModel, PlayerModel player) { if (pointModel == null || pointModel.Piece != null) { return; } var pieceModel = new PieceModel() { Color = player.Color }; boardModel.PlaceNewPiece(pieceModel, pointModel); }
public void setup(PieceModel pieceModel) { this.model = pieceModel; setTeam(); if (this.model.type == PieceType.MAN) { crown.SetActive(false); } setPosition(); //watch Model this.model.OnMove += moveTo; this.model.OnJump += jumpTo; this.model.OnDestroyed += destroyMe; this.model.OnKing += kingMe; }
/// <summary> /// Creates the children of this node with a given new piece /// </summary> /// <param name="newCurrentPiece"></param> public void ExtendNode(PieceModel newCurrentPiece) { List <PieceAction> actions = state.GetActions(newCurrentPiece); foreach (PieceAction action in actions) //Each child is related with one of the possible actions for the newCurrentPiece played in the state of this node { TetrisState newState = state.CloneState(); newState.DoAction(newCurrentPiece, action); newCurrentPiece.ResetCoordinates(); MCTSNode newNode = new MCTSNode(MCTreeSearch.nNodes, this, newState, action, newCurrentPiece); children.Add(newNode); } }
public static ChessBoard CloneBoard(ChessBoard board) { PieceModel[,] clone = new PieceModel[8, 8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (board[i, j] != null) { clone[i, j] = ClonePiece(board[i, j]); } } } return(new ChessBoard(clone)); }
public async Task <ActionResult> Post([FromBody] PieceModel pieceModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } PieceDomainModel domainModel = new PieceDomainModel { Description = pieceModel.Description, Genre = pieceModel.Genre, isActive = pieceModel.IsActive, Title = pieceModel.Title, Year = pieceModel.Year }; PieceDomainModel createPiece; try { createPiece = await _pieceService.AddPiece(domainModel); } catch (DbUpdateException e) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = e.InnerException.Message ?? e.Message, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } if (createPiece == null) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = Messages.PIECE_CREATION_ERROR, StatusCode = System.Net.HttpStatusCode.InternalServerError }; return(BadRequest(errorResponse)); } return(CreatedAtAction(nameof(Get), new { Id = createPiece.Id }, createPiece)); }
public void VisualizePossibleTiles() { var moves = PieceModel.Moves(Main.Board); moves = Main.Board.FilterOutIllegalMoves(moves, IsWhite); var borderColor = Brushes.Chartreuse; if (IsWhite != Main.PlayerIsWhite) { borderColor = Brushes.Coral; } foreach (var singleMove in moves) { Main.VisualizationTiles.Add(new Position(singleMove.NewPos.row, singleMove.NewPos.column, borderColor)); } }
/// <summary> /// Clones a piece. It's unused for now /// </summary> /// <returns></returns> public PieceModel ClonePiece() { PieceModel newPiece = new PieceModel(pieceType); newPiece.originalTileCoordinates = new Vector2Int[4]; for (int i = 0; i < originalTileCoordinates.Length; i++) { newPiece.originalTileCoordinates[i] = originalTileCoordinates[i]; } newPiece.tileCoordinates = new Vector2Int[4]; for (int i = 0; i < tileCoordinates.Length; i++) { newPiece.tileCoordinates[i] = tileCoordinates[i]; } return(newPiece); }
public float evaluate(PieceColor color, BoardModel board) { float eval = 1f; float pointSimple = 1f; float pointCapture = 5f; int rows = board.board.GetLength(0); int cols = board.board.GetLength(1); int i; int j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { PieceModel p = board.board[i, j]; if (p == null) { continue; } if (p.color != color) { continue; } Move[] moves = p.GetMoves(ref board.board); foreach (Move mv in moves) { MoveModel m = (MoveModel)mv; if (m.isCapture()) { eval += pointCapture; } else { eval += pointSimple; } } } } return(eval); }
public (Response, RummyModel) AddPieceOnTable(RummyModel game, PieceModel piece, string playerName) { if (!IsPlayerTurn(game, playerName)) { var errorResponse = new ResponseWithPiece { Success = false, Message = "It is not your turn" }; return(errorResponse, game); } if (!game.HasDrawnPiece) { var errorResponse = new ResponseWithPiece { Success = false, Message = "You must draw a piece first" }; return(errorResponse, game); } var tmp = piece.ShallowCopy(); tmp.Location = PieceModel.Locations.Table; game.PiecesOnTable.Insert(game.PiecesOnTable.Count - 1, tmp); game.Players[playerName].PiecesOnBoard.Remove(piece); game.CurrentPlayerTurn = PassTurn(game.PlayerOrder, game.CurrentPlayerTurn); game.HasDrawnPiece = false; if (game.Players[playerName].PiecesOnBoard.Count == 0) { game.GameEnded = true; game.Players[playerName].Score += 50; foreach (var player in game.Players) { player.Value.Score -= CalculateScore(player.Value.PiecesOnBoard); } } var response = new Response { Success = true }; return(response, game); }
protected IEnumerator BotConstructionCoroutine(PieceType[] initialPieces, float budget) { t0 = 0.0f; pieces = new List <PieceType>(initialPieces); PieceModel[] nextPieces = new PieceModel[initialPieces.Length]; for (int i = 0; i < initialPieces.Length; i++) { if (!TBController.pausedGame) { t0 += Time.deltaTime; nextPieces[i] = new PieceModel(initialPieces[i]); } yield return(null); } CreateTree(nextPieces, budget); }
public static PieceModel[,] InitBoard() { PieceModel[,] board = new PieceModel[8, 8]; board[0, 0] = Utils.NewPiece(PieceType.Rook, Color.Black); board[0, 7] = Utils.NewPiece(PieceType.Rook, Color.Black); board[0, 1] = Utils.NewPiece(PieceType.Knight, Color.Black); board[0, 6] = Utils.NewPiece(PieceType.Knight, Color.Black); board[0, 2] = Utils.NewPiece(PieceType.Bishop, Color.Black); board[0, 5] = Utils.NewPiece(PieceType.Bishop, Color.Black); board[0, 3] = Utils.NewPiece(PieceType.Queen, Color.Black); board[0, 4] = Utils.NewPiece(PieceType.King, Color.Black); for (int i = 0; i < 8; i++) { board[1, i] = Utils.NewPiece(PieceType.Pawn, Color.Black); } board[7, 0] = Utils.NewPiece(PieceType.Rook, Color.White); board[7, 7] = Utils.NewPiece(PieceType.Rook, Color.White); board[7, 1] = Utils.NewPiece(PieceType.Knight, Color.White); board[7, 6] = Utils.NewPiece(PieceType.Knight, Color.White); board[7, 2] = Utils.NewPiece(PieceType.Bishop, Color.White); board[7, 5] = Utils.NewPiece(PieceType.Bishop, Color.White); board[7, 3] = Utils.NewPiece(PieceType.Queen, Color.White); board[7, 4] = Utils.NewPiece(PieceType.King, Color.White); for (int i = 0; i < 8; i++) { board[6, i] = Utils.NewPiece(PieceType.Pawn, Color.White); } return(board); }
public void CopyPieceToCard(PieceModel src, CardModel dest, bool link) { var templateCard = cardDirectory.Card(src.cardTemplateId); dest.cardTemplateId = src.cardTemplateId; dest.playerId = src.playerId; dest.name = templateCard.name; dest.description = templateCard.description; dest.cost = templateCard.cost; dest.baseCost = templateCard.baseCost; dest.attack = src.attack; dest.health = src.health; dest.movement = src.movement; dest.range = src.range; dest.tags = src.tags; dest.statuses = src.statuses; dest.metCondition = false; if (link) { dest.linkedPiece = src; } }
//private void DeterminePiecesColors() //{ // _colors = GetShuffledColors(); // for (int i = 0; i < _pieces.Length; i++) // { // _pieces[i].Color = _colors[i]; // } //} //private Color[] GetShuffledColors() //{ // var randNumbers = new List<int>(); // foreach (var color in _colors) // { // int num; // do // { // num = StaticRandom.Next(_colors.Length); // } // while (randNumbers.Contains(num)); // randNumbers.Add(num); // } // return randNumbers.Select(item => _colors[item]).ToArray(); //} private PreviewPiece GetRandomPiece() { var modelIndex = _randomBag.Next(); var model = new PieceModel(_pieces[modelIndex]); return new PreviewPiece(_board, _pieces[modelIndex].Color, model, rotationIndex: 0); }
private void onPieceDragging(PieceModel p) { view.setDragEnabled(p == null); }
public PieceModel CreatePiece(SpawnPieceModel spawnedPiece, string name = null) { GameObject pieceModelResource = resourceLoader.Load<GameObject>("Models/" + spawnedPiece.cardTemplateId + "/prefab"); var piecePrefab = resourceLoader.Load<GameObject>("Piece"); //position is x and z from server, and y based on the map var spawnPosition = map.tiles[spawnedPiece.position.Vector2].fullPosition; var newPiece = GameObject.Instantiate( piecePrefab, spawnPosition, Quaternion.identity ) as GameObject; newPiece.transform.parent = contextView.transform; newPiece.name = "Piece " + spawnedPiece.pieceId; //Set up new model if we have one if (pieceModelResource != null) { var pieceModelChild = newPiece.transform.FindChild("Model"); pieceModelChild.DestroyChildren(true); var newModelInstance = GameObject.Instantiate(pieceModelResource, pieceModelChild, false) as GameObject; newModelInstance.transform.localPosition = Vector3.zero; //newModelInstance.transform.localRotation = Quaternion.Euler(new Vector3(-90f, 0, 0)); } var opponentId = gamePlayers.OpponentId(turnModel.currentPlayerId); var cardTemplate = cardDirectory.Card(spawnedPiece.cardTemplateId); var pieceModel = new PieceModel() { id = spawnedPiece.pieceId.Value, playerId = spawnedPiece.playerId, cardTemplateId = spawnedPiece.cardTemplateId, currentPlayerHasControl = spawnedPiece.playerId != opponentId, gameObject = newPiece, attack = cardTemplate.attack, health = cardTemplate.health, baseAttack = cardTemplate.attack, baseHealth = cardTemplate.health, tilePosition = spawnPosition.ToTileCoordinates(), direction = spawnedPiece.direction, movement = cardTemplate.movement, baseMovement = cardTemplate.movement, range = cardTemplate.range, baseRange = cardTemplate.range, tags = spawnedPiece.tags, buffs = new List<PieceBuffModel>(), statuses = cardTemplate.statuses, }; SetInitialMoveAttackStatus(pieceModel); var pieceView = newPiece.AddComponent<PieceView>(); pieceView.piece = pieceModel; pieceView.opponentId = opponentId; pieceView.currentTurnPlayerId = turnModel.currentPlayerId; piecesModel.Pieces.Add(pieceModel); return pieceModel; }
private void onPieceHovered(PieceModel piece) { //hovering cards takes priority so don't hide/show if we're hovering from a card if(hoveringCard) return; if (piece != null) { view.showPieceCardWorld(piece, piece.gameObject.transform.position, possibleActions.GetSpellDamage(piece.playerId)); //debug.Log("Hovering from piece"); } else { view.hideCard(); //debug.Log("Hiding from piece"); } }
public void CopyPropertiesFromPiece(PieceModel src, PieceModel dest) { dest.name = src.name; dest.cardTemplateId = src.cardTemplateId; dest.attack = src.attack; dest.baseAttack = src.baseAttack; dest.health = src.health; dest.baseHealth = src.baseHealth; dest.movement = src.movement; dest.baseMovement = src.movement; dest.range = src.range; dest.baseRange = src.baseRange; dest.tags = src.tags; dest.statuses = src.statuses; dest.buffs = src.buffs; }
private void onTargetAbilityCancel(PieceModel card) { disableTargetCandidate(); }
private void onTargetAbilitySelected(StartAbilityTargetModel c, PieceModel m) { disableTargetCandidate(); }
private void onPieceDied(PieceModel p) { checkEnemiesInRange(); }
private void onAbilityCancelSelectTarget(PieceModel card) { view.disable(); }
private void onPieceSelected(PieceModel pieceSelected) { if (selectedPiece != null) { selectedPiece.isSelected = false; } selectedPiece = pieceSelected; if (selectedPiece != null) { selectedPiece.isSelected = true; } }
internal void showPieceCardWorld(PieceModel piece, Vector3 worldPosition, int spellDamage) { pieceService.CopyPieceToCard(piece, hoverCardView.card, true); hoverCardView.UpdateBuffsDisplay(); hoverCardView.rectTransform.SetAnchor(topLeftAnchor); var hWidth = hoverCardView.rectTransform.sizeDelta; var position = new Vector2(hWidth.x / 2, -hWidth.y / 2) + (topLeftOffset * canvas.scaleFactor); showCard(new Vector3(position.x, position.y, zPos), spellDamage); }
private void onPieceDied(PieceModel piece) { if (selectedPiece != null && piece.id == selectedPiece.id) { selectedPiece = null; } updateTauntTiles(piece); view.onTileSelected(null); view.toggleTileFlags(null, TileHighlightStatus.Movable); setAttackRangeTiles(null); onPieceHover(null); }
private void onTargetCancel(PieceModel card) { startTargetModel = null; }
private void onPieceHover(PieceModel piece) { if(isDeployingPiece) return; if (piece != null && selectedPiece == null && !FlagsHelper.IsSet(piece.statuses, Statuses.Paralyze) && !FlagsHelper.IsSet(piece.statuses, Statuses.Root) ) { //check for ranged units first since they can't move and attack if (piece.range.HasValue && piece.attack > 0) { var attackRangeTiles = mapService.GetTilesInRadius(piece.tilePosition, piece.range.Value); setAttackRangeTiles(attackRangeTiles.Values.ToList(), !piece.currentPlayerHasControl); } else { //melee units var movePositions = mapService.GetMovementTilesInRadius(piece.tilePosition, piece.movement, piece.playerId); var moveTiles = movePositions.Values.ToList(); List<Tile> attackTiles = null; if (piece.attack > 0) { var attackPositions = mapService.Expand(movePositions.Keys.ToList(), 1); attackTiles = attackPositions.Values.ToList(); //find diff to get just attack tiles attackTiles = attackTiles.Except(moveTiles).ToList(); } //take out the central one var center = moveTiles.FirstOrDefault(t => t.position == piece.tilePosition); moveTiles.Remove(center); //TODO: take friendly units out of move and untargetable enemies like Cloak view.toggleTileFlags(moveTiles, TileHighlightStatus.MoveRange, true); setAttackRangeTiles(attackTiles, !piece.currentPlayerHasControl); } } else { if (selectedPiece == null) { view.toggleTileFlags(null, TileHighlightStatus.MoveRange, true); setAttackRangeTiles(null); } } //attacking enemy at range if ( selectedPiece != null && selectedPiece.attackCount < selectedPiece.maxAttacks && piece != null && piece != selectedPiece && selectedPiece.range.HasValue ) { if (mapService.TileDistance(selectedPiece.tilePosition, piece.tilePosition) <= selectedPiece.range.Value) { var gameTile = map.tiles.Get(piece.tilePosition); view.onAttackTile(gameTile); } else { view.onAttackTile(null); } } else { view.onAttackTile(null); } }
private void onAbilitySelectTarget(StartAbilityTargetModel card, PieceModel piece) { view.disable(); }
private void onPieceMove(PieceModel piece) { updateTauntTiles(); }
private void onSelectedTarget(StartAbilityTargetModel targetModel, PieceModel piece) { if(targetModel.targetingPiece.id != view.ability.pieceId) return; activateAbility.Dispatch(new ActivateAbilityModel() { piece = targetModel.targetingPiece, optionalTarget = piece }); startTargetModel = null; }
private void onPieceSelected(PieceModel selectedPiece) { if(isDeployingPiece) return; if (selectedPiece == null) { this.selectedPiece = null; view.onTileSelected(null); view.toggleTileFlags(null, TileHighlightStatus.Movable, true); setAttackRangeTiles(null); view.toggleTileFlags(null, TileHighlightStatus.MoveRange); return; } //check for attack range tiles if (selectedPiece.range.HasValue) { if (selectedPiece.canAttack) { var attackTiles = mapService.GetTilesInRadius(selectedPiece.tilePosition, selectedPiece.range.Value); setAttackRangeTiles(attackTiles.Values.ToList(), false); } else { setAttackRangeTiles(null, false); } } //set movement and tile selected highlights if ( FlagsHelper.IsSet(selectedPiece.statuses, Statuses.Paralyze) || FlagsHelper.IsSet(selectedPiece.statuses, Statuses.Root) || selectedPiece.movement <= 0 ) { return; } var gameTile = map.tiles.Get(selectedPiece.tilePosition); this.selectedPiece = selectedPiece; view.onTileSelected(gameTile); if (!selectedPiece.hasMoved) { //find movement var moveTiles = mapService.GetMovementTilesInRadius(gameTile.position, selectedPiece.movement, selectedPiece.playerId); //take out the central one moveTiles.Remove(gameTile.position); view.toggleTileFlags(moveTiles.Values.ToList(), TileHighlightStatus.Movable, true); } }
private void updateTauntTiles(PieceModel deadPiece = null) { var tauntPieces = pieces.Pieces.Where(p => FlagsHelper.IsSet(p.statuses, Statuses.Taunt) && (deadPiece == null || p != deadPiece)); var friendlyTauntTiles = new List<Tile>(); var enemyTauntTiles = new List<Tile>(); foreach (var tauntPiece in tauntPieces) { var kingTiles = mapService.GetKingTilesInRadius(tauntPiece.tilePosition, 1); //filter tiles that are too high/low to protect kingTiles = kingTiles.Where(t => mapService.isHeightPassable(t.Value, mapService.Tile(tauntPiece.tilePosition)) ).ToDictionary(k => k.Key, v => v.Value); if (tauntPiece.currentPlayerHasControl) { friendlyTauntTiles.AddRange(kingTiles.Values); } else { enemyTauntTiles.AddRange(kingTiles.Values); } } if (friendlyTauntTiles.Count > 0) { view.toggleTileFlags(friendlyTauntTiles.Distinct().ToList(), TileHighlightStatus.FriendlyTauntArea); } else { view.toggleTileFlags(null, TileHighlightStatus.FriendlyTauntArea); } if (enemyTauntTiles.Count > 0) { view.toggleTileFlags(enemyTauntTiles.Distinct().ToList(), TileHighlightStatus.EnemyTauntArea); } else { view.toggleTileFlags(null, TileHighlightStatus.EnemyTauntArea); } }
private PieceModel CopyPiece(PieceModel src) { var dst = new PieceModel(); src.CopyProperties(dst); dst.gameObject = null; //don't need the original game object here return dst; }
private void onAnimFinished(PieceModel pieceModel) { if (pieceModel.health <= 0) { animationQueue.Add( new PieceView.DieAnim() { piece = pieceModel, pieceDied = pieceDied } ); } }
public void SetInitialMoveAttackStatus(PieceModel piece) { piece.hasMoved = !FlagsHelper.IsSet(piece.statuses, Statuses.Charge) && piece.range == null; piece.attackCount = FlagsHelper.IsSet(piece.statuses, Statuses.Charge) ? 0 : 9; }