/******************************************************************************************** * Copyright (c) ©2000,2001 Sony Online Entertainment Inc. * All Rights Reserved ******************************************************************************************** * Title: chance_cube.script * Description: Like Watto's cube from Episode 1. It can either roll blue or red. * * @author $Author: Matthew Kwid$ * @version $Revision: $ * ******************************************************************************************** /***** METHODS ***************************************************************************** trigger OnInitialize() messageHandler roll() trigger OnDetach() /***** INCLUDES *****************************************************************************/ include library.utils; include library.debug; include library.xp; include library.craftinglib; /***** INHERITS *****************************************************************************/ inherits item.dice.base.base_dice; /***** CONSTANTS ****************************************************************************/ const string DICE_FACE_COLOR_RED = "red"; const string DICE_FACE_COLOR_BLUE = "blue"; const int DICE_FACE_COUNT = 2; const int NUMBER_OF_DICE = 1; const string TYPE_NAME = "chance_cube"; /******************************************************************************************** * @brief trigger handler when initializing the script * * @return SCRIPT_CONTINUE ********************************************************************************************/ trigger OnInitialize() { debug.debugAllMsg("DEBUG", self, "##########chance_cube initialized##############"); setObjVar(self, DICE_TYPE_NAME, TYPE_NAME); return SCRIPT_CONTINUE; }//OnInitialize messageHandler roll() { debug.debugAllMsg("DEBUG", self, "##########chance_cube roll()##############"); obj_id player = params.getObjId( "player" ); xp.grantCraftingXpChance( self, player, 40 ); int rollResult = rand(NUMBER_OF_DICE, DICE_FACE_COUNT, 0); if(rollResult == 1) setObjVar(self, VAR_ROLL_RESULT, DICE_FACE_COLOR_RED); if(rollResult == 2) setObjVar(self, VAR_ROLL_RESULT, DICE_FACE_COLOR_BLUE); return SCRIPT_CONTINUE; }//roll /******************************************************************************************** * @brief trigger handler when detaching the script * * @return trigger SCRIPT_CONTINUE *********************************************************************************************/ trigger OnDetach() { debug.debugAllMsg("DEBUG", self, "##########chance script detached##############"); return SCRIPT_CONTINUE; }//OnDetach trigger OnGetAttributes(obj_id player, string[] names, string[] attribs) { int idx = utils.getValidAttributeIndex(names); if (idx == -1) return SCRIPT_CONTINUE; if (hasObjVar(self, craftinglib.COMPONENT_ATTRIBUTE_OBJVAR_NAME + ".useModifier")) { names[idx] = "usemodifier"; int attrib = (int)getFloatObjVar(self, craftinglib.COMPONENT_ATTRIBUTE_OBJVAR_NAME + ".useModifier"); attribs[idx] = "" + attrib; idx++; if (idx >= names.length) return SCRIPT_CONTINUE; } return SCRIPT_CONTINUE; }