public void UseItem(uint hpid) { //TODO: move healing of bats/bots to cfg? const float HIT_PTS_PER_BAT = 300; const float HIT_PTS_PER_BOT = 600; ShipItem item = player.Ship.FindByHpid(hpid); if (item == null) { return; } // Calculate the number of shield bats needed to fully recharge the shield and if possible // repair the shield and use the items. if (item.arch is ShieldBatteryArchetype && Shield != null && Shield.Health < 1.0f) { uint bats_needed = 1 + (uint)(((1.0f - Shield.Health) * Shield.Arch.MaxCapacity) / HIT_PTS_PER_BAT); if (bats_needed > item.count) { bats_needed = item.count; } if (bats_needed > 0) { Items[item.hpid].count -= bats_needed; if (player != null) { player.SendUseItem(Objid, item.hpid, bats_needed); } RepairShield(bats_needed * HIT_PTS_PER_BAT); } } // Otherwise try to repair the hull else if (item.arch is RepairKitArchetype && Health < 1.0f) { uint bots_needed = 1 + (uint)(((1.0f - Health) * Arch.HitPts) / HIT_PTS_PER_BOT); if (bots_needed > item.count) { bots_needed = item.count; } if (bots_needed > 0) { Items[item.hpid].count -= bots_needed; if (player != null) { player.SendUseItem(Objid, item.hpid, bots_needed); } RepairHull(bots_needed * HIT_PTS_PER_BOT); } } }
/// <summary> /// Repair equipment by hpid if it exists /// </summary> /// <param name="hpid"></param> /// <param name="hit_pts"></param> public void RepairEquipment(uint hpid, float hit_pts) { if (hit_pts <= 0) { return; } // Repair equipment if we can find it. ShipItem item = FindByHpid(hpid); if (item != null && item.arch is EquipmentArchetype && item.health > 0) // fixme: change to external equipment { item.health += hit_pts / item.arch.HitPts; if (item.health > 1.0f) { item.health = 1.0f; } Runner.NotifyOnSetHitPoints(Objid, item.hpid, item.health * item.arch.HitPts, false); } }
public GunSim(Ship ship, ShipItem item) { this.ship = ship; this.item = item; arch = item.arch as GunArchetype; }
/// <summary> /// Damage the ship, either the shield, external equipment or hull. /// </summary> /// <param name="hpid">Subtarget taking damage</param> /// <param name="energy_damage">The energy damage in hitpts</param> /// <param name="hull_damage">The hull damage in hitpts</param> /// <param name="type">Weapon type.</param> /// <returns>Returns true if the ship or an equipment item was destroyed</returns> public bool Damage(uint hpid, float energy_damage, float hull_damage, DeathCause cause) { if (energy_damage < 0 || hull_damage < 0) { return(false); } if (energy_damage == 0 && hull_damage == 0) { return(false); } // If we have an active shield ignore hits on the hull or external equipment // and make them on the shield. if (Shield != null && (Shield.Health > 0 || hpid == 0xFFF1)) { // Step 1: calculate shield damage from energy damage float relative_shield_damage = (energy_damage * 1.0f) / Shield.Arch.MaxCapacity; Shield.Health -= relative_shield_damage; if (Shield.Health <= 0) { energy_damage = -Shield.Health * 1.0f * Shield.Arch.MaxCapacity; Shield.Health = 0; } else { energy_damage = 0; // Step 2 : calculate shield damage from hull damage if the shield is still up relative_shield_damage = (hull_damage * 0.5f) / Shield.Arch.MaxCapacity; Shield.Health -= relative_shield_damage; if (Shield.Health < 0) { hull_damage = -Shield.Health * 1.0f * Shield.Arch.MaxCapacity; Shield.Health = 0; } else { hull_damage = 0; } } if (Shield.Health < Shield.Arch.OfflineThreshold) { Shield.OfflineTime = Shield.Arch.OfflineRebuildTime; } Runner.NotifyOnSetHitPoints(Objid, DamageListItem.SHIELD, Shield.Health * Shield.Arch.MaxCapacity, false); } // Any remaining energy damage hits the powerplant if (energy_damage > 0) { Powergen.CurrPower -= energy_damage; Runner.NotifyOnSetHitPoints(Objid, Powergen.Item.hpid, Powergen.CurrPower, false); } // Avoid running the rest if the shield absorbed all damage if (hull_damage <= 0) { return(false); } bool hasDestroyedSomething = false; // Otherwise if this is a hit on an external equipment item do the hit on that ShipItem item = FindByHpid(hpid); if (item != null && item.arch is ExternalEquipmentArechetype && item.health > 0) { item.health -= (hull_damage / item.arch.HitPts) * _armorDamageFactor; if (item.health < 0) { hull_damage = -item.health * item.arch.HitPts / _armorDamageFactor; item.health = 0; } if (item.health == 0) { Runner.NotifyOnSetHitPoints(Objid, item.hpid, 0, true); Items.Remove(item.hpid); hasDestroyedSomething = true; } Runner.NotifyOnSetHitPoints(Objid, item.hpid, item.health * item.arch.HitPts, false); } // Avoid running the rest if the equipment absorbed all damage if (hull_damage <= 0) { return(hasDestroyedSomething); } // Otherwise this is a hull hit. Health -= (hull_damage / Arch.HitPts) * _armorDamageFactor; if (Health < 0) { Health = 0; } if (Health == 0) { Destroy(cause); return(true); } Runner.NotifyOnSetHitPoints(Objid, DamageListItem.HULL, Health * Arch.HitPts, false); return(hasDestroyedSomething); }
public ThrusterSim(Ship ship, ShipItem item) { this.ship = ship; this.item = item; arch = item.arch as ThrusterArchetype; }