public ItemFactory(OtbFile otbFile, DatFile datFile, ItemsFile itemsFile) { metadatas = new Dictionary <ushort, ItemMetadata>(datFile.Items.Count); foreach (var otbItem in otbFile.Items) { if (otbItem.Group != ItemGroup.Deprecated) { metadatas.Add(otbItem.OpenTibiaId, new ItemMetadata() { TibiaId = otbItem.TibiaId, OpenTibiaId = otbItem.OpenTibiaId }); } } var lookup = otbFile.Items.ToLookup(otbItem => otbItem.TibiaId, otbItem => otbItem.OpenTibiaId); foreach (var datItem in datFile.Items) { foreach (var openTibiaId in lookup[datItem.TibiaId]) { ItemMetadata metadata = metadatas[openTibiaId]; if (datItem.Flags.Is(ItemFlags.IsGround)) { metadata.TopOrder = TopOrder.Ground; } else if (datItem.Flags.Is(ItemFlags.AlwaysOnTop1)) { metadata.TopOrder = TopOrder.HighPriority; } else if (datItem.Flags.Is(ItemFlags.AlwaysOnTop2)) { metadata.TopOrder = TopOrder.MediumPriority; } else if (datItem.Flags.Is(ItemFlags.AlwaysOnTop3)) { metadata.TopOrder = TopOrder.LowPriority; } else { metadata.TopOrder = TopOrder.Other; } if (datItem.Flags.Is(ItemFlags.IsContainer)) { metadata.Flags |= ItemMetadataFlags.IsContainer; } if (datItem.Flags.Is(ItemFlags.Stackable)) { metadata.Flags |= ItemMetadataFlags.Stackable; } if (datItem.Flags.Is(ItemFlags.Useable)) { metadata.Flags |= ItemMetadataFlags.Useable; } if (datItem.Flags.Is(ItemFlags.NotWalkable)) { metadata.Flags |= ItemMetadataFlags.NotWalkable; } if (datItem.Flags.Is(ItemFlags.NotMoveable)) { metadata.Flags |= ItemMetadataFlags.NotMoveable; } if (datItem.Flags.Is(ItemFlags.BlockProjectile)) { metadata.Flags |= ItemMetadataFlags.BlockProjectile; } if (datItem.Flags.Is(ItemFlags.BlockPathFinding)) { metadata.Flags |= ItemMetadataFlags.BlockPathFinding; } if (datItem.Flags.Is(ItemFlags.Pickupable)) { metadata.Flags |= ItemMetadataFlags.Pickupable; } if (datItem.Flags.Is(ItemFlags.Rotatable)) { metadata.Flags |= ItemMetadataFlags.Rotatable; } if (datItem.ItemHeight > 0) { metadata.Flags |= ItemMetadataFlags.HasHeight; } metadata.Speed = datItem.Speed; if (datItem.LightLevel > 0 || datItem.LightColor > 0) { metadata.Light = new Light((byte)datItem.LightLevel, (byte)datItem.LightColor); } } } foreach (var xmlItem in itemsFile.Items) { if (xmlItem.OpenTibiaId < 20000) { ItemMetadata metadata = metadatas[xmlItem.OpenTibiaId]; metadata.Name = xmlItem.Name; metadata.Capacity = xmlItem.ContainerSize; metadata.FloorChange = xmlItem.FloorChange; } } }
public void Start() { dispatcher = new Dispatcher(); scheduler = new Scheduler(dispatcher); listeners = new List <Listener>(); listeners.Add(new Listener(7171, socket => new LoginConnection(this, socket))); listeners.Add(new Listener(7172, socket => new GameConnection(this, socket))); Clock = new Clock(12, 0); Logger = new Logger(); Channels = new ChannelCollection(); RuleViolations = new RuleViolationCollection(); PacketsFactory = new PacketsFactory(); using (Logger.Measure("Loading items", true)) { var otb = OtbFile.Load("data/items/items.otb"); var dat = DatFile.Load("data/items/tibia.dat"); var items = ItemsFile.Load("data/items/items.xml"); ItemFactory = new ItemFactory(otb, dat, items); } using (Logger.Measure("Loading monsters", true)) { var monsters = MonsterFile.Load("data/monsters"); MonsterFactory = new MonsterFactory(monsters); } using (Logger.Measure("Loading npcs", true)) { var npcs = NpcFile.Load("data/npcs"); NpcFactory = new NpcFactory(npcs); } using (Logger.Measure("Loading map", true)) { var otbm = OtbmFile.Load("data/map/pholium3.otbm"); Map = new Map(ItemFactory, otbm); } Pathfinding = new Pathfinding(Map); Events = new EventsCollection(); Scripts = new ScriptsCollection(); using (Logger.Measure("Loading scripts", true)) { Scripts.Start(this); } dispatcher.Start(); scheduler.Start(); foreach (var listener in listeners) { listener.Start(); } Logger.WriteLine("Server online"); }