Skip to content

Commit

Permalink
Merge pull request #8 from wizguin/develop
Browse files Browse the repository at this point in the history
1.7.0-beta
  • Loading branch information
wizguin authored Nov 17, 2023
2 parents 85d3832 + 0fba2e4 commit c6aea7f
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 35 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yukon-server",
"version": "1.6.0-beta",
"version": "1.7.0-beta",
"description": "A server for https://github.com/wizguin/yukon",
"scripts": {
"dev": "babel-watch ./src/World.js Login Blizzard",
Expand Down
55 changes: 30 additions & 25 deletions src/handlers/GameHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,44 @@ export default class GameHandler extends BaseHandler {
}

close(user) {
if (!user) {
return
}
try {
if (!user) {
return
}

if (!user.authenticated) {
return this.closeAndUpdatePopulation(user)
}
if (!user.authenticated) {
return this.closeAndUpdatePopulation(user)
}

if (user.room) {
user.room.remove(user)
}
if (user.room) {
user.room.remove(user)
}

if (user.buddies) {
user.buddies.sendOffline()
}
if (user.buddies) {
user.buddies.sendOffline()
}

if (user.waddle) {
user.waddle.remove(user)
}
if (user.waddle) {
user.waddle.remove(user)
}

if (user.minigameRoom) {
user.minigameRoom.remove(user)
}
if (user.minigameRoom) {
user.minigameRoom.remove(user)
}

if (user.id && user.id in this.usersById) {
delete this.usersById[user.id]
}
if (user.id && user.id in this.usersById) {
delete this.usersById[user.id]
}

if (user.id) {
this.openIgloos.remove(user)
}
if (user.id) {
this.openIgloos.remove(user)
}

this.closeAndUpdatePopulation(user)
this.closeAndUpdatePopulation(user)
}
catch (error) {
this.error(error)
}
}

get joined() {
Expand Down
12 changes: 12 additions & 0 deletions src/objects/instance/BaseInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ export default class BaseInstance {
// Don't start until all users are ready
this.ready = []

// Game room ID
this.id = null

this.started = false

this.handleStartGame = this.handleStartGame.bind(this)
this.handleLeaveGame = this.handleLeaveGame.bind(this)
}

init() {
Expand All @@ -21,10 +27,12 @@ export default class BaseInstance {

addListeners(user) {
user.events.on('start_game', this.handleStartGame)
user.events.on('leave_game', this.handleLeaveGame)
}

removeListeners(user) {
user.events.off('start_game', this.handleStartGame)
user.events.off('leave_game', this.handleLeaveGame)
}

handleStartGame(args, user) {
Expand All @@ -35,6 +43,10 @@ export default class BaseInstance {
}
}

handleLeaveGame(args, user) {
this.remove(user)
}

checkStart() {
// Compare with non null values in case user disconnects
if (this.ready.length == this.users.length) {
Expand Down
4 changes: 3 additions & 1 deletion src/objects/instance/InstanceFactory.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import CardInstance from './card/CardInstance'
import SledInstance from './sled/SledInstance'


export default class InstanceFactory {

static types = {
'card': CardInstance
'card': CardInstance,
'sled': SledInstance
}

static createInstance(waddle) {
Expand Down
7 changes: 0 additions & 7 deletions src/objects/instance/card/CardInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default class CardInstance extends BaseInstance {

this.handleSendDeal = this.handleSendDeal.bind(this)
this.handlePickCard = this.handlePickCard.bind(this)
this.handleLeaveGame = this.handleLeaveGame.bind(this)
}

init() {
Expand All @@ -45,15 +44,13 @@ export default class CardInstance extends BaseInstance {
addListeners(user) {
user.events.on('send_deal', this.handleSendDeal)
user.events.on('pick_card', this.handlePickCard)
user.events.on('leave_game', this.handleLeaveGame)

super.addListeners(user)
}

removeListeners(user) {
user.events.off('send_deal', this.handleSendDeal)
user.events.off('pick_card', this.handlePickCard)
user.events.off('leave_game', this.handleLeaveGame)

super.removeListeners(user)
}
Expand Down Expand Up @@ -82,10 +79,6 @@ export default class CardInstance extends BaseInstance {
this.judgeRound(me)
}

handleLeaveGame(args, user) {
this.remove(user)
}

start() {
let users = this.users.map(user => {
return {
Expand Down
59 changes: 59 additions & 0 deletions src/objects/instance/sled/SledInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import BaseInstance from '../BaseInstance'

import { hasProps, isInRange } from '@utils/validation'


export default class SledInstance extends BaseInstance {

constructor(waddle) {
super(waddle)

this.id = 999

this.coins = [20, 10, 5, 5]
}

addListeners(user) {
super.addListeners(user)
}

removeListeners(user) {
super.removeListeners(user)
}

start() {
const users = this.users.map(user => {
return {
username: user.username,
color: user.color,
hand: user.hand
}
})

this.send('start_game', { users: users })

super.start()
}

sendMove(args, user) {
if (!hasProps(args, 'move')) {
return
}

if (!isInRange(args.move, 1, 5)) {
return
}

if (args.move === 5) {
return this.sendGameOver(user)
}

this.send('send_move', { id: this.getSeat(user), move: args.move }, user)
}

sendGameOver(user) {
this.remove(user)
user.updateCoins(this.coins.shift(), true)
}

}
2 changes: 1 addition & 1 deletion src/objects/room/matchmaker/MatchmakerFactory.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CardMatchmaker from './CardMatchmaker'


export default class TableFactory {
export default class MatchmakerFactory {

static types = {
'card': CardMatchmaker
Expand Down
4 changes: 4 additions & 0 deletions src/plugin/plugins/game/Join.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export default class Join extends GamePlugin {
}

joinRoom(args, user) {
if (!isNumber(args.room)) {
return
}

user.joinRoom(this.rooms[args.room], args.x, args.y)
}

Expand Down
44 changes: 44 additions & 0 deletions src/plugin/plugins/game/Puck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import GamePlugin from '@plugin/GamePlugin'

import { hasProps, isNumber } from '@utils/validation'


export default class Puck extends GamePlugin {

constructor(handler) {
super(handler)

this.events = {
'get_puck': this.getPuck,
'move_puck': this.movePuck
}

this.rinkRoomId = 802

this.puckX = 0
this.puckY = 0
}

getPuck(args, user) {
if (user.room.id !== this.rinkRoomId) return

user.send('get_puck', { x: this.puckX, y: this.puckY })
}

movePuck(args, user) {
if (user.room.id !== this.rinkRoomId) return

if (!hasProps(args, 'x', 'y', 'speedX', 'speedY')) return

if (!isNumber(args.x)) return
if (!isNumber(args.y)) return
if (!isNumber(args.speedX)) return
if (!isNumber(args.speedY)) return

this.puckX = args.x
this.puckY = args.y

user.room.send(user, 'move_puck', { x: args.x, y: args.y, speedX: args.speedX, speedY: args.speedY })
}

}
5 changes: 5 additions & 0 deletions src/plugin/plugins/game/Table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import GamePlugin from '@plugin/GamePlugin'

import { isNumber } from '@utils/validation'

export default class Table extends GamePlugin {

Expand All @@ -24,6 +25,10 @@ export default class Table extends GamePlugin {
}

joinTable(args, user) {
if (!isNumber(args.table)) {
return
}

let table = user.room.tables[args.table]

user.joinTable(table)
Expand Down

0 comments on commit c6aea7f

Please sign in to comment.