mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-13 22:01:04 -04:00
272 lines
7.7 KiB
Plaintext
272 lines
7.7 KiB
Plaintext
// =====================================================================
|
|
// remote_object_requester.script
|
|
// =====================================================================
|
|
|
|
include library.utils;
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
inherits base.remote_object;
|
|
|
|
// ======================================================================
|
|
|
|
trigger OnClusterWideDataResponse(String managerName, String elementNameExp, int requestId,
|
|
String[] elementNameList, dictionary[] dictionaryList, int lockKey)
|
|
{
|
|
if (logsEnabled())
|
|
{
|
|
log("OnClusterWideDataResponse() manager name (" + managerName + ") element name ("
|
|
+ elementNameExp + ") request id (" + requestId + ") match count (" + elementNameList.length
|
|
+ ") lock key (" + lockKey + ")");
|
|
|
|
for (int i = 0; i < elementNameList.length; ++i)
|
|
{
|
|
log("element " + (i+1) + " is (" + elementNameList[i] + ")");
|
|
log("dictionary " + dictionaryList[i].toString());
|
|
}
|
|
}
|
|
|
|
if (managerName == REMOTE_OBJECT_MANAGER)
|
|
{
|
|
if (dictionaryList.length < 1)
|
|
{
|
|
logError("No object available for remote creation. [" + elementNameExp + "]");
|
|
}
|
|
else if (!hasValidCreateScriptVars(self, requestId))
|
|
{
|
|
logError("Missing script vars for this request! [" + requestId + "]");
|
|
}
|
|
else if (utils.hasScriptVar(self, getSceneNameVarName(requestId)) && !elementNameExp.equals(getSceneName(self, requestId)))
|
|
{
|
|
logError("Wrong scene! [" + elementNameExp + "][" + getSceneName(self, requestId) + "]");
|
|
}
|
|
else
|
|
{
|
|
obj_id remoteObjectCreator = getRemoteObjectCreator(self, requestId, elementNameList, dictionaryList);
|
|
|
|
if (isValidId(remoteObjectCreator))
|
|
{
|
|
messageTo(remoteObjectCreator, CREATE_REMOTE_OBJECT, getRemoteCreateParams(self, requestId), 0.0f, false);
|
|
log("Remote object creation request sent!");
|
|
}
|
|
else
|
|
{
|
|
logError("No valid remote object creator found!");
|
|
}
|
|
}
|
|
|
|
removeRemoteCreateScriptVars(self, requestId);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
messageHandler createRemoteObjectResponse()
|
|
{
|
|
log("createRemoteObjectResponse: " + params.toString());
|
|
|
|
obj_id remoteObject = params.getObjId(REMOTE_OBJECT);
|
|
|
|
if (isValidId(remoteObject))
|
|
{
|
|
log("Successfully created " + remoteObject);
|
|
}
|
|
else
|
|
{
|
|
logError("Creation failed!");
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
void remoteCreate(String sceneName, String objectName, float x, float y, float z)
|
|
{
|
|
obj_id self = getSelf();
|
|
|
|
int requestId = getClusterWideData(REMOTE_OBJECT_MANAGER, sceneName, false, self);
|
|
|
|
utils.setScriptVar(self, getSceneNameVarName(requestId), sceneName);
|
|
utils.setScriptVar(self, getObjectNameVarName(requestId), objectName);
|
|
|
|
utils.setScriptVar(self, getUseRandomLocationVarName(requestId), false);
|
|
utils.setScriptVar(self, getXVarName(requestId), x);
|
|
utils.setScriptVar(self, getYVarName(requestId), y);
|
|
utils.setScriptVar(self, getZVarName(requestId), z);
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
void remoteCreate(String sceneName, String objectName)
|
|
{
|
|
obj_id self = getSelf();
|
|
|
|
int requestId = getClusterWideData(REMOTE_OBJECT_MANAGER, sceneName, false, self);
|
|
|
|
utils.setScriptVar(self, getSceneNameVarName(requestId), sceneName);
|
|
utils.setScriptVar(self, getObjectNameVarName(requestId), objectName);
|
|
utils.setScriptVar(self, getUseRandomLocationVarName(requestId), true);
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
/**
|
|
* Invoke remote create and the base class will provide all parameters
|
|
*/
|
|
int remoteCreate()
|
|
{
|
|
obj_id self = getSelf();
|
|
|
|
int requestId = getClusterWideData(REMOTE_OBJECT_MANAGER, "*", false, self);
|
|
|
|
return requestId;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
String getSceneNameVarName(int requestId)
|
|
{
|
|
return SCENE_NAME + "." + requestId;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
String getSceneName(obj_id self, int requestId)
|
|
{
|
|
return utils.getStringScriptVar(self, getSceneNameVarName(requestId));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
String getObjectNameVarName(int requestId)
|
|
{
|
|
return OBJECT_NAME + "." + requestId;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
String getObjectName(obj_id self, int requestId)
|
|
{
|
|
return utils.getStringScriptVar(self, getObjectNameVarName(requestId));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
String getXVarName(int requestId)
|
|
{
|
|
return X + "." + requestId;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
float getX(obj_id self, int requestId)
|
|
{
|
|
return utils.getFloatScriptVar(self, getXVarName(requestId));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
String getYVarName(int requestId)
|
|
{
|
|
return Y + "." + requestId;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
float getY(obj_id self, int requestId)
|
|
{
|
|
return utils.getFloatScriptVar(self, getYVarName(requestId));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
String getZVarName(int requestId)
|
|
{
|
|
return Z + "." + requestId;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
float getZ(obj_id self, int requestId)
|
|
{
|
|
return utils.getFloatScriptVar(self, getZVarName(requestId));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
String getUseRandomLocationVarName(int requestId)
|
|
{
|
|
return USE_RANDOM_LOCATION + "." + requestId;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
boolean getUseRandomLocationVarName(obj_id self, int requestId)
|
|
{
|
|
return utils.getBooleanScriptVar(self, getUseRandomLocationVarName(requestId));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
/**
|
|
* Base classes should override this method to remove creation parameters
|
|
*/
|
|
void removeRemoteCreateScriptVars(obj_id self, int requestId)
|
|
{
|
|
utils.removeScriptVar(self, getSceneNameVarName(requestId));
|
|
utils.removeScriptVar(self, getObjectNameVarName(requestId));
|
|
|
|
utils.removeScriptVar(self, getXVarName(requestId));
|
|
utils.removeScriptVar(self, getYVarName(requestId));
|
|
utils.removeScriptVar(self, getZVarName(requestId));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
/**
|
|
* Base classes should override this method if sceneName and objectName are not stored
|
|
*/
|
|
boolean hasValidCreateScriptVars(obj_id self, int requestId)
|
|
{
|
|
return utils.hasScriptVar(self, getSceneNameVarName(requestId)) &&
|
|
utils.hasScriptVar(self, getObjectNameVarName(requestId));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
/**
|
|
* Base classes should override this method to control creation parameters
|
|
*/
|
|
dictionary getRemoteCreateParams(obj_id self, int requestId)
|
|
{
|
|
dictionary createParams = new dictionary();
|
|
|
|
createParams.put(REQUESTER, self);
|
|
|
|
createParams.put(SCENE_NAME, getSceneName(self, requestId));
|
|
createParams.put(OBJECT_NAME, getObjectName(self, requestId));
|
|
createParams.put(X, getX(self, requestId));
|
|
createParams.put(Y, getY(self, requestId));
|
|
createParams.put(Z, getZ(self, requestId));
|
|
|
|
return createParams;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
/**
|
|
* Base classes should override this method to control which remote creator to use
|
|
*/
|
|
obj_id getRemoteObjectCreator(obj_id self, int requestId, String[] elementNameList, dictionary[] dictionaryList)
|
|
{
|
|
int randomIndex = rand(0, dictionaryList.length);
|
|
obj_id remoteObjectCreator = dictionaryList[randomIndex].getObjId(CREATOR);
|
|
|
|
return remoteObjectCreator;
|
|
}
|
|
|
|
// ======================================================================
|