Ejemplo n.º 1
0
 public IBlock getWaitingBlock(BlockPos blockPos)
 {
     lock (waitingBlocks)
     {
         if (waitingBlocks.ContainsKey(blockPos))
             return waitingBlocks[blockPos];
         else
             return null;
     }
 }
Ejemplo n.º 2
0
 public void OnBlockPlace(int x, int y, int layer, int blockId)
 {
     lock (this)
     {
         BlockPos pos = new BlockPos(layer, x, y);
         if (this.furnitures.ContainsKey(pos))
         {
             Furniture furniture = furnitures[pos];
             if (blockId != furniture.getBlock().Id)
                 furnitures.Remove(pos);
         }
     }
 }
Ejemplo n.º 3
0
        public void AddWaitingBlock(BlockWithPos blockWithPos)
        {
            lock (waitingBlocks)
            {
                BlockPos blockPos = new BlockPos(blockWithPos.Block.Layer, blockWithPos.X, blockWithPos.Y);
                if (waitingBlocks.ContainsKey(blockPos))
                {
                    if (blockWithPos.Block.Equals(waitingBlocks[blockPos]))
                        return;

                    waitingBlocks.Remove(blockPos);
                }
                waitingBlocks.Add(blockPos, blockWithPos.Block);
            }
        }
Ejemplo n.º 4
0
        public void PlaceBlock(BlockWithPos blockWithPos)
        {
            BlockPos blockPos = new BlockPos(blockWithPos.Block.Layer, blockWithPos.X, blockWithPos.Y);

            if (!blockWithPos.Block.Equals(blockDrawerPool.getWaitingBlock(blockPos)) && bot.Room.BlockMap.getBlock(blockWithPos.Block.Layer, blockPos.X, blockPos.Y).Id != blockWithPos.Block.Id)
            {
                if (bot.Room.BlockMap.isPlaceAble(blockWithPos))
                {
                    blockDrawerPool.AddWaitingBlock(blockWithPos);

                    lock (blocksToDraw)
                    {
                        blocksToDraw.Enqueue(blockWithPos);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public void OnBlockPlace(BlockWithPos blockWithPos)
 {
     lock (waitingBlocks)
     {
         BlockPos blockPos = new BlockPos(blockWithPos.Block.Layer, blockWithPos.X, blockWithPos.Y);
         if (waitingBlocks.ContainsKey(blockPos))
         {
             if (blockWithPos.Block.Equals(waitingBlocks[blockPos]))
                 waitingBlocks.Remove(blockPos);
         }
     }
 }
Ejemplo n.º 6
0
        public void OnPlayerPush(IPlayer player, int x, int y, int dx, int dy)
        {
            lock (this)
            {
                BlockPos pos = new BlockPos(0, x + dx, y + dy);
                House house = FindHouse(pos.X, pos.Y);

                if (house != null && house.Furniture.ContainsKey(pos))
                {
                    Furniture furniture = house.Furniture[pos];

                    furniture.OnPush(bot, player, house, dx, dy);
                }
            }
        }
Ejemplo n.º 7
0
        public void OnPlayerMine(IPlayer player, int x1, int y1, int x2, int y2)
        {
            if (buildingHouses.ContainsKey(player))
            {
                House house = buildingHouses[player];
                if (x2 >= house.x && y2 >= house.y && x2 < house.x + house.width && y2 < house.y + house.height)
                {
                    CurrentMiningBlock currentMiningBLock = new CurrentMiningBlock(x2, y2);

                    if (miningBlocks.ContainsKey(player))
                    {
                        currentMiningBLock = miningBlocks[player];

                        if (currentMiningBLock.x != x2 || currentMiningBLock.y != y2)
                            currentMiningBLock = new CurrentMiningBlock(x2, y2);
                    }
                    else
                    {
                        miningBlocks.Add(player, currentMiningBLock);
                    }

                    currentMiningBLock.health--;
                    miningBlocks[player] = currentMiningBLock;

                    if (currentMiningBLock.health == 0)
                    {
                        BlockPos pos = new BlockPos(0, x2, y2);
                        if (!house.Furniture.ContainsKey(pos))
                            house.Furniture.Add(pos, new FurnitureEmpty(x2, y2));
                        else
                            house.Furniture[pos] = new FurnitureEmpty(x2, y2);
                        Save();
                        miningBlocks.Remove(player);
                        bot.Room.BlockDrawer.PlaceBlock(
                            new Room.Block.BlockWithPos(x2, y2,
                                new Room.Block.NormalBlock(414)));
                    }

                }
            }
            //else
            //    furnitureManager.OnPlayerPush(x1, y1, x2, y2);
        }
Ejemplo n.º 8
0
        public void OnBlockPlace(IPlayer player, int x, int y, int layer, int blockId)
        {
            lock (this)
            {
                BlockPos pos = new BlockPos(layer, x, y);
                House house = FindHouse(pos.X, pos.Y);

                if (house != null && house.Furniture.ContainsKey(pos))
                {
                    Furniture furniture = house.Furniture[pos];
                    if (blockId != furniture.getBlock(bot, player, house).Id)
                    {
                        house.Furniture.Remove(pos);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public void Tick()
        {
            long elapsed = playerTickStopwatch.ElapsedMilliseconds;
            if (elapsed >= msPerTick)
            {
                playerTickStopwatch.Restart();
                ticksToNextSearch--;
                if (ticksToNextSearch <= 0)
                {
                    //Find a target
                    IPlayer target = GetNearestPlayer(searchRange);
                    if (target != null)
                    {
                        this.target = target;
                    }
                    ticksToNextSearch = 5;
                }

                //Generate path
                ticksBetweenNewPath--;
                if (ticksBetweenNewPath <= 0 || currentPath == null || currentPath.Count <= 0)
                {
                    if (target != null && !(x == target.BlockX && y == target.BlockY))
                    {
                        pathFinding = new PathFinding();
                        int xx = target.BlockX;
                        int yy = target.BlockY;
                        DateTime first = DateTime.Now;
                        currentPath = pathFinding.FindPath(x, y, xx, yy, new List<Zombie>(ZombiesSubbot.zombies), bot);
                        DateTime second = DateTime.Now;
                        Console.WriteLine("Pahtfinding took " + (second - first).TotalMilliseconds);
                        ticksBetweenNewPath = 1;
                    }
                    else
                        ticksBetweenNewPath = 2;
                }

                //Walk with path
                if (currentPath != null && currentPath.Count > 0)
                {
                    Node next = currentPath.Pop();
                    x = next.x;
                    y = next.y;
                    BlockPos pos = new BlockPos(0, x, y);

                    while (tailDic.ContainsKey(pos) && currentPath.Count > 0)
                    {
                        next = currentPath.Pop();
                        x = next.x;
                        y = next.y;
                        pos = new BlockPos(0, x, y);
                    }

                    if (tailDic.ContainsKey(pos))
                        return;

                    pos = new BlockPos(0, x, y); // tail-free block we are moving to
                    IBlock toReplace = bot.Room.getBlock(0, pos.X, pos.Y);
                    tailDic.Add(pos, toReplace);
                    tail.Enqueue(new BlockWithPos(pos.X, pos.Y, toReplace));

                    bot.Room.setBlock(pos.X, pos.Y, new NormalBlock(196, 0));

                    //As we move, remove the last block of the tail
                    if (tail.Count > 10)
                    {
                        BlockWithPos toRemove = tail.Dequeue();
                        BlockPos toRemovePos = new BlockPos(0, toRemove.X, toRemove.Y);

                        if (toRemove.Block != null)
                        {
                            bot.Room.setBlock(toRemove.X, toRemove.Y, toRemove.Block);
                        }

                        if (tailDic.ContainsKey(toRemovePos))
                            tailDic.Remove(toRemovePos);
                    }

                    //Console.WriteLine("Moving to x:" + x + " y:" + y);

                    //bot.Room.setBlock(oldx, oldy, new NormalBlock(0, 0));
                    //bot.Room.setBlock(x, y, new NormalBlock(32, 0));
                    //bot.Room.setBlock(oldx, oldy, new NormalBlock(0));

                    /*if ()
                    {
                        //we aren't moving on the tail
                    }

                    if (!(x == oldx && y == oldy))
                    {
                        if (target != null && !target.IsGod && target.BlockX == x && target.BlockY == y)
                        {
                            KillPlayer(target);
                            target = null;
                        }

                        //bot.Connection.Send(bot.Room.WorldKey, 0, x, y, 32);
                        //bot.Connection.Send(bot.Room.WorldKey, 0, oldx, oldy, 0);
                        bot.Room.setBlock(x, y, new NormalBlock(32, 0));
                        bot.Room.setBlock(oldx, oldy, new NormalBlock(4));
                    }*/
                }
            }
            else if (elapsed > 2)
                Thread.Sleep((int)(msPerTick - elapsed) - 1);
        }
Ejemplo n.º 10
0
        public void OnPlayerPush(IPlayer player, int x, int y, int dx, int dy)
        {
            lock (this)
            {
                BlockPos pos = new BlockPos(0, x + dx, y + dy);

                if (furnitures.ContainsKey(pos))
                {
                    Furniture furniture = furnitures[pos];

                    furniture.OnPush(bot, player, dx, dy);
                }
            }
        }
Ejemplo n.º 11
0
        public override void onCommand(string cmd, string[] args, ICmdSource cmdSource)
        {
            switch (cmd)
            {
                case "loadhouses":
                    if (cmdSource is IPlayer)
                    {
                        IPlayer player = cmdSource as IPlayer;
                        if (player.IsOp)
                            houseManager.Load();
                    }
                    break;
                case "helphouse":
                case "househelp":
                    if (cmdSource is IPlayer)
                    {
                        IPlayer player = cmdSource as IPlayer;
                        player.Send("House commands: !houseinfo, !build, !finishhouse, !edithouse, !destroyhouse, !place, !trust, !untrust, !whoistrusted");
                    }
                    break;
                case "deletehouse":
                case "removehouse":
                case "destroyhouse":
                    if (cmdSource is IPlayer)
                    {
                        IPlayer builder = cmdSource as IPlayer;
                        houseManager.DestroyHouse(builder);
                    }
                    break;
                case "changehouse":
                case "edithouse":
                    if (cmdSource is IPlayer)
                    {
                        IPlayer builder = cmdSource as IPlayer;
                        houseManager.EditHouse(builder);
                    }
                    break;
                case "buildhouse":
                case "build":
                    if (cmdSource is IPlayer)
                    {
                        IPlayer builder = cmdSource as IPlayer;
                        if (args.Count() >= 1)
                        {
                            int width = 12;
                            int height = 12;

                            int x = builder.BlockX - width;
                            int y = builder.BlockY - height;

                            string houseType = args[0];

                            if (houseManager.BuildHouse(builder, houseType))
                                builder.Reply("say !finishhouse when you're done!");
                        }
                        else
                            houseManager.ShowHouses(builder);
                    }
                    break;
                case "placefurniture":
                case "placef":
                case "place":
                    if (cmdSource is IPlayer)
                    {
                        IPlayer player = cmdSource as IPlayer;
                        if (args.Length >= 1)
                        {
                            string furnitureType = args[0];

                            if (furnitureManager.GetFurnitureType(furnitureType) == null)
                            {
                                player.Reply("That is not a valid furniture.");
                                return;
                            }

                            Furniture furniture = (Furniture)Activator.CreateInstance(furnitureManager.GetFurnitureType(furnitureType).GetType(), new object[] {-1, -1});
                            if (furnitureType != null)
                            {
                                House house = houseManager.FindHouse(player.BlockX, player.BlockY);
                                if (house != null)
                                {
                                    if (house.IsValidFurniturePosition(player.BlockX, player.BlockY))
                                    {
                                        BlockPos pos = new BlockPos(0, player.BlockX, player.BlockY);
                                        furniture.X = pos.X;
                                        furniture.Y = pos.Y;
                                        bot.Room.setBlock(pos.X, pos.Y, furniture.getBlock(bot, player, house));
                                        if (house.Furniture.ContainsKey(pos))
                                        {
                                            if (house.Furniture[pos].Type != "empty")
                                                player.Reply("Replaced old furniture.");
                                            else
                                                player.Reply("Furniture placed.");

                                            house.Furniture[pos] = furniture;
                                        }
                                        else
                                        {
                                            house.Furniture.Add(pos, furniture);
                                            player.Reply("Furniture placed.");
                                        }
                                        houseManager.Save();
                                    }
                                    else
                                        player.Reply("You can't place furniture there.");
                                }
                                else
                                    player.Reply("You must be inside your house to place furniture!");
                            }
                            else
                            {
                                furnitureManager.PrintFurnitures(player);
                            }
                        }
                        else
                        {
                            furnitureManager.PrintFurnitures(player);
                            //string s = "You can place: ";
                            //foreach (var v in FurnitureManager.FurnitureTypes)
                            //    s += v.Key + ", ";
                            //s = s.Remove(s.Length - 3, 2);
                            //player.Reply(s);
                        }
                    }
                    break;
                case "finishouse":
                case "finishhouse":
                    if (cmdSource is IPlayer)
                    {
                        IPlayer builder = cmdSource as IPlayer;
                        houseManager.FinishHouse(builder);
                    }
                    break;
                case "houseinfo":
                    if (cmdSource is IPlayer && args.Length >= 1)
                    {
                        IPlayer player = cmdSource as IPlayer;

                        HouseType houseType = houseManager.GetHouseType(args[0]);

                        if (houseType == null)
                        {
                            houseManager.ListHouseTypes(player);
                        }
                        else
                        {
                            IInventoryContainer inventoryPlayer = (IInventoryContainer)player.GetMetadata("digplayer");
                            player.Reply(houseType.Name + "   " + "Size: " + houseType.Width + "*" + houseType.Height);
                            houseType.PrintCost(player, inventoryPlayer.Inventory);
                        }
                    }
                    break;

                case "trust":
                    if (cmdSource is IPlayer && args.Length >= 1)
                    {
                        HousePlayer housePlayer = HousePlayer.Get(cmdSource as IPlayer);
                        housePlayer.Trust(args[0]);
                        housePlayer.PrintTrusted();
                    }
                    break;

                case "untrust":
                    if (cmdSource is IPlayer && args.Length >= 1)
                    {
                        HousePlayer housePlayer = HousePlayer.Get(cmdSource as IPlayer);
                        if (housePlayer.IsTrusted(args[0]))
                        {
                            housePlayer.Untrust(args[0]);
                            cmdSource.Reply("You no longer trust" + args[0] + ".");
                            housePlayer.PrintTrusted();
                        }
                        else
                        {
                            cmdSource.Reply("You never trusted " + args[0] + ".");
                        }
                    }
                    break;

                case "whoistrusted":
                    if (cmdSource is IPlayer && args.Length >= 1)
                    {
                        HousePlayer.Get(cmdSource as IPlayer).PrintTrusted();
                    }
                    break;
                default:
                    break;
            }
        }