Files
dsrc/sku.0/sys.server/compiled/game/script/systems/event_perk/promoter.script
T

188 lines
5.4 KiB
Plaintext

include library.sui;
include library.utils;
include library.money;
include java.util.StringTokenizer;
/********************************************************************************
const string TBL_GAME = "datatables/event_perk/promoter_game.iff";
const string TBL_PERSON = "datatables/event_perk/promoter_person.iff";
const string TBL_PERSON_IMP = "datatables/event_perk/promoter_person_imp.iff";
const string TBL_PERSON_REB = "datatables/event_perk/promoter_person_reb.iff";
const string TBL_STATIC = "datatables/event_perk/promoter_static.iff";
const string TBL_STATIC_IMP = "datatables/event_perk/promoter_static_imp.iff";
const string TBL_STATIC_REB = "datatables/event_perk/promoter_static_reb.iff";
const string TBL_THEATER = "datatables/event_perk/promoter_theater.iff";
const string TBL_THEATER_IMP = "datatables/event_perk/promoter_theater_imp.iff";
const string TBL_THEATER_REB = "datatables/event_perk/promoter_theater_reb.iff";
**********************************************************************************/
trigger OnAttach()
{
setInvulnerable(self, true);
if ( !hasScript(self, "systems.storyteller.storyteller_vendor") )
{
attachScript(self, "systems.storyteller.storyteller_vendor");
}
if ( hasScript(self, "conversation.event_promoter") )
{
detachScript(self, "conversation.event_promoter");
}
return SCRIPT_CONTINUE;
}
trigger OnInitialize()
{
setInvulnerable(self, true);
if ( !hasScript(self, "systems.storyteller.storyteller_vendor") )
{
attachScript(self, "systems.storyteller.storyteller_vendor");
}
if ( hasScript(self, "conversation.event_promoter") )
{
detachScript(self, "conversation.event_promoter");
}
return SCRIPT_CONTINUE;
}
messageHandler showPromoterItemList()
{
obj_id player = params.getObjId("player");
string table = params.getString("table");
utils.setScriptVar(player, "promoter.table_select", table);
int[] cost = dataTableGetIntColumn(table, 2);
string[] rawName = dataTableGetStringColumn(table, 1);
string[] derivedName = new string[rawName.length];
string[] concatMsg = new string[rawName.length];
for (int i=0; i<rawName.length; i++ )
{
derivedName[i] = "@event_perk:"+rawName[i];
string_id sid_name = utils.unpackString(derivedName[i]);
string name = getString(sid_name);
concatMsg[i] = "[" + cost[i] + "] " + name;
}
sui.listbox(self, player, "@event_perk:pro_show_list_desc", sui.OK_CANCEL, "@event_perk:pro_show_list_title", concatMsg, "selectPromoterItem", true);
return SCRIPT_CONTINUE;
}
messageHandler selectPromoterItem()
{
obj_id player = sui.getPlayerId(params);
string table = utils.getStringScriptVar(player, "promoter.table_select");
int idx = sui.getListboxSelectedRow(params);
if (idx < 0) idx = 0;
int btn = sui.getIntButtonPressed(params);
if (btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
string[] templateTable = dataTableGetStringColumn(table, 0);
int[] costTable = dataTableGetIntColumn(table, 2);
if(templateTable == null || templateTable.length == 0)
return SCRIPT_CONTINUE;
if(costTable == null || costTable.length == 0)
return SCRIPT_CONTINUE;
obj_id[] allContents = utils.getAllItemsInBankAndInventory(player);
int perkCount = 0;
for(int i = 0; i < allContents.length; i++)
{
// string whatsThis = getTemplateName(allContents[i]);
// if(whatsThis == "object/tangible/deed/event_perk/shuttle_beacon.iff")
// {
// sendSystemMessage(player, new string_id("event_perk", "promoter_only_one"));
// return SCRIPT_CONTINUE;
// }
if(hasObjVar(allContents[i], "event_perk"))
perkCount++;
if(perkCount >= 5)
{
sendSystemMessage(player, new string_id("event_perk", "pro_too_many_perks"));
return SCRIPT_CONTINUE;
}
}
string template = templateTable[idx];
int cost = costTable[idx];
for(int i = 0; i < allContents.length; i++)
{
string whatsThis = getTemplateName(allContents[i]);
if(whatsThis == "object/tangible/deed/event_perk/shuttle_beacon.iff" && whatsThis == template)
{
sendSystemMessage(player, new string_id("event_perk", "promoter_only_one"));
return SCRIPT_CONTINUE;
}
}
if(cost < 1)
{
sendSystemMessage(player, new string_id("event_perk", "pro_error_cost"));
return SCRIPT_CONTINUE;
}
int totalMoney = getTotalMoney(player);
if(cost > totalMoney)
{
sendSystemMessage(player, new string_id("event_perk", "lottery_add_credits_nsf"));
return SCRIPT_CONTINUE;
}
obj_id playerInventory = utils.getInventoryContainer(player);
obj_id purchasedItem = createObject(template, playerInventory, "");
if(isIdValid(purchasedItem))
{
money.pay(player, self, cost, "derpDerpDerp", null);
CustomerServiceLog("EventPerk", "(Promoter - [" + self + "]) Player [" + player + "] purchased " + purchasedItem + " at a cost of " + cost);
}
else
{
sendSystemMessage(player, new string_id("event_perk", "promoter_full_inv"));
}
return SCRIPT_CONTINUE;
}
/*****************************************************************
trigger OnHearSpeech(obj_id objSpeaker, string strText) //***** TEST ONLY
{
dictionary params = new dictionary();
StringTokenizer st = new StringTokenizer(strText);
if(strText.startsWith("show"))
{
string command = st.nextToken();
string table = st.nextToken();
params.put("table", table);
params.put("player", objSpeaker);
messageTo(self, "showPromoterItemList", params, 1, false);
}
return SCRIPT_CONTINUE;
}
***********************************************************************/