コード例 #1
0
        public static Fighter GenHeroFightStats(Heros hero, my_appContext _context)
        {
            Equipment    Equipment     = _context.Equipment.FirstOrDefault(e => e.HeroId == hero.HeroId);
            List <Items> itemsOn       = new List <Items>();
            List <int?>  itemsPossible = new List <int?>()
            {
                Equipment.Armour, Equipment.Bracelet, Equipment.FirstHand, Equipment.Gloves, Equipment.Helmet,
                Equipment.Neckles, Equipment.Ring1,
                Equipment.Ring2, Equipment.SecondHand, Equipment.Shoes, Equipment.Trousers
            };

            int[] attributes = new int[8] {
                hero.Strength, hero.Endurance, hero.Dexterity, hero.Reflex, hero.Wisdom, hero.Intelligence, hero.Charisma, hero.Willpower
            };
            int AttackMin = 0;
            int AttackMax = 0;
            int Armour    = 0;

            foreach (int?it in itemsPossible)
            {
                if (it.HasValue)
                {
                    var found = _context.Items.FirstOrDefault(e => e.ItemId == it.Value);
                    if (found == null)
                    {
                        throw new Exception("Unknown item in equipment");
                    }
                    itemsOn.Add(found);
                }
            }
            foreach (Items it in itemsOn)
            {
                int[] itAttr = new int[8] {
                    it.Strength, it.Endurance, it.Dexterity, it.Reflex, it.Wisdom, it.Intelligence, it.Charisma, it.Willpower
                };
                for (int i = 0; i < 8; i++)
                {
                    attributes[i] += itAttr[i];
                }
                AttackMin += it.DmgMin;
                AttackMax += it.DmgMax;
                Armour    += it.Armour;
            }
            AttackMin += (int)Math.Ceiling(attributes[0] * 0.1);
            AttackMax += (int)Math.Ceiling(attributes[0] * 0.1);
            Armour    += (int)Math.Floor(attributes[1] * 0.1);
            return(new Fighter()
            {
                Strength = attributes[0],
                Endurance = attributes[1],
                Dexterity = attributes[2],
                Reflex = attributes[3],
                Wisdom = attributes[4],
                Intelligence = attributes[5],
                Charisma = attributes[6],
                Willpower = attributes[7],
                AttackMax = AttackMax,
                AttackMin = AttackMin,
                Armour = Armour,
                Hp = hero.Hp,
            });
        }
コード例 #2
0
        public static GeneralStatus GetHeroGeneralStatus(my_appContext _context, Heros hero, DateTime now)
        {
            object statusData = null;
            var    location   = _context.HerosLocations.FirstOrDefault(e => (e.HeroId == hero.HeroId) && (e.LocationIdentifier == hero.CurrentLocation));

            if (location == null)
            {
                throw new Exception("Location is not available.");
            }
            var descr = _context.LocationsDb.FirstOrDefault(e => e.LocationIdentifier == location.LocationIdentifier);

            if (descr == null)
            {
                throw new Exception("LocationData is not available.");
            }
            // TODO Location Type
            object locationResult = new LocationResult <object>();

            int LocationType = descr.LocationGlobalType;

            if (LocationType != 2)
            {
                LocationDescription description = JsonConvert.DeserializeObject <LocationDescription>(descr.Sketch);
                LocationState       state       = JsonConvert.DeserializeObject <LocationState>(location.Description);
                description.LocationGlobalType = descr.LocationGlobalType;

                if (hero.Status == 1)
                {
                    Traveling travel = _context.Traveling.FirstOrDefault(e => e.HeroId == hero.HeroId);
                    if (travel == null)
                    {
                        throw new Exception("Traveling hero without travel in DB.");
                    }
                    if (travel.HasEnded(now))
                    {
                        state                = description.MoveTo(travel.UpdatedLocationID(), state);
                        hero.Status          = 0;
                        location.Description = JsonConvert.SerializeObject(state);
                        _context.Traveling.Remove(travel);
                        try
                        {
                            _context.SaveChanges();
                        }
                        catch (DbUpdateException)
                        {
                            throw new Exception("Failed to remove travel.");
                        }
                    }
                    else
                    {
                        statusData = travel.GenTravelResult(now);
                    }
                }
                locationResult = description.GenLocalForm(state);
            }
            else
            {
                InstanceDescription description = JsonConvert.DeserializeObject <InstanceDescription>(descr.Sketch);
                InstanceState       state       = JsonConvert.DeserializeObject <InstanceState>(location.Description);
                description.LocationGlobalType = descr.LocationGlobalType;

                if (hero.Status == 1)
                {
                    Traveling travel = _context.Traveling.FirstOrDefault(e => e.HeroId == hero.HeroId);
                    if (travel == null)
                    {
                        throw new Exception("Traveling hero without travel in DB.");
                    }
                    if (travel.HasEnded(now))
                    {
                        state                = description.MoveTo(travel.UpdatedLocationID(), state);
                        hero.Status          = 0;
                        location.Description = JsonConvert.SerializeObject(state);
                        _context.Traveling.Remove(travel);
                        try
                        {
                            _context.SaveChanges();
                        }
                        catch (DbUpdateException)
                        {
                            throw new Exception("Failed to remove travel.");
                        }
                    }
                    else
                    {
                        statusData = travel.GenTravelResult(now);
                    }
                }
                locationResult = description.GenLocalForm(state);
            }

            if (hero.Status == 2)
            {
                Healing heal = _context.Healing.FirstOrDefault(e => e.HeroId == hero.HeroId);
                if (heal == null)
                {
                    throw new Exception("Healing hero without heal in DB.");
                }
                if (heal.HasEnded(now))
                {
                    int newHP = heal.FinalHealth(now);
                    hero.Hp = newHP;
                    HeroCalculator.CheckHeroHP(hero, _context);

                    _context.Healing.Remove(heal);
                    hero.Status = 0;
                    try
                    {
                        _context.SaveChanges();
                    }
                    catch (DbUpdateException)
                    {
                        throw new Exception("Failed to remove healing.");
                    }
                }
                else
                {
                    statusData = heal.GenHealingResult(now);
                }
            }
            if (hero.Status == 3)
            {
                Fighting fight = _context.Fighting.FirstOrDefault(e => e.HeroId == hero.HeroId);
                if (fight == null)
                {
                    throw new Exception("Healing hero without heal in DB.");
                }
                statusData = fight.GenResult(_context, hero);
            }
            return(new GeneralStatus()
            {
                HeroStatus = hero.Status,
                Location = locationResult,
                StatusData = statusData,
            });
        }
コード例 #3
0
 public static int MoveHeroToGlobal(my_appContext _context, Heros hero, int locationID)
 {
     MoveHeroToLocation(_context, hero, 0);
     return(0);
 }
コード例 #4
0
        public static LocationResult <InstanceNodeResult> InstanceClearCurrent(my_appContext _context, Heros hero)
        {
            var location = _context.HerosLocations.FirstOrDefault(e => (e.HeroId == hero.HeroId) && (e.LocationIdentifier == hero.CurrentLocation));

            if (location == null)
            {
                throw new Exception("Location is not available.");
            }
            var descr = _context.LocationsDb.FirstOrDefault(e => e.LocationIdentifier == location.LocationIdentifier);

            if (descr == null)
            {
                throw new Exception("LocationData is not available.");
            }

            int LocationType = descr.LocationGlobalType;

            if (LocationType != 2)
            {
                throw new OperationException("locationErr", "Fight outside the location");
            }
            else
            {
                InstanceDescription description = JsonConvert.DeserializeObject <InstanceDescription>(descr.Sketch);
                InstanceState       state       = JsonConvert.DeserializeObject <InstanceState>(location.Description);
                description.LocationGlobalType = descr.LocationGlobalType;

                if (hero.Hp > 0)
                {
                    state.IsCleared[state.CurrentLocation] = true;
                    location.Description = JsonConvert.SerializeObject(state);
                }

                return(description.GenLocalForm(state));
            }
        }