Exemplo n.º 1
0
/*
 * PDS is ready
 */
void	CPDSLib::ready(uint32 lastUpdateId)
{
	nlassert(_PDSConnected);

	nlinfo("PDS is ready to work");
	_PDSReady = true;

	// set up next update Id
	_UpdateId = lastUpdateId+1;

	// flush previous messages that have already been written on hd
	if ((sint)lastUpdateId >= 0)
	{
		flushAcknowledged(lastUpdateId);
	}

	// prepare PD string mapper for sheet ids
	CPDStringMapper	sheetIdStringMapper;

	std::vector<NLMISC::CSheetId>	sheetIds;
	NLMISC::CSheetId::buildIdVector(sheetIds);

	uint	i;
	for (i=0; i<sheetIds.size(); ++i)
	{
		NLMISC::CSheetId	sheetId = sheetIds[i];
		sheetIdStringMapper.setMapping(sheetId.toString(), sheetId.asInt());
	}

	CMessage	msgout("PD_SHEETID_MAPPING");
	msgout.serial(_DatabaseId);
	msgout.serial(sheetIdStringMapper);
	CUnifiedNetwork::getInstance()->send("PDS", msgout);

	// if there are still some messages in queue, resend them
	if (!_QueuedMessages.empty())
	{
		// sort them before, so they are in right order
		// this is in theory useless, since new messages are inserted at end
		std::sort(_QueuedMessages.begin(), _QueuedMessages.end(), CQueuedMessagePred());

		TQueuedMessages::iterator	it;
		for (it=_QueuedMessages.begin(); it!=_QueuedMessages.end(); ++it)
		{
			uint32	updateId = (*it).first;

			if (updateId != _UpdateId)
				nlwarning("CPDSLib::ready(): update id '%d' is not consistent with message id '%d' to be sent", _UpdateId, updateId);

			_UpdateId = updateId+1;

			NLNET::CMessage*	msg = (*it).second;
			CUnifiedNetwork::getInstance()->send("PDS", *msg);
		}
	}
}
Exemplo n.º 2
0
/*
 * Spawn the source as an entity in mirror. Return false in case of failure.
 */
bool CToxicCloud::spawn( const NLMISC::CSheetId &sheet )
{
	// Add into mirror
	CEntityId entityId = CEntityId::getNewEntityId( RYZOMID::fx_entity );
	if ( ! Mirror.createEntity( entityId ) )
		return false;
	_DataSetRow = TheDataset.getDataSetRow( entityId );

	// Set the sheet id
	CMirrorPropValue<TYPE_SHEET> sheetMirror( TheDataset, _DataSetRow, DSPropertySHEET );
	sheetMirror = sheet.asInt();

	// Set the initial position
	CMirrorPropValue<TYPE_POSX> posX( TheDataset, _DataSetRow, DSPropertyPOSX );
	CMirrorPropValue<TYPE_POSY> posY( TheDataset, _DataSetRow, DSPropertyPOSY );
	posX = (TYPE_POSX)(_Pos.x * 1000.0f);
	posY = (TYPE_POSY)(_Pos.y * 1000.0f);

	// Set the mode
	MBEHAV::TMode md;
	md.setModeAndPos( MBEHAV::NORMAL, _DataSetRow );
	CMirrorPropValue<MBEHAV::TMode> mode( TheDataset, _DataSetRow, DSPropertyMODE );
	mode = md;

	// Set the WhoSeesMe bitfield (every bit set to 1)
	const uint64 bitfield = IsRingShard? R2_VISION::buildWhoSeesMe(R2_VISION::WHOSEESME_VISIBLE_PLAYER,true): UINT64_CONSTANT(0xffffffffffffffff);
	CMirrorPropValue<TYPE_WHO_SEES_ME> whoSeesMe(TheDataset, _DataSetRow, DSPropertyWHO_SEES_ME );
	whoSeesMe = bitfield;

	// Contextual properties init
	CMirrorPropValue<TYPE_CONTEXTUAL> contextualProperties(TheDataset, _DataSetRow, DSPropertyCONTEXTUAL );
	contextualProperties = 0;

	TheDataset.declareEntity( _DataSetRow );
	return true;
}
Exemplo n.º 3
0
void CMirrors::initSheetServer( const TDataSetRow& entityIndex, const NLMISC::CSheetId& sheetId )
{
	nlassert(sheetId != NLMISC::CSheetId::Unknown);
	CMirrorPropValue<TYPE_SHEET> value( *DataSet, entityIndex, DSPropertySHEET_SERVER );
	value = sheetId.asInt();
}
Exemplo n.º 4
0
void CMirrors::initSheet( const TDataSetRow& entityIndex, const NLMISC::CSheetId& sheetId )
{
	CMirrorPropValue<TYPE_SHEET> value( *DataSet, entityIndex, DSPropertySHEET );
	value = sheetId.asInt();
}
Exemplo n.º 5
0
//***************************************************************
std::string CToolCreateEntity::cloneEntityIntoScenario(CEntityCL *clonee,
												const NLMISC::CVector &createPosition,
												float createAngle,
												bool  newAction,
												bool  createGhost
											   )
{
	//H_AUTO(R2_CToolCreateEntity_cloneEntityIntoScenario)
	if (!clonee) return "";
	std::string instanceId;
	bool isBotObject = isBotObjectSheet(clonee->sheetId());

	if (!getEditor().verifyRoomLeft(isBotObject ? 0 : 1, isBotObject ? 1 : 0)) { return ""; }

	std::string className;
	// if class is given in the palette node, then use it. Default to 'Npc' else
	CObject *paletteNode = getDMC().getPaletteElement(_PaletteId);
	if (paletteNode && paletteNode->findIndex("Class") != -1)
	{
		className = getString(paletteNode, "Class");
	}
	if (className.empty())
	{
		className = "Npc";
	}

	ucstring readableName;
	// retrieve name from the palette id
	CLuaState &ls = getEditor().getLua();
	getEditor().getEnv()["PaletteIdToTranslation"][_PaletteId].push();
	if (ls.isString(-1))
	{
		readableName.fromUtf8(ls.toString(-1));
	}
	if (readableName.empty())
	{
		// if no name found then give a default one
		readableName = CI18N::get(isBotObject ? "uiR2EDNameBotObject" : "uiR2EDNameNPC");
	}

	// except for creatures, posfix the name with a number
	std::string creaturePaletteRoot = "palette.entities.creatures";
	if (_PaletteId.substr(0, creaturePaletteRoot.size()) != creaturePaletteRoot)
	{
		readableName = getEditor().genInstanceName(readableName);
	}
	else
	{
		className = "NpcCreature";

		// is Plant
		std::string sheetClient = getString(paletteNode, "SheetClient");
		getEditor().getLua().push(sheetClient);
		if (getEditor().getEnv().callMethodByNameNoThrow("isNPCPlant", 1, 1))
		{
			CLuaObject result(getEditor().getLua());
			bool isPlant = result.toBoolean();
			if (isPlant)
				className = "NpcPlant";
		}
	}

	if (newAction)
	{
		getDMC().newAction(NLMISC::CI18N::get("uiR2EDCreateAction") + readableName);
	}
	// send network commands to create entity on server
	std::auto_ptr<CObject> desc(getDMC().newComponent(className));

	if (desc.get())
	{
		// TMP FIX : if the created entity is a custom npc, then retrieve look from the clonee visual properties
		if (className == "NpcCustom")
		{
			SPropVisualA vA;
			SPropVisualB vB;
			SPropVisualC vC;
			const string propNameA = toString("SERVER:Entities:E%d:P%d", clonee->slot(), CLFECOMMON::PROPERTY_VPA);
			const string propNameB = toString("SERVER:Entities:E%d:P%d", clonee->slot(), CLFECOMMON::PROPERTY_VPB);
			const string propNameC = toString("SERVER:Entities:E%d:P%d", clonee->slot(), CLFECOMMON::PROPERTY_VPC);
			CCDBNodeLeaf *leafA = CInterfaceManager::getInstance()->getDbProp(propNameA);
			CCDBNodeLeaf *leafB = CInterfaceManager::getInstance()->getDbProp(propNameB);
			CCDBNodeLeaf *leafC = CInterfaceManager::getInstance()->getDbProp(propNameC);
			if (!leafA)
			{
				nlwarning("Can't find DB leaf %s", propNameA.c_str());
				return "";
			}
			if (!leafB)
			{
				nlwarning("Can't find DB leaf %s", propNameB.c_str());
				return "";
			}
			if (!leafC)
			{
				nlwarning("Can't find DB leaf %s", propNameC.c_str());
				return "";
			}

			vA.PropertyA = leafA->getValue64();
			vB.PropertyB = leafB->getValue64();
			vC.PropertyC = leafC->getValue64();
			nlassert(desc->isTable());
			CObjectTable *props = (CObjectTable *) desc.get();

			props->set("GabaritHeight",     (double)vC.PropertySubData.CharacterHeight);
			props->set("GabaritTorsoWidth", (double)vC.PropertySubData.TorsoWidth);
			props->set("GabaritArmsWidth",  (double)vC.PropertySubData.ArmsWidth);
			props->set("GabaritLegsWidth",  (double)vC.PropertySubData.LegsWidth);
			props->set("GabaritBreastSize", (double)vC.PropertySubData.BreastSize);

			props->set("HairColor", (double)vA.PropertySubData.HatColor);
			props->set("Tattoo",    (double)vC.PropertySubData.Tattoo);
			props->set("EyesColor", (double)vC.PropertySubData.EyesColor);

			props->set("MorphTarget1", (double)vC.PropertySubData.MorphTarget1);
			props->set("MorphTarget2", (double)vC.PropertySubData.MorphTarget2);
			props->set("MorphTarget3", (double)vC.PropertySubData.MorphTarget3);
			props->set("MorphTarget4", (double)vC.PropertySubData.MorphTarget4);
			props->set("MorphTarget5", (double)vC.PropertySubData.MorphTarget5);
			props->set("MorphTarget6", (double)vC.PropertySubData.MorphTarget6);
			props->set("MorphTarget7", (double)vC.PropertySubData.MorphTarget7);
			props->set("MorphTarget8", (double)vC.PropertySubData.MorphTarget8);

			props->set("Sex", (double)vA.PropertySubData.Sex);

			CVisualSlotManager * vsManager = CVisualSlotManager::getInstance();
			NLMISC::CSheetId * sheetId = NULL;

			if(vA.PropertySubData.HatModel == 0)
			{
				props->set("HatModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.HatModel, SLOTTYPE::HEAD_SLOT);
				if (sheetId)
				{
					props->set("HairType",  (double)sheetId->asInt());
				}
			}

			if(vA.PropertySubData.JacketModel == 0)
			{
				props->set("JacketModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.JacketModel, SLOTTYPE::CHEST_SLOT);
				if (sheetId)
				{
					props->set("JacketModel",  (double)sheetId->asInt());
				}
			}

			if(vA.PropertySubData.TrouserModel == 0)
			{
				props->set("TrouserModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.TrouserModel, SLOTTYPE::LEGS_SLOT);
				if (sheetId)
				{
					props->set("TrouserModel",  (double)sheetId->asInt());
				}
			}

			if(vB.PropertySubData.FeetModel == 0)
			{
				props->set("FeetModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vB.PropertySubData.FeetModel, SLOTTYPE::FEET_SLOT);
				if (sheetId)
				{
					props->set("FeetModel",  (double)sheetId->asInt());
				}
			}

			if(vB.PropertySubData.HandsModel == 0)
			{
				props->set("HandsModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vB.PropertySubData.HandsModel, SLOTTYPE::HANDS_SLOT);
				if (sheetId)
				{
					props->set("HandsModel",  (double)sheetId->asInt());
				}
			}

			if(vA.PropertySubData.ArmModel == 0)
			{
				props->set("ArmModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.ArmModel, SLOTTYPE::ARMS_SLOT);
				if (sheetId)
				{
					props->set("ArmModel",  (double)sheetId->asInt());
				}
			}

			double weaponRH=0, weaponLH=0;
			if(vA.PropertySubData.WeaponRightHand == 0)
			{
				props->set("WeaponRightHand", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.WeaponRightHand, SLOTTYPE::RIGHT_HAND_SLOT);
				if (sheetId)
				{
					weaponRH = (double)sheetId->asInt();
				}
				props->set("WeaponRightHand",  weaponRH);
			}

			if(vA.PropertySubData.WeaponLeftHand == 0)
			{
				props->set("WeaponLeftHand", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.WeaponLeftHand, SLOTTYPE::LEFT_HAND_SLOT);
				if (sheetId)
				{
					weaponLH = (double)sheetId->asInt();
				}
				props->set("WeaponLeftHand",  weaponLH);
			}

			props->set("JacketColor", (double)vA.PropertySubData.JacketColor);
			props->set("TrouserColor", (double)vA.PropertySubData.TrouserColor);
			props->set("FeetColor", (double)vB.PropertySubData.FeetColor);
			props->set("HandsColor", (double)vB.PropertySubData.HandsColor);
			props->set("ArmColor", (double)vA.PropertySubData.ArmColor);

			CPlayerR2CL * player = (CPlayerR2CL*)dynamic_cast<CPlayerR2CL*>(clonee);
			if(player != NULL)
			{
				std::string race, gender, sheetClient;
				switch(player->people())
				{
				case EGSPD::CPeople::Fyros:
					sheetClient = "basic_fyros_";
					race = "Fyros";
					break;

				case EGSPD::CPeople::Matis:
					sheetClient = "basic_matis_";
					race = "Matis";
					break;

				case EGSPD::CPeople::Tryker:
					sheetClient = "basic_tryker_";
					race = "Tryker";
					break;

				case EGSPD::CPeople::Zorai:
					sheetClient = "basic_zorai_";
					race = "Zorai";
					break;

				default:
					nlwarning("CToolCreateEntity::commit unknown people");
				}
				switch(player->getGender())
				{
				case GSGENDER::female:
					sheetClient = sheetClient+"female.creature";
					gender = "female";
					break;

				case GSGENDER::male:
					sheetClient = sheetClient+"male.creature";
					gender = "male";
					break;

				default:
					nlwarning("CToolCreateEntity::commit unknown gender");
				}

				props->set("SheetClient", sheetClient);

				// random name
				getEditor().getLua().push(race);
				getEditor().getLua().push(gender);
				if (getEditor().getEnv().callMethodByNameNoThrow("randomNPCName", 2, 1))
				{
					CLuaObject result(getEditor().getLua());
					std::string name = result.toString();
					props->set("Name", name);
				}
			}

			getEditor().getLua().push(getString(paletteNode, "Equipment"));
			getEditor().getLua().push(weaponRH);
			getEditor().getLua().push(weaponLH);
			getEditor().getLua().push(getString(paletteNode, "Sheet"));
			getEditor().getLua().push(getString(paletteNode, "SheetModel"));
			if (getEditor().getEnv().callMethodByNameNoThrow("searchSheet", 5, 1))
			{
				CLuaObject result(getEditor().getLua());
				std::string sheet = result.toString();
				props->set("Sheet", sheet);
			}
			else
			{
				nlwarning("SearchSheet failed : Palette Id = %s", _PaletteId.c_str());
				return "";
			}
		}
		else
		{
			desc->set("Name", readableName.toUtf8());
		}

		desc->set("Base", _PaletteId);
		desc->setObject("Position", buildVector(CVectorD(createPosition)));
		desc->set("Angle", createAngle);
		//desc->set("Name", readableName.toUtf8());

		instanceId = getString(desc.get(), "InstanceId");
		if (!instanceId.empty())
		{
			if (!createGhost)
			{
				// selection asked when instance is created
				getEditor().setCookie(instanceId, "Select", true);
			}
			else
			{
				getEditor().setCookie(instanceId, "GhostDuplicate", true);
			}
		}

		// send creation command
		// tmp : static npc counter
		// add in component list of default feature
		if (getEditor().getDefaultFeature())
		{
			std::string targetInstanceId;
			// if object is a bot object, it is considered to be permanent content
			// and should be created in the base act
			CInstance *targetAct =  isBotObject ? getEditor().getBaseAct() : getEditor().getCurrentAct();
			if (!targetAct)
			{
				nlwarning("Can't find act when creating an entity");
			}
			else
			{
				if (_AutoGroup.getGroupingCandidate())
				{
					nlassert(!createGhost); // either autogroup or arraymode, both at the same time not supported
					_AutoGroup.group(desc.get(), createPosition);
				}
				else
				{
					// create standalone
					desc->setGhost(createGhost);
					getDMC().requestInsertNode(getEditor().getDefaultFeature(targetAct)->getId(),
											   "Components",
											   -1,
											   "",
											   desc.get());
				}
			}
		}
	}
	return instanceId;
}