⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gamecombat.java

📁 JAKE2用JAVA写的queck2的3D游戏开发引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (attacker == targ || attacker == targ.enemy)            return;            // if we are a good guy monster and our attacker is a player        // or another good guy, do not get mad at them        if (0 != (targ.monsterinfo.aiflags & Defines.AI_GOOD_GUY)) {            if (attacker.client != null                    || (attacker.monsterinfo.aiflags & Defines.AI_GOOD_GUY) != 0)                return;        }            // we now know that we are not both good guys            // if attacker is a client, get mad at them because he's good and we're        // not        if (attacker.client != null) {            targ.monsterinfo.aiflags &= ~Defines.AI_SOUND_TARGET;                // this can only happen in coop (both new and old enemies are            // clients)            // only switch if can't see the current enemy            if (targ.enemy != null && targ.enemy.client != null) {                if (GameUtil.visible(targ, targ.enemy)) {                    targ.oldenemy = attacker;                    return;                }                targ.oldenemy = targ.enemy;            }            targ.enemy = attacker;            if (0 == (targ.monsterinfo.aiflags & Defines.AI_DUCKED))                GameUtil.FoundTarget(targ);            return;        }            // it's the same base (walk/swim/fly) type and a different classname and        // it's not a tank        // (they spray too much), get mad at them        if (((targ.flags & (Defines.FL_FLY | Defines.FL_SWIM)) == (attacker.flags & (Defines.FL_FLY | Defines.FL_SWIM)))                && (!(targ.classname.equals(attacker.classname)))                && (!(attacker.classname.equals("monster_tank")))                && (!(attacker.classname.equals("monster_supertank")))                && (!(attacker.classname.equals("monster_makron")))                && (!(attacker.classname.equals("monster_jorg")))) {            if (targ.enemy != null && targ.enemy.client != null)                targ.oldenemy = targ.enemy;            targ.enemy = attacker;            if (0 == (targ.monsterinfo.aiflags & Defines.AI_DUCKED))                GameUtil.FoundTarget(targ);        }        // if they *meant* to shoot us, then shoot back        else if (attacker.enemy == targ) {            if (targ.enemy != null && targ.enemy.client != null)                targ.oldenemy = targ.enemy;            targ.enemy = attacker;            if (0 == (targ.monsterinfo.aiflags & Defines.AI_DUCKED))                GameUtil.FoundTarget(targ);        }        // otherwise get mad at whoever they are mad at (help our buddy) unless        // it is us!        else if (attacker.enemy != null && attacker.enemy != targ) {            if (targ.enemy != null && targ.enemy.client != null)                targ.oldenemy = targ.enemy;            targ.enemy = attacker.enemy;            if (0 == (targ.monsterinfo.aiflags & Defines.AI_DUCKED))                GameUtil.FoundTarget(targ);        }    }    static boolean CheckTeamDamage(edict_t targ, edict_t attacker) {        //FIXME make the next line real and uncomment this block        // if ((ability to damage a teammate == OFF) && (targ's team ==        // attacker's team))        return false;    }    /**     * T_RadiusDamage.     */    static void T_RadiusDamage(edict_t inflictor, edict_t attacker,            float damage, edict_t ignore, float radius, int mod) {        float points;        EdictIterator edictit = null;            float[] v = { 0, 0, 0 };        float[] dir = { 0, 0, 0 };            while ((edictit = GameBase.findradius(edictit, inflictor.s.origin,                radius)) != null) {            edict_t ent = edictit.o;            if (ent == ignore)                continue;            if (ent.takedamage == 0)                continue;                Math3D.VectorAdd(ent.mins, ent.maxs, v);            Math3D.VectorMA(ent.s.origin, 0.5f, v, v);            Math3D.VectorSubtract(inflictor.s.origin, v, v);            points = damage - 0.5f * Math3D.VectorLength(v);            if (ent == attacker)                points = points * 0.5f;            if (points > 0) {                if (CanDamage(ent, inflictor)) {                    Math3D.VectorSubtract(ent.s.origin, inflictor.s.origin, dir);                    T_Damage(ent, inflictor, attacker, dir, inflictor.s.origin,                            Globals.vec3_origin, (int) points, (int) points,                            Defines.DAMAGE_RADIUS, mod);                }            }        }    }    public static void T_Damage(edict_t targ, edict_t inflictor,            edict_t attacker, float[] dir, float[] point, float[] normal,            int damage, int knockback, int dflags, int mod) {        gclient_t client;        int take;        int save;        int asave;        int psave;        int te_sparks;            if (targ.takedamage == 0)            return;            // friendly fire avoidance        // if enabled you can't hurt teammates (but you can hurt yourself)        // knockback still occurs        if ((targ != attacker)                && ((GameBase.deathmatch.value != 0 && 0 != ((int) (GameBase.dmflags.value) & (Defines.DF_MODELTEAMS | Defines.DF_SKINTEAMS))) || GameBase.coop.value != 0)) {            if (GameUtil.OnSameTeam(targ, attacker)) {                if (((int) (GameBase.dmflags.value) & Defines.DF_NO_FRIENDLY_FIRE) != 0)                    damage = 0;                else                    mod |= Defines.MOD_FRIENDLY_FIRE;            }        }        GameBase.meansOfDeath = mod;            // easy mode takes half damage        if (GameBase.skill.value == 0 && GameBase.deathmatch.value == 0                && targ.client != null) {            damage *= 0.5;            if (damage == 0)                damage = 1;        }            client = targ.client;            if ((dflags & Defines.DAMAGE_BULLET) != 0)            te_sparks = Defines.TE_BULLET_SPARKS;        else            te_sparks = Defines.TE_SPARKS;            Math3D.VectorNormalize(dir);            // bonus damage for suprising a monster        if (0 == (dflags & Defines.DAMAGE_RADIUS)                && (targ.svflags & Defines.SVF_MONSTER) != 0                && (attacker.client != null) && (targ.enemy == null)                && (targ.health > 0))            damage *= 2;            if ((targ.flags & Defines.FL_NO_KNOCKBACK) != 0)            knockback = 0;            // figure momentum add        if (0 == (dflags & Defines.DAMAGE_NO_KNOCKBACK)) {            if ((knockback != 0) && (targ.movetype != Defines.MOVETYPE_NONE)                    && (targ.movetype != Defines.MOVETYPE_BOUNCE)                    && (targ.movetype != Defines.MOVETYPE_PUSH)                    && (targ.movetype != Defines.MOVETYPE_STOP)) {                float[] kvel = { 0, 0, 0 };                float mass;                    if (targ.mass < 50)                    mass = 50;                else                    mass = targ.mass;                    if (targ.client != null && attacker == targ)                    Math3D.VectorScale(dir, 1600.0f * (float) knockback / mass,                            kvel);                // the rocket jump hack...                else                    Math3D.VectorScale(dir, 500.0f * (float) knockback / mass,                            kvel);                    Math3D.VectorAdd(targ.velocity, kvel, targ.velocity);            }        }            take = damage;        save = 0;            // check for godmode        if ((targ.flags & Defines.FL_GODMODE) != 0                && 0 == (dflags & Defines.DAMAGE_NO_PROTECTION)) {            take = 0;            save = damage;            SpawnDamage(te_sparks, point, normal, save);        }            // check for invincibility        if ((client != null && client.invincible_framenum > GameBase.level.framenum)                && 0 == (dflags & Defines.DAMAGE_NO_PROTECTION)) {            if (targ.pain_debounce_time < GameBase.level.time) {                GameBase.gi.sound(targ, Defines.CHAN_ITEM, GameBase.gi                        .soundindex("items/protect4.wav"), 1,                        Defines.ATTN_NORM, 0);                targ.pain_debounce_time = GameBase.level.time + 2;            }            take = 0;            save = damage;        }            psave = CheckPowerArmor(targ, point, normal, take, dflags);        take -= psave;            asave = CheckArmor(targ, point, normal, take, te_sparks, dflags);        take -= asave;            // treat cheat/powerup savings the same as armor        asave += save;            // team damage avoidance        if (0 == (dflags & Defines.DAMAGE_NO_PROTECTION)                && CheckTeamDamage(targ, attacker))            return;            // do the damage        if (take != 0) {            if (0 != (targ.svflags & Defines.SVF_MONSTER) || (client != null))                SpawnDamage(Defines.TE_BLOOD, point, normal, take);            else                SpawnDamage(te_sparks, point, normal, take);                targ.health = targ.health - take;                if (targ.health <= 0) {                if ((targ.svflags & Defines.SVF_MONSTER) != 0                        || (client != null))                    targ.flags |= Defines.FL_NO_KNOCKBACK;                Killed(targ, inflictor, attacker, take, point);                return;            }        }            if ((targ.svflags & Defines.SVF_MONSTER) != 0) {            M_ReactToDamage(targ, attacker);            if (0 == (targ.monsterinfo.aiflags & Defines.AI_DUCKED)                    && (take != 0)) {                targ.pain.pain(targ, attacker, knockback, take);                // nightmare mode monsters don't go into pain frames often                if (GameBase.skill.value == 3)                    targ.pain_debounce_time = GameBase.level.time + 5;            }        } else if (client != null) {            if (((targ.flags & Defines.FL_GODMODE) == 0) && (take != 0))                targ.pain.pain(targ, attacker, knockback, take);        } else if (take != 0) {            if (targ.pain != null)                targ.pain.pain(targ, attacker, knockback, take);        }            // add to the damage inflicted on a player this frame        // the total will be turned into screen blends and view angle kicks        // at the end of the frame        if (client != null) {            client.damage_parmor += psave;            client.damage_armor += asave;            client.damage_blood += take;            client.damage_knockback += knockback;            Math3D.VectorCopy(point, client.damage_from);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -