protected override void ObjectCollision(SimObjectInstance obj) { SimUnitInstance inst = obj as SimUnitInstance; if (inst != null && (inst.UnitConfig.Team == ProjectileConfig.CollidesWithTeam || ProjectileConfig.CollidesWithTeam == SimUnitConfig.ETeam.Both)) { inst.DoDamage(ProjectileConfig.Damage, 0.0f); if (OnCollision != null) { OnCollision(this, new OnCollisionEventArgs(inst)); } Destroy(); } }
private void EvaluateAttack(float deltatime) { if (UnitConfig.WeaponConfig != null && Sim.SimTime >= nextFireTime && UnitConfig.FireRate > 0.0f) { float closestdist = 0.0f; float closestdisttogoal = 0.0f; SimUnitInstance closest = null; IOctreeObject[] objs = Sim.Octtree.GetColliding(new Bounds(simposition, Vector3.one * UnitConfig.RadiusOfAffect)); foreach (IOctreeObject obj in objs) { SimUnitInstance inst = obj as SimUnitInstance; if (inst != null && inst != this && inst.UnitConfig.Team != this.UnitConfig.Team) { float disttoobject = Vector3.Distance(this.simposition, inst.simposition); if (disttoobject <= UnitConfig.RadiusOfAffect) { float dist = Sim.Goal.GetDistanceToPoint(inst.simposition); if (closest == null || dist < closestdisttogoal) { closest = inst; closestdisttogoal = dist; closestdist = disttoobject; } } } } if (closest != null) { //Attack closest to goal float impacttime = closestdist / UnitConfig.WeaponConfig.Speed; closest.DoDamage(UnitConfig.WeaponConfig.DamageAmount, impacttime); OnFireWeapon(closest.simposition, impacttime, closest); nextFireTime = Sim.SimTime + 1.0f / UnitConfig.FireRate; } } }