Beispiel #1
0
    public void OnDeath_UCE_LootRules()
    {
        lootRules.deathTime = NetworkTime.time;

        // ---------------------------------------------------------------------- Equipment

        for (int i = 0; i < equipment.Count; ++i)
        {
            int      idx      = i;
            ItemSlot itemSlot = equipment[i];

            if (itemSlot.amount > 0 && Random.value <= itemSlot.item.data.dropChance + lootRules.equipmentDropModifier)
            {
                Vector3 position = UCE_Tools.ReachableRandomUnitCircleOnNavMesh(transform.position, lootRules.radiusMultiplier, lootRules.dropSolverAttempts);

                GameObject drop = Instantiate(itemSlot.item.data.dropPrefab.gameObject, position, Quaternion.identity);

                drop.GetComponent <UCE_ItemDrop>().itemData = itemSlot.item.data;
                drop.GetComponent <UCE_ItemDrop>().amount   = itemSlot.amount;
                drop.GetComponent <UCE_ItemDrop>().item     = new Item(itemSlot.item.data);

#if _iMMOLOOTRULES && _iMMOITEMDROP
                drop.GetComponent <UCE_ItemDrop>().LiftRulesAfter  = lootRules.LiftRulesAfter;
                drop.GetComponent <UCE_ItemDrop>().LootVictorParty = lootRules.LootVictorParty;
                drop.GetComponent <UCE_ItemDrop>().LootVictorGuild = lootRules.LootVictorGuild;
#if _iMMOPVP
                drop.GetComponent <UCE_ItemDrop>().LootVictorRealm = lootRules.LootVictorRealm;
                drop.GetComponent <UCE_ItemDrop>().hashRealm       = hashRealm;
                drop.GetComponent <UCE_ItemDrop>().hashAlly        = hashAlly;
#endif
                drop.GetComponent <UCE_ItemDrop>().LootEverybody = lootRules.LootEverybody;

                drop.GetComponent <UCE_ItemDrop>().lastAggressor = this.lastAggressor;
                drop.GetComponent <UCE_ItemDrop>().owner         = this;
#endif

                itemSlot.amount = 0;
                equipment[idx]  = itemSlot;

                NetworkServer.Spawn(drop);
            }
        }

        // ---------------------------------------------------------------------- Gold
        if (lootRules.goldDropPrefab != null && gold > 0)
        {
            Vector3 position = UCE_Tools.ReachableRandomUnitCircleOnNavMesh(transform.position, lootRules.radiusMultiplier, lootRules.dropSolverAttempts);

            GameObject drop = Instantiate(lootRules.goldDropPrefab.gameObject, position, Quaternion.identity);

            drop.GetComponent <UCE_ItemDrop>().amount = 0;
            int droppedGold = (int)(gold * lootRules.goldPercentage);
            drop.GetComponent <UCE_ItemDrop>().gold = droppedGold;
            gold -= droppedGold;

#if _iMMOLOOTRULES && _iMMOITEMDROP
            drop.GetComponent <UCE_ItemDrop>().LiftRulesAfter  = lootRules.LiftRulesAfter;
            drop.GetComponent <UCE_ItemDrop>().LootVictorParty = lootRules.LootVictorParty;
            drop.GetComponent <UCE_ItemDrop>().LootVictorGuild = lootRules.LootVictorGuild;
#if _iMMOPVP
            drop.GetComponent <UCE_ItemDrop>().LootVictorRealm = lootRules.LootVictorRealm;
            drop.GetComponent <UCE_ItemDrop>().hashRealm       = hashRealm;
            drop.GetComponent <UCE_ItemDrop>().hashAlly        = hashAlly;
#endif
            drop.GetComponent <UCE_ItemDrop>().LootEverybody = lootRules.LootEverybody;
            drop.GetComponent <UCE_ItemDrop>().lastAggressor = this.lastAggressor;
            drop.GetComponent <UCE_ItemDrop>().owner         = this;
#endif
            NetworkServer.Spawn(drop);
        }
        else if (lootRules.goldDropPrefab == null && gold > 0)
        {
            Debug.LogWarning("You forgot to assign a gold drop to: " + this.name);
        }

        // ---------------------------------------------------------------------- Inventory

        for (int i = 0; i < inventory.Count; ++i)
        {
            int      idx      = i;
            ItemSlot itemSlot = inventory[i];

            if (itemSlot.amount > 0 && Random.value <= itemSlot.item.data.dropChance + lootRules.inventoryDropModifier)
            {
                if (itemSlot.item.data.dropPrefab == null)
                {
                    Debug.LogWarning("You forgot to assign a item drop to: " + itemSlot.item.name);
                    continue;
                }

                Vector3 position = UCE_Tools.ReachableRandomUnitCircleOnNavMesh(transform.position, lootRules.radiusMultiplier, lootRules.dropSolverAttempts);

                GameObject drop = Instantiate(itemSlot.item.data.dropPrefab.gameObject, position, Quaternion.identity);

                drop.GetComponent <UCE_ItemDrop>().itemData = itemSlot.item.data;
                drop.GetComponent <UCE_ItemDrop>().amount   = itemSlot.amount;
                drop.GetComponent <UCE_ItemDrop>().item     = new Item(itemSlot.item.data);

#if _iMMOLOOTRULES && _iMMOITEMDROP
                drop.GetComponent <UCE_ItemDrop>().LiftRulesAfter  = lootRules.LiftRulesAfter;
                drop.GetComponent <UCE_ItemDrop>().LootVictorParty = lootRules.LootVictorParty;
                drop.GetComponent <UCE_ItemDrop>().LootVictorGuild = lootRules.LootVictorGuild;
#if _iMMOPVP
                drop.GetComponent <UCE_ItemDrop>().LootVictorRealm = lootRules.LootVictorRealm;
                drop.GetComponent <UCE_ItemDrop>().hashRealm       = hashRealm;
                drop.GetComponent <UCE_ItemDrop>().hashAlly        = hashAlly;
#endif
                drop.GetComponent <UCE_ItemDrop>().LootEverybody = lootRules.LootEverybody;

                drop.GetComponent <UCE_ItemDrop>().lastAggressor = this.lastAggressor;
                drop.GetComponent <UCE_ItemDrop>().owner         = this;
#endif

                itemSlot.amount = 0;
                inventory[idx]  = itemSlot;

                NetworkServer.Spawn(drop);
            }
        }
    }
    public void OnDeath_UCE_ItemDrop()
    {
        // ---------- drop gold
        if (goldDropPrefab != null && gold > 0)
        {
            Vector3 position = UCE_Tools.ReachableRandomUnitCircleOnNavMesh(transform.position, radiusMultiplier, dropSolverAttempts);

            GameObject drop = Instantiate(goldDropPrefab.gameObject, position, Quaternion.identity);

            drop.GetComponent <UCE_ItemDrop>().amount = 0;
            drop.GetComponent <UCE_ItemDrop>().gold   = gold;
            gold = 0;

#if _iMMOLOOTRULES && _iMMOITEMDROP
            drop.GetComponent <UCE_ItemDrop>().LiftRulesAfter  = LiftRulesAfter;
            drop.GetComponent <UCE_ItemDrop>().LootVictorParty = LootVictorParty;
            drop.GetComponent <UCE_ItemDrop>().LootVictorGuild = LootVictorGuild;
#if _iMMOPVP
            drop.GetComponent <UCE_ItemDrop>().LootVictorRealm = LootVictorRealm;
            drop.GetComponent <UCE_ItemDrop>().hashRealm       = hashRealm;
            drop.GetComponent <UCE_ItemDrop>().hashAlly        = hashAlly;
#endif
            drop.GetComponent <UCE_ItemDrop>().LootEverybody = LootEverybody;
            drop.GetComponent <UCE_ItemDrop>().lastAggressor = this.lastAggressor;
            drop.GetComponent <UCE_ItemDrop>().owner         = this;
#endif
            NetworkServer.Spawn(drop);
        }
        else if (goldDropPrefab == null && gold > 0)
        {
            Debug.LogWarning("You forgot to assign a gold drop to: " + this.name);
        }

        // ---------- drop items
        foreach (ItemSlot itemSlot in inventory)
        {
            if (itemSlot.amount > 0)
            {
                if (itemSlot.item.data.dropPrefab == null)
                {
                    Debug.LogWarning("You forgot to assign a item drop to: " + itemSlot.item.name);
                    continue;
                }

                Vector2 position = UCE_Tools.ReachableRandomUnitCircleOnNavMesh(transform.position, radiusMultiplier, dropSolverAttempts);

                GameObject drop = Instantiate(itemSlot.item.data.dropPrefab.gameObject, position, Quaternion.identity);

                drop.GetComponent <UCE_ItemDrop>().itemData = itemSlot.item.data;
                drop.GetComponent <UCE_ItemDrop>().amount   = itemSlot.amount;
                drop.GetComponent <UCE_ItemDrop>().gold     = 0;
                drop.GetComponent <UCE_ItemDrop>().item     = new Item(itemSlot.item.data);

#if _iMMOLOOTRULES && _iMMOITEMDROP
                drop.GetComponent <UCE_ItemDrop>().LiftRulesAfter  = LiftRulesAfter;
                drop.GetComponent <UCE_ItemDrop>().LootVictorParty = LootVictorParty;
                drop.GetComponent <UCE_ItemDrop>().LootVictorGuild = LootVictorGuild;
#if _iMMOPVP
                drop.GetComponent <UCE_ItemDrop>().LootVictorRealm = LootVictorRealm;
                drop.GetComponent <UCE_ItemDrop>().hashRealm       = hashRealm;
                drop.GetComponent <UCE_ItemDrop>().hashAlly        = hashAlly;
#endif
                drop.GetComponent <UCE_ItemDrop>().LootEverybody = LootEverybody;
                drop.GetComponent <UCE_ItemDrop>().lastAggressor = this.lastAggressor;
                drop.GetComponent <UCE_ItemDrop>().owner         = this;
#endif

                NetworkServer.Spawn(drop);
            }
        }

        inventory.Clear();
    }