Skip to content

Commit

Permalink
Merge pull request #46 from codergautam/newevols
Browse files Browse the repository at this point in the history
Newevols
  • Loading branch information
codergautam authored May 12, 2024
2 parents 9663a0c + af3bfe9 commit bce6a5a
Show file tree
Hide file tree
Showing 24 changed files with 236 additions and 25 deletions.
Binary file added client/public/assets/game/player/knight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/assets/game/player/rook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/assets/game/player/samurai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/assets/game/player/stalker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/assets/game/player/vampire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions client/src/ServerList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Server {
ping: number;
offline?: boolean;
playerCnt?: number;
realPlayersCnt?: number;
}


Expand Down Expand Up @@ -54,7 +55,7 @@ export async function updatePing() {
if (cache[server.address]) {
server.offline = cache[server.address].offline;
server.ping = cache[server.address].ping;
server.playerCnt = cache[server.address].playerCnt;
server.playerCnt = cache[server.address].realPlayersCnt;
} else {
try {
const data = await fetch(`${window.location.protocol}//${server.address}/serverinfo?${Date.now()}`, {
Expand All @@ -67,7 +68,7 @@ export async function updatePing() {
const json = await data.json()
server.offline = false;
server.ping = Date.now() - start;
server.playerCnt = json.playerCnt;
server.playerCnt = json.realPlayersCnt;
cache[server.address] = server;
} catch (e) {

Expand Down
8 changes: 8 additions & 0 deletions client/src/game/Controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ export class Controls {
});
this.joystick.on('pointerup', () => {
this.joystickPointer = null;
this.joystick.setVisible(false);
})
this.game.input.on('pointerdown', (pointer: Phaser.Input.Pointer) => {
if (pointer.x < this.game.scale.width / 2 && !this.joystick.visible) {
this.joystick.setPosition(pointer.x, pointer.y);
this.joystick.setVisible(true);
}
});

input.addPointer(2);
}

Expand Down
5 changes: 5 additions & 0 deletions client/src/game/Evolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ import { EvolutionTypes } from './Types';
export const Evolutions: Record<any, [string, string, number, [number, number]]> = {
[EvolutionTypes.Tank]: ['Tank', 'tankOverlay', 1, [0.5, 0.55]],
[EvolutionTypes.Berserker]: ['Berserker', 'berserkerOverlay', 1.18, [0.47, 0.6]],
[EvolutionTypes.Vampire]: ['Vampire', 'vampireOverlay', 1.09, [0.5, 0.53]],
[EvolutionTypes.Knight]: ['Knight', 'knightOverlay', 1.09, [0.5, 0.53]],
[EvolutionTypes.Samurai]: ['Samurai', 'samuraiOverlay', 1.09, [0.5, 0.53]],
[EvolutionTypes.Rook]: ['Rook', 'rookOverlay', 1.09, [0.5, 0.53]],
[EvolutionTypes.Stalker]: ['Stalker', 'stalkerOverlay', 1.09, [0.5, 0.53]],
};
5 changes: 5 additions & 0 deletions client/src/game/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export enum EvolutionTypes {
Default = 0,
Tank = 1,
Berserker = 2,
Vampire = 3,
Knight = 4,
Samurai = 5,
Rook = 6,
Stalker = 7,
}

export enum BuffTypes {
Expand Down
8 changes: 8 additions & 0 deletions client/src/game/scenes/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class Game extends Phaser.Scene {
this.gameState.initialize();
this.game.canvas.oncontextmenu = (e) => e.preventDefault();
this.isMobile = this.game.device.os.android || this.game.device.os.iOS;
// this.isMobile = true
}

preload() {
Expand Down Expand Up @@ -77,8 +78,15 @@ export default class Game extends Phaser.Scene {
this.load.image('chest6', publicPath + '/assets/game/Chest6.png');

this.load.image('crown', publicPath + '/assets/game/player/crown.png');

// evols
this.load.image('tankOverlay', publicPath + '/assets/game/player/tank.png');
this.load.image('berserkerOverlay', publicPath + '/assets/game/player/berserker.png');
this.load.image('vampireOverlay', publicPath + '/assets/game/player/vampire.png');
this.load.image('knightOverlay', publicPath + '/assets/game/player/knight.png');
this.load.image('samuraiOverlay', publicPath + '/assets/game/player/samurai.png');
this.load.image('rookOverlay', publicPath + '/assets/game/player/rook.png');
this.load.image('stalkerOverlay', publicPath + '/assets/game/player/stalker.png');

this.load.image('hitParticle', publicPath + '/assets/game/particles/hit.png');
this.load.image('starParticle', publicPath + '/assets/game/particles/star.png');
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function App() {
}, 10);

if(!firstGame) return;
// setModal(<ChangelogModal />);
setModal(<ChangelogModal />);
}, [gameStarted]);

const [server, setServer] = useState(Settings.server);
Expand Down
11 changes: 6 additions & 5 deletions client/src/ui/modals/ChangelogModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import './ChangelogModal.scss';
function ChangelogModal() {
return (
<div className="changelog">
<h1 style={{fontSize: 30}}>Sunsetting swordbattle.io</h1>
<p>We regret to announce that swordbattle.io will be discontinued soon. Thank you for your support and engagement over the years! The game servers will be shutdown within the next week.</p>
<p>In the meantime, we encourage our community to get involved one last time. Show your creativity by designing your own game skins:</p>
<a className="primary-link" target="_blank" href="https://iogames.forum/t/how-to-make-your-own-swordbattle-io-skin/585">
<h1 style={{fontSize: 30}}>Evolution Revamp! (May 11th, 2024)</h1>
<li>- 4 new evolutions added!</li>
<li>- Balancing and improvements to PvP</li>
<li>- Improved Mobile Controls</li>
{/* <a className="primary-link" target="_blank" href="https://iogames.forum/t/how-to-make-your-own-swordbattle-io-skin/585">
Create your own skins to be added in the game!
</a>
</a>*/}
<p>Stay tuned for more updates and future projects from our team.</p>
</div>

Expand Down
5 changes: 5 additions & 0 deletions server/src/game/Types.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ module.exports = {
Basic: 0,
Tank: 1,
Berserker: 2,
Vampire: 3,
Knight: 4,
Samurai: 5,
Rook: 6,
Stalker: 7,
},
Buff: {
Speed: 1,
Expand Down
4 changes: 4 additions & 0 deletions server/src/game/components/Health.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Health {
}
}

gain(amount) {
this.percent = Math.min(this.percent + amount / this.max.value, 1);
}

update(dt) {
if(Date.now() - this.lastDamage < this.regenWait.value) return;
const coef = this.regen.value / this.max.value * dt;
Expand Down
20 changes: 20 additions & 0 deletions server/src/game/entities/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Player extends Entity {
this.evolutions = new EvolutionSystem(this);
this.tamedWolves = new Set();

this.modifiers = {};

this.chatMessage = '';
this.chatMessageTimer = new Timer(0, 3);
}
Expand Down Expand Up @@ -221,6 +223,16 @@ class Player extends Entity {
this.movementDirection = mouseAngle;
dx = speed * Math.cos(this.movementDirection);
dy = speed * Math.sin(this.movementDirection);

if(this.modifiers.disableDiagonalMovement) {
if (Math.abs(dx) > Math.abs(dy)) {
dy = 0;
dx = dx > 0 ? speed : -speed;
} else {
dx = 0;
dy = dy > 0 ? speed : -speed;
}
}
} else {
let directionX = 0;
let directionY = 0;
Expand All @@ -241,6 +253,13 @@ class Player extends Entity {
this.movementDirection = Math.atan2(directionY, directionX);
dx = speed * Math.cos(this.movementDirection);
dy = speed * Math.sin(this.movementDirection);

if(this.modifiers.disableDiagonalMovement) {
if (directionX !== 0 && directionY !== 0) {
dy = directionY * speed;
dx = 0;
}
}
} else {
this.movementDirection = 0;
}
Expand Down Expand Up @@ -360,6 +379,7 @@ class Player extends Entity {
super.cleanup();
this.sword.cleanup();
this.flags.clear();
this.modifiers = {};

[this.speed, this.regeneration, this.friction, this.viewport.zoom, this.knockbackResistance, this.health.regenWait].forEach((property) => property.reset());
}
Expand Down
4 changes: 4 additions & 0 deletions server/src/game/entities/Sword.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ class Sword extends Entity {
entity.velocity.y = -1*yComp;
entity.damaged(this.damage.value, this.player);

if(this.player.modifiers.leech) {
this.player.health.gain(this.damage.value * this.player.modifiers.leech);
}

this.collidedEntities.add(entity);
this.player.flags.set(Types.Flags.EnemyHit, entity.id);

Expand Down
13 changes: 7 additions & 6 deletions server/src/game/evolutions/Berserker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ const Types = require('../Types');

module.exports = class Berserker extends Evolution {
static type = Types.Evolution.Berserker;
static level = 10;
static level = 13;
static previousEvol = Types.Evolution.Knight;
static abilityDuration = 7;
static abilityCooldown = 50;
static abilityCooldown = 60;

applyAbilityEffects() {
this.player.sword.damage.multiplier *= 1.25;
this.player.sword.damage.multiplier *= 1.15;
this.player.sword.knockback.multiplier['ability'] = 1.8;
this.player.speed.multiplier *= 1.5;
this.player.sword.swingDuration.multiplier['ability'] = 0.6;
}

update(dt) {
super.update(dt);

this.player.sword.damage.multiplier *= 1.2;
this.player.knockbackResistance.multiplier *= 1.1;
this.player.sword.damage.multiplier *= 1.1;
this.player.knockbackResistance.multiplier *= 1.05;
this.player.speed.multiplier *= 1.1;
this.player.health.max.multiplier *= 0.9;
}
}

25 changes: 25 additions & 0 deletions server/src/game/evolutions/Knight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const Evolution = require('./BasicEvolution');
const Types = require('../Types');

module.exports = class Knight extends Evolution {
static type = Types.Evolution.Knight;
static level = 8;
static abilityDuration = 6;
static abilityCooldown = 90;

applyAbilityEffects() {
this.player.sword.damage.multiplier *= 1.15;
this.player.sword.knockback.multiplier['ability'] = 1.8;
this.player.speed.multiplier *= 1.5;
this.player.sword.swingDuration.multiplier['ability'] = 0.6;
}

update(dt) {
super.update(dt);

this.player.sword.damage.multiplier *= 1.1;
// this.player.knockbackResistance.multiplier *= 1.05;
this.player.speed.multiplier *= 1.05;
this.player.health.max.multiplier *= 0.9;
}
}
49 changes: 49 additions & 0 deletions server/src/game/evolutions/Rook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const Evolution = require('./BasicEvolution');
const Types = require('../Types');

module.exports = class Rook extends Evolution {
static type = Types.Evolution.Rook;
static level = 13;
static previousEvol = Types.Evolution.Tank;
static abilityDuration = 0.1;
static abilityCooldown = 40;

applyAbilityEffects() {
const downInputs = this.player.inputs?.downInputs;

let angle = Math.PI / 2; // dwn

if(downInputs && downInputs.length > 0) {
switch (downInputs[0]) {
case 1:
angle = -Math.PI / 2;
break;
case 2:
angle = 0;
break;
case 3:
angle = Math.PI / 2;
break;
case 4:
angle = Math.PI;
break;
}
}

this.player.shape.x = this.player.shape.x + (10000000 * Math.cos(angle));
this.player.shape.y = this.player.shape.y + (10000000 * Math.sin(angle));
}

update(dt) {
this.player.modifiers.disableDiagonalMovement = true;

this.player.shape.setScale(1.25);
this.player.sword.damage.multiplier *= 1.2;
this.player.sword.knockback.multiplier['ability'] = 1.25;
this.player.knockbackResistance.multiplier *= 1.25;
this.player.health.max.multiplier *= 1.25;
this.player.health.regen.multiplier *= 1.25;
this.player.health.regenWait.multiplier *= 1.15;
super.update(dt);
}
}
35 changes: 35 additions & 0 deletions server/src/game/evolutions/Samurai.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Evolution = require('./BasicEvolution');
const Types = require('../Types');

module.exports = class Samurai extends Evolution {
static type = Types.Evolution.Samurai;
static level = 13;
static previousEvol = Types.Evolution.Tank;
static abilityDuration = 6;
static abilityCooldown = 60;

applyAbilityEffects() {
this.player.sword.damage.multiplier *= 1.5;
this.player.sword.knockback.multiplier['ability'] = 2.5;
this.player.knockbackResistance.multiplier *= 1.5;
this.player.health.regen.multiplier *= 8;
this.player.speed.multiplier *= 1.25;


this.player.health.regenWait.multiplier = 0;
this.player.sword.swingDuration.multiplier['ability'] = 0.5;
}

update(dt) {
super.update(dt);
this.player.speed.multiplier *= 0.85;
this.player.shape.setScale(1.05);
this.player.sword.damage.multiplier *= 1.15;
this.player.sword.knockback.multiplier['ability'] = 1.15;
this.player.knockbackResistance.multiplier *= 1.15;
this.player.health.max.multiplier *= 1.15;
this.player.health.regen.multiplier *= 1.15;
this.player.health.regenWait.multiplier *= 1;
//TODO: Damagecooldown: 1.1
}
}
17 changes: 17 additions & 0 deletions server/src/game/evolutions/Stalker.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// const Evolution = require('./BasicEvolution');
// const Types = require('../Types');

// module.exports = class Stalker extends Evolution {
// static type = Types.Evolution.Stalker;
// static level = 3;
// static previousEvol = Types.Evolution.Vampire;
// static abilityDuration = 6;
// static abilityCooldown = 90;

// applyAbilityEffects() {
// }

// update(dt) {
// super.update(dt);
// }
// }
19 changes: 9 additions & 10 deletions server/src/game/evolutions/Tank.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,30 @@ const Types = require('../Types');

module.exports = class Tank extends Evolution {
static type = Types.Evolution.Tank;
static level = 10;
static level = 8;
static abilityDuration = 6;
static abilityCooldown = 90;

applyAbilityEffects() {
this.player.sword.damage.multiplier *= 2;
this.player.sword.damage.multiplier *= 1.5;
this.player.sword.knockback.multiplier['ability'] = 2.5;
this.player.knockbackResistance.multiplier *= 1.5;
this.player.shape.setScale(1.75);
this.player.health.regen.multiplier *= 8;

// todo: fix bug why it cant be 0 (it doesnt recover then)
this.player.health.regenWait.multiplier = 0;
this.player.sword.swingDuration.multiplier['ability'] = 0.5;
}

update(dt) {
super.update(dt);
this.player.speed.multiplier *= 0.75;
this.player.shape.setScale(1.25);
this.player.sword.damage.multiplier *= 1.25;
this.player.sword.knockback.multiplier['ability'] = 1.25;
this.player.knockbackResistance.multiplier *= 1.25;
this.player.health.max.multiplier *= 1.25;
this.player.health.regen.multiplier *= 1.25;
this.player.speed.multiplier *= 0.7;
this.player.shape.setScale(1.15);
this.player.sword.damage.multiplier *= 1.15;
this.player.sword.knockback.multiplier['ability'] = 1.15;
this.player.knockbackResistance.multiplier *= 1.15;
this.player.health.max.multiplier *= 1.15;
this.player.health.regen.multiplier *= 1.15;
this.player.health.regenWait.multiplier *= 1;
//TODO: Damagecooldown: 1.1
}
Expand Down
Loading

0 comments on commit bce6a5a

Please sign in to comment.