public byte tval; /* Item type for book this spell is in */ #endregion Fields #region Methods /** * Adjust damage according to resistance or vulnerability. * * \param type is the attack type we are checking. * \param dam is the unadjusted damage. * \param dam_aspect is the calc we want (min, avg, max, random). * \param resist is the degree of resistance (-1 = vuln, 3 = immune). */ public static int adjust_dam(Player.Player p, GF type, int dam, aspect dam_aspect, int resist) { GF gf_ptr = type; int i, denom; if (resist == 3) /* immune */ return 0; /* Hack - acid damage is halved by armour, holy orb is halved */ if ((type == GF.ACID && minus_ac(p)) || type == GF.HOLY_ORB) dam = (dam + 1) / 2; if (resist == -1) /* vulnerable */ return (dam * 4 / 3); /* Variable resists vary the denominator, so we need to invert the logic * of dam_aspect. (m_bonus is unused) */ switch (dam_aspect) { case aspect.MINIMISE: denom = Random.randcalc(gf_ptr.denom, 0, aspect.MAXIMISE); break; case aspect.MAXIMISE: denom = Random.randcalc(gf_ptr.denom, 0, aspect.MINIMISE); break; default: denom = Random.randcalc(gf_ptr.denom, 0, dam_aspect); break; } for (i = resist; i > 0; i--) if (denom != 0) dam = dam * gf_ptr.num / denom; return dam; }
/** * Adjust damage according to resistance or vulnerability. * * \param type is the attack type we are checking. * \param dam is the unadjusted damage. * \param dam_aspect is the calc we want (min, avg, max, random). * \param resist is the degree of resistance (-1 = vuln, 3 = immune). */ public static int adjust_dam(Player.Player p, GF type, int dam, aspect dam_aspect, int resist) { GF gf_ptr = type; int i, denom; if (resist == 3) /* immune */ { return(0); } /* Hack - acid damage is halved by armour, holy orb is halved */ if ((type == GF.ACID && minus_ac(p)) || type == GF.HOLY_ORB) { dam = (dam + 1) / 2; } if (resist == -1) /* vulnerable */ { return(dam * 4 / 3); } /* Variable resists vary the denominator, so we need to invert the logic * of dam_aspect. (m_bonus is unused) */ switch (dam_aspect) { case aspect.MINIMISE: denom = Random.randcalc(gf_ptr.denom, 0, aspect.MAXIMISE); break; case aspect.MAXIMISE: denom = Random.randcalc(gf_ptr.denom, 0, aspect.MINIMISE); break; default: denom = Random.randcalc(gf_ptr.denom, 0, dam_aspect); break; } for (i = resist; i > 0; i--) { if (denom != 0) { dam = dam * gf_ptr.num / denom; } } return(dam); }
/** * Check for resistance to a GF_ attack type. Return codes: * -1 = vulnerability * 0 = no resistance (or resistance plus vulnerability) * 1 = single resistance or opposition (or double resist plus vulnerability) * 2 = double resistance (including opposition) * 3 = total immunity * * \param type is the attack type we are trying to resist * \param flags is the set of flags we're checking * \param real is whether this is a real attack */ public static int check_for_resist(Player.Player p, GF type, Bitflag flags, bool real) { //GF gf_ptr = &gf_table[type]; GF gf_ptr = type; int result = 0; if (gf_ptr.vuln != Object.Object_Flag.NONE && flags.has(gf_ptr.vuln.value)) { result--; } /* If it's not a real attack, we don't check timed status explicitly */ if (real && (int)gf_ptr.opp != 0 && p.timed[(int)gf_ptr.opp] != 0) { result++; } if (gf_ptr.resist != Object.Object_Flag.NONE && flags.has(gf_ptr.resist.value)) { result++; } if (gf_ptr.immunity != Object.Object_Flag.NONE && flags.has(gf_ptr.immunity.value)) { result = 3; } /* Notice flags, if it's a real attack */ if (real && gf_ptr.immunity.value != 0) { Object.Object.wieldeds_notice_flag(p, gf_ptr.immunity.value); } if (real && gf_ptr.resist.value != 0) { Object.Object.wieldeds_notice_flag(p, gf_ptr.resist.value); } if (real && gf_ptr.vuln.value != 0) { Object.Object.wieldeds_notice_flag(p, gf_ptr.vuln.value); } return(result); }
/** * Check for resistance to a GF_ attack type. Return codes: * -1 = vulnerability * 0 = no resistance (or resistance plus vulnerability) * 1 = single resistance or opposition (or double resist plus vulnerability) * 2 = double resistance (including opposition) * 3 = total immunity * * \param type is the attack type we are trying to resist * \param flags is the set of flags we're checking * \param real is whether this is a real attack */ public static int check_for_resist(Player.Player p, GF type, Bitflag flags, bool real) { //GF gf_ptr = &gf_table[type]; GF gf_ptr = type; int result = 0; if (gf_ptr.vuln != Object.Object_Flag.NONE && flags.has(gf_ptr.vuln.value)) result--; /* If it's not a real attack, we don't check timed status explicitly */ if (real && (int)gf_ptr.opp != 0 && p.timed[(int)gf_ptr.opp] != 0) result++; if (gf_ptr.resist != Object.Object_Flag.NONE && flags.has(gf_ptr.resist.value)) result++; if (gf_ptr.immunity != Object.Object_Flag.NONE && flags.has(gf_ptr.immunity.value)) result = 3; /* Notice flags, if it's a real attack */ if (real && gf_ptr.immunity.value != 0) Object.Object.wieldeds_notice_flag(p, gf_ptr.immunity.value); if (real && gf_ptr.resist.value != 0) Object.Object.wieldeds_notice_flag(p, gf_ptr.resist.value); if (real && gf_ptr.vuln.value != 0) Object.Object.wieldeds_notice_flag(p, gf_ptr.vuln.value); return result; }