public bool AddAvatarToRoom(GameClient Session) { if (_room == null) return false; if (Session == null) return false; if (Session.GetHabbo().CurrentRoom == null) return false; #region Old Stuff RoomUser User = new RoomUser(Session.GetHabbo().Id, _room.RoomId, primaryPrivateUserID++, _room); if (User == null || User.GetClient() == null) return false; User.UserId = Session.GetHabbo().Id; Session.GetHabbo().TentId = 0; int PersonalID = secondaryPrivateUserID++; User.InternalRoomID = PersonalID; Session.GetHabbo().CurrentRoomId = _room.RoomId; if (!this._users.TryAdd(PersonalID, User)) return false; #endregion DynamicRoomModel Model = _room.GetGameMap().Model; if (Model == null) return false; if (!_room.PetMorphsAllowed && Session.GetHabbo().PetId != 0) Session.GetHabbo().PetId = 0; if (!Session.GetHabbo().IsTeleporting && !Session.GetHabbo().IsHopping) { if (!Model.DoorIsValid()) { Point Square = _room.GetGameMap().getRandomWalkableSquare(); Model.DoorX = Square.X; Model.DoorY = Square.Y; Model.DoorZ = _room.GetGameMap().GetHeightForSquareFromData(Square); } User.SetPos(Model.DoorX, Model.DoorY, Model.DoorZ); User.SetRot(Model.DoorOrientation, false); } else if (!User.IsBot && (User.GetClient().GetHabbo().IsTeleporting || User.GetClient().GetHabbo().IsHopping)) { Item Item = null; if (Session.GetHabbo().IsTeleporting) Item = _room.GetRoomItemHandler().GetItem(Session.GetHabbo().TeleporterId); else if (Session.GetHabbo().IsHopping) Item = _room.GetRoomItemHandler().GetItem(Session.GetHabbo().HopperId); if (Item != null) { if (Session.GetHabbo().IsTeleporting) { Item.ExtraData = "2"; Item.UpdateState(false, true); User.SetPos(Item.GetX, Item.GetY, Item.GetZ); User.SetRot(Item.Rotation, false); Item.InteractingUser2 = Session.GetHabbo().Id; Item.ExtraData = "0"; Item.UpdateState(false, true); } else if (Session.GetHabbo().IsHopping) { Item.ExtraData = "1"; Item.UpdateState(false, true); User.SetPos(Item.GetX, Item.GetY, Item.GetZ); User.SetRot(Item.Rotation, false); User.AllowOverride = false; Item.InteractingUser2 = Session.GetHabbo().Id; Item.ExtraData = "2"; Item.UpdateState(false, true); } } else { User.SetPos(Model.DoorX, Model.DoorY, Model.DoorZ - 1); User.SetRot(Model.DoorOrientation, false); } } _room.SendMessage(new UsersComposer(User)); //Below = done if (_room.CheckRights(Session, true)) { User.SetStatus("flatctrl", "useradmin"); Session.SendMessage(new YouAreOwnerComposer()); Session.SendMessage(new YouAreControllerComposer(4)); } else if (_room.CheckRights(Session, false) && _room.Group == null) { User.SetStatus("flatctrl", "1"); Session.SendMessage(new YouAreControllerComposer(1)); } else if (_room.Group != null && _room.CheckRights(Session, false, true)) { User.SetStatus("flatctrl", "3"); Session.SendMessage(new YouAreControllerComposer(3)); } else Session.SendMessage(new YouAreNotControllerComposer()); User.UpdateNeeded = true; if (Session.GetHabbo().GetPermissions().HasRight("mod_tool") && !Session.GetHabbo().DisableForcedEffects) Session.GetHabbo().Effects().ApplyEffect(102); foreach (RoomUser Bot in this._bots.Values.ToList()) { if (Bot == null || Bot.BotAI == null) continue; Bot.BotAI.OnUserEnterRoom(User); } return true; }
public void UpdateUserStatus(RoomUser User, bool cyclegameitems) { if (User == null) return; try { bool isBot = User.IsBot; if (isBot) cyclegameitems = false; if (PlusEnvironment.GetUnixTimestamp() > PlusEnvironment.GetUnixTimestamp() + User.SignTime) { if (User.Statusses.ContainsKey("sign")) { User.Statusses.Remove("sign"); User.UpdateNeeded = true; } } if ((User.Statusses.ContainsKey("lay") && !User.isLying) || (User.Statusses.ContainsKey("sit") && !User.isSitting)) { if (User.Statusses.ContainsKey("lay")) User.Statusses.Remove("lay"); if (User.Statusses.ContainsKey("sit")) User.Statusses.Remove("sit"); User.UpdateNeeded = true; } else if (User.isLying || User.isSitting) return; double newZ; List<Item> ItemsOnSquare = _room.GetGameMap().GetAllRoomItemForSquare(User.X, User.Y); if (ItemsOnSquare != null || ItemsOnSquare.Count != 0) { if (User.RidingHorse && User.IsPet == false) newZ = _room.GetGameMap().SqAbsoluteHeight(User.X, User.Y, ItemsOnSquare.ToList()) + 1; else newZ = _room.GetGameMap().SqAbsoluteHeight(User.X, User.Y, ItemsOnSquare.ToList()); } else { newZ = 1; } if (newZ != User.Z) { User.Z = newZ; User.UpdateNeeded = true; } DynamicRoomModel Model = _room.GetGameMap().Model; if (Model.SqState[User.X, User.Y] == SquareState.SEAT) { if (!User.Statusses.ContainsKey("sit")) User.Statusses.Add("sit", "1.0"); User.Z = Model.SqFloorHeight[User.X, User.Y]; User.RotHead = Model.SqSeatRot[User.X, User.Y]; User.RotBody = Model.SqSeatRot[User.X, User.Y]; User.UpdateNeeded = true; } if (ItemsOnSquare.Count == 0) User.LastItem = null; foreach (Item Item in ItemsOnSquare.ToList()) { if (Item == null) continue; if (Item.GetBaseItem().IsSeat) { if (!User.Statusses.ContainsKey("sit")) { if (!User.Statusses.ContainsKey("sit")) User.Statusses.Add("sit", TextHandling.GetString(Item.GetBaseItem().Height)); } User.Z = Item.GetZ; User.RotHead = Item.Rotation; User.RotBody = Item.Rotation; User.UpdateNeeded = true; } switch (Item.GetBaseItem().InteractionType) { #region Beds & Tents case InteractionType.BED: case InteractionType.TENT_SMALL: { if (!User.Statusses.ContainsKey("lay")) User.Statusses.Add("lay", TextHandling.GetString(Item.GetBaseItem().Height) + " null"); User.Z = Item.GetZ; User.RotHead = Item.Rotation; User.RotBody = Item.Rotation; User.UpdateNeeded = true; break; } #endregion #region Banzai Gates case InteractionType.banzaigategreen: case InteractionType.banzaigateblue: case InteractionType.banzaigatered: case InteractionType.banzaigateyellow: { if (cyclegameitems) { int effectID = Convert.ToInt32(Item.team + 32); TeamManager t = User.GetClient().GetHabbo().CurrentRoom.GetTeamManagerForBanzai(); if (User.Team == TEAM.NONE) { if (t.CanEnterOnTeam(Item.team)) { if (User.Team != TEAM.NONE) t.OnUserLeave(User); User.Team = Item.team; t.AddUser(User); if (User.GetClient().GetHabbo().Effects().CurrentEffect != effectID) User.GetClient().GetHabbo().Effects().ApplyEffect(effectID); } } else if (User.Team != TEAM.NONE && User.Team != Item.team) { t.OnUserLeave(User); User.Team = TEAM.NONE; User.GetClient().GetHabbo().Effects().ApplyEffect(0); } else { //usersOnTeam--; t.OnUserLeave(User); if (User.GetClient().GetHabbo().Effects().CurrentEffect == effectID) User.GetClient().GetHabbo().Effects().ApplyEffect(0); User.Team = TEAM.NONE; } //Item.ExtraData = usersOnTeam.ToString(); //Item.UpdateState(false, true); } break; } #endregion #region Freeze Gates case InteractionType.FREEZE_YELLOW_GATE: case InteractionType.FREEZE_RED_GATE: case InteractionType.FREEZE_GREEN_GATE: case InteractionType.FREEZE_BLUE_GATE: { if (cyclegameitems) { int effectID = Convert.ToInt32(Item.team + 39); TeamManager t = User.GetClient().GetHabbo().CurrentRoom.GetTeamManagerForFreeze(); if (User.Team == TEAM.NONE) { if (t.CanEnterOnTeam(Item.team)) { if (User.Team != TEAM.NONE) t.OnUserLeave(User); User.Team = Item.team; t.AddUser(User); if (User.GetClient().GetHabbo().Effects().CurrentEffect != effectID) User.GetClient().GetHabbo().Effects().ApplyEffect(effectID); } } else if (User.Team != TEAM.NONE && User.Team != Item.team) { t.OnUserLeave(User); User.Team = TEAM.NONE; User.GetClient().GetHabbo().Effects().ApplyEffect(0); } else { //usersOnTeam--; t.OnUserLeave(User); if (User.GetClient().GetHabbo().Effects().CurrentEffect == effectID) User.GetClient().GetHabbo().Effects().ApplyEffect(0); User.Team = TEAM.NONE; } //Item.ExtraData = usersOnTeam.ToString(); //Item.UpdateState(false, true); } break; } #endregion #region Banzai Teles case InteractionType.banzaitele: { if (User.Statusses.ContainsKey("mv")) _room.GetGameItemHandler().onTeleportRoomUserEnter(User, Item); break; } #endregion #region Football Gate #endregion #region Effects case InteractionType.EFFECT: { if (User == null) return; if (!User.IsBot) { if (Item == null || Item.GetBaseItem() == null || User.GetClient() == null || User.GetClient().GetHabbo() == null || User.GetClient().GetHabbo().Effects() == null) return; if (Item.GetBaseItem().EffectId == 0 && User.GetClient().GetHabbo().Effects().CurrentEffect == 0) return; User.GetClient().GetHabbo().Effects().ApplyEffect(Item.GetBaseItem().EffectId); Item.ExtraData = "1"; Item.UpdateState(false, true); Item.RequestUpdate(2, true); } break; } #endregion #region Arrows case InteractionType.ARROW: { if (User.GoalX == Item.GetX && User.GoalY == Item.GetY) { if (User == null || User.GetClient() == null || User.GetClient().GetHabbo() == null) continue; Room Room; if (!PlusEnvironment.GetGame().GetRoomManager().TryGetRoom(User.GetClient().GetHabbo().CurrentRoomId, out Room)) return; if (!ItemTeleporterFinder.IsTeleLinked(Item.Id, Room)) User.UnlockWalking(); else { int LinkedTele = ItemTeleporterFinder.GetLinkedTele(Item.Id, Room); int TeleRoomId = ItemTeleporterFinder.GetTeleRoomId(LinkedTele, Room); if (TeleRoomId == Room.RoomId) { Item TargetItem = Room.GetRoomItemHandler().GetItem(LinkedTele); if (TargetItem == null) { if (User.GetClient() != null) User.GetClient().SendWhisper("Hey, that arrow is poorly!"); return; } else { Room.GetGameMap().TeleportToItem(User, TargetItem); } } else if (TeleRoomId != Room.RoomId) { if (User != null && !User.IsBot && User.GetClient() != null && User.GetClient().GetHabbo() != null) { User.GetClient().GetHabbo().IsTeleporting = true; User.GetClient().GetHabbo().TeleportingRoomID = TeleRoomId; User.GetClient().GetHabbo().TeleporterId = LinkedTele; User.GetClient().GetHabbo().PrepareRoom(TeleRoomId, ""); } } else if (this._room.GetRoomItemHandler().GetItem(LinkedTele) != null) { User.SetPos(Item.GetX, Item.GetY, Item.GetZ); User.SetRot(Item.Rotation, false); } else User.UnlockWalking(); } } break; } #endregion } } if (User.isSitting && User.TeleportEnabled) { User.Z -= 0.35; User.UpdateNeeded = true; } if (cyclegameitems) { if (_room.GotSoccer()) _room.GetSoccer().OnUserWalk(User); if (_room.GotBanzai()) _room.GetBanzai().OnUserWalk(User); if (_room.GotFreeze()) _room.GetFreeze().OnUserWalk(User); } } catch (Exception e) { Logging.LogException(e.ToString()); } }
public RoomUser DeployBot(RoomBot Bot, Pet PetData) { var BotUser = new RoomUser(0, _room.RoomId, primaryPrivateUserID++, _room); Bot.VirtualId = primaryPrivateUserID; int PersonalID = secondaryPrivateUserID++; BotUser.InternalRoomID = PersonalID; _users.TryAdd(PersonalID, BotUser); DynamicRoomModel Model = _room.GetGameMap().Model; if ((Bot.X > 0 && Bot.Y > 0) && Bot.X < Model.MapSizeX && Bot.Y < Model.MapSizeY) { BotUser.SetPos(Bot.X, Bot.Y, Bot.Z); BotUser.SetRot(Bot.Rot, false); } else { Bot.X = Model.DoorX; Bot.Y = Model.DoorY; BotUser.SetPos(Model.DoorX, Model.DoorY, Model.DoorZ); BotUser.SetRot(Model.DoorOrientation, false); } BotUser.BotData = Bot; BotUser.BotAI = Bot.GenerateBotAI(BotUser.VirtualId); if (BotUser.IsPet) { BotUser.BotAI.Init(Bot.BotId, BotUser.VirtualId, _room.RoomId, BotUser, _room); BotUser.PetData = PetData; BotUser.PetData.VirtualId = BotUser.VirtualId; } else BotUser.BotAI.Init(Bot.BotId, BotUser.VirtualId, _room.RoomId, BotUser, _room); //UpdateUserStatus(BotUser, false); BotUser.UpdateNeeded = true; _room.SendMessage(new UsersComposer(BotUser)); if (BotUser.IsPet) { if (_pets.ContainsKey(BotUser.PetData.PetId)) //Pet allready placed _pets[BotUser.PetData.PetId] = BotUser; else _pets.TryAdd(BotUser.PetData.PetId, BotUser); petCount++; } else if (BotUser.IsBot) { if (_bots.ContainsKey(BotUser.BotData.BotId)) _bots[BotUser.BotData.BotId] = BotUser; else _bots.TryAdd(BotUser.BotData.Id, BotUser); _room.SendMessage(new DanceComposer(BotUser, BotUser.BotData.DanceId)); } return BotUser; }