-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] add action (charge_action_point)
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
@planetarium/lib9c/tests/actions/charge_action_point.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
]); | ||
}); | ||
}); |