protected override void OnActivated(Vec3F32 dir, BlockID block) { AmmunitionData args = MakeArgs(dir, block); SchedulerTask task = new SchedulerTask(GunCallback, args, TimeSpan.Zero, true); p.CriticalTasks.Add(task); }
bool TickGun(AmmunitionData args) { while (true) { Vec3U16 pos = args.PosAt(args.iterations); args.iterations++; BlockID cur = p.level.GetBlock(pos.X, pos.Y, pos.Z); if (cur == Block.Invalid) { return(false); } if (cur != Block.Air && !args.all.Contains(pos) && OnHitBlock(args, pos, cur)) { return(false); } p.level.BroadcastChange(pos.X, pos.Y, pos.Z, args.block); args.visible.Add(pos); args.all.Add(pos); Player pl = PlayerAt(p, pos, true); if (pl != null) { OnHitPlayer(args, pl); return(false); } if (TickMove(args)) { return(true); } } }
protected override bool OnHitBlock(AmmunitionData args, Vec3U16 pos, BlockID block) { if (p.level.physics >= 3) { p.level.MakeExplosion(pos.X, pos.Y, pos.Z, 1); } return(true); }
protected virtual bool TickMove(AmmunitionData args) { if (args.iterations > 12) { Vec3U16 pos = args.visible[0]; args.visible.RemoveAt(0); p.level.BroadcastRevert(pos.X, pos.Y, pos.Z); } return(true); }
protected AmmunitionData MakeArgs(Vec3F32 dir, BlockID block) { AmmunitionData args = new AmmunitionData(); args.block = block; args.start = (Vec3U16)p.Pos.BlockCoords; args.dir = dir; args.iterations = 4; return(args); }
protected override void OnHitPlayer(AmmunitionData args, Player pl) { if (pl.level.physics >= 3) { pl.HandleDeath(Block.Cobblestone, "@p %Swas blown up by " + p.ColoredName, true); } else { base.OnHitPlayer(args, pl); } }
void DoTeleport(AmmunitionData args) { int i = args.visible.Count - 3; if (i >= 0 && i < args.visible.Count) { Vec3U16 coords = args.visible[i]; Position pos = new Position(coords.X * 32, coords.Y * 32 + 32, coords.Z * 32); p.SendPos(Entities.SelfID, pos, p.Rot); } }
protected virtual bool TickRevert(SchedulerTask task) { AmmunitionData args = (AmmunitionData)task.State; if (args.visible.Count > 0) { Vec3U16 pos = args.visible[0]; args.visible.RemoveAt(0); p.level.BroadcastRevert(pos.X, pos.Y, pos.Z); } return(args.visible.Count > 0); }
protected void GunCallback(SchedulerTask task) { AmmunitionData args = (AmmunitionData)task.State; if (args.moving) { args.moving = TickGun(args); } else { task.Repeating = TickRevert(task); } }
protected override bool OnHitBlock(AmmunitionData args, Vec3U16 pos, BlockID block) { if (p.level.physics < 2) { return(true); } if (!p.level.Props[block].LavaKills) { return(true); } // Penetrative gun goes through blocks lava can go through p.level.Blockchange(pos.X, pos.Y, pos.Z, Block.Air); return(false); }
protected override bool TickRevert(SchedulerTask task) { AmmunitionData args = (AmmunitionData)task.State; if (args.all.Count > 0) { // laser persists for a short while task.Delay = TimeSpan.FromMilliseconds(400); args.all.Clear(); } else { foreach (Vec3U16 pos in args.visible) { p.level.BroadcastRevert(pos.X, pos.Y, pos.Z); } args.visible.Clear(); } return(args.visible.Count > 0); }
/// <summary> Called when a bullet has collided with a player. </summary> protected virtual void OnHitPlayer(AmmunitionData args, Player pl) { pl.HandleDeath(Block.Cobblestone, "@p %Swas shot by " + p.ColoredName); }
/// <summary> Called when a bullet has collided with a block. </summary> /// <returns> true if this block stops the bullet, false if it should continue moving. </returns> protected virtual bool OnHitBlock(AmmunitionData args, Vec3U16 pos, BlockID block) { return(true); }
protected override bool OnHitBlock(AmmunitionData args, Vec3U16 pos, BlockID block) { args.DoTeleport(p); return(true); }
protected override void OnHitPlayer(AmmunitionData args, Player pl) { args.DoTeleport(p); }
protected override bool TickMove(AmmunitionData args) { // laser immediately strikes target return(false); }