void StoreRecipe(RecipeConfig recipe) { if (TabletopManager.IsInMansus()) { return; } var situation = this.GetOpenSituation(); if (situation == null) { return; } var slots = situation.situationWindow.GetStartingSlots(); var elements = slots.Select(x => ValidRecipeSlotOrNull(x)).Select(x => x?.GetElementStackInSlot()?.EntityId); recipe.Situation = situation.GetTokenId(); recipe.RecipeElements = elements.ToArray(); }
void Update() { //检测操作相关的操作 try { var situation = this.GetOpenSituation();//当没打开situation时这个函数会报错 if (!TabletopManager.IsInMansus() && situation != null) { var Situation = situation.GetTokenId(); if (Input.GetKeyDown(KeyCode.F1) && situation.SituationClock.State == SituationState.Unstarted) //保存配方 { if (!Recipes.ContainsKey(Situation)) { Recipes[Situation] = new RecipeConfig(); } this.StoreRecipe(Recipes[Situation]); this.Notify("automation", "Recipe added"); } if (Input.GetKeyDown(KeyCode.F2))//取消配方 { Recipes.Remove(Situation); SoundManager.PlaySfx("CardDragFail"); this.Notify("automation", "Recipe canceled"); } if (Input.GetKeyDown(KeyCode.F3)) //调试用:立即执行该配方 { this.Logger.LogError("F3"); this.RestoreRecipe(Recipes[Situation], true); } } }catch (Exception e) { } //自动执行 if (DateTime.Now.Ticks - this.startTime > 10000 * 100) { startTime = DateTime.Now.Ticks; foreach (var item in Recipes.ToList()) { this.RestoreRecipe(item.Value, true); } startTime = DateTime.Now.Ticks; } }
void RestoreRecipe(RecipeConfig recipe, bool executeOnRestore) { var situation = this.GetSituation(recipe.Situation); if (situation == null) { return; } this.Logger.LogError(" " + situation.SituationClock.State); switch (situation.SituationClock.State) { //case SituationState.RequiringExecution: case SituationState.Complete: situation.situationWindow.DumpAllResultingCardsToDesktop(); break; case SituationState.Unstarted: situation.situationWindow.DumpAllStartingCardsToDesktop(); break; default: //SoundManager.PlaySfx("CardDragFail"); //this.Notify("I am busy", "I cannot start a recipe while I am busy doing somthing else."); return; } // The first slot is the primary slot, so slot it independently. // A successful slot here may cause new slots to be added. var primaryElement = recipe.RecipeElements.FirstOrDefault(); //if (primaryElement == null) return;//针对无卡 if (primaryElement != null) { var slot = situation.situationWindow.GetStartingSlots().FirstOrDefault(); if (!slot || !this.TryPopulateSlot(slot, primaryElement)) { //this.Notify("Something is missing", "I cannot start this recipe, as I am missing a critical component."); return; } } // Slot the remainder of the elements, now that // the primary has opened up new slots for us. var slots = situation.situationWindow.GetStartingSlots(); for (var i = 1; i < Math.Min(slots.Count, recipe.RecipeElements.Length); i++) { var element = recipe.RecipeElements[i]; var slot = slots[i]; this.TryPopulateSlot(slot, element); } if (executeOnRestore) { situation.AttemptActivateRecipe(); if (situation.SituationClock.State == SituationState.Unstarted) { this.Notify("Something went wrong", "I could not start the recipe."); this.Logger.LogError("I could not start the recipe."); situation.OpenWindow(); } // If we started the recipe, there is no need to open the window. } else { situation.OpenWindow(); } }