void PlanetManagerImplementation::loadBadgeAreas(LuaObject* badges) { if (!badges->isValidTable()) return; uint32 hashCode = STRING_HASHCODE("object/badge_area.iff"); for (int i = 1; i <= badges->getTableSize(); ++i) { lua_State* L = badges->getLuaState(); lua_rawgeti(L, -1, i); LuaObject badge(L); String badgeName = badge.getStringAt(1); float x = badge.getFloatAt(2); float y = badge.getFloatAt(3); float radius = badge.getFloatAt(4); int badgeID = badge.getIntAt(5); ManagedReference<BadgeActiveArea*> obj = server->getZoneServer()->createObject(hashCode, 0).castTo<BadgeActiveArea*>(); Locker objLocker(obj); obj->setRadius(radius); obj->setBadge(badgeID); obj->initializePosition(x, 0, y); zone->transferObject(obj, -1, false); badge.pop(); } }
void PlanetManagerImplementation::loadPlanetObjects(LuaObject* luaObject) { if (!luaObject->isValidTable()) return; for (int i = 1; i <= luaObject->getTableSize(); ++i) { lua_State* L = luaObject->getLuaState(); lua_rawgeti(L, -1, i); LuaObject planetObject(L); String templateFile = planetObject.getStringField("templateFile"); ManagedReference<SceneObject*> obj = ObjectManager::instance()->createObject(templateFile.hashCode(), 0, ""); if (obj != NULL) { Locker objLocker(obj); float x = planetObject.getFloatField("x"); float y = planetObject.getFloatField("y"); float z = planetObject.getFloatField("z"); float ox = planetObject.getFloatField("ox"); float oy = planetObject.getFloatField("oy"); float oz = planetObject.getFloatField("oz"); float ow = planetObject.getFloatField("ow"); uint64 parentID = planetObject.getLongField("parent"); if (obj->isBuildingObject()) { BuildingObject* building = obj->asBuildingObject(); building->createCellObjects(); } obj->initializePosition(x, z, y); obj->setDirection(ow, ox, oy, oz); ManagedReference<SceneObject*> parent = zone->getZoneServer()->getObject(parentID); if (parent != NULL) parent->transferObject(obj, -1, true); else zone->transferObject(obj, -1, true); obj->createChildObjects(); } planetObject.pop(); } }
void SpawnAreaMap::loadStaticSpawns() { String planetName = zone->getZoneName(); LuaObject obj = lua->getGlobalObject(planetName + "_static_spawns"); if (!obj.isValidTable()) { obj.pop(); return; } int count = 0; int max = obj.getTableSize(); for (int i = 1; i <= obj.getTableSize(); ++i) { lua_rawgeti(obj.getLuaState(), -1, i); LuaObject spawn(obj.getLuaState()); if (spawn.isValidTable()) { CreatureManager* creatureManager = zone->getCreatureManager(); String name = obj.getStringAt(1); uint32 respawn = obj.getIntAt(2); float x = obj.getFloatAt(3); float z = obj.getFloatAt(4); float y = obj.getFloatAt(5); float heading = obj.getFloatAt(6); uint64 parentID = obj.getLongAt(7); String moodString; UnicodeString customName; String aiString; int junkDealerBuyingType =0; int junkDealerConversationType =0; if (obj.getTableSize() > 7) moodString = obj.getStringAt(8); if (obj.getTableSize() > 8) customName = obj.getStringAt(9); if (obj.getTableSize() > 9) aiString = obj.getStringAt(10); if (obj.getTableSize() > 10) junkDealerBuyingType = obj.getIntAt(11); if (obj.getTableSize() > 11) junkDealerConversationType = obj.getIntAt(12); if (parentID == 0) z = zone->getHeight(x, y); ManagedReference<CreatureObject*> creatureObject = creatureManager->spawnCreature(name.hashCode(), 0, x, z, y, parentID); if (creatureObject != NULL) { Locker objLocker(creatureObject); creatureObject->setDirection(Math::deg2rad(heading)); if (creatureObject->isJunkDealer()){ cast<JunkdealerCreature*>(creatureObject.get())->setJunkDealerConversationType(junkDealerConversationType); cast<JunkdealerCreature*>(creatureObject.get())->setJunkDealerBuyerType(junkDealerBuyingType); } if (!moodString.isEmpty()) { creatureObject->setMoodString(moodString); //TODO: remove after fixing commoners if (moodString == "conversation" || moodString == "calm") { creatureObject->setPvpStatusBitmask(0); creatureObject->setCloseObjects(NULL); } } if (!customName.isEmpty()) creatureObject->setCustomObjectName(customName, true); if (creatureObject->isAiAgent()) { AiAgent* ai = cast<AiAgent*>( creatureObject.get()); ai->setRespawnTimer(respawn); if (!aiString.isEmpty()) { ai->activateLoad(aiString); } } if (name.contains("trainer_")) { Vector3 coords(creatureObject.get()->getWorldPositionX(), creatureObject.get()->getWorldPositionY(), 0); trainerObjects.add(coords); } } else { StringBuffer msg; msg << "could not spawn mobile: " + name; error(msg.toString()); } } spawn.pop(); if (ConfigManager::instance()->isProgressMonitorActivated()) printf("\r\tLoading static spawns: [%d] / [%d]\t", ++count, max); } obj.pop(); //--{"mobile", x, z, y, degrees heading, parentID} //spawnCreature(uint32 templateCRC, uint32 objectCRC, float x, float z, float y, uint64 parentID) }
void SpawnAreaMap::readAreaObject(LuaObject& areaObj) { String name = areaObj.getStringAt(1); float x = areaObj.getFloatAt(2); float y = areaObj.getFloatAt(3); int tier = areaObj.getIntAt(5); int constant = areaObj.getIntAt(6); if (tier == UNDEFINEDAREA) return; float radius = 0; float width = 0; float height = 0; float innerRadius = 0; float outerRadius = 0; LuaObject areaShapeObject = areaObj.getObjectAt(4); if (areaShapeObject.isValidTable()) { if (areaShapeObject.getIntAt(1) == 1) { radius = areaShapeObject.getFloatAt(2); } else if (areaShapeObject.getIntAt(1) == 2) { width = areaShapeObject.getFloatAt(2); height = areaShapeObject.getFloatAt(3); } else if (areaShapeObject.getIntAt(1) == 3) { innerRadius = areaShapeObject.getFloatAt(2); outerRadius = areaShapeObject.getFloatAt(3); } areaShapeObject.pop(); } else { areaShapeObject.pop(); radius = areaObj.getFloatAt(4); width = 0; height = 0; } if (radius == 0 && width == 0 && height == 0 && innerRadius == 0 && outerRadius == 0) return; static const uint32 crc = STRING_HASHCODE("object/spawn_area.iff"); ManagedReference<SpawnArea*> area = dynamic_cast<SpawnArea*>(ObjectManager::instance()->createObject(crc, 0, "spawnareas")); if (area == NULL) return; Locker objLocker(area); StringId nameID(zone->getZoneName() + "_region_names", name); area->setObjectName(nameID); if (height > 0 && width > 0) { ManagedReference<RectangularAreaShape*> rectangularAreaShape = new RectangularAreaShape(); Locker shapeLocker(rectangularAreaShape); rectangularAreaShape->setAreaCenter(x, y); rectangularAreaShape->setDimensions(height, width); area->setAreaShape(rectangularAreaShape); } else if (radius > 0) { ManagedReference<CircularAreaShape*> circularAreaShape = new CircularAreaShape(); Locker shapeLocker(circularAreaShape); circularAreaShape->setAreaCenter(x, y); circularAreaShape->setRadius(radius); area->setAreaShape(circularAreaShape); } else if (innerRadius > 0 && outerRadius > 0) { ManagedReference<RingAreaShape*> ringAreaShape = new RingAreaShape(); Locker shapeLocker(ringAreaShape); ringAreaShape->setAreaCenter(x, y); ringAreaShape->setInnerRadius(innerRadius); ringAreaShape->setOuterRadius(outerRadius); area->setAreaShape(ringAreaShape); } else { ManagedReference<CircularAreaShape*> circularAreaShape = new CircularAreaShape(); Locker shapeLocker(circularAreaShape); circularAreaShape->setAreaCenter(x, y); circularAreaShape->setRadius(zone->getBoundingRadius()); area->setAreaShape(circularAreaShape); } area->setTier(tier); area->setSpawnConstant(constant); if (tier & SPAWNAREA) { area->setTemplate(areaObj.getStringAt(7).hashCode()); area->setMaxSpawnLimit(areaObj.getIntAt(8)); } if ((radius != -1) && !(tier & WORLDSPAWNAREA)) { zone->transferObject(area, -1, true); } else { if (tier & WORLDSPAWNAREA) { worldSpawnAreas.add(area); } area->setZone(zone); } area->updateToDatabase(); put(nameID.getStringID().hashCode(), area); if (tier & NOSPAWNAREA) { area->setNoSpawnArea(true); noSpawnAreas.add(area); } if (tier & NOBUILDZONEAREA) { area->setNoBuildArea(true); } }
void SceneObjectImplementation::createChildObjects() { if (getZone() == NULL) return; ZoneServer* zoneServer = getZone()->getZoneServer(); bool client = isStaticObject(); for (int i = 0; i < templateObject->getChildObjectsSize(); ++i) { ChildObject* child = templateObject->getChildObject(i); if (child == NULL) continue; ManagedReference<SceneObject*> obj = NULL; if (client) obj = zoneServer->createObject(child->getTemplateFile().hashCode(), "clientobjects", getPersistenceLevel()); else obj = zoneServer->createObject(child->getTemplateFile().hashCode(), getPersistenceLevel()); if (obj == NULL) continue; Locker objLocker(obj, asSceneObject()); Vector3 childPosition = child->getPosition(); childObjects.put(obj); obj->initializePosition(childPosition.getX(), childPosition.getZ(), childPosition.getY()); obj->setDirection(child->getDirection()); if (isBuildingObject() && child->getCellId() >= 0) { BuildingObject* buildingObject = asBuildingObject(); int totalCells = buildingObject->getTotalCellNumber(); try { if (totalCells >= child->getCellId()) { ManagedReference<CellObject*> cellObject = buildingObject->getCell(child->getCellId()); if (cellObject != NULL) { if (!cellObject->transferObject(obj, child->getContainmentType(), true)) { obj->destroyObjectFromDatabase(true); continue; } //cellObject->broadcastObject(obj, false); } else { error("NULL CELL OBJECT"); obj->destroyObjectFromDatabase(true); continue; } } } catch (Exception& e) { error("unreported exception caught in void SceneObjectImplementation::createChildObjects()!"); e.printStackTrace(); } } else { //Create the object outdoors in relation to its parent. Vector3 position; if (obj->isActiveArea()) position = getWorldPosition(); else position = getPosition(); float angle = direction.getRadians(); float x = (Math::cos(angle) * childPosition.getX()) + (childPosition.getY() * Math::sin(angle)); float y = (Math::cos(angle) * childPosition.getY()) - (childPosition.getX() * Math::sin(angle)); x += position.getX(); y += position.getY(); float z = position.getZ() + childPosition.getZ(); float degrees = direction.getDegrees(); Quaternion dir = child->getDirection(); obj->initializePosition(x, z, y); obj->setDirection(dir.rotate(Vector3(0, 1, 0), degrees)); if (obj->isBuildingObject()) { BuildingObject* building = obj->asBuildingObject(); if (building != NULL) { building->createCellObjects(); } } if (!getZone()->transferObject(obj, -1, false)) { obj->destroyObjectFromDatabase(true); continue; } } //childObjects.put(obj); ContainerPermissions* permissions = obj->getContainerPermissions(); permissions->setOwner(getObjectID()); permissions->setInheritPermissionsFromParent(false); permissions->setDefaultDenyPermission(ContainerPermissions::MOVECONTAINER); permissions->setDenyPermission("owner", ContainerPermissions::MOVECONTAINER); obj->initializeChildObject(asSceneObject()); } }
void PlanetManagerImplementation::loadLuaConfig() { String planetName = zone->getZoneName(); Lua* lua = new Lua(); lua->init(); lua->runFile("scripts/managers/planet_manager.lua"); //Get's the configuration settings object for this planet. LuaObject luaObject = lua->getGlobalObject(planetName); if (luaObject.isValidTable()) { bool weatherEnabled = luaObject.getIntField("weatherEnabled"); if(weatherEnabled) { weatherManager = new WeatherManager(zone); weatherManager->initialize(); } else { info("Weather Disabled", true); } LuaObject planetTravelPointsTable = luaObject.getObjectField("planetTravelPoints"); planetTravelPointList->readLuaObject(&planetTravelPointsTable); planetTravelPointsTable.pop(); loadSnapshotObjects(); LuaObject planetObjectsTable = luaObject.getObjectField("planetObjects"); loadPlanetObjects(&planetObjectsTable); planetObjectsTable.pop(); } else { warning("Configuration settings not found."); } luaObject.pop(); // Configure shuttleport timing if ((shuttleportAwayTime = lua->getGlobalInt("shuttleportAwayTime")) <= 0) shuttleportAwayTime = 300; if ((shuttleportLandedTime = lua->getGlobalInt("shuttleportLandedTime")) <= 0) shuttleportLandedTime = 120; if ((shuttleportLandingTime = lua->getGlobalInt("shuttleportLandingTime")) <= 0) shuttleportLandingTime = 11; // Configure starport timing if ((starportAwayTime = lua->getGlobalInt("starportAwayTime")) <= 0) starportAwayTime = 60; if ((starportLandedTime = lua->getGlobalInt("starportLandedTime")) <= 0) starportLandedTime = 120; if ((starportLandingTime = lua->getGlobalInt("starportLandingTime")) <= 0) starportLandingTime = 120; lua->runFile("scripts/managers/spawn_manager/" + zone->getZoneName() + ".lua"); LuaObject badges = lua->getGlobalObject(zone->getZoneName() + "_badges"); if (badges.isValidTable()) { uint32 hashCode = String("object/badge_area.iff").hashCode(); for (int i = 1; i <= badges.getTableSize(); ++i) { lua_rawgeti(lua->getLuaState(), -1, i); LuaObject badge(lua->getLuaState()); String badgeName = badge.getStringAt(1); float x = badge.getFloatAt(2); float y = badge.getFloatAt(3); float radius = badge.getFloatAt(4); int badgeID = badge.getIntAt(5); ManagedReference<BadgeActiveArea*> obj = server->getZoneServer()->createObject(hashCode, 0).castTo<BadgeActiveArea*>(); Locker objLocker(obj); obj->setRadius(radius); obj->setBadge(badgeID); obj->initializePosition(x, 0, y); zone->transferObject(obj, -1, false); badge.pop(); } } badges.pop(); delete lua; lua = NULL; }