TheGodfather

I would love to make item insurance that only triggers if killed by a monster. If a player kills another player it is as if that player doesn't have insurance. Anyone interested in working on this with me?
 
Check out PlayerMobile.cs, in the OnBeforeDeath() method.

There are references to "FindMostRecentDamager()" and how that affects insurance.

It should be fairly simple to add a check there comparing what happens if the most recent damager was a PlayerMobile vs a BaseCreature, or if that BaseCreature was owned by another Player.

If I have time I could work on this more, but that might be enough to get you started.
 
Check out PlayerMobile.cs, in the OnBeforeDeath() method.

There are references to "FindMostRecentDamager()" and how that affects insurance.

It should be fairly simple to add a check there comparing what happens if the most recent damager was a PlayerMobile vs a BaseCreature, or if that BaseCreature was owned by another Player.

If I have time I could work on this more, but that might be enough to get you started.
Code:
        private Mobile m_InsuranceAward;
        private int m_InsuranceCost;
        private int m_InsuranceBonus;

        private List<Item> m_EquipSnapshot;

        public List<Item> EquipSnapshot { get { return m_EquipSnapshot; } }

        private bool FindItems_Callback(Item item)
        {
            if (!item.Deleted && (item.LootType == LootType.Blessed || item.Insured))
            {
                if (Backpack != item.ParentEntity)
                {
                    return true;
                }
            }
            return false;
        }

        public override bool OnBeforeDeath()
        {
            NetState state = NetState;

            if (state != null)
            {
                state.CancelAllTrades();
            }

            DropHolding();

            if (Core.AOS && Backpack != null && !Backpack.Deleted)
            {
                var ilist = Backpack.FindItemsByType<Item>(FindItems_Callback);

                for (int i = 0; i < ilist.Count; i++)
                {
                    Backpack.AddItem(ilist[i]);
                }
            }

            m_EquipSnapshot = new List<Item>(Items);

            m_NonAutoreinsuredItems = 0;
            m_InsuranceCost = 0;
            m_InsuranceAward = base.FindMostRecentDamager(false);

            if (m_InsuranceAward is BaseCreature)
            {
                Mobile master = ((BaseCreature)m_InsuranceAward).GetMaster();

                if (master != null)
                {
                    m_InsuranceAward = master;
                }
            }

            if (m_InsuranceAward != null && (!m_InsuranceAward.Player || m_InsuranceAward == this))
            {
                m_InsuranceAward = null;
            }

            if (m_InsuranceAward is PlayerMobile)
            {
                ((PlayerMobile)m_InsuranceAward).m_InsuranceBonus = 0;
            }

            if (m_ReceivedHonorContext != null)
            {
                m_ReceivedHonorContext.OnTargetKilled();
            }
            if (m_SentHonorContext != null)
            {
                m_SentHonorContext.OnSourceKilled();
            }

            RecoverAmmo();

            return base.OnBeforeDeath();
        }

        private bool CheckInsuranceOnDeath(Item item)
        {
            if (Young) { return false; }

            if (InsuranceEnabled && item.Insured)
            {
                if (XmlPoints.InsuranceIsFree(this, m_InsuranceAward))
                {
                    item.PayedInsurance = true;
                    return true;
                }

                #region Dueling
                if (m_DuelPlayer != null && m_DuelContext != null && m_DuelContext.Registered && m_DuelContext.Started &&
                    !m_DuelPlayer.Eliminated)
                {
                    return true;
                }
                #endregion

                int insuredAmount = item.GetInsuranceCost();
                if (AutoRenewInsurance)
                {
                    int cost = (m_InsuranceAward == null ? insuredAmount : insuredAmount / 2);

                    if (Banker.Withdraw(this, cost))
                    {
                        m_InsuranceCost += cost;
                        item.PayedInsurance = true;
                        SendLocalizedMessage(1060398, cost.ToString()); // ~1_AMOUNT~ gold has been withdrawn from your bank box.
                    }
                    else
                    {
                        SendLocalizedMessage(1061079, "", 0x23); // You lack the funds to purchase the insurance
                        item.PayedInsurance = false;
                        item.Insured = false;
                        m_NonAutoreinsuredItems++;
                    }
                }
                else
                {
                    item.PayedInsurance = false;
                    item.Insured = false;
                }

                if (m_InsuranceAward != null)
                {
                    if (Banker.Deposit(m_InsuranceAward, insuredAmount / 2))
                    {
                        if (m_InsuranceAward is PlayerMobile)
                        {
                            ((PlayerMobile)m_InsuranceAward).m_InsuranceBonus += insuredAmount / 2;
                        }
                    }
                }

                return true;
            }

            return false;
        }

        public override DeathMoveResult GetParentMoveResultFor(Item item)
        {
            if (CheckInsuranceOnDeath(item) && !Young)
            {
                return DeathMoveResult.MoveToBackpack;
            }

            DeathMoveResult res = base.GetParentMoveResultFor(item);

            if (res == DeathMoveResult.MoveToCorpse && item.Movable && Young)
            {
                res = DeathMoveResult.MoveToBackpack;
            }

            return res;
        }

        public override DeathMoveResult GetInventoryMoveResultFor(Item item)
        {
            if (CheckInsuranceOnDeath(item) && !Young)
            {
                return DeathMoveResult.MoveToBackpack;
            }

            DeathMoveResult res = base.GetInventoryMoveResultFor(item);

            if (res == DeathMoveResult.MoveToCorpse && item.Movable && Young)
            {
                res = DeathMoveResult.MoveToBackpack;
            }

            return res;
        }

        public override void OnDeath(Container c)
        {
            PlayerMobile killer = null;
            Mobile m = FindMostRecentDamager(false);
            killer = m as PlayerMobile;
            if(killer == null)
            {
                if(m is BaseCreature)
                {
                    killer = ((BaseCreature)m).ControlMaster as PlayerMobile;
                }
            }
           
            if (m_NonAutoreinsuredItems > 0)
            {
                SendLocalizedMessage(1061115);
            }

So, what would be a command to terminate insurance, as most of it is just renewing it.
 
Back