Ejemplo n.º 1
0
        public override void ReceiveDamage(IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId)
        {
            if (!IsServer || IsDead() || weapon == null)
            {
                return;
            }

            base.ReceiveDamage(attacker, weapon, allDamageAmounts, debuff, hitEffectsId);
            BaseCharacterEntity attackerCharacter = attacker as BaseCharacterEntity;

            // Play hit effect
            if (hitEffectsId == 0)
            {
                hitEffectsId = gameInstance.DefaultHitEffects.Id;
            }
            if (hitEffectsId > 0)
            {
                RequestPlayEffect(hitEffectsId);
            }
            // Apply damages
            int  totalDamage = 0;
            Item weaponItem  = weapon.GetWeaponItem();
            HarvestEffectiveness harvestEffectiveness;
            WeightedRandomizer <ItemDropByWeight> itemRandomizer;

            if (harvestable.CacheHarvestEffectivenesses.TryGetValue(weaponItem.weaponType, out harvestEffectiveness) &&
                harvestable.CacheHarvestItems.TryGetValue(weaponItem.weaponType, out itemRandomizer))
            {
                totalDamage = (int)(weaponItem.harvestDamageAmount.GetAmount(weapon.level).Random() * harvestEffectiveness.damageEffectiveness);
                ItemDropByWeight receivingItem = itemRandomizer.TakeOne();
                int   dataId           = receivingItem.item.DataId;
                short amount           = (short)(receivingItem.amountPerDamage * totalDamage);
                bool  droppingToGround = collectType == HarvestableCollectType.DropToGround;
                if (attackerCharacter.IncreasingItemsWillOverwhelming(dataId, amount))
                {
                    droppingToGround = true;
                }
                if (!droppingToGround)
                {
                    attackerCharacter.IncreaseItems(CharacterItem.Create(dataId, 1, amount));
                }
                else
                {
                    ItemDropEntity.DropItem(this, CharacterItem.Create(dataId, 1, amount), new uint[0]);
                }
            }
            CurrentHp -= totalDamage;
            ReceivedDamage(attackerCharacter, CombatAmountType.NormalDamage, totalDamage);

            if (IsDead())
            {
                CurrentHp = 0;
                CallNetFunction(NetFuncOnHarvestableDestroy, FunctionReceivers.All);
                DestroyAndRespawn();
            }
        }