Files
dsrc/sku.0/sys.server/compiled/game/script/systems/crafting/station_cell.script
T

158 lines
4.5 KiB
Plaintext

include library.buff;
include library.craftinglib;
include library.utils;
trigger OnReceivedItem(obj_id srcContainer, obj_id transferer, obj_id item)
{
if(getGameObjectType (item) == GOT_misc_crafting_station)
{
if(utils.hasScriptVar(self, craftinglib.SCRIPTVAR_CELL_STATIONS))
{
resizeable obj_id[] stations = utils.getResizeableObjIdArrayScriptVar(self, craftinglib.SCRIPTVAR_CELL_STATIONS);
if(!utils.isElementInArray(stations, item))
{
stations = utils.addElement(stations, item);
utils.setScriptVar(self, craftinglib.SCRIPTVAR_CELL_STATIONS, stations);
}
}
else
{
resizeable obj_id[] stations = new obj_id [0];
stations = utils.addElement(stations, item);
utils.setScriptVar(self, craftinglib.SCRIPTVAR_CELL_STATIONS, stations);
}
int craftingType = getIntObjVar(item, craftinglib.OBJVAR_CRAFTING_TYPE);
if(craftingType < 0)
return SCRIPT_CONTINUE;
//possible list of buffs to apply
string[] buffNames = craftinglib.getAllStationBuffNames(craftingType);
if(buffNames == null || buffNames.length <= 0)
return SCRIPT_CONTINUE;
//get everyone in the cell
obj_id[] cellContents = getContents(self);
if(cellContents == null || cellContents.length <= 0)
return SCRIPT_CONTINUE;
for(int i = 0; i < cellContents.length; ++i)
{
if(!isPlayer(cellContents[i]))
continue;
for(int a = 0; a < buffNames.length; a++)
buff.applyBuff(cellContents[i], item, buffNames[a]);
}
}
if(!isPlayer(item))
return SCRIPT_CONTINUE;
if(!utils.hasScriptVar(self, craftinglib.SCRIPTVAR_CELL_STATIONS))
return SCRIPT_CONTINUE;
obj_id[] stations = utils.getObjIdArrayScriptVar(self, craftinglib.SCRIPTVAR_CELL_STATIONS);
if(stations == null || stations.length <= 0)
return SCRIPT_CONTINUE;
//if this is a player walking into cell where stations exist.
for(int i = 0; i < stations.length; ++i)
{
if(!isIdValid(stations[i]) || !exists(stations[i]))
continue;
int craftingType = getIntObjVar(stations[i], craftinglib.OBJVAR_CRAFTING_TYPE);
if(craftingType < 0)
return SCRIPT_CONTINUE;
//possible list of buffs to apply
string[] buffNames = craftinglib.getAllStationBuffNames(craftingType);
if(buffNames == null || buffNames.length <= 0)
return SCRIPT_CONTINUE;
for(int a = 0; a < buffNames.length; a++)
buff.applyBuff(item, stations[i], buffNames[a]);
}
return SCRIPT_CONTINUE;
}
trigger OnAboutToLoseItem(obj_id destContainer, obj_id transferer, obj_id item)
{
if(getGameObjectType (item) == GOT_misc_crafting_station)
{
if(utils.hasScriptVar(self, craftinglib.SCRIPTVAR_CELL_STATIONS))
{
boolean secondStation = false;
int craftingTypeItem = getIntObjVar(item, craftinglib.OBJVAR_CRAFTING_TYPE);
if(craftingTypeItem < 0)
return SCRIPT_CONTINUE;
//possible list of buffs to apply
string[] buffNames = craftinglib.getAllStationBuffNames(craftingTypeItem);
if(buffNames == null || buffNames.length <= 0)
return SCRIPT_CONTINUE;
resizeable obj_id[] stations = utils.getResizeableObjIdArrayScriptVar(self, craftinglib.SCRIPTVAR_CELL_STATIONS);
obj_id secondStationId = obj_id.NULL_ID;
if(stations != null && stations.length > 0)
{
for(int i = 0; i < stations.length; ++i)
{
int craftingTypeSearch = getIntObjVar(stations[i], craftinglib.OBJVAR_CRAFTING_TYPE);
if(craftingTypeSearch == craftingTypeItem && stations[i] != item)
{
secondStation = true;
secondStationId = stations[i];
break;
}
}
}
stations = utils.removeElement(stations, item);
utils.setScriptVar(self, craftinglib.SCRIPTVAR_CELL_STATIONS, stations);
obj_id[] cellContents = getContents(self);
if(cellContents != null && cellContents.length > 0)
{
for(int i = 0; i < cellContents.length; ++i)
{
if(!isPlayer(cellContents[i]))
continue;
for(int a = 0; a < buffNames.length; a++)
buff.removeBuff(cellContents[i], buffNames[a]);
if(secondStation && isIdValid(secondStationId) && exists(secondStationId))
{
for(int a = 0; a < buffNames.length; a++)
buff.applyBuff(cellContents[i], secondStationId, buffNames[a]);
}
}
}
}
}
if(!isPlayer(item))
return SCRIPT_CONTINUE;
int[] stationBuffs = buff.getAllBuffsByEffect(item, "station_buff");
if(stationBuffs == null || stationBuffs.length <= 0)
return SCRIPT_CONTINUE;
for(int i = 0; i < stationBuffs.length; ++i)
{
buff.removeBuff(item, stationBuffs[i]);
}
return SCRIPT_CONTINUE;
}