private void WalkOnPosition(FDPosition position, int leftMovePoint, FDMoveRange range) { int moveCost = GetMoveCost(position, creature); if (moveCost == -1 || leftMovePoint < moveCost) { // Nothing to walk return; } // If this is ZOC, stop the move if (!position.AreSame(this.creature.Position) && HasAdjacentEnemy(position)) { return; } int leftPoint = leftMovePoint - moveCost; foreach (FDPosition direction in position.GetAdjacentPositions()) { if (direction.X <= 0 || direction.X > gameField.Width || direction.Y <= 0 || direction.Y > gameField.Height) { continue; } if (range.Contains(direction)) { continue; } // If already occupied by creature FDCreature existing = gameAction.GetCreatureAt(direction); if (existing != null && existing.IsOppositeFaction(creature)) { continue; } if (GetMoveCost(direction, creature) == -1) { // Cannot land on target direction continue; } range.AddPosition(direction, position); positionQueue.Enqueue(new MoveRangeQueueObject(direction, leftPoint)); } }
public void ResolveDistanceFrom(FDPosition originPos, FDPosition terminatePos) { this.originalPosition = originPos; this.distanceDict = new Dictionary <FDPosition, float>(); this.positionQueue = new Queue <FDPosition>(); this.SetKey(originPos, 0); while (positionQueue.Count > 0) { FDPosition pos = positionQueue.Dequeue(); this.Walk(pos); if (pos.AreSame(terminatePos)) { break; } } }
public void TouchCreature(int creatureId) { if (currentDialog != null) { return; } UICreature creature = GetUICreature(creatureId); FDPosition creaturePosition = creature.GetCurrentPosition(); FDPosition cursorPosition = FieldTransform.GetObjectUnitPosition(gameCursor.transform.localPosition); if (!creaturePosition.AreSame(cursorPosition)) { gameCursor.transform.localPosition = FieldTransform.GetObjectPixelPosition(FieldTransform.FieldObjectLayer.Ground, creaturePosition.X, creaturePosition.Y); } else { // Do the actuall game event gameManager.HandleOperation(creaturePosition); } }