public void OnGetFight(BattleChoice choice)
 {
     BattleRoom = _rgl.BattleRoom;
     Npc        = _rgl.Npc;
     Player     = _rgl.Player;
     Result     = _rgl.Battle(choice);
 }
Exemple #2
0
 //EffectMappingが呼ばれるたびにフィールド変数の値を更新する
 private void FieldUpdate()
 {
     //ゲーム全体に関して
     mapPosition.ObjectInformation(ref obstaclemap, ref charamap);
     turn           = battleMapManager.turn;
     encampmentflag = battleMapManager.flagproperties;
     pencam         = 0;
     eencam         = 0;
     for (int i = 0; i < encampmentnum; i++)
     {
         if (encampmentflag[i, 2] == 0)
         {
             pencam++;
         }
         else
         {
             eencam++;
         }
     }
     //敵に関して
     enemyx           = enemyStatus.posX;
     enemyy           = enemyStatus.posY;
     enemyatk         = enemyStatus.attack;
     enemydef         = enemyStatus.defense;
     enemyhp          = enemyStatus.hp;
     enemyhpmax       = enemyStatus.maxhp;
     eLongRangeAttack = enemyStatus.farAttacker;
     enemyJob         = enemyStatus.actionKind;
     eprotectionposx  = enemyStatus.saveX;
     eprotectionposy  = enemyStatus.saveY;
     //味方に関して                                                                ←{# 死亡判定に気を付けつつ #}
     for (int i = 0; i < 4; i++)
     {
         if (player[i] != null)
         {
             pPosx[i]  = playerStatus[i].posX;
             pPosy[i]  = playerStatus[i].posY;
             pAtk[i]   = playerStatus[i].attack;
             pDef[i]   = playerStatus[i].defense;
             pHp[i]    = playerStatus[i].hp;
             pHpmax[i] = playerStatus[i].maxhp;
             for (int ti = 0; ti <= turn; ti++)
             {
                 pAct[i, ti] = playerStatus[i].actionLevel[ti];
             }
         }
         else
         {
             pPosx[i] = 0;
             pPosy[i] = 0;
             pHp[i]   = 0;
         }
     }
     //結果用変数、配列に関して
     battlechoice  = 0;
     battlecommand = 0;
     effectmap     = new float[maprange[0], maprange[1]];
     destination   = new int[2];
     attackpos     = new int[2];
 }
        /// <summary>
        /// Gets the next decision of the owner of this battle position
        /// Uses AI if an NPC, otherwise gets player input
        /// </summary>
        /// <returns>the next battle choice</returns>
        public void GetNextDecision()
        {
            battle.waitingForPlayerInput = false;
            BattleChoice nextChoice = null;

            if (trainer.GetType() == typeof(Trainer))
            {
                //get random move from pokemon's movepool
                Random random = new Random();
                while (nextChoice == null)
                {
                    int num = random.Next(0, 3);
                    if (pokemon.move[num] != null)
                    {
                        nextChoice = BattleChoice.UseMove(pokemon.move[num], GetRandomOpponentTarget());
                    }
                }
                choice = nextChoice;
            }
            else
            {
                lock (battle.lockObject)
                {
                    battle.waitingForPlayerInput = true;
                    battle.waitingIndex          = index;
                    //get player input
                    Monitor.Wait(battle.lockObject);
                    if (choice == null)
                    {
                        throw new Exception();
                    }
                }
            }
        }
Exemple #4
0
 public override void HandleInput(GamePadState gamePadState, KeyboardState keyState, MouseState mouseState)
 {
     BattleMenu.HandleInput(gamePadState, keyState, mouseState, this);
     //if the battle is waiting for player input
     if (state == State.Input)
     {
         //get input based on key presses
         lock (battle.lockObject)
         {
             if (Input.InputHandler.WasKeyPressed(keyState, Keys.D1, 10) && battle.Positions[battle.waitingIndex].pokemon.move[0] != null)
             {
                 BattleChoice nextChoice = BattleChoice.UseMove(battle.Positions[battle.waitingIndex].pokemon.move[0], battle.Positions[1]);
                 battle.Positions[battle.waitingIndex].choice = nextChoice;
                 battle.waitingForPlayerInput = false;
                 Monitor.Pulse(battle.lockObject);
             }
             else if (Input.InputHandler.WasKeyPressed(keyState, Keys.D2, 10) && battle.Positions[battle.waitingIndex].pokemon.move[1] != null)
             {
                 BattleChoice nextChoice = BattleChoice.UseMove(battle.Positions[battle.waitingIndex].pokemon.move[1], battle.Positions[1]);
                 battle.Positions[battle.waitingIndex].choice = nextChoice;
                 battle.waitingForPlayerInput = false;
                 Monitor.Pulse(battle.lockObject);
             }
             else if (Input.InputHandler.WasKeyPressed(keyState, Keys.D3, 10) && battle.Positions[battle.waitingIndex].pokemon.move[2] != null)
             {
                 BattleChoice nextChoice = BattleChoice.UseMove(battle.Positions[battle.waitingIndex].pokemon.move[2], battle.Positions[1]);
                 battle.Positions[battle.waitingIndex].choice = nextChoice;
                 battle.waitingForPlayerInput = false;
                 Monitor.Pulse(battle.lockObject);
             }
             else if (Input.InputHandler.WasKeyPressed(keyState, Keys.D4, 10))
             {
                 BattleChoice nextChoice = BattleChoice.RunFromBattle();
                 battle.Positions[battle.waitingIndex].choice = nextChoice;
                 battle.waitingForPlayerInput = false;
                 Monitor.Pulse(battle.lockObject);
             }
         }
     }
 }
Exemple #5
0
        public static void HandleInput(GamePadState gamePadState, KeyboardState keyState, MouseState mouseState)
        {
            if (battleScreen.state == State.Input)
            {
                if (!inMenu) //if selecting an option
                {
                    //go in the menu
                    if (Input.InputHandler.WasKeyPressed(keyState, Keys.Z, 10) || Input.InputHandler.WasKeyPressed(keyState, Keys.Down, 10))
                    {
                        inMenu = true;
                    }

                    //go right
                    if (Input.InputHandler.WasKeyPressed(keyState, Keys.Right, 10))
                    {
                        optionChoice = (byte)(optionChoice < (byte)3 ? optionChoice + 1 : 0);
                    }

                    //go left
                    if (Input.InputHandler.WasKeyPressed(keyState, Keys.Left, 10))
                    {
                        optionChoice = (byte)(optionChoice > (byte)0 ? optionChoice - 1 : 3);
                    }
                }
                else //else if currently in an option
                {
                    //go out of the menu to select an option
                    if (Input.InputHandler.WasKeyPressed(keyState, Keys.X, 10) || Input.InputHandler.WasKeyPressed(keyState, Keys.Up, 10))
                    {
                        inMenu = false;
                    }

                    lock (battle.lockObject)
                    {
                        switch (optionChoice)
                        {
                        //FIGHT
                        case 0:

                            //use move
                            if (Input.InputHandler.WasKeyPressed(keyState, Keys.Z, 10))
                            {
                                if (pokemon.pokemon.move[fightChoice] != null)
                                {
                                    battle.Positions[battle.waitingIndex].choice =
                                        BattleChoice.UseMove(battle.Positions[battle.waitingIndex].pokemon.move[fightChoice],
                                                             battle.Positions[1]);
                                    battle.waitingForPlayerInput = false;
                                    Monitor.Pulse(battle.lockObject);
                                }
                            }

                            //go right
                            if (Input.InputHandler.WasKeyPressed(keyState, Keys.Right, 10))
                            {
                                fightChoice = (byte)(fightChoice < (byte)3 ? fightChoice + 1 : 0);
                            }

                            //go left
                            if (Input.InputHandler.WasKeyPressed(keyState, Keys.Left, 10))
                            {
                                fightChoice = (byte)(fightChoice > (byte)0 ? fightChoice - 1 : 3);
                            }
                            break;

                        //POKE
                        case 1:

                            //switch pokemon
                            if (Input.InputHandler.WasKeyPressed(keyState, Keys.Z, 10))
                            {
                                if (player.currentPokemon[pokeChoice] != null)
                                {
                                    battle.Positions[0].SwitchPokemon(player.currentPokemon[pokeChoice]);
                                    battle.waitingForPlayerInput = false;
                                    Monitor.Pulse(battle.lockObject);
                                }
                            }

                            //go right
                            if (Input.InputHandler.WasKeyPressed(keyState, Keys.Right, 10))
                            {
                                pokeChoice = (byte)(pokeChoice < (byte)5 ? pokeChoice + 1 : 0);
                            }

                            //go left
                            if (Input.InputHandler.WasKeyPressed(keyState, Keys.Left, 10))
                            {
                                pokeChoice = (byte)(pokeChoice > (byte)0 ? pokeChoice - 1 : 5);
                            }
                            break;

                        //ITEM
                        case 2:

                            //use item
                            if (Input.InputHandler.WasKeyPressed(keyState, Keys.Z, 10))
                            {
                                if (player.inventory[itemChoice] != null)
                                {
                                    battle.Positions[battle.waitingIndex].choice =
                                        BattleChoice.UseItem(Item.getItem(battle.Positions[battle.waitingIndex].trainer.inventory[itemChoice].itemID),
                                                             battle.Positions[1]);
                                    battle.waitingForPlayerInput = false;
                                    Monitor.Pulse(battle.lockObject);
                                }
                            }

                            //go right
                            if (Input.InputHandler.WasKeyPressed(keyState, Keys.Right, 10))
                            {
                                itemChoice = (itemChoice < itemOptions.Length - 1 ? itemChoice + 1 : 0);
                            }

                            //go left
                            if (Input.InputHandler.WasKeyPressed(keyState, Keys.Left, 10))
                            {
                                itemChoice = (itemChoice > 0 ? itemChoice - 1 : itemOptions.Length - 1);
                            }
                            break;

                        //RUN
                        case 3:

                            //get the f**k out of there (or try to atleast)
                            if (Input.InputHandler.WasKeyPressed(keyState, Keys.Z, 10))
                            {
                                battle.Positions[battle.waitingIndex].choice =
                                    BattleChoice.RunFromBattle();
                                battle.waitingForPlayerInput = false;
                                Monitor.Pulse(battle.lockObject);
                            }

                            break;
                        }
                    }
                }
            }
        }
Exemple #6
0
        public string Battle(BattleChoice choice)
        {
            string result = "";
            int    rand;

            switch (choice)
            {
            case BattleChoice.None:
                break;

            case BattleChoice.Attack:
                rand             = _rand.Next(100);
                PlayerIsCritical = Player.PlayerStats.CritChance >= rand ? true : false;
                PlayerDmg        = Player.PlayerStats.CritChance >= rand ? (Player.PlayerStats.Attack * 2) - Npc.NpcStats.Defense : Player.PlayerStats.Attack - Npc.NpcStats.Defense;
                if (PlayerDmg > 0)
                {
                    Npc.NpcStats.HealthPoints = Npc.NpcStats.HealthPoints - PlayerDmg;
                }

                if (Npc.NpcStats.HealthPoints > 0)
                {
                    rand          = _rand.Next(100);
                    NpcIsCritical = Npc.NpcStats.CritChance >= rand ? true : false;
                    NpcDmg        = Npc.NpcStats.CritChance >= rand ? (Npc.NpcStats.Attack * 2) - Player.PlayerStats.Defense : Npc.NpcStats.Attack - Player.PlayerStats.Defense;
                    if (NpcDmg > 0)
                    {
                        Player.PlayerStats.HealthPoints = Player.PlayerStats.HealthPoints - NpcDmg;
                    }
                }


                if (PlayerIsCritical)
                {
                    if (PlayerDmg < 1)
                    {
                        result = $"Dal jsi do toho útoku všechno ... ale bohužel si {Npc.Name}a minul X";
                    }
                    else
                    {
                        result = $"Dal jsi do toho útoku všechno ... daří se ti zasadit {Npc.Name}ovi kritický zásah za {PlayerDmg} bodů poškození X";
                    }
                }
                else
                {
                    if (PlayerDmg < 1)
                    {
                        result = $"Útočíš na {Npc.Name}a ... ale bohužel si {Npc.Name}a minul X";
                    }
                    else
                    {
                        result = $"Útočíš na {Npc.Name}a ... Působíš {Npc.Name}ovi {PlayerDmg} bodů poškození X";
                    }
                }
                if (NpcIsCritical)
                {
                    if (NpcDmg < 1)
                    {
                        result += $" {Npc.Name} se ti pokusil zasadit kritický zásah ... ale neprošel přes tvou obranu";
                    }
                    else
                    {
                        result += $" {Npc.Name}ovi se podarilo ti zasadit kritický zásah za {NpcDmg} bodů poškození ";
                    }
                }
                else
                {
                    if (NpcDmg < 1)
                    {
                        result += $" {Npc.Name} na tebe útočí ... ale neprošel přes tvou obranu";
                    }
                    else
                    {
                        result += $" {Npc.Name} na tebe útočí ... a způsobuje {NpcDmg} bodů poškození";
                    }
                }
                break;

            case BattleChoice.Defend:
                rand          = _rand.Next(100);
                NpcIsCritical = Npc.NpcStats.CritChance >= rand ? true : false;
                NpcDmg        = Npc.NpcStats.CritChance >= rand ? (Npc.NpcStats.Attack * 2) - (Player.PlayerStats.Defense + Player.PlayerStats.Defense / 2) : Npc.NpcStats.Attack - (Player.PlayerStats.Defense + Player.PlayerStats.Defense / 2);
                if (NpcDmg > 0)
                {
                    Player.PlayerStats.HealthPoints = Player.PlayerStats.HealthPoints - NpcDmg;
                }

                if (NpcIsCritical)
                {
                    if (NpcDmg < 1)
                    {
                        result = $"{Npc.Name} se ti pokusil zasadit kritický zásah ... Tobě se ho však podařilo plně vykrít";
                    }
                    else
                    {
                        result = $"{Npc.Name}ovi se podařilo zasadit ti kritický zásah který způsobuje {NpcDmg} bodů poškození";
                    }
                }
                else
                {
                    if (NpcDmg < 1)
                    {
                        result = $"Úspěšně jsi vykril {Npc.Name}ův útok ";
                    }
                    else
                    {
                        result = $"Snažíš se ubránit {Npc.Name}ovi ale {Npc.Name} způsobuje {NpcDmg} bodů poškození";
                    }
                }

                break;

            default:
                break;
            }
            if (Npc.NpcStats.HealthPoints < 1 && BattleRoom.Reward != null)
            {
                Player.Gold += BattleRoom.Reward.GoldReward;
                Player.Inventory.Add(BattleRoom.Reward.ItemReward);
            }
            UpdateCooldowns();
            _session.SavePlayerStats(Player);
            _session.SaveNpcStats(Npc);
            return(result);
        }
Exemple #7
0
    //################################################################################################
    //#             行動選択処理から結果の出力
    //################################################################################################
    //行動選択から各種関数を呼び出し結果を配列にまとめて出力
    public int[] EffectMapping()
    {
        FieldUpdate();                                           //ステータス、マップ情報などの変数、配列を更新
        obstaclemap[enemyx, enemyy] = 0;                         //行動する敵自体は障害物ではないと認識
        if ((float)enemyhp / enemyhpmax >= behaveDecide_HpRatio) //行動の決定、影響マップの生成方法を決める。この決定がコマンドを直接決定するわけではない。
        {
            if ((float)eencam / encampmentnum >= behaveDecide_EncamRatio)
            {
                battlechoice = BattleChoice.ATK;//攻撃行動
            }
            else if ((float)eencam / encampmentnum < behaveDecide_EncamRatio)
            {
                battlechoice = BattleChoice.CAP;//占領行動
            }
        }
        else if ((float)enemyhp / enemyhpmax < behaveDecide_HpRatio)
        {
            if ((float)eencam / encampmentnum >= behaveDecide_EncamRatio)
            {
                battlechoice = BattleChoice.EVC;//退避行動
            }
            else if ((float)eencam / encampmentnum < behaveDecide_EncamRatio)
            {
                battlechoice = BattleChoice.DEF;//防衛行動
            }
        }

        switch (battlechoice)//行動選択から分岐し、以下の関数内でeffectmapが生成される
        {
        case BattleChoice.ATK:
            Debug.Log("攻撃");
            switch (enemyJob)    //攻撃行動選択時はさらに3つに分かれる
            {
            case 0:
                Attack();
                break;

            case 1:
                Guard();
                break;

            case 2:
                Search();
                break;

            default:
                Debug.Log("エラー(影響マップ):存在しないはずの選択肢が選択されました。");
                break;
            }
            break;

        case BattleChoice.EVC:
            Debug.Log("退避");
            Evacuate();
            break;

        case BattleChoice.CAP:
            Debug.Log("占領");
            Capture();
            break;

        case BattleChoice.DEF:
            Debug.Log("防衛");
            Defense();
            break;

        case BattleChoice.NULL:
            Debug.Log("エラー(影響マップ)行動が選択されませんでした。");
            break;

        default:
            Debug.Log("エラー(影響マップ):存在しないはずの選択肢が選択されました。");
            break;
        }
        int[] test1 = DecideDestination();
        destination[0] = test1[0];//生成した影響マップから移動目的座標を決定
        destination[1] = test1[1];
        attackpos[0]   = destination[0];
        attackpos[1]   = destination[1];
        if (battlechoice == BattleChoice.ATK || battlechoice == BattleChoice.DEF)
        {
            int[] test2 = AttackPos();
            attackpos[0] = test2[0];//攻撃座標を決定
            attackpos[1] = test2[1];
        }
        if (attackpos[0] == destination[0] && attackpos[1] == destination[1])//攻撃行動を選択しても攻撃可能範囲に味方がない場合回復か待機が選択される
        {
            if (enemyhp / enemyhpmax <= healhp)
            {
                battlecommand = BattleCommand.HEAL;//回復
            }
            else
            {
                battlecommand = BattleCommand.WAIT;//待機
            }
        }
        else
        {
            battlecommand = BattleCommand.ATTACK;
        }
        obstaclemap[enemyx, enemyy] = 1;                                                                   //敵の位置を障害物に直す

        int[] result = { destination[0], destination[1], (int)battlecommand, attackpos[0], attackpos[1] }; //結果の格納

        Debug.Log(enemyx + "," + enemyy + "のターン " + destination[0] + "," + destination[1] + "," + result[2] + "," + result[3] + "," + result[4]);
        return(result);
    }