private InventoryItemDTO Insert(InventoryItemDTO inventoryitem, OpenNosContainer context) { InventoryItem entity = Mapper.Map<InventoryItem>(inventoryitem); context.inventoryitem.Add(entity); context.SaveChanges(); return Mapper.Map<InventoryItemDTO>(entity); }
public SaveResult InsertOrUpdate(ref InventoryItemDTO item) { try { using (var context = DataAccessHelper.CreateContext()) { long InventoryItemId = item.InventoryItemId; InventoryItem entity = context.inventoryitem.SingleOrDefault(c => c.InventoryItemId.Equals(InventoryItemId)); if (entity == null) //new entity { item = Insert(item, context); return SaveResult.Inserted; } else //existing entity { item = Update(entity, item, context); return SaveResult.Updated; } } } catch (Exception e) { Logger.Log.ErrorFormat(Language.Instance.GetMessageFromKey("UPDATE_ACCOUNT_ERROR"), item.InventoryItemId, e.Message); return SaveResult.Error; } }
private InventoryItemDTO Update(InventoryItem entity, InventoryItemDTO inventoryitem, OpenNosContainer context) { using (context) { var result = context.inventoryitem.SingleOrDefault(c => c.InventoryItemId.Equals(inventoryitem.InventoryItemId)); if (result != null) { result = Mapper.Map<InventoryItemDTO, InventoryItem>(inventoryitem, entity); context.SaveChanges(); } } return Mapper.Map<InventoryItemDTO>(entity); }
public int UpgradeItem(InventoryItemDTO item, InventoryItem.UpgradeMode mode, InventoryItem.UpgradeProtection protection) { #region Upgrade Stats short[] upsuccess = { 100, 100, 90, 80, 60, 40, 20, 10, 5, 1 }; short[] upfix = { 0, 0, 10, 15, 20, 20, 20, 20, 15, 10 }; #endregion short itempricevnum1 = 0; short itempricevnum2 = 0; short goldprice = 500; double reducedpricefactor = 0.5; switch (mode) { case InventoryItem.UpgradeMode.Free: break; case InventoryItem.UpgradeMode.Reduced: //TODO: Reduced Item Amount Session.Character.Gold = Session.Character.Gold - (long)(goldprice * reducedpricefactor); break; case InventoryItem.UpgradeMode.Normal: //TODO: Normal Item Amount Session.Character.Gold = Session.Character.Gold - goldprice; break; } Random r = new Random(); int rnd = r.Next(100); if (rnd <= upsuccess[item.Upgrade + 1]) { item.Upgrade++; return 2; } else if (rnd <= upfix[item.Upgrade + 1]) { return 1; } else { if (protection == InventoryItem.UpgradeProtection.None) { //TODO: Item Destroy return -1; } else { return 0; } } }
public int RarifyItem(InventoryItemDTO item, InventoryItem.RarifyMode mode, InventoryItem.RarifyProtection protection) { double rare1 = 50; double rare2 = 35; double rare3 = 25; double rare4 = 10; double rare5 = 10; double rare6 = 5; double rare7 = 1; double reducedchancefactor = 1.1; short itempricevnum = 0; short goldprice = 500; double reducedpricefactor = 0.5; if (protection == InventoryItem.RarifyProtection.RedAmulet) { rare1 = rare1 * reducedchancefactor; rare2 = rare2 * reducedchancefactor; rare3 = rare3 * reducedchancefactor; rare4 = rare4 * reducedchancefactor; rare5 = rare5 * reducedchancefactor; rare6 = rare6 * reducedchancefactor; rare7 = rare7 * reducedchancefactor; } switch (mode) { case InventoryItem.RarifyMode.Free: break; case InventoryItem.RarifyMode.Reduced: //TODO: Reduced Item Amount Session.Character.Gold = Session.Character.Gold - (long)(goldprice * reducedpricefactor); break; case InventoryItem.RarifyMode.Normal: //TODO: Normal Item Amount Session.Character.Gold = Session.Character.Gold - goldprice; break; } Random r = new Random(); int rnd = r.Next(100); if (rnd <= rare7) { return item.Rare = 7; } else if (rnd <= rare6) { return item.Rare = 6; } else if (rnd <= rare5) { return item.Rare = 5; } else if (rnd <= rare4) { return item.Rare = 4; } else if (rnd <= rare3) { return item.Rare = 3; } else if (rnd <= rare2) { return item.Rare = 2; } else if (rnd <= rare1) { return item.Rare = 1; } else { if (protection == InventoryItem.RarifyProtection.None) { //TODO: Item Destroy return -1; } else { return 0; } } }
public void LoadCharacters(string packet) { string[] loginPacketParts = packet.Split(' '); //load account by given SessionId if (Session.Account == null) { bool hasRegisteredAccountLogin = true; try { hasRegisteredAccountLogin = ServiceFactory.Instance.CommunicationService.HasRegisteredAccountLogin(loginPacketParts[4], Session.SessionId); } catch (Exception ex) { Logger.Log.Error(ex.Message); } if (loginPacketParts.Length > 4 && hasRegisteredAccountLogin) { AccountDTO accountDTO = DAOFactory.AccountDAO.LoadByName(loginPacketParts[4]); if (accountDTO != null) { if (accountDTO.Password.Equals(EncryptionBase.sha256(loginPacketParts[6]))) { var account = new GameObject.Account() { AccountId = accountDTO.AccountId, Name = accountDTO.Name, Password = accountDTO.Password, Authority = accountDTO.Authority }; Session.InitializeAccount(account); } else { Logger.Log.ErrorFormat("Client {0} forced Disconnection, invalid Password or SessionId.", Session.Client.ClientId); Session.Client.Disconnect(); } } else { Logger.Log.ErrorFormat("Client {0} forced Disconnection, invalid AccountName.", Session.Client.ClientId); Session.Client.Disconnect(); } } else { Logger.Log.ErrorFormat("Client {0} forced Disconnection, login has not been registered or Account has already logged in.", Session.Client.ClientId); Session.Client.Disconnect(); Session.Destroy(); return; } } IEnumerable<CharacterDTO> characters = DAOFactory.CharacterDAO.LoadByAccount(Session.Account.AccountId); Logger.Log.InfoFormat(Language.Instance.GetMessageFromKey("ACCOUNT_ARRIVED"), Session.SessionId); Session.Client.SendPacket("clist_start 0"); foreach (CharacterDTO character in characters) { //move to character InventoryItemDTO[] item = new InventoryItemDTO[15]; for (short i = 0; i < 15; i++) { InventoryDTO inv = DAOFactory.InventoryDAO.LoadBySlotAndType(character.CharacterId, i, (short)InventoryType.Equipment); if (inv != null) { item[i] = DAOFactory.InventoryItemDAO.LoadById(inv.InventoryItemId); } } Session.Client.SendPacket(String.Format("clist {0} {1} {2} {3} {4} {5} {6} {7} {8} {9}.{10}.{11}.{12}.{13}.{14}.{15}.{16} {17} {18} {19} {20}.{21} {22} {23}", character.Slot, character.Name, 0, character.Gender, character.HairStyle, character.HairColor, 5, character.Class, character.Level, item[(short)EquipmentType.Hat] != null ? item[(short)EquipmentType.Hat].ItemVNum : 0, item[(short)EquipmentType.Armor] != null ? item[(short)EquipmentType.Armor].ItemVNum : 0, item[(short)EquipmentType.MainWeapon] != null ? item[(short)EquipmentType.MainWeapon].ItemVNum : 0, item[(short)EquipmentType.SecondaryWeapon] != null ? item[(short)EquipmentType.SecondaryWeapon].ItemVNum : 0, item[(short)EquipmentType.Mask] != null ? item[(short)EquipmentType.Mask].ItemVNum : 0, item[(short)EquipmentType.Fairy] != null ? item[(short)EquipmentType.Fairy].ItemVNum : 0, item[(short)EquipmentType.CostumeSuite] != null ? item[(short)EquipmentType.CostumeSuite].ItemVNum : 0, item[(short)EquipmentType.CostumeHat] != null ? item[(short)EquipmentType.CostumeHat].ItemVNum : 0, 1, 0, 0, -1, -1, item[(short)EquipmentType.Hat] != null ? (ServerManager.GetItem(item[(short)EquipmentType.Hat].ItemVNum).Colored ? item[(short)EquipmentType.Hat].Color : character.HairColor) : character.HairColor, 0)); } Session.Client.SendPacket("clist_end"); }
private InventoryItemDTO Insert(InventoryItemDTO inventoryitem, OpenNosContainer context) { InventoryItem entity = new InventoryItem() { Ammo = inventoryitem.Ammo, FireElement = inventoryitem.FireElement, IsFixed = inventoryitem.IsFixed, Color = inventoryitem.Color, Concentrate = inventoryitem.Concentrate, Amount = inventoryitem.Amount, CriticalLuckRate = inventoryitem.CriticalLuckRate, CriticalRate = inventoryitem.CriticalRate, DamageMaximum = inventoryitem.DamageMaximum, DamageMinimum = inventoryitem.DamageMinimum, DarkElement = inventoryitem.DarkElement, DefenceDodge = inventoryitem.DefenceDodge, DistanceDefence = inventoryitem.DistanceDefence, DistanceDefenceDodge = inventoryitem.DistanceDefenceDodge, ElementRate = inventoryitem.ElementRate, HitRate = inventoryitem.HitRate, ItemVNum = inventoryitem.ItemVNum, LightElement = inventoryitem.LightElement, MagicDefence = inventoryitem.MagicDefence, Rare = inventoryitem.Rare, SlDefence = inventoryitem.SlDefence, SlElement = inventoryitem.SlElement, SlHit = inventoryitem.SlHit, SlHP = inventoryitem.SlHP, SpLevel = inventoryitem.SpLevel, SpXp = inventoryitem.SpXp, Upgrade = inventoryitem.Upgrade, WaterElement = inventoryitem.WaterElement, RangeDefence = inventoryitem.RangeDefence, }; context.inventoryitem.Add(entity); try { context.SaveChanges(); } catch (Exception e) { Logger.Log.ErrorFormat(e.Message); } return Mapper.Map<InventoryItemDTO>(entity); }