public FeedEvent(EntityUid user, FoodComponent food, Solution foodSolution, List <UtensilComponent> utensils) { User = user; Food = food; FoodSolution = foodSolution; Utensils = utensils; }
/// <summary> /// Feed someone else /// </summary> private void OnFeedFood(EntityUid uid, FoodComponent foodComponent, AfterInteractEvent args) { if (args.Handled || args.Target == null) { return; } if (!_actionBlockerSystem.CanInteract(args.User) || !_actionBlockerSystem.CanUse(args.User)) { return; } if (!args.User.InRangeUnobstructed(uid, popup: true)) { args.Handled = true; return; } if (args.User == args.Target) { args.Handled = TryUseFood(uid, args.User); return; } if (!args.User.InRangeUnobstructed(args.Target.Value, popup: true)) { args.Handled = true; return; } args.Handled = TryForceFeed(uid, args.User, args.Target.Value); }
private void AddEatVerb(EntityUid uid, FoodComponent component, GetVerbsEvent <InteractionVerb> ev) { if (component.CancelToken != null) { return; } if (uid == ev.User || !ev.CanInteract || !ev.CanAccess || !EntityManager.TryGetComponent(ev.User, out SharedBodyComponent? body) || !_bodySystem.TryGetComponentsOnMechanisms <StomachComponent>(ev.User, out var stomachs, body)) { return; } if (EntityManager.TryGetComponent <MobStateComponent>(uid, out var mobState) && mobState.IsAlive()) { return; } InteractionVerb verb = new() { Act = () => { TryFeed(uid, ev.User, component); }, IconTexture = "/Textures/Interface/VerbIcons/cutlery.svg.192dpi.png", Text = Loc.GetString("food-system-verb-eat"), Priority = -1 }; ev.Verbs.Add(verb); }
/// <summary> /// If the user is currently force feeding someone, this cancels the attempt if they swap hands or otherwise /// loose the item. Prevents force-feeding dual-wielding. /// </summary> private void OnFoodDeselected(EntityUid uid, FoodComponent component, HandDeselectedEvent args) { if (component.CancelToken != null) { component.CancelToken.Cancel(); component.CancelToken = null; } }
/// <summary> /// Feed someone else /// </summary> private void OnFeedFood(EntityUid uid, FoodComponent foodComponent, AfterInteractEvent args) { if (args.Handled || args.Target == null || !args.CanReach) { return; } args.Handled = TryFeed(args.User, args.Target.Value, foodComponent); }
/// <summary> /// Eat item /// </summary> private void OnUseFoodInHand(EntityUid uid, FoodComponent foodComponent, UseInHandEvent ev) { if (ev.Handled) { return; } ev.Handled = TryFeed(ev.User, ev.User, foodComponent); }
public void Apply(IEntity entity) { var foodComponent = new FoodComponent(); var isSoda = ShouldBeSoda(); foodComponent.IsSoda = isSoda; foodComponent.FoodAmount = isSoda ? SodaValue : FoodValue; entity.AddComponents(foodComponent, new ViewComponent(), new RandomlyPlacedComponent()); }
public void EatMe(FoodComponent food) { if (!this.IsDead) { this._timeToRise += 1f; food.LocalPosition = new Vector2(-10f, -10f); // this kills it this._spriteAnimationComponent.Play(this._chompAnimation, false); this._spriteAnimationComponent.Enqueue(this._idleAnimation, true); } }
public HttpResponseMessage DeleteItem(FoodComponent item) { this.brep.DeleteItem(item); IEnumerable <FoodComponent> itemlist = this.brep.GetAllItems(item.ItemType); var response = Request.CreateResponse <IEnumerable <FoodComponent> >(System.Net.HttpStatusCode.Created, itemlist); return(response); }
void OnCollisionEnter(Collision collision) { FoodComponent foodComp = collision.gameObject.GetComponent <FoodComponent>(); if (foodComp != null) { Destroy(collision.gameObject); board.checkOrders(foodComp.food); } }
public FoodComponent SaveItem(FoodComponent item, ItemType type) { FoodComponent result = null; BaBuDataAccess bda = new BaBuDataAccess(); result = bda.SaveItem(item, type); return(result); }
public FoodComponent GetItem(int id, ItemType type) { FoodComponent result = null; BaBuDataAccess bda = new BaBuDataAccess(); result = bda.GetItem(id, type); return(result); }
public FoodComponent SaveItem(FoodComponent item, ItemType type) { FoodComponent result = new FoodComponent(); result.ID = 0; string connString = ConfigurationManager.ConnectionStrings["dbConn"].ToString().Trim(); string queryString; if (item.ID == 0) { queryString = @"INSERT INTO " + this.GetTableName(type) + " VALUES ( @name ); SELECT SCOPE_IDENTITY() AS 'newID' "; } else { queryString = @"UPDATE " + this.GetTableName(type) + " SET name = @name WHERE id = @id "; } SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(queryString, conn); cmd.Parameters.Add(new SqlParameter("@name", item.Name)); if (item.ID > 0) { cmd.Parameters.Add(new SqlParameter("@id", item.ID)); } SqlDataReader sdr; try { conn.Open(); sdr = cmd.ExecuteReader(CommandBehavior.SingleRow); if (sdr.Read()) { result = item; result.ID = Int32.Parse(sdr["newID"].ToString()); } } catch (Exception e) { throw e; } finally { conn.Close(); } return(result); }
public EateryViewController(IEateryView view, IFoodRepository foodRepository, ICurrencyRepository currencyRepository, CharacterManager characterManager) : base(view) { this.foodRepository = foodRepository; this.price = currencyRepository.FindByType(CurrencyType.Gold); this.currencies = characterManager.Character.Entity.GetComponent <CurrenciesComponent>(); this.foodComponent = characterManager.Character.Entity.GetComponent <FoodComponent>(); foreach (var pair in this.foodComponent.Foods) { this.foods.Add(pair.Key, pair.Value); } }
private void DeleteAndSpawnTrash(FoodComponent component, EntityUid?user = null) { //We're empty. Become trash. var position = EntityManager.GetComponent <TransformComponent>(component.Owner).Coordinates; var finisher = EntityManager.SpawnEntity(component.TrashPrototype, position); // If the user is holding the item if (user != null && _handsSystem.IsHolding(user.Value, component.Owner, out var hand)) { EntityManager.DeleteEntity((component).Owner); // Put the trash in the user's hand _handsSystem.TryPickup(user.Value, finisher, hand); return; } EntityManager.QueueDeleteEntity(component.Owner); }
private bool TryGetRequiredUtensils(EntityUid user, FoodComponent component, out List <UtensilComponent> utensils, HandsComponent?hands = null) { utensils = new List <UtensilComponent>(); if (component.Utensil != UtensilType.None) { return(true); } if (!Resolve(user, ref hands, false)) { return(false); } var usedTypes = UtensilType.None; foreach (var item in _handsSystem.EnumerateHeld(user, hands)) { // Is utensil? if (!EntityManager.TryGetComponent(item, out UtensilComponent? utensil)) { continue; } if ((utensil.Types & component.Utensil) != 0 && // Acceptable type? (usedTypes & utensil.Types) != utensil.Types) // Type is not used already? (removes usage of identical utensils) { // Add to used list usedTypes |= utensil.Types; utensils.Add(utensil); } } // If "required" field is set, try to block eating without proper utensils used if (component.UtensilRequired && (usedTypes & component.Utensil) != component.Utensil) { _popupSystem.PopupEntity(Loc.GetString("food-you-need-to-hold-utensil", ("utensil", component.Utensil ^ usedTypes)), user, Filter.Entities(user)); return(false); } return(true); }
/// <summary> /// Eat item /// </summary> private void OnUseFoodInHand(EntityUid uid, FoodComponent foodComponent, UseInHandEvent ev) { if (ev.Handled) { return; } if (!_actionBlockerSystem.CanInteract(ev.User) || !_actionBlockerSystem.CanUse(ev.User)) { return; } if (!ev.User.InRangeUnobstructed(uid, popup: true)) { ev.Handled = true; return; } ev.Handled = TryUseFood(uid, ev.User); }
public GetComponentPercentageByDailyEnergyResponse GetComponentPercentageByDailyEnergy() { GetComponentPercentageByDailyEnergyResponse result; try { List <FoodComponent> dailyComponentList = new List <FoodComponent>(); FoodComponent dailyComponent = new FoodComponent(); dailyComponent.Name = "蛋白质"; dailyComponent.EnglishName = "Protein"; dailyComponent.NameCode = "P"; dailyComponent.Value = 14; dailyComponent.Unit = "%"; dailyComponentList.Add(dailyComponent); dailyComponent = new FoodComponent(); dailyComponent.Name = "脂肪"; dailyComponent.EnglishName = "Fats"; dailyComponent.NameCode = "F"; dailyComponent.Value = 27; dailyComponent.Unit = "%"; dailyComponentList.Add(dailyComponent); dailyComponent = new FoodComponent(); dailyComponent.Name = "碳水化合物"; dailyComponent.EnglishName = "Carbohydrates"; dailyComponent.NameCode = "C"; dailyComponent.Value = 59; dailyComponent.Unit = "%"; dailyComponentList.Add(dailyComponent); result = new GetComponentPercentageByDailyEnergyResponse(); result.ComponentList = dailyComponentList; } catch (Exception) { return(null); } return(result); }
public FoodComponent GetItem(int id, ItemType type) { FoodComponent result = null; string connString = ConfigurationManager.ConnectionStrings["dbConn"].ToString().Trim(); string queryString = @"SELECT * FROM " + this.GetTableName(type) + " (NOLOCK) WHERE ID = @userID"; SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(queryString, conn); cmd.Parameters.Add(new SqlParameter("@id", id)); SqlDataReader sdr; try { conn.Open(); sdr = cmd.ExecuteReader(CommandBehavior.SingleRow); if (sdr.Read()) { result = new FoodComponent { ID = Int32.Parse(sdr["id"].ToString()), Name = sdr["name"].ToString() }; } } catch (Exception e) { throw e; } finally { conn.Close(); } return(result); }
private void DeleteAndSpawnTrash(FoodComponent component, EntityUid?user = null) { //We're empty. Become trash. var position = EntityManager.GetComponent <TransformComponent>(component.Owner).Coordinates; var finisher = EntityManager.SpawnEntity(component.TrashPrototype, position); // If the user is holding the item if (user != null && EntityManager.TryGetComponent(user.Value, out HandsComponent? handsComponent) && handsComponent.IsHolding(component.Owner)) { EntityManager.DeleteEntity((component).Owner); // Put the trash in the user's hand if (EntityManager.TryGetComponent(finisher, out SharedItemComponent? item) && handsComponent.CanPutInHand(item)) { handsComponent.PutInHand(item); } return; } EntityManager.QueueDeleteEntity(component.Owner); }
public bool DeleteItem(FoodComponent item) { BaBuLogic ul = new BaBuLogic(); return(ul.DeleteUser(item.ID, item.ItemType)); }
public GetDailyFoodComponentResponse GetDailyFoodComponent(float dailyEnergy, string pNameCode, float pValue, string fNameCode, float fValue, string cNameCode, float cValue) { GetDailyFoodComponentResponse result; try { //蛋白质能量(kcal) float proteinEnergy = (dailyEnergy * pValue) / 100f; //蛋白质重量(g) float proteinWeight = proteinEnergy / 4f; //脂肪能量(kcal) float fatsEnergy = (dailyEnergy * fValue) / 100f; //脂肪重量(g) float fatsWeight = fatsEnergy / 9f; //碳水化合物能量(kcal) float carbohydratesEnergy = (dailyEnergy * cValue) / 100f; //碳水化合物重量(g) float carbohydratesWeight = carbohydratesEnergy / 4f; //3,4,3分配方式 List <MealFoodComponent> mealFoodComponentList = new List <MealFoodComponent>(); MealFoodComponent mealFoodComponent; List <FoodComponent> foodComponentList; #region 早餐 foodComponentList = new List <FoodComponent>(); FoodComponent foodComponent = new FoodComponent(); foodComponent.Name = "蛋白质"; foodComponent.EnglishName = "Protein"; foodComponent.NameCode = pNameCode; foodComponent.Value = proteinWeight / 3f; foodComponent.Unit = "g"; foodComponentList.Add(foodComponent); foodComponent = new FoodComponent(); foodComponent.Name = "脂肪"; foodComponent.EnglishName = "Fats"; foodComponent.NameCode = fNameCode; foodComponent.Value = fatsWeight / 3f; foodComponent.Unit = "g"; foodComponentList.Add(foodComponent); foodComponent = new FoodComponent(); foodComponent.Name = "碳水化合物"; foodComponent.EnglishName = "Carbohydrates"; foodComponent.NameCode = cNameCode; foodComponent.Value = carbohydratesWeight / 3f; foodComponent.Unit = "g"; foodComponentList.Add(foodComponent); mealFoodComponent = new MealFoodComponent(); mealFoodComponent.Name = "早餐"; mealFoodComponent.EnglishName = "Breakfast"; mealFoodComponent.ComponentList = foodComponentList; mealFoodComponentList.Add(mealFoodComponent); #endregion 早餐 #region 午餐 foodComponentList = new List <FoodComponent>(); foodComponent = new FoodComponent(); foodComponent.Name = "蛋白质"; foodComponent.EnglishName = "Protein"; foodComponent.NameCode = pNameCode; foodComponent.Value = proteinWeight / 4f; foodComponent.Unit = "g"; foodComponentList.Add(foodComponent); foodComponent = new FoodComponent(); foodComponent.Name = "脂肪"; foodComponent.EnglishName = "Fats"; foodComponent.NameCode = fNameCode; foodComponent.Value = fatsWeight / 4f; foodComponent.Unit = "g"; foodComponentList.Add(foodComponent); foodComponent = new FoodComponent(); foodComponent.Name = "碳水化合物"; foodComponent.EnglishName = "Carbohydrates"; foodComponent.NameCode = cNameCode; foodComponent.Value = carbohydratesWeight / 4f; foodComponent.Unit = "g"; foodComponentList.Add(foodComponent); mealFoodComponent = new MealFoodComponent(); mealFoodComponent.Name = "午餐"; mealFoodComponent.EnglishName = "Lunch"; mealFoodComponent.ComponentList = foodComponentList; mealFoodComponentList.Add(mealFoodComponent); #endregion 午餐 #region 晚餐 foodComponentList = new List <FoodComponent>(); foodComponent = new FoodComponent(); foodComponent.Name = "蛋白质"; foodComponent.EnglishName = "Protein"; foodComponent.NameCode = pNameCode; foodComponent.Value = proteinWeight / 3f; foodComponent.Unit = "g"; foodComponentList.Add(foodComponent); foodComponent = new FoodComponent(); foodComponent.Name = "脂肪"; foodComponent.EnglishName = "Fats"; foodComponent.NameCode = fNameCode; foodComponent.Value = fatsWeight / 3f; foodComponent.Unit = "g"; foodComponentList.Add(foodComponent); foodComponent = new FoodComponent(); foodComponent.Name = "碳水化合物"; foodComponent.EnglishName = "Carbohydrates"; foodComponent.NameCode = cNameCode; foodComponent.Value = carbohydratesWeight / 3f; foodComponent.Unit = "g"; foodComponentList.Add(foodComponent); mealFoodComponent = new MealFoodComponent(); mealFoodComponent.Name = "晚餐"; mealFoodComponent.EnglishName = "Dinner"; mealFoodComponent.ComponentList = foodComponentList; mealFoodComponentList.Add(mealFoodComponent); #endregion 晚餐 result = new GetDailyFoodComponentResponse(); result.MealList = mealFoodComponentList; } catch (Exception) { return(null); } return(result); }
public bool TryFeed(EntityUid user, EntityUid target, FoodComponent food) { // if currently being used to feed, cancel that action. if (food.CancelToken != null) { food.CancelToken.Cancel(); food.CancelToken = null; return(true); } if (food.Owner == user || //Suppresses self-eating EntityManager.TryGetComponent <MobStateComponent>(food.Owner, out var mobState) && mobState.IsAlive()) // Suppresses eating alive mobs { return(false); } // Target can't be fed if (!EntityManager.HasComponent <SharedBodyComponent>(target)) { return(false); } if (!_solutionContainerSystem.TryGetSolution(food.Owner, food.SolutionName, out var foodSolution)) { return(false); } if (food.UsesRemaining <= 0) { _popupSystem.PopupEntity(Loc.GetString("food-system-try-use-food-is-empty", ("entity", food.Owner)), user, Filter.Entities(user)); DeleteAndSpawnTrash(food, user); return(false); } if (IsMouthBlocked(target, user)) { return(false); } if (!TryGetRequiredUtensils(user, food, out var utensils)) { return(false); } if (!_interactionSystem.InRangeUnobstructed(user, food.Owner, popup: true)) { return(true); } var forceFeed = user != target; food.CancelToken = new CancellationTokenSource(); if (forceFeed) { EntityManager.TryGetComponent(user, out MetaDataComponent? meta); var userName = meta?.EntityName ?? string.Empty; _popupSystem.PopupEntity(Loc.GetString("food-system-force-feed", ("user", userName)), user, Filter.Entities(target)); // logging _logSystem.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(user):user} is forcing {ToPrettyString(target):target} to eat {ToPrettyString(food.Owner):food} {SolutionContainerSystem.ToPrettyString(foodSolution)}"); } var moveBreak = user != target; _doAfterSystem.DoAfter(new DoAfterEventArgs(user, forceFeed ? food.ForceFeedDelay : food.Delay, food.CancelToken.Token, target) { BreakOnUserMove = moveBreak, BreakOnDamage = true, BreakOnStun = true, BreakOnTargetMove = moveBreak, MovementThreshold = 0.01f, TargetFinishedEvent = new FeedEvent(user, food, foodSolution, utensils), BroadcastCancelledEvent = new ForceFeedCancelledEvent(food), NeedHand = true, }); return(true); }
public ForceFeedCancelledEvent(FoodComponent food) { Food = food; }
public FoodComponent SaveUser(FoodComponent item) { BaBuLogic bl = new BaBuLogic(); return(bl.SaveItem(item, item.ItemType)); }