internal bool SetFloorItem(RoomItem Item, int newX, int newY, Double newZ) { room.GetGameMap().RemoveFromMap(Item); Item.SetState(newX, newY, newZ, Gamemap.GetAffectedTiles(Item.GetBaseItem().Length, Item.GetBaseItem().Width, newX, newY, Item.Rot)); UpdateItem(Item); room.GetGameMap().AddItemToMap(Item); return(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); } }
private void Initialize(UInt32 Id, string Name, string Description, string Type, string Owner, int Category, int State, int UsersMax, string ModelName, string CCTs, int Score, List <string> pTags, bool AllowPets, bool AllowPetsEating, bool AllowWalkthrough, bool Hidewall, RoomIcon Icon, string Password, string Wallpaper, string Floor, string Landscape, RoomData RoomData, bool RightOverride, int walltickness, int floorthickness) { this.mDisposed = false; this.Id = Id; this.Name = Name; this.Description = Description; this.Owner = Owner; this.Category = Category; this.Type = Type; this.State = State; this.UsersNow = 0; this.UsersMax = UsersMax; this.ModelName = ModelName; this.CCTs = CCTs; this.Score = Score; tagCount = 0; this.Tags = new ArrayList(); foreach (string tag in pTags) { tagCount++; Tags.Add(tag); } this.AllowPets = AllowPets; this.AllowPetsEating = AllowPetsEating; this.AllowWalkthrough = AllowWalkthrough; this.Hidewall = Hidewall; this.myIcon = Icon; this.Password = Password; this.Bans = new Dictionary <UInt32, double>(); this.Wallpaper = Wallpaper; this.Floor = Floor; this.Landscape = Landscape; this.chatMessageManager = new ChatMessageManager(); this.groups = new QueuedDictionary <int, Group>(); this.ActiveTrades = new ArrayList(); this.mCycleEnded = false; this.mRoomData = RoomData; this.EveryoneGotRights = RightOverride; this.roomMessages = new Queue(); this.chatMessageQueue = new Queue(); this.rnd = new Random(); this.roomMessages = new Queue(); this.roomAlerts = new Queue(); this.roomBadge = new Queue(); this.roomKick = new Queue(); this.roomServerMessages = new Queue(); this.IdleTime = 0; this.RoomMuted = false; this.WallThickness = walltickness; this.FloorThickness = floorthickness; this.gamemap = new Gamemap(this); this.roomItemHandling = new RoomItemHandling(this); this.roomUserManager = new RoomUserManager(this); this.wiredHandler = new WiredHandler(this); LoadRights(); GetRoomItemHandler().LoadFurniture(); wiredHandler.LoadWired(); GetGameMap().GenerateMaps(); LoadMusic(); //LoadBots(); using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor()) { if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MySQL) { dbClient.runFastQuery("REPLACE INTO room_active VALUES (" + Id + ",1)"); } else { dbClient.runFastQuery("IF EXISTS (SELECT roomid FROM room_active WHERE roomid = " + Id + ") " + "UPDATE room_active SET active_users = 1 WHERE roomid = " + Id + " " + "ELSE " + "INSERT INTO room_active VALUES (" + Id + ",1)"); } } PiciEnvironment.GetGame().GetRoomManager().QueueActiveRoomAdd(mRoomData); }
internal bool SetFloorItem(GameClient Session, RoomItem Item, int newX, int newY, int newRot, bool newItem, bool OnRoller, bool sendMessage, bool updateRoomUserStatuses) { bool NeedsReAdd = false; if (!newItem) { NeedsReAdd = room.GetGameMap().RemoveFromMap(Item); } Dictionary <int, ThreeDCoord> AffectedTiles = Gamemap.GetAffectedTiles(Item.GetBaseItem().Length, Item.GetBaseItem().Width, newX, newY, newRot); if (!room.GetGameMap().ValidTile(newX, newY) || room.GetGameMap().SquareHasUsers(newX, newY)) { if (NeedsReAdd) { AddItem(Item); room.GetGameMap().AddToMap(Item); } return(false); } foreach (ThreeDCoord Tile in AffectedTiles.Values) { if (!room.GetGameMap().ValidTile(Tile.X, Tile.Y) || room.GetGameMap().SquareHasUsers(Tile.X, Tile.Y)) { if (NeedsReAdd) { AddItem(Item); room.GetGameMap().AddToMap(Item); } return(false); } } // Start calculating new Z coordinate Double newZ = room.GetGameMap().Model.SqFloorHeight[newX, newY]; if (!OnRoller) { // Is the item trying to stack on itself!? //if (Item.Rot == newRot && Item.GetX == newX && Item.GetY == newY && Item.GetZ != newZ) //{ // if (NeedsReAdd) // AddItem(Item); // return false; //} // Make sure this tile is open and there are no users here if (room.GetGameMap().Model.SqState[newX, newY] != SquareState.OPEN) { if (NeedsReAdd) { AddItem(Item); room.GetGameMap().AddToMap(Item); } return(false); } foreach (ThreeDCoord Tile in AffectedTiles.Values) { if (room.GetGameMap().Model.SqState[Tile.X, Tile.Y] != SquareState.OPEN) { if (NeedsReAdd) { AddItem(Item); room.GetGameMap().AddToMap(Item); } return(false); } } // And that we have no users if (!Item.GetBaseItem().IsSeat&& !Item.IsRoller) { foreach (ThreeDCoord Tile in AffectedTiles.Values) { if (room.GetGameMap().GetRoomUsers(new Point(Tile.X, Tile.Y)).Count > 0) { if (NeedsReAdd) { AddItem(Item); room.GetGameMap().AddToMap(Item); } return(false); } } } } // Find affected objects List <RoomItem> ItemsOnTile = GetFurniObjects(newX, newY); List <RoomItem> ItemsAffected = new List <RoomItem>(); List <RoomItem> ItemsComplete = new List <RoomItem>(); foreach (ThreeDCoord Tile in AffectedTiles.Values) { List <RoomItem> Temp = GetFurniObjects(Tile.X, Tile.Y); if (Temp != null) { ItemsAffected.AddRange(Temp); } } ItemsComplete.AddRange(ItemsOnTile); ItemsComplete.AddRange(ItemsAffected); if (!OnRoller) { // Check for items in the stack that do not allow stacking on top of them foreach (RoomItem I in ItemsComplete) { if (I == null) { continue; } if (I.Id == Item.Id) { continue; } if (I.GetBaseItem() == null) { continue; } if (!I.GetBaseItem().Stackable) { if (NeedsReAdd) { AddItem(Item); room.GetGameMap().AddToMap(Item); } return(false); } } } //if (!Item.IsRoller) { // If this is a rotating action, maintain item at current height if (Item.Rot != newRot && Item.GetX == newX && Item.GetY == newY) { newZ = Item.GetZ; } // Are there any higher objects in the stack!? foreach (RoomItem I in ItemsComplete) { if (I.Id == Item.Id) { continue; // cannot stack on self } if (I.TotalHeight > newZ) { newZ = I.TotalHeight; } } } // Verify the rotation is correct if (newRot != 0 && newRot != 2 && newRot != 4 && newRot != 6 && newRot != 8) { newRot = 0; } //Item.GetX = newX; //Item.GetY = newY; //Item.GetZ = newZ; Item.Rot = newRot; int oldX = Item.GetX; int oldY = Item.GetY; Item.SetState(newX, newY, newZ, AffectedTiles); if (!OnRoller && Session != null) { Item.Interactor.OnPlace(Session, Item); } if (newItem) { if (mFloorItems.ContainsKey(Item.Id)) { if (Session != null) { Session.SendNotif(LanguageLocale.GetValue("room.itemplaced")); } //Remove from map!!! return(true); } //using (DatabaseClient dbClient = PiciEnvironment.GetDatabase().GetClient()) //{ // dbClient.addParameter("extra_data", Item.ExtraData); // dbClient.runFastQuery("INSERT INTO room_items (id,room_id,base_item,extra_data,x,y,z,rot,wall_pos) VALUES ('" + Item.Id + "','" + RoomId + "','" + Item.BaseItem + "',@extra_data,'" + Item.GetX + "','" + Item.GetY + "','" + Item.GetZ + "','" + Item.Rot + "','')"); //} //if (mRemovedItems.ContainsKey(Item.Id)) // mRemovedItems.Remove(Item.Id); //if (mAddedItems.ContainsKey(Item.Id)) // return false; //mAddedItems.Add(Item.Id, Item); if (Item.IsFloorItem && !mFloorItems.ContainsKey(Item.Id)) { mFloorItems.Add(Item.Id, Item); } else if (Item.IsWallItem && !mWallItems.ContainsKey(Item.Id)) { mWallItems.Add(Item.Id, Item); } AddItem(Item); if (sendMessage) { ServerMessage Message = new ServerMessage(93); Item.Serialize(Message); room.SendMessage(Message); } } else { //using (DatabaseClient dbClient = PiciEnvironment.GetDatabase().GetClient()) //{ // dbClient.runFastQuery("UPDATE room_items SET x = '" + Item.GetX + "', y = '" + Item.GetY + "', z = '" + Item.GetZ + "', rot = '" + Item.Rot + "', wall_pos = '' WHERE id = '" + Item.Id + "' LIMIT 1"); //} UpdateItem(Item); if (!OnRoller && sendMessage) { ServerMessage Message = new ServerMessage(95); Item.Serialize(Message); room.SendMessage(Message); } } if (!newItem) { room.GetWiredHandler().RemoveWiredItem(new System.Drawing.Point(oldX, oldY)); if (WiredHandler.TypeIsWire(Item.GetBaseItem().InteractionType)) { room.GetWiredHandler().AddWire(Item, new System.Drawing.Point(newX, newY), newRot, Item.GetBaseItem().InteractionType); } } else { if (WiredHandler.TypeIsWire(Item.GetBaseItem().InteractionType)) { room.GetWiredHandler().AddWire(Item, Item.Coordinate, newRot, Item.GetBaseItem().InteractionType); } } //GenerateMaps(false); room.GetGameMap().AddToMap(Item); if (updateRoomUserStatuses) { room.GetRoomUserManager().UpdateUserStatusses(); } return(true); }
private void Initialize(UInt32 Id, string Name, string Description, string Type, string Owner, int Category, int State, int UsersMax, string ModelName, string CCTs, int Score, List<string> pTags, bool AllowPets, bool AllowPetsEating, bool AllowWalkthrough, bool Hidewall, RoomIcon Icon, string Password, string Wallpaper, string Floor, string Landscape, RoomData RoomData, bool RightOverride, int walltickness, int floorthickness) { this.mDisposed = false; this.Id = Id; this.Name = Name; this.Description = Description; this.Owner = Owner; this.Category = Category; this.Type = Type; this.State = State; this.UsersNow = 0; this.UsersMax = UsersMax; this.ModelName = ModelName; this.CCTs = CCTs; this.Score = Score; tagCount = 0; this.Tags = new ArrayList(); foreach (string tag in pTags) { tagCount++; Tags.Add(tag); } this.AllowPets = AllowPets; this.AllowPetsEating = AllowPetsEating; this.AllowWalkthrough = AllowWalkthrough; this.Hidewall = Hidewall; this.myIcon = Icon; this.Password = Password; this.Bans = new Dictionary<UInt32, double>(); this.Wallpaper = Wallpaper; this.Floor = Floor; this.Landscape = Landscape; this.chatMessageManager = new ChatMessageManager(); this.groups = new QueuedDictionary<int, Group>(); this.ActiveTrades = new ArrayList(); this.mCycleEnded = false; this.mRoomData = RoomData; this.EveryoneGotRights = RightOverride; this.roomMessages = new Queue(); this.chatMessageQueue = new Queue(); this.rnd = new Random(); this.roomMessages = new Queue(); this.roomAlerts = new Queue(); this.roomBadge = new Queue(); this.roomKick = new Queue(); this.roomServerMessages = new Queue(); this.IdleTime = 0; this.RoomMuted = false; this.WallThickness = walltickness; this.FloorThickness = floorthickness; this.gamemap = new Gamemap(this); this.roomItemHandling = new RoomItemHandling(this); this.roomUserManager = new RoomUserManager(this); this.wiredHandler = new WiredHandler(this); LoadRights(); GetRoomItemHandler().LoadFurniture(); wiredHandler.LoadWired(); GetGameMap().GenerateMaps(); LoadMusic(); //LoadBots(); using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor()) { if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MySQL) { dbClient.runFastQuery("REPLACE INTO room_active VALUES (" + Id + ",1)"); } else { dbClient.runFastQuery("IF EXISTS (SELECT roomid FROM room_active WHERE roomid = " + Id + ") " + "UPDATE room_active SET active_users = 1 WHERE roomid = " + Id + " " + "ELSE " + "INSERT INTO room_active VALUES (" + Id + ",1)"); } } PiciEnvironment.GetGame().GetRoomManager().QueueActiveRoomAdd(mRoomData); }