public static FoodBag CompleteFoodBag(MyContext ctx, FoodBag foodBag, string[] includes) { if (includes != null) { foreach (var str in includes) { switch (str.Trim()) { case "creator": foodBag.Creator = ctx.Users.FirstOrDefault(u => u.Id == foodBag.CreatorId); break; case "description": var descp = ctx.ObjectMetas.FirstOrDefault(m => m.ObjectId == foodBag.Id && m.Name == str); if (descp != null) { foodBag.Description = descp.Value; } break; case "ingredientStacks": var temp = ctx .ObjectStacks .Where(s => s.ParentId == foodBag.Id && s.Type == ObjectStack.StackTypes.Ingredient) .ToList(); foodBag.IngredientStacks = ctx .ObjectStacks .Where(s => s.ParentId == foodBag.Id && s.Type == ObjectStack.StackTypes.Ingredient) .AsEnumerable() .Select(IngredientStack => { return(IngredientStackService.CompleteIngredientStack(ctx, IngredientStack)); }) .ToList(); break; case "recipeStacks": foodBag.RecipeStacks = ctx .ObjectStacks .Where(s => s.ParentId == foodBag.Id && s.Type == ObjectStack.StackTypes.Recipe) .AsEnumerable() .Select(recipeStack => { return(RecipeStackService.CompleteRecipeStack(ctx, recipeStack)); }) .ToList(); break; } } } return(foodBag); }
public void OnTriggerEnter(Collider other) { FoodBag script = other.gameObject.GetComponent <FoodBag>(); if (script == null) { return; } OpeningSound.Play(); script.OpenBag(); }
public ActionResult <FoodBag> CreateFoodBag(FoodBag foodBag) { using (var ctx = MyContext.New()) { foodBag.IsPersisted = 1; ctx.FoodBags.Add(foodBag); ctx.ObjectMetas.Add(new ObjectMeta { Id = Guid.NewGuid().ToString(), ObjectId = foodBag.Id, Name = "description", Value = foodBag.Description ?? "", }); foreach (var ingredientStack in foodBag.IngredientStacks) { var s = new ObjectStack { Id = Guid.NewGuid().ToString(), Type = StackTypes.Ingredient, ParentId = foodBag.Id, ItemId = ingredientStack.ItemId, TotalAmount = ingredientStack.TotalAmount, IsDeleted = 0, IsPersisted = 1, }; ctx.ObjectStacks.Add(s); } foreach (var recipeStack in foodBag.RecipeStacks) { var s = new ObjectStack { Id = Guid.NewGuid().ToString(), Type = StackTypes.Recipe, ParentId = foodBag.Id, ItemId = recipeStack.ItemId, TotalAmount = recipeStack.TotalAmount, IsDeleted = 0, IsPersisted = 1, }; ctx.ObjectStacks.Add(s); } ctx.SaveChanges(); return(foodBag); } }
public ActionResult <FoodBag> Put(String foodBagId, [FromBody] FoodBag foodBag) { using (var ctx = MyContext.New()) { ctx.FoodBags.Update(foodBag); foreach (var ingredientStack in foodBag.IngredientStacks) { if (ingredientStack.IsPersisted == 0) { ingredientStack.IsPersisted = 1; ingredientStack.ParentId = foodBagId; ingredientStack.Type = StackTypes.Ingredient; ctx.ObjectStacks.Add(ingredientStack); } else { ctx.ObjectStacks.Update(ingredientStack); } } foreach (var recipeStack in foodBag.RecipeStacks) { if (recipeStack.IsPersisted == 0) { recipeStack.IsPersisted = 1; recipeStack.ParentId = foodBagId; recipeStack.Type = StackTypes.Recipe; ctx.ObjectStacks.Add(recipeStack); } else { ctx.ObjectStacks.Update(recipeStack); } } var descp = ctx.ObjectMetas.FirstOrDefault(m => m.ObjectId == foodBagId && m.Name == "description"); if (descp != null) { descp.Value = foodBag.Description; ctx.ObjectMetas.Update(descp); } ctx.SaveChanges(); } return(foodBag); }
public void OnTriggerEnter(Collider other) { FoodBag foodBag = other.GetComponent <FoodBag>(); if (foodBag == null || foodBag.AttatchedHydrator != null || foodBag.IsHydrated || Hydrator.AttatchedBag != null) { return; } foodBag.AttatchedHydrator = Hydrator; Debug.Log("Snapping bag to hydrator"); Rigidbody otherRb = other.GetComponent <Rigidbody>(); other.transform.parent = transform.parent; other.transform.localRotation = Quaternion.Euler(0, 180, 0); other.transform.localPosition = new Vector3(0.233f, 0, 0); otherRb.isKinematic = true; Hydrator.HydrateBag(other.gameObject); }
private void TryGrab() { Collider[] cols = Physics.OverlapSphere(_grabCenter.position, .75f, _interactObj); if (cols != null && cols.Length > 0) { if (cols[0].CompareTag("Donor")) { BloodDonor donor = (cols[0].GetComponent <BloodDonor>()); if (donor.state != BloodDonor.State.taking && donor.state != BloodDonor.State.leave && donor.state != BloodDonor.State.rageQuit) { AttachObj(donor, _attrachAnchor); SetBul(true, sprites[(int)donor.bloodInfo.type - 1], "" + donor.bloodInfo.family); ResetHighlightAndBul(false); } else if (donor.state == BloodDonor.State.rageQuit) { donor.PlayRageSound(); } } else if (cols[0].CompareTag("Bloodbag")) { BloodBag bloodbag = (cols[0].GetComponent <BloodBag>()); AttachObj(bloodbag, _grabCenter); SetBul(true, sprites[(int)bloodbag.bloodInfo.type - 1], "" + bloodbag.bloodInfo.family); ResetHighlightAndBul(false); } else if (cols[0].CompareTag("FoodBag")) { FoodBag bloodbag = (cols[0].GetComponent <FoodBag>()); AttachObj(bloodbag, _grabCenter); ResetHighlightAndBul(true); } } else { cols = Physics.OverlapSphere(_grabCenter.position, .75f, _interactPlace); if (cols != null && cols.Length > 0) { if (cols[0].CompareTag("BloodShelf") || cols[0].CompareTag("FoodShelf")) { Shelf shelf = cols[0].GetComponent <Shelf>(); if (shelf != null) { DragableObj b = shelf.TakeOut(); if (b != null) { AttachObj(b, _grabCenter); if (b is BloodBag) { BloodBag bloodBag = ((BloodBag)b); SetBul(true, sprites[(int)bloodBag.bloodInfo.type - 1], "" + bloodBag.bloodInfo.family); } } } } else if (cols[0].CompareTag("CallCenter")) { CallCenter cc = cols[0].GetComponent <CallCenter>(); if (cc != null) { cc.Open(this); } } } } }