dmg things and fish

This commit is contained in:
Raphael 2024-06-24 15:15:02 +02:00
parent e477a9faf1
commit 71c86ecb6b
3 changed files with 43 additions and 9 deletions

View File

@ -15,8 +15,7 @@
Pirate!!!
<div id="map"></div>
</div>
<div id="bottomHud"
style="position: fixed; bottom: 5px; left: 0px; left: 5px; z-index: 1000;">
<div id="bottomHud" style="position: fixed; bottom: 5px; left: 0px; left: 5px; z-index: 1000;">
<table style="margin-bottom: 5px; padding: 5px; border-radius: 5px; border: 3px solid #0000002e; background: rgb(26 26 26 / 49%); border-bottom-right-radius: 0px;">
<tr>
<td style="width:50px; height: 50px; background: #00000052;" class="playerSlot" id="slot_head"></td>
@ -38,6 +37,9 @@
<td style="width:50px; height: 50px; background: #00000052;" class="playerSlot" id="slot_item"></td>
</tr>
</table>
<div style="position: absolute; background-color: red; width: 100px; height: 13px; left: 90px; bottom: 95px;"></div>
<div class="hpBar" style="position: absolute; background-color: green; width: 80px; height: 13px; left: 90px; bottom: 95px;"></div>
<div style="position: absolute; width: 99px; border:1px solid black; height: 12px; left: 90px; bottom: 95px;"></div>
</div>
<!-- jQuery and co -->
<script src="./js/jquery.min.js"></script>

View File

@ -38,8 +38,8 @@ var tooltiptexts = {
"item_weapon_sword3": "Schwert: Schaden erhöht 400",
"item_weapon_sword4": "Schwert: Schaden erhöht 500",
"item_weapon_sword5": "Schwert: Schaden erhöht 600",
"item_weapon_stick1": "Stock: Schaden erhöht 50",
"item_item_bone1": "Mach nix, ehöht aber dein Level um 1",
"item_weapon_stick1": "Stock: Schaden +20",
"item_item_bone1": "Knochen: Schaden +5",
"item_consumable_fish1": "Erhöht deine Lebenspunkte um 20",
"item_consumable_fish2": "Erhöht deine Lebenspunkte um 10",
"item_item_dimond1": "Verkaufe den Diamand für 10 Siegpunkte! Bewegungsgeschwindigkeit verlangsamt!",
@ -120,6 +120,21 @@ socket.on('replaceUtil', function (obj) {
utilMap[obj["mapY"]][obj["mapX"]] = obj["newName"];
});
socket.on('hpChange', function (obj) {
console.log(obj);
$(".hpBar").css({"width" : obj+"px"});
});
socket.on('newPlayerHp', function (obj) {
console.log(obj)
if(obj.socketId == socket.id) {
$(".hpBar").css({"width" : obj["hp"]+"px"});
}
});
socket.on('dropItem', function (obj) {
console.log(obj);
var utilTitle = tooltiptexts[obj["newName"]] ? tooltiptexts[obj["newName"]] : "";

View File

@ -150,6 +150,7 @@ var itemAttrs = {
},
"item_item_bone1": {
lvl: 1,
dmg: 5
},
"item_consumable_fish1": {
lvl: 3,
@ -196,11 +197,12 @@ io.on('connection', function (socket) {
chest: null,
legs: null,
boots: null,
weapon: 'item_weapon_sword2',
weapon: null,
tool: null,
item: null
},
hp : 100
hp : 80,
socketId : socket.id
};
var player = allPlayers[socket.id];
io.sockets.emit("newPlayer", {
@ -251,7 +253,7 @@ io.on('connection', function (socket) {
socket.on('keyDown', function (key) {
allPlayers[socket.id]["keys"][key] = true;
if(key == 32) { //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]["hitPending"]) {
io.sockets.emit("showHitAnimation", socket.id);
@ -376,7 +378,15 @@ io.on('connection', function (socket) {
if(slotArt == "consumable") {
let hp = itemAttrs[obj["name"]]["hp"];
allPlayers[socket.id]["hp"] += hp;
socket.emit("displayMsg", "Lebenspunkte +"+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);
@ -419,11 +429,17 @@ function calcDmgAndHitPlayer(player1, player2) {
}
let hitDmg = dmg * (armor/100) * 100
player2["hp"] -= hitDmg;
if(player2["hp"] < 0) {
player2["hp"] = 0;
}
io.sockets.emit("newPlayerHp", { socketId : player2["socketId"], hp : player2["hp"]})
console.log(hitDmg, dmg, armor, player1, player2)
}
function getRandomItem(minLvl, maxLvl) {
//console.log("rnd", items.length, getRandomNumber(0, items.length), items)
//return items[32] //fish
while (1) {
let item = items[getRandomNumber(0, items.length)];
console.log(item)
@ -480,7 +496,8 @@ setInterval(function () {
for (var id in allPlayers) {
var player = allPlayers[id];
for (var key in player["keys"]) {
if (player["keys"][key]) { //if key is pressed
if (player["keys"][key] && player["hp"] >0) { //if key is pressed
var tx = 0;
var ty = 0;