示例#1
0
        private static NonPlayerCharacter CreateNpc(ModelEnums.NpcType type, Race race, string name, Location location = null, int level = 1)
        {
            var npc = new NonPlayerCharacter()
            {
                Name = name,
                Type = type,
                Level = level,
                Race = race,
                Creature = race.Creature
            };
            npc.SetTag();

            if (location != null)
            {
                var now = DateTime.Now;

                var entryLocation = new EntryLocationCharacter
                {
                    EntryInto = now,
                    Arrival = now,
                    Location = location,
                    Character = npc
                };
                npc.EntryLocations.Add(entryLocation);
            }

            return npc;
        }
示例#2
0
        public ActionResult Create(PlayerCharacterViewModel fm)
        {
            if (this.ModelState.IsValid)
            {
                var @class = this.db.Classes.Single(x => x.Name.ToLower() == fm.Class);
                var race = this.db.Races
                    .Include(x => x.Creature)
                    .Include(x => x.InitialLocation).Single(x => x.Name.ToLower() == fm.Race);

                var now = DateTime.Now;

                var entryLocation = new EntryLocationCharacter
                {
                    EntryInto = now,
                    Location = race.InitialLocation,
                    Arrival = now
                };
                this.db.EntryLocationCharacters.Add(entryLocation);

                var character = new PlayerCharacter
                {
                    Name = fm.Name,
                    Level = 1,
                    Class = @class,
                    Race = race,
                    Creature = race.Creature,
                    Owner_Id = this.User.Identity.GetUserId(),
                    EntryLocations = { entryLocation }
                };
                character.SetTag();

                this.db.Characters.Add(character);

                this.db.SaveChanges();

                return RedirectToAction("Index");
            }

            return View(fm);
        }