コード例 #1
0
        private void goButton_Click(object sender, RoutedEventArgs e)
        {
            if (abilityPicker.SelectedIndex != -1)
            {
                //apply the status effects to the player. If they've expired, get rid of them
                for (int i = 0; i < Program.main.player.effects.Count; i++)
                {
                    if (Program.main.player.effects[i].turns >= 0)
                    {
                        Program.main.player.effects[i].Expire();
                        Program.main.player.effects.Remove(Program.main.player.effects[i]);
                    }
                    else
                    {
                        Program.main.player.effects[i].ApplyEffect(Program.main.player);
                    }
                }
                //if the Player is an Orc and he's missing health
                if (Program.main.player.pRace is Orc && Program.main.player.hp != Program.main.player.maxhp)
                {
                    var mod = 1.0f - (float)Program.main.player.hp / Program.main.player.maxhp;
                    Program.main.player.atk = Convert.ToInt32(Program.main.player.atk * mod);
                }
                //check to see that nothing's blocking the Player from attacking
                if (Program.main.player.canAttack)
                {
                    int damage = 0;
                    //determine if the player missed
                    bool result = Dice.misschance(enemy.spd);
                    //if you're an elf
                    if (!result || Program.main.player.pRace is Elf)
                    {
                        if (result)
                        {
                            write(Program.main.player.name + "'s ", "Black");
                            write("Keen Shot ", "Aqua", true);
                            write("prevented a miss!", "Black", true);
                        }
                        //use the selected Ability
                        var used = (Ability)abilityPicker.SelectedItem;
                        if (used.SingleUse && used.hasUsed)
                        {
                            descBlock.Text = "YOU HAVE ALREADY USED THIS ABILITY.";
                            return;
                        }
                        if (used.manacost > Program.main.player.mana)
                        {
                            descBlock.Text = "YOU DO NOT HAVE ENOUGH MANA.";
                            return;
                        }
                        Program.main.player.mana -= used.manacost;
                        int prevdef = Program.main.player.def, prevatk = Program.main.player.atk, prevspd = Program.main.player.spd, previntl = Program.main.player.intl;
                        int eprevdef = enemy.def, eprevatk = enemy.atk, eprevspd = enemy.spd, eprevintl = enemy.intl;
                        //change target based on the type of Ability
                        switch (used.TargetType)
                        {
                        case targetType.Enemy:
                            damage = Program.main.player.canBeHit ? used.Execute(enemy) : 0;
                            if (Program.main.player.pRace is Demon && (enemy.effects.FirstOrDefault(ef => ef.isNegative) != null))
                            {
                                enemy.hp -= Convert.ToInt32(damage + (damage * 1.33));
                            }
                            else
                            {
                                enemy.hp -= damage;
                            }
                            break;

                        case targetType.Self:
                            used.Execute(Program.main.player);
                            break;
                        }
                        write(Program.main.player.name + " used ", "Black");
                        write(used.Name, "Indigo", true);
                        write(".", "Black", true);
                        if (enemy.hp > 0)
                        {
                            if (used.Type == type.Physical && Program.main.player.pRace is Halfdragon)
                            {
                                write(Program.main.player.name + "'s ", "Black");
                                write("Burning Scales ", "Aqua", true);
                                write("have ignited the enemy!", "Black", true);
                                enemy.effects.Add(new OnFire(3, 1));
                            }
                            else if (used.Type == type.Magical && Program.main.player.pRace is Djinn)
                            {
                                write(Program.main.player.name + "'s ", "Black");
                                write("Power Tap ", "Aqua", true);
                                write("has lowered the enemy's defense!", "Black", true);
                                enemy.def -= 1;
                            }
                        }
                        if (used.TargetType == targetType.Enemy)
                        {
                            write(enemy.name + " took " + damage + " damage.", "Aqua");
                        }

                        if (Program.main.player.pRace is Vampire && damage != 0)
                        {
                            int heal = Convert.ToInt32(damage * .1);
                            write(Program.main.player.name + "'s ", "Black");
                            write("Life Drain ", "Aqua", true);
                            write("has healed " + Program.main.player.name + " for " + heal + " hp!", "Black", true);
                            Program.main.player.hp += heal;
                        }
                        if (Program.main.player.def < prevdef)
                        {
                            write(Program.main.player.name + "'s defense fell!", "Red");
                        }
                        if (Program.main.player.atk < prevatk)
                        {
                            write(Program.main.player.name + "'s attack fell!", "Red");
                        }
                        if (Program.main.player.spd < prevspd)
                        {
                            write(Program.main.player.name + "'s speed fell!", "Red");
                        }
                        if (Program.main.player.intl < previntl)
                        {
                            write(Program.main.player.name + "'s intelligence fell!", "Red");
                        }
                        if (enemy.def < eprevdef)
                        {
                            write(enemy.name + "'s defense fell!", "Red");
                        }
                        if (enemy.atk < eprevatk)
                        {
                            write(enemy.name + "'s attack fell!", "Red");
                        }
                        if (enemy.spd < eprevspd)
                        {
                            write(enemy.name + "'s speed fell!", "Red");
                        }
                        if (enemy.intl < eprevintl)
                        {
                            write(enemy.name + "'s intelligence fell!", "Red");
                        }
                    }
                    else
                    {
                        write(Program.main.player.name + " missed!", "Gray");
                    }
                }
                //update stats
                Program.main.writeStats();
                writeEnemyStats();
                //apply Enemy status effects
                for (int i = 0; i < enemy.effects.Count; i++)
                {
                    if (enemy.effects[i].turns <= 0)
                    {
                        enemy.effects[i].Expire();
                        enemy.effects.Remove(enemy.effects[i]);
                    }
                    else
                    {
                        enemy.effects[i].ApplyEffect(enemy);
                    }
                }
                EnemyAttack(Program.main.player);
                writeEnemyStats();
                Program.main.writeStats();
            }
        }
コード例 #2
0
        private void EnemyAttack(Player player)
        {
            //attack the Player
            if (enemy.canAttack)
            {
                int prevdef = player.def, prevatk = player.atk, prevspd = player.spd, previntl = player.intl;
                int eprevdef = enemy.def, eprevatk = enemy.atk, eprevspd = enemy.spd, eprevintl = enemy.intl;
                if (!Dice.misschance(Program.main.player.spd))
                {
                    string used   = "";
                    int    damage = player.canBeHit ? enemy.Attack(player, out used) : 0;
                    if (player.pRace is Dwarf)
                    {
                        if (player.hp <= player.hp / 5)
                        {
                            damage /= 2;
                            write(player.name + "'s ", "Black");
                            write("Reinforced Armor ", "Aqua", true);
                            write("has halved the incoming damage!", "Black", true);
                        }
                        else
                        {
                            damage -= Convert.ToInt32(damage * 0.15);
                        }
                    }
                    //if damage is less than one, it's one
                    damage = Math.Max(1, damage);
                    switch (used)
                    {
                    case "Attack":
                        write(enemy.name + " attacked the player!", "Red");
                        break;

                    case "Crazed Slashes":
                        break;

                    default:
                        write(enemy.name + " used " + used + "!", "Red");
                        break;
                    }
                    if (player.def < prevdef)
                    {
                        write(player.name + "'s defense fell!", "Red");
                    }
                    if (player.atk < prevatk)
                    {
                        write(player.name + "'s attack fell!", "Red");
                    }
                    if (player.spd < prevspd)
                    {
                        write(player.name + "'s speed fell!", "Red");
                    }
                    if (player.intl < previntl)
                    {
                        write(player.name + "'s intelligence fell!", "Red");
                    }
                    if (enemy.def < eprevdef)
                    {
                        write(enemy.name + "'s defense fell!", "Red");
                    }
                    if (enemy.atk < eprevatk)
                    {
                        write(enemy.name + "'s attack fell!", "Red");
                    }
                    if (enemy.spd < eprevspd)
                    {
                        write(enemy.name + "'s speed fell!", "Red");
                    }
                    if (enemy.intl < eprevintl)
                    {
                        write(enemy.name + "'s intelligence fell!", "Red");
                    }
                    write(player.name + " took " + damage + " damage.", "Red");
                    player.hp -= damage;
                }
                else
                {
                    write(enemy.name + " missed!", "Gray");
                }
            }
        }