graben auf G und Knochen
This commit is contained in:
parent
71c86ecb6b
commit
1862fcd955
10
css/main.css
10
css/main.css
@ -295,6 +295,14 @@
|
|||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item_item_spaten3 {
|
||||||
|
background: url(../img/items.png) -59px -149px;
|
||||||
|
width: 30px;
|
||||||
|
background-size: 476px;
|
||||||
|
margin-left: 5px;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
.item_weapon_stick1 {
|
.item_weapon_stick1 {
|
||||||
background: url(../img/items.png) -150px -91px;
|
background: url(../img/items.png) -150px -91px;
|
||||||
width: 30px;
|
width: 30px;
|
||||||
@ -303,7 +311,7 @@
|
|||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item_item_bone1 {
|
.item_item_bone0 {
|
||||||
background: url(../img/items.png) -356px -29px;
|
background: url(../img/items.png) -356px -29px;
|
||||||
width: 30px;
|
width: 30px;
|
||||||
background-size: 476px;
|
background-size: 476px;
|
||||||
|
17
js/main.js
17
js/main.js
@ -39,7 +39,8 @@ var tooltiptexts = {
|
|||||||
"item_weapon_sword4": "Schwert: Schaden erhöht 500",
|
"item_weapon_sword4": "Schwert: Schaden erhöht 500",
|
||||||
"item_weapon_sword5": "Schwert: Schaden erhöht 600",
|
"item_weapon_sword5": "Schwert: Schaden erhöht 600",
|
||||||
"item_weapon_stick1": "Stock: Schaden +20",
|
"item_weapon_stick1": "Stock: Schaden +20",
|
||||||
"item_item_bone1": "Knochen: Schaden +5",
|
"item_item_bone0": "Ganz toller Knochen!",
|
||||||
|
"item_item_spaten3": "Spaten: Schneller graben",
|
||||||
"item_consumable_fish1": "Erhöht deine Lebenspunkte um 20",
|
"item_consumable_fish1": "Erhöht deine Lebenspunkte um 20",
|
||||||
"item_consumable_fish2": "Erhöht deine Lebenspunkte um 10",
|
"item_consumable_fish2": "Erhöht deine Lebenspunkte um 10",
|
||||||
"item_item_dimond1": "Verkaufe den Diamand für 10 Siegpunkte! Bewegungsgeschwindigkeit verlangsamt!",
|
"item_item_dimond1": "Verkaufe den Diamand für 10 Siegpunkte! Bewegungsgeschwindigkeit verlangsamt!",
|
||||||
@ -363,13 +364,9 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(document).keydown(function (event) {
|
$(document).keydown(function (event) {
|
||||||
//console.log(event.which)
|
|
||||||
if (event.ctrlKey == true && (event.which == '61' || event.which == '107' || event.which == '173' || event.which == '109' || event.which == '187' || event.which == '189')) {
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
var key = event.which;
|
var key = event.which;
|
||||||
//console.log(key);
|
//console.log(key);
|
||||||
if (key == 37 || key == 38 || key == 39 || key == 40)
|
if (key == 37 || key == 38 || key == 39 || key == 40 || key == 71)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (!keys[key]) {
|
if (!keys[key]) {
|
||||||
|
|
||||||
@ -379,13 +376,19 @@ $(document).ready(function () {
|
|||||||
socket.emit("keyDown", key);
|
socket.emit("keyDown", key);
|
||||||
}
|
}
|
||||||
keys[key] = true;
|
keys[key] = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
//console.log(event.which)
|
||||||
|
if (event.ctrlKey == true && (event.which == '61' || event.which == '107' || event.which == '173' || event.which == '109' || event.which == '187' || event.which == '189')) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).keyup(function (event) {
|
$(document).keyup(function (event) {
|
||||||
var key = event.which;
|
var key = event.which;
|
||||||
socket.emit("keyUp", key);
|
socket.emit("keyUp", key);
|
||||||
if (key == 69) {
|
if (key == 69 || key == 71) {
|
||||||
$("#animationDiv").remove();
|
$("#animationDiv").remove();
|
||||||
}
|
}
|
||||||
keys[key] = false;
|
keys[key] = false;
|
||||||
|
339
server.js
339
server.js
@ -148,9 +148,11 @@ var itemAttrs = {
|
|||||||
lvl: 1,
|
lvl: 1,
|
||||||
dmg: 20
|
dmg: 20
|
||||||
},
|
},
|
||||||
"item_item_bone1": {
|
"item_item_bone0": {
|
||||||
|
lvl: 0,
|
||||||
|
},
|
||||||
|
"item_item_spaten3": {
|
||||||
lvl: 1,
|
lvl: 1,
|
||||||
dmg: 5
|
|
||||||
},
|
},
|
||||||
"item_consumable_fish1": {
|
"item_consumable_fish1": {
|
||||||
lvl: 3,
|
lvl: 3,
|
||||||
@ -165,7 +167,7 @@ var itemAttrs = {
|
|||||||
changeMovementSpeed: -0.5
|
changeMovementSpeed: -0.5
|
||||||
},
|
},
|
||||||
"item_item_woods1": {
|
"item_item_woods1": {
|
||||||
lvl: 0,
|
lvl: 1,
|
||||||
//changeMovementSpeed: -0.5
|
//changeMovementSpeed: -0.5
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -188,8 +190,8 @@ io.on('connection', function (socket) {
|
|||||||
x: 10,
|
x: 10,
|
||||||
y: 10,
|
y: 10,
|
||||||
mvnt: defaultMvnt,
|
mvnt: defaultMvnt,
|
||||||
lookingLeft : 0,
|
lookingLeft: 0,
|
||||||
lookingUp : 0,
|
lookingUp: 0,
|
||||||
special: {},
|
special: {},
|
||||||
mode: 0, //0 = ship //1 foot
|
mode: 0, //0 = ship //1 foot
|
||||||
slots: {
|
slots: {
|
||||||
@ -201,8 +203,8 @@ io.on('connection', function (socket) {
|
|||||||
tool: null,
|
tool: null,
|
||||||
item: null
|
item: null
|
||||||
},
|
},
|
||||||
hp : 80,
|
hp: 80,
|
||||||
socketId : socket.id
|
socketId: socket.id
|
||||||
};
|
};
|
||||||
var player = allPlayers[socket.id];
|
var player = allPlayers[socket.id];
|
||||||
io.sockets.emit("newPlayer", {
|
io.sockets.emit("newPlayer", {
|
||||||
@ -214,7 +216,7 @@ io.on('connection', function (socket) {
|
|||||||
for (var i in player.slots) {
|
for (var i in player.slots) {
|
||||||
if (player.slots[i]) {
|
if (player.slots[i]) {
|
||||||
let nearFieldCoords = getNearEmptyField(Math.floor(player["x"] / 32), Math.floor(player["y"] / 32));
|
let nearFieldCoords = getNearEmptyField(Math.floor(player["x"] / 32), Math.floor(player["y"] / 32));
|
||||||
if(nearFieldCoords) {
|
if (nearFieldCoords) {
|
||||||
let newObj = {
|
let newObj = {
|
||||||
mapY: nearFieldCoords["y"],
|
mapY: nearFieldCoords["y"],
|
||||||
mapX: nearFieldCoords["x"],
|
mapX: nearFieldCoords["x"],
|
||||||
@ -241,7 +243,7 @@ io.on('connection', function (socket) {
|
|||||||
|
|
||||||
socket.on('keyUp', function (key) {
|
socket.on('keyUp', function (key) {
|
||||||
allPlayers[socket.id]["keys"][key] = false;
|
allPlayers[socket.id]["keys"][key] = false;
|
||||||
if (key == 69) { //space
|
if (key == 69 || key == 71) { //space oder G
|
||||||
player["action"] = false;
|
player["action"] = false;
|
||||||
if (playerActionTimer) {
|
if (playerActionTimer) {
|
||||||
clearTimeout(playerActionTimer);
|
clearTimeout(playerActionTimer);
|
||||||
@ -253,147 +255,187 @@ io.on('connection', function (socket) {
|
|||||||
|
|
||||||
socket.on('keyDown', function (key) {
|
socket.on('keyDown', function (key) {
|
||||||
allPlayers[socket.id]["keys"][key] = true;
|
allPlayers[socket.id]["keys"][key] = true;
|
||||||
if(key == 32 && allPlayers[socket.id]["mode"] != 0) { //Space HIT SOMEONE
|
if (key == 32 && allPlayers[socket.id]["mode"] != 0) { //Space HIT SOMEONE
|
||||||
//if(allPlayers[socket.id]["mode"] == 1) { // On land
|
//if(allPlayers[socket.id]["mode"] == 1) { // On land
|
||||||
if(!allPlayers[socket.id]["hitPending"]) {
|
if (!allPlayers[socket.id]["hitPending"]) {
|
||||||
io.sockets.emit("showHitAnimation", socket.id);
|
io.sockets.emit("showHitAnimation", socket.id);
|
||||||
allPlayers[socket.id]["hitPending"] = true;
|
allPlayers[socket.id]["hitPending"] = true;
|
||||||
let allPlayersWithCollision = checkHitWithOtherPlayers(socket.id);
|
let allPlayersWithCollision = checkHitWithOtherPlayers(socket.id);
|
||||||
for(var i=0;i<allPlayersWithCollision.length;i++) {
|
for (var i = 0; i < allPlayersWithCollision.length; i++) {
|
||||||
calcDmgAndHitPlayer(allPlayers[socket.id], allPlayers[allPlayersWithCollision[i]])
|
calcDmgAndHitPlayer(allPlayers[socket.id], allPlayers[allPlayersWithCollision[i]])
|
||||||
}
|
|
||||||
console.log(allPlayersWithCollision);
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
allPlayers[socket.id]["hitPending"] = false;
|
|
||||||
}, 500)
|
|
||||||
}
|
}
|
||||||
|
console.log(allPlayersWithCollision);
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
allPlayers[socket.id]["hitPending"] = false;
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
//}
|
//}
|
||||||
|
} else if (key == 71) { // Taste G
|
||||||
|
var groundUnder = getGroundUnderPlayer(player["x"], player["y"]);
|
||||||
|
if (groundUnder == 10) { //its land
|
||||||
|
let cutTime = 6000; //6 Secs
|
||||||
|
console.log(player)
|
||||||
|
if(player["slots"] && player["slots"]["item"] && player["slots"]["item"] == "item_item_spaten3") {
|
||||||
|
cutTime = 2000;
|
||||||
|
}
|
||||||
|
if (playerActionTimer) {
|
||||||
|
clearTimeout(playerActionTimer);
|
||||||
|
playerActionTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
playerActionTimer = setTimeout(function () {
|
||||||
|
|
||||||
|
//Drop a random Item
|
||||||
|
let randomItem = getRandomItem(0, 0);
|
||||||
|
let nearFieldCoords = getNearEmptyField(Math.floor(player["x"] / 32), Math.floor(player["y"] / 32));
|
||||||
|
|
||||||
|
utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = randomItem;
|
||||||
|
let newObj = {
|
||||||
|
mapY: nearFieldCoords["y"],
|
||||||
|
mapX: nearFieldCoords["x"],
|
||||||
|
newName: randomItem
|
||||||
|
}
|
||||||
|
io.sockets.emit("dropItem", newObj);
|
||||||
|
|
||||||
|
socket.emit("stopAnimation", cutTime);
|
||||||
|
allPlayers[socket.id]["action"] = false;
|
||||||
|
|
||||||
|
}, cutTime);
|
||||||
|
allPlayers[socket.id]["action"] = true;
|
||||||
|
socket.emit("animation", cutTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
console.log(groundUnder)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('actionKey', function (key) {
|
socket.on('actionKey', function (key) {
|
||||||
var groundUnder = getGroundUnderPlayer(player["x"], player["y"]);
|
var groundUnder = getGroundUnderPlayer(player["x"], player["y"]);
|
||||||
if (player["mode"] == 0) { //ship
|
if (key == 69) {// E
|
||||||
if (groundUnder >= 1) { //its nearly land
|
|
||||||
player["mode"] = 1;
|
|
||||||
player["special"]["modechange"] = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (groundUnder <= 1) { //its water land
|
|
||||||
player["mode"] = 0;
|
|
||||||
player["special"]["modechange"] = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
//console.log(player["mode"], groundUnder);
|
|
||||||
var obj = getNearestObject(player["x"], player["y"]);
|
|
||||||
if (obj) {
|
|
||||||
obj["socketId"] = socket.id;
|
|
||||||
if (playerActionTimer) {
|
|
||||||
clearTimeout(playerActionTimer);
|
|
||||||
playerActionTimer = null;
|
|
||||||
}
|
|
||||||
if (obj["name"] == "forest") {
|
|
||||||
let cutTime = 2000; //2 Secs
|
|
||||||
if (player["slots"]["tool"] && itemAttrs[player["slots"]["tool"]] && itemAttrs[player["slots"]["tool"]]["reduceTreeCutSpeed"] > 0) {
|
|
||||||
cutTime -= itemAttrs[player["slots"]["tool"]]["reduceTreeCutSpeed"];
|
|
||||||
playerActionTimer = setTimeout(function () {
|
|
||||||
|
|
||||||
if (Math.random() > 0.75) {
|
if (player["mode"] == 0) { //ship
|
||||||
utilMap[obj["mapY"]][obj["mapX"]] = "item_item_woods1";
|
if (groundUnder >= 1) { //its nearly land
|
||||||
obj["newName"] = "item_item_woods1";
|
player["mode"] = 1;
|
||||||
io.sockets.emit("replaceUtil", obj);
|
player["special"]["modechange"] = true;
|
||||||
} else {
|
|
||||||
utilMap[obj["mapY"]][obj["mapX"]] = "";
|
|
||||||
io.sockets.emit("removeUtil", obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.emit("stopAnimation", cutTime);
|
|
||||||
|
|
||||||
}, cutTime);
|
|
||||||
socket.emit("animation", cutTime);
|
|
||||||
} else {
|
|
||||||
socket.emit("displayMsg", "Baum kann nur mit einer Axt gefällt werden!");
|
|
||||||
|
|
||||||
//can not cut tree
|
|
||||||
}
|
}
|
||||||
} else if (obj["name"] == "treasure-closed") {
|
} else {
|
||||||
playerActionTimer = setTimeout(function () {
|
if (groundUnder <= 1) { //its water land
|
||||||
utilMap[obj["mapY"]][obj["mapX"]] = "treasure-open";
|
player["mode"] = 0;
|
||||||
obj["newName"] = "treasure-open";
|
player["special"]["modechange"] = true;
|
||||||
io.sockets.emit("replaceUtil", obj);
|
}
|
||||||
socket.emit("stopAnimation", 2000);
|
};
|
||||||
|
//console.log(player["mode"], groundUnder);
|
||||||
|
var obj = getNearestObject(player["x"], player["y"]);
|
||||||
|
if (obj) {
|
||||||
|
obj["socketId"] = socket.id;
|
||||||
|
if (playerActionTimer) {
|
||||||
|
clearTimeout(playerActionTimer);
|
||||||
|
playerActionTimer = null;
|
||||||
|
}
|
||||||
|
if (obj["name"] == "forest") {
|
||||||
|
let cutTime = 2000; //2 Secs
|
||||||
|
if (player["slots"]["tool"] && itemAttrs[player["slots"]["tool"]] && itemAttrs[player["slots"]["tool"]]["reduceTreeCutSpeed"] > 0) {
|
||||||
|
cutTime -= itemAttrs[player["slots"]["tool"]]["reduceTreeCutSpeed"];
|
||||||
|
playerActionTimer = setTimeout(function () {
|
||||||
|
|
||||||
//Drop a random Item
|
if (Math.random() > 0.75) {
|
||||||
let randomItem = getRandomItem(2, 5);
|
utilMap[obj["mapY"]][obj["mapX"]] = "item_item_woods1";
|
||||||
let nearFieldCoords = getNearEmptyField(obj["mapX"], obj["mapY"]);
|
obj["newName"] = "item_item_woods1";
|
||||||
|
io.sockets.emit("replaceUtil", obj);
|
||||||
|
} else {
|
||||||
|
utilMap[obj["mapY"]][obj["mapX"]] = "";
|
||||||
|
io.sockets.emit("removeUtil", obj);
|
||||||
|
}
|
||||||
|
|
||||||
utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = randomItem;
|
socket.emit("stopAnimation", cutTime);
|
||||||
let newObj = {
|
|
||||||
mapY: nearFieldCoords["y"],
|
}, cutTime);
|
||||||
mapX: nearFieldCoords["x"],
|
socket.emit("animation", cutTime);
|
||||||
newName: randomItem
|
} else {
|
||||||
|
socket.emit("displayMsg", "Baum kann nur mit einer Axt gefällt werden!");
|
||||||
|
|
||||||
|
//can not cut tree
|
||||||
}
|
}
|
||||||
io.sockets.emit("dropItem", newObj);
|
} else if (obj["name"] == "treasure-closed") {
|
||||||
}, 2000); //2 Secs
|
playerActionTimer = setTimeout(function () {
|
||||||
socket.emit("animation", 2000);
|
utilMap[obj["mapY"]][obj["mapX"]] = "treasure-open";
|
||||||
} else if (obj["name"] == "fass") {
|
obj["newName"] = "treasure-open";
|
||||||
playerActionTimer = setTimeout(function () {
|
io.sockets.emit("replaceUtil", obj);
|
||||||
|
socket.emit("stopAnimation", 2000);
|
||||||
|
|
||||||
|
//Drop a random Item
|
||||||
|
let randomItem = getRandomItem(2, 5);
|
||||||
|
let nearFieldCoords = getNearEmptyField(obj["mapX"], obj["mapY"]);
|
||||||
|
|
||||||
|
utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = randomItem;
|
||||||
|
let newObj = {
|
||||||
|
mapY: nearFieldCoords["y"],
|
||||||
|
mapX: nearFieldCoords["x"],
|
||||||
|
newName: randomItem
|
||||||
|
}
|
||||||
|
io.sockets.emit("dropItem", newObj);
|
||||||
|
}, 2000); //2 Secs
|
||||||
|
socket.emit("animation", 2000);
|
||||||
|
} else if (obj["name"] == "fass") {
|
||||||
|
playerActionTimer = setTimeout(function () {
|
||||||
|
utilMap[obj["mapY"]][obj["mapX"]] = "";
|
||||||
|
io.sockets.emit("removeUtil", obj);
|
||||||
|
socket.emit("stopAnimation", 500);
|
||||||
|
|
||||||
|
//Drop a random Item
|
||||||
|
let randomItem = getRandomItem(1, 2);
|
||||||
|
let nearFieldCoords = getNearEmptyField(obj["mapX"], obj["mapY"]);
|
||||||
|
|
||||||
|
utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = randomItem;
|
||||||
|
let newObj = {
|
||||||
|
mapY: nearFieldCoords["y"],
|
||||||
|
mapX: nearFieldCoords["x"],
|
||||||
|
newName: randomItem
|
||||||
|
}
|
||||||
|
io.sockets.emit("dropItem", newObj);
|
||||||
|
}, 500); //2 Secs
|
||||||
|
socket.emit("animation", 500);
|
||||||
|
} else if (obj["name"].split("_")[0] == "item") {
|
||||||
|
let itemName = obj["name"];
|
||||||
utilMap[obj["mapY"]][obj["mapX"]] = "";
|
utilMap[obj["mapY"]][obj["mapX"]] = "";
|
||||||
io.sockets.emit("removeUtil", obj);
|
io.sockets.emit("removeUtil", obj);
|
||||||
socket.emit("stopAnimation", 500);
|
|
||||||
|
|
||||||
//Drop a random Item
|
let slotArt = obj["name"].split("_")[1];
|
||||||
let randomItem = getRandomItem(1, 2);
|
if (allPlayers[socket.id]["slots"][slotArt]) { //Slot is not empty so drop it
|
||||||
let nearFieldCoords = getNearEmptyField(obj["mapX"], obj["mapY"]);
|
let nearFieldCoords = getNearEmptyField(Math.floor(player["x"] / 32), Math.floor(player["y"] / 32));
|
||||||
|
let newObj = {
|
||||||
utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = randomItem;
|
mapY: nearFieldCoords["y"],
|
||||||
let newObj = {
|
mapX: nearFieldCoords["x"],
|
||||||
mapY: nearFieldCoords["y"],
|
newName: allPlayers[socket.id]["slots"][slotArt]
|
||||||
mapX: nearFieldCoords["x"],
|
}
|
||||||
newName: randomItem
|
utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = newObj["newName"];
|
||||||
|
io.sockets.emit("dropItem", newObj);
|
||||||
|
//console.log("drop", newObj)
|
||||||
}
|
}
|
||||||
io.sockets.emit("dropItem", newObj);
|
|
||||||
}, 500); //2 Secs
|
|
||||||
socket.emit("animation", 500);
|
|
||||||
} else if (obj["name"].split("_")[0] == "item") {
|
|
||||||
let itemName = obj["name"];
|
|
||||||
utilMap[obj["mapY"]][obj["mapX"]] = "";
|
|
||||||
io.sockets.emit("removeUtil", obj);
|
|
||||||
|
|
||||||
let slotArt = obj["name"].split("_")[1];
|
console.log(slotArt)
|
||||||
if (allPlayers[socket.id]["slots"][slotArt]) { //Slot is not empty so drop it
|
if (slotArt == "consumable") {
|
||||||
let nearFieldCoords = getNearEmptyField(Math.floor(player["x"] / 32), Math.floor(player["y"] / 32));
|
let hp = itemAttrs[obj["name"]]["hp"];
|
||||||
let newObj = {
|
allPlayers[socket.id]["hp"] += hp;
|
||||||
mapY: nearFieldCoords["y"],
|
let toMutch = 0;
|
||||||
mapX: nearFieldCoords["x"],
|
if (allPlayers[socket.id]["hp"] > 100) {
|
||||||
newName: allPlayers[socket.id]["slots"][slotArt]
|
toMutch = allPlayers[socket.id]["hp"] - 100;
|
||||||
|
}
|
||||||
|
if (allPlayers[socket.id]["hp"] > 100) {
|
||||||
|
allPlayers[socket.id]["hp"] = 100;
|
||||||
|
}
|
||||||
|
socket.emit("displayMsg", "Lebenspunkte +" + (hp - toMutch));
|
||||||
|
socket.emit("hpChange", allPlayers[socket.id]["hp"]);
|
||||||
|
} else {
|
||||||
|
allPlayers[socket.id]["slots"][slotArt] = itemName;
|
||||||
|
socket.emit("addItemToInventar", itemName);
|
||||||
}
|
}
|
||||||
utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = newObj["newName"];
|
|
||||||
io.sockets.emit("dropItem", newObj);
|
|
||||||
//console.log("drop", newObj)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(slotArt)
|
io.sockets.emit("objAction", obj);
|
||||||
if(slotArt == "consumable") {
|
|
||||||
let hp = itemAttrs[obj["name"]]["hp"];
|
|
||||||
allPlayers[socket.id]["hp"] += hp;
|
|
||||||
let toMutch = 0;
|
|
||||||
if(allPlayers[socket.id]["hp"]>100) {
|
|
||||||
toMutch = allPlayers[socket.id]["hp"]-100;
|
|
||||||
}
|
|
||||||
if(allPlayers[socket.id]["hp"] > 100) {
|
|
||||||
allPlayers[socket.id]["hp"] = 100;
|
|
||||||
}
|
|
||||||
socket.emit("displayMsg", "Lebenspunkte +"+(hp-toMutch));
|
|
||||||
socket.emit("hpChange", allPlayers[socket.id]["hp"]);
|
|
||||||
} else {
|
|
||||||
allPlayers[socket.id]["slots"][slotArt] = itemName;
|
|
||||||
socket.emit("addItemToInventar", itemName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
io.sockets.emit("objAction", obj);
|
|
||||||
}
|
}
|
||||||
player["action"] = true;
|
player["action"] = true;
|
||||||
});
|
});
|
||||||
@ -419,32 +461,33 @@ function getNearEmptyField(x, y) {
|
|||||||
|
|
||||||
function calcDmgAndHitPlayer(player1, player2) {
|
function calcDmgAndHitPlayer(player1, player2) {
|
||||||
let dmg = 1;
|
let dmg = 1;
|
||||||
dmg += parseFloat(player1["slots"]["weapon"] ? itemAttrs[player1["slots"]["weapon"]]["dmg"] : 0 );
|
dmg += parseFloat(player1["slots"]["weapon"] ? itemAttrs[player1["slots"]["weapon"]]["dmg"] : 0);
|
||||||
|
|
||||||
let armor = 1;
|
let armor = 1;
|
||||||
for(var k in player2["slots"]) {
|
for (var k in player2["slots"]) {
|
||||||
if(k == "head" || k=="chest" || k == "legs") {
|
if (k == "head" || k == "chest" || k == "legs") {
|
||||||
armor+= parseFloat(player1["slots"][k] ? itemAttrs[player1["slots"][k]]["armor"] : 0);
|
armor += parseFloat(player1["slots"][k] ? itemAttrs[player1["slots"][k]]["armor"] : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let hitDmg = dmg * (armor/100) * 100
|
let hitDmg = dmg * (armor / 100) * 100
|
||||||
player2["hp"] -= hitDmg;
|
player2["hp"] -= hitDmg;
|
||||||
if(player2["hp"] < 0) {
|
if (player2["hp"] < 0) {
|
||||||
player2["hp"] = 0;
|
player2["hp"] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
io.sockets.emit("newPlayerHp", { socketId : player2["socketId"], hp : player2["hp"]})
|
io.sockets.emit("newPlayerHp", { socketId: player2["socketId"], hp: player2["hp"] })
|
||||||
console.log(hitDmg, dmg, armor, player1, player2)
|
console.log(hitDmg, dmg, armor, player1, player2)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandomItem(minLvl, maxLvl) {
|
function getRandomItem(minLvl, maxLvl) {
|
||||||
//console.log("rnd", items.length, getRandomNumber(0, items.length), items)
|
//console.log("rnd", items.length, getRandomNumber(0, items.length), items)
|
||||||
//return items[32] //fish
|
// return items[32] //Spaten
|
||||||
|
// return items[32] //fish
|
||||||
while (1) {
|
while (1) {
|
||||||
let item = items[getRandomNumber(0, items.length)];
|
let item = items[getRandomNumber(0, items.length)];
|
||||||
console.log(item)
|
console.log(item)
|
||||||
if (item && (typeof (maxLvl) == "undefined" || typeof (minLvl) == "undefined" || (itemAttrs[item]["lvl"] >= minLvl && itemAttrs[item]["lvl"] <= maxLvl))) {
|
if (item && (typeof (maxLvl) == "undefined" || typeof (minLvl) == "undefined" || (itemAttrs[item]["lvl"] >= minLvl && itemAttrs[item]["lvl"] <= maxLvl))) {
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -496,7 +539,7 @@ setInterval(function () {
|
|||||||
for (var id in allPlayers) {
|
for (var id in allPlayers) {
|
||||||
var player = allPlayers[id];
|
var player = allPlayers[id];
|
||||||
for (var key in player["keys"]) {
|
for (var key in player["keys"]) {
|
||||||
if (player["keys"][key] && player["hp"] >0) { //if key is pressed
|
if (player["keys"][key] && player["hp"] > 0) { //if key is pressed
|
||||||
|
|
||||||
var tx = 0;
|
var tx = 0;
|
||||||
var ty = 0;
|
var ty = 0;
|
||||||
@ -617,26 +660,26 @@ function getRandomNumber(min, max) { //min (inclusive) and max (exclusive)
|
|||||||
function checkHitWithOtherPlayers(socketId) {
|
function checkHitWithOtherPlayers(socketId) {
|
||||||
let playersWithCollision = [];
|
let playersWithCollision = [];
|
||||||
let mainPlayer = allPlayers[socketId];
|
let mainPlayer = allPlayers[socketId];
|
||||||
for(var sid in allPlayers) {
|
for (var sid in allPlayers) {
|
||||||
if(sid != socketId) { //Dont check collision with self
|
if (sid != socketId) { //Dont check collision with self
|
||||||
let targetPlayer = allPlayers[sid];
|
let targetPlayer = allPlayers[sid];
|
||||||
let bottom = mainPlayer.keys["40"];
|
let bottom = mainPlayer.keys["40"];
|
||||||
let left = mainPlayer.keys["37"];
|
let left = mainPlayer.keys["37"];
|
||||||
//console.log(mainPlayer.x, mainPlayer.y, 28, targetPlayer.x, targetPlayer.y, 8)
|
//console.log(mainPlayer.x, mainPlayer.y, 28, targetPlayer.x, targetPlayer.y, 8)
|
||||||
if(isCircleCircleCollision(mainPlayer.x, mainPlayer.y, 28, targetPlayer.x, targetPlayer.y, 8)) {
|
if (isCircleCircleCollision(mainPlayer.x, mainPlayer.y, 28, targetPlayer.x, targetPlayer.y, 8)) {
|
||||||
let hit = false;
|
let hit = false;
|
||||||
console.log(mainPlayer.lookingLeft, mainPlayer.lookingUp , mainPlayer.x, mainPlayer.y, targetPlayer.x, targetPlayer.y)
|
console.log(mainPlayer.lookingLeft, mainPlayer.lookingUp, mainPlayer.x, mainPlayer.y, targetPlayer.x, targetPlayer.y)
|
||||||
if(mainPlayer.lookingLeft == 1 && mainPlayer.x >= targetPlayer.x) {
|
if (mainPlayer.lookingLeft == 1 && mainPlayer.x >= targetPlayer.x) {
|
||||||
hit = true;
|
hit = true;
|
||||||
} else if(mainPlayer.lookingLeft == -1 && mainPlayer.x <= targetPlayer.x) {
|
} else if (mainPlayer.lookingLeft == -1 && mainPlayer.x <= targetPlayer.x) {
|
||||||
hit = true;
|
hit = true;
|
||||||
} else if(mainPlayer.lookingUp == 1 && mainPlayer.y >= targetPlayer.y) {
|
} else if (mainPlayer.lookingUp == 1 && mainPlayer.y >= targetPlayer.y) {
|
||||||
hit = true;
|
hit = true;
|
||||||
} else if(mainPlayer.lookingUp == -1 && mainPlayer.y <= targetPlayer.y) {
|
} else if (mainPlayer.lookingUp == -1 && mainPlayer.y <= targetPlayer.y) {
|
||||||
hit = true;
|
hit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hit) {
|
if (hit) {
|
||||||
playersWithCollision.push(sid);
|
playersWithCollision.push(sid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user