void GenerateDeck() { foodDeck.Clear(); for (int foodIndex = 0; foodIndex < k.FoodData.Count; foodIndex++) { FoodChance result = foodChances.Find(x => x.name == k.FoodData[foodIndex].type); for (int oneFoodAmount = 0; oneFoodAmount < 10 /*Math.Floor(result.chance*100)*/; oneFoodAmount++) { foodDeck.Add(foodIndex); } } Shuffle(foodDeck); }
public override void _Ready() { placeSound = (AudioStreamPlayer)GetNode("Place"); SlotPrefab = (PackedScene)ResourceLoader.Load("res://Instances/Slot.tscn"); FoodPrefab = (PackedScene)ResourceLoader.Load("res://Instances/Food.tscn"); k = (Kitchen)GetNode("../../Kitchen"); foreach (FoodInfo fi in k.FoodData) { foodChances.Add(new FoodChance(fi.type)); } float totalFoodItems = 0; foreach (Recipe re in k.recipes) { foreach (string ingredient in re.ingredients) { totalFoodItems += 1; FoodChance result = foodChances.Find(x => x.name == ingredient); if (result != null) { result.chance += 1; } } } foreach (FoodChance fc in foodChances) { fc.chance /= totalFoodItems; } GenerateDeck(); for (int y = 0; y < 2; y++) { for (int x = 0; x < 4; x++) { Slot NewSlot = (Slot)SlotPrefab.Instance(); NewSlot.SetPosition(new Vector2((x * 64) + 32, (y * 64) + 32)); NewSlot.place = Slot.PLACE.TABLE; Slots.Add(NewSlot); AddChild(NewSlot); } } SetProcess(true); }