mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-08-03 03:15:55 -04:00
170 lines
4.2 KiB
Plaintext
170 lines
4.2 KiB
Plaintext
/**
|
|
* Copyright (c)2000-2002 Sony Online Entertainment Inc.
|
|
* All Rights Reserved
|
|
*
|
|
* Title: lifeday gift xmas 2005
|
|
* Description: Grants holiday items to the player and unpacks them
|
|
* @author Thomas Blair
|
|
* @version 1.0
|
|
*/
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
include library.utils;
|
|
include library.static_item;
|
|
include java.util.HashSet;
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
|
|
const string_id CRATE_USED = new string_id("spam", "opened_crate");
|
|
const string_id GIVE_AWAY = new string_id("spam", "give_away");
|
|
const string_id OUTSIDE = new string_id("spam", "must_be_outside");
|
|
const string_id MOUNTED = new string_id("spam", "mounted");
|
|
const string_id UNABLE = new string_id("spam", "no_data");
|
|
const string LIFEDAY_TABLE = "datatables/event/lifeday/lifeday_gift.iff";
|
|
|
|
|
|
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
|
|
{
|
|
if (canManipulate(player, self, true, true, 5, true))
|
|
{
|
|
if (utils.isNestedWithinAPlayer(self))
|
|
{
|
|
menu_info_data mid = mi.getMenuItemByType(menu_info_types.ITEM_USE);
|
|
if ( mid != null )
|
|
mid.setServerNotify(true);
|
|
else
|
|
mi.addRootMenu(menu_info_types.ITEM_USE, new string_id("ui_radial", "item_use"));
|
|
}
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
|
|
trigger OnObjectMenuSelect(obj_id player, int item)
|
|
{
|
|
if(utils.getContainingPlayer(self) != player )
|
|
return SCRIPT_CONTINUE;
|
|
|
|
if (item == menu_info_types.ITEM_USE)
|
|
{
|
|
string [] itemNames = new string[1];
|
|
dictionary giftData = new dictionary();
|
|
string year = getStringObjVar(self, "year");
|
|
|
|
if(year == null || year.equals (""))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
giftData = dataTableGetRow(LIFEDAY_TABLE, year);
|
|
|
|
if (giftData == null)
|
|
{
|
|
sendSystemMessage (player, UNABLE);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
//this is a gift for someone else
|
|
if(hasObjVar(self, utils.LIFEDAY_OWNER))
|
|
{
|
|
obj_id owner = getObjIdObjVar(self , utils.LIFEDAY_OWNER);
|
|
|
|
if(owner != player)
|
|
{
|
|
string giftsOtherUnparsed = giftData.getString("gift_other");
|
|
string [] giftsOther = split(giftsOtherUnparsed, ',');
|
|
|
|
itemNames[0] = giftsOther[rand(0, giftsOther.length-1)];
|
|
|
|
//oh yes we might want to give them all the gifts!
|
|
int grantAllGiftsOther = giftData.getInt("grant_all_other");
|
|
if (grantAllGiftsOther != 0)
|
|
{
|
|
itemNames = giftsOther;
|
|
}
|
|
|
|
if(grantReward(player, itemNames, giftData))
|
|
{
|
|
destroyObject(self);
|
|
sendSystemMessage (player, CRATE_USED);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessage (player, GIVE_AWAY);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//this is a gift for you
|
|
string giftsSelfUnparsed = giftData.getString("gift_self");
|
|
string [] giftsSelf = split(giftsSelfUnparsed, ',');
|
|
|
|
itemNames[0] = giftsSelf[rand(0, giftsSelf.length-1)];
|
|
|
|
//oh yes we might want to give them all the gifts!
|
|
int grantAllGiftsSelf = giftData.getInt("grant_all_self");
|
|
if (grantAllGiftsSelf != 0)
|
|
{
|
|
itemNames = giftsSelf;
|
|
}
|
|
|
|
if(grantReward(player, itemNames, giftData))
|
|
{
|
|
destroyObject(self);
|
|
sendSystemMessage (player, CRATE_USED);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
boolean grantReward (obj_id player, string[] itemNames, dictionary giftData)
|
|
{
|
|
obj_id mount = getMountId(player);
|
|
|
|
//Can't use the gift while on a mount.
|
|
if (isIdValid(mount))
|
|
{
|
|
sendSystemMessage(player, MOUNTED);
|
|
return false;
|
|
}
|
|
|
|
if (getTopMostContainer(player) != player)
|
|
{
|
|
sendSystemMessage (player, OUTSIDE);
|
|
return false;
|
|
}
|
|
|
|
if(giftData == null)
|
|
return false;
|
|
|
|
if(isIdValid(player))
|
|
{
|
|
obj_id pInv = utils.getInventoryContainer(player);
|
|
if (isIdValid(pInv) && (itemNames != null && itemNames.length > 0))
|
|
{
|
|
HashSet theSet = new HashSet();
|
|
|
|
for(int i = 0; i < itemNames.length; i++)
|
|
{
|
|
theSet.add(static_item.createNewItemFunction(itemNames[i], pInv));
|
|
}
|
|
|
|
obj_id[] gift = new obj_id[theSet.size()];
|
|
theSet.toArray(gift);
|
|
showLootBox(player, gift);
|
|
|
|
playMusic( player, giftData.getString("music"));
|
|
playClientEffectObj(player, giftData.getString("client_effect"), player, "");
|
|
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|