Ejemplo n.º 1
0
    private IEnumerator FloatingXPTextDisplay(ItemOre ore)
    {
        floatingOreText = (GameObject)GameObject.Instantiate(Resources.Load("FloatingXPText"), transform.position, Quaternion.identity);
        floatingOreTextScript = floatingOreText.GetComponent<FloatingXPText>();
        floatingOreTextScript.parent2 = transform;
        floatingOreTextScript.textColor = new Color(1.0f, 0.6f, 0.0f, 1.0f);
        yield return new WaitForEndOfFrame();
        floatingOreTextScript.displayText("+1 " + ore.ToString());
        Destroy(floatingOreText,2);

        // Surface level parent should be a rogue room, so assume:
        renderer.material.SetTexture("_DecalTex", crackTextures[0]);
        ((RogueRoom)_cube.Parent).DestroyMineableBlock(this);

        //Destroy (gameObject);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Destroys the cube, and alerts all necessary parties that it was.
 /// </summary>
 void killUnit()
 {
     if (_cube.Type != ItemBase.tOreType.Stone && _cube.Type != ItemBase.tOreType.NOT_ORE)
      	    {
         floatingOreText = (GameObject)GameObject.Instantiate(Resources.Load("FloatingXPText"), transform.position, Quaternion.identity);
         floatingOreTextScript = floatingOreText.GetComponent<FloatingXPText>();
         floatingOreTextScript.parent2 = transform;
         floatingOreTextScript.enabled = true;
         floatingOreTextScript.textColor = new Color(1.0f, 0.6f, 0.0f, 1.0f);
         ItemOre ore = new ItemOre(_cube.Type);
         floatingOreTextScript.displayText("+1 " + ore.ToString());
         StartCoroutine(FloatingXPTextDisplay(ore));
         Inventory.getInstance().inventoryAddItem(ore);
     }
     else
     {
          // Surface level parent should be a rogue room, so assume:
         renderer.material.SetTexture("_DecalTex", crackTextures[0]);
         ((RogueRoom)_cube.Parent).DestroyMineableBlock(this);
     }
     //_cube.Parent.DestroyCube(_cube);
     //Destroy (gameObject);
 }
Ejemplo n.º 3
0
        public static List <ItemStack> GetMacerate(CollectibleObject co, ICoreAPI api, string machinename)
        {
            if (machinename == "")
            {
                machinename = "macerator";
            }
            List <ItemStack> outputstack = new List <ItemStack>();

            if (!CanMacerate(co, api, machinename))
            {
                return(outputstack);
            }
            string fcp      = co.FirstCodePart();
            string fullcode = co.Code.ToString();
            Random rand     = new Random();

            if (fcp == "ore")
            {
                ItemOre oreitem = co as ItemOre;
                if (oreitem != null)
                {
                    string outitemcode = "game:nugget-";
                    bool   metalfound  = false;
                    foreach (string outmetal in orelookups.Keys)
                    {
                        if (fullcode.Contains(outmetal))
                        {
                            outitemcode += outmetal;
                            metalfound   = true;
                            break;
                        }
                    }
                    if (metalfound)
                    {
                        int outitemqty = oreitem.Attributes["metalUnits"].AsInt(1) + rand.Next(0, 5);

                        Item outputItem = api.World.GetItem(new AssetLocation(outitemcode));
                        if (outputItem != null)
                        {
                            ItemStack itmstk = new ItemStack(outputItem, outitemqty);
                            outputstack.Add(itmstk);
                        }
                    }
                }
            }
            if (maceratelist.ContainsKey(fcp))
            {
                foreach (MacerationRecipe mr in maceratelist[fcp])
                {
                    if (mr.type == enTypes.DIRECT)
                    {
                        continue;
                    }
                    if (mr.machinename != machinename && mr.machinename != "*")
                    {
                        continue;
                    }
                    double roll = rand.NextDouble() * 100;
                    if (!(mr.odds == 100 || roll <= mr.odds))
                    {
                        continue;
                    }
                    string al = fullcode;
                    if (mr.type == enTypes.SWAP)
                    {
                        al = al.Replace(fcp, mr.outputmaterial);
                    }
                    else if (mr.type == enTypes.ORESWAP)
                    {
                        foreach (string nativemetal in orelookups.Keys)
                        {
                            if (fullcode.Contains(nativemetal))
                            {
                                al = al.Replace(nativemetal, orelookups[nativemetal]);
                                al = al.Replace("game", "machines");//THIS IS A HACK PLZ FIX
                            }
                        }
                    }
                    else if (mr.type == enTypes.PARTIAL)
                    {
                        al = mr.outputmaterial;
                    }
                    int outqty = mr.outputquantity;
                    if (mr.odds != 100)
                    {
                        outqty = rand.Next(1, mr.outputquantity + 1);
                    }
                    Block outputBlock = api.World.GetBlock(new AssetLocation(al));
                    Item  outputItem  = api.World.GetItem(new AssetLocation(al));
                    if (outputBlock != null)
                    {
                        ItemStack itmstk = new ItemStack(outputBlock, outqty);
                        outputstack.Add(itmstk);
                    }
                    if (outputItem != null)
                    {
                        ItemStack itmstk = new ItemStack(outputItem, outqty);
                        outputstack.Add(itmstk);
                    }
                }
            }
            if (maceratelist.ContainsKey(fullcode))
            {
                foreach (MacerationRecipe mr in maceratelist[fullcode])
                {
                    if (mr.type == enTypes.SWAP || mr.type == enTypes.PARTIAL)
                    {
                        continue;
                    }
                    if (mr.machinename != machinename && mr.machinename != "*")
                    {
                        continue;
                    }
                    double roll = rand.NextDouble() * 100;
                    if (!(mr.odds == 100 || roll <= mr.odds))
                    {
                        continue;
                    }
                    string al = mr.outputmaterial;

                    int outqty = mr.outputquantity;
                    if (mr.odds != 100)
                    {
                        outqty = rand.Next(1, mr.outputquantity + 1);
                    }
                    Block outputBlock = api.World.GetBlock(new AssetLocation(al));
                    Item  outputItem  = api.World.GetItem(new AssetLocation(al));
                    if (outputBlock != null)
                    {
                        ItemStack itmstk = new ItemStack(outputBlock, outqty);
                        outputstack.Add(itmstk);
                    }
                    if (outputItem != null)
                    {
                        ItemStack itmstk = new ItemStack(outputItem, outqty);
                        outputstack.Add(itmstk);
                    }
                }
            }
            return(outputstack);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Add an item to the inventory.
    /// </summary>
    /// <param name="newItem">ItemOre</param>
    public void inventoryAddItem(ItemOre newItem)
    {
        if (newItem == null)
            return;

        //Since ores are defined soly on their ore type, we can disregard any other info about the ore
        ores[(int)newItem.oreType] += 1;
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Returns and ArrayList of ores in the inventory.
    /// </summary>
    /// <returns></returns>
    public ArrayList getInventoryOres()
    {
        ArrayList temp = new ArrayList();

        //Only return those ores which have are actually present
        foreach (KeyValuePair<int, int> entry in ores)
        {
            if (entry.Value > 0)
            {
                ItemOre oreToBeAdded = new ItemOre((ItemBase.tOreType)entry.Key);
                oreToBeAdded.Quantity = entry.Value;

                temp.Add(oreToBeAdded);
            }
        }

        return temp;
    }
Ejemplo n.º 6
0
    /// <summary>
    /// This method handles the button presses relevant to crafting while in the crafting menu
    /// </summary>
    private void handleCraftingMovement()
    {
        if (InputContextManager.isMENU_UP())
        {
            switch (craftingState)
            {
                case tCraftingState.CATEGORY_SELECTION:
                    //Decrement the crafting index w/o going negative
                    intCraftingCategory = Math.Max(0, intCraftingCategory - 1);
                    break;
                case tCraftingState.ITEM_TYPE:
                    //Decrement the type index w/o going negative
                    intCraftingTypesInCategory = Math.Max(0, intCraftingTypesInCategory - 1);
                    break;
                case tCraftingState.ATTRIBUTE_SELECTION:
                    //Decrement the attribute index w/o going negative
                    intCraftingAttributes = Math.Max(0, intCraftingAttributes - 1);
                    break;
                case tCraftingState.ORE_SELECTION:
                    //Decrement the ore type index w/o going negative
                    intCraftingOres = Math.Max(0, intCraftingOres - 1);
                    break;
                case tCraftingState.WEAPON_TYPE:
                    //Decrement the weapon type index w/o going negative
                    intCraftingWeaponTypes = Math.Max(0, intCraftingWeaponTypes - 1);
                    break;
            };

        }
        else if (InputContextManager.isMENU_DOWN())
        {
            switch (craftingState)
            {
                case tCraftingState.CATEGORY_SELECTION:
                    //Increment the category index w/o going over the total states
                    intCraftingCategory = Math.Min(craftingCategories.Count - 1, intCraftingCategory + 1);
                    break;
                case tCraftingState.ITEM_TYPE:
                    //Increment the category types index w/o going over the total states
                    intCraftingTypesInCategory = Math.Min(craftingTypeInCategory.Count - 1, intCraftingTypesInCategory + 1);
                    break;
                case tCraftingState.ATTRIBUTE_SELECTION:
                    //Increment the attributes index w/o going over the total states
                    intCraftingAttributes = Math.Min(craftingAttributes.Count - 1, intCraftingAttributes + 1);
                    break;
                case tCraftingState.ORE_SELECTION:
                    //Increment the ore type index w/o going over the total states
                    intCraftingOres = Math.Min(craftingOres.Count - 1, intCraftingOres + 1);
                    break;
                case tCraftingState.WEAPON_TYPE:
                    //Increment the weapon type index w/o going over the total states
                    intCraftingWeaponTypes = Math.Min(craftingWeaponTypes.Count - 1, intCraftingWeaponTypes + 1);
                    break;
            };
        }
        else if (InputContextManager.isMENU_LEFT())
        {
            //Go left one state w/o going negative
            craftingState = (tCraftingState)Math.Max(0, (int)craftingState - 1);
        }
        else if (InputContextManager.isMENU_RIGHT())
        {
            //Go right one state w/o going off the end of the states
            int numStates = Enum.GetNames(typeof(tCraftingState)).Length;

            if (craftingCategories[intCraftingCategory].Equals(ItemBase.tItemType.Component))
            {
                craftingState = (tCraftingState)Math.Min(numStates - 1, (int)craftingState + 1);
            }
            else
            { //If we're not making components, we have one less group and so subtract by 2 instaed of 1
                craftingState = (tCraftingState)Math.Min(numStates - 2, (int)craftingState + 1);
            }
        }
        else if (InputContextManager.isMENU_SELECT())
        {
            //Check what we're making
            if (craftingCategories[intCraftingCategory].Equals(ItemBase.tItemType.Armor)) //We're making armor
            {
                //Create the item
                String armorCode = ItemArmor.generateArmorCode(craftingAttributes[intCraftingAttributes], craftingOres[intCraftingOres], armors[intCraftingTypesInCategory]);
                ItemArmor madeArmor = ItemFactory.createArmor(armorCode);

                //Check the requirements
                ItemSlot armorSlot = new ItemSlot();
                ItemOre oreRequirement = new ItemOre(madeArmor.oreType);
                oreRequirement.neededOreQuantity = madeArmor.neededOreQuantity;
                oreRequirement.neededPoints = madeArmor.neededPoints;
                armorSlot.oreNeeded = oreRequirement;

                if (playerCanCraft(armorSlot))
                {
                    //Remove the required parts and add the selected item to the inventory
                    inventory.inventoryRemoveItem(oreRequirement, armorSlot.oreNeeded.neededOreQuantity);
                    player.CraftingPoints -= armorSlot.oreNeeded.neededPoints;
                    inventory.inventoryAddItem(madeArmor);
                }
            }
            else //We're making components
            {
                //Create the item
                String componentCode = ItemComponent.generateComponentCode(craftingAttributes[intCraftingAttributes], craftingOres[intCraftingOres],
                                        craftingWeaponTypes[intCraftingWeaponTypes], (ItemComponent.tComponentPart)craftingTypeInCategory[intCraftingTypesInCategory]);
                ItemComponent madeComponent = ItemFactory.createComponent(componentCode);

                //Check the item requirements
                ItemSlot componentSlot = new ItemSlot();
                ItemOre oreRequirement = new ItemOre(madeComponent.oreType);
                oreRequirement.neededOreQuantity = madeComponent.neededOreQuantity;
                componentSlot.oreNeeded = oreRequirement;

                if (playerCanCraft(componentSlot))
                {
                    //Remove the required parts and add the selected item to the inventory
                    inventory.inventoryRemoveItem(oreRequirement, componentSlot.oreNeeded.neededOreQuantity);
                    player.CraftingPoints -= componentSlot.oreNeeded.neededPoints;
                    inventory.inventoryAddItem(madeComponent);
                }
            }
        }
    }
Ejemplo n.º 7
0
        public ItemSlot()
        {
            item = null;
            unlocked = false;

            oreNeeded = new ItemOre(ItemBase.tOreType.NOT_ORE);
            oreNeeded.Quantity = 0;
            oreNeeded.neededPoints = 0;
        }