A UserHero contains information pertaining to a particular hero; a UserAccount may contain several of these
コード例 #1
0
        public static void OnCharacterCreate(GameClient client, ClientHeroCreatePacket packet)
        {
            Logger.Instance.Info("Attempting to create hero with name {0}", packet.Name);
            bool heroExists;

            using (var context = new GameDatabaseContext())
            {
                // We try to load a hero with a similar name to see if they exist
                heroExists = context.Characters.Any(x => x.Name.ToUpper() == packet.Name.ToUpper());
            }

            if (heroExists)
            {
                client.Send(new ServerHeroCreateResponsePacket(HeroStatus.Invalid));
                return;
            }

            // Create a hero and attach it if it dosen't exist yet

            var hero = new UserHero(client.Account, 0, 0, 0, packet.Name);

            // Save our hero into the database
            using (var context = new GameDatabaseContext())
            {
                context.Accounts.Attach(client.Account);
                context.Entry(client.Account).Collection(a => a.Heroes).Load();
                client.Account.Heroes.Add(hero);
                context.SaveChanges();
            }

            client.Send(new ServerHeroCreateResponsePacket(HeroStatus.OK));

            SendHeroList(client);
        }
コード例 #2
0
        public static Player CreateHero(UserHero userHero, GameClient gameClient)
        {
            var entity = new Player("male_base", gameClient, userHero);
            entity.Position = new Vector2(userHero.PositionX, userHero.PositionY);
            entity.Name = userHero.Name;

            // Copy the stats from the DB into the player
            CopyStatsFromTemplateToCharacter(userHero, entity);

            return entity;
        }
コード例 #3
0
ファイル: Player.cs プロジェクト: Erikai/OpenORPG
        public Player(string sprite, GameClient client, UserHero userHero)
            : base(sprite)
        {
            Client = client;
            Backpack = new ItemStorage();
            Bank = new ItemStorage();
            QuestInfo = new List<UserQuestInfo>();

            using (var context = new GameDatabaseContext())
            {
                // Add the skills this player knows
                foreach (var skillEntry in userHero.Skills)
                {
                    var skillTemplate = context.SkillTemplates.First(x => x.Id == skillEntry.SkillId);
                    var skill = new Skill(skillTemplate);
                    Skills.Add(skill);
                }

                // Add the inventory stuff...
                foreach (var inventoryItem in userHero.Inventory)
                {
                    var itemTemplate = context.ItemTemplates.First(x => x.Id == inventoryItem.ItemId);
                    var item = ItemFactory.CreateItem(itemTemplate);
                    Backpack.TryAddItemAt(item, inventoryItem.ItemAmount, inventoryItem.SlotId);
                }

                // Add the state of the quest world to the user
                foreach (var questEntry in userHero.QuestInfo)
                {
                    QuestInfo.Add(questEntry);
                }

                foreach (var eq in userHero.Equipment)
                {
                    var itemTemplate = context.ItemTemplates.First(x => x.Id == eq.ItemId);
                    var equipment = ItemFactory.CreateItem(itemTemplate) as Equipment;
                    Equipment[(int)equipment.Slot] = equipment;
                }

                UserId = userHero.UserHeroId;
                Experience = userHero.Experience;
                Level = userHero.Level;

            }

            // Store the user hero internally
            _hero = userHero;
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: gitter-badger/OpenORPG
        public Player(string sprite, GameClient client, UserHero userHero)
            : base(sprite)
        {
            Client = client;
            Backpack = new ItemStorage();
            Bank = new ItemStorage();

            // Allow extraction of the quest information
            QuestLog = new QuestLog(userHero.QuestInfo);

            using (var context = new GameDatabaseContext())
            {
                // Add the skills this player knows
                foreach (var skillEntry in userHero.Skills)
                {
                    var skillTemplate = context.SkillTemplates.First(x => x.Id == skillEntry.SkillId);
                    var skill = new Skill(skillTemplate);
                    Skills.Add(skill);
                }

                // Add the inventory stuff...
                foreach (var inventoryItem in userHero.Inventory)
                {
                    var itemTemplate = context.ItemTemplates.First(x => x.Id == inventoryItem.ItemId);
                    var item = ItemFactory.CreateItem(itemTemplate);
                    Backpack.TryAddItemAt(item, inventoryItem.ItemAmount, inventoryItem.SlotId);
                }

                foreach (var eq in userHero.Equipment)
                {
                    var itemTemplate = context.ItemTemplates.First(x => x.Id == eq.ItemId);
                    var equipment = ItemFactory.CreateItem(itemTemplate) as Equipment;
                    Equipment[(int)equipment.Slot] = equipment;
                }

                UserId = userHero.UserHeroId;
                Experience = userHero.Experience;
                Level = userHero.Level;

                Backpack.StorageChanged += BackpackOnStorageChanged;
                QuestLog.QuestAccepted += QuestLogOnQuestAccepted;
            }

            // Store the user hero internally
            _hero = userHero;
        }