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