void Goto(Player p, string playerName = null, ushort page = 0) { bool all = false; if (playerName != null) { playerName = playerName.ToLower(); if (playerName == "all") { all = true; } else if (playerName == "public") { playerName = null; } else { playerName = StoredCustomModel.GetPlayerName(playerName) ?? StoredCustomModel.GetPlayerName(playerName + "+"); } } List <string> modelNames; if (all) { var dict = GetAllModels(p); modelNames = dict // public ones first .OrderByDescending(pair => pair.Key == "Public") // then by player name A-Z .ThenBy(pair => pair.Key) .Select(pair => pair.Value) .SelectMany(x => x) .ToList(); } else { modelNames = GetModels(playerName, p); } if (modelNames == null) { return; } // - 1 for our self player var partitionSize = Packet.MaxCustomModels - 1; var partitions = modelNames.Partition(partitionSize).ToList(); if (page >= partitions.Count) { p.Message( "%WPage doesn't exist" ); return; } var total = modelNames.Count; modelNames = partitions[page]; p.Message( "%HViewing %T{0} %Hmodels{1}", total, partitions.Count > 1 ? string.Format( " %S(page %T{0}%S/%T{1}%S)", page + 1, partitions.Count ) : "" ); if (partitions.Count > 1 && page < (partitions.Count - 1)) { p.Message( "%SUse \"%H/cm goto {0} {1}%S\" to go to the next page", playerName, page + 2 ); } var mapName = string.Format( "&f{0} Custom Models{1}", all ? "All" : ( playerName == null ? "Public" : GetNameWithoutPlus(playerName) + "'s" ), page != 0 ? string.Format(" ({0})", page + 1) : "" ); ushort spacing = 4; ushort width = (ushort)( // edges (spacing * 2) + // grass blocks modelNames.Count + // inbetween blocks ((modelNames.Count - 1) * (spacing - 1)) ); ushort height = 1; ushort length = 16; byte[] blocks = new byte[width * height * length]; Level lvl = new Level(mapName, width, height, length, blocks); for (int i = 0; i < blocks.Length; i++) { blocks[i] = 1; } lvl.SaveChanges = false; lvl.ChangedSinceBackup = false; lvl.IsMuseum = true; lvl.BuildAccess.Min = LevelPermission.Nobody; lvl.Config.Physics = 0; lvl.spawnx = spacing; lvl.spawny = 2; lvl.Config.HorizonBlock = 1; lvl.Config.EdgeLevel = 1; lvl.Config.CloudsHeight = -0xFFFFFF; lvl.Config.SidesOffset = 0; lvl.Config.Buildable = false; lvl.Config.Deletable = false; for (ushort i = 0; i < modelNames.Count; i++) { ushort x = (ushort)(spacing + (i * spacing)); ushort y = 0; ushort z = spacing; blocks[lvl.PosToInt(x, y, z)] = 2; var modelName = modelNames[i]; var storedModel = new StoredCustomModel(modelName); if (storedModel.Exists()) { storedModel.LoadFromFile(); } var skinName = p.SkinName; if ( !storedModel.usesHumanSkin && storedModel.defaultSkin != null ) { skinName = storedModel.defaultSkin; } // hack because clients strip + at the end var botName = "&f" + (modelName.EndsWith("+") ? modelName + "&0+" : modelName); var bot = new PlayerBot(botName, lvl) { id = (byte)i, Model = modelName, SkinName = skinName, }; bot.SetInitialPos(Position.FromFeetBlockCoords(x, y + 1, z)); bot.SetYawPitch(Orientation.DegreesToPacked(180), Orientation.DegreesToPacked(0)); bot.ClickedOnText = "/CustomModel wear " + modelName; _ = lvl.Bots.Add(bot); } if (!PlayerActions.ChangeMap(p, lvl)) { return; } }
void DoMove() { if ((pos[1] - 19) % 32 != 0 && !jumping) { pos[1] = (ushort)((pos[1] + 19) - (pos[1] % 32)); } ushort x = (ushort)Math.Round((decimal)(pos[0] - 16) / 32); ushort y = (ushort)((pos[1] - 64) / 32); ushort z = (ushort)Math.Round((decimal)(pos[2] - 16) / 32); int dx = Math.Sign(foundPos[0] - pos[0]), dz = Math.Sign(foundPos[2] - pos[2]); byte b = Block.Convert(level.GetTile(x, y, z)); byte b1, b2, b3; if (Block.Walkthrough(b) && !jumping) { pos[1] = (ushort)(pos[1] - 32); } y = (ushort)((pos[1] - 64) / 32); //Block below feet int index = level.PosToInt((ushort)(x + dx), y, (ushort)(z + dz)); b = Block.Convert(level.GetTile(index)); b1 = Block.Convert(level.GetTile(level.IntOffset(index, 0, 1, 0))); b2 = Block.Convert(level.GetTile(level.IntOffset(index, 0, 2, 0))); b3 = Block.Convert(level.GetTile(level.IntOffset(index, 0, 3, 0))); if (Block.Walkthrough(b2) && Block.Walkthrough(b3) && !Block.Walkthrough(b1)) { pos[0] += (ushort)dx; // Get ready to go up step pos[1] += (ushort)32; pos[2] += (ushort)dz; } else if (Block.Walkthrough(b1) && Block.Walkthrough(b2)) { pos[0] += (ushort)dx; // Stay on current level pos[2] += (ushort)dz; } else if (Block.Walkthrough(b) && Block.Walkthrough(b1)) { pos[0] += (ushort)dx; // Drop a level pos[1] -= (ushort)32; pos[2] += (ushort)dz; } /*x = (ushort)Math.Round((decimal)(pos[0] - 16) / (decimal)32); * y = (ushort)((pos[1] - 64) / 32); * z = (ushort)Math.Round((decimal)(pos[2] - 16) / (decimal)32); * * b1 = Block.Convert(level.GetTile(x, (ushort)(y + 1), z)); * b2 = Block.Convert(level.GetTile(x, (ushort)(y + 2), z)); * b3 = Block.Convert(level.GetTile(x, y, z)); * * * if ((ushort)(foundPos[1] / 32) > y) { * if (b1 == Block.water || b1 == Block.waterstill || b1 == Block.lava || b1 == Block.lavastill) { * if (Block.Walkthrough(b2)) { * pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1]))); * } * } else if (b2 == Block.water || b2 == Block.waterstill || b2 == Block.lava || b2 == Block.lavastill) { * pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1]))); * } * } else if ((ushort)(foundPos[1] / 32) < y) { * if (b3 == Block.water || b3 == Block.waterstill || b3 == Block.lava || b3 == Block.lavastill) { * pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1]))); * } * }*/ }
void MoveTimerFunc(object sender, ElapsedEventArgs e) { moveTimer.Interval = Server.updateTimer.Interval / movementSpeed; if (!movement) { return; } int newNum; Random rand = new Random(); if ((pos[1] - 19) % 32 != 0 && !jumping) { pos[1] = (ushort)((pos[1] + 19) - (pos[1] % 32)); } ushort x = (ushort)Math.Round((decimal)(pos[0] - 16) / 32); ushort y = (ushort)((pos[1] - 64) / 32); ushort z = (ushort)Math.Round((decimal)(pos[2] - 16) / 32); byte b = Block.Convert(level.GetTile(x, y, z)); byte b1, b2, b3;//, b4; if (Block.Walkthrough(b) && !jumping) { pos[1] = (ushort)(pos[1] - 32); } y = (ushort)((pos[1] - 64) / 32); //Block below feet newNum = level.PosToInt((ushort)(x + Math.Sign(foundPos[0] - pos[0])), y, (ushort)(z + Math.Sign(foundPos[2] - pos[2]))); b = Block.Convert(level.GetTile(newNum)); b1 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 1, 0))); b2 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 2, 0))); b3 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 3, 0))); if (Block.Walkthrough(b2) && Block.Walkthrough(b3) && !Block.Walkthrough(b1)) { //Get ready to go up step pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]); pos[1] += (ushort)32; pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]); } else if (Block.Walkthrough(b1) && Block.Walkthrough(b2)) { //Stay on current level pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]); pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]); } else if (Block.Walkthrough(b) && Block.Walkthrough(b1)) { //Drop a level pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]); pos[1] -= (ushort)32; pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]); } x = (ushort)Math.Round((decimal)(pos[0] - 16) / (decimal)32); y = (ushort)((pos[1] - 64) / 32); z = (ushort)Math.Round((decimal)(pos[2] - 16) / (decimal)32); b1 = Block.Convert(level.GetTile(x, (ushort)(y + 1), z)); b2 = Block.Convert(level.GetTile(x, (ushort)(y + 2), z)); b3 = Block.Convert(level.GetTile(x, y, z)); /* * if ((ushort)(foundPos[1] / 32) > y) { * if (b1 == Block.water || b1 == Block.waterstill || b1 == Block.lava || b1 == Block.lavastill) { * if (Block.Walkthrough(b2)) { * pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1]))); * } * } else if (b2 == Block.water || b2 == Block.waterstill || b2 == Block.lava || b2 == Block.lavastill) { * pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1]))); * } * } else if ((ushort)(foundPos[1] / 32) < y) { * if (b3 == Block.water || b3 == Block.waterstill || b3 == Block.lava || b3 == Block.lavastill) { * pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1]))); * } * }*/ }
public PlayerBot(string n, Level l, ushort x, ushort y, ushort z, byte rotx, byte roty) { name = n; color = "&1"; id = FreeId(); level = l; pos = new ushort[3] { x, y, z }; rot = new byte[2] { rotx, roty }; GlobalSpawn(); foreach (Player p in Player.players) { if (p.level == level) { Player.SendMessage(p, color + name + Server.DefaultColor + ", the bot, has been added."); } } botTimer.Elapsed += delegate { int currentNum, foundNum = (32 * 75); Random rand = new Random(); x = (ushort)Math.Round((decimal)pos[0] / (decimal)32); y = (ushort)((pos[1] - 33) / 32); z = (ushort)Math.Round((decimal)pos[2] / (decimal)32); if (kill) { foreach (Player p in Player.players) { if ((ushort)(p.pos[0] / 32) == x) { if (Math.Abs((ushort)(p.pos[1] / 32) - y) < 2) { if ((ushort)(p.pos[2] / 32) == z) { p.HandleDeath(Block.Zero); } } } } } if (Waypoints.Count < 1) { if (hunt) Player.players.ForEach(delegate(Player p) { if (p.level == level && !p.invincible) { currentNum = Math.Abs(p.pos[0] - pos[0]) + Math.Abs(p.pos[1] - pos[1]) + Math.Abs(p.pos[2] - pos[2]); if (currentNum < foundNum) { foundNum = currentNum; foundPos = p.pos; foundRot = p.rot; movement = true; rot[1] = (byte)(255 - foundRot[1]); if (foundRot[0] < 128) rot[0] = (byte)(foundRot[0] + 128); else rot[0] = (byte)(foundRot[0] - 128); } } }); } else { bool skip = false; movement = false; retry: switch (Waypoints[currentPoint].type) { case "walk": foundPos[0] = Waypoints[currentPoint].x; foundPos[1] = Waypoints[currentPoint].y; foundPos[2] = Waypoints[currentPoint].z; movement = true; if ((ushort)(pos[0] / 32) == (ushort)(Waypoints[currentPoint].x / 32)) { if ((ushort)(pos[2] / 32) == (ushort)(Waypoints[currentPoint].z / 32)) { rot[0] = Waypoints[currentPoint].rotx; rot[1] = Waypoints[currentPoint].roty; currentPoint++; movement = false; if (currentPoint == Waypoints.Count) currentPoint = 0; if (!skip) { skip = true; goto retry; } } } break; case "teleport": pos[0] = Waypoints[currentPoint].x; pos[1] = Waypoints[currentPoint].y; pos[2] = Waypoints[currentPoint].z; rot[0] = Waypoints[currentPoint].rotx; rot[1] = Waypoints[currentPoint].roty; currentPoint++; if (currentPoint == Waypoints.Count) currentPoint = 0; return; case "wait": if (countdown != 0) { countdown--; if (countdown == 0) { currentPoint++; if (currentPoint == Waypoints.Count) currentPoint = 0; if (!skip) { skip = true; goto retry; } } } else { countdown = Waypoints[currentPoint].seconds; } return; case "nod": if (countdown != 0) { countdown--; if (nodUp) { if (rot[1] > 32 && rot[1] < 128) nodUp = !nodUp; else { if (rot[1] + (byte)Waypoints[currentPoint].rotspeed > 255) rot[1] = 0; else rot[1] += (byte)Waypoints[currentPoint].rotspeed; } } else { if (rot[1] > 128 && rot[1] < 224) nodUp = !nodUp; else { if (rot[1] - (byte)Waypoints[currentPoint].rotspeed < 0) rot[1] = 255; else rot[1] -= (byte)Waypoints[currentPoint].rotspeed; } } if (countdown == 0) { currentPoint++; if (currentPoint == Waypoints.Count) currentPoint = 0; if (!skip) { skip = true; goto retry; } } } else { countdown = Waypoints[currentPoint].seconds; } return; case "spin": if (countdown != 0) { countdown--; if (rot[0] + (byte)Waypoints[currentPoint].rotspeed > 255) rot[0] = 0; else if (rot[0] + (byte)Waypoints[currentPoint].rotspeed < 0) rot[0] = 255; else rot[0] += (byte)Waypoints[currentPoint].rotspeed; if (countdown == 0) { currentPoint++; if (currentPoint == Waypoints.Count) currentPoint = 0; if (!skip) { skip = true; goto retry; } } } else { countdown = Waypoints[currentPoint].seconds; } return; case "speed": movementSpeed = (int)Math.Round((decimal)((decimal)24 / (decimal)100 * (decimal)Waypoints[currentPoint].seconds)); if (movementSpeed == 0) movementSpeed = 1; currentPoint++; if (currentPoint == Waypoints.Count) currentPoint = 0; if (!skip) { skip = true; goto retry; } return; case "reset": currentPoint = 0; return; case "remove": removeBot(); return; case "linkscript": if (File.Exists("bots/" + Waypoints[currentPoint].newscript)) { Command.all.Find("botset").Use(null, this.name + " " + Waypoints[currentPoint].newscript); return; } currentPoint++; if (currentPoint == Waypoints.Count) currentPoint = 0; if (!skip) { skip = true; goto retry; } return; case "jump": jumpTimer.Elapsed += delegate { currentjump++; switch (currentjump) { case 1: case 2: pos[1] += 24; break; case 3: break; case 4: pos[1] -= 24; break; case 5: pos[1] -= 24; jumping = false; currentjump = 0; jumpTimer.Stop(); break; } }; jumpTimer.Start(); currentPoint++; if (currentPoint == Waypoints.Count) currentPoint = 0; if (!skip) { skip = true; goto retry; } break; } if (currentPoint == Waypoints.Count) currentPoint = 0; } if (!movement) { if (rot[0] < 245) rot[0] += 8; else rot[0] = 0; if (rot[1] > 32 && rot[1] < 64) rot[1] = 224; else if (rot[1] > 250) rot[1] = 0; else rot[1] += 4; } }; botTimer.Start(); moveTimer.Elapsed += delegate { moveTimer.Interval = Server.updateTimer.Interval / movementSpeed; if (!movement) return; int newNum; Random rand = new Random(); if ((pos[1] - 19) % 32 != 0 && !jumping) { pos[1] = (ushort)((pos[1] + 19) - (pos[1] % 32)); } x = (ushort)Math.Round((decimal)(pos[0] - 16) / (decimal)32); y = (ushort)((pos[1] - 64) / 32); z = (ushort)Math.Round((decimal)(pos[2] - 16) / (decimal)32); byte b = Block.Convert(level.GetTile(x, y, z)); byte b1, b2, b3;//, b4; if (Block.Walkthrough(b) && !jumping) { pos[1] = (ushort)(pos[1] - 32); } y = (ushort)((pos[1] - 64) / 32); //Block below feet newNum = level.PosToInt((ushort)(x + Math.Sign(foundPos[0] - pos[0])), y, (ushort)(z + Math.Sign(foundPos[2] - pos[2]))); b = Block.Convert(level.GetTile(newNum)); b1 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 1, 0))); b2 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 2, 0))); b3 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 3, 0))); if (Block.Walkthrough(b2) && Block.Walkthrough(b3) && !Block.Walkthrough(b1)) { //Get ready to go up step pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]); pos[1] += (ushort)32; pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]); } else if (Block.Walkthrough(b1) && Block.Walkthrough(b2)) { //Stay on current level pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]); pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]); } else if (Block.Walkthrough(b) && Block.Walkthrough(b1)) { //Drop a level pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]); pos[1] -= (ushort)32; pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]); } x = (ushort)Math.Round((decimal)(pos[0] - 16) / (decimal)32); y = (ushort)((pos[1] - 64) / 32); z = (ushort)Math.Round((decimal)(pos[2] - 16) / (decimal)32); b1 = Block.Convert(level.GetTile(x, (ushort)(y + 1), z)); b2 = Block.Convert(level.GetTile(x, (ushort)(y + 2), z)); b3 = Block.Convert(level.GetTile(x, y, z)); /* if ((ushort)(foundPos[1] / 32) > y) { if (b1 == Block.water || b1 == Block.waterstill || b1 == Block.lava || b1 == Block.lavastill) { if (Block.Walkthrough(b2)) { pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1]))); } } else if (b2 == Block.water || b2 == Block.waterstill || b2 == Block.lava || b2 == Block.lavastill) { pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1]))); } } else if ((ushort)(foundPos[1] / 32) < y) { if (b3 == Block.water || b3 == Block.waterstill || b3 == Block.lava || b3 == Block.lavastill) { pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1]))); } }*/ }; moveTimer.Start(); }