Skip to content

Commit aa0c994

Browse files
authored
Add files via upload
1 parent 5d4a733 commit aa0c994

2 files changed

Lines changed: 240 additions & 0 deletions

File tree

lua/try.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--- Function for try-catching
2+
--- @param func function
3+
function try(func)
4+
-- Try
5+
local status, exception = pcall(func)
6+
-- Catch
7+
if not status then
8+
-- Show exception in the message panel in-game
9+
displayZooMessageTextWithZoom("Exception: "..exception, 1, 30)
10+
end
11+
end
12+
13+
--- Function for try-catching with a custom callback
14+
--- @param func function
15+
--- @param callback function
16+
function tryCatch(func, callback)
17+
-- Try
18+
local status, exception = pcall(func)
19+
-- Catch
20+
if not status then
21+
-- Call callback function
22+
callback(exception)
23+
end
24+
end

services/AnimalService.lua

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
-- Include Zoo Tycoon 2 libraries
2+
include "scenario/scripts/entity.lua"
3+
include "scenario/scripts/misc.lua"
4+
include "scenario/scripts/token.lua"
5+
include "scenario/scripts/ui.lua"
6+
7+
--- Service for modifiying animals.
8+
AnimalService = {}
9+
10+
--- Delete animal
11+
--- @param animal animal
12+
function AnimalService.delete (animal)
13+
deleteEntity(animal)
14+
end
15+
16+
--- Get animal age as sting
17+
--- @param animal animal
18+
--- @return string
19+
function AnimalService.getAgeString (animal)
20+
local isAdult = animal:BFG_GET_ATTR_BOOLEAN("b_Adult")
21+
if isAdult then
22+
return "Adult"
23+
end
24+
return "Young"
25+
end
26+
27+
--- Get animal gender as sting
28+
--- @param animal animal
29+
--- @return string
30+
function AnimalService.getGenderString (animal)
31+
local isMale = animal:BFG_GET_ATTR_BOOLEAN("b_Male")
32+
if isMale then
33+
return "M"
34+
end
35+
return "F"
36+
end
37+
38+
--- Get animal super status as sting
39+
--- @param animal animal
40+
--- @return string
41+
function AnimalService.getSuperString (animal)
42+
local isSuper = animal:BFG_GET_ATTR_BOOLEAN("b_Super")
43+
if isSuper then
44+
return "_Super"
45+
end
46+
return ""
47+
end
48+
49+
--- Set whether or not an animal can be put up for adoption
50+
--- @param animal animal
51+
--- @param canBeAdopted bool
52+
function AnimalService.setAdoptOption (animal, canBeAdopted)
53+
animal:BFG_SET_ATTR_BOOLEAN("b_showAdopt", canBeAdopted)
54+
end
55+
56+
--- Set animal age
57+
--- @param animal animal
58+
--- @param age string
59+
function AnimalService.setAge (animal, age)
60+
local species = animal:BFG_GET_ATTR_STRING("s_Species")
61+
local gender = AnimalService.getGenderString(animal)
62+
local super = AnimalService.getSuperString(animal)
63+
64+
animal:BFG_ENTITY_MORPH_TO_NEW_ENTITY(species .. "_" .. age .. "_" .. gender .. super, false, 0, false, 1)
65+
end
66+
67+
--- Set animal crated status
68+
--- @param animal animal
69+
--- @param isCrated bool
70+
function AnimalService.setCrated (animal, isCrated)
71+
if isCrated then
72+
crateEntity(animal)
73+
else
74+
uncrateEntity(animal)
75+
end
76+
end
77+
78+
--- Set animal enviroment suitability
79+
--- @param animal animal
80+
--- @param enviroment int
81+
function AnimalService.setEnviroment (animal, enviroment)
82+
setNeed(animal, "enviroment", enviroment)
83+
end
84+
85+
--- Set animal exercise stat
86+
--- @param animal animal
87+
--- @param exercise int
88+
function AnimalService.setExercise (animal, exercise)
89+
setNeed(animal, "exercise", exercise)
90+
end
91+
92+
--- Set animal happiness
93+
--- @param animal animal
94+
--- @param happiness int
95+
function AnimalService.setHappiness (animal, happiness)
96+
setNeed(animal, "happiness", happiness)
97+
end
98+
99+
--- Set animal hunger
100+
--- @param animal animal
101+
--- @param hunger int
102+
function AnimalService.setHunger (animal, hunger)
103+
setNeed(animal, "hunger", hunger)
104+
end
105+
106+
--- Set animal hygiene
107+
--- @param animal animal
108+
--- @param hygiene int
109+
function AnimalService.setHygiene (animal, hygiene)
110+
setNeed(animal, "hygiene", hygiene)
111+
end
112+
113+
--- Set animal gender
114+
--- @param animal animal
115+
--- @param gender string
116+
function AnimalService.setGender (animal, gender)
117+
local species = animal:BFG_GET_ATTR_STRING("s_Species")
118+
local age = AnimalService.getAgeString(animal)
119+
local super = AnimalService.getSuperString(animal)
120+
121+
animal:BFG_ENTITY_MORPH_TO_NEW_ENTITY(species .. "_" .. age .. "_" .. gender .. super, false, 0, false, 1)
122+
end
123+
124+
--- Set animal pregnancy
125+
--- @param animal animal
126+
--- @param isPregnant bool
127+
function AnimalService.setPregnant (animal, isPregnant)
128+
local isMale = animal:BFG_GET_ATTR_BOOLEAN("b_Male")
129+
130+
if isPregnant then
131+
if (isMale == false) then
132+
local pregnantSeed = string.format("[[<BFAIToken Name=\"%s\" Force=\"%d\" Timeout=\"%.1f\" Timein=\"%.1f\" />]]", "t_Pregnant", 100, -1, 90)
133+
local pregnantSeedToken = loadComponent(pregnantSeed)
134+
animal:BFG_SEND_TOKEN(pregnantSeedToken)
135+
animal:BFG_SET_ATTR_BOOLEAN("b_Pregnant", true)
136+
end
137+
else
138+
animal:BFG_SET_ATTR_BOOLEAN("b_Pregnant", false)
139+
end
140+
end
141+
142+
--- Set animal privacy
143+
--- @param animal animal
144+
--- @param privacy int
145+
function AnimalService.setPrivacy (animal, privacy)
146+
setNeed(animal, "privacy", privacy)
147+
end
148+
149+
--- Set animal rampage status
150+
--- @param animal animal
151+
--- @param isRampaging bool
152+
function AnimalService.setRampage (animal, isRampaging)
153+
local rampageManager = queryObject("BFGRampageMgr")
154+
rampageManager:BFG_FORCE_RAMPAGE(animal)
155+
end
156+
157+
--- Set whether or not an animal can be released to the wild
158+
--- @param animal animal
159+
--- @param canBeReleased bool
160+
function AnimalService.setReleaseOption (animal, canBeReleased)
161+
animal:BFG_SET_ATTR_BOOLEAN("b_showRelease", canBeReleased)
162+
end
163+
164+
--- Set animal rest
165+
--- @param animal animal
166+
--- @param rest int
167+
function AnimalService.setRest (animal, rest)
168+
setNeed(animal, "rest", rest)
169+
end
170+
171+
--- Set animal social stat
172+
--- @param animal animal
173+
--- @param social int
174+
function AnimalService.setSocial (animal, social)
175+
setNeed(animal, "social", social)
176+
end
177+
178+
--- Set animal stimulation stat
179+
--- @param animal animal
180+
--- @param stimulation int
181+
function AnimalService.setStimulation (animal, stimulation)
182+
setNeed(animal, "stimulation", stimulation)
183+
end
184+
185+
--- Set animal super status
186+
--- @param animal animal
187+
--- @param isSuper bool
188+
function AnimalService.setSuper (animal, isSuper)
189+
local species = animal:BFG_GET_ATTR_STRING("s_Species")
190+
local age = AnimalService.getAgeString(animal)
191+
local gender = AnimalService.getGenderString(animal)
192+
193+
if isSuper then
194+
animal:BFG_ENTITY_MORPH_TO_NEW_ENTITY(species .. "_" .. age .. "_" .. gender .. "_Super", false, 0, false, 1)
195+
else
196+
animal:BFG_ENTITY_MORPH_TO_NEW_ENTITY(species .. "_" .. age .. "_" .. gender, false, 0, false, 1)
197+
end
198+
end
199+
200+
--- Set animal species
201+
--- @param animal animal
202+
--- @param setSpecies string
203+
function AnimalService.setSpecies (animal, species)
204+
local gender = AnimalService.getGenderString(animal)
205+
local age = AnimalService.getAgeString(animal)
206+
local super = AnimalService.getSuperString(animal)
207+
208+
animal:BFG_ENTITY_MORPH_TO_NEW_ENTITY(species .. "_" .. age .. "_" .. gender .. super, false, 0, false, 1)
209+
end
210+
211+
--- Set animal thirst
212+
--- @param animal animal
213+
--- @param thirst int
214+
function AnimalService.setThirst (animal, thirst)
215+
setNeed(animal, "thirst", thirst)
216+
end

0 commit comments

Comments
 (0)