示例#1
0
 private void OnEntityTakeDamage(EntityFightable entity, DamageSource dmgSource)
 {
     HookCalled("OnEntityHurt");
     var source = (EntityFightable)GameManager.Instance.World.GetEntity(dmgSource.mdv0007());
     var dmgtype = dmgSource.GetName();
     PrintWarning($"{entity.EntityName} took {dmgtype} damage from {source.EntityName}");
 }
    public void Start()
    {
        _ambassador = (Ambassador) FindObjectOfType(typeof(Ambassador));
        _damageSource = GetComponent<DamageSource>();

        if(_ambassador == null
           || _damageSource == null)
        {
            if(DebugMode)
                Debug.LogWarning("Was unable to find damage source or ambassador!" + Environment.NewLine
                                 + "Ambassador: " + ((_ambassador == null) ? "Not Found" : "Found") + Environment.NewLine
                                 + "Damage Source: " + ((_damageSource == null) ? "Not Found" : "Found"));

            return;
        }

        if(_ambassador.HasItem(ItemName))
        {
            if(DebugMode)
                Debug.Log("This damage trigger can break breakable objects.");

            _damageSource.AffectedTags.AddRange(BreakableItemTags);
        }
        else
        {
            if(DebugMode)
                Debug.Log("This damage trigger can't break breakables.");
        }
    }
    public void ApplyDamage(DamageSource damageSource)
    {
        // Find quadrant of Player that was hit and broadcast that info
        Vector3 hitDir = damageSource.fromPosition - transform.position;
        Vector3 forward = transform.TransformDirection(Vector3.forward);
        Vector3 left = transform.TransformDirection(Vector3.left);

        hitDir.y = 0f; //y distance should not be considered
        float forwardDist = Vector3.Dot(forward, hitDir);
        float sideDist = Vector3.Dot(left, hitDir);

        HurtQuadrant hurtQuad;
        if(Mathf.Abs(forwardDist) > Mathf.Abs(sideDist)) {
            if(forwardDist >= 0) {
                hurtQuad = HurtQuadrant.FRONT;
            } else {
                hurtQuad = HurtQuadrant.BACK;
            }
        } else {
            if(sideDist >= 0) {
                hurtQuad = HurtQuadrant.LEFT;
            } else {
                hurtQuad = HurtQuadrant.RIGHT;
            }
        }

        BroadcastMessage("GotHurtQuadrant", (int)hurtQuad);

        dataController.current -= damageSource.damageAmount;
        DeathCheck();
    }
示例#4
0
    public void TakeDamage(DamageSource damageSource)
    {
        if (Time.time > m_LastHitTime + m_InvicibilityTime)
        {
            //Si le joueur a toujours de la vie
            if (Health > 0f)
            {
                m_Damaged = true;
                // ... prends des dégat et reset le temps du dernier coup pris
                // Creer un vecteur de l'enemi jusqu'au joueur plus un boost up
                Vector3 hurtVector = transform.position - damageSource.transform.position + Vector3.up * 5f;

                // Ajoute une force en direction du vecteur multiplié par la force de dégats
                m_RigidBody.AddForce(hurtVector * damageSource.hurtForce);

                // Réduit la vie du joueur de 10
                m_Health -= damageSource.damage;

                m_LastHitTime = Time.time;

                if (m_Health <= 0)
                {
                    //m_Manager.Death();
                }
            }
        }
    }
	//Events

    void Awake()
    {
        //Get the damageSrc
        damageSrc = GetComponent<DamageSource>();

        //Pre-compute the animation stages
        readyPos = transform.localPosition;
        readyRot = transform.localRotation;

        //Calculate the swing start and end positions
        float midAngle = 90f * Mathf.Deg2Rad;
        float halfAngle = Mathf.Deg2Rad * (swingAngle / 2);

        float startAngle = midAngle - halfAngle;
        float endAngle = midAngle + halfAngle;

        swingStartPos = new Vector3(Mathf.Cos(startAngle), 0, Mathf.Sin(startAngle)) * swingDistance;
        swingEndPos = new Vector3(Mathf.Cos(endAngle), 0, Mathf.Sin(endAngle)) * swingDistance;

        //Calculate start and end rotations
        swingStartRot = Quaternion.Euler(90, swingAngle / 2, 0);
        swingEndRot = Quaternion.Euler(90, -swingAngle / 2, 0);

        //Set up the state machine
        stateMethods.Add(State.ready, WhileReady);
        stateMethods.Add(State.swinging, WhileSwinging);
        stateMethods.Add(State.recovering, WhileRecovering);
        stateMethods.Add(State.swappedOut, WhileSwappedOut);
    }
示例#6
0
    private void DamageBreak(DamageSource src)
    {
        if (!isReady) return;
        isReady = false;

        src.transform.position = toWarp;
        WarpField ().StartBy (this);
    }
    public virtual bool CanBeHurtBy(DamageSource src)
    {
        //Returns if this object can be hurt by the given source, taking into account both the vulnerability lists, the ignore list, and the cooldown state.

        return (!isCoolingDown) &&
            (!src.ignoreList.Contains(this)) &&
            (!ignoreList.Contains(src)) &&
            IsVulnerableTo(src);
    }
    public abstract void DealDamage(float amount);    //Deals the given amount of damage.  Different implementations can have different ways of handling this.
                                                    //Must broadcast the "OnTakeDamage" message.

    public virtual void AttackFrom(DamageSource src)
    {
        //Gets this object attacked by src.  Deals damage if vulnerable.
        if (CanBeHurtBy(src))
        {
            DealDamage(src.damageAmount);
            src.BroadcastMessage("OnDealDamage", SendMessageOptions.DontRequireReceiver);
        }
    }
示例#9
0
 public void Hit(DamageSource source)
 {
     int power = source.GetPower ();
     if (IsDamaging()){
         print(power + " damage to player, but nodamage");
         return;
     }
     Damage (source);
 }
示例#10
0
 protected virtual void Damage(DamageSource source)
 {
     int power = source.GetPower ();
     print (power + " damage to Player!");
     controller.transform.rotation = Quaternion.LookRotation (source.GetDirection());
     animator.SetTrigger ("damage_trig");
     hp -= power;
     hp = Mathf.Max (0, hp);
 }
    //Public methods
    public void CopyDataTo(DamageSource target)
    {
        //Copies the damage tags, ignoreList, and damage amount to the target DamageSource.
        //isHot and useDefaultHitDetection are NOT copied over.

        target.tags = new List<DamageTag>(tags);
        target.ignoreList = new List<AbstractHealthPoints>(ignoreList);
        target.damageAmount = damageAmount;
    }
示例#12
0
    public void OnTriggerEnter(Collider who)
    {
        if (who.tag != AffectedTag)
        {
            return;
        }

        DamageSource weapon = who.gameObject.GetComponentInChildren <DamageSource>();

        weapon.AffectedTags.Add(ConferWeaponTag);
    }
示例#13
0
文件: Damage.cs 项目: c2001324/Leo
 /// <summary>
 /// 是否为同一个伤害来源
 /// </summary>
 public static bool IsSameDamageSource(DamageSource source, DamageSource otherSource)
 {
     if (source == DamageSource.All || otherSource == DamageSource.All)
     {
         return(true);
     }
     else
     {
         return(source == otherSource);
     }
 }
    void checkDamageTrigger(Collider2D col)
    {
        DamageSource dmg = col.gameObject.GetComponent <DamageSource>();

        if (alive && dmg != null && dmg.type != DamageSource.damageTypes.toEnvironment)
        {
            ApplyDamage(dmg.damageAmount);
            Debug.Log("Health: " + health.Value);
            hitSound.Play();
        }
    }
示例#15
0
 /// <summary>
 /// Returns the defense based on the source of the damage.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="stats"></param>
 /// <returns></returns>
 public static int GetDefense(DamageSource source, BaseStats stats)
 {
     if ((source & DamageSource.Magic) != 0)
     {
         return(stats.resistance);
     }
     else
     {
         return(stats.defense);
     }
 }
示例#16
0
 /// <summary>
 /// Returns the base damage output based on the source of the damage.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="stats"></param>
 /// <returns></returns>
 public static int GetDamage(DamageSource source, BaseStats stats)
 {
     if ((source & DamageSource.Magic) != 0)
     {
         return(stats.magic);
     }
     else
     {
         return(stats.strength);
     }
 }
示例#17
0
        public List <BossEnemy> GetBossEnemies(int roomID)
        {
            List <BossEnemy> bosses = new List <BossEnemy>();


            using (SqlConnection connection = new SqlConnection(conn))
            {
                connection.Open();
                using (SqlCommand cmd = new SqlCommand("SELECT X, Y, SoortSpecialATK, DMGspecialATK, Attack, AttackPointsPerAttack, SpecialATKCooldown, MovePointsPerMove, Defence, Health, Levels FROM BossEnemies WHERE RoomID = @roomID", connection))
                {
                    cmd.Connection = connection;
                    cmd.Parameters.Add("@roomID", SqlDbType.Int).Value = roomID;
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int          x = reader.GetInt32(0);
                            int          y = reader.GetInt32(1);
                            DamageSource enemyDamageSource  = DamageSource.Physical; //default damage type
                            int          DMGspecialATK      = reader.GetInt32(3);
                            int          Attack             = reader.GetInt32(4);
                            int          ATKpointsPerAttack = reader.GetInt32(5);
                            double       ATKpointsRegen     = Math.Round((Convert.ToDouble(ATKpointsPerAttack) / 5) + 1);
                            int          SpecialATKcooldown = reader.GetInt32(6);
                            int          MovePointsPerMove  = reader.GetInt32(7);
                            int          Defence            = reader.GetInt32(8);
                            int          Health             = reader.GetInt32(9);
                            int          Levels             = reader.GetInt32(10);

                            string damageSource = reader.GetString(2);
                            switch (damageSource)
                            {
                            case "Cold":
                                enemyDamageSource = DamageSource.Cold;
                                break;

                            case "Fire":
                                enemyDamageSource = DamageSource.Fire;
                                break;

                            case "Physical":
                                enemyDamageSource = DamageSource.Physical;
                                break;
                            }

                            BossEnemy boss = new BossEnemy(x, y, DMGspecialATK, enemyDamageSource, Attack, SpecialATKcooldown, ATKpointsPerAttack, Convert.ToInt32(ATKpointsRegen), Defence, MovePointsPerMove, Health, Levels);
                            boss.Soort = Soort.Boss;
                            bosses.Add(boss);
                        }
                    }
                }
            }
            return(bosses);
        }
示例#18
0
    public void Hit(DamageSource source)
    {
        int power = source.GetPower();

        if (IsDamaging())
        {
            print(power + " damage to player, but nodamage");
            return;
        }
        Damage(source);
    }
示例#19
0
 protected virtual void OnHit(Collider collider)
 {
     if (collider.tag == TagName.Player.String())
     {
         isHit = true;
         DamageSource damage = new DamageSource(collider.ClosestPoint(this.transform.position),
                                                power, holderEnemyAI);
         PlayerAction player = collider.GetComponent <PlayerAction>();
         Assert.IsNotNull(player, "PlayerActionが取得できませんでした。");
         player.OnHit(damage);
     }
 }
示例#20
0
        public List <HumanEnemy> GetHumanEnemies(int roomID)
        {
            List <HumanEnemy> humanEnemies = new List <HumanEnemy>();

            using (SqlConnection connection = new SqlConnection(conn))
            {
                connection.Open();
                using (SqlCommand cmd = new SqlCommand("SELECT X, Y, CritChance, Attack, AttackPointsPerAttack, AttackPointsRegen, MovePointsPerMove, Defence, Health, Levels FROM HumanEnemies WHERE RoomID = @roomID", connection))
                {
                    cmd.Connection = connection;
                    cmd.Parameters.Add("@roomID", SqlDbType.Int).Value = roomID;
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int          x                  = reader.GetInt32(0);
                            int          y                  = reader.GetInt32(1);
                            int          critChance         = reader.GetInt32(2);
                            DamageSource enemyDamageSource  = DamageSource.Physical; //default damage type
                            int          Attack             = reader.GetInt32(3);
                            int          ATKpointsPerAttack = reader.GetInt32(4);
                            int          ATKpointsRegen     = reader.GetInt32(5);
                            int          MovePointsPerMove  = reader.GetInt32(6);
                            int          Defence            = reader.GetInt32(7);
                            int          Health             = reader.GetInt32(8);
                            int          Levels             = reader.GetInt32(9);



                            // For later expansion.
                            //string damageSource = reader.GetString(7);
                            //switch (damageSource)
                            //{
                            //    case "Cold":
                            //        enemyDamageSource = DamageSource.Cold;
                            //        break;
                            //    case "Fire":
                            //        enemyDamageSource = DamageSource.Fire;
                            //        break;
                            //    case "Physical":
                            //        enemyDamageSource = DamageSource.Physical;
                            //        break;
                            //}

                            HumanEnemy Human = new HumanEnemy(x, y, enemyDamageSource, Attack, ATKpointsPerAttack, ATKpointsRegen, critChance, Defence, MovePointsPerMove, Health, Levels);
                            Human.Soort = Soort.Human;
                            humanEnemies.Add(Human);
                        }
                    }
                }
            }
            return(humanEnemies);
        }
示例#21
0
 public void TakeDamage(int amount, DamageSource source)
 {
     if (damageSources[source])
     {
         damageSources[source] = false;
         life -= amount;
         if (life == 0)
         {
             disc.Die(false);
         }
     }
 }
示例#22
0
        void OnTriggerEnter2D(Collider2D coll)
        {
            DamageSource damageSource = coll.GetComponent <DamageSource>();

            if (damageSource)
            {
                if (damageTags.Contains(damageSource.Source))
                {
                    eventManager.TriggerEvent(EnemyEvents.OnRoll, new ParamsObject(coll.attachedRigidbody.velocity));
                }
            }
        }
        protected DamageModifier(string name, string tooltip, DamageSource damageSource, double gainPerStack, DamageType srctype, DamageType compareType, ModifierSource src, string url, GainComputer gainComputer, DamageLogChecker dlChecker, ulong minBuild, ulong maxBuild)
        {
            Tooltip      = name + " - " + tooltip;
            Name         = name;
            _dmgSrc      = damageSource;
            GainPerStack = gainPerStack;
            _compareType = compareType;
            _srcType     = srctype;
            Src          = src;
            Url          = url;
            GainComputer = gainComputer;
            DLChecker    = dlChecker;
            MaxBuild     = maxBuild;
            MinBuild     = minBuild;
            switch (_dmgSrc)
            {
            case DamageSource.All:
                Tooltip += "<br>Actor + Minions";
                break;

            case DamageSource.NoPets:
                Tooltip += "<br>No Minions";
                break;
            }
            switch (_srcType)
            {
            case DamageType.All:
                Tooltip += "<br>All Damage type";
                break;

            case DamageType.Power:
                Tooltip += "<br>Power Damage only";
                break;

            case DamageType.Condition:
                Tooltip += "<br>Condition Damage only";
                break;
            }
            switch (_compareType)
            {
            case DamageType.All:
                Tooltip += "<br>Compared against All Damage";
                break;

            case DamageType.Power:
                Tooltip += "<br>Compared against Power Damage";
                break;

            case DamageType.Condition:
                Tooltip += "<br>Compared against Condition Damage";
                break;
            }
        }
    public override int DamageEntity(DamageSource _damageSource, int _strength, bool _criticalHit, float _impulseScale)
    {
        // If we are being attacked, let the state machine know it can fight back
        this.emodel.avatarController.SetBool("IsBusy", false);

        // Turn off the trader ID while it deals damage to the entity
        ToggleTraderID(false);
        int Damage = base.DamageEntity(_damageSource, _strength, _criticalHit, _impulseScale);

        ToggleTraderID(true);
        return(Damage);
    }
示例#25
0
 protected void Damage(DamageSource damageSource)
 {
     if (isDead)
         return;
     print (damageSource.GetPower () + " damage to enemy");
     hp -= damageSource.GetPower ();
     if(hp <= 0){
         hp = 0;
         isDead = true;
         Death();
     }
 }
示例#26
0
        private void OnPlayerDeath(IServerPlayer player, DamageSource damageSource)
        {
            var placeForGrave = DetermineGraveSpot(player);

            _serverApi.World.BlockAccessor.BreakBlock(placeForGrave, player);
            _serverApi.World.BlockAccessor.SetBlock(_graveBlock.BlockId, placeForGrave);

            if (_serverApi.World.BlockAccessor.GetBlockEntity(placeForGrave) is GraveBlockEntity graveEntity)
            {
                PlaceItemsInGrave(player, graveEntity);
            }
        }
示例#27
0
    public void TakeDamage(DamageSource damage)
    {
        int   totalDmg = damage.damageValue;
        float distance = damage.transform.position.x - transform.position.x;

        if (anim)
        {
            anim.SetFloat("damageSide", distance);
        }
        //calcular dano
        ComputateDamage(totalDmg);
    }
示例#28
0
 public override int DamageEntity(DamageSource _damageSource, int _strength, bool _criticalHit, float impulseScale)
 {
     if (base.GetRevengeTarget() == null && _damageSource.getEntityId() != -1)
     {
         EntityAlive entityAlive = this.world.GetEntity(_damageSource.getEntityId()) as EntityAlive;
         if (entityAlive != null && entityAlive.IsCrouching && (_damageSource.GetDamageType() == EnumDamageTypes.Piercing || _damageSource.GetDamageType() == EnumDamageTypes.Bashing || _damageSource.GetDamageType() == EnumDamageTypes.Slashing || _damageSource.GetDamageType() == EnumDamageTypes.Crushing))
         {
             _damageSource.DamageMultiplier = Constants.cSneakDamageMultiplier;
         }
     }
     return(base.DamageEntity(_damageSource, _strength, _criticalHit, impulseScale));
 }
示例#29
0
        public override void OnEntityHurt(DamageSource source, float damage)
        {
            base.OnEntityHurt(source, damage);

            if (targetEntity == source.SourceEntity || !active)
            {
                lastHurtByTargetTotalMs = entity.World.ElapsedMilliseconds;
                float dist = targetEntity == null ? 0 : (float)targetEntity.ServerPos.DistanceTo(entity.ServerPos);
                //Console.WriteLine("max of {0} and {1}", tacticalRetreatRange, (int)dist + 15);
                tacticalRetreatRange = Math.Max(tacticalRetreatRange, dist + 15);
            }
        }
示例#30
0
 private void OnTriggerEnter(Collider other)
 {
     //プレイヤーと当たったらプレイヤーにダメージ
     if (TagNameManager.Equals(other.tag, TagName.Player))
     {
         //衝突したときの最近点を衝突点とする
         Vector3      hitPos = other.ClosestPointOnBounds(this.transform.position);
         DamageSource damage = new DamageSource(hitPos, power, holderObjectDamagable);
         //相手に当たったと通知
         other.gameObject.GetComponent <IDamageable>().OnHit(damage);
     }
 }
        public void Check()
        {
            if (entity is EntityPlayer)
            {
                EntityPlayer plr  = (EntityPlayer)entity;
                EnumGameMode mode = entity.World.PlayerByUid(plr.PlayerUID).WorldData.CurrentGameMode;
                if (mode == EnumGameMode.Creative || mode == EnumGameMode.Spectator)
                {
                    return;
                }
            }

            BlockPos pos = new BlockPos(
                (int)(entity.ServerPos.X + entity.LocalEyePos.X),
                (int)(entity.ServerPos.Y + entity.LocalEyePos.Y),
                (int)(entity.ServerPos.Z + entity.LocalEyePos.Z)
                );

            Block block = entity.World.BlockAccessor.GetBlock(pos);

            Cuboidf[] collisionboxes = block.GetCollisionBoxes(entity.World.BlockAccessor, pos);

            Cuboidf box = new Cuboidf();

            if (collisionboxes == null)
            {
                return;
            }

            for (int i = 0; i < collisionboxes.Length; i++)
            {
                box.Set(collisionboxes[i]);
                box.OmniGrowBy(-padding);
                tmp.Set(pos.X + box.X1, pos.Y + box.Y1, pos.Z + box.Z1, pos.X + box.X2, pos.Y + box.Y2, pos.Z + box.Z2);
                box.OmniGrowBy(padding);

                if (tmp.Contains(entity.ServerPos.X + entity.LocalEyePos.X, entity.ServerPos.Y + entity.LocalEyePos.Y, entity.ServerPos.Z + entity.LocalEyePos.Z))
                {
                    Cuboidd EntitySuffocationBox = entity.CollisionBox.ToDouble();

                    if (tmp.Intersects(EntitySuffocationBox))
                    {
                        DamageSource dmgsrc = new DamageSource()
                        {
                            Source = EnumDamageSource.Block, SourceBlock = block, Type = EnumDamageType.Suffocation
                        };
                        entity.ReceiveDamage(dmgsrc, 1f);
                        break;
                    }
                }
            }
        }
示例#32
0
    void GameOverOnKilled(DamageSource source)
    {
        Debug.Log("Game over mon!");
        Destroy(astronautDamageable.gameObject);


        GameObject go = Instantiate(deathPrefab);

        go.transform.localRotation = astronautDamageable.transform.localRotation;
        go.transform.position      = astronautDamageable.transform.position;

        UIManager.instance.PresentGameOver();
    }
示例#33
0
    /// <summary>
    /// ノックバックされる
    /// </summary>
    public void BeKnockedBack(DamageSource damageSource)
    {
        if (state == PlayerState.KnockBack)
        {
            return;
        }

        state = PlayerState.KnockBack;

        AudioManager.Instance.PlayPlayerSE(AudioName.bougyouke.String());

        StartCoroutine(PlayerKockBack(damageSource));
    }
示例#34
0
    public void AddBlock(object key, DamageType damageType, DamageSource damageSource, CheckDamageDelegate handle)
    {
        BlockData data = new BlockData(damageType, damageSource, handle);

        if (m_BlockDatas.ContainsKey(key))
        {
            m_BlockDatas[key] = data;
        }
        else
        {
            m_BlockDatas.Add(key, data);
        }
    }
示例#35
0
        public override bool ReceiveDamage(DamageSource damageSource, float damage)
        {
            if (damageSource.Source == EnumDamageSource.Internal && damageSource.Type == EnumDamageType.Fire)
            {
                fireDamage += damage;
            }
            if (fireDamage > 4)
            {
                Die();
            }

            return(base.ReceiveDamage(damageSource, damage));
        }
    public bool Damage(int baseDamage, Transform origin, DamageSource source)
    {
        if (IsImmune(source))
        {
            return(false);
        }
        if (isInvinsible)
        {
            return(false);
        }

        return(TakeDamage(baseDamage, origin, source));
    }
示例#37
0
        public override void OnEntityReceiveDamage(DamageSource damageSource, float damage)
        {
            if (damageSource.Type == EnumDamageType.Heal && damageSource.Source == EnumDamageSource.Respawn)
            {
                SaturationLossDelayFruit     = 60;
                SaturationLossDelayVegetable = 60;
                SaturationLossDelayProtein   = 60;
                SaturationLossDelayGrain     = 60;
                SaturationLossDelayDairy     = 60;

                Saturation = MaxSaturation / 2;
            }
        }
示例#38
0
        public override void OnEntityReceiveDamage(DamageSource damageSource, float damage)
        {
            damage = onDamaged(damage, damageSource);

            if (damageSource.Type == EnumDamageType.Heal)
            {
                if (damageSource.Source != EnumDamageSource.Revive)
                {
                    damage *= Math.Max(0, entity.Stats.GetBlended("healingeffectivness"));
                    Health  = Math.Min(Health + damage, MaxHealth);
                }
                else
                {
                    damage  = Math.Min(damage, MaxHealth);
                    damage *= Math.Max(0.33f, entity.Stats.GetBlended("healingeffectivness"));
                    Health  = damage;
                }

                entity.OnHurt(damageSource, damage);
                UpdateMaxHealth();
                return;
            }

            if (!entity.Alive)
            {
                return;
            }



            Health -= damage;
            entity.OnHurt(damageSource, damage);
            UpdateMaxHealth();

            if (Health <= 0)
            {
                Health = 0;

                entity.Die(
                    EnumDespawnReason.Death,
                    damageSource
                    );
            }
            else
            {
                if (damage > 1f)
                {
                    entity.AnimManager.StartAnimation("hurt");
                }
            }
        }
示例#39
0
        public override void OnEntityReceiveDamage(DamageSource damageSource, float damage)
        {
            if (damageSource.Type == EnumDamageType.Heal)
            {
                Health = Math.Min(Health + damage, MaxHealth);
                entity.OnHurt(damageSource, damage);
                UpdateMaxHealth();
                return;
            }

            if (!entity.Alive)
            {
                return;
            }

            Health -= damage;
            entity.OnHurt(damageSource, damage);
            UpdateMaxHealth();

            if (Health <= 0)
            {
                Health = 0;
                entity.Die(
                    EnumDespawnReason.Death,
                    damageSource
                    );

                float  lengthHalf = entity.CollisionBox.X2 - entity.CollisionBox.X1;
                float  height     = entity.CollisionBox.Y2;
                Random rnd        = entity.World.Rand;

                entity.World.SpawnParticles(30,
                                            ColorUtil.ToRgba(100, 255, 255, 255),
                                            entity.Pos.XYZ.SubCopy(lengthHalf, 0, lengthHalf),
                                            entity.Pos.XYZ.AddCopy(lengthHalf, height, lengthHalf),
                                            new Vec3f(0, 0, 0),
                                            new Vec3f(2 * (float)rnd.NextDouble() - 1f, 2 * (float)rnd.NextDouble() - 1f, 2 * (float)rnd.NextDouble() - 1f),
                                            1f,
                                            -0.1f,
                                            1f,
                                            EnumParticleModel.Quad
                                            );
            }
            else
            {
                if (damage > 1f)
                {
                    entity.StartAnimation("hurt");
                }
            }
        }
示例#40
0
 public HumanEnemy(int x, int y, DamageSource enemyDamageSource, int Attack, int ATKpointsPerAttack, int ATKpointsRegen, int CritChance, int Defence, int MovePointsPerMove, int Health, int Level)
 {
     X                      = x;
     Y                      = y;
     DamageSource           = enemyDamageSource;
     this.Attack            = Attack;
     AttackPointsPerAttack  = ATKpointsPerAttack;
     AttackPointsRegen      = ATKpointsRegen;
     this.CritChance        = CritChance;
     this.Defence           = Defence;
     this.MovePointsPerMove = MovePointsPerMove;
     this.Health            = Health;
     this.Level             = Level;
 }
        public override void OnEntityReceiveDamage(DamageSource damageSource, float damage)
        {
            base.OnEntityReceiveDamage(damageSource, damage);

            if (damageSource.Type == EnumDamageType.Heal)
            {
                return;
            }

            for (int i = 0; i < modifiers.Count; i++)
            {
                modifiers[i].OnHurt(damage);
            }
        }
示例#42
0
        //----------------------------------------------------------------------------
        //             AddDamage
        //----------------------------------------------------------------------------

        #region AddDamage
        /// <summary>
        /// Wrapper function for adding an element to the damage dictionary
        /// </summary>
        public void AddDamage(float value, DamageType damageType, DamageSource damageSource)
        {
            SingleDamageID damageID = new SingleDamageID(damageType, damageSource);


            if (!MyDamageDict.ContainsKey(damageID))
            {
                MyDamageDict[damageID] = value;
            }
            else
            {
                MyDamageDict[damageID] += value;
            }
        }
示例#43
0
    /// <summary>
    /// Adds destroyed ship. If there wasn't ship with this name - function creates a new <see cref="ShipsStatistics"> class. Else it just adds one to destroyed quantity.
    /// </summary>
    /// <param name="shipName">
    /// A <see cref="System.String"/> name of ship that was destroyed.
    /// </param>
    /// <param name="deathSource">
    /// A <see cref="DamageSource"/> info, about a source of damage that destroyed the ship.
    /// </param>
    public void AddDestroyedShip(string shipName, DamageSource deathSource)
    {
        if (deathSource == DamageSource.Player || deathSource == DamageSource.Self || deathSource == DamageSource.FriendlyShip) {
            numberOfDestroyedShips++;

            foreach (ShipsStatistics shipsstats in shipsStatistics) {
                if (shipsstats.name.Equals (shipName)) {
                    shipsstats.quantity++;
                    return;
                }
            }

            ShipsStatistics newShipStatistics = new ShipsStatistics ();
            shipsStatistics.Add (newShipStatistics);
            newShipStatistics.name = shipName;
        }
    }
示例#44
0
 void OnCollisionEnter(Collision collisionInfo)
 {
     Damageable damageable = collisionInfo.transform.GetComponent<Damageable>();
     if (damageable != null)
     {
         DamageSource damageSource = new DamageSource();
         damageSource.appliedToPosition = collisionInfo.contacts[0].point;
         damageSource.damageAmount = damageAmount;
         damageSource.fromPosition = transform.position;
         damageSource.hitCollider = collisionInfo.collider;
         damageSource.sourceObjectType = DamageSource.DamageSourceObjectType.Player;
         damageSource.sourceType = DamageSource.DamageSourceType.GunFire;
         damageable.ApplyDamage(damageSource);
     }
     Destroy(gameObject);
     if (explotionPrefab != null) GameObject.Instantiate(explotionPrefab, transform.position, Quaternion.identity);
 }
示例#45
0
 /*
 public override void CatchBullet (BulletProperties bulletProperties)
 {
     if (bulletProperties.master == levelProperties.playerController.shipMotor) {
         DamageShip (bulletProperties.baseDamage, DamageSource.Player);
     } else if (bulletProperties.master == levelProperties.playerController.shipMotor) {
         DamageShip (bulletProperties.baseDamage, DamageSource.Enviroment);
     }
 }*/
 public void DamageShip(float damageAmount, DamageSource source)
 {
     foreach (HullSlot slot in properties.equipmentList.hullSlots) {
         if (slot.mountedEquipmentUnit != null) {
             ((TypicalHull)slot.mountedEquipmentUnit).ResetShieldRegenTimeStamp ();
         }
     }
     if (currentSP > 0) {
         if (damageAmount < currentSP) {
             currentSP -= damageAmount;
             damageAmount = 0;
         } else {
             damageAmount -= currentSP;
             currentSP = 0;
         }
     }
     currentHP -= damageAmount;
     if (currentHP <= 0) {
         transform.parent.GetComponent<ShipController> ().DestroyShip (source);
     }
 }
    //Interface
    public virtual bool IsVulnerableTo(DamageSource src)
    {
        //Returns if this object is vulnerable to the given damage source according to only the vulnerability lists.

        //If the src's tags are empty, log a warning and return true.
        if (src.tags.Count <= 0)
        {
            Debug.LogError("ERROR: " + src.name + "'s damage source has no DamageTags.  Please fix this.");
        }

        //If the vulnerable list has something in it, then the src must contain one of tags in vulnerableTo
        if (vulnerableTo.Count > 0)
        {
            //Return true if there was atleast one match
            foreach (DamageTag tag in src.tags)
            {
                if (vulnerableTo.Contains(tag))
                {
                    return true;
                }
            }

            //If there were no matches, return false.
            return false;
        }

        //If the vulernableTo list is empty, then src must contain one tag that *isn't* on the invulnerableTo list.
        foreach(DamageTag tag in src.tags)
        {
            //Return true if this tag isn't there
            if (!invulnerableTo.Contains(tag))
            {
                return true;
            }
        }

        //If all of the tags are on the invulnerableTo list, return false.
        return false;
    }
示例#47
0
    private Rigidbody2D rigidBody2D; //Référence au rigidbody

    #endregion Fields

    #region Methods

    //Fonction public appelé lors d'une prise de dégat
    public void TakeDamage(DamageSource damageSource)
    {
        if (Time.time > lastHitTime + invicibilityTime)
        {
            //Si le joueur a toujours de la vie
            if (health > 0f)
            {
                // ... prends des dégat et reset le temps du dernier coup pris
                // Creer un vecteur de l'enemi jusqu'au joueur plus un boost up
                Vector3 hurtVector = transform.position - damageSource.transform.position + Vector3.up * 5f;

                // Ajoute une force en direction du vecteur multiplié par la force de dégats
                rigidBody2D.AddForce(hurtVector * damageSource.hurtForce);

                // Réduit la vie du joueur de 10
                health -= damageSource.damage;

                // Update la barre de vie
                UpdateHealthBar();
                lastHitTime = Time.time;
            }
        }
    }
示例#48
0
 public override void Selfdestruct(DamageSource source)
 {
     SendMessage ("ShipDestroyed", source, SendMessageOptions.DontRequireReceiver);
     Destroy (gameObject);
 }
示例#49
0
    // Hit by something
    protected void OnCollisionEnter(Collision collision)
    {
        float damage = collision.relativeVelocity.magnitude;

        // Take collider damage? (fall damage, etc)
        if(takeCollideDamage && damage > collideDamageThreshold) {
            DamageSource damageSource = new DamageSource();
            damageSource.damageAmount = damage - collideDamageThreshold;
            damageSource.fromPosition = collision.transform.position;
            damageSource.appliedToPosition = collision.transform.position;
            damageSource.sourceObject = collision.gameObject;
            damageSource.sourceObjectType = DamageSource.DamageSourceObjectType.Obstacle;
            damageSource.sourceType = DamageSource.DamageSourceType.StaticCollision;
            ApplyDamage(damageSource);
        }
    }
示例#50
0
 public DamageNature(List<string> keywords)
 {
     foreach (string word in keywords)
     {
         if (Forms.ContainsKey(word)) Form |= Forms[word];
         if (Weapon.Types.ContainsKey(word)) WeaponType = Weapon.Types[word];
         if (Sources.ContainsKey(word)) Source = Sources[word];
     }
 }
示例#51
0
 public bool Is(DamageSource source)
 {
     return Source == source;
 }
示例#52
0
 public DamageNature(DamageSource source, DamageType type)
 {
     Source = source;
     Type = type;
 }
示例#53
0
            public DamageNature(DamageSource source, string str)
            {
                Source = source;

                string[] words = str.Split(' ');
                foreach (string word in words)
                {
                    if (Forms.ContainsKey(word)) Form |= Forms[word];
                    if (Types.ContainsKey(word)) Type = Types[word];
                    if (Weapon.Types.ContainsKey(word)) WeaponType = Weapon.Types[word];
                    if (Sources.ContainsKey(word)) Source = Sources[word];
                }
            }
示例#54
0
 public DamageNature(DamageNature nature)
 {
     Form = nature.Form;
     Source = nature.Source;
     Type = nature.Type;
     WeaponHand = nature.WeaponHand;
     WeaponType = nature.WeaponType;
 }
示例#55
0
            public DamageNature(DamageNature nature, string str)
            {
                Form = nature.Form;
                Source = nature.Source;
                Type = nature.Type;
                WeaponHand = nature.WeaponHand;
                WeaponType = nature.WeaponType;

                string[] words = str.Split(' ');
                foreach (string word in words)
                {
                    if (Forms.ContainsKey(word)) Form |= Forms[word];
                    if (Types.ContainsKey(word)) Type = Types[word];
                    if (Weapon.Types.ContainsKey(word)) WeaponType = Weapon.Types[word];
                    if (Sources.ContainsKey(word)) Source = Sources[word];
                }
            }
示例#56
0
 // Damage from specified source with specified type.
 public Damage(DamageSource source, DamageType type, float min, float max)
     : base(source, type)
 {
     Origin = new DamageNature(Source, Type);
     Min = min;
     Max = max;
 }
示例#57
0
 public Increased(DamageSource source, string type, float percent)
     : base(source, type)
 {
     Percent = percent;
 }
示例#58
0
                // Creates added damage from weapon local mod.
                public static Added Create(DamageSource source, ItemMod itemMod)
                {
                    Match m = ReAddMod.Match(itemMod.Attribute);
                    if (m.Success)
                        return new Added(source, m.Groups[1].Value, itemMod.Value[0], itemMod.Value[1]);
                    else
                    {
                        m = ReAddInHandMod.Match(itemMod.Attribute);
                        if (m.Success)
                            return new Added(source, m.Groups[1].Value, itemMod.Value[0], itemMod.Value[1]) { Hand = m.Groups[2].Value == "Main" ? WeaponHand.Main : WeaponHand.Off };
                    }

                    return null;
                }
示例#59
0
                // Creates added damage.
                public static Added Create(DamageSource source, KeyValuePair<string, List<float>> attr)
                {
                    Match m = ReAddMod.Match(attr.Key);
                    if (m.Success)
                        return new Added(source, m.Groups[1].Value, attr.Value[0], attr.Value[1]);
                    else
                    {
                        m = ReAddWithBows.Match(attr.Key);
                        if (m.Success)
                        {
                            return new Added(DamageSource.Attack, m.Groups[1].Value, attr.Value[0], attr.Value[1]) { WeaponType = WeaponType.Bow };
                        }
                    }

                    return null;
                }
示例#60
0
 public Added(DamageSource source, string type, float min, float max)
     : base()
 {
     Source = source;
     Type = DamageNature.TypeOf(type);
     Min = min;
     Max = max;
 }