Beispiel #1
0
        public bool VisitBlock(World world, Vector3I pos, Block block, Player owner, ref int restDistance,
                               IList <BlockUpdate> updates, Block sending)
        {
            if (Block.Air != block) //hit a building
            {
                if (owner.bluePortal.Count > 0)
                {
                    if (pos == owner.bluePortal[0] || pos == owner.bluePortal[1])
                    {
                        return(false);
                    }
                }
                if (owner.orangePortal.Count > 0)
                {
                    if (pos == owner.orangePortal[0] || pos == owner.orangePortal[1])
                    {
                        return(false);
                    }
                }
                //blue portal
                if (sending == Block.Water)
                {
                    if (CanPlacePortal(pos.X, pos.Y, pos.Z, world.Map))
                    {
                        if (owner.bluePortal.Count > 0)
                        {
                            int i = 0;
                            foreach (Vector3I b in owner.bluePortal)
                            {
                                world.Map.QueueUpdate(new BlockUpdate(null, b, owner.blueOld[i]));
                                i++;
                            }
                            owner.blueOld.Clear();
                            owner.bluePortal.Clear();
                        }

                        owner.blueOld.Add(world.Map.GetBlock(pos));
                        owner.blueOld.Add(world.Map.GetBlock(pos.X, pos.Y, pos.Z + 1));
                        owner.orangeOut = owner.Position.R;
                        for (double z = pos.Z; z < pos.Z + 2; z++)
                        {
                            world.Map.QueueUpdate(new BlockUpdate(null, (short)(pos.X), (short)(pos.Y), (short)z,
                                                                  Block.Water));
                            owner.bluePortal.Add(new Vector3I((int)pos.X, (int)pos.Y, (int)z));
                        }
                        return(false);
                    }
                    else
                    {
                        return(false);
                    }
                }

                //orange portal
                else if (sending == Block.Lava)
                {
                    if (CanPlacePortal(pos.X, pos.Y, pos.Z, world.Map))
                    {
                        if (owner.orangePortal.Count > 0)
                        {
                            int i = 0;
                            foreach (Vector3I b in owner.orangePortal)
                            {
                                world.Map.QueueUpdate(new BlockUpdate(null, b, owner.orangeOld[i]));
                                i++;
                            }
                            owner.orangeOld.Clear();
                            owner.orangePortal.Clear();
                        }
                        owner.orangeOld.Add(world.Map.GetBlock(pos));
                        owner.orangeOld.Add(world.Map.GetBlock(pos.X, pos.Y, pos.Z + 1));
                        owner.blueOut = owner.Position.R;
                        for (double z = pos.Z; z < pos.Z + 2; z++)
                        {
                            world.Map.QueueUpdate(new BlockUpdate(null, (short)(pos.X), (short)(pos.Y), (short)z,
                                                                  Block.Lava));
                            owner.orangePortal.Add(new Vector3I((int)pos.X, (int)pos.Y, (int)z));
                        }
                        return(false);
                    }
                    else
                    {
                        return(false);
                    }
                }
                updates.Add(new BlockUpdate(null, pos, world.Map.GetBlock(pos))); //restore
                restDistance = 0;
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        static void PlantRainForestTrees(ForesterArgs args, ICollection <Tree> treelist)
        {
            int treeHeight = args.Height;

            int existingTreeNum = treelist.Count;
            int remainingTrees  = args.TreeCount - existingTreeNum;

            const int shortTreeFraction = 6;
            int       attempts          = 0;

            for (int i = 0; i < remainingTrees && attempts < MaxTries; attempts++)
            {
                float randomfac =
                    (float)((Math.Sqrt(args.Rand.NextDouble()) * 1.618 - .618) * args.HeightVariation + .5);

                int height;
                if (i % shortTreeFraction == 0)
                {
                    height = (int)(treeHeight + randomfac);
                }
                else
                {
                    height = (int)(treeHeight - randomfac);
                }
                Vector3I xyz = FindRandomTreeLocation(args, height);
                if (xyz.Y < 0)
                {
                    continue;
                }

                xyz.Y++;

                bool displaced = false;
                // ReSharper disable LoopCanBeConvertedToQuery
                foreach (Tree otherTree in treelist)
                {
                    Vector3I otherLoc    = otherTree.Pos;
                    float    otherheight = otherTree.Height;
                    int      tallx       = otherLoc[0];
                    int      tallz       = otherLoc[2];
                    float    dist        = (float)Math.Sqrt(Sqr(tallx - xyz.X + .5) + Sqr(tallz - xyz.Z + .5));
                    float    threshold   = (otherheight + height) * .193f;
                    if (dist < threshold)
                    {
                        displaced = true;
                        break;
                    }
                }
                // ReSharper restore LoopCanBeConvertedToQuery
                if (displaced)
                {
                    continue;
                }
                treelist.Add(new RainforestTree {
                    Args   = args,
                    Pos    = xyz,
                    Height = height
                });
                i++;
            }
        }
Beispiel #3
0
            void MakeBranches()
            {
                int   topy   = Pos[1] + (int)(TrunkHeight + .5);
                float endrad = TrunkRadius * (1 - TrunkHeight / Height);

                if (endrad < 1)
                {
                    endrad = 1;
                }

                foreach (Vector3I coord in FoliageCoords)
                {
                    float dist  = (float)Math.Sqrt(Sqr(coord.X - Pos.X) + Sqr(coord.Z - Pos.Z));
                    float ydist = coord[1] - Pos[1];
                    float value = (BranchDensity * 220 * Height) / Cub(ydist + dist);

                    if (value < Args.Rand.NextDouble())
                    {
                        continue;
                    }

                    int   posy  = coord[1];
                    float slope = (float)(BranchSlope + (.5 - Args.Rand.NextDouble()) * .16);

                    float branchy, basesize;
                    if (coord[1] - dist * slope > topy)
                    {
                        float threshold = 1 / (float)Height;
                        if (Args.Rand.NextDouble() < threshold)
                        {
                            continue;
                        }
                        branchy  = topy;
                        basesize = endrad;
                    }
                    else
                    {
                        branchy  = posy - dist * slope;
                        basesize = endrad + (TrunkRadius - endrad) *
                                   (topy - branchy) / TrunkHeight;
                    }

                    float startsize = (float)(basesize * (1 + Args.Rand.NextDouble()) *
                                              .618 * Math.Pow(dist / Height, .618));
                    float    rndr       = (float)(Math.Sqrt(Args.Rand.NextDouble()) * basesize * .618);
                    float    rndang     = (float)(Args.Rand.NextDouble() * 2 * Math.PI);
                    int      rndx       = (int)(rndr * Math.Sin(rndang) + .5);
                    int      rndz       = (int)(rndr * Math.Cos(rndang) + .5);
                    Vector3I startcoord = new Vector3I {
                        X = Pos[0] + rndx,
                        Z = Pos[2] + rndz,
                        Y = (int)branchy
                    };
                    if (startsize < 1)
                    {
                        startsize = 1;
                    }
                    const float endsize = 1;
                    TaperedLimb(startcoord, coord, startsize, endsize);
                }
            }
Beispiel #4
0
 public int CompareTo(Vector3I other)
 {
     return(Math.Sign(LengthSquared - other.LengthSquared));
 }
Beispiel #5
0
 public Vector3F Cross(Vector3I b)
 {
     return(new Vector3F((Y * b.Z) - (Z * b.Y),
                         (Z * b.X) - (X * b.Z),
                         (X * b.Y) - (Y * b.X)));
 }
Beispiel #6
0
 /// <summary> Checks if a given point is inside this bounding box. </summary>
 public bool Contains(Vector3I point)
 {
     return(point.X >= XMin && point.X <= XMax &&
            point.Y >= YMin && point.Y <= YMax &&
            point.Z >= ZMin && point.Z <= ZMax);
 }
Beispiel #7
0
 public Firework(World world, Vector3I position)
     : base(world)
 {
     _pos = position;
     _z   = position.Z + 1;
 }
Beispiel #8
0
        public short GetCloudsHeight()
        {
            Vector3I dims = GetOrLoadDimensions();

            return((CloudsHeight == short.MinValue) ? (short)(dims.Z + 2) : CloudsHeight);
        }
Beispiel #9
0
 /// <summary> Converts given coordinates to a block array index. </summary>
 /// <param name="coords"> Coordinate vector (X,Y,Z). </param>
 /// <returns> Index of the block in Map.Blocks array. </returns>
 public int Index(Vector3I coords)
 {
     return((coords.Z * Length + coords.Y) * Width + coords.X);
 }
Beispiel #10
0
        internal static void RaisePlayerPlacedBlockEvent([NotNull] Player player, [NotNull] Map map, Vector3I coords,
                                                         Block oldBlock, Block newBlock, BlockChangeContext context)
        {
            var handler = PlacedBlock;

            if (handler != null)
            {
                handler(null, new PlayerPlacedBlockEventArgs(player, map, coords, oldBlock, newBlock, context));
            }
        }
Beispiel #11
0
        public short GetEdgeLevel()
        {
            Vector3I dims = GetOrLoadDimensions();

            return((EdgeLevel == -1) ? (short)(dims.Z / 2) : EdgeLevel);
        }
Beispiel #12
0
 public float DistanceTo(Vector3I other)
 {
     return((other - Origin).Length);
 }
Beispiel #13
0
        public override Map Generate()
        {
            if (Finished)
            {
                return(Result);
            }
            try {
                ReportProgress(0, "Clumping spheres...");
                rand = new Random(genParams.Seed);
                map  = new Map(null, genParams.MapWidth, genParams.MapLength, genParams.MapHeight, true);

                int    numIslands      = Math.Max(1, (int)(map.Volume * genParams.IslandDensity / (96 * 96 * 64)));
                Random islandCoordRand = new Random(rand.Next());

                List <Island> islands = new List <Island>();

                for (int i = 0; i < numIslands; i++)
                {
                    Vector3I offset = new Vector3I(islandCoordRand.Next(16, genParams.MapWidth - 16),
                                                   islandCoordRand.Next(16, genParams.MapLength - 16),
                                                   islandCoordRand.Next(16, genParams.MapHeight - 16));
                    islands.Add(CreateIsland(offset));
                }
                if (Canceled)
                {
                    return(null);
                }

                ReportProgress(10, "Smoothing (0%)...");
                SmoothEdges();
                if (Canceled)
                {
                    return(null);
                }

                ReportProgress(15, "Smoothing (50%)...");
                SmoothEdges();
                if (Canceled)
                {
                    return(null);
                }

                ReportProgress(20, "Expanding...");
                ExpandGround();
                if (Canceled)
                {
                    return(null);
                }

                ReportProgress(70, "Adding stone...");
                for (int i = 0; i < numIslands; i++)
                {
                    MakeIslandBase(islands[i]);
                }

                ReportProgress(75, "Planting grass...");
                PlantGrass();
                if (Canceled)
                {
                    return(null);
                }

                ReportProgress(80, "Watering...");
                for (int x = 0; x < map.Width; x++)
                {
                    for (int y = 0; y < map.Length; y++)
                    {
                        map.SetBlock(x, y, 0, Block.Admincrete);
                        map.SetBlock(x, y, 1, Block.Water);
                    }
                }
                MakeWater();
                if (Canceled)
                {
                    return(null);
                }

                ReportProgress(85, "Planting trees...");
                PlantGiantTrees();
                PlantTrees();
                if (Canceled)
                {
                    return(null);
                }

                ReportProgress(88, "Planting flowers...");
                PlantFlowers();
                if (Canceled)
                {
                    return(null);
                }

                ReportProgress(90, "Eroding (0%)...");
                Erode();
                if (Canceled)
                {
                    return(null);
                }
                ReportProgress(95, "Eroding (50%)...");
                Erode();
                if (Canceled)
                {
                    return(null);
                }

                Result = map;
                return(Result);
            } finally {
                Finished     = true;
                Progress     = 100;
                StatusString = (Canceled ? "Canceled" : "Finished");
            }
        }
Beispiel #14
0
 public void HitPlayer(World world, Vector3I pos, Player hitted, Player by, ref int restDistance,
                       IList <BlockUpdate> updates)
 {
 }
Beispiel #15
0
        public static void movePortal(object sender, PlayerMovingEventArgs e)
        {
            try
            {
                if (e.Player.LastUsedPortal != null && (DateTime.UtcNow - e.Player.LastUsedPortal).TotalSeconds < 4)
                {
                    return;
                }
                Vector3I newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, (e.NewPosition.Z / 32));
                foreach (Player p in e.Player.World.Players)
                {
                    foreach (Vector3I block in p.bluePortal)
                    {
                        if (newPos == block)
                        {
                            if (p.World.Map.GetBlock(block) == Block.Water)
                            {
                                if (p.orangePortal.Count > 0)
                                {
                                    e.Player.TeleportTo(new Position
                                    {
                                        X = (short)(((p.orangePortal[0].X) + 0.5) * 32),
                                        Y = (short)(((p.orangePortal[0].Y) + 0.5) * 32),
                                        Z = (short)(((p.orangePortal[0].Z) + 1.59375) * 32),
                                        R = (byte)(p.blueOut - 128),
                                        L = e.Player.Position.L
                                    });
                                }
                                e.Player.LastUsedPortal = DateTime.UtcNow;
                            }
                        }
                    }

                    foreach (Vector3I block in p.orangePortal)
                    {
                        if (newPos == block)
                        {
                            if (p.World.Map.GetBlock(block) == Block.Lava)
                            {
                                if (p.bluePortal.Count > 0)
                                {
                                    e.Player.TeleportTo(new Position
                                    {
                                        X = (short)(((p.bluePortal[0].X + 0.5)) * 32),
                                        Y = (short)(((p.bluePortal[0].Y + 0.5)) * 32),
                                        Z = (short)(((p.bluePortal[0].Z) + 1.59375) * 32), //fixed point 1.59375 lol.
                                        R = (byte)(p.orangeOut - 128),
                                        L = e.Player.Position.L
                                    });
                                }
                                e.Player.LastUsedPortal = DateTime.UtcNow;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.SeriousError, "MovePortal: " + ex);
            }
        }
Beispiel #16
0
 /// <summary> Checks whether the given coordinate (in block units) is within the bounds of the map. </summary>
 /// <param name="vec"> Coordinate vector (X,Y,Z). </param>
 public bool InBounds(Vector3I vec)
 {
     return(vec.X < Width && vec.Y < Length && vec.Z < Height && vec.X >= 0 && vec.Y >= 0 && vec.Z >= 0);
 }
Beispiel #17
0
        // ReSharper restore FieldCanBeMadeReadOnly.Global

        /// <summary> Constructs a bounding box using two vectors as opposite corners. </summary>
        public BoundingBox(Vector3I p1, Vector3I p2) :
            this(p1.X, p1.Y, p1.Z, p2.X, p2.Y, p2.Z)
        {
        }
Beispiel #18
0
        public static void coords(Player player)
        {
            Vector3I Blockcoords = player.Position.ToBlockCoords();

            player.Message("Your current coordinates are " + Blockcoords + ".");
        }
Beispiel #19
0
        //processess one blockupdate
        public void sendWorldBlock(int index, byte type)
        {
            if (world.Map == null)
            {
                started = false;
                return;
            }
            if (world.IsLoaded)
            {
                int x = 0, y = 0, z = 0;
                switch (direction)
                {
                case Direction.one:
                    x = ( int )(index / 8) + EndPos.X;
                    y = StartPos.Y;
                    z = StartPos.Z + (index % 8);
                    if (world.map.InBounds(x, y, z))
                    {
                        if (x >= StartPos.X && x <= FinishPos.X)
                        {
                            if (( Block )type != Block.Air)
                            {
                                Vector3I Pos = new Vector3I(x, y, z);
                                world.map.QueueUpdate(new BlockUpdate(null, Pos, ( Block )type));
                                Blocks.TryAdd(Pos.ToString(), Pos);
                            }
                        }
                    }
                    break;

                case Direction.two:
                    x = ( short )(EndPos.X - (index / 8));
                    y = ( short )StartPos.Y;
                    z = ( short )(StartPos.Z + (index % 8));
                    if (world.map.InBounds(x, y, z))
                    {
                        if (x <= StartPos.X && x >= FinishPos.X)
                        {
                            if (( Block )type != Block.Air)
                            {
                                Vector3I Pos = new Vector3I(x, y, z);
                                world.map.QueueUpdate(new BlockUpdate(null, Pos, ( Block )type));
                                Blocks.TryAdd(Pos.ToString(), Pos);
                            }
                        }
                    }
                    break;

                case Direction.three:
                    x = ( short )StartPos.X;
                    y = ( short )(EndPos.Y + (index / 8));
                    z = ( short )(StartPos.Z + (index % 8));
                    if (world.map.InBounds(x, y, z))
                    {
                        if (y >= StartPos.Y && y <= FinishPos.Y)
                        {
                            if (( Block )type != Block.Air)
                            {
                                Vector3I Pos = new Vector3I(x, y, z);
                                world.map.QueueUpdate(new BlockUpdate(null, Pos, ( Block )type));
                                Blocks.TryAdd(Pos.ToString(), Pos);
                            }
                        }
                    }
                    break;

                case Direction.four:
                    x = ( short )StartPos.X;
                    y = ( short )(EndPos.Y - (index / 8));
                    z = ( short )(StartPos.Z + (index % 8));
                    if (world.map.InBounds(x, y, z))
                    {
                        if (y <= StartPos.Y && y >= FinishPos.Y)
                        {
                            if (( Block )type != Block.Air)
                            {
                                Vector3I Pos = new Vector3I(x, y, z);
                                world.map.QueueUpdate(new BlockUpdate(null, Pos, ( Block )type));
                                Blocks.TryAdd(Pos.ToString(), Pos);
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #20
0
 public Football(Player player, World world, Vector3I FootballPos)
 {
     _world          = world;
     Player.Clicked += ClickedFootball;
 }
Beispiel #21
0
        /// <summary>
        /// Attempts to move bot between two lines, will use a straight line if possible
        /// </summary>
        private void Move()
        {
            if (!isMoving)
            {
                return;
            }

            //Create vector list of positions
            if (!beganMoving)
            {
                beganMoving = true;

                //create an IEnumerable list of all blocks that will be in the path between blocks
                IEnumerable <Vector3I> positions = fCraft.Drawing.LineDrawOperation.LineEnumerator(Position.ToBlockCoords(), NewPosition.ToBlockCoords());

                //edit IEnumarable into List
                foreach (Vector3I v in positions)
                {
                    PositionList.Add(v);
                }

                bool clear = true;

                //Make sure that each block in the line is a fluid
                foreach (Vector3I vect in PositionList)
                {
                    Vector3I underVect = new Vector3I(vect.X, vect.Y, vect.Z - 1);

                    if (!ValidBlock(vect) || !ValidBlock(underVect))
                    {
                        clear = false;
                    }
                }

                //if list contains blocks that aren't air blocks, bot cannot make a direct line to target, need a path
                if (!clear)
                {
                    PositionList.Clear();
                    Path(NewPosition.ToBlockCoords());
                }
            }

            //once the posList is empty, we have reached the final point
            if (PositionList.Count() == 0 || Position == NewPosition)
            {
                isMoving    = false;
                beganMoving = false;
                return;
            }

            //determine distance from the target player to the target bot
            double groundDistance = Math.Sqrt(Math.Pow((NewPosition.X - OldPosition.X), 2) + Math.Pow((NewPosition.Y - OldPosition.Y), 2));

            int xDisplacement = NewPosition.X - Position.X;
            int yDisplacement = NewPosition.Y - Position.Y;
            int zDisplacement = NewPosition.Z - Position.Z;

            //use arctan to find appropriate angles (doesn't work yet)
            double rAngle = Math.Atan((double)zDisplacement / groundDistance); //pitch
            double lAngle = Math.Atan((double)xDisplacement / yDisplacement);  //yaw

            //create a new position with the next pos list in the posList, then remove that pos
            Position targetPosition = new Position
            {
                X = (short)(PositionList.First().X * 32 + 16),
                Y = (short)(PositionList.First().Y * 32 + 16),
                Z = (short)(PositionList.First().Z * 32 + 16),
                R = (byte)(rAngle),
                L = (byte)(lAngle)
            };

            //Remove the position the bot just went to in the list, teleport to that created position, change position to created position
            PositionList.Remove(PositionList.First());
            Position = targetPosition;
            teleportBot(targetPosition);
        }
Beispiel #22
0
        internal static Packet MakeSelectionCuboid(byte ID, string label, Vector3I start, Vector3I end, System.Drawing.Color color, int percentOpacity)
        {
            double opacity = Math.Round(255 * ((double)percentOpacity * 0.01), 1);            //apply percent opaque to total opaque, create a whole number

            Packet packet = new Packet(OpCode.SelectionCuboid);

            packet.Data[1] = ID;
            Encoding.ASCII.GetBytes(label.PadRight(64), 0, 64, packet.Data, 2);
            ToNetOrder(start.X, packet.Data, 66);
            ToNetOrder(start.Z, packet.Data, 68);
            ToNetOrder(start.Y, packet.Data, 70);
            ToNetOrder(end.X, packet.Data, 72);
            ToNetOrder(end.Z, packet.Data, 74);
            ToNetOrder(end.Y, packet.Data, 76);
            ToNetOrder(color.R, packet.Data, 78);
            ToNetOrder(color.G, packet.Data, 80);
            ToNetOrder(color.B, packet.Data, 82);
            ToNetOrder((int)opacity, packet.Data, 84);
            return(packet);
        }
Beispiel #23
0
 public float Dot(Vector3I b)
 {
     return((X * b.X) + (Y * b.Y) + (Z * b.Z));
 }
Beispiel #24
0
        public static void PlayerMoving(object poo, fCraft.Events.PlayerMovingEventArgs e)
        {
            if (!started)
            {
                return;
            }
            //If the player has the red flag (player is no the blue team)
            if (e.Player.Info.hasRedFlag)
            {
                Vector3I oldPos = e.OldPosition.ToBlockCoords(); //get positions as block coords
                Vector3I newPos = e.NewPosition.ToBlockCoords();

                if (oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z) //check if player has moved at least one block
                {
                    //If the player is near enough to the blue spawn
                    if (e.NewPosition.DistanceSquaredTo(world_.blueCTFSpawn.ToPlayerCoords()) <= 42 * 42)
                    {
                        blueScore++;
                        world_.Players.Message("&f{0} has capped the &cred &fflag. The score is now &cRed&f: {1} and &1Blue&f: {2}.", e.Player.Name, redScore, blueScore);
                        e.Player.Info.hasRedFlag = false;
                        redFlagHolder            = null;
                        e.Player.Info.CTFCaptures++;

                        //Replace red block as flag
                        BlockUpdate blockUpdate = new BlockUpdate(null, world_.redFlag, Block.Red);
                        foreach (Player p in world_.Players)
                        {
                            p.World.Map.QueueUpdate(blockUpdate);

                            //set game score
                            if (p.SupportsMessageTypes)
                            {
                                p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: " + redScore + ",&1 Blue&f: " + blueScore));
                                p.Send(PacketWriter.MakeSpecialMessage((byte)100, e.Player.Name + " has successfully capped the &cred &fflag"));
                            }
                        }
                        world_.redFlagTaken = false;
                        announced           = DateTime.UtcNow;
                        return;
                    }
                }
            }
            //If the player has the blue flag (player must be on red team)
            else if (e.Player.Info.hasBlueFlag)
            {
                Vector3I oldPos = e.OldPosition.ToBlockCoords(); //get positions as block coords
                Vector3I newPos = e.NewPosition.ToBlockCoords();

                if (oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z) //check if player has moved at least one block
                {
                    //If the player is near enough to the red spawn
                    if (e.NewPosition.DistanceSquaredTo(world_.redCTFSpawn.ToPlayerCoords()) <= 42 * 42)
                    {
                        redScore++;
                        world_.Players.Message("&f{0} has capped the &1blue &fflag. The score is now &cRed&f: {1} and &1Blue&f: {2}.", e.Player.Name, redScore, blueScore);
                        e.Player.Info.hasBlueFlag = false;
                        blueFlagHolder            = null;
                        e.Player.Info.CTFCaptures++;

                        //Replace blue block as flag
                        BlockUpdate blockUpdate = new BlockUpdate(null, world_.blueFlag, Block.Blue);
                        foreach (Player p in world_.Players)
                        {
                            p.World.Map.QueueUpdate(blockUpdate);

                            //set game scorecboard
                            if (p.SupportsMessageTypes)
                            {
                                p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: " + redScore + ",&1 Blue&f: " + blueScore));
                                p.Send(PacketWriter.MakeSpecialMessage((byte)100, e.Player.Name + " has successfully capped the &cred &fflag"));
                            }
                        }
                        world_.blueFlagTaken = false;
                        announced            = DateTime.UtcNow;
                        return;
                    }
                }
            }

            //backstabbing, player with a flag cannot backstab an enemy player
            else
            {
                if (e.Player.Info.stabDisarmed)
                {
                    return;
                }

                Vector3I oldPos = e.OldPosition.ToBlockCoords(); //get positions as block coords
                Vector3I newPos = e.NewPosition.ToBlockCoords();

                if (oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z) //check if player has moved at least one block
                {
                    //loop through each player, detect if current player is "touching" another player
                    foreach (Player p in world_.Players)
                    {
                        Vector3I pos = p.Position.ToBlockCoords(); //convert to block coords

                        //determine if player is "touching" another player
                        if (e.NewPosition.DistanceSquaredTo(pos.ToPlayerCoords()) <= 42 * 42 && p != e.Player)
                        {
                            if ((p.Info.CTFBlueTeam && e.Player.Info.CTFBlueTeam) || (p.Info.CTFRedTeam && e.Player.Info.CTFRedTeam))
                            {
                                //friendly fire, do not stab
                                return;
                            }

                            //create just under a 180 degree semicircle in the direction the target player is facing (90 degrees = 64 pos.R bytes)
                            short lowerLimit = (short)(p.Position.R - 63);
                            short upperLimit = (short)(p.Position.R + 63);

                            //if lower limit is -45 degrees for example, convert to 256 + (-32) = 201 bytes (-45 degrees translates to -32 bytes)
                            if (lowerLimit < 0)
                            {
                                lowerLimit = (short)(256 + lowerLimit);
                            }

                            //if upper limit is 450 degrees for example, convert to 320 - 256 = 54 bytes (450 degrees translates to 320 bytes, 360 degrees translates to 256 bytes)
                            if (upperLimit > 256)
                            {
                                upperLimit = (short)(upperLimit - 256);
                            }

                            //Logger.LogToConsole(upperLimit.ToString() + " " + lowerLimit.ToString() + " " + e.Player.Position.R.ToString() + " " + p.Position.R);

                            bool kill = false;

                            //if target's line of sight contains 0
                            if (p.Position.R > 192 && p.Position.R < 64)
                            {
                                if (Enumerable.Range(lowerLimit, 255).Contains(e.Player.Position.R) || Enumerable.Range(0, upperLimit).Contains(e.Player.Position.R))
                                {
                                    kill = true;
                                }
                            }
                            else
                            {
                                if (Enumerable.Range(lowerLimit, upperLimit).Contains(e.Player.Position.R))
                                {
                                    kill = true;
                                }
                            }

                            if (e.Player.Info.stabAnywhere)
                            {
                                kill = true;
                            }

                            if (kill)
                            {
                                p.KillCTF(world_, String.Format("&f{0}&S was backstabbed by &f{1}", p.Name, e.Player.Name));
                                e.Player.Info.CTFKills++;
                                PowerUp(e.Player);

                                if (p.Info.hasRedFlag)
                                {
                                    world_.Players.Message("The red flag has been returned.");
                                    p.Info.hasRedFlag = false;
                                    redFlagHolder     = null;

                                    //Put flag back
                                    BlockUpdate blockUpdate = new BlockUpdate(null, world_.redFlag, Block.Red);
                                    foreach (Player pl in world_.Players)
                                    {
                                        pl.World.Map.QueueUpdate(blockUpdate);
                                    }
                                    world_.redFlagTaken = false;
                                }

                                if (p.Info.hasBlueFlag)
                                {
                                    world_.Players.Message("The blue flag has been returned.");
                                    p.Info.hasBlueFlag = false;
                                    blueFlagHolder     = null;

                                    //Put flag back
                                    BlockUpdate blockUpdate = new BlockUpdate(null, world_.blueFlag, Block.Blue);
                                    foreach (Player pl in world_.Players)
                                    {
                                        pl.World.Map.QueueUpdate(blockUpdate);
                                    }
                                    world_.blueFlagTaken = false;
                                }
                            }
                            //target player can see player, do not stab
                        }
                    }
                }
            }
        }
Beispiel #25
0
 public Vector3F(Vector3I other)
 {
     X = other.X;
     Y = other.Y;
     Z = other.Z;
 }
Beispiel #26
0
 private void CheckCoords(ref Vector3I pos)
 {
     CheckDim(ref pos.X, 0);
     CheckDim(ref pos.Y, 1);
 }
Beispiel #27
0
 public void Copy(Tree other)
 {
     Args   = other.Args;
     Pos    = other.Pos;
     Height = other.Height;
 }
Beispiel #28
0
        public static void gunMove(Player player)
        {
            World world = player.World;

            if (null == world)
            {
                return;
            }
            try
            {
                lock (world.SyncRoot)
                {
                    if (null == world.Map)
                    {
                        return;
                    }
                    if (player.IsOnline)
                    {
                        Position p    = player.Position;
                        double   ksi  = 2.0 * Math.PI * (-player.Position.L) / 256.0;
                        double   phi  = 2.0 * Math.PI * (player.Position.R - 64) / 256.0;
                        double   sphi = Math.Sin(phi);
                        double   cphi = Math.Cos(phi);
                        double   sksi = Math.Sin(ksi);
                        double   cksi = Math.Cos(ksi);

                        if (player.IsOnline)
                        {
                            if (player.GunCache.Values.Count > 0)
                            {
                                foreach (Vector3I block in player.GunCache.Values)
                                {
                                    if (player.IsOnline)
                                    {
                                        player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, world.Map.GetBlock(block)));
                                        Vector3I removed;
                                        player.GunCache.TryRemove(block.ToString(), out removed);
                                    }
                                }
                            }
                        }

                        for (int y = -1; y < 2; ++y)
                        {
                            for (int z = -1; z < 2; ++z)
                            {
                                if (player.IsOnline)
                                {
                                    //4 is the distance betwen the player and the glass wall
                                    Vector3I glassBlockPos = new Vector3I((int)(cphi * cksi * 4 - sphi * (0.5 + y) - cphi * sksi * (0.5 + z)),
                                                                          (int)(sphi * cksi * 4 + cphi * (0.5 + y) - sphi * sksi * (0.5 + z)),
                                                                          (int)(sksi * 4 + cksi * (0.5 + z)));
                                    glassBlockPos += p.ToBlockCoords();
                                    if (world.Map.GetBlock(glassBlockPos) == Block.Air)
                                    {
                                        player.Send(PacketWriter.MakeSetBlock(glassBlockPos, Block.Glass));
                                        player.GunCache.TryAdd(glassBlockPos.ToString(), glassBlockPos);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.SeriousError, "GunGlass: " + ex);
            }
        }
Beispiel #29
0
            void MakeRoots(IList <RootBase> rootbases)
            {
                if (rootbases.Count == 0)
                {
                    return;
                }
                foreach (Vector3I coord in FoliageCoords)
                {
                    float dist  = (float)Math.Sqrt(Sqr(coord[0] - Pos[0]) + Sqr(coord[2] - Pos[2]));
                    float ydist = coord[1] - Pos[1];
                    float value = (BranchDensity * 220 * Height) / Cub(ydist + dist);
                    if (value < Args.Rand.NextDouble())
                    {
                        continue;
                    }

                    RootBase rootbase       = rootbases[Args.Rand.Next(0, rootbases.Count)];
                    int      rootx          = rootbase.X;
                    int      rootz          = rootbase.Z;
                    float    rootbaseradius = rootbase.Radius;

                    float    rndr       = (float)(Math.Sqrt(Args.Rand.NextDouble()) * rootbaseradius * .618);
                    float    rndang     = (float)(Args.Rand.NextDouble() * 2 * Math.PI);
                    int      rndx       = (int)(rndr * Math.Sin(rndang) + .5);
                    int      rndz       = (int)(rndr * Math.Cos(rndang) + .5);
                    int      rndy       = (int)(Args.Rand.NextDouble() * rootbaseradius * .5);
                    Vector3I startcoord = new Vector3I {
                        X = rootx + rndx,
                        Z = rootz + rndz,
                        Y = Pos[1] + rndy
                    };
                    Vector3F offset = new Vector3F(startcoord - coord);

                    if (Args.Shape == TreeShape.Mangrove)
                    {
                        // offset = [int(val * 1.618 - 1.5) for val in offset]
                        offset = offset * 1.618f - HalfBlock * 3;
                    }

                    Vector3I endcoord      = startcoord + offset.RoundDown();
                    float    rootstartsize = (float)(rootbaseradius * .618 * Math.Abs(offset[1]) / (Height * .618));

                    if (rootstartsize < 1)
                    {
                        rootstartsize = 1;
                    }
                    const float endsize = 1;

                    if (Args.Roots == RootMode.ToStone ||
                        Args.Roots == RootMode.Hanging)
                    {
                        float offlength = offset.Length;
                        if (offlength < 1)
                        {
                            continue;
                        }
                        float    rootmid = endsize;
                        Vector3F vec     = offset / offlength;

                        Block searchIndex = Block.Air;
                        if (Args.Roots == RootMode.ToStone)
                        {
                            searchIndex = Block.Stone;
                        }
                        else if (Args.Roots == RootMode.Hanging)
                        {
                            searchIndex = Block.Air;
                        }

                        int      startdist   = (int)(Args.Rand.NextDouble() * 6 * Math.Sqrt(rootstartsize) + 2.8);
                        Vector3I searchstart = new Vector3I(startcoord + vec * startdist);

                        dist = startdist + DistanceToBlock(Args.Map, new Vector3F(searchstart), vec, searchIndex);

                        if (dist < offlength)
                        {
                            rootmid += (rootstartsize - endsize) * (1 - dist / offlength);
                            endcoord = new Vector3I(startcoord + vec * dist);
                            if (Args.Roots == RootMode.Hanging)
                            {
                                float    remainingDist = offlength - dist;
                                Vector3I bottomcord    = endcoord;
                                bottomcord[1] -= (int)remainingDist;
                                TaperedLimb(endcoord, bottomcord, rootmid, endsize);
                            }
                        }
                        TaperedLimb(startcoord, endcoord, rootstartsize, rootmid);
                    }
                    else
                    {
                        TaperedLimb(startcoord, endcoord, rootstartsize, endsize);
                    }
                }
            }
Beispiel #30
0
        protected override int PerformInternal()
        {
            //lock is done already
            if (Block.Undefined == _prevBlock) //created out of bounds, dont continue
            {
                return(0);
            }
            //fix for portal gun
            if (_owner.orangePortal.Count > 0)
            {
                if (_pos == _owner.orangePortal[0] || _pos == _owner.orangePortal[1])
                {
                    return(0);
                }
            }
            if (_owner.bluePortal.Count > 0)
            {
                if (_pos == _owner.bluePortal[0] || _pos == _owner.bluePortal[1])
                {
                    return(0);
                }
            }

            //delete at the previous position, restore water unconditionally, lava only when bullet is still there to prevent restoration of explosion lava
            if (_prevBlock != Block.Water)
            {
                _prevBlock = Block.Air;
            }
            //edit: lazyfix, dont restore lava coz tnt.

            if (Block.Undefined != _prevBlock)
            {
                if (_owner.CanPlace(_map, _pos, Block.Plank, BlockChangeContext.Manual) == CanPlaceResult.Allowed)
                {
                    UpdateMap(new BlockUpdate(null, _pos, _prevBlock));
                }
            }

            List <BlockUpdate> updates = new List <BlockUpdate>();

            for (int i = 0; i < _behavior.MovesPerProcessingStep && _restDistance > 0; ++i)
            {
                _pos       = Move();
                _prevBlock = _map.GetBlock(_pos);

                if (Block.Undefined == _prevBlock)
                {
                    _restDistance = 0;
                    break;
                }

                _behavior.ModifyDirection(ref _direction, _prevBlock);
                //e.g. if you want it to be dependent on gravity or change direction depending on current block etc

                if (_behavior.VisitBlock(_world, _pos, _prevBlock, _owner, ref _restDistance, updates, _block) &&
                    _behavior.CanKillPlayer)
                {
                    CheckHitPlayers(updates);
                }
            }

            bool cont = _restDistance > 0;

            if (cont) //check if the last update was for the current position and replace it with the particle
            {
                int idx = updates.Count - 1;
                if (idx >= 0 && updates[idx].X == _pos.X &&
                    updates[idx].Y == _pos.Y &&
                    updates[idx].Z == _pos.Z)
                {
                    if (_owner.CanPlace(_map, _pos, Block.Plank, BlockChangeContext.Manual) == CanPlaceResult.Allowed)
                    {
                        updates[idx] = new BlockUpdate(null, _pos, _block);
                    }
                }
                else
                {
                    if (_owner.CanPlace(_map, _pos, Block.Plank, BlockChangeContext.Manual) == CanPlaceResult.Allowed)
                    {
                        updates.Add(new BlockUpdate(null, _pos, _block));
                    }
                }
            }

            for (int i = 0; i < updates.Count; ++i)
            {
                UpdateMap(updates[i]);
            }

            return(cont ? _stepDelay : 0);
        }