Commit 23b124f7 authored by Killian LUCAS's avatar Killian LUCAS
Browse files

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	not-alone-server/src/main/java/fr/univnantes/alma/server/game/item/planet/Planet.java
parents f22f53db f66cdd5c
namespace java fr.univnantes.alma.thrift
namespace js core
namespace js common
exception InvalidOperationException {
1: i32 code,
......
include "common.thrift"
namespace java fr.univnantes.alma.thrift
namespace js common
// Types
......@@ -27,7 +28,7 @@ struct TColor {
//Service
service GameServerService {
service GameService {
TRoomId createRoom(TPlayerId playerId) throws (1:common.InvalidOperationException e)
......
include "common.thrift"
namespace java fr.univnantes.alma.thrift
namespace js common
//Type
......@@ -52,7 +53,7 @@ struct TCreature{
//Service
service GameClientService {
service PlayerService {
bool ping() throws (1:common.InvalidOperationException e)
void sendGameDescription(TPlayerTeam team, THand hand, TScore score, TPlanet planet, list<TCardReserve> reserve, list<TTraque> traquesInformation, TCreature creatureInformation)
......
......@@ -70,7 +70,7 @@ class Room{
- currentActivatePowers : PowerContainer[*]
- nextRoundPowers : PowerContainer[*]
- gameRoundVariables : GameRoundVariables
- gameClientHandler : GameClientHandler
- playerServiceHandler : GameClientHandler
- initializePlayer(creatureId : Integer, playerNumber : Integer)
- initializeReserve(playerNumber : Integer)
......
node_modules/
node/
dist/
src/codegen/
\ No newline at end of file
This diff is collapsed.
{
"name": "not-alone-web",
"version": "0.0.0",
"scripts": {
"prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
"build": "tsc",
"prestart": "npm run build",
"start": "node .",
"test": "echo \"Error: no test specified\" && exit 1",
"codegen": "\"./node_modules/.bin/thrift-typescript\" --target thrift-server --sourceDir \"../not-alone-core/src/main/thrift/\" --outDir \"./src/codegen/\""
},
"private": true,
"devDependencies": {
"@creditkarma/thrift-parser": "^1.2.0",
"@creditkarma/thrift-typescript": "^3.7.6",
"@types/thrift": "^0.10.10",
"codelyzer": "^6.0.1",
"tslint": "^6.1.3"
},
"dependencies": {
"@creditkarma/thrift-client": "^0.16.1",
"@creditkarma/thrift-server-core": "^0.16.1",
"@creditkarma/thrift-server-express": "^0.16.1"
},
"browser": {
"crypto": false,
"stream": false
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>not-alone</artifactId>
<groupId>fr.univnantes.alma</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>not-alone-player</artifactId>
<name>Not Alone Player Services</name>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.10.0</version>
<configuration>
<workingDirectory>./</workingDirectory>
<nodeVersion>v14.11.0</nodeVersion>
<npmVersion>7.0.10</npmVersion>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
<execution>
<id>code generation</id>
<phase>compile</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run codegen</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>./dist/not-alone-web</directory>
<targetPath>static</targetPath>
</resource>
</resources>
</build>
</project>
import { IJoinRequest } from 'src/codegen/common';
import { IHandler } from '../codegen/common/GameService';
import { PlayerService } from '../player/player-service';
export class ClientServiceHandler<Context> implements IHandler<Context> {
private service: PlayerService;
constructor() {
this.service = new PlayerService();
}
public createGame(numberOfPlayers: number, context?: Context): number | Promise<number> {
throw new Error('Method not implemented.');
}
public join(gameId: number, request: IJoinRequest, context?: Context): number | Promise<number> {
throw new Error('Method not implemented.');
}
public startGame(gameId: number): void | Promise<void> {
return this.service.startGame(gameId);
}
}
export class PlayerService {
startGame(gameId: number): void {
console.log('Start game', gameId);
}
}
import { createHttpClient, HttpConnection } from '@creditkarma/thrift-client';
import * as request from 'request';
import { CoreOptions } from 'request';
import { Client } from '../codegen/common/GameService';
const CONFIG = {
hostName: 'localhost',
port: 8045,
};
const thriftClient: Client<CoreOptions> = createHttpClient(Client, CONFIG);
const id: Promise<Number> = thriftClient.createGame(8);
export class ThriftClient {}
import { GameService } from '../codegen/common/';
import { ClientServiceHandler } from '../handler/client-service-handler';
import * as express from 'express';
import { createThriftServer } from '@creditkarma/thrift-server-express';
const handler: ClientServiceHandler<express.Request> = new ClientServiceHandler<express.Request>();
const PORT = 8090;
export class ThriftServer {
private app: express.Application;
constructor() {
this.app = createThriftServer({
path: '/thrift',
thriftOptions: {
serviceName: 'calculator-service',
handler: new GameService.Processor(handler),
},
});
this.app.listen(PORT, () => {
console.log(`Express server listening on port: ${PORT}`);
});
}
}
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "ES6",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"paths": {
"core-js/es7/reflect": [
"node_modules/core-js/proposals/reflect-metadata"
]
}
},
"include": ["target/generated-sources/thrift//**/*", "src/**/*"]
}
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"arrow-return-shorthand": true,
"callable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"deprecation": {
"severity": "warn"
},
"eofline": true,
"forin": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": [
true,
"spaces"
],
"interface-over-type-literal": true,
"label-position": true,
"max-line-length": [
true,
140
],
"member-access": false,
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-arg": true,
"no-bitwise": true,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-debugger": true,
"no-duplicate-super": true,
"no-empty": false,
"no-empty-interface": true,
"no-eval": true,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-misused-new": true,
"no-non-null-assertion": true,
"no-redundant-jsdoc": true,
"no-shadowed-variable": true,
"no-string-literal": false,
"no-string-throw": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unnecessary-initializer": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"prefer-const": true,
"quotemark": [
true,
"single"
],
"radix": true,
"semicolon": [
true,
"always"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"unified-signatures": true,
"variable-name": false,
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],
"no-output-on-prefix": true,
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"no-input-rename": true,
"no-output-rename": true,
"use-life-cycle-interface": true,
"use-pipe-transform-interface": true,
"component-class-suffix": true,
"directive-class-suffix": true
}
}
......@@ -5,7 +5,7 @@ import fr.univnantes.alma.server.game.item.planet.Planet;
import fr.univnantes.alma.thrift.InvalidOperationException;
import fr.univnantes.alma.thrift.Response;
public interface GameService {
public interface RoomService {
/**
* Create a room if the player is not already in a room
......
......@@ -7,7 +7,6 @@ import fr.univnantes.alma.server.game.item.card.CardName;
import fr.univnantes.alma.server.game.item.card.PlaceCard;
import fr.univnantes.alma.server.game.item.card.SurvivalCard;
import fr.univnantes.alma.server.game.item.card.TrackingCard;
import fr.univnantes.alma.server.game.item.jeton.JetonArtemia;
import fr.univnantes.alma.server.game.item.jeton.JetonSymbol;
import java.util.*;
......@@ -52,13 +51,37 @@ public class DatabaseStub implements NotAloneDatabase {
private void initializeSurvivalCardMap(){
survivalCardMap = new HashMap<>();
survivalCardMap.put("ADRENALINE", new SurvivalCard(CardName.ADRENALINE,"Adrénaline", "Lorem ipsum", Phase.PHASE_1));
survivalCardMap.put("ALERTE", new SurvivalCard(CardName.ALERTE,"Alerte", "Lorem ipsum", Phase.PHASE_1));
survivalCardMap.put("AMPLIFICATEUR", new SurvivalCard(CardName.AMPLIFICATEUR,"Amplificateur", "Lorem ipsum", Phase.PHASE_1));
survivalCardMap.put("BROUILLAGE", new SurvivalCard(CardName.BROUILLAGE,"Brouillage", "Lorem ipsum", Phase.PHASE_1));
survivalCardMap.put("CAVALE", new SurvivalCard(CardName.CAVALE,"Cavale", "Lorem ipsum", Phase.PHASE_1));
survivalCardMap.put("DETECTEUR", new SurvivalCard(CardName.DETECTEUR,"Détecteur", "Lorem ipsum", Phase.PHASE_1));
survivalCardMap.put("DRONE", new SurvivalCard(CardName.DRONE,"Drone", "Lorem ipsum", Phase.PHASE_1));
survivalCardMap.put("ADRENALINE", new SurvivalCard(CardName.ADRENALINE,"Adrénaline", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("ALERTE", new SurvivalCard(CardName.ALERTE,"Alerte", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("AMPLIFICATEUR", new SurvivalCard(CardName.AMPLIFICATEUR,"Amplificateur", "Lorem ipsum", Phase.PREPHASE_4));
survivalCardMap.put("BROUILLAGE", new SurvivalCard(CardName.BROUILLAGE,"Brouillage", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("CAVALE", new SurvivalCard(CardName.CAVALE,"Cavale", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("DETECTEUR", new SurvivalCard(CardName.DETECTEUR,"Détecteur", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("DRONE", new SurvivalCard(CardName.DRONE,"Drone", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("ENTRAVE", new SurvivalCard(CardName.ENTRAVE,"Entrave", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("EQUIPEMENT", new SurvivalCard(CardName.EQUIPEMENT,"Equipement", "Lorem ipsum", Phase.PREPHASE_4));
survivalCardMap.put("ESQUIVE", new SurvivalCard(CardName.ESQUIVE,"Esquive", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("FAUSSE_PISTE", new SurvivalCard(CardName.FAUSSE_PISTE,"Fausse-piste", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("HOLOGRAMME", new SurvivalCard(CardName.HOLOGRAMME,"Hologramme", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("LEURRE", new SurvivalCard(CardName.LEURRE,"Leurre", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("MIMETISME", new SurvivalCard(CardName.MIMETISME,"Mimétisme", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("NAVETTE", new SurvivalCard(CardName.NAVETTE,"Navette", "Lorem ipsum", Phase.PREPHASE_4));
survivalCardMap.put("PLANQUES", new SurvivalCard(CardName.PLANQUES,"Planques", "Lorem ipsum", Phase.PREPHASE_4));
survivalCardMap.put("PORTAIL_SURVIVAL", new SurvivalCard(CardName.PORTAIL_SURVIVAL,"Portail", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("RALLIEMENT", new SurvivalCard(CardName.RALLIEMENT,"Ralliement", "Lorem ipsum", Phase.PREPHASE_4));
survivalCardMap.put("REFUGE", new SurvivalCard(CardName.REFUGE,"Refuge", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("REGENERATION", new SurvivalCard(CardName.REGENERATION,"Régénération", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("RESISTANCE", new SurvivalCard(CardName.RESISTANCE,"Résistance", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("RETRAITE", new SurvivalCard(CardName.RETRAITE,"Retraite", "Lorem ipsum", Phase.PREPHASE_3));
survivalCardMap.put("RIPOSTE", new SurvivalCard(CardName.RIPOSTE,"Riposte", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("SACRIFICE", new SurvivalCard(CardName.SACRIFICE,"Sacrifice", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("SECOND_SOUFFLE", new SurvivalCard(CardName.SECOND_SOUFFLE,"Second souffle", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("SIXIEME_SENS", new SurvivalCard(CardName.SIXIEME_SENS,"Sixième sens", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("SYSTEME_D", new SurvivalCard(CardName.SYSTEME_D,"Système D", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("TENACITE", new SurvivalCard(CardName.TENACITE,"Ténacité", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("VACCIN", new SurvivalCard(CardName.VACCIN,"Vaccin", "Lorem ipsum", Phase.PREPHASE_1));
survivalCardMap.put("VOLTE_FACE", new SurvivalCard(CardName.VOLTE_FACE,"Volte-face", "Lorem ipsum", Phase.PREPHASE_4));
survivalCardMap.put("VORTEX", new SurvivalCard(CardName.VORTEX,"Vortex", "Lorem ipsum", Phase.PREPHASE_2));
}
private void initializeTrackingCardMap(){
......
package fr.univnantes.alma.server;
import fr.univnantes.alma.server.handler.GameServiceHandler;
import fr.univnantes.alma.thrift.GameServerService;
import fr.univnantes.alma.thrift.GameService;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TServlet;
......@@ -28,7 +28,7 @@ public class NotAloneApplication {
@Bean
public ServletRegistrationBean gameServer(TProtocolFactory protocolFactory, GameServiceHandler handler) {
TServlet tServlet = new TServlet(new GameServerService.Processor<GameServiceHandler>(handler), protocolFactory);
TServlet tServlet = new TServlet(new GameService.Processor<GameServiceHandler>(handler), protocolFactory);
return new ServletRegistrationBean(tServlet, "/api");
}
......
......@@ -17,12 +17,12 @@ import fr.univnantes.alma.server.game.item.player.Player;
import fr.univnantes.alma.server.game.item.player.Traque;
import fr.univnantes.alma.server.game.item.power.Power;
import fr.univnantes.alma.server.game.item.power.PowerType;
import fr.univnantes.alma.server.game.item.power.modificator.PowerModificator;
import fr.univnantes.alma.server.game.item.power.modificator.PowerModificatorType;
import fr.univnantes.alma.server.game.item.power.modifier.PowerModifier;
import fr.univnantes.alma.server.game.item.power.modifier.PowerModifierType;
import fr.univnantes.alma.server.game.item.power.recurrent.PowerRecurrent;
import fr.univnantes.alma.server.game.utilitary.Conversion;
import fr.univnantes.alma.server.game.utilitary.Pair;
import fr.univnantes.alma.server.handler.GameClientHandler;
import fr.univnantes.alma.server.handler.PlayerServiceHandler;
import fr.univnantes.alma.thrift.Response;
import fr.univnantes.alma.thrift.TAskAction;
import fr.univnantes.alma.thrift.TPair;
......@@ -113,10 +113,10 @@ public class Game implements GameInterface {
/**
* The game client handler
*/
private GameClientHandler gameClientHandler;
private PlayerServiceHandler playerServiceHandler;
public Game(int playerNumber, int creatureId, Planet planet, Board board, Room room) {
this.gameClientHandler = new GameClientHandler();
this.playerServiceHandler = new PlayerServiceHandler();
this.planet = planet;
this.board = board;
this.board.initializeScore(playerNumber);
......@@ -133,8 +133,8 @@ public class Game implements GameInterface {
sendFirstRoundStart();
}
public Game(int playerNumber, int creatureId, Planet planet, Board board, Room room, GameClientHandler gameClientHandler) {
this.gameClientHandler = gameClientHandler;
public Game(int playerNumber, int creatureId, Planet planet, Board board, Room room, PlayerServiceHandler playerServiceHandler) {
this.playerServiceHandler = playerServiceHandler;
this.planet = planet;
this.board = board;
this.board.initializeScore(playerNumber);
......@@ -494,14 +494,14 @@ public class Game implements GameInterface {
response = new Response(false, "Only the Creature can played jeton");
}
else if(! state.equals(Phase.PHASE_2)) {
if(gameRoundVariables.isJetonCibleBlockPlace() && placedJeton.getJeton().getType().equals(CIBLE)) {
if(gameRoundVariables.isJetonCibleBlockPlace() && placedJeton.getJetonSymbol().equals(CIBLE)) {
response = creaturePlaceAJeton(creature, placedJeton);
}
else {
response = new Response(false, "You can play jeton only in Phase 2");
}
}
else if(gameRoundVariables.refugeIsActive() && placedJeton.getJeton().getType().equals(CIBLE)) {
else if(gameRoundVariables.refugeIsActive() && isJetonCibleOnThisPlace(placedJeton.getPlaces())) {
response = new Response(false, "Can't play JetonCible when Refuge is active");
}
else{
......@@ -556,7 +556,8 @@ public class Game implements GameInterface {
int cardsPerWillingness = 2 + traque.getNumberOfAdditionalCardsTakeBackPerPawnWillingnessLostWithResist();
int numberCard = Math.min(cardsPerWillingness * number, traque.defausseSize());
if(numberCard > 0) {
choosePlaceCardsAction(playerId, numberCard, traque.getDefausse());
List<PlaceCard> chosen = choosePlaceCardsAction(playerId, numberCard, traque.getDefausse());
traque.takeBackPlaceCard(chosen);
}
traque.getRights().setCanGiveUp(false);
traque.getRights().setCanResist(false);
......@@ -607,7 +608,7 @@ public class Game implements GameInterface {
public Action askAction(int inGameIdPlayer, TAskAction askedAction) {
//TODO
try{
return Conversion.toAction(gameClientHandler.askAction(askedAction));
return Conversion.toAction(playerServiceHandler.askAction(askedAction));
}
catch (Exception e){
throw new IllegalArgumentException("Unknown error");
......@@ -757,7 +758,7 @@ public class Game implements GameInterface {
Phase toApplied = trackingCard.getPhaseToApply();
if(toApplied.equals(state)) {
creature.removeTrackingCardToApplied(trackingCard);
applyPlayerCard(creature.getInGameId(), trackingCard, this);
applyPlayerCard(this, creature.getInGameId(), trackingCard);
trackingCardPioche.throwAway(trackingCard);
}
else {
......@@ -851,13 +852,13 @@ public class Game implements GameInterface {
traque.addSurvivalCardToApplied(survivalCard);
}
else{
applyPlayerCard(traque.getInGameId(), survivalCard, this);
applyPlayerCard(this, traque.getInGameId(), survivalCard);
traque.removeSurvivalCardToApplied(survivalCard);
survivalCardPioche.throwAway(survivalCard);
}
}
else{
applyPlayerCard(traque.getInGameId(), survivalCard, this);
applyPlayerCard(this, traque.getInGameId(), survivalCard);
traque.playSurvivalCard(survivalCard);
survivalCardPioche.throwAway(survivalCard);
}
......@@ -947,6 +948,8 @@ public class Game implements GameInterface {
List<TrackingCard> trackingCards = creature.getTrackingCardsPlayed();