// Get a random character. public Character GetRandomCharacter(int ScaleLevelMin, int ScaleLevelMax) { var myCharacterViewModel = CharactersViewModel.Instance; var rnd = HelperEngine.RollDice(1, myCharacterViewModel.Dataset.Count); var myData = new Character(myCharacterViewModel.Dataset[rnd - 1]); // Help identify which Character it is... myData.Name += " " + (1 + CharacterList.Count).ToString(); var rndScale = HelperEngine.RollDice(ScaleLevelMin, ScaleLevelMax); myData.ScaleLevel(rndScale); // Add Items to Character myData.Head = ItemsViewModel.Instance.ChooseRandomItemString(ItemLocationEnum.Head, AttributeEnum.Unknown); myData.Necklass = ItemsViewModel.Instance.ChooseRandomItemString(ItemLocationEnum.Necklass, AttributeEnum.Unknown); myData.PrimaryHand = ItemsViewModel.Instance.ChooseRandomItemString(ItemLocationEnum.PrimaryHand, AttributeEnum.Unknown); myData.OffHand = ItemsViewModel.Instance.ChooseRandomItemString(ItemLocationEnum.OffHand, AttributeEnum.Unknown); myData.RightFinger = ItemsViewModel.Instance.ChooseRandomItemString(ItemLocationEnum.RightFinger, AttributeEnum.Unknown); myData.LeftFinger = ItemsViewModel.Instance.ChooseRandomItemString(ItemLocationEnum.LeftFinger, AttributeEnum.Unknown); myData.Feet = ItemsViewModel.Instance.ChooseRandomItemString(ItemLocationEnum.Feet, AttributeEnum.Unknown); return(myData); }
// Add Monsters // Scale them to meet Character Strength... public void AddMonstersToRound() { // Check to see if the monster list is full, if so, no need to add more... if (MonsterList.Count() >= GameGlobals.MaxNumberPartyPlayers) { return; } // Make Sure Monster List exists and is loaded... var myMonsterViewModel = MonstersViewModel.Instance; if (myMonsterViewModel.Dataset.Count() > 0) { // Scale monsters to be within the range of the Characters var ScaleLevelMax = 1; var ScaleLevelMin = 1; var ScaleLevelAverage = 1; if (CharacterList.Any()) { ScaleLevelMax = GetMaxCharacterLevel(); ScaleLevelMin = GetMinCharacterLevel(); ScaleLevelAverage = GetAverageCharacterLevel(); } // Get 1 monsters do { //Force Random Roll here. Important for the debug override setting. //Game will not work without a random value here var rnd = HelperEngine.RollDice(1, myMonsterViewModel.Dataset.Count, true); { var monster = new Monster(myMonsterViewModel.Dataset[rnd - 1]); // Help identify which monster it is... monster.Name += " " + (1 + MonsterList.Count()).ToString(); // Scale the monster to be between the average level of the characters+1 var rndScale = HelperEngine.RollDice(1, ScaleLevelAverage + 1); monster.ScaleLevel(rndScale); MonsterList.Add(monster); } } while (MonsterList.Count() < 1); } else { // No monsters in DB, so add 1 new ones... for (var i = 0; i < 1; i++) { var item = new Monster(); // Help identify which monster it is... item.Name += " " + MonsterList.Count() + 1; MonsterList.Add(item); } } }
// Add Monsters // Scale them to meet Character Strength... public void AddMonstersToRound() { // Check to see if the monster list is full, if so, no need to add more... if (MonsterList.Count() >= 6) { return; } // TODO, determine the character strength // add monsters up to that strength... var ScaleLevelMax = 2; var ScaleLevelMin = 1; // Make Sure Monster List exists and is loaded... var myMonsterViewModel = MonstersViewModel.Instance; myMonsterViewModel.ForceDataRefresh(); if (myMonsterViewModel.Dataset.Count() > 0) { // Get 6 monsters do { var rnd = HelperEngine.RollDice(1, myMonsterViewModel.Dataset.Count); { var item = new Monster(myMonsterViewModel.Dataset[rnd - 1]); // Help identify which monster it is... item.Name += " " + (1 + MonsterList.Count()).ToString(); var rndScale = HelperEngine.RollDice(ScaleLevelMin, ScaleLevelMax); item.ScaleLevel(rndScale); MonsterList.Add(item); } } while (MonsterList.Count() < 6); } else { // No monsters in DB, so add 6 new ones... for (var i = 0; i < 6; i++) { var item = new Monster(); // Help identify which monster it is... item.Name += " " + MonsterList.Count() + 1; MonsterList.Add(item); } } }
//For unit testing public HitStatusEnum RollToHitTarget(int AttackScore, int DefenseScore) { var d20 = HelperEngine.RollDice(1, 20); // Turn On UnitTestingSetRoll if (GameGlobals.ForceRollsToNotRandom) { // Don't let it be 0, if it was not initialized... if (GameGlobals.ForceToHitValue < 1) { GameGlobals.ForceToHitValue = 1; } d20 = GameGlobals.ForceToHitValue; } if (d20 == 1) { // Force Miss BattleMessages.HitStatus = HitStatusEnum.CriticalMiss; return(BattleMessages.HitStatus); } if (d20 == 20) { // Force Hit BattleMessages.HitStatus = HitStatusEnum.CriticalHit; return(BattleMessages.HitStatus); } var ToHitScore = d20 + AttackScore; if (ToHitScore < DefenseScore) { BattleMessages.AttackStatus = " misses "; // Miss BattleMessages.HitStatus = HitStatusEnum.Miss; BattleMessages.DamageAmount = 0; } else { // Hit BattleMessages.HitStatus = HitStatusEnum.Hit; } return(BattleMessages.HitStatus); }
// Will drop between 1 and 4 items from the item set... public List <Item> GetRandomMonsterItemDrops(int round) { var myList = new List <Item>(); if (!GameGlobals.AllowMonsterDropItems) { return(myList); } var myItemsViewModel = ItemsViewModel.Instance; if (myItemsViewModel.Dataset.Count > 0) { // Random is enabled so build up a list of items dropped... var ItemCount = HelperEngine.RollDice(1, 4); for (var i = 0; i < ItemCount; i++) { var rnd = HelperEngine.RollDice(1, myItemsViewModel.Dataset.Count); var itemBase = myItemsViewModel.Dataset[rnd - 1]; var item = new Item(itemBase); item.ScaleLevel(round); // Make sure the item is added to the global list... var myItem = ItemsViewModel.Instance.CheckIfItemExists(item); if (myItem == null) { // Item does not exist, so add it to the datstore // TODO: Need way to not save the Item ItemsViewModel.Instance.InsertUpdateAsync(item).GetAwaiter().GetResult(); } else { // Swap them becaues it already exists, no need to create a new one... item = myItem; } // Add the item to the local list... myList.Add(item); } } return(myList); }
public HitStatusEnum RollToHitTarget(int AttackScore, int DefenseScore, Monster Attacker, Character Target) { var d20 = HelperEngine.RollDice(1, 20); // Turn On UnitTestingSetRoll if (GameGlobals.ForceRollsToNotRandom) { // Don't let it be 0, if it was not initialized... if (GameGlobals.ForceToHitValue < 1) { GameGlobals.ForceToHitValue = 1; } // result of the dice roll between 1 to 20 d20 = GameGlobals.ForceToHitValue; } //critical miss then force a miss if 1 or 2 is rolled if (d20 == 1 || d20 == 2) { //If Critical Miss Roll for item drop if (d20 == 1) { //Roll a dice roll of 10, then follow Hackathon request #4 to complete the below var d10 = HelperEngine.RollDice(1, 10); // Turn On UnitTestingSetRoll if (GameGlobals.ForceRollsToNotRandom) { // Don't let it be 0, if it was not initialized... if (GameGlobals.ForceToHitValue < 1) { GameGlobals.ForceToHitValue = 1; } // result of the dice roll between 1 to 10 d10 = GameGlobals.ForceToHitValue; } //critical miss then force a miss if 1 or 2 is rolled if (d10 == 1) { // Force an item drop var myItemList = Target.DropAllItems(); // Add to Score foreach (var item in myItemList) { BattleScore.ItemsDroppedList += item.FormatOutput() + "\n"; BattleMessages.TurnMessageSpecial += " Item " + item.Name + "dropped forever"; } Debug.WriteLine("#########################"); Debug.WriteLine("Tough Luck, the item was dropped forever!!!"); } if (d10 > 1 && d10 < 5) { // Force an item drop // Drop Items to item Pool var myItemList = Target.DropAllItems(); // Add to Score foreach (var item in myItemList) { BattleScore.ItemsDroppedList += item.FormatOutput() + "\n"; BattleMessages.TurnMessageSpecial += " Item " + item.Name + "dropped to item pool"; } Debug.WriteLine("#########################"); Debug.WriteLine("Tough Luck, the item was dropped into the pool!!!"); } if (d10 > 4 && d10 < 7) { // Force an item drop // 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"; BattleMessages.TurnMessageSpecial += " Item " + item.Name + "Random Item dropped in pool"; } Debug.WriteLine("#########################"); Debug.WriteLine("Tough Luck, a Random item was dropped in pool!!!"); } if (d10 > 6) { Debug.WriteLine("#########################"); Debug.WriteLine("GREAT LUCK Buddy, YOU Got Away this time!!!"); } } // Force Miss BattleMessages.HitStatus = HitStatusEnum.CriticalMiss; return(BattleMessages.HitStatus); } //critical hit if 20 then force a hit if (d20 == 20) { // Force Hit BattleMessages.HitStatus = HitStatusEnum.CriticalHit; return(BattleMessages.HitStatus); } //total hitscore is based on attack and the dice. var ToHitScore = d20 + AttackScore; // if the attack with the dice roll is less than defence score then its a miss if (ToHitScore < DefenseScore) { BattleMessages.AttackStatus = " misses "; // Miss BattleMessages.HitStatus = HitStatusEnum.Miss; BattleMessages.DamageAmount = 0; } else // if attack and dice is more than defence then its a hit { // Hit BattleMessages.HitStatus = HitStatusEnum.Hit; } return(BattleMessages.HitStatus); }
// Character attacks Monster public bool TurnAsAttack(Character Attacker, int AttackScore, Monster Target, int DefenseScore) { BattleMessages.TurnMessage = string.Empty; BattleMessages.TurnMessageSpecial = string.Empty; BattleMessages.AttackStatus = string.Empty; BattleMessages.LevelUpMessage = string.Empty; if (Attacker == null) { return(false); } if (Target == null) { return(false); } BattleScore.TurnCount++; //Names for attacker and target BattleMessages.TargetName = Target.Name; BattleMessages.AttackerName = Attacker.Name; // Determine whether hit or miss based on character attack total and monster defense total var HitSuccess = RollToHitTarget(AttackScore, DefenseScore, Target, Attacker); Debug.WriteLine("#############"); //miss based on attack and roll being less than defence if (BattleMessages.HitStatus == HitStatusEnum.Miss) { BattleMessages.TurnMessage = Attacker.Name + " misses " + Target.Name; Debug.WriteLine(BattleMessages.TurnMessage); if (GameGlobals.Mulligan) { var d4 = HelperEngine.RollDice(1, 4); // only happens sometimes if (d4 == 2 || d4 == 3) { //doing 50% damage for mulligan BattleMessages.DamageAmount = Attacker.GetDamageRollValue() / 2; Debug.WriteLine("#### Mulligan Alert #####"); Debug.WriteLine("Mulligan was applied"); BattleMessages.AttackStatus = string.Format(" hits for {0} damage on using Mulligan ", BattleMessages.DamageAmount); } } return(true); } // force a miss if you roll a 1 or 2 no matter what the attack is if (BattleMessages.HitStatus == HitStatusEnum.CriticalMiss) { Debug.WriteLine("#########################"); Debug.WriteLine("Unfortunately Character rolled 1 or 2 so you critically MISSED!!!"); BattleMessages.TurnMessage = Attacker.Name + " rolls 1 or 2 and the character critically misses " + Target.Name; Debug.WriteLine(BattleMessages.TurnMessage); return(true); } // It's a Hit if your attack and roll is greater than the defence 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); // double the damage if critical hit and character rolls 20 or 19 if (GameGlobals.EnableCriticalHitDamage) { if (BattleMessages.HitStatus == HitStatusEnum.CriticalHit) { Debug.WriteLine("#########################"); Debug.WriteLine("Amazing Roll, Character rolled 20 so CRITICALLY HIT!!!"); //2x damage BattleMessages.DamageAmount += BattleMessages.DamageAmount; BattleMessages.AttackStatus = string.Format(" hits CRITICALLY hard for {0} damage on ", BattleMessages.DamageAmount); } } //the monster takes the damage Target.TakeDamage(BattleMessages.DamageAmount); // calculate experience earned var experienceEarned = Target.CalculateExperienceEarned(BattleMessages.DamageAmount); // check whether enough xp is given to level up var LevelUp = Attacker.AddExperience(experienceEarned); if (LevelUp) { BattleMessages.LevelUpMessage = Attacker.Name + " is now Level " + Attacker.Level + " With Health Max of " + Attacker.GetHealthMax(); Debug.WriteLine(BattleMessages.LevelUpMessage); } BattleScore.ExperienceGainedTotal += experienceEarned; } //display health of Monster if still alive if (Target.Attribute.CurrentHealth > 0) { BattleMessages.TurnMessageSpecial = " remaining health is " + Target.Attribute.CurrentHealth; } // Check for alive if (Target.Alive == false) { // Remover target from list... MonsterList.Remove(Target); // Mark Status in output BattleMessages.TurnMessageSpecial = " and causes death"; // Add one to the monsters killd count... BattleScore.MonsterSlainNumber++; // Add the monster to the killed list BattleScore.MonstersKilledList += Target.FormatOutput() + "\n"; // 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"; BattleMessages.TurnMessageSpecial += " Item " + item.Name + " dropped"; } ItemPool.AddRange(myItemList); //Implementation of Enhanced Feature Reincarnation if (GameGlobals.SleeplessZombies) { var d20 = HelperEngine.RollDice(1, 4); // only happens sometimes based on dice for a randomized chance of reincarnation if (d20 == 2 || d20 == 3) { Target.Alive = true; // health is set to half int health = Target.GetHealthMax() / 2; Target.Attribute.setCurrentHealth(health); string newname = "REINCARNATED<MONSTER>"; Target.setName(newname); // add reincarnated monster back to the monster list for this round MonsterList.Add(Target); Debug.WriteLine("REINCARNATED ZOMBIES MONSTER BACK FROM THE DEAD!!!!!! "); Debug.WriteLine(Target.Name); BattleMessages.TurnMessage = Attacker.Name + BattleMessages.AttackStatus + Target.Name + BattleMessages.TurnMessageSpecial; Debug.WriteLine(BattleMessages.TurnMessage); return(true); } else { // had a chance for reincarnation, but reincarnation did not happen BattleMessages.TurnMessage = Attacker.Name + BattleMessages.AttackStatus + Target.Name + BattleMessages.TurnMessageSpecial; Debug.WriteLine(BattleMessages.TurnMessage); Debug.WriteLine("sleepless zombies random chance missed"); return(true); } } else { BattleMessages.TurnMessage = Attacker.Name + BattleMessages.AttackStatus + Target.Name + BattleMessages.TurnMessageSpecial; Debug.WriteLine(BattleMessages.TurnMessage); return(true); } } BattleMessages.TurnMessage = Attacker.Name + BattleMessages.AttackStatus + Target.Name + BattleMessages.TurnMessageSpecial; Debug.WriteLine(BattleMessages.TurnMessage); return(true); }
// Add Monsters // Scale them to meet Character Strength... public void AddMonstersToRound() { // Check to see if the monster list is full, if so, no need to add more... if (MonsterList.Count() >= 6) { return; } // init monster scaling var ScaleLevelMax = 6; var ScaleLevelMin = 6; // scale based on game harder which is enabled by default if (GameGlobals.EnableGameHarder) { // Scale monsters based on round count.. higher round higher and stronger monsters if (BattleScore.RoundCount <= 1) { ScaleLevelMax = 1; ScaleLevelMin = 1; } if (BattleScore.RoundCount > 0 && BattleScore.RoundCount <= 2) { ScaleLevelMax = 2; ScaleLevelMin = 2; } if (BattleScore.RoundCount > 2 && BattleScore.RoundCount <= 4) { ScaleLevelMax = 4; ScaleLevelMin = 4; } if (BattleScore.RoundCount > 4 && BattleScore.RoundCount <= 8) { ScaleLevelMax = 8; ScaleLevelMin = 8; } if (BattleScore.RoundCount > 8 && BattleScore.RoundCount <= 16) { ScaleLevelMax = 16; ScaleLevelMin = 16; } if (BattleScore.RoundCount > 50) { ScaleLevelMax = 20; ScaleLevelMin = 20; } } else { ScaleLevelMax = 6; ScaleLevelMin = 6; } // Make Sure Monster List exists and is loaded... var myMonsterViewModel = MonstersViewModel.Instance; //myMonsterViewModel.ForceDataRefresh(); if (myMonsterViewModel.Dataset.Count() > 0) { // Get 6 monsters based on the scaling that was set earlier and assign unique items to monster do { var RndMon = HelperEngine.RollDice(1, myMonsterViewModel.Dataset.Count); { var mons = new Monster(myMonsterViewModel.Dataset[RndMon - 1]); // Help identify which monster it is... mons.Name += " " + (1 + MonsterList.Count()).ToString(); var rndScale = HelperEngine.RollDice(ScaleLevelMin, ScaleLevelMax); mons.ScaleLevel(rndScale); MonsterList.Add(mons); } } while (MonsterList.Count() < 6); } else { // No monsters in DB, so add 6 new ones... for (var i = 0; i < 6; i++) { var mon = new Monster(); // Help identify which monster it is... mon.Name += " " + MonsterList.Count() + 1; MonsterList.Add(mon); } } }
// Determin Critiical Miss. public string DetermineCriticalMissProblem(Character attacker) { if (attacker == null) { return(" Invalid Character "); } var myReturn = " Nothing Bad Happened "; Item droppedItem; // It may be a critical miss, roll again and find out... var rnd = HelperEngine.RollDice(1, 10); /* * 1. Primary Hand Item breaks, and is lost forever * 2-4, Character Drops the Primary Hand Item back into the item pool * 5-6, Character drops a random equipped item back into the item pool * 7-10, Nothing bad happens, luck was with the attacker */ switch (rnd) { case 1: myReturn = " Luckly, nothing to drop from " + ItemLocationEnum.PrimaryHand; var myItem = ItemsViewModel.Instance.GetItem(attacker.PrimaryHand); if (myItem != null) { myReturn = " Item " + myItem.Name + " from " + ItemLocationEnum.PrimaryHand + " Broke, and lost forever"; } attacker.PrimaryHand = null; break; case 2: case 3: case 4: // Put on the new item, which drops the one back to the pool myReturn = " Luckly, nothing to drop from " + ItemLocationEnum.PrimaryHand; droppedItem = attacker.AddItem(ItemLocationEnum.PrimaryHand, null); if (droppedItem != null) { // Add the dropped item to the pool ItemPool.Add(droppedItem); myReturn = " Dropped " + droppedItem.Name + " from " + ItemLocationEnum.PrimaryHand; } break; case 5: case 6: var LocationRnd = HelperEngine.RollDice(1, ItemLocationList.GetListCharacter.Count); var myLocationEnum = ItemLocationList.GetLocationByPosition(LocationRnd); myReturn = " Luckly, nothing to drop from " + myLocationEnum; // Put on the new item, which drops the one back to the pool droppedItem = attacker.AddItem(myLocationEnum, null); if (droppedItem != null) { // Add the dropped item to the pool ItemPool.Add(droppedItem); myReturn = " Dropped " + droppedItem.Name + " from " + myLocationEnum; } break; } return(myReturn); }
// Roll for attack. public HitStatusEnum RollToHitTarget(int AttackScore, int DefenseScore) { var d20 = HelperEngine.RollDice(1, 20); // Turn On UnitTestingSetRoll if (GameGlobals.ForceRollsToNotRandom) { // Don't let it be 0, if it was not initialized... if (GameGlobals.ForceToHitValue < 1) { GameGlobals.ForceToHitValue = 1; } d20 = GameGlobals.ForceToHitValue; } if (GameGlobals.ForcingHitValue == true) { d20 = GameGlobals.ForcedHitValue; } Debug.WriteLine("Roll: " + d20); if (d20 == 1) { //Critical Miss, if enabled if (GameGlobals.EnableCriticalMissProblems) { HitStatus = HitStatusEnum.CriticalMiss; } else { HitStatus = HitStatusEnum.Miss; } BattleMessages.HitStatus = HitStatus; return(HitStatus); } if (d20 == 20) { // Force Hit HitStatus = HitStatusEnum.CriticalHit; BattleMessages.HitStatus = HitStatus; return(HitStatus); } var ToHitScore = d20 + AttackScore; if (ToHitScore < DefenseScore) { AttackStatus = " misses "; BattleMessages.AttackStatus = AttackStatus; // Miss HitStatus = HitStatusEnum.Miss; BattleMessages.HitStatus = HitStatus; DamageAmount = 0; BattleMessages.DamageAmount = DamageAmount; } else { // Hit HitStatus = HitStatusEnum.Hit; BattleMessages.HitStatus = HitStatus; } return(HitStatus); }