示例#1
0
文件: Sprite.cs 项目: yc322/MMORPG
        // the enemy is null if not exists one
        public override void OnHit(Creature enemy, int hpDec)
        {
            if (currentHP == 0)
            {
                return;
            }

            if (IsInvulnerable())
            {
                return;
            }

            // TODO calculate hit point decrease by creature's attribute
            hpDec = currentHP - hpDec < 0 ? currentHP : hpDec;
            SHit hit = new SHit();

            hit.decHP    = hpDec;
            hit.sourceId = enemy != null ? enemy.entityId : 0;
            hit.targetId = this.entityId;
            Broadcast(hit);
            currentHP = currentHP - hpDec;
            if (currentHP == 0)
            {
                OnDie();
                World.Instance.DelayInvoke(20, OnReSpawn);
            }
            else
            {
                EnemyClosing(enemy);
            }
        }
示例#2
0
        private void OnRecvHit(IChannel channel, Message message)
        {
            SHit msg = message as SHit;

            NetworkEntity target = networkEntities[msg.targetId];
            NetworkEntity source = null;

            if (msg.sourceId != 0)
            {
                source = networkEntities[msg.sourceId];
            }

            if (source.behavior == null)
            {
                return;
            }

            ICreatureBehavior srcBehavior = source == null ? null : source.behavior;
            ICreatureBehavior tarBehavior = target.behavior;

            tarBehavior.BeHit(msg.decHP, srcBehavior);

            if (target.entityId == World.Instance.selfId && source.entityType == EntityType.PLAYER)
            {
                World.Instance.setDeathId(source.entityId);
            }
            else
            {
                World.Instance.setDeathId(-1);
            }
        }
示例#3
0
文件: Player.cs 项目: qxlllll/MMORPG
        override public void OnHit(Creature enemy, int hpDec)
        {
            if (currentHP == 0)
            {
                return;
            }

            if (IsInvulnerable())
            {
                return;
            }

            m_lastHitTS = DateTime.Now;
            hpDec       = currentHP - hpDec < 0 ? currentHP : hpDec;

            SHit hit = new SHit();

            hit.decHP    = hpDec;
            hit.sourceId = enemy != null ? enemy.entityId : 0;
            hit.targetId = this.entityId;
            Broadcast(hit);

            currentHP = currentHP - hpDec;
            if (currentHP == 0)
            {
                OnDie();
                World.Instance.DelayInvoke(5, OnReSpawn);
            }
        }
示例#4
0
        override public void OnHit(Creature enemy, int hpDec)
        {
            lock (hitLock)
            {
                if (currentHP == 0)
                {
                    return;
                }

                if (IsInvulnerable())
                {
                    return;
                }

                m_lastHitTS = DateTime.Now;

                // use defence attribute
                hpDec = (int)Math.Ceiling((double)hpDec * 100d / ((double)attr_defence + 100d));

                hpDec = currentHP - hpDec < 0 ? currentHP : hpDec;

                SHit hit = new SHit();
                hit.decHP    = hpDec;
                hit.sourceId = enemy != null ? enemy.entityId : 0;
                hit.targetId = this.entityId;
                Broadcast(hit);

                currentHP = currentHP - hpDec;
                if (currentHP == 0)
                {
                    if (enemy.entityType == EntityType.PLAYER)
                    {
                        BeatPlayer((Player)enemy, this);
                    }
                    OnDie();
                    World.Instance.DelayInvoke(5, OnReSpawn);
                }
            }
        }
示例#5
0
        private void OnRecvHit(IChannel channel, Message message)
        {
            SHit msg = message as SHit;

            NetworkEntity target = networkEntities[msg.targetId];
            NetworkEntity source = null;

            if (msg.sourceId != 0)
            {
                source = networkEntities[msg.sourceId];
            }

            if (source.behavior == null)
            {
                return;
            }

            ICreatureBehavior srcBehavior = source == null ? null : source.behavior;
            ICreatureBehavior tarBehavior = target.behavior;

            tarBehavior.BeHit(msg.decHP, srcBehavior);
        }
示例#6
0
        // the enemy is null if not exists one
        public override void OnHit(Creature enemy, int hpDec)
        {
            // Use lock to prevent multi-hit
            lock (hitLock)
            {
                if (currentHP == 0 && dead)
                {
                    return;
                }

                if (IsInvulnerable())
                {
                    return;
                }
                m_lastHitTS = DateTime.Now;
                // TODO calculate hit point decrease by creature's attribute
                hpDec     = currentHP - hpDec < 0 ? currentHP : hpDec;
                currentHP = currentHP - hpDec;

                SHit hit = new SHit();
                hit.decHP    = hpDec;
                hit.sourceId = enemy != null ? enemy.entityId : 0;
                hit.targetId = this.entityId;
                Broadcast(hit);

                if (currentHP == 0)
                {
                    OnDie((Player)enemy);
                    //World.Instance.DelayInvoke(20, OnReSpawn);
                }
                else
                {
                    EnemyClosing(enemy);
                }
            }
        }
示例#7
0
        private void OnRecvHit(IChannel channel, Message message)
        {
            SHit msg = message as SHit;

            UnityEngine.Debug.Log(string.Format("{0} hit {1} hp:{2}", msg.sourceId, msg.targetId, msg.decHP));
            NetworkEntity target = networkEntities[msg.targetId];
            NetworkEntity source = null;

            if (msg.sourceId != 0)
            {
                source = networkEntities[msg.sourceId];
                source.gameObject.SetActive(true);
            }

            if (source.behavior == null)
            {
                return;
            }

            ICreatureBehavior srcBehavior = source == null ? null : source.behavior;
            ICreatureBehavior tarBehavior = target.behavior;

            tarBehavior.BeHit(msg.decHP, srcBehavior);
        }