示例#1
0
        private void Fire(IEntity user, GridCoordinates clickLocation)
        {
            if (capacitorComponent.Charge < _lowerChargeLimit)
            {//If capacitor has less energy than the lower limit, do nothing
                return;
            }
            float energyModifier = capacitorComponent.GetChargeFrom(_baseFireCost) / _baseFireCost;
            var   userPosition   = user.Transform.WorldPosition; //Remember world positions are ephemeral and can only be used instantaneously
            var   angle          = new Angle(clickLocation.Position - userPosition);

            var ray            = new CollisionRay(userPosition, angle.ToVec(), (int)(CollisionGroup.Impassable | CollisionGroup.MobImpassable));
            var rayCastResults = IoCManager.Resolve <IPhysicsManager>().IntersectRay(user.Transform.MapID, ray, MaxLength, user);

            Hit(rayCastResults, energyModifier);
            AfterEffects(user, rayCastResults, angle, energyModifier);
        }
示例#2
0
        private void Fire(IEntity user, GridCoordinates clickLocation)
        {
            if (capacitorComponent.Charge < _lowerChargeLimit)
            {//If capacitor has less energy than the lower limit, do nothing
                return;
            }
            float energyModifier = capacitorComponent.GetChargeFrom(_baseFireCost) / _baseFireCost;
            var   userPosition   = user.Transform.WorldPosition; //Remember world positions are ephemeral and can only be used instantaneously
            var   angle          = new Angle(clickLocation.Position - userPosition);

            var ray            = new CollisionRay(userPosition, angle.ToVec(), (int)(CollisionGroup.Opaque));
            var rayCastResults = IoCManager.Resolve <IPhysicsManager>().IntersectRay(user.Transform.MapID, ray, MaxLength, user, returnOnFirstHit: false).ToList();

            //The first result is guaranteed to be the closest one
            if (rayCastResults.Count >= 1)
            {
                Hit(rayCastResults[0], energyModifier, user);
                AfterEffects(user, rayCastResults[0], angle, energyModifier);
            }
        }