context: using System;
  using System.Collections;
  using System.Collections.Generic;
  using Server.Gumps;
  using Server.Items;
  using Server.Misc;
  using Server.Mobiles;
  using Server.Network;
  
  namespace Server.Misc
  {
      public enum TreasuresOfTokunoEra
      {
          None,
          ToTOne,
          ToTTwo,
          ToTThree
      }
  	
      public class TreasuresOfTokuno
      {
          public const int ItemsPerReward = 10;
  		
          private static readonly Type[] m_LesserArtifactsTotal = new Type[]
          {
              typeof(AncientFarmersKasa), typeof(AncientSamuraiDo), typeof(ArmsOfTacticalExcellence), typeof(BlackLotusHood),
              typeof(DaimyosHelm), typeof(DemonForks), typeof(DragonNunchaku), typeof(Exiler), typeof(GlovesOfTheSun),
              typeof(HanzosBow), typeof(LegsOfStability), typeof(PeasantsBokuto), typeof(PilferedDancerFans), typeof(TheDestroyer),
              typeof(TomeOfEnlightenment), typeof(AncientUrn), typeof(HonorableSwords), typeof(PigmentsOfTokuno), typeof(FluteOfRenewal),
              typeof(LeurociansMempoOfFortune), typeof(LesserPigmentsOfTokuno), typeof(MetalPigmentsOfTokuno), typeof(ChestOfHeirlooms)
          };
  		
          public static Type[] LesserArtifactsTotal
          {
              get
              {
                  return m_LesserArtifactsTotal;
              }
          }
  		
          private static TreasuresOfTokunoEra _DropEra = TreasuresOfTokunoEra.None;
          private static TreasuresOfTokunoEra _RewardEra = TreasuresOfTokunoEra.ToTOne;
  		
          public static TreasuresOfTokunoEra DropEra
          {
              get
              {
                  return _DropEra;
              }
              set
              {
                  _DropEra = value;
              }
          }
  		
          public static TreasuresOfTokunoEra RewardEra
          {
              get
              {
                  return _RewardEra;
              }
              set
              {
                  _RewardEra = value;
              }
          }
  
          private static readonly Type[][] m_LesserArtifacts = new Type[][]
          {
              // ToT One Rewards
              new Type[]
              {
                  typeof(AncientFarmersKasa), typeof(AncientSamuraiDo), typeof(ArmsOfTacticalExcellence), typeof(BlackLotusHood),
                  typeof(DaimyosHelm), typeof(DemonForks), typeof(DragonNunchaku), typeof(Exiler), typeof(GlovesOfTheSun),
                  typeof(HanzosBow), typeof(LegsOfStability), typeof(PeasantsBokuto), typeof(PilferedDancerFans), typeof(TheDestroyer),
                  typeof(TomeOfEnlightenment), typeof(AncientUrn), typeof(HonorableSwords), typeof(PigmentsOfTokuno),
                  typeof(FluteOfRenewal), typeof(ChestOfHeirlooms)
              },
              // ToT Two Rewards
              new Type[]
              {
                  typeof(MetalPigmentsOfTokuno), typeof(AncientFarmersKasa), typeof(AncientSamuraiDo), typeof(ArmsOfTacticalExcellence),
                  typeof(MetalPigmentsOfTokuno), typeof(BlackLotusHood), typeof(DaimyosHelm), typeof(DemonForks),
                  typeof(MetalPigmentsOfTokuno), typeof(DragonNunchaku), typeof(Exiler), typeof(GlovesOfTheSun), typeof(HanzosBow),
                  typeof(MetalPigmentsOfTokuno), typeof(LegsOfStability), typeof(PeasantsBokuto), typeof(PilferedDancerFans), typeof(TheDestroyer),
                  typeof(MetalPigmentsOfTokuno), typeof(TomeOfEnlightenment), typeof(AncientUrn), typeof(HonorableSwords),
                  typeof(MetalPigmentsOfTokuno), typeof(FluteOfRenewal), typeof(ChestOfHeirlooms)
              },
              // ToT Three Rewards
              new Type[]
              {
                  typeof(LesserPigmentsOfTokuno), typeof(AncientFarmersKasa), typeof(AncientSamuraiDo), typeof(ArmsOfTacticalExcellence),
                  typeof(LesserPigmentsOfTokuno), typeof(BlackLotusHood), typeof(DaimyosHelm), typeof(HanzosBow),
                  typeof(LesserPigmentsOfTokuno), typeof(DemonForks), typeof(DragonNunchaku), typeof(Exiler), typeof(GlovesOfTheSun),
                  typeof(LesserPigmentsOfTokuno), typeof(LegsOfStability), typeof(PeasantsBokuto), typeof(PilferedDancerFans), typeof(TheDestroyer),
                  typeof(LesserPigmentsOfTokuno), typeof(TomeOfEnlightenment), typeof(AncientUrn), typeof(HonorableSwords), typeof(FluteOfRenewal),
                  typeof(LesserPigmentsOfTokuno), typeof(LeurociansMempoOfFortune), typeof(ChestOfHeirlooms)
              }
          };
  
          public static Type[] LesserArtifacts 
          { 
              get
              {
                  return m_LesserArtifacts[(int)RewardEra - 1];
              }
          }
  
          private static Type[][] m_GreaterArtifacts = null;
  		
          public static Type[] GreaterArtifacts
          {
              get
              {
                  if (m_GreaterArtifacts == null)
                  {
                      m_GreaterArtifacts = new Type[ToTRedeemGump.NormalRewards.Length][];
  					
                      for (int i = 0; i < m_GreaterArtifacts.Length; i++)
                      {
                          m_GreaterArtifacts[i] = new Type[ToTRedeemGump.NormalRewards[i].Length];
  						
                          for (int j = 0; j < m_GreaterArtifacts[i].Length; j++)
                          {
                              m_GreaterArtifacts[i][j] = ToTRedeemGump.NormalRewards[i][j].Type;
                          }
                      }
                  }
  
                  return m_GreaterArtifacts[(int)RewardEra - 1];
              }
          }
  
          private static bool CheckLocation(Mobile m)
          {
              Region r = m.Region;
  
              if (r.IsPartOf(typeof(Server.Regions.HouseRegion)) || Server.Multis.BaseBoat.FindBoatAt(m, m.Map) != null)
                  return false;
              //TODO: a CanReach of something check as opposed to above?
  
              if (r.IsPartOf("Yomotsu Mines") || r.IsPartOf("Fan Dancer's Dojo"))
                  return true;
  
              return (m.Map == Map.Tokuno);
          }
  
          public static void HandleKill(Mobile victim, Mobile killer)
          {
              PlayerMobile pm = killer as PlayerMobile;
              BaseCreature bc = victim as BaseCreature;
  
              if (DropEra == TreasuresOfTokunoEra.None || pm == null || bc == null || !CheckLocation(bc) || !CheckLocation(pm) || !killer.InRange(victim, 18))
                  return;
  
              if (bc.Controlled || bc.Owners.Count > 0 || bc.Fame <= 0)
                  return;
  
              //25000 for 1/100 chance, 10 hyrus
              //1500, 1/1000 chance, 20 lizard men for that chance.
  
              pm.ToTTotalMonsterFame += (int)(bc.Fame * (1 + Math.Sqrt(pm.Luck) / 100));
  
              //This is the Exponentional regression with only 2 datapoints.
              //A log. func would also work, but it didn't make as much sense.
              //This function isn't OSI exact beign that I don't know OSI's func they used ;p
              int x = pm.ToTTotalMonsterFame;
  
              //const double A = 8.63316841 * Math.Pow( 10, -4 );
              const double A = 0.000863316841;
              //const double B = 4.25531915 * Math.Pow( 10, -6 );
              const double B = 0.00000425531915;
  
              double chance = A * Math.Pow(10, B * x);
  
              if (chance > Utility.RandomDouble())
              {
                  Item i = null;
  				
                  try
                  {
                      i = Activator.CreateInstance(m_LesserArtifacts[(int)DropEra - 1][Utility.Random(m_LesserArtifacts[(int)DropEra - 1].Length)]) as Item;
                  }
                  catch
                  {
                  }
  
                  if (i != null)
                  {
  					killer.PlaySound(0x5B4);
                      pm.SendLocalizedMessage(1062317); // For your valor in combating the fallen beast, a special artifact has been bestowed on you.
  					
                      if (!pm.PlaceInBackpack(i))
                      {
                          if (pm.BankBox != null && pm.BankBox.TryDropItem(killer, i, false))
                              pm.SendLocalizedMessage(1079730); // The item has been placed into your bank box.
                          else
                          {
                              pm.SendLocalizedMessage(1072523); // You find an artifact, but your backpack and bank are too full to hold it.
                              i.MoveToWorld(pm.Location, pm.Map);
                          }
                      }
  					
                      pm.ToTTotalMonsterFame = 0;
                  }
              }
          }
      }
  }
  
  namespace Server.Mobiles
  {
      public class IharaSoko : BaseVendor
      {
          public override bool IsActiveVendor
          {
              get
              {
                  return false;
              }
          }
          public override bool IsInvulnerable
          {
              get
              {
                  return true;
              }
          }
          public override bool DisallowAllMoves
          {
              get
              {
                  return true;
              }
          }
          public override bool ClickTitle
          {
              get
              {
                  return true;
              }
          }
          public override bool CanTeach
          {
              get
              {
                  return false;
              }
          }
  
          protected List<SBInfo> m_SBInfos = new List<SBInfo>();
          protected override List<SBInfo> SBInfos
          {
              get
              {
                  return this.m_SBInfos;
              }
          }
  		
          public override void InitSBInfo()
          {
          }
  
          public override void InitOutfit()
          {
              this.AddItem(new Waraji(0x711));
              this.AddItem(new Backpack());
              this.AddItem(new Kamishimo(0x483));
  
              Item item = new LightPlateJingasa();
              item.Hue = 0x711;
  
              this.AddItem(item);
          }
  
          [Constructable]
          public IharaSoko()
              : base("the Imperial Minister of Trade")
          {
              this.Name = "Ihara Soko";
              this.Female = false;
              this.Body = 0x190;
              this.Hue = 0x8403;
          }
  
          public IharaSoko(Serial serial)
              : base(serial)
          {
          }
  
          public override void Serialize(GenericWriter writer)
          {
              base.Serialize(writer);
  
              writer.Write((int)0);
          }
  		
          public override void Deserialize(GenericReader reader)
          {
              base.Deserialize(reader);
  
  
gt:             int version = reader.ReadInt();