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

📄 centity.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                Infantry inf_attacker = new Infantry();        BattleArmor ba_attacker = new BattleArmor();        Mounted lnk_guide;        if (attacker instanceof BattleArmor) {            ba_attacker = (BattleArmor) attacker;        }        if ((attacker instanceof Infantry)                && !(attacker instanceof BattleArmor)) {            inf_attacker = (Infantry) attacker;        }        // Only infantry can fire into their own hex                if (!(attacker instanceof Infantry) & range == 0){            return 0.0;        }                double fDamage = 0.0;        WeaponType wt = (WeaponType) weapon.getType();                // The "Stop Swarm Attack" really isn't one                if (wt.getName() == "Stop Swarm Attack"){            return 0.0;        }                // Get the range modifier for the weapon                if (range <= wt.getMinimumRange()){            total_mod = total_mod + 1 + (wt.getMinimumRange() - range);        } else {            if (range > wt.getShortRange()){                total_mod += 2;            }            if (range > wt.getMediumRange()){                total_mod +=2;            }            if (range > wt.getLongRange()){                total_mod += 4;            }            if (range > wt.getExtremeRange()){                return 0.0;            }        }                // Get the weapon to-hit mod        total_mod += wt.getToHitModifier();        // Some weapons use multiple hits, as determined by the missile        // hits table.  This method is used for an approximation, so        // assume LBX cannon are using cluster rounds, Ultra-cannon        // are firing double rate, and RACs are fired in quad mode.        if (wt.getDamage() == WeaponType.DAMAGE_MISSILE &                 wt.getAmmoType() != AmmoType.T_TBOLT5 &                 wt.getAmmoType() != AmmoType.T_TBOLT10 &                 wt.getAmmoType() != AmmoType.T_TBOLT15 &                 wt.getAmmoType() != AmmoType.T_TBOLT20) {            use_table = true;        }        if ((wt.getAmmoType() == AmmoType.T_AC_LBX)                || (wt.getAmmoType() == AmmoType.T_AC_LBX_THB)) {                use_table = true;                total_mod -= 1;        }        if ((wt.getAmmoType() == AmmoType.T_AC_ULTRA)                || (wt.getAmmoType() == AmmoType.T_AC_ULTRA_THB)                || (wt.getAmmoType() == AmmoType.T_AC_ROTARY)) {            use_table = true;        }        // Kinda cheap, but lets use the missile hits table for Battle armor        // weapons too        if (attacker instanceof BattleArmor) {            if ((wt.getInternalName() != Infantry.SWARM_MEK)                    & (wt.getInternalName() != Infantry.LEG_ATTACK)                    & !(wt.hasFlag(WeaponType.F_INFANTRY))) {                use_table = true;            }        }        if (use_table == true) {            double fHits = 0.0;            if (!(attacker instanceof BattleArmor)) {                if (weapon.getLinked() == null)                    return 0.0;            }            AmmoType at = null;            if (weapon.getLinked() != null) {                at = (AmmoType) weapon.getLinked().getType();                // Override damage by ammo type for some items                // Set LRM and MRM damage at 1.0, SRM types at 2.0,                // and ATMs at 2.4 (2.0 nominal x 1.2 for built-in                // Artemis)                fDamage = at.getDamagePerShot();                if (wt.getAmmoType() == AmmoType.T_SRM_STREAK                        || wt.getAmmoType() == AmmoType.T_SRM) {                    fDamage = 2.0;                }                if (wt.getAmmoType() == AmmoType.T_ATM) {                    fDamage = 2.4;                }                if (wt.getAmmoType() == AmmoType.T_LRM_STREAK                        || wt.getAmmoType() == AmmoType.T_LRM                        || wt.getAmmoType() == AmmoType.T_MRM) {                    fDamage = 1.0;                }            }            if (wt.getRackSize() != 40 && wt.getRackSize() != 30) {                fHits = expectedHitsByRackSize[wt.getRackSize()];            } else {                fHits = 2.0f * expectedHitsByRackSize[wt.getRackSize() / 2];            }            if (wt.getAmmoType() == AmmoType.T_SRM_STREAK                    || wt.getAmmoType() == AmmoType.T_LRM_STREAK){                fHits = wt.getRackSize();            }            if (wt.getAmmoType() == AmmoType.T_AC_ULTRA                    || wt.getAmmoType() == AmmoType.T_AC_ULTRA_THB){                fHits = expectedHitsByRackSize[2];            }            if (wt.getAmmoType() == AmmoType.T_AC_ROTARY){                fHits = expectedHitsByRackSize[4];            }            if ((wt.getAmmoType() == AmmoType.T_AC_LBX)                    || (wt.getAmmoType() == AmmoType.T_AC_LBX_THB)) {                fHits = expectedHitsByRackSize[wt.getDamage()];            }            if (wt.getAmmoType() == AmmoType.T_LRM                    || wt.getAmmoType() == AmmoType.T_SRM) {                lnk_guide = weapon.getLinkedBy();                if (lnk_guide != null                        && lnk_guide.getType() instanceof MiscType                        && !lnk_guide.isDestroyed()                        && !lnk_guide.isMissing()                        && !lnk_guide.isBreached()                        && lnk_guide.getType().hasFlag(MiscType.F_ARTEMIS)) {                    fHits *= 1.2f;                }            }            // Most Battle Armor units have a weapon per trooper, plus their            // weapons do odd things when mounting multiples            if (attacker instanceof BattleArmor) {                // The number of troopers hitting                fHits = expectedHitsByRackSize[ba_attacker                        .getShootingStrength()];                if (wt.getDamage() == WeaponType.DAMAGE_MISSILE) {                    fHits *= expectedHitsByRackSize[wt.getRackSize()];                }                if (wt.getDamage() != WeaponType.DAMAGE_MISSILE) {                    if (wt.getDamage() != WeaponType.DAMAGE_VARIABLE) {                        fDamage = wt.getDamage();                    } else {                        fDamage = wt.getRackSize();                    }                }                if (wt.hasFlag(WeaponType.F_DOUBLE_HITS)) {                    fHits *= 2.0;                }                if (wt.hasFlag(WeaponType.F_MISSILE_HITS)) {                    fHits *= expectedHitsByRackSize[wt.getRackSize()];                }            }            fDamage *= fHits;            if ((wt.getAmmoType() == AmmoType.T_AC_ULTRA)                    || (wt.getAmmoType() == AmmoType.T_AC_ULTRA_THB)                    || (wt.getAmmoType() == AmmoType.T_AC_ROTARY)) {                fDamage = fHits * wt.getDamage();            }                    } else {            // Direct fire weapons just do a single shot            // so they don't use the missile hits table                        fDamage = wt.getDamage();                        // Heavy gauss and Thunderbolt LRMs do odd things with range                        if (wt.getAmmoType() == AmmoType.T_GAUSS_HEAVY){                fDamage = 25.0;                if (range > 6){                    fDamage = 20.0;                }                if (range > 13){                    fDamage = 10.0;                }            }            if (wt.getAmmoType() == AmmoType.T_TBOLT5                     || wt.getAmmoType() == AmmoType.T_TBOLT10                    || wt.getAmmoType() == AmmoType.T_TBOLT15                    || wt.getAmmoType() == AmmoType.T_TBOLT20){                if (range <= wt.getMinimumRange()){                    fDamage *= 0.5;                }            }            // Infantry follow some special rules, but do fixed amounts of            // damage            if (attacker instanceof Infantry) {                                if (wt.hasFlag(WeaponType.F_INFANTRY)) {                    // Weapons fielded by conventional infantry and light BA                    // Field guns should be handled under the normal weapons section                    fDamage = inf_attacker.getDamage(inf_attacker.                            getShootingStrength());                    if (attacker instanceof BattleArmor){                        fDamage = inf_attacker.getDamage(ba_attacker.                                getShootingStrength());                    }                }                                if (wt.getInternalName() == Infantry.LEG_ATTACK) {                    // Odds change based on number of troopers.  Make an estimate.                    if (!(attacker instanceof BattleArmor)){                        total_mod = 4 + 2 * (inf_attacker.getOInternal(0) - inf_attacker.getShootingStrength())/5;                    } else {                        total_mod = 8 - ba_attacker.getShootingStrength();                    }                    fDamage = 10.0;  // Damage is actually 5 plus chance at crits                }                                if (wt.getInternalName() == Infantry.SWARM_MEK) {                    // Odds change based on number of troopers.  Make an estimate.                    // Damage is same as conventional weapons, but with chance for crits                    if (!(attacker instanceof BattleArmor)){                        total_mod = 7 + 2 * (inf_attacker.getOInternal(0) - inf_attacker.getShootingStrength())/5;                        fDamage = 1.5 * inf_attacker.getDamage(inf_attacker                                .getShootingStrength());                    } else {                        total_mod = 11 - ba_attacker.getShootingStrength();                        fDamage = 5.0 * ba_attacker.getShootingStrength();                    }                }                             }        }        double fChance = Compute.oddsAbove(total_mod)/100;        fDamage *= fChance;        return fDamage;    }    public static int getFiringAngle(final Coords dest, int dest_facing, final Coords src) {        int fa = dest.degree(src) - (dest_facing % 6) * 60;        if (fa < 0) {            fa += 360;        } else if (fa >= 360) {            fa -= 360;        }        return fa;    }    public static int getThreatHitArc(Coords dest, int dest_facing, Coords src) {        int fa = getFiringAngle(dest, dest_facing, src);        if (fa >= 300 || fa <= 60)            return ToHitData.SIDE_FRONT;        if (fa >= 60 && fa <= 120)            return ToHitData.SIDE_RIGHT;        if (fa >= 240 && fa <= 300)            return ToHitData.SIDE_LEFT;        return ToHitData.SIDE_REAR;    }    public static int firingArcToHitArc(int arc) {        switch (arc) {            case Compute.ARC_FORWARD :                return ToHitData.SIDE_FRONT;            case Compute.ARC_LEFTARM :                return ToHitData.SIDE_LEFT;            case Compute.ARC_RIGHTARM :                return ToHitData.SIDE_RIGHT;            case Compute.ARC_REAR :                return ToHitData.SIDE_REAR;            case Compute.ARC_LEFTSIDE:                return ToHitData.SIDE_LEFT;            case Compute.ARC_RIGHTSIDE:                return ToHitData.SIDE_RIGHT;        }        return 0;    }    public boolean equals(Object obj) {        if (obj instanceof Entity || obj instanceof CEntity) {            return obj.hashCode() == hashCode();        }        return false;    }    public int hashCode() {        return entity.getId();    }    public TestBot getTb() {        return tb;    }}

⌨️ 快捷键说明

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