public HexTile(TileMap tileMap, HexTileCoord coord, string name, TileSpecialResourceType specialResource) { TileMap = tileMap; Coord = coord; Name = name; SpecialResource = specialResource; }
public void RemoveTileObject(string typeName, HexTileCoord coord) { if (!IsValidCoord(coord)) { return; } if (!_onTileMapObjects.TryGetValue(coord, out var objs)) { return; } if (!objs.ContainsKey(typeName)) { return; } objs.Remove(typeName); // Remove dictionary if there is no object left if (objs.Count == 0) { _onTileMapObjects.Remove(coord); } }
public IOnHexTileObject AddTileObjectWithName(string typeName, string name, HexTileCoord coord) { switch (typeName) { default: return(null); } }
public int GetDistanceOfTwoTile(HexTileCoord c1, HexTileCoord c2) { if (!IsValidCoord(c1) || !IsValidCoord(c2)) { return(-1); } return((Math.Abs(c1.Q - c2.Q) + Math.Abs(c1.Q + c1.R - c2.Q - c2.R) + Math.Abs(c1.R - c2.R)) / 2); }
public void AddTileObject(IOnHexTileObject obj, HexTileCoord coord) { if (!_onTileMapObjects.ContainsKey(coord)) { _onTileMapObjects.Add(coord, new Dictionary <string, IOnHexTileObject>()); } var objDict = _onTileMapObjects[coord]; if (objDict.ContainsKey(obj.TypeName)) { return; } objDict[obj.TypeName] = obj; }
public HexTile GetHexTile(HexTileCoord coord) { if (!IsValidCoord(coord)) { return(null); } var q = coord.Q; var r = coord.R; if (r < Radius) { q = q - Radius + r; } return(_tileMap[r][q]); }
public (float x, float y) ToCartesian(HexTileCoord coord) { if (!IsValidCoord(coord)) { return(0, 0); } var q = coord.Q - Radius; var r = coord.R - Radius; var sqrt3 = (float)Math.Sqrt(3); var x = sqrt3 * q + sqrt3 / 2 * r; var y = 1.5f * r; return(x, y); }
public bool DoAction(HexTileCoord coord) { if (!IsAvailable) { return(false); } if (NeedCoordinate && !AvailableTiles.Contains(coord)) { return(false); } if (!_owner.CheckSpecialActionCost(GetCost(coord))) { return(false); } _owner.ConsumeSpecialActionCost(GetCost(coord)); _core.DoAction(_owner, coord); return(true); }
public IReadOnlyList <IOnHexTileObject> GetAllTileObjects(HexTileCoord coord) => !_onTileMapObjects.TryGetValue(coord, out var result) ? new List <IOnHexTileObject>() : result.Values.ToList();
/// <summary> /// Is it valid coordinate on this tile map? /// </summary> public bool IsValidCoord(HexTileCoord coord) => coord.Q + coord.R >= Radius && coord.Q + coord.R <= 3 * Radius;
public bool IsTileObjectExists(string typeName, HexTileCoord coord) => _onTileMapObjects.TryGetValue(coord, out var objDict) && objDict.ContainsKey(typeName);
public bool IsInRange(HexTileCoord coord) => _infos.Values.Any(info => info.Tiles.Contains(coord));
public IReadOnlyDictionary <string, int> GetCost(HexTileCoord coord) => _core.GetCost(_owner, coord);