private FurniInfo ProcessDataRow(DataRow dRow) { FurniInfo info = new FurniInfo(); info.FurniID = int.Parse(dRow["FurniID"].ToString()); info.RoomID = int.Parse(dRow["RoomID"].ToString()); info.FurniDefinitionID = int.Parse(dRow["FurniDefinitionID"].ToString()); info.PosX = int.Parse(dRow["PosX"].ToString()); info.PosY = int.Parse(dRow["PosY"].ToString()); info.PosZ = float.Parse(dRow["PosZ"].ToString()); info.W = int.Parse(dRow["W"].ToString()); info.L = int.Parse(dRow["L"].ToString()); info.Col = dRow["Col"].ToString(); info.PosRotation = int.Parse(dRow["PosRotation"].ToString()); info.OwnerID = int.Parse(dRow["OwnerID"].ToString()); info.FurniSprite = dRow["Sprite"].ToString(); info.FurniFlags = dRow["Flags"].ToString(); info.FurniVar = dRow["FurniVar"].ToString(); info.HeightOffset = float.Parse(dRow["HeightOffset"].ToString()); info.HandType = dRow["HandType"].ToString(); info.WallLocation = dRow["WallLocation"].ToString(); info.VarType = (FurniInfo.VarTypes) int.Parse(dRow["VarType"].ToString()); info.FurniName = GetItemName(info.Flags.WallItem, info.FurniSprite, info.Col); info.FurniDesc = GetItemDesc(info.Flags.WallItem, info.FurniSprite, info.Col); info.TeleportId = (int)dRow["TeleportId"]; info.FurniTypeId = (int)dRow["FurniTypeID"]; info.ActionHeight = float.Parse(dRow["ActionHeight"].ToString()); info.CanTrade = (bool)dRow["CanTrade"]; info.PublicFurni = (bool)dRow["PublicFurni"]; info.ProcessFlags(); return(info); }
private string BuildTradeList(List <int> ids) { int counter = 0; StringBuilder sb = new StringBuilder(); foreach (int itemId in ids) { FurniInfo info = InstanceManager.Game.Furni.GetFurni(itemId); sb.Append("SI"); sb.Append(Convert.ToChar(30)); sb.Append(info.FurniID); sb.Append(Convert.ToChar(30)); sb.Append(counter); sb.Append(Convert.ToChar(30)); if (info.Flags.WallItem) { sb.Append("I"); } if (!info.Flags.WallItem) { sb.Append("S"); } sb.Append(Convert.ToChar(30)); sb.Append(info.FurniID); sb.Append(Convert.ToChar(30)); sb.Append(info.FurniSprite); sb.Append(Convert.ToChar(30)); if (!info.Flags.WallItem) { sb.Append(info.L); sb.Append(Convert.ToChar(30)); sb.Append(info.W); sb.Append(Convert.ToChar(30)); sb.Append(info.FurniVar); sb.Append(Convert.ToChar(30)); } sb.Append(info.Col); sb.Append(Convert.ToChar(30)); sb.Append(counter); sb.Append(Convert.ToChar(30)); sb.Append("/"); counter++; } return(sb.ToString()); }
//72 - "TRADE_ADDITEM": "AH" public void Listener72() { int roomId = InstanceManager.Sessions.GetSession(mSessionID).mRoomID; int itemId = 0; if (roomId > 0) { if (int.TryParse(mPacketBody, out itemId)) { RoomInstance instance = InstanceManager.Game.Rooms.GetRoomInstance(roomId); RoomUser thisUser = instance.GetUser(mSessionID); if (thisUser.SpecialStates.ContainsKey("trd")) { RoomUser targetUser = instance.GetUser(thisUser.TradingWith); if (InstanceManager.Game.Furni.FurniExists(itemId)) { FurniInfo furni = InstanceManager.Game.Furni.GetFurni(itemId); if (furni.CanTrade) { if (furni.OwnerID == thisUser.UserInfo.userId && furni.RoomID == 0) { if (!thisUser.TradeOffer.Contains(furni.FurniID)) { thisUser.TradeAccepted = false; targetUser.TradeAccepted = false; thisUser.TradeOffer.Add(furni.FurniID); RefreshTrades(thisUser.SessionID, targetUser.SessionID); } } } else { mMessage.Init(139); //BK mMessage.appendString(InstanceManager.Game.Externals.GetTextValue("room_cant_trade")); InstanceManager.Sessions.GetSession(thisUser.SessionID).SendMessage(mMessage); } } } } } }
public List <FurniInfo> GetRoomWallFurni(int roomId) { Database db = new Database(); db.sqlexecute.Parameters.AddWithValue("@roomid", roomId); DataTable dt = db.GetDataSet("SELECT * FROM Furni JOIN FurniDefinitions ON Furni.FurniTypeID = FurniDefinitions.FurniDefinitionID WHERE RoomID = @roomid").Tables[0]; db.sqlexecute.Parameters.Clear(); List <FurniInfo> results = new List <FurniInfo>(); foreach (DataRow dRow in dt.Rows) { FurniInfo info = ProcessDataRow(dRow); if (info.Flags.WallItem) { results.Add(info); } } return(results); }
private string ProcessWallFurniDefinition(FurniInfo wallItem) { StringBuilder sb = new StringBuilder(); sb.Append(wallItem.FurniID.ToString()); sb.Append(Convert.ToChar(9)); sb.Append(wallItem.FurniSprite); sb.Append(Convert.ToChar(9)); sb.Append(" "); sb.Append(Convert.ToChar(9)); sb.Append(wallItem.WallLocation); sb.Append(Convert.ToChar(9)); sb.Append(wallItem.Col); return sb.ToString(); }
private void ProcessTeleporter(FurniInfo Teleporter1, RoomUser user) { FurniInfo Teleporter2 = null; Point invalidPoint = new Point(Teleporter1.PosX, Teleporter1.PosY); if (Teleporter1.PosRotation == 0 || Teleporter1.PosRotation == 2) invalidPoint.X++; if (Teleporter1.PosRotation == 4) invalidPoint.Y++; if (InstanceManager.Game.Furni.FurniExists(Teleporter1.TeleportId)) { Teleporter2 = InstanceManager.Game.Furni.GetFurni(Teleporter1.TeleportId); } if (!user.UserLocked) { user.UserLocked = true; Thread.Sleep(1000); if (Teleporter1.PosX == user.CurrentX && Teleporter1.PosY == user.CurrentY) { ClientMessage message = new ClientMessage(); if (Teleporter2 != null && Teleporter2.RoomID > 0 && Teleporter1.Flags.IsTeleport && Teleporter2.Flags.IsTeleport) { message.Init(89); //AY message.appendInt(Teleporter1.FurniID); message.appendString("/"); message.appendString(user.UserInfo.sUsername); message.appendString("/"); message.appendString(Teleporter1.FurniSprite); mRoomInstance.RoomBroadcast(message); if (Teleporter2.RoomID == Teleporter1.RoomID) //Same room { Thread.Sleep(2000); Teleporter2 = InstanceManager.Game.Furni.GetFurni(Teleporter1.TeleportId); Teleporter1 = InstanceManager.Game.Furni.GetFurni(Teleporter1.FurniID); if (Teleporter2.RoomID == Teleporter1.RoomID && Teleporter1.PosX == user.CurrentX && Teleporter1.PosY == user.CurrentY) { message.Init(92); //A\ message.appendInt(Teleporter2.FurniID); message.appendString("/"); message.appendString(user.UserInfo.sUsername); message.appendString("/"); message.appendString(Teleporter2.FurniSprite); mRoomInstance.RoomBroadcast(message); mPlayerMap[user.CurrentX, user.CurrentY] = false; user.CurrentX = Teleporter2.PosX; user.CurrentY = Teleporter2.PosY; user.CurrentZ = Teleporter2.PosZ; mRoomInstance.AnnounceUserStatus(user.SessionID, true); mPlayerMap[user.CurrentX, user.CurrentY] = true; user.UserLocked = false; } else { if (Teleporter1.PosX == user.CurrentX && Teleporter1.PosY == user.CurrentY) { RequestSetStuffDataFloorItem(Teleporter1.FurniID, "TRUE", user, FurniInfo.VarTypes.TempOpen); RequestMovePlayer(user.SessionID, invalidPoint.X, invalidPoint.Y, null, true); } user.UserLocked = false; } } else //In another room { InstanceManager.Sessions.GetSession(user.SessionID).authenticatedDoor = Teleporter2.FurniID; InstanceManager.Sessions.GetSession(user.SessionID).authenticatedFlat = Teleporter2.RoomID; message.Init(62); //@~ message.appendArgumentInt(Teleporter2.FurniID); message.appendArgumentInt(Teleporter2.RoomID); mRoomInstance.SendMessage(message, user.SessionID); } } else //No linked teleporter exists { Thread.Sleep(700); RequestSetStuffDataFloorItem(Teleporter1.FurniID, "TRUE", user, FurniInfo.VarTypes.TempOpen); RequestMovePlayer(user.SessionID, invalidPoint.X, invalidPoint.Y, null, true); user.UserLocked = false; } } } }
private string ProcessFloorObjectDefinition(FurniInfo info) { StringBuilder sb = new StringBuilder(); sb.Append(info.FurniID.ToString()); sb.Append(" "); sb.Append(info.FurniSprite); sb.Append(" "); sb.Append(info.PosX); sb.Append(" "); sb.Append(info.PosY); sb.Append(" "); sb.Append(info.PosZ); sb.Append(" "); sb.Append(info.PosRotation); sb.Append(Convert.ToChar(13).ToString()); return sb.ToString(); }
private string ProcessFloorFurniDefinition(FurniInfo info) { StringBuilder sb = new StringBuilder(); sb.Append(info.FurniID); sb.Append(Convert.ToChar(2)); sb.Append(info.FurniSprite); sb.Append(Convert.ToChar(2)); sb.Append(ArgumentEncoding.encodeInt(info.PosX)); sb.Append(ArgumentEncoding.encodeInt(info.PosY)); sb.Append(ArgumentEncoding.encodeInt(info.W)); sb.Append(ArgumentEncoding.encodeInt(info.L)); sb.Append(ArgumentEncoding.encodeInt(info.PosRotation)); sb.Append(info.PosZ.ToString().Replace(',', '.')); sb.Append(Convert.ToChar(2)); sb.Append(info.Col); sb.Append(Convert.ToChar(2)); sb.Append(Convert.ToChar(2)); sb.Append(ArgumentEncoding.encodeInt(info.TeleportId)); sb.Append(info.FurniVar); sb.Append(Convert.ToChar(2)); return sb.ToString(); }
private int FindTileOffset(FurniInfo info, int x, int y) { Dictionary<int, AffectedTile> pointList = GetAffectedTiles(info); foreach (int tileOffset in pointList.Keys) { if (pointList[tileOffset].X == x && pointList[tileOffset].Y == y) { return pointList[tileOffset].I; } } return -1; }
private bool ExecuteFloorMoveItem(FurniInfo item, int itemId, int newX, int newY, int newRot, bool firstTime, long sessionId) { int furniCount = 0; int rollerCount = 0; //Work out new affectedTiles Dictionary<int, AffectedTile> affectedTiles = GetAffectedTiles(item.L, item.W, newX, newY, newRot); //Verify the new tiles exist if (!ValidTile(item.PosX, item.PosY)) return false; foreach (AffectedTile tile in affectedTiles.Values) { if (!ValidTile(tile.X, tile.Y)) return false; } //Verify the user has rights, or owns the item if they are dropping it if (firstTime && item.OwnerID != mRoomInstance.GetUser(sessionId).UserInfo.userId) return false; if (!firstTime && item.RoomID != mRoomInstance.RoomInfo.RoomID) return false; //Verify if it's the first time and not the users room, the item is tradeable if (firstTime && mRoomInstance.RoomInfo.RoomOwner != mRoomInstance.GetUser(sessionId).UserInfo.userId && item.CanTrade == false) return false; //Calculate the new height according to the heightmap float newZ = mHeightMap[newX, newY]; //Is the item trying to stack on itself? if (item.PosRotation == newRot && item.PosX == newX && item.PosY == newY && item.PosZ != newZ) return false; //Check it's not a bad heightmap tile if (mClientMap[newX, newY] == "x") return false; foreach (AffectedTile tile in affectedTiles.Values) { if (mClientMap[tile.X, tile.Y] == "x") return false; } //Check for players if (mPlayerMap[newX, newY] && !(item.PosRotation != newRot && item.PosX == newX && item.PosY == newY)) return false; foreach (AffectedTile tile in affectedTiles.Values) { if (mPlayerMap[tile.X, tile.Y]) return false; } //Get the furniture counts (not including this item) foreach (FurniInfo tmp in mFloorFurni) { furniCount++; if (tmp.Flags.IsRoller) rollerCount++; } //Get the affected objects List<FurniInfo> objectsOnTile = GetFurniObjects(newX, newY); List<FurniInfo> objectsAffected = new List<FurniInfo>(); List<FurniInfo> objectsComplete = new List<FurniInfo>(); foreach (AffectedTile tile in affectedTiles.Values) { List<FurniInfo> objectsTmp = GetFurniObjects(tile.X, tile.Y); if (objectsTmp != null) { objectsAffected.AddRange(objectsTmp); } } //Check the item isn't a roller and furni exists if (objectsComplete.Count > 0 && item.Flags.IsRoller) return false; if (objectsOnTile == null) objectsOnTile = new List<FurniInfo>(); objectsComplete.AddRange(objectsOnTile); if (objectsAffected == null) objectsAffected = new List<FurniInfo>(); objectsComplete.AddRange(objectsAffected); //Check you can stack the item if (objectsComplete.Count > 0 && !item.Flags.CanStack) return false; //Check for nonstackable items and rollers foreach (FurniInfo info in objectsComplete) { if (!info.Flags.CanStackOn || (info.Flags.IsRoller && (item.W > 1 || item.L > 1))) return false; } //Rotating the item, should remain at the same height for now if (item.PosRotation != newRot && item.PosX == newX && item.PosY == newY) newZ = item.PosZ; //Are any of the other tiles higher? foreach (FurniInfo info in objectsAffected) { if (info.TotalHeight > newZ) newZ = info.TotalHeight; } //Impose stacking limit if (newZ > MaxStackHeight) { newZ = MaxStackHeight; } //Impose furni limit if (furniCount >= 125 && firstTime) { ClientMessage mMessage = new ClientMessage(); mMessage.Init(139); //BK mMessage.appendString(InstanceManager.Game.Externals.GetTextValue("room_alert_furni_limit")); mRoomInstance.SendMessage(mMessage, sessionId); return false; } //Impose roller limit if (item.Flags.IsRoller) { if (rollerCount >= 10 && firstTime) { ClientMessage mMessage = new ClientMessage(); mMessage.Init(139); //BK mMessage.appendString(InstanceManager.Game.Externals.GetTextValue("queue_tile_limit")); mRoomInstance.SendMessage(mMessage, sessionId); return false; } } //Ensure it's a valid rotation if (newRot != 0 && newRot != 2 && newRot != 4 && newRot != 6 && newRot != 8) newRot = 0; //Move the item int oldX = item.PosX; int oldY = item.PosY; affectedTiles = GetAffectedTiles(item); InstanceManager.Game.Furni.MoveFloorItem(itemId, newX, newY, newZ, newRot, mRoomInstance.RoomInfo); mFloorFurni = InstanceManager.Game.Furni.GetRoomFloorFurni(mRoomInstance.RoomInfo.RoomID); GenerateMaps(); // Remove statuses on users affected by this item UpdateChangedUsers(oldX, oldY); foreach (AffectedTile affectedTile in affectedTiles.Values) { UpdateChangedUsers(affectedTile.X, affectedTile.Y); } return true; }
public void RequestSetStuffDataFloorItem(int itemId, string data, RoomUser user, FurniInfo.VarTypes overrideType) { FurniInfo item = GetFurniObject(itemId); ClientMessage mMessage = new ClientMessage(); if (item != null) { if (overrideType != 0) item.VarType = overrideType; switch (item.VarType) { case FurniInfo.VarTypes.TempOpen: if (TilesTouching(item.PosX, item.PosY, user.CurrentX, user.CurrentY)) { InstanceManager.Game.Furni.SetStuffDataFloorItem(itemId, "FALSE"); if (data == "TRUE") NotifyClientSetStuffTempOpen(itemId); } break; case FurniInfo.VarTypes.TrueFalse: if (TilesTouching(item.PosX, item.PosY, user.CurrentX, user.CurrentY)) { if ((data == "TRUE" || data == "FALSE")) { InstanceManager.Game.Furni.SetStuffDataFloorItem(itemId, data); NotifyClientSetStuffChange(itemId, data); } } break; case FurniInfo.VarTypes.DoorDivider: if (user.HasAdmin || user.HasRights) { if (data == "O" || data == "C") { if (!PlayerCheck(item.PosX, item.PosY)) { InstanceManager.Game.Furni.SetStuffDataFloorItem(itemId, data); NotifyClientSetStuffChange(itemId, data); mFloorFurni = InstanceManager.Game.Furni.GetRoomFloorFurni(mRoomInstance.RoomInfo.RoomID); GenerateMaps(); } } } break; case FurniInfo.VarTypes.Dice: if (TilesTouching(item.PosX, item.PosY, user.CurrentX, user.CurrentY)) { if (data == "dice_roll" || data == "dice_off") { int newVal = 0; if (data == "dice_roll") newVal = SpecialMath.RandomNumber(1, 6); bool isRoll = newVal > 0; int rollVal = (item.FurniID * 38) + newVal; InstanceManager.Game.Furni.SetStuffDataFloorItem(itemId, newVal.ToString()); NotifyClientDiceRoll(item.FurniID, rollVal, isRoll); } } break; case FurniInfo.VarTypes.Bottle: if (data == "dice_roll") { int newVal = SpecialMath.RandomNumber(0, 7); bool isRoll = newVal > 0; int rollVal = (item.FurniID * 38) + newVal; InstanceManager.Game.Furni.SetStuffDataFloorItem(itemId, newVal.ToString()); NotifyClientDiceRoll(item.FurniID, rollVal, isRoll); } break; case FurniInfo.VarTypes.OnOff: if (data == "ON" || data == "OFF") { InstanceManager.Game.Furni.SetStuffDataFloorItem(itemId, data); NotifyClientSetStuffChange(itemId, data); } break; case FurniInfo.VarTypes.OpenOrClosed: if (data == "O" || data == "C") { InstanceManager.Game.Furni.SetStuffDataFloorItem(itemId, data); NotifyClientSetStuffChange(itemId, data); } break; case FurniInfo.VarTypes.NumericalOff: int tmpNum = -1; if (int.TryParse(data, out tmpNum) || data == "OFF") { if (tmpNum >= -1 && tmpNum < 10 && !(tmpNum == -1 && data == "-1")) { InstanceManager.Game.Furni.SetStuffDataFloorItem(itemId, data); NotifyClientSetStuffChange(itemId, data); } } break; } } }
private void SendHandInfo() { List <FurniInfo> furniInfo = InstanceManager.Game.Furni.GetHandFurniList(mUserInfo.userId); StringBuilder sb = new StringBuilder(); int startId = 0; int endId = furniInfo.Count; if (furniInfo.Count > 0) { startId = mHandPage * 9; if (endId > (startId + 9)) { endId = startId + 9; } if (startId > endId || startId == endId) { mHandPage--; SendHandInfo(); return; } sb.Append("SI"); for (int i = startId; i < endId; i++) { FurniInfo info = furniInfo[i]; if (!info.Flags.WallItem) //Floor Item { sb.Append(Convert.ToChar(30)); sb.Append(info.FurniID.ToString()); sb.Append(Convert.ToChar(30)); sb.Append(i.ToString()); sb.Append(Convert.ToChar(30)); sb.Append(info.HandType); sb.Append(Convert.ToChar(30)); sb.Append(info.FurniID); sb.Append(Convert.ToChar(30)); sb.Append(info.FurniSprite); sb.Append(Convert.ToChar(30)); sb.Append(info.W); sb.Append(Convert.ToChar(30)); sb.Append(info.L); sb.Append(Convert.ToChar(30)); sb.Append(info.Col); sb.Append("/"); } else //Wall item { sb.Append(Convert.ToChar(30)); sb.Append(info.FurniID.ToString()); sb.Append(Convert.ToChar(30)); sb.Append(i.ToString()); sb.Append(Convert.ToChar(30)); sb.Append(info.HandType); sb.Append(Convert.ToChar(30)); sb.Append(info.FurniID.ToString()); sb.Append(Convert.ToChar(30)); sb.Append(info.FurniSprite); sb.Append(Convert.ToChar(30)); if (info.Flags.StickyNote || info.Flags.Decoration) { sb.Append(info.FurniVar); } else { sb.Append(info.Col); } sb.Append("/"); } } } mMessage.Init(140); //BL mMessage.appendString(sb.ToString()); mMessage.appendChar(13); mMessage.appendInt(furniInfo.Count); SendMessage(mMessage); }
private Dictionary<int, AffectedTile> GetAffectedTiles(FurniInfo info) { return GetAffectedTiles(info.L, info.W, info.PosX, info.PosY, info.PosRotation); }
private void UpdateRollerFurni(FurniInfo info, int nextX, int nextY, float nextZ, bool isLastRoller, int rollerId) { ClientMessage mMessage = new ClientMessage(); mMessage.Init(230); // Cf mMessage.appendArgumentInt(info.PosX); mMessage.appendArgumentInt(info.PosY); mMessage.appendArgumentInt(nextX); mMessage.appendArgumentInt(nextY); mMessage.appendArgumentInt(1); mMessage.appendArgumentInt(info.FurniID); mMessage.appendString(info.PosZ.ToString().Replace(',', '.')); mMessage.appendChar(2); mMessage.appendString(nextZ.ToString().Replace(',', '.')); mMessage.appendChar(2); mMessage.appendArgumentInt(rollerId); mRollerBroadcast.Append(mMessage.ToString()); info.PosX = nextX; info.PosY = nextY; info.PosZ = nextZ; InstanceManager.Game.Furni.MoveFloorItem(info.FurniID, info.PosX, info.PosY, info.PosZ, info.PosRotation, mRoomInstance.RoomInfo); }
private FurniInfo ProcessDataRow(DataRow dRow) { FurniInfo info = new FurniInfo(); info.FurniID = int.Parse(dRow["FurniID"].ToString()); info.RoomID = int.Parse(dRow["RoomID"].ToString()); info.FurniDefinitionID= int.Parse(dRow["FurniDefinitionID"].ToString()); info.PosX = int.Parse(dRow["PosX"].ToString()); info.PosY = int.Parse(dRow["PosY"].ToString()); info.PosZ = float.Parse(dRow["PosZ"].ToString()); info.W = int.Parse(dRow["W"].ToString()); info.L = int.Parse(dRow["L"].ToString()); info.Col = dRow["Col"].ToString(); info.PosRotation = int.Parse(dRow["PosRotation"].ToString()); info.OwnerID = int.Parse(dRow["OwnerID"].ToString()); info.FurniSprite = dRow["Sprite"].ToString(); info.FurniFlags = dRow["Flags"].ToString(); info.FurniVar = dRow["FurniVar"].ToString(); info.HeightOffset = float.Parse(dRow["HeightOffset"].ToString()); info.HandType = dRow["HandType"].ToString(); info.WallLocation = dRow["WallLocation"].ToString(); info.VarType = (FurniInfo.VarTypes) int.Parse(dRow["VarType"].ToString()); info.FurniName = GetItemName(info.Flags.WallItem, info.FurniSprite, info.Col); info.FurniDesc = GetItemDesc(info.Flags.WallItem, info.FurniSprite, info.Col); info.TeleportId = (int)dRow["TeleportId"]; info.FurniTypeId = (int)dRow["FurniTypeID"]; info.ActionHeight = float.Parse(dRow["ActionHeight"].ToString()); info.CanTrade = (bool)dRow["CanTrade"]; info.PublicFurni = (bool)dRow["PublicFurni"]; info.ProcessFlags(); return info; }