public void buildMagicGrid()
 {
     foreach (ItemModel item in CharacterObj1.inventory)
     {
         if (item.name.Contains("Tomb") && !magicList.ContainsKey(item.name))
         {
             MagicToggle(true);
             MagicModel magic = new MagicModel(item.itemID, item.name, item.type, item.upgradeAttribute, item.upgradeValue);
             //MagicModel magic = new MagicModel();
             //               magic.Itemid = item.itemID;
             //magic.AttribMod = item.upgradeAttribute;
             //magic.AttribValues = item.upgradeValue;
             //magic.Name = item.name;
             //magic.Type = item.type;
             magicList.Add(item.name, magic);
         }
     }
 }
Example #2
0
		public void ProcessBattle()
		{
            if (battleEventLoaded == false)
                return;
			// Have some interval
			battleCount++;
			if (battleCount < 10)
				return;

			GameModel gm = GameModel.Instance;

			// No targets
			if (offense == null)
			{
				// EndCheck
				if (gm.battleModel.party.Count == 0)
				{
					inBattle = false;
					DependencyService.Get<i_audio>().PlayAudioFile("lose.mp3");
					EndBattlePage(false);
					gm.AddCharToParty();
					gm.AddCharToParty(); // Add by 2
					return;
				}
				if (gm.battleModel.monsters.Count == 0)
				{
					inBattle = false;
					DependencyService.Get<i_audio>().PlayAudioFile("bestwin.mp3");
					gm.BattleVictory += 1;
					EndBattlePage(true);
					gm.AddCharToParty();
					gm.AddCharToParty(); // Add by 2
					return;
				}

				// Select objects
				if (charTurn)
				{
					offense = gm.battleModel.party[charOrder % gm.battleModel.party.Count];
					int target = rand.Next(gm.battleModel.monsters.Count);
					defense = gm.battleModel.monsters[target];
					charOrder++;
				}
				else
				{
					offense = gm.battleModel.monsters[monsterOrder % gm.battleModel.monsters.Count];
					int target = rand.Next(gm.battleModel.party.Count);
					defense = gm.battleModel.party[target];
					monsterOrder++;
				}
				charTurn = !charTurn;
				aniCount = 0;
			}
			else
			{
				aniCount++;
				double factor;
				double space = BattlePage.ImgSize * 0.7;
				if (!offense.isCharacter) space *= -1;

				if (aniCount <= 12)
				{
					factor = aniCount / 8.0;
				}
				else
				{
					int newCount = 24 - aniCount;
					factor = newCount / 8.0;
				}

				if (factor < 0.0) factor = 0.0;
				if (factor > 1.0) factor = 1.0;
				double aniX = offense.PositionX * (1 - factor) + (defense.PositionX - space) * factor;
				double aniY = offense.PositionY * (1 - factor) + defense.PositionY * factor;
				offense.SetPos(aniX, aniY);

				if (aniCount == 10)
				{
                    BattleEventStart();
					// Impact
					string msg;
                    int damage = 0;
                    if (offense.Creature.Magic && offense.isCharacter)
                    int damage = bc.GetDamage(offense.Creature, defense.Creature);

                    if (damage == 0)
                        msg = "Miss";
                    else if (damage == 1)
                    {
                        MagicController mc = new MagicController((CharacterModel)offense.Creature);
                        CharacterController cc = new CharacterController((CharacterModel)offense.Creature);
                        cc.buildMagicGrid();
                        List<MagicModel> magiclist = new List<MagicModel>();
                        foreach(string key in cc.magicList.Keys)
                        {
                            magiclist.Add(cc.magicList[key]);
                        }
                        Random rand = new Random();
                        int num = rand.Next(magiclist.Count);
                        MagicModel magic = magiclist[num];

                        // make a list of all the creatures
                        ObservableCollection<MonsterModel> mons = gm.Monsters;
                        List<CreatureModel> creaturelist = new List<CreatureModel>();
                        creaturelist.Add(defense.Creature);
                        foreach(CreatureModel c in mons)
                        {
                            if(!c.Equals(creaturelist[0]))
                            {
                                creaturelist.Add(c);
                                
                            }
                        }

                        Tuple<string, int, List<CreatureModel>> result = mc.UseMagic(magic.Name, creaturelist);
                        damage = result.Item2;
                        msg = result.Item1;
                        mons.Clear();

                        foreach(CreatureModel c in result.Item3)
                        {
                            mons.Add((MonsterModel)c);
                    }
					else
					{
                        if (offense.isCharacter)
                        {
                            CharacterModel character = (CadmusDND.CharacterModel)offense.Creature;
							//FIST FIGHT WITH DAMAGE 2 INFLICTED
							if (character.Inventory.Count == 0)
                                damage = 2;
							if (bc.isCritical())
							{
								msg = string.Format("{0} (CRITICAL)", damage);
							}
							else
							{
                                msg = string.Format("{0} (DAMAGE WITH FIST)", damage);
							}
                        }
                        else
                        {
                            if (bc.isCritical())
                            {
                                msg = string.Format("{0} (CRITICAL)", damage);
                            }
                            else
                            {
                                msg = string.Format("{0}", damage);
                            }
                        }

                        gm.Monsters = mons;

                     }

                    else
                    {
						damage = bc.GetDamage(offense.Creature, defense.Creature);
						if (damage == 0)
							msg = "Miss";
						else if (damage == 1)
						{
							msg = "Critical Miss";
							damage = 0;
							if (offense.isCharacter)
							{
								bool DiDShieldBreak = CriticalMissConsequence((CharacterModel)offense.Creature);
							}
						}
						else
						{
							if (bc.isCritical())
							{
								msg = string.Format("{0} (CRITICAL)", damage);
							}
							else
							{
								msg = string.Format("{0}", damage);
							}
						}
                    }

					DamageMessage(msg, defense.PositionX - space / 2 + 5, defense.PositionY);
					defense.CurHealth -= damage;
					if (defense.CurHealth <= 0)
					{
						CharacterModel cm = offense.Creature as CharacterModel;
						MonsterModel mm = defense.Creature as MonsterModel;
						if (cm != null)
						{
							cm.Experience += rand.Next(8) + 3;
							gm.MonsterKill += 1;
							if (mm != null)
							{
								gm.Gold += mm.Reward;
							}

							if (cm.Experience >= gm.GetExperience(cm.Level + 1))
							{
								leveled = true;
								List<int> lvl = gm.leveling;
								cm.Level = cm.Level + lvl[0];
								cm.Strength = cm.Strength + lvl[1];
								cm.Dexterity = cm.Dexterity + lvl[2];
								cm.Speed = cm.Speed + lvl[3];
								cm.Health = cm.Health + lvl[4];
							}

							cm.UpdateText();
						}
						Dying(defense);
					}
					BattleEventEnd();
				}

				if (aniCount == 24)
				{
					offense.SetPos();
					if (defense.CurHealth <= 0)
					{
						if (defense.isCharacter)
							gm.battleModel.party.Remove(defense);
						else
							gm.battleModel.monsters.Remove(defense);
					}
					offense = null;
					defense = null;
					aniCount = 0;
				}
			}