Esempio n. 1
0
        private IEnumerator beginSave(Weapon weapon, LoginAuth loginAuth)
        {
            WeaponDTO dto        = weapon.serialize();
            string    weaponJson = JsonUtility.ToJson(weapon);

            Debug.Log(weaponJson);
            byte[] weaponJsonByte = System.Text.Encoding.UTF8.GetBytes(weaponJson);
            //byte[] testData = System.Text.Encoding.UTF8.GetBytes("helloUnity");
            UnityWebRequest www = UnityWebRequest.Put(saveWeaponUri + weapon.id, weaponJsonByte);

            www.SetRequestHeader("Authorization", "Token token=" + loginAuth.auth_token);

            // this is key for rails to know what kind of data to even think how to start parsing
            www.SetRequestHeader("Content-Type", "application/json");
            www.downloadHandler = new DownloadHandlerBuffer();

            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log("weapon update success");
                // Debug.Log (www.downloadHandler.text);

                NetworkResponses rd = JsonUtility.FromJson <NetworkResponses>(www.downloadHandler.text);
                Debug.Log(rd.success [0]);
            }
        }
        //start of interface implementation
        public void AddNewWeapon(WeaponDTO model)
        {
            System.Diagnostics.Debug.WriteLine("inside Add new weapon of WeaponService");
            bool hasElement = false;

            if (model.Element.ToLower() != "none")
            {
                hasElement = true;
            }
            //check if weapon has element
            //find element id
            //add new Equipment_element
            if (ValidateWeaponAttributes(model))
            {
                _weaponRepo.AddNewWeaponToDb(model);
            }


            if (hasElement)
            {
                //int weaponId = _weaponRepo.GetWeapon(model.Name).WeaponId;
                ElementDTO equipElement = new ElementDTO();

                if (ValidateElementProperty(0, model.Element, model.ElementDamage, equipElement))
                {
                    _equipmentElementRepo.AddNewEquipmentElement(0, equipElement);
                }
            }
            //check is weapon has element and if element name exists
            //find if  element name exists in element DB

            // _equipmentElementRepo.AddNewEquipmentElement(model.Name, model.Element, model.ElementDamage);
        }
        public void AddNewEquipmentElement(string weaponName, string elementName, int elementDamange)
        {
            WeaponDTO tempWeapon = _weaponRepo.GetWeapon(weaponName);

            //find element to see if exists in element table
            //_elementRepo

            //_elementService.CheckElementName(elementName);
            throw new NotImplementedException();
        }
Esempio n. 4
0
 /// <summary>
 /// Deserialize from dto
 /// </summary>
 /// <param name="dto">Dto.</param>
 public void loadFromDTO(WeaponDTO dto)
 {
     id             = dto.id;
     weaponName     = dto.name;
     rarity         = dto.rarity;
     minDamage      = dto.minDamage;
     maxDamage      = dto.maxDamage;
     quality        = dto.quality;
     max_durability = dto.max_durability;
 }
Esempio n. 5
0
    /// <summary>
    /// Serialize this instance and return a weaponDTO
    /// </summary>
    public WeaponDTO serialize()
    {
        WeaponDTO dto = new WeaponDTO();

        dto.id             = id;
        dto.name           = name;
        dto.rarity         = rarity;
        dto.minDamage      = minDamage;
        dto.maxDamage      = maxDamage;
        dto.quality        = quality;
        dto.max_durability = max_durability;
        return(dto);
    }
 private Weapon WeaponMapper(WeaponDTO model)
 {
     return(new Weapon()
     {
         Name = model.Name,
         Rarity = model.Rarity,
         Attack = model.Attack,
         Sharpness = model.Sharpness,
         Slots = model.Slots,
         Affinity = model.Affinity,
         Defense = model.Defense
     });
 }
        public void AddNewWeaponToDb(WeaponDTO model)
        {
            Weapon newWeapon = WeaponMapper(model);

            System.Diagnostics.Debug.WriteLine("INSIDE DAL layer Weapons Repo");
            System.Diagnostics.Debug.WriteLine(newWeapon.Name);
            System.Diagnostics.Debug.WriteLine(newWeapon.Attack);
            System.Diagnostics.Debug.WriteLine(newWeapon.Sharpness);
            System.Diagnostics.Debug.WriteLine(newWeapon.Rarity);
            System.Diagnostics.Debug.WriteLine(newWeapon.Affinity);
            System.Diagnostics.Debug.WriteLine(newWeapon.Slots);


            //_db.Weapons.Add(WeaponMapper(model));
            //_db.SaveChanges();
        }
        private bool ValidateWeaponAttributes(WeaponDTO weapon)
        {
            bool isValid = true;

            if (weapon.Rarity < 0 || weapon.Rarity > 6)
            {
                isValid = false;
            }

            if (weapon.Slots > 3)
            {
                isValid = false;
            }

            System.Diagnostics.Debug.WriteLine("inside validate weapon");
            return(isValid);
        }
Esempio n. 9
0
        public async Task <ServiceResponse <CharacterDTO> > AddWeapon(WeaponDTO weaponDTO)
        {
            ServiceResponse <CharacterDTO> serviceResponse = new ServiceResponse <CharacterDTO>();

            try
            {
                Character character = await _dataContext.Characters.Include(x => x.User).FirstOrDefaultAsync(x =>
                                                                                                             x.Id == weaponDTO.CharacterId && x.User.Id == GetUserId());

                if (character == null)
                {
                    serviceResponse.Success = false;
                    serviceResponse.Message = "Character not found.";
                }

                Weapon weapon = new Weapon
                {
                    Name        = weaponDTO.Name,
                    Damage      = weaponDTO.Damage,
                    CharacterId = character.User.Id
                };

                await _dataContext.Weapons.AddAsync(weapon);

                await _dataContext.SaveChangesAsync();

                serviceResponse.Data = _iMapper.Map <CharacterDTO>(await _dataContext.Characters.FirstOrDefaultAsync(x =>
                                                                                                                     x.Id == weaponDTO.CharacterId));
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }

            return(serviceResponse);
        }
Esempio n. 10
0
        public async Task <serviceResponse <GetCharacterDTO> > AddWeapon(WeaponDTO newWeapon)
        {
            serviceResponse <GetCharacterDTO> response = new serviceResponse <GetCharacterDTO>();

            try
            {
                Character character = await _context.Characters.FirstOrDefaultAsync(c => c.Id == newWeapon.CharacterId &&
                                                                                    c.User.id == int.Parse(_httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)));

                if (character == null)
                {
                    response.Success = false;
                    response.Message = "No Character was found";
                }

                WeaponModel Weapons = new WeaponModel
                {
                    Name      = newWeapon.Name,
                    Damage    = newWeapon.Damage,
                    Character = character
                };

                await _context.Weapons.AddAsync(Weapons);

                await _context.SaveChangesAsync();


                response.Data = _mapper.Map <GetCharacterDTO>(character);
            }

            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Esempio n. 11
0
 public async Task <IActionResult> AddWeapon(WeaponDTO newWeapon)
 {
     return(Ok(await _weaponService.AddWeapon(newWeapon)));
 }
 public async Task <IActionResult> AddWeapon(WeaponDTO weaponDTO)
 {
     return(Ok(await _iWeaponService.AddWeapon(weaponDTO)));
 }