Sorthious
Member
I'm trying to fix some errors I found in a script from RunUO....Cursed Pirates...here is a link to the page
http://www.runuo.com/community/threads/cursed-pirates-and-artifacts.60932/
Here is what I've done so far....sorry lots of notes and me stumbling around. Fairly new to C# and scripting. I want to find a way, basically to have it check if player is Dead when it hits OnTick() and if dead or Blessed(immortal) then have it wait like a minute and check again. I'm totally lossed on this and any help would be appreciated...thanks in advance!
http://www.runuo.com/community/threads/cursed-pirates-and-artifacts.60932/
Here is what I've done so far....sorry lots of notes and me stumbling around. Fairly new to C# and scripting. I want to find a way, basically to have it check if player is Dead when it hits OnTick() and if dead or Blessed(immortal) then have it wait like a minute and check again. I'm totally lossed on this and any help would be appreciated...thanks in advance!
Code:
sing System;
using System.Collections;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.Scripts;
namespace Server.Items
{
public abstract class PirateCurse
{
public static void CursedPirateLoot(BaseCreature pirate, int chance)
{
switch (Utility.Random(chance))
{
case 0: pirate.PackItem(new CursedJugOfRum()); break;
}
}
public static void SummonPirate( Mobile m, int i_type )
{
Map map = m.Map;
if (map == null)
return;
bool validLocation = false;
Point3D loc = m.Location;
for (int j = 0; !validLocation && j < 10; ++j)
{
int x = loc.X + Utility.Random(3) - 1;
int y = loc.Y + Utility.Random(3) - 1;
int z = map.GetAverageZ(x, y);
if (validLocation = map.CanFit(x, y, loc.Z, 16, false, false))
loc = new Point3D(x, y, loc.Z);
else if (validLocation = map.CanFit(x, y, z, 16, false, false))
loc = new Point3D(x, y, z);
}
if (!validLocation)
return;
BaseCreature spawn;
switch ( i_type )
{
default: return;
case 0:
{
m.SendMessage("You have summoned a cursed pirate!");
spawn = new CursedPirate();
break;
}
case 1:
{
m.SendMessage("Uh oh, you have summoned the cursed pirate king");
spawn = new CursedPirateKing();
break;
}
}
spawn.FightMode = FightMode.Closest;
spawn.MoveToWorld( loc, map );
spawn.Combatant = m;
}
public static void HurtPlayer(Mobile m)
{
m.SendMessage("Ouch, that hurts");
AOS.Damage(m, m, Utility.RandomMinMax(30, 150), 0, 100, 0, 0, 0);
if (m.Alive && m.Body.IsHuman && !m.Mounted)
m.Animate(20, 7, 1, true, false, 0); // take hit
}
//was static
public static void CursePlayer(Mobile m)
{
if (IsCursed(m))
return;
if (!UnEquipPlayer(m))
return;
ExpireTimer timer = (ExpireTimer)m_Table[m];
if (timer != null)
timer.DoExpire();
else
m.SendMessage("You feel yourself transform into a cursed pirate");
Effects.SendLocationEffect(m.Location, m.Map, 0x3709, 28, 10, 0x1D3, 5);
TimeSpan duration = TimeSpan.FromSeconds(240.0);
//replaced duration with the following:
//_pirateCurseRemainingDuration = DateTime.Now + TimeSpan.FromSeconds(240);
ResistanceMod[] mods = new ResistanceMod[4]
{
new ResistanceMod( ResistanceType.Fire, -10 ),
new ResistanceMod( ResistanceType.Poison, -10 ),
new ResistanceMod( ResistanceType.Cold, +10 ),
new ResistanceMod( ResistanceType.Physical, +10 )
};
timer = new ExpireTimer(m, mods, duration);
timer.Start();
m_Table[m] = timer;
for (int i = 0; i < mods.Length; ++i)
m.AddResistanceMod(mods[i]);
m.ApplyPoison(m, Poison.Greater);
m.Criminal = true;
}
public static bool IsCursed(Mobile m)
{
BankBox bankBox = m.BankBox;
Console.WriteLine("Bank MaxItems at time of IsCurseCheck = {0}", m.BankBox.MaxItems);
if (bankBox == null)
{
Console.WriteLine("IsCursed() and BankBox = null");
return false;
}
Item piratebag = bankBox.FindItemByType(typeof(PirateBag));
if (piratebag == null)
{
Console.WriteLine("PirateBag is null in IsCursed");
return false;
}
m.SendMessage("You are already under the effects of the pirate curse!");
return true;
}
public static bool UnEquipPlayer(Mobile m)
{
ArrayList ItemsToMove = new ArrayList();
PirateBag pirateBag = new PirateBag();
BankBox bankBox = m.BankBox;
//removed following due to players with full banks
//|| !bankBox.TryDropItem(m, bag, false)
if (bankBox == null )
{
Console.WriteLine("BankBox is null in UnEquipPlayer");
pirateBag.Delete();
return false;
}
else
{
Console.WriteLine("Bank MaxItems before adjustments = {0}",m.BankBox.MaxItems);
Console.WriteLine("Backpack MaxItems before adjustments = {0}", m.Backpack.MaxItems);
pirateBag.Owner = m;
pirateBag.PlayerTitle = m.Title;
pirateBag.PlayerHue = m.Hue;
//keep track of MaxItems for Bank/Backpack
pirateBag.PlayerBankMaxItems = m.BankBox.MaxItems;
pirateBag.PlayerBackpackMaxItems = m.Backpack.MaxItems;
//increase bank max items temp to accomodate items
// include TotalItems incase bank is already over cap
//from Holliday Gift Boxes and other stuff
m.BankBox.MaxItems = m.BankBox.TotalItems + 1;
m.BankBox.AddItem(pirateBag);
foreach (Item item in m.Items)
if (item.Layer != Layer.Bank && item.Layer != Layer.Hair && item.Layer != Layer.FacialHair && item.Layer != Layer.Mount && item.Layer != Layer.Backpack)
ItemsToMove.Add(item);
foreach (Item item in ItemsToMove)
{
//increase bank MaxITems for each item in bag
m.BankBox.MaxItems += 1; ;
pirateBag.AddItem(item);
}
Console.WriteLine("Done adding items to PirateBag in UnequipPlayer");
m.Title = "the Cursed Pirate";
m.Hue = Utility.RandomMinMax(0x8596, 0x8599);
EquipPirateItems(m);
}
Console.WriteLine("Returning true in UnequipPlayer");
Console.WriteLine("Bank MaxItems = {0}", m.BankBox.MaxItems);
return true;
}
private static void EquipPirateItems(Mobile player)
{
//Equip the cursed pirate garb.
//Cutlass
Cutlass cutlass = new Cutlass();
cutlass.Movable = false;
cutlass.Skill = SkillName.Swords;
cutlass.Layer = Layer.OneHanded;
player.AddItem(cutlass);
//Fancy Shirt
FancyShirt shirt = new FancyShirt(Utility.RandomNeutralHue());
shirt.Movable = false;
player.AddItem(shirt);
//Long Pants
LongPants pants = new LongPants(Utility.RandomNeutralHue());
pants.Movable = false;
player.AddItem(pants);
//Tricorne Hat
TricorneHat hat = new TricorneHat(Utility.RandomNeutralHue());
hat.Movable = false;
player.AddItem(hat);
//Thigh Boots
ThighBoots boots = new ThighBoots();
boots.Movable = false;
player.AddItem(boots);
}
public static bool UnequipPirateItems(Mobile m)
{
ArrayList ItemsToMove = new ArrayList();
ArrayList ItemsToDelete = new ArrayList();
Bag deletePirateGearBag = new Bag();
BankBox bankBox = m.BankBox;
//removed this from check because players with
//full bank boxes would not be cursed
//|| !bankBox.TryDropItem(m, bag, false)||
if (bankBox == null )
{
deletePirateGearBag.Delete();
return false;
}
else
{
bankBox.MaxItems = bankBox.TotalItems > bankBox.MaxItems ?
bankBox.TotalItems + 1 : bankBox.MaxItems + 1;
bankBox.AddItem(deletePirateGearBag);
}
Bag playerUnequippedItems = new Bag();
playerUnequippedItems.Name = "Pirate Curse Unequiped Items";
playerUnequippedItems.Hue = m.Hue;
Container pack = m.Backpack;
//cut these for same reason as previously
//&& !pack.CheckHold( m, bag2, false, true )
if ( pack == null )
{
playerUnequippedItems.Delete();
return false;
}
//temp increase backpack storage to accomodate xfer
pack.MaxItems = pack.TotalItems > pack.MaxItems ?
pack.TotalItems + 1 : pack.MaxItems + 1;
pack.AddItem(playerUnequippedItems);
foreach (Item item in m.Items)
{
if (item.Layer != Layer.Bank && item.Layer != Layer.Hair && item.Layer != Layer.FacialHair && item.Layer != Layer.Mount && item.Layer != Layer.Backpack)
{
if (item.Layer == Layer.OneHanded || item.Layer == Layer.Shirt || item.Layer == Layer.Pants || item.Layer == Layer.Helm || item.Layer == Layer.Shoes )
ItemsToDelete.Add(item);
else
ItemsToMove.Add(item);
}
}
foreach (Item item in ItemsToDelete)
deletePirateGearBag.AddItem(item);
deletePirateGearBag.Delete();
//need something here to account for increase to players
foreach (Item item in ItemsToMove)
{
//increase pack max items temp to accomodate items
pack.MaxItems = pack.TotalItems > pack.MaxItems ?
pack.TotalItems + 1 : pack.MaxItems + 1;
playerUnequippedItems.AddItem(item);
}
RestorePlayerItems(m);
return true;
}
public static bool RestorePlayerItems(Mobile player)
{
ArrayList ItemsToEquip = new ArrayList();
BankBox bankBox = player.BankBox;
if ( bankBox == null )
return false;
PirateBag pirateBag = (PirateBag)bankBox.FindItemByType( typeof( PirateBag ));
if (pirateBag == null)
{
Console.WriteLine("Returning false in RestorePlayerItems: Piratebag = null");
return false;
}
//PirateBag piratebag = bag as PirateBag;
foreach (Item item in pirateBag.Items)
ItemsToEquip.Add(item);
foreach (Item item in ItemsToEquip)
{
player.AddItem(item);
}
Console.WriteLine("Finished adding items to player in RestorePlayerItems");
player.Title = pirateBag.PlayerTitle;
player.Hue = pirateBag.PlayerHue;
//reset containers MaxItems
player.BankBox.MaxItems = pirateBag.PlayerBankMaxItems;
player.Backpack.MaxItems = pirateBag.PlayerBackpackMaxItems;
pirateBag.Delete();
Console.WriteLine("Bank MaxItems = {0}", player.BankBox.MaxItems);
Console.WriteLine("Backpack MaxItems = {0}", player.Backpack.MaxItems);
return true;
}
private static Hashtable m_Table = new Hashtable();
//why is there a bool returned???
public static bool RemoveCurse(Mobile m)
{
ExpireTimer t = (ExpireTimer)m_Table[m];
if (t == null)
return false;
//place If Alive check here and extend DelayCall?
while (!m.Alive)
{
}
m.SendMessage("The effects of the pirate curse have been removed");
t.DoExpire();
return true;
}
private class ExpireTimer : Timer
{
private Mobile m_Mobile;
private ResistanceMod[] m_Mods;
private DateTime _pirateCurseRemainingDuration;
public DateTime PirateCurseRemainingDuration
{
get { return _pirateCurseRemainingDuration; }
set { _pirateCurseRemainingDuration = value; }
}
public ExpireTimer(Mobile m, ResistanceMod[] mods, TimeSpan delay):base(delay)
{
m_Mobile = m;
m_Mods = mods;
PirateCurseRemainingDuration = DateTime.Now + TimeSpan.FromMinutes(1);
}
public void DoExpire()
{
UnequipPirateItems(m_Mobile);
for (int i = 0; i < m_Mods.Length; ++i)
m_Mobile.RemoveResistanceMod(m_Mods[i]);
if (m_Mobile.Criminal)
m_Mobile.Criminal = false;
if (m_Mobile.Poisoned)
m_Mobile.CurePoison(m_Mobile);
Stop();
m_Table.Remove(m_Mobile);
}
protected override void OnTick()
{
while( !m_Mobile.Alive || !m_Mobile.Blessed)
{
Timer.DelayCall(TimeSpan.FromMinutes(1.0),OnTick);
m_Mobile.SendMessage("The pirates curse endures, even in death!");
}
m_Mobile.SendMessage("You feel the effects of the pirate curse wear off");
DoExpire();
}
}
}
}