Example #1
0
        /* This function creates a default NPC turn to add to the round. */
        public void AddNpcTurn(PokemonInBattle user, PokemonInBattle target)
        {
            /* A new ProportionValue<Move> array is created with a length equal to the user's move array.
             * The moves are assigned with equal proportions so that each move has the same chance of being used. */
            ProportionValue <Move>[] moves = new ProportionValue <Move> [user.Moves.Count(m => m != null)];
            for (int i = 0; i < 4; i++)
            {
                if (user.Moves[i] != null)
                {
                    moves[i] = ProportionValue.Create(1.0 / user.Moves.Count(m => m != null), user.Moves[i]); // DOES NOT HANDLE UNCOMPACTED MOVE ARRAYS
                }
            }

            /* A new turn is created using the user, target and a move chosen randomly via ProportionValue choosing. */
            turns.Add(new TurnMove(user, target, this, moves.ChooseByRandom()));
        }
Example #2
0
        /* The CheckSpawn() function checks if a wild Pokemon battle will be triggered on this frame.
         * It is only called when the player's StepCheck bit is true, so it is only called once every step. */
        private void CheckSpawn()
        {
            /* This Random object will be needed for a lot of things later. */
            Random r = new Random();

            /* Each MapLayer in the map needs to be checked for a Tile with its Spawn bit set to true. */
            foreach (MapLayer layer in world.CurrentMap.MapLayers)
            {
                /* If tile that the player is standing on in the layer has its Spawn bit set to true, a battle may happen. */
                if (layer.GetTile(player.Sprite.TileLocation.X, player.Sprite.TileLocation.Y).Spawn)
                {
                    /* This condition determines whether an actual battle happens or not.
                     * If a random double between 0 and 187.5 is less than the level's grass encounter rate, then a battle will happen.
                     * The most likely a battle can be to happen is a VeryCommon encounter rate, which is 10.0.
                     * With a VeryCommon encounter rate, the chance of a battle occurring is 10/187.5.
                     * The least likely a battle can be to happen is with a VeryRare encounter rate, which has a chance of 1.25/187.5.
                     * Note the the encounter rate is not how likely it is for a certain Pokemon to be battled - it is how likely that a battle will happen at all. */
                    if ((r.NextDouble() * 187.5) < World.CurrentLevel.GrassEncounterRate)
                    {
                        /* A new array of ProportionValue<PokemonSpawn> objects is created with the length of the GrassSpawns in the current level.
                         * GrassSpawns is a list of PokemonSpawn objects for the level's grass, stating what Pokemon at what level can be encountered.
                         * The spawns array is filled with ProportionValues created using the PokemonSpawn's Percentage property, and the PokemonSpawn object itself. */
                        ProportionValue <PokemonSpawn>[] spawns = new ProportionValue <PokemonSpawn> [World.CurrentLevel.GrassSpawns.Count];
                        for (int i = 0; i < spawns.Length; i++) // NOTE TO SELF: IT WOULD BE MORE EFFICIENT TO CREATE THE ARRAY IN A HIGHER SCOPE, SINCE IT IS PART OF THE LEVEL, BUT THIS WILL DO FOR NOW.
                        {
                            spawns[i] = ProportionValue.Create(World.CurrentLevel.GrassSpawns[i].Percentage, World.CurrentLevel.GrassSpawns[i]);
                        }

                        /* The encounter for the spawn is found proportionally from the array using ChooseByRandom().
                         * A new Pokemon object is created using the encounter data's ID, gender, and minimum/maximum levels.
                         * The wild Pokemon's level is chosen randomly between the minimum and maximum level in the selected PokemonSpawn.
                         * The moveset is currently just "Scratch". Although dynamic moveset generation is not part of the user requirements,
                         * I could add it if I have time by choosing the last four moves that the species can learn before it reaches its level. */
                        PokemonSpawn encounter = spawns.ChooseByRandom();
                        Pokemon      p         = new Pokemon(DataManager.PokemonSpecies[encounter.ID], Pokemon.GetGender(DataManager.PokemonSpecies[encounter.ID].GenderRatio), new[] { DataManager.Moves["Scratch"], null, null, null }, (byte)PkmnUtils.RandomInclusive(encounter.MinLevel, encounter.MaxLevel), null);

                        /* A wild battle is essentially a fight against an enemy team of one Pokemon.
                         * The BattleScreen.InitBattle() is called, which sends the player and enemy to the screen and sets the battle background index to zero.
                         * Finally, the BattleScreen is pushed on to the state stack. */
                        GameRef.BattleScreen.InitBattle(player.Team, p, 0);
                        Change(ChangeType.Push, GameRef.BattleScreen);
                    }
                }
            }
        }
Example #3
0
 /* This static function uses the Gender Ratio of the Pokemon's species to randomly generate a Gender value for the Pokemon,
  * according to the proportions in the Gender Ratio. */
 public static Gender GetGender(GenderRatio ratio)
 {
     /* If the ratio's male and female values are both zero, the Pokemon is genderless. */
     if (ratio.male == 0 && ratio.female == 0)
     {
         return(Gender.none);
     }
     else
     {
         /* If the Pokemon can be male or female, the function uses the Mechanics.ProportionValue<T> class.
          * An array of two ProportionValue<Gender>s is created for the male and female proportion values.
          * The male and female ratioes are added to the array.
          * The ratios are bytes between 0 and 100, so they are converted to doubles between 0 and 1 to be used in the ProportionValue.
          * Finally, the ChooseByRandom() function is used to return a gender using the ratios from the GenderRatio passed in.
          * ChooseByRandom() works such that, for example, if the GenderRatio was 75 for male and 25 for female,
          * there is a 75% chance of the function returning male, and a 25% chance of it returning female. */
         ProportionValue <Gender>[] genders = new ProportionValue <Gender> [2];
         genders[0] = ProportionValue.Create(Convert.ToDouble(ratio.male) / 100, Gender.male);
         genders[1] = ProportionValue.Create(Convert.ToDouble(ratio.female) / 100, Gender.female);
         return(genders.ChooseByRandom());
     }
 }
Example #4
0
    void GetSupport()
    {
        if (skills_defense.Length == 0)
        {
            return;
        }

        MobileAgent ally = agent.session.agents.Find(x => (x == agent || (x.team == agent.team && agent.session.teamsize != 0)) && !x.isDead && x.health < x.maxHealth / 2 && (x == agent || PhysikEngine.GetDistance(x.transform.position, agent.transform.position) <= 20));

        if (ally == null)
        {
            return;
        }

        if (ally != agent && agent.session.teamsize == 0)
        {
            ally = agent;
        }

        if (ally == agent || !MapLoader.isBlocked(agent.session.map, transform.position, ally.transform.position, false)) // TARGET IN SIGHT
        {
            short tSpell = -1;

            /*
             * DECIDE WITH PROPORTION RANDOM
             * */
            /*
             * */

            ProportionValue <ushort>[] clist = new ProportionValue <ushort> [skills_defense.Length];

            ushort rVal = (ushort)clist.Length;

            for (ushort r = 0; r < rVal; r++)
            {
                ushort idx = (ushort)agent.skills.ToList().FindIndex(x => x == skills_defense[r]);
                clist[r] = ProportionValue.Create((agent.cooldowns[idx] < Time.time) ? agent.skills[idx].botsDecideChance : 1, idx);
            }

            if (rVal > 1)
            {
                rVal = clist.ChooseByRandom();
            }
            else
            {
                rVal = clist[0].Value;
            }

            float distance = (agent.skills[rVal].skillType == SkillType.Area) ? 10 : (agent.skills[rVal].moveSpeed * agent.skills[rVal].life);

            if ((distance * 3) / 4 > distanceToActive)
            {
                tSpell = (short)rVal;
            }

            if (tSpell != -1)
            {
                /*
                 * CAST SPELL
                 * */
                agent.session.LastAim(agent.customId, ally.transform.position, transform.position);
                agent.session.SkillRequest(agent.customId, (ushort)tSpell);
                return;
            }
        }
        //
    }
Example #5
0
    void GetAction()
    {
        if (skills_attack.Length == 0)
        {
            return;
        }

        if (agent.skillStart != 0f)
        {
            return; // already in action
        }
        if (activeTarget != null)
        {
            distanceToActive = PhysikEngine.GetDistance(activeTarget.transform.position, transform.position);

            if (distanceToActive > vision)
            {
                activeTarget = null;
                return;
            }

            else if (!MapLoader.isBlocked(agent.session.map, transform.position, activeTarget.transform.position, false))  // TARGET IN SIGHT, SEARCH FOR SKILLS OR NOT MOVE TO TARGET
            {
                short tSpell = -1;

                /*
                 * DECIDE WITH PROPORTION RANDOM
                 * */
                /*
                 * */

                ProportionValue <ushort>[] clist = new ProportionValue <ushort> [skills_attack.Length];

                ushort rVal = (ushort)clist.Length;

                for (ushort r = 0; r < rVal; r++)
                {
                    ushort idx = (ushort)agent.skills.ToList().FindIndex(x => x == skills_attack[r]);
                    clist[r] = ProportionValue.Create((agent.cooldowns[idx] < Time.time) ? agent.skills[idx].botsDecideChance : 1, idx);
                }

                if (rVal > 1)
                {
                    rVal = clist.ChooseByRandom();
                }
                else
                {
                    rVal = clist[0].Value;
                }

                if (agent.skills[rVal].skillType != SkillType.Self)
                {
                    float distance = (agent.skills[rVal].skillType == SkillType.Area) ? 10 : (agent.skills[rVal].moveSpeed * agent.skills[rVal].life);

                    if ((distance * 3) / 4 > distanceToActive)
                    {
                        tSpell = (short)rVal;
                    }
                }
                else
                {
                    tSpell = (short)rVal;
                }

                if (tSpell != -1)
                {
                    /*
                     * CAST SPELL
                     * */
                    agent.session.LastAim(agent.customId, activeTarget.transform.position, transform.position);
                    agent.session.SkillRequest(agent.customId, (ushort)tSpell);
                    return;
                }
            }

            GetPath(activeTarget.transform.position);
        }
    }