package TileData import Entity import Assets import RegionData import Json public function vec2.toTile() returns vec2 return vec2((this.x / 128.).round()*128. ,(this.y / 128.).round()*128.) public enum Tile UNWALKABLE WALKABLE LAVA POISON ICE_NORMAL ICE_DARK ICE_REVERSE public class TileData implements Serializable int xoff int yoff vec2 pos effect fx player owner Tile tile = Tile.WALKABLE construct() construct(vec2 realpos, int xoff, int yoff, player owner) this.pos = realpos this.xoff = xoff this.yoff = yoff this.owner = owner this.fx = addEffect(Abilities.vengeanceMissile, pos) ondestroy if fx != null fx.destr() override function serialize() returns Json this.tile = getTileFromType(pos) let json = new Json() ..addProperty(new Property(KEY_X, (xoff - (serializeOrigin.x / 128)).toInt().toString())) ..addProperty(new Property(KEY_Y, (yoff - (serializeOrigin.y / 128)).toInt().toString())) if tile != Tile.WALKABLE json..addProperty(new Property(KEY_TYPE, (tile castTo int).toString())) return json override function deserialize(Json json) xoff = json.getInt(KEY_X) yoff = json.getInt(KEY_Y) pos = vec2(serializeOrigin.x + xoff * 128., serializeOrigin.y + yoff * 128.).toTile() if not getRegionData(pos).canBuild(owner) return tile = json.getInt(KEY_TYPE) castTo Tile if tile == Tile.UNWALKABLE tile = Tile.WALKABLE let rdat = getRegionData(pos) switch tile case WALKABLE pos.setTerrainType(rdat.getTypeSet().walkableId, -1, 1, 0) case ICE_NORMAL pos.setTerrainType(CONTROLLABLEICE, -1, 1, 0) case ICE_DARK pos.setTerrainType(UNCONTROLLABLEICE, -1, 1, 0) case ICE_REVERSE pos.setTerrainType(REVICE, -1, 1, 0) case LAVA pos.setTerrainType(LAVA, -1, 1, 0) case POISON pos.setTerrainType(POISON, -1, 1, 0) default pos.setTerrainType(rdat.getTypeSet().walkableId, -1, 1, 0) public function getTileFromType(vec2 pos) returns Tile let ttype = GetTerrainType(pos.x, pos.y) let rdat = getRegionData(pos) switch ttype case rdat.getTypeSet().walkableId return Tile.WALKABLE case REVICE return Tile.ICE_REVERSE case CONTROLLABLEICE return Tile.ICE_NORMAL case UNCONTROLLABLEICE return Tile.ICE_DARK case 1147958883 return Tile.LAVA case POISON return Tile.POISON return Tile.UNWALKABLE