static Vec3U16 MissileTarget(WeaponArgs args) { Player p = args.player; args.start = MakePos(p); args.dir = DirUtils.GetDirVector(p.Rot.RotY, p.Rot.HeadX); int i; for (i = 1; ; i++) { Vec3U16 target = args.PosAt(i); BlockID block = p.level.GetBlock(target.X, target.Y, target.Z); if (block == Block.Invalid) { break; } if (block != Block.Air && !args.allBlocks.Contains(target) && HandlesHitBlock(p, block, args.weaponType, target, false)) { break; } Player hit = GetPlayer(p, target, true); if (hit != null) { return(MakePos(hit)); } } return(args.PosAt(i - 1)); }
protected override void PlacedMark(Player p, ushort x, ushort y, ushort z, BlockID block) { p.RevertBlock(x, y, z); if (!p.level.Config.Guns) { p.ClearBlockchange(); return; } if (!CommandParser.IsBlockAllowed(p, "use", block)) { return; } WeaponArgs args = new WeaponArgs(); args.player = p; args.block = block; args.weaponType = (WeaponType)p.blockchangeObject; args.start = MakePos(p); args.dir = DirUtils.GetFlatDirVector(p.Rot.RotY, p.Rot.HeadX); args.pos = args.PosAt(3); args.iterations = 4; SchedulerTask task = new SchedulerTask(GunCallback, args, TimeSpan.Zero, true); p.CriticalTasks.Add(task); }
static bool MoveGun(WeaponArgs args) { while (true) { args.pos = args.PosAt(args.iterations); args.iterations++; Vec3U16 pos = args.pos; BlockID cur = args.player.level.GetBlock(pos.X, pos.Y, pos.Z); if (cur == Block.Invalid) { return(false); } if (cur != Block.Air && !args.allBlocks.Contains(pos) && HandlesHitBlock(args.player, cur, args.weaponType, pos, true)) { return(false); } args.player.level.Blockchange(pos.X, pos.Y, pos.Z, args.block); args.previous.Add(pos); args.allBlocks.Add(pos); if (HitsPlayer(args, pos)) { return(false); } if (args.iterations > 12 && args.weaponType != WeaponType.Laser) { pos = args.previous[0]; args.previous.RemoveAt(0); args.player.level.Blockchange(pos.X, pos.Y, pos.Z, Block.Air, true); } if (args.weaponType != WeaponType.Laser) { return(true); } } }