Example #1
0
    // Use this for initialization
    void Start()
    {
        ShipDefinitions.Faction faction = ShipDefinitions.stringToFaction(gameObject.tag);
        projectile = GameObject.Find("GameLogic").GetComponent <PrefabHost>().getMissileObject();

        projectile.GetComponent <HomingMissile>().setDamage(20);
        projectile.GetComponent <HomingMissile>().setLifetime(25);

        if (testItem != "")
        {
            ItemAbstract testThing = ItemDefinitions.stringToItem(testItem);
            applyBuff(testThing);
        }

        /*
         * GameObject firingSprite = GameObject.Find("GameLogic")
         *  .GetComponent<PrefabHost>().getFiringSpriteObject();
         * firingSprite.transform.parent = gameObject.transform;
         * firingSprite.transform.position = new Vector3(
         *  gameObject.transform.position.x,
         *  gameObject.transform.position.y - 0.07f,
         *  gameObject.transform.position.z);
         * firingSprite.GetComponent<FiringSprite>()
         *  .setSprite(faction, "crown");
         */

        timer = GameObject.Find("GameLogic").GetComponent <Timer>();
        timer.addTimer(this.GetInstanceID());
        timer.addTimer(this.GetInstanceID() + 1);
    }
Example #2
0
    public void OnDrop(PointerEventData eventData)
    {
        Debug.Log("onDrop is called");
        if (!draggedObject)
        {                                               // check if slot has an item already
            GameObject obj = GameObject.Instantiate(dragHandler.draggedObject.gameObject);
            obj.GetComponent <IconHandler>().setNum(1); // check if slot has an item already
            obj.transform.SetParent(transform);
            dragHandler.draggedObject.GetComponent <IconHandler>()
            .decOne();
            ItemAbstract item = ItemDefinitions.stringToItem(
                draggedObject.GetComponent <ItemBasic>().itemString);
            transform.parent.GetComponent <ShipModSlotHandler>().setShipItem(item);
            //dragHandler.draggedObject.transform.SetParent(transform);

            print("obj: " + draggedObject.GetComponent <ItemBasic>().itemString);
            print("item: " + item.getType());
            ShipDefinitions.ShipEntity entity = ShipDefinitions.loadShip(transform.parent.GetComponent <ShipModSlotHandler>().thisEntity.uniqueId);
            print("ship: " + entity.uniqueId);
            print("currentItems: " + ItemDefinitions.itemsToString(entity.items));
            entity.items.Add(item);
            print("newCurrentItems: " + ItemDefinitions.itemsToString(entity.items));
            ShipDefinitions.saveShip(entity);
        }
    }
Example #3
0
    public void saveInventory()
    {
        List <ItemAbstract> items = new List <ItemAbstract>();

        foreach (string key in inventory.Keys)
        {
            ItemAbstract item = ItemDefinitions.stringToItem(key);
            for (int i = 0; i < inventory[key]; i++)
            {
                items.Add(item);
            }
        }
        ItemDefinitions.saveItems(uniqueId, ItemDefinitions.itemsToString(items));

        /*
         * string invSlotLabel = uniqueId + "InventorySlotLabel[Weapon]";
         * for (int i = 0; i < WeaponItem.numWeaponTypes; i++)
         * {
         *  string currLabel = invSlotLabel + i.ToString();
         *  print("Saving weapon item: " + i + " and num = " + numOfEachWeapItem[i]);
         *  UnityEngine.PlayerPrefs.SetInt(currLabel, numOfEachWeapItem[i]);
         * }
         * invSlotLabel = uniqueId + "InventorySlotLabel[Engine]";
         * for (int i = 0; i < EngineItem.numEngineTypes; i++)
         * {
         *  string currLabel = invSlotLabel + i.ToString();
         *  print("Saving engine item: " + i + " and num = " + numOfEachEngItem[i]);
         *  UnityEngine.PlayerPrefs.SetInt(currLabel, numOfEachEngItem[i]);
         * }
         */
    }
Example #4
0
    // Use this for initialization
    void Start()
    {
        gameObject.AddComponent <TargetFinder>();
        faction = ShipDefinitions.stringToFaction(gameObject.tag);

        // bad guys use red lasers, good guys use blue?
        if (faction == ShipDefinitions.Faction.Enemy)
        {
            color1 = Color.red;
            color2 = Color.yellow;
        }

        if (testItem != "")
        {
            ItemAbstract testThing = ItemDefinitions.stringToItem(testItem);
            applyBuff(testThing);
        }

        /*
         * GameObject firingSprite = GameObject.Find("GameLogic")
         *  .GetComponent<PrefabHost>().getFiringSpriteObject();
         * firingSprite.transform.parent = gameObject.transform;
         * firingSprite.transform.position = new Vector3(
         *  gameObject.transform.position.x,
         *  gameObject.transform.position.y - 0.07f,
         *  gameObject.transform.position.z);
         * firingSprite.GetComponent<FiringSprite>()
         *  .setSprite(faction, "crown");
         */
        timer = GameObject.Find("GameLogic").GetComponent <Timer>();
        timer.addTimer(this.GetInstanceID());
    }
Example #5
0
 public void reloadItems()
 {
     print(engines + " " + weapons + " " + engineBlueprints + " " + weaponBlueprints);
     inventoryDisplay.GetComponent <ItemListHandler>().removeAllItems();
     foreach (string key in inventory.Keys)
     {
         if (inventory[key] <= 0)
         {
             continue;
         }
         ItemAbstract item = ItemDefinitions.stringToItem(key);
         print(key + "->" + item.getType() + ":" + item.getTier());
         if (item.getType() == "Error")
         {
             continue;
         }
         if (WeaponItem.isWeaponType(item.getType()))
         {
             if (item.getTier() < 4)
             {
                 if (weapons)
                 {
                     addNumItems(item, inventory[key]);
                 }
             }
             else
             {
                 if (weaponBlueprints)
                 {
                     addNumItems(item, inventory[key]);
                 }
             }
         }
         else if (EngineItem.isEngineType(item.getType()))
         {
             if (item.getTier() < 4)
             {
                 if (engines)
                 {
                     addNumItems(item, inventory[key]);
                 }
             }
             else
             {
                 if (engineBlueprints)
                 {
                     addNumItems(item, inventory[key]);
                 }
             }
         }
     }
 }
Example #6
0
    // if an item is selected, keep track of it
    public void itemSelected(GameObject obj)
    {
        ItemAbstract item;

        if (!iconsMode)
        {
            UnityEngine.UI.Text indexItem = obj.transform.GetChild(0).
                                            GetComponent <UnityEngine.UI.Text>();
            item = ItemDefinitions.stringToItem(
                indexItem.text.Substring(0, indexItem.text.Length - 4));
        }
        else
        {
            item = ItemDefinitions.stringToItem(
                obj.GetComponent <ItemBasic>().itemString);
        }

        if (itemImage != null)
        {
            GameObject imgObj = itemImage;

            UnityEngine.UI.Image img = null;
            if (imgObj != null)
            {
                img = imgObj.GetComponent <UnityEngine.UI.Image>();
            }
            if (img != null)
            {
                img.sprite = getImage(item);
            }
        }
        if (panel1 != null)
        {
            panel1.GetComponent <UnityEngine.UI.Text>()
            .text = ItemDefinitions.getDesc(item);
        }
        if (panel2 != null)
        {
            panel2.GetComponent <UnityEngine.UI.Text>()
            .text = ItemDefinitions.getSpec(item);
        }

        if (alchemizeButton != null)
        {
            alchemizeButton.GetComponent <AlchemizeButton>()
            .itemSelected(item);
        }

        selectedItem = obj;
    }
Example #7
0
    public List <ItemAbstract> getAllItems()
    {
        List <ItemAbstract> retItems = new List <ItemAbstract>();

        for (int i = 0; i < transform.GetChild(0).childCount; i++)
        {
            UnityEngine.UI.Text indexItem = transform.GetChild(0).GetChild(i).GetChild(0).
                                            GetComponent <UnityEngine.UI.Text>();
            string       labelItemText = indexItem.text.Substring(0, indexItem.text.Length - 4);
            int          numItems      = int.Parse(indexItem.text.Substring(indexItem.text.Length - 2, 1));
            ItemAbstract item          = ItemDefinitions.stringToItem(labelItemText);
            for (int j = 0; j < numItems; j++)
            {
                retItems.Add(item);
            }
        }

        return(retItems);
    }
Example #8
0
    // handle buying or selling
    public void handleItem()
    {
        GameObject itemObj = null;

        // whichever object is being bought or sold
        if (buying)
        {
            itemObj = merchantItemList.selectedItem;
        }
        else
        {
            itemObj = playerItemList.selectedItem;
        }

        // if nothing is selected, return
        if (itemObj == null)
        {
            return;
        }

        // convert the text from that object to an item
        // It's of the form "ObjectName (x)" where x is a quantity
        ItemAbstract item;

        UnityEngine.UI.Text indexItem = itemObj.transform.GetChild(0).
                                        GetComponent <UnityEngine.UI.Text>();
        Regex           regex   = new Regex(@"\w+");
        MatchCollection matches = regex.Matches(indexItem.text);

        item = ItemDefinitions.stringToItem(matches[0].ToString() + ":" +
                                            matches[1].ToString());

        int cost;

        // handle inventory and currency changes
        if (buying)
        {
            cost = ItemDefinitions.getCost(item, merchantId, buying);
            merchantInventory.addCurrency(cost);
            playerInventory.addCurrency(-cost);
            merchantItemList.removeItem(item);
            playerItemList.addItem(item);
            if (item.getTier() > 3)
            {
                BlueprintDefinitions.applyBlueprint(item);
                print("applying blueprint " + ItemDefinitions.itemToString(item));
            }
        }
        else
        {
            cost = ItemDefinitions.getCost(item, playerId, buying);
            merchantInventory.addCurrency(-cost);
            playerInventory.addCurrency(cost);
            playerItemList.removeItem(item);
            merchantItemList.addItem(item);
            if (item.getTier() > 3)
            {
                BlueprintDefinitions.deapplyBlueprint(item);
                print("deapplying blueprint " + ItemDefinitions.itemToString(item));
            }
        }
    }