Exemplo n.º 1
0
        public static void HandleDeckSave(object packet, Session session)
        {
            if (session.Player.ValidatedDeck.Count == 0)
            {
                LogManager.Write("Player", "Player {0} tried to save a deck without validating it!", session.Player.Id);
                return;
            }

            // scrolls sent are completly ignored by server, saved scrolls from DeckValidate are used instead
            var packetDeckSaveCli = (PacketDeckSave)packet;

            var deck = session.Player.GetDeck(packetDeckSaveCli.Name);
            if (deck != null)
            {
                // update current deck
                deck.Scrolls.Clear();
                foreach (var scrollId in session.Player.ValidatedDeck)
                    deck.Scrolls.Add(session.Player.GetScroll(scrollId));

                deck.Timestamp = (ulong)DateTime.UtcNow.Ticks;
                deck.CalculateResources();
                deck.Save();
            }
            else
            {
                // create new deck
                var newDeck = new Deck(session.Player, AssetManager.GetNewDeckInstanceId(), packetDeckSaveCli.Name,
                    (ulong)DateTime.UtcNow.Ticks, DeckFlags.None);

                foreach (var scrollId in session.Player.ValidatedDeck)
                    newDeck.Scrolls.Add(session.Player.GetScroll(scrollId));

                newDeck.CalculateResources();
                newDeck.Save();

                session.Player.Decks.Add(newDeck);
            }

            session.Player.ValidatedDeck.Clear();
            session.SendOkPacket("DeckSave");
        }
Exemplo n.º 2
0
        public void LoadDecks()
        {
            var deckResult = DatabaseManager.Database.Select("SELECT `id`, `name`, `timestamp`, `flags` FROM `account_deck` WHERE `accountId` = ?", Id);
            if (deckResult != null)
            {
                for (int i = 0; i < deckResult.Count; i++)
                {
                    var deck = new Deck(this, deckResult.Read<uint>(i, "id"), deckResult.Read<string>(i, "name"),
                        deckResult.Read<ulong>(i, "timestamp"), deckResult.Read<DeckFlags>(i, "flags"));

                    // get all scrolls associated with deck
                    var deckScrollResult = DatabaseManager.Database.Select("SELECT `scrollInstance` FROM `account_deck_scroll` WHERE `id` = ?", deck.Id);
                    if (deckScrollResult == null)
                    {
                        LogManager.Write("Player", "Deck instance {0} has no scrolls associated with it! Skipping.", deck.Id);
                        continue;
                    }

                    for (int j = 0; j < deckScrollResult.Count; j++)
                    {
                        uint scrollId      = deckScrollResult.Read<uint>(j, "scrollInstance");
                        var scrollInstance = GetScroll(scrollId);

                        if (scrollInstance == null)
                        {
                            LogManager.Write("Player", "Scroll instance {0} in deck {1} doesn't belong to player or doesn't exist! Skipping.", scrollId, deck.Id);
                            continue;
                        }

                        deck.Scrolls.Add(scrollInstance);
                    }

                    if (deck.Scrolls.Count >= 1)
                    {
                        deck.CalculateResources();
                        Decks.Add(deck);
                    }
                }
            }
        }