コード例 #1
0
        private void onPhysicsTickCallback(float dtFac)
        {
            if (ShouldDespawn || !Alive)
            {
                return;
            }
            if (World is IClientWorldAccessor || World.ElapsedMilliseconds <= msCollide + 500)
            {
                return;
            }
            if (ServerPos.Motion.X == 0 && ServerPos.Motion.Y == 0 && ServerPos.Motion.Z == 0)
            {
                return;                                                                                 // don't do damage if stuck in ground
            }
            Cuboidd projectileBox = SelectionBox.ToDouble().Translate(ServerPos.X, ServerPos.Y, ServerPos.Z);

            if (ServerPos.Motion.X < 0)
            {
                projectileBox.X1 += ServerPos.Motion.X * dtFac;
            }
            else
            {
                projectileBox.X2 += ServerPos.Motion.X * dtFac;
            }
            if (ServerPos.Motion.Y < 0)
            {
                projectileBox.Y1 += ServerPos.Motion.Y * dtFac;
            }
            else
            {
                projectileBox.Y2 += ServerPos.Motion.Y * dtFac;
            }
            if (ServerPos.Motion.Z < 0)
            {
                projectileBox.Z1 += ServerPos.Motion.Z * dtFac;
            }
            else
            {
                projectileBox.Z2 += ServerPos.Motion.Z * dtFac;
            }

            ep.WalkEntities(ServerPos.XYZ, 5f, (e) => {
                if (e.EntityId == this.EntityId || !e.IsInteractable || (FiredBy != null && e.EntityId == FiredBy.EntityId && World.ElapsedMilliseconds - msLaunch < 500))
                {
                    return(true);
                }

                Cuboidd eBox = e.SelectionBox.ToDouble().Translate(e.ServerPos.X, e.ServerPos.Y, e.ServerPos.Z);

                if (eBox.IntersectsOrTouches(projectileBox))
                {
                    impactOnEntity(e);
                    return(false);
                }

                return(true);
            });
        }
コード例 #2
0
        bool TryAttackEntity(double impactSpeed)
        {
            if (World is IClientWorldAccessor || World.ElapsedMilliseconds <= msCollide + 250)
            {
                return(false);
            }
            if (impactSpeed <= 0.01)
            {
                return(false);
            }

            EntityPos pos = SidedPos;

            Cuboidd projectileBox = SelectionBox.ToDouble().Translate(ServerPos.X, ServerPos.Y, ServerPos.Z);

            // We give it a bit of extra leeway of 50% because physics ticks can run twice or 3 times in one game tick
            if (ServerPos.Motion.X < 0)
            {
                projectileBox.X1 += 1.5 * ServerPos.Motion.X;
            }
            else
            {
                projectileBox.X2 += 1.5 * ServerPos.Motion.X;
            }
            if (ServerPos.Motion.Y < 0)
            {
                projectileBox.Y1 += 1.5 * ServerPos.Motion.Y;
            }
            else
            {
                projectileBox.Y2 += 1.5 * ServerPos.Motion.Y;
            }
            if (ServerPos.Motion.Z < 0)
            {
                projectileBox.Z1 += 1.5 * ServerPos.Motion.Z;
            }
            else
            {
                projectileBox.Z2 += 1.5 * ServerPos.Motion.Z;
            }

            Entity entity = World.GetNearestEntity(ServerPos.XYZ, 5f, 5f, (e) => {
                if (e.EntityId == this.EntityId || !e.IsInteractable)
                {
                    return(false);
                }

                if (FiredBy != null && e.EntityId == FiredBy.EntityId && World.ElapsedMilliseconds - msLaunch < 500)
                {
                    return(false);
                }

                Cuboidd eBox = e.SelectionBox.ToDouble().Translate(e.ServerPos.X, e.ServerPos.Y, e.ServerPos.Z);

                return(eBox.IntersectsOrTouches(projectileBox));
            });

            if (entity != null)
            {
                impactOnEntity(entity);
                return(true);
            }


            return(false);
        }