Exemplo n.º 1
0
        private List <Spell> GetSpellsFromDatabase(character character)
        {
            List <Spell> Spells = new List <Spell>();

            var dbspells = CharacterSpells.Where(cs => cs.guid == character.guid).ToList();

            dbspells.ForEach(characterSpell => Spells.Add(CreateSpell((int)characterSpell.spell)));
            return(Spells);
        }
Exemplo n.º 2
0
        public ActionResult <string> Post([FromBody] SpellsUpdateInfo spellsUpdate)
        {
            Spells updateSpell = new Spells();

            updateSpell.SpellName        = spellsUpdate.SpellName;
            updateSpell.SpellLevel       = (short)spellsUpdate.SpellLevel;
            updateSpell.SchoolOfMagic    = spellsUpdate.SchoolOfMagic;
            updateSpell.SpellCastingTime = spellsUpdate.SpellCastingTime;
            updateSpell.Ritual           = spellsUpdate.Ritual;
            updateSpell.SpellRange       = spellsUpdate.SpellRange;
            updateSpell.SpellComponents  = spellsUpdate.SpellComponents;
            updateSpell.SpellDuration    = spellsUpdate.SpellDuration;
            updateSpell.SpellDescription = spellsUpdate.SpellDescription;

            CharacterSpells spellListToUpdate = new CharacterSpells();

            spellListToUpdate.CharacterName = spellsUpdate.CharacterName;
            spellListToUpdate.SpellName     = spellsUpdate.SpellName;

            try
            {
                using (var context = new CharacterManagementDBContext())
                {
                    if (!context.Spells.Any(spell => spell.SpellName == updateSpell.SpellName))
                    {
                        context.Spells.Add(updateSpell);
                    }

                    if (!context.CharacterSpells.Any(spellList => (spellList.CharacterName == spellListToUpdate.CharacterName &&
                                                                   spellList.SpellName == spellListToUpdate.SpellName)))
                    {
                        context.CharacterSpells.Add(spellListToUpdate);
                    }
                    else
                    {
                        return($"{spellsUpdate.CharacterName} already knows that spell!");
                    }

                    context.SaveChanges();
                }
            }
            catch (DbUpdateException)
            {
                return("Spells could not be updated. Please try again.");
            }
            catch (Exception)
            {
                return("Spells update failed.");
            }

            return($"{spellsUpdate.CharacterName}'s spell list updated successfully!");
        }
Exemplo n.º 3
0
        public void RemoveSpell(Spell spell)
        {
            if (!Collection.ContainsKey(spell.SpellID))
            {
                return;
            }
            Collection.Remove(spell.SpellID);

            CharacterSpells.Delete(new character_spell()
            {
                guid = Owner.ObjectGUID.Low, spell = (long)spell.SpellID
            });
            CharacterDatabase.SaveChanges();

            Owner.Session.SendPacket(new PSRemoveSpell((uint)spell.SpellID));
        }
Exemplo n.º 4
0
        public void AddSpell(Spell spell)
        {
            if (Collection.ContainsKey(spell.SpellID))
            {
                return;
            }
            Collection.Add(spell.SpellID, spell);

            CharacterSpells.Add(new character_spell()
            {
                guid = Owner.ObjectGUID.Low, spell = (long)spell.SpellID
            });
            CharacterDatabase.SaveChanges();

            Owner.Session.SendPacket(new PSLearnSpell((uint)spell.SpellID));
        }
Exemplo n.º 5
0
        private List <Spell> GetCharacterCreationSpells()
        {
            List <Spell> result = new List <Spell>();

            List <playercreateinfo_spell> newCharacterSpells = PlayerCreateSpells.Where(s => s.race == Owner.Character.race && s.@class == Owner.Character.@class).ToList();

            newCharacterSpells.ForEach(s =>
            {
                Spell spell = this.CreateSpell(s.Spell);
                CharacterSpells.Add(new character_spell()
                {
                    guid = Owner.ObjectGUID.Low, spell = (long)spell.SpellID
                });
                result.Add(spell);
            });

            CharacterDatabase.SaveChanges();
            return(result);
        }