File size: 4,459 Bytes
b6a38d7 |
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
MapVar("g_Animals", {})
DefineClass.AmbientLifeAnimal = {
__parents = {
"SyncObject", "CombatObject", "AppearanceObject",
"HittableObject", "AnimMomentHook", "AmbientLifeZoneUnit"
},
collision_radius = const.SlabSizeX/3,
radius = const.SlabSizeX/4,
anim_moments_single_thread = true,
anim_moments_hook = true,
__toluacode = empty_func,
PrePlay = empty_func,
PostPlay = empty_func,
}
function AmbientLifeAnimal:Done()
table.remove_entry(g_Animals, self)
end
function AmbientLifeAnimal:GameInit()
table.insert(g_Animals, self)
end
function AmbientLifeAnimal:Despawn()
DoneObject(self)
end
function AmbientLifeAnimal:OnDie(...)
CombatObject.OnDie(self, ...)
PlayFX("Animal", "die", self)
end
function AmbientLifeAnimal:OnAnimMoment(moment, anim)
if self:IsDead() then return end
anim = anim or GetStateName(self)
PlayFX(FXAnimToAction(anim), moment, self, self.anim_moment_fx_target or nil)
local anim_moments_hook = self.anim_moments_hook
if type(anim_moments_hook) == "table" and anim_moments_hook[moment] then
local method = moment_hooks[moment]
return self[method](self, anim)
end
end
DefineClass.AmbientAnimalSpawnDef = {
__parents = {"PropertyObject"},
properties = {
{id = "UnitDef", name = "Animal Definition", editor = "dropdownlist", default = false,
items = ClassDescendantsCombo("AmbientLifeAnimal"),
},
{id = "CountMin", name = "Count Min", editor = "number", default = 3},
{id = "CountMax", name = "Count Max", editor = "number", default = 6},
},
EditorView = Untranslated("<UnitDef> : <CountMin>-<CountMax>"),
}
DefineClass.AmbientZone_Animal = {
__parents = {"AmbientZoneMarker", "EditorCallbackObject"},
properties = {
{category = "Ambient Zone", id = "SpawnDefs", name = "Spawn Definitions", editor = "nested_list",
base_class = "AmbientAnimalSpawnDef", default = false,
},
{id = "Banters"},
{id = "ApproachBanters"},
},
entity = "Animal_Hen",
marker_scale = 400,
marker_state = "idle2",
persist_units = false,
}
function AmbientZone_Animal:Init()
self:SetScale(self.marker_scale)
self:SetState(self.marker_state)
self.SpawnDefs = {
PlaceObj('AmbientAnimalSpawnDef', {
'UnitDef', "Animal_Hen",
})
}
end
function AmbientZone_Animal:PlaceSpawnDef(unit_def, pos)
local animal = PlaceObject(unit_def.UnitDef)
animal.zone = self
animal:SetPos(pos)
animal:SetScale(70 + self:Random(61))
animal:SetCommand("Idle")
return animal
end
function AmbientZone_Animal:SetDynamicData(data)
self:Spawn()
end
AmbientZone_Animal.EditorCallbackPlace = AmbientZone_Animal.RecalcAreaPositions
AmbientZone_Animal.EditorCallbackMove = AmbientZone_Animal.RecalcAreaPositions
AmbientZone_Animal.EditorCallbackRotate = AmbientZone_Animal.RecalcAreaPositions
AmbientZone_Animal.EditorCallbackScale = AmbientZone_Animal.RecalcAreaPositions
function AmbientZone_Animal:ReduceUnits()
for idx, units_def in ipairs(self.units) do
for _, unit in ipairs(units_def) do
Msg(unit)
end
end
end
function AmbientZone_Animal:VME_Checks()
if #self:GetAreaPositions() == 0 then
StoreErrorSource(self, "AmbientZone_Animal without valid area positions. Check Width and Height!")
end
end
DefineClass.Animal_Hen_Cosmetic = {
__parents = { "Object" },
entity = "Animal_Hen",
}
DefineClass.Animal_Hen = {
__parents = {"AmbientLifeAnimal"},
entity = "Animal_Hen",
in_combat = false,
}
function Animal_Hen:Init()
self.species = "Hen"
end
function Animal_Hen:CanPlay(anim_entry)
if anim_entry.Animation == "fly" or not anim_entry.Animation then
return not self.in_combat
end
return true
end
function Animal_Hen:PrePlay(anim_entry)
if anim_entry.Animation == "fly" then
Sleep(self:Random(1000))
elseif not anim_entry.Animation then
self:SetAngle(self:Random(360 * 60), 200)
Sleep(200)
end
end
function Animal_Hen:PostPlay(anim_entry)
if GameState.Combat and anim_entry.Animation == "fly" then
self.in_combat = true
end
end
function Animal_Hen:Idle()
CombatPathReset()
local anim_set = Presets.AnimationSet["AmbientLife"]["Animal_Hen"]
while true do
local anim_entry = anim_set:Play(self)
if not GameState.Combat then
self.in_combat = false
end
end
end
function NetSyncEvents.RespawnAmbientZone_Animal()
MapForEach("map", "AmbientZone_Animal", function(zone)
zone:Despawn()
zone:Spawn()
end)
end
function OnMsg.LoadSessionData()
--this msg comes from a rtt
FireNetSyncEventOnHost("RespawnAmbientZone_Animal")
end |