Ejemplo n.º 1
0
        // Character attacks Monster
        public bool TurnAsAttack(Character Attacker, int AttackScore, Monster Target, int DefenseScore)
        {
            // Reset the battle messages
            BattleMessage.ResetBattleMessages();

            // Show what items there are in the characters bag to the output window
            Debug.WriteLine("Item: " + Attacker.GetItemByLocation(ItemLocationEnum.Bag));

            // If attacker is null, don't attack
            if (Attacker == null)
            {
                return(false);
            }

            // If the target is null, don't attack
            if (Target == null)
            {
                return(false);
            }

            // Increment the turncount
            BattleScore.TurnCount++;

            // Set the target name
            BattleMessage.TargetName = Target.Name;

            // Set the attacker name
            BattleMessage.AttackerName = Attacker.Name;

            // Get hit status
            var HitSuccess = RollToHitTarget(AttackScore, DefenseScore);

            // missed bool is used for mulligan
            bool missed = false;

            // Logic for a miss
            if (BattleMessage.HitStatus == HitStatusEnum.Miss)
            {
                // If mulligan is enabled, character can retry their attack
                if (GameGlobals.EnableMulligan)
                {
                    // Miss message
                    BattleMessage.TurnMessage += BattleMessage.AttackerName + " misses " + BattleMessage.TargetName + "\n";

                    // Chance for mulligan
                    var chance = 20 - ((GameGlobals.MulliganChance / 100) * 20);

                    // Determine the roll value
                    var roll = HelperEngine.RollDice(1, 20);

                    // If roll is greater than or equal to chance, set hit status to hit
                    if (roll >= chance)
                    {
                        missed = true;
                        BattleMessage.HitStatus = HitStatusEnum.Hit;
                        Debug.WriteLine("However, there is a Mulligan");
                    }
                }
                // Otherwise they miss as normal
                else
                {
                    // Miss message
                    BattleMessage.TurnMessage += BattleMessage.AttackerName + " misses " + BattleMessage.TargetName;
                    Debug.WriteLine(BattleMessage.TurnMessage);

                    return(true);
                }
            }

            // Logic for a critical miss
            if (BattleMessage.HitStatus == HitStatusEnum.CriticalMiss)
            {
                // If mulligan is enabled, character can retry their attack
                if (GameGlobals.EnableMulligan)
                {
                    // Miss message
                    BattleMessage.TurnMessage += BattleMessage.AttackerName + " misses " + BattleMessage.TargetName + "\n";

                    // Chance for mulligan
                    var chance = 20 - ((GameGlobals.MulliganChance / 100) * 20);

                    // Determine the rell
                    var roll = HelperEngine.RollDice(1, 20);

                    // Determine if mulligan occurs
                    if (roll >= chance)
                    {
                        missed = true;
                        BattleMessage.HitStatus = HitStatusEnum.Hit;
                        Debug.WriteLine("However, there is a Mulligan");
                    }
                }
                // Otherwise they miss as normal
                else
                {
                    // Critical miss message
                    BattleMessage.TurnMessage += "CRITICAL MISS-- " + Attacker.Name + " swings and critically misses " +
                                                 Target.Name;
                    Debug.WriteLine(BattleMessage.TurnMessage);

                    // Critical miss problems
                    if (GameGlobals.EnableCriticalMissProblems)
                    {
                        BattleMessage.TurnMessage += DetermineCriticalMissProblem(Attacker);
                    }

                    return(true);
                }
            }

            // Logic for a hit or critical hit
            if (BattleMessage.HitStatus == HitStatusEnum.Hit || BattleMessage.HitStatus == HitStatusEnum.CriticalHit)
            {
                //Calculate Damage
                BattleMessage.DamageAmount = Attacker.GetDamageRollValue();

                // If mulligan occurred
                if (missed)
                {
                    Debug.WriteLine("Mulligan occured ");
                    BattleMessage.TurnMessageSpecial += "Mulligan occured.\n";
                    BattleMessage.DamageAmount       /= 2;
                    BattleMessage.DamageAmount       += 1;
                    missed = false;
                }

                // Add forced damange
                BattleMessage.DamageAmount += GameGlobals.ForceCharacterDamangeBonusValue;   // Add the Forced Damage Bonus (used for testing...)

                // Normal hit message
                if (BattleMessage.HitStatus == HitStatusEnum.Hit)
                {
                    BattleMessage.AttackStatus = string.Format(Attacker.Name + " hits for {0} damage on " + Target.Name + ". ", BattleMessage.DamageAmount);
                }

                // Check if critical hits are enabled
                if (GameGlobals.EnableCriticalHitDamage)
                {
                    // Its a critical hit!
                    if (BattleMessage.HitStatus == HitStatusEnum.CriticalHit)
                    {
                        //2x damage
                        BattleMessage.DamageAmount += BattleMessage.DamageAmount;
                        BattleMessage.AttackStatus  = string.Format("CRITICAL HIT -- " + Attacker.Name + " hits really hard for {0} damage on " + Target.Name, BattleMessage.DamageAmount) + ".\n";
                    }
                }

                // Give the damage to the target
                Target.TakeDamage(BattleMessage.DamageAmount);

                // See if a rebound occurs after dealing damage to monster
                if (GameGlobals.EnableRebound)
                {
                    if (ReboundDamage())
                    {
                        // Calculate rebound damage
                        var rebDmg = HelperEngine.RollDice(1, (BattleMessage.DamageAmount / 2));

                        // Apply damange
                        if (Attacker.GetHealthCurrent() <= rebDmg)
                        {
                            // If rebound damage would cause death, set it so that character only has one HP left.
                            rebDmg = Attacker.GetHealthCurrent() - 1;
                            Attacker.TakeDamage(rebDmg);
                            BattleMessage.TurnMessageSpecial = string.Format(Attacker.Name + " gets hit by rebound for {0}.", rebDmg);
                        }
                        else
                        {
                            // Otherwise, apply damage
                            Attacker.TakeDamage(rebDmg);
                            BattleMessage.TurnMessageSpecial = string.Format(Attacker.Name + " gets hit by rebound for {0}.", rebDmg);
                        }
                    }
                }

                // Calculate the amount of experience
                var experienceEarned = Target.CalculateExperienceEarned(BattleMessage.DamageAmount);

                // Check if level up occurs
                var LevelUp = Attacker.AddExperience(experienceEarned);

                // If level up occured
                if (LevelUp)
                {
                    // Level up message
                    BattleMessage.LevelUpMessage = BattleMessage.AttackerName + " levels up to " + Attacker.Level + " with max health of " + Attacker.GetHealthMax();
                    Debug.WriteLine(BattleMessage.LevelUpMessage);
                }

                // Add expereience to total experience
                BattleScore.ExperienceGainedTotal += experienceEarned;
            }

            // Message for remaining health
            BattleMessage.TurnMessageSpecial += Target.Name + " has remaining health of " + Target.Attribute.CurrentHealth;

            // Check for alive
            if (Target.Alive == false)
            {
                // Check if zombies setting is on
                if (GameGlobals.EnableZombies && !Target.HasBeenZombie)
                {
                    var chance = 20 - ((GameGlobals.ZombieChance / 100) * 20);
                    var roll   = HelperEngine.RollDice(1, 20);

                    // and roll to turn monster to zombie
                    if (roll >= chance)
                    {
                        BattleMessage.TurnMessageSpecial += "\n" + Target.Name + " dies but returns as a zombie. ";
                        Target.isZombie("Zombie " + Target.Name);
                        Target.Alive = true;
                    }
                }
                // Otherwise, remove monster and items
                else
                {
                    // Remove target from list...
                    MonsterList.Remove(Target);

                    // Mark Status in output
                    BattleMessage.TurnMessageSpecial += " and dies.\n";

                    // Add one to the monsters killd count...
                    BattleScore.MonsterSlainNumber++;

                    // Add the monster to the killed list
                    BattleScore.AddMonsterToKillList(Target);

                    // Drop Items to item Pool
                    var myItemList = Target.DropAllItems();

                    // If Random drops are enabled, then add some....
                    myItemList.AddRange(GetRandomMonsterItemDrops(BattleScore.RoundCount));

                    // Add to Score
                    foreach (var item in myItemList)
                    {
                        BattleScore.ItemsDroppedList     += item.FormatOutput() + "\n\n";
                        BattleMessage.TurnMessageSpecial += " Item " + item.Name + " dropped\n";
                    }

                    // Add items to item pool
                    ItemPool.AddRange(myItemList);
                }
            }

            // Debug output
            Debug.WriteLine(BattleMessage.TurnMessage + "\n");

            return(true);
        }