using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Server;
using Server.Mobiles;
using Server.Regions;
using Server.Targeting;
using Server.Items;
namespace Server.AutoPVP
{
public class AutoPVP_RegionPreviewTile : Static
{
public override bool DisplayLootType { get { return false; } }
public override bool DisplayWeight { get { return false; } }
public override double DefaultWeight { get { return 0; } }
public override bool Decays { get { return true; } }
public override TimeSpan DecayTime { get { return TimeSpan.FromMinutes(1.0); } }
public AutoPVP_RegionPreviewTile(string name, int hue)
: base(9272, 1)
{
Movable = false;
Name = name;
Hue = hue;
}
public AutoPVP_RegionPreviewTile(Serial serial)
: base(serial)
{ }
public override void Serialize(GenericWriter writer)
{ }
public override void Deserialize(GenericReader reader)
{ Delete(); }
}
public class AutoPVP_RegionParams : IEnumerable
{
private object[] _Args;
public object[] Args { get { return _Args; } set { _Args = (value != null) ? value : new object[0]; } }
public AutoPVP_RegionParams(params object[] args)
{
if (args == null)
{ args = new object[0]; }
_Args = args;
}
public object this[int index]
{
get
{
if (index < 0 || index >= _Args.Length)
{ return null; }
return _Args[index];
}
set
{
if (index < 0 || index >= _Args.Length)
{ return; }
_Args[index] = value;
}
}
public Dictionary<int, T> Select<T>()
{
Dictionary<int, T> list = new Dictionary<int, T>();
for (int index = 0; index < _Args.Length; index++)
{
if (_Args[index] != null && _Args[index] is T)
{ list.Add(index, (T)_Args[index]); }
}
return list;
}
public T Get<T>(int index)
{
if (index < 0 || index >= _Args.Length)
{ return default(T); }
if (_Args[index] != null && _Args[index] is T)
{ return (T)_Args[index]; }
return default(T);
}
public void Set(int index, object value)
{
if (index < 0 || index >= _Args.Length)
{ return; }
_Args[index] = value;
}
public int Add(object value)
{
List<object> args = new List<object>(_Args);
args.Add(value);
int index = args.IndexOf(value);
_Args = args.ToArray();
args.Clear();
return index;
}
public void RemoveAt(int index)
{
if (index < 0 || index >= _Args.Length)
{ return; }
List<object> args = new List<object>(_Args);
args.RemoveAt(index);
_Args = args.ToArray();
args.Clear();
}
public IEnumerator GetEnumerator()
{ return _Args.GetEnumerator(); }
}
[PropertyObject]
public class AutoPVP_Region : BaseRegion
{
private static Dictionary<AutoPVP_Battle, Dictionary<Point3D, AutoPVP_RegionPreviewTile>>
_PreviewTiles = new Dictionary<AutoPVP_Battle, Dictionary<Point3D, AutoPVP_RegionPreviewTile>>();
public static void DisplayPreview(AutoPVP_Battle battle)
{
if (!_PreviewTiles.ContainsKey(battle))
{ _PreviewTiles.Add(battle, new Dictionary<Point3D, AutoPVP_RegionPreviewTile>()); }
int hueBase = 11, hueJump = 11;
try
{
for (int index = 0; index < battle.Options.Locations.Bounds.Count; index++)
{
Rectangle3D rect = battle.Options.Locations.Bounds[index];
Point3D
start = rect.Start,
end = rect.End;
int area = (rect.Width * rect.Height);
if (area > 1024)
{
for (int w = 0; w < rect.Width; w++)
{
AddPreviewTile(battle, hueBase, hueJump, index, start.X + w, start.Y);
AddPreviewTile(battle, hueBase, hueJump, index, end.X - w, end.Y);
}
for (int h = 0; h < rect.Height; h++)
{
AddPreviewTile(battle, hueBase, hueJump, index, start.X, start.Y + h);
AddPreviewTile(battle, hueBase, hueJump, index, end.X, end.Y - h);
}
}
else
{
for (int x = start.X; x < end.X; x++)
{
for (int y = start.Y; y < end.Y; y++)
{ AddPreviewTile(battle, hueBase, hueJump, index, x, y); }
}
}
battle.Ticker.AddHandler(new AutoPVP_BattleTickerHandler(delegate(AutoPVP_BattleTickerHandlerState state)
{
if (index < 0 || index >= battle.Options.Locations.Bounds.Count)
{ return true; }
Rectangle3D subRect = battle.Options.Locations.Bounds[index];
int subArea = (rect.Width * rect.Height);
if (subArea == area && subRect.Start == rect.Start && subRect.End == rect.End)
{ ClearPreview(battle, index); }
return true;
}), battle.Ticker.InternalCounter + (area / 60));
}
}
catch { }
}
public static Point3D GetSurfaceTop(Point3D p, Map map)
{
Point3D point = new Point3D(p.X, p.Y, map.GetAverageZ(p.X, p.Y));
object o = map.GetTopSurface(p);
if (o != null)
{
if (o is LandTile)
{ point.Z = ((LandTile)o).Z + ((LandTile)o).Height; }
else if (o is StaticTile)
{ point.Z = ((StaticTile)o).Z + ((StaticTile)o).Height; }
else if (o is Item)
{ point = ((Item)o).GetSurfaceTop(); }
}
return point;
}
private static void AddPreviewTile(AutoPVP_Battle battle, int hueBase, int hueJump, int index, int x, int y)
{
Point3D p = new Point3D(x, y, 0);
AutoPVP_RegionPreviewTile tile;
if (!_PreviewTiles[battle].ContainsKey(p))
{
tile = new AutoPVP_RegionPreviewTile(AutoPVP_System.GetMessage(41, battle.GameRegionName), hueBase + (hueJump * index));
_PreviewTiles[battle].Add(p, tile);
}
else
{
tile = _PreviewTiles[battle][p];
tile.Hue = hueBase + (hueJump * index);
}
tile.MoveToWorld(GetSurfaceTop(p, battle.Options.Locations.BattleMap), battle.Options.Locations.BattleMap);
}
public static void ClearPreview(AutoPVP_Battle battle)
{
if (!_PreviewTiles.ContainsKey(battle))
{ return; }
try
{
for (int index = 0; index < battle.Options.Locations.Bounds.Count; index++)
{ ClearPreview(battle, index); }
}
catch { }
}
public static void ClearPreview(AutoPVP_Battle battle, int index)
{
if (!_PreviewTiles.ContainsKey(battle))
{ return; }
try
{
Rectangle3D rect = battle.Options.Locations.Bounds[index];
Point3D
start = rect.Start,
end = rect.End;
for (int x = start.X; x < end.X; x++)
{
for (int y = start.Y; y < end.Y; y++)
{
Point3D p = new Point3D(x, y, 0);
if (_PreviewTiles[battle].ContainsKey(p))
{
_PreviewTiles[battle][p].Delete();
_PreviewTiles[battle].Remove(p);
}
}
}
}
catch { }
}
public static Rectangle3D[] AreaHotFix(params Rectangle3D[] rects)
{
if (rects == null)
{ return new Rectangle3D[0]; }
List<Rectangle3D> fixedRects = new List<Rectangle3D>(rects.Length);
foreach (Rectangle3D orig in rects)
{
Point3D start = orig.Start, end = orig.End;
start.Z = MinZ;
end.Z = MaxZ;
fixedRects.Add(new Rectangle3D(start, end));
}
return fixedRects.ToArray();
}
public static bool Contains(Sector s, Point3D p)
{
foreach (RegionRect rRect in s.RegionRects)
{
if (Contains(rRect.Rect, p))
{ return true; }
}
return false;
}
public static bool Contains(Region r, Point3D p)
{ return Contains(r.Area, p); }
public static bool Contains(List<Rectangle3D> rects, Point3D p)
{ return Contains(rects.ToArray(), p); }
public static bool Contains(Rectangle3D[] rects, Point3D p)
{
foreach (Rectangle3D rect in rects)
{
if (Contains(rect, p))
{ return true; }
}
return false;
}
public static bool Contains(Rectangle3D rect, Point3D p)
{ return (p.X >= rect.Start.X && p.Y >= rect.Start.Y && p.X <= rect.End.X && p.Y <= rect.End.Y); }
private AutoPVP_Battle _Battle;
public AutoPVP_Battle Battle { get { return _Battle; } }
private AutoPVP_RegionParams _Args = new AutoPVP_RegionParams();
public AutoPVP_RegionParams Args { get { return _Args; } }
public AutoPVP_Region(AutoPVP_Battle battle, AutoPVP_RegionParams args)
: base(battle.GameRegionName, battle.Options.Locations.BattleMap, battle.Options.Locations.BattlePriority, AreaHotFix(battle.Options.Locations.Bounds.ToArray()))
{
_Battle = battle;
if (args != null)
{ _Args = args; }
}
public AutoPVP_Region(AutoPVP_Battle battle, params object[] args)
: this(battle, new AutoPVP_RegionParams(args))
{ }
public void MicroSync()
{
if (_Battle == null)
{ return; }
OnMicroSync();
}
public virtual void OnMicroSync()
{ }
public virtual void Serialize(GenericWriter writer)
{
int version = 0;
writer.Write(version); //Version
switch (version)
{
case 0: { } break;
}
}
public virtual void Deserialize(GenericReader reader)
{
int version = reader.ReadInt();
switch (version)
{
case 0: { } break;
}
}
public override bool AllowBeneficial(Mobile from, Mobile target)
{
if (_Battle != null)
{ return _Battle.AllowBeneficial(from, target); }
return base.AllowBeneficial(from, target);
}
public override bool AllowHarmful(Mobile from, Mobile target)
{
if (_Battle != null)
{ return _Battle.AllowHarmful(from, target); }
return base.AllowHarmful(from, target);
}
public override bool AllowHousing(Mobile from, Point3D p)
{
if (_Battle != null)
{ return _Battle.AllowHousing(from, p); }
return base.AllowHousing(from, p);
}
public override bool AllowSpawn()
{
if (_Battle != null)
{ return _Battle.AllowSpawn(); }
return base.AllowSpawn();
}
public override bool CanUseStuckMenu(Mobile m)
{
if (_Battle != null)
{ return _Battle.CanUseStuckMenu(m); }
return base.CanUseStuckMenu(m);
}
public override void OnAggressed(Mobile aggressor, Mobile aggressed, bool criminal)
{
if (_Battle != null)
{
_Battle.OnAggressed(aggressor, aggressed, criminal);
return;
}
base.OnAggressed(aggressor, aggressed, criminal);
}
public override bool AcceptsSpawnsFrom(Region region)
{
if (_Battle != null)
{ return _Battle.AcceptsSpawnsFrom(region); }
return base.AcceptsSpawnsFrom(region);
}
public override void AlterLightLevel(Mobile m, ref int global, ref int personal)
{
if (_Battle != null)
{
_Battle.AlterLightLevel(m, ref global, ref personal);
return;
}
base.AlterLightLevel(m, ref global, ref personal);
}
public override bool CheckAccessibility(Item item, Mobile from)
{
if (_Battle != null)
{ return _Battle.CheckAccessibility(item, from); }
return base.CheckAccessibility(item, from);
}
public override TimeSpan GetLogoutDelay(Mobile m)
{
if (_Battle != null)
{ return _Battle.GetLogoutDelay(m); }
return base.GetLogoutDelay(m);
}
public override bool OnDecay(Item item)
{
if (_Battle != null)
{ return _Battle.OnDecay(item); }
return base.OnDecay(item);
}
public override bool OnSingleClick(Mobile m, object o)
{
if (_Battle != null)
{ return _Battle.OnSingleClick(m, o); }
return base.OnSingleClick(m, o);
}
public override bool OnBeforeDeath(Mobile m)
{
if (_Battle != null)
{ return _Battle.OnBeforeDeath(m); }
return base.OnBeforeDeath(m);
}
public override bool OnBeginSpellCast(Mobile m, ISpell s)
{
if (_Battle != null)
{ return _Battle.OnBeginSpellCast(m, s); }
return base.OnBeginSpellCast(m, s);
}
public override void OnBeneficialAction(Mobile helper, Mobile target)
{
if (_Battle != null)
{
_Battle.OnBeneficialAction(helper, target);
return;
}
base.OnBeneficialAction(helper, target);
}
public override bool OnCombatantChange(Mobile m, Mobile oldMob, Mobile newMob)
{
if (_Battle != null)
{ return _Battle.OnCombatantChange(m, oldMob, newMob); }
return base.OnCombatantChange(m, oldMob, newMob);
}
public override void OnCriminalAction(Mobile m, bool message)
{
if (_Battle != null)
{
_Battle.OnCriminalAction(m, message);
return;
}
base.OnCriminalAction(m, message);
}
public override bool OnDamage(Mobile m, ref int damage)
{
if (_Battle != null)
{ return _Battle.OnDamage(m.FindMostRecentDamager(true), m, ref damage); }
return base.OnDamage(m, ref damage);
}
public override void OnDeath(Mobile m)
{
if (_Battle != null)
{
_Battle.OnDeath(m);
return;
}
base.OnDeath(m);
}
public override void OnDidHarmful(Mobile harmer, Mobile harmed)
{
if (_Battle != null)
{
_Battle.OnDidHarmful(harmer, harmed);
return;
}
base.OnDidHarmful(harmer, harmed);
}
public override bool OnDoubleClick(Mobile m, object o)
{
if (_Battle != null)
{ return _Battle.OnDoubleClick(m, o); }
return base.OnDoubleClick(m, o);
}
public override void OnEnter(Mobile m)
{
if (_Battle != null)
{
_Battle.OnEnter(m);
return;
}
base.OnEnter(m);
}
public override void OnExit(Mobile m)
{
if (_Battle != null)
{
_Battle.OnExit(m);
return;
}
base.OnExit(m);
}
public override void OnGotBeneficialAction(Mobile helper, Mobile target)
{
if (_Battle != null)
{
_Battle.OnGotBeneficialAction(helper, target);
return;
}
base.OnGotBeneficialAction(helper, target);
}
public override void OnGotHarmful(Mobile harmer, Mobile harmed)
{
if (_Battle != null)
{
_Battle.OnGotHarmful(harmer, harmed);
return;
}
base.OnGotHarmful(harmer, harmed);
}
public override bool OnHeal(Mobile m, ref int heal)
{
if (_Battle != null)
{
Mobile from = null;
return _Battle.OnHeal(from, m, ref heal);
}
return base.OnHeal(m, ref heal);
}
public override void OnLocationChanged(Mobile m, Point3D oldLocation)
{
if (_Battle != null)
{
_Battle.OnLocationChanged(m, oldLocation);
return;
}
base.OnLocationChanged(m, oldLocation);
}
public override bool OnMoveInto(Mobile m, Direction d, Point3D newLocation, Point3D oldLocation)
{
if (_Battle != null)
{ return _Battle.OnMoveInto(m, d, newLocation, oldLocation); }
return base.OnMoveInto(m, d, newLocation, oldLocation);
}
public override bool OnResurrect(Mobile m)
{
if (_Battle != null)
{ return _Battle.OnResurrect(m); }
return base.OnResurrect(m);
}
public override bool OnSkillUse(Mobile m, int skill)
{
if (_Battle != null)
{ return _Battle.OnSkillUse(m, skill); }
return base.OnSkillUse(m, skill);
}
public override void OnSpeech(SpeechEventArgs args)
{
if (_Battle != null)
{
_Battle.OnSpeech(args);
return;
}
base.OnSpeech(args);
}
public override void OnSpellCast(Mobile m, ISpell s)
{
if (_Battle != null)
{
_Battle.OnSpellCast(m, s);
return;
}
base.OnSpellCast(m, s);
}
public override bool OnTarget(Mobile m, Target t, object o)
{
if (_Battle != null)
{ return _Battle.OnTarget(m, t, o); }
return base.OnTarget(m, t, o);
}
public override void SpellDamageScalar(Mobile caster, Mobile target, ref double damage)
{
if (_Battle != null)
{
_Battle.SpellDamageScalar(caster, target, ref damage);
return;
}
base.SpellDamageScalar(caster, target, ref damage);
}
}
}