static void Postfix(ElementStackToken __instance, string elementId) { ElementStackToken token = null; // Find the newly created stack foreach (var stack in Registry.Retrieve <TabletopManager>()._tabletop.GetElementStacksManager().GetStacks().OfType <ElementStackToken>()) { if (stack.transform.position == __instance.transform.position && stack.EntityId == elementId) { token = stack; break; } } if (token == null) { return; } foreach (var stack in Registry.Retrieve <TabletopManager>()._tabletop.GetElementStacksManager().GetStacks().OfType <ElementStackToken>()) { if (token != stack && token.CanInteractWithTokenDroppedOn(stack)) { // Manually combine stacks stack.SetQuantity(stack.Quantity + token.Quantity); token.Retire(false); //FileLog.Log("__instance = " + __instance.SaveLocationInfo + " token = " + token.SaveLocationInfo + " stack = " + stack.SaveLocationInfo); return; } } }
// Instantly moves card into slot public static void MoveStackIntoSlot(ElementStackToken elementStack, RecipeSlot slot) { // Make sure slot and stack are valid and empty and we have a match // Abort with feedback if we don't if (!(Validator.Available(elementStack) && Validator.Available(slot) && StackMatchesSlot(elementStack, slot))) { SoundManager.PlaySfx("CardDragFail"); return; } // Remove glow so that it won't flicker when moved elementStack.ShowGlow(false, true); // Force stack to remember its last position elementStack.lastTablePos = new Vector2?(elementStack.RectTransform.anchoredPosition); if (elementStack.Quantity != 1) { IElementStack newStack = elementStack.SplitAllButNCardsToNewStack(elementStack.Quantity - 1, new Context(Context.ActionSource.PlayerDrag)); slot.AcceptStack(newStack, new Context(Context.ActionSource.PlayerDrag)); } else { slot.AcceptStack(elementStack, new Context(Context.ActionSource.PlayerDrag)); } }
static bool Prefix(ElementStackToken __instance, Context context) { //FileLog.Log("ElementStackToken_ReturnToTabletop_Patch v2"); if (Registry.Retrieve <ICompendium>().GetElementById(__instance.EntityId).Unique) { return(true); } foreach (var stack in Registry.Retrieve <TabletopManager>()._tabletop.GetElementStacksManager().GetStacks().OfType <ElementStackToken>()) { // Make sure we're merging into a stack that's on the tabletop - otherwise we can lose elements forever if (stack.IsInAir || stack.transform.parent.GetComponent <TabletopTokenContainer>() == null) { continue; } if (stack == __instance) { continue; } if (__instance.CanInteractWithTokenDroppedOn(stack)) { // Manually combine stacks stack.SetQuantity(stack.Quantity + __instance.Quantity); __instance.Retire(false); return(false); } } return(true); }
public static List <SituationController> GetSituationsRelativeTo(ElementStackToken stack) { return(GameBoard.GetAllSituations() .OrderBy(situ => GetDistanceBetween(GetPosition(situ), GetPosition(stack))) .ThenByDescending(o => GetPosition(o)[1]) // Order by y (higher first) .ThenBy(o => GetPosition(o)[0]) // Order by x (lower first) .ToList()); }
// This runs right after an element (card) token is placed onto the table from elsewhere static void Postfix(ref ElementStackToken stack, Context context, Vector2?pos = null, bool pushOthers = false) { float x = stack.RectTransform.position.x; float y = stack.RectTransform.position.y; Utility.Snap(ref x, ref y); stack.RectTransform.position = new Vector3(x, y, stack.RectTransform.position.z); }
public static bool Available(ElementStackToken stack) { return(!( stack == null || stack.Equals(null) || stack.Defunct || stack.IsBeingAnimated || DraggableToken.itemBeingDragged == stack )); }
void PopulateSlot(RecipeSlot slot, ElementStackToken stack) { stack.lastTablePos = new Vector2?(stack.RectTransform.anchoredPosition); if (stack.Quantity != 1) { var newStack = stack.SplitAllButNCardsToNewStack(stack.Quantity - 1, new Context(Context.ActionSource.PlayerDrag)); slot.AcceptStack(newStack, new Context(Context.ActionSource.PlayerDrag)); } else { slot.AcceptStack(stack, new Context(Context.ActionSource.PlayerDrag)); } }
// Add a slot to fill to the queue of animations to perform public static void FillSlotEventually(TokenAndSlot tokenAndSlot, ElementStackToken elementStackToken) { SlotToFill slotToFill = new SlotToFill { TokenAndSlot = tokenAndSlot, ElementStackToken = elementStackToken }; if (Validator.Available(slotToFill) && !AlreadyHandlingSlotToFill(slotToFill)) { SlotsToFill.Add(slotToFill); } }
public static string GetRefinedDescription(Element elem, ElementStackToken token) { IAspectsDictionary aspects; if (token == null) { aspects = new AspectsDictionary(); aspects[elem.Id] = 1; } else { aspects = token.GetAspects(true); } var refiner = new TextRefiner(aspects); return(refiner.RefineString(elem.Description)); }
static bool Prefix(ElementStackToken __instance) { return(Patcher.Run(() => { // If neither shift is down give back control to the game immediately if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift)) { return true; } // Do not move cards in Mansus. Supporting this could be a future addition if (TabletopManager.IsInMansus()) { return false; } var stack = __instance; var situation = GameBoard.GetOpenSituation(); List <RecipeSlot> slots = null; if (situation == null) { foreach (var closedSituation in Positions.GetSituationsRelativeTo(stack)) { if (closedSituation.CanAcceptStackWhenClosed(stack)) { closedSituation.OpenWindow(); situation = closedSituation; break; } } } if (situation == null) { // Let controller handle the fail state SituSlotController.MoveStackIntoSlot(stack, null); } else { var populatedSlot = false; slots = SituSlotController.GetAllEmptySlots(situation); for (int i = 0; i < slots.Count; i++) { if (SituSlotController.StackMatchesSlot(stack, slots[i])) { SituSlotController.MoveStackIntoSlot(stack, slots[i]); populatedSlot = true; break; } } // There is no slot available for us, allow the controller to handle the fail state if (!populatedSlot) { SituSlotController.MoveStackIntoSlot(stack, null); } } return false; })); }
public static string GetRefinedDescription(Element elem, ElementStackToken token) { var refiner = new TextRefiner(token.GetAspects(true)); return(refiner.RefineString(elem.Description)); }
private static void MansusExitPostfix(Transform origin, ElementStackToken mansusCard) { GreatWorkAPI.Events.FireEvent(new MansusEvent.Exit.Post(origin, mansusCard)); }
public Post(Transform origin, ElementStackToken mansusCard) : base(origin, mansusCard) { }
public Exit(Transform origin, ElementStackToken mansusCard) { Origin = origin; MansusCard = mansusCard; }