public Augment ConvertToScienceObject() => new Augment( name, description, CustomEnum.GetValueFromDescription <Character.BodyPartSlot.SlotType>(slot), CustomEnum.GetValueFromDescription <Character.RaceType>(race), genderInverted, customParams) { Id = id };
private void CreateCharacter_Click(object sender, RoutedEventArgs e) { newCharacter.Name = BoxName.Text; newCharacter.Description = BoxDescription.Text; newCharacter.Gender = CustomEnum.GetValueFromDescription <Character.GenderType>(BoxGender.Text); newCharacter.Race = CustomEnum.GetValueFromDescription <Character.RaceType>(BoxRace.Text); chars.Add(newCharacter); DefaultCharacter_Click(this, new RoutedEventArgs()); UpdateGrids(); }
public Organ ConvertToScienceObject() { var Slot = CustomEnum.GetValueFromDescription <Character.BodyPartSlot.SlotType>(slot); return(new Organ(name, Slot, Character.BodyPartSlot.GetSlotPicture(Slot, CustomEnum.GetValueFromDescription <Character.RaceType>(race), genderInverted), description) { Id = id, Gender = genderInverted, Race = CustomEnum.GetValueFromDescription <Character.RaceType>(race) }); }
/// <param name="Type">0 - all items [OBSOLETE]; /// 1 - only organs; /// 2 - only augments [OBSOLETE]; /// 3 - only primary augs; /// 4 - only auxilary augs;</param> public static async Task <List <Database.BodyPart> > GetUserItems(int Type, Database.Character.BodyPartSlot.SlotType?Slot = null, Database.Character.RaceType?Race = null) { switch (Type) { case 1: // Organs { HttpResponseMessage response = await Database.Controller.Client.GetAsync("player/medicine/getUserOrgans"); if (response.IsSuccessStatusCode) { string responseString = JsonConverter(await response.Content.ReadAsStringAsync(), false); File.WriteAllText("temp.json", JToken.Parse(responseString).ToString(Formatting.Indented)); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List <EjectedOrgan>)); MemoryStream stream = new MemoryStream(File.ReadAllBytes("temp.json")) { Position = 0 }; List <EjectedOrgan> items = serializer.ReadObject(stream) as List <EjectedOrgan>; if (Slot != null) { restart: foreach (var item in items) { if (CustomEnum.GetValueFromDescription <Database.Character.BodyPartSlot.SlotType>(item.slot) != Slot) { items.Remove(item); goto restart; } } } if (Race != null) { restart: foreach (var item in items) { if (CustomEnum.GetValueFromDescription <Database.Character.RaceType>(item.race) != Race) { items.Remove(item); goto restart; } } } List <Database.Organ> result = new List <Database.Organ>(); foreach (var item in items) { int count = item.count; Database.Organ scienceOrgan = item.ConvertToScienceObject(); for (int i = 0; i < count; i++) { result.Add(scienceOrgan); } } return(result.Cast <Database.BodyPart>().ToList()); } else { throw new HttpRequestException("Сервер возвратил ошибку " + response.StatusCode.ToString() + " по причине " + response.ReasonPhrase + "."); } } case 2: throw new ArgumentException(); case 3: // Primary augs { HttpResponseMessage response = await Database.Controller.Client.GetAsync("player/medicine/getUserAugments"); if (response.IsSuccessStatusCode) { string responseString = JsonConverter(await response.Content.ReadAsStringAsync(), false); File.WriteAllText("temp.json", JToken.Parse(responseString).ToString(Formatting.Indented)); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List <PrimaryAugment>)); MemoryStream stream = new MemoryStream(File.ReadAllBytes("temp.json")) { Position = 0 }; List <PrimaryAugment> items = serializer.ReadObject(stream) as List <PrimaryAugment>; if (Slot != null) { restart: foreach (var item in items) { if (CustomEnum.GetValueFromDescription <Database.Character.BodyPartSlot.SlotType>(item.slot) != Slot) { items.Remove(item); goto restart; } } } if (Race != null) { restart: foreach (var item in items) { if (CustomEnum.GetValueFromDescription <Database.Character.RaceType>(item.race) != Race) { items.Remove(item); goto restart; } } } List <Database.Augment> result = new List <Database.Augment>(); foreach (var item in items) { int count = item.count; Database.Augment scienceAugment = item.ConvertToScienceObject(); for (int i = 0; i < count; i++) { result.Add(scienceAugment); } } return(result.Cast <Database.BodyPart>().ToList()); } else { throw new HttpRequestException("Сервер возвратил ошибку " + response.StatusCode.ToString() + " по причине " + response.ReasonPhrase + "."); } } case 4: // Auxilary augs { HttpResponseMessage response = await Database.Controller.Client.GetAsync("player/medicine/getUserAugments"); if (response.IsSuccessStatusCode) { string responseString = JsonConverter(await response.Content.ReadAsStringAsync(), false); File.WriteAllText("temp.json", JToken.Parse(responseString).ToString(Formatting.Indented)); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List <AuxilaryAugment>)); MemoryStream stream = new MemoryStream(File.ReadAllBytes("temp.json")) { Position = 0 }; List <AuxilaryAugment> items = serializer.ReadObject(stream) as List <AuxilaryAugment>; List <Database.Augment> result = new List <Database.Augment>(); foreach (var item in items) { if (item.slot == "") // Auxilary aug = aug without slot { int count = item.count; Database.Augment scienceAugment = item.ConvertToScienceObject(); for (int i = 0; i < count; i++) { result.Add(scienceAugment); } } } return(result.Cast <Database.BodyPart>().ToList()); } else { throw new HttpRequestException("Сервер возвратил ошибку " + response.StatusCode.ToString() + " по причине " + response.ReasonPhrase + "."); } } default: throw new ArgumentException("Передан неверный тип предметов при запросе на экономический сервер: " + Type.ToString(), "Type"); } }