public GetPosition ( Placement placement, int border = -1 ) : int[] | ||
placement | Placement | |
border | int | |
return | int[] |
public int[] GetPosition(Placement placement, int border = -1)
{
if (this.PlaceIndex == -1)
throw new PuzzleException("Place hasn't been declared anything or it wasn't reserved.");
// todo: check those values
var radius = 0;
if (border >= 0)
{
radius = (_room.RoomType == RoomType.Alley ? 200 - border : 800 - border);
if (radius < 0)
radius = 0;
}
else
radius = (_room.RoomType == RoomType.Alley ? 200 : 800);
if (!_placementProviders.ContainsKey(placement))
_placementProviders[placement] = new PlacementProvider(placement, radius);
var pos = _placementProviders[placement].GetPosition();
if (pos == null)
{
if (!_placementProviders.ContainsKey(Placement.Random))
_placementProviders[Placement.Random] = new PlacementProvider(Placement.Random, radius);
pos = _placementProviders[Placement.Random].GetPosition();
}
pos[0] += this.X;
pos[1] += this.Y;
return pos;
}
/// <summary> /// Adds prop to puzzle in place. /// </summary> /// <param name="place"></param> /// <param name="prop"></param> /// <param name="positionType"></param> public void AddProp(PuzzlePlace place, DungeonProp prop, Placement positionType) { if (this.Region == null) { throw new PuzzleException("AddProp outside of OnPuzzleCreate."); } var pos = place.GetPosition(positionType); prop.RegionId = this.Region.Id; prop.Info.X = pos[0]; prop.Info.Y = pos[1]; prop.UpdateShapes(); prop.Info.Direction = MabiMath.DegreeToRadian(pos[2]); prop.Behavior += PuzzleEvent; this.Region.AddProp(prop); this.Props[prop.Name] = prop; }