Пример #1
0
        public static void DeleteTrickOrTreatEntries()
        {
            Queue m_Queue = new Queue();

            foreach (TrickOrTreatPlayerEntry entry in HalloweenPersistance.m_TrickOrTreatPlayerEntries)
            {
                if (entry == null)
                {
                    continue;
                }
                if (entry.Deleted)
                {
                    continue;
                }

                m_Queue.Enqueue(entry);
            }

            while (m_Queue.Count > 0)
            {
                TrickOrTreatPlayerEntry entry = (TrickOrTreatPlayerEntry)m_Queue.Dequeue();
                entry.Delete();
            }

            HalloweenPersistance.m_TrickOrTreatPlayerEntries.Clear();
        }
Пример #2
0
        public static void TrickOrTreat(BaseCreature creature, Mobile from)
        {
            PlayerMobile player = from as PlayerMobile;

            if (player == null)
            {
                return;
            }
            if (!HalloweenPersistance.TrickOrTreatEnabled)
            {
                return;
            }

            TrickOrTreatPlayerEntry trickOrTreatEntry = null;

            bool foundPlayer = false;

            foreach (TrickOrTreatPlayerEntry playerEntry in HalloweenPersistance.m_TrickOrTreatPlayerEntries)
            {
                if (playerEntry.m_Player == player)
                {
                    trickOrTreatEntry = playerEntry;
                    foundPlayer       = true;
                }
            }

            if (!foundPlayer)
            {
                trickOrTreatEntry = new TrickOrTreatPlayerEntry(player);
                HalloweenPersistance.m_TrickOrTreatPlayerEntries.Add(trickOrTreatEntry);
            }

            bool foundCreatureMatch = false;
            bool interactionReady   = true;

            TimeSpan InteractionCooldown = TimeSpan.FromMinutes(60);

            foreach (KeyValuePair <BaseCreature, DateTime> interaction in trickOrTreatEntry.m_Interactions)
            {
                BaseCreature interactionCreature = interaction.Key;
                DateTime     interactionTime     = interaction.Value;

                if (interactionCreature == null)
                {
                    continue;
                }
                if (interactionTime == null)
                {
                    continue;
                }

                if (interactionCreature == creature)
                {
                    foundCreatureMatch = true;

                    if (DateTime.UtcNow < interactionTime + InteractionCooldown)
                    {
                        interactionReady = false;
                    }

                    break;
                }
            }

            if (foundCreatureMatch)
            {
                if (interactionReady)
                {
                    trickOrTreatEntry.m_Interactions[creature] = DateTime.UtcNow;
                    ResolveTrickOrTreat(creature, player, false);
                }

                else
                {
                    ResolveTrickOrTreat(creature, player, false);
                }
            }

            else
            {
                trickOrTreatEntry.m_Interactions.Add(creature, DateTime.UtcNow);
                ResolveTrickOrTreat(creature, player, true);
            }
        }