Skip to content

Commit

Permalink
Merge pull request #8 from imjangkar/dps
Browse files Browse the repository at this point in the history
Dps
  • Loading branch information
imjangkar authored Jul 4, 2024
2 parents 25755ed + 2462bdc commit d8fca0d
Show file tree
Hide file tree
Showing 22 changed files with 273 additions and 159 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

### Prerequisites

- You need Python 3.8 and above
- You need Python 3.10 and above
- Ability to type or copy paste in your computer's Terminal or Command Line

### 🔰 Casual Users
Expand Down Expand Up @@ -71,6 +71,8 @@ albibong

2. A window will pop out and you're good to go!

Note: If you can't start the application by typing `albibong`, you can try use `sudo albibong` instead.

### 👨‍💻 Devs

1. Clone this repository
Expand Down
1 change: 0 additions & 1 deletion gui/src/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ const Navigation = () => {
})}
</List>
</Drawer>
<p>Hello</p>
</>
);
};
Expand Down
32 changes: 20 additions & 12 deletions gui/src/pages/DPSMeter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import classNames from "classnames";
import { useContext, useRef, useState } from "react";
import styles from "./DPSMeter.module.css";
import dungeon from "./DungeonTracker.module.css";

import app from "../App.module.css";
import Checkbox from "../components/Checkbox";
import { WorldContext } from "../providers/WorldProvider";
Expand All @@ -17,9 +19,7 @@ import { theme } from "../theme";

export type DisplayedColumn = {
Heal: boolean;
"Heal%": boolean;
Damage: boolean;
"Damage%": boolean;
};

export const formatter = (num: number) => {
Expand All @@ -28,10 +28,8 @@ export const formatter = (num: number) => {

const DPSMeter = () => {
const [displayedCol, setDisplayedCol] = useState<DisplayedColumn>({
Heal: true,
"Heal%": true,
Heal: false,
Damage: true,
"Damage%": true,
});
const [alert, setAlert] = useState({
copyDamage: false,
Expand All @@ -43,7 +41,7 @@ const DPSMeter = () => {
const { me, world } = useContext(WorldContext);
const { sendMessage } = useContext(WebsocketContext);

const dpsRowBold = classNames(styles.bold, styles.dpsRow);
const dpsRowBold = classNames(styles.bold, styles.dpsRow, dungeon.stickToTop);

const getMaxHeal = () => {
let maxHeal = 0;
Expand All @@ -56,8 +54,7 @@ const DPSMeter = () => {
};

const show = (label: keyof DisplayedColumn) =>
classNames({
[styles.dpsNumber]: true,
classNames(styles.dpsNumber, {
[styles.hidden]: !displayedCol[label],
});

Expand Down Expand Up @@ -107,7 +104,7 @@ const DPSMeter = () => {
<Alert severity="success">Damage has been reset.</Alert>
</Collapse>
</div>
<Typography variant="h1">Damage Meter</Typography>
<Typography variant="h2">Damage Meter</Typography>
<Typography>
Damage Meter is currently{" "}
<b>{world.isDPSMeterRunning ? "recording damage" : "paused"}</b>
Expand Down Expand Up @@ -162,7 +159,10 @@ const DPSMeter = () => {
style={{ backgroundColor: theme.palette.background.default }}
ref={dpsRef}
>
<div className={dpsRowBold}>
<div
className={dpsRowBold}
style={{ backgroundColor: theme.palette.background.default }}
>
<div className={styles.player}>
{world.isDPSMeterRunning == false ? (
<Button
Expand All @@ -186,8 +186,10 @@ const DPSMeter = () => {
<Typography className={show("Heal")}>Heal</Typography>
<Typography className={show("Heal")}>Heal%</Typography>
<Typography className={show("Damage")}>Damage</Typography>
<Typography className={show("Damage")}>Damage%</Typography>
<Typography className={styles.dpsNumber}>Duration</Typography>
<Typography className={show("Damage")} sx={{ fontWeight: "bold" }}>
Damage%
DPS
</Typography>
</div>
{world.party.map((member, index) => {
Expand Down Expand Up @@ -221,11 +223,17 @@ const DPSMeter = () => {
<Typography className={show("Damage")}>
{formatter(member.damage_dealt)}
</Typography>
<Typography className={show("Damage")}>
{formatter(member.damage_percent)}%
</Typography>
<Typography className={styles.dpsNumber}>
{member.combat_duration}
</Typography>
<Typography
className={show("Damage")}
sx={{ fontWeight: "bold" }}
>
{formatter(member.damage_percent)}%
{member.dps}/dps
</Typography>
</div>
<div className={styles.dmgBar} style={dpsWidth} />
Expand Down
11 changes: 11 additions & 0 deletions gui/src/pages/DungeonTracker.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@
color: #0f3c4e;
font-weight: bold;
}

.stickToTop {
z-index: 10;

position: sticky;
top: 64px;
left: 0;

width: 100%;
padding: 24px 0;
}
42 changes: 25 additions & 17 deletions gui/src/pages/DungeonTracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
import { useContext, useEffect, useState } from "react";
import { Dungeon, WorldContext } from "../providers/WorldProvider";
import DungeonCard from "../components/DungeonCard";
import style from "./DungeonTracker.module.css";
import { theme } from "../theme";

const DungeonTracker = () => {
const { world, dungeonFilter } = useContext(WorldContext);
Expand Down Expand Up @@ -38,23 +40,29 @@ const DungeonTracker = () => {

return (
<div className={app.container}>
<Typography variant="h1">Dungeon Tracker</Typography>
<FormControl fullWidth>
<InputLabel id="demo-simple-select-label">
Filter by Dungeon Type
</InputLabel>
<Select
value={selectedFilter}
label="Filter by Dungeon Type"
onChange={(e) => setSelectedFilter(e.target.value)}
>
{dungeonFilter.map((filter, index) => (
<MenuItem key={index} value={filter}>
{filter}
</MenuItem>
))}
</Select>
</FormControl>
<Typography variant="h2">Dungeon Tracker</Typography>
<div
className={style.stickToTop}
style={{ backgroundColor: theme.palette.background.default }}
>
<FormControl fullWidth>
<InputLabel id="demo-simple-select-label">
Filter by Dungeon Type
</InputLabel>
<Select
value={selectedFilter}
label="Filter by Dungeon Type"
onChange={(e) => setSelectedFilter(e.target.value)}
>
{dungeonFilter.map((filter, index) => (
<MenuItem key={index} value={filter}>
{filter}
</MenuItem>
))}
</Select>
</FormControl>
</div>

{filteredDungeon.length > 0 ? (
filteredDungeon.map((dungeon) => {
return <DungeonCard key={dungeon.id} dungeon={dungeon}></DungeonCard>;
Expand Down
2 changes: 2 additions & 0 deletions gui/src/providers/WorldProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type PartyMember = {
damage_dealt: number;
heal_percent: number;
healing_dealt: number;
combat_duration: string;
dps: number;
weapon: string;
};

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ albibong = "albibong:main"

[project]
name = "albibong"
version = "1.0.4"
version = "1.0.5"
authors = [
{ name="imjangkar", email="[email protected]" },
]
description = "A cross-platform Albion Online damage, fame, and dungeon tracker"
requires-python = ">=3.8"
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down
Binary file modified readme_screenshots/damage_meter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 26 additions & 4 deletions src/albibong/classes/character.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime, timedelta
import json
from uuid import UUID

Expand All @@ -20,25 +21,46 @@ def __init__(
coords: Coords,
equipment: list[Item] = [Item.get_item_from_code("0")] * 10,
):
# Profile
self.id = id
self.uuid = uuid
self.username = username
self.guild = guild
self.alliance = alliance
self.coords = coords
self.equipment = equipment

# Stats
self.fame_gained: int = 0
self.re_spec_gained: int = 0
self.silver_gained: int = 0
self.loot: list[str] = []

# Combat
self.damage_dealt: int = 0
self.healing_dealt: int = 0
self.loot: list[str] = []
self.equipment = equipment
self.is_already_in_combat: bool = False
self.start_combat_time: timedelta = timedelta(0, 0)
self.total_combat_duration: timedelta = timedelta(0, 0)

def update_combat_duration(self, is_starting_combat):
if self.is_already_in_combat == False:
if is_starting_combat == True:
self.is_already_in_combat = True
self.start_combat_time = datetime.now()
else:
if is_starting_combat == False:
self.is_already_in_combat = False
current_combat_duration = datetime.now() - self.start_combat_time
self.total_combat_duration += current_combat_duration

def update_damage_dealt(self, nominal):
self.damage_dealt += nominal
if self.is_already_in_combat:
self.damage_dealt += nominal

def update_heal_dealt(self, nominal):
self.healing_dealt += nominal
if self.is_already_in_combat:
self.healing_dealt += nominal

def update_coords(self, parameters):
if 3 in parameters:
Expand Down
7 changes: 7 additions & 0 deletions src/albibong/classes/event_handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
handle_event_health_update,
handle_event_health_updates,
)
from albibong.classes.event_handler.handle_event_in_combat_state_update import (
handle_event_in_combat_state_update,
)
from albibong.classes.event_handler.handle_event_new_character import (
handle_event_new_character,
)
Expand Down Expand Up @@ -48,6 +51,10 @@ def __init__(self):
self.event_handler[EventCode.NEW_CHARACTER.value] = handle_event_new_character
self.event_handler[EventCode.HEALTH_UPDATE.value] = handle_event_health_update
self.event_handler[EventCode.HEALTH_UPDATES.value] = handle_event_health_updates
self.event_handler[EventCode.IN_COMBAT_STATE_UPDATE.value] = (
handle_event_in_combat_state_update
)

self.event_handler[EventCode.UPDATE_FAME.value] = handle_event_update_fame
self.event_handler[EventCode.UPDATE_RE_SPEC_POINTS.value] = (
handle_event_update_re_spec_points
Expand Down
38 changes: 3 additions & 35 deletions src/albibong/classes/event_handler/handle_event_health.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from albibong.classes.character import Character
from albibong.classes.event_handler.world_data_utils import WorldDataUtils
from albibong.classes.world_data import WorldData
from albibong.threads.websocket_server import send_event

Expand All @@ -15,7 +16,7 @@ def handle_event_health_update(world_data: WorldData, parameters):
target = parameters[0]
inflictor = parameters[6]

update_damage_or_heal(world_data, target, inflictor, nominal)
WorldDataUtils.update_damage_or_heal(world_data, target, inflictor, nominal)


def handle_event_health_updates(world_data: WorldData, parameters):
Expand All @@ -31,37 +32,4 @@ def handle_event_health_updates(world_data: WorldData, parameters):
target = parameters[0]
inflictor = parameters[6][i]

update_damage_or_heal(world_data, target, inflictor, nominal)


def update_damage_or_heal(world_data: WorldData, target, inflictor, nominal):

if inflictor not in world_data.char_id_to_username:
# character not initialized yet
return

username = world_data.char_id_to_username[inflictor]

if username == "not initialized":
# self not initialized
return

char: Character = world_data.characters[username]

if nominal < 0:
if target == inflictor:
# suicide
return
char.update_damage_dealt(abs(nominal))
else:
char.update_heal_dealt(nominal)

ws_update_damage_heal(world_data)


def ws_update_damage_heal(world_data: WorldData):
event = {
"type": "update_dps",
"payload": {"party_members": world_data.serialize_party_members()},
}
send_event(event)
WorldDataUtils.update_damage_or_heal(world_data, target, inflictor, nominal)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from albibong.classes.character import Character
from albibong.classes.world_data import WorldData


def handle_event_in_combat_state_update(world_data: WorldData, parameters):

if parameters[0] not in world_data.char_id_to_username:
# character not initialized
return

name = world_data.char_id_to_username[parameters[0]]
char: Character = world_data.characters[name]

if 1 in parameters:
char.update_combat_duration(True)
else:
char.update_combat_duration(False)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from albibong.classes.character import Character
from albibong.classes.coords import Coords
from albibong.classes.event_handler.world_data_utils import WorldDataUtils
from albibong.classes.utils import Utils
from albibong.classes.world_data import WorldData

Expand Down Expand Up @@ -38,4 +39,6 @@ def handle_event_new_character(world_data: WorldData, parameters):
char: Character = world_data.characters[username]
char.update_equipment(equipments)
char.coords = coords
world_data.convert_id_to_name(old_id=char.id, new_id=id, char=char)
WorldDataUtils.convert_id_to_name(
world_data, old_id=char.id, new_id=id, char=char
)
Loading

0 comments on commit d8fca0d

Please sign in to comment.