Skip to content

Commit

Permalink
[feat] add action (charge_action_point)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanade012 committed Oct 25, 2024
1 parent 5c9c1e1 commit 091b561
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
37 changes: 37 additions & 0 deletions @planetarium/lib9c/src/actions/charge_action_point.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Address } from "@planetarium/account";
import { BencodexDictionary, Dictionary, type Value } from "@planetarium/bencodex";
import { GameAction, type GameActionArgs } from "./common.js";

/**
* The arguments of the `ChargeActionPoint` action.
*/
export type ChargeActionPointArgs = {
avatarAddress: Address;
} & GameActionArgs;

/**
* The `ChargeActionPoint` action is used to charge action points for an avatar.
*/
export class ChargeActionPoint extends GameAction {
protected readonly type_id: string = "charge_action_point3";

public readonly avatarAddress: Address;

/**
* Create a new `ChargeActionPoint` action.
* @param params The arguments of the `ChargeActionPoint` action.
*/
constructor({ avatarAddress, id }: ChargeActionPointArgs) {
super({ id });
this.avatarAddress = avatarAddress;
}

/**
* Serialize the action data to Bencodex format.
*/
protected plain_value_internal(): Dictionary {
return new BencodexDictionary([
["avatarAddress", this.avatarAddress.toBytes()],
]);
}
}
1 change: 1 addition & 0 deletions @planetarium/lib9c/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {
type ClaimStakeRewardArgs,
} from "./actions/claim_stake_reward.js";
export { Stake, type StakeArgs } from "./actions/stake.js";
export { ChargeActionPoint, type ChargeActionPointArgs } from "./actions/charge_action_point.js";
export { DailyReward, type DailyRewardArgs } from "./actions/daily_reward.js";
export {
TransferAsset,
Expand Down
23 changes: 23 additions & 0 deletions @planetarium/lib9c/tests/actions/charge_action_point.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe } from "vitest";
import { ChargeActionPoint, uuidToGuidBytes } from "../../src/index.js";
import { runTests } from "./common.js";
import { avatarAddress } from "./fixtures.js";

describe("ChargeActionPoint", () => {
describe("odin", () => {
runTests("valid case", [
new ChargeActionPoint({
id: uuidToGuidBytes("ae195a5e-b43f-4c6d-8fd3-9f38311a45eb"),
avatarAddress,
}),
]);
});
describe("heimdall", () => {
runTests("valid case", [
new ChargeActionPoint({
id: uuidToGuidBytes("97b69171-6482-4e11-b2c9-1c671615321b"),
avatarAddress,
}),
]);
});
});

0 comments on commit 091b561

Please sign in to comment.