public static void UpdateInDatabase(IWiredTrigger wiredItem, IQueryAdapter dbClient) { RemoveFromDatabase(wiredItem, dbClient); RoomItem item = wiredItem.GetOriginalWiredItem(); InteractionType type = item.GetBaseItem().InteractionType; if (WiredLoaderObject.HasSettings(type)) { string[] data = (wiredItem as IWiredSettingsTrigger).GetSettings(); dbClient.setQuery("INSERT INTO `wired_data` (`wired_id`, `data_one`, `data_two`, `data_three`, `data_four`) VALUES (@id, @data1, @data2, @data3, @data4) "); dbClient.addParameter("id", item.Id); dbClient.addParameter("data1", data.Length >= 1 ? data[0] : ""); dbClient.addParameter("data2", data.Length >= 2 ? data[1] : ""); dbClient.addParameter("data3", data.Length >= 3 ? data[2] : ""); dbClient.addParameter("data4", data.Length >= 4 ? data[3] : ""); dbClient.runQuery(); } if (WiredLoaderObject.HasOriginalItemLocations(type)) { Dictionary<uint, OriginalItemLocation> originalLoc = (wiredItem as IWiredOriginalItemTrigger).GetOriginalItemLocation(); foreach (OriginalItemLocation itemLoc in originalLoc.Values) { dbClient.setQuery("INSERT INTO `wired_original_item_locations` (`wired_id`,`item_id`, `original_x`, `original_y`, `rotation`, `extradata`, `height`) VALUES (@wid, @id, @orx, @ory, @orrot, @data, @height)"); dbClient.addParameter("wid", item.Id); dbClient.addParameter("id", itemLoc.itemID); dbClient.addParameter("orx", itemLoc.X); dbClient.addParameter("ory", itemLoc.Y); dbClient.addParameter("orrot", itemLoc.Rot); dbClient.addParameter("data", itemLoc.ExtraData); dbClient.addParameter("height", itemLoc.Height); dbClient.runQuery(); } } if (WiredLoaderObject.NeedsFurnitures(type)) { List<RoomItem> items = (wiredItem as IWiredFurniTrigger).getAffectedItemList(); foreach (RoomItem rItem in items) { dbClient.setQuery("INSERT INTO `wired_to_item` (`wired_id`, `trigger_item`) VALUES (@id, @triggeritem)"); dbClient.addParameter("id", item.Id); dbClient.addParameter("triggeritem", rItem.Id); dbClient.runQuery(); } } }
public static void RemoveFromDatabase(IWiredTrigger wiredItem, IQueryAdapter dbClient) { RoomItem item = wiredItem.GetOriginalWiredItem(); InteractionType type = item.GetBaseItem().InteractionType; if(WiredLoaderObject.HasSettings(type)) { dbClient.setQuery("DELETE FROM wired_data WHERE wired_id = @id"); dbClient.addParameter("id", item.Id); dbClient.runQuery(); } if (WiredLoaderObject.HasOriginalItemLocations(type)) { dbClient.setQuery("DELETE FROM wired_original_item_locations WHERE wired_id = @id"); dbClient.addParameter("id", item.Id); dbClient.runQuery(); } if (WiredLoaderObject.NeedsFurnitures(type)) { dbClient.setQuery("DELETE FROM wired_to_item WHERE wired_id = @id"); dbClient.addParameter("id", item.Id); dbClient.runQuery(); } }