public DomainItem Add(DomainItemUpdateModel item) { var added = db.Item.Add(mapper.Map <DAItem>(item)); db.SaveChanges(); return(mapper.Map <DomainItem>(added.Entity)); }
public DomainPlayer Add(DomainPlayerUpdateModel item) { var added = db.Player.Add(mapper.Map <DAPlayer>(item)); db.SaveChanges(); return(mapper.Map <DomainPlayer>(added.Entity)); }
public IActionResult Create(Character character) { if (character.Name == "Goku") { character.Level = 9001; } db.Characters.Add(character); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Equip equip) { if (ModelState.IsValid) { db.Equips.Add(equip); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(equip)); }
public ActionResult Create(Race race) { if (ModelState.IsValid) { db.Races.Add(race); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(race)); }
public IActionResult Edit(User user) { var id = user.Id; var thisUser = _db.Users.FirstOrDefault(User => User.Id == id); thisUser.Avatar = user.Avatar; _db.SaveChanges(); //_db.Entry(user).State = EntityState.Modified; //_db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "MonsterId,Name,Atk,Def,Spd,Hp")] Monster monster) { if (ModelState.IsValid) { db.Monsters.Add(monster); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(monster)); }
public ActionResult Create(Armor armor) { if (ModelState.IsValid) { db.Armors.Add(armor); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(armor)); }
public ActionResult Create(Region region) { if (ModelState.IsValid) { db.Regions.Add(region); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(region)); }
public ActionResult Create(NPC NPC) { if (ModelState.IsValid) { db.NPCs.Add(NPC); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RegionId = new SelectList(db.Regions, "RegionID", "RegionName", NPC.RegionID); return(View(NPC)); }
public ActionResult Create(Reward reward) { if (ModelState.IsValid) { db.Rewards.Add(reward); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RegionId = new SelectList(db.Regions, "RegionID", "RegionName", reward.RegionID); ViewBag.NPCId = new SelectList(db.NPCs, "NPCID", "NPCName", reward.NPCID); return(View(reward)); }
public ActionResult Create(Character character) { if (ModelState.IsValid) { db.Characters.Add(character); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ArmorID = new SelectList(db.Armors, "ArmorId", "ArmorToString", character.ArmorID); ViewBag.EquipID = new SelectList(db.Equips, "EquipId", "EquipToString", character.EquipID); ViewBag.RaceID = new SelectList(db.Races, "RaceId", "RaceToString", character.RaceID); ViewBag.WeaponID = new SelectList(db.Weapons, "WeaponId", "WeaponToString", character.WeaponID); return(View(character)); }
public bool Equip(Item item) { bool success = false; using (RPGContext context = new RPGContext()) { if (this.PlayerItem.Item.Type != ItemType.None) { Unequip(); } context.PlayerItems.Remove(this.PlayerItem); context.Items.Remove(this.PlayerItem.Item); bool inRoom = this.Room.Inventory.Items.Exists(x => x.ItemId == item.ItemId); bool inPlayerInventory = this.Inventory.Items.Exists(x => x.ItemId == item.ItemId); if (inRoom || inPlayerInventory) { Inventory inventory; if (inRoom) { inventory = this.Room.Inventory; } else { inventory = this.Inventory; } InventoryItem inventoryItem = inventory.Items.Find(x => x.ItemId == item.ItemId); inventory.Items.Remove(inventoryItem); context.Remove(inventoryItem); context.Update(inventory); } else { //the item is not somewhere that can be picked up and/or equipped } PlayerItem playerItem = new PlayerItem { PlayerItemId = Guid.NewGuid(), Player = this, Item = item }; context.PlayerItems.Add(playerItem); context.SaveChanges(); } return(success); }
private GameState Continue() { GameState gameState = new GameState(); using (RPGContext context = new RPGContext()) { Player player = context.Players.OrderBy(x => x.LastPlayed).First(); player.LastPlayed = DateTime.Now; context.Update(player); context.SaveChanges(); gameState = context.GameStates.FirstOrDefault(x => x.Player == player); } return(gameState); }
public bool Unequip() { bool success = false; using (RPGContext context = new RPGContext()) { if (this.PlayerItem.Item.Type == ItemType.None) { //you cannot unequip your hand } else { context.PlayerItems.Remove(PlayerItem); Inventory.AddItem(PlayerItem.Item); context.Update(Inventory); } context.SaveChanges(); } return(success); }
private GameState NewGame() { GameState gameState = new GameState(); bool nameEntered = false; string input = ""; while (!nameEntered) { Console.WriteLine("Please enter a name:"); input = Console.ReadLine(); using (RPGContext context = new RPGContext()) { Player player = context.Players.FirstOrDefault(x => x.Name == input); if (player == null) { nameEntered = true; } else { Console.Write("I'm sorry but that player name is taken. "); } } } Room startRoom = new Room { RoomId = Guid.NewGuid(), //TODO:initialize the inventory with a sledgehammer Inventory = new Inventory(), Vector = new Vector(0, 0, 0) }; Player newPlayer = new Player { PlayerId = Guid.NewGuid(), Name = input, PlayerItem = null, Inventory = new Inventory(), LastPlayed = DateTime.Now, Room = startRoom }; gameState = new GameState { GameStateId = Guid.NewGuid(), Player = newPlayer, Rooms = new List <GameStateRoom>() }; GameStateRoom gameStateStartRoom = new GameStateRoom { GameStateRoomId = Guid.NewGuid(), GameState = gameState, Room = startRoom }; gameState.Rooms.Add(gameStateStartRoom); int prizeMinDistance = 5; int prizeMaxDistance = 20; Random rand = new Random(); Room prizeRoom = new Room { RoomId = Guid.NewGuid(), //TODO:initialize the inventory with a TON of gold Inventory = new Inventory(), Vector = new Vector(rand.Next(prizeMinDistance, prizeMaxDistance), rand.Next(prizeMinDistance, prizeMaxDistance), rand.Next(prizeMinDistance, prizeMaxDistance)) }; GameStateRoom gameStatePrizeRoom = new GameStateRoom { GameStateRoomId = Guid.NewGuid(), GameState = gameState, Room = prizeRoom }; gameState.Rooms.Add(gameStatePrizeRoom); using (RPGContext context = new RPGContext()) { context.GameStates.Add(gameState); context.SaveChanges(); } return(gameState); }
public IActionResult Create(Item item) { _db.Items.Add(item); _db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Create(Inventory inventory) { db.Inventories.Add(inventory); db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Create(Character character) { db.Characters.Add(character); db.SaveChanges(); return(RedirectToAction("Index")); }