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); var 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); } } }
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 void SetupDamage( IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId, float missileDistance, float missileSpeed, IDamageableEntity lockingTarget) { SetupDamage(attacker, weapon, allDamageAmounts, debuff, hitEffectsId); this.missileDistance = missileDistance; this.missileSpeed.Value = missileSpeed; if (missileDistance <= 0 && missileSpeed <= 0) { // Explode immediately when distance and speed is 0 Explode(); NetworkDestroy(destroyDelay); destroying = true; return; } LockingTarget = lockingTarget; launchTime = Time.unscaledTime; missileDuration = missileDistance / missileSpeed; }
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 AttackResults AttackWithMelee(IAttackerEntity attackerEntity, float damage) { Rectangle attackerBounds = attackerEntity.AttackerBounds; Point[] attackerPixels = attackerEntity.AttackerPixels; Matrix attackerTransformMatrix = attackerEntity.AttackerTransformMatrix; Point[] attackerTransformedPixels = CollisionHelper.ConvertTexturePixelsToScreenPixels(attackerPixels, attackerTransformMatrix); foreach (IAttackableEntity attackableEntity in attackableEntities) { if (attackableEntity.AttackBounds.Intersects(attackerBounds)) { Boolean[,] attackableBooleans = attackableEntity.AttackBooleans; foreach (Point attackerPixel in attackerTransformedPixels) { Vector2 attackablePixelVector = CollisionHelper.ConvertScreenPixelToTexturePixel( new Vector2((float)attackerPixel.X, (float)attackerPixel.Y), attackableEntity.AttackTransformMatrix); Point attackablePoint = new Point((int)attackablePixelVector.X, (int)attackablePixelVector.Y); if (attackablePoint.X >= 0 && attackablePoint.Y >= 0 && attackablePoint.X < attackableBooleans.GetLength(0) && attackablePoint.Y < attackableBooleans.GetLength(1)) { if (attackableBooleans[attackablePoint.X, attackablePoint.Y]) { if (attackableEntity.AttackWithDamage(DamageType.Melee, damage)) { return AttackResults.Kill; } else { return AttackResults.Damage; } } } } } } return AttackResults.None; }
public AttackResults AttackWithProjectileSingleTarget(IAttackerEntity attackerEntity, float damage) { IAttackableEntity[] attackableEntitiesWithinAttackersBounds = AttackHelper.AttackableEntitiesWithinAttackersBounds(attackerEntity.AttackerBounds, this.AttackableEntities.ToArray()); foreach (Point attackersPixel in attackerEntity.AttackerPixels) { Point attackersPixelInScreenCoordinates = CollisionHelper.ConvertTexturePixelToScreenPixel(attackersPixel, attackerEntity.AttackerTransformMatrix); for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++) { IAttackableEntity attackableEntity = attackableEntitiesWithinAttackersBounds[index]; Point attackersPixelInAttackableEntitysTextureCoordinates = CollisionHelper.ConvertScreenPixelToTexturePixel(attackersPixelInScreenCoordinates, attackableEntity.AttackTransformMatrix); if (attackersPixelInAttackableEntitysTextureCoordinates.X >= 0 && attackersPixelInAttackableEntitysTextureCoordinates.Y >= 0) { if (attackersPixelInAttackableEntitysTextureCoordinates.X < attackableEntity.AttackBooleans.GetLength(0) && attackersPixelInAttackableEntitysTextureCoordinates.Y < attackableEntity.AttackBooleans.GetLength(1)) { if (attackableEntity.AttackBooleans[attackersPixelInAttackableEntitysTextureCoordinates.X, attackersPixelInAttackableEntitysTextureCoordinates.Y]) { if (attackableEntity.AttackWithDamage(DamageType.Projectile, damage)) { return(AttackResults.Kill); } else { return(AttackResults.Damage); } } } } } } return(AttackResults.None); }
public override void ReceiveDamage(IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId) { if (!IsServer || IsDead()) { return; } base.ReceiveDamage(attacker, weapon, allDamageAmounts, debuff, hitEffectsId); float calculatingTotalDamage = 0f; if (allDamageAmounts.Count > 0) { foreach (KeyValuePair <DamageElement, MinMaxFloat> allDamageAmount in allDamageAmounts) { DamageElement damageElement = allDamageAmount.Key; MinMaxFloat damageAmount = allDamageAmount.Value; calculatingTotalDamage += damageAmount.Random(); } } // Apply damages int totalDamage = (int)calculatingTotalDamage; CurrentHp -= totalDamage; ReceivedDamage(attacker, CombatAmountType.NormalDamage, totalDamage); // If current hp <= 0, character dead if (IsDead()) { NetworkDestroy(); } }
public virtual void ReceivedDamage(IAttackerEntity attacker, CombatAmountType combatAmountType, int damage) { RequestCombatAmount(combatAmountType, damage); if (onReceivedDamage != null) { onReceivedDamage.Invoke(attacker, combatAmountType, damage); } }
public virtual void ReceiveDamage(IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId) { if (!IsServer || IsDead()) { return; } this.InvokeInstanceDevExtMethods("ReceiveDamage", attacker, weapon, allDamageAmounts, debuff, hitEffectsId); }
protected void DevExtReceivedDamageDemo(IAttackerEntity attacker, CombatAmountType combatAmountType, int damage) { if (writeAddonLog) { Debug.Log("[" + name + "] MonsterCharacterEntity.ReceivedDamage(" + attacker.gameObject.name + ", " + combatAmountType + ", " + damage + ")"); } }
protected void DevExtReceiveDamageDemo(IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId) { if (writeAddonLog) { Debug.Log("[" + name + "] MonsterCharacterEntity.ReceiveDamage(" + attacker.gameObject.name + ", " + weapon + ", " + allDamageAmounts.Count + ", " + debuff + ", " + hitEffectsId + ")"); } }
public override void ReceivedDamage(IAttackerEntity attacker, CombatAmountType combatAmountType, int damage) { base.ReceivedDamage(attacker, combatAmountType, damage); if (attacker is BaseCharacterEntity) { gameInstance.GameplayRule.OnHarvestableReceivedDamage(attacker as BaseCharacterEntity, this, combatAmountType, damage); } }
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(); } }
public override void ReceiveDamage(IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId) { if (!IsServer || IsDead()) { return; } base.ReceiveDamage(attacker, weapon, allDamageAmounts, debuff, hitEffectsId); // TODO: Reduce current hp }
public void ReceiveDamage(IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId) { List <DamageElement> keys = new List <DamageElement>(allDamageAmounts.Keys); foreach (DamageElement key in keys) { allDamageAmounts[key] = allDamageAmounts[key] * damageRate; } characterEntity.ReceiveDamageFunction(attacker, weapon, allDamageAmounts, debuff, hitEffectsId); }
public virtual void ReceiveDamage(IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId) { if (!IsServer || IsDead()) { return; } if (onReceiveDamage != null) { onReceiveDamage.Invoke(attacker, weapon, allDamageAmounts, debuff, hitEffectsId); } }
public virtual void SetupDamage( IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId) { this.attacker = attacker; this.weapon = weapon; this.allDamageAmounts = allDamageAmounts; this.debuff = debuff; this.hitEffectsId = hitEffectsId; }
public MultiAttackResults AttackWithProjectile(IAttackerEntity attackerEntity, float damage) { IAttackableEntity[] attackableEntitiesWithinAttackersBounds = AttackHelper.AttackableEntitiesWithinAttackersBounds(attackerEntity.AttackerBounds, this.AttackableEntities.ToArray()); float[] damageValuesArray = new float[attackableEntitiesWithinAttackersBounds.Length]; MultiAttackResults multiAttackResults = new MultiAttackResults(); foreach (Point attackersPixel in attackerEntity.AttackerPixels) { Point attackersPixelInScreenCoordinates = CollisionHelper.ConvertTexturePixelToScreenPixel(attackersPixel, attackerEntity.AttackerTransformMatrix); for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++) { IAttackableEntity attackableEntity = attackableEntitiesWithinAttackersBounds[index]; Point attackersPixelInAttackableEntitysTextureCoordinates = CollisionHelper.ConvertScreenPixelToTexturePixel(attackersPixelInScreenCoordinates, attackableEntity.AttackTransformMatrix); if (attackersPixelInAttackableEntitysTextureCoordinates.X >= 0 && attackersPixelInAttackableEntitysTextureCoordinates.Y >= 0) { if (attackersPixelInAttackableEntitysTextureCoordinates.X < attackableEntity.AttackBooleans.GetLength(0) && attackersPixelInAttackableEntitysTextureCoordinates.Y < attackableEntity.AttackBooleans.GetLength(1)) { if (attackableEntity.AttackBooleans[attackersPixelInAttackableEntitysTextureCoordinates.X, attackersPixelInAttackableEntitysTextureCoordinates.Y]) { damageValuesArray[index] += damage; } } } } } for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++) { if (damageValuesArray[index] > 0.0f) { if (attackableEntitiesWithinAttackersBounds[index].AttackWithDamage(DamageType.Projectile, damageValuesArray[index])) { multiAttackResults.Kills++; } else { multiAttackResults.Damages++; } } } return(multiAttackResults); }
public AttackResults AttackWithMelee(IAttackerEntity attackerEntity, float damage) { Rectangle attackerBounds = attackerEntity.AttackerBounds; Point[] attackerPixels = attackerEntity.AttackerPixels; Matrix attackerTransformMatrix = attackerEntity.AttackerTransformMatrix; Point[] attackerTransformedPixels = CollisionHelper.ConvertTexturePixelsToScreenPixels(attackerPixels, attackerTransformMatrix); foreach (IAttackableEntity attackableEntity in attackableEntities) { if (attackableEntity.AttackBounds.Intersects(attackerBounds)) { Boolean[,] attackableBooleans = attackableEntity.AttackBooleans; foreach (Point attackerPixel in attackerTransformedPixels) { Vector2 attackablePixelVector = CollisionHelper.ConvertScreenPixelToTexturePixel( new Vector2((float)attackerPixel.X, (float)attackerPixel.Y), attackableEntity.AttackTransformMatrix); Point attackablePoint = new Point((int)attackablePixelVector.X, (int)attackablePixelVector.Y); if (attackablePoint.X >= 0 && attackablePoint.Y >= 0 && attackablePoint.X < attackableBooleans.GetLength(0) && attackablePoint.Y < attackableBooleans.GetLength(1)) { if (attackableBooleans[attackablePoint.X, attackablePoint.Y]) { if (attackableEntity.AttackWithDamage(DamageType.Melee, damage)) { return(AttackResults.Kill); } else { return(AttackResults.Damage); } } } } } } return(AttackResults.None); }
public override void ReceivedDamage(IAttackerEntity attacker, CombatAmountType damageAmountType, int damage) { var 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) { var 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); // If dead destroy / respawn if (IsDead()) { CurrentHp = 0; if (!IsSummoned) { // If not summoned by someone, destroy and respawn it DestroyAndRespawn(); } } }
public override bool CanReceiveDamageFrom(IAttackerEntity attacker) { if (attacker == null) { return(false); } var 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 another character is not ally assume that it can receive damage return(!IsAlly(characterEntity)); }
public void SetupDamage( IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId, float missileDistance, float missileSpeed, IDamageableEntity lockingTarget) { SetupDamage(attacker, weapon, allDamageAmounts, debuff, hitEffectsId); this.missileDistance = missileDistance; this.missileSpeed.Value = missileSpeed; if (missileDistance <= 0 && missileSpeed <= 0) { NetworkDestroy(); return; } LockingTarget = lockingTarget; NetworkDestroy(missileDistance / missileSpeed); }
public bool CanReceiveDamageFrom(IAttackerEntity attacker) { return(characterEntity.CanReceiveDamageFrom(attacker)); }
public MultiAttackResults AttackWithProjectile(IAttackerEntity attackerEntity, float damage) { IAttackableEntity[] attackableEntitiesWithinAttackersBounds = AttackHelper.AttackableEntitiesWithinAttackersBounds(attackerEntity.AttackerBounds, this.AttackableEntities.ToArray()); float[] damageValuesArray = new float[attackableEntitiesWithinAttackersBounds.Length]; MultiAttackResults multiAttackResults = new MultiAttackResults(); foreach (Point attackersPixel in attackerEntity.AttackerPixels) { Point attackersPixelInScreenCoordinates = CollisionHelper.ConvertTexturePixelToScreenPixel(attackersPixel, attackerEntity.AttackerTransformMatrix); for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++) { IAttackableEntity attackableEntity = attackableEntitiesWithinAttackersBounds[index]; Point attackersPixelInAttackableEntitysTextureCoordinates = CollisionHelper.ConvertScreenPixelToTexturePixel(attackersPixelInScreenCoordinates, attackableEntity.AttackTransformMatrix); if (attackersPixelInAttackableEntitysTextureCoordinates.X >= 0 && attackersPixelInAttackableEntitysTextureCoordinates.Y >= 0) { if (attackersPixelInAttackableEntitysTextureCoordinates.X < attackableEntity.AttackBooleans.GetLength(0) && attackersPixelInAttackableEntitysTextureCoordinates.Y < attackableEntity.AttackBooleans.GetLength(1)) { if (attackableEntity.AttackBooleans[attackersPixelInAttackableEntitysTextureCoordinates.X,attackersPixelInAttackableEntitysTextureCoordinates.Y]) { damageValuesArray[index] += damage; } } } } } for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++) { if (damageValuesArray[index] > 0.0f) { if (attackableEntitiesWithinAttackersBounds[index].AttackWithDamage(DamageType.Projectile, damageValuesArray[index])) { multiAttackResults.Kills++; } else { multiAttackResults.Damages++; } } } return multiAttackResults; }
public AttackResults AttackWithProjectileSingleTarget(IAttackerEntity attackerEntity, float damage) { IAttackableEntity[] attackableEntitiesWithinAttackersBounds = AttackHelper.AttackableEntitiesWithinAttackersBounds(attackerEntity.AttackerBounds, this.AttackableEntities.ToArray()); foreach (Point attackersPixel in attackerEntity.AttackerPixels) { Point attackersPixelInScreenCoordinates = CollisionHelper.ConvertTexturePixelToScreenPixel(attackersPixel, attackerEntity.AttackerTransformMatrix); for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++) { IAttackableEntity attackableEntity = attackableEntitiesWithinAttackersBounds[index]; Point attackersPixelInAttackableEntitysTextureCoordinates = CollisionHelper.ConvertScreenPixelToTexturePixel(attackersPixelInScreenCoordinates, attackableEntity.AttackTransformMatrix); if (attackersPixelInAttackableEntitysTextureCoordinates.X >= 0 && attackersPixelInAttackableEntitysTextureCoordinates.Y >= 0) { if (attackersPixelInAttackableEntitysTextureCoordinates.X < attackableEntity.AttackBooleans.GetLength(0) && attackersPixelInAttackableEntitysTextureCoordinates.Y < attackableEntity.AttackBooleans.GetLength(1)) { if (attackableEntity.AttackBooleans[attackersPixelInAttackableEntitysTextureCoordinates.X,attackersPixelInAttackableEntitysTextureCoordinates.Y]) { if (attackableEntity.AttackWithDamage(DamageType.Projectile, damage)) { return AttackResults.Kill; } else { return AttackResults.Damage; } } } } } } return AttackResults.None; }
public virtual void ReceivedDamage(IAttackerEntity attacker, CombatAmountType combatAmountType, int damage) { this.InvokeInstanceDevExtMethods("ReceivedDamage", attacker, combatAmountType, damage); RequestCombatAmount(combatAmountType, damage); }
public void ReceiveDamage(IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId) { buildingEntity.ReceiveDamage(attacker, weapon, allDamageAmounts, debuff, hitEffectsId); }
public bool CanReceiveDamageFrom(IAttackerEntity attacker) { return(buildingEntity.CanReceiveDamageFrom(attacker)); }
public virtual bool CanReceiveDamageFrom(IAttackerEntity attacker) { return(true); }