public static Item createItem(ItemData datablock)
 {
     ObjectCreator tch = new ObjectCreator("Item");
     tch["dataBlock"] = datablock;
     tch["static"] = true;
     tch["rotate"] = true;
     return tch.Create();
 }
 public virtual bool Throw(ItemData data, int amount = 1)
 {
     bool functionresult = false;
     if (getInventory(data) > 0)
         {
         Item objectid = data.onThrow(this, amount);
             {
             if (objectid != 0)
                 {
                 throwObject(objectid);
                 Audio.AudioServerPlay3D("ThrowSnd", this.getTransform());
                 functionresult = true;
                 }
             }
         }
     return functionresult;
 }
        public virtual bool Use(ItemData data)
        {
            GameConnection client = getControllingClient();
            if (client.isObject())
                {
                double defaultfov = client.getControlCameraDefaultFov();
                double fov = client.getControlCameraFov();
                if (defaultfov != fov)
                    return false;
                }
            if (getInventory(data) > 0)

                return data.onUse(_ID);

            return false;
        }
        public virtual int setInventory(ItemData data, int value = 0)
        {
            int max = 0;

            max = maxInventory(data);
            if (value > max)
                value = max;

            int amount = this["inv[" + data.getName() + "]"].AsInt();

            if (amount != value)
                {
                this["inv[" + data.getName() + "]"] = value.AsString();
                //console.warn("Setting " + data.getName() + " to " + value);

                data.onInventory(this, value);
                }
            return value;
        }
        public virtual int decInventory(ItemData data, int amount = 0)
        {
            int total = this["inv[" + data.getName() + "]"].AsInt();

            if (total > 0)
                {
                if (total < amount)
                    amount = total;

                setInventory(data, (total - amount));
                return amount;
                }
            return 0;
        }
        public virtual int incInventory(ItemData datablock, int amount)
        {
            int maxamount = maxInventory(datablock);

            int total = this["inv[" + datablock.getName() + "]"].AsInt();

            if (total < maxamount)
                {
                if (total + amount > maxamount)
                    amount = (maxamount - total);
                setInventory(datablock, (total + amount));
                return amount;
                }
            return 0;
        }
 public static void serverCmdUse(GameConnection client, ItemData data)
 {
     if (((Player) client.getControlObject()).isObject())
         ((Player) client.getControlObject()).Use(data);
 }
Exemple #8
0
 public override bool Use(ItemData data)
 {
     if (isPilot())
         return false;
     //Instead of going through the parent stuff, we can now just call the parent function via base.
     return base.Use(data);
 }