private static void doWeaponDamage(ActionPackage aPack) { Item aWeapon = ActionUtils.getWeapon(aPack.Owner); Item dArmor = ActionUtils.getArmor(aPack.Target); float aSkill = ActionUtils.getSkill(aPack.Owner, aPack.ActionDef.DamageDef.SkillName); float dSkill = ActionUtils.getSkill(aPack.Target, SkillName.AVOIDANCE); float aStat = ActionUtils.getStat(aPack.Owner, aPack.ActionDef.DamageDef.StatType); float dStat = ActionUtils.getStat(aPack.Target, ActionUtils.getOppositeStat(aPack.ActionDef.DamageDef.StatType)); float aKnow = ActionUtils.getKnowledge(aPack.Owner, aPack.Target); float dKnow = ActionUtils.getKnowledge(aPack.Target, aPack.Owner); float aProb = ActionUtils.getStatProbability((float)aSkill, (float)aStat, aKnow, (float)aWeapon.Speed); float dProb = ActionUtils.getStatProbability((float)dSkill, (float)dStat, dKnow, (float)dArmor.Mobility); float hitProb = ActionUtils.getHitProbability(dProb, aProb, 1.75f, 0.15f); int damage = ActionUtils.getDamage(hitProb, aSkill, aStat, aWeapon.Lethality, dArmor.Mitigation, ActionUtils.getStat(aPack.Target, StatType.ENDURANCE)); Position pos = ComponentMapper.get <Position> (aPack.Target); UtilFactory.createDirectDamage(damage, aPack.ActionDef.DamageDef.DamageType, aPack.Target, pos); Position newPos = new Position(pos.Pos + new Vector2(rand.Next(16) + 8, 0), Vector2.Zero); if (damage == 0) { UIFactory.createFloatingText("MISS", "DAMAGE", Color.White, 500, newPos); } else { UIFactory.createFloatingText("" + damage, "DAMAGE", DamageUtils.getDamageColor(aPack.ActionDef.DamageDef.DamageType), 500, newPos); } AwardUtils.attemptSkillAward(aPack.Owner, aPack.Target, aSkill, dSkill, aPack.ActionDef.DamageDef.SkillName, 1); AwardUtils.attemptStatAward(aPack.Owner, aPack.Target, aStat, dStat, aPack.ActionDef.DamageDef.StatType, 1); AwardUtils.attemptStatAward(aPack.Target, aPack.Owner, ActionUtils.getStat(aPack.Target, StatType.ENDURANCE), aStat, StatType.ENDURANCE, 1); }
private static void doStaticDamage(ActionPackage aPack) { int dmg = rand.Next(aPack.ActionDef.DamageDef.Min, aPack.ActionDef.DamageDef.Max); Position pos = ComponentMapper.get <Position> (aPack.Target); UtilFactory.createDirectDamage(dmg, aPack.ActionDef.DamageDef.DamageType, aPack.Target, pos); Position newPos = new Position(pos.Pos + new Vector2(rand.Next(16) + 8, 0), Vector2.Zero); UIFactory.createFloatingText("" + dmg, "DAMAGE", DamageUtils.getDamageColor(aPack.ActionDef.DamageDef.DamageType), 500, newPos); }
/// <summary> /// handle projectile attacks /// </summary> /// <param name="attack">attack to handle</param> private void handleProjectile(Attack attack) { Position position = (Position)_PositionMapper.get(attack.Defender); //dont continue if this attack has no position if (position == null) { return; } //calculate position Vector2 pos = position.Pos; Position newPos = new Position(pos + new Vector2(rand.Next(16) + 8, 0), Vector2.Zero); //get equipment Equipment attEquip = (Equipment)_EquipmentMapper.get(attack.Attacker); Equipment defEquip = (Equipment)_EquipmentMapper.get(attack.Defender); //dont continue if we have no equipment to use if (attEquip == null || defEquip == null) { return; } //get weapon and armor Item weapon = (Item)_ItemMapper.get(attEquip.RangedWeapon); Item armor = (Item)_ItemMapper.get(defEquip.Armor); //dont continue if either of these are null if (weapon == null || armor == null) { return; } //get attributes Statistics attAttr = (Statistics)_AttributeMapper.get(attack.Attacker); Statistics defAttr = (Statistics)_AttributeMapper.get(attack.Defender); //dont continue if either of these are null if (attAttr == null || defAttr == null) { return; } int perception = attAttr.Perception.Value; int quickness = defAttr.Quickness.Value; int focus = attAttr.Focus.Value; int endurance = defAttr.Endurance.Value; //get Experience Knowledges attKnw = (Knowledges)_KnowledgeMapper.get(attack.Attacker); Knowledges defKnw = (Knowledges)_KnowledgeMapper.get(attack.Defender); //dont continue if null if (attKnw == null || defKnw == null) { return; } //get Skills Skills attSkills = (Skills)_SkillMapper.get(attack.Attacker); Skills defSkills = (Skills)_SkillMapper.get(attack.Defender); //dont continue if either of these are null if (attSkills == null || defSkills == null) { return; } int atkSkill = attSkills.Ranged.Value; int defSkill = defSkills.Avoidance.Value; Information infoDef = (Information)_InfoMapper.get(attack.Defender); Information infoAtk = (Information)_InfoMapper.get(attack.Attacker); //dont continue if you dont have info if (infoDef == null || infoAtk == null) { return; } float probHit = atkSkill / 4 + perception / 4 + attKnw.GeneralKnowledge[infoDef.GeneralGroup].Value + weapon.Speed; float probDef = defSkill / 4 + quickness / 4 + defKnw.GeneralKnowledge[infoAtk.GeneralGroup].Value + armor.Mobility; float hitProb = (probHit / (probHit + probDef)) * 1.75f + (probDef / (probHit + probDef)) * 0.15f; float toHit = (float)rand.NextDouble(); int damage = 0; if (toHit < hitProb) { float overhit = 0f; if (hitProb > 1f) { overhit = hitProb - 1f; } //int maxDmg = (int)((overhit + 1f) * ((atkSkill / 5 + focus / 4) / (endurance / 10)) * (weapon.Lethality / armor.Mitigation)); int maxDmg = (int)((overhit + 1f) * ((atkSkill / 5 + focus / 4)) * (weapon.Lethality / armor.Mitigation)) - (endurance / 10); damage = rand.Next(maxDmg / 2, maxDmg); if (damage < 0) { damage = 0; } } UtilFactory.createDirectDamage(damage, weapon.DamageType, attack.Defender, newPos); //create the floating dmg if (damage == 0) { UIFactory.createFloatingText("MISS", "DAMAGE", Color.White, 500, new Position(newPos.Pos, newPos.Offset)); } else { UIFactory.createFloatingText("" + damage, "DAMAGE", Color.Yellow, 500, new Position(newPos.Pos, newPos.Offset)); } Interactable interactor = (Interactable)_InteractMapper.get(attack.Attacker); Interactable interactee = (Interactable)_InteractMapper.get(attack.Defender); //only do if interaction supported if (interactor != null && interactor != null) { //only skill-up if you can if (interactor.SupportedInteractions.MAY_ADVANCE && interactee.SupportedInteractions.CAUSES_ADVANCEMENT) { //if still possible to skill-up if (atkSkill < defSkill) { if (rand.NextDouble() <= ((double)(defSkill - atkSkill) / (double)defSkill) * GameConfig.AwardDefs.SkillChance) { UtilFactory.createSkillupAward(attack.Defender, attack.Attacker, SkillName.RANGED, GameConfig.AwardDefs.SkillMinimum); } } if (perception < quickness) { if (rand.NextDouble() <= ((double)(quickness - perception) / (double)quickness) * GameConfig.AwardDefs.StatChance) { UtilFactory.createAttributeAward(attack.Defender, attack.Attacker, StatType.PERCEPTION, GameConfig.AwardDefs.StatMinimum); } } if (focus < endurance) { if (rand.NextDouble() <= ((double)(endurance - focus) / (double)endurance) * GameConfig.AwardDefs.StatChance) { UtilFactory.createAttributeAward(attack.Defender, attack.Attacker, StatType.FOCUS, GameConfig.AwardDefs.StatMinimum); } } } if (interactor.SupportedInteractions.CAUSES_ADVANCEMENT && interactee.SupportedInteractions.MAY_ADVANCE) { //if still possible to skill-up if (defSkill < atkSkill) { if (rand.NextDouble() <= ((double)(atkSkill - defSkill) / (double)atkSkill) * GameConfig.AwardDefs.SkillChance) { UtilFactory.createSkillupAward(attack.Attacker, attack.Defender, SkillName.AVOIDANCE, GameConfig.AwardDefs.SkillMinimum); } } if (quickness < perception) { if (rand.NextDouble() <= ((double)(perception - quickness) / (double)perception) * GameConfig.AwardDefs.StatChance) { UtilFactory.createAttributeAward(attack.Attacker, attack.Defender, StatType.QUICKNESS, GameConfig.AwardDefs.StatMinimum); } } if (endurance < focus) { if (rand.NextDouble() <= ((double)(focus - endurance) / (double)focus) * GameConfig.AwardDefs.StatChance) { UtilFactory.createAttributeAward(attack.Attacker, attack.Defender, StatType.ENDURANCE, GameConfig.AwardDefs.StatMinimum); } } } } //remove attack ecs_instance.delete_entity(_CurrentEntity); }