示例#1
0
文件: AmmoInfo.cs 项目: pallop/Servuo
        public static string GetAmmoName(BaseCannon cannon)
        {
            AmmoInfo info = AmmoInfo.GetAmmoInfo(cannon.LoadedAmmo);

            if (info != null)
            {
                return(info.Name);
            }

            return("unloaded");
        }
示例#2
0
        public virtual void OnMobileHit(object obj)
        {
            object[] objects = (object[])obj;
            Mobile   toHit   = objects[0] as Mobile;
            Point3D  pnt     = (Point3D)objects[1];

            AmmoInfo ammoInfo = AmmoInfo.GetAmmoInfo((AmmunitionType)objects[2]);

            if (ammoInfo != null)
            {
                int damage = Utility.RandomMinMax(ammoInfo.MinDamage, ammoInfo.MaxDamage);

                if (Operator != null)
                {
                    Operator.DoHarmful(toHit);
                }

                AOS.Damage(toHit, Operator, damage, ammoInfo.PhysicalDamage, ammoInfo.FireDamage, ammoInfo.ColdDamage, ammoInfo.PoisonDamage, ammoInfo.EnergyDamage);
                Effects.SendLocationEffect(toHit.Location, toHit.Map, Utility.RandomBool() ? 14000 : 14013, 15, 10);
                Effects.PlaySound(toHit.Location, toHit.Map, 0x207);
            }
        }
示例#3
0
        public virtual void OnShipHit(object obj)
        {
            object[] list   = (object[])obj;
            BaseBoat target = list[0] as BaseBoat;
            Point3D  pnt    = (Point3D)list[1];

            var ammoInfo = AmmoInfo.GetAmmoInfo((AmmunitionType)list[2]);

            if (ammoInfo != null && target != null)
            {
                int damage = (Utility.RandomMinMax(ammoInfo.MinDamage, ammoInfo.MaxDamage));
                damage /= 7;
                target.OnTakenDamage(Operator, damage);

                int z = target.ZSurface;

                if (target.TillerMan != null && target.TillerMan is IEntity)
                {
                    z = ((IEntity)target.TillerMan).Z;
                }

                Direction d       = Utility.GetDirection(this, pnt);
                int       xOffset = 0;
                int       yOffset = 0;
                Point3D   hit     = pnt;

                if (!ammoInfo.RequiresSurface)
                {
                    switch (d)
                    {
                    default:
                    case Direction.North:
                        xOffset = Utility.RandomMinMax(-1, 1);
                        yOffset = Utility.RandomMinMax(-2, 0);
                        hit     = new Point3D(pnt.X + xOffset, pnt.Y + yOffset, z);
                        break;

                    case Direction.South:
                        xOffset = Utility.RandomMinMax(-1, 1);
                        yOffset = Utility.RandomMinMax(0, 2);
                        hit     = new Point3D(pnt.X + xOffset, pnt.Y + yOffset, z);
                        break;

                    case Direction.East:
                        xOffset = Utility.RandomMinMax(0, 2);
                        yOffset = Utility.RandomMinMax(-1, 1);
                        hit     = new Point3D(pnt.X + xOffset, pnt.Y + yOffset, z);
                        break;

                    case Direction.West:
                        xOffset = Utility.RandomMinMax(-2, 0);
                        yOffset = Utility.RandomMinMax(-1, 1);
                        hit     = new Point3D(pnt.X + xOffset, pnt.Y + yOffset, z);
                        break;
                    }
                }

                Effects.SendLocationEffect(hit, target.Map, Utility.RandomBool() ? 14000 : 14013, 15, 10);
                Effects.PlaySound(hit, target.Map, 0x207);

                if (Operator != null && (!Operator.Deleted || CanFireUnmanned))
                {
                    Mobile victim = target.Owner;

                    if (victim != null && target.Contains(victim) && Operator.CanBeHarmful(victim, false))
                    {
                        Operator.DoHarmful(victim);
                    }
                    else
                    {
                        List <Mobile> candidates = new List <Mobile>();
                        SecurityLevel highest    = SecurityLevel.Passenger;

                        foreach (var mob in target.GetMobilesOnBoard().OfType <PlayerMobile>().Where(pm => Operator.CanBeHarmful(pm, false)))
                        {
                            if (target is BaseGalleon && ((BaseGalleon)target).GetSecurityLevel(mob) > highest)
                            {
                                candidates.Insert(0, mob);
                            }
                            else
                            {
                                candidates.Add(mob);
                            }
                        }

                        if (candidates.Count > 0)
                        {
                            Operator.DoHarmful(candidates[0]);
                        }
                        else if (victim != null && Operator.IsHarmfulCriminal(victim))
                        {
                            Operator.CriminalAction(false);
                        }

                        ColUtility.Free(candidates);
                    }
                }
            }
        }
示例#4
0
        public Target[] AcquireTarget()
        {
            AmmoInfo ammo = AmmoInfo.GetAmmoInfo(AmmoType);

            int     xOffset = 0; int yOffset = 0;
            int     currentRange = 0;
            Point3D pnt          = Location;
            Map     map          = Map;

            switch (GetFacing())
            {
            case Direction.North:
                xOffset = 0; yOffset = -1; break;

            case Direction.South:
                xOffset = 0; yOffset = 1; break;

            case Direction.West:
                xOffset = -1; yOffset = 0; break;

            case Direction.East:
                xOffset = 1; yOffset = 0; break;
            }

            int xo            = xOffset;
            int yo            = yOffset;
            int lateralOffset = 1;

            while (currentRange++ <= Range)
            {
                xOffset = xo;
                yOffset = yo;

                if (LateralOffset > 1 && currentRange % LateralOffset == 0)
                {
                    lateralOffset++;
                }

                TimeSpan delay = TimeSpan.FromSeconds(currentRange / 10.0);

                switch (AmmoType)
                {
                case AmmunitionType.Empty: break;

                case AmmunitionType.Cannonball:
                case AmmunitionType.FrostCannonball:
                case AmmunitionType.FlameCannonball:
                {
                    Point3D newPoint = pnt;
                    //List<IEntity> list = new List<IEntity>();

                    for (int i = -lateralOffset; i <= lateralOffset; i++)
                    {
                        if (xOffset == 0)
                        {
                            newPoint = new Point3D(pnt.X + (xOffset + i), pnt.Y + (yOffset * currentRange), pnt.Z);
                        }
                        else
                        {
                            newPoint = new Point3D(pnt.X + (xOffset * currentRange), pnt.Y + (yOffset + i), pnt.Z);
                        }

                        BaseGalleon g = FindValidBoatTarget(newPoint, map, ammo);

                        if (g != null && g.DamageTaken < DamageLevel.Severely && g.Owner is PlayerMobile)
                        {
                            var target = new Target();
                            target.Entity   = g;
                            target.Location = newPoint;
                            target.Range    = currentRange;

                            return(new Target[] { target });
                        }
                    }
                }
                break;

                case AmmunitionType.Grapeshot:
                {
                    Point3D       newPoint = pnt;
                    List <Target> mobiles  = new List <Target>();

                    for (int i = -lateralOffset; i <= lateralOffset; i++)
                    {
                        if (xOffset == 0)
                        {
                            newPoint = new Point3D(pnt.X + (xOffset + i), pnt.Y + (yOffset * currentRange), pnt.Z);
                        }
                        else
                        {
                            newPoint = new Point3D(pnt.X + (xOffset * currentRange), pnt.Y + (yOffset + i), pnt.Z);
                        }

                        foreach (Mobile m in GetTargets(newPoint, map))
                        {
                            var target = new Target();
                            target.Entity   = m;
                            target.Location = newPoint;
                            target.Range    = currentRange;

                            mobiles.Add(target);
                        }

                        if (mobiles.Count > 0 && ammo.SingleTarget)
                        {
                            var toHit = mobiles[Utility.Random(mobiles.Count)];
                            ColUtility.Free(mobiles);
                            return(new Target[] { toHit });
                        }
                    }

                    if (mobiles.Count > 0)
                    {
                        return(mobiles.ToArray());
                    }
                }
                break;
                }
            }

            return(null);
        }
示例#5
0
        public virtual void Shoot(object cannoneer)
        {
            AmmoInfo ammo = AmmoInfo.GetAmmoInfo(AmmoType);

            if (ammo == null)
            {
                return;
            }

            Mobile shooter = null;

            if (cannoneer is Mobile)
            {
                shooter = (Mobile)cannoneer;
            }

            if (shooter != null && shooter.Player)
            {
                m_Hits -= Utility.RandomMinMax(0, 4);
            }

            DoShootEffects();
            AddAction(shooter, 1149691); //Fired successfully.

            int       xOffset = 0; int yOffset = 0;
            int       currentRange = 0;
            Point3D   pnt          = this.Location;
            Map       map          = this.Map;
            Direction d            = GetFacing();

            switch (d)
            {
            case Direction.North:
                xOffset = 0; yOffset = -1; break;

            case Direction.South:
                xOffset = 0; yOffset = 1; break;

            case Direction.West:
                xOffset = -1; yOffset = 0; break;

            case Direction.East:
                xOffset = 1; yOffset = 0; break;
            }

            int xo            = xOffset;
            int yo            = yOffset;
            int lateralOffset = 1;

            int latDist = ammo.LateralOffset;

            int  range = Range;
            bool hit   = false;

            while (currentRange++ <= range)
            {
                xOffset = xo;
                yOffset = yo;

                if (currentRange % latDist == 0)
                {
                    lateralOffset++;
                }

                TimeSpan delay = TimeSpan.FromSeconds((double)currentRange / 10.0);

                switch (AmmoType)
                {
                case AmmunitionType.Empty: break;

                case AmmunitionType.Cannonball:
                case AmmunitionType.FrostCannonball:
                case AmmunitionType.FlameCannonball:
                {
                    Point3D            newPoint    = pnt;
                    List <IEntity>     list        = new List <IEntity>();
                    List <IDamageable> damageables = new List <IDamageable>();

                    for (int i = -lateralOffset; i <= lateralOffset; i++)
                    {
                        if (xOffset == 0)
                        {
                            newPoint = new Point3D(pnt.X + (xOffset + i), pnt.Y + (yOffset * currentRange), pnt.Z);
                        }
                        else
                        {
                            newPoint = new Point3D(pnt.X + (xOffset * currentRange), pnt.Y + (yOffset + i), pnt.Z);
                        }

                        BaseGalleon g = FindValidBoatTarget(newPoint, map, ammo);

                        if (g != null && g != Galleon && g.IsEnemy(Galleon))
                        {
                            list.Add(g);
                        }

                        damageables.AddRange(FindDamageables(shooter, newPoint, map, false, false, false, true, true));
                    }

                    foreach (var m in damageables)
                    {
                        list.Add(m);
                    }

                    if (list.Count > 0)
                    {
                        IEntity toHit = list[Utility.Random(list.Count)];

                        if (toHit is Mobile)
                        {
                            Timer.DelayCall(delay, new TimerStateCallback(OnMobileHit), new object[] { (Mobile)toHit, newPoint, ammo, shooter });
                            hit = true;
                        }
                        else if (toHit is BaseGalleon)
                        {
                            Timer.DelayCall(delay, new TimerStateCallback(OnShipHit), new object[] { (BaseGalleon)toHit, newPoint, ammo, shooter });
                            hit = true;
                        }
                        else if (toHit is DamageableItem)
                        {
                            Timer.DelayCall(delay, new TimerStateCallback(OnDamageableItemHit), new object[] { (DamageableItem)toHit, newPoint, ammo, shooter });
                            hit = true;
                        }
                    }
                }
                break;

                case AmmunitionType.Grapeshot:
                {
                    Point3D       newPoint = pnt;
                    List <Mobile> mobiles  = new List <Mobile>();

                    for (int i = -lateralOffset; i <= lateralOffset; i++)
                    {
                        if (xOffset == 0)
                        {
                            newPoint = new Point3D(pnt.X + (xOffset + i), pnt.Y + (yOffset * currentRange), pnt.Z);
                        }
                        else
                        {
                            newPoint = new Point3D(pnt.X + (xOffset * currentRange), pnt.Y + (yOffset + i), pnt.Z);
                        }

                        mobiles.AddRange(FindDamageables(shooter, newPoint, map, true, true, true, true, false).OfType <Mobile>());
                    }

                    if (mobiles.Count > 0)
                    {
                        Timer.DelayCall(delay, new TimerStateCallback(OnMobileHit), new object[] { mobiles, newPoint, ammo, shooter });
                        hit = true;
                    }
                }
                break;
                }

                if (hit && ammo.SingleTarget)
                {
                    break;
                }
            }

            ClearCannon();
            InvalidateDamageState();

            if (shooter != null)
            {
                ResendGump(shooter);
            }
        }