halloween pumpkin spawning in farmlands.

This commit is contained in:
xavier 2012-10-27 02:26:30 +00:00
parent 97048673e4
commit f110e63e05
2 changed files with 87 additions and 20 deletions

View file

@ -45,31 +45,29 @@ namespace Server.Items
if( item != null && !item.Deleted && item == this && Name == null )
{
if( Utility.RandomBool() )
if( ItemID == 0x4694 || ItemID == 0x4691 || ItemID == 0x4695 || ItemID == 0x4695 )
{
int[][] coord = { new int[] { -3, -3 }, new int[] { -3, 0 }, new int[] { 0, 3 }, new int[] { 3, 3 } };
for( int i=0; i < 4; i++ )
if( Utility.RandomBool() )
{
Point3D loc = new Point3D( from.X + coord[ i ][ 0 ], from.Y + coord[ i ][ 1 ], Map.GetAverageZ( from.X, from.Y ) );
BaseCreature pumpkinhead = new PumpkinHead();
if( Map.CanSpawnMobile( loc ) )
{
BaseCreature pumpkinhead = new PumpkinHead();
pumpkinhead.MoveToWorld( Location, from.Map );
pumpkinhead.FocusMob = from;
pumpkinhead.MoveToWorld( loc, from.Map );
}
Delete();
}
Delete();
}
else
{
else
{
Name = String.Format( "{0}'s Jack-O-antern", staff[ Utility.Random( staff.Length ) ] );
}
}
}
}
public HalloweenPumpkin( Serial serial )
: base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
@ -77,11 +75,6 @@ namespace Server.Items
writer.Write( ( int )0 ); // version
}
public HalloweenPumpkin( Serial serial )
: base( serial)
{
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );

View file

@ -0,0 +1,74 @@
using System;
using Server.Items;
using Server.Events.Halloween;
namespace Server.Engines.Events
{
public class PumpkinPatchSpawner
{
private static Timer m_Timer;
private static Rectangle2D[] m_PumpkinFields =
{
new Rectangle2D( 4557, 1471, 20, 10 ),
new Rectangle2D( 796, 2152, 36, 24 ),
new Rectangle2D( 816, 2251, 16, 8 ),
new Rectangle2D( 816, 2261, 16, 8 ),
new Rectangle2D( 816, 2271, 16, 8 ),
new Rectangle2D( 816, 2281, 16, 8 ),
new Rectangle2D( 835, 2344, 16, 16 ),
new Rectangle2D( 816, 2344, 16, 24 )
};
public static void Initialize()
{
DateTime now = DateTime.Now;
if( DateTime.Now >= HolidaySettings.StartHalloween && DateTime.Now <= HolidaySettings.FinishHalloween )
{
m_Timer = Timer.DelayCall( TimeSpan.Zero, TimeSpan.FromMinutes( .50 ), 0, new TimerCallback( PumpkinPatchSpawnerCallback ));
}
}
protected static void PumpkinPatchSpawnerCallback()
{
AddPumpkin( Map.Felucca );
AddPumpkin( Map.Trammel );
}
private static void AddPumpkin( Map map )
{
for( int i = 0; i < m_PumpkinFields.Length; i++ )
{
Rectangle2D rect = m_PumpkinFields[ i ];
int spawncount = ( ( rect.Height * rect.Width ) / 20 );
int pumpkins = 0;
foreach( Item item in map.GetItemsInBounds( rect ) )
{
if( item is HalloweenPumpkin )
{
pumpkins++;
}
}
if( spawncount > pumpkins )
{
Item item = new HalloweenPumpkin();
item.MoveToWorld( RandomPointIn( rect, map ), map );
}
}
}
private static Point3D RandomPointIn( Rectangle2D rect, Map map )
{
int x = Utility.Random( rect.X, rect.Width );
int y = Utility.Random( rect.Y, rect.Height );
int z = map.GetAverageZ( x, y );
return new Point3D( x, y, z );
}
}
}