internal ResourcePackManifest(Image <Rgba32> icon, string name, string description, ResourcePackType type = ResourcePackType.Unknown) { Icon = icon; Name = name; Description = description; Type = type; }
/// <summary> /// ダイアログを表示してユーザーにリソースパックを選択することを求める /// </summary> /// <returns>ユーザーがキャンセルしたらfalse</returns> public bool ShowDialog() { var packTypeDialog = new ResourcePackTypeDialog(); if (packTypeDialog.ShowDialog() != DialogResult.OK) { return(false); } this.ResourcePackType = packTypeDialog.ResourcePackType; var packPathDialog = packTypeDialog.ResourcePackType.value switch { EnumResourcePackType.Zip => this.zipDialog, EnumResourcePackType.Folder => this.folderDialog, EnumResourcePackType.Mod => this.modDialog, EnumResourcePackType.PlainFolder => this.plainFolderDialog, _ => null, }; if (packPathDialog.ShowDialog() != CommonFileDialogResult.Ok) { return(false); } this.ResourcePackPaths.Clear(); this.ResourcePackPaths.AddRange(packPathDialog.FileNames); return(true); }
/// <summary> /// Try selling resources. Recieves: 1 - ResourcePackType to sell. 2 - number of packs to sell. 3 - Sell Price for pack Returns: 0 - Not enough Resources. 1 - Resources Sold. /// </summary> /// <param name="typeToSell"></param> /// <param name="numberOfReourcePacks"></param> /// <param name="sellPrice"></param> /// <returns></returns> public int TrySellResources(ResourcePackType typeToSell, int numberOfReourcePacks, int sellPrice) { int sellState = 0; List <Market> globalMarket = markets.All().ToList(); List <ResourcePack> resourcePackCollection = null; foreach (var resourcePack in CurrentGatherer.Resources.ResourcePacks) { if (resourcePack.Type == typeToSell) { resourcePackCollection.Add(resourcePack); } } if (resourcePackCollection.Count >= numberOfReourcePacks) { for (int i = 0; i < numberOfReourcePacks; i++) { CurrentGatherer.Resources.ResourcePacks.Remove(resourcePackCollection[i]); resourcePackCollection[i].Price = sellPrice; resourcePackCollection[i].Seller = CurrentGatherer.User; resourcePackCollection[i].UserId = CurrentGatherer.UserId; globalMarket[0].ResourcePacks.Add(resourcePackCollection[i]); } markets.Update(globalMarket[0]); markets.SaveChanges(); sellState = 1; } return(sellState); }
private void selectionBtn_Click(object sender, EventArgs e) { var dialog = new ResourcePackSelector(); if (dialog.ShowDialog()) { this.pathBox.Text = string.Join(", ", dialog.ResourcePackPaths); this.resourcePackPaths = dialog.ResourcePackPaths; this.resourcePackType = dialog.ResourcePackType; } }
protected static ResourcePackManifest GetManifest(ZipArchive archive, ResourcePackType type) { if (type == ResourcePackType.Java) { var entry = archive.GetEntry("pack.mcmeta"); if (entry != null) { ResourcePackInfo info; using (TextReader reader = new StreamReader(entry.Open())) { ResourcePackInfoWrapper wrap = MCJsonConvert.DeserializeObject <ResourcePackInfoWrapper>(reader.ReadToEnd()); info = wrap.pack; } try { var imgEntry = archive.GetEntry("pack.png"); if (imgEntry != null) { // Bitmap bmp = new Bitmap(imgEntry.Open()); using (var stream = imgEntry.Open()) { var bmp = Image.Load <Rgba32>(stream.ReadToSpan(entry.Length)); return(new ResourcePackManifest(bmp, "", info.Description)); } } } catch (Exception ex) { Log.Warn(ex, $"Could not read resourcepack logo: {archive.ToString()}"); } return(new ResourcePackManifest("", info.Description)); } else { throw new InvalidResourcePackException(); } } else if (type == ResourcePackType.Bedrock) { } return(null); }
protected static ResourcePackManifest GetManifest(ZipArchive archive, ResourcePackType type) { if (type == ResourcePackType.Java) { var entry = archive.GetEntry("pack.mcmeta"); if (entry != null) { ResourcePackInfo info; using (TextReader reader = new StreamReader(entry.Open())) { ResourcePackInfoWrapper wrap = MCJsonConvert.DeserializeObject <ResourcePackInfoWrapper>(reader.ReadToEnd()); info = wrap.pack; } var imgEntry = archive.GetEntry("pack.png"); if (imgEntry != null) { // Bitmap bmp = new Bitmap(imgEntry.Open()); var bmp = Image.Load <Rgba32>(imgEntry.Open()); return(new ResourcePackManifest(bmp, "", info.Description)); } else { return(new ResourcePackManifest("", info.Description)); } } else { throw new InvalidResourcePackException(); } } else if (type == ResourcePackType.Bedrock) { } return(null); }
internal ResourcePackManifest(string name, string description, ResourcePackType type = ResourcePackType.Unknown) : this(UnknownPack, name, description, type) { }
private void okBtn_Click(object sender, EventArgs e) { this.ResourcePackType = (ResourcePackType)this.packTypeComboBox.SelectedValue; this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// Try gathering Resources. Recives Resource Type to gather. Returns: 0 - Field is not cleared. 1 - Field Cleared, No Resources of Type. 2 - All resources left gathered. 3 - Resources gathere, more left. 4 - All resources left gathered. Gathering Tool Broken. 5 - Resources gathere, more left. Gathering Tool Broken. /// </summary> /// <returns></returns> public int TryGatherResources(ResourcePackType typeToGather) { int gatherState = 0; if (CurrentGatherer.Field.IsCleared) { int resCount = 0; switch (typeToGather) { case ResourcePackType.Metal: resCount = CurrentGatherer.Field.MetalCount; break; case ResourcePackType.Wood: resCount = CurrentGatherer.Field.WoodCount; break; } if (resCount > 0) { int skill = 0; switch (typeToGather) { case ResourcePackType.Metal: skill = CurrentGatherer.GatherStats.MetalGatherSkill; foreach (var equipedItem in CurrentGatherer.GatherEquipment.EquipedItems) { if (equipedItem.Type == ItemType.MetalGatherTool) { skill += equipedItem.MetalGatherSkill; } } break; case ResourcePackType.Wood: skill = CurrentGatherer.GatherStats.WoodGatherSkill; foreach (var equipedItem in CurrentGatherer.GatherEquipment.EquipedItems) { if (equipedItem.Type == ItemType.WoodGatherTool) { skill += equipedItem.WoodGatherSkill; } } break; } if (skill > resCount) { for (int i = 0; i < resCount; i++) { CurrentGatherer.Resources.ResourcePacks.Add(new ResourcePack() { Type = typeToGather }); } resCount = 0; switch (typeToGather) { case ResourcePackType.Metal: CurrentGatherer.Field.MetalCount = resCount; gatherState = 2; foreach (var equipedItem in CurrentGatherer.GatherEquipment.EquipedItems) { if (equipedItem.Type == ItemType.MetalGatherTool) { equipedItem.Durability -= 1; if (equipedItem.Durability <= 0) { CurrentGatherer.GatherEquipment.EquipedItems.Remove(equipedItem); gatherState = 4; } } } if (CurrentGatherer.Field.WoodCount == 0) { CurrentGatherer.Field.IsCleared = false; } break; case ResourcePackType.Wood: CurrentGatherer.Field.WoodCount = resCount; gatherState = 2; foreach (var equipedItem in CurrentGatherer.GatherEquipment.EquipedItems) { if (equipedItem.Type == ItemType.WoodGatherTool) { equipedItem.Durability -= 1; if (equipedItem.Durability <= 0) { CurrentGatherer.GatherEquipment.EquipedItems.Remove(equipedItem); gatherState = 4; } } } if (CurrentGatherer.Field.MetalCount == 0) { CurrentGatherer.Field.IsCleared = false; } break; } gatherers.Update(CurrentGatherer); gatherers.SaveChanges(); } else { for (int i = 0; i < skill; i++) { CurrentGatherer.Resources.ResourcePacks.Add(new ResourcePack() { Type = typeToGather }); } switch (typeToGather) { case ResourcePackType.Metal: foreach (var equipedItem in CurrentGatherer.GatherEquipment.EquipedItems) { if (equipedItem.Type == ItemType.MetalGatherTool) { equipedItem.Durability -= 1; if (equipedItem.Durability <= 0) { CurrentGatherer.GatherEquipment.EquipedItems.Remove(equipedItem); gatherState = 5; } } } break; case ResourcePackType.Wood: foreach (var equipedItem in CurrentGatherer.GatherEquipment.EquipedItems) { if (equipedItem.Type == ItemType.WoodGatherTool) { equipedItem.Durability -= 1; if (equipedItem.Durability <= 0) { CurrentGatherer.GatherEquipment.EquipedItems.Remove(equipedItem); gatherState = 5; } } } break; } CurrentGatherer.Field.MetalCount -= skill; gatherers.Update(CurrentGatherer); gatherers.SaveChanges(); gatherState = 3; } } else { gatherState = 1; } } return(gatherState); }