public stripItem createPresent(int receivingUserID, string saleCode, string Note, string customData) { int definitionID = ObjectTree.Game.Items.getRandomPresentBoxDefinitionID(); if (definitionID != 1) { stripItem presentBoxItem = ObjectTree.Game.Items.createItemInstance(definitionID, receivingUserID, "!" + Note); Database dbClient = new Database(false, true); dbClient.addParameterWithValue("itemid", presentBoxItem.ID); dbClient.addParameterWithValue("salecode", saleCode); if (customData == "") { dbClient.addParameterWithValue("customdata", DBNull.Value); } else { dbClient.addParameterWithValue("customdata", customData); } dbClient.Open(); if (dbClient.Ready) { dbClient.runQuery("INSERT INTO items_presents VALUES (@itemid,@salecode,@customdata)"); } return(presentBoxItem); } else { Logging.Log("Failed to create presentbox for sale '" + saleCode + "', one of the present box definitions is missing!", Logging.logType.commonError); return(null); } }
/// <summary> /// Places a wall item in the room and makes it visible for all clients, and returns a boolean that holds true if the operation has succeeded. /// </summary> /// <param name="handItemInstance">The stripItem instance of the wall item that is being placed down.</param> /// <param name="Position">The new position of the wall item as a string.</param> public bool placeWallItem(stripItem handItemInstance, string Position) { if (this.containsWallItem(handItemInstance.ID)) { return(false); } wallItem pItem = new wallItem(); pItem.ID = handItemInstance.ID; pItem.roomID = this.roomID; pItem.ownerID = handItemInstance.ownerID; pItem.Definition = handItemInstance.Definition; pItem.customData = handItemInstance.customData; pItem.wallPosition = Position; if (handItemInstance.Definition.Behaviour.isPostIt) // New post.it, set blank message data { pItem.postItMessage = String.Empty; } this.broadcoastWallItemPlacement(pItem); this.wallItems.Add(pItem); pItem.Update(); // Save position return(true); }
/// <summary> /// 66 - "AB" /// </summary> public void FLATPROPBYITEM() { if (Session.roomInstance.sessionHasRights(Session.ID)) // Permission { int itemID = int.Parse(Request.Content.Split('/')[1]); stripItem pItem = Session.itemStripHandler.getHandItem(itemID); if (pItem != null && pItem.Definition.Behaviour.isDecoration) { Session.itemStripHandler.removeHandItem(itemID, true); int decorationValue = int.Parse(pItem.customData); if (pItem.Definition.Sprite == "wallpaper") { Session.roomInstance.Information.Wallpaper = decorationValue; } else // Floor { Session.roomInstance.Information.Floor = decorationValue; } serverMessage msgUpdate = new serverMessage(46); // "@n" msgUpdate.Append(pItem.Definition.Sprite); msgUpdate.Append("/"); msgUpdate.Append(decorationValue); Session.roomInstance.sendMessage(msgUpdate); Session.roomInstance.Information.updateFlatProperties(); } } }
/// <summary> /// 90 - "AZ" /// </summary> public void PLACESTUFF() { if (Session.roomInstance.sessionHasRights(Session.ID)) { int itemID = int.Parse(Request.Content.Split(' ')[0]); stripItem pItem = Session.itemStripHandler.getHandItem(itemID); if (pItem == null) // Item not in hand { return; } bool Success = false; if (pItem.Definition.Behaviour.isWallItem) { if (pItem.Definition.Behaviour.isDecoration) // Can't place down decoration items (floor and wallpaper) { return; } string wallPosition = Request.Content.Substring(itemID.ToString().Length + 1); ObjectTree.Game.Items.correctWallItemPosition(ref wallPosition); if (wallPosition == null) // Invalid wall position { return; } if (pItem.Definition.Behaviour.isPostIt) // Sticky pad { int padSize = int.Parse(pItem.customData) - 1; if (padSize <= 0) // Pad is empty now, remove and delete { Session.itemStripHandler.removeHandItem(pItem.ID, true); } else // Decrease pad size { pItem.customData = padSize.ToString(); ObjectTree.Game.Items.setItemCustomData(pItem.ID, pItem.customData); } pItem = ObjectTree.Game.Items.createItemInstance(pItem.Definition.ID, Session.roomInstance.Information.ownerID, "FFFF33"); } Success = Session.roomInstance.placeWallItem(pItem, wallPosition); } else { string[] locationData = Request.Content.Split(' '); byte X = byte.Parse(locationData[1]); byte Y = byte.Parse(locationData[2]); //byte Rotation = byte.Parse(locationData[3]); Success = Session.roomInstance.moveFloorItem(itemID, pItem, X, Y, 0); } if (Success && !pItem.Definition.Behaviour.isPostIt) { Session.itemStripHandler.removeHandItem(itemID, false); } } }
/// <summary> /// 72 - "AH" /// </summary> public void TRADE_ADDITEM() { if (Session.itemStripHandler.isTrading) { int itemID = int.Parse(Request.Content); stripItem pItem = Session.itemStripHandler.getHandItem(itemID); if (pItem != null && !Session.itemStripHandler.itemIsInTradeOffer(itemID)) // Item tradeable check here todo { Session.itemStripHandler.addItemToTradeOffer(itemID); Session.refreshTradeBoxes(); } } }
/// <summary> /// 67 - "AC" /// </summary> public void ADDSTRIPITEM() { if (Session.roomInstance.sessionHasFlatAdmin(Session.ID)) // Can pickup items { string[] removalData = Request.Content.Split(' '); int itemID = int.Parse(removalData[2]); stripItem returnItem = null; if (removalData[1] == "item") // Wall item { returnItem = Session.roomInstance.pickupWallItem(itemID, Session.User.ID); } else if (removalData[1] == "stuff") // Floor item { returnItem = Session.roomInstance.pickupFloorItem(itemID, Session.User.ID); } if (returnItem != null) // Successfully picked up to hand { Session.itemStripHandler.addHandItem(returnItem); Session.sendHandStrip("update"); } } }
public void requestSaleShipping(int receivingUserID, string saleCode, bool isNewPurchase, bool purchaseAsPresent, string presentNote, string customData) { storeCatalogueSale pSale = this.getSale(saleCode); if (pSale == null) { Logging.Log("Failed to purchase sale '" + saleCode + "' for user " + receivingUserID + ", the requested sale ('" + saleCode + "') was not found!", Logging.logType.commonWarning); return; } List <stripItem> shippedItems = new List <stripItem>(); if (purchaseAsPresent) { stripItem presentBox = this.createPresent(receivingUserID, saleCode, presentNote, customData); if (presentBox != null) { shippedItems.Add(presentBox); } else { return; } } else { int itemIdOffset = ObjectTree.Game.Items.getItemIdOffset(); foreach (stripItem lItem in pSale.getItemInstances()) { lItem.ID = ++itemIdOffset; lItem.ownerID = receivingUserID; #region Special events upon purchase if (lItem.Definition.Behaviour.isTeleporter) // Teleporter, create linking teleporter { stripItem Teleporter2 = new stripItem(); Teleporter2.ID = ++itemIdOffset; Teleporter2.ownerID = receivingUserID; Teleporter2.Definition = lItem.Definition; Teleporter2.teleporterID = lItem.ID; lItem.teleporterID = Teleporter2.ID; shippedItems.Add(Teleporter2); } else if (lItem.Definition.Behaviour.isPostIt) { lItem.customData = "20"; } else if (lItem.Definition.Behaviour.isDecoration || lItem.Definition.Behaviour.isPrizeTrophy) { lItem.customData = customData; } else if (lItem.Definition.Behaviour.isRedeemable) { int creditValue = 0; if (int.TryParse(lItem.Definition.Sprite.Split('_')[1], out creditValue)) { lItem.customData = creditValue.ToString(); } } else if (lItem.Definition.Sprite == "nest") { string[] petData = customData.Split(Convert.ToChar(2)); string Name = petData[0]; char Type = char.Parse(petData[1]); byte Race = byte.Parse(petData[2]); string Color = petData[3]; ObjectTree.Game.Items.createPet(lItem.ID, Name, Type, Race, Color); } #endregion shippedItems.Add(lItem); } ObjectTree.Game.Items.createItemInstances(shippedItems); } Session Receiver = ObjectTree.Game.Users.getUserSession(receivingUserID); if (Receiver != null) // Receiver was online { Receiver.itemStripHandler.addHandItems(shippedItems); serverMessage Notification = new serverMessage(); if (isNewPurchase) { Notification.Initialize(67); // "AC" } else #region Open as present box { stripItem displayItem = shippedItems[0]; Notification.Initialize(129); // "BA" Notification.appendNewLineValue(displayItem.Definition.Sprite); string displaySprite = displayItem.Definition.Sprite; //if (displayItem.Definition.isPartialSprite && displayItem.customData != null) // displaySprite += " " + displayItem.customData; Notification.appendNewLineValue(displaySprite); if (!displayItem.Definition.Behaviour.isWallItem) { Notification.appendStripValue(displayItem.Definition.Length.ToString()); Notification.appendStripValue(displayItem.Definition.Width.ToString()); Notification.appendStripValue(displayItem.Definition.Color); } } #endregion Receiver.gameConnection.sendMessage(Notification); } }
public bool moveFloorItem(int itemID, stripItem handItemInstance, byte newX, byte newY, byte newRotation) { bool isNewPlacement = (handItemInstance != null); floorItem pItem = null; if (isNewPlacement) { if (this.containsFloorItem(itemID)) // L o l w u t { return(false); } pItem = new floorItem(); pItem.ID = handItemInstance.ID; pItem.roomID = this.roomID; pItem.ownerID = this.Information.ownerID; pItem.Definition = handItemInstance.Definition; pItem.customData = handItemInstance.customData; pItem.teleporterID = handItemInstance.teleporterID; } else { pItem = this.getFloorItem(itemID); if (pItem == null) { return(false); } } Sessions.Session owner = Engine.Game.Users.getUserSession(pItem.ownerID); // Calculate new height float newZ = this.gridHeight[newX, newY]; // Trying to stack on itself? if (pItem.Rotation == newRotation && pItem.X == newX && pItem.Y == newY && pItem.Z != newZ) { if (owner != null && !owner.StackAnything) { return(false); } } // Get the tiles this item would reside on if this item was placed here, and verify if they exist Dictionary <int, roomTile> itemTiles = getAffectedTiles(pItem.Definition.Length, pItem.Definition.Width, newX, newY, newRotation, true); List <floorItem> itemsOnTile = getFloorItems(newX, newY); List <floorItem> itemsAffected = new List <floorItem>(); List <floorItem> itemsComplete = new List <floorItem>(); foreach (roomTile lTile in itemTiles.Values) { if (!this.tileExists(lTile.X, lTile.Y) || this.gridClientMap[lTile.X, lTile.Y] == 'x') { if (owner != null && !owner.StackAnything) { return(false); // Out of map range / invalid tile } } if (this.gridUnit[lTile.X, lTile.Y]) // Room unit on this tile { if (newRotation == pItem.Rotation && (lTile.X != pItem.X || lTile.Y != pItem.Y)) { if (owner != null && !owner.StackAnything) { return(false); // Can't rotate } } } List <floorItem> tileItems = getFloorItems(lTile.X, lTile.Y); if (tileItems.Count > 0) { if (pItem.Definition.Behaviour.isRoller) { if (newX != pItem.X || newY != pItem.Y) // Not just rotation change { if (owner != null && !owner.StackAnything) { return(false); // Can't place these items on diff ones } } } itemsAffected.AddRange(tileItems); } } itemsComplete.AddRange(itemsOnTile); itemsComplete.AddRange(itemsAffected); // If item is at same position, keep height if (pItem.Z != newZ && pItem.X == newX && pItem.Y == newY) { newZ = pItem.Z; } if (!pItem.Definition.Behaviour.isRoller) // Rollers are never placed above the the floor { foreach (floorItem lItem in itemsComplete) { if (lItem.ID != pItem.ID && !lItem.Definition.Behaviour.canStackOnTop || (lItem.Definition.Behaviour.isRoller && (pItem.Definition.Width > 1 || pItem.Definition.Length > 1))) // Placing on roller, but item exceeds 1x1 size { if (owner != null && !owner.StackAnything) { return(false); // Can't stack on item (in this way) } } } // Position item on top of stack foreach (floorItem lItem in itemsAffected) { if (lItem.ID != pItem.ID && lItem.totalHeight > newZ) { newZ = lItem.totalHeight; } } //if (newZ > 8) // Max height: 8 // newZ = 8; } byte oldX = pItem.X; byte oldY = pItem.Y; byte oldRotation = pItem.Rotation; pItem.X = newX; pItem.Y = newY; pItem.Z = newZ; pItem.Rotation = newRotation; if (owner != null && owner.StackAnything) { pItem.Z = Engine.Game.Users.getUserSession(pItem.ownerID).StackHeight; } if (isNewPlacement) { pItem.Update(); this.floorItems.Add(pItem); } else { pItem.requiresUpdate = true; } this.generateFloorMap(); this.broadcoastFloorItemMove(pItem, isNewPlacement); if (!isNewPlacement) // Item moves to different tiles, reset room units on current tiles { foreach (roomTile lTile in this.getAffectedTiles(pItem.Definition.Length, pItem.Definition.Width, oldX, oldY, oldRotation, true).Values) { refreshRoomUnitOnTile(lTile.X, lTile.Y); } } foreach (roomTile lTile in getAffectedTiles(pItem, true).Values) { refreshRoomUnitOnTile(lTile.X, lTile.Y); } if (isNewPlacement) // Item is not just moved { if (pItem.Definition.Sprite == "nest") // Pet nest { this.loadRoomPet(pItem.ID, newX, newY); // Load pet at new position } } this.broadcoastHeightmap(); return(true); }
public bool moveFloorItem(int itemID, stripItem handItemInstance, byte newX, byte newY, byte newRotation) { bool isNewPlacement = (handItemInstance != null); floorItem pItem = null; if (isNewPlacement) { if (this.containsFloorItem(itemID)) // L o l w u t return false; //if (this.floorItems.Count == 100) // return false; pItem = new floorItem(); pItem.ID = handItemInstance.ID; pItem.roomID = this.roomID; pItem.ownerID = this.Information.ownerID; pItem.Definition = handItemInstance.Definition; pItem.customData = handItemInstance.customData; pItem.teleporterID = handItemInstance.teleporterID; } else { pItem = this.getFloorItem(itemID); if (pItem == null) return false; } // Calculate new height float newZ = this.gridHeight[newX, newY]; // Trying to stack on itself? if (pItem.Rotation == newRotation && pItem.X == newX && pItem.Y == newY && pItem.Z != newZ) return false; // Get the tiles this item would reside on if this item was placed here, and verify if they exist Dictionary<int, roomTile> itemTiles = getAffectedTiles(pItem.Definition.Length, pItem.Definition.Width, newX, newY, newRotation, true); List<floorItem> itemsOnTile = getFloorItems(newX, newY); List<floorItem> itemsAffected = new List<floorItem>(); List<floorItem> itemsComplete = new List<floorItem>(); foreach (roomTile lTile in itemTiles.Values) { if (!this.tileExists(lTile.X, lTile.Y) || this.gridClientMap[lTile.X, lTile.Y] == 'x') return false; // Out of map range / invalid tile if (this.gridUnit[lTile.X, lTile.Y]) // Room unit on this tile { if (newRotation == pItem.Rotation && (lTile.X != pItem.X || lTile.Y != pItem.Y)) return false; // Can't rotate } List<floorItem> tileItems = getFloorItems(lTile.X, lTile.Y); if (tileItems.Count > 0) { if (pItem.Definition.Behaviour.isRoller || pItem.Definition.Behaviour.isDoor) { if (newX != pItem.X || newY != pItem.Y) // Not just rotation change return false; // Can't place these items on diff ones } itemsAffected.AddRange(tileItems); } } itemsComplete.AddRange(itemsOnTile); itemsComplete.AddRange(itemsAffected); // If item is at same position, keep height if (pItem.Z != newZ && pItem.X == newX && pItem.Y == newY) newZ = pItem.Z; if (!pItem.Definition.Behaviour.isRoller) // Rollers are never placed above the the floor { foreach (floorItem lItem in itemsComplete) { if (lItem.ID != pItem.ID && !lItem.Definition.Behaviour.canStackOnTop || (lItem.Definition.Behaviour.isRoller && (pItem.Definition.Width > 1 || pItem.Definition.Length > 1))) // Placing on roller, but item exceeds 1x1 size return false; // Can't stack on item (in this way) } // Position item on top of stack foreach (floorItem lItem in itemsAffected) { if (lItem.ID != pItem.ID && lItem.totalHeight > newZ) newZ = lItem.totalHeight; } if (newZ > 8) // Max height: 8 newZ = 8; } byte oldX = pItem.X; byte oldY = pItem.Y; byte oldRotation = pItem.Rotation; pItem.X = newX; pItem.Y = newY; pItem.Z = newZ; pItem.Rotation = newRotation; if (isNewPlacement) { pItem.Update(); this.floorItems.Add(pItem); } else pItem.requiresUpdate = true; this.generateFloorMap(); this.broadcoastFloorItemMove(pItem, isNewPlacement); if (!isNewPlacement) // Item moves to different tiles, reset room units on current tiles { foreach (roomTile lTile in this.getAffectedTiles(pItem.Definition.Length, pItem.Definition.Width, oldX, oldY, oldRotation, true).Values) { refreshRoomUnitOnTile(lTile.X, lTile.Y); } } foreach (roomTile lTile in getAffectedTiles(pItem, true).Values) { refreshRoomUnitOnTile(lTile.X, lTile.Y); } if (isNewPlacement) // Item is not just moved { if (pItem.Definition.Sprite == "nest") // Pet nest { this.loadRoomPet(pItem.ID, newX, newY); // Load pet at new position } } this.broadcoastHeightmap(); return true; }
/// <summary> /// Places a wall item in the room and makes it visible for all clients, and returns a boolean that holds true if the operation has succeeded. /// </summary> /// <param name="handItemInstance">The stripItem instance of the wall item that is being placed down.</param> /// <param name="Position">The new position of the wall item as a string.</param> public bool placeWallItem(stripItem handItemInstance, string Position) { if (this.containsWallItem(handItemInstance.ID)) return false; wallItem pItem = new wallItem(); pItem.ID = handItemInstance.ID; pItem.roomID = this.roomID; pItem.ownerID = handItemInstance.ownerID; pItem.Definition = handItemInstance.Definition; pItem.customData = handItemInstance.customData; pItem.wallPosition = Position; if (handItemInstance.Definition.Behaviour.isPostIt) // New post.it, set blank message data { pItem.postItMessage = String.Empty; } this.broadcoastWallItemPlacement(pItem); this.wallItems.Add(pItem); pItem.Update(); // Save position return true; }