HelheimLabs / autochessia

Fully on-chain auto chess, built with MUD
https://dev.autochessia.xyz
GNU Affero General Public License v3.0
21 stars 14 forks source link

New feature: race of hero #123

Closed ClaudeZsb closed 10 months ago

ClaudeZsb commented 1 year ago

Prerequisite. This feature requires that More gas efficient is resolved.

racial effect

What we want to have is that when a player has a certain number of heroes of the same race, it will give a specific effect to all his heroes. And this mechanism can give birth to a variety of hero combinations.

race representation

Creature: {
  keySchema: {
    index: "uint16",
  },
  schema: {
    race: "uint32",
    health: "uint32",
    attack: "uint32",
    range: "uint32",
    defense: "uint32",
    speed: "uint32",
    movement: "uint32",
  },
},

race is an uint32 and is composited by 8 numbers of length 4 bits. Each number of length 4 bits represents one race and its position within race is fixed.

race race_1 race_2-7 race_8
length 4 bits 24 bits 4 bits

race_* = 0000 or 0001. 0001 represents this creature belongs to race_*

ClaudeZsb commented 1 year ago

calculation

Given an array of heroes, we can simply sum all Creature.race together. Then what we got is a uint32 number that could be split into 8 parts of length 4 bits. Each part denotes the number of heroes of the specific race. Since we have the hero number for each race, we could search maybe from a table named by RacialEffect whether there is an available racial effect.