/// <summary> /// Tries to parse a script node. /// </summary> /// <param name="Parser">Custom parser.</param> /// <param name="Result">Parsed Script Node.</param> /// <returns>If successful in parsing a script node.</returns> public bool TryParse(ScriptParser Parser, out ScriptNode Result) { Result = null; try { string s = Parser.NextToken().ToUpper(); if (s != "INDEX") { return(false); } ScriptNode Name = Parser.ParseNoWhiteSpace(); s = Parser.NextToken().ToUpper(); if (s != "ON") { return(false); } if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source)) { return(false); } Result = new DropIndex(Name, Source, Parser.Start, Parser.Length, Parser.Expression); return(true); } catch (Exception) { return(false); } }
public void RestartGame() { PlayerIndex.Clear(); MobIndex.Clear(); DropIndex.Clear(); FallingBlockIndex.Clear(); RedTent = new Tent(true, Vector2.Zero, false, false); BlueTent = new Tent(false, Vector2.Zero, false, false); }
public void RestartGame() { foreach (KeyValuePair <int, Player> entry in PlayerIndex.ToArray()) { entry.Value.Restart(); } MobIndex.Clear(); DropIndex.Clear(); FallingBlockIndex.Clear(); WorldMap.InitLevelFromRotation(); TimeRemaining.Start(DEFAULT_TIME_REMAINING); RestartInterval.Reset(); RedTent = new Tent(true, WorldMap.RedTentPosition, ServerMode == GameMode.CaptureTheFlag, true); BlueTent = new Tent(false, WorldMap.BlueTentPosition, ServerMode == GameMode.CaptureTheFlag, true); }
/// <summary> /// Tries to parse a script node. /// </summary> /// <param name="Parser">Custom parser.</param> /// <param name="Result">Parsed Script Node.</param> /// <returns>If successful in parsing a script node.</returns> public bool TryParse(ScriptParser Parser, out ScriptNode Result) { Result = null; try { string s = Parser.NextToken().ToUpper(); switch (s) { case "INDEX": ScriptNode Name = Parser.ParseNoWhiteSpace(); s = Parser.NextToken().ToUpper(); if (s != "ON") { return(false); } if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source)) { return(false); } Result = new DropIndex(Name, Source, Parser.Start, Parser.Length, Parser.Expression); return(true); case "TABLE": case "COLLECTION": if (!SelectParser.TryParseSources(Parser, out Source)) { return(false); } Result = new DropCollection(Source, Parser.Start, Parser.Length, Parser.Expression); return(true); default: return(false); } } catch (Exception) { return(false); } }
public bool AddDrop(int id, ItemDrop drop) { return(DropIndex.TryAdd(id, drop)); }
public void Update(float msElapsed) { if (RestartInterval.Left > 1 || !RestartInterval.IsRunning) { foreach (KeyValuePair <int, Player> entry in PlayerIndex.ToArray()) { Player player = entry.Value; player.Update(msElapsed, WorldMap, RedTent.Position, BlueTent.Position); if (player.Y >= WorldMap.Height * Universal.TILE_SIZE - Universal.TILE_SIZE * 3) { network.SendKilledPlayer(-1, entry.Key, player); player.DeathAction(false); network.SendServerMove(entry.Key, player); player.RespondMove = false; network.CheckWinCondition(); } } foreach (KeyValuePair <int, Mob> entry in MobIndex.ToArray()) { if (entry.Value.Dead) { foreach (ItemDrop drop in entry.Value.Drops) { int id = 0; foreach (KeyValuePair <int, ItemDrop> dropEntry in DropIndex.ToArray()) { if (dropEntry.Key == id) { id++; } } DropIndex.TryAdd(id, drop); } network.SendRemoveMob(entry.Key, entry.Value.Drops); Universal.TryDictRemove(MobIndex, entry.Key); } else { entry.Value.Update(msElapsed, WorldMap); } } foreach (KeyValuePair <int, ItemDrop> entry in DropIndex.ToArray()) { entry.Value.Update(msElapsed, WorldMap); } foreach (KeyValuePair <int, FallingBlock> entry in FallingBlockIndex.ToArray()) { FallingBlock fallingBlock = entry.Value; fallingBlock.Update(msElapsed, WorldMap); if (Math.Abs(fallingBlock.DY) > 70) { foreach (KeyValuePair <int, Mob> mobEntry in MobIndex.ToArray()) { Mob mob = mobEntry.Value; if (fallingBlock.CollideBox.Intersects(mob.CollideBox)) { mob.Damage(2); network.SendHitMob(mobEntry.Key, 2); } } foreach (KeyValuePair <int, Player> playerEntry in PlayerIndex.ToArray()) { Player targetPlayer = playerEntry.Value; if (fallingBlock.CollideBox.Intersects(targetPlayer.CollideBox)) { targetPlayer.Damage(2); network.SendHitPlayer(playerEntry.Key, 2, targetPlayer.DX, targetPlayer.DY); if (targetPlayer.HP <= 0) { Player killer; if (fallingBlock.PlayerID != playerEntry.Key && PlayerIndex.TryGetValue(fallingBlock.PlayerID, out killer) && (targetPlayer.PlayerTeam.Name == "No Team" || killer.PlayerTeam.Name != targetPlayer.PlayerTeam.Name)) { killer.Kills++; network.SendKilledPlayer(fallingBlock.PlayerID, playerEntry.Key, targetPlayer); } else { network.SendKilledPlayer(-1, playerEntry.Key, targetPlayer); } targetPlayer.DeathAction(false); network.SendServerMove(playerEntry.Key, targetPlayer); targetPlayer.RespondMove = false; network.CheckWinCondition(); } } } } if (fallingBlock.CanDestroy) { network.SendRemoveFallingBlock(entry.Key); Universal.TryDictRemove(FallingBlockIndex, entry.Key); } } if (ServerMode == GameMode.TeamDeathmatch || ServerMode == GameMode.CaptureTheFlag) { RedTent.Update(msElapsed, WorldMap); BlueTent.Update(msElapsed, WorldMap); } } TimeRemaining.Update(msElapsed); RestartInterval.Update(msElapsed); }
public void Update(GameTime gameTime, KeyboardState lastKeyState, MouseState lastMouseState, bool chatting) { MouseState mouseState = Mouse.GetState(); bool playerTeam = MainPlayer.PlayerTeam.Name == "Red Team"; if (online) { foreach (KeyValuePair <int, Player> entry in PlayerIndex.ToArray()) { if (!chatting) { entry.Value.Update(gameTime, lastKeyState, lastMouseState, DrawBlockOutline, entry.Value == MainPlayer); } else { entry.Value.Update(gameTime, lastKeyState, lastMouseState, DrawBlockOutline, false); } } } foreach (KeyValuePair <int, Mob> entry in MobIndex.ToArray()) { entry.Value.Update(gameTime, WorldMap); } foreach (KeyValuePair <int, ItemDrop> entry in DropIndex.ToArray()) { entry.Value.Update(gameTime, WorldMap, MainPlayer.Items, new Vector2(MainPlayer.X + MainPlayer.BoundWidth, MainPlayer.Y + MainPlayer.BoundHeight), playerTeam); } foreach (KeyValuePair <int, FallingBlock> entry in FallingBlockIndex.ToArray()) { FallingBlock fallingBlock = entry.Value; fallingBlock.Update(gameTime, WorldMap); if (fallingBlock.CanDestroy) { Universal.TryDictRemove(FallingBlockIndex, entry.Key); } } if (ServerMode == GameMode.TeamDeathmatch || ServerMode == GameMode.CaptureTheFlag) { RedTent.Update(gameTime, WorldMap, MainPlayer.Items, MainPlayer.Position, playerTeam); BlueTent.Update(gameTime, WorldMap, MainPlayer.Items, MainPlayer.Position, playerTeam); } foreach (GameObject gameObject in objectList.ToArray()) { gameObject.Update(gameTime); if (gameObject.Dead) { objectList.Remove(gameObject); } } int blockX = (camera.CX + mouseState.X) / 16; int blockY = (camera.CY + mouseState.Y) / 16; Item selectedItem = MainPlayer.SelectedItem; if (MainPlayer.Motion != Vector2.Zero || mouseState.LeftButton != lastMouseState.LeftButton || mouseState.RightButton != lastMouseState.RightButton || blockX != lastBlockX || blockY != lastBlockY) { DrawBlockOutline = false; if (blockX >= 0 && blockX < WorldMap.Width && blockY >= 0 && blockY < WorldMap.Height && Vector2.Distance(new Vector2(MainPlayer.X + MainPlayer.BoundWidth, MainPlayer.Y + MainPlayer.BoundHeight / 2), new Vector2(camera.CX + mouseState.X, camera.CY + mouseState.Y)) <= Universal.TILE_SIZE * Universal.PLACE_DISTANCE) { if (mouseState.RightButton == ButtonState.Pressed && WorldMap.Tiles[0, blockX, blockY].ID >= 0) { DrawBlockOutline = true; } else if (selectedItem.Type == ItemType.Block && mouseState.RightButton == ButtonState.Released && WorldMap.Tiles[0, blockX, blockY].ID == -1) { if (blockX >= 0 && blockX < WorldMap.Width) { if (blockY - 1 >= 0 && WorldMap.Tiles[0, blockX, blockY - 1].ID >= 0) { DrawBlockOutline = true; } if (blockY + 1 < WorldMap.Height && WorldMap.Tiles[0, blockX, blockY + 1].ID >= 0) { DrawBlockOutline = true; } } if (blockY >= 0 && blockY < WorldMap.Height) { if (blockX - 1 >= 0 && WorldMap.Tiles[0, blockX - 1, blockY].ID >= 0) { DrawBlockOutline = true; } if (blockX + 1 < WorldMap.Width && WorldMap.Tiles[0, blockX + 1, blockY].ID >= 0) { DrawBlockOutline = true; } } if (blockX == 0 || blockX == WorldMap.Width - 1 || blockY == 0 || blockY == WorldMap.Height - 1) { DrawBlockOutline = true; } } } } if (network != null && (mouseState.RightButton != lastMouseState.RightButton || blockX != lastBlockX || blockY != lastBlockY)) { network.SendHitBlock(DrawBlockOutline, mouseState.X, mouseState.Y); } lastBlockX = blockX; lastBlockY = blockY; if (!MainPlayer.RespawnInterval.IsRunning) { camera.Position = MainPlayer.Position; } if (camera.X < Universal.SCREEN_WIDTH / 2) { camera.X = Universal.SCREEN_WIDTH / 2; } else if (camera.X > WorldMap.Width * Universal.TILE_SIZE - Universal.SCREEN_WIDTH / 2) { camera.X = WorldMap.Width * Universal.TILE_SIZE - Universal.SCREEN_WIDTH / 2; } if (camera.Y < Universal.SCREEN_HEIGHT / 2) { camera.Y = Universal.SCREEN_HEIGHT / 2; } else if (camera.Y > WorldMap.Height * Universal.TILE_SIZE - Universal.SCREEN_HEIGHT / 2) { camera.Y = WorldMap.Height * Universal.TILE_SIZE - Universal.SCREEN_HEIGHT / 2; } WorldMap.CheckRender(); }
public Expression GetNode(ExpressionParser parser) { Lexem lex = parser.Collection.CurrentLexem(); Expression res = null; if (lex.LexemType == LexType.Command) { string lowerLexem = lex.LexemText.ToLower(); if (ParserUtils.ParseCommandPhrase(parser.Collection, "create view", false, false)) { res = new CreateView(); } if (ParserUtils.ParseCommandPhrase(parser.Collection, "create table", false, false)) { res = new CreateTable(); } if (res == null && ParserUtils.ParseCommandPhrase(parser.Collection, "alter table", false, false)) { res = new AlterTable(); } if (res == null && ParserUtils.ParseCommandPhrase(parser.Collection, "drop table", false, false)) { res = new DropTable(); } if (res == null && ParserUtils.ParseCommandPhrase(parser.Collection, "drop index", false, false)) { res = new DropIndex(); } if (res == null && (ParserUtils.ParseCommandPhrase(parser.Collection, "create unique index", false, false) || ParserUtils.ParseCommandPhrase(parser.Collection, "create index", false, false))) { res = new CreateIndex(); } if (res == null) { if (parser.Collection.GetNext() != null && parser.Collection.GetNext().IsSkobraOpen()) { switch (lowerLexem) { case "count": res = new CountExpr(); break; case "sum": res = new SumExpr(); break; case "min": res = new MinExpr(); break; case "max": res = new MaxExpr(); break; case "avg": res = new AvgExpr(); break; case "lastinsertrowid": res = new LastInsertRowidExpr(); break; case "exists": res = new ExistsExpr(); break; case "any": res = new AnyExpr(); break; } } switch (lowerLexem) { case "between": //не функция res = new Between(); break; case "select": res = new SelectExpresion(); break; case "update": res = new UpdateStatement(); break; case "insert": res = new InsertStatement(); break; case "delete": res = new DeleteStatement(); break; } } } if (res != null) { return(res); } return(res); }
public string visit(DropIndex ddl) { return ""; }