public override void Add(Deck newDeck) { LevelSlot newLevelSlot1 = new LevelSlot() { Level = 0, Deck = newDeck, CardId = PackRepository.DEFAULT_LEVEL_0_CARD_ID }; LevelSlot newLevelSlot2 = new LevelSlot() { Level = 1, Deck = newDeck, CardId = PackRepository.DEFAULT_LEVEL_1_CARD_ID }; LevelSlot newLevelSlot3 = new LevelSlot() { Level = 2, Deck = newDeck, CardId = PackRepository.DEFAULT_LEVEL_2_CARD_ID }; LevelSlot newLevelSlot4 = new LevelSlot() { Level = 3, Deck = newDeck, CardId = PackRepository.DEFAULT_LEVEL_3_CARD_ID }; GodsArenaApiContext.Decks.Add(newDeck); _levelSlotRepository.Add(newLevelSlot1); _levelSlotRepository.Add(newLevelSlot2); _levelSlotRepository.Add(newLevelSlot3); _levelSlotRepository.Add(newLevelSlot4); }
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); }
int IComparable <LevelSlot <K, V> > .CompareTo(LevelSlot <K, V> InFac2) { if (LevelNx != InFac2.LevelNx) { return(LevelNx.CompareTo(InFac2.LevelNx)); } else { return(SlotNx.CompareTo(InFac2.SlotNx)); } }
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 void SelectLevel(LevelSlot selected) { if (selectedSlot == selected) { return; } //deselect slots DeselectedLevel(); selectedSlot = selected; selectedSlot.GetComponent <Image>().color = Color.red; levelDescription.text = selectedSlot.levelData.Description; }
IEnumerator CreateLevelSlots() { yield return(new WaitUntil(() => ItemDatabase.Instance.Loaded)); foreach (var level in ItemDatabase.Instance.LevelDatas) { LevelSlot levelSlot = Instantiate(levelSlotPrefab, levelGrid).GetComponent <LevelSlot>(); levelSlot.Setup(level.Key, this); levelSlots.Add(levelSlot); } if (levelSlots.Count > 0) { GetComponent <UnityEngine.EventSystems.EventSystem>().firstSelectedGameObject = levelSlots[0].gameObject; } }
public void PlayLevel(LevelSlot levelSlot) { GameManager.Instance.LoadScene(levelSlot.levelDataId); }
public bool UpdateMultiple(int playerId, List <Deck> newDecks) { bool updateIsValid = true; var optionsBuilder = new DbContextOptionsBuilder <GodsArenaApiContext>(); optionsBuilder.UseSqlServer(Startup.connectionString); using (IDbContextTransaction transaction = GodsArenaApiContext.Database.BeginTransaction()) { Pack pack = _packRepository.GetInclude <Pack>(p => p.PlayerId == playerId, p => p.PackContents); List <int> levelSlotIdTakenCardFromList = new List <int>(); //List of the Player old decks state List <Deck> oldDecks = GetMultipleInclude <Deck>(d => d.PlayerId == playerId, d => d.LevelSlots).ToList(); Dictionary <int, Dictionary <int, LevelSlot> > levelTo_IdToLevelSlotDictionaryForLooping = new Dictionary <int, Dictionary <int, LevelSlot> >(); //Will be used as a cash to search in the old levelSlots Dictionary <int, Dictionary <int, LevelSlot> > levelTo_IdToLevelSlotDictionaryForVerification = new Dictionary <int, Dictionary <int, LevelSlot> >(); Dictionary <int, Deck> idToDeckDictionary = new Dictionary <int, Deck>(); foreach (var deck in oldDecks) { idToDeckDictionary.Add(deck.Id, deck); foreach (var levelSlot in deck.LevelSlots) { if (!levelTo_IdToLevelSlotDictionaryForVerification.ContainsKey(levelSlot.Level)) { levelTo_IdToLevelSlotDictionaryForVerification.Add(levelSlot.Level, new Dictionary <int, LevelSlot>()); levelTo_IdToLevelSlotDictionaryForLooping.Add(levelSlot.Level, new Dictionary <int, LevelSlot>()); } levelTo_IdToLevelSlotDictionaryForVerification[levelSlot.Level].Add(levelSlot.Id, levelSlot); levelTo_IdToLevelSlotDictionaryForLooping[levelSlot.Level].Add(levelSlot.Id, levelSlot); } } foreach (var newDeck in newDecks) { if (updateIsValid) { var oldDeck = idToDeckDictionary[newDeck.Id]; foreach (var oldLevelSlot in oldDeck.LevelSlots) { LevelSlot newLevelSlot = newDeck.LevelSlots.Find(ls => ls.Level == oldLevelSlot.Level); if (oldLevelSlot.CardId != newLevelSlot.CardId) { //Immediatly take it out of consideration as we won't look in itself for the card levelTo_IdToLevelSlotDictionaryForVerification[oldLevelSlot.Level].Remove(oldLevelSlot.Id); PackContent packContentContainingNewDeckCard = pack.PackContents.Find(pc => pc.CardId == newLevelSlot.CardId); if (packContentContainingNewDeckCard != null) { _packContentRepository.RemoveCard(packContentContainingNewDeckCard); if (!levelSlotIdTakenCardFromList.Contains(oldLevelSlot.Id)) { _packContentRepository.AddCard(pack.Id, oldLevelSlot.CardId); } _packContentRepository.Save(); } else { LevelSlot levelSlotContainingNewDeckCard = levelTo_IdToLevelSlotDictionaryForVerification[oldLevelSlot.Level].Where(p => p.Value.CardId == newLevelSlot.CardId).FirstOrDefault().Value; if (levelSlotContainingNewDeckCard != null) { levelSlotIdTakenCardFromList.Add(levelSlotContainingNewDeckCard.Id); levelTo_IdToLevelSlotDictionaryForVerification[oldLevelSlot.Level].Remove(levelSlotContainingNewDeckCard.Id); _packContentRepository.AddCard(pack.Id, oldLevelSlot.CardId); _packContentRepository.Save(); } else { //Here it hasn't been found in pack neither in any old level slot so it came from nowhere and can't be added transaction.Rollback(); updateIsValid = false; break; } } } } } } //Here if updateIsValid is till true it means that the update is valid and we can then modify the decks if (updateIsValid) { foreach (var newDeck in newDecks) { var oldDeck = idToDeckDictionary[newDeck.Id]; foreach (var newLevelSlot in newDeck.LevelSlots) { //levelTo_IdToLevelSlotDictionaryForLooping[newLevelSlot.Level][newLevelSlot.Id].CardId = newLevelSlot.CardId; oldDeck.LevelSlots.Where(ls => ls.Level == newLevelSlot.Level).FirstOrDefault().CardId = newLevelSlot.CardId; } } transaction.Commit(); } } return(updateIsValid); }
public void Setup(string[] extensionPaths, Setup settings) { if (settings == null) { throw new ArgumentNullException("settings", "Settings is null"); } if (settings.Level == null) { throw new ArgumentNullException("settings", "Leve is null"); } if (settings.Player.Length != Level.MAX_SLOTS) { throw new ArgumentException(string.Format("Player-Array must have a length of {0}", Level.MAX_SLOTS)); } if (settings.Colors.Length != Level.MAX_SLOTS) { throw new ArgumentException(string.Format("Player-Array must have a length of {0}", Level.MAX_SLOTS)); } // Eindeutigkeit der Farben prüfen var colors = new List <PlayerColor>(); for (int i = 0; i < Level.MAX_SLOTS; i++) { if (settings.Colors[i] == PlayerColor.Undefined) { throw new ArgumentException("Undefined is not a valid color for slot " + i, "settings"); } if (colors.Contains(settings.Colors[i])) { throw new ArgumentException("Color " + settings.Colors[i] + " is assigned double", "settings"); } colors.Add(settings.Colors[i]); } colors.Clear(); // Load Default Assemblies ExtensionLoader.LoadExtensions(extensionPaths, null, false); // TODO: this is for debug AppDomain.CurrentDomain.AssemblyLoad += (x, y) => { }; AppDomain.CurrentDomain.AssemblyResolve += (x, y) => null; AppDomain.CurrentDomain.ResourceResolve += (x, y) => null; AppDomain.CurrentDomain.TypeResolve += (x, y) => null; // Level erzeugen Assembly levelAssembly = Assembly.Load(settings.Level.AssemblyFile); Type levelType = levelAssembly.GetType(settings.Level.TypeName, true); Level lvl = Activator.CreateInstance(levelType, ExtensionLoader.DefaultTypeResolver) as Level; _level = lvl; // Player erzeugen LevelSlot[] levelSlots = new LevelSlot[Level.MAX_SLOTS]; for (int i = 0; i < Level.MAX_SLOTS; i++) { // Skipp, falls nicht vorhanden if (settings.Player[i] == null) { continue; } Assembly playerAssembly = Assembly.Load(settings.Player[i].AssemblyFile); Type factoryType = playerAssembly.GetType(settings.Player[i].TypeName); // Identify Name object[] playerAttributes = factoryType.GetCustomAttributes(typeof(FactoryAttribute), true); if (playerAttributes.Length != 1) { throw new Exception("Player does not have the right number of Player Attributes"); } var playerAttribute = playerAttributes[0] as FactoryAttribute; // Find the right Mapping object[] mappingAttributes = playerAttribute.GetType(). GetCustomAttributes(typeof(FactoryAttributeMappingAttribute), false); if (mappingAttributes.Length != 1) { throw new Exception("Player Attribute has no valid Property Mapping Attribute"); } var mappingAttribute = mappingAttributes[0] as FactoryAttributeMappingAttribute; // Werte auslesen var name = playerAttribute.GetType().GetProperty(mappingAttribute.NameProperty). GetValue(playerAttribute, null) as string; levelSlots[i] = new LevelSlot() { FactoryType = factoryType, Name = name, Color = settings.Colors[i], Team = settings.Teams[i] }; } // Level initialisieren _level.Init(settings.Seed, levelSlots); }