public void CheckDestruction(Vector3 pos) { if (!destroingTile) { destroingTile = true; Vector3Int currentCell = tileMaps[0].WorldToCell(pos); float cd = 0; for (int i = 0; i < tileMaps.Count; i++) { TileBase tile = null; foreach (var p in new BoundsInt(0, 0, 0, 1, 1, 1).allPositionsWithin)//brush { tile = tileMaps[i].GetTile(currentCell + p); } if (tile is ItemTile) { ItemTile item = tile as ItemTile; if (cd < item.Item.hardness) { cd = item.Item.hardness; } } } if (0 > cd) { cd = 0.025f; } StartCoroutine(DeleteTiles(currentCell, cd)); } }
/// <summary> /// Does initial population of Bacteria for all maps in the world /// </summary> public static void PopulateBacteria() { Random gen = new Random(); for (int i = 0; i < Maps.Count; i++) { List <System.Drawing.Point> emptySpaces = new List <System.Drawing.Point>(EmptyLocations(i)); // Randomize emptySpaces using Fisher-Yates shuffling algorithm for (int j = 0; j < emptySpaces.Count; j++) { int rnd = gen.Next(0, emptySpaces.Count - 1); System.Drawing.Point tmp = emptySpaces[j]; emptySpaces[j] = emptySpaces[rnd]; emptySpaces[rnd] = tmp; } // Generate items at the first [size * proportion] locations int items = (int)Math.Floor(emptySpaces.Count * Const.FILL_PROPORTION); for (int j = 0; j < items; j++) { ItemTile tile = new ItemTile(ItemTileSpec.BACTERIA, emptySpaces[j].X, emptySpaces[j].Y, gen.Next(Const.MIN_BACTERIA, Const.MAX_BACTERIA)); Maps[i].AddTile(new Microsoft.Xna.Framework.Vector2(emptySpaces[j].X, emptySpaces[j].Y), LAYERS.Item, tile); } } }
public Tile[,,] setTilesInLayer(Tile[,,] tilechunk, Tile tile, int layer) { for (int y = 0; y < Heigth; y++) { for (int x = 0; x < Width; x++) { if (layer == 0) { if (chunkMap[x, y, layer] == 1) { tilechunk[x, y, layer] = tile; } else if (chunkMap[x, y, layer] == 0) { tilechunk[x, y, layer] = backGround; } } else if (chunkMap[x, y, layer] == 1) { if (tile is ItemTile) { tile = new ItemTile(Item.ChanceRandomItem(chunkSources)); } tilechunk[x, y, layer] = tile; } } } return(tilechunk); }
public static Tile[,,] IdsToTiles(int[][][] ids) { int xSizes = ids.GetLength(0); int ySizes = ids[0].GetLength(0); int zSizes = ids[0][0].GetLength(0); Tile[,,] tiles = new Tile[xSizes, ySizes, zSizes]; for (int y = 0; y < ySizes; y++) { for (int x = 0; x < xSizes; x++) { for (int z = 0; z < zSizes; z++) { if (z == 0) { tiles[x, y, z] = TerrainTile.GetTerrainTileOfID(ids[x][y][z]); } if (z == 1) { Item item = Item.GetItemOfID(ids[x][y][z]); if (item != null) { tiles[x, y, z] = new ItemTile(item); } } } } } return(tiles); }
/// <summary> /// Called when the object is initialized, but only if the object is active. /// Then called every time the object becomes active /// </summary> private void OnEnable() { _myScript = (ItemTile)target; _myScripts = new List <ItemTile>(); foreach (var item in targets) { _myScripts.Add((ItemTile)item); } }
private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Object") { ItemTile itemTile = other.GetComponent <ItemTile>(); InventoryController.instance.AddNewItem(itemTile.item); GameManager.instance.Massage(itemTile.item); Destroy(other.gameObject); } }
public Item CreateItemTile(Vector3Int position, Item.ItemType type) { ItemTile itemTile = TileFinder.Activated.GetItem(type); Item item = new Item(type, 0); Items.SetTile(position, itemTile); var newItemTile = Items.GetTile <ItemTile>(position); newItemTile.Item = item; return(item); }
/// <summary> /// Transfer itemTile data to moneyItemTile /// </summary> /// <param name="itemTile"></param> public void TranferItemData(ItemTile itemTile) { this.TileID = itemTile.TileID; this.TilePlayerPos = itemTile.TilePlayerPos; this.neighborTiles = itemTile.neighborTiles; this.item = itemTile.item; this.IsItemTile = true; this.locationName = itemTile.locationName; this.TileItemType = ItemTile.ItemType.MoneyItem; this.IsStartTile = false; this.HasItem = itemTile.HasItem; }
public GameObject CreateItemTileGameObject(ItemTile item) { GameObject g = new GameObject(); ItemTileUnity itemTileUnity = (ItemTileUnity)g.AddComponent(typeof(ItemTileUnity)); itemTileUnity.gameManagerUnity = gameManagerUnity; itemTileUnity.item = item; unityItemTiles.Add(itemTileUnity); return(g); }
public static void ResetAllTiles() { PopulateTileList(); foreach (ItemTile tileObject in _tileList) { if (!tileObject.CompareTag("TilePath")) { _myScript = tileObject; _myScript.GetComponent <MeshFilter>().mesh = _tiles.Meshes[0]; ResetTile(); } } }
public static Block GetBlockType(string name) { ItemTile block = GetItemSet(name); if (block != null) { if (block is Block) { return((Block)block); } } return((Block)GetItemSet("Air")); }
public static int[][][] TilesToIds(Tile[,,] tiles) { int xSizes = tiles.GetLength(0); int ySizes = tiles.GetLength(1); int zSizes = tiles.GetLength(2); int[][][] ids = new int[xSizes][][]; for (int i = 0; i < xSizes; i++) { ids[i] = new int[ySizes][]; for (int j = 0; j < ySizes; j++) { ids[i][j] = new int[zSizes]; } } for (int y = 0; y < ySizes; y++) { for (int x = 0; x < xSizes; x++) { for (int z = 0; z < zSizes; z++) { if (z == 0) { Tile tile = tiles[x, y, z]; TerrainTile ttile = tile as TerrainTile; if (tile != null) { ids[x][y][z] = ttile.Id; } } if (z == 1) { ItemTile item = tiles[x, y, z] as ItemTile; if (item != null) { if (item.Item != null) { ids[x][y][z] = item.Item.Id; } } } } } } return(ids); }
/// <summary> /// TODO /// </summary> private void AddItemTileTypes() { //Debug.Log("No. item tiles = " + m_numOfAddedItemTiles); // Create item deployment minus one of the total of item tiles. That one is used for the vr googles ItemTileDeployment itemTileDeployment = new ItemTileDeployment(m_numOfAddedItemTiles - 1); List <int> itemTileIDs = new List <int>(); // Get all item tile id's foreach (Transform t in m_itemTiles) { Tile tile = t.GetComponent <Tile>(); itemTileIDs.Add(tile.TileID); } // Shuffle the id's so items is not added at the same tiles each game System.Random rnd = new System.Random(); itemTileIDs.Shuffle(rnd); int currentItemIdIndex = 0; int numOfItems = itemTileDeployment.MoneyItemDeployment.Count; foreach (KeyValuePair <string, int> kvp in itemTileDeployment.MoneyItemDeployment) { int moneyValue; Int32.TryParse(kvp.Key, out moneyValue); for (int i = 0; i < kvp.Value; i++) { //Transform t = m_tiles.GetChild(itemTileIDs[currentItemIdIndex]); Tile tile = GetTile(itemTileIDs[currentItemIdIndex].ToString()); if (tile.IsItemTile) { ItemTile itemTile = tile.GetComponent <ItemTile>(); MoneyItemTile moneyItemTile = tile.gameObject.AddComponent <MoneyItemTile>(); moneyItemTile.TranferItemData(itemTile); moneyItemTile.Value = moneyValue; moneyItemTile.TilePrize = moneyItemTile.Value; //Debug.Log("TileID: " + moneyItemTile.TileID); Destroy(itemTile); } currentItemIdIndex++; } } }
public static Gem GetGem(ItemTile item) { switch (item) { case ItemTile.SMALL_GEM: return(Gem.Small); case ItemTile.MEDIUM_GEM: return(Gem.Medium); case ItemTile.LARGE_GEM: return(Gem.Large); default: throw new Exception("ItemTile is not a gem!"); } }
// Установить плитку public void SetTile(TileType type, int i, int j) { // Находим соседей Tile upTile = GetTile(i, j - 1); // Верхний сосед Tile downTile = GetTile(i, j + 1); // Нижний сосед Tile leftTile = GetTile(i - 1, j); // Левый сосед Tile rightTile = GetTile(i + 1, j); // Правый сосед if (type != TileType.NONE) { var tile = new Tile(type, upTile, downTile, leftTile, rightTile); tile.Position = new Vector2f(i * Tile.TILE_SIZE, j * Tile.TILE_SIZE) + Position; tiles[i, j] = tile; } else { var tile = tiles[i, j]; if (tile != null) { var item = new ItemTile(this, InfoItem.ItemGround); item.Position = tile.Position; items.Add(item); } tiles[i, j] = null; // Присваиваем соседей, а соседям эту плитку if (upTile != null) { upTile.DownTile = null; } if (downTile != null) { downTile.UpTile = null; } if (leftTile != null) { leftTile.RightTile = null; } if (rightTile != null) { rightTile.LeftTile = null; } } }
// Update is called once per frame void Update() { if (cooldown <= Time.time) { for (int tier = itemList.RandomTier(); tier >= 0; --tier) { List <ItemTile> availableTiles = GetAvailableItemTiles(tier); if (availableTiles.Count > 0) { ItemTile tile = availableTiles[Random.Range(0, availableTiles.Count)]; SpawnItem(tile.transform.position, itemList.RandomItem(tier)); tile.AddCooldown(2.5f); // Add cooldown to tile to offset Spawn Indicator time break; } } ResetCooldown(); } }
public override ChunkInfo GenerateChunk(Vector2Int gPos) { Tile[,,] chunkTileInfo = new Tile[Width, Heigth, chunkSources.Length + 1]; int layer = 0; int[,] groundpositionMap = new int[Width, Heigth]; chunkTileInfo = GenerateLayer(groundpositionMap, chunkTileInfo, ground, layer); if (chunkSources.Length != 0) { layer = 1; int[,] itempositionMap = new int[Width, Heigth]; ItemTile tile = new ItemTile(Item.ItemsList[0]);//tileinfo "identity" chunkTileInfo = GenerateLayer(itempositionMap, chunkTileInfo, tile, layer); } return(new ChunkInfo(World.TilesToIds(chunkTileInfo), gPos)); }
//set tile public void SetTile(TileType type, int i, int j) { Tile upTileNeighbor = GetTile(i, j - 1); //up Tile downTileNeighbor = GetTile(i, j + 1); //down Tile leftTileNeighbor = GetTile(i - 1, j); //left Tile rightTileNeighbor = GetTile(i + 1, j); //right if (type != TileType.NONE) { var tile = new Tile(type, upTileNeighbor, downTileNeighbor, leftTileNeighbor, rightTileNeighbor); tile.Position = new Vector2f(i * Tile.TILE_SIZE, j * Tile.TILE_SIZE) + Position; tiles[i, j] = tile; } else { var tile = tiles[i, j]; if (tile != null) { var item = new ItemTile(this, InfoItem.ItemGround); item.Position = tile.Position; items.Add(item); } tiles[i, j] = null; if (upTileNeighbor != null) { upTileNeighbor.DownTile = null; } if (downTileNeighbor != null) { downTileNeighbor.UpTile = null; } if (leftTileNeighbor != null) { leftTileNeighbor.RightTile = null; } if (rightTileNeighbor != null) { rightTileNeighbor.LeftTile = null; } } }
/// <summary> /// Adds some more bacteria to all maps in the World. Called from a server timer. /// </summary> /// <param name="param">Since this is a System.Threading.Timer callback, param is an instance of a Server passed as an object</param> public static void AddBacteria(object param) { if (Maps == null) { return; } Server serverInstance; try { serverInstance = param as Server; } catch (InvalidCastException) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error: In World.AddBacteria: Unable to cast server instance from timer callback function!"); Console.ResetColor(); return; } Random gen = new Random(); for (int i = 0; i < Maps.Count; i++) { List <System.Drawing.Point> emptySpaces = new List <System.Drawing.Point>(EmptyLocations(i)); if (Maps[i].Layers[(int)LAYERS.Item].Count < (int)Math.Floor(emptySpaces.Count * Const.FILL_PROPORTION)) { // Add bacteria to map int index = gen.Next(0, emptySpaces.Count - 1); ItemTile tile = new ItemTile(ItemTileSpec.BACTERIA, emptySpaces[index].X, emptySpaces[index].Y, gen.Next(Const.MIN_BACTERIA, Const.MAX_BACTERIA)); Maps[i].AddTile(new Microsoft.Xna.Framework.Vector2(emptySpaces[index].X, emptySpaces[index].Y), LAYERS.Item, tile); ItemData data = new ItemData(tile.Type, tile.X, tile.Y, tile.Quantity); if (!serverInstance.SendToClient(ServerAction.Content, data)) { serverInstance.Log(System.Reflection.MethodBase.GetCurrentMethod().Name, "There was an error sending newly added bacteria to clients"); } } } }
/// <summary> /// Step one of createing a graph. This method adding a node to the grap /// for each tile in m_tiles. /// </summary> private void AddTilesToGraph() { foreach (Transform transform in m_tiles) { Tile tile = transform.GetComponent <Tile>(); m_tileGraph.AddNode(tile.TileID.ToString(), transform); if (tile.IsItemTile) { ItemTile itemTile = (ItemTile)tile; if (!itemTile.IsStartTile) { itemTile.HasItem = true; m_itemTiles.Add(transform); m_numOfAddedItemTiles++; } } } }
/// <summary> /// Get the tile item and save the value in player inventory /// </summary> private void RetriveTileItem() { ItemTile itemTile = m_playerMovement.CurrentItemTile; itemTile.HasItem = false; itemTile.SetColor(Color.gray); ItemTile.ItemType itemType = itemTile.TileItemType; switch (itemType) { case ItemTile.ItemType.MoneyItem: Debug.Log("Itemtype = MoneyItem"); MoneyItemTile moneyItemTile = (MoneyItemTile)itemTile; int value = moneyItemTile.Value; m_gameManager.Bank.WithdrawMoney(value); break; default: break; } }
public override void Draw(Microsoft.Xna.Framework.GameTime gameTime) { int screenWidth = GraphicsDevice.Viewport.Width; int screenHeight = GraphicsDevice.Viewport.Height; // Main player light circle Engine.SpriteBatch.Draw(lightCircle, Engine.AnglerGame.MainPlayer.Bounds, Color.White); // Draw items for (int i = World.CurrentMap.VisibleBounds.Left; i < World.CurrentMap.VisibleBounds.Right; i++) { for (int j = World.CurrentMap.VisibleBounds.Top; j < World.CurrentMap.VisibleBounds.Bottom; j++) { Texture2D texture = bacteriaFew; ItemTile tile = World.CurrentMap.GetTile(i, j, LAYERS.Item) as ItemTile; if (tile == null || tile.Type == ItemTileSpec.NONE) { continue; } if (tile.Quantity > Const.MIN_BACTERIA + (Const.MAX_BACTERIA - Const.MIN_BACTERIA) / 3) { texture = bacteriaMedium; } if (tile.Quantity > Const.MIN_BACTERIA + 2 * ((Const.MAX_BACTERIA - Const.MIN_BACTERIA) / 3)) { texture = bacteriaMany; } Engine.SpriteBatch.Draw(texture, World.CurrentMap.PositionOnVisibleMap(tile.X, tile.Y), Color.White * (float)(((1.0 - minimumOpactiy) * Math.Sin((double)(gameTime.TotalGameTime.TotalMilliseconds) * tile.Speed * (Math.PI / 180)) + 1) / 2)); } } Engine.SpriteBatch.Draw(bacteriaCount, new Vector2(GraphicsDevice.Viewport.Width - bacteriaCount.Width - 10, 10), Color.White); base.Draw(gameTime); }
/// <summary> /// Set the starting tile for current player /// </summary> /// <param name="startTile"></param> public void SetStartTileCurrentPlayer(Transform startTile) { ItemTile tile = startTile.GetComponent <ItemTile>(); // A check to see that the tile selected as start tile on the button is a valid start tile. if (tile.IsStartTile) { m_currentPlayer.SetStartingTile(startTile); // If all players has selected starting tile the game can start if (m_currentPlayer.PlayerId == players.Length) { gameState = GameState.StartGame; } else { NextPlayer(); } } else { //Debug.LogError(String.Format("Tile {0} is not a start tile", tile.TileID)); } }
/// <summary> /// When player movement is done check if the player is standing on an item tile. /// If there is an item there check if the player can buy it. Activate ui buttons /// to buy or roll. /// </summary> private void PlayerMovementDone() { if (m_playerMovement.CurrentTile.IsItemTile) { ItemTile itemTile = (ItemTile)m_playerMovement.CurrentTile; if (itemTile.HasItem) { bool canAfford = CanAffordTile(itemTile.TilePrize); if (canAfford) { m_userInterfaceManager.ShowBuyButton(); } } m_userInterfaceManager.ShowRollDiceButton(); m_playerState = PlayerState.TurnTile; } else { m_playerState = PlayerState.Done; } }
public bool HandleClientLogin(PacketStream pkt, ConnectedPlayer client) { string uName = "", pass = ""; int x = -1, y = -1, mapNum = 1, bacteriaCount = 0, admin = 0; if (!pkt.GetString(ref uName) || !pkt.GetString(ref pass)) { this.m_log.LogError(System.Reflection.MethodBase.GetCurrentMethod().Name, "Unable to get username and password from login request"); SendResponse(client, ServerErrorResponse.DataFormatError); return(false); } int maxClients; bool enc; if (!this.m_config.GetValue("loggedinusers", out maxClients) || !this.m_config.GetValue("passwordenc", out enc)) { this.m_log.LogWarning(System.Reflection.MethodBase.GetCurrentMethod().Name, "Unable to get passwordlen and passwordenc from log file"); this.m_config.Add("general", "loggedinusers", 50); maxClients = 50; enc = true; } if (enc) { pass = Encryption.SHA256(pass); } object[] accData = this.m_database.GetAccount(uName); if (accData == null || pass != accData[(int)DBAccountIndex.Password].ToString()) { SendResponse(client, ServerErrorResponse.AccountCredentialMismatch); return(false); } if ((int)accData[(int)DBAccountIndex.LoggedIn] == 1) { this.m_log.LogWarning(System.Reflection.MethodBase.GetCurrentMethod().Name, "User " + uName + " tried to log in twice"); SendResponse(client, ServerErrorResponse.InvalidAccessError); return(false); } if (!this.m_database.Login(uName, client.EndPoint.Address.ToString())) { SendResponse(client, ServerErrorResponse.SQLQueryError); return(false); } if (this.m_players.Count >= maxClients) { SendResponse(client, ServerErrorResponse.ServerTooManyClients); this.m_database.Logout(uName); return(false); } x = (int)accData[(int)DBAccountIndex.LocX]; y = (int)accData[(int)DBAccountIndex.LocY]; mapNum = (int)accData[(int)DBAccountIndex.LocMap]; bacteriaCount = (int)accData[(int)DBAccountIndex.BactCount]; admin = (int)accData[(int)DBAccountIndex.AdminLevel]; client.Login(uName, mapNum, x, y, bacteriaCount, admin); //send response with: map num, x, y, bacteria count Packet loginResponse = new Packet(ServerAction.ClientLoginResponse); loginResponse.AddData <string>(uName); loginResponse.AddData <int>(mapNum); loginResponse.AddData <int>(x); loginResponse.AddData <int>(y); loginResponse.AddData <int>(bacteriaCount); loginResponse.AddData <int>(admin); client.SendData(loginResponse); // Log the new player into everyone else's window Packet packet = new Packet(ServerAction.ClientLogin); packet.AddData <string>(client.UserName); packet.AddData <int>(client.X); packet.AddData <int>(client.Y); packet.AddData <int>(admin); SendResponse(client, packet); SortedList <string, Tile> items = World.Maps[client.CurrentMap].Layers[(int)LAYERS.Item]; if (items != null && items.Count > 0) { Packet itemsPacket = new Packet(ServerAction.Content); itemsPacket.AddData((byte)ContentType.Items); itemsPacket.AddData(items.Count); foreach (var pair in items) { if (!(pair.Value is ItemTile)) { continue; } ItemTile iTile = pair.Value as ItemTile; itemsPacket.AddData((byte)iTile.Type); itemsPacket.AddData(iTile.X); itemsPacket.AddData(iTile.Y); itemsPacket.AddData(iTile.Quantity); } client.SendData(itemsPacket); } if (m_players != null) { Packet playersPacket = new Packet(ServerAction.Content); playersPacket.AddData((byte)ContentType.Players); playersPacket.AddData(m_players.Where(i => i.CurrentMap == client.CurrentMap).Count()); foreach (ConnectedPlayer player in m_players) { if (player.CurrentMap == client.CurrentMap) { playersPacket.AddData(player.CurrentMap); playersPacket.AddData(player.X); playersPacket.AddData(player.Y); playersPacket.AddData(player.UserName); playersPacket.AddData(player.AdminLevel); } } client.SendData(playersPacket); } Console.WriteLine(uName + " logged in from " + client.EndPoint.Address.ToString()); Console.Write("\n> "); return(true); }
private static void UpdateObject(ItemTile myScriptInc) { _myScript = myScriptInc; _meshFilter = _myScript.GetComponent <MeshFilter>(); //0 Sides, i[0] /* XXX * XTX * XXX */ ResetTile(); if (IsNorth() && IsNorthEast() && IsEast() && IsSouthEast() && IsSouth() && IsSouthWest() && IsWest() && IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[0]; } //1 Side, i[1] /* OXO * TTT * TTT */ else if (IsWest() && IsEast() && IsSouth() && IsSouthEast() && IsSouthWest() && !IsNorth()) { _meshFilter.mesh = _tiles.Meshes[1]; MeshRot90(); MeshFlipZ(); } //1 Side, i[1] /* OTT * XTT * OTT */ else if (IsNorth() && IsSouth() && IsEast() && IsSouthEast() && !IsWest() && IsNorthEast()) { _meshFilter.mesh = _tiles.Meshes[1]; } //1 Side, i[1] /* TTT * TTT * OXO */ else if (IsNorth() && IsEast() && IsWest() && IsNorthWest() && IsNorthEast() && !IsSouth()) { _meshFilter.mesh = _tiles.Meshes[1]; MeshRot90(); MeshFlipX(); } //1 Side, i[1] /* TTO * TTX * TTO */ else if (IsNorth() && IsSouth() && IsWest() && IsNorthWest() && IsSouthWest() && !IsEast()) { _meshFilter.mesh = _tiles.Meshes[1]; MeshFlipX(); } //2 Side Corner, i[2] /* OXO * XTT * OTT */ else if (IsEast() && IsSouth() && IsSouthEast() && !IsNorth() && !IsWest()) { _meshFilter.mesh = _tiles.Meshes[2]; MeshFlipZ(); } //2 Side Corner, i[2] /* OTT * XTT * OXO */ else if (IsEast() && IsNorth() && IsNorthEast() && !IsSouth() && !IsWest()) { _meshFilter.mesh = _tiles.Meshes[2]; } //2 Side Corner, i[2] /* TTO * TTX * OXO */ else if (IsWest() && IsNorth() && IsNorthWest() && !IsSouth() && !IsEast()) { _meshFilter.mesh = _tiles.Meshes[2]; MeshFlipX(); } //2 Side Corner, i[2] /* OXO * TTX * TTO */ else if (IsWest() && IsSouth() && IsSouthWest() && !IsNorth() && !IsEast()) { _meshFilter.mesh = _tiles.Meshes[2]; MeshFlipX(); MeshFlipZ(); } //2 Sides opposite, i[3] /* OXO * TTT * OXO */ else if (IsWest() && IsEast() && !IsNorth() && !IsSouth()) { _meshFilter.mesh = _tiles.Meshes[3]; } //2 Sides opposite, i[3] /* OTO * XTX * OTO */ else if (IsNorth() && IsSouth() && !IsEast() && !IsWest()) { _meshFilter.mesh = _tiles.Meshes[3]; MeshRot90(); } //3 Sides, i[4] /* OTO * XTX * OXO */ else if (IsNorth() && !IsSouth() && !IsEast() && !IsWest()) { _meshFilter.mesh = _tiles.Meshes[4]; MeshRot90(); MeshFlipX(); } //3 Sides, i[4] /* OXO * XTX * OTO */ else if (IsSouth() && !IsNorth() && !IsEast() && !IsWest()) { _meshFilter.mesh = _tiles.Meshes[4]; MeshRot90(); } //3 Sides, i[4] /* OXO * XTT * OXO */ else if (IsEast() && !IsNorth() && !IsSouth() && !IsWest()) { _meshFilter.mesh = _tiles.Meshes[4]; } //3 Sides, i[4] /* OXO * TTX * OXO */ else if (IsWest() && !IsNorth() && !IsSouth() && !IsEast()) { _meshFilter.mesh = _tiles.Meshes[4]; MeshFlipX(); } //4 Sides, i[5] /* OOO * OTO * OOO */ else if (!IsNorth() && !IsEast() && !IsSouth() && !IsWest()) { _meshFilter.mesh = _tiles.Meshes[5]; } //1 Corner, i[6] /* TTT * TTT * TTX */ else if (IsNorth() && IsNorthEast() && IsEast() && !IsSouthEast() && IsSouth() && IsSouthWest() && IsWest() && IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[6]; MeshFlipZ(); } //1 Corner, i[6] /* TTX * TTT * TTT */ else if (IsNorth() && !IsNorthEast() && IsEast() && IsSouthEast() && IsSouth() && IsSouthWest() && IsWest() && IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[6]; } //1 Corner, i[6] /* XTT * TTT * TTT */ else if (IsNorth() && IsNorthEast() && IsEast() && IsSouthEast() && IsSouth() && IsSouthWest() && IsWest() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[6]; MeshFlipX(); } //1 Corner, i[6] /* TTT * TTT * XTT */ else if (IsNorth() && IsNorthEast() && IsEast() && IsSouthEast() && IsSouth() && !IsSouthWest() && IsWest() && IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[6]; MeshFlipX(); MeshFlipZ(); } //2 Corners SameSide, i[7] /* TTT * TTT * XTX */ else if (IsNorth() && IsNorthEast() && IsEast() && !IsSouthEast() && IsSouth() && !IsSouthWest() && IsWest() && IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[7]; MeshFlipZ(); } //2 Corners SameSide, i[7] /* TTX * TTT * TTX */ else if (IsNorth() && !IsNorthEast() && IsEast() && !IsSouthEast() && IsSouth() && IsSouthWest() && IsWest() && IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[7]; MeshRot90(); } //2 Corners SameSide, i[7] /* XTX * TTT * TTT */ else if (IsNorth() && !IsNorthEast() && IsEast() && IsSouthEast() && IsSouth() && IsSouthWest() && IsWest() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[7]; } //2 Corners SameSide, i[7] /* XTT * TTT * XTT */ else if (IsNorth() && IsNorthEast() && IsEast() && IsSouthEast() && IsSouth() && !IsSouthWest() && IsWest() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[7]; MeshRot90(); MeshFlipZ(); } //2 Corners OppositeSide, i[8] /* TTX * TTT * XTT */ else if (IsNorth() && !IsNorthEast() && IsEast() && IsSouthEast() && IsSouth() && !IsSouthWest() && IsWest() && IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[8]; } //2 Corners OppositeSide, i[8] /* XTT * TTT * TTX */ else if (IsNorth() && IsNorthEast() && IsEast() && !IsSouthEast() && IsSouth() && IsSouthWest() && IsWest() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[8]; MeshRot90(); } //3 Corners, i[9] /* XTX * TTT * TTX */ else if (IsNorth() && !IsNorthEast() && IsEast() && !IsSouthEast() && IsSouth() && IsSouthWest() && IsWest() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[9]; MeshRot90(); } //3 Corners, i[9] /* TTX * TTT * XTX */ else if (IsNorth() && !IsNorthEast() && IsEast() && !IsSouthEast() && IsSouth() && !IsSouthWest() && IsWest() && IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[9]; MeshFlipZ(); MeshFlipX(); } //3 Corners, i[9] /* XTT * TTT * XTX */ else if (IsNorth() && IsNorthEast() && IsEast() && !IsSouthEast() && IsSouth() && !IsSouthWest() && IsWest() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[9]; MeshFlipZ(); } //4 Corners, i[10] /* XTX * TTT * XTX */ else if (IsNorth() && !IsNorthEast() && IsEast() && !IsSouthEast() && IsSouth() && !IsSouthWest() && IsWest() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[10]; } //1 Side 1 corner /* OXO * TTT * TTX */ else if (IsWest() && IsEast() && IsSouth() && IsSouthWest() && !IsNorth() && !IsSouthEast()) { _meshFilter.mesh = _tiles.Meshes[11]; MeshFlipZ(); } //1 Side 1 corner /* OTX * XTT * OTT */ else if (IsNorth() && IsSouth() && IsEast() && IsSouthEast() && !IsWest() && !IsNorthEast()) { _meshFilter.mesh = _tiles.Meshes[11]; MeshRot90(); MeshFlipX(); } //1 Side 1 corner /* XTT * TTT * OXO */ else if (IsWest() && IsEast() && IsNorth() && IsNorthEast() && !IsSouth() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[11]; MeshFlipX(); } //1 Side 1 corner /* TTO * TTX * XTO */ else if (IsNorth() && IsSouth() && IsWest() && IsNorthWest() && !IsEast() && !IsSouthWest()) { _meshFilter.mesh = _tiles.Meshes[11]; MeshRot90(); MeshFlipZ(); } //1 Side 1 corner /* OXO * TTT * XTT */ else if (IsWest() && IsEast() && IsSouth() && IsSouthEast() && !IsNorth() && !IsSouthWest()) { _meshFilter.mesh = _tiles.Meshes[11]; MeshFlipZ(); MeshFlipX(); } //1 Side 1 corner /* XTO * TTX * TTO */ else if (IsNorth() && IsSouth() && IsWest() && IsSouthWest() && !IsEast() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[11]; MeshRot90(); MeshFlipZ(); MeshFlipX(); } //1 Side 1 corner /* TTX * TTT * OXO */ else if (IsWest() && IsEast() && IsNorth() && IsNorthWest() && !IsSouth() && !IsNorthEast()) { _meshFilter.mesh = _tiles.Meshes[11]; } //1 Side 1 corner /* OTT * XTT * OTX */ else if (IsNorth() && IsSouth() && IsEast() && IsNorthEast() && !IsWest() && !IsSouthEast()) { _meshFilter.mesh = _tiles.Meshes[11]; MeshRot90(); } //2 Side 1 Corner, i[12] /* OXO * XTT * OTX */ else if (IsEast() && IsSouth() && !IsNorth() && !IsWest() && !IsSouthEast()) { _meshFilter.mesh = _tiles.Meshes[12]; MeshFlipZ(); } //2 Side 1 Corner, i[12] /* OTX * XTT * OXO */ else if (IsEast() && IsNorth() && !IsSouth() && !IsWest() && !IsNorthEast()) { _meshFilter.mesh = _tiles.Meshes[12]; } //2 Side 1 Corner, i[12] /* XTO * TTX * OXO */ else if (IsWest() && IsNorth() && !IsSouth() && !IsEast() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[12]; MeshFlipX(); } //2 Side 1 Corner, i[12] /* OXO * TTX * XTO */ else if (IsWest() && IsSouth() && !IsNorth() && !IsEast() && !IsSouthWest()) { _meshFilter.mesh = _tiles.Meshes[12]; MeshFlipX(); MeshFlipZ(); } //1 Side 2 corner, i[13] /* OXO * TTT * XTX */ else if (IsWest() && IsEast() && IsSouth() && !IsNorth() && !IsSouthEast() && !IsSouthWest()) { _meshFilter.mesh = _tiles.Meshes[13]; MeshFlipZ(); } //1 Side 2 corner, i[13] /* XTX * TTT * OXO */ else if (IsWest() && IsEast() && IsNorth() && !IsSouth() && !IsNorthEast() && !IsNorthWest()) { _meshFilter.mesh = _tiles.Meshes[13]; } //1 Side 2 corner, i[13] /* OTX * XTT * OTX */ else if (IsNorth() && IsSouth() && IsEast() && !IsWest() && !IsNorthEast() && !IsSouthEast()) { _meshFilter.mesh = _tiles.Meshes[13]; MeshRot90(); } //1 Side 2 corner, i[13] /* XTO * TTX * XTO */ else if (IsNorth() && IsSouth() && IsWest() && !IsEast() && !IsNorthWest() && !IsSouthWest()) { _meshFilter.mesh = _tiles.Meshes[13]; MeshRot90(); MeshFlipZ(); } _myScript = null; _meshFilter = null; }
private static void UpdatePathTiles(ItemTile myScriptInc) { }
public static int TreasureValue(this ItemTile t) => t switch {
//callback for handling data received from the server (client-side) public void HandleReceivedData(object state) { PacketStream pkt = PopReceivedData(); pkt.Seek(1, System.IO.SeekOrigin.Begin); //these have to be out of scope of the switch block string uName; string msg; int dist, dir, newMapX, newMapY; int mapX, mapY, mapNum, bactCount, admin; switch (pkt.Action) { case ServerAction.ServerMessage: if (AddChatMessage != null) { msg = ""; if (!pkt.GetString(ref msg)) { break; } AddChatMessage(new ChatMessage { Message = msg, Username = "******", UsernameColor = System.Drawing.Color.Yellow }); } break; case ServerAction.ServerKick: //match packet formatting. two bytes to prevent erroneous kicks if ((ServerAction)pkt.Peek() == ServerAction.ServerKick) { World.GameState = GameState.PregameMenu; //hacky workaround so that the game state changes on the other thread before the dialog is construted // allows for the dialog to pop up once the game state changes properly and all the components are happy Thread.Sleep(100); Close(); //close first: we exit the game in UpdateErrorMessage if the client isn't connected if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Kicked from server by server.", "You were kicked!")); } } break; case ServerAction.ServerShutdown: World.GameState = GameState.Login; //hacky workaround so that the game state changes on the other thread before the dialog is construted // allows for the dialog to pop up once the game state changes properly and all the components are happy Thread.Sleep(100); Close(); //close first: we exit the game in UpdateErrorMessage if the client isn't connected. if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("The game server has been shut down.", "Server shut down")); } break; case ServerAction.ServerResponse: if ((ServerErrorResponse)pkt.Peek() == ServerErrorResponse.Success) { if (World.GameState == GameState.Registering) { World.GameState = GameState.Login; } LastAction = true; } else { if (World.GameState == GameState.Registering) { World.GameState = GameState.Register; } else if (World.GameState == GameState.LoggingIn) { World.GameState = GameState.Login; } else { World.GameState = GameState.PregameMenu; } switch ((ServerErrorResponse)pkt.Peek()) { //handle the errors case ServerErrorResponse.AccountAlreadyExists: if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("The specified account already exists.", "Error creating account!")); } break; case ServerErrorResponse.AccountCredentialMismatch: if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Mismatched username or password.")); } break; case ServerErrorResponse.AccountPasswordStrength: pkt.Seek(1); msg = "Password does not match requirement"; string custMsg = ""; if (!pkt.GetString(ref custMsg)) { msg += "."; } else { msg += "s " + custMsg; } if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs(msg, "Error creating account!")); } break; case ServerErrorResponse.DataFormatError: if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Data was formatted improperly.", "Server error")); } break; case ServerErrorResponse.InvalidAccessError: if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Access denied.")); } break; case ServerErrorResponse.ServerFatalError: if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Fatal server-side error.", "Server error")); } break; case ServerErrorResponse.ServerTooManyClients: if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("The server has reached the connection limit. Try again later.")); } break; case ServerErrorResponse.SQLQueryError: if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("There was an error querying the database.", "Server error")); } break; default: if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("The server returned an error.", "Server error")); } break; } LastAction = false; } response.Set(); break; case ServerAction.ClientCollectItem: uName = ""; int clientX = 0, clientY = 0; if (!pkt.GetString(ref uName) || !pkt.GetInt(ref clientX) || !pkt.GetInt(ref clientY)) { Console.WriteLine("Error getting data from server (collect)!"); break; } Tile iTile = World.CurrentMap.GetTile(clientX, clientY, LAYERS.Item); if (iTile != null) { ItemTile itemTile = iTile as ItemTile; if (itemTile.Type == ItemTileSpec.BACTERIA) { if (uName == UserName) { BacteriaCount += itemTile.Quantity; } World.CurrentMap.AddTile( new Microsoft.Xna.Framework.Vector2(clientX, clientY), LAYERS.Item, new ItemTile(ItemTileSpec.NONE, clientX, clientY)); if (BacteriaCollect != null && uName == UserName) { BacteriaCollect(null, null); } } } break; case ServerAction.Content: byte type = 0; int values = 0; if (!pkt.GetByte(ref type) || !pkt.GetInt(ref values)) { Console.WriteLine("Error getting data from server (content)!"); break; } ContentType contentType = (ContentType)type; if (contentType == ContentType.Items) { for (int i = 0; i < values; i++) { int x = 0, y = 0, quantity = 0; if (!pkt.GetByte(ref type) || !pkt.GetInt(ref x) || !pkt.GetInt(ref y) || !pkt.GetInt(ref quantity)) { Console.WriteLine("Error getting data from server (content)!"); break; } ItemTile tile = new ItemTile(ItemTileSpec.BACTERIA, x, y, quantity); World.CurrentMap.AddTile(new Microsoft.Xna.Framework.Vector2(x, y), LAYERS.Item, tile); } } else if (contentType == ContentType.Players) { for (int i = 0; i < values; i++) { mapNum = mapX = mapY = admin = 0; uName = ""; if (!pkt.GetInt(ref mapNum) || !pkt.GetInt(ref mapX) || !pkt.GetInt(ref mapY) || !pkt.GetString(ref uName) || !pkt.GetInt(ref admin)) { Console.WriteLine("Error getting data from server (content)!"); break; } if (World.Players.Where(j => j.UserName == uName).Count() == 0) { Player newPlayer = new Player(uName, mapNum, mapX, mapY, admin); newPlayer.FrontGraphicIndex = World.MainPlayer.FrontGraphicIndex; newPlayer.BackGraphicIndex = World.MainPlayer.BackGraphicIndex; newPlayer.LeftGraphicIndex = World.MainPlayer.LeftGraphicIndex; newPlayer.RightGraphicIndex = World.MainPlayer.RightGraphicIndex; newPlayer.CurrentGraphicIndex = newPlayer.FrontGraphicIndex; World.Players.Add(newPlayer); } } } break; case ServerAction.Walk: uName = ""; dist = dir = newMapX = newMapY = 0; int prevX = 0, prevY = 0; if (!pkt.GetString(ref uName) || !pkt.GetInt(ref dir) || !pkt.GetInt(ref dist) || !pkt.GetInt(ref newMapX) || !pkt.GetInt(ref newMapY) || !pkt.GetInt(ref prevX) || !pkt.GetInt(ref prevY)) { Console.WriteLine("Error getting data from server (walk)!"); break; } Player playerToMove; string directionString = ""; if (uName != UserName) { int otherPlayerIndex; if ((otherPlayerIndex = World.Players.FindIndex((Player other) => { return(other.UserName == uName); })) < 0) { //add the other player, manually set x/y Player add = new Player(uName, CurrentMap, prevX, prevY, 0); // Establish the graphic indices. For now, just set them to the same as the main player add.FrontGraphicIndex = World.MainPlayer.FrontGraphicIndex; add.BackGraphicIndex = World.MainPlayer.BackGraphicIndex; add.LeftGraphicIndex = World.MainPlayer.LeftGraphicIndex; add.RightGraphicIndex = World.MainPlayer.RightGraphicIndex; add.CurrentGraphicIndex = add.FrontGraphicIndex; World.Players.Add(add); playerToMove = add; directionString = ((Direction)dir).ToString(); } else { //move the other player based on direction/dist if it exists in the collection Direction direction = (Direction)dir; playerToMove = World.Players[otherPlayerIndex]; directionString = direction.ToString(); } if (Math.Abs(newMapX - playerToMove.X) > 1 || Math.Abs(newMapY - playerToMove.Y) > 1) { // Don't bother animating if we are too far away playerToMove.X = newMapX; playerToMove.Y = newMapY; switch ((Direction)dir) { case Direction.Up: playerToMove.CurrentGraphicIndex = playerToMove.BackGraphicIndex; break; case Direction.Down: playerToMove.CurrentGraphicIndex = playerToMove.FrontGraphicIndex; break; case Direction.Left: playerToMove.CurrentGraphicIndex = playerToMove.LeftGraphicIndex; break; case Direction.Right: playerToMove.CurrentGraphicIndex = playerToMove.RightGraphicIndex; break; } } else { playerToMove.NextMoves.Enqueue((Keys)Enum.Parse(typeof(Keys), directionString)); } } else { Direction direction = (Direction)dir; int correctedDistance = direction == Direction.Left || direction == Direction.Up ? dist * -1 : dist; int newPosition = direction == Direction.Left || direction == Direction.Right ? X + correctedDistance : Y + correctedDistance; if (CheckPosition(direction, newPosition)) { StartMoving(direction, dist); } } Console.Write("Player "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(uName); Console.ResetColor(); Console.WriteLine(" walked to [{0},{1}]", newMapX, newMapY); break; case ServerAction.WalkResponse: Console.WriteLine("Player {0} unable to walk because of obstacle on server.", UserName); break; case ServerAction.ClientLogin: uName = ""; newMapX = newMapY = admin = 0; if (!pkt.GetString(ref uName) || !pkt.GetInt(ref newMapX) || !pkt.GetInt(ref newMapY) || !pkt.GetInt(ref admin)) { World.GameState = GameState.PregameMenu; if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Error getting data from server (login).")); } break; } if (uName != World.MainPlayer.UserName) { int otherPlayerIndex; if ((otherPlayerIndex = World.Players.FindIndex((Player other) => { return(other.UserName == uName); })) < 0) { //add the other player, manually set x/y Player add = new Player(uName, CurrentMap, newMapX, newMapY, admin); // Establish the graphic indices. For now, just set them to the same as the main player add.FrontGraphicIndex = World.MainPlayer.FrontGraphicIndex; add.BackGraphicIndex = World.MainPlayer.BackGraphicIndex; add.LeftGraphicIndex = World.MainPlayer.LeftGraphicIndex; add.RightGraphicIndex = World.MainPlayer.RightGraphicIndex; add.CurrentGraphicIndex = add.FrontGraphicIndex; World.Players.Add(add); break; } } World.GameState = GameState.PregameMenu; if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Unexpected login packet received.")); } break; case ServerAction.ClientLoginResponse: uName = ""; mapX = mapY = mapNum = bactCount = admin = 0; if (LoggedIn) { if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Erroneous login response packet received!", "Unsupported game state!")); } break; } if (!pkt.GetString(ref uName) || !pkt.GetInt(ref mapNum) || !pkt.GetInt(ref mapX) || !pkt.GetInt(ref mapY) || !pkt.GetInt(ref bactCount) || !pkt.GetInt(ref admin)) { World.GameState = GameState.PregameMenu; if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Error getting data from server (LoginResponse)")); } break; } Login(uName, mapNum, mapX, mapY, bactCount, admin); LastAction = true; response.Set(); if (World.GameState == GameState.LoggingIn) { World.GameState = GameState.InGame; } break; case ServerAction.ClientLogout: uName = ""; if (!pkt.GetString(ref uName)) { World.GameState = GameState.PregameMenu; if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Error getting data from server (logout).")); } Logout(); break; } if (uName == UserName) { World.GameState = GameState.PregameMenu; Logout(); } else { World.Players.RemoveAll((Player x) => { return(x.UserName == uName); }); } break; case ServerAction.ClientSay: uName = msg = ""; if (!pkt.GetString(ref uName) || !pkt.GetString(ref msg)) { Console.WriteLine("Error getting data from server (say)!"); break; } bool isAdmin = World.Players.FindIndex((Player adminSearch) => { return(adminSearch.UserName == uName && adminSearch.AdminLevel > 0); }) >= 0; System.Drawing.Color uNameColor = uName == UserName ? System.Drawing.Color.Blue : System.Drawing.Color.Cyan; uNameColor = isAdmin ? System.Drawing.Color.Purple : uNameColor; AddChatMessage(new ChatMessage { Message = msg, MessageColor = System.Drawing.Color.White, Username = uName, UsernameColor = uNameColor }); break; case ServerAction.Warp: uName = ""; mapNum = mapX = mapY = 0; Player playa = null; if (!pkt.GetString(ref uName) || !pkt.GetInt(ref mapNum) || !pkt.GetInt(ref mapX) || !pkt.GetInt(ref mapY)) { Console.WriteLine("Error getting data from server (Warp)!"); break; } if (uName != UserName) { int otherPlayerIndex; if ((otherPlayerIndex = World.Players.FindIndex((Player other) => { return(other.UserName == uName); })) < 0) { //add the other player, manually set x/y Player add = new Player(uName, CurrentMap, mapX, mapY, 1); // Establish the graphic indices. For now, just set them to the same as the main player add.FrontGraphicIndex = World.MainPlayer.FrontGraphicIndex; add.BackGraphicIndex = World.MainPlayer.BackGraphicIndex; add.LeftGraphicIndex = World.MainPlayer.LeftGraphicIndex; add.RightGraphicIndex = World.MainPlayer.RightGraphicIndex; add.CurrentGraphicIndex = add.FrontGraphicIndex; World.Players.Add(add); break; } } playa = World.Players.Find((Player p) => { return(uName == p.UserName); }); playa.CurrentMap = mapNum; playa.X = mapX; playa.Y = mapY; break; default: World.GameState = GameState.PregameMenu; if (UpdateErrorMessage != null) { UpdateErrorMessage(this, new UpdateArgs("Unhandled data received from server.")); } break; } pendingResponse = false; }
public void TranferItemData(ItemTile itemTile) { throw new NotImplementedException(); }