Skip to content

Commit

Permalink
feat(combat): added multiple sizes for trees, fixed word filter, comb…
Browse files Browse the repository at this point in the history
…at changes

added multiple sizes for trees, fixed word filter to not filter words like hello with banned words
in them, added health to /set command, added weapon data for all weapons, added item data, optimized
for local development, fixed knockback scale
  • Loading branch information
Project-Magenta committed Jul 24, 2020
1 parent 5671bc2 commit 62a86ce
Show file tree
Hide file tree
Showing 12 changed files with 2,152 additions and 79 deletions.
4 changes: 4 additions & 0 deletions .data/sanctuary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"bannedIPs": [],
"moderatorIPs": []
}
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^14.0.1",
"@types/node": "^14.0.24",
"cz-conventional-changelog": "3.2.0",
"typescript": "^3.9.2"
},
"dependencies": {
Expand All @@ -36,6 +37,11 @@
"ws": "^7.3.1"
},
"engines": {
"node": "10.x"
"node": ">=10.x"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
6 changes: 6 additions & 0 deletions src/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ dispatcher.register(
player.wood = resourceAmount;
break;

case "health":
case "hp":
case "hitpoints":
player.health = resourceAmount;
break;

default:
error("Invalid resource type " + resourceType);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/gameobjects/gameobjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ enum GameObjectType {
Cactus
}

let gameObjectSizes: Partial<Record<GameObjectType, number>> = { };
gameObjectSizes[GameObjectType.Tree] = 140;
let gameObjectSizes: Partial<Record<GameObjectType, number[]>> = { };
gameObjectSizes[GameObjectType.Tree] = [150, 160, 165, 175];

gameObjectSizes = Object.freeze(gameObjectSizes);

Expand Down
1 change: 1 addition & 0 deletions src/items/items.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"group":{"id":0,"name":"food","layer":0},"name":"apple","desc":"restores 20 health when consumed","req":["food",10],"scale":22,"holdOffset":15},{"age":3,"group":{"id":0,"name":"food","layer":0},"name":"cookie","desc":"restores 40 health when consumed","req":["food",15],"scale":27,"holdOffset":15},{"age":7,"group":{"id":0,"name":"food","layer":0},"name":"cheese","desc":"restores 30 health and another 50 over 5 seconds","req":["food",25],"scale":27,"holdOffset":15},{"group":{"id":1,"name":"walls","place":true,"limit":30,"layer":0},"name":"wood wall","desc":"provides protection for your village","req":["wood",10],"projDmg":true,"health":380,"scale":50,"holdOffset":20,"placeOffset":-5},{"age":3,"group":{"id":1,"name":"walls","place":true,"limit":30,"layer":0},"name":"stone wall","desc":"provides improved protection for your village","req":["stone",25],"health":900,"scale":50,"holdOffset":20,"placeOffset":-5},{"age":7,"pre":1,"group":{"id":1,"name":"walls","place":true,"limit":30,"layer":0},"name":"castle wall","desc":"provides powerful protection for your village","req":["stone",35],"health":1500,"scale":52,"holdOffset":20,"placeOffset":-5},{"group":{"id":2,"name":"spikes","place":true,"limit":15,"layer":0},"name":"spikes","desc":"damages enemies when they touch them","req":["wood",20,"stone",5],"health":400,"dmg":20,"scale":49,"spritePadding":-23,"holdOffset":8,"placeOffset":-5},{"age":5,"group":{"id":2,"name":"spikes","place":true,"limit":15,"layer":0},"name":"greater spikes","desc":"damages enemies when they touch them","req":["wood",30,"stone",10],"health":500,"dmg":35,"scale":52,"spritePadding":-23,"holdOffset":8,"placeOffset":-5},{"age":9,"pre":1,"group":{"id":2,"name":"spikes","place":true,"limit":15,"layer":0},"name":"poison spikes","desc":"poisons enemies when they touch them","req":["wood",35,"stone",15],"health":600,"dmg":30,"pDmg":5,"scale":52,"spritePadding":-23,"holdOffset":8,"placeOffset":-5},{"age":9,"pre":2,"group":{"id":2,"name":"spikes","place":true,"limit":15,"layer":0},"name":"spinning spikes","desc":"damages enemies when they touch them","req":["wood",30,"stone",20],"health":500,"dmg":45,"turnSpeed":0.003,"scale":52,"spritePadding":-23,"holdOffset":8,"placeOffset":-5},{"group":{"id":3,"name":"mill","place":true,"limit":7,"layer":1},"name":"windmill","desc":"generates gold over time","req":["wood",50,"stone",10],"health":400,"pps":1,"turnSpeed":0.0016,"spritePadding":25,"iconLineMult":12,"scale":45,"holdOffset":20,"placeOffset":5},{"age":5,"pre":1,"group":{"id":3,"name":"mill","place":true,"limit":7,"layer":1},"name":"faster windmill","desc":"generates more gold over time","req":["wood",60,"stone",20],"health":500,"pps":1.5,"turnSpeed":0.0025,"spritePadding":25,"iconLineMult":12,"scale":47,"holdOffset":20,"placeOffset":5},{"age":8,"pre":1,"group":{"id":3,"name":"mill","place":true,"limit":7,"layer":1},"name":"power mill","desc":"generates more gold over time","req":["wood",100,"stone",50],"health":800,"pps":2,"turnSpeed":0.005,"spritePadding":25,"iconLineMult":12,"scale":47,"holdOffset":20,"placeOffset":5},{"age":5,"group":{"id":4,"name":"mine","place":true,"limit":1,"layer":0},"type":2,"name":"mine","desc":"allows you to mine stone","req":["wood",20,"stone",100],"iconLineMult":12,"scale":65,"holdOffset":20,"placeOffset":0},{"age":5,"group":{"id":11,"name":"sapling","place":true,"limit":2,"layer":0},"type":0,"name":"sapling","desc":"allows you to farm wood","req":["wood",150],"iconLineMult":12,"colDiv":0.5,"scale":110,"holdOffset":50,"placeOffset":-15},{"age":4,"group":{"id":5,"name":"trap","place":true,"limit":6,"layer":-1},"name":"pit trap","desc":"pit that traps enemies if they walk over it","req":["wood",30,"stone",30],"trap":true,"ignoreCollision":true,"hideFromEnemy":true,"health":500,"colDiv":0.2,"scale":50,"holdOffset":20,"placeOffset":-5},{"age":4,"group":{"id":6,"name":"booster","place":true,"limit":12,"layer":-1},"name":"boost pad","desc":"provides boost when stepped on","req":["stone",20,"wood",5],"ignoreCollision":true,"boostSpeed":1.5,"health":150,"colDiv":0.7,"scale":45,"holdOffset":20,"placeOffset":-5},{"age":7,"group":{"id":7,"name":"turret","place":true,"limit":2,"layer":1},"doUpdate":true,"name":"turret","desc":"defensive structure that shoots at enemies","req":["wood",200,"stone",150],"health":800,"projectile":1,"shootRange":700,"shootRate":2200,"scale":43,"holdOffset":20,"placeOffset":-5},{"age":7,"group":{"id":8,"name":"watchtower","place":true,"limit":12,"layer":1},"name":"platform","desc":"platform to shoot over walls and cross over water","req":["wood",20],"ignoreCollision":true,"zIndex":1,"health":300,"scale":43,"holdOffset":20,"placeOffset":-5},{"age":7,"group":{"id":9,"name":"buff","place":true,"limit":4,"layer":-1},"name":"healing pad","desc":"standing on it will slowly heal you","req":["wood",30,"food",10],"ignoreCollision":true,"healCol":15,"health":400,"colDiv":0.7,"scale":45,"holdOffset":20,"placeOffset":-5},{"age":9,"group":{"id":10,"name":"spawn","place":true,"limit":1,"layer":-1},"name":"spawn pad","desc":"you will spawn here when you die but it will dissapear","req":["wood",100,"stone",100],"health":400,"ignoreCollision":true,"spawnPoint":true,"scale":45,"holdOffset":20,"placeOffset":-5},{"age":7,"group":{"id":12,"name":"blocker","place":true,"limit":3,"layer":-1},"name":"blocker","desc":"blocks building in radius","req":["wood",30,"stone",25],"ignoreCollision":true,"blocker":300,"health":400,"colDiv":0.7,"scale":45,"holdOffset":20,"placeOffset":-5},{"age":7,"group":{"id":13,"name":"teleporter","place":true,"limit":2,"layer":-1},"name":"teleporter","desc":"teleports you to a random point on the map","req":["wood",60,"stone",60],"ignoreCollision":true,"teleport":true,"health":200,"colDiv":0.7,"scale":45,"holdOffset":20,"placeOffset":-5}]
59 changes: 7 additions & 52 deletions src/items/items.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import weapons from './weapons.json';

/**
* An enum containing the names of all the items. Saves you the effort of differentiating weapon items and other items
*/
Expand Down Expand Up @@ -79,61 +81,14 @@ function getHitTime(weapon: Weapons) {
}
}

function getWeaponAttackDetails(item: Weapons) {
switch (item) {
case Weapons.ToolHammer:
return { kbMultiplier: 1, attackRange: 10 };
default:
return { kbMultiplier: 2.1, attackRange: 10 };
}
function getWeaponAttackDetails(item: Weapons): AttackDetails {
let weapon = weapons.find(weapon => weapon.id == item);
return { kbMultiplier: weapon?.knock || 1, attackRange: weapon?.range || 10 };
}

function getWeaponDamage(item: Weapons) {
switch (item) {
case Weapons.ToolHammer:
return 25;

case Weapons.Axe:
return 560;

case Weapons.Bat:
return 450;

case Weapons.Bow:
return 785;

case Weapons.Crossbow:
return 900;

case Weapons.Daggers:
return 225;

case Weapons.GreatHammer:
return 560;

case Weapons.McGrabby:
return 900;

case Weapons.Musket:
return 1685;

case Weapons.Polearm:
return 900;

case Weapons.RepeaterCrossbow:
return 450;

case Weapons.Shield:
throw 'Shield does not have damage!';

case Weapons.Stick:
return 560;

case Weapons.Sword:
return 450;
}

return 0;
let weapon = weapons.find(weapon => weapon.id == item);
return weapon?.dmg || 0;
}

function getWeaponId(item: Weapons): number {
Expand Down
1 change: 1 addition & 0 deletions src/items/weapons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":0,"type":0,"name":"tool hammer","desc":"tool for gathering all resources","src":"hammer_1","length":140,"width":140,"xOff":-3,"yOff":18,"dmg":25,"range":65,"gather":1,"speed":300},{"id":1,"type":0,"age":2,"name":"hand axe","desc":"gathers resources at a higher rate","src":"axe_1","length":140,"width":140,"xOff":3,"yOff":24,"dmg":30,"spdMult":1,"range":70,"gather":2,"speed":400},{"id":2,"type":0,"age":8,"pre":1,"name":"great axe","desc":"deal more damage and gather more resources","src":"great_axe_1","length":140,"width":140,"xOff":-8,"yOff":25,"dmg":35,"spdMult":1,"range":75,"gather":4,"speed":400},{"id":3,"type":0,"age":2,"name":"short sword","desc":"increased attack power but slower move speed","src":"sword_1","iPad":1.3,"length":130,"width":210,"xOff":-8,"yOff":46,"dmg":35,"spdMult":0.85,"range":110,"gather":1,"speed":300},{"id":4,"type":0,"age":8,"pre":3,"name":"katana","desc":"greater range and damage","src":"samurai_1","iPad":1.3,"length":130,"width":210,"xOff":-8,"yOff":59,"dmg":40,"spdMult":0.8,"range":118,"gather":1,"speed":300},{"id":5,"type":0,"age":2,"name":"polearm","desc":"long range melee weapon","src":"spear_1","iPad":1.3,"length":130,"width":210,"xOff":-8,"yOff":53,"dmg":45,"knock":0.2,"spdMult":0.82,"range":142,"gather":1,"speed":700},{"id":6,"type":0,"age":2,"name":"bat","desc":"fast long range melee weapon","src":"bat_1","iPad":1.3,"length":110,"width":180,"xOff":-8,"yOff":53,"dmg":20,"knock":0.7,"range":110,"gather":1,"speed":300},{"id":7,"type":0,"age":2,"name":"daggers","desc":"really fast short range weapon","src":"dagger_1","iPad":0.8,"length":110,"width":110,"xOff":18,"yOff":0,"dmg":20,"knock":0.1,"range":65,"gather":1,"hitSlow":0.1,"spdMult":1.13,"speed":100},{"id":8,"type":0,"age":2,"name":"stick","desc":"great for gathering but very weak","src":"stick_1","length":140,"width":140,"xOff":3,"yOff":24,"dmg":1,"spdMult":1,"range":70,"gather":7,"speed":400},{"id":9,"type":1,"age":6,"name":"hunting bow","desc":"bow used for ranged combat and hunting","src":"bow_1","req":["wood",4],"length":120,"width":120,"xOff":-6,"yOff":0,"projectile":0,"spdMult":0.75,"speed":600},{"id":10,"type":1,"age":6,"name":"great hammer","desc":"hammer used for destroying structures","src":"great_hammer_1","length":140,"width":140,"xOff":-9,"yOff":25,"dmg":10,"spdMult":0.88,"range":75,"sDmg":7.5,"gather":1,"speed":400},{"id":11,"type":1,"age":6,"name":"wooden shield","desc":"blocks projectiles and reduces melee damage","src":"shield_1","length":120,"width":120,"shield":0.2,"xOff":6,"yOff":0,"spdMult":0.7},{"id":12,"type":1,"age":8,"pre":9,"name":"crossbow","desc":"deals more damage and has greater range","src":"crossbow_1","req":["wood",5],"aboveHand":true,"armS":0.75,"length":120,"width":120,"xOff":-4,"yOff":0,"projectile":2,"spdMult":0.7,"speed":700},{"id":13,"type":1,"age":9,"pre":12,"name":"repeater crossbow","desc":"high firerate crossbow with reduced damage","src":"crossbow_2","req":["wood",10],"aboveHand":true,"armS":0.75,"length":120,"width":120,"xOff":-4,"yOff":0,"projectile":3,"spdMult":0.7,"speed":230},{"id":14,"type":1,"age":6,"name":"mc grabby","desc":"steals resources from enemies","src":"grab_1","length":130,"width":210,"xOff":-8,"yOff":53,"dmg":0,"steal":250,"knock":0.2,"spdMult":1.05,"range":125,"gather":0,"speed":700},{"id":15,"type":1,"age":9,"pre":12,"name":"musket","desc":"slow firerate but high damage and range","src":"musket_1","req":["stone",10],"aboveHand":true,"rec":0.35,"armS":0.6,"hndS":0.3,"hndD":1.6,"length":205,"width":205,"xOff":25,"yOff":0,"projectile":5,"hideProjectile":true,"spdMult":0.6,"speed":1500}]
38 changes: 21 additions & 17 deletions src/moomoo/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,26 @@ export default class Game {
outerLoop: for (let i = 0; i < 200; i++) {
let gameObjectType =
gameObjectTypes[Math.floor(Math.random() * gameObjectTypes.length)];
let newGameObject = new GameObject(
this.state.gameObjects.length > 0
? Math.max(...this.state.gameObjects.map((gameObj) => gameObj.id)) + 1
: 0,
randomPos(12e3, 12e3),
0,
gameObjectSizes[gameObjectType],
gameObjectType
);
let sizes = gameObjectSizes[gameObjectType];

if (sizes) {
let newGameObject = new GameObject(
this.state.gameObjects.length > 0
? Math.max(...this.state.gameObjects.map((gameObj) => gameObj.id)) + 1
: 0,
randomPos(12e3, 12e3),
0,
sizes[Math.floor(Math.random() * sizes.length)],
gameObjectType
);

for (let gameObject of this.state.gameObjects) {
if (Physics.collideGameObjects(gameObject, newGameObject))
continue outerLoop;
}
for (let gameObject of this.state.gameObjects) {
if (Physics.collideGameObjects(gameObject, newGameObject))
continue outerLoop;
}

this.state.gameObjects.push(newGameObject);
this.state.gameObjects.push(newGameObject);
}
}
}

Expand Down Expand Up @@ -176,7 +180,7 @@ export default class Game {

async banClient(client: Client) {
if (this.db) {
if (!(await (await (await this.db.get("bannedIPs")).includes(client.ip)).value())){
if (!(await (await (await this.db.get("bannedIPs")).includes(client.ip)).value())) {
await (await (await this.db.get("bannedIPs")).push(client.ip)).write();
}

Expand Down Expand Up @@ -336,7 +340,7 @@ export default class Game {
},
[]
)
]
]
)
)
);
Expand Down Expand Up @@ -589,7 +593,7 @@ export default class Game {
case PacketType.CHAT:
for (let badWord of badWords) {
if (packet.data[0].includes(badWord))
packet.data[0] = packet.data[0].replace(new RegExp(badWord.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), "M" + "o".repeat(badWord.length - 1));
packet.data[0] = packet.data[0].replace(new RegExp(`\\b${badWord.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'g'), "M" + "o".repeat(badWord.length - 1));
}

if (packet.data[0].startsWith("/")) {
Expand Down
8 changes: 4 additions & 4 deletions src/moomoo/Physics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function movePlayer(player: Player, delta: number) {
if (player.velocity.x || player.velocity.y) {
let angle = Math.atan2(player.velocity.y, player.velocity.x);
tryMovePlayer(player, delta, player.velocity.x, player.velocity.y);
player.velocity = player.velocity.multiply(.85, .85);
player.velocity = player.velocity.multiply(0.993 ** delta, 0.993 ** delta);
}
}

Expand All @@ -51,23 +51,23 @@ function checkAttack(player: Player, angle: number, players: Player[]) {
let hitPlayers: Player[] = [];

for (let hitPlayer of players) {
if (collideCircles(getAttackLocation(player), 10, hitPlayer.location, 35 * 2))
if (pointCircle(getAttackLocation(player), hitPlayer.location, 35 * 2))
hitPlayers.push(hitPlayer);
}

return hitPlayers;
}

function collideGameObjects(gameObject1: GameObject, gameObject2: GameObject) {
return collideCircles(gameObject1.location, gameObjectSizes[gameObject1.type] || 0, gameObject2.location, gameObjectSizes[gameObject2.type] || 0);
return collideCircles(gameObject1.location, gameObject1.scale, gameObject2.location, gameObject1.scale);
}

function checkAttackGameObj(player: Player, angle: number, gameObjects: GameObject[]) {
let weaponDetails = getWeaponAttackDetails(player.weapon);
let hitGameObjects: GameObject[] = [];

for (let gameObject of gameObjects) {
if (collideCircles(getAttackLocation(player), 10, gameObject.location, gameObjectSizes[gameObject.type] || 0))
if (pointCircle(getAttackLocation(player), gameObject.location, gameObject.scale))
hitGameObjects.push(gameObject);
}

Expand Down
1 change: 0 additions & 1 deletion src/moomoo/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export default class Player extends Entity {

public set points(newPoints: number) {
let packetFactory = PacketFactory.getInstance();
console.log("send");
this.client?.socket.send(
packetFactory.serializePacket(
new Packet(PacketType.UPDATE_STATS, ["points", newPoints, 1])
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ server.on('upgrade', function upgrade(request, socket, head) {

console.startConsole();

server.listen(3000, () => console.log(`Sanctuary listening at https://localhost:${port}`));
server.listen(port || 3000, () => console.log(`Sanctuary listening at https://localhost:${port || 3000}`));
Loading

0 comments on commit 62a86ce

Please sign in to comment.