/***** INCLUDES ********************************************************/ include library.sui; include library.utils; include library.prose; include library.money; include library.gambling; /***** INHERITS ********************************************************/ inherits terminal.base.base_terminal; /***** CONSTANTS *******************************************************/ const float BET_RANGE = 15f; const string_id MNU_JOIN = new string_id(gambling.STF_INTERFACE, "mnu_join"); const string_id MNU_LEAVE = new string_id(gambling.STF_INTERFACE, "mnu_leave"); const string_id STOP_GAMBLING = new string_id(gambling.STF_INTERFACE, "stop_gambling"); /***** TRIGGERS ********************************************************/ trigger OnObjectMenuRequest(obj_id player, menu_info mi) { if ( !hasObjVar(self, gambling.VAR_GAMBLE_BASE) ) return SCRIPT_CONTINUE; int max = getIntObjVar(self, gambling.VAR_TABLE_PLAYER_LIMIT_MAX); obj_id[] players = getObjIdArrayObjVar(self, gambling.VAR_TABLE_PLAYERS); if ( players == null || players.length == 0 ) { //no players currently! if ( utils.hasScriptVar(player, "isGambling") ) { int mnuLeave = mi.addRootMenu(menu_info_types.SERVER_MENU2, MNU_LEAVE); return SCRIPT_CONTINUE; } } else { if ( utils.getElementPositionInArray(players, player) > -1 ) { int mnuLeave = mi.addRootMenu(menu_info_types.SERVER_MENU2, MNU_LEAVE); return SCRIPT_CONTINUE; } if ( max > 0 ) { if ( players.length >= max ) { prose_package ppFull = prose.getPackage(gambling.PROSE_STATION_FULL, self); sendSystemMessageProse(player, ppFull); return SCRIPT_CONTINUE; } } } if ( !utils.hasScriptVar(player, gambling.SCRIPTVAR_GAMBLING) ) int mnuJoin = mi.addRootMenu(menu_info_types.SERVER_MENU1, MNU_JOIN); return SCRIPT_CONTINUE; } trigger OnObjectMenuSelect(obj_id player, int item) { if ( !hasObjVar(self, gambling.VAR_GAMBLE_BASE) ) return SCRIPT_CONTINUE; if ( item == menu_info_types.ITEM_USE ) { if ( !utils.hasScriptVar(player, gambling.SCRIPTVAR_GAMBLING) ) item = menu_info_types.SERVER_MENU1; else item = menu_info_types.SERVER_MENU2; } if ( item == menu_info_types.SERVER_MENU1 ) { int totalMoney = getTotalMoney(player); if ( totalMoney < 1 ) { sendSystemMessage(player, gambling.SID_PLAYER_BROKE); return SCRIPT_CONTINUE; } queueCommand(player, ##"joinGame", self, "", COMMAND_PRIORITY_DEFAULT); } else if ( item == menu_info_types.SERVER_MENU2 ) { queueCommand(player, ##"leaveGame", self, "", COMMAND_PRIORITY_DEFAULT); } return SCRIPT_CONTINUE; } /***** COMMANDHANDLERS ********************************************************/ commandHandler cmdJoinGame() { if ( !isIdValid(target) ) return SCRIPT_CONTINUE; gambling.addTablePlayer(self, target, params); return SCRIPT_CONTINUE; } commandHandler cmdLeaveGame() { if ( !isIdValid(target) ) return SCRIPT_CONTINUE; if ( utils.hasScriptVar(target, "isGambling") ) { obj_id table = utils.getObjIdScriptVar(target, "isGambling"); if ( isIdValid(table) ) { if ( table != self ) { if ( table.isLoaded() ) { gambling.removeTablePlayer(table, target, params); return SCRIPT_CONTINUE; } } else { gambling.removeTablePlayer(self, target, params); return SCRIPT_CONTINUE; } } sendSystemMessage(target, STOP_GAMBLING); utils.removeScriptVar(target, "isGambling"); return SCRIPT_CONTINUE; } return SCRIPT_CONTINUE; } commandHandler cmdPlaceBet() { if ( !isIdValid(target) ) return SCRIPT_CONTINUE; if ( getDistance(getLocation(self), getLocation(target)) > BET_RANGE ) { sendSystemMessage(target, new string_id(gambling.STF_INTERFACE, "bet_failed_distance")); return SCRIPT_CONTINUE; } gambling.placeBet(self, target, params); return SCRIPT_CONTINUE; } commandHandler cmdBetFailed() { if ( !isIdValid(target) ) return SCRIPT_CONTINUE; if ( getDistance(getLocation(self), getLocation(target)) > BET_RANGE ) { sendSystemMessage(target, new string_id(gambling.STF_INTERFACE, "bet_failed_distance")); } dictionary d = new dictionary(); d.put("player", target); messageTo(self, "handleBetFailed", d, 0f, false); return SCRIPT_CONTINUE; } /***** MSG HANDLERS ********************************************************/ /***** FUNCTIONS ********************************************************/