protected void useItem(NPCProto npc, Item item, short state, short targetState)
        {
            if (!(state == -1 && targetState == -2))
            {
                return;
            }

            npc.ApplyOverlay("HUMANS_SPRINT.MDS");

            ITPO_SPEED_TIMER timer = (ITPO_SPEED_TIMER)npc.getUserObjects("itpo_speed_timer");

            if (timer == null)
            {
                timer          = new ITPO_SPEED_TIMER(npc); //5 Minuten
                timer.TimeSpan = 10000 * 1000 * 15;         //15 Sekunden
                timer.Start();
                npc.setUserObject("itpo_speed_timer", timer);
            }
            else
            {
                timer.TimeSpan = 10000 * 1000 * 15;//15 Sekunden
                timer.End();
                timer.Start();
            }
        }
Esempio n. 2
0
        public static void OnDamage(NPCProto victim, DamageTypes damageMode, Vec3f hitLoc, Vec3f flyDir, Vob aggressor, int weaponMode, Spell spell, Item weapon, float fallDownDistanceY)
        {
            if (victim.getUserObjects("IMMORTAL") != null && (bool)victim.getUserObjects("IMMORTAL"))           //Victim is immortal!
            {
                return;
            }
            NPCProto attacker = null;

            if (aggressor is NPCProto)
            {
                attacker = (NPCProto)aggressor;
            }


            if (attacker != null && attacker.getUserObjects("FRIENDS") != null && ((List <NPCProto>)attacker.getUserObjects("FRIENDS")).Contains(victim))          //Victim is a friend!
            {
                return;
            }



            int damage = 0;

            Console.WriteLine("OnDamage: " + damageMode + " | " + weaponMode + " | " + spell + " | " + weapon + " | " + attacker);

            if (damageMode == DamageTypes.DAM_FALL)
            {
                damage = (int)(fallDownDistanceY - 500) / 100 * 20;
            }

            if (attacker != null)
            {
                if (weapon == null && weaponMode == 1)                 //1 is fist!, 2 => 1h
                {
                    damage = attacker.Strength - victim.getProtection(damageMode);
                }
                else if (weapon != null)
                {
                    damage = attacker.Strength + weapon.TotalDamage - victim.getProtection(weapon.DamageType);
                }
            }

            damage = Math.Max(damage, 5);

            bool toUnconscious = false;
            bool canKill       = true;

            if (attacker != null && victim.HP - damage <= 1)
            {
                if (damageMode == DamageTypes.DAM_BLUNT)
                {
                    canKill = false;
                }

                if (damageMode == DamageTypes.DAM_BLUNT || damageMode == DamageTypes.DAM_EDGE)
                {
                    toUnconscious = true;
                }
            }

            if (!victim.IsHuman() || !(attacker != null && attacker.IsHuman()))
            {
                toUnconscious = false;
                canKill       = true;
            }

            if (toUnconscious && !victim.isUnconscious)
            {
                damage = victim.HP - 1;
                victim.dropUnconscious(0.0f);

                if (Damages != null)
                {
                    Damages(victim, attacker, damage, true, false);
                }
            }
            else if (!canKill && victim.HP - damage <= 1)
            {
                victim.HP = 1;

                if (Damages != null)
                {
                    Damages(victim, attacker, damage, false, false);
                }
            }
            else
            {
                victim.HP -= damage;

                if (Damages != null && victim.HP <= 0)
                {
                    Damages(victim, attacker, damage, false, true);
                }
                else if (Damages != null)
                {
                    Damages(victim, attacker, damage, true, false);
                }
            }
        }
 public static NPCAI getAI(this NPCProto proto)
 {
     return((NPCAI)proto.getUserObjects("AI"));
 }