示例#1
0
    private void Start()
    {
        driver = GetComponent <AnimationDriverBase>();

        if (startAmmo != null)
        {
            if (startAmmo is IRangedWeaponAmmo)
            {
                currentAmmos = ScriptableObject.Instantiate(startAmmo) as IRangedWeaponAmmo;
            }
            else
            {
                Debug.LogWarning("StartAmmo defined on " + this.name + " is not a IRangedWeaponAmmo.");
            }
        }

        if (debugMainHandStartWeaponPrefab != null && MainHandWeapon == null && saveLoaded == false)
        {
            MainHandWeapon = (GameObject.Instantiate(debugMainHandStartWeaponPrefab, Vector3.zero, debugMainHandStartWeaponPrefab.transform.rotation) as GameObject).GetComponent <IWeapon>();
        }

        if (debugOffHandStartWeaponPrefab != null && OffHandWeapon == null && saveLoaded == false)
        {
            OffHandWeapon = (GameObject.Instantiate(debugOffHandStartWeaponPrefab, Vector3.zero, debugOffHandStartWeaponPrefab.transform.rotation) as GameObject).GetComponent <IWeapon>();
        }
    }
示例#2
0
    public void Use(InteractManager user, UsableArgs args = null)
    {
        IRangedWeaponAmmo a  = ScriptableObject.Instantiate(ammo as ScriptableObject) as IRangedWeaponAmmo;
        WeaponManager     wp = user.GetComponentInChildren <WeaponManager>();

        wp.CurrentAmmos = a;

        if (ammoLeft >= 0)
        {
            a.AmmoLeft = ammoLeft;
        }

        user.gameObject.GetComponentInChildren <IContainer>().RemoveItem(this);
        Destroy(this.gameObject);
    }
示例#3
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();
            }
        }
    }
示例#4
0
    public void Load(SaveData data)
    {
        string origPrefix = data.Prefix; // save original Prefix before editing it

        if (MainHandWeapon != null)
        {
            Destroy((MainHandWeapon as Behaviour).gameObject);
            mainHandWeapon = null; // set the variable (not the property) to null to avoid transfering to inventory
        }

        if (OffHandWeapon != null)
        {
            Destroy((OffHandWeapon as Behaviour).gameObject);
            offHandWeapon = null; // set the variable (not the property) to null to avoid transfering to inventory
        }


        string mainHandPath = data.Get("mainWeapon_path");
        string offHandPath  = data.Get("offWeapon_path");

        if (mainHandPath != null)
        {
            GameObject prefab = Resources.Load <GameObject>(mainHandPath);
            if (prefab == null)
            {
                Debug.LogWarning("Loading Weapon MainHand : Failed to load \"" + mainHandPath + "\"");
            }
            else
            {
                GameObject instance = Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;

                MainHandWeapon = instance.GetComponent <IWeapon>();
            }
        }

        if (offHandPath != null)
        {
            GameObject prefab = Resources.Load <GameObject>(offHandPath);
            if (prefab == null)
            {
                Debug.LogWarning("Loading Weapon OffHand : Failed to load \"" + offHandPath + "\"");
            }
            else
            {
                GameObject instance = Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;

                OffHandWeapon = instance.GetComponent <IWeapon>();
            }
        }

        string ammoType = data.Get("ammos_type");

        if (ammoType != null)
        {
            Type type = Type.GetType(ammoType);

            IRangedWeaponAmmo ammo;

            if (type.BaseType == typeof(ScriptableObject)) // need to call CreateInstance from ScriptableObject
            {
                ammo = (IRangedWeaponAmmo)ScriptableObject.CreateInstance(type);
            }
            else
            {
                ammo = (IRangedWeaponAmmo)Activator.CreateInstance(type);
            }

            data.Prefix = origPrefix + "ammos_";
            ammo.Load(data);

            CurrentAmmos = ammo;
        }

        saveLoaded = true;
    }
示例#5
0
 private void OnOutOfAmmoCallback(object sender, EventArgs args)
 {
     currentAmmos = null;
 }