120 | function RideableAnimal:activateRiding(player, noEventSend) |
121 | AnimalRidingEvent.sendEvent(self, true, player, noEventSend) |
122 | |
123 | if self.owner.isServer then |
124 | local posX, posY, posZ |
125 | local rotX, rotY, rotZ |
126 | if self.loadedRidingData ~= nil then |
127 | local pos = self.loadedRidingData.position |
128 | posX, posY, posZ = pos[1] or 0.0, pos[2] or nil, pos[3] or 0.0 |
129 | rotX, rotY, rotZ = self.loadedRidingData.rotation[1], self.loadedRidingData.rotation[2], self.loadedRidingData.rotation[3] |
130 | else |
131 | local visualId = self.visualId |
132 | local husbandryId = self.module.husbandryId |
133 | posX, posY, posZ = getAnimalPosition(husbandryId, visualId) |
134 | rotX, rotY, rotZ = getAnimalRotation(husbandryId, visualId) |
135 | end |
136 | |
137 | local dx,dy,dz = mathEulerRotateVector(rotX, rotY, rotZ, 0,0,1) |
138 | rotY = MathUtil.getYRotationFromDirection(dx, dz) |
139 | |
140 | self.ridingPlayer = player |
141 | |
142 | local ownerFarmId = self.module.owner:getOwnerFarmId() |
143 | g_currentMission:loadVehicle(self.subType.rideableFileName, posX, posY, posZ, 0, rotY, true, 0.0, Vehicle.PROPERTY_STATE_OWNED, ownerFarmId, {}, nil, self.onLoadedRideable, self) |
144 | else |
145 | self.module:hideAnimal(self.visualId) |
146 | end |
147 | end |
151 | function RideableAnimal:deactivateRiding(noEventSend) |
152 | AnimalRidingEvent.sendEvent(self, false, nil, noEventSend) |
153 | |
154 | if self.rideableVehicle ~= nil then |
155 | self.rideableVehicle:setDirtChangedCallback(nil, nil) |
156 | self.dirtScale = self.rideableVehicle:getDirtScale() |
157 | if self.owner.isServer and not self.rideableVehicle.isDeleted then |
158 | g_currentMission:removeVehicle(self.rideableVehicle) |
159 | end |
160 | |
161 | self.rideableVehicle = nil |
162 | end |
163 | |
164 | self.ridingPlayer = nil |
165 | self.module:showAnimal(self.visualId) |
166 | end |
86 | function RideableAnimal:loadFromXMLFile(xmlFile, key) |
87 | RideableAnimal:superClass().loadFromXMLFile(self, xmlFile, key) |
88 | |
89 | local isRidingActive = getXMLBool(xmlFile, key.."#isRidingActive") |
90 | if isRidingActive then |
91 | local x,y,z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#position")) |
92 | local xRot,yRot,zRot = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotation")) |
93 | |
94 | xRot = math.rad(xRot or 0) |
95 | yRot = math.rad(yRot or 0) |
96 | zRot = math.rad(zRot or 0) |
97 | |
98 | self.loadedRidingData = {position={x, y, z}, rotation={xRot, yRot, zRot}} |
99 | end |
100 | end |
104 | function RideableAnimal:saveToXMLFile(xmlFile, key, usedModNames) |
105 | RideableAnimal:superClass().saveToXMLFile(self, xmlFile, key, usedModNames) |
106 | |
107 | setXMLBool(xmlFile, key.."#isRidingActive", self.rideableVehicle ~= nil) |
108 | |
109 | if self.rideableVehicle ~= nil then |
110 | local x,y,z = self.rideableVehicle:getPosition() |
111 | local xRot,yRot,zRot = self.rideableVehicle:getRotation() |
112 | |
113 | setXMLString(xmlFile, key.."#position", string.format("%.4f %.4f %.4f", x, y, z)) |
114 | setXMLString(xmlFile, key.."#rotation", string.format("%.4f %.4f %.4f", math.deg(xRot), math.deg(yRot), math.deg(zRot))) |
115 | end |
116 | end |