forked from SunsetLabs-Game/COA-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguild.cairo
More file actions
132 lines (116 loc) · 3.02 KB
/
Copy pathguild.cairo
File metadata and controls
132 lines (116 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use starknet::ContractAddress;
use core::num::traits::zero::Zero;
use crate::helpers::base::ContractAddressDefault;
// --- ENUMS ---
#[derive(Drop, Copy, Serde, Debug, Default, PartialEq, Introspect)]
pub enum GuildRole {
#[default]
Member,
Officer,
Leader,
}
// --- MODELS ---
#[dojo::model]
#[derive(Drop, Copy, Serde, Debug, Default, PartialEq)]
pub struct Guild {
#[key]
pub id: u256,
pub name: felt252,
pub leader: ContractAddress,
pub level: u32,
pub experience: u256,
pub member_count: u32,
pub max_members: u32,
pub created_at: u64,
pub description: felt252,
}
#[dojo::model]
#[derive(Drop, Copy, Serde, Debug, PartialEq, Default)]
pub struct GuildMember {
#[key]
pub guild_id: u256,
#[key]
pub player_id: ContractAddress,
pub role: GuildRole,
pub joined_at: u64,
pub contribution: u256,
}
#[dojo::model]
#[derive(Drop, Copy, Serde, Debug, PartialEq, Default)]
pub struct PlayerGuildMembership {
#[key]
pub player_id: ContractAddress,
pub guild_id: u256,
}
#[dojo::model]
#[derive(Drop, Copy, Serde, Debug, PartialEq, Default)]
pub struct GuildInvite {
#[key]
pub guild_id: u256,
#[key]
pub player_id: ContractAddress,
pub invited_by: ContractAddress,
pub created_at: u64,
pub expires_at: u64,
pub is_accepted: bool,
}
// --- EVENTS ---
#[derive(Copy, Drop, Serde)]
#[dojo::event]
pub struct GuildCreated {
#[key]
pub guild_id: u256,
pub leader: ContractAddress,
pub name: felt252,
}
#[derive(Copy, Drop, Serde)]
#[dojo::event]
pub struct GuildJoined {
#[key]
pub guild_id: u256,
pub player_id: ContractAddress,
pub role: GuildRole,
}
#[derive(Copy, Drop, Serde)]
#[dojo::event]
pub struct GuildLeft {
#[key]
pub guild_id: u256,
pub player_id: ContractAddress,
}
#[derive(Copy, Drop, Serde)]
#[dojo::event]
pub struct GuildInviteSent {
#[key]
pub guild_id: u256,
pub player_id: ContractAddress,
pub invited_by: ContractAddress,
}
#[derive(Copy, Drop, Serde)]
#[dojo::event]
pub struct GuildInviteAccepted {
#[key]
pub guild_id: u256,
pub player_id: ContractAddress,
}
#[derive(Copy, Drop, Serde)]
#[dojo::event]
pub struct GuildLevelUp {
#[key]
pub guild_id: u256,
pub new_level: u32,
}
// --- HELPERS & ERRORS ---
pub mod Errors {
pub const GUILD_NOT_FOUND: felt252 = 'Guild not found';
pub const PLAYER_ALREADY_IN_GUILD: felt252 = 'Player already in guild';
pub const PLAYER_NOT_IN_GUILD: felt252 = 'Player not in guild';
pub const NOT_GUILD_LEADER: felt252 = 'Not the guild leader';
pub const NOT_GUILD_OFFICER: felt252 = 'Not a guild officer';
pub const GUILD_FULL: felt252 = 'Guild is full';
pub const INVALID_GUILD_NAME: felt252 = 'Invalid guild name';
pub const INSUFFICIENT_PERMISSIONS: felt252 = 'Insufficient permissions';
pub const INVITE_NOT_FOUND: felt252 = 'Invite not found';
pub const INVITE_EXPIRED: felt252 = 'Invite expired';
pub const ALREADY_INVITED: felt252 = 'Player already invited';
}