Beispiel #1
0
        public override void OnClose()
        {
            // Unequp old weapons.
            for (int i = 0; i < Inventory.NumEquipSlots; i++)
            {
                ItemWeapon weapon = oldEquippedWeapons[i];
                if (weapon != null && !GameControl.Inventory.IsWeaponEquipped(weapon))
                {
                    weapon.Unequip();
                    if (weapon.IsTwoHanded)
                    {
                        break;
                    }
                }
            }

            // Equip new weapons.
            for (int i = 0; i < Inventory.NumEquipSlots; i++)
            {
                ItemWeapon weapon = GameControl.Inventory.EquippedWeapons[i];
                if (weapon != null)
                {
                    weapon.Equip(i);
                    if (weapon.IsTwoHanded)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Provides an entity's total modified attack rating for a particular weapon
        /// </summary>
        /// <param name="entity">The entity to calculate from</param>
        /// <param name="weapon">The weapon to use when calculating rating</param>
        /// <returns>The total attack rating modified by associated skills</returns>
        /// <remarks>If this is an unarmed attack with no unarmed weapons, provide 'null' for the weapon.
        /// Dual Wielding and Two Handed will presently not be included in modifying the attack rating.
        /// The skill rating is reduced by a factor of 4 before improving attack rating.</remarks>
        /// TODO: This could probably be refactored by putting calculated code inside the entity's ModifiedQualities.AttackRating property.
        public static int GetEntityAttackRatingFor(EntityAnimate entity, ItemWeapon weapon)
        {
            if (entity == null)
            {
                return(GetEntityAttackRating(entity));
            }

            int    baseAttackRating = GetEntityAttackRating(entity);
            double skill;

            if (weapon == null)
            {
                skill = SkillHelper.SkillOfWeapon(entity, WeaponType.Unarmed);
            }
            else
            {
                skill = SkillHelper.SkillOfWeapon(entity, weapon.WeaponType);
            }

            if (skill < 0)
            {
                skill = 0;
            }

            return(baseAttackRating + (int)(skill / 4));
        }
Beispiel #3
0
    void IStrikeable.Strike(Vector2 weaponLocation, ItemWeapon weapon)
    {
        SetMotionState(MoveState.HIT);
        Vector2 knockbackDirection = ((Vector2)this.transform.position - weaponLocation).normalized;

        rb.AddForce(knockbackDirection * 1000f);
    }
    //given an itemWeapon instance, equips the appropriate
    //weapon model and texture
    public override void equipWeapon(ItemWeapon newWeapon)
    {
        if (newWeapon == null) { return; }

        base.equipWeapon(newWeapon);
        wepSwitcher.SwitchWeapon(newWeapon.weaponType, newWeapon.oreType);
    }
Beispiel #5
0
    public void HoverItemInfo(Item info)
    {
        ClearHover();

        item_name.text   = info.name;
        item_icon.sprite = info.image;
        item_desc.text   = info.desc;
        item_stat1.text  = "Weight: " + (info.weight * info.quantity).ToString("F2") + " kg";

        if (info.stackable)
        {
            item_statA.text = "" + info.quantity;
        }


        if (info is ItemWeapon)
        {
            ItemWeapon weapon = (ItemWeapon)info;
            item_statA.text = weapon.bulletsLeft + " / " + weapon.capacity;
            item_stat2.text = "Caliber: " + ConvertAmmoTypeToString(weapon.ammoUsed.ammo);
            item_stat3.text = "Power: " + weapon.power;
            item_stat4.text = "Accuracy Bonus: " + weapon.accuracy + "%";
            item_stat5.text = "Velocity: " + weapon.velocity + "m/s";
        }
    }
    void IStrikeable.Strike(Vector2 weaponLocation, ItemWeapon weapon)
    {
        // Debug.Log("Smap");
        base.TakeDamage(1f);

        // Hitting big boi does not affect his state.
    }
Beispiel #7
0
        private void EquipWeapon(int slot)
        {
            ItemWeapon weapon = slotGroups[0].CurrentSlot.SlotItem as ItemWeapon;

            AudioSystem.PlaySound(GameData.SOUND_MENU_SELECT);

            if (GameControl.Inventory.EquippedWeapons[slot] != null)
            {
                if (GameControl.Inventory.EquippedWeapons[slot].IsTwoHanded)
                {
                    GameControl.Inventory.EquippedWeapons[1 - slot] = null;
                }

                ItemWeapon placeholder = GameControl.Inventory.EquippedWeapons[slot];
                GameControl.Inventory.EquippedWeapons[slot] = weapon;

                slotGroups[0].CurrentSlot.SlotItem = placeholder;
            }
            else
            {
                GameControl.Inventory.EquippedWeapons[slot] = weapon;
                slotGroups[0].CurrentSlot.SlotItem          = null;
            }

            if (weapon != null && weapon.IsTwoHanded)
            {
                if (GameControl.Inventory.EquippedWeapons[1 - slot] != null)
                {
                    NextAvailableSlot.SlotItem = GameControl.Inventory.EquippedWeapons[1 - slot];
                }
                GameControl.Inventory.EquippedWeapons[1 - slot] = weapon;
            }

            ResetDescription();
        }
Beispiel #8
0
    public void ChangeWeapon(Weapon nextWeapon)
    {
        Weapon pre;

        if (currWeapon.isCloseInWeapon == nextWeapon.isCloseInWeapon)
        {
            ChangeWeaponWhenBackUp(currWeapon, nextWeapon);
        }
        else
        {
            WeaponBackUp(nextWeapon);
        }

        if (nextWeapon.isCloseInWeapon)
        {
            pre           = closeinWeapon;
            closeinWeapon = nextWeapon;
        }
        else
        {
            pre          = rangedWeapon;
            rangedWeapon = nextWeapon;
        }

        AudioManager.Instance.PlaySound("Voices/RetroWeaponReloadBestA03");
        ItemWeapon itemWeapon = Instantiate((GameObject)Resources.Load("Item/WeaponItem"), transform.parent.position + transform.right, Quaternion.identity).GetComponentInChildren <ItemWeapon>();

        itemWeapon.ConfigWeapon(pre);
    }
Beispiel #9
0
        //-----------------------------------------------------------------------------
        // Constructors & Setup
        //-----------------------------------------------------------------------------

        public PlayerSwingState()
        {
            weapon       = null;
            timedActions = new Dictionary <int, Action>();

            InitStandardSwing(GameData.ANIM_SWORD_SWING, GameData.ANIM_SWORD_MINECART_SWING);
        }
Beispiel #10
0
 public void Use(ItemWeapon weapon)
 {
     Damage = new Damage
     {
         Strength = weapon.Strength
     };
 }
Beispiel #11
0
    public void SetData(int damage, WeaponType wt, List <int> weaponEffects, int id, string name, ItemQuality quality, ItemType type, string description, int amount, int capacity, int buyprice, int sellprice)
    {
        ItemWeapon dataTmp = new ItemWeapon();

        dataTmp.SetData(damage, wt, weaponEffects, id, name, quality, type, description, amount, capacity, buyprice, sellprice);
        data = dataTmp;
    }
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------

        public PlayerHoldSwordState()
        {
            weaponAnimation = GameData.ANIM_SWORD_HOLD;
            nextState       = null;
            weapon          = null;
            chargeTimer     = 0;
            direction       = Directions.Right;
            playerTool      = null;
        }
Beispiel #13
0
    /// <summary>
    /// Adds an Item to your Inventory.
    /// </summary>
    /// <param name="_ListOfItems"></param>
    /// <param name="_ItemID"></param>
    public void AddItem(List <Item> _ListOfItems, int _ItemID, int _AmountOfItemsToAdd)
    {
        // If the List we are peeking into is the List for Food...
        if (_ListOfItems == m_ItemManager.ItemsFood)
        {
            // Look at each of the Items within the List
            foreach (Item item in m_ItemManager.ItemsFood)
            {
                // Create a temporary Item to look for the ID
                ItemFood tmp = (ItemFood)item;

                // If the items ID matches the Id of the searched Item...
                if (tmp.m_FoodID == _ItemID)
                {
                    AddItemToSlot(ChangeSlotToAdd(tmp), tmp, _AmountOfItemsToAdd);
                    break;
                }
            }
        }

        // If the List we are peeking into is the List for Armor...
        if (_ListOfItems == m_ItemManager.ItemsArmor)
        {
            // Look at each of the Items within the List
            foreach (Item item in m_ItemManager.ItemsArmor)
            {
                // Create a temporary Item to look for the ID
                ItemArmor tmp = (ItemArmor)item;

                // If the items ID matches the Id of the searched Item...
                if (tmp.m_ArmorID == _ItemID)
                {
                    AddItemToSlot(ChangeSlotToAdd(tmp), tmp, _AmountOfItemsToAdd);
                    break;
                }
            }
        }

        // If the List we are peeking into is the List for Weapons...
        if (_ListOfItems == m_ItemManager.ItemsWeapon)
        {
            // Look at each of the Items within the List
            foreach (Item item in m_ItemManager.ItemsWeapon)
            {
                // Create a temporary Item to look for the ID
                ItemWeapon tmp = (ItemWeapon)item;

                // If the items ID matches the Id of the searched Item...
                if (tmp.m_WeaponID == _ItemID)
                {
                    AddItemToSlot(ChangeSlotToAdd(tmp), tmp, _AmountOfItemsToAdd);
                    break;
                }
            }
        }
    }
Beispiel #14
0
 private void SetStatsForWeaponItem(ItemWeapon itemWeapon)
 {
     AddAttackSpeedStat(itemWeapon.attackSpeed);
     AddDamageStat(itemWeapon.minDamage, itemWeapon.maxDamage, itemWeapon.equipmentSlot);
     AddStat(itemWeapon.magicDamage, StatType.StatUp, "Magic damage");
     AddStat(itemWeapon.requiredLevel, StatType.RequiredLevel);
     AddStat(itemWeapon.requiredStrength, StatType.RequiredSkill, "strength");
     AddStat(itemWeapon.requiredDexterity, StatType.RequiredSkill, "dexterity");
     AddStat(itemWeapon.requiredMagic, StatType.RequiredSkill, "magic");
 }
Beispiel #15
0
        // Called when the player hits this tile with the sword.
        public virtual void OnSwordHit(ItemWeapon swordItem)
        {
            int minLevel = properties.GetInteger("cuttable_sword_level", Item.Level1);

            if (!isMoving && flags.HasFlag(TileFlags.Cuttable) &&
                (!(swordItem is ItemSword) || swordItem.Level >= minLevel))
            {
                Break(true);
            }
        }
Beispiel #16
0
    void IStrikeable.Strike(Vector2 weaponLocation, ItemWeapon weapon)
    {
        // Debug.Log("Smap");
        base.TakeDamage(0f);
        SetMotionState(MoveState.HIT);

        // Effects for getting hit here
        // E.g. simple Physics2D knockback based on the position of the weapon
        // Vector2 knockbackDirection = (this.transform.position - weaponLocation).normalized;
        // rb.AddForce(knockbackDirection * 1000f);
    }
Beispiel #17
0
        public IItemWeapon AddItemWeapon(Guid guid, ItemWeaponBlueprint blueprint, IContainer container)
        {
            if (blueprint == null)
            {
                throw new ArgumentNullException(nameof(blueprint));
            }
            IItemWeapon item = new ItemWeapon(guid, blueprint, container);

            _items.Add(item);
            return(item);
        }
    void IStrikeable.Strike(Vector2 weaponLocation, ItemWeapon weapon)
    {
        base.TakeDamage(1f);
        SetMotionState(MoveState.HIT);

        // Effects for getting hit here
        // Project vector from weapon to us onto the X axis and normalize to decide direction (left or right)
        float knockbackX = ((Vector2)this.transform.position - weaponLocation).normalized.x;

        rb.velocity = new Vector2(knockbackX * SELF_KNOCKBACK_VELOCITY, rb.velocity.y);
    }
Beispiel #19
0
    /// <summary>
    /// 解析武器
    /// </summary>
    private void ParseWeapon()
    {
        var jsonData = SerializeTool.JsonDeserialize(Contract.Instance.weaponDataPath);

        for (int i = 0; i < jsonData.Count; i++)
        {
            var weaponData = new ItemWeapon();
            weaponData.SetBaseData(jsonData[i]);
            allItems.Add(weaponData.id, weaponData);//向物品管理器中添加该数据
        }
    }
 public void SetWeapon(ItemWeapon weapon)
 {
     if (Weapon != null)
     {
         Weapon.Deactivate();
     }
     Weapon = weapon;
     if (onSetWeapon != null)
     {
         onSetWeapon(weapon);
     }
 }
Beispiel #21
0
    void IStrikeable.Strike(Vector2 weaponLocation, ItemWeapon weapon)
    {
        base.TakeDamage(1f);
        SetMotionState(MoveState.HIT);

        // Effects for getting hit here
        // Project vector from weapon to us onto the X axis and normalize to decide direction (left or right)
        Vector2 knockback = ((Vector2)this.transform.position - weaponLocation).normalized;

        rb.AddForce(knockback * 1000f);
        // rb.velocity = knockback;
    }
 // Use this for initialization
 void Start()
 {
     spawnPos = transform.position;
     Weapon = new ItemWeapon(BattleCore.elements.Fire , 1);
     isReadByBoss = false;
     killTime = TIME;
     if(this.gameObject.layer == 10){
         maxRange = 30;
         speed = 30;
     }
     else
         maxRange = 10;
 }
Beispiel #23
0
    void SetWeapon(int index)
    {
        if (weapon != null)
        {
            weapon.Unequip();
            IC.PushItem(weapon);
        }
        var i = IC.PopItem(index);

        weapon = (ItemWeapon)i;


        weapon.Equip();
        OnRefreshWeapon.Invoke(weapon);
    }
Beispiel #24
0
    public void Info(Vector3 lineDir, ItemWeapon weapon)
    {
        GameObject line = Instantiate(weapon.trace, transform.position, transform.rotation);

        line.transform.forward = lineDir;
        line.GetComponent <Trace>().Info(weapon.velocity / Formulas.VELOCITY_SCALER);
        RaycastHit hit;
        float      realDistance = 0;

        if (Physics.Raycast(transform.position, lineDir, out hit))
        {
            realDistance = Formulas.Distance(transform, hit.transform);
        }
        StartCoroutine(Delay(lineDir, realDistance, weapon, line));
    }
Beispiel #25
0
        //-----------------------------------------------------------------------------
        // Items
        //-----------------------------------------------------------------------------

        public void InterruptItems()
        {
            for (int i = 0; i < EquippedUsableItems.Length; i++)
            {
                ItemWeapon item = EquippedUsableItems[i];
                if (item != null)
                {
                    item.Interrupt();
                    if (item.IsTwoHanded)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #26
0
        public void SetActiveWeapon(ItemWeapon weapon)
        {
            // deactivate old weapon
            if (Weapon != null)
            {
                Weapon.Deactivate();
            }
            // equip new weapon
            Weapon = weapon;
            if (onSetWeapon != null)
            {
                onSetWeapon(weapon);
            }

            UI.UIController.Instance.systemMessageScreen.ShowSystemMessage("You equipped " + weapon.Name, weapon.Icon);
        }
    // TODO: Make this more memory efficient? Save references to weapons and activate/deactivate them
    public void SetWeapon(ItemWeapon weaponItem)
    {
        if (weaponObject)
        {
            Destroy(weaponObject);
        }
        if (weaponItem == null)
        {
            return;
        }

        weaponObject = Instantiate(weaponItem.inGamePrefab, transform) as GameObject;
        weaponObject.transform.localPosition = Vector3.zero;

        weapon = weaponItem;
    }
Beispiel #28
0
    public static float ChanceToHit(Stats attacker, Transform defenderPart)
    {
        float      distance = Distance(attacker.shootPoint.transform, defenderPart);
        ItemWeapon weapon   = attacker.weapon;
        part       bodyPart = defenderPart.GetComponent <BodyPart>().bodyPart;
        Stats      defender = defenderPart.GetComponent <BodyPart>().owner;

        float modeP  = attacker.accuracyModePenalty;
        float stateB = attacker.accuracyStateBonus;
        float stateP = defender.defenseStateBonus;


        //STEP 1: out of range
        if ((weapon.effectiveRange / RANGE_SCALER) * 10 < distance)
        {
            return(0);
        }

        //STEP 2: formula
        float chanceToHit;

        chanceToHit = (attacker.accuracy * 4 * ((float)weapon.accuracy / 100 + 1) / (distance / 7)) * modeP * stateB * stateP;

        //STEP 3: 1/2 cth if out of effectiveRange
        if (weapon.effectiveRange / RANGE_SCALER < distance)
        {
            chanceToHit /= 2;
        }

        //STEP 4: 1/2 cth if head
        if (bodyPart == part.head)
        {
            chanceToHit /= 2;
        }

        //STEP 5: minor window for miss if cth < 200
        if (chanceToHit > 200)
        {
            chanceToHit = 100;
        }
        else if (chanceToHit > 95)
        {
            chanceToHit = 95;
        }

        return(chanceToHit);
    }
Beispiel #29
0
        public RoomClosed(int x, int y) : base(x, y)
        {
            double random = CustomMath.RandomUnit();

            if (CustomMath.RandomUnit() < 1 / 3d)
            {
                ene = new Enemigo(Enemigo.eneList[CustomMath.RandomIntNumber(Enemigo.eneList.Length - 1)], (int)Math.Pow(Program.GetLevel() + 1, 1.4));
                ene.SetName("Super " + ene.GetName());
                if (random < 0.5)
                {
                    item[0] = new ItemWeapon("Espada legendaria", CustomMath.RandomIntNumber(5, 3) + Program.level, 20, CustomMath.RandomIntNumber(5, 3) + Program.level);
                }
                else
                {
                    item[0] = new ItemWeapon("Espada de espadas", (CustomMath.RandomIntNumber(3, 0) + Program.level) * 2, -10);
                }
            }
            else
            {
                if (CustomMath.RandomUnit() < 0.25)
                {
                    ene = new Enemigo(Enemigo.eneList[CustomMath.RandomIntNumber(Enemigo.eneList.Length - 1)], Program.GetLevel());
                }
                if (random < 0.05)
                {
                    item[0] = new ItemWeapon("Espada legendaria", CustomMath.RandomIntNumber(5, 3) + Program.level, 20, CustomMath.RandomIntNumber(5, 3) + Program.level);
                }
                else if (random < 0.3)
                {
                    item[0] = new ItemWeapon("Espada buena", CustomMath.RandomIntNumber(3, 0) + Program.level, 20);
                }
                else if (random < 0.675)
                {
                    item[0] = new ItemWeapon("Espada normal", (CustomMath.RandomIntNumber(3, 0) + Program.level) / 2, 10);
                }
                else if (random < 0.95)
                {
                    item[0] = new ItemWeapon("Baston Mágico", (CustomMath.RandomIntNumber(2, 0) + Program.level) / 3, 10, CustomMath.RandomIntNumber(1 + Program.level, 1 + Program.level / 2));
                }
                else
                {
                    item[0] = new ItemWeapon("Espada podrida", 1, 0);
                }
            }
        }
Beispiel #30
0
    public Item GetItemByName(List <Item> _ListOFItems, string _ItemName)
    {
        if (_ListOFItems == m_ItemManager.ItemsFood)
        {
            foreach (Item item in m_ItemManager.ItemsFood)
            {
                ItemFood tmp = (ItemFood)item;

                if (tmp.m_IName == _ItemName)
                {
                    return(item);
                }
            }
        }

        if (_ListOFItems == m_ItemManager.ItemsArmor)
        {
            foreach (Item item in m_ItemManager.ItemsArmor)
            {
                ItemArmor tmp = (ItemArmor)item;

                if (tmp.m_IName == _ItemName)
                {
                    return(item);
                }
            }
        }

        if (_ListOFItems == m_ItemManager.ItemsWeapon)
        {
            foreach (Item item in m_ItemManager.ItemsWeapon)
            {
                ItemWeapon tmp = (ItemWeapon)item;

                if (tmp.m_IName == _ItemName)
                {
                    return(item);
                }
            }
        }

        // If there is no item found...
        return(null);
    }
Beispiel #31
0
    // GetItemByIndex(ItemManager.ItemsFood, 1) == Apfel

    public Item GetItemByIndex(List <Item> _ListOFItems, int _Index)
    {
        if (_ListOFItems == m_ItemManager.ItemsFood)
        {
            foreach (Item item in m_ItemManager.ItemsFood)
            {
                ItemFood tmp = (ItemFood)item;

                if (tmp.m_FoodID == _Index)
                {
                    return(item);
                }
            }
        }

        if (_ListOFItems == m_ItemManager.ItemsArmor)
        {
            foreach (Item item in m_ItemManager.ItemsArmor)
            {
                ItemArmor tmp = (ItemArmor)item;

                if (tmp.m_ArmorID == _Index)
                {
                    return(item);
                }
            }
        }

        if (_ListOFItems == m_ItemManager.ItemsWeapon)
        {
            foreach (Item item in m_ItemManager.ItemsWeapon)
            {
                ItemWeapon tmp = (ItemWeapon)item;

                if (tmp.m_WeaponID == _Index)
                {
                    return(item);
                }
            }
        }

        // If there is no item found...
        return(null);
    }
Beispiel #32
0
    private void RemoveItem(List <Item> _ListOfItems, int _ItemID, int _AmountOfItemsToRemove)
    {
        if (_ListOfItems == m_ItemManager.ItemsFood)
        {
            foreach (Item item in _ListOfItems)
            {
                ItemFood tmp = (ItemFood)item;

                if (tmp.m_FoodID == _ItemID)
                {
                    RemoveItemFromSlot(ChangeSlotToRemove(tmp), tmp, _AmountOfItemsToRemove);
                    break;
                }
            }
        }

        if (_ListOfItems == m_ItemManager.ItemsArmor)
        {
            foreach (Item item in _ListOfItems)
            {
                ItemArmor tmp = (ItemArmor)item;

                if (tmp.m_ArmorID == _ItemID)
                {
                    RemoveItemFromSlot(ChangeSlotToRemove(tmp), tmp, _AmountOfItemsToRemove);
                    break;
                }
            }
        }

        if (_ListOfItems == m_ItemManager.ItemsWeapon)
        {
            foreach (Item item in _ListOfItems)
            {
                ItemWeapon tmp = (ItemWeapon)item;

                if (tmp.m_WeaponID == _ItemID)
                {
                    RemoveItemFromSlot(ChangeSlotToRemove(tmp), tmp, _AmountOfItemsToRemove);
                    break;
                }
            }
        }
    }
	public Collider myTriggerCol {get; private set;} // What kind of collider is being used.

	void Awake()
	{
		if(gameObject.tag != "Item")
		{
			Attacker = transform.root;
			CharStatus = Attacker.GetComponent<CharacterStatus> ();
			CharAttacking = Attacker.GetComponent<CharacterAttacking>();
			_myRigidbody = Attacker.GetComponent<Rigidbody>();
			myTriggerCol = GetComponent<Collider>();
			Anim = transform.root.GetComponent<Animator> ();
		}
		else // Must be a weapon. _attacker will get set by the user.
		{
			myTriggerCol = gameObject.GetComponent<CapsuleCollider>() as CapsuleCollider;
			_itemWeapon = GetComponent<ItemWeapon>();
		}
		if(gameObject.tag == "GrabHitbox")
			_isGrabBox = true;
		charactersHit = new List<GameObject> ();
	}
Beispiel #34
0
    // Use this for initialization
    private Inventory()
    {
        weapons = new List<ItemWeapon>();
        armors = new ArrayList();
        components = new ArrayList();
        items = new ArrayList();
        ores = new Dictionary<int, int>();

        equipedWeapon = null;
        equipedHelmet = null;
        equipedChest = null;
        equipedLegs = null;

        List<ItemBase.tOreType> exludedOres = ItemBase.getNonCraftingOres();
        foreach (ItemBase.tOreType oreType in Enum.GetValues(typeof(ItemBase.tOreType)))
        {
            if (exludedOres.Contains(oreType))
                continue;

            //Create all the ores beforehand w/ quantity=0
            ores[(int)oreType] = 0;
        }
    }
    //given a newWeapon type and an oreType, swaps the weapon model to the appropriate
    //model and texture
    public void SwitchWeapon(ItemWeapon.tWeaponType newWeapon, ItemWeapon.tOreType oreType)
    {
        sword.SetActive(false);
        pickaxe.SetActive(false);
        staff.SetActive(false);
        wrench.SetActive(false);
        bow.SetActive(false);
        key.SetActive(false);

        //switch model to the model used for new weapon type.
        switch(newWeapon)
        {
            case ItemWeapon.tWeaponType.WeaponBow:
                bow.SetActive(true);
                Active = bow;

            break;
            case ItemWeapon.tWeaponType.WeaponKey:
                key.SetActive(true);
                Active = key;
            break;
            case ItemWeapon.tWeaponType.WeaponPickaxe:
                pickaxe.SetActive(true);
                Active = pickaxe;
            break;
            case ItemWeapon.tWeaponType.WeaponStaff:
                staff.SetActive(true);
                Active = staff;
            break;
            case ItemWeapon.tWeaponType.WeaponSword:
                sword.SetActive(true);
                Active = sword;
            break;
            case ItemWeapon.tWeaponType.WeaponToolbox:
                wrench.SetActive(true);
                Active = wrench;
            break;
            default:
                Active = null;
            break;

        }

        //apply the texture.
        if (newWeapon != ItemWeapon.tWeaponType.WeaponStaff)
        {
            ItemTextureSwitcher texSwitcher;
            texSwitcher = Active.GetComponent<ItemTextureSwitcher>();
            texSwitcher.SwitchTexture(oreType);

            if (newWeapon == ItemWeapon.tWeaponType.WeaponBow)
            {
                WeaponBowFiringScript s = bow.GetComponent<WeaponBowFiringScript>();
                PlayerStaffTextureSwitcher arrowTexSwitcher = s.arrowModel.GetComponent<PlayerStaffTextureSwitcher>();
                arrowTexSwitcher.SwitchTexture(oreType);
            }

        }
        else
        {
            PlayerStaffTextureSwitcher texSwitcher;
            texSwitcher = Active.GetComponent<PlayerStaffTextureSwitcher>();
            texSwitcher.SwitchTexture(oreType);
        }
    }
Beispiel #36
0
    // Use this for initialization
    public virtual void Start()
    {
        controller = GetComponent<CharacterController>();

        if (!controller)
        {
            Debug.LogError("Unit.Start() " + name + "has no character controller.");
            enabled = false;
        }
        // Load Resources

        // Initialize Data
        _CurHP = MaxHP;
        Weapon = new ItemWeapon(BattleCore.elements.None,1,1f);
        Armour = new ItemArmour(BattleCore.elements.None,0);
        targetForward = this.transform.forward;
    }
 public static string generateComponentCode(tAttributeType att, tOreType ore, ItemWeapon.tWeaponType wep, tComponentPart part)
 {
     return "" + (int)att + (int)ore + (int)wep + (int)part;
 }
Beispiel #38
0
 public void hurt(ItemWeapon weapon)
 {
     if (!dead && canBeHit){
         if(AnimControl.EnemyState == AIStates.states.Attack && this.tag == "Bear" ||
            AnimControl.EnemyState == AIStates.states.Attack && this.tag == "Bat" ||
            AnimControl.EnemyState == AIStates.states.Attack && this.tag == "Hover" ||
            AnimControl.EnemyState == AIStates.states.Attack && this.tag == "Sword" ||
             AnimControl.EnemyState == AIStates.states.Attack && this.tag == "MechBoss" ||
             AnimControl.EnemyState == AIStates.states.Attack && this.tag == "CaptainBoss" ||
             AnimControl.EnemyState == AIStates.states.Attack && this.tag == "Queen"
            ){}else{
                 AnimControl.EnemyState = AIStates.states.Hit;
                 if(this.tag != "Sword" || this.tag != "Wolf")
                     animation.Play("Hit");
                 canMove = false;
                 canSearch = false;
         }
         int damage = BattleCore.CalculateDamage(weapon.BaseDamage,weapon.Element,BaseArmour,Element);
         CurHP -= damage;
         canBeHit = false;
         if (CurHP == 0){
             GameObject.Find("CameraSelf").GetComponentInChildren<script_HUD>().StartCoroutine("bunnyGuage");
             Die();
         }else{
             StartCoroutine("resetHit");
         }
     }
 }
Beispiel #39
0
    /// <summary>
    /// Add an item to the inventory.
    /// </summary>
    /// <param name="newItem">ItemWeapon</param>
    public void inventoryAddItem(ItemWeapon newItem)
    {
        if (newItem == null)
            return;

        weapons.Add((ItemWeapon)newItem);
    }
Beispiel #40
0
    //generic to equip any itemEquipment. will replace it in the appropriate spot.
    public void inventoryEquipItem(ItemEquipment itemToEquip)
    {
        //equip items if applicaple.
        if(itemToEquip is ItemWeapon)
        {
            equipedWeapon = (ItemWeapon)itemToEquip;
        }
        else if(itemToEquip is ItemArmor)
        {
            ItemArmor armorToEquip = itemToEquip as ItemArmor;
            switch (armorToEquip.armorPart)
            {
                case ItemArmor.tArmorPart.Chest:
                    equipedChest = armorToEquip;
                break;
                case ItemArmor.tArmorPart.Head:
                    equipedHelmet = armorToEquip;
                break;
                case ItemArmor.tArmorPart.Legs:
                    equipedLegs = armorToEquip;
                break;
            }
        }
        else
        {
            return; //change nothing if it was not equipable equipment....
        }

        calculateAndApplyStats();
    }
Beispiel #41
0
    //destroys the old instance of the weapon script
    //and adds a new weapon script to the unit
    public virtual void equipWeapon(ItemWeapon newWeapon)
    {
        GameObject.Destroy(weapon);

        if (newWeapon != null)
        {
            weapon = (WeaponBase) gameObject.AddComponent("" + newWeapon.weaponType);//weaponType enum name will match weapon script name
        }
        else
        {
            weapon = null;
        }
    }
 public static string getComponentCategoryCode(ItemWeapon.tWeaponType wep, tComponentPart part)
 {
     return "" + (int)wep + (int)part;
 }
Beispiel #43
0
 /// <summary>
 /// Gets the index of the specified weapon in the inventory.
 /// </summary>
 /// <returns>The inventory weapon index.</returns>
 /// <param name="name">Name.</param>
 public int getInventoryWeaponIndex(ItemWeapon itemToFind)
 {
     return weapons.IndexOf(itemToFind);
 }
Beispiel #44
0
    public void Init(string file)
    {
        TextAsset textAsset = (TextAsset) Resources.Load(file);
        if (!textAsset) Debug.Log("failed to load xml resource");
        var doc = new XmlDocument();

        doc.LoadXml (textAsset.text);

        //parse the item definition XML file
        XmlNodeList root = doc.SelectNodes ("items/item");
        foreach (XmlNode node in root) {
            BaseItem temp;
            if (node.Attributes.GetNamedItem("type").Value=="weapon")
                temp = new ItemWeapon();
            else if (node.Attributes.GetNamedItem("type").Value=="potion")
                temp = new ItemPotion();
            else
                temp = new BaseItem();

            temp.Name = node.Attributes.GetNamedItem("name").Value;
            temp.Desc = node.Attributes.GetNamedItem("description").Value;
            temp.type = node.Attributes.GetNamedItem("type").Value;

            temp.range = float.Parse(node.Attributes.GetNamedItem("range").Value);
            temp.prefab = node.Attributes.GetNamedItem("prefab").Value;
            temp.portrait = node.Attributes.GetNamedItem("portrait").Value;
            temp.weight = int.Parse(node.Attributes.GetNamedItem("weight").Value);
            //temp.speed = int.Parse(node.Attributes.GetNamedItem("speed").Value);
            temp.ParentSkill = node.Attributes.GetNamedItem("skill").Value;
            var slot = node.Attributes.GetNamedItem("slot").Value;
            if(slot=="weapon")
                temp.slot = ItemSlot.Weapon;
            else if (slot=="shield")
                temp.slot = ItemSlot.Shield;
            else if  (slot=="chest")
                temp.slot = ItemSlot.Chest;
            else if (slot=="legs")
                temp.slot = ItemSlot.Legs;
            temp.attach = node.Attributes.GetNamedItem("bone").Value;
            string[] vals;
            vals = node.Attributes.GetNamedItem("offset").Value.Split(' ');
            float.TryParse(vals[0], out temp.offset.x);
            float.TryParse(vals[1], out temp.offset.y );
            float.TryParse(vals[2], out temp.offset.z);
            vals = node.Attributes.GetNamedItem("rotation").Value.Split(' ');
            float.TryParse(vals[0], out temp.rot.x);
            float.TryParse(vals[1], out temp.rot.y);
            float.TryParse(vals[2], out temp.rot.z);
            vals = node.Attributes.GetNamedItem("scale").Value.Split(' ');
            float.TryParse(vals[0], out temp.scale.x);
            float.TryParse(vals[1], out temp.scale.y);
            float.TryParse(vals[2], out temp.scale.z);
            XmlNodeList properties = node.ChildNodes;
            foreach (XmlNode pn in properties) {
                var p = new Property();
                p.name = pn.Attributes.GetNamedItem("name").Value;
                p.type = pn.Attributes.GetNamedItem("type").Value;
                p.value = float.Parse(pn.Attributes.GetNamedItem("value").Value);
                temp.props.Add(p);
            }
            ItemDefs.Add(node.Attributes.GetNamedItem("id").Value, temp);
        }
    }
Beispiel #45
0
 public void hurt(ItemWeapon weapon)
 {
     // When player get hurt
     if (!invinsible){
         int BaseAttack = weapon.BaseDamage;
         BattleCore.elements Ele = weapon.Element;
         //PopoutNum pop = PopoutNum.Get();
         int Damage = BattleCore.CalculateDamage(BaseAttack,Ele,this.Armour.BaseArmour,this.Armour.Element);
         /*if (pop != null){
             pop.popupText(this.transform.position,Damage, (int)Ele);
         }*/
         CurHP-= Damage;
         transparency = 0.5f;
         if (CurHP == 0){
             // Death
             GameManager.GameOver();
             CameraController.Get().fadeIn = false;
             CameraController.Get().fadeOut = true;
             GameManager.isPaused = true;
             dead = true;
         }else{
             invinsible = true;
             StartCoroutine("invinsiTime");
         }
     }
 }
Beispiel #46
0
 //can be called with null to un-equip the item
 public void inventoryEquipWeapon(ItemWeapon newWeapon)
 {
     equipedWeapon = newWeapon;
     calculateAndApplyStats();
 }
    public static string getWeaponTypeName(ItemWeapon.tWeaponType wep)
    {
        string strName = "";

        switch(wep)
        {
            case ItemWeapon.tWeaponType.WeaponBow:
                strName += "Bow ";
                break;
            case ItemWeapon.tWeaponType.WeaponSword:
                strName += "Sword ";
                break;
            case ItemWeapon.tWeaponType.WeaponStaff:
                strName += "Staff ";
                break;
            case ItemWeapon.tWeaponType.WeaponToolbox:
                strName += "Toolbox ";
                break;
            case ItemWeapon.tWeaponType.WeaponPickaxe:
                strName += "Pickaxe ";
                break;
            case ItemWeapon.tWeaponType.WeaponKey:
                strName += "Pickaxe ";
                break;
        }

        return strName;
    }
    /// <summary>
    /// The initializer for this object.
    /// </summary>
    protected override void Start()
    {
        //Grab the weapon switcher
        wepSwitcher = gameObject.GetComponentInChildren<WeaponModelSwitcher>();

        //Grab an instance of the inventory
        inventory = Inventory.getInstance();

        //Add the default weapons
        ItemEquipment myFirstPickaxe = new ItemWeapon(1, 1.0f, 0, 0, 0.0f, "Rusty Pickaxe", ItemWeapon.tWeaponType.WeaponPickaxe, "A slightly worn, but reliable pickaxe.", ItemBase.tOreType.Copper);

        string bladeCode = ItemComponent.generateComponentCode(ItemComponent.tAttributeType.Normal, ItemBase.tOreType.Bone, ItemWeapon.tWeaponType.WeaponSword,
                                                               ItemComponent.tComponentPart.Blade);
        string handleCode = ItemComponent.generateComponentCode(ItemComponent.tAttributeType.Normal, ItemBase.tOreType.Bone, ItemWeapon.tWeaponType.WeaponSword,
                                                                ItemComponent.tComponentPart.Handle);
        ItemWeapon myFirstSword = ItemFactory.createWeapon(ItemFactory.createComponent(bladeCode), ItemFactory.createComponent(handleCode));

        inventory.inventoryAddItem(myFirstPickaxe);
        inventory.inventoryAddItem(myFirstSword);

        cheat(cheatAmount.a_little);//add all weapons
        //cheat(cheatAmount.a_lot);//add all weapons and make them top tier

        base.Start();

        inventory.initialize();//calling initialize here ensures inventory Character field is set before it is used
        inventory.inventorySwitchWeapon();

        //Create a new gameobejct with a GUITexture attached to it
        damageTexture = new GameObject();
        damageTexture.AddComponent("GUITexture");

        //Store away the color struct that gets returned and change it before saving it back again. Can't change color.a in one line
        Color damageTextureColor = damageTexture.guiTexture.color;
        damageTextureColor.a = 0;

        //Get the texture that should take up the whole screen
        Texture2D hurtScreen = (Texture2D)Resources.Load("HurtScreen");

        //Center the damageTexture
        Vector3 damagePos = damageTexture.transform.position;
        damagePos.x = 0.5f; //GUITexture corrdinates are a bit different than usual ones
        damagePos.y = 0.5f;
        damagePos.z = 0f;
        damageTexture.transform.position = damagePos;

        damageTexture.guiTexture.texture = hurtScreen;
        damageTexture.guiTexture.color = damageTextureColor;
    }