Class MMOItemVariable

  • All Implemented Interfaces:
    UserVariable, Variable, IMMOItemVariable, java.io.Serializable, java.lang.Cloneable

    public class MMOItemVariable
    extends SFSUserVariable
    implements IMMOItemVariable
    MMOItem Variables allow to attach custom properties to MMOItems inside an MMORoom. MMOItems can represent bonuses, triggers, bullets or any other non-player entity inside an MMORoom that will be handled with the same Area Of Interest rules.

    This means that whenever one or more MMOItem fall within the AoI of a Player it will be notified to the User with a client side PROXIMITY_LIST_UPDATE. MMOItems are identified by unique ID and by all of their custom variables.

    MMOItem Variables behave exactly like User Variables and can be updated or removed via server side code. This allows MMOItems to be highly dynamic within the context of the MMORoom.

    Example of use:

     // Prepare the variables
     List<IMMOItemVariables> vars = new LinkedList<IMMOItemVariables>();
     vars.add(new MMOItemVariable("type", "1");  // identifies the type of bonus based on our game rules
     vars.add(new MMOitemVariable("val", 100);   // the value of the bonus
     
     // Create the item
     MMOItem bonus = new MMOItem(vars);
     
     // Access the MMO API
     ISFSMMOApi mmoApi = SmartfoxServer.getInstance().getAPIManager().getMMOApi;
     
     // Set the Item in the room at specific coordinates 
     mmoApi.setMMOItemPosition(bonus, new Vec3D(10, 20, 5), theMMORoom);
      
     

    The final line of code assumes we already have an MMORoom object where the Item will be added. It might be an existing room or one that has just been created. After the Item is placed in the MMORoom a PROXIMITY_LIST_UPDATE will be sent to Users that are within range of the object.

    Removing Variables: in order to remove one or more existing variables you will need to set those variables to NULL, using the SFSUserVariable.setNull() method;

    Since:
    2.8.x
    See Also:
    MMOItemVariable, MMORoom, SFSMMOApi, Serialized Form
    • Constructor Detail

      • MMOItemVariable

        public MMOItemVariable​(java.lang.String name,
                               java.lang.Object value,
                               boolean isHidden)
        Construct an MMOVariable with it's name and value. The hidden flag allows to hide the variable to clients
        Parameters:
        name - name of the variable
        value - value of the variables (can be Bool, Int, Double, String, SFSArray, SFSObject)
        isHidden - if true the variable will remain server side only
        See Also:
        MMOItem, MMORoom, SFSMMOApi.setMMOItemVariables(BaseMMOItem, java.util.List)
      • MMOItemVariable

        protected MMOItemVariable​(java.lang.String name)
      • MMOItemVariable

        protected MMOItemVariable​(java.lang.String name,
                                  VariableType type,
                                  java.lang.String literal)
      • MMOItemVariable

        protected MMOItemVariable​(java.lang.String name,
                                  java.lang.String type,
                                  java.lang.String literal)
    • Method Detail

      • newInstance

        public static MMOItemVariable newInstance​(java.lang.String name,
                                                  java.lang.Object value)
      • newFromStringLiteral

        public static MMOItemVariable newFromStringLiteral​(java.lang.String name,
                                                           java.lang.String type,
                                                           java.lang.String literal)