who isn't sick of converting the freaking scripts? this negates the need

This commit is contained in:
DarthArgus
2015-11-24 09:27:45 -06:00
parent 2e64106bc8
commit bbee2d328c
11077 changed files with 2604347 additions and 3425075 deletions
@@ -0,0 +1,466 @@
package script.corpse;
import script.*;
import script.base_class.*;
import script.combat_engine.*;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
import script.base_script;
import script.library.pet_lib;
import script.library.beast_lib;
import script.library.utils;
import script.library.corpse;
import script.library.permissions;
import script.library.money;
import script.library.prose;
import script.library.group;
import script.library.ai_lib;
import script.library.loot;
import script.library.smuggler;
public class ai_corpse extends script.base_script
{
public ai_corpse()
{
}
public static final string_id SID_NO_ITEMS = new string_id("loot_n", "no_items");
public static final string_id SID_NOT_IN_COMBAT = new string_id("loot_n", "not_in_combat");
public int OnAttach(obj_id self) throws InterruptedException
{
setCreatureStatic(self, true);
if (beast_lib.isBeast(self))
{
return SCRIPT_CONTINUE;
}
obj_id inventory = utils.getInventoryContainer(self);
if (!hasScript(inventory, corpse.SCRIPT_AI_CORPSE_INVENTORY))
{
attachScript(inventory, corpse.SCRIPT_AI_CORPSE_INVENTORY);
}
utils.setScriptVar(self, "timeLootable", getGameTime() + 1);
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, corpse.AI_CORPSE_EXPIRATION_TIME, false);
return SCRIPT_CONTINUE;
}
public int OnObjectMenuRequest(obj_id self, obj_id player, menu_info mi) throws InterruptedException
{
if (beast_lib.isBeast(self))
{
return SCRIPT_CONTINUE;
}
boolean canOpen = corpse.hasLootPermissions(self, player);
int mnu = -1;
menu_info_data mid = mi.getMenuItemByType(menu_info_types.LOOT);
if (mid == null)
{
mnu = mi.addRootMenu(menu_info_types.LOOT, new string_id("", ""));
}
else
{
mid.setServerNotify(true);
mnu = mid.getId();
}
if (mnu > 0)
{
if (canOpen)
{
if (canHarvest(self, player))
{
int[] hasResource = getIntArrayObjVar(self, corpse.VAR_HAS_RESOURCE);
if (hasResource != null)
{
int hm = mi.addRootMenu(menu_info_types.SERVER_HARVEST_CORPSE, corpse.SID_HARVEST_CORPSE);
if (hasResource[corpse.CCR_MEAT] > 0)
{
mi.addSubMenu(hm, menu_info_types.SERVER_MENU5, corpse.SID_HARVEST_MEAT);
}
if (hasResource[corpse.CCR_HIDE] > 0)
{
mi.addSubMenu(hm, menu_info_types.SERVER_MENU6, corpse.SID_HARVEST_HIDE);
}
if (hasResource[corpse.CCR_BONE] > 0)
{
mi.addSubMenu(hm, menu_info_types.SERVER_MENU7, corpse.SID_HARVEST_BONE);
}
}
}
}
}
String strLootTable = getStringObjVar(self, "loot.lootTable");
if (strLootTable == null || strLootTable.length() < 1)
{
return SCRIPT_CONTINUE;
}
if ((!strLootTable.startsWith("npc") && !strLootTable.startsWith("droid")) || utils.hasScriptVar(self, "contrabandChecked"))
{
return SCRIPT_CONTINUE;
}
String playerClass = getSkillTemplate(player);
if (isIdValid(player) && canOpen && playerClass.startsWith("smuggler") && getLevel(player) > 9)
{
mnu = mi.addRootMenu(menu_info_types.SERVER_MENU1, new string_id("smuggler/items", "mnu_find_illicit_goods"));
}
return SCRIPT_CONTINUE;
}
public int OnObjectMenuSelect(obj_id self, obj_id player, int item) throws InterruptedException
{
if (getState(player, STATE_COMBAT) == 1)
{
sendSystemMessage(player, SID_NOT_IN_COMBAT);
return SCRIPT_OVERRIDE;
}
if (utils.getDistance2D(self, player) > 10)
{
return SCRIPT_OVERRIDE;
}
if (beast_lib.isBeast(self))
{
return SCRIPT_CONTINUE;
}
int timeLootable = utils.getIntScriptVar(self, "timeLootable");
int currentTime = getGameTime();
if (timeLootable >= currentTime)
{
return SCRIPT_OVERRIDE;
}
boolean canOpen = corpse.hasLootPermissions(self, player);
if (!isMob(self))
{
return SCRIPT_OVERRIDE;
}
if (!isIncapacitated(self))
{
return SCRIPT_OVERRIDE;
}
if (isIncapacitated(player))
{
return SCRIPT_OVERRIDE;
}
if (pet_lib.isPet(self))
{
return SCRIPT_OVERRIDE;
}
if (!hasObjVar(self, "readyToLoot"))
{
return SCRIPT_OVERRIDE;
}
if (item == menu_info_types.SERVER_MENU1)
{
String playerClass = getSkillTemplate(player);
if (isIdValid(player) && canOpen && playerClass.startsWith("smuggler") && getLevel(player) > 9)
{
smuggler.inspectCorpseForContraband(player, self);
}
}
obj_id inv = utils.getInventoryContainer(self);
obj_id[] items = getContents(inv);
boolean emptyCorpse = (items == null || items.length < 1);
if (item == menu_info_types.LOOT)
{
if (canOpen)
{
if (isIdValid(inv))
{
if (!isIdValid(player) || !isPlayer(player) || getContainerType(self) == 0)
{
return SCRIPT_OVERRIDE;
}
if (pet_lib.isPet(self))
{
return SCRIPT_OVERRIDE;
}
if (group.isGrouped(player))
{
obj_id team = getGroupObject(player);
int lootRule = getGroupLootRule(team);
if (lootRule == group.MASTER_LOOTER)
{
if (!loot.doGroupLootAllCheck(player, self))
{
return SCRIPT_OVERRIDE;
}
}
else if (lootRule == group.LOTTERY)
{
if (hasObjVar(self, "allowedToOpenFromFailedTransfer_" + player))
{
if (!emptyCorpse)
{
queueCommand(player, (1880585606), inv, "", COMMAND_PRIORITY_DEFAULT);
}
else
{
sendSystemMessage(player, SID_NO_ITEMS);
if (!canHarvest(self, player) && !utils.hasScriptVar(self, "quickDestroy"))
{
utils.setScriptVar(self, "quickDestroy", true);
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, 2.0f, false);
}
}
return SCRIPT_CONTINUE;
}
if (!loot.doGroupLootAllCheck(player, self))
{
return SCRIPT_OVERRIDE;
}
}
}
if (!emptyCorpse)
{
queueCommand(player, (1880585606), inv, "", COMMAND_PRIORITY_DEFAULT);
}
else
{
sendSystemMessage(player, SID_NO_ITEMS);
if (!canHarvest(self, player) && !utils.hasScriptVar(self, "quickDestroy"))
{
utils.setScriptVar(self, "quickDestroy", true);
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, 2.0f, false);
}
}
}
return SCRIPT_CONTINUE;
}
}
else
{
if (canOpen)
{
if (canHarvest(self, player))
{
if (item == menu_info_types.SERVER_HARVEST_CORPSE)
{
queueCommand(player, (43846853), self, "", COMMAND_PRIORITY_DEFAULT);
}
else if (item == menu_info_types.SERVER_MENU5)
{
queueCommand(player, (43846853), self, "meat", COMMAND_PRIORITY_DEFAULT);
}
else if (item == menu_info_types.SERVER_MENU6)
{
queueCommand(player, (43846853), self, "hide", COMMAND_PRIORITY_DEFAULT);
}
else if (item == menu_info_types.SERVER_MENU7)
{
queueCommand(player, (43846853), self, "bone", COMMAND_PRIORITY_DEFAULT);
}
sendDirtyObjectMenuNotification(self);
}
}
}
if (!canOpen)
{
sendSystemMessage(player, permissions.SID_NO_CORPSE_PERMISSION);
}
return SCRIPT_CONTINUE;
}
public int harvestCorpse(obj_id self, dictionary params) throws InterruptedException
{
if (params == null)
{
return SCRIPT_CONTINUE;
}
obj_id player = params.getObjId("player");
if (!isIdValid(player))
{
return SCRIPT_CONTINUE;
}
String args = params.getString("args");
corpse.harvestCreatureCorpse(player, self, args);
return SCRIPT_CONTINUE;
}
public int handleLootAddPass(obj_id self, dictionary params) throws InterruptedException
{
int bankBalance = getBankBalance(self);
withdrawCashFromBank(self, bankBalance, money.HANDLER_LOOT_WITHDRAW_PASS, money.HANDLER_LOOT_WITHDRAW_FAIL, params);
return SCRIPT_CONTINUE;
}
public int handleLootAddFail(obj_id self, dictionary params) throws InterruptedException
{
return SCRIPT_CONTINUE;
}
public int handleLootWithdrawPass(obj_id self, dictionary params) throws InterruptedException
{
if (params != null)
{
int amt = params.getInt(money.DICT_AMOUNT);
}
else
{
}
return SCRIPT_CONTINUE;
}
public int handleLootWithdrawFail(obj_id self, dictionary params) throws InterruptedException
{
return SCRIPT_CONTINUE;
}
public int handleCorpseExpire(obj_id self, dictionary params) throws InterruptedException
{
obj_id inv = utils.getInventoryContainer(self);
if (isIdValid(inv))
{
obj_id[] contents = getContents(inv);
if ((contents != null) && (contents.length != 0))
{
int time = getGameTime();
int lootTime = utils.getIntScriptVar(self, "lootTimestamp");
if (time - lootTime < 60)
{
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, 10, false);
return SCRIPT_CONTINUE;
}
}
}
destroyObject(self);
return SCRIPT_CONTINUE;
}
public int handleCorpseEmpty(obj_id self, dictionary params) throws InterruptedException
{
obj_id inv = utils.getInventoryContainer(self);
if (isIdValid(inv))
{
obj_id[] contents = getContents(inv);
if ((contents == null) || (contents.length == 0))
{
int cash = getCashBalance(self);
if (cash == 0)
{
if (!hasObjVar(self, corpse.VAR_HAS_RESOURCE))
{
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, 0, false);
return SCRIPT_CONTINUE;
}
else
{
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, corpse.AI_CORPSE_EMPTY_TIME, false);
return SCRIPT_CONTINUE;
}
}
}
}
return SCRIPT_CONTINUE;
}
public int handleAttemptCorpseCleanup(obj_id self, dictionary params) throws InterruptedException
{
messageTo(self, "handleCorpseEmpty", null, 0, false);
return SCRIPT_CONTINUE;
}
public int OnLootLotterySelected(obj_id self, obj_id player, obj_id[] selection_ids) throws InterruptedException
{
obj_id selfInv = utils.getInventoryContainer(self);
int numWindowsOpen = getIntObjVar(self, "numWindowsOpen");
numWindowsOpen = numWindowsOpen - 1;
setObjVar(self, "numWindowsOpen", numWindowsOpen);
for (int i = 0; i < selection_ids.length; ++i)
{
obj_id thisObject = selection_ids[i];
if (!hasObjVar(thisObject, "numLotteryPlayers"))
{
setObjVar(thisObject, "numLotteryPlayers", 1);
setObjVar(thisObject, "lotteryPlayer1", player);
}
else
{
int numLotteryPlayers = getIntObjVar(thisObject, "numLotteryPlayers");
numLotteryPlayers = numLotteryPlayers + 1;
setObjVar(thisObject, "lotteryPlayer" + numLotteryPlayers, player);
setObjVar(thisObject, "numLotteryPlayers", numLotteryPlayers);
}
}
return SCRIPT_CONTINUE;
}
public int fireLotteryPulse(obj_id self, dictionary params) throws InterruptedException
{
obj_id player = params.getObjId("player");
obj_id corpseInv = params.getObjId("corpseInv");
obj_id corpseId = getContainedBy(corpseInv);
int numTimesFired = params.getInt("fired");
int numWindowsOpen = getIntObjVar(corpseId, "numWindowsOpen");
numTimesFired = numTimesFired + 1;
if (!utils.hasScriptVar(self, "default_money_recipient_inventory"))
{
utils.setScriptVar(self, "default_money_recipient_inventory", utils.getInventoryContainer(player));
}
if (numTimesFired > 18 || numWindowsOpen <= 0)
{
boolean allTransfersComplete = true;
obj_id[] corpseContents = getContents(corpseInv);
for (int i = 0; i < corpseContents.length; ++i)
{
obj_id item = corpseContents[i];
int numLotteryPlayers = getIntObjVar(item, "numLotteryPlayers");
int lotteryNumber = rand(1, numLotteryPlayers);
obj_id lottoWinner = getObjIdObjVar(item, "lotteryPlayer" + lotteryNumber);
if (numWindowsOpen > 0)
{
setObjVar(item, "pickupable", lottoWinner);
}
obj_id winventory = utils.getInventoryContainer(lottoWinner);
utils.setScriptVar(lottoWinner, "autostack.ignoreitems", 1);
if (loot.isCashLootItem(item))
{
if (isIdNull(winventory))
{
winventory = utils.getObjIdScriptVar(self, "default_money_recipient_inventory");
}
putIn(item, winventory);
continue;
}
if (!putIn(item, winventory))
{
if (!loot.isCashLootItem(item))
{
String transferProblem = "full_inventory_free_for_all";
boolean inventoryHasRoom = (getVolumeFree(winventory) > 0);
if (inventoryHasRoom)
{
transferProblem = "unable_to_transfer";
setObjVar(corpseId, "allowedToOpenFromFailedTransfer_" + lottoWinner, 1);
setObjVar(item, "pickupable", lottoWinner);
}
else
{
loot.setAutoLootComplete(lottoWinner, corpseId, item);
}
dictionary proseParameters = new dictionary();
proseParameters.put("stf", group.GROUP_STF);
proseParameters.put("message", transferProblem);
proseParameters.put("TO", item);
proseParameters.put("TT", lottoWinner);
obj_id gid = getGroupObject(lottoWinner);
obj_id[] members = utils.getLocalGroupMemberIds(gid);
for (int x = 0; x < members.length; ++x)
{
messageTo(members[x], "sendSystemMessageProseAuthoritative", proseParameters, 1, true);
}
allTransfersComplete = false;
}
}
else
{
loot.sendGroupLootSystemMessage(item, lottoWinner, "loot_n", "group_looted");
messageTo(item, "msgStackItem", null, 1, false);
}
utils.removeScriptVar(lottoWinner, "autostack.ignoreitems");
}
if (allTransfersComplete)
{
messageTo(corpseId, "handleCorpseEmpty", null, 1f, isObjectPersisted(corpseId));
}
return SCRIPT_CONTINUE;
}
dictionary lottery = new dictionary();
lottery.put("fired", numTimesFired);
lottery.put("player", player);
lottery.put("corpseInv", corpseInv);
obj_id team = getGroupObject(player);
obj_id[] objMembersWhoExist = utils.getLocalGroupMemberIds(team);
messageTo(self, "fireLotteryPulse", lottery, 2, true);
return SCRIPT_CONTINUE;
}
public boolean canHarvest(obj_id self, obj_id player) throws InterruptedException
{
return (hasObjVar(self, corpse.VAR_HAS_RESOURCE) && !utils.hasScriptVar(self, "harvestedBy." + player));
}
}
@@ -1,632 +0,0 @@
/**
* Title: ai_corpse.script
* Description: ai corpse script: to be attached to killed creatures
*/
/***** INCLUDES ********************************************************/
include library.pet_lib;
include library.beast_lib;
include library.utils;
include library.corpse;
include library.permissions;
include library.money;
include library.prose;
include library.group;
include library.ai_lib;
include library.loot;
include library.smuggler;
/***** CONSTANTS *******************************************************/
const string_id SID_NO_ITEMS = new string_id( "loot_n", "no_items" );
const string_id SID_NOT_IN_COMBAT = new string_id( "loot_n", "not_in_combat" );
/***** TRIGGER *********************************************************/
trigger OnAttach()
{
setCreatureStatic(self, true);
if(beast_lib.isBeast(self))
{
return SCRIPT_CONTINUE;
}
obj_id inventory = utils.getInventoryContainer(self);
if ( !hasScript(inventory, corpse.SCRIPT_AI_CORPSE_INVENTORY) )
{
attachScript(inventory, corpse.SCRIPT_AI_CORPSE_INVENTORY);
}
utils.setScriptVar( self, "timeLootable", getGameTime() + 1 );
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, corpse.AI_CORPSE_EXPIRATION_TIME, false);
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
if(beast_lib.isBeast(self))
{
return SCRIPT_CONTINUE;
}
boolean canOpen = corpse.hasLootPermissions(self, player);
int mnu = -1;
menu_info_data mid = mi.getMenuItemByType(menu_info_types.LOOT);
if ( mid == null )
{
mnu = mi.addRootMenu (menu_info_types.LOOT, new string_id("",""));
}
else
{
mid.setServerNotify(true);
mnu = mid.getId();
}
if ( mnu > 0 )
{
if ( canOpen )
{
if ( canHarvest( self, player ) )
{
int[] hasResource = getIntArrayObjVar(self, corpse.VAR_HAS_RESOURCE);
if ( hasResource != null )
{
int hm = mi.addRootMenu( menu_info_types.SERVER_HARVEST_CORPSE, corpse.SID_HARVEST_CORPSE );
if ( hasResource[corpse.CCR_MEAT] > 0 )
mi.addSubMenu( hm, menu_info_types.SERVER_MENU5, corpse.SID_HARVEST_MEAT );
if ( hasResource[corpse.CCR_HIDE] > 0 )
mi.addSubMenu( hm, menu_info_types.SERVER_MENU6, corpse.SID_HARVEST_HIDE );
if ( hasResource[corpse.CCR_BONE] > 0 )
mi.addSubMenu( hm, menu_info_types.SERVER_MENU7, corpse.SID_HARVEST_BONE );
}
}
}
}
string strLootTable = getStringObjVar(self, "loot.lootTable");
// Contraband is not available on non-npcs or previously searched corpses.
if ( strLootTable == null || strLootTable.length() < 1 )
{
return SCRIPT_CONTINUE;
}
if((!strLootTable.startsWith("npc") && !strLootTable.startsWith("droid")) || utils.hasScriptVar(self, "contrabandChecked"))
{
return SCRIPT_CONTINUE;
}
string playerClass = getSkillTemplate(player);
// Level 10 smugglers can search corpses for contraband.
if(isIdValid(player) && canOpen && playerClass.startsWith("smuggler") && getLevel(player) > 9)
{
mnu = mi.addRootMenu(menu_info_types.SERVER_MENU1, new string_id("smuggler/items", "mnu_find_illicit_goods"));
}
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id player, int item)
{
if ( getState( player, STATE_COMBAT ) == 1 )
{
sendSystemMessage( player, SID_NOT_IN_COMBAT );
return SCRIPT_OVERRIDE;
}
if ( utils.getDistance2D( self, player) > 10 )
return SCRIPT_OVERRIDE;
if(beast_lib.isBeast(self))
{
return SCRIPT_CONTINUE;
}
int timeLootable = utils.getIntScriptVar( self, "timeLootable" );
int currentTime = getGameTime();
if ( timeLootable >= currentTime )
return SCRIPT_OVERRIDE;
//debugSpeakMsg(player, "OnObjectMenuSelect: selected item = " + item);
boolean canOpen = corpse.hasLootPermissions(self, player);
if ( !isMob(self) )
{
return SCRIPT_OVERRIDE;
}
if ( !isIncapacitated(self) )
{
return SCRIPT_OVERRIDE;
}
if ( isIncapacitated(player))
{
return SCRIPT_OVERRIDE;
}
if ( pet_lib.isPet (self))
{
return SCRIPT_OVERRIDE;
}
if ( !hasObjVar(self, "readyToLoot") )
{
return SCRIPT_OVERRIDE;
}
// Search a corpse for contraband.
if ( item == menu_info_types.SERVER_MENU1)
{
string playerClass = getSkillTemplate(player);
// Level 10 smugglers can search corpses for contraband.
if(isIdValid(player) && canOpen && playerClass.startsWith("smuggler") && getLevel(player) > 9)
{
smuggler.inspectCorpseForContraband(player, self);
}
}
// Corpse looting
obj_id inv = utils.getInventoryContainer(self);
obj_id[] items = getContents(inv);
boolean emptyCorpse = ( items == null || items.length < 1 );
if ( item == menu_info_types.LOOT)
{
if ( canOpen )
{
if ( isIdValid(inv) )
{
if ( !isIdValid(player) || !isPlayer(player) || getContainerType(self) == 0 )
{
return SCRIPT_OVERRIDE;
}
if (pet_lib.isPet(self))
{
return SCRIPT_OVERRIDE;
}
if (group.isGrouped (player))
{
obj_id team = getGroupObject(player);
int lootRule = getGroupLootRule (team);
if (lootRule == group.MASTER_LOOTER) // master looter
{
// somehow were transfering when not the master looter
if (!loot.doGroupLootAllCheck (player, self))
{
return SCRIPT_OVERRIDE;
}
}
else if (lootRule == group.LOTTERY) // Lottery, we don't let you open individual objects
{
if (hasObjVar (self, "allowedToOpenFromFailedTransfer_" + player ))
{
// we previously won this item.
if (!emptyCorpse)
queueCommand(player, ##"openContainer", inv, "", COMMAND_PRIORITY_DEFAULT);
else
{
sendSystemMessage( player, SID_NO_ITEMS );
if (!canHarvest(self,player) && !utils.hasScriptVar(self,"quickDestroy") )
{
utils.setScriptVar(self,"quickDestroy", true);
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, 2.0f, false);
}
}
return SCRIPT_CONTINUE;
}
if (!loot.doGroupLootAllCheck (player, self))
{
return SCRIPT_OVERRIDE;
}
}
}
if (!emptyCorpse)
queueCommand(player, ##"openContainer", inv, "", COMMAND_PRIORITY_DEFAULT);
else
{
sendSystemMessage( player, SID_NO_ITEMS );
if (!canHarvest(self,player) && !utils.hasScriptVar(self,"quickDestroy") )
{
utils.setScriptVar(self,"quickDestroy", true);
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, 2.0f, false);
}
}
}
return SCRIPT_CONTINUE;
}
}
else // HA HA
{
if ( canOpen )
{
if ( canHarvest( self, player ) )
{
if ( item == menu_info_types.SERVER_HARVEST_CORPSE )
{
queueCommand( player, ##"harvestCorpse", self, "", COMMAND_PRIORITY_DEFAULT );
}
else if ( item == menu_info_types.SERVER_MENU5 )
{
queueCommand( player, ##"harvestCorpse", self, "meat", COMMAND_PRIORITY_DEFAULT );
}
else if ( item == menu_info_types.SERVER_MENU6 )
{
queueCommand( player, ##"harvestCorpse", self, "hide", COMMAND_PRIORITY_DEFAULT );
}
else if ( item == menu_info_types.SERVER_MENU7 )
{
queueCommand( player, ##"harvestCorpse", self, "bone", COMMAND_PRIORITY_DEFAULT );
}
sendDirtyObjectMenuNotification(self);
}
}
}
if ( !canOpen )
sendSystemMessage( player, permissions.SID_NO_CORPSE_PERMISSION );
return SCRIPT_CONTINUE;
}
// Player harvesting removed, resources are now loot on the creature.
messageHandler harvestCorpse()
{
// Valid parameters.
if ( params == null )
return SCRIPT_CONTINUE;
obj_id player = params.getObjId( "player" );
if ( !isIdValid( player ) )
return SCRIPT_CONTINUE;
string args = params.getString( "args" );
// Have the corpse harvest itself.
corpse.harvestCreatureCorpse( player, self, args );
return SCRIPT_CONTINUE;
}
/***** MESSAGEHANDLERS **************************************************/
/***** LOOT HANDLERS **************************************************/
/******************************************
//BYPASSED BY LOOT SCRIPTLIB::addLoot() function
messageHandler handleRequestLootAdd()
{
if ( params == null )
{
return SCRIPT_CONTINUE;
}
//debugSpeakMsg(self, "received handleRequestLootAdd message");
int amt = params.getInt(money.DICT_AMOUNT);
if ( amt < 1 )
{
return SCRIPT_CONTINUE;
}
money.addCreatureLoot(self, amt);
return SCRIPT_CONTINUE;
}
********************************************/
messageHandler handleLootAddPass()
{
int bankBalance = getBankBalance(self);
withdrawCashFromBank(self, bankBalance, money.HANDLER_LOOT_WITHDRAW_PASS, money.HANDLER_LOOT_WITHDRAW_FAIL, params);
return SCRIPT_CONTINUE;
}
messageHandler handleLootAddFail()
{
//debugSpeakMsg(self, "unable to TRANSFER credits loot from named account!");
return SCRIPT_CONTINUE;
}
messageHandler handleLootWithdrawPass()
{
if ( params != null )
{
int amt = params.getInt(money.DICT_AMOUNT);
//debugSpeakMsg(self, "I should have " + amt + " credits in my cash account!");
}
else
{
//debugSpeakMsg(self, "handleLootWithdrawPass: should have credits but params was null!");
}
return SCRIPT_CONTINUE;
}
messageHandler handleLootWithdrawFail()
{
//debugSpeakMsg(self, "unable to WITHDRAW credits loot from bank account!");
return SCRIPT_CONTINUE;
}
/***** PERMISSIONS HANDLERS **************************************************/
//messageHandler handleCorpsePermInit()
//{
// if ( params != null )
// {
// obj_id lootWinner = params.getObjId(corpse.DICT_LOOTERS);
// obj_id[] looters = null;
//
// if ( group.isGroupObject(lootWinner) )
// {
// looters = getGroupMemberIds(lootWinner);
// }
// else
// {
// looters = new obj_id[1];
// looters[0] = lootWinner;
// }
//
// if ( (looters == null) || (looters.length == 0) )
// {
// return SCRIPT_CONTINUE;
// }
//
// for ( int i = 0; i < looters.length; i++ )
// {
// permissions.addUserToPermissionsGroup(self, looters[i], corpse.GROUP_CONSENTED);
// }
// }
// return SCRIPT_CONTINUE;
//}
/***** CLEANUP HANDLERS **************************************************/
messageHandler handleCorpseExpire()
{
obj_id inv = utils.getInventoryContainer(self);
if ( isIdValid(inv) )
{
obj_id[] contents = getContents(inv);
if ( (contents != null) && (contents.length != 0) )
{
int time = getGameTime();
int lootTime = utils.getIntScriptVar(self, "lootTimestamp");
//LOG("corpse", "TIME: " + (time - lootTime));
if (time - lootTime < 60) // Prevent corpses from expiring for 60s from the last loot
{
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, 10, false);
return SCRIPT_CONTINUE;
}
}
}
destroyObject(self);
return SCRIPT_CONTINUE;
}
messageHandler handleCorpseEmpty()
{
obj_id inv = utils.getInventoryContainer(self);
if ( isIdValid(inv) )
{
obj_id[] contents = getContents(inv);
if ( (contents == null) || (contents.length == 0) )
{
int cash = getCashBalance(self);
if ( cash == 0 )
{
if ( !hasObjVar(self, corpse.VAR_HAS_RESOURCE) )
{
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, 0, false);
return SCRIPT_CONTINUE;
}
else
{
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, corpse.AI_CORPSE_EMPTY_TIME, false);
return SCRIPT_CONTINUE;
}
}
}
}
return SCRIPT_CONTINUE;
}
messageHandler handleAttemptCorpseCleanup()
{
messageTo(self, "handleCorpseEmpty", null, 0, false);
return SCRIPT_CONTINUE;
}
/***** FUNCTIONS ********************************************************/
trigger OnLootLotterySelected (obj_id player, obj_id[] selection_ids)
{
obj_id selfInv = utils.getInventoryContainer (self);
int numWindowsOpen = getIntObjVar(self, "numWindowsOpen");
numWindowsOpen = numWindowsOpen - 1;
setObjVar (self, "numWindowsOpen", numWindowsOpen);
for (int i = 0; i < selection_ids.length; ++i)
{
obj_id thisObject = selection_ids[i];
if (!hasObjVar (thisObject, "numLotteryPlayers"))
{
setObjVar (thisObject, "numLotteryPlayers", 1);
setObjVar (thisObject, "lotteryPlayer1", player);
}
else
{
int numLotteryPlayers = getIntObjVar (thisObject, "numLotteryPlayers");
numLotteryPlayers = numLotteryPlayers + 1;
setObjVar (thisObject, "lotteryPlayer" + numLotteryPlayers, player);
setObjVar (thisObject, "numLotteryPlayers", numLotteryPlayers);
}
}
return SCRIPT_CONTINUE;
}
messageHandler fireLotteryPulse()
{
obj_id player = params.getObjId ("player");
obj_id corpseInv = params.getObjId ("corpseInv");
obj_id corpseId = getContainedBy(corpseInv);
int numTimesFired = params.getInt ("fired");
int numWindowsOpen = getIntObjVar (corpseId, "numWindowsOpen");
numTimesFired = numTimesFired + 1;
// The inventory of the first person sending a pulse will be the default money recipient in the case that things are full of fail.
// Lotto money is always split between the group anyway so who this person is ultimately doesn't matter.
if(!utils.hasScriptVar(self, "default_money_recipient_inventory"))
{
utils.setScriptVar(self, "default_money_recipient_inventory", utils.getInventoryContainer(player));
}
// This is the lottery timer. You get a free 2 seconds because of the initial message, and then
// every pulse is another 2 seconds. So, if it says numTimesFired > 14, that's 30 seconds.
// if you want it to be a minute set num times fired to 29, etc.
// the client is set to be 30 seconds to allow for lag.
if (numTimesFired > 18 || numWindowsOpen <= 0)
{
boolean allTransfersComplete = true;
obj_id [] corpseContents = getContents (corpseInv);
for (int i = 0; i < corpseContents.length; ++i)
{
obj_id item = corpseContents[i];
//LOG ("LOTTERY", "item is " + item);
int numLotteryPlayers = getIntObjVar (item, "numLotteryPlayers");
//LOG("LOTTERY", "numLotteryPLayers is " + numLotteryPlayers);
int lotteryNumber = rand (1, numLotteryPlayers);
obj_id lottoWinner = getObjIdObjVar (item, "lotteryPlayer" + lotteryNumber);
//If the lotto times out but not everyone has responded (particularly LD cases), let the winner loot.
if (numWindowsOpen > 0)
setObjVar (item, "pickupable", lottoWinner);
//LOG("LOTTERY", "lottery Winner is " + lottoWinner);
//LOG("LOTTERY", "I won " + getName (item) + " which is obj_id " + item);
obj_id winventory = utils.getInventoryContainer(lottoWinner);
// Stop autostacking so the item can transfer correctly
utils.setScriptVar(lottoWinner, "autostack.ignoreitems", 1);
//cash is handled specially so putIn call works even though
//it returns false, so just do this for cash and continue on
if (loot.isCashLootItem(item))
{
//LOG("LOTTERY","Lottery won item is cash");
//If winventory is null then use our default inventory so the money still gets handed out.
//This will happen if all players choose a "Selection" without choosing "All" or no one clicks on credits.
if(isIdNull(winventory))
winventory = utils.getObjIdScriptVar(self, "default_money_recipient_inventory");
putIn(item, winventory);
continue;
}
if (!putIn(item, winventory))
{
//LOG("LOTTERY","Lottery put in inventory failed!!!!");
if (!loot.isCashLootItem(item))
{
//LOG("LOTTERY","Lottery put in inventory failed, not a cash loot item");
string transferProblem = "full_inventory_free_for_all";
boolean inventoryHasRoom = (getVolumeFree(winventory) > 0);
if (inventoryHasRoom)
{
//LOG("LOTTERY","Lottery put in inventory failed, has inventory space but failed anyway");
transferProblem = "unable_to_transfer";
setObjVar (corpseId, "allowedToOpenFromFailedTransfer_" + lottoWinner, 1);
setObjVar (item, "pickupable", lottoWinner);
}
else
{
//LOG("LOTTERY","Lottery put in inventory failed, possibly a server boundary problem");
// failure probably due to trying to transfer
// over a server boundary.
loot.setAutoLootComplete(lottoWinner, corpseId, item);
}
dictionary proseParameters = new dictionary();
proseParameters.put ("stf", group.GROUP_STF);
proseParameters.put ("message", transferProblem);
proseParameters.put ("TO", item);
proseParameters.put ("TT", lottoWinner);
obj_id gid = getGroupObject (lottoWinner);
obj_id [] members = utils.getLocalGroupMemberIds(gid);
for (int x = 0; x < members.length; ++x)
{
messageTo(members[x], "sendSystemMessageProseAuthoritative", proseParameters, 1, true);
}
allTransfersComplete = false;
}
}
else
{
//LOG("LOTTERY","Lottery put in inventory worked, telling everyone");
loot.sendGroupLootSystemMessage (item, lottoWinner, "loot_n", "group_looted");
//send message to item to try and stack it
messageTo(item, "msgStackItem", null, 1, false);
}
// Turn autostacking back on
utils.removeScriptVar(lottoWinner, "autostack.ignoreitems");
}
if (allTransfersComplete)
{
//LOG("LOTTERY","all transfers complete, handle empty corpse");
messageTo(corpseId, "handleCorpseEmpty", null, 1f, isObjectPersisted(corpseId));
}
return SCRIPT_CONTINUE;
}
dictionary lottery = new dictionary();
lottery.put ("fired", numTimesFired);
lottery.put ("player", player);
lottery.put ("corpseInv", corpseInv);
obj_id team = getGroupObject (player);
obj_id [] objMembersWhoExist = utils.getLocalGroupMemberIds(team);
messageTo(self, "fireLotteryPulse", lottery, 2, true);
return SCRIPT_CONTINUE;
}
boolean canHarvest( obj_id self, obj_id player )
{
return ( hasObjVar(self, corpse.VAR_HAS_RESOURCE) && !utils.hasScriptVar(self, "harvestedBy." + player) );
}
@@ -0,0 +1,184 @@
package script.corpse;
import script.*;
import script.base_class.*;
import script.combat_engine.*;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
import script.base_script;
import script.library.sui;
import script.library.prose;
import script.library.spam;
import script.library.utils;
import script.library.group;
import script.library.corpse;
import script.library.permissions;
import script.library.loot;
public class ai_corpse_inventory extends script.base_script
{
public ai_corpse_inventory()
{
}
public int OnAboutToReceiveItem(obj_id self, obj_id srcContainer, obj_id transferer, obj_id item) throws InterruptedException
{
if (isPlayer(transferer))
{
sendSystemMessage(transferer, corpse.SID_REMOVE_ONLY_CORPSE);
return SCRIPT_OVERRIDE;
}
return SCRIPT_CONTINUE;
}
public int OnAboutToLoseItem(obj_id self, obj_id destContainer, obj_id transferer, obj_id item) throws InterruptedException
{
obj_id lootingPlayer = transferer;
if (!isIdValid(lootingPlayer) || !isPlayer(lootingPlayer))
{
lootingPlayer = getContainedBy(destContainer);
}
if (isPlayer(lootingPlayer))
{
obj_id corpseId = getContainedBy(self);
if (corpseId == null)
{
return SCRIPT_CONTINUE;
}
if (hasObjVar(item, "pickupable"))
{
obj_id winningPlayer = getObjIdObjVar(item, "pickupable");
if (winningPlayer == lootingPlayer)
{
removeObjVar(item, "unpickable");
return SCRIPT_CONTINUE;
}
string_id noLoot = new string_id(group.GROUP_STF, "no_loot_permission");
sendSystemMessage(lootingPlayer, noLoot);
return SCRIPT_OVERRIDE;
}
if (corpse.hasLootPermissions(corpseId, lootingPlayer))
{
if (loot.isCashLootItem(item))
{
int cash = getIntObjVar(item, "loot.cashAmount");
dictionary data = new dictionary();
data.put(corpse.DICT_COINS, cash);
data.put(corpse.DICT_CORPSE_ID, corpseId);
messageTo(lootingPlayer, "handleRequestCoinLoot", data, 0, false);
destroyObject(item);
return SCRIPT_OVERRIDE;
}
if (group.isGrouped(lootingPlayer))
{
obj_id team = getGroupObject(lootingPlayer);
int lootRule = getGroupLootRule(team);
if (lootRule == 3)
{
lootingPlayer = loot.chooseRandomLootPlayerFromGroup(self, lootingPlayer);
}
else if (lootRule == 1)
{
if (!loot.isMasterLooter(lootingPlayer, true))
{
return SCRIPT_OVERRIDE;
}
}
if (loot.doGroupLooting(corpseId, lootingPlayer, item))
{
if (canPutIn(item, utils.getInventoryContainer(lootingPlayer)) != 0)
{
loot.sendGroupLootSystemMessage(item, lootingPlayer, group.GROUP_STF, "full_inventory");
return SCRIPT_OVERRIDE;
}
}
else
{
return SCRIPT_OVERRIDE;
}
}
CustomerServiceLog("Loot", "(" + lootingPlayer + ") " + getName(lootingPlayer) + " is attempting to remove (" + item + ") " + getName(item) + " from (" + self + ")" + getName(self) + " to " + destContainer);
}
else
{
sendSystemMessage(lootingPlayer, permissions.SID_INSUFFICIENT_PERMISSIONS);
return SCRIPT_OVERRIDE;
}
}
return SCRIPT_CONTINUE;
}
public int OnLostItem(obj_id self, obj_id destContainer, obj_id transferer, obj_id item) throws InterruptedException
{
if (!isIdValid(transferer))
{
return SCRIPT_CONTINUE;
}
if (isPlayer(transferer))
{
CustomerServiceLog("Loot", "(" + transferer + ") " + getName(transferer) + " has transferred (" + item + ") " + getName(item) + " from (" + self + ")" + getName(self) + " to " + destContainer);
obj_id gid = getGroupObject(transferer);
if (isIdValid(gid))
{
group.notifyItemLoot(gid, transferer, getContainedBy(self), item);
return SCRIPT_CONTINUE;
}
prose_package pp = new prose_package();
string_id lootMsg = new string_id("loot_n", "solo_looted");
pp = prose.setStringId(pp, lootMsg);
pp = prose.setTO(pp, item);
sendSystemMessageProse(transferer, pp);
}
obj_id[] itemsLeft = getContents(self);
if ((itemsLeft == null) || (itemsLeft.length == 0))
{
obj_id corpseId = getContainedBy(self);
if (isIdValid(corpseId))
{
corpse.clearLootMeParticle(corpseId);
}
}
return SCRIPT_CONTINUE;
}
public int OnOpenedContainer(obj_id self, obj_id whoOpenedMe) throws InterruptedException
{
obj_id corpseId = getContainedBy(self);
if (corpseId == null)
{
return SCRIPT_OVERRIDE;
}
if (corpse.hasLootPermissions(corpseId, whoOpenedMe))
{
corpse.openAICorpse(whoOpenedMe, corpseId);
int cnt = utils.getIntScriptVar(self, "openCount");
cnt++;
utils.setScriptVar(self, "openCount", cnt);
utils.setScriptVar(corpseId, "lootTimestamp", getGameTime());
return SCRIPT_CONTINUE;
}
return SCRIPT_OVERRIDE;
}
public int OnClosedContainer(obj_id self, obj_id whoClosedMe) throws InterruptedException
{
int cnt = utils.getIntScriptVar(self, "openCount");
cnt--;
if (cnt > 0)
{
utils.setScriptVar(self, "openCount", cnt);
return SCRIPT_CONTINUE;
}
obj_id[] itemsLeft = getContents(self);
if ((itemsLeft == null) || (itemsLeft.length == 0))
{
obj_id corpseId = getContainedBy(self);
if (corpseId == null)
{
return SCRIPT_CONTINUE;
}
if (!hasObjVar(self, corpse.VAR_HAS_RESOURCE))
{
messageTo(corpseId, corpse.HANDLER_CORPSE_EMPTY, null, 0, true);
}
}
return SCRIPT_CONTINUE;
}
}
@@ -1,202 +0,0 @@
/**
* Title: ai_corpse_inventory.script
* Description: ai corpse inventory script: to handle transactions with mob inventory
*/
/***** INCLUDES ********************************************************/
include library.sui;
include library.prose;
include library.spam;
include library.utils;
include library.group;
include library.corpse;
include library.permissions;
include library.loot;
/***** TRIGGER *********************************************************/
trigger OnAboutToReceiveItem(obj_id srcContainer, obj_id transferer, obj_id item)
{
if ( isPlayer(transferer) )
{
sendSystemMessage(transferer, corpse.SID_REMOVE_ONLY_CORPSE);
return SCRIPT_OVERRIDE;
}
return SCRIPT_CONTINUE;
}
trigger OnAboutToLoseItem(obj_id destContainer, obj_id transferer, obj_id item)
{
obj_id lootingPlayer = transferer;
if (!isIdValid(lootingPlayer) || !isPlayer(lootingPlayer))
{
lootingPlayer = getContainedBy(destContainer);
}
if ( isPlayer(lootingPlayer) )
{
obj_id corpseId = getContainedBy(self);
if ( corpseId == null )
{
return SCRIPT_CONTINUE;
}
if (hasObjVar (item, "pickupable"))
{
obj_id winningPlayer = getObjIdObjVar (item, "pickupable");
if (winningPlayer == lootingPlayer)
{
removeObjVar (item, "unpickable");
return SCRIPT_CONTINUE;
}
string_id noLoot = new string_id (group.GROUP_STF, "no_loot_permission");
sendSystemMessage (lootingPlayer, noLoot);
return SCRIPT_OVERRIDE;
}
if ( corpse.hasLootPermissions(corpseId, lootingPlayer) )
{
if (loot.isCashLootItem(item))
{
int cash = getIntObjVar(item, "loot.cashAmount");
dictionary data = new dictionary();
data.put(corpse.DICT_COINS, cash);
data.put(corpse.DICT_CORPSE_ID, corpseId);
messageTo(lootingPlayer, "handleRequestCoinLoot", data, 0, false);
destroyObject(item);
return SCRIPT_OVERRIDE;
}
if (group.isGrouped (lootingPlayer))
{
obj_id team = getGroupObject(lootingPlayer);
int lootRule = getGroupLootRule (team);
if (lootRule == 3)
{
lootingPlayer = loot.chooseRandomLootPlayerFromGroup (self, lootingPlayer);
}
else if (lootRule == 1)
{
// somehow were transfering when not the master looter
if (!loot.isMasterLooter (lootingPlayer, true))
{
return SCRIPT_OVERRIDE;
}
}
if (loot.doGroupLooting (corpseId, lootingPlayer, item))
{
if (canPutIn(item, utils.getInventoryContainer(lootingPlayer)) != 0)
{
loot.sendGroupLootSystemMessage (item, lootingPlayer, group.GROUP_STF, "full_inventory");
return SCRIPT_OVERRIDE;
}
}
else
{
return SCRIPT_OVERRIDE;
}
}
CustomerServiceLog("Loot", "(" + lootingPlayer + ") " + getName(lootingPlayer) + " is attempting to remove (" + item + ") " + getName(item) + " from (" + self + ")" + getName(self) + " to " + destContainer);
}
else
{
sendSystemMessage(lootingPlayer, permissions.SID_INSUFFICIENT_PERMISSIONS);
return SCRIPT_OVERRIDE;
}
}
return SCRIPT_CONTINUE;
}
trigger OnLostItem(obj_id destContainer, obj_id transferer, obj_id item)
{
if ( !isIdValid(transferer) )
return SCRIPT_CONTINUE;
if ( isPlayer(transferer) )
{
CustomerServiceLog("Loot", "(" + transferer + ") " + getName(transferer) + " has transferred (" + item + ") " + getName(item) + " from (" + self + ")" + getName(self) + " to " + destContainer);
obj_id gid = getGroupObject(transferer);
if ( isIdValid(gid) )
{
group.notifyItemLoot(gid, transferer, getContainedBy(self), item);
return SCRIPT_CONTINUE;
}
prose_package pp = new prose_package();
string_id lootMsg = new string_id ("loot_n", "solo_looted");
//"You looted %TO from the corpse."
pp = prose.setStringId(pp, lootMsg);
pp = prose.setTO(pp, item);
sendSystemMessageProse(transferer, pp);
}
obj_id[] itemsLeft = getContents(self);
if ( (itemsLeft == null) || (itemsLeft.length == 0) )
{
obj_id corpseId = getContainedBy(self);
if (isIdValid(corpseId))
{
corpse.clearLootMeParticle(corpseId);
}
}
return SCRIPT_CONTINUE;
}
trigger OnOpenedContainer(obj_id whoOpenedMe)
{
obj_id corpseId = getContainedBy(self);
if ( corpseId == null )
{
return SCRIPT_OVERRIDE;
}
if ( corpse.hasLootPermissions(corpseId, whoOpenedMe) )
{
corpse.openAICorpse(whoOpenedMe, corpseId);
int cnt = utils.getIntScriptVar(self, "openCount");
cnt++;
utils.setScriptVar(self, "openCount", cnt);
utils.setScriptVar(corpseId, "lootTimestamp", getGameTime());
return SCRIPT_CONTINUE;
}
return SCRIPT_OVERRIDE;
}
trigger OnClosedContainer(obj_id whoClosedMe)
{
int cnt = utils.getIntScriptVar(self, "openCount");
cnt--;
if ( cnt > 0 )
{
utils.setScriptVar(self, "openCount", cnt);
return SCRIPT_CONTINUE;
}
obj_id[] itemsLeft = getContents(self);
if ( (itemsLeft == null) || (itemsLeft.length == 0) )
{
obj_id corpseId = getContainedBy(self);
if ( corpseId == null )
{
return SCRIPT_CONTINUE;
}
if ( !hasObjVar(self, corpse.VAR_HAS_RESOURCE) )
{
messageTo(corpseId, corpse.HANDLER_CORPSE_EMPTY, null, 0, true);
}
}
return SCRIPT_CONTINUE;
}
@@ -0,0 +1,42 @@
package script.corpse;
import script.*;
import script.base_class.*;
import script.combat_engine.*;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
import script.base_script;
import script.library.pet_lib;
import script.library.utils;
import script.library.corpse;
import script.library.permissions;
import script.library.money;
import script.library.prose;
import script.library.group;
import script.library.ai_lib;
import script.library.loot;
public class corpse_fast_recycle extends script.base_script
{
public corpse_fast_recycle()
{
}
public int OnDeath(obj_id self, obj_id killer, obj_id corpseId) throws InterruptedException
{
if (isIdValid(self))
{
messageTo(self, "handleIsCorpseEmpty", null, 5, false);
}
return SCRIPT_CONTINUE;
}
public int handleIsCorpseEmpty(obj_id self, dictionary params) throws InterruptedException
{
if (isIdValid(self) && hasScript(self, "corpse.ai_corpse") && corpse.isCorpseEmpty(self) == true)
{
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, 0, false);
}
return SCRIPT_CONTINUE;
}
}
@@ -1,31 +0,0 @@
include library.pet_lib;
include library.utils;
include library.corpse;
include library.permissions;
include library.money;
include library.prose;
include library.group;
include library.ai_lib;
include library.loot;
// attach this script to all NPE shared space station critters
// this script will recycle their corpses quickly, allowing for more spawns
trigger OnDeath(obj_id killer, obj_id corpseId)
{
if (isIdValid(self))
messageTo(self, "handleIsCorpseEmpty", null, 5, false);
return SCRIPT_CONTINUE;
}
messageHandler handleIsCorpseEmpty()
{
//if the npc isn't packing any resources, cash, or loot, destroy it.
//also check to make sure its a valid ID and really a corpse
if (isIdValid(self) && hasScript(self, "corpse.ai_corpse") && corpse.isCorpseEmpty(self) == true)
{
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, null, 0, false);
}
return SCRIPT_CONTINUE;
}
@@ -0,0 +1,285 @@
package script.corpse;
import script.*;
import script.base_class.*;
import script.combat_engine.*;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
import script.base_script;
import script.library.utils;
import script.library.permissions;
import script.library.corpse;
import script.library.spam;
import script.library.money;
public class player_corpse extends script.base_script
{
public player_corpse()
{
}
public int OnObjectMenuRequest(obj_id self, obj_id player, menu_info mi) throws InterruptedException
{
menu_info_data mid = mi.getMenuItemByType(menu_info_types.LOOT);
if (mid != null)
{
mid.setServerNotify(true);
}
mid = mi.getMenuItemByType(menu_info_types.LOOT_ALL);
if (mid != null)
{
mid.setServerNotify(true);
}
return SCRIPT_CONTINUE;
}
public int OnObjectMenuSelect(obj_id self, obj_id player, int item) throws InterruptedException
{
if (item == menu_info_types.LOOT)
{
if (utils.isOwner(self, player))
{
utils.requestContainerOpen(player, self);
return SCRIPT_CONTINUE;
}
else
{
sendSystemMessage(player, permissions.SID_NO_CORPSE_PERMISSION);
}
}
else if (item == menu_info_types.LOOT_ALL)
{
if (utils.isOwner(self, player))
{
utils.requestContainerOpen(player, self);
return SCRIPT_CONTINUE;
}
else
{
sendSystemMessage(player, permissions.SID_NO_CORPSE_PERMISSION);
}
}
return SCRIPT_CONTINUE;
}
public int OnDestroy(obj_id self) throws InterruptedException
{
corpse.cleanUpPlayerCorpse(self, false);
String corpseName = getAssignedName(self);
location here = getLocation(self);
CustomerServiceLog("Death", "PCorpse(" + self + " - " + corpseName + ") is being deleted at " + here.toString());
CustomerServiceLog("Death", "PCorpse(" + self + " - " + corpseName + ") owner = " + getOwner(self));
return SCRIPT_CONTINUE;
}
public int OnAboutToReceiveItem(obj_id self, obj_id srcContainer, obj_id transferer, obj_id item) throws InterruptedException
{
if (isPlayer(transferer))
{
sendSystemMessage(transferer, corpse.SID_REMOVE_ONLY_CORPSE);
return SCRIPT_OVERRIDE;
}
return SCRIPT_CONTINUE;
}
public int OnAboutToLoseItem(obj_id self, obj_id destContainer, obj_id transferer, obj_id item) throws InterruptedException
{
if (isPlayer(transferer))
{
if (!utils.isOwner(self, transferer) && !isGod(transferer))
{
sendSystemMessage(transferer, permissions.SID_INSUFFICIENT_PERMISSIONS);
return SCRIPT_OVERRIDE;
}
else
{
CustomerServiceLog("Death", "(" + transferer + ") " + getName(transferer) + " is removing (" + item + ") " + getName(item) + " from (" + self + ")" + getName(self));
}
}
return SCRIPT_CONTINUE;
}
public int OnLostItem(obj_id self, obj_id destContainer, obj_id transferer, obj_id item) throws InterruptedException
{
if (!isIdValid(transferer))
{
return SCRIPT_CONTINUE;
}
if (isPlayer(transferer))
{
CustomerServiceLog("Death", "(" + transferer + ") " + getName(transferer) + " has transferred (" + item + ") " + getName(item) + " from (" + self + ")" + getName(self) + " to " + destContainer);
CustomerServiceLog("Loot", "(" + transferer + ") " + getName(transferer) + " has transferred (" + item + ") " + getName(item) + " from (" + self + ")" + getName(self) + " to " + destContainer);
spam.lootItem(transferer, item, self, false);
}
return SCRIPT_CONTINUE;
}
public int OnOpenedContainer(obj_id self, obj_id whoOpenedMe) throws InterruptedException
{
if (utils.isOwner(self, whoOpenedMe))
{
if (corpse.openPlayerCorpse(whoOpenedMe, self))
{
return SCRIPT_CONTINUE;
}
}
return SCRIPT_OVERRIDE;
}
public int OnClosedContainer(obj_id self, obj_id whoClosedMe) throws InterruptedException
{
obj_id[] itemsLeft = getContents(self);
if ((itemsLeft == null) || (itemsLeft.length == 0))
{
if (getCashBalance(self) > 0)
{
corpse.lootCorpseCoins(whoClosedMe, self);
}
else
{
corpse.cleanUpPlayerCorpse(self);
}
}
return SCRIPT_CONTINUE;
}
public int OnInitialize(obj_id self) throws InterruptedException
{
obj_id[] itemsLeft = getContents(self);
if ((itemsLeft == null) || (itemsLeft.length == 0))
{
if (getTotalMoney(self) == 0)
{
destroyObject(self);
return SCRIPT_CONTINUE;
}
}
return SCRIPT_CONTINUE;
}
public int handleCorpseExpire(obj_id self, dictionary params) throws InterruptedException
{
if (hasObjVar(self, corpse.VAR_TIME_CREATED))
{
int create_time = getIntObjVar(self, corpse.VAR_TIME_CREATED);
int dt = getGameTime() - create_time;
if (dt < corpse.PLAYER_CORPSE_EXPIRATION_TIME)
{
int msgTime = corpse.PLAYER_CORPSE_EXPIRATION_TIME - dt;
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, params, msgTime, true);
return SCRIPT_CONTINUE;
}
}
obj_id owner = getObjIdObjVar(self, utils.VAR_OWNER);
if (owner != null)
{
dictionary d = new dictionary();
d.put(corpse.DICT_CORPSE_ID, self);
messageTo(owner, corpse.HANDLER_CORPSE_EXPIRE, d, 0, true);
}
corpse.cleanUpPlayerCorpse(self);
return SCRIPT_CONTINUE;
}
public int handleAddConsentedUser(obj_id self, dictionary params) throws InterruptedException
{
if (params != null)
{
obj_id player = params.getObjId(corpse.DICT_PLAYER_ID);
if (player != null)
{
if (permissions.addUserToPermissionsGroup(self, player, corpse.GROUP_CONSENTED))
{
return SCRIPT_CONTINUE;
}
else
{
}
}
}
return SCRIPT_OVERRIDE;
}
public int handleRemoveConsentedUser(obj_id self, dictionary params) throws InterruptedException
{
if (params != null)
{
obj_id player = params.getObjId(corpse.DICT_PLAYER_ID);
if (player != null)
{
if (permissions.deleteUserFromPermissionsGroup(self, player, corpse.GROUP_CONSENTED))
{
return SCRIPT_CONTINUE;
}
}
}
return SCRIPT_OVERRIDE;
}
public int handleCorpseDepositSuccess(obj_id self, dictionary params) throws InterruptedException
{
if (params == null)
{
return SCRIPT_OVERRIDE;
}
int cash = params.getInt(corpse.DICT_COINS);
transferBankCreditsToNamedAccount(self, money.ACCT_CORPSE_EXPIRATION, cash, corpse.HANDLER_DESTROY_SELF, corpse.HANDLER_DESTROY_SELF, params);
utils.moneyOutMetric(self, money.ACCT_CORPSE_EXPIRATION, cash);
return SCRIPT_CONTINUE;
}
public int handleCorpseDepositFail(obj_id self, dictionary params) throws InterruptedException
{
destroyObject(self);
return SCRIPT_CONTINUE;
}
public int handleAttemptCorpseCleanup(obj_id self, dictionary params) throws InterruptedException
{
obj_id[] stuff = getContents(self);
if ((stuff == null) || (stuff.length == 0) && (getCashBalance(self) == 0))
{
corpse.cleanUpPlayerCorpse(self);
}
else
{
int stamp = 0;
if (hasObjVar(self, "cleanupStamp"))
{
stamp = getIntObjVar(self, "cleanupStamp");
}
int now = getGameTime();
if (now - stamp >= 300)
{
messageTo(self, "handleAttemptCorpseCleanup", null, 300, true);
setObjVar(self, "cleanupStamp", now);
}
}
return SCRIPT_CONTINUE;
}
public int handleDestroySelf(obj_id self, dictionary params) throws InterruptedException
{
destroyObject(self);
return SCRIPT_CONTINUE;
}
public int handleRequestCorpseMove(obj_id self, dictionary params) throws InterruptedException
{
obj_id sender = params.getObjId("sender");
if (!isIdValid(sender))
{
return SCRIPT_CONTINUE;
}
location spot = getBuildingEjectLocation(sender);
if (spot == null)
{
spot = params.getLocation("senderLoc");
location locLowerLeft = spot;
locLowerLeft.x -= 20f;
locLowerLeft.z -= 20f;
location locUpperRight = spot;
locUpperRight.x += 20f;
locUpperRight.z += 20f;
spot = getGoodLocation(2f, 2f, locLowerLeft, locUpperRight, false, true);
if (spot == null)
{
return SCRIPT_CONTINUE;
}
spot.y = getHeightAtLocation(spot.x, spot.z);
}
setLocation(self, spot);
corpse.updateCorpseOwnerWaypoint(getOwner(self), self);
return SCRIPT_CONTINUE;
}
public int handleRequestLocation(obj_id self, dictionary params) throws InterruptedException
{
corpse.updateCorpseOwnerWaypoint(getOwner(self), self);
return SCRIPT_CONTINUE;
}
}
@@ -1,373 +0,0 @@
/**
* Title: player_corpse.script
* Description: player corpse
*/
/***** INCLUDES ********************************************************/
include library.utils;
include library.permissions;
include library.corpse;
include library.spam;
include library.money;
/***** TRIGGER *********************************************************/
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
menu_info_data mid = mi.getMenuItemByType(menu_info_types.LOOT);
if ( mid != null )
{
mid.setServerNotify(true);
}
mid = mi.getMenuItemByType(menu_info_types.LOOT_ALL);
if ( mid != null )
{
mid.setServerNotify(true);
}
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id player, int item)
{
if ( item == menu_info_types.LOOT)
{
if ( utils.isOwner(self, player) )
{
utils.requestContainerOpen(player, self);
return SCRIPT_CONTINUE;
}
else
{
sendSystemMessage(player, permissions.SID_NO_CORPSE_PERMISSION);
}
}
else if ( item == menu_info_types.LOOT_ALL)
{
/** NEW HOTNESS: **/
if ( utils.isOwner(self, player) )
{
utils.requestContainerOpen(player, self);
return SCRIPT_CONTINUE;
}
else
{
sendSystemMessage(player, permissions.SID_NO_CORPSE_PERMISSION);
}
/** OLD AND BUSTED:
if ( utils.isOwner(self, player) )
{
queueCommand(player, ##"lootPlayerCorpse", self, "", COMMAND_PRIORITY_DEFAULT);
}
else
{
sendSystemMessage(player, permissions.SID_NO_CORPSE_PERMISSION);
}*/
}
return SCRIPT_CONTINUE;
}
trigger OnDestroy()
{
//call the clean-up function, but tell it not to send a destroy message, since this
// is already being destroyed:
corpse.cleanUpPlayerCorpse(self, false );
string corpseName = getAssignedName(self);
location here = getLocation(self);
CustomerServiceLog("Death", "PCorpse(" + self + " - " + corpseName + ") is being deleted at " + here.toString());
CustomerServiceLog("Death", "PCorpse(" + self + " - " + corpseName + ") owner = " + getOwner(self));
return SCRIPT_CONTINUE;
}
trigger OnAboutToReceiveItem(obj_id srcContainer, obj_id transferer, obj_id item)
{
if ( isPlayer(transferer) )
{
sendSystemMessage(transferer, corpse.SID_REMOVE_ONLY_CORPSE);
return SCRIPT_OVERRIDE;
}
return SCRIPT_CONTINUE;
}
trigger OnAboutToLoseItem(obj_id destContainer, obj_id transferer, obj_id item)
{
if ( isPlayer(transferer) )
{
if ( !utils.isOwner(self, transferer) && !isGod(transferer) )
{
sendSystemMessage(transferer, permissions.SID_INSUFFICIENT_PERMISSIONS);
return SCRIPT_OVERRIDE;
}
else
{
CustomerServiceLog("Death", "(" + transferer + ") " + getName(transferer) + " is removing (" + item + ") " + getName(item) + " from (" + self + ")" + getName(self));
}
}
return SCRIPT_CONTINUE;
}
trigger OnLostItem(obj_id destContainer, obj_id transferer, obj_id item)
{
if ( !isIdValid(transferer) )
return SCRIPT_CONTINUE;
if ( isPlayer(transferer) )
{
CustomerServiceLog("Death", "(" + transferer + ") " + getName(transferer) + " has transferred (" + item + ") " + getName(item) + " from (" + self + ")" + getName(self) + " to " + destContainer);
CustomerServiceLog("Loot", "(" + transferer + ") " + getName(transferer) + " has transferred (" + item + ") " + getName(item) + " from (" + self + ")" + getName(self) + " to " + destContainer);
spam.lootItem(transferer, item, self, false);
}
return SCRIPT_CONTINUE;
}
trigger OnOpenedContainer(obj_id whoOpenedMe)
{
//debugSpeakMsg(self, "OnOpenedContainer triggered!");
if ( utils.isOwner(self, whoOpenedMe) )
{
if ( corpse.openPlayerCorpse(whoOpenedMe, self) )
{
return SCRIPT_CONTINUE;
}
}
return SCRIPT_OVERRIDE;
}
trigger OnClosedContainer(obj_id whoClosedMe)
{
//debugSpeakMsg(self, "OnClosedContainer triggered!");
obj_id[] itemsLeft = getContents(self);
if ( (itemsLeft == null) || (itemsLeft.length == 0) )
{
if ( getCashBalance(self) > 0 )
{
corpse.lootCorpseCoins(whoClosedMe, self);
}
else
{
corpse.cleanUpPlayerCorpse(self);
}
}
return SCRIPT_CONTINUE;
}
trigger OnInitialize()
{
obj_id[] itemsLeft = getContents(self);
if ( (itemsLeft == null) || (itemsLeft.length == 0) )
{
if ( getTotalMoney(self) == 0 )
{
//messageTo(self, corpse.HANDLER_DESTROY_SELF, null, 0 , true);
destroyObject( self );
return SCRIPT_CONTINUE;
}
}
return SCRIPT_CONTINUE;
}
/***** MESSAGEHANDLERS **************************************************/
messageHandler handleCorpseExpire()
{
if ( hasObjVar(self, corpse.VAR_TIME_CREATED) )
{
int create_time = getIntObjVar(self, corpse.VAR_TIME_CREATED);
int dt = getGameTime() - create_time;
if ( dt < corpse.PLAYER_CORPSE_EXPIRATION_TIME )
{
int msgTime = corpse.PLAYER_CORPSE_EXPIRATION_TIME - dt;
messageTo(self, corpse.HANDLER_CORPSE_EXPIRE, params, msgTime,true);
return SCRIPT_CONTINUE;
}
}
obj_id owner = getObjIdObjVar(self, utils.VAR_OWNER);
if ( owner != null )
{
dictionary d = new dictionary();
d.put(corpse.DICT_CORPSE_ID, self);
messageTo(owner, corpse.HANDLER_CORPSE_EXPIRE, d, 0, true);
}
corpse.cleanUpPlayerCorpse(self);
return SCRIPT_CONTINUE;
}
messageHandler handleAddConsentedUser()
{
//debugSpeakMsg(self, "received handleAddConsentedUser msg");
if ( params != null )
{
obj_id player = params.getObjId(corpse.DICT_PLAYER_ID);
if ( player != null )
{
if ( permissions.addUserToPermissionsGroup(self, player, corpse.GROUP_CONSENTED) )
{
return SCRIPT_CONTINUE;
}
else
{
//debugSpeakMsg(self, "permissions grant failed!");
}
}
}
//message player that add consent failed
return SCRIPT_OVERRIDE;
}
messageHandler handleRemoveConsentedUser()
{
if ( params != null )
{
obj_id player = params.getObjId(corpse.DICT_PLAYER_ID);
if ( player != null )
{
if ( permissions.deleteUserFromPermissionsGroup(self, player, corpse.GROUP_CONSENTED) )
{
return SCRIPT_CONTINUE;
}
}
}
//message player that remove consent failed
return SCRIPT_OVERRIDE;
}
/*
messageHandler handleCorpseCoinLoot()
{
if ( params == null )
{
return SCRIPT_OVERRIDE;
}
obj_id player = params.getObjId(corpse.DICT_PLAYER_ID);
if ( player != null )
{
messageTo(player, corpse.HANDLER_COINS_LOOTED, params, 0, true);
}
obj_id[] stuff = getContents(self);
if ( (stuff == null) || (stuff.length == 0) && (getCashBalance(self) == 0) )
{
corpse.cleanUpPlayerCorpse(self);
}
return SCRIPT_CONTINUE;
}
messageHandler handleCorpseCoinLootFailed()
{
if ( params == null )
{
return SCRIPT_OVERRIDE;
}
obj_id player = params.getObjId(corpse.DICT_PLAYER_ID);
if ( player != null )
{
messageTo(player, corpse.HANDLER_COINLOOT_FAILED, params, 0, true);
}
return SCRIPT_CONTINUE;
}
*/
messageHandler handleCorpseDepositSuccess()
{
if ( params == null )
{
return SCRIPT_OVERRIDE;
}
int cash = params.getInt(corpse.DICT_COINS);
transferBankCreditsToNamedAccount(self, money.ACCT_CORPSE_EXPIRATION, cash, corpse.HANDLER_DESTROY_SELF, corpse.HANDLER_DESTROY_SELF, params);
utils.moneyOutMetric(self, money.ACCT_CORPSE_EXPIRATION, cash);
return SCRIPT_CONTINUE;
}
messageHandler handleCorpseDepositFail()
{
//messageTo(self, corpse.HANDLER_DESTROY_SELF, params, 0 , true);
destroyObject(self );
return SCRIPT_CONTINUE;
}
messageHandler handleAttemptCorpseCleanup()
{
obj_id[] stuff = getContents(self);
if ( (stuff == null) || (stuff.length == 0) && (getCashBalance(self) == 0) )
{
corpse.cleanUpPlayerCorpse(self);
}
else
{
int stamp = 0;
if( hasObjVar(self, "cleanupStamp") )
{
stamp = getIntObjVar(self, "cleanupStamp");
}
int now = getGameTime();
if( now - stamp >= 300 )
{
messageTo(self, "handleAttemptCorpseCleanup", null, 300, true);
setObjVar(self, "cleanupStamp", now);
}
}
return SCRIPT_CONTINUE;
}
messageHandler handleDestroySelf()
{
destroyObject(self);
return SCRIPT_CONTINUE;
}
messageHandler handleRequestCorpseMove()
{
obj_id sender = params.getObjId("sender");
if ( !isIdValid(sender) )
return SCRIPT_CONTINUE;
location spot = getBuildingEjectLocation(sender);
if ( spot == null )
{
spot = params.getLocation("senderLoc");
location locLowerLeft = spot;
locLowerLeft.x -= 20f;
locLowerLeft.z -= 20f;
location locUpperRight = spot;
locUpperRight.x += 20f;
locUpperRight.z += 20f;
spot = getGoodLocation(2f, 2f, locLowerLeft, locUpperRight, false, true);
if ( spot == null )
return SCRIPT_CONTINUE;
spot.y = getHeightAtLocation(spot.x, spot.z);
}
setLocation(self, spot);
corpse.updateCorpseOwnerWaypoint(getOwner(self), self);
return SCRIPT_CONTINUE;
}
messageHandler handleRequestLocation()
{
corpse.updateCorpseOwnerWaypoint(getOwner(self), self);
return SCRIPT_CONTINUE;
}