private void CalculatePath(RoomUser player) { SquarePoint point = DreamPathfinder.GetNextStep(player.X, player.Y, player.TargetX, player.TargetY, GameMap.Map, GameMap.ItemHeightMap, Model.MaxX, Model.MaxY, false, GameMap.DiagonalEnabled); if (point.X == player.X && point.Y == player.Y) //No path found, or reached goal (: { player.IsWalking = false; player.RemoveStatus("mv"); } else { HandleSetMovement(point, player); } player.NeedsUpdate = true; }
internal void OnCycle(ref int idleCount) { ToRemove.Clear(); int userCounter = 0; foreach (RoomUser User in UserList.Values) { if (!isValid(User)) { if (User.GetClient() != null) { RemoveUserFromRoom(User.GetClient(), false, false); } else { RemoveRoomUser(User); } } bool updated = false; User.IdleTime++; if (!User.IsAsleep && User.IdleTime >= 600) { User.IsAsleep = true; ServerMessage FallAsleep = new ServerMessage(486); FallAsleep.AppendInt32(User.VirtualId); FallAsleep.AppendBoolean(true); room.SendMessage(FallAsleep); } if (User.NeedsAutokick && !ToRemove.Contains(User)) { ToRemove.Add(User); continue; } if (User.CarryItemID > 0) { User.CarryTimer--; if (User.CarryTimer <= 0) { User.CarryItem(0); } } if (room.GotFreeze()) { room.GetFreeze().CycleUser(User); } if (User.isFlying) { User.OnFly(); } if (User.SetStep) { if (room.GetGameMap().CanWalk(User.SetX, User.SetY, User.AllowOverride)) { room.GetGameMap().UpdateUserMovement(new Point(User.Coordinate.X, User.Coordinate.Y), new Point(User.SetX, User.SetY), User); List <RoomItem> items = room.GetGameMap().GetCoordinatedItems(new Point(User.X, User.Y)); User.X = User.SetX; User.Y = User.SetY; User.Z = User.SetZ; if (User.isFlying) { User.Z += 4 + 0.5 * Math.Sin(0.7 * User.flyk); } foreach (RoomItem item in items) { item.UserWalksOffFurni(User); } if (User.X == room.GetGameMap().Model.DoorX&& User.Y == room.GetGameMap().Model.DoorY&& !ToRemove.Contains(User) && !User.IsBot) { ToRemove.Add(User); continue; } if (room.IsPublic) { room.GetGameMap().HandleRoomLinks(User); } UpdateUserStatus(User, true); } User.SetStep = false; } if (User.IsWalking && !User.Freezed) { Gamemap map = room.GetGameMap(); SquarePoint Point = DreamPathfinder.GetNextStep(User.X, User.Y, User.GoalX, User.GoalY, map.GameMap, map.ItemHeightMap, map.Model.MapSizeX, map.Model.MapSizeY, User.AllowOverride, map.DiagonalEnabled); if (Point.X == User.X && Point.Y == User.Y) //No path found, or reached goal (: { User.IsWalking = false; User.RemoveStatus("mv"); UpdateUserStatus(User, false); } else { int nextX = Point.X; int nextY = Point.Y; User.RemoveStatus("mv"); double nextZ = room.GetGameMap().SqAbsoluteHeight(nextX, nextY); User.Statusses.Remove("lay"); User.Statusses.Remove("sit"); if (!User.isFlying) { User.AddStatus("mv", nextX + "," + nextY + "," + TextHandling.GetString(nextZ)); } else { User.AddStatus("mv", nextX + "," + nextY + "," + TextHandling.GetString(nextZ + 4 + (0.5 * Math.Sin(0.7 * User.flyk)))); } int newRot = Rotation.Calculate(User.X, User.Y, nextX, nextY, User.moonwalkEnabled); User.RotBody = newRot; User.RotHead = newRot; User.SetStep = true; User.SetX = nextX; User.SetY = nextY; User.SetZ = nextZ; UpdateUserEffect(User, User.SetX, User.SetY); updated = true; room.GetGameMap().GameMap[User.X, User.Y] = User.SqState; // REstore the old one User.SqState = room.GetGameMap().GameMap[User.SetX, User.SetY]; //Backup the new one if (!room.AllowWalkthrough) { room.GetGameMap().GameMap[nextX, nextY] = 0; } } User.UpdateNeeded = true; } else { if (User.Statusses.ContainsKey("mv")) { User.RemoveStatus("mv"); User.UpdateNeeded = true; } } if (User.IsBot) { User.BotAI.OnTimerTick(); } else { userCounter++; } if (!updated) { UpdateUserEffect(User, User.X, User.Y); } } if (userCounter == 0) { idleCount++; } foreach (RoomUser toRemove in ToRemove) { GameClient client = PiciEnvironment.GetGame().GetClientManager().GetClientByUserID(toRemove.HabboId); if (client != null) { RemoveUserFromRoom(client, true, false); client.CurrentRoomUserID = -1; } else { RemoveRoomUser(toRemove); } } if (userCount != userCounter) { UpdateUserCount(userCounter); } }
internal void OnCycle(ref int idleCount) { ToRemove.Clear(); int userCounter = 0; foreach (RoomUnit unit in UnitList.Values) { unit.OnCycle(); bool updated = false; RoomUser user = unit as RoomUser; if (room.GotFreeze() && user != null) { room.GetFreeze().CycleUser(user); } if (unit.SetStep) { if (room.GetGameMap().CanWalk(unit.SetX, unit.SetY, unit.AllowOverride)) { room.GetGameMap().UpdateUnitMovement(new Point(unit.Coordinate.X, unit.Coordinate.Y), new Point(unit.SetX, unit.SetY), unit); List <RoomItem> items = room.GetGameMap().GetCoordinatedItems(new Point(unit.X, unit.Y)); unit.X = unit.SetX; unit.Y = unit.SetY; unit.Z = unit.SetZ; lock (items) { foreach (RoomItem item in items) { item.UserWalksOffFurni(unit); } } if (user != null && unit.X == room.GetGameMap().Model.DoorX&& unit.Y == room.GetGameMap().Model.DoorY&& !ToRemove.Contains(unit)) { ToRemove.Add(user); continue; } UpdateUserStatus(unit, true); } unit.SetStep = false; } if (unit.IsWalking) { // Find next square GameMap map = room.GetGameMap(); SquarePoint Point = DreamPathfinder.GetNextStep(unit.X, unit.Y, unit.GoalX, unit.GoalY, map.Map, map.ItemHeightMap, map.Model.MapSizeX, map.Model.MapSizeY, unit.AllowOverride, map.DiagonalEnabled); if (Point.X == unit.X && Point.Y == unit.Y) //No path found, or reached goal (: { unit.IsWalking = false; unit.RemoveStatus("mv"); UpdateUserStatus(unit, false); } else { // Let's walk! int nextX = Point.X; int nextY = Point.Y; //unit.RemoveStatus("mv"); double nextZ = room.GetGameMap().SqAbsoluteHeight(nextX, nextY); unit.Statuses.Remove("lay"); unit.Statuses.Remove("sit"); unit.AddStatus("mv", nextX + "," + nextY + "," + TextHandling.GetString(nextZ)); bool moonWalk = user == null ? false : user.moonwalkEnabled; int newRot = Rotation.Calculate(unit.X, unit.Y, nextX, nextY, moonWalk); unit.RotBody = newRot; unit.RotHead = newRot; unit.SetStep = true; unit.SetX = nextX; unit.SetY = nextY; unit.SetZ = nextZ; updated = true; room.GetGameMap().Map[unit.X, unit.Y] = unit.SqState; // REstore the old one unit.SqState = room.GetGameMap().Map[unit.SetX, unit.SetY]; //Backup the new one if (user != null) { UpdateUserEffect(user, user.SetX, user.SetY); if (user.IsSitting == true) { user.IsSitting = false; } if (user.IsLaying == true) { user.IsLaying = false; } } if (!room.AllowWalkthrough) { room.GetGameMap().Map[nextX, nextY] = 0; } } unit.UpdateNeeded = true; } else { if (unit.Statuses.ContainsKey("mv")) { unit.Statuses.Remove("mv"); unit.UpdateNeeded = true; } } if (user != null) { userCounter++; } if (!updated && user != null) { UpdateUserEffect(user, user.X, user.Y); } } if (userCounter == 0) { idleCount++; } foreach (RoomUser toRemove in ToRemove) { GameClient client = FirewindEnvironment.GetGame().GetClientManager().GetClientByUserID(toRemove.ID); if (client != null) { RemoveUserFromRoom(client, true, false); client.CurrentRoomUserID = -1; } else { RemoveRoomUnit(toRemove); } } if (userCount != userCounter) { UpdateUserCount(userCounter); } }