Esempio n. 1
0
 /// <summary>
 /// Use to spawn an item into the game world as if dropped by this player, but only spawns it locally.
 /// You may notice that the vanilla game's source-code uses Resources.Load to spawn items. You should not use that.
 /// </summary>
 /// <param name="pos">The position to spawn the item at. Note that despite being a 2D game, Roguelands uses 3D space. That being said, the z-coordinate should nearly always be 0.</param>
 /// <param name="item">The item to spawn.</param>
 /// <param name="isChip">True to drop a chip instead of a normal item.</param>
 public static ItemScript DropItemLocal(Vector3 pos, Item item, bool isChip = false)
 {
     if (!isChip)
     {
         int[]      st         = ConstructIntArrayFromItem(item);
         ItemScript itemScript = ((GameObject)UnityEngine.Object.Instantiate(Resources.Load("i2"), pos, Quaternion.identity)).GetComponent <ItemScript>();
         itemScript.SendMessage("InitL", st);
         if (ItemRegistry.GetSingleton().HasEntry(item.id) && (ItemRegistry.GetSingleton().GetEntry(item.id).Type & ItemType.EQUIPABLE) == ItemType.EQUIPABLE)
         {
             itemScript.back.SetActive(true);
         }
         return(itemScript);
     }
     else
     {
         ItemScript itemScript = ((GameObject)UnityEngine.Object.Instantiate(Resources.Load("i2"), pos, Quaternion.identity)).GetComponent <ItemScript>();
         itemScript.SendMessage("ChipL", item.id);
         return(itemScript);
     }
 }
Esempio n. 2
0
 public bool TryDrop(Vector3 pos)
 {
     if (CheckValidToDrop == null || CheckValidToDrop(pos))
     {
         if (dropChance <= 0)
         {
             return(false);
         }
         if (UnityEngine.Random.value <= dropChance)
         {
             if (isChip || (ItemRegistry.GetTypeByID(itemToDrop.id) & ItemType.NONSTACKING) == ItemType.NONSTACKING)
             {
                 if (itemToDrop != null)
                 {
                     itemToDrop.q = 1;
                 }
                 for (int i = 0; i < Mathf.RoundToInt(UnityEngine.Random.value * (maxDropQuantity - minDropQuantity)) + minDropQuantity; i++)
                 {
                     if ((CustomDropBehavior == null || CustomDropBehavior(itemToDrop, pos)) && itemToDrop != null)
                     {
                         GadgetCoreAPI.SpawnItemLocal(pos, itemToDrop, isChip);
                     }
                 }
             }
             else
             {
                 if (itemToDrop != null)
                 {
                     itemToDrop.q = Mathf.RoundToInt(UnityEngine.Random.value * (maxDropQuantity - minDropQuantity)) + minDropQuantity;
                 }
                 if ((CustomDropBehavior == null || CustomDropBehavior(itemToDrop, pos)) && itemToDrop != null)
                 {
                     GadgetCoreAPI.SpawnItemLocal(pos, itemToDrop, isChip);
                 }
             }
             return(true);
         }
     }
     return(false);
 }
Esempio n. 3
0
 /// <summary>
 /// Constructs a new VanillaItemInfo based upon the given ID. Do not try to call this yourself - use <see cref="Wrap"/>
 /// </summary>
 /// <param name="ID">The vanilla ID to be wrapped.</param>
 /// <param name="WrapForTile">If true, the Tile property should not be set by this constructor, as it will be set later as part of a TileInfo's constructor.</param>
 protected VanillaItemInfo(int ID, bool WrapForTile) : base(ItemRegistry.GetDefaultTypeByID(ID), GadgetCoreAPI.GetItemName(ID), GadgetCoreAPI.GetItemDesc(ID), GadgetCoreAPI.GetItemMaterial(ID), -1, GadgetCoreAPI.GetTrueGearBaseStats(ID), GadgetCoreAPI.GetWeaponMaterial(ID), ID >= 1000 && ID < 2000 ? GadgetCoreAPI.GetDroidHeadMaterial(ID) : GadgetCoreAPI.GetHeadMaterial(ID), ID >= 1000 && ID < 2000 ? GadgetCoreAPI.GetDroidBodyMaterial(ID) : GadgetCoreAPI.GetBodyMaterial(ID), GadgetCoreAPI.GetArmMaterial(ID))
 {
     this.ID = ID;
     if ((Type & ItemType.EQUIP_MASK) == (ItemType.WEAPON & ItemType.EQUIP_MASK))
     {
         SetWeaponInfo(ItemRegistry.GetDefaultWeaponScalingByID(ID), GadgetCoreAPI.GetAttackSound(ID), ItemRegistry.GetDefaultCritChanceBonus(ID), ItemRegistry.GetDefaultCritPowerBonus(ID), ID);
         OnAttack += (script) => { Attacking = true; IEnumerator ie = script.Attack(); Attacking = false; return(ie); };
     }
     else if ((Type & ItemType.USABLE) == ItemType.USABLE)
     {
         OnUse += (slot) => { Using = true; InstanceTracker.GameScript.StartCoroutine(InstanceTracker.GameScript.UseItemFinal(slot)); return(false); };
     }
     if (!WrapForTile)
     {
         if (TileRegistry.Singleton.HasEntry(ID))
         {
             SetTile(TileRegistry.Singleton.GetEntry(ID));
         }
         else
         {
             SetTile(VanillaTileInfo.Wrap(ID, false));
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Constructs a new VanillaItemInfo based upon the given ID. Do not try to call this yourself - use <see cref="Wrap"/>
 /// </summary>
 /// <param name="ID">The vanilla ID to be wrapped.</param>
 protected VanillaTileInfo(int ID) : base(TileRegistry.GetDefaultTypeByID(ID), GadgetCoreAPI.GetTileMaterial(ID), TileRegistry.GetDefaultTypeByID(ID) == TileType.INTERACTIVE ? GadgetCoreAPI.GetPlaceableNPCResource(ID) : GadgetCoreAPI.GetPropResource(ID), ItemRegistry.GetSingleton().HasEntry(ID) ? ItemRegistry.GetSingleton().GetEntry(ID) : VanillaItemInfo.WrapForTile(ID, false))
 {
     this.ID = ID;
 }