Ignacio Vazquez-Abrams
Wanderer
Of course not. You initialize actualhours to 0 and never change it.
else if ( hours <= 0 && hours >= 0 )
{
day += 1;
}
worldTime = String.Format( "{0}/{1}/{2} B.T.", month, day, year );
//worldTime = String.Format( "Disabled" );
hours %= 12;
if ( hours == 0 )
{
hours = 12;
}
int actualhours = hours % 24;
clockTime = String.Format( "{0}:{1} {2}", hours, minutes, actualhours >= 12 ? "R.C." : "F.C." );
//clockTime = String.Format( "Disabled" );
}
hours %= 12;
if ( hours == 0 )
{
hours = 12;
}
int actualhours = hours % 24;
int actualhours = hours % 24;
hours %= 12;
if ( hours == 0 )
hours = 12;
clockTime = String.Format( "{0}:{1} {2}", hours, minutes, actualhours >= 12 ? "R.C." : "F.C." );
hours %= 12;
if ( hours == 0 )
hours = 12;
Ignacio Vazquez-Abrams said:The % is the modulus operator. For two integers x and y, it does x / y and returns the remainder. So 3 % 2 is 1, 10 % 4 is 2, and so on.
So, what your code does is:
1) Takes the modulus of hours and 12 and assigns it to hours,
2) If hours equals 0 then it assigns 12 to hours, and
3) Assigns the modulus of hours and 24 to a newly-declared variable called actualhours.
No, that doesn't sound right for keeping time, does it?
public static void WorldTime( Mobile from, out string worldTime, out string clockTime )
{
int hours;
int minutes;
Server.Items.Clock.GetTime(from.Map, from.Location.X, from.Location.Y, out hours, out minutes);
int day = 41; // Default Day;
int month = 10; // Default Month;
int year = 22556; // You can change the year to whatever you want
if ( month == 11 )
{
day = 1;
month = 1;
year -= 1;
}
if ( day == 42 )
{
month += 1;
day = 1;
}
if ( hours >= 0 )
{
day += 1;
}
//worldTime = String.Format( "{0}/{1}/{2} B.T.", month, day, year );
worldTime = String.Format( "Disabled" );
private static DateTime WorldStart = new DateTime( 1997, 9, 1 );
private static DateTime WorldStart = new DateTime( 22548, 1, 1 );
using System;
using Server;
namespace Server.Items
{
public enum MoonPhase
{
NewMoon,
WaxingCrescentMoon,
FirstQuarter,
WaxingGibbous,
FullMoon,
WaningGibbous,
LastQuarter,
WaningCrescent
}
[Flipable( 0x104B, 0x104C )]
public class Clock : Item
{
private static DateTime m_ServerStart;
public static DateTime ServerStart
{
get{ return m_ServerStart; }
}
public static void Initialize()
{
m_ServerStart = DateTime.Now;
}
[Constructable]
public Clock() : this( 0x104B )
{
}
[Constructable]
public Clock( int itemID ) : base( itemID )
{
Weight = 3.0;
}
public Clock( Serial serial ) : base( serial )
{
}
public const double SecondsPerALMinute = 4;
public const double MinutesPerALDay = SecondsPerALMinute * 24;
private static DateTime WorldStart = new DateTime( 1997, 9, 1 );
public static MoonPhase GetMoonPhase( Map map, int x, int y )
{
int hours, minutes, totalMinutes;
GetTime( map, x, y, out hours, out minutes, out totalMinutes );
if ( map != null )
totalMinutes /= 10 + (map.MapIndex * 20);
return (MoonPhase)(totalMinutes % 8);
}
public static void GetTime( Map map, int x, int y, out int hours, out int minutes )
{
int totalMinutes;
GetTime( map, x, y, out hours, out minutes, out totalMinutes );
}
public static void GetTime( Map map, int x, int y, out int hours, out int minutes, out int totalMinutes )
{
TimeSpan timeSpan = DateTime.Now - WorldStart;
totalMinutes = (int)(timeSpan.TotalSeconds / SecondsPerALMinute);
if ( map != null )
totalMinutes += map.MapIndex * 320;
totalMinutes += x / 16;
hours = (totalMinutes / 60) % 24;
minutes = totalMinutes % 60;
}
public static void GetTime( out string generalString, out string exactTime )
{
GetTime( null, 0, 0, out generalString, out exactTime );
}
public static void GetTime( Mobile from, out string generalString, out string exactTime )
{
GetTime( from.Map, from.X, from.Y, out generalString, out exactTime );
}
public static void GetTime( Map map, int x, int y, out string generalString, out string exactTime )
{
int hours, minutes;
GetTime( map, x, y, out hours, out minutes );
// 00:00 AM - 00:59 AM : Witching hour
// 01:00 AM - 03:59 AM : Middle of night
// 04:00 AM - 07:59 AM : Early morning
// 08:00 AM - 11:59 AM : Late morning
// 12:00 PM - 12:59 PM : Noon
// 01:00 PM - 03:59 PM : Afternoon
// 04:00 PM - 07:59 PM : Early evening
// 08:00 PM - 11:59 AM : Late at night
if ( hours >= 20 )
generalString = String.Format( "It's late at frusk *Night*" ); // It's late at night
else if ( hours >= 16 )
generalString = String.Format( "It's early in the dusk *Evening*" ); // It's early in the evening
else if ( hours >= 13 )
generalString = String.Format( "It's the Middawn *AfterNoon*" ); // It's the afternoon
else if ( hours >= 12 )
generalString = String.Format( "It's Noon *Noon*" ); // It's around noon
else if ( hours >= 08 )
generalString = String.Format( "It's rising to morrow *Morning*" ); // It's late in the morning
else if ( hours >= 04 )
generalString = String.Format( "It's early of Dawns *Early Morning*" ); // It's early in the morning
else if ( hours >= 01 )
generalString = String.Format( "It's the middle of frusk *Middle Night*" ); // It's the middle of the night
else
generalString = String.Format( "'Tis the chiming hour. 12 Midfrusk *Midnight*" ); // 'Tis the witching hour. 12 Midnight.
hours %= 12;
if ( hours == 0 )
hours = 12;
exactTime = String.Format( "{0}:{1:D2}", hours, minutes );
}
public override void OnDoubleClick( Mobile from )
{
string generalString;
string exactTime;
GetTime( from, out generalString, out exactTime );
SendLocalizedMessageTo( from, 1042971, generalString );
SendLocalizedMessageTo( from, 1042958, exactTime ); // ~1_TIME~ to be exact
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
if ( Weight == 2.0 )
Weight = 3.0;
}
}
[Flipable( 0x104B, 0x104C )]
public class ClockRight : Clock
{
[Constructable]
public ClockRight() : base( 0x104B )
{
}
public ClockRight( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
[Flipable( 0x104B, 0x104C )]
public class ClockLeft : Clock
{
[Constructable]
public ClockLeft() : base( 0x104C )
{
}
public ClockLeft( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}
It implodes your shard.awakenlands said:if i change this
Code:private static DateTime WorldStart = new DateTime( 1997, 9, 1 );
to this
Code:private static DateTime WorldStart = new DateTime( 22548, 1, 1 );
what does it do??? in Clocks...