Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Effect #124

Closed
wants to merge 16 commits into from
60 changes: 31 additions & 29 deletions packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export default mudConfig({
name: "shopSystem",
openAccess: true,
},
EncodeSystem: {
name: "encode",
openAccess: true,
},
// EncodeSystem: {
// name: "encode",
// openAccess: true,
// },
// sub-system
CoinIncomeSystem: {
name: "coinIncome",
Expand Down Expand Up @@ -75,6 +75,8 @@ export default mudConfig({
PlayerStatus: ["UNINITIATED", "INGAME"],
GameStatus: ["UNINITIATED", "PREPARING", "INBATTLE", "FINISHED"],
BoardStatus: ["UNINITIATED", "INBATTLE", "FINISHED"],
EventType: ["NONE", "ON_MOVE", "ON_ATTACK", "ON_CAST", "ON_DAMAGE", "ON_DEATH", "ON_END_TURN"],
Attribute: ["NONE", "STATUS", "HEALTH", "MAX_HEALTH", "ATTACK", "RANGE", "DEFENSE", "SPEED", "MOVEMENT"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STATUS is not clear enough

},
tables: {
NetworkConfig: {
Expand Down Expand Up @@ -148,23 +150,14 @@ export default mudConfig({
tier: "uint8", // start from 0
exp: "uint32", // experience
heroes: "bytes32[]",
heroAltar: "uint64[]", // list heros that user can buy, creature id + tier
inventory: "uint64[]",
},
},
CreatureConfig: {
keySchema: {
index: "uint32",
},
schema: {
healthAmplifier: "uint16[]", // decimal 2 // example: [210,330]
attackAmplifier: "uint16[]", // decimal 2
defenseAmplifier: "uint16[]", // decimal 2
heroAltar: "uint16[]", // list heros that user can buy, creature id + tier
inventory: "uint16[]",
},
},
Creature: {
keySchema: {
index: "uint32",
// uint16 index = | uint8 tier | uint8 internal_index|
index: "uint16",
},
schema: {
health: "uint32",
Expand All @@ -173,32 +166,41 @@ export default mudConfig({
defense: "uint32",
speed: "uint32",
movement: "uint32",
},
},
CreatureUri: {
keySchema: {
index: "uint8", // creature internal index
},
schema: {
uri: "string",
},
},
Hero: {
schema: {
creatureId: "uint32",
tier: "uint8",
creatureId: "uint16",
x: "uint32",
y: "uint32",
},
},
Piece: {
// using uint8 in order to put all data into one slot of bytes32
// 8+8+8+32+32+8+32+32+8+32+32=232 < 256
// put all data into one slot of bytes32
// 8+8+32+16+192=256
schema: {
x: "uint8",
y: "uint8",
tier: "uint8",
health: "uint32",
attack: "uint32",
range: "uint8",
defense: "uint32",
speed: "uint32",
movement: "uint8",
maxHealth: "uint32",
creatureId: "uint32",
creatureId: "uint16",
effects: "uint192",
},
},
Effect: {
keySchema: {
index: "uint16",
},
schema: {
modification: "uint160",
trigger: "uint96",
},
},
WaitingRoom: {
Expand Down
9 changes: 1 addition & 8 deletions packages/contracts/script/ConfigInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.0;

import {console} from "forge-std/console.sol";
import {IWorld} from "../src/codegen/world/IWorld.sol";
import {GameConfig, ShopConfig, CreatureConfig} from "../src/codegen/Tables.sol";
import {GameConfig, ShopConfig} from "../src/codegen/Tables.sol";

library ConfigInitializer {
function initGameConfig(IWorld _world) internal {
Expand Down Expand Up @@ -53,11 +53,4 @@ library ConfigInitializer {
tierRate
);
}

function initCreatureConfig(IWorld _world) internal {
uint16[] memory tierAmplifier = new uint16[](2);
tierAmplifier[0] = 210;
tierAmplifier[1] = 330;
CreatureConfig.set(_world, 0, tierAmplifier, tierAmplifier, tierAmplifier);
}
}
57 changes: 48 additions & 9 deletions packages/contracts/script/CreatureInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,52 @@ pragma solidity >=0.8.0;

import {console} from "forge-std/console.sol";
import {IWorld} from "../src/codegen/world/IWorld.sol";
import {Creature, GameConfig} from "../src/codegen/Tables.sol";
import {Creature, CreatureUri, GameConfig} from "../src/codegen/Tables.sol";

library CreatureInitializer {
function _genCreatureIndex(uint256 _tier, uint256 _index) private returns (uint16 index) {
index = uint16((_tier << 8) + _index);
}

function _initOneKindOfCreature(
IWorld _world,
uint8 _index,
uint32 _health,
uint32 _attack,
uint32 _range,
uint32 _defense,
uint32 _speed,
uint32 _movement,
string memory _uri
) private {
Creature.set(_world, _genCreatureIndex(0, _index), _health, _attack, _range, _defense, _speed, _movement);
Creature.set(
_world,
_genCreatureIndex(1, _index),
_health * 210 / 100,
_attack * 210 / 100,
_range,
_defense * 210 / 100,
_speed,
_movement
);
Creature.set(
_world,
_genCreatureIndex(2, _index),
_health * 330 / 100,
_attack * 330 / 100,
_range,
_defense * 330 / 100,
_speed,
_movement
);
CreatureUri.set(_world, _index, _uri);
}

function init(IWorld _world) internal {
// creature id start from 1
// BREWMASTER
Creature.set(
_initOneKindOfCreature(
_world,
1, // index
520, // health
Expand All @@ -21,7 +60,7 @@ library CreatureInitializer {
"https://www.dota2.com/hero/brewmaster" // uri
);
// OMNIKNIGHT
Creature.set(
_initOneKindOfCreature(
_world,
2, // index
650, // health
Expand All @@ -33,7 +72,7 @@ library CreatureInitializer {
"https://www.dota2.com/hero/omniknight" // uri
);
// CRYSTAL MAIDEN
Creature.set(
_initOneKindOfCreature(
_world,
3, // index
650, // health
Expand All @@ -45,7 +84,7 @@ library CreatureInitializer {
"https://www.dota2.com/hero/crystalmaiden" // uri
);
// RIKI
Creature.set(
_initOneKindOfCreature(
_world,
4, // index
520, // health
Expand All @@ -57,7 +96,7 @@ library CreatureInitializer {
"https://www.dota2.com/hero/riki" // uri
);
// RUBICK
Creature.set(
_initOneKindOfCreature(
_world,
5, // index
650, // health
Expand All @@ -69,7 +108,7 @@ library CreatureInitializer {
"https://www.dota2.com/hero/rubick" // uri
);
// ZEUS
Creature.set(
_initOneKindOfCreature(
_world,
6, // index
650, // health
Expand All @@ -81,7 +120,7 @@ library CreatureInitializer {
"https://www.dota2.com/hero/zeus" // uri
);
// HUSKAR
Creature.set(
_initOneKindOfCreature(
_world,
7, // index
650, // health
Expand All @@ -93,7 +132,7 @@ library CreatureInitializer {
"https://www.dota2.com/hero/huskar" // uri
);
// JUGGERNAUT
Creature.set(
_initOneKindOfCreature(
_world,
8, // index
650, // health
Expand Down
1 change: 0 additions & 1 deletion packages/contracts/script/PostDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ contract PostDeploy is Script {

ConfigInitializer.initGameConfig(IWorld(worldAddress));
ConfigInitializer.initShopConfig(IWorld(worldAddress));
ConfigInitializer.initCreatureConfig(IWorld(worldAddress));

// // hack
// Game.set(IWorld(worldAddress), 666, address(123), address(456), GameStatus.INBATTLE, 1, 0, 0, 0, 1);
Expand Down
Loading