protected override void InitSimulation(int seed, LevelInfo level, PlayerInfo[] players, Slot[] slots) { Assembly levelAssembly = Assembly.Load(level.Type.AssemblyFile); Type levelType = levelAssembly.GetType(level.Type.TypeName); SimulationContext context = new SimulationContext( ExtensionLoader.DefaultTypeResolver, ExtensionLoader.ExtensionSettings); simulation = Activator.CreateInstance(levelType, context) as Level; // Player erzeugen LevelSlot[] levelSlots = new LevelSlot[AntMe.Level.MAX_SLOTS]; for (int i = 0; i < AntMe.Level.MAX_SLOTS; i++) { // Skipp, falls nicht vorhanden if (players[i] == null) continue; Assembly playerAssembly = Assembly.Load(players[i].Type.AssemblyFile); Type factoryType = playerAssembly.GetType(players[i].Type.TypeName); // Identify Name var playerAttributes = factoryType.GetCustomAttributes(typeof(FactoryAttribute), true); if (playerAttributes.Length != 1) throw new Exception("Player does not have the right number of Player Attributes"); FactoryAttribute playerAttribute = playerAttributes[0] as FactoryAttribute; // Find the right Mapping var mappingAttributes = playerAttribute.GetType(). GetCustomAttributes(typeof(FactoryAttributeMappingAttribute), false); if (mappingAttributes.Length != 1) throw new Exception("Player Attribute has no valid Property Mapping Attribute"); FactoryAttributeMappingAttribute mappingAttribute = mappingAttributes[0] as FactoryAttributeMappingAttribute; // Werte auslesen string name = playerAttribute.GetType().GetProperty(mappingAttribute.NameProperty). GetValue(playerAttribute, null) as string; levelSlots[i] = new LevelSlot() { FactoryType = factoryType, Name = name, Color = slots[i].ColorKey, Team = slots[i].Team }; } // Level initialisieren simulation.Init(seed, levelSlots); }
public LocalSimulationClient(string[] extensionPaths, ITypeResolver resolver) { this.resolver = resolver; this.extensionPaths = extensionPaths; // User erstellen master = new UserProfile() { Id = clientId, Username = "******" }; users = new List<UserProfile>(); users.Add(master); // Slots erstellen slots = new Slot[AntMe.Level.MAX_SLOTS]; players = new PlayerInfo[AntMe.Level.MAX_SLOTS]; for (byte i = 0; i < AntMe.Level.MAX_SLOTS; i++) slots[i] = new Slot() { Id = i, ColorKey = (PlayerColor)i }; // Defaults rate = AntMe.Level.FRAMES_PER_SECOND; log = Log.CreateLog(true); }
/// <summary> /// Initialisierung der Simulation. /// </summary> /// <returns>Erfolgsmeldung</returns> protected abstract void InitSimulation(int seed, LevelInfo level, PlayerInfo[] players, Slot[] slots);
private void SendPlayerReset(Slot[] slots) { lock (clients) { foreach (var receiver in clients.Values) RunAsync(receiver, () => receiver.CallbackInterface.PlayerReset(slots)); } }
private void callback_OnPlayerReset(Slot[] parameter) { foreach (var slot in parameter) { if (slot.Id < 0 || slot.Id > 7) continue; slots[slot.Id].ColorKey = slot.ColorKey; slots[slot.Id].PlayerInfo = slot.PlayerInfo; slots[slot.Id].Profile = slot.Profile; slots[slot.Id].ReadyState = slot.ReadyState; slots[slot.Id].Team = slot.Team; } if (OnPlayerReset != null) OnPlayerReset(this); }
private void callback_OnPlayerChanged(Slot slot) { var hit = slots.SingleOrDefault(s => s.Id == slot.Id); if (hit != null) { hit.ColorKey = slot.ColorKey; hit.PlayerInfo = slot.PlayerInfo; hit.Profile = slot.Profile; hit.ReadyState = slot.ReadyState; hit.Team = slot.Team; if (OnPlayerChanged != null) OnPlayerChanged(this, hit.Id); } }