AvatarsConquest/Scripts/Quests/Rewards/ScavagerCoin.cs

105 lines
3.5 KiB
C#

using System;
using Server;
using Server.Mobiles;
namespace Server.Items
{
public class ScavengersCoin : Item
{
private DateTime m_NextUse;
[CommandProperty( AccessLevel.GameMaster )]
public DateTime NextUse
{
get { return m_NextUse; }
set { m_NextUse = value; }
}
[Constructable]
public ScavengersCoin() : base( 0x1096 )
{
Name = "Scavenger's Coin";
Weight = 1.0;
Hue = 1175; // A shadowy charcoal hue to fit the stealth theme
}
public override void OnDoubleClick( Mobile from )
{
// 1. Must be in their backpack
if ( !IsChildOf( from.Backpack ) )
{
from.SendLocalizedMessage( 1042001 ); // "That must be in your pack for you to use it."
return;
}
if ( DateTime.UtcNow < m_NextUse )
{
TimeSpan wait = m_NextUse - DateTime.UtcNow;
from.SendMessage( 33, String.Format( "You must wait {0} minutes and {1} seconds before using this again.", wait.Minutes, wait.Seconds ) );
return;
}
SkillMod hideMod = new DefaultSkillMod( SkillName.Hiding, true, 100.0 );
SkillMod stealthMod = new DefaultSkillMod( SkillName.Stealth, true, 100.0 );
from.Hidden = true;
from.UseSkill( SkillName.Stealth );
from.AddSkillMod( hideMod );
from.AddSkillMod( stealthMod );
m_NextUse = DateTime.UtcNow + TimeSpan.FromMinutes( 5 );
from.PlaySound( 0x3CA );
from.FixedParticles( 0x376A, 9, 32, 5005, EffectLayer.Waist );
from.SendMessage( 63, "You flip the coin and are enveloped in unnatural shadows for 60 seconds." );
new ScavengerTimer( from, hideMod, stealthMod ).Start();
}
// --- The Custom Countdown Timer ---
private class ScavengerTimer : Timer
{
private Mobile m_Mobile;
private SkillMod m_HideMod;
private SkillMod m_StealthMod;
public ScavengerTimer( Mobile m, SkillMod hide, SkillMod stealth ) : base( TimeSpan.FromSeconds( 60 ) )
{
m_Mobile = m;
m_HideMod = hide;
m_StealthMod = stealth;
// Priority dictates how strictly the server keeps track of this timer on the main thread
Priority = TimerPriority.OneSecond;
}
protected override void OnTick()
{
// When 60 seconds are up, this code fires
if ( m_Mobile != null )
{
m_Mobile.RemoveSkillMod( m_HideMod );
m_Mobile.RemoveSkillMod( m_StealthMod );
m_Mobile.SendMessage( 33, "The magical shadows fade away, returning your skills to normal." );
}
}
}
public ScavengersCoin( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
// We save the cooldown time so players can't just log out and back in to reset it
writer.Write( m_NextUse );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
m_NextUse = reader.ReadDateTime();
}
}
}