Esempio n. 1
0
    void FixedUpdate()
    {
        if (currentMineable != null)
        {
            miningProgress++;
            if (miningProgress > currentMineable.miningTime)
            {
                currentMineable.OnMine(playerInventory);
                miningProgress = 0;
            }
        }

        if (firingTimer < firingSpeed)
        {
            firingTimer++;
        }
        if (fireWeapon == true && firingTimer == firingSpeed)
        {
            if (ammoInventory.inventoryReadOnly[selectedAmmoSlot] != null)
            {
                ItemAmmo ammo = ammoInventory.inventoryReadOnly[selectedAmmoSlot].item as ItemAmmo;
                if (ammo != null)
                {
                    ammo.OnFire(Camera.main.ScreenToWorldPoint(Input.mousePosition), this.gameObject);
                    ammoInventory.DecrementStack(selectedAmmoSlot);
                    firingTimer = 0;
                }
            }
        }
        fireWeapon = false;
    }
Esempio n. 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (target == null || target.gameObject == null)
        {
            int count = Physics2D.OverlapCircleNonAlloc(this.transform.position, attackRange, results, mask);
            for (int i = 0; i < count; i++)
            {
                if (results[i].TryGetComponent(out target) && AllianceDefinitions.Instance.GetAlliance(this.GetComponent <Health>().alliance).hostileTowards.Contains(target.alliance))
                {
                    break;
                }
                else
                {
                    target = null;
                }
            }
        }
        else
        {
            Vector2 targetVector = target.transform.position - this.transform.position;
            counter++;
            animator.speed = 15.0f / firingRate;
            if (targetVector.magnitude > attackRange)
            {
                target         = null;
                animator.speed = 0.0f;
            }
            else if (ammoInventory.inventoryReadOnly[0] != null && counter > firingRate)
            {
                //change this to interface with ammo item (ammo item should have some sort of onfire method which either does a hitscan or spawns
                //a projectile, there also needs to be some sort of check to make sure ammo inserted is correct ammo for turret)

                ItemAmmo ammo = ammoInventory.inventoryReadOnly[0].item as ItemAmmo;
                if (ammo != null)
                {
                    ammo.OnFire(target, this.gameObject);
                    ammoInventory.DecrementStack(0);
                    counter        = 0;
                    turretRotation = Mathf.Rad2Deg * Mathf.Atan2(targetVector.y, targetVector.x);

                    if (turretRotation < 0)
                    {
                        turretRotation += 360;
                    }
                    int rotationIncrement = Mathf.RoundToInt(turretRotation / angleDivider);
                    int rotationSnap      = rotationIncrement * 45;
                    ParticleSystemPool.Instance.EmitParticle(flareType, ((Vector2)this.transform.position + flareOffset) + (Vector2)(Quaternion.AngleAxis(rotationSnap, Vector3.forward) * flareDistance), -rotationSnap, 1);
                    ChangeAnimationState(hashCodes[rotationIncrement % hashCodes.Length]);
                }
            }
            else if (ammoInventory.inventoryReadOnly[0] == null)
            {
                animator.speed = 0;
            }
        }
    }
Esempio n. 3
0
 public void ManualReload(ItemAmmo ammo)
 {
     if (stats.weapon)
     {
         if (stats.weapon.ammoUsed.ammo == ammo.ammo)
         {
             ReloadWeaponButton();
         }
     }
 }
Esempio n. 4
0
    public ItemAmmo ConsumeAmmo()
    {
        inventory[currentSlot].size--;
        ItemAmmo item = inventory[currentSlot].item as ItemAmmo;

        if (inventory[currentSlot].size == 0)
        {
            inventory[currentSlot] = null;
        }
        return(item);
    }
Esempio n. 5
0
File: Stats.cs Progetto: exewin/Tact
 public void FindAmmo()
 {
     for (int i = 0; i < inv.items.Count; i++)
     {
         if (inv.items[i] is ItemAmmo)
         {
             ItemAmmo item = (ItemAmmo)inv.items[i];
             if (item.ammo == weapon.ammoUsed.ammo)
             {
                 weapon.ammoUsed = item;
             }
         }
     }
 }
Esempio n. 6
0
 public override void TransferMouse(Inventory mouse, int slotID)
 {
     if (mouse.inventoryReadOnly[0] == null)
     {
         base.TransferMouse(mouse, slotID);
     }
     else
     {
         ItemAmmo ammo = mouse.inventoryReadOnly[0].item as ItemAmmo;
         if ((ammo != null) && (ammoRestriction == ItemAmmo.AmmoType.None || ammoRestriction == ammo.ammoType))
         {
             base.TransferMouse(mouse, slotID);
         }
     }
 }
Esempio n. 7
0
    public void RebuildTooltipDescription(UIMouseEvents sender)
    {
        UITooltip.Text = "";
        UITooltip.DisableForceHide();

        int senderIndex = System.Array.FindIndex(armorSlots, x => x.gameObject == sender.gameObject);

        if (senderIndex != -1 && armorTarget != null)
        {
            if (armorTarget.Armor[senderIndex] != null && armorTarget.Armor[senderIndex].ItemPrefab != null)
            {
                IItem item = armorTarget.Armor[senderIndex].ItemPrefab.GetComponent <IItem>();
                if (item != null)
                {
                    Armor a = armorTarget.Armor[senderIndex];

                    UITooltip.Text += "<size=12>";
                    UITooltip.Text += "<color=#" + item.Quality.ToColor().ToHexStringRGBA() + ">" + item.Name;
                    UITooltip.Text += "</color>";
                    UITooltip.Text += "</size>\n";
                    UITooltip.Text += "<color=yellow><size=7><i>";
                    UITooltip.Text += item.Description;
                    UITooltip.Text += "</i></size></color>\n\n";

                    UITooltip.Text += a.Type.ToString() + " armor\n";
                    UITooltip.Text += "Armor value : " + a.ArmorValue + "\n";

                    if (a.Stats != 0)
                    {
                        UITooltip.Text += "<color=green>";
                        if (a.Stats.Strength != 0)
                        {
                            UITooltip.Text += "Strength +" + a.Stats.Strength + "\n";
                        }
                        if (a.Stats.Stamina != 0)
                        {
                            UITooltip.Text += "Stamina +" + a.Stats.Stamina + "\n";
                        }
                        if (a.Stats.Defense != 0)
                        {
                            UITooltip.Text += "Defense +" + a.Stats.Defense + "\n";
                        }
                        if (a.Stats.Energy != 0)
                        {
                            UITooltip.Text += "Energy +" + a.Stats.Energy + "\n";
                        }
                        UITooltip.Text += "</color>";
                    }

                    UITooltip.Text += "\n<color=green><i>Right click to Unequip</i></color>";
                }
            }
            else
            {
                UITooltip.ForceHide();
            }
        }
        else if (senderIndex == -1 && weapTarget != null)
        {
            IWeapon           weapon = null;
            IRangedWeaponAmmo ammo   = null;
            if (sender == mainHandSlot.GetComponent <UIMouseEvents>())
            {
                weapon = weapTarget.MainHandWeapon;
            }
            else if (sender == offHandSlot.GetComponent <UIMouseEvents>())
            {
                weapon = weapTarget.OffHandWeapon;
            }
            else if (sender == ammoSlot.GetComponent <UIMouseEvents>())
            {
                ammo = weapTarget.CurrentAmmos;
            }

            if (weapon != null)
            {
                IItem item = weapon.InventoryItemPrefab != null?weapon.InventoryItemPrefab.GetComponent <IItem>() : null;

                if (item != null)
                {
                    UITooltip.Text += "<size=12>";
                    UITooltip.Text += "<color=#" + item.Quality.ToColor().ToHexStringRGBA() + ">" + item.Name;
                    UITooltip.Text += "</color>";
                    UITooltip.Text += "</size>\n";
                    UITooltip.Text += "<color=yellow><size=7><i>";
                    UITooltip.Text += item.Description;
                    UITooltip.Text += "</i></size></color>\n\n";

                    if (weapon.WeaponRestrictions != WeaponRestriction.Both)
                    {
                        UITooltip.Text += "Only usable on " + (weapon.WeaponRestrictions == WeaponRestriction.MainHand ? "main hand." : "offhand.") + "\n";
                    }

                    UITooltip.Text += (weapon.WeaponHand == WeaponHand.OneHanded ? "One Handed " : "Two Handed ") + weapon.WeaponType.ToString() + "\n";

                    if (weapon is IPhysicalWeapon)
                    {
                        IPhysicalWeapon physWeap = weapon as IPhysicalWeapon;
                        UITooltip.Text += "Damages : " + physWeap.MinDamages + " - " + physWeap.MaxDamages + "\n";
                        UITooltip.Text += "Attack speed : " + physWeap.AttackSpeed + "\n";
                    }
                    else if (weapon is IMagicalWeapon)
                    {
                        UITooltip.Text += weapon.GetInventoryDescription() + "\n";
                    }
                    else if (weapon is IRangedWeapon)
                    {
                        IRangedWeapon rweap = weapon as IRangedWeapon;
                        UITooltip.Text += "Base damages : " + rweap.BaseDamages + " X" + rweap.ProjectilePerShot + "\n";
                        UITooltip.Text += "Consumed ammo per shot : " + rweap.ConsumedAmmoPerShot + "\n";
                        UITooltip.Text += "Projectile deviation : " + rweap.ProjectileDeviation + "\n";
                    }

                    if (weapon.GearStats != 0)
                    {
                        UITooltip.Text += "<color=green>";
                        if (weapon.GearStats.Strength != 0)
                        {
                            UITooltip.Text += "Strength +" + weapon.GearStats.Strength + "\n";
                        }
                        if (weapon.GearStats.Stamina != 0)
                        {
                            UITooltip.Text += "Stamina +" + weapon.GearStats.Stamina + "\n";
                        }
                        if (weapon.GearStats.Defense != 0)
                        {
                            UITooltip.Text += "Defense +" + weapon.GearStats.Defense + "\n";
                        }
                        if (weapon.GearStats.Energy != 0)
                        {
                            UITooltip.Text += "Energy +" + weapon.GearStats.Energy + "\n";
                        }
                        UITooltip.Text += "</color>";
                    }

                    UITooltip.Text += "<color=green><i>Right click to Unequip</i></color>";
                }
            }
            else if (ammo != null)
            {
                ItemAmmo item = ammo.ItemPrefab as ItemAmmo;
                UITooltip.Text += "<size=12>";
                UITooltip.Text += "<color=#" + item.Quality.ToColor().ToHexStringRGBA() + ">" + item.Name;
                UITooltip.Text += "</color>";
                UITooltip.Text += "</size>\n";
                UITooltip.Text += "<color=yellow><size=7><i>";
                UITooltip.Text += item.RealDescription;
                UITooltip.Text += "</i></size></color>\n\n";

                UITooltip.Text += "Added damages : " + ammo.AddedDamages + "\n";

                UITooltip.Text += "Ammo left : " + ammo.AmmoLeft + "\n";

                UITooltip.Text += "\n<color=green><i>Right click to Unequip</i></color>";
            }
            else
            {
                UITooltip.ForceHide();
            }
        }
    }
Esempio n. 8
0
    // Update is called once per frame
    void FixedUpdate()
    {
        pointerData = new PointerEventData(EventSystem.current)
        {
            position = Input.mousePosition
        };
        results.Clear();
        EventSystem.current.RaycastAll(pointerData, results);
        InventorySlot tempItem  = null;
        CraftingSlot  tempCraft = null;

        for (int i = 0; i < results.Count; i++)
        {
            if (results[i].gameObject.TryGetComponent(out tempItem))
            {
                break;
            }
            else if (results[i].gameObject.TryGetComponent(out tempCraft))
            {
                itemSlot = null;
                break;
            }
        }
        if ((tempCraft != null && recipeSlot != null && tempCraft.recipeID != recipeSlot.recipeID) ||
            tempCraft == null)
        {
            changed = true;
        }
        recipeSlot = tempCraft;
        if ((tempItem != null && tempItem.item != null && itemSlot != null && itemSlot.item != null && tempItem.item.id != itemSlot.item.id) ||
            tempItem == null || tempItem.item == null)
        {
            changed = true;
        }
        itemSlot = tempItem;



        if (itemSlot != null && itemSlot.item != null && changed)
        {
            tooltipPanel.SetActive(true);
            mainHeader.GetComponentInChildren <TextMeshProUGUI>().SetText(itemSlot.item.name);
            if (itemSlot.item.description != null && itemSlot.item.description != "")
            {
                description.SetActive(true);
                description.GetComponentInChildren <TextMeshProUGUI>().text = itemSlot.item.description;
            }
            else
            {
                description.SetActive(false);
            }
            //if the item is ammo or thrown list damage.
            ingredientsPanel.SetActive(false);
            resultsPanel.SetActive(false);
            craftingTime.SetActive(false);
            ItemAmmo itemAmmo = itemSlot.item as ItemAmmo;
            if (itemAmmo != null)
            {
                damageHeader.SetActive(true);
                damageDescriptionAmmo.SetActive(true);
                damageDescriptionAmmo.GetComponentInChildren <TextMeshProUGUI>().SetText(System.Enum.GetName(typeof(Health.DamageType), itemAmmo.damageType) + " Damage " + itemAmmo.damage +
                                                                                         "\nFiring Rate {0:1}/s", (50.0f / itemAmmo.firingRate));
            }
            else
            {
                damageHeader.SetActive(false);
                damageDescriptionAmmo.SetActive(false);
            }
            changed = false;
        }
        else if (recipeSlot != null && changed)
        {
            tooltipPanel.SetActive(true);
            Recipe recipe = Definitions.Instance.RecipeDictionaryIndexed[recipeSlot.recipeID];
            if (recipe.Results.Count > 1)
            {
                description.SetActive(false);
                damageHeader.SetActive(false);
                damageDescriptionAmmo.SetActive(false);
                resultsPanel.SetActive(true);
            }
            else
            {
                if (recipe.Results[0].item.description != null && recipe.Results[0].item.description != "")
                {
                    description.SetActive(true);
                    description.GetComponentInChildren <TextMeshProUGUI>().text = recipe.Results[0].item.description;
                }
                else
                {
                    description.SetActive(false);
                }
                resultsPanel.SetActive(false);
                ItemAmmo itemAmmo = recipe.Results[0].item as ItemAmmo;
                if (itemAmmo != null)
                {
                    damageHeader.SetActive(true);
                    damageDescriptionAmmo.SetActive(true);
                    damageDescriptionAmmo.GetComponentInChildren <TextMeshProUGUI>().SetText(System.Enum.GetName(typeof(Health.DamageType), itemAmmo.damageType) + " Damage " + itemAmmo.damage +
                                                                                             "\nFiring Rate {0:1}/s", (50.0f / itemAmmo.firingRate));
                }
                else
                {
                    damageHeader.SetActive(false);
                    damageDescriptionAmmo.SetActive(false);
                }
            }
            mainHeader.GetComponentInChildren <TextMeshProUGUI>().SetText(recipe.name);
            ingredientsPanel.SetActive(true);
            craftingTime.SetActive(true);
            craftingTime.GetComponentInChildren <TextMeshProUGUI>().SetText("{0:1}s Crafting Time", (recipe.craftingTime / 50.0f));

            for (int i = 0; i < ingredientsItemElements.Count; i++)
            {
                if (i < recipe.Ingredients.Count)
                {
                    if (ingredientsItemElements[i] == null)
                    {
                        ingredientsItemElements[i] = Instantiate(ingredientsItemPrefab, ingredientsPanel.transform, false);
                    }
                    ingredientsItemElements[i].SetActive(true);
                    ingredientsItemElements[i].transform.GetComponentInChildren <Image>().sprite = recipe.Ingredients[i].item.itemSprite;
                    ingredientsItemElements[i].transform.GetComponentInChildren <TextMeshProUGUI>().SetText("x " + recipe.Ingredients[i].Amount + " " + recipe.Ingredients[i].item.name);
                }
                else
                {
                    if (ingredientsItemElements[i] != null)
                    {
                        ingredientsItemElements[i].SetActive(false);
                    }
                }
            }

            if (recipe.Results.Count > 1)
            {
                for (int i = 0; i < resultsItemElements.Count; i++)
                {
                    if (i < recipe.Results.Count)
                    {
                        if (resultsItemElements[i] == null)
                        {
                            resultsItemElements[i] = Instantiate(ingredientsItemPrefab, resultsPanel.transform, false);
                        }
                        resultsItemElements[i].SetActive(true);
                        resultsItemElements[i].transform.GetComponentInChildren <Image>().sprite = recipe.Results[i].item.itemSprite;
                        resultsItemElements[i].transform.GetComponentInChildren <TextMeshProUGUI>().SetText("x " + recipe.Results[i].Amount + " " + recipe.Results[i].item.name);
                    }
                    else
                    {
                        if (resultsItemElements[i] != null)
                        {
                            resultsItemElements[i].SetActive(false);
                        }
                    }
                }
            }


            changed = false;
        }
        else if (changed == true)
        {
            tooltipPanel.SetActive(false);
            changed = false;
        }

        float   width    = tooltipPanelTransform.rect.width * canvas.scaleFactor;
        float   height   = tooltipPanelTransform.rect.height * canvas.scaleFactor;
        Vector3 position = Input.mousePosition;

        if (Input.mousePosition.x + width > Screen.width)
        {
            position.x -= width;
            position.x -= adjustXY;
        }
        else
        {
            position.x += adjustXY;
        }
        if (Input.mousePosition.y - height < 0)
        {
            position.y += height;
            position.y += adjustXY;
        }
        else
        {
            position.y -= adjustXY;
        }
        this.transform.position = position;
    }