public Tiles(Texture2D texture, TileType tileType, TileAction tileAction) { this.texture = texture; this.tileType = tileType; this.tileAction = tileAction; this.getWidth(); this.getHeight(); }
public void PerformAction( TileAction _action ) { if( m_actionIdx < (m_actionsHistoric.Count - 1) && m_actionsHistoric.Count > 0 ) { m_actionsHistoric.RemoveRange( m_actionIdx+1, m_actionsHistoric.Count - m_actionIdx - 1 ); } m_actionsHistoric.Add( _action ); ++m_actionIdx; _action.DoAction( MyAutoTileMap ); }
public Tile(string id, string name, TileType tileType, string color, Style style, Coordinate coordinate, TileAction action, string actionURI, string content = null, ContentType? correspondingScreenContentType = null, Dictionary<string, Tile> subTiles = null) { Id = id; Name = name; TileType = tileType; Color = (Color)ColorConverter.ConvertFromString(color); Style = style; Coordinate = coordinate; Action = action; ActionURI = actionURI; Content = content; CorrespondingScreenContentType = correspondingScreenContentType; SubTiles = subTiles; }
internal static void Postfix(Vector2 grabTile, ref bool __result) { GameLocation location = Game1.currentLocation; if (!Utility.tileWithinRadiusOfPlayer((int)grabTile.X, (int)grabTile.Y, 1, Game1.player)) { return; } if (Game1.currentLocation.doesTileHaveProperty((int)grabTile.X, (int)grabTile.Y, "Action", "Buildings") is string action && TileAction.getCustomAction(action) is TileAction customAction) { __result = TileAction.invokeCustomTileActions("Action", Game1.currentLocation, grabTile, "Buildings"); } }
IEnumerator AssignTiles() { // Fill out all tiles by page in order Dictionary <int, TileAction[]> tilesCollection = new Dictionary <int, TileAction[]>(); for (int i = 0; i < pageTiles.Length; i++) { tilesCollection.Add(i, pageTiles[i].tiles); } // Assign randomized tiles GameObject obj; TileAction newTile = null; TileAction[] arr; Renderer[] rends; int r, prevR = -1, max = System.Enum.GetNames(typeof(TileTypes)).Length; // Iterate through keys for (int i = 0; i < tilesCollection.Count; i++) { arr = tilesCollection[i]; bonus = false; // Iterate through tiles for (int j = 0; j < arr.Length; j++) { obj = arr[j].gameObject; r = Random.Range(0, max); /** * Here it should re-roll in 3 cases: * - Tile is the same as the previous one, not being a question tile * - Tile is a return tile and it's too close to the start * - Tile is an advance tile and it's too close to the end */ while ((r == prevR && r != (int)TileTypes.Question) || (r == (int)TileTypes.Return && i == 0 && j < 2) || (r == (int)TileTypes.Advance && i == tilesCollection.Count - 1 && j > arr.Length - 3) || (r == (int)TileTypes.Bonus && bonus)) { r = Random.Range(0, max); } switch (r) { case (int)TileTypes.Question: newTile = obj.AddComponent <TileQuestion>(); (newTile as TileQuestion).page = i; break; case (int)TileTypes.Advance: newTile = obj.AddComponent <TileMove>(); (newTile as TileMove).forward = true; break; case (int)TileTypes.Return: newTile = obj.AddComponent <TileMove>(); (newTile as TileMove).forward = false; break; case (int)TileTypes.Stop: newTile = obj.AddComponent <TileModifier>(); (newTile as TileModifier).positive = false; break; case (int)TileTypes.Bonus: newTile = obj.AddComponent <TileModifier>(); (newTile as TileModifier).positive = true; bonus = true; break; case (int)TileTypes.Minigame: newTile = obj.AddComponent <TileMinigame>(); break; case (int)TileTypes.Surprise: newTile = obj.AddComponent <TileSurprise>(); (newTile as TileSurprise).mats = surpriseTileMats; obj.AddComponent <TileQuestion>(); obj.AddComponent <TileMove>(); obj.AddComponent <TileModifier>(); obj.AddComponent <TileMinigame>(); break; } obj.name = tileNames[r]; rends = obj.GetComponentsInChildren <Renderer>(true); foreach (Renderer rd in rends) { rd.material = tileMats[r]; } Destroy(arr[j]); arr[j] = newTile; prevR = r; yield return(new WaitForFixedUpdate()); } } // Give all tiles to the manager, inserting start and end tiles manager.levelTiles = new Dictionary <int, Tile[]>(); List <Tile> tiles; for (int i = 0; i < tilesCollection.Count; i++) { tiles = new List <Tile>(); if (i == 0) { tiles.Add(startTile as Tile); } tiles.AddRange(tilesCollection[i]); if (i == tilesCollection.Count - 1) { tiles.Add(endTile as Tile); } manager.levelTiles[i] = tiles.ToArray(); } }
public void UpdateAction(DrawableTile tile, TileAction action) { objectsLayer.UpdateAction(tile, action); reselectTile(tile); }
private Tiles LoadTile(string name, TileType tileType, TileAction tileAction) { return new Tiles(Content.Load<Texture2D>("Tiles/" + name), tileType, tileAction); }
private int CalculatePriorityScore(int layerPriority, int lod, int distanceSquared, TileAction action) { float distanceFactor = ((5000f * 5000f) / distanceSquared); int priority = 1; switch (action) { case TileAction.Create: priority = (int)((1 + (10 * (lod + layerPriority))) * distanceFactor); break; case TileAction.Upgrade: priority = (int)((1 + (1 * (lod + layerPriority))) * distanceFactor); break; case TileAction.Downgrade: priority = (int)((1 + (0.5 * (lod + layerPriority))) * distanceFactor); break; case TileAction.Remove: priority = (int)((1 + (100 * (lod + layerPriority))) * distanceFactor); break; default: break; } return(priority); }
// private int m_actionIdx = -1; // private List<TileAction> m_actionsHistoric = new List<TileAction>(); //Return only 1 TileData has change public TileAction.TileData PerformAction(TileAction _action) { return(_action.DoAction(MyAutoTileMap)); }
/// <summary> /// Copy a section of the tileset and use it as drawing template /// </summary> /// <param name="tilesetSelStart"></param> /// <param name="tilesetSelEnd"></param> public void RefreshBrushGizmoFromTileset( int tilesetSelStart, int tilesetSelEnd ) { SpriteRenderer[] aSprites = GetComponentsInChildren<SpriteRenderer>(); BrushAction = new TileAction(); Vector2 pivot = new Vector2(0f,1f); int selTileW = (Mathf.Abs(tilesetSelStart - tilesetSelEnd) % MyAutoTileMap.Tileset.AutoTilesPerRow + 1); int selTileH = (Mathf.Abs(tilesetSelStart - tilesetSelEnd) / MyAutoTileMap.Tileset.AutoTilesPerRow + 1); int tilesetIdx = Mathf.Min( tilesetSelStart, tilesetSelEnd ); int sprIdx = 0; Vector3 vSprPos = new Vector3( 0f, 0f, 0f ); for (int j = 0; j < selTileH; ++j, tilesetIdx += (MyAutoTileMap.Tileset.AutoTilesPerRow - selTileW), vSprPos.y -= MyAutoTileMap.Tileset.TileWorldHeight) { vSprPos.x = 0; for (int i = 0; i < selTileW; ++i, ++tilesetIdx, ++sprIdx, vSprPos.x += MyAutoTileMap.Tileset.TileWorldWidth) { SpriteRenderer spriteRender = sprIdx < aSprites.Length? aSprites[sprIdx] : null; if( spriteRender == null ) { GameObject spriteObj = new GameObject(); spriteObj.transform.parent = transform; spriteRender = spriteObj.AddComponent<SpriteRenderer>(); } spriteRender.transform.gameObject.name = "BrushGizmoPart"+sprIdx; spriteRender.sprite = Sprite.Create(MyAutoTileMap.Tileset.AtlasTexture, MyAutoTileMap.Tileset.ThumbnailRects[tilesetIdx], pivot, AutoTileset.PixelToUnits); spriteRender.sortingOrder = 50; //TODO: +50 temporal? see for a const number later spriteRender.color = new Color32( 255, 255, 255, 160); spriteRender.transform.localPosition = vSprPos; bool hasAlpha = MyAutoTileMap.IsAutoTileHasAlpha( tilesetIdx ); BrushAction.Push( MyAutoTileMap, i, j, tilesetIdx, (int)( hasAlpha? AutoTileMap.eTileLayer.GROUND_OVERLAY : AutoTileMap.eTileLayer.GROUND)); } } // clean unused sprite objects while(sprIdx < aSprites.Length) { if( Application.isEditor ) { DestroyImmediate( aSprites[sprIdx].transform.gameObject ); } else { Destroy( aSprites[sprIdx].transform.gameObject ); } ++sprIdx; } }
public void CopyRelative( AutoTileMap _autoTileMap, TileAction _action, int tile_x, int tile_y ) { foreach( TileData tileData in _action.aTileData ) { Push( _autoTileMap, tileData.Tile_x + tile_x, tileData.Tile_y + tile_y, tileData.Tile_type, tileData.Tile_layer ); } }
/// <summary> /// Copy a section of the tileset and use it as drawing template /// </summary> /// <param name="tilesetSelStart"></param> /// <param name="tilesetSelEnd"></param> public void RefreshBrushGizmoFromTileset( int tilesetSelStart, int tilesetSelEnd ) { SpriteRenderer[] aSprites = GetComponentsInChildren<SpriteRenderer>(); BrushAction = new TileAction(); Vector2 pivot = new Vector2(0f,1f); int selTileW = (Mathf.Abs(tilesetSelStart - tilesetSelEnd) % MyAutoTileMap.Tileset.AutoTilesPerRow + 1); int selTileH = (Mathf.Abs(tilesetSelStart - tilesetSelEnd) / MyAutoTileMap.Tileset.AutoTilesPerRow + 1); int tileIdx = Mathf.Min( tilesetSelStart, tilesetSelEnd ); int sprIdx = 0; Vector3 vSprPos = new Vector3( 0f, 0f, 0f ); for (int j = 0; j < selTileH; ++j, tileIdx += (MyAutoTileMap.Tileset.AutoTilesPerRow - selTileW), vSprPos.y -= MyAutoTileMap.Tileset.TileWorldHeight) { vSprPos.x = 0; for (int i = 0; i < selTileW; ++i, ++tileIdx, ++sprIdx, vSprPos.x += MyAutoTileMap.Tileset.TileWorldWidth) { SpriteRenderer spriteRender = sprIdx < aSprites.Length? aSprites[sprIdx] : null; if( spriteRender == null ) { GameObject spriteObj = new GameObject(); spriteObj.transform.parent = transform; spriteRender = spriteObj.AddComponent<SpriteRenderer>(); } spriteRender.transform.gameObject.name = "BrushGizmoPart"+sprIdx; spriteRender.sprite = Sprite.Create(MyAutoTileMap.Tileset.AtlasTexture, MyAutoTileMap.Tileset.ThumbnailRects[tileIdx], pivot, AutoTileset.PixelToUnits); spriteRender.sortingOrder = 50; //TODO: +50 temporal? see for a const number later spriteRender.color = new Color32( 255, 255, 255, 160); spriteRender.transform.localPosition = vSprPos; // If smart brush is enabled, the tiles with collision type Overlay will be placed directly in the first overlay layer found over current SelectedLayer if (SmartBrushEnabled) { int overlayLayer = MyAutoTileMap.FindFirstLayerIdx(AutoTileMap.eLayerType.Overlay, MyAutoTileMap.BrushGizmo.SelectedLayer); if (overlayLayer >= 0 && tileIdx >= 0 && MyAutoTileMap.Tileset.AutotileCollType[tileIdx] == AutoTileMap.eTileCollisionType.OVERLAY) { BrushAction.Push(MyAutoTileMap, i, j, tileIdx, overlayLayer); } else { // If SmartBrushEnabled and tile has alpha, it will be draw in the layer over the SelectedLayer BrushAction.Push(MyAutoTileMap, i, j, tileIdx, SmartBrushEnabled && MyAutoTileMap.IsAutoTileHasAlpha(tileIdx) ? SelectedLayer + 1 : SelectedLayer); } } else { BrushAction.Push(MyAutoTileMap, i, j, tileIdx, SelectedLayer); } } } // clean unused sprite objects while(sprIdx < aSprites.Length) { if( Application.isEditor ) { DestroyImmediate( aSprites[sprIdx].transform.gameObject ); } else { Destroy( aSprites[sprIdx].transform.gameObject ); } ++sprIdx; } }
public static bool lockAction(string action, GameLocation location, Vector2 tile, string layer) { string[] strings = action.Split(' '); if (Game1.player.ActiveObject is Item i && i.ParentSheetIndex == int.Parse(strings[2]) && i.Stack >= int.Parse(strings[1])) { int amount = int.Parse(strings[1]); Game1.playSound("newArtifact"); if (i.Stack > amount) { i.Stack -= amount; } else { Game1.player.removeItemFromInventory(i); } TileAction.invokeCustomTileActions("Success", location, tile, layer); if (strings.Length >= 4 && strings[3].ToLower() == "persist") { string lockid = layer + "_" + (int)tile.X + "_" + (int)tile.Y; if (strings.Length >= 5 && strings[4].ToLower() == "recall") { lockid += "_recall"; } string lname = location.isStructure.Value ? location.uniqueName.Value : location.Name; if (!location.Map.Properties.ContainsKey("PersistentData")) { location.Map.Properties.Add("PersistentData", "lock:" + lname + ":" + lockid); } else { location.Map.Properties["PersistentData"] = location.Map.Properties["PersistentData"].ToString() + ";" + "lock:" + lname + ":" + lockid; } if (!location.Map.Properties.ContainsKey("Unlocked")) { location.Map.Properties.Add("Unlocked", lockid); } else { location.Map.Properties["Unlocked"] = location.Map.Properties["Unlocked"].ToString() + ";" + lockid; } try { Tile calledTile = location.Map.GetLayer(layer).Tiles[(int)tile.X, (int)tile.Y]; if (calledTile != null && (calledTile.Properties.ContainsKey("Action") && calledTile.Properties["Action"].ToString().ToLower().Contains("lock") && calledTile.Properties["Action"].ToString().Contains(action))) { if (strings.Length >= 5 && strings[4].ToLower() == "recall") { if (calledTile.Properties.ContainsKey("Recall")) { calledTile.Properties["Action"] = calledTile.Properties["Recall"]; } else { calledTile.Properties["Action"] = calledTile.Properties["Success"]; } } else { calledTile.Properties.Remove("Action"); } } } catch { } } }
private void registerTileActions() { TileAction CC = new TileAction("CC", (action, location, tile, layer) => { List <string> text = action.Split(' ').ToList(); string key = text[1]; text.RemoveAt(0); text.RemoveAt(0); action = String.Join(" ", text); if (key == "cs") { action += ";"; } Helper.ConsoleCommands.Trigger(key, action.Split(' ')); return(true); }).register(); TileAction Game = new TileAction("Game", (action, location, tile, layer) => { List <string> text = action.Split(' ').ToList(); text.RemoveAt(0); action = String.Join(" ", text); return(location.performAction(action, Game1.player, new xTile.Dimensions.Location((int)tile.X, (int)tile.Y))); }).register(); TileAction Lua = new TileAction("Lua", (action, location, tile, layer) => { string[] a = action.Split(' '); if (a.Length > 2) { if (a[1] == "this") { string id = location.Name + "." + layer + "." + tile.Y + tile.Y; if (!PyLua.hasScript(id)) { if (layer == "Map") { if (location.map.Properties.ContainsKey("Lua_" + a[2])) { string script = @" function callthis(location,tile,layer) " + location.map.Properties["Lua_" + a[2]].ToString() + @" end"; PyLua.loadScriptFromString(script, id); } } else { if (location.doesTileHaveProperty((int)tile.X, (int)tile.Y, "Lua_" + a[2], layer) is string lua) { PyLua.loadScriptFromString(@" function callthis(location,tile,layer) " + lua + @" end", id); } } } if (PyLua.hasScript(id)) { PyLua.callFunction(id, "callthis", new object[] { location, tile, layer }); } } else { try { PyLua.callFunction(a[1], a[2], new object[] { location, tile, layer }); } catch { } } } return(true); }).register(); }
public abstract IEnumerator DisplayAction(TileAction originTile);
void Awake() { state = TileType.None; action = TileAction.None; }
/// <summary> /// Clear Brush tile selection /// </summary> public void Clear() { // RefreshBrushGizmo( -1, -1, -1, -1, -1, -1, false ); BrushAction = null; RefreshSpriteRenderers(); }
public static void addTouchAction(this Map m, Vector2 position, TileAction action, string args) { m.GetLayer("Back").PickTile(new Location((int)position.X * Game1.tileSize, (int)position.Y * Game1.tileSize), Game1.viewport.Size).Properties.AddOrReplace("TouchAction", action.trigger + " " + args); }
public override List <Tile> Handle(List <Tile> initialTiles) { List <Tile> tiles = initialTiles; for (int i = 0; i < initialTiles.Count(); i++) { Tile tile = initialTiles[i]; TileAction action = tile.getNextAction(); List <Tile> updatedTiles = tiles; bool canMove = true; bool lightstrue = true; TileAction nextAction = new NoAction(); if (tile != null && tile.Actions.Count > 0) { nextAction = tile.Actions[0]; } if (nextAction.GetType() == typeof(MoveAction)) { switch (((MoveAction)nextAction).direction) { case Direction.Up: canMove = checkFront(tile.Position.X, tile.Position.Y - 1, initialTiles); lightstrue = !(checkTrafficLight(tile.Position.X + 1, tile.Position.Y, initialTiles) && checkRightLight(tile.Position.X + 1, tile.Position.Y - 1, initialTiles)); break; case Direction.Down: canMove = checkFront(tile.Position.X, tile.Position.Y + 1, initialTiles); lightstrue = !(checkTrafficLight(tile.Position.X - 1, tile.Position.Y, initialTiles) && checkRightLight(tile.Position.X - 1, tile.Position.Y + 1, initialTiles)); break; case Direction.Left: canMove = checkFront(tile.Position.X - 1, tile.Position.Y, initialTiles); lightstrue = !(checkTrafficLight(tile.Position.X, tile.Position.Y - 1, initialTiles) && checkRightLight(tile.Position.X - 1, tile.Position.Y - 1, initialTiles)); break; case Direction.Right: canMove = checkFront(tile.Position.X + 1, tile.Position.Y, initialTiles); lightstrue = !(checkTrafficLight(tile.Position.X, tile.Position.Y + 1, initialTiles) && checkRightLight(tile.Position.X + 1, tile.Position.Y + 1, initialTiles)); break; } } if (nextAction.GetType() == typeof(NoAction) && tile.Type == TileType.Car) { updatedTiles = action.Handle(tile, initialTiles); return(updatedTiles); } if (!tile.Dirty && lightstrue && canMove) { updatedTiles = action.Handle(tile, initialTiles); } else { tile.Actions.Insert(0, action); } tiles = updatedTiles; } return(tiles); }
/// <summary> /// Clear Brush tile selection /// </summary> public void Clear() { RefreshBrushGizmo( -1, -1, -1, -1, -1, -1, false ); BrushAction = null; }
public void TileHandled(TileChange handledTileChange) { TileAction action = handledTileChange.action; activeTileChanges.Remove(new Vector3Int(handledTileChange.X, handledTileChange.Y, handledTileChange.layerIndex)); }
void FixedUpdate(){ if (cooldown != 0) { cooldown--; } if(currentExecutingTileAction != null){ currentExecutingTileAction.updateTileAction (); if(currentExecutingTileAction.finished){ currentExecutingTileAction = null; BoardController.playerDone(); } return; } if(playerID == BoardController.getCurrentPlayerID()){ if(roll == 0 && GlobalPlayerManager.GetButton(playerID, "Start") && cooldown == 0){ runeMenu.open = !runeMenu.open; runeMenu.playerID = playerID; cooldown = 7; } if (!runeMenu.open) { if (branch) { float xaxis = GlobalPlayerManager.GetAxis (playerID, "Horizontal"); float yaxis = GlobalPlayerManager.GetAxis (playerID, "Vertical"); if (upOption != null && yaxis > 0) { currentTile = upOption; branch = false; return; } if (downOption != null && yaxis < 0) { currentTile = downOption; branch = false; return; } if (leftOption != null && xaxis < 0) { currentTile = leftOption; branch = false; return; } if (rightOption != null && xaxis > 0) { currentTile = rightOption; branch = false; return; } return; } if (cooldown == 0 && GlobalPlayerManager.GetButton (playerID, "A")) { Roll (); visualRoll = roll; cooldown = 7; } else if (roll == 0) { popupText.text = "Press A to roll the dice"; diceBackground.enabled = false; } if (roll != 0) { popupText.text = "" + visualRoll; diceBackground.enabled = true; if (moveFactor <= 0) { moveFactor = 1; roll--; if (roll != 0) { getNextTiles (); visualRoll = roll; } else { TileAction action = currentTile.GetComponent<TileAction> (); if(action != null){ action.runTileAction(this); currentExecutingTileAction = action; return; } BoardController.playerDone (); } } else { moveFactor -= 0.07f; transform.position = lastTile.transform.position * (moveFactor) + currentTile.transform.position * (1f - moveFactor); } } } else { popupText.text = ""; diceBackground.enabled = false; } } }
private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e) { TileAction tileAction = new TileAction("alert", PyTKTileAction_Action); tileAction.register(); }