public void Save(WzImage dest, Rectangle?VR) { WzSubProperty info = new WzSubProperty(); info["bgm"] = InfoTool.SetString(bgm); info["cloud"] = InfoTool.SetBool(cloud); info["swim"] = InfoTool.SetBool(swim); info["forcedReturn"] = InfoTool.SetInt(forcedReturn); info["hideMinimap"] = InfoTool.SetBool(hideMinimap); info["mapDesc"] = InfoTool.SetOptionalString(mapDesc); info["mapName"] = InfoTool.SetOptionalString(mapDesc); info["mapMark"] = InfoTool.SetString(mapMark); info["mobRate"] = InfoTool.SetFloat(mobRate); info["moveLimit"] = InfoTool.SetOptionalInt(moveLimit); info["returnMap"] = InfoTool.SetInt(returnMap); info["town"] = InfoTool.SetBool(town); info["version"] = InfoTool.SetInt(version); info["fieldLimit"] = InfoTool.SetInt((int)fieldLimit); info["timeLimit"] = InfoTool.SetOptionalInt(timeLimit); info["lvLimit"] = InfoTool.SetOptionalInt(lvLimit); info["onFirstUserEnter"] = InfoTool.SetOptionalString(onFirstUserEnter); info["onUserEnter"] = InfoTool.SetOptionalString(onUserEnter); info["fly"] = InfoTool.SetOptionalBool(fly); info["noMapCmd"] = InfoTool.SetOptionalBool(noMapCmd); info["partyOnly"] = InfoTool.SetOptionalBool(partyOnly); info["fieldType"] = InfoTool.SetOptionalInt((int?)fieldType); info["miniMapOnOff"] = InfoTool.SetOptionalBool(miniMapOnOff); info["reactorShuffle"] = InfoTool.SetOptionalBool(reactorShuffle); info["reactorShuffleName"] = InfoTool.SetOptionalString(reactorShuffleName); info["personalShop"] = InfoTool.SetOptionalBool(personalShop); info["entrustedShop"] = InfoTool.SetOptionalBool(entrustedShop); info["effect"] = InfoTool.SetOptionalString(effect); info["lvForceMove"] = InfoTool.SetOptionalInt(lvForceMove); if (timeMob != null) { WzSubProperty prop = new WzSubProperty(); prop["startHour"] = InfoTool.SetOptionalInt(timeMob.Value.startHour); prop["endHour"] = InfoTool.SetOptionalInt(timeMob.Value.endHour); prop["id"] = InfoTool.SetOptionalInt(timeMob.Value.id); prop["message"] = InfoTool.SetOptionalString(timeMob.Value.message); info["timeMob"] = prop; } info["help"] = InfoTool.SetOptionalString(help); info["snow"] = InfoTool.SetOptionalBool(snow); info["rain"] = InfoTool.SetOptionalBool(rain); info["dropExpire"] = InfoTool.SetOptionalInt(dropExpire); info["decHP"] = InfoTool.SetOptionalInt(decHP); info["decInterval"] = InfoTool.SetOptionalInt(decInterval); if (autoLieDetector != null) { WzSubProperty prop = new WzSubProperty(); prop["startHour"] = InfoTool.SetOptionalInt(autoLieDetector.Value.startHour); prop["endHour"] = InfoTool.SetOptionalInt(autoLieDetector.Value.endHour); prop["interval"] = InfoTool.SetOptionalInt(autoLieDetector.Value.interval); prop["prop"] = InfoTool.SetOptionalInt(autoLieDetector.Value.prop); info["autoLieDetector"] = prop; } info["expeditionOnly"] = InfoTool.SetOptionalBool(expeditionOnly); info["fs"] = InfoTool.SetOptionalFloat(fs); info["protectItem"] = InfoTool.SetOptionalInt(protectItem); info["createMobInterval"] = InfoTool.SetOptionalInt(createMobInterval); info["fixedMobCapacity"] = InfoTool.SetOptionalInt(fixedMobCapacity); info["streetName"] = InfoTool.SetOptionalString(streetName); info["noRegenMap"] = InfoTool.SetOptionalBool(noRegenMap); if (allowedItem != null) { WzSubProperty prop = new WzSubProperty(); for (int i = 0; i < allowedItem.Count; i++) { prop[i.ToString()] = InfoTool.SetInt(allowedItem[i]); } info["allowedItem"] = prop; } info["recovery"] = InfoTool.SetOptionalFloat(recovery); info["blockPBossChange"] = InfoTool.SetOptionalBool(blockPBossChange); info["everlast"] = InfoTool.SetOptionalBool(everlast); info["damageCheckFree"] = InfoTool.SetOptionalBool(damageCheckFree); info["dropRate"] = InfoTool.SetOptionalFloat(dropRate); info["scrollDisable"] = InfoTool.SetOptionalBool(scrollDisable); info["needSkillForFly"] = InfoTool.SetOptionalBool(needSkillForFly); info["zakum2Hack"] = InfoTool.SetOptionalBool(zakum2Hack); info["allMoveCheck"] = InfoTool.SetOptionalBool(allMoveCheck); info["VRLimit"] = InfoTool.SetOptionalBool(VRLimit); info["consumeItemCoolTime"] = InfoTool.SetOptionalBool(consumeItemCoolTime); foreach (WzImageProperty prop in additionalProps) { info.AddProperty(prop); } if (VR.HasValue) { info["VRLeft"] = InfoTool.SetInt(VR.Value.Left); info["VRRight"] = InfoTool.SetInt(VR.Value.Right); info["VRTop"] = InfoTool.SetInt(VR.Value.Top); info["VRBottom"] = InfoTool.SetInt(VR.Value.Bottom); } dest["info"] = info; }
internal WzImageProperty ParsePropertyFromXMLElement(XmlElement element) { switch (element.Name) { case "imgdir": WzSubProperty sub = new WzSubProperty(element.GetAttribute("name")); foreach (XmlElement subelement in element) { sub.AddProperty(ParsePropertyFromXMLElement(subelement)); } return(sub); case "canvas": WzCanvasProperty canvas = new WzCanvasProperty(element.GetAttribute("name")); if (!element.HasAttribute("basedata")) { throw new NoBase64DataException("no base64 data in canvas element with name " + canvas.Name); } canvas.PngProperty = new WzPngProperty(); MemoryStream pngstream = new MemoryStream(Convert.FromBase64String(element.GetAttribute("basedata"))); canvas.PngProperty.SetPNG((Bitmap)Image.FromStream(pngstream, true, true)); foreach (XmlElement subelement in element) { canvas.AddProperty(ParsePropertyFromXMLElement(subelement)); } return(canvas); case "int": WzIntProperty compressedInt = new WzIntProperty(element.GetAttribute("name"), int.Parse(element.GetAttribute("value"), formattingInfo)); return(compressedInt); case "double": WzDoubleProperty doubleProp = new WzDoubleProperty(element.GetAttribute("name"), double.Parse(element.GetAttribute("value"), formattingInfo)); return(doubleProp); case "null": WzNullProperty nullProp = new WzNullProperty(element.GetAttribute("name")); return(nullProp); case "sound": if (!element.HasAttribute("basedata") || !element.HasAttribute("basehead") || !element.HasAttribute("length")) { throw new NoBase64DataException("no base64 data in sound element with name " + element.GetAttribute("name")); } WzSoundProperty sound = new WzSoundProperty(element.GetAttribute("name"), int.Parse(element.GetAttribute("length")), Convert.FromBase64String(element.GetAttribute("basehead")), Convert.FromBase64String(element.GetAttribute("basedata"))); return(sound); case "string": WzStringProperty stringProp = new WzStringProperty(element.GetAttribute("name"), element.GetAttribute("value")); return(stringProp); case "short": WzShortProperty shortProp = new WzShortProperty(element.GetAttribute("name"), short.Parse(element.GetAttribute("value"), formattingInfo)); return(shortProp); case "long": WzLongProperty longProp = new WzLongProperty(element.GetAttribute("name"), long.Parse(element.GetAttribute("value"), formattingInfo)); return(longProp); case "uol": WzUOLProperty uol = new WzUOLProperty(element.GetAttribute("name"), element.GetAttribute("value")); return(uol); case "vector": WzVectorProperty vector = new WzVectorProperty(element.GetAttribute("name"), new WzIntProperty("x", Convert.ToInt32(element.GetAttribute("x"))), new WzIntProperty("y", Convert.ToInt32(element.GetAttribute("y")))); return(vector); case "float": WzFloatProperty floatProp = new WzFloatProperty(element.GetAttribute("name"), float.Parse(element.GetAttribute("value"), formattingInfo)); return(floatProp); case "extended": WzConvexProperty convex = new WzConvexProperty(element.GetAttribute("name")); foreach (XmlElement subelement in element) { convex.AddProperty(ParsePropertyFromXMLElement(subelement)); } return(convex); } throw new InvalidDataException("unknown XML prop " + element.Name); }
private void UpdateNodes() { void ApplyUpdates(TabControl.TabPageCollection pages) { foreach (TabPage tab in pages) { var view = (CItemGroup)tab.Controls[0]; var table = view.GridView; var replacements = view.TextBox.Lines; for (var i = 0; i < table.RowCount; i++) { var row = table.Rows[i]; var img = (WzImageProperty)row.Tag; // replace price value var priceObject = row.Cells[2]?.Value; if (priceObject != null) { var priceImg = img.GetFromPath("Price"); // convert to string then parse as int due to edited values being a string while original, un-values are still ints var price = int.Parse(row.Cells[2].Value.ToString()); if (priceImg == null && price > 0) { img.ParentImage.Changed = true; img.WzProperties.Add(new WzIntProperty("Price", price)); } else if (priceImg != null && priceImg.GetInt() != price) { img.ParentImage.Changed = true; ((WzIntProperty)priceImg).Value = price; } } // replace donor value var donorImg = img.GetFromPath("isDonor"); var donor = int.Parse(row.Cells[3].Value.ToString()) == 1; if (donorImg == null && donor) { img.ParentImage.Changed = true; img.WzProperties.Add(new WzIntProperty("isDonor", 1)); } else if (donorImg != null && (donorImg.GetInt() == 1) != donor) { img.ParentImage.Changed = true; ((WzIntProperty)donorImg).Value = donor ? 1 : 0; } // replace period value var periodImg = img.GetFromPath("Period"); var period = int.Parse(row.Cells[4].Value.ToString()); if (periodImg == null && period > 0) { img.ParentImage.Changed = true; img.WzProperties.Add(new WzIntProperty("Period", 1)); } else if (periodImg != null && periodImg.GetInt() != period) { img.ParentImage.Changed = true; ((WzIntProperty)periodImg).Value = period; } } for (var i = 0; i < replacements.Length; i++) { if (!int.TryParse(replacements[i], out var itemId)) { MessageBox.Show($"Invalid ID at line {i}: {replacements[i]}"); return; } // replace existing item if (i < table.RowCount) { var row = table.Rows[i]; var img = (WzImageProperty)row.Tag; var itemIdImg = img.GetFromPath("ItemId"); img.ParentImage.Changed = true; ((WzIntProperty)itemIdImg).Value = itemId; } else { // insert new item var isDonor = MainPage.SelectedIndex == 1; var sn = ItemCategory.GenerateSn(isDonor, itemId); var sub = new WzSubProperty((++largestNodeValue).ToString()); sub.AddProperty(new WzIntProperty("Count", 1)); sub.AddProperty(new WzIntProperty("Gender", 2)); sub.AddProperty(new WzIntProperty("ItemId", itemId)); sub.AddProperty(new WzIntProperty("OnSale", 1)); sub.AddProperty(new WzIntProperty("Period", 90)); sub.AddProperty(new WzIntProperty("Price", 1)); sub.AddProperty(new WzIntProperty("Priority", 99)); sub.AddProperty(new WzIntProperty("isDonor", isDonor ? 1 : 0)); sub.AddProperty(new WzIntProperty("SN", sn)); Debug.WriteLine($"Generated SN for item {itemId}: {sn}. Node {sub.Name}"); commodityImg.AddProperty(sub); sub.ParentImage.Changed = true; } } } } ApplyUpdates(RegularViewer.tabControl.TabPages); ApplyUpdates(DonorViewer.tabControl.TabPages); }