Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions assets/scripts/lobby/publicData/avalon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function runPublicDataAvalon(gameDataInc) {
}

// Reset cards container
$('.playerDiv').find('.cardsContainer')[0].innerHTML = '';

$('.playerDiv').find('.cardsContainer').html = '';
// Draw cards:
for (const key in gd.publicData.cards) {
if (gd.publicData.cards.hasOwnProperty(key) === true) {
Expand All @@ -39,10 +39,24 @@ function runPublicDataAvalon(gameDataInc) {

const padding =
"<span class='cardObject glyphicon glyphicon-asterisk' style='visibility: hidden;'></span> ";

const playerDiv = $('.playerDiv')[index];
if (!playerDiv) {
console.log('Card index out of bounds', {
index, card: key, playerDivCount: $('.playerDiv').length, cardData: gd.publicData.cards[key]
});
continue;
}
const cardsContainer = $(playerDiv).find('.cardsContainer')[0];
if (!cardsContainer) {
console.log('No cardsContainer found for player', {
index, card: key, playerDiv
});
continue;
}

$($('.playerDiv')[index]).find('.cardsContainer')[0].innerHTML += card;
$($('.playerDiv')[index]).find('.cardsContainer')[0].innerHTML +=
padding;
cardsContainer.innerHTML += card;
cardsContainer.innerHTML += padding;

// Initialise the tooltip.
$('.cardObject').tooltip();
Expand Down
6 changes: 2 additions & 4 deletions src/gameplay/gameEngine/cards/avalon/ladyOfTheLake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class LadyOfTheLake implements ICard {
this.thisRoom = thisRoom;
}

initialise(): void {
this.setHolder(
(this.thisRoom.teamLeader + 1) % this.thisRoom.playersInGame.length,
);
initialise(indexOfPlayerHolding: number): void {
this.setHolder(indexOfPlayerHolding);
}

setHolder(index: number): void {
Expand Down
6 changes: 2 additions & 4 deletions src/gameplay/gameEngine/cards/avalon/refOfTheRain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class RefOfTheRain implements ICard {
this.thisRoom = thisRoom;
}

initialise(): void {
this.setHolder(
(this.thisRoom.teamLeader + 1) % this.thisRoom.playersInGame.length,
);
initialise(indexOfPlayerHolding: number): void {
this.setHolder(indexOfPlayerHolding);
}

setHolder(index: number): void {
Expand Down
12 changes: 2 additions & 10 deletions src/gameplay/gameEngine/cards/avalon/sireOfTheSea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,8 @@ class SireOfTheSea implements ICard {
this.thisRoom = thisRoom;
}

initialise(): void {
// If lady of the sea is in the game, give the card to the next person.
let addOne = 0;
if (this.thisRoom.options.includes('Lady of the Lake')) {
addOne = 1;
}
this.setHolder(
(this.thisRoom.teamLeader + 1 + addOne) %
this.thisRoom.playersInGame.length,
);
initialise(indexOfPlayerHolding: number): void {
this.setHolder(indexOfPlayerHolding);
}

setHolder(index: number): void {
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/gameEngine/cards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export enum Card {
export interface ICard {
card: Card;

initialise(): void;
initialise(indexOfPlayerHolding: number): void;

setHolder(index: number): void;

Expand Down
20 changes: 17 additions & 3 deletions src/gameplay/gameEngine/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,24 @@ class Game extends Room {
for (let i = 0; i < this.playersInGame.length; i++) {
this.voteHistory[this.playersInGame[i].request.user.username] = [];
}

// Initialise all the Cards
for (let i = 0; i < this.cardKeysInPlay.length; i++) {
this.specialCards[this.cardKeysInPlay[i]].initialise();
const cardPosition = {};
const numPlayers = this.playersInGame.length;

for (const cardKey of this.cardKeysInPlay) {
const firstCardPosition = (this.hammer + 5 + numPlayers) % numPlayers;
let offset = 0;
// potentially refactor this so that the indexes of the cards matter rather than the cards themselves, would make life easier if a new card gets implemented
if (cardKey === Card.SireOfTheSea && this.cardKeysInPlay.includes(Card.LadyOfTheLake))
offset++;
if (cardKey === Card.RefOfTheRain && this.cardKeysInPlay.includes(Card.LadyOfTheLake))
offset++;
if (cardKey === Card.RefOfTheRain && this.cardKeysInPlay.includes(Card.SireOfTheSea))
offset++;

cardPosition[cardKey] = (firstCardPosition + offset) % numPlayers;
this.specialCards[cardKey].initialise(cardPosition[cardKey]);
}

this.distributeGameData();
Expand Down
2 changes: 2 additions & 0 deletions src/sockets/sockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1614,11 +1614,13 @@ function startGame(data) {
) {
rooms[this.request.user.inRoomId].configureTimeouts(timeouts);
rooms[this.request.user.inRoomId].configureAnonymousMode(anonymousMode);
rooms[this.request.user.inRoomId].configurerandomizeCardPosition(randomizeCardPosition);
rooms[this.request.user.inRoomId].hostTryStartGame(
options,
gameMode,
timeouts,
anonymousMode,
randomizeCardPosition,
);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/views/changelog.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
<div class="myContainer">
<h1>Changelog!</h1>
<ul class="list-group" id="my-list">

<li class="list-group-item">
<strong>10-06-2026: </strong>
<ul>
<li>Fixed: If Ref of the Rain is in the same lobby as Lady of the Lake or Sire of the Sea, make sure they don't overlap/start with the same person.</li>
<li>Improved: Card initialization (happens in the main game script file instead of each individual card's script file)</li>
<li>Improved: Card container resetting</li>
<li>Thanks QuinnWuest for these changes!</li>
</ul>
</li>

<li class="list-group-item">
<strong>10-05-2026: </strong>
<ul>
Expand Down
Loading