
using System;
using System.Drawing;
using Phoenix;
using Phoenix.WorldData;
using System.Collections.Generic;
namespace Phoenix.Scripts
{
public class MapsArrange
{
[Executable]
public void mapy()
{
// Radius pro slucovani mapek
const ushort mapRadX = 150;
const ushort mapRadY = 150;
// Odsazeni jednolivych hromadek
const ushort bagStepX = 15;
const ushort bagStepY = 15;
// Pocatecni pozice v pytliku
const ushort bagMinPosX = 16;
const ushort bagMinPosY = 20;
// Koncova pozice v pytliku
const ushort bagPosMaxX = 100;
// -------------- Script ------------------ //
const string coordpref = "Map is located at ";
UO.Print("Targetni bagl s mapkama");
Serial bagl = UIManager.TargetObject();
Point actBagPos = new Point(bagMinPosX, bagMinPosY);
List<KeyValuePair<Point, Point>> coords = new List<KeyValuePair<Point, Point>>();
foreach (UOItem item in World.GetItem(bagl).AllItems)
{
if (item.Graphic == 0x14EB)
{
Journal.Clear();
item.Grab();
item.Use();
UO.Wait(800);
if (Journal.Contains(coordpref))
{
int i = 0;
while (true)
{
JournalEntry jentry = Journal.GetLine(i);
if (jentry.Text.IndexOf(coordpref) >= 0)
{
string bufstr = jentry.Text;
int auxPos;
Point mapPos = new Point();
bufstr = bufstr.Remove(0, coordpref.Length).Trim();
auxPos = bufstr.IndexOf(",");
mapPos.X = int.Parse(bufstr.Substring(0, auxPos));
mapPos.Y = int.Parse(bufstr.Substring(auxPos + 1, bufstr.Length - auxPos - 1));
Point bagPos = actBagPos;
foreach (KeyValuePair<Point, Point> p in coords)
{
if (mapPos.X >= p.Value.X - mapRadX && mapPos.X <= p.Value.X + mapRadX &&
mapPos.Y >= p.Value.Y - mapRadY && mapPos.Y <= p.Value.Y + mapRadY)
{
bagPos = p.Key;
}
}
UO.Print("Mapa " + mapPos.X.ToString() + ", " + mapPos.Y.ToString());
using (ItemUpdateEventWaiter ew = new ItemUpdateEventWaiter(item))
{
UO.MoveItem(item.Serial, 1, bagl, (ushort)bagPos.X, (ushort)bagPos.Y);
if (!ew.Wait(5000))
{
ScriptErrorException.Throw("Nemuzu pohnout s itemem, konec.");
return;
}
}
coords.Add(new KeyValuePair<Point, Point>(bagPos, mapPos));
if (bagPos == actBagPos)
{
actBagPos.X += bagStepX;
if (actBagPos.X > bagPosMaxX)
{
actBagPos.X = bagMinPosX;
actBagPos.Y += bagStepY;
}
}
break;
}
i++;
}
}
}
}
}
}
}