Merge branch 'master' of ssh://cryps.gg:40022/~/cryps

This commit is contained in:
ntr 2018-12-20 19:03:13 +11:00
commit a6e91a1442
6 changed files with 67 additions and 27 deletions

View File

@ -208,20 +208,7 @@ class CombatCryps extends Phaser.Scene {
} }
if (key === 'crypStatusUpdate' && data) { if (key === 'crypStatusUpdate' && data) {
const targetCryp = this.cryps.children.entries this.updateCrypStatus(data);
.find(c => c.cryp.id === data.id);
if (this.phase === 'Skill') {
targetCryp.statusText.text = data.target === targetCryp.cryp.account
? `${data.skill} on ally team`
: `${data.skill} on enemy team`;
}
if (this.phase === 'Target') {
const sourceCryp = this.cryps.children.entries
.find(c => c.cryp.id === data.skill.source_cryp_id);
targetCryp.statusText.text = `${sourceCryp.cryp.name} ${data.skill.skill} ${targetCryp.cryp.name}`;
}
} }
return true; return true;
@ -260,6 +247,23 @@ class CombatCryps extends Phaser.Scene {
if (crypId) this.cryps.children.entries.find(c => c.cryp.id === crypId).select(); if (crypId) this.cryps.children.entries.find(c => c.cryp.id === crypId).select();
} }
updateCrypStatus(status) {
const targetCryp = this.cryps.children.entries
.find(c => c.cryp.id === status.id);
if (this.phase === 'Skill') {
targetCryp.statusText.text = status.target === targetCryp.cryp.account
? `${status.skill} on ally team`
: `${status.skill} on enemy team`;
}
if (this.phase === 'Target') {
const sourceCryp = this.cryps.children.entries
.find(c => c.cryp.id === status.skill.source_cryp_id);
targetCryp.statusText.text = `${sourceCryp.cryp.name} ${status.skill.skill} ${targetCryp.cryp.name}`;
}
}
cleanUp() { cleanUp() {
this.registry.events.off('changedata', this.updateData); this.registry.events.off('changedata', this.updateData);
this.scene.remove(); this.scene.remove();

View File

@ -24,8 +24,6 @@ class Combat extends Phaser.Scene {
aztecImg.onload = () => { aztecImg.onload = () => {
this.textures.addAtlas('aztec', aztecImg, aztecAtlas); this.textures.addAtlas('aztec', aztecImg, aztecAtlas);
}; };
// this.textures.addBase64('alk', `data:image/png;base64,${new Buffer.from(fs.readFileSync('./assets/magmar.png')).toString('base64')}`);
// this.textures.addBase64('magmar', `data:image/png;base64,${new Buffer.from(fs.readFileSync('./assets/magmar.png')).toString('base64')}`);
this.load.image('proj', 'https://labs.phaser.io/assets/sprites/bullet.png'); this.load.image('proj', 'https://labs.phaser.io/assets/sprites/bullet.png');
this.load.image('blue', 'https://labs.phaser.io/assets/particles/blue.png'); this.load.image('blue', 'https://labs.phaser.io/assets/particles/blue.png');
this.load.image('green', 'https://labs.phaser.io/assets/particles/green.png'); this.load.image('green', 'https://labs.phaser.io/assets/particles/green.png');

View File

@ -44,6 +44,16 @@ class GameList extends Phaser.GameObjects.Group {
.text(pve.getCenter().x, pve.getCenter().y, 'new PVE\ngame', TEXT.HEADER) .text(pve.getCenter().x, pve.getCenter().y, 'new PVE\ngame', TEXT.HEADER)
.setOrigin(0.5, 0.5)); .setOrigin(0.5, 0.5));
const boss = list.add
.rectangle(X, GAME_LIST.y(2), WIDTH, HEIGHT, 0x441122)
.setInteractive()
.setOrigin(0);
this.add(list.add
.text(boss.getCenter().x, boss.getCenter().y, 'new Boss\ngame', TEXT.HEADER)
.setOrigin(0.5, 0.5));
const refresh = list.add const refresh = list.add
.rectangle(X + WIDTH, GAME_LIST.y(1), WIDTH, HEIGHT, 0x000044) .rectangle(X + WIDTH, GAME_LIST.y(1), WIDTH, HEIGHT, 0x000044)
.setInteractive() .setInteractive()
@ -88,9 +98,16 @@ class GameList extends Phaser.GameObjects.Group {
pve.on('pointerdown', () => { pve.on('pointerdown', () => {
const team = cryps.filter(c => c.active).map(c => c.id); const team = cryps.filter(c => c.active).map(c => c.id);
if (team.length === 0) return false; if (team.length === 0) return false;
return ws.sendGamePve(team); return ws.sendGamePve(team, 'normal');
}); });
boss.on('pointerdown', () => {
const team = cryps.filter(c => c.active).map(c => c.id);
if (team.length === 0) return false;
return ws.sendGamePve(team, 'boss');
});
refresh.on('pointerdown', () => { refresh.on('pointerdown', () => {
return ws.sendGameJoinableList(); return ws.sendGameJoinableList();
}); });

View File

@ -64,8 +64,8 @@ function createSocket(events) {
send({ method: 'game_state', params: { id } }); send({ method: 'game_state', params: { id } });
} }
function sendGamePve(crypIds) { function sendGamePve(crypIds, mode) {
send({ method: 'game_pve', params: { cryp_ids: crypIds } }); send({ method: 'game_pve', params: { cryp_ids: crypIds, mode } });
} }
function sendGamePvp(crypIds) { function sendGamePvp(crypIds) {

View File

@ -753,6 +753,32 @@ fn generate_mob(lvl: u8) -> Cryp {
} }
fn generate_mob_team(mode: String, cryps: &Vec<Cryp>) -> Team {
let mut mob_team = Team::new(Uuid::nil());
// Default settings
let mut team_size = 1;
let mut mob_lvl = 1;
// Modify the NPC cryps for game mode settings
if (mode == "normal") {
team_size = cryps.len();
mob_lvl = cryps.iter().max_by_key(|c| c.lvl).unwrap().lvl;
} else if (mode == "boss") {
mob_lvl = cryps.iter().max_by_key(|c| c.lvl).unwrap().lvl + 2;
}
// Generate and return the NPC team based on settings
let mobs = iter::repeat_with(|| generate_mob(mob_lvl).set_account(Uuid::nil()))
.take(team_size)
.collect::<Vec<Cryp>>();
mob_team.set_cryps(mobs);
return mob_team;
}
pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> { pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
let cryps = params.cryp_ids let cryps = params.cryp_ids
.iter() .iter()
@ -773,19 +799,13 @@ pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account)
.set_team_size(cryps.len()); .set_team_size(cryps.len());
// create the mob team // create the mob team
let mut mob_team = Team::new(Uuid::nil()); let mut mob_team = generate_mob_team(params.mode, &cryps);
let mob_lvl = cryps.iter().max_by_key(|c| c.lvl).unwrap().lvl;
let mobs = iter::repeat_with(|| generate_mob(mob_lvl).set_account(Uuid::nil()))
.take(cryps.len())
.collect::<Vec<Cryp>>();
// add the players // add the players
let mut plr_team = Team::new(account.id); let mut plr_team = Team::new(account.id);
plr_team plr_team
.set_cryps(cryps); .set_cryps(cryps);
mob_team
.set_cryps(mobs);
game game
.team_add(plr_team)? .team_add(plr_team)?

View File

@ -395,6 +395,7 @@ struct GamePveMsg {
#[derive(Debug,Clone,Serialize,Deserialize)] #[derive(Debug,Clone,Serialize,Deserialize)]
pub struct GamePveParams { pub struct GamePveParams {
pub cryp_ids: Vec<Uuid>, pub cryp_ids: Vec<Uuid>,
pub mode: String,
} }
#[derive(Debug,Clone,Serialize,Deserialize)] #[derive(Debug,Clone,Serialize,Deserialize)]