Files
dsrc/sku.0/sys.server/compiled/game/script/event/lifeday/monkey_pet.script
T

311 lines
7.3 KiB
Plaintext

/***** INCLUDES ********************************************************/
include library.create;
include library.utils;
include library.player_structure;
include library.locations
include library.space_transition;
include library.space_utils;
include library.buff;
include library.ai_lib;
/***** CONSTS **********************************************************/
const string LIFEDAY = new string("event/life_day");
const string MONKEY_RED = new string("lifeday_monkey_lizard");
const string MONKEY_GREEN = new string("lifeday_monkey_lizard_green");
//laugh and animations
const string LAUGH = new string("sound/voc_kowakian_laugh.snd");
const string ANIMATION_1 = new string("wave2");
const string ANIMATION_2 = new string("laugh_cackle");
const string ANIMATION_3 = new string("pound_fist_palm");
const string ANIMATION_4 = new string("bow2");
const string ANIMATION_5 = new string("wave1");
//Misc
const string_id SID_TURN_ON = new string_id(LIFEDAY, "free_monkey");
const string_id SID_TURN_OFF = new string_id(LIFEDAY, "cage_monkey");
/***** FUNCTIONS ********************************************************/
trigger OnInitialize()
{
if (inHouse(self))
{
location spawnLoc = getLocation(self);
spawnLoc.x += 1;
if (hasObjVar(self, "petCalled"))
{
if (hasObjVar(self, "petId"))
{
obj_id oldPet = getObjIdObjVar(self, "petId");
if (!exists(oldPet))
{
obj_id monkey = create.object(whichMonkey(), spawnLoc);
ai_lib.setDefaultCalmBehavior(monkey, ai_lib.BEHAVIOR_WANDER);
setObjVar(self, "petId", monkey);
setObjVar(monkey, "momId", self);
}
}
else
{
obj_id monkey = create.object(whichMonkey(), spawnLoc);
setObjVar(self, "petId", monkey);
setObjVar(monkey, "momId", self);
}
createTriggerVolume("laughAura", 5, true);
}
else
removeTriggerVolume("laughAura");
}
return SCRIPT_CONTINUE;
}
trigger OnAttach()
{
if (inHouse(self))
{
location spawnLoc = getLocation(self);
spawnLoc.x += 1;
if (hasObjVar(self, "petCalled"))
{
if (hasObjVar(self, "petId"))
{
obj_id oldPet = getObjIdObjVar(self, "petId");
if (!exists(oldPet))
{
obj_id monkey = create.object(whichMonkey(), spawnLoc);
ai_lib.setDefaultCalmBehavior(monkey, ai_lib.BEHAVIOR_LOITER);
setObjVar(self, "petId", monkey);
setObjVar(monkey, "momId", self);
}
}
else
{
obj_id monkey = create.object(whichMonkey(), spawnLoc);
setObjVar(self, "petId", monkey);
setObjVar(monkey, "momId", self);
}
createTriggerVolume("laughAura", 5, true);
}
else
removeTriggerVolume("laughAura");
}
return SCRIPT_CONTINUE;
}
trigger OnAboutToBeTransferred(obj_id destContainer, obj_id transferer)
{
if (hasObjVar(self, "petCalled"))
{
if (hasObjVar(self, "petId"))
{
obj_id oldPet = getObjIdObjVar(self, "petId");
if (exists(oldPet))
destroyObject(oldPet);
removeObjVar(self, "petId");
}
removeObjVar(self, "petCalled");
}
return SCRIPT_CONTINUE;
}
trigger OnTriggerVolumeEntered(string volumeName, obj_id breacher)
{
//To not play the monkey laugh too often we set a invisible lockout buff on the player.
if (!buff.hasBuff(breacher, "event_lifeday_no_laugh"))
{
if (volumeName == "laughAura")
{
if (hasObjVar(self, "petId"))
{
obj_id monkey = getObjIdObjVar(self, "petId");
if (exists(monkey))
{
int idx = rand(0,4);
dictionary params = new dictionary ();
params.put("breacher", breacher);
params.put("monkey", monkey);
params.put("idx", idx);
messageTo(self, "animationOne", params, 3, false);
messageTo(self, "animationTwo", params, 6, false);
messageTo(self, "getMoving", params, 9, false);
faceTo(monkey, breacher);
suspendMovement(monkey);
buff.applyBuff(breacher, "event_lifeday_no_laugh");
}
}
}
}
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
if (inHouse(self))
{
menu_info_data data = mi.getMenuItemByType (menu_info_types.ITEM_USE);
mi.addRootMenu (menu_info_types.ITEM_USE, new string_id("",""));
if(hasObjVar(self, "petCalled"))
int monkeyCalled = mi.addRootMenu(menu_info_types.ITEM_USE, SID_TURN_OFF);
else
int monkeyCalled = mi.addRootMenu(menu_info_types.ITEM_USE, SID_TURN_ON);
}
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id player, int item)
{
if(inHouse(self))
{
if(item == menu_info_types.ITEM_USE && !hasObjVar(self, "petCalled"))
{
//release the monkey
location spawnLoc = getLocation(self);
spawnLoc.x += 1;
obj_id monkey = create.object(whichMonkey(), spawnLoc);
ai_lib.setDefaultCalmBehavior(monkey, ai_lib.BEHAVIOR_LOITER);
setObjVar(self, "petCalled", 1);
setObjVar(self, "petId", monkey);
setObjVar(monkey, "momId", self);
createTriggerVolume("laughAura", 5, true);
return SCRIPT_CONTINUE;
}
if(item == menu_info_types.ITEM_USE && hasObjVar(self, "petCalled"))
{
//Cage the monkey
if (hasObjVar(self, "petId"))
{
obj_id oldPet = getObjIdObjVar(self, "petId");
if (exists(oldPet))
destroyObject(oldPet);
removeObjVar(self, "petId");
}
removeObjVar(self, "petCalled");
removeTriggerVolume("laughAura");
}
}
return SCRIPT_CONTINUE;
}
//Which color on the monkeys clothes? 1 is red, 2 is green.
string whichMonkey()
{
int monkeyColor = rand(1,2);
if (monkeyColor > 1)
return MONKEY_GREEN;
else
return MONKEY_RED;
}
//House or POB ship check.
boolean inHouse(obj_id device)
{
obj_id selfContainer = getContainedBy(device);
obj_id ship = space_transition.getContainingShip(selfContainer);
string templateName ="";
if(isIdValid(ship))
{
templateName = getTemplateName(ship);
}
if ((utils.isInHouseCellSpace(device) || space_utils.isPobType(templateName)) && !utils.isNestedWithinAPlayer(device))
return true;
return false;
}
//Playing animations twice to make them more obvious.
messageHandler animationOne()
{
int idx = params.getInt("idx");
obj_id breacher = params.getObjId("breacher");
obj_id monkey = params.getObjId("monkey");
play2dNonLoopingMusic(breacher, LAUGH);
switch(idx)
{
case 0:
doAnimationAction(monkey, ANIMATION_1);
break;
case 1:
doAnimationAction(monkey, ANIMATION_2);
break;
case 2:
doAnimationAction(monkey, ANIMATION_3);
break;
case 3:
doAnimationAction(monkey, ANIMATION_4);
break;
case 4:
doAnimationAction(monkey, ANIMATION_5);
break;
default:
}
return SCRIPT_CONTINUE;
}
messageHandler animationTwo()
{
int idx = params.getInt("idx");
obj_id breacher = params.getObjId("breacher");
obj_id monkey = params.getObjId("monkey");
switch(idx)
{
case 0:
doAnimationAction(monkey, ANIMATION_1);
break;
case 1:
doAnimationAction(monkey, ANIMATION_2);
break;
case 2:
doAnimationAction(monkey, ANIMATION_3);
break;
case 3:
doAnimationAction(monkey, ANIMATION_4);
break;
case 4:
doAnimationAction(monkey, ANIMATION_5);
break;
default:
}
return SCRIPT_CONTINUE;
}
messageHandler getMoving()
{
obj_id monkey = params.getObjId("monkey");
resumeMovement(monkey);
return SCRIPT_CONTINUE;
}
trigger OnDestroy()
{
if (hasObjVar(self, "petCalled"))
{
if (hasObjVar(self, "petId"))
{
obj_id oldPet = getObjIdObjVar(self, "petId");
if (exists(oldPet))
destroyObject(oldPet);
removeObjVar(self, "petId");
}
removeObjVar(self, "petCalled");
}
return SCRIPT_CONTINUE;
}