· 4 years ago · Apr 08, 2021, 07:40 PM
1API = {open_ui_count, localData = {}}
2
3function API.SetLocalData(key, value)
4 API.key = value
5end
6
7function API.GetLocalData(key)
8 return API.key
9end
10
11function API.IsDestructable(coreObject)
12 if coreObject == nil then
13 coreObject:WaitForObject()
14 end
15
16 local isDestructable = coreObject:GetCustomProperty("IsDestructable")
17 if isDestructable == nil then
18 return false
19 end
20 return isDestructable
21end
22
23function API.IsNPC(coreObject)
24 if coreObject == nil then
25 coreObject:WaitForObject()
26 end
27
28 if coreObject == nil then
29 return false
30 end
31
32 if coreObject.name == nil then
33 UI.PrintToScreen("WTF is name nil??? " .. tostring(coreObject))
34 end
35
36 if Object.IsValid(coreObject) and coreObject:IsA("Player") then
37 return false
38 end
39
40 local isNPC = coreObject:GetCustomProperty("IsNPC")
41 if isNPC == nil then
42 return false
43 end
44 return isNPC
45end
46
47function API.IsColliderOnNPC(collider)
48 if not Object.IsValid(collider) then return end
49 if not Object.IsValid(collider.parent) then return false end
50 if not Object.IsValid(collider.parent.parent) then return false end
51 return API.IsNPC(collider.parent.parent)
52end
53
54function API.GetLevel(coreObject)
55 local level = 0
56
57 if coreObject:IsA("Player") then
58 level = Storage.GetPlayerData(player).level
59 return level
60 end
61
62 if API.IsNPC(coreObject) then
63 local abydosNPC = coreObject:GetCustomProperty("NPCServer"):WaitForObject()
64 level = abydosNPC:GetCustomProperty("Level")
65 end
66
67 return level
68end
69
70function API.GetAC(coreObject)
71 local ac = 0
72 if API.IsNPC(coreObject) then
73 local abydosNPC = coreObject:GetCustomProperty("NPCServer"):WaitForObject()
74 ac = abydosNPC:GetCustomProperty("AC")
75 elseif coreObject:IsA("Player") then
76 local data = Storage.GetPlayerData(coreObject)
77 ac = data.AC
78 end
79
80 return ac
81end
82
83function API.GetWC(ability)
84 if API.IsNPC(ability.parent) then
85 local abydosNPCServer = ability.parent:GetCustomProperty("NPCServer"):WaitForObject()
86 return abydosNPCServer:GetCustomProperty("WC")
87 end
88
89 local weapon = ability.parent
90 local wc = weapon:GetCustomProperty("WC")
91 if wc == nil then
92 return 0
93 end
94 return wc
95end
96
97function API.GetAbilitySkillAsTable(ability)
98 local groupSkillName = ability:GetCustomProperty("GroupSkill")
99 local majorSkillName = ability:GetCustomProperty("MajorSkill")
100 local minorSkillName = ability:GetCustomProperty("MinorSkill")
101
102 return {
103 groupSkillName = groupSkillName,
104 majorSkillName = majorSkillName,
105 minorSkillName = minorSkillName
106 }
107end
108
109function API.GetAbilitySkillAsName(ability)
110 local groupSkillName = ability:GetCustomProperty("GroupSkill")
111 local majorSkillName = ability:GetCustomProperty("MajorSkill")
112 local minorSkillName = ability:GetCustomProperty("MinorSkill")
113 return groupSkillName .. "." .. majorSkillName .. "." .. minorSkillName
114
115end
116
117function API.GetSimpleSkillname(skillName)
118 local groupSkillName, majorSkillName, minorSkillName = CoreString.Split(skillName, ".")
119
120 if minorSkillName ~= nil then
121 return minorSkillName
122 end
123
124 if majorSkillName ~= nil then
125 return majorSkillName
126 end
127
128 return groupSkillName
129end
130
131function API.GetAttackerSkill(attacker, groupSkillName, majorSkillName, minorSkillName)
132 if not Object.IsValid(attacker) then
133 return {
134 groupSkillLevel = 100,
135 majorSkillLevel = 100,
136 minorSkillLevel = 100
137 }
138 end
139
140 if attacker:IsA("Player") then
141 local skills = Storage.GetPlayerData(attacker).skills
142 local groupSkill = skills[groupSkillName]
143 local majorSkill = groupSkill.skills[majorSkillName]
144 local minorSkill = majorSkill.skills[minorSkillName]
145
146 return {
147 groupSkillLevel = groupSkill.level,
148 majorSkillLevel = majorSkill.level,
149 minorSkillLevel = minorSkill
150 }
151 end
152
153 if API.IsNPC(attacker) then
154 local abydosNPC = attacker:GetCustomProperty("NPCServer"):WaitForObject()
155 -- how to handle NPC skills
156 return {
157 groupSkillLevel = 100,
158 majorSkillLevel = 100,
159 minorSkillLevel = 100
160 }
161 end
162end
163
164function API.RecalculateMaxStats(data)
165 data.maxStats.hitpoints = data.attributes.con * 10
166 data.maxStats.spellpoints = data.attributes.int * 10
167 data.maxStats.stamina = data.attributes.dex * 10
168end
169
170function API.ChangeNumOpenUI(num)
171 if API.open_ui_count < 0 then
172 API.open_ui_count = 0
173 end
174
175 API.open_ui_count = API.open_ui_count + num
176 if API.open_ui_count > 0 then
177 UI.SetCursorVisible(true)
178 UI.SetCanCursorInteractWithUI(true)
179 return
180 end
181
182 UI.SetCursorVisible(false)
183 UI.SetCanCursorInteractWithUI(false)
184end
185
186function API.PrintTableToScreen(table)
187 if table == nil then
188 UI.PrintToScreen("NIL Table!")
189 return
190 end
191
192 for key, value in pairs(table) do
193 UI.PrintToScreen("KeyValue: " .. tostring(key) .. "/" .. tostring(value))
194 end
195end
196
197function API.GiveExpToPlayer(player, exp)
198 UI.PrintToScreen("Giving " .. tostring(exp) .. " EXP to player " .. player.name)
199 local data = Storage.GetPlayerData(player)
200 data.levelData.exp = data.levelData.exp + exp
201 Storage.SetPlayerData(player, data)
202end
203
204function API.EnableColliders(coreObject)
205 if coreObject == nil then return end
206 local colliderGroup = coreObject:FindChildByName("Colliders")
207 if colliderGroup == nil then return end
208 for _, collider in ipairs(colliderGroup:GetChildren()) do
209 collider.collision = Collision.FORCE_ON
210 end
211end
212
213function API.DisableColliders(coreObject)
214 if coreObject == nil then return end
215 local colliderGroup = coreObject:FindChildByName("Colliders")
216 if colliderGroup == nil then return end
217 for _, collider in ipairs(colliderGroup:GetChildren()) do
218 collider.collision = Collision.FORCE_OFF
219 end
220end
221
222function API.GetShortId(coreObject)
223 if coreObject == nil then return nil end
224 return coreObject:GetCustomProperty("ShortId")
225end
226
227return API