示例#1
0
            protected override void OnTarget(Mobile from, object targeted)
            {
                if (from == null || m_tool == null || from.Map == null)
                {
                    return;
                }

                // find any xmlsiege attachment on the target
                XmlSiege a = (XmlSiege)XmlAttach.FindAttachment(targeted, typeof(XmlSiege));

                // if it isnt on the target, but the target is an addon, then check the addon
                if (a == null && targeted is AddonComponent)
                {
                    a = (XmlSiege)XmlAttach.FindAttachment(((AddonComponent)targeted).Addon, typeof(XmlSiege));
                }

                // if it still isnt found, the look for nearby targets
                if (a == null)
                {
                    Point3D loc = Point3D.Zero;
                    if (targeted is IEntity)
                    {
                        loc = ((IEntity)targeted).Location;
                    }
                    else
                    if (targeted is StaticTarget)
                    {
                        loc = ((StaticTarget)targeted).Location;
                    }
                    else
                    if (targeted is LandTarget)
                    {
                        loc = ((LandTarget)targeted).Location;
                    }

                    if (loc != Point3D.Zero)
                    {
                        foreach (Item p in from.Map.GetItemsInRange(loc, RepairRange))
                        {
                            a = (XmlSiege)XmlAttach.FindAttachment(p, typeof(XmlSiege));
                            if (a != null)
                            {
                                break;
                            }
                        }
                    }
                }

                // repair the target
                if (a != null)
                {
                    if (a.Hits >= a.HitsMax)
                    {
                        from.SendMessage("This does not require repair.");
                        return;
                    }

                    if (a.BeingRepaired)
                    {
                        from.SendMessage("You must wait to repair again.");
                        return;
                    }
                    Container pack = from.Backpack;

                    // does the player have it?
                    if (pack != null)
                    {
                        int nhits = 0;



                        double resourcepenalty = 1;

                        // require more resources for repairing destroyed structures
                        if (a.Hits == 0)
                        {
                            resourcepenalty = RepairDestroyedResourcePenalty;
                        }

                        // dont consume resources for staff
                        if (from.AccessLevel > AccessLevel.Player)
                        {
                            resourcepenalty = 0;
                        }

                        int requirediron  = (int)(a.Iron * resourcepenalty);
                        int requiredstone = (int)(a.Stone * resourcepenalty);
                        int requiredwood  = (int)(a.Wood * resourcepenalty);

                        int niron  = pack.ConsumeUpTo(typeof(IronIngot), requirediron);
                        int nstone = pack.ConsumeUpTo(typeof(BaseGranite), requiredstone);
                        int nwood  = pack.ConsumeUpTo(typeof(Board), requiredwood);

                        if (niron == requirediron && nstone == requiredstone && nwood == requiredwood)
                        {
                            nhits += m_tool.HitsPerRepair;
                        }



                        if (nhits == 0)
                        {
                            from.SendMessage("Insufficient resources to complete the repair. Resources lost.");
                            return;
                        }
                        from.PlaySound(0x2A);                         // play anvil sound
                        from.SendMessage("You begin your repair");

                        m_tool.UsesRemaining--;
                        if (m_tool.UsesRemaining == 0)
                        {
                            from.SendLocalizedMessage(1044038);                             // You have worn out your tool!
                            m_tool.Delete();
                        }

                        a.BeingRepaired = true;

                        double smithskill     = from.Skills[SkillName.Blacksmith].Value;
                        double carpentryskill = from.Skills[SkillName.Carpentry].Value;

                        double timepenalty = 1;
                        if (a.Hits == 0)
                        {
                            // repairing destroyed structures requires more time
                            timepenalty = RepairDestroyedTimePenalty;
                        }

                        // compute repair speed with modifiers
                        TimeSpan repairtime = TimeSpan.FromSeconds(m_tool.BaseRepairTime * timepenalty - from.Dex / 40.0 - smithskill / 50.0 - carpentryskill / 50.0);

                        // allow staff instant repair
                        if (from.AccessLevel > AccessLevel.Player)
                        {
                            repairtime = TimeSpan.Zero;
                        }

                        // setup for the delayed repair
                        Timer.DelayCall(repairtime, new TimerStateCallback(SiegeRepair_Callback), new object[] { from, a, nhits });
                    }
                }
                else
                {
                    from.SendMessage("Invalid target");
                    return;
                }
            }