Example #1
0
        /// <summary>
        /// Loads serialized data
        /// </summary>
        private static void OnWorldLoad()
        {
            if (!File.Exists(DataFile))
            {
                return;
            }

            using (FileStream stream = new FileStream(DataFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryFileReader reader = new BinaryFileReader(new BinaryReader(stream));

                int tableCount = reader.ReadInt();
                EoCTable = new Dictionary <Player, EoCContext>(tableCount);

                for (int i = 0; i < tableCount; i++)
                {
                    if (!reader.ReadBool())
                    {
                        continue;
                    }

                    Player pl = reader.ReadMobile <Player>();

                    if (pl != null && !pl.Deleted)
                    {
                        EoCTable[pl] = new EoCContext(reader);
                    }
                }

                int hitsCount = reader.ReadInt();
                HitsTable = new Dictionary <Player, HitsTimer>(hitsCount);

                for (int i = 0; i < hitsCount; i++)
                {
                    if (!reader.ReadBool())
                    {
                        continue;
                    }

                    Player player = reader.ReadMobile <Player>();

                    if (player == null || player.Deleted)
                    {
                        continue;
                    }

                    HitsTable[player] = new HitsTimer(player);

                    DateTime next = reader.ReadDateTime();

                    if (next < DateTime.Now)
                    {
                        next = DateTime.Now;
                    }

                    HitsTable[player].Delay = (next - DateTime.Now);
                }

                reader.Close();
            }
        }
Example #2
0
        /// <summary>
        /// Grants EoC for:
        /// <para>getting damaged by a player or NPC</para>
        /// <para>getting knocked out</para>
        /// <para>knocking out another player</para>
        /// <para> </para>
        /// <para>Also starts the <code>HitsTable</code> to trigger &lt;5% HP EoC generation</para>
        /// </summary>
        private static void OnDamaged(PlayerDamagedEventArgs args)
        {
            Mobile aggr = args.Aggressor;
            Player p    = args.Player;

            if (aggr != null)
            {
                if (p.Guild != null && !p.Guild.Disbanded && p.Guild == aggr.Guild)
                {
                    return;
                }

                if (p.Party != null && p.Party == aggr.Party)
                {
                    return;
                }

                p.EssenceOfCharacter += Math.Max(1, (args.DamageAmount / 10));

                if (args.WillKill)
                {
                    if (aggr is Player)
                    {
                        int change = (int)(p.SkillsTotal / aggr.SkillsTotal) * 10;

                        ((Player)aggr).EssenceOfCharacter += change;
                        p.EssenceOfCharacter += change;
                    }
                    else
                    {
                        int count = 0;

                        for (int i = 0; i < p.Aggressed.Count; i++)
                        {
                            if (AttackMessage.CheckAggressions(p, p.Aggressed[i].Defender))
                            {
                                count++;
                            }
                        }

                        for (int i = 0; i < p.Aggressors.Count; i++)
                        {
                            if (AttackMessage.CheckAggressions(p, p.Aggressors[i].Attacker))
                            {
                                count++;
                            }
                        }

                        p.EssenceOfCharacter += Math.Max(50, (50 * count));
                    }
                }
            }

            if (p.Hits < (int)(p.HitsMax * 0.05))
            {
                if (!HitsTable.ContainsKey(p))
                {
                    HitsTable[p] = new HitsTimer(p);
                    HitsTable[p].Start();
                }
                else if (!HitsTable[p].Running)
                {
                    HitsTable[p].Start();
                }
            }
            else if (HitsTable.ContainsKey(p))
            {
                HitsTable[p].Stop();
                HitsTable.Remove(p);
            }
        }
Example #3
0
        public virtual void CheckStatTimers()
        {
            if ( m_Deleted )
                return;

            if ( Hits < HitsMax )
            {
                if ( CanRegenHits )
                {
                    if ( m_HitsTimer == null )
                        m_HitsTimer = new HitsTimer( this );

                    m_HitsTimer.Start();
                }
                else if ( m_HitsTimer != null )
                {
                    m_HitsTimer.Stop();
                }
            }
            else
            {
                Hits = HitsMax;
            }

            if ( Stam < StamMax )
            {
                if ( CanRegenStam )
                {
                    if ( m_StamTimer == null )
                        m_StamTimer = new StamTimer( this );

                    m_StamTimer.Start();
                }
                else if ( m_StamTimer != null )
                {
                    m_StamTimer.Stop();
                }
            }
            else
            {
                Stam = StamMax;
            }

            if ( Mana < ManaMax )
            {
                if ( CanRegenMana )
                {
                    if ( m_ManaTimer == null )
                        m_ManaTimer = new ManaTimer( this );

                    m_ManaTimer.Start();
                }
                else if ( m_ManaTimer != null )
                {
                    m_ManaTimer.Stop();
                }
            }
            else
            {
                Mana = ManaMax;
            }
        }
Example #4
0
        /// <summary>
        /// Loads serialized data
        /// </summary>
        private static void OnWorldLoad()
        {
            if( !File.Exists(DataFile) )
                return;

            using( FileStream stream = new FileStream(DataFile, FileMode.Open, FileAccess.Read, FileShare.Read) )
            {
                BinaryFileReader reader = new BinaryFileReader(new BinaryReader(stream));

                int tableCount = reader.ReadInt();
                EoCTable = new Dictionary<Player, EoCContext>(tableCount);

                for( int i = 0; i < tableCount; i++ )
                {
                    if( !reader.ReadBool() )
                        continue;

                    Player pl = reader.ReadMobile<Player>();

                    if( pl != null && !pl.Deleted )
                        EoCTable[pl] = new EoCContext(reader);
                }

                int hitsCount = reader.ReadInt();
                HitsTable = new Dictionary<Player, HitsTimer>(hitsCount);

                for( int i = 0; i < hitsCount; i++ )
                {
                    if( !reader.ReadBool() )
                        continue;

                    Player player = reader.ReadMobile<Player>();

                    if( player == null || player.Deleted )
                        continue;

                    HitsTable[player] = new HitsTimer(player);

                    DateTime next = reader.ReadDateTime();

                    if( next < DateTime.Now )
                        next = DateTime.Now;

                    HitsTable[player].Delay = (next - DateTime.Now);
                }

                reader.Close();
            }
        }
Example #5
0
        /// <summary>
        /// Grants EoC for:
        /// <para>getting damaged by a player or NPC</para>
        /// <para>getting knocked out</para>
        /// <para>knocking out another player</para>
        /// <para> </para>
        /// <para>Also starts the <code>HitsTable</code> to trigger &lt;5% HP EoC generation</para>
        /// </summary>
        private static void OnDamaged( PlayerDamagedEventArgs args )
        {
            Mobile aggr = args.Aggressor;
            Player p = args.Player;

            if( aggr != null )
            {
                if( p.Guild != null && !p.Guild.Disbanded && p.Guild == aggr.Guild )
                    return;

                if( p.Party != null && p.Party == aggr.Party )
                    return;

                p.EssenceOfCharacter += Math.Max(1, (args.DamageAmount / 10));

                if( args.WillKill )
                {
                    if( aggr is Player )
                    {
                        int change = (int)(p.SkillsTotal / aggr.SkillsTotal) * 10;

                        ((Player)aggr).EssenceOfCharacter += change;
                        p.EssenceOfCharacter += change;
                    }
                    else
                    {
                        int count = 0;

                        for( int i = 0; i < p.Aggressed.Count; i++ )
                        {
                            if( AttackMessage.CheckAggressions(p, p.Aggressed[i].Defender) )
                                count++;
                        }

                        for( int i = 0; i < p.Aggressors.Count; i++ )
                        {
                            if( AttackMessage.CheckAggressions(p, p.Aggressors[i].Attacker) )
                                count++;
                        }

                        p.EssenceOfCharacter += Math.Max(50, (50 * count));
                    }
                }
            }

            if( p.Hits < (int)(p.HitsMax * 0.05) )
            {
                if( !HitsTable.ContainsKey(p) )
                {
                    HitsTable[p] = new HitsTimer(p);
                    HitsTable[p].Start();
                }
                else if( !HitsTable[p].Running )
                {
                    HitsTable[p].Start();
                }
            }
            else if( HitsTable.ContainsKey(p) )
            {
                HitsTable[p].Stop();
                HitsTable.Remove(p);
            }
        }
Example #6
0
        public virtual void CheckStatTimers()
        {
            if (m_Deleted)
            {
                return;
            }

            if (Hits < HitsMax)
            {
                if (CanRegenHits)
                {
                    if (m_HitsTimer == null)
                    {
                        m_HitsTimer = new HitsTimer(this);
                    }

                    m_HitsTimer.Start();
                }
                else if (m_HitsTimer != null)
                {
                    m_HitsTimer.Stop();
                }
            }
            else
            {
                Hits = HitsMax;
            }

            if (Stam < StamMax)
            {
                if (CanRegenStam)
                {
                    if (m_StamTimer == null)
                    {
                        m_StamTimer = new StamTimer(this);
                    }

                    m_StamTimer.Start();
                }
                else if (m_StamTimer != null)
                {
                    m_StamTimer.Stop();
                }
            }
            else
            {
                Stam = StamMax;
            }

            if (Mana < ManaMax)
            {
                if (CanRegenMana)
                {
                    if (m_ManaTimer == null)
                    {
                        m_ManaTimer = new ManaTimer(this);
                    }

                    m_ManaTimer.Start();
                }
                else if (m_ManaTimer != null)
                {
                    m_ManaTimer.Stop();
                }
            }
            else
            {
                Mana = ManaMax;
            }
        }