// Monster Attacks Character // this is working fine in terms of choosing next turn public bool TurnAsAttack(Monster Attacker, int AttackScore, Character Target, int DefenseScore) { BattleMessages.TurnMessage = string.Empty; BattleMessages.TurnMessageSpecial = string.Empty; BattleMessages.AttackStatus = string.Empty; //BattleMessages.AttackDescription = string.Empty; BattleMessages.PlayerType = PlayerTypeEnum.Monster; if (Attacker == null) { return(false); } if (Target == null) { return(false); } BattleScore.TurnCount++; // Choose who to attack // Name of attacker and target BattleMessages.TargetName = Target.Name; BattleMessages.AttackerName = Attacker.Name; var HitSuccess = RollToHitTarget(AttackScore, DefenseScore); Debug.WriteLine(BattleMessages.GetTurnMessage()); if (BattleMessages.HitStatus == HitStatusEnum.Miss) { BattleMessages.TurnMessage = " " + Attacker.Name + " misses " + Target.Name; Debug.WriteLine(BattleMessages.TurnMessage); return(true); } if (BattleMessages.HitStatus == HitStatusEnum.CriticalMiss) { Debug.WriteLine("-----------------------"); Debug.WriteLine("Monster critically missed!"); BattleMessages.TurnMessage = Attacker.Name + " critically misses " + Target.Name; Debug.WriteLine(BattleMessages.TurnMessage); return(true); } // It's a Hit or a Critical Hit if (BattleMessages.HitStatus == HitStatusEnum.Hit || BattleMessages.HitStatus == HitStatusEnum.CriticalHit) { //Calculate Damage BattleMessages.DamageAmount = Attacker.GetDamageRollValue(); BattleMessages.DamageAmount += GameGlobals.ForceCharacterDamangeBonusValue; // Add the Forced Damage Bonus (used for testing...) BattleMessages.AttackStatus = string.Format(" hits for {0} damage on ", BattleMessages.DamageAmount); if (GameGlobals.EnableCriticalHitDamage) { if (BattleMessages.HitStatus == HitStatusEnum.CriticalHit) { //2x damage BattleMessages.DamageAmount += BattleMessages.DamageAmount; Debug.WriteLine("-----------------------"); Debug.WriteLine("Monster critically hit!"); BattleMessages.AttackStatus = string.Format(" hits critically hard for {0} damage on ", BattleMessages.DamageAmount); } } // Target take the damage Target.TakeDamage(BattleMessages.DamageAmount); } BattleMessages.CurrentHealth = Target.CharacterAttribute.CurrentHealth; BattleMessages.TurnMessageSpecial = BattleMessages.GetCurrentHealthMessage(); // Calculate experience earned // Check for alive if (Target.Alive == false) { // Remover target from list... CharacterList.Remove(Target); // Mark Status in output BattleMessages.TurnMessageSpecial = " and causes death"; // Add the monster to the killed list BattleScore.CharacterAtDeathList += Target.FormatOutput() + "\n"; // Drop Items to item Pool var myItemList = Target.DropAllItems(); // Add to Score foreach (var item in myItemList) { BattleScore.ItemsDroppedList += item.FormatOutput() + "\n"; BattleMessages.TurnMessageSpecial += "; \n Item " + item.Name + " dropped"; } ItemPool.AddRange(myItemList); } BattleMessages.TurnMessage = Attacker.Name + BattleMessages.AttackStatus + Target.Name + BattleMessages.TurnMessageSpecial; Debug.WriteLine(BattleMessages.TurnMessage); return(true); }
/// <summary> /// Process the attack. Use BattleMessagesModel to communicate actions. /// </summary> /// <param name="attacker"></param> /// <param name="target"></param> /// <returns></returns> public bool TurnAsAttack(BattleEntityModel attacker, BattleEntityModel target) { if (attacker == null) { return(false); } if (target == null) { return(false); } // refresh battle messages for turn BattleMessages.ClearMessages(); // Hackathon // Hackathon Scenario 2, Bob alwasys misses if (attacker.Name.Equals("Bob")) { BattleMessages.HitStatus = HitStatusEnum.Miss; BattleMessages.TurnMessage = "Bob always Misses"; Debug.WriteLine(BattleMessages.TurnMessage); return(true); } BattleMessages.PlayerType = EntityTypeEnum.Monster; var AttackScore = GetAttack(attacker); var DefenseScore = GetDefense(target); // Choose who to attack BattleMessages.TargetName = target.Name; BattleMessages.AttackerName = attacker.Name; BattleMessages.HitStatus = RollToHitTarget(AttackScore, DefenseScore); Debug.WriteLine(BattleMessages.GetTurnMessage()); // It's a Miss if (BattleMessages.HitStatus == HitStatusEnum.Miss) { BattleMessages.TurnMessage = attacker.Name + " blunders and misses " + target.Name; // Check if Critical Miss is enabled (hackathon rule) if (CriticalMissEnabled) { if (BattleMessages.CriticalMiss) { CriticalMiss(attacker); BattleMessages.TurnMessage += BattleMessages.CriticalMissMessage; // toggle flag BattleMessages.CriticalMiss = false; } } Debug.WriteLine(BattleMessages.TurnMessage); return(true); } // It's a Hit if (BattleMessages.HitStatus == HitStatusEnum.Hit) { //Calculate Damage BattleMessages.DamageAmount = GetDamage(attacker); // Calculate Critical Hit if enabled if (CriticalHitsEnabled) { if (BattleMessages.CriticalHit) { BattleMessages.DamageAmount *= 2; } } if (target.EntityType == EntityTypeEnum.Monster) { double FractionalExperience = (double)BattleMessages.DamageAmount / (double)target.MaxHealth; int ExperienceGained = (int)Math.Ceiling(FractionalExperience * (double)target.ExperiencePoints); TakeDamage(target, BattleMessages.DamageAmount); // If monster takes damage he loses proportional amount of remaining experience points to attacker AddExperience(attacker, ExperienceGained); target.ExperiencePoints -= ExperienceGained; } else { TakeDamage(target, BattleMessages.DamageAmount); } } // update battle messages BattleMessages.CurrentHealth = target.CurrentHealth; BattleMessages.AttackStatus = " strikes "; BattleMessages.TurnMessage = attacker.Name + BattleMessages.AttackStatus + target.Name + BattleMessages.GetCurrentHealthMessage(); if (CriticalHitsEnabled) { if (BattleMessages.CriticalHit) { BattleMessages.TurnMessage += "\nCritical Hit!!!"; BattleMessages.CriticalHit = false; // toggle flag } } Debug.WriteLine(BattleMessages.TurnMessage); RemoveIfDead(target); return(true); }