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

v1.1.5 #3

Merged
merged 5 commits into from
Nov 29, 2022
Merged
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
14 changes: 7 additions & 7 deletions Bingo[BP]/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
"authors": [ "FondUnicycle" ]
},
"header": {
"name": "Bedrock Bingo 1.1.4 for 1.19.40",
"name": "Bedrock Bingo 1.1.5 for 1.19.50",
"description": "Play Bingo in Minecraft\n§oMade by§r §l§9FondUnicycle",
"uuid": "5ad6d6a8-c46f-4d95-a681-21b65caedf5c",
"version": [ 1, 1, 4 ],
"min_engine_version": [ 1, 19, 40 ]
"version": [ 1, 1, 5 ],
"min_engine_version": [ 1, 19, 50 ]
},
"modules": [
{
"description": "Behaviors",
"type": "data",
"uuid": "d8d2d351-efb8-40e7-ba7d-96e7d66e66f1",
"version": [ 1, 1, 4 ]
"version": [ 1, 1, 5 ]
},
{
"description": "Scripts",
"language": "javascript",
"type": "script",
"entry": "scripts/main.js",
"uuid": "9952c1d0-55e5-4d52-9cff-5faea4620f98",
"version": [ 1, 1, 4 ]
"version": [ 1, 1, 5 ]
}
],
"dependencies": [
{
// Resource Pack
"uuid": "f01c794a-cd2f-46b1-a31e-eaa7548dcdf2",
"version": [ 1, 1, 4 ]
"version": [ 1, 1, 5 ]
},
{
"module_name": "@minecraft/server",
"version": "1.0.0-beta"
"version": "1.1.0-beta"
},
{
"module_name": "@minecraft/server-ui",
Expand Down
310 changes: 142 additions & 168 deletions Bingo[BP]/scripts/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,160 +12,161 @@ let spawnLoc;
let winner;

// 1.19.50 fix
// let gameLoopScheduleId;
// let celebrationRunId;
let celebrationCounter = 0; // Only for 1.19.40
let gameLoopScheduleId;
let celebrationScheduleId;
let celebrationCounter = 0;

export let winnerFound = false;
export let gameRunning = false;

let invSlot = 0;

// 1.19.50 fix
// function celebrationEvent() {
// // Show title
// overworld.runCommandAsync(`title @a title §6${winner.nameTag}`);
// overworld.runCommandAsync(`title @a subtitle §6got BINGO!!`);
// // Play challenge sound
// overworld.runCommandAsync('playsound bingo.win @a');
// let celebrationCounter = 0;
// do {
// winner.runCommandAsync('summon fireworks_rocket');
// celebrationCounter++;
// } while (celebrationCounter < 20);
// }
function launchRockets(){
celebrationCounter++;
winner.runCommandAsync('summon fireworks_rocket');
if(celebrationCounter > 30){
system.clearRunSchedule(celebrationScheduleId);
}
}

function celebrationEvent() {
// Show title
overworld.runCommandAsync(`title @a title §6${winner.nameTag}`);
overworld.runCommandAsync(`title @a subtitle §6got BINGO!!`);
// Play challenge sound
overworld.runCommandAsync('playsound bingo.win @a');

celebrationScheduleId = system.runSchedule(launchRockets, tickDelay);
}

/**
* @param {Player} player The player Entity object
*/
@param {Player} player The player Entity object
*/
function setWinner(player) {
winnerFound = true;

// 1.19.50 fix
//gameRunning = false;

winner = player;
// tp players to spawn
winner.teleport(spawnLoc, overworld, 0, 0);
winner.runCommandAsync(`tp @a @s`);

// 1.19.50 fix
// celebrationRunId = system.run(celebrationEvent, tickDelay);
winnerFound = true;
gameRunning = false;

winner = player;

winner.teleport(spawnLoc, overworld, 0, 0);
winner.runCommandAsync(`tp @a @s`);

celebrationEvent();
}

/**
* @param {Player} player The player Entity object
*/
@param {Player} player The player Entity object
*/
function checkBingo(player) {
switch (gameMode) {
case 'Line':
const card = player.card.itemGrid;
// Checks diagonals
let topLeftBingo = card.filter((elm, idx) => elm[idx] >= cardMarker);
if(topLeftBingo.length == CardRows) {
setWinner(player);
break;
}
let topRightBingo = card.filter((elm, idx) => elm[(CardRows-1) - idx] >= cardMarker);
if(topRightBingo.length == CardRows) {
setWinner(player);
break;
}
let hBingo;
let vBingo;
for (let i = 0; i < card.length; i++) {
// Checks horizontals
hBingo = card[i].filter((elm) => elm >= cardMarker);
if(hBingo.length == CardCols) {
setWinner(player);
break;
}
// Checks verticals
vBingo = card.filter((elm) => elm[i] >= cardMarker);
if(vBingo.length == CardRows) {
setWinner(player);
break;
}
}
break;
case 'Blackout':
let markerCount = 0;
let item;
for (const row in player.card.itemGrid) {
for (const col in player.card.itemGrid[row]) {
item = player.card.itemGrid[row][col];
if(item >= cardMarker) markerCount++;
if(markerCount == CardRows*CardCols) setWinner(player);
}
}
break;
}
switch (gameMode) {
case 'Line':
const card = player.card.itemGrid;
// Checks diagonals
let topLeftBingo = card.filter((elm, idx) => elm[idx] >= cardMarker);
if(topLeftBingo.length == CardRows) {
setWinner(player);
break;
}
let topRightBingo = card.filter((elm, idx) => elm[(CardRows-1) - idx] >= cardMarker);
if(topRightBingo.length == CardRows) {
setWinner(player);
break;
}
let hBingo;
let vBingo;
for (let i = 0; i < card.length; i++) {
// Checks horizontals
hBingo = card[i].filter((elm) => elm >= cardMarker);
if(hBingo.length == CardCols) {
setWinner(player);
break;
}
// Checks verticals
vBingo = card.filter((elm) => elm[i] >= cardMarker);
if(vBingo.length == CardRows) {
setWinner(player);
break;
}
}
break;
case 'Blackout':
let markerCount = 0;
let item;
for (const row in player.card.itemGrid) {
for (const col in player.card.itemGrid[row]) {
item = player.card.itemGrid[row][col];
if(item >= cardMarker) markerCount++;
if(markerCount == CardRows*CardCols) setWinner(player);
}
}
break;
}
}

function checkInvs() {
/** CHECKS IF THE GIVEN ITEM IS IN THE CARD, IF SO TAKES 1 OF THAT ITEM, AND UPDATES THE CARD ACCORDINGLY. THEN CHECKS FOR BINGO*/
let container;
let item;
let cardItem;
for (const p of [...world.getPlayers()]) {
container = p.getComponent('inventory').container;
item = container.getItem(invSlot);
if(!item) continue;
for (let r = 0; r < p.card.itemGrid.length; r++) {
for (let c = 0; c < p.card.itemGrid[r].length; c++) {
cardItem = emoji_ids[p.card.itemGrid[r][c]];
if ((cardItem == item.typeId) || (cardItem?.id == item.typeId && cardItem?.data == item.data)) {
item.amount--;
container.setItem(invSlot, item);
p.card.update(r, c);
p.runCommandAsync('playsound random.levelup @s');
checkBingo(p);
}
}
/** CHECKS IF THE GIVEN ITEM IS IN THE CARD, IF SO TAKES 1 OF THAT ITEM, AND UPDATES THE CARD ACCORDINGLY. THEN CHECKS FOR BINGO*/
let container;
let item;
let cardItem;
for (const p of [...world.getPlayers()]) {
container = p.getComponent('inventory').container;
item = container.getItem(invSlot);
if(!item) continue;
for (let r = 0; r < p.card.itemGrid.length; r++) {
for (let c = 0; c < p.card.itemGrid[r].length; c++) {
cardItem = emoji_ids[p.card.itemGrid[r][c]];
if ((cardItem == item.typeId) || (cardItem?.id == item.typeId && cardItem?.data == item.data)) {
item.amount--;
container.setItem(invSlot, item);
p.card.update(r, c);
p.runCommandAsync('playsound random.levelup @s');
checkBingo(p);
}
}
}
invSlot++
if(invSlot == playerInvSize) invSlot = 0;

}
invSlot++
if(invSlot == playerInvSize) invSlot = 0;

}

export function setUpGame(location) {
spawnLoc = location;
overworld.runCommandAsync(`say Spawn set to ( ${Math.floor(spawnLoc.x)}, ${Math.floor(spawnLoc.y)}, ${Math.floor(spawnLoc.z)} )`)

overworld.runCommandAsync('title @a title §o§gLoading...');
for (const p of [...world.getPlayers()]) {
if(!p.card) {
setNewCard(p);
}
spawnLoc = location;
overworld.runCommandAsync(`say Spawn set to ( ${Math.floor(spawnLoc.x)}, ${Math.floor(spawnLoc.y)}, ${Math.floor(spawnLoc.z)} )`)

overworld.runCommandAsync('title @a title §o§gLoading...');
for (const p of [...world.getPlayers()]) {
if(!p.card) {
setNewCard(p);
}
overworld.runCommandAsync('title @a clear');

overworld.runCommandAsync('gamerule sendCommandFeedback false');
// Clearing the inventory
overworld.runCommandAsync('clear @a');
overworld.runCommandAsync('give @a fond:bingo_card 1 0 {"minecraft:keep_on_death":{},"minecraft:item_lock":{"mode":"lock_in_inventory"}}');
overworld.runCommandAsync('give @a fond:info_book');

// Resetting World Settings
overworld.runCommandAsync('gamemode survival @a')
// overworld.runCommandAsync('difficulty hard');
overworld.runCommandAsync('gamerule doDaylightCycle true');

overworld.runCommandAsync(`spreadplayers ${spawnLoc.x} ${spawnLoc.z} 32 512 @a`);
overworld.runCommandAsync('effect @a slow_falling 60 1');

overworld.runCommandAsync('gamerule sendCommandFeedback true');
// winnerFound = false; // To be able to play another game.
// celebrationCounter = 0; // To be able to play another game.
gameRunning = true;

// 1.19.50 fix
// gameLoopScheduleId = system.runSchedule(gameLoop, tickDelay);
}
overworld.runCommandAsync('title @a clear');

overworld.runCommandAsync('gamerule sendCommandFeedback false');
// Clearing the inventory
overworld.runCommandAsync('clear @a');
overworld.runCommandAsync('give @a fond:bingo_card 1 0 {"minecraft:keep_on_death":{},"minecraft:item_lock":{"mode":"lock_in_inventory"}}');
overworld.runCommandAsync('give @a fond:info_book');

// Resetting World Settings
overworld.runCommandAsync('gamemode survival @a')
// overworld.runCommandAsync('difficulty hard');
overworld.runCommandAsync('gamerule doDaylightCycle true');

overworld.runCommandAsync(`spreadplayers ${spawnLoc.x} ${spawnLoc.z} 32 512 @a`);
overworld.runCommandAsync('effect @a slow_falling 60 1');

overworld.runCommandAsync('gamerule sendCommandFeedback true');
// winnerFound = false; // To be able to play another game.
// celebrationCounter = 0; // To be able to play another game.
gameRunning = true;

// 1.19.50 fix
gameLoopScheduleId = system.runSchedule(gameLoop, tickDelay);
}

export function setGameMode() {
gameMode = SETTINGS.mode;
gameMode = SETTINGS.mode;
}

// function isUsedCard(card) {
Expand All @@ -180,47 +181,20 @@ export function setGameMode() {
// }

/**
* Generates a new Card and attatches it to the player
* @param {Player} player Player Entity
*/
Generates a new Card and attatches it to the player
@param {Player} player Player Entity
*/
export function setNewCard(player) {
let newCard = new Card(player);
player['card'] = newCard;
player.card.cardToText();
player.card.display(true);
let newCard = new Card(player);
player['card'] = newCard;
player.card.cardToText();
player.card.display(true);
}

export function gameLoop(tick) {
// 1.19.50 fix
// if(!gameRunning) {
// system.clearRunSchedule(gameLoopScheduleId);
// return;
// }
// checkInvs();

if(!gameRunning) {
return;
}
if(!winnerFound) {
if(tick % tickDelay == 0) {
checkInvs();
}
}
else if( tick % tickDelay == 0 ) {
if(celebrationCounter == 2) {
// Show title
overworld.runCommandAsync(`title @a title §6${winner.nameTag}`);
overworld.runCommandAsync(`title @a subtitle §6got BINGO!!`);
// Play challenge sound
overworld.runCommandAsync('playsound bingo.win @a');
}
// Throw fireworks
if(celebrationCounter < 20) {
winner.runCommandAsync('summon fireworks_rocket');
celebrationCounter++;
}
else {
gameRunning = false;
}
}
if(!gameRunning) {
system.clearRunSchedule(gameLoopScheduleId);
return;
}
checkInvs();
}
Loading