Esempio n. 1
0
        /// <summary>
        /// Fight among hero and monster
        /// </summary>
        /// <param name="parHero">Hero</param>
        /// <param name="parMonster">Monster</param>
        public void Fight(Hero parHero, Monster parMonster)
        {
            if (parHero.ClassHero == Class.Assassin)
            {
                if (parMonster.Level < parHero.Level)
                {
                    parHero.AddExperience(parMonster.Level, true, 0);
                    map.DeathMonster(parMonster);
                    return;
                }

                if (VisibleAroundMonster(parMonster))
                    parHero.FirstStrike = true;
            }

            //first strike
            if (parHero.CheckFirstStrike(parMonster))
            {
                if (FirstStrikeSecond(parHero, parMonster))
                {
                    if (parHero.ClassHero == Class.Paladin && parMonster.Undead)
                        parHero.HealthCurrent += parHero.HealthMax / 2;
                    parHero.AddExperience(parMonster.Level, true, 0);
                    map.DeathMonster(parMonster);
                    return;
                }
                if (FirstStrikeSecond(parMonster, parHero))
                {
                    if (parHero.Death())
                    {
                        if (parHero.ClassHero == Class.Crusader)
                        {
                            parMonster.HealthCurrent -= parHero.DamageBase * 3;
                            if (parMonster.HealthCurrent <= 0)
                            {
                                parHero.AddExperience(parMonster.Level, true, 0);
                                map.DeathMonster(parMonster);
                            }
                        }
                        ChangeGameState(GameState.Score);
                    }
                }
                if (parHero.ClassHero == Class.Sorcerer)
                {
                    parMonster.SetDamage(parHero.AttackResponse(true), true);
                    if (parMonster.HealthCurrent <= 0)
                    {
                        parHero.AddExperience(parMonster.Level, true, 0);
                        map.DeathMonster(parMonster);
                        return;
                    }
                }
            }
            else
            {
                if (FirstStrikeSecond(parMonster, parHero))
                {
                    if (parHero.Death())
                    {
                        if (parHero.ClassHero == Class.Crusader)
                        {
                            parMonster.HealthCurrent -= parHero.DamageBase * 3;
                            if (parMonster.HealthCurrent <= 0)
                            {
                                parHero.AddExperience(parMonster.Level, true, 0);
                                map.DeathMonster(parMonster);
                            }
                        }
                        ChangeGameState(GameState.Score);
                    }
                }
                if (parHero.ClassHero == Class.Sorcerer)
                {
                    parMonster.SetDamage(parHero.AttackResponse(true), true);
                    if (parMonster.HealthCurrent <= 0)
                    {
                        if (parHero.ClassHero == Class.Paladin && parMonster.Undead)
                            parHero.HealthCurrent += parHero.HealthMax / 2;
                        parHero.AddExperience(parMonster.Level, true, 0);
                        map.DeathMonster(parMonster);
                        return;
                    }
                }
                if (FirstStrikeSecond(parHero, parMonster))
                {
                    parHero.AddExperience(parMonster.Level, true, 0);
                    map.DeathMonster(parMonster);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Check that hero attack is first
        /// </summary>
        /// <param name="parMonster">Monster</param>
        /// <returns>First attack</returns>
        public virtual bool CheckFirstStrike(Monster parMonster)
        {
            bool ret = false;

            if (parMonster.FirstStrike == false && (Level > parMonster.Level || FirstStrike == true))
                ret = true;

            FirstStrike = false;

            return ret;
        }
Esempio n. 3
0
        /// <summary>
        /// Update IO class
        /// </summary>
        /// <param name="gameTime">GameTime</param>
        public void Update(GameTime gameTime)
        {
            keyStateNow = Keyboard.GetState();
            mouseStateNow = Mouse.GetState();

            //position of mouse with scale
            int stateX = (int)((float)mouseStateNow.X / Game.ScaleWindow);
            int stateY = (int)((float)mouseStateNow.Y / Game.ScaleWindow);

            // ===== Keyboard Update =====

            if (keyStateNow.IsKeyDown(Keys.Escape))
                game.Exit();
            else if (keyStateNow.IsKeyDown(Keys.F4) && keyStateLast.IsKeyUp(Keys.F4))
                game.ChangeFullScreen();
            else if (keyStateNow.IsKeyDown(Keys.H) && keyStateLast.IsKeyUp(Keys.H))
                map.hero.ApplyPotion(TileType.HealthPotion);
            else if (keyStateNow.IsKeyDown(Keys.M) && keyStateLast.IsKeyUp(Keys.M))
                map.hero.ApplyPotion(TileType.ManaPotion);
            else if (keyStateNow.IsKeyDown(Keys.F2) && keyStateLast.IsKeyUp(Keys.F2))
                game.DoubleScreen();
            else if (keyStateNow.IsKeyDown(Keys.Space) && keyStateLast.IsKeyUp(Keys.Space))
                referee.AddMagicToHeroSlot();
            #region NumberKeyboard
            else if (keyStateNow.IsKeyDown(Keys.D1) && keyStateLast.IsKeyUp(Keys.D1))
            {
                int index = 0;
                if (map.hero.Magics[index] != MagicType.Empty
                    && map.hero.ManaCurrent >= map.hero.CostMagic(map.hero.Magics[index]))
                {
                    CurrentMagicIndex = index;
                    if (referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], -1, -1))
                        CurrentMagicIndex = -1;
                }
            }
            else if (keyStateNow.IsKeyDown(Keys.D2) && keyStateLast.IsKeyUp(Keys.D2))
            {
                int index = 1;
                if (map.hero.Magics[index] != MagicType.Empty
                    && map.hero.ManaCurrent >= map.hero.CostMagic(map.hero.Magics[index]))
                {
                    CurrentMagicIndex = index;
                    if (referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], -1, -1))
                        CurrentMagicIndex = -1;
                }
            }
            else if (keyStateNow.IsKeyDown(Keys.D3) && keyStateLast.IsKeyUp(Keys.D3))
            {
                int index = 2;
                if (map.hero.Magics[index] != MagicType.Empty
                    && map.hero.ManaCurrent >= map.hero.CostMagic(map.hero.Magics[index]))
                {
                    CurrentMagicIndex = index;
                    if (referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], -1, -1))
                        CurrentMagicIndex = -1;
                }
            }
            else if (keyStateNow.IsKeyDown(Keys.D4) && keyStateLast.IsKeyUp(Keys.D4))
            {
                int index = 3;
                if (map.hero.Magics[index] != MagicType.Empty
                    && map.hero.ManaCurrent >= map.hero.CostMagic(map.hero.Magics[index]))
                {
                    CurrentMagicIndex = index;
                    if (referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], -1, -1))
                        CurrentMagicIndex = -1;
                }
            }
            else if (keyStateNow.IsKeyDown(Keys.D5) && keyStateLast.IsKeyUp(Keys.D5))
            {
                int index = 4;
                if (map.hero.Magics[index] != MagicType.Empty
                    && map.hero.ManaCurrent >= map.hero.CostMagic(map.hero.Magics[index]))
                {
                    CurrentMagicIndex = index;
                    if (referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], -1, -1))
                        CurrentMagicIndex = -1;
                }
            }
            #endregion

            //===== Mouse Update =====

            //mouse click
            if (mouseStateNow.LeftButton == ButtonState.Pressed && mouseStateLast.LeftButton == ButtonState.Released)
            {
                //choose one magic
                if (CurrentMagicIndex != -1)
                {
                    //chosen CONVERTER
                    if (buttonMagic[CurrentMagicIndex].Parameter == MagicType.Converter)
                    {
                        for (int i = 0; i < buttonMagic.Length; ++i)
                        {
                            if (buttonMagic[i] != null && buttonMagic[i].Rectangle.Contains(stateX, stateY))
                            {
                                referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], i, stateY);
                                break;
                            }
                        }
                    }
                    //not CONVERTER, apply magic, if posible
                    else if (stateX >= 0 && stateY >= 0
                        && stateX < Constants.MAP_SIZE * Constants.TEXTURE_SIZE
                        && stateY < Constants.MAP_SIZE * Constants.TEXTURE_SIZE
                        && map.visible[stateX / Constants.TEXTURE_SIZE, stateY / Constants.TEXTURE_SIZE] != 0)
                            referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], stateX, stateY);

                    CurrentMagicIndex = -1;
                }
                else
                    MouseClick(stateX, stateY);
            }

            //not mouse click
            switch (map.GameState)
            {
                #region case GameState.Menu
                case GameState.Menu:
                    //===== information =====
                    bool cleanString = true;

                    //if button of race under cursor
                    for (int i = 0; i < buttonRaces.Count; ++i)
                    {
                        if (buttonRaces[i].Rectangle.Contains(stateX, stateY))
                        {
                            if (buttonRaces[i].Invisible)
                            {
                                switch (buttonRaces[i].Parameter)
                                {
                                    case Race.Gnome:
                                        InformationInMenu = localization.Get("RACE_INVISIBLE_GNOME");
                                        break;
                                    case Race.Goblin:
                                        InformationInMenu = localization.Get("RACE_INVISIBLE_GOBLIN");
                                        break;
                                    case Race.Orc:
                                        InformationInMenu = localization.Get("RACE_INVISIBLE_ORC");
                                        break;
                                }
                            }
                            else
                            {
                                InformationInMenu = localization.Get("RACE_" + (i + 1));
                                InformationInMenu += " " + localization.Get("CONVERT_SKILL_STRING") + "\n";
                                InformationInMenu += localization.Get("CONVERT_BONUS_" + (i + 1));
                            }
                            cleanString = false;
                        }
                    }

                    //if button of class under cursor
                    for (int i = 0; i < buttonClass.Count; ++i)
                    {
                        if (buttonClass[i].Rectangle.Contains(stateX, stateY))
                        {
                            if (buttonClass[i].Invisible)
                            {
                                switch (buttonClass[i].Parameter)
                                {
                                    case Class.Berserker:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_BERSERKER");
                                        break;
                                    case Class.Rogue:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_ROGUE");
                                        break;
                                    case Class.Monk:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_MONK");
                                        break;
                                    case Class.Sorcerer:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_SORCERER");
                                        break;
                                    case Class.Warlord:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_WARLORD");
                                        break;
                                    case Class.Assassin:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_ASSASSIN");
                                        break;
                                    case Class.Paladin:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_PALADIN");
                                        break;
                                    case Class.Bloodmage:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_BLOODMAGE");
                                        break;
                                    case Class.Transmuter:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_TRANSMUTER");
                                        break;
                                    case Class.Crusader:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_CRUSADER");
                                        break;
                                    case Class.Tinker:
                                        InformationInMenu = localization.Get("CLASS_INVISIBLE_TINKER");
                                        break;
                                }
                            }
                            else
                            {
                                InformationInMenu = localization.Get("CLASS_" + (i + 1));
                                InformationInMenu += " " + localization.Get("CLASS_TRAITS_STRING") + ":\n";
                                InformationInMenu += localization.Get("CLASS_STRING_BONUS_" + (i + 1));
                            }
                            cleanString = false;
                        }
                    }

                    if (cleanString)
                        InformationInMenu = "";
                    break;
                #endregion

                #region GameState.Game
                case GameState.Game:
                    monsterCurrent = null;

                    //if cursor over visible block of map
                    if (stateX >= 0 && stateY >= 0
                        && stateX < Constants.MAP_SIZE * Constants.TEXTURE_SIZE
                        && stateY < Constants.MAP_SIZE * Constants.TEXTURE_SIZE
                        && map.visible[stateX / Constants.TEXTURE_SIZE, stateY / Constants.TEXTURE_SIZE] != 0)
                    {
                        foreach (Monster monster in map.monsterList)
                        {
                            if (monster.Rectangle.Contains(stateX, stateY))
                            {
                                monsterCurrent = monster;
                                break;
                            }
                        }
                    }

                    buttonBonusCurrent = null;

                    if (buttonAttack.Rectangle.Contains(stateX, stateY))
                        buttonBonusCurrent = buttonAttack;

                    buttonMagicCurrent = null;

                    for (int i = 0; i < buttonMagic.Length; ++i)
                    {
                        if (buttonMagic[i] == null)
                            continue;
                        if (buttonMagic[i].Rectangle.Contains(stateX, stateY))
                        {
                            buttonMagicCurrent = buttonMagic[i];
                            buttonMagicCurrent.Parameter = map.hero.Magics[i];
                        }
                    }

                    break;
                #endregion
            }

            keyStateLast = Keyboard.GetState();
            mouseStateLast = Mouse.GetState();
        }
Esempio n. 4
0
 /// <summary>
 /// Death monster
 /// </summary>
 /// <param name="parMonster">Monster</param>
 public void DeathMonster(Monster parMonster)
 {
     map[parMonster.Rectangle.X / Constants.TEXTURE_SIZE,
         parMonster.Rectangle.Y / Constants.TEXTURE_SIZE] = (int)MapItem.None;
     bloodList.Add(new Tile(parMonster.Rectangle.X,
         parMonster.Rectangle.Y, ContentPack.TileTexture[(int)TileType.Blood]));
     monsterList.Remove(parMonster);
 }