mirror of
https://bitbucket.org/seefoe/dsrc.git
synced 2026-07-31 01:15:55 -04:00
414 lines
12 KiB
Plaintext
414 lines
12 KiB
Plaintext
/**
|
|
* Title: marriage.scriptlib
|
|
* Description: for "unity" functions
|
|
*/
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
|
|
const float PROPOSAL_RANGE = 5f;
|
|
const float PROPOSAL_TIME = 120f;
|
|
|
|
const string SCRIPT_RING_BASE = "item.ring.base";
|
|
const string SCRIPT_RING_UNITY = "item.ring.wedding";
|
|
|
|
const string SCRIPT_UNITY = "player.unity";
|
|
|
|
const string VAR_MARRIAGE_BASE = "marriage";
|
|
const string VAR_SPOUSE_ID = VAR_MARRIAGE_BASE + ".spouseId";
|
|
const string VAR_SPOUSE_NAME = VAR_MARRIAGE_BASE + ".spouseName";
|
|
const string VAR_RING = VAR_MARRIAGE_BASE + ".ringId";
|
|
|
|
const string VAR_PROPOSAL_BASE = VAR_MARRIAGE_BASE + ".proposal";
|
|
const string VAR_PROPOSAL_TARGET = VAR_PROPOSAL_BASE + ".targetId";
|
|
const string VAR_PROPOSAL_NAME = VAR_PROPOSAL_BASE + ".targetName";
|
|
const string VAR_PROPOSAL_RING = VAR_PROPOSAL_BASE + ".ringId";
|
|
|
|
const string VAR_PROPOSEDTO_BASE = VAR_MARRIAGE_BASE + ".proposedTo";
|
|
const string VAR_PROPOSEDTO_TARGET = VAR_PROPOSEDTO_BASE + ".targetId";
|
|
const string VAR_PROPOSEDTO_NAME = VAR_PROPOSEDTO_BASE + ".targetName";
|
|
const string VAR_PROPOSEDTO_RING = VAR_PROPOSEDTO_BASE + ".ringId";
|
|
|
|
const string VAR_ACCEPT_BASE = VAR_MARRIAGE_BASE + ".accept";
|
|
const string VAR_ACCEPT_SUI = VAR_ACCEPT_BASE + ".sui";
|
|
const string VAR_ACCEPT_SUI_OPTIONS = VAR_ACCEPT_BASE + ".sui_options";
|
|
const string VAR_ACCEPT_RING = VAR_ACCEPT_BASE + ".ringId";
|
|
|
|
const string HANDLER_PROPOSED_TO = "handleProposedTo";
|
|
const string HANDLER_PROPOSAL_ACCEPTED = "handleProposalAccepted";
|
|
const string HANDLER_PROPOSAL_EXPIRE = "handleProposalExpire";
|
|
|
|
const string HANDLER_ACCEPT_FAIL = "handleAcceptFail";
|
|
const string HANDLER_PROPOSAL_DECLINED = "handleProposalDeclined";
|
|
|
|
const string HANDLER_RING_EXCHANGE = "handleRingExchange";
|
|
const string HANDLER_RING_SETUP = "handleRingSetup";
|
|
const string HANDLER_WED_COMPLETE = "handleWedComplete";
|
|
|
|
const string HANDLER_WED_ERROR = "handleWedError";
|
|
|
|
const string HANDLER_DIVORCE = "handleDivorce";
|
|
|
|
const string STF = "unity";
|
|
|
|
const string_id MNU_PROPOSE = new string_id(STF, "mnu_propose");
|
|
const string_id MNU_DIVORCE = new string_id(STF, "mnu_divorce");
|
|
|
|
const string_id SID_BAD_TARGET = new string_id(STF, "bad_target");
|
|
const string_id SID_BAD_FACING = new string_id(STF, "bad_facing");
|
|
const string_id SID_OUT_OF_RANGE = new string_id(STF, "out_of_range");
|
|
|
|
const string_id PROSE_PROPOSE = new string_id(STF, "prose_propose");
|
|
|
|
//PLAYER error messages
|
|
const string_id PROSE_ALREADY_PROPOSED = new string_id(STF, "prose_already_proposed");
|
|
const string_id PROSE_ALREADY_MARRIED = new string_id(STF, "prose_already_married");
|
|
|
|
//errors messages about TARGET
|
|
const string_id SID_TARGET_NOT_PLAYER = new string_id(STF, "target_not_player");
|
|
const string_id SID_TARGET_MARRIED = new string_id(STF, "target_married");
|
|
const string_id SID_TARGET_PROPOSED = new string_id(STF, "target_proposed");
|
|
|
|
//misc error messages
|
|
const string_id SID_NO_RING = new string_id(STF, "no_ring");
|
|
const string_id SID_ACCEPT_FAIL = new string_id(STF, "accept_fail");
|
|
const string_id PROSE_ACCEPT_FAIL = new string_id(STF, "prose_accept_fail");
|
|
|
|
const string_id SID_DECLINE = new string_id(STF, "decline");
|
|
const string_id SID_DECLINED = new string_id(STF, "declined");
|
|
const string_id PROSE_DECLINED = new string_id(STF, "prose_declined");
|
|
|
|
const string_id SID_EXPIRED_PLAYER = new string_id(STF, "expired_player");
|
|
const string_id SID_EXPIRED_TARGET = new string_id(STF, "expired_target");
|
|
|
|
const string_id PROSE_EXPIRE_PLAYER = new string_id(STF, "prose_expire_player");
|
|
const string_id PROSE_EXPIRE_TARGET = new string_id(STF, "prose_expire_target");
|
|
|
|
//WEDDING messages
|
|
const string_id PROSE_WED_COMPLETE = new string_id(STF, "prose_wed_complete");
|
|
const string_id SID_WED_ERROR = new string_id(STF, "wed_error");
|
|
const string_id SID_WED_OOR = new string_id(STF, "wed_oor"); //wedding out-of-range
|
|
const string_id SID_YOU_EXCHANGE_RINGS = new string_id(STF, "you_exchange_rings");
|
|
|
|
//misc messages
|
|
const string_id PROSE_END_UNITY = new string_id(STF, "prose_end_unity");
|
|
|
|
|
|
/***** FUNCTIONS *******************************************************/
|
|
boolean isMarried(obj_id target)
|
|
{
|
|
if ( !isIdValid(target) || !isPlayer(target) )
|
|
return false;
|
|
|
|
return hasObjVar(target, VAR_MARRIAGE_BASE);
|
|
}
|
|
|
|
boolean hasProposed(obj_id target)
|
|
{
|
|
if ( !isIdValid(target) || !isPlayer(target) )
|
|
return false;
|
|
|
|
return utils.hasScriptVar(target, VAR_PROPOSAL_NAME);
|
|
}
|
|
|
|
void propose(obj_id player, obj_id target, obj_id ring)
|
|
{
|
|
if ( !isIdValid(player) || !isIdValid(target) || !isIdValid(ring) )
|
|
return;
|
|
|
|
if ( !isPlayer(player) )
|
|
return;
|
|
|
|
if ( !isPlayer(target) )
|
|
{
|
|
sendSystemMessage(player, SID_TARGET_NOT_PLAYER);
|
|
return;
|
|
}
|
|
|
|
location here = getLocation(player);
|
|
location there = getLocation(target);
|
|
float distance = getDistance(here, there);
|
|
if ( distance > PROPOSAL_RANGE )
|
|
{
|
|
sendSystemMessage(player, SID_OUT_OF_RANGE);
|
|
return;
|
|
}
|
|
|
|
if ( !isFacing(player, there) )
|
|
{
|
|
sendSystemMessage(player, SID_BAD_FACING);
|
|
return;
|
|
}
|
|
|
|
if ( isMarried(target) )
|
|
{
|
|
sendSystemMessage(player, SID_TARGET_MARRIED);
|
|
return;
|
|
}
|
|
|
|
if ( hasProposed(target) )
|
|
{
|
|
sendSystemMessage(player, SID_TARGET_PROPOSED);
|
|
return;
|
|
}
|
|
|
|
if ( utils.hasScriptVar(player, VAR_PROPOSAL_NAME) )
|
|
{
|
|
string proposedTarget = getStringObjVar(player, VAR_PROPOSAL_NAME);
|
|
if ( proposedTarget != null && !proposedTarget.equals("") )
|
|
{
|
|
prose_package ppAlreadyProposed = prose.getPackage(PROSE_ALREADY_PROPOSED, proposedTarget);
|
|
sendSystemMessageProse(player, ppAlreadyProposed);
|
|
return;
|
|
}
|
|
}
|
|
|
|
if ( !hasScript(player, SCRIPT_UNITY) )
|
|
attachScript(player, SCRIPT_UNITY);
|
|
|
|
if ( !hasScript(target, SCRIPT_UNITY) )
|
|
attachScript(target, SCRIPT_UNITY);
|
|
|
|
string targetName = getAssignedName(target);
|
|
|
|
utils.setScriptVar(player, VAR_PROPOSAL_TARGET, target);
|
|
utils.setScriptVar(player, VAR_PROPOSAL_NAME, targetName);
|
|
utils.setScriptVar(player, VAR_PROPOSAL_RING, ring);
|
|
|
|
queueCommand(player, ##"kneel", null, "", COMMAND_PRIORITY_DEFAULT);
|
|
|
|
dictionary params = new dictionary();
|
|
params.put("proposer", player);
|
|
params.put("proposerName", getAssignedName(player));
|
|
|
|
utils.setScriptVar(player, VAR_PROPOSAL_RING, ring);
|
|
|
|
|
|
prose_package ppPropose = prose.getPackage(PROSE_PROPOSE, targetName);
|
|
sendSystemMessageProse(player, ppPropose);
|
|
messageTo(target, HANDLER_PROPOSED_TO, params, 2, false);
|
|
}
|
|
|
|
void cleanupProposal(obj_id player)
|
|
{
|
|
if ( !isIdValid(player) )
|
|
return;
|
|
|
|
utils.removeScriptVar(player, VAR_PROPOSAL_TARGET);
|
|
utils.removeScriptVar(player, VAR_PROPOSAL_NAME);
|
|
utils.removeScriptVar(player, VAR_PROPOSAL_RING);
|
|
}
|
|
|
|
void cleanupProposedTo(obj_id player)
|
|
{
|
|
if ( !isIdValid(player) )
|
|
return;
|
|
|
|
utils.removeScriptVar(player, VAR_PROPOSEDTO_TARGET);
|
|
utils.removeScriptVar(player, VAR_PROPOSEDTO_NAME);
|
|
utils.removeScriptVar(player, VAR_PROPOSEDTO_RING);
|
|
}
|
|
|
|
void cleanupAcceptance(obj_id player)
|
|
{
|
|
if ( !isIdValid(player) )
|
|
return;
|
|
|
|
if ( utils.hasScriptVar(player, VAR_ACCEPT_SUI) )
|
|
{
|
|
int pid = utils.getIntScriptVar(player, VAR_ACCEPT_SUI);
|
|
forceCloseSUIPage(pid);
|
|
utils.removeScriptVar(player, VAR_ACCEPT_SUI);
|
|
}
|
|
|
|
utils.removeScriptVar(player, VAR_ACCEPT_SUI_OPTIONS);
|
|
utils.removeScriptVar(player, VAR_ACCEPT_RING);
|
|
}
|
|
|
|
obj_id[] getRings(obj_id player)
|
|
{
|
|
if ( !isIdValid(player) )
|
|
return null;
|
|
|
|
obj_id inv = utils.getInventoryContainer(player);
|
|
if ( !isIdValid(inv) )
|
|
return null;
|
|
|
|
Vector vEq = new Vector();
|
|
obj_id[] eqRings = utils.getContainedGOTObjects(player, GOT_jewelry_ring, false);
|
|
if ( eqRings != null && eqRings.length > 0 )
|
|
vEq = new Vector(Arrays.asList(eqRings));
|
|
|
|
Vector vInv = new Vector();
|
|
obj_id[] invRings = utils.getContainedGOTObjects(inv, GOT_jewelry_ring, true);
|
|
if ( invRings != null && invRings.length > 0 )
|
|
vInv = new Vector(Arrays.asList(invRings));
|
|
|
|
resizeable obj_id[] rings = utils.concatArrays(vEq, vInv);
|
|
if ( rings == null || rings.length == 0 )
|
|
return null;
|
|
|
|
return utils.toStaticObjIdArray(rings);
|
|
}
|
|
|
|
void wed(obj_id player, obj_id target)
|
|
{
|
|
if ( !isIdValid(player) || !isIdValid(target) )
|
|
return;
|
|
|
|
if ( !isPlayer(player) || !isPlayer(target) )
|
|
return;
|
|
|
|
location pLoc = getLocation(player);
|
|
location tLoc = getLocation(target);
|
|
if ( getDistance(pLoc, tLoc) > PROPOSAL_RANGE )
|
|
{
|
|
sendSystemMessage(player, SID_WED_OOR);
|
|
sendSystemMessage(target, SID_WED_OOR);
|
|
detachScript(player, SCRIPT_UNITY);
|
|
detachScript(target, SCRIPT_UNITY);
|
|
return;
|
|
}
|
|
|
|
obj_id pRing = utils.getObjIdScriptVar(player, VAR_PROPOSAL_RING);
|
|
obj_id tRing = utils.getObjIdScriptVar(target, VAR_ACCEPT_RING);
|
|
//debugSpeakMsg(player, "wedding rings: pRing = " + pRing + " tRing = " + tRing);
|
|
if ( !isIdValid(pRing) || !isIdValid(tRing) )
|
|
{
|
|
weddingError(player, target);
|
|
return;
|
|
}
|
|
|
|
obj_id pSlot = getObjectInSlot(player, "ring_l");
|
|
obj_id pInv = utils.getInventoryContainer(player);
|
|
if ( isIdValid(pSlot) && isIdValid(pInv) )
|
|
putInOverloaded(pSlot, pInv);
|
|
|
|
putInOverloaded(pRing, pInv);
|
|
|
|
obj_id tSlot = getObjectInSlot(player, "ring_l");
|
|
obj_id tInv = utils.getInventoryContainer(target);
|
|
if ( isIdValid(tSlot) && isIdValid(tInv) )
|
|
putInOverloaded(tSlot, tInv);
|
|
|
|
putInOverloaded(tRing, tInv);
|
|
|
|
dictionary toPlayer = new dictionary();
|
|
toPlayer.put("other", target);
|
|
toPlayer.put("ring", pRing);
|
|
|
|
|
|
dictionary toTarget = new dictionary();
|
|
toTarget.put("other", player);
|
|
toTarget.put("ring", tRing);
|
|
|
|
|
|
messageTo(player, HANDLER_RING_SETUP, toPlayer, 0, false);
|
|
messageTo(target, HANDLER_RING_SETUP, toTarget, 0, false);
|
|
}
|
|
|
|
void weddingError(obj_id player, obj_id target)
|
|
{
|
|
sendSystemMessage(player, SID_WED_ERROR);
|
|
sendSystemMessage(target, SID_WED_ERROR);
|
|
detachScript(player, SCRIPT_UNITY);
|
|
detachScript(target, SCRIPT_UNITY);
|
|
}
|
|
|
|
void weddingError(obj_id player)
|
|
{
|
|
obj_id target = null;
|
|
if ( utils.hasScriptVar(player, VAR_PROPOSAL_TARGET) )
|
|
{
|
|
target = utils.getObjIdScriptVar(player, VAR_PROPOSAL_TARGET);
|
|
}
|
|
|
|
if ( utils.hasScriptVar(player, VAR_PROPOSEDTO_TARGET) )
|
|
{
|
|
target = utils.getObjIdScriptVar(player, VAR_PROPOSEDTO_TARGET);
|
|
}
|
|
|
|
if ( isIdValid(target) )
|
|
{
|
|
weddingError(player, target);
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessage(player, SID_WED_ERROR);
|
|
detachScript(player, SCRIPT_UNITY);
|
|
}
|
|
}
|
|
|
|
void divorce(obj_id player)
|
|
{
|
|
if ( !isIdValid(player) )
|
|
return;
|
|
|
|
if ( !isMarried(player) )
|
|
return;
|
|
|
|
obj_id spouse = getObjIdObjVar(player, VAR_SPOUSE_ID);
|
|
if ( isIdValid(spouse) )
|
|
{
|
|
dictionary params = new dictionary();
|
|
params.put("self", player);
|
|
|
|
messageTo(spouse, HANDLER_DIVORCE, params, 0, true);
|
|
}
|
|
|
|
endUnity(player);
|
|
}
|
|
|
|
void declineProposal(obj_id player)
|
|
{
|
|
if ( !isIdValid(player) )
|
|
return;
|
|
|
|
obj_id proposer = utils.getObjIdScriptVar(player, VAR_PROPOSEDTO_TARGET);
|
|
if ( isIdValid(proposer) )
|
|
{
|
|
messageTo(proposer, HANDLER_PROPOSAL_DECLINED, null, 0, false);
|
|
}
|
|
|
|
sendSystemMessage(player, SID_DECLINE);
|
|
detachScript(player, SCRIPT_UNITY);
|
|
}
|
|
|
|
void cannotAccept(obj_id player)
|
|
{
|
|
if ( !isIdValid(player) )
|
|
return;
|
|
|
|
obj_id proposer = utils.getObjIdScriptVar(player, VAR_PROPOSEDTO_TARGET);
|
|
if ( isIdValid(proposer) )
|
|
{
|
|
messageTo(proposer, HANDLER_ACCEPT_FAIL, null, 0, false);
|
|
}
|
|
|
|
sendSystemMessage(player, SID_NO_RING);
|
|
detachScript(player, SCRIPT_UNITY);
|
|
}
|
|
|
|
void endUnity(obj_id player)
|
|
{
|
|
if ( !isIdValid(player) )
|
|
return;
|
|
|
|
string spouseName = getStringObjVar(player, VAR_SPOUSE_NAME);
|
|
|
|
obj_id ring = getObjIdObjVar(player, VAR_RING);
|
|
if ( !isIdValid(ring) )
|
|
{
|
|
ring = getObjectInSlot(player, "ring_l");
|
|
}
|
|
|
|
if ( isIdValid(ring) )
|
|
detachScript(ring, SCRIPT_RING_UNITY);
|
|
|
|
prose_package ppEndUnity = prose.getPackage(PROSE_END_UNITY, spouseName);
|
|
sendSystemMessageProse(player, ppEndUnity);
|
|
|
|
removeObjVar(player, VAR_MARRIAGE_BASE);
|
|
}
|