Skip to content

Commit c9f2fff

Browse files
committed
Fixed CharacterOperator and added deploy script
1 parent 276f1a4 commit c9f2fff

3 files changed

Lines changed: 41 additions & 12 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Deploy to Server
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: SSH to server and trigger rebuild
14+
uses: appleboy/ssh-action@v1.0.3
15+
with:
16+
host: raf-testnet.g9software.xyz
17+
username: deploy
18+
key: ${{ secrets.DEPLOY_SSH_KEY }}
19+
port: 22

src/node/CharacterOperator.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,17 @@ export class CharacterOperator {
159159
const battle = battleResult.battles.items.find(b => b.id.toLowerCase() === this.config.gameAddress.toLowerCase());
160160

161161
if (!battle) {
162-
this.log("Battle not found for game address", this.config.gameAddress);
162+
this.log("Battle not found for game address " + this.config.gameAddress);
163163
return false;
164164
}
165165

166166
if (battle.winner != null) {
167-
this.log("Battle already finished with winner", battle.winner, "for game address", this.config.gameAddress);
167+
this.log("Battle already finished with winner " + battle.winner + " for game address " + this.config.gameAddress);
168168
return false;
169169
}
170170

171171
if (!battle.gameStartedAt) {
172-
this.log("Battle has not started yet", battle.id);
172+
this.log("Battle has not started yet " + battle.id);
173173
return true;
174174
}
175175

@@ -320,9 +320,17 @@ export class CharacterOperator {
320320
}
321321
}
322322

323-
// If no cards can be played, end the turn
324-
if (playableCards.length === 0) {
325-
this.log('No playable cards with current energy:', currentEnergy);
323+
// Filter out cards we've already attempted
324+
const untriedPlayableCards = playableCards.filter(card => !attemptedCardIndices.has(card.cardId));
325+
326+
// If no cards can be played or all playable cards have been tried, end the turn
327+
if (playableCards.length === 0 || untriedPlayableCards.length === 0) {
328+
this.log('No more playable cards:', {
329+
currentEnergy,
330+
playableCardsCount: playableCards.length,
331+
untriedCount: untriedPlayableCards.length,
332+
attemptedCount: attemptedCardIndices.size
333+
});
326334

327335
// End the turn
328336
const endTurnData = encodeFunctionData({
@@ -362,8 +370,8 @@ export class CharacterOperator {
362370
break;
363371
}
364372

365-
// Randomly select a card from the playable cards
366-
const selectedCard = playableCards[Math.floor(Math.random() * playableCards.length)];
373+
// Randomly select a card from the untried playable cards
374+
const selectedCard = untriedPlayableCards[Math.floor(Math.random() * untriedPlayableCards.length)];
367375
const playableCardId = selectedCard.cardId;
368376
const playableHandIndex = selectedCard.handIndex;
369377
const energyCost = selectedCard.energyCost;
@@ -437,13 +445,15 @@ export class CharacterOperator {
437445
this.lastActionTime = Date.now();
438446
} catch (error: any) {
439447
if (error.message?.includes('CardNotInHandError')) {
440-
// This should never happen with proper tracking
441-
this.error('Unexpected CardNotInHandError - this indicates a bug in the card tracking logic', {
448+
// This can happen if there's a race condition or state mismatch
449+
this.error('CardNotInHandError - marking card as attempted and continuing', {
442450
playableHandIndex,
443451
playableCardId,
444452
attemptedIndices: Array.from(attemptedCardIndices)
445453
});
446-
break; // Exit to prevent further issues
454+
// Continue to next iteration instead of breaking - this allows us to try other cards
455+
// The attempted card is already marked, so we won't try it again
456+
continue;
447457
} else if (error.message?.includes('GameHasNotStartedError')) {
448458
this.log('Game has ended, stopping card play');
449459
break;

src/utils/graphql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const GraphQLQueries = {
230230

231231
getSpecificPartyByZiggurat: `
232232
query GetSpecificPartyByZiggurat($zigguratAddress: String!, $partyId: String!) {
233-
partys(where: { zigguratAddress: $zigguratAddress, partyId: $partyId, state: "1" }) {
233+
partys(where: { zigguratAddress: $zigguratAddress, partyId: $partyId}) {
234234
items {
235235
id
236236
zigguratAddress

0 commit comments

Comments
 (0)