コード例 #1
0
        public static void Create(string name, int strenght, int weakness, int weapon, ApplicationDbContext ctx)
        {
            _ctx = ctx;

            Creature Hero = new Creature
            {
                Name       = name,
                Type       = Enumerators.CreatureTypeEnum.Hero,
                Level      = 0,
                Experience = 10,
                Alive      = true,
                Strength   = 8,
                Endurance  = 8,
                Willpower  = 8,
                Speed      = 8,
                Agility    = 8,
                Weapon     = new Weapon(),
                Armor      = _ctx.Armors.FirstOrDefault(x => x.Id == 29),
                MagicBook  = new List <Spell>(),
                Items      = new List <CreatureItem>()
            };

            switch (strenght)
            {
            case 0:
                Hero.Strength += 2;
                break;

            case 1:
                Hero.Endurance += 2;
                break;

            case 2:
                Hero.Willpower += 2;
                break;

            case 3:
                Hero.Speed += 2;
                break;

            case 4:
                Hero.Agility += 2;
                break;
            }             // switch (strenght)

            switch (weakness)
            {
            case 0:
                Hero.Strength -= 1;
                break;

            case 1:
                Hero.Endurance -= 1;
                break;

            case 2:
                Hero.Willpower -= 1;
                break;

            case 3:
                Hero.Speed -= 1;
                break;

            case 4:
                Hero.Agility -= 1;
                break;
            }             // switch (weakness)

            switch (weapon)
            {
            case 0:
                Hero.Weapon = _ctx.Weapons.FirstOrDefault(x => x.Id == 5);
                break;

            case 1:
                Hero.Weapon = _ctx.Weapons.FirstOrDefault(x => x.Id == 39);
                break;

            case 2:
                Hero.Weapon = _ctx.Weapons.FirstOrDefault(x => x.Id == 12);
                break;
            }             // switch (weapon)


            Hero.MagicBook.Add(_ctx.Spells.First(x => x.Id == 1));
            Hero.MagicBook.Add(_ctx.Spells.First(x => x.Id == 2));

            _ctx.Creatures.Add(Hero);
            _ctx.SaveChanges();

            Hero = _ctx.Creatures.Include(x => x.Items).OrderBy(x => x.Id).LastOrDefault();
            Item item = _ctx.Items.FirstOrDefault(x => x.Id == 1);

            Hero.Items.Add(new CreatureItem
            {
                CreatureId = Hero.Id,
                ItemId     = item.Id,
                Qty        = 3,

                Creature = Hero,
                Item     = item
            });

            _ctx.SaveChanges();

            CalculateCreature.DerivedStatistics(Hero, _ctx);

            BattleStatus.AssignHero(Hero.Id, _ctx);
        }         // Create()
コード例 #2
0
ファイル: BattleStatus.cs プロジェクト: Mlorism/LastTemple
        }         // VerifyStatus()

        public static void CheckLevel(ApplicationDbContext ctx)
        {
            switch (Hero.Experience)
            {
            case int n when(n >= 50 && n < 150):
                if (Hero.Level != 1)
                {
                    AddToLog(new string($"{Hero.Name} osiąga poziom 1."));
                    CalculateCreature.DerivedStatistics(Hero, ctx);
                    Hero.Level = 1;
                }

                break;

            case int n when(n >= 150 && n < 350):
                if (Hero.Level != 2)
                {
                    AddToLog(new string($"{Hero.Name} osiąga poziom 2."));
                    CalculateCreature.DerivedStatistics(Hero, ctx);
                    Hero.Level = 2;
                }

                break;

            case int n when(n >= 350 && n < 750):
                if (Hero.Level != 3)
                {
                    AddToLog(new string($"{Hero.Name} osiąga poziom 3."));
                    CalculateCreature.DerivedStatistics(Hero, ctx);
                    Hero.Level = 3;
                }

                break;

            case int n when(n >= 750 && n < 1550):
                if (Hero.Level != 4)
                {
                    AddToLog(new string($"{Hero.Name} osiąga poziom 4."));
                    CalculateCreature.DerivedStatistics(Hero, ctx);
                    Hero.Level = 4;
                }

                break;

            case int n when(n >= 1550 && n < 3150):
                if (Hero.Level != 5)
                {
                    AddToLog(new string($"{Hero.Name} osiąga poziom 5."));
                    CalculateCreature.DerivedStatistics(Hero, ctx);
                    Hero.Level = 5;
                }

                break;

            case int n when(n >= 3150 && n < 6350):
                if (Hero.Level != 6)
                {
                    AddToLog(new string($"{Hero.Name} osiąga poziom 6."));
                    CalculateCreature.DerivedStatistics(Hero, ctx);
                    Hero.Level = 6;
                }

                break;

            case int n when(n >= 6350 && n < 12750):
                if (Hero.Level != 7)
                {
                    AddToLog(new string($"{Hero.Name} osiąga poziom 7."));
                    CalculateCreature.DerivedStatistics(Hero, ctx);
                    Hero.Level = 7;
                }

                break;

            case int n when(n >= 12750 && n < 25500):
                if (Hero.Level != 8)
                {
                    AddToLog(new string($"{Hero.Name} osiąga poziom 8."));
                    CalculateCreature.DerivedStatistics(Hero, ctx);
                    Hero.Level = 8;
                }

                break;

            case int n when(n >= 25500 && n < 51150):
                if (Hero.Level != 9)
                {
                    AddToLog(new string($"{Hero.Name} osiąga poziom 9."));
                    CalculateCreature.DerivedStatistics(Hero, ctx);
                    Hero.Level = 9;
                }

                break;

            case int n when(n >= 51150):
                if (Hero.Level != 10)
                {
                    AddToLog(new string($"{Hero.Name} osiąga poziom 10."));
                    CalculateCreature.DerivedStatistics(Hero, ctx);
                    Hero.Level = 10;
                }

                break;
            }
        }         // CheckLevel()