public override void ReleaseAltClick(Entity entity, ItemStack item) { // TODO: Handle non-players if (!(entity is PlayerEntity)) { return; } PlayerEntity player = (PlayerEntity)entity; if (player.TheRegion.GlobalTickTime - player.LastGunShot < fireRate) { return; } player.LastGunShot = player.TheRegion.GlobalTickTime; for (int i = 1; i < player.Breadcrumbs.Count; i++) { if ((player.GetPosition() - player.Breadcrumbs[i]).LengthSquared() < 4) { player.Breadcrumbs.RemoveRange(i, player.Breadcrumbs.Count - i); } } List<Location> locs = new List<Location>(); Location cpos = player.GetPosition(); for (int i = player.Breadcrumbs.Count - 1; i >= 0; i--) { if ((player.Breadcrumbs[i] - cpos).LengthSquared() > MaxRadius * MaxRadius) { break; } locs.Add(player.Breadcrumbs[i]); } if (locs.Count > 0) { player.Network.SendPacket(new PathPacketOut(locs)); } }
public AnimationPacketOut(Entity e, string anim, byte mode) { UsageType = NetUsageType.PLAYERS; ID = ServerToClientPacket.ANIMATION; Data = new byte[8 + 4 + 1]; Utilities.LongToBytes(e.EID).CopyTo(Data, 0); Utilities.IntToBytes(e.TheServer.Networking.Strings.IndexForString(anim)).CopyTo(Data, 8); Data[8 + 4] = mode; }
public override void Click(Entity entity, ItemStack item) { if (!(entity is PlayerEntity)) { // TODO: Work with non-players! return; } PlayerEntity player = (PlayerEntity)entity; player.TheRegion.SendToAll(new SunAnglePacketOut(180f + (double)player.Direction.Yaw, (double)-player.Direction.Pitch)); }
public JointForceWeld(Entity one, Entity two) { One = one; Two = two; Matrix worldTrans = Matrix.CreateFromQuaternion(One.GetOrientation()) * Matrix.CreateTranslation(One.GetPosition().ToBVector()); Matrix.Invert(ref worldTrans, out worldTrans); Relative = (Matrix.CreateFromQuaternion(two.GetOrientation()) * Matrix.CreateTranslation(two.GetPosition().ToBVector())) * worldTrans; }
public override void SwitchFrom(Entity entity, ItemStack item) { if (!(entity is PlayerEntity)) { // TODO: non-player support return; } PlayerEntity player = (PlayerEntity)entity; Off(player); }
public override void AltClick(Entity entity, ItemStack item) { if (!(entity is PlayerEntity)) { // TODO: non-player support return; } PlayerEntity player = (PlayerEntity)entity; if (player.GrabJoint != null) { player.TheRegion.DestroyJoint(player.GrabJoint); } player.GrabJoint = null; }
public override void AltClick(Entity entity, ItemStack item) { if (!(entity is PlayerEntity)) { // TODO: non-player support return; } PlayerEntity player = (PlayerEntity)entity; if (player.LastAltClick + 0.2 > player.TheRegion.GlobalTickTime) { return; } RemoveHook(player); }
public override void AltClick(Entity entity, ItemStack item) { if (!(entity is PlayerEntity)) { // TODO: non-player support return; } PlayerEntity player = (PlayerEntity)entity; Location eye = player.GetEyePosition(); Location forw = player.ForwardVector(); RayCastResult rcr; bool h = player.TheRegion.SpecialCaseRayTrace(eye, forw, 5, MaterialSolidity.ANY, player.IgnoreThis, out rcr); if (h) { if (rcr.HitObject != null && rcr.HitObject is EntityCollidable && ((EntityCollidable)rcr.HitObject).Entity != null) { // TODO: ??? } else if (player.Mode.GetDetails().CanPlace && player.TheRegion.GlobalTickTime - player.LastBlockPlace >= 0.2) { Location block = new Location(rcr.HitData.Location) + new Location(rcr.HitData.Normal).Normalize() * 0.9f; block = block.GetBlockLocation(); Material mat = player.TheRegion.GetBlockMaterial(block); if (player.TheRegion.IsAllowedToPlaceIn(player, block, mat)) { CollisionResult hit = player.TheRegion.Collision.CuboidLineTrace(new Location(0.45, 0.45, 0.45), block + new Location(0.5), block + new Location(0.5, 0.5, 0.501), player.TheRegion.Collision.ShouldCollide); if (!hit.Hit) { BlockInternal bi = BlockInternal.FromItemDatum(item.Datum); player.TheRegion.PhysicsSetBlock(block, (Material)bi.BlockMaterial, bi.BlockData, bi.BlockPaint); player.Network.SendPacket(new DefaultSoundPacketOut(block, DefaultSound.PLACE, (byte)((Material)bi.BlockMaterial).Sound())); item.Count = item.Count - 1; if (item.Count <= 0) { player.Items.RemoveItem(player.Items.cItem); } else { player.Items.SetSlot(player.Items.cItem - 1, item); } player.LastBlockPlace = player.TheRegion.GlobalTickTime; } } } } }
public override void Click(Entity entity, ItemStack item) { if (!(entity is HumanoidEntity)) { // TODO: non-humanoid support return; } HumanoidEntity character = (HumanoidEntity)entity; double fireRate = FireRate * item.GetAttributeF("firerate_mod", 1f); if (item.Datum != 0 && !character.WaitingForClickRelease && (character.TheRegion.GlobalTickTime - character.LastGunShot >= fireRate)) { double spread = Spread * item.GetAttributeF("spread_mod", 1f); double speed = Speed * item.GetAttributeF("speed_mod", 1f); int shots = (int)((double)Shots * item.GetAttributeF("shots_mod", 1f)); for (int i = 0; i < shots; i++) { BulletEntity be = new BulletEntity(character.TheRegion); be.SetPosition(character.GetEyePosition()); // TODO: ItemPosition? be.NoCollide.Add(character.EID); Location ang = character.Direction; ang.Yaw += Utilities.UtilRandom.NextDouble() * spread * 2 - spread; ang.Pitch += Utilities.UtilRandom.NextDouble() * spread * 2 - spread; be.SetVelocity(Utilities.ForwardVector_Deg(ang.Yaw, ang.Pitch) * speed); be.Size = RoundSize; be.Damage = ImpactDamage; be.SplashSize = SplashSize; be.SplashDamage = SplashMaxDamage; character.TheRegion.SpawnEntity(be); } if (ShotPerClick) { character.WaitingForClickRelease = true; } character.LastGunShot = character.TheRegion.GlobalTickTime; item.Datum -= 1; if (character is PlayerEntity) { ((PlayerEntity)character).Network.SendPacket(new SetItemPacketOut(character.Items.Items.IndexOf(item), item)); } } else if (item.Datum == 0 && !character.WaitingForClickRelease) { Reload(character, item); } }
public override void Click(Entity entity, ItemStack item) { if (!(entity is PlayerEntity)) { // TODO: non-player support return; } PlayerEntity player = (PlayerEntity)entity; Location end = player.GetEyePosition() + player.ForwardVector() * 5; CollisionResult cr = player.TheRegion.Collision.CuboidLineTrace(new Location(0.1, 0.1, 0.1), player.GetEyePosition(), end, player.IgnoreThis); if (cr.Hit && cr.HitEnt != null) { // TODO: handle static world impact PhysicsEntity pe = (PhysicsEntity)cr.HitEnt.Tag; if (pe.GetMass() > 0 && pe.GetMass() < 200) { Grab(player, pe, cr.Position); } else { // If (HandHold) { Grab(player, pe, cr.Position); } } } }
public override void SwitchFrom(Entity entity, ItemStack item) { // TODO: Handle non-players if (!(entity is PlayerEntity)) { return; } PlayerEntity player = (PlayerEntity)entity; player.LastGunShot = 0; }
public override void ReleaseAltClick(Entity entity, ItemStack item) { }
public EntityInventory(Region tregion, Entity owner) : base(tregion) { Owner = owner; }
public abstract void Use(Entity entity, ItemStack item);
public override void Tick(Entity entity, ItemStack item) { if (!(entity is HumanoidEntity)) { // TODO: non-humanoid support return; } HumanoidEntity character = (HumanoidEntity)entity; if (character.Flags.HasFlag(YourStatusFlags.RELOADING) && (character.TheRegion.GlobalTickTime - character.LastGunShot >= FireRate)) { character.Flags &= ~YourStatusFlags.RELOADING; UpdatePlayer(character); } else if (!character.Flags.HasFlag(YourStatusFlags.RELOADING) && (character.TheRegion.GlobalTickTime - character.LastGunShot < FireRate)) { character.Flags |= YourStatusFlags.RELOADING; UpdatePlayer(character); } if (!character.Flags.HasFlag(YourStatusFlags.NEEDS_RELOAD) && item.Datum == 0) { character.Flags |= YourStatusFlags.NEEDS_RELOAD; UpdatePlayer(character); } else if (character.Flags.HasFlag(YourStatusFlags.NEEDS_RELOAD) && item.Datum != 0) { character.Flags &= ~YourStatusFlags.NEEDS_RELOAD; UpdatePlayer(character); } }
public override void Click(Entity entity, ItemStack item) { }
public abstract void ReleaseClick(Entity entity, ItemStack item);
public override void ReleaseAltClick(Entity player, ItemStack item) { }
public override void ReleaseClick(Entity entity, ItemStack item) { if (!(entity is HumanoidEntity)) { // TODO: non-humanoid support return; } HumanoidEntity character = (HumanoidEntity)entity; character.WaitingForClickRelease = false; }
public override void Tick(Entity entity, ItemStack item) { if (!(entity is PlayerEntity)) { // TODO: non-player support return; } PlayerEntity player = (PlayerEntity)entity; if (player.ItemLeft && !player.WasItemLefting && player.Hooks.Count > 0) { Extend(player); } if (player.ItemRight && !player.WasItemRighting && player.Hooks.Count > 0) { Shrink(player); } }
public override void Click(Entity entity, ItemStack item) { if (!(entity is PlayerEntity)) { // TODO: non-player support return; } PlayerEntity player = (PlayerEntity)entity; if (player.LastClick + 0.2 > player.TheRegion.GlobalTickTime) { return; } Location eye = player.GetEyePosition(); Location adj = player.ForwardVector() * 20f; CollisionResult cr = player.TheRegion.Collision.CuboidLineTrace(new Location(0.1f), eye, eye + adj, player.IgnoreThis); if (!cr.Hit) { return; } ApplyHook(player, item, cr.Position, cr.HitEnt); }
public override void Use(Entity player, ItemStack item) { }
public override void SwitchTo(Entity entity, ItemStack item) { }
public abstract void SwitchTo(Entity entity, ItemStack item);
public override void Use(Entity entity, ItemStack item) { }
public abstract void Tick(Entity entity, ItemStack item);
public override void PrepItem(Entity entity, ItemStack item) { }
public override void SwitchFrom(Entity entity, ItemStack item) { if (!(entity is HumanoidEntity)) { // TODO: non-humanoid support return; } HumanoidEntity character = (HumanoidEntity)entity; character.WaitingForClickRelease = false; character.LastGunShot = 0; if (!(entity is PlayerEntity)) { return; } PlayerEntity player = (PlayerEntity)entity; player.Flags &= ~YourStatusFlags.RELOADING; player.Flags &= ~YourStatusFlags.NEEDS_RELOAD; UpdatePlayer(player); }
public override void ReleaseClick(Entity entity, ItemStack item) { // TODO: Handle non-players if (!(entity is PlayerEntity)) { return; } PlayerEntity player = (PlayerEntity)entity; player.Breadcrumbs.Clear(); player.Breadcrumbs.Add(player.GetPosition().GetBlockLocation() + new Location(0.5f, 0.5f, 0.5f)); // TODO: Effect? }
// TODO: Entity -> LivingEntity? Or CharacterEntity? public abstract void PrepItem(Entity entity, ItemStack item);