Skip to content

Random battles

jjppof edited this page Feb 22, 2023 · 1 revision

Random battles

In this tutorial, we'll be seeing how to set up random battles in gshtml5.

Enemies

First, you need to create enemies in assets/dbs/enemies_db.json db file. In this database file, you'll be setting specific stats and spritesheet of enemies (see detailed info here). See example below for Mini Goblin:

[
  {
    "key_name": "mini_goblin",
    "name": "Mini Goblin",
    "level": 17,
    "turns": 1,
    "max_hp": 220,
    "max_pp": 0,
    "hp_recovery": 0,
    "pp_recovery": 0,
    "atk": 209,
    "def": 21,
    "agi": 61,
    "luk": 20,
    "battle_scale": 1.0,
    "battle_shadow_key": "00",
    "status_sprite_shift": 15,
    "defeat_voice": "monster_defeat/monster_2",
    "items": [
      {
        "key_name": "herb",
        "quantity": 1,
        "use_weight": 0.25
      }
    ],
    "abilities": [
      {
        "key_name": "attack",
        "use_weight": 0.75
      }
    ],
    "vulnerabilities": [],
    "coins_reward": 120,
    "item_reward": "",
    "item_reward_chance": 0,
    "exp_reward": 90,
    "base_level": {
      "venus": 1,
      "mercury": 1,
      "mars": 1,
      "jupiter": 1
    },
    "base_power": {
      "venus": 100,
      "mercury": 100,
      "mars": 100,
      "jupiter": 100
    },
    "base_resist": {
      "venus": 100,
      "mercury": 100,
      "mars": 100,
      "jupiter": 100
    },
    "battle_animations_variations": {
      "attack": "attack"
    },
    "battle_spritesheet": {
      "spritesheet": {
        "json": "assets/images/spritesheets/battle/mini_goblin_battle.json",
        "image": "assets/images/spritesheets/battle/mini_goblin_battle.png"
      },
      "animations": [
        "idle_back",
        "idle_front",
        "attack_back",
        "attack_front",
        "damage_back",
        "damage_front",
        "attack_init_back",
        "attack_init_front",
        "cast_back",
        "cast_front",
        "cast_init_back",
        "cast_init_front"
      ],
      "frames_count": [4, 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1],
      "frame_rate": [3, 3, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1],
      "loop": [
        true,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false
      ]
    }
  }
]

Enemies' parties

After defining the characteristics of your enemies, you have to set up enemies' parties. For below example, beyond Mini Globin, I'll also use Wild Wolf and also Momonga. Please find details about enemies' parties here.

[
  {
    "key_name": "mini_goblin_party",
    "name": "Mini Goblin's party",
    "can_escape": true,
    "members": [
      {
        "key": "wild_wolf",
        "min": 0,
        "max": 1
      },
      {
        "key": "mini_goblin",
        "min": 1,
        "max": 1
      },
      {
        "key": "wild_wolf",
        "min": 0,
        "max": 1
      }
    ]
  },
  {
    "key_name": "mini_goblin_party_2",
    "name": "Mini Goblin's party",
    "can_escape": true,
    "members": [
      {
        "key": "wild_wolf",
        "min": 0,
        "max": 1
      },
      {
        "key": "mini_goblin",
        "min": 1,
        "max": 1
      },
      {
        "key": "momonga",
        "min": 0,
        "max": 1
      }
    ]
  }
]

Notice that is possible to have multiple parties using the same enemies. For each enemy entry, you can define how many of each enemy could show up in the party when facing an encounter. This quantity is bound by those "min" and "max" properties.

Encounter zones

Encounter zones are regions that we create in the maps where is possible to encounter enemies' parties. These regions must be Tiled rectangles objects, it can't be any other form. See an example below for the Forest map in the demo:

Notice that these rectangles are inside an Object layer that was created specifically to hold encounter zones. This is a requirement. The Object layer that will hold the zones has to have the encounter_zone custom layer property set and set to true. You also need to pass the base rate to find an enemy party inside this region by setting the base_rate property. The higher this property, the bigger the chance to find an enemy party. You can have specific base rate values per zone if you set a custom property for it directly in the custom properties for the object that represents a zone. You can find all the details about these properties here.

In order to set which parties these zones will have, select a specific zone and set a custom property called parties, this is of string type. For the value of this property, you need to pass a list of parties that you want to encounter in that specific zone in JSON format, example: ["mini_goblin_party", "mini_goblin_party_2"].

Clone this wiki locally