chore(release): 0.3.1
[risinglegends.git] / src / shared / inventory.ts
1 import {Profession} from "./profession";
2 import {SkillID} from "./skills";
3 import { max } from 'lodash';
4
5 export type InventoryType = 'ARMOUR' | 'WEAPON' | 'SPELL';
6
7 export type ArmourEquipmentSlot = 'HEAD' | 'LEGS' | 'ARMS' | 'CHEST';
8 export type WeaponEquipmentSlot = 'LEFT_HAND' | 'RIGHT_HAND' | 'TWO_HANDED' | 'ANY_HAND';
9
10 export type EquipmentSlot = ArmourEquipmentSlot | WeaponEquipmentSlot;
11
12
13 export type InventoryItem = {
14   item_id: string;
15   player_id: string;
16   name: string;
17   type: InventoryType;
18   profession:  Profession;
19   equipment_slot: EquipmentSlot;
20   cost: number;
21   count: number;
22   icon: string;
23   requirements: {
24     level: number,
25     strength: number,
26     constitution: number,
27     dexterity: number,
28     intelligence: number
29   },
30   boosts: {
31     strength: number;
32     constitution: number;
33     dexterity: number;
34     intelligence: number;
35     damage: number;
36     damage_mitigation: number;
37     defence: number;
38   }
39   currentAp: number;
40   maxAp: number;
41   affectedSkills: SkillID[];
42 }
43
44 // shop items have a numeric id since they're tracked in a separate spreadsheet 
45 // and they are also tied to a specific location
46 export type ShopEquipment = Omit<InventoryItem, 'id' | 'player_id'> & {
47   id: number;
48   location_id: number;
49 };
50
51 export function repairCost(item: InventoryItem): number {
52   const totalCost = item.cost * 0.7;
53
54   const damageRatio = 1 - (item.currentAp / item.maxAp);
55
56   return max([Math.floor(totalCost * damageRatio), 1]);
57 }