private void TrySelectPokemon(PokeBoxTagStructure tag)
 {
     IPokemon pkm = tag.Control.pokeContainer[tag.BoxIndex];
     if (mode == PokeBoxControlModes.MovePokemon && pkm != null) {
         bool safeToSelect = true;
         // Make sure we don't select every pokemon in a party. Otherwise we could move them all outside of the party and make the game unsafe.
         if (tag.Control.IsViewingParty && !PokeManager.IsPokemonSelected(pkm)) {
             safeToSelect = false;
             foreach (IPokemon partyPkm in tag.Control.pokeContainer) {
                 if (!PokeManager.IsPokemonSelected(partyPkm) && partyPkm != pkm) {
                     safeToSelect = true;
                     break;
                 }
             }
         }
         // Note: Temporarily dissallowing party selection
         if (IsViewingBox) {
             PokeManager.TogglePokemonSelection(pkm);
             PokeManager.RefreshUI();
             /*if (PokeManager.IsPokemonSelected(pkm)) {
                 if (tag.Control.IsViewingParty) {
                     tag.Control.partySelectMasks[tag.BoxIndex].OpacityMask = new ImageBrush(pkm.BoxSprite);
                     tag.Control.partySelectMasks[tag.BoxIndex].Visibility = Visibility.Visible;
                 }
                 else {
                     tag.Control.boxSelectMasks[tag.BoxIndex].OpacityMask = new ImageBrush(pkm.BoxSprite);
                     tag.Control.boxSelectMasks[tag.BoxIndex].Visibility = Visibility.Visible;
                 }
             }
             else {
                 if (tag.Control.IsViewingParty) {
                     tag.Control.partySelectMasks[tag.BoxIndex].OpacityMask = null;
                     tag.Control.partySelectMasks[tag.BoxIndex].Visibility = Visibility.Hidden;
                 }
                 else {
                     tag.Control.boxSelectMasks[tag.BoxIndex].OpacityMask = null;
                     tag.Control.boxSelectMasks[tag.BoxIndex].Visibility = Visibility.Hidden;
                 }
             }*/
         }
     }
 }
        private void TryMovePokemon(PokeBoxTagStructure tag)
        {
            IPokemon pkm = tag.Control.pokeContainer[tag.BoxIndex];
            if (mode == PokeBoxControlModes.MovePokemon) {
                if (PokeManager.IsHoldingPokemon) {
                    if (!PokeManager.CanSafelyPlaceHeldUnknownItem(tag.Control.pokeContainer)) {
                        MessageBoxResult unknownItemResult = TriggerMessageBox.Show(Window.GetWindow(this), "A Pokémon that you are holding is holding an Unknown Item. Sending it to a different game may cause problems. Are you sure you want to place it?", "Unknown Item", MessageBoxButton.YesNo);
                        if (unknownItemResult == MessageBoxResult.No)
                            return;
                    }
                    if (!PokeManager.CanPlaceShadowPokemon(tag.Control.pokeContainer)) {
                        TriggerMessageBox.Show(Window.GetWindow(this), "Cannot move Shadow Pokémon to a different game until they have been purified", "Can't Place");
                    }
                    else if (!PokeManager.CanPlaceEgg(tag.Control.pokeContainer)) {
                        TriggerMessageBox.Show(Window.GetWindow(this), "Cannot move eggs to Colosseum or XD", "Can't Place");
                    }
                    else if (tag.Control.IsViewingPurifier && tag.BoxIndex != 0 && PokeManager.HoldPokemon.Pokemon.IsShadowPokemon) {
                        TriggerMessageBox.Show(Window.GetWindow(this), "Cannot put Shadow Pokémon in that Purifier slot", "No Shadow Pokémon");
                    }
                    else if (tag.Control.IsViewingPurifier && tag.BoxIndex == 0 && !PokeManager.HoldPokemon.Pokemon.IsShadowPokemon) {
                        TriggerMessageBox.Show(Window.GetWindow(this), "Only Shadow Pokémon can go in that Purifier slot", "No Regular Pokémon");
                    }
                    else if (pkm == null) {
                        if (PokeManager.IsHoldingSelection) {
                            if (tag.Control.IsViewingPurifier) {
                                TriggerMessageBox.Show(Window.GetWindow(this), "Cannot place a selection in the Purifier", "No Selections Allowed");
                            }
                            else if (tag.Control.IsViewingDaycare) {
                                TriggerMessageBox.Show(Window.GetWindow(this), "Cannot place a selection in the Daycare", "No Selections Allowed");
                            }
                            else if (tag.Control.IsViewingParty) {
                                TriggerMessageBox.Show(Window.GetWindow(this), "Cannot place a selection in your party", "No Selections Allowed");
                            }
                            else if (tag.Control.pokeContainer.PokePC.HasRoomForPokemon(PokeManager.NumSelectedPokemon)) {
                                PokeManager.PlaceSelection(tag.Control.pokeContainer, tag.BoxIndex);
                                RefreshUI();
                                PokemonViewer.RefreshUI();
                                PokeManager.ManagerWindow.RefreshSearchResultsUI();
                                PokeManager.ManagerWindow.RefreshStoredPokemon();
                            }
                            else {
                                TriggerMessageBox.Show(Window.GetWindow(this), "Not enough room to place the selected Pokémon", "No Room");
                            }
                        }
                        else if (tag.Control.IsViewingDaycare && PokeManager.HoldPokemon.Pokemon.IsShadowPokemon && tag.Control.pokeContainer.GameType == GameTypes.XD) {
                            TriggerMessageBox.Show(Window.GetWindow(this), "Cannot put Shadow Pokémon in the daycare in XD", "No Shadow Pokémon");
                        }
                        else if (tag.Control.IsViewingDaycare && PokeManager.HoldPokemon.Pokemon.IsEgg) {
                            TriggerMessageBox.Show(Window.GetWindow(this), "Cannot put Eggs in the daycare", "No Eggs");
                        }
                        else {
                            PokeManager.PlacePokemon(tag.Control.pokeContainer, tag.BoxIndex);
                            RefreshUI();
                            PokemonViewer.RefreshUI();
                            PokeManager.ManagerWindow.RefreshSearchResultsUI();
                            PokeManager.ManagerWindow.RefreshStoredPokemon();
                        }
                    }
                    else if (!PokeManager.CanSwitchShadowPokemon(pkm)) {
                        TriggerMessageBox.Show(Window.GetWindow(this), "Cannot switch with that Pokémon. There is nowhere to safely force drop the Shadow Pokémon", "Nowhere to Drop");
                    }
                    else if (!PokeManager.CanSwitchEgg(pkm)) {
                        TriggerMessageBox.Show(Window.GetWindow(this), "Cannot switch with that Pokémon. There is nowhere to safely force drop the Egg", "Nowhere to Drop");
                    }
                    else if (PokeManager.CanSwitchPokemon(pkm)) {
                        MessageBoxResult daycareResult = MessageBoxResult.OK;
                        bool refreshAll = false;
                        if (tag.Control.IsViewingDaycare) {
                            if (PokeManager.HoldPokemon.Pokemon.IsShadowPokemon && tag.Control.pokeContainer.GameType == GameTypes.XD) {
                                TriggerMessageBox.Show(Window.GetWindow(this), "Cannot put Shadow Pokémon in the daycare in XD", "No Shadow Pokémon");
                                daycareResult = MessageBoxResult.Cancel;
                            }
                            else if (tag.Control.IsViewingDaycare && PokeManager.HoldPokemon.Pokemon.IsEgg) {
                                TriggerMessageBox.Show(Window.GetWindow(this), "Cannot put Eggs in the daycare", "No Eggs");
                                daycareResult = MessageBoxResult.Cancel;
                            }
                            else {
                                uint cost = tag.Control.Daycare.GetWithdrawCost(tag.BoxIndex);
                                if (cost != 0) {
                                    if (pkm.GameSave.Money >= cost) {
                                        daycareResult = TriggerMessageBox.Show(Window.GetWindow(this), "If you would like to take back " + pkm.Nickname + " from the daycare, it will cost $" + cost.ToString("#,0"), "Daycare Fee", MessageBoxButton.OKCancel);
                                        if (daycareResult == MessageBoxResult.OK)
                                            pkm.GameSave.Money -= cost;
                                    }
                                    else {
                                        TriggerMessageBox.Show(Window.GetWindow(this), "You do not have enough Pokédollars to withdraw " + pkm.Nickname + ". You need $" + cost.ToString("#,0"), "Not Enough Money");
                                        daycareResult = MessageBoxResult.Cancel;
                                    }
                                }
                                if (daycareResult == MessageBoxResult.OK && pkm.PokeContainer is GBADaycare) {
                                    GBADaycare daycare = (GBADaycare)pkm.PokeContainer;
                                    if (daycare.HasLearnedNewMoves(pkm.ContainerIndex)) {
                                        daycareResult = TriggerMessageBox.Show(Window.GetWindow(this), "Would you like to keep the new moves " + pkm.Nickname + " has learned in the daycare?", "Keep New Moves", MessageBoxButton.YesNo);
                                        if (daycareResult == MessageBoxResult.No) {
                                            daycare.CancelLearnedMoves(pkm.ContainerIndex);
                                            PokemonViewer.RefreshUI();
                                        }
                                    }
                                }
                            }
                        }

                        if (daycareResult != MessageBoxResult.Cancel) {
                            IPokemon switchPokemon = PokeManager.HoldPokemon.Pokemon;
                            PokeManager.SwitchPokemon(pkm);
                            if (refreshAll) {
                                PokeManager.RefreshUI();
                            }
                            else {
                                RefreshUI();
                                PokemonViewer.RefreshUI();
                                PokeManager.ManagerWindow.RefreshSearchResultsUI();
                            }
                        }
                    }
                    else if (PokeManager.IsPartyHoldingMail(pkm.PokeContainer)) {
                        TriggerMessageBox.Show(Window.GetWindow(this), "Cannot switch with that Pokémon. One of the Pokémon in your party is holding mail. To remove the mail goto the mailbox tab and click Take Mail From Party", "Can't Pickup");
                    }
                    else {
                        TriggerMessageBox.Show(Window.GetWindow(this), "Cannot switch with that Pokémon. It is the last valid Pokémon in your party", "Can't Pickup");
                    }
                }
                else if (pkm != null) {
                    MessageBoxResult daycareResult = MessageBoxResult.OK;
                    if (tag.Control.IsViewingDaycare) {
                        uint cost = tag.Control.Daycare.GetWithdrawCost(tag.BoxIndex);
                        if (cost != 0) {
                            if (pkm.GameSave.Money >= cost) {
                                daycareResult = TriggerMessageBox.Show(Window.GetWindow(this), "If you would like to take back " + pkm.Nickname + " from the daycare, it will cost $" + cost.ToString("#,0"), "Daycare Fee", MessageBoxButton.OKCancel);
                                if (daycareResult == MessageBoxResult.OK)
                                    pkm.GameSave.Money -= cost;
                            }
                            else {
                                TriggerMessageBox.Show(Window.GetWindow(this), "You do not have enough Pokédollars to withdraw " + pkm.Nickname + ". You need $" + cost.ToString("#,0"), "Not Enough Money");
                                daycareResult = MessageBoxResult.Cancel;
                            }
                        }
                        if (daycareResult == MessageBoxResult.OK && pkm.PokeContainer is GBADaycare) {
                            GBADaycare daycare = (GBADaycare)pkm.PokeContainer;
                            if (daycare.HasLearnedNewMoves(pkm.ContainerIndex)) {
                                daycareResult = TriggerMessageBox.Show(Window.GetWindow(this), "Would you like to keep the new moves " + pkm.Nickname + " has learned in the daycare?", "Keep New Moves", MessageBoxButton.YesNo);
                                if (daycareResult == MessageBoxResult.No) {
                                    daycare.CancelLearnedMoves(pkm.ContainerIndex);
                                    PokemonViewer.RefreshUI();
                                }
                            }
                        }
                    }

                    if (daycareResult != MessageBoxResult.Cancel) {
                        if (PokeManager.IsPokemonSelected(pkm))
                            PokeManager.PickupSelection(this);
                        else if (PokeManager.CanPickupPokemon(pkm))
                            PokeManager.PickupPokemon(pkm, this);
                        else if (PokeManager.IsPartyHoldingMail(pkm.PokeContainer))
                            TriggerMessageBox.Show(Window.GetWindow(this), "Cannot pickup that Pokémon. One of the Pokémon in your party is holding mail. To remove the mail goto the mailbox tab and click Take Mail From Party", "Can't Pickup");
                        else
                            TriggerMessageBox.Show(Window.GetWindow(this), "Cannot pickup that Pokémon. It is the last valid Pokémon in your party", "Can't Pickup");
                        RefreshUI();
                    }
                }
            }
        }