Ejemplo n.º 1
0
		private static void ExportStatics1( Mobile from, Map map, Point3D start, Point3D end, object state )
		{
			//World.Broadcast( 0x35, true, "Export file is being generated, please wait." );
			from.SendMessage( "Export file is being generated. Please wait." );

			DateTime startTime = DateTime.Now;
			DirectoryInfo di = null;
			if( !Directory.Exists( path ) )
				di = Directory.CreateDirectory( path );
			path = string.Format( @".\Exports\" + name + ".cs" );

			using( StreamWriter sw = File.CreateText( path ) )
			{
				int x = end.X - start.X;
				int y = end.Y - start.Y;
				int z1 = 0;
				StaticTarget st = null;
				StaticTile[] statics;
				LandTile[] tiles;
				//======================================================================================
				sw.WriteLine( "using System;" );
				sw.WriteLine( "using Server;" );
				sw.WriteLine( "using Server.Items;" );
				sw.WriteLine( "using Server.Targeting;" );
				sw.WriteLine( "namespace Server.Scripts.Commands" );
				sw.WriteLine( "{" );
				sw.WriteLine( "\tpublic class " + name );
				sw.WriteLine( "\t{" );
				sw.WriteLine( "\t\tpublic static void Initialize()" );
				sw.WriteLine( "\t\t{" );
				sw.WriteLine( "\t\t\tCommandSystem.Register( \"" + name + "\", AccessLevel.Administrator, new CommandEventHandler( " + name + "_OnCommand ) );" );
				sw.WriteLine( "\t\t}" );
				sw.WriteLine( "\t\t[Usage( \"" + name + "\" )]" );
				sw.WriteLine( "\t\t[Description( \"Creates a replica of an exported static\" )]" );
				sw.WriteLine( "\t\tprivate static void " + name + "_OnCommand( CommandEventArgs e )" );
				sw.WriteLine( "\t\t{" );
				sw.WriteLine( "\t\t\te.Mobile.Target = new InternalTarget();" );
				sw.WriteLine( "\t\t}" );
				sw.WriteLine( "\t\tprivate class InternalTarget : Target" );
				sw.WriteLine( "\t\t\t{" );
				sw.WriteLine( "\t\t\tpublic InternalTarget() : base( 6, true, TargetFlags.None )" );
				sw.WriteLine( "\t\t\t{" );
				sw.WriteLine( "\t\t\t}" );
				sw.WriteLine( "\t\t\tprotected override void OnTarget( Mobile from, object o )" );
				sw.WriteLine( "\t\t\t{" );
				sw.WriteLine( "\t\t\tStatic item = null;" );
				//======================================================================================
				tiles = from.Map.Tiles.GetLandBlock( start.X, start.Y );
				for( int a = 0; a < tiles.Length; a++ )
				{
					try
					{
						z1 = tiles[a].Z;
					}
					catch { sw.WriteLine( "No location for tile" ); }
				}
				for( int i = 0; i < x; i++ )
				{
					for( int j = 0; j < y; j++ )
					{
						statics = from.Map.Tiles.GetStaticTiles( start.X + i, start.Y + j, true );
						for( int z = 0; z < statics.Length; z++ )
						{
							st = new StaticTarget( new Point3D( start.X + i, start.Y + j, statics[z].Z ), statics[z].ID );
							sw.WriteLine( "\t\t\titem = new Static(" + st.ItemID + ");" );
							sw.WriteLine( "\t\t\titem.Movable = false;" );
							sw.WriteLine( "\t\t\titem.Location = new Point3D( ((IPoint3D)o).X + " + i + ", ((IPoint3D)o).Y + " + j + ", ((IPoint3D)o).Z + " + (statics[z].Z - z1) + ");" );
							sw.WriteLine( "\t\t\titem.Map = from.Map;" );
							sw.WriteLine( "" );
						}
					}
				}
				sw.WriteLine( "\t\t\t}" );
				sw.WriteLine( "\t\t}" );
				sw.WriteLine( "\t}" );
				sw.WriteLine( "}" );
				DateTime endTime = DateTime.Now;

				//World.Broadcast( 0x35, true, "Export file has been completed. The entire process took {0:F1} seconds.", (endTime - startTime).TotalSeconds );
				from.SendMessage( "Export file has been completed. The entire process took {0:F1} seconds.", (endTime - startTime).TotalSeconds );
				path = string.Format( @".\Exports" );
			}
		}
Ejemplo n.º 2
0
		public static void TargetResponse( NetState state, PacketReader pvSrc )
		{
			int type = pvSrc.ReadByte();
			int targetID = pvSrc.ReadInt32();
			int flags = pvSrc.ReadByte();
			Serial serial = pvSrc.ReadInt32();
			int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
			int graphic = pvSrc.ReadUInt16();

			if ( targetID == unchecked( (int) 0xDEADBEEF ) )
				return;

			Mobile from = state.Mobile;

			Target t = from.Target;

			if ( t != null )
			{
				TargetProfile prof = TargetProfile.Acquire( t.GetType() );

				if ( prof != null ) {
					prof.Start();
				}

				try {
					if ( x == -1 && y == -1 && !serial.IsValid )
					{
						// User pressed escape
						t.Cancel( from, TargetCancelType.Canceled );
					}
					else if ( Target.TargetIDValidation && t.TargetID != targetID )
					{
						// Sanity, prevent fake target
						return;
					}
					else
					{
						object toTarget;

						if ( type == 1 )
						{
							if ( graphic == 0 )
							{
								toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
							}
							else
							{
								Map map = from.Map;

								if ( map == null || map == Map.Internal )
								{
									t.Cancel( from, TargetCancelType.Canceled );
									return;
								}
								else
								{
									StaticTile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );

									bool valid = false;

									if ( state.HighSeas ) {
										ItemData id = TileData.ItemTable[graphic&TileData.MaxItemValue];
										if ( id.Surface ) {
											z -= id.Height;
										}
									}

									for ( int i = 0; !valid && i < tiles.Length; ++i )
									{
										if ( tiles[i].Z == z && tiles[i].ID == graphic )
											valid = true;
									}

									if ( !valid )
									{
										t.Cancel( from, TargetCancelType.Canceled );
										return;
									}
									else
									{
										toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
									}
								}
							}
						}
						else if ( serial.IsMobile )
						{
							toTarget = World.FindMobile( serial );
						}
						else if ( serial.IsItem )
						{
							toTarget = World.FindItem( serial );
						}
						else
						{
							t.Cancel( from, TargetCancelType.Canceled );
							return;
						}

						t.Invoke( from, toTarget );
					}
				} finally {
					if ( prof != null ) {
						prof.Finish();
					}
				}
			}
		}
Ejemplo n.º 3
0
		private void AddSingleCallback( StaticTarget st )
		{
			Tile tile = new Tile( (short) ( st.ItemID + 16384 ), (sbyte) st.Z );
			Point2D p = new Point2D( st.X, st.Y );

			ArrayList current = m_Tiles[ p ] as ArrayList;

			if ( current != null )
			{
				if ( ! current.Contains( tile ) )
				{
					current.Add( tile );
				}
			}
			else
			{
				current = new ArrayList();
				current.Add( tile );
				m_Tiles[ p ] = current;
			}

			ResendGump();
		}
		public static void TargetResponse( NetState state, PacketReader pvSrc )
		{
			int type = pvSrc.ReadByte();
			int targetID = pvSrc.ReadInt32();
			/*int flags = */pvSrc.ReadByte();
			Serial serial = pvSrc.ReadInt32();
			int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
			int graphic = pvSrc.ReadInt16();

			if ( targetID == unchecked( (int) 0xDEADBEEF ) )
				return;

			Mobile from = state.Mobile;

			Target t = from.Target;

			if ( t != null )
			{
				if ( x == -1 && y == -1 && !serial.IsValid )
				{
					// User pressed escape
					t.Cancel( from, TargetCancelType.Canceled );
				}
				else
				{
					object toTarget;

					if ( type == 1 )
					{
						if ( graphic == 0 )
						{
							toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
						}
						else
						{
							Map map = from.Map;

							if ( map == null || map == Map.Internal )
							{
								t.Cancel( from, TargetCancelType.Canceled );
								return;
							}
							else
							{
								Tile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );

								bool valid = false;

								for ( int i = 0; !valid && i < tiles.Length; ++i )
								{
									if ( tiles[i].Z == z && (tiles[i].ID & 0x3FFF) == (graphic & 0x3FFF) )
										valid = true;
								}

								if ( !valid )
								{
									t.Cancel( from, TargetCancelType.Canceled );
									return;
								}
								else
								{
									toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
								}
							}
						}
					}
					else if ( serial.IsMobile )
					{
						toTarget = World.FindMobile( serial );
					}
					else if ( serial.IsItem )
					{
						toTarget = World.FindItem( serial );
					}
					else
					{
						t.Cancel( from, TargetCancelType.Canceled );
						return;
					}

					try {
						t.Invoke( from, toTarget );
					} catch (Exception e) {
						log.Fatal(String.Format("Exception disarmed in target {0} > {1} > {2}",
												from, t, toTarget), e);
					}
				}
			}
		}
Ejemplo n.º 5
0
		public void SmeltOre( Mobile from )
		{
			object forge = null;

			IPooledEnumerable eable = from.GetItemsInRange( 2 );

			foreach ( Item item in eable )
			{
				if ( IsForge( item ) )
				{
					forge = item;
					break;
				}
			}

			eable.Free();

			eable = from.GetMobilesInRange( 2 );

			foreach ( Mobile mob in eable )
			{
				if ( IsForge( mob ) )
				{
					forge = mob;
					break;
				}
			}

			eable.Free();

			if ( forge == null )
			{
				for ( int x = from.X-2;forge == null && x < from.X+2; x++ )
				{
					for ( int y = from.Y-2;forge == null &&  y < from.Y+2; y++ )
					{
						StaticTile[] tiles = from.Map.Tiles.GetStaticTiles( x, y, true );
						for ( int j = 0;forge == null && j < tiles.Length; j++ )
						{
							StaticTarget st = new StaticTarget( tiles[j], tiles[j].ID );
							if ( IsForge( st ) )
								forge = st;
						}
					}
				}
			}

			if ( forge != null )
			{
				double difficulty;

				switch ( Resource )
				{
					default: difficulty = 50.0; break;
					case CraftResource.DullCopper: difficulty = 65.0; break;
					case CraftResource.ShadowIron: difficulty = 70.0; break;
					case CraftResource.Copper: difficulty = 75.0; break;
					case CraftResource.Bronze: difficulty = 80.0; break;
					case CraftResource.Gold: difficulty = 85.0; break;
					case CraftResource.Agapite: difficulty = 90.0; break;
					case CraftResource.Verite: difficulty = 95.0; break;
					case CraftResource.Valorite: difficulty = 99.0; break;
				}

				double minSkill = difficulty - 25.0;
				double maxSkill = difficulty + 25.0;

				if ( difficulty > 50.0 && difficulty > from.Skills[SkillName.Mining].Value )
					from.SendLocalizedMessage( 501986 ); // You have no idea how to smelt this strange ore!
				//else if ( Amount <= 1 )
				//	from.SendLocalizedMessage( 501987 ); // There is not enough metal-bearing ore in this pile to make an ingot.
				else
				{
					/*
					int successes = 0;
					int count = Amount / 2;

					for ( int i = 0;i < count; i++ )
						if ( from.CheckTargetSkill( SkillName.Mining, forge, minSkill, maxSkill ) )
							successes++;

					Consume( count * 2 );

					if ( successes > 0 )
					{
						string[] locals = new string[3];

						BaseIngot ingot = GetIngot();
						ingot.Amount = successes;

						if ( Parent != from.Backpack && Parent is Container && RootParent == from && ((Container)Parent).TryDropItem( from, ingot, false ) ) //Its in a container, on the player
						{
							if ( locals[0] == null )
								locals[0] = "back in the same container";
						}
						else if ( from.AddToBackpack( ingot ) )
						{
							if ( locals[1] == null )
								locals[1] = "in your backpack";
						}
						else	if ( locals[2] == null )
								locals[2] = "on the floor";

						string localText = String.Empty;
						//Trimmed list
						List<string> localslist = new List<string>();
						for ( int i = 0;i < locals.Length; i++ )
							if ( locals[i] != null )
								localslist.Add( locals[i] );

						//We know there is at least ONE location
						localText = localslist[0];

						for ( int i = 1;i < localslist.Count; i++ )
							localText = String.Format( "{0},{1}{2}", localText, (i+1 < localslist.Count) ? " and" : " ", localslist[i] );

						from.SendMessage( "You smelt the ore removing the impurities and put the metal {0}.", localText );
					}
					else
						from.SendLocalizedMessage( 501990 ); // You burn away the impurities but are left with less useable metal.

					from.PlaySound( 0x2B ); // Smelting/Bellow noise
*/
					bool atcap = from.Skills[SkillName.Mining].Value > from.Skills[SkillName.Mining].Cap || from.Skills[SkillName.Mining].Value >= maxSkill;
					//int amountIngot = atcap ? (Amount / 2) : 1;
					//int amountOre = amountIngot * 2;
					int amountIngot = atcap ? Amount : 1;
					from.PlaySound( 0x2B ); // Smelting/Bellow noise

					if ( from.CheckTargetSkill( SkillName.Mining, forge, minSkill, maxSkill ) )
					{
						string[] locals = new string[3];

						BaseIngot ingot = GetIngot();
                        double chanceOfDoublingIronSmelt = from.Skills[SkillName.Mining].Value / 200.0; // 50% chance at 100
                        if (ingot.Resource == CraftResource.Iron && chanceOfDoublingIronSmelt > Utility.RandomDouble()) // per 10 skill, 5% chance of 2 ingots
                        {
                            ingot.Amount = amountIngot * 2;
                            from.SendMessage("You skillfully extract extra metal out of the ore pile.");
                        }
                        else
                        {
                            ingot.Amount = amountIngot;
                        }

						if ( Parent != from.Backpack && Parent is Container && RootParent == from && ((Container)Parent).TryDropItem( from, ingot, false ) ) //Its in a container, on the player
						{
							if ( locals[0] == null )
								locals[0] = "back in the same container";
						}
						else if ( from.AddToBackpack( ingot ) )
						{
							if ( locals[1] == null )
								locals[1] = "in your backpack";
						}
						else	if ( locals[2] == null )
								locals[2] = "on the floor";

						string localText = String.Empty;
						//Trimmed list
						List<string> localslist = new List<string>();
						for ( int i = 0;i < locals.Length; i++ )
							if ( locals[i] != null )
								localslist.Add( locals[i] );

						//We know there is at least ONE location
						localText = localslist[0];

						for ( int i = 1;i < localslist.Count; i++ )
							localText = String.Format( "{0},{1}{2}", localText, (i+1 < localslist.Count) ? " and" : " ", localslist[i] );

						from.SendMessage( "You smelt the ore removing the impurities and put the metal {0}.", localText );
						Consume( amountIngot );
					}
					else
					{
						Consume( Math.Max(amountIngot / 2, 1) );
						from.SendLocalizedMessage( 501990 ); // You burn away the impurities but are left with less useable metal.
					}
				}
			}
			else
				from.SendLocalizedMessage( 500420 ); // You are not near a forge.
		}
Ejemplo n.º 6
0
        public static void TargetResponse( NetState state, PacketReader pvSrc )
        {
            int type = pvSrc.ReadByte();
            int targetID = pvSrc.ReadInt32();
            int flags = pvSrc.ReadByte();
            Serial serial = pvSrc.ReadInt32();
            int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
            int graphic = pvSrc.ReadInt16();

            Mobile from = state.Mobile;

            Target t = from.Target;

            if ( t != null )
            {
                TargetProfile prof = TargetProfile.Acquire( t.GetType() );

                if ( prof != null ) {
                    prof.Start();
                }

                try {
                    if (( x == -1 && y == -1 && !serial.IsValid ) || ( targetID == unchecked( (int) 0xDEADBEEF ) ))
                    {
                        // User pressed escape
                        t.Cancel( from, TargetCancelType.Canceled );
                    }
                    else
                    {
                        object toTarget;

                        if ( type == 1 )
                        {
                            if ( graphic == 0 )
                            {
                                toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
                            }
                            else
                            {
                                Map map = from.Map;

                                if ( map == null || map == Map.Internal )
                                {
                                    t.Cancel( from, TargetCancelType.Canceled );
                                    return;
                                }
                                else
                                {
                                    Tile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );

                                    bool valid = false;

                                    for ( int i = 0; !valid && i < tiles.Length; ++i )
                                    {
                                        if ( tiles[i].Z == z && (tiles[i].ID & 0x3FFF) == (graphic & 0x3FFF) )
                                            valid = true;
                                    }

                                    if ( !valid )
                                    {
                                        t.Cancel( from, TargetCancelType.Canceled );
                                        return;
                                    }
                                    else
                                    {
                                        toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
                                    }
                                }
                            }
                        }
                        else if ( serial.IsMobile )
                        {
                            toTarget = World.FindMobile( serial );
                        }
                        else if ( serial.IsItem )
                        {
                            toTarget = World.FindItem( serial );
                        }
                        else
                        {
                            t.Cancel( from, TargetCancelType.Canceled );
                            return;
                        }

                        t.Invoke( from, toTarget );
                    }
                } finally {
                    if ( prof != null ) {
                        prof.Finish();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void Invoke(Mobile from, object targeted)
        {
            CancelTimeout();
            from.ClearTarget();

            if (from.Deleted)
            {
                OnTargetCancel(from, TargetCancelType.Canceled);
                OnTargetFinish(from);
                return;
            }

            Point3D loc               = default;
            Map     map               = null;
            Item    item              = null;
            Mobile  mobile            = null;
            bool    isValidTargetType = true;

            bool valid = targeted switch
            {
                LandTarget landTarget => CanTarget(from, landTarget, ref loc, ref map),
                StaticTarget staticTarget => CanTarget(from, staticTarget, ref loc, ref map),
                Item i => CanTarget(from, item     = i, ref loc, ref map),
                Mobile m => CanTarget(from, mobile = m, ref loc, ref map),
                _ => isValidTargetType             = false
            };

            if (!valid)
            {
                if (!isValidTargetType)
                {
                    OnTargetCancel(from, TargetCancelType.Canceled);
                }

                OnTargetFinish(from);
            }

            if (map == null || map != from.Map || Range >= 0 && !from.InRange(loc, Range))
            {
                OnTargetOutOfRange(from, targeted);
            }
            else if (!from.CanSee(targeted))
            {
                OnCantSeeTarget(from, targeted);
            }
            else if (CheckLOS && !from.InLOS(targeted))
            {
                OnTargetOutOfLOS(from, targeted);
            }
            else if (item?.InSecureTrade == true)
            {
                OnTargetInSecureTrade(from, targeted);
            }
            else if (item?.IsAccessibleTo(from) == false)
            {
                OnTargetNotAccessible(from, targeted);
            }
            else if (item?.CheckTarget(from, this, targeted) == false)
            {
                OnTargetUntargetable(from, targeted);
            }
            else if (mobile?.CheckTarget(from, this, mobile) == false)
            {
                OnTargetUntargetable(from, mobile);
            }
            else if (from.Region.OnTarget(from, this, targeted))
            {
                OnTarget(from, targeted);
            }

            OnTargetFinish(from);
        }
Ejemplo n.º 8
0
 protected virtual bool CanTarget(Mobile from, StaticTarget staticTarget, ref Point3D loc, ref Map map)
 {
     loc = staticTarget.Location;
     map = from.Map;
     return(true);
 }
Ejemplo n.º 9
0
        public void TargetResponse( GameClient state, PacketReader pvSrc )
        {
            int type = pvSrc.ReadByte();
            /*int targetID = */
            pvSrc.ReadInt32();
            /*int flags = */
            pvSrc.ReadByte();
            Serial serial = pvSrc.ReadInt32();
            int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
            int graphic = pvSrc.ReadInt16();

            Mobile from = state.Mobile;

            Target t = from.Target;

            if ( t == null )
            {
                state.NullTargets++;

                if ( state.NullTargets > GameClient.MaxNullTargets )
                {
                    state.Dispose();
                    return;
                }
            }
            else
            {
                state.NullTargets = 0;

                if ( x == -1 && y == -1 && !serial.IsValid )
                {
                    // User pressed escape
                    t.Cancel( from, TargetCancelType.Canceled );
                }
                else
                {
                    object toTarget;

                    if ( type == 1 )
                    {
                        if ( graphic == 0 )
                        {
                            toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
                        }
                        else
                        {
                            Map map = from.Map;

                            if ( map == null || map == Map.Internal )
                            {
                                t.Cancel( from, TargetCancelType.Canceled );
                                return;
                            }
                            else
                            {
                                Tile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );

                                bool valid = false;

                                for ( int i = 0; !valid && i < tiles.Length; ++i )
                                {
                                    bool surface = ( TileData.ItemTable[tiles[i].ID & TileData.MaxItemValue].Flags & TileFlag.Surface ) != 0;
                                    int zOffset = surface ? tiles[i].Height : 0;

                                    if ( ( tiles[i].Z + zOffset ) == z && ( tiles[i].ID & TileData.MaxItemValue ) == ( graphic & TileData.MaxItemValue ) )
                                    {
                                        valid = true;
                                        z -= zOffset;
                                    }
                                }

                                if ( !valid )
                                {
                                    t.Cancel( from, TargetCancelType.Canceled );
                                    return;
                                }
                                else
                                {
                                    toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
                                }
                            }
                        }
                    }
                    else if ( serial.IsMobile )
                    {
                        toTarget = World.Instance.FindMobile( serial );
                    }
                    else if ( serial.IsItem )
                    {
                        toTarget = World.Instance.FindItem( serial );
                    }
                    else
                    {
                        t.Cancel( from, TargetCancelType.Canceled );
                        return;
                    }

                    try
                    {
                        t.Invoke( from, toTarget );
                    }
                    catch ( Exception e )
                    {
                        Logger.Error( "Exception disarmed in target {0} > {1} > {2}: {3}", from, t, toTarget, e );
                    }
                }
            }
        }