public ServiceResult Insert(INode n) { if (!this.DataAccessAuthorized(n, "POST", false)) { return(ServiceResponse.Error("You are not authorized this action.")); } n.Initialize(this._requestingUser.UUID, this._requestingUser.AccountUUID, this._requestingUser.RoleWeight); var s = (Strain)n; using (var context = new GreenWerxDbContext(this._connectionKey)) { Strain dbU = context.GetAll <Strain>()?.FirstOrDefault(wu => (wu.Name?.EqualsIgnoreCase(s.Name) ?? false) && wu.AccountUUID == s.AccountUUID); if (dbU != null) { return(ServiceResponse.Error("Strain already exists.")); } if (context.Insert <Strain>((Strain)s)) { return(ServiceResponse.OK("", s)); } } return(ServiceResponse.Error("An error occurred inserting strain " + s.Name)); }
public bool IsValid(Strain strain) { int totalLength = 0; strain.PlayerSelectedGenes.ForEach(gene => { totalLength += gene.Length; }); return(totalLength < strain.BasicRace.MaxLength); }
public void DecreaseQuantity(Strain strain) { int quantity = 0; switch (quantityMode) { case QuantityMode.state1: quantity = 1; break; case QuantityMode.state2: quantity = 10; break; case QuantityMode.state3: quantity = 28; break; } currentOrder.DecreaseQuantity(strain, quantity); Order.Order_Bud budOrder = currentOrder.GetBud(strain); if (budOrder.GetWeight() <= 0) { currentOrder.RemoveBud(budOrder); } UpdateList(); }
public void AddStartJar() { List <StoreObjectReference> containerObjects = db.GetProducts(StoreObjectReference.productType.container); GameObject jar = Instantiate(containerObjects[1].gameObject_); ProductGO productGO = jar.GetComponent <ProductGO>(); productGO.objectID = containerObjects[1].objectID; StorageJar storageJar = new StorageJar(containerObjects[1], jar); storageJar.uniqueID = Dispensary.GetUniqueProductID(); storageJar.objectID = containerObjects[1].objectID; productGO.product = storageJar; productGO.canHighlight = true; jar.GetComponent <Jar>().product = storageJar; List <Bud> toAdd = new List <Bud>(); Strain toUse = db.GetRandomStrain(); for (int i = 0; i < 28; i++) { GameObject bud = new GameObject("Bud"); Bud newBud = bud.AddComponent <Bud>(); newBud.strain = toUse; newBud.weight = UnityEngine.Random.Range(.65f, 1.35f); newBud.weight = Mathf.Round(newBud.weight * 100f) / 100f; // Round to 2 decimal places jar.GetComponent <Jar>().AddBud(bud); bud.transform.position = Vector3.zero; toAdd.Add(newBud); } storageJar.AddBud(toAdd); ShelfPosition jarPosition = dm.dispensary.Storage_cs[0].GetRandomStorageLocation(storageJar); jar.transform.position = jarPosition.transform.position; jar.transform.parent = jarPosition.transform; jarPosition.shelf.parentShelf.AddProduct(storageJar); }
/// <summary> Returns star rating. </summary> public static float Calculate(Beatmap aBeatmap) { if (aBeatmap.hitObjects.Count == 0) { return(0); } Strain s = new Strain(); // First object cannot generate strain, so we offset this to account for that. double currentSectionEnd = sectionLength; s.previousObjects.Add(aBeatmap.hitObjects.First()); foreach (HitObject hitObject in aBeatmap.hitObjects.Skip(1)) { // Performed on the previous object, hence before Process. while (hitObject.time > currentSectionEnd) { s.SaveCurrentPeak(); s.StartNewSectionFrom(currentSectionEnd); currentSectionEnd += sectionLength; } s.Process(hitObject); } return((float)(s.DifficultyValue() * star_scaling_factor)); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var strain = new Strain { Name = request.Name, Comment = request.Comment, Notes = request.Notes, Aquired = request.Aquired, Price = request.Price, ThcPercentage = request.ThcPercentage, CbdPercentage = request.CbdPercentage, Parentage = request.Parentage, Aroma = request.Aroma, Taste = request.Taste, Tags = request.Tags, Editors = request.Editors, Created = DateTime.Now, LastUpdated = DateTime.Now }; _context.Strains.Add(strain); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }
/// <summary> /// 分解的量的公式需要再修改 /// </summary> /// <param name="parentStrain"></param> /// <param name="currentBlock"></param> /// <param name="gene"></param> /// <returns></returns> public bool Decomposite(ref Strain parentStrain, ref Block currentBlock, ref CodingGene gene) { if (string.IsNullOrEmpty(gene.DecompositionChemicalName)) { return(true); } string DeposChemicalName = gene.DecompositionChemicalName.Clone() as string; // 若分解物质不存在,gene罢工 var decompositeChemical = currentBlock.PublicChemicals.Find(chem => { return(chem.Name == DeposChemicalName); }); var chemicalToDecomposite = (gene.IsDecompositionPublic ? currentBlock.PublicChemicals : parentStrain.PrivateChemicals).Find(chem => { return(chem.Name == DeposChemicalName); }); if (chemicalToDecomposite == null) { return(false); // 根本不存在该物质,不工作 } else { if (chemicalToDecomposite.Count >= gene.DecompositionChemicalCount) { chemicalToDecomposite.Count -= gene.DecompositionChemicalCount; } else { return(false); // 需要消耗的量不足,不工作 } } return(true); }
public bool ProductChemical(ref Strain parentStrain, ref Block currentBlock, ref CodingGene gene) { if (string.IsNullOrEmpty(gene.ProductionChemicalName)) { return(true); } var ProductionChemicalName = gene.ProductionChemicalName; var productionChemical = Local.FindChemicalByName(ProductionChemicalName); // ----- 对化学物质产生影响 ----- // 查找是否存在这个物质 var productChem = currentBlock.PublicChemicals.Find(che => { return(che.Name == ProductionChemicalName); }); if (productChem == null) { productChem = new Chemical { Name = ProductionChemicalName, Count = 0, SpreadRate = productionChemical.SpreadRate }; // 向block物质集中添加改变的chemical currentBlock.PublicChemicals.Add(productChem); } productChem.Count += ( int )GetProductionChemicalDelta(ref parentStrain, ref gene); // ----- 对化学 物质产生影响 ----- return(true); }
public async Task <CreateOperationResult> CreateStrain(Strain strain) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { try { var getstrain = dbContext.Strains.FirstOrDefault(s => s.AccountId == account.Id && s.Name.ToLower() == strain.Name.ToLower()); if (getstrain == null) { dbContext.Strains.Add(strain); dbContext.SaveChanges(); } return(new CreateOperationResult() { Success = true, Data = strain }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public void StrainModelTest() { //ARRANGE string json = null; string path = "JSON/Strains/Strains.json"; var strains = new List <Strain>(); //ACT Debug.WriteLine("Path: " + path); using (var reader = new StreamReader(path)) { json = reader.ReadToEnd(); } JObject rawData = JObject.Parse(json); //Debug.WriteLine(rawData["data"].ToString()); foreach (JToken strain in rawData["data"].Children()) { Strain tempStrain = strain.ToObject <Strain>(); Console.WriteLine("Strain Added: " + tempStrain.Name); strains.Add(tempStrain); } //ASSERT Assert.IsNotNull(json); Assert.IsTrue(json != ""); Assert.IsTrue(strains.Count > 0); //*/ //OUTPUT Console.WriteLine("Strain Count: " + strains.Count); }
public bool Consume(ref Strain parentStrain, ref Block currentBlock, ref CodingGene gene) { if (string.IsNullOrEmpty(gene.ConsumeChemicalName)) { return(true); } string ConsumeChemicalName = gene.ConsumeChemicalName.Clone() as string; // 若消耗物质不存在,gene罢工 var chemicalToConsume = (gene.IsConsumePublic ? currentBlock.PublicChemicals : parentStrain.PrivateChemicals).Find(chem => { return(chem.Name == ConsumeChemicalName); }); if (chemicalToConsume == null) { if (gene.ConsumeChemicalName == "") { return(true); // 不消耗 } return(false); // 根本不存在该物质,不工作 } int count = (int)GetConsumeLinearDelta(ref parentStrain, ref gene); if (chemicalToConsume.Count >= count) { chemicalToConsume.Count -= count; } else { return(false); } return(true); }
public async Task <ProductStrain> GetProductAsyncByStrain(int strain_id) { Task <string> stringAsync = client.GetStringAsync(uri + "/Product/" + strain_id); string message = await stringAsync; Product product = System.Text.Json.JsonSerializer.Deserialize <Product>(message); Strain strain = await GetStrainByIDAsync(strain_id); ProductStrain ps = new ProductStrain(); ftc.businesslayer.Models.DTO.Effects ef = new ftc.businesslayer.Models.DTO.Effects(); ef.medical = strain.Effects.First().Medical.ToList(); ef.negative = strain.Effects.First().Negative.ToList(); ef.positive = strain.Effects.First().Positive.ToList(); ps.effects = ef; ps.flavors.Add("DisabledDueToRestrictions"); ps.ProductId = product.ProductId; ps.id = strain.StrainId; ps.StrainId = strain.StrainId; ps.race = strain.Race; ps.strainname = strain.StrainName; ps.GrowType = product.GrowType; ps.Orderlines = product.Orderlines; ps.Unit = product.Unit; ps.Vendor = product.Vendor; ps.AvailableInventory = product.AvailableInventory; ps.IsAvailable = product.IsAvailable; ps.ProductName = product.ProductName; ps.ReservedInventory = product.ReservedInventory; ps.ThcContent = product.ThcContent; ps.VendorId = product.VendorId; return(ps); }
private bool PopulateData(IPlant plant) { SaveCommand = new Command(Save, CanSave); CancelCommand = new Command(Cancel, CanCancel); try { Strains = Strain.FindAll().OrderBy(x => x.Name); Schedules = Schedule.FindAll().OrderBy(x => x.Name); Gardens = Garden.FindAll().OrderBy(x => x.Name); if (plant == null) { Plant = new Plant(); return(true); } Plant = Plant.Find(plant.Id); SelectedSchedule = Schedules.Where(x => x.Id == plant.ScheduleId).FirstOrDefault(); SelectedStrain = Strains.Where(x => x.Id == plant.Strain.Id).FirstOrDefault(); SelectedGarden = Gardens.Where(x => x.Id == plant.GardenId).SingleOrDefault(); _isDirty = false; return(true); } catch (Exception) { return(false); } }
private void StrainSelected(object sender, ItemClickEventArgs e) // Get information about strain { ListView lst = sender as ListView; Strain s = e.ClickedItem as Strain; Frame.Navigate(typeof(StrainSearchResults), s); }
public void LoadStrain(Strain strainToLoad, bool THCGraph) { if (currentDisplayedStrain != null) { if (THCGraph) { previousItem1Percent = currentDisplayedStrain.THC; previousItem2Percent = currentDisplayedStrain.CBD; } else { previousItem1Percent = currentDisplayedStrain.Sativa; previousItem2Percent = currentDisplayedStrain.Indica; } } gameObject.SetActive(true); currentDisplayedStrain = strainToLoad; if (THCGraph) { SetItem1Percent(currentDisplayedStrain.THC); SetItem2Percent(currentDisplayedStrain.CBD); } else { SetItem1Percent(currentDisplayedStrain.Sativa); SetItem2Percent(currentDisplayedStrain.Indica); } }
private IEnumerable <Plant> FindAllPlants() { IEnumerable <Plant> collection; List <Plant> plants = new List <Plant>(); const string selectAllPlants = "SELECT * FROM Plant"; using (SQLiteConnection connection = Data.DataBaseAccess.DbConnection) { SQLiteCommand command = connection.CreateCommand(selectAllPlants); try { collection = command.ExecuteQuery <Plant>(); plants.AddRange(collection); } catch (Exception) { throw; } } foreach (Plant plant in collection) { plant.Strain = Strain.Find(plant.StrainId); } return(plants); }
public bool StrainSpread(ref Strain parentStrain, ref Block currentBlock, ref CodingGene gene) { var SpreadConditionRate = gene.SpreadConditionRate; // ----- 细菌扩散 ----- // 是否满足扩散条件 // 避免人口为0时的幽灵扩散 if (parentStrain.Population == 0 || gene.FirstSpreadMountRate.Equals(0)) { return(true); } if (parentStrain.Population >= currentBlock.Capacity * SpreadConditionRate) { string strainName = parentStrain.Name.Clone() as string; // 为周围的格子添加该细菌 foreach (var neighborBlock in currentBlock.NeighborBlocks) { // 只要隔壁有存在相同的strain,就不传递 if (neighborBlock.Strains.Exists(m => { return(m.Name == strainName); })) { continue; } var cloneStrain = ( Strain )parentStrain.Clone(); // 设定初始人口数 cloneStrain.Population = ( int )(parentStrain.Population * gene.FirstSpreadMountRate); neighborBlock.Strains.Add(cloneStrain); } } return(true); // ----- 细菌扩散 ----- }
private bool SaveBacterialClone(SequencingPostModel postModel) { ValidateBacterialClone(postModel); if (ModelState.IsValid) { var userJob = new UserJob(); var userJobBacterialClone = new UserJobBacterialClone(); AutoMapper.Mapper.Map(postModel, userJob); AutoMapper.Mapper.Map(postModel, userJobBacterialClone); userJob.UserJobBacterialClone = userJobBacterialClone; userJob.User = GetCurrentUser(true); userJob.RechargeAccount = postModel.RechargeAccount; AddPlates(postModel.PlateNames, userJob, userJob.JobType); if (postModel.Strain != null && postModel.Strain.IsOther()) { var strain = new Strain() { Name = postModel.NewStrain, Bacteria = postModel.Bacteria, Supplied = false }; userJob.UserJobBacterialClone.Strain = strain; } _repositoryFactory.UserJobRepository.EnsurePersistent(userJob); return(true); } return(false); }
public void AddBudToOrder(Strain newStrain, int quantity) { if (orderFormPanel.currentOrder != null) { orderFormPanel.currentOrder.AddBud(newStrain, quantity); orderFormPanel.UpdateList(); } }
private void Add(object obj) { Editing = true; NewStrain = new Strain() { Id = 0 }; }
private void Cancel(object obj) { NewStrain = new Strain() { Id = -1 }; Editing = false; }
public CuringJar_s(CuringJar jar) : base(Product.type_.curingJar, jar.uniqueID, jar.objectID, jar.subID, jar.GetName(), jar.productGO.transform.position, jar.productGO.transform.eulerAngles) { strain = jar.GetStrain(); foreach (Bud bud in jar.buds) { buds.Add(bud.MakeSerializable()); } }
public async Task <Strain> GetStrainByIDAsync(int id) { Task <string> stringAsync = client.GetStringAsync(uri2 + "/Strain/" + id); string message = await stringAsync; Strain strain = System.Text.Json.JsonSerializer.Deserialize <Strain>(message); return(strain); }
public Vertex(Vertex vertex) { X = vertex.X; Y = vertex.Y; dX = vertex.dX; dY = vertex.dY; strain = vertex.strain; stress = vertex.stress; }
public void SetupDesired() { // The outcomes of the first number generators affects the outcome of later ones (ex. chance for bongs goes down if theres already a desired bong, although it is possible to desire 2 bongs) smokeLounge = (UnityEngine.Random.value < .15) ? true : false; float wantWeed = UnityEngine.Random.value; if (wantWeed > .225f) // 22.5% chance to not want to buy weed { Strain desiredStrain = db.GetRandomStrain(); // If the strain they want is high thc content, they might want less of it DesiredStrain desiredStrainReference = new DesiredStrain(desiredStrain); desiredStrains.Add(desiredStrainReference); } bool extras = (UnityEngine.Random.value < .5) ? true : false; // If they decide to get extras, they might want less weed if (extras) { int randMax = UnityEngine.Random.Range(1, 6); int rand = UnityEngine.Random.Range(1, randMax); for (int i = 0; i < rand; i++) { Product.type_ random = Product.GetRandomType(); Product desiredProduct = null; switch (random) { case Product.type_.rollingPaper: desiredProduct = new DesiredPaper(); break; case Product.type_.glassBong: case Product.type_.acrylicBong: desiredProduct = new DesiredGlass(random); break; case Product.type_.glassPipe: case Product.type_.acrylicPipe: desiredProduct = new DesiredGlass(random); break; case Product.type_.edible: desiredProduct = new DesiredEdible(); break; case Product.type_.bowl: //desiredProduct = new DesiredBowl(); break; } if (desiredProduct != null) { //print(desiredProduct.GetName()); desiredProducts.Add(desiredProduct); } } } }
public void Spawn(Strain strain) { if (spawnCoolDown < 0 && hub.GetBytes() >= (int)strain) { hub.SpendBytes((int)strain); GameObject virus = (GameObject)Instantiate(Resources.Load("Virus" + strain.ToString())); virus.transform.position = gameObject.transform.position; spawnCoolDown = spawnRate; } }
public void DecreaseQuantity(Strain strain, float weight) { for (int i = 0; i < budList.Count; i++) { if (budList[i].GetStrain().name.Equals(strain.name)) { budList[i].DecreaseWeight(weight); } } }
public Account AddAccountFromStrain(Strain s) { if (s == null) { return(null); } ///if (!this.DataAccessAuthorized(v, "GET", false)) return ServiceResponse.Error("You are not authorized this action."); var res = Get(s.BreederUUID); if (res.Code != 200) { return(null); } Account v = (Account)res.Result; if (v != null) { return(v); } //try getting the Account by name with the UUID because the ui allows adding //via text/combobox. res = Get(s.BreederUUID); if (res.Code != 200) { return(null); } v = (Account)res.Result; if (v != null) { return(v); } v = new Account() { AccountUUID = s.AccountUUID, Active = true, CreatedBy = s.CreatedBy, DateCreated = DateTime.UtcNow, Deleted = false, Name = s.BreederUUID, UUIDType = "Account" }; ServiceResult resi = this.Insert(v); if (resi.Code == 200) { return((Account)res.Result); } return(null); }
public ServiceResult Delete(Strain s) { if (s == null || string.IsNullOrWhiteSpace(s.UUID)) { return(ServiceResponse.Error("Invalid account was sent.")); } StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); return(strainManager.Delete(s)); }
/// <summary> /// 游戏核心函数 /// </summary> /// <param name="parentStrain">该基因的父细菌</param> /// <param name="currentBlock">父细菌所在的block</param> public void Effect(ref Strain parentStrain, ref Block currentBlock, ref CodingGene gene) { foreach (var eve in EffectEvents) { if (!eve(ref parentStrain, ref currentBlock, ref gene)) { //Debug.Log("Stop at" + EffectEvents.FindIndex( m => m == eve ) + "\n Name: " + eve.Method.Name ); return; } } }
private bool SaveBacterialClone(SequencingPostModel postModel) { ValidateBacterialClone(postModel); if (ModelState.IsValid) { var userJob = new UserJob(); var userJobBacterialClone = new UserJobBacterialClone(); AutoMapper.Mapper.Map(postModel, userJob); AutoMapper.Mapper.Map(postModel, userJobBacterialClone); userJob.UserJobBacterialClone = userJobBacterialClone; userJob.User = GetCurrentUser(true); userJob.RechargeAccount = postModel.RechargeAccount; AddPlates(postModel.PlateNames, userJob, userJob.JobType); if (postModel.Strain != null && postModel.Strain.IsOther()) { var strain = new Strain() { Name = postModel.NewStrain, Bacteria = postModel.Bacteria, Supplied = false }; userJob.UserJobBacterialClone.Strain = strain; } _repositoryFactory.UserJobRepository.EnsurePersistent(userJob); return true; } return false; }
/// <summary> /// Updates a single strain /// </summary> /// <param name="strain"></param> /// <returns></returns> public virtual string UpdateStrain(Strain strain) { return UpdateStrain(strain, null); }
/// <summary> /// Updates Single Strain with an associated pubmedid /// </summary> /// <param name="strain"></param> /// <returns></returns> public virtual string UpdateStrain(Strain strain, string pubmedid) { StrainList strains = StrainList.New(); strains.Add(strain); return UpdateResource(ObjectToResource(GetSourceID(), strain.HtmlName, strain.ID.ToString(), strain.StrainDescription, GetUrl("Strain") + strain.ID.ToString(), "mouse", "Mouse Strain", strain.History.CreationDate, GetGeneIDsFromStrain(strain.ID), null, pubmedid)); }