Example #1
0
 private void Awake()
 {
     if (characterEntity == null)
     {
         characterEntity = GetComponentInParent <BaseCharacterEntity>();
     }
 }
Example #2
0
        public override float GetHitChance(BaseCharacterEntity attacker, BaseCharacterEntity damageReceiver)
        {
            // Attacker stats
            var attackerStats = attacker.CacheStats;
            // Damage receiver stats
            var dmgReceiverStats = damageReceiver.CacheStats;
            // Calculate chance to hit
            var attackerAcc    = attackerStats.accuracy;
            var dmgReceiverEva = dmgReceiverStats.evasion;
            var attackerLvl    = attacker.Level;
            var dmgReceiverLvl = damageReceiver.Level;
            var hitChance      = 2f;

            if (attackerAcc != 0 && dmgReceiverEva != 0)
            {
                hitChance *= (attackerAcc / (attackerAcc + dmgReceiverEva));
            }

            if (attackerLvl != 0 && dmgReceiverLvl != 0)
            {
                hitChance *= ((float)attackerLvl / (float)(attackerLvl + dmgReceiverLvl));
            }

            // Minimum hit chance is 5%
            if (hitChance < 0.05f)
            {
                hitChance = 0.05f;
            }
            // Maximum hit chance is 95%
            if (hitChance > 0.95f)
            {
                hitChance = 0.95f;
            }
            return(hitChance);
        }
 public void Summon(BaseCharacterEntity summoner, SummonType summonType, short level)
 {
     Summoner   = summoner;
     SummonType = summonType;
     Level      = level;
     InitStats();
 }
Example #4
0
        private void DecreaseEquipShieldsDurability(BaseCharacterEntity entity, float decreaseDurability)
        {
            var tempDestroy  = false;
            var equipWeapons = entity.EquipWeapons;
            var rightHand    = equipWeapons.rightHand;
            var leftHand     = equipWeapons.leftHand;

            if (rightHand.GetShieldItem() != null && rightHand.GetMaxDurability() > 0)
            {
                rightHand = DecreaseDurability(rightHand, decreaseDurability, out tempDestroy);
                if (tempDestroy)
                {
                    equipWeapons.rightHand = CharacterItem.Empty;
                }
                else
                {
                    equipWeapons.rightHand = rightHand;
                }
            }
            if (leftHand.GetShieldItem() != null && leftHand.GetMaxDurability() > 0)
            {
                leftHand = DecreaseDurability(leftHand, decreaseDurability, out tempDestroy);
                if (tempDestroy)
                {
                    equipWeapons.leftHand = CharacterItem.Empty;
                }
                else
                {
                    equipWeapons.leftHand = leftHand;
                }
            }
            entity.EquipWeapons = equipWeapons;
        }
Example #5
0
        public override bool IncreaseExp(BaseCharacterEntity character, int exp)
        {
            var monsterCharacter = character as BaseMonsterCharacterEntity;

            if (monsterCharacter != null && monsterCharacter.SummonType != SummonType.Pet)
            {
                // If it's monster and not pet, do not increase exp
                return(false);
            }

            var isLevelUp = false;

            character.Exp += exp;
            var playerCharacter = character as BasePlayerCharacterEntity;
            var nextLevelExp    = character.GetNextLevelExp();

            while (nextLevelExp > 0 && character.Exp >= nextLevelExp)
            {
                character.Exp = character.Exp - nextLevelExp;
                ++character.Level;
                nextLevelExp = character.GetNextLevelExp();
                if (playerCharacter != null)
                {
                    playerCharacter.StatPoint  += increaseStatPointEachLevel;
                    playerCharacter.SkillPoint += increaseSkillPointEachLevel;
                }
                isLevelUp = true;
            }
            return(isLevelUp);
        }
 public override void NotifyEnemySpotted(BaseCharacterEntity ally, BaseCharacterEntity attacker)
 {
     if ((Summoner != null && Summoner == ally) || MonsterDatabase.characteristic == MonsterCharacteristic.Assist)
     {
         SetAttackTarget(attacker);
     }
 }
Example #7
0
        public override bool CanReceiveDamageFrom(IAttackerEntity attacker)
        {
            if (attacker == null)
            {
                return(false);
            }

            BaseCharacterEntity characterEntity = attacker as BaseCharacterEntity;

            if (characterEntity == null)
            {
                return(false);
            }

            if (isInSafeArea || characterEntity.isInSafeArea)
            {
                // If this character or another character is in safe area so it cannot receive damage
                return(false);
            }
            if (characterEntity is BasePlayerCharacterEntity)
            {
                // If not ally while this is Pvp map, assume that it can receive damage
                if (!IsAlly(characterEntity) && gameManager.CurrentMapInfo.canPvp)
                {
                    return(true);
                }
            }
            if (characterEntity is BaseMonsterCharacterEntity)
            {
                // If this character is not summoner so it is enemy and also can receive damage
                return(!IsAlly(characterEntity));
            }
            return(false);
        }
        public override bool IsAlly(BaseCharacterEntity characterEntity)
        {
            if (characterEntity == null)
            {
                return(false);
            }

            if (IsSummoned)
            {
                // If summoned by someone, will have same allies with summoner
                return(characterEntity == Summoner || characterEntity.IsAlly(Summoner));
            }
            if (characterEntity is BaseMonsterCharacterEntity)
            {
                // If another monster has same allyId so it is ally
                var monsterCharacterEntity = characterEntity as BaseMonsterCharacterEntity;
                if (monsterCharacterEntity != null)
                {
                    if (monsterCharacterEntity.IsSummoned)
                    {
                        return(IsAlly(monsterCharacterEntity.Summoner));
                    }
                    return(monsterCharacterEntity.MonsterDatabase.allyId == MonsterDatabase.allyId);
                }
            }
            return(false);
        }
Example #9
0
        public override sealed void Killed(BaseCharacterEntity lastAttacker)
        {
            float     expLostPercentage = gameInstance.GameplayRule.GetExpLostPercentageWhenDeath(this);
            GuildData guildData;

            if (gameManager.TryGetGuild(GuildId, out guildData))
            {
                expLostPercentage -= expLostPercentage * guildData.DecreaseExpLostPercentage;
            }
            if (expLostPercentage <= 0f)
            {
                expLostPercentage = 0f;
            }
            int exp = Exp;

            exp -= (int)(this.GetNextLevelExp() * expLostPercentage / 100f);
            if (exp <= 0)
            {
                exp = 0;
            }
            Exp = exp;

            base.Killed(lastAttacker);
            currentNpcDialog = null;
        }
        public override void ReceivedDamage(IAttackerEntity attacker, CombatAmountType damageAmountType, int damage)
        {
            BaseCharacterEntity attackerCharacter = attacker as BaseCharacterEntity;

            // If summoned by someone, summoner is attacker
            if (attackerCharacter != null &&
                attackerCharacter is BaseMonsterCharacterEntity &&
                (attackerCharacter as BaseMonsterCharacterEntity).IsSummoned)
            {
                attackerCharacter = (attackerCharacter as BaseMonsterCharacterEntity).Summoner;
            }

            // Add received damage entry
            if (attackerCharacter != null)
            {
                ReceivedDamageRecord receivedDamageRecord = new ReceivedDamageRecord();
                receivedDamageRecord.totalReceivedDamage = damage;
                if (receivedDamageRecords.ContainsKey(attackerCharacter))
                {
                    receivedDamageRecord = receivedDamageRecords[attackerCharacter];
                    receivedDamageRecord.totalReceivedDamage += damage;
                }
                receivedDamageRecord.lastReceivedDamageTime = Time.unscaledTime;
                receivedDamageRecords[attackerCharacter]    = receivedDamageRecord;
            }

            base.ReceivedDamage(attackerCharacter, damageAmountType, damage);
        }
        public override void ReceiveDamage(IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId)
        {
            if (!IsServer || IsDead() || !CanReceiveDamageFrom(attacker))
            {
                return;
            }

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

            // If character is not dead, try to attack
            if (!IsDead())
            {
                BaseCharacterEntity targetEntity;
                if (!TryGetTargetEntity(out targetEntity))
                {
                    // If no target enemy, set target enemy as attacker
                    SetAttackTarget(attackerCharacter);
                }
                else if (attackerCharacter != targetEntity && Random.value > 0.5f)
                {
                    // Random 50% to change target when receive damage from anyone
                    SetAttackTarget(attackerCharacter);
                }
            }
        }
Example #12
0
 public override float GetExpLostPercentageWhenDeath(BaseCharacterEntity character)
 {
     if (character is BaseMonsterCharacterEntity)
     {
         return(0f);
     }
     return(expLostPercentageWhenDeath);
 }
Example #13
0
 public override float GetDecreasingWaterPerSeconds(BaseCharacterEntity character)
 {
     if (character is BaseMonsterCharacterEntity)
     {
         return(0f);
     }
     return(waterDecreasePerSeconds);
 }
Example #14
0
 public override float GetRecoveryMpPerSeconds(BaseCharacterEntity character)
 {
     if (IsThirsty(character))
     {
         return(0);
     }
     return(character.CacheMaxMp * mpRecoveryRatePerSeconds);
 }
Example #15
0
 public override float GetRecoveryHpPerSeconds(BaseCharacterEntity character)
 {
     if (IsHungry(character))
     {
         return(0);
     }
     return(character.CacheMaxHp * hpRecoveryRatePerSeconds);
 }
Example #16
0
 protected void DevExtReceivedDamageDemo(BaseCharacterEntity attacker, CombatAmountType combatAmountType, int damage)
 {
     if (writeAddonLog)
     {
         Debug.Log("[" + name + "] MonsterCharacterEntity.ReceivedDamage("
                   + attacker.Title + ", " + combatAmountType + ", " + damage + ")");
     }
 }
Example #17
0
 protected void DevExtReceiveDamageDemo(BaseCharacterEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId)
 {
     if (writeAddonLog)
     {
         Debug.Log("[" + name + "] MonsterCharacterEntity.ReceiveDamage("
                   + attacker.Title + ", " + weapon + ", " + allDamageAmounts.Count + ", " + debuff + ", " + hitEffectsId + ")");
     }
 }
        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();
            }
        }
Example #19
0
 public bool IsAbleToLoot(BaseCharacterEntity baseCharacterEntity)
 {
     if (looters == null ||
         looters.Contains(baseCharacterEntity.ObjectId) ||
         Time.unscaledTime - dropTime > GameInstance.itemLootLockDuration)
     {
         return(true);
     }
     return(false);
 }
Example #20
0
        public override void OnHarvestableReceivedDamage(BaseCharacterEntity attacker, HarvestableEntity damageReceiver, CombatAmountType combatAmountType, int damage)
        {
            var decreaseWeaponDurability = normalDecreaseWeaponDurability;
            var decreaseShieldDurability = normalDecreaseShieldDurability;
            var decreaseArmorDurability  = normalDecreaseArmorDurability;

            GetDecreaseDurabilityAmount(combatAmountType, out decreaseWeaponDurability, out decreaseShieldDurability, out decreaseArmorDurability);
            // Decrease Weapon Durability
            DecreaseEquipWeaponsDurability(attacker, decreaseWeaponDurability);
        }
Example #21
0
 /// <summary>
 /// Return TRUE if this will override default apply skill function
 /// </summary>
 /// <param name="character"></param>
 /// <param name="skillLevel"></param>
 /// <param name="isLeftHand"></param>
 /// <param name="weapon"></param>
 /// <param name="damageInfo"></param>
 /// <param name="allDamageAmounts"></param>
 /// <param name="hasAimPosition"></param>
 /// <param name="aimPosition"></param>
 /// <returns></returns>
 public virtual bool OnApplySkill(
     BaseCharacterEntity character,
     short skillLevel,
     bool isLeftHand,
     CharacterItem weapon,
     DamageInfo damageInfo,
     Dictionary <DamageElement, MinMaxFloat> allDamageAmounts,
     bool hasAimPosition,
     Vector3 aimPosition)
 {
     return(false);
 }
 public void UseItem(BaseCharacterEntity characterEntity, short itemIndex, CharacterItem characterItem)
 {
     if (!characterEntity.CanUseItem() || characterItem.level <= 0 || !characterEntity.DecreaseItemsByIndex(itemIndex, 1))
     {
         return;
     }
     characterEntity.FillEmptySlots();
     characterEntity.ApplyBuff(DataId, BuffType.PotionBuff, characterItem.level, characterEntity.GetInfo());
     characterEntity.RewardExp(new Reward()
     {
         exp = Exp
     }, 1, RewardGivenType.None);
 }
Example #23
0
 /// <summary>
 /// Finds the BaseCharacterEntity with the same ID as the storage's creator and sets it as the ownerEntity.
 /// Called by CLIENT only.
 /// </summary>
 protected void FindOwnerEntity()
 {
     BaseCharacterEntity[] characters = FindObjectsOfType <BaseCharacterEntity>();
     foreach (BaseCharacterEntity bce in characters)
     {
         if (bce.ObjectId == OwnerObjectID)
         {
             ownerEntity = bce;
             ownerSet    = true;
             return;
         }
     }
 }
        public override float GetMoveSpeed(BaseCharacterEntity character)
        {
            float moveSpeed = character.CacheMoveSpeed;

            if (character.MovementState.HasFlag(MovementState.IsSprinting))
            {
                moveSpeed *= moveSpeedRateWhileSprint;
            }
            if (character.isAttackingOrUsingSkill)
            {
                moveSpeed *= character.moveSpeedRateWhileAttackOrUseSkill;
            }
            return(moveSpeed);
        }
        public override void OnCharacterReceivedDamage(BaseCharacterEntity attacker, BaseCharacterEntity damageReceiver, CombatAmountType combatAmountType, int damage)
        {
            float decreaseWeaponDurability = normalDecreaseWeaponDurability;
            float decreaseShieldDurability = normalDecreaseShieldDurability;
            float decreaseArmorDurability  = normalDecreaseArmorDurability;

            GetDecreaseDurabilityAmount(combatAmountType, out decreaseWeaponDurability, out decreaseShieldDurability, out decreaseArmorDurability);
            // Decrease Weapon Durability
            DecreaseEquipWeaponsDurability(attacker, decreaseWeaponDurability);
            // Decrease Shield Durability
            DecreaseEquipShieldsDurability(damageReceiver, decreaseShieldDurability);
            // Decrease Armor Durability
            DecreaseEquipItemsDurability(damageReceiver, decreaseArmorDurability);
        }
        public override bool IsEnemy(BaseCharacterEntity characterEntity)
        {
            if (characterEntity == null)
            {
                return(false);
            }

            if (IsSummoned)
            {
                // If summoned by someone, will have same enemies with summoner
                return(characterEntity != Summoner && characterEntity.IsEnemy(Summoner));
            }
            // Attack only player by default
            return(characterEntity is BasePlayerCharacterEntity);
        }
Example #27
0
        public override float GetDamageReducedByResistance(BaseCharacterEntity damageReceiver, float damageAmount, DamageElement damageElement)
        {
            if (damageElement == null)
            {
                return(damageAmount -= damageReceiver.CacheStats.armor); // If armor is minus damage will be increased
            }
            var   resistances      = damageReceiver.CacheResistances;
            float resistanceAmount = 0f;

            resistances.TryGetValue(damageElement, out resistanceAmount);
            if (resistanceAmount > damageElement.maxResistanceAmount)
            {
                resistanceAmount = damageElement.maxResistanceAmount;
            }
            return(damageAmount -= damageAmount * resistanceAmount); // If resistance is minus damage will be increased
        }
        protected void SetTargetCharacter(BaseCharacterEntity character)
        {
            if (uiTargetCharacter == null)
            {
                return;
            }

            if (character == null)
            {
                uiTargetCharacter.Hide();
                return;
            }

            uiTargetCharacter.Data = character;
            uiTargetCharacter.Show();
        }
Example #29
0
        public override float GetCriticalChance(BaseCharacterEntity attacker, BaseCharacterEntity damageReceiver)
        {
            var criRate = damageReceiver.CacheStats.criRate;

            // Minimum critical chance is 5%
            if (criRate < 0.05f)
            {
                criRate = 0.05f;
            }
            // Maximum critical chance is 95%
            if (criRate > 0.95f)
            {
                criRate = 0.95f;
            }
            return(criRate);
        }
        public virtual void SetAttackTarget(BaseCharacterEntity target)
        {
            if (target == null || target.IsDead())
            {
                return;
            }
            // Already have target so don't set target
            BaseCharacterEntity oldTarget;

            if (TryGetTargetEntity(out oldTarget) && !oldTarget.IsDead())
            {
                return;
            }
            // Set target to attack
            SetTargetEntity(target);
        }