protected override void Save() { var ContentTemplate = this.ContentTemplate as DialogTemplate; // Update the payload try { ContentTemplate.JsonPayload = ToJson(); } catch (Exception exception) { MessageBox.Show("There was a problem saving the dialog. It was not saved. Aborting..."); Close(); } using (var db = new GameDatabaseContext()) { var repository = new DialogRepository(db); repository.Update(ContentTemplate, ContentTemplate.Id); } base.Save(); }
public void ProcessContent(IContentPersister persister) { using (var db = new GameDatabaseContext()) { var repo = new SkillRepository(db); var skills = repo.GetAll(); foreach (var skill in skills) { // Save out properties we want to a new object and then persist dynamic persistable = new ExpandoObject(); Console.WriteLine("Processing skill with ID {0}", skill.Id); persistable.id = skill.Id; persistable.name = skill.Name; persistable.castTime = skill.CastTime; persistable.cooldownTime = skill.CooldownTime; persistable.description = skill.Description; persistable.damage = skill.Damage; persistable.type = skill.SkillType; persistable.iconId = skill.IconId; persister.Persist(persistable, "\\skills\\{0}.json".FormatWith(skill.Id)); } } }
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); }
public static void Logout(GameClient client) { if (client.Account == null) return; var account = client.Account; using (var context = new GameDatabaseContext()) { context.Accounts.Attach(account); account.IsOnline = false; context.SaveChanges(); } client.Account = null; if (client.Zone == null) return; if (client.Hero == null) return; client.Zone.OnClientLeave(client); }
public void ProcessContent(IContentPersister persister) { using (var db = new GameDatabaseContext()) { var repo = new ItemRepository(db); var items = repo.GetAll(); foreach (var item in items) { // Save out properties we want to a new object and then persist dynamic persistable = new ExpandoObject(); Console.WriteLine("Processing item with ID {0}", item.Id); persistable.id = item.Id; persistable.name = item.Name; persistable.type = item.Type; persistable.equipSlot = item.EquipmentSlot; persistable.description = item.Description; persistable.restoreHp = item.RestoreHp; persistable.iconId = item.IconId; persister.Persist(persistable, "\\items\\{0}.json".FormatWith(item.Id)); } } }
public void ProcessContent(IContentPersister persister) { using (var db = new GameDatabaseContext()) { var repo = new QuestRepository(db); var items = repo.GetAll(); foreach (var item in items) { // Save out properties we want to a new object and then persist dynamic persistable = new ExpandoObject(); Console.WriteLine("Processing quest with ID {0}", item.Id); persistable.id = item.Id; persistable.name = item.Name; persistable.description = item.Description; persister.Persist(persistable, "\\quests\\{0}.json".FormatWith(item.Id)); } } }
public IEnumerable<ItemTemplate> GetItemsWithNameStartingWith() { using (var context = new GameDatabaseContext()) { return context.ItemTemplates.ToList(); } }
public void ProcessContent(IContentPersister persister) { using (var db = new GameDatabaseContext()) { var repo = new DialogRepository(db); var dialogs = repo.GetAll(); foreach (var dialog in dialogs) { // Save out properties we want to a new object and then persist var dialogTemplate = JsonConvert.DeserializeObject<DialogNode>(dialog.JsonPayload, jsonSerializerSettings); dynamic persistable = new ExpandoObject(); Console.WriteLine("Processing dialog with ID {0}", dialog.Id); // TODO: Scrub conditions here so users cannot access them, as this would reveal information we do not desire persistable = dialogTemplate; persister.Persist(persistable, "\\dialogs\\{0}.json".FormatWith(dialog.Id)); } } }
public static Npc CreateNpc(long id) { using (var context = new GameDatabaseContext()) { var template = context.Npcs.FirstOrDefault(x => x.Id == id); if (template == null) throw new Exception("Creating an NPC with the given Id is invalid."); // Load up the quests this NPC will have context.Entry(template).Collection(x => x.Quests).Load(); context.Entry(template).Reference(x => x.ConversationAvailableTemplate).Load(); foreach (var quest in template.Quests) { context.Entry(quest).Collection(x => x.QuestSteps).Load(); context.Entry(quest).Collection(x => x.Rewards).Load(); // Load up our set of requirements from the table foreach (var x in quest.QuestSteps) context.Entry(x).Collection(a => a.Requirements).Load(); } var npc = new Npc(template); return npc; } }
public static void Logout(GameClient client) { if (client.Account == null) return; UserAccount account = client.Account; using (var context = new GameDatabaseContext()) { context.Accounts.Attach(account); account.IsOnline = false; context.SaveChanges(); } client.Account = null; if (client.HeroEntity == null) return; PersistPlayer(client.HeroEntity); client.HeroEntity.Zone.RemoveEntity(client.HeroEntity); }
public void ProcessContent(IContentPersister persister) { using (var db = new GameDatabaseContext()) { var repo = new MonsterRepository(db); var monsters = repo.GetAll(); foreach (var monster in monsters) { // Save out properties we want to a new object and then persist dynamic persistable = new ExpandoObject(); Console.WriteLine("Processing monster with ID {0}", monster.Id); persistable.id = monster.Id; persistable.name = monster.Name; persistable.maxHp = monster.Hitpoints; persistable.category = monster.VirtualCategory; persistable.sprite = monster.Sprite; persister.Persist(persistable, "\\monsters\\{0}.json".FormatWith(monster.Id)); } } }
public ItemTemplate GetItemById(int id) { using (var context = new GameDatabaseContext()) { return context.ItemTemplates.FirstOrDefault(x => x.Id == id); } }
public SkillTemplate GetSkillById(int id) { using (var context = new GameDatabaseContext()) { var repo = new SkillRepository(context); return repo.Get(id); } }
public IEnumerable<SkillTemplate> GetSkills() { using (var context = new GameDatabaseContext()) { var repo = new SkillRepository(context); return repo.GetAll(); } }
protected override void Save() { using (var db = new GameDatabaseContext()) { var ContentTemplate = this.ContentTemplate as SkillTemplate; var repository = new SkillRepository(db); repository.Update(ContentTemplate, ContentTemplate.Id); } base.Save(); }
public bool Authenticate(string username, string password, out UserAccount account) { using (var context = new GameDatabaseContext()) { account = context.Accounts.FirstOrDefault((a) => a.Username == username); if (account == null) return false; return account.Password == password; } }
public IHttpActionResult NewItem() { using (var context = new GameDatabaseContext()) { var repo = new ItemRepository(context); var item = repo.Add(new ItemTemplate(0, "New Item", "", ItemType.FieldItem , 0, true, 0)); return Ok(item); } }
public IHttpActionResult SaveSkill(SkillTemplate skillTemplate, int id) { using (var context = new GameDatabaseContext()) { var repo = new SkillRepository(context); repo.Update(skillTemplate, id); return Ok(); } }
public IHttpActionResult SaveItem(ItemTemplate item, int id) { using (var context = new GameDatabaseContext()) { var repo = new ItemRepository(context); repo.Update(item, id); return Ok(); } }
public IHttpActionResult NewSkill() { using (var context = new GameDatabaseContext()) { var repo = new SkillRepository(context); var skill = repo.Add(new SkillTemplate(SkillType.Elemental, SkillTargetType.Enemy, SkillActivationType.Immediate, 0, 0, "", 0, "New Skill")); return Ok(skill); } }
public void Run() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // This intial query is needed to warm up the database using (var context = new GameDatabaseContext()) { List<UserAccount> accounts = context.Accounts.Where(x => x.IsOnline).ToList(); accounts.ForEach(x => x.IsOnline = false); context.SaveChanges(); } Log.Info("GameServer.Run"); List<IManager> managers = new List<IManager>(); managers.Add(new ChatManager()); managers.Add(new ZoneManager()); managers.Add(new ContentManager(root: PathHelper.AssetBasePath)); managers.Add(new NetworkManager(port: 1234)); managers.Add(new PowerManager()); managers.Add(new AttributeRepository()); foreach (IManager manager in managers) { manager.Initialize(); } NetworkManager.Current.Connected += OnConnection; NetworkManager.Current.PacketRecieved += OnPacketRecieved; NetworkManager.Current.Disconnected += OnDisconnected; // Test data only var testZone = new Zone(); testZone.Name = "Island"; ZoneManager.Current.Zones.Add(testZone); testZone.World.GameObjects.Add(GameObjectFactory.CreateMap(testZone, "Maps/Island.json")); testZone.World.GameObjects.Add(GameObjectFactory.CreateSkeleton(testZone, new Utils.Math.Vector2(6 * 32, 3 * 32))); // Start our stopwatch _stopwatch.Start(); while (true) { Tick(); Thread.Sleep(100); // sleep until we have proper game loop } }
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; }
protected override void Save() { var ContentTemplate = this.ContentTemplate as QuestTemplate; // Persist rewards ContentTemplate.Rewards = questRewardEditor1.Rewards; ContentTemplate.QuestSteps = questStepEditor1.Steps; using (var db = new GameDatabaseContext()) { var repository = new QuestRepository(db); repository.Update(ContentTemplate, ContentTemplate.Id); } base.Save(); }
/// <summary> /// Retrieves a quest that has been created /// </summary> /// <param name="id"></param> /// <returns></returns> public QuestTemplate GetQuest(long id) { using (var context = new GameDatabaseContext()) { var quest = context.Quests.First(x => x.Id == id); context.Entry(quest).Collection(x => x.Rewards).Load(); context.Entry(quest).Collection(x => x.QuestSteps).Load(); // Load up our set of requirements from the table foreach (var x in quest.QuestSteps) context.Entry(x).Collection(a => a.Requirements).Load(); return quest; } }
public IHttpActionResult DeleteItem(int id) { using (var context = new GameDatabaseContext()) { var item = context.ItemTemplates.FirstOrDefault(x => x.Id == id); if (item != null) { var entry = context.Entry(item); entry.State = EntityState.Deleted; context.SaveChanges(); return Ok(); } return NotFound(); } }
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; }
/// <summary> /// Creates a monster given a reference ID. /// </summary> /// <param name="id">The ID of the monster to fetch the template for</param> /// <returns></returns> public static Monster CreateMonster(long id) { using (var context = new GameDatabaseContext()) { var template = context.MonsterTemplates.FirstOrDefault(x => x.Id == id); // Setup actual object var monster = new Monster(template); // Copy stats into CopyStatsFromTemplateToCharacter(template, monster); monster.CurrentAi = new WanderAi(monster); monster.Skills.Add(new Skill(context.SkillTemplates.First(x => x.Id == 1))); return monster; } }
protected override void Save() { // (:: It might be a good idea to move some of the NPC update logic into the repo, but for now this works) using (var db = new GameDatabaseContext()) { var ContentTemplate = this.ContentTemplate as NpcTemplate; var originalJob = db.Npcs.Include(j => j.ConversationAvailableTemplate).Include(x => x.Quests) .Single(j => j.Id == ContentTemplate.Id); // Update scalar/complex properties db.Entry(originalJob).CurrentValues.SetValues(ContentTemplate); if (ContentTemplate.ConversationAvailableTemplate != null) { var originalDialog = db.DialogTemplates.Single(x => x.Id == ContentTemplate.ConversationAvailableTemplate.Id); originalJob.ConversationAvailableTemplate = originalDialog; } if (ContentTemplate.Quests != null) { List<QuestTemplate> templates = new List<QuestTemplate>(); foreach (var quest in ContentTemplate.Quests) { // For each quest we now have, try and find the new, opposing quest var originalQuest = db.Quests.First(x => x.Id == quest.Id); templates.Add(originalQuest); } originalJob.Quests = templates; } db.SaveChanges(); } base.Save(); }
public override void UseItemOn(Character character, Character user) { var player = character as Player; if (player != null) { using (var context = new GameDatabaseContext()) { var skillRepo = new SkillRepository(context); var skillTemplate = skillRepo.Get(ItemTemplate.LearntSkillId); player.AddSkill(new Skill(skillTemplate)); } } else { Logger.Instance.Warn("You cannot use a skillbook on a non-player target."); } }
public static void OnLoginRequest(GameClient client, ClientLoginRequestPacket packet) { Logger.Instance.Info("LoginHandler.OnLoginRequest", client, packet); UserAccount account; bool loginSuccessful = AuthenticationProvider.Authenticate(packet.Username, packet.Password, out account); if (!loginSuccessful) { client.Send(new ServerLoginResponsePacket(LoginStatus.InvalidCredentials)); return; } if (account.IsOnline) { client.Send(new ServerLoginResponsePacket(LoginStatus.AlreadyLoggedIn)); return; } client.Account = account; using (var context = new GameDatabaseContext()) { context.Accounts.Attach(account); account.IsOnline = true; context.SaveChanges(); // Load heroes context.Entry(account).Collection(a => a.Heroes).Load(); } client.Send(new ServerLoginResponsePacket(LoginStatus.OK)); HeroSelectionHandler.SendHeroList(client); }