Example #1
0
        public override bool OnBeforeDeath(Mobile m)
        {
            if (m is DespiseCreature && m.Region != null && m.Region.IsPartOf(this.GetType()))
            {
                DespiseCreature dc = (DespiseCreature)m;

                if (!dc.Controlled && dc.Orb == null)
                {
                    Dictionary <DespiseCreature, int> creatures = new Dictionary <DespiseCreature, int>();

                    foreach (DamageEntry de in m.DamageEntries)
                    {
                        if (de.Damager is DespiseCreature)
                        {
                            DespiseCreature creat = de.Damager as DespiseCreature;

                            if (!creat.Controlled || creat.Orb == null)
                            {
                                continue;
                            }

                            if (creatures.ContainsKey(creat))
                            {
                                creatures[creat] += de.DamageGiven;
                            }
                            else
                            {
                                creatures[creat] = de.DamageGiven;
                            }
                        }
                    }

                    if (creatures.Count > 0)
                    {
                        DespiseCreature topdam  = null;
                        int             highest = 0;

                        foreach (KeyValuePair <DespiseCreature, int> kvp in creatures)
                        {
                            if (topdam == null || kvp.Value > highest)
                            {
                                topdam  = kvp.Key;
                                highest = kvp.Value;
                            }
                        }

                        if (topdam != null && highest > 0)
                        {
                            int mobKarma = Math.Abs(dc.Karma);
                            int karma    = (int)(((double)mobKarma / 10) * (double)highest / (double)dc.HitsMax);

                            if (karma < 1)
                            {
                                karma = 1;
                            }

                            if (dc.Karma > 0)
                            {
                                karma *= -1;
                            }

                            Mobile    master   = topdam.GetMaster();
                            Alignment oldAlign = topdam.Alignment;
                            int       power    = topdam.Power;
                            topdam.Karma += karma;
                            Alignment newAlign = topdam.Alignment;

                            if (master != null && karma > 0)
                            {
                                master.SendLocalizedMessage(1153281); // Your possessed creature has gained karma!
                            }
                            else if (master != null && karma < 0)
                            {
                                master.SendLocalizedMessage(1153282); // Your possessed creature has lost karma!
                            }
                            if (power < topdam.MaxPower)
                            {
                                topdam.Progress += dc.Power;

                                if (topdam.Power > power && master != null)
                                {
                                    master.SendLocalizedMessage(1153293, topdam.Name); // ~1_NAME~ is growing in strength.
                                }
                            }
                            else if (master != null)
                            {
                                master.SendLocalizedMessage(1153309); // Your controlled creature cannot gain further power.
                            }
                            if (oldAlign != newAlign && newAlign != Alignment.Neutral && topdam.MaxPower < 15)
                            {
                                topdam.MaxPower = 15;

                                if (master != null)
                                {
                                    master.SendLocalizedMessage(1153294, topdam.Name); // ~1_NAME~ has achieved a new threshold in power!
                                }
                                topdam.Delta(MobileDelta.Noto);

                                topdam.FixedEffect(0x373A, 10, 30);
                                topdam.PlaySound(0x209);
                            }
                        }
                    }

                    int amount = Utility.RandomMinMax(dc.Power * 8, dc.Power * 10);
                    dc.PackItem(new PutridHeart(amount));
                }
            }

            return(base.OnBeforeDeath(m));
        }
Example #2
0
        public override bool OnBeforeDeath(Mobile m)
        {
            if (m is DespiseCreature despiseCreature && despiseCreature.Region != null && despiseCreature.Region.IsPartOf(GetType()) && !despiseCreature.Controlled && despiseCreature.Orb == null)
            {
                Dictionary <DespiseCreature, int> creatures = new Dictionary <DespiseCreature, int>();

                for (var index = 0; index < despiseCreature.DamageEntries.Count; index++)
                {
                    DamageEntry de = despiseCreature.DamageEntries[index];

                    if (de.Damager is DespiseCreature creat)
                    {
                        if (!creat.Controlled || creat.Orb == null)
                        {
                            continue;
                        }

                        if (creatures.ContainsKey(creat))
                        {
                            creatures[creat] += de.DamageGiven;
                        }
                        else
                        {
                            creatures[creat] = de.DamageGiven;
                        }
                    }
                }

                if (creatures.Count > 0)
                {
                    DespiseCreature topdam  = null;
                    int             highest = 0;

                    foreach (KeyValuePair <DespiseCreature, int> kvp in creatures)
                    {
                        if (topdam == null || kvp.Value > highest)
                        {
                            topdam  = kvp.Key;
                            highest = kvp.Value;
                        }
                    }

                    if (topdam != null && highest > 0)
                    {
                        int mobKarma = Math.Abs(despiseCreature.Karma);
                        int karma    = (int)((double)mobKarma / 10 * highest / despiseCreature.HitsMax);

                        if (karma < 1)
                        {
                            karma = 1;
                        }

                        if (despiseCreature.Karma > 0)
                        {
                            karma *= -1;
                        }

                        Mobile    master   = topdam.GetMaster();
                        Alignment oldAlign = topdam.Alignment;
                        int       power    = topdam.Power;
                        topdam.Karma += karma;
                        Alignment newAlign = topdam.Alignment;

                        if (master != null && karma > 0)
                        {
                            master.SendLocalizedMessage(1153281); // Your possessed creature has gained karma!
                        }
                        else if (master != null && karma < 0)
                        {
                            master.SendLocalizedMessage(1153282); // Your possessed creature has lost karma!
                        }
                        if (power < topdam.MaxPower)
                        {
                            topdam.Progress += despiseCreature.Power;

                            if (topdam.Power > power && master != null)
                            {
                                master.SendLocalizedMessage(1153294,
                                                            topdam.Name); // ~1_NAME~ has achieved a new threshold in power!
                            }
                        }
                        else if (master != null)
                        {
                            master.SendLocalizedMessage(1153309); // Your controlled creature cannot gain further power.
                        }
                        if (oldAlign != newAlign && newAlign != Alignment.Neutral && topdam.MaxPower < 15)
                        {
                            topdam.MaxPower = 15;

                            if (master != null)
                            {
                                master.SendLocalizedMessage(1153293, topdam.Name); // ~1_NAME~ is growing in strength.
                            }
                            topdam.Delta(MobileDelta.Noto);

                            topdam.FixedEffect(0x373A, 10, 30);
                            topdam.PlaySound(0x209);
                        }

                        if (master != null && master.Map != null && master.Map != Map.Internal &&
                            master.Backpack != null)
                        {
                            PutridHeart heart = new PutridHeart(Utility.RandomMinMax(despiseCreature.Power * 8,
                                                                                     despiseCreature.Power * 10));

                            if (!master.Backpack.TryDropItem(master, heart, false))
                            {
                                heart.MoveToWorld(master.Location, master.Map);
                            }
                        }
                    }
                }
            }

            return(base.OnBeforeDeath(m));
        }