public IUnitMetaConfig ConvertValueBased(Unit second, Func <decimal, decimal> firstToSecond, Func <decimal, decimal> secondToFirst) { if (PhysicalUnit == null) { PhysicalUnit = unit.DerivePhysicalUnitsFromConstituentParts(); } if (PhysicalUnit.IsDimensionless()) { throw new InvalidOperationException("You must define physical unit of the left-hand side"); } var unitMeta = second.GetUnitData(); if (unitMeta == null || unitMeta.PhysicalUnit.IsDimensionless()) { // If right-hand side of conversion has no physical unit, we'll assume that it has the same physical unit as left-hand. unitMeta = (UnitMeta)config.Unit(second).IsPhysicalUnit(PhysicalUnit); } if (unitMeta.PhysicalUnit != PhysicalUnit) { throw new InvalidOperationException("You can only define conversions between units that are compatible as physical units"); } var node = config.UnitGraph.AddUnit(second); ConversionInfo.AddConversion(node, firstToSecond); node.AddConversion(ConversionInfo, secondToFirst); return(this); }
protected ProjectileWeapon(ProjectileWeaponData data, PhysicalUnit owner) : base(TimeSpan.FromSeconds(1.0 / data.FireRate), owner) { _name = data.Name; _projectilesPerFire = data.ProjectilesPerFire; _projectileInfo = data.ProjectileInfo; _spread = data.Spread; _contactEffect = _projectileInfo.ContactEffect == null ? ProjectileEffect.NullEffect : new ProjectileEffect(_projectileInfo.ContactEffect); _proximityEffect = _projectileInfo.ProximityEffect == null ? ProjectileEffect.NullEffect : new ProjectileEffect(_projectileInfo.ProximityEffect); _destinationEffect = _projectileInfo.DestinationEffect == null ? ProjectileEffect.NullEffect : new ProjectileEffect(_projectileInfo.DestinationEffect); _fireParticleEffect = data.FireParticleEffectName == null ? null : new ParticleEffect(data.FireParticleEffectName); float maxProjLife = data.ProjectileInfo.SecondsToLive + Math.Max((float)_contactEffect.Duration.TotalSeconds, (float)_destinationEffect.Duration.TotalSeconds); float maxProjectiles = data.FireRate * maxProjLife * data.ProjectilesPerFire; maxProjectiles = Math.Max(maxProjectiles, _projectilesPerFire); _projectiles = new Projectile[(int)maxProjectiles + 1]; for (int i = 0; i < _projectiles.Length; i++) { _projectiles[i] = new Projectile(data.ProjectileInfo.SpriteName); } }
public HookShot(PhysicalUnit owner) : base(TimeSpan.FromSeconds(FIRE_DELAY), owner) { _hookState = HookState.Idle; _hookSprite = new Sprite("HookClaw", Sprite.SpriteType.Projectile); _chainSprite = new Sprite("HookChain", Sprite.SpriteType.Projectile); _hookHitRect = new Rectangle(0, 0, (int)_hookSprite.Width, (int)_hookSprite.Height); }
/// <summary> /// Create a new weapon /// </summary> /// <param name="fireDelay">Time between successive shots</param> /// <param name="maxAmmo">Total ammo capacity. Set to 1 for infinite ammo.</param> /// <param name="ammoConsumption">Ammo used per shot. Set to 0 for infinite ammo.</param> /// <param name="levelWidth">Width of the level in which this weapon is instantiated.</param> /// <param name="levelHeight">Height of the level in which this weapon is instantiated.</param> public Weapon(TimeSpan fireDelay, int maxAmmo, int ammoConsumption, PhysicalUnit owner) { _fireDelay = fireDelay; _maxAmmo = maxAmmo; _currentAmmo = maxAmmo; _ammoConsumption = ammoConsumption; _owner = owner; }
public void MinMaxValues() { PhysicalUnit physicalUnit1 = new PhysicalUnit(1, 1, 0, 0); PhysicalUnit physicalUnit2 = new PhysicalUnit(1, 1, 0, 0, 1, 1000); Assert.AreEqual(expected: null, actual: physicalUnit1.MaxValue); Assert.AreEqual(expected: 1000, actual: physicalUnit2.MaxValue); }
public void CheckCollisions(GameTime gameTime, PhysicalUnit unit) { foreach (IConsumable item in _slots) { if (item is ProjectileWeapon) { (item as ProjectileWeapon).CheckAndApplyCollision(unit, gameTime.ElapsedGameTime); } } }
public override void CheckAndApplyCollision(PhysicalUnit unit, TimeSpan time) { if (_hookState == HookState.Fired || _hookState == HookState.Retracting) { if (XnaHelper.RectsCollide(_hookHitRect, unit.HitRect)) { _hookedUnit = unit; _hookState = HookState.Attached; } } }
public override void CheckAndApplyCollision(PhysicalUnit unit, TimeSpan time) { if (!unit.Collides) { return; } foreach (Projectile p in _projectiles) { p.CheckAndApplyCollision(unit, time); } }
/// <summary> /// Check if target unit is in range. If so, apply force and damage /// </summary> /// <param name="effectPos">origin of effect</param> /// <param name="target">target unit</param> public void TryApply(Vector2 effectPos, PhysicalUnit target, TimeSpan time) { if (utility.XnaHelper.RectangleIntersectsCircle(target.HitRect, effectPos, _radius)) { tempVec.X = target.Position.X - effectPos.X; tempVec.Y = target.Position.Y - effectPos.Y; Vector2.Normalize(tempVec); float factor = Duration == TimeSpan.Zero ? 1 : (float)time.TotalSeconds / (float)Duration.TotalSeconds; target.ApplyForce(_force * factor * tempVec); target.ApplyDamage((_damage * factor)); target.ApplyStatus(_statEffects); } }
protected MeleeWeapon(MeleeWeaponData data, PhysicalUnit owner) : base(TimeSpan.FromSeconds(1.0 / data.FireRate), owner) { _damage = data.Damage; _force = data.Impact; _recoil = data.Recoil; _hitArc = data.HitArc; _range = data.Range; _attackParticleEffect = (data.AttackParticleEffect == null) ? null : new ParticleEffect(data.AttackParticleEffect); _hitParticleEffect = (data.HitParticleEffect == null) ? null : new ParticleEffect(data.HitParticleEffect); }
public override void CheckAndApplyCollision(PhysicalUnit unit, TimeSpan time) { if (!_firing || !unit.Collides) { return; //don't check collisions if not firing } float fireAngle = XnaHelper.RadiansFromVector(_fireDirection); if (XnaHelper.RectangleIntersectsArc(unit.HitRect, _owner.Center, _range, fireAngle, _hitArc)) { _tempVector = unit.Center - _owner.Center; _tempVector.Normalize(); unit.ApplyImpact(_force * _tempVector, 1); unit.ApplyDamage(_damage); } }
public void CheckAndApplyCollision(PhysicalUnit u, TimeSpan time) { if (!u.Collides) { return; } switch (_state) { case State.Dormant: break; case State.Moving: if (u.HitRect.Intersects(_hitRect)) { if (_penetration != -1) { _penetration -= 1; if (_penetration <= 0) { _state = State.JustHit; } } u.ApplyImpact(_velocity, _mass); } _proximityEffect.TryApply(_position, u, time); break; case State.JustHit: break; case State.ApplyContactEffect: _contactEffect.TryApply(_position, u, time); break; case State.ReachedDestination: _destinationEffect.TryApply(_position, u, time); break; default: break; } }
public MeleeWeapon(string weaponName, PhysicalUnit owner) : this(MeleeWeaponDataDict[weaponName], owner) { }
public VisualizerAttribute(PhysicalProperty property, PhysicalUnit unit) { this.property = property; this.unit = unit; }
/// <summary> /// Check if weapon is hitting a target, and apply its affects if so /// Call during the update loop on each unit /// </summary> /// <param name="unit"></param> public abstract void CheckAndApplyCollision(PhysicalUnit unit, TimeSpan time);
public ConverterAttribute(PhysicalUnit input, PhysicalUnit output) { this.input = input; this.output = output; }
public ThrowableWeapon(string name, PhysicalUnit owner) : base(DataDict[name], owner) { _maxAmmo = DataDict[name].UsesPerStack; NumUses = _maxAmmo; }
public ProjectileWeapon(string name, PhysicalUnit owner) : this(DataDict[name], owner) { }
public SensorAttribute(PhysicalProperty property, PhysicalUnit unit) { this.property = property; this.unit = unit; }
/// <summary> /// Create a new weapon /// </summary> /// <param name="fireDelay">Time between successive shots</param> /// <param name="maxAmmo">Total ammo capacity. Set to 1 for infinite ammo.</param> /// <param name="ammoConsumption">Ammo used per shot. Set to 0 for infinite ammo.</param> /// <param name="levelWidth">Width of the level in which this weapon is instantiated.</param> /// <param name="levelHeight">Height of the level in which this weapon is instantiated.</param> public Weapon(TimeSpan fireDelay, PhysicalUnit owner) { _fireDelay = fireDelay; _owner = owner; }