chore(release): 0.4.0
[risinglegends.git] / src / shared / player.ts
index e3af5f7e8050380b1009c4338cd8794a5767d3d9..339396dce76a04bc2a36dfadb2d869d689eee287 100644 (file)
@@ -1,6 +1,15 @@
 import { Profession } from './profession'; 
 import { Stat } from './stats';
 import { SkillDefinition, Skill } from './skills';
+import { EquippedItemDetails } from './equipped';
+
+export function PermissionGuard(request: any): boolean {
+  const perms: Permission[] = ['admin', 'moderator', 'tester', 'archaeologist'];
+
+  return perms.includes(request);
+}
+
+export type Permission = 'admin' | 'moderator' | 'tester' | 'archaeologist';
 
 export type Player = {
   id: string,
@@ -19,6 +28,8 @@ export type Player = {
   hp: number;
   city_id: number;
   stat_points: number;
+  vigor: number;
+  permissions: Permission[]
 }
 
 export type PlayerWithSkills = Player & {
@@ -26,7 +37,11 @@ export type PlayerWithSkills = Player & {
 }
 
 export function maxHp(constitution: number, playerLevel: number): number {
-  return Math.ceil((constitution + (playerLevel * 1.3)) * 1.7);
+  return Math.ceil((constitution * 1.7) + (playerLevel * 1.3));
+}
+
+export function maxVigor(constitution: number, playerLevel: number): number {
+  return Math.ceil((constitution * 3.8) + (playerLevel * 1.5));
 }
 
 export function expToLevel(level: number): number {
@@ -38,11 +53,28 @@ export function expToLevel(level: number): number {
   }
 }
 
+export function totalDefence(equippedItems: EquippedItemDetails[], player: Player, accountForVigor: boolean = true): number {
+  const vigorPercent = player.vigor / maxVigor(player.constitution, player.level);
+
+  const totalDefence = equippedItems.reduce((acc, curr) => {
+    let defence = curr.boosts.defence ?? 0;
+    return acc += defence;
+  }, 0);
+
+  if(accountForVigor) {
+    return Math.ceil(totalDefence * vigorPercent);
+  }
+  else {
+    return totalDefence;
+  }
+}
+
 
 export type StatDisplay = {
   id: Stat,
   display: string;
   abbrv: string;
+  description: string;
 }
 
 export const StatDef: Map<Stat, StatDisplay> = new Map<Stat, StatDisplay>();
@@ -50,23 +82,27 @@ export const StatDef: Map<Stat, StatDisplay> = new Map<Stat, StatDisplay>();
 StatDef.set(Stat.strength, {
   id: Stat.strength,
   display: 'Strength',
-  abbrv: 'STR'
+  abbrv: 'STR',
+  description: 'Affects your melee damage'
 });
 
 StatDef.set(Stat.constitution, {
   id: Stat.constitution,
   display: 'Constitution',
-  abbrv: 'CON'
+  abbrv: 'CON',
+  description: 'Affects your max HP and Vigor'
 });
 
 StatDef.set(Stat.dexterity, {
   id: Stat.dexterity,
   display: 'Dexterity',
-  abbrv: 'DEX'
+  abbrv: 'DEX',
+  description: 'Affects you ability to dodge attacks double-hit'
 });
 
 StatDef.set(Stat.intelligence, {
   id: Stat.intelligence,
   display: 'Intelligence',
-  abbrv: 'INT'
+  abbrv: 'INT',
+  description: 'Affects your magical damage'
 });