Ejemplo n.º 1
0
        public async Task <bool> Insert(AttributesDto data)
        {
            var  attribute = _mapper.Map <AttributesDto, Attributes>(data);
            bool result    = _repo.AttributesRepository.Insert(attribute);
            await _repo.SaveAsync();

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <bool> Update(int id, AttributesDto data)
        {
            var  attribute = _mapper.Map <AttributesDto, Attributes>(data);
            bool result    = _repo.AttributesRepository.Update(id, attribute);
            await _repo.SaveAsync();

            return(result);
        }
Ejemplo n.º 3
0
        public AttributesDto GenerateAttributesAccordingToCharacter(CharacterCreateDto character)
        {
            var attr = new AttributesDto()
            {
                Id = Guid.NewGuid(), Damage = 10, Defense = 10, Hp = 15
            };

            float[] raceMultiplier;
            float[] schoolMultiplier;
            switch (character.Race)
            {
            case Race.Human:
                raceMultiplier = new[] { 1.8F, 1.8F, 1.8F };
                break;

            case Race.Elf:
                raceMultiplier = new[] { 2.2F, 1.6F, 1.6F };
                break;

            case Race.Dwarf:
                raceMultiplier = new[] { 1.7F, 2.0F, 2F };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            switch (character.School)
            {
            case School.Wolf:
                schoolMultiplier = new[] { 1.8F, 1.8F, 1.8F };
                break;

            case School.Bear:
                schoolMultiplier = new[] { 1.5F, 2.0F, 2.0F };
                break;

            case School.Cat:
                schoolMultiplier = new[] { 2.0F, 1.7F, 1.7F };
                break;

            case School.Viper:
                schoolMultiplier = new[] { 1.9F, 1.9F, 1.7F };
                break;

            case School.Griffin:
                schoolMultiplier = new[] { 1.7F, 1.8F, 2.0F };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            attr.Damage  = (int)(attr.Damage * raceMultiplier[0] * schoolMultiplier[0]);
            attr.Defense = (int)(attr.Defense * raceMultiplier[1] * schoolMultiplier[1]);
            attr.Hp      = (int)(attr.Hp * raceMultiplier[2] * schoolMultiplier[2]);

            return(attr);
        }
Ejemplo n.º 4
0
        public async Task <Guid> CreateAttributes(AttributesDto attributes)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                attributes.Id = _attributesService.Create(attributes);
                await uow.Commit();

                return(attributes.Id);
            }
        }
Ejemplo n.º 5
0
        public async Task <Guid> CreateItem(ItemDto item, AttributesDto attr)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                attr.Id         = Guid.NewGuid();
                item.Attributes = attr;
                item.Id         = _itemService.Create(item);
                await uow.Commit();

                return(item.Id);
            }
        }
Ejemplo n.º 6
0
        public async Task <Guid> CreateMonster(MonsterDto monster, AttributesDto attr)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                attr.Id = Guid.NewGuid();

                monster.Attributes = attr;
                monster.Id         = _monsterService.Create(monster);
                await uow.Commit();

                return(monster.Id);
            }
        }
Ejemplo n.º 7
0
        private AttributesDto GenerateAttributesAccordingToExperience(int ex)
        {
            var baseAttr = new AttributesDto()
            {
                Hp = 15, Damage = 15, Defense = 15
            };
            var lvl = Math.Floor(25 + Math.Sqrt(625 + 100 * ex)) / 50;

            baseAttr.Hp      += (int)lvl;
            baseAttr.Defense += (int)lvl;
            baseAttr.Damage  += (int)lvl;
            return(baseAttr);
        }
Ejemplo n.º 8
0
        //random attributes
        private AttributesDto ItemAttributes(int level, ArmorClass armor, Quality quality)
        {
            var multiplier = 1.0;

            switch (quality)
            {
            case Quality.Common: break;

            case Quality.Rare:
                multiplier = 1.4;
                break;

            case Quality.Epic:
                multiplier = 1.7;
                break;

            case Quality.Legendary: break;
            }

            var attr = new AttributesDto();

            switch (armor)
            {
            case ArmorClass.Sword:
                attr.Hp      = (int)(level * multiplier);
                attr.Damage  = 2 * (int)(level * multiplier);
                attr.Defense = (int)(level * multiplier);
                return(attr);

            case ArmorClass.Armor:
                attr.Hp      = 2 * (int)(level * multiplier);
                attr.Damage  = (int)(level * multiplier);
                attr.Defense = (int)(level * multiplier);
                return(attr);

            case ArmorClass.Trousers:
                attr.Hp      = (int)(level * multiplier);
                attr.Damage  = (int)(level * multiplier);
                attr.Defense = 2 * (int)(level * multiplier);
                return(attr);

            case ArmorClass.Consumable:
                attr.Hp      = 5 * (int)(level * multiplier);
                attr.Damage  = 0;
                attr.Defense = 0;
                return(attr);

            default:
                return(attr);
            }
        }
Ejemplo n.º 9
0
    public void Initialize(Actor actor, AttributesDto attributesDto)
    {
        MaxHealth          = attributesDto.MaxHealth;
        Health             = attributesDto.Health;
        HealthRegeneration = attributesDto.HealthRegeneration;
        Speed       = attributesDto.Speed;
        Damage      = attributesDto.Damage;
        HungerRate  = attributesDto.HungerRate;
        Food        = attributesDto.Food;
        Temperature = attributesDto.Temperature;

        _actor = actor;
        StatusEffectScheduler.Instance(_actor.Guid).AddStatusEffect(new StatusEffectSystem.Status(_actor, 1f, StatusEffectManager.GetStatusEffectData(Constant.HUNGRY)));
    }
Ejemplo n.º 10
0
        public async Task <IActionResult> Post([FromBody] AttributesDto data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _attributeServices.Insert(data);

            if (result == true)
            {
                return(Ok("Successfully Created."));
            }
            return(BadRequest());
        }
Ejemplo n.º 11
0
        public async Task <bool> EditAttributesAsync(AttributesDto attr)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                if ((await _attributesService.GetAsync(attr.Id, false)) == null)
                {
                    return(false);
                }
                await _attributesService.Update(attr);

                await uow.Commit();

                return(true);
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] AttributesDto data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != data.Id)
            {
                return(BadRequest());
            }
            var result = await _attributeServices.Update(id, data);

            if (result == true)
            {
                return(Ok("Successfully Updated."));
            }
            return(BadRequest());
        }
Ejemplo n.º 13
0
        public async Task <Dictionary <string, object> > ChangeAttributes(string orgSlug, string dsSlug,
                                                                          AttributesDto attributes)
        {
            if (attributes == null)
            {
                throw new BadRequestException("Attributes are null");
            }

            var ds = await _utils.GetDataset(orgSlug, dsSlug);

            if (!await _authManager.IsOwnerOrAdmin(ds))
            {
                throw new UnauthorizedException("The current user is not allowed to change attributes");
            }

            var ddb   = _ddbManager.Get(orgSlug, ds.InternalRef);
            var attrs = await ddb.GetAttributesAsync();

            attrs.IsPublic = attributes.IsPublic;

            return(await ddb.GetAttributesRawAsync());
        }
Ejemplo n.º 14
0
        public AttributesDto CalculateAttributes()
        {
            var result = new AttributesDto()
            {
                Damage = Attributes.Damage, Defense = Attributes.Defense, Hp = Attributes.Hp
            };
            var equip = new List <ItemDto>()
            {
                Equipment.Armor, Equipment.Sword, Equipment.Trousers
            };

            foreach (var itemDto in equip)
            {
                if (itemDto == null)
                {
                    continue;
                }
                result.Damage  += itemDto.Attributes.Damage;
                result.Hp      += itemDto.Attributes.Hp;
                result.Defense += itemDto.Attributes.Defense;
            }
            return(result);
        }
Ejemplo n.º 15
0
        private Tuple <bool, int, int> Combat(AttributesDto p1, AttributesDto p2, ICollection <string> logger)
        {
            var whoseTurn = _random.Next(0, 100);

            var player1 = new CombatDto(p1, true);
            var player2 = new CombatDto(p2);

            logger.Add("You found yourself alone, riding in the green fields with the sun on your face, but you are not be troubled. For you are in Elysium, and you\'re already dead!");

            if (whoseTurn < 50) //50% for each side to start
            {
                player1.First = false;
                logger.Add("Your opponent took his chance and attacked you first.");
            }
            else
            {
                logger.Add("Your instincts awoke you and you took your chance to assault first.");
            }
            var i = 1;

            while (player1.Hp > 0 && player2.Hp > 0)
            {
                logger.Add($"------------Round number {i}------------");
                if (player1.First)
                {
                    var hit = Hit(p1.Damage, p2.Defense, logger, true);
                    player2.Hp -= hit;
                    if (player2.Hp <= 0)
                    {
                        break;
                    }

                    hit         = Hit(p2.Damage, p1.Defense, logger);
                    player1.Hp -= hit;
                    if (player1.Hp <= 0)
                    {
                        break;
                    }
                }
                else
                {
                    var hit = Hit(p2.Damage, p1.Defense, logger);
                    player1.Hp -= hit;
                    if (player1.Hp <= 0)
                    {
                        break;
                    }

                    hit         = Hit(p1.Damage, p2.Defense, logger, true);
                    player2.Hp -= hit;
                    if (player2.Hp <= 0)
                    {
                        break;
                    }
                }
                i++;
            }

            if (player1.Hp <= 0)
            {
                logger.Add("You died. (No darksouls pun intended)");
                return(new Tuple <bool, int, int>(false, 0, player2.Hp));
            }
            logger.Add("Congratulations, you have defeated the opponent.");
            return(new Tuple <bool, int, int>(true, player1.Hp, 0));
        }
Ejemplo n.º 16
0
 public CombatDto(AttributesDto a, bool f = false)
 {
     Attr  = a;
     Hp    = a.Hp * 10;
     First = f;
 }