Exemplo n.º 1
0
        public static void On_PlayerGathering(ResourceDispenser dispenser, BaseEntity to, ItemAmount itemAmt, float gatherDamage, float destroyFraction)
        {
            BaseEntity from = (BaseEntity)dispenser.GetFieldValue("baseEntity");

            if (itemAmt.amount == 0)
            {
                return;
            }

            float num   = gatherDamage / from.MaxHealth();
            float num2  = itemAmt.startAmount / (float)dispenser.GetFieldValue("startingItemCounts");
            float value = itemAmt.startAmount * num / num2;
            float num3  = Mathf.Clamp(value, 0, itemAmt.amount);
            float num4  = num3 * destroyFraction * 2;

            if (itemAmt.amount < num3 + num4)
            {
                itemAmt.amount -= destroyFraction * num3;
                num3            = itemAmt.amount;
                num4            = 0;
            }
            float amount = itemAmt.amount;

            itemAmt.amount -= num3;
            if (itemAmt.amount < 0)
            {
                itemAmt.amount = 0;
            }
            int num5 = Mathf.Clamp(Mathf.RoundToInt(num3), 0, Mathf.CeilToInt(amount));

            itemAmt.amount -= num4;
            if (itemAmt.amount < 0)
            {
                itemAmt.amount = 0;
            }

            GatherEvent ge = new GatherEvent(dispenser, from, to, itemAmt, num5);

            OnNext("On_PlayerGathering", ge);

            if (ge.Amount <= 0)
            {
                return;
            }
            Item item = ItemManager.CreateByItemID(itemAmt.itemid, ge.Amount);

            if (item == null)
            {
                return;
            }

            to.GiveItem(item, BaseEntity.GiveItemReason.ResourceHarvested);
        }
Exemplo n.º 2
0
        public static void Gathering(ResourceDispenser dispenser, BaseEntity to, ItemAmount itemAmt, int amount)
        {
            itemAmt.amount += amount;
            BaseEntity  from = (BaseEntity)dispenser.GetFieldValue("baseEntity");
            GatherEvent ge   = new GatherEvent(dispenser, from, to, itemAmt, amount);

            OnGathering.OnNext(ge);

            if (ge.Amount > 0)
            {
                amount = Mathf.RoundToInt(Mathf.Min((float)ge.Amount, itemAmt.amount));

                if (amount > 0)
                {
                    itemAmt.amount -= amount;
                    if (itemAmt.amount < 0)
                    {
                        itemAmt.amount = 0;
                    }

                    Item item = ItemManager.CreateByItemID(itemAmt.itemid, amount, false);
                    if (item == null)
                    {
                        return;
                    }
                    to.GiveItem(item);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called from <c>ResourceDispenser.GiveResourceFromItem(BaseEntity, ItemAmount, float, float, AttackEntity)</c> .
        /// </summary>
        public static void On_PlayerGathering(ResourceDispenser dispenser,
                                              BaseEntity to,
                                              ItemAmount itemAmount,
                                              float gatherDamage,
                                              float destroyFraction)
        {
            BaseEntity from = (BaseEntity)dispenser.GetFieldValue("baseEntity");

            if (itemAmount.amount == 0)
                return;

            float num = gatherDamage / from.MaxHealth();
            float num2 = itemAmount.startAmount / (float)dispenser.GetFieldValue("startingItemCounts");
            float value = itemAmount.startAmount * num / num2;
            float num3 = Mathf.Clamp(value, 0, itemAmount.amount);
            float num4 = num3 * destroyFraction * 2;

            if (itemAmount.amount < num3 + num4) {
                itemAmount.amount -= destroyFraction * num3;
                num3 = itemAmount.amount;
                num4 = 0;
            }

            float amount = itemAmount.amount;

            itemAmount.amount -= num3;

            if (itemAmount.amount < 0) {
                itemAmount.amount = 0;
            }

            int num5 = Mathf.Clamp(Mathf.RoundToInt(num3), 0, Mathf.CeilToInt(amount));

            itemAmount.amount -= num4;

            if (itemAmount.amount < 0) {
                itemAmount.amount = 0;
            }

            GatherEvent ge = new GatherEvent(dispenser, from, to, itemAmount, num5);

            OnNext("On_PlayerGathering", ge);

            if (ge.Amount <= 0)
                return;

            Item item = ItemManager.CreateByItemID(itemAmount.itemid, ge.Amount);

            if (item == null)
                return;

            to.GiveItem(item, BaseEntity.GiveItemReason.ResourceHarvested);
        }
Exemplo n.º 4
0
        public static void Gathering(ResourceDispenser dispenser, BaseEntity to, ItemAmount itemAmt, int amount)
        {
            itemAmt.amount += amount;
            BaseEntity from = (BaseEntity)dispenser.GetFieldValue("baseEntity");
            GatherEvent ge = new GatherEvent(dispenser, from, to, itemAmt, amount);
            OnGathering.OnNext(ge);

            if (ge.Amount > 0) {

                if (amount > 0) {

                    itemAmt.amount -= amount;
                    if (itemAmt.amount < 0)
                        itemAmt.amount = 0;

                    Item item = ItemManager.CreateByItemID(itemAmt.itemid, ge.Amount, false);
                    if (item == null) {
                        return;
                    }
                    to.GiveItem(item);
                }
            }
        }