示例#1
0
        public void SpawnRadiationMote()
        {
            if (props.motes == null || !props.motes.Any())
            {
                return;
            }
            var def = props.motes.RandomElement();

            if (def.skip)
            {
                return;
            }

            MoteRadiation moteThrown = ThingMaker.MakeThing(def.mote, null) as MoteRadiation;

            if (moteThrown == null)
            {
                return;
            }

            List <Thing> chambers = Chambers;

            if (!chambers.Any())
            {
                return;
            }
            Thing chamber = chambers.RandomElement();

            Vector2 rotationVector2 = parent.Rotation.AsVector2.RotatedBy(90);
            Vector3 rotationVector  = new Vector3(rotationVector2.x, 0, rotationVector2.y);
            Vector3 origin          = parent.ExactPosition() + Rand.Range(-def.initialSpread, def.initialSpread) * rotationVector;
            Vector3 destination     = chamber.ExactPosition() + Rand.Range(-def.spread, def.spread) * rotationVector;
            Vector3 offset          = destination - origin;
            Vector3 dir             = offset.normalized;

            float positionPercent = Mathf.Sqrt(Rand.Range(0f, 1f));
            float position        = def.offset.LerpThroughRange(positionPercent);
            float scale           = def.scaleRange.RandomInRange;

            Vector3 startOffset = offset * position;
            float   angle       = startOffset.AngleFlat();

            moteThrown.exactPosition = origin + startOffset;
            moteThrown.exactRotation = angle;
            moteThrown.reflectAt     = motesReflectAt;
            moteThrown.reflectChance = def.reflectChance;

            if (parent.Rotation.IsHorizontal)
            {
                moteThrown.deathLocation      = chamber.Position.x + 0.5f;
                moteThrown.isHorizontal       = true;
                moteThrown.reflectIndex       = parent.Rotation == Rot4.West ? 0 : motesReflectAt.Count() - 1;
                moteThrown.reflectIndexChange = parent.Rotation == Rot4.West ? 1 : -1;
            }
            else
            {
                moteThrown.deathLocation      = chamber.Position.z + 0.5f;
                moteThrown.isHorizontal       = false;
                moteThrown.reflectIndex       = parent.Rotation == Rot4.North ? 0 : motesReflectAt.Count() - 1;
                moteThrown.reflectIndexChange = parent.Rotation == Rot4.North ? 1 : -1;
            }


            moteThrown.exactScale = new Vector3(scale, scale, scale);
            moteThrown.SetVelocity(angle, def.speed.RandomInRange);
            GenSpawn.Spawn(moteThrown, parent.Position, parent.Map, WipeMode.Vanish);
        }
示例#2
0
        public void SpawnRadiationMote()
        {
            if (linked == null)
            {
                return;
            }


            CompPropertiesIrradiator moteProps = MoteProps;

            if (moteProps?.motes == null || !moteProps.motes.Any())
            {
                return;
            }

            var def = moteProps.motes.RandomElement();

            if (def.skip)
            {
                return;
            }

            if (def.speed.max < 0.5f)
            {
                if (Rand.RangeInclusive(0, 5) > linked.Position.DistanceTo(parent.Position))
                {
                    return;
                }
            }

            MoteRadiation moteThrown = ThingMaker.MakeThing(def.mote, null) as MoteRadiation;

            if (moteThrown == null)
            {
                return;
            }

            Vector3 origin      = parent.ExactPosition();
            Vector3 destination = linked.ExactPosition();

            origin.y = destination.y;
            Vector3 sideways = (destination - origin).normalized.RotatedBy(90);

            origin      += sideways * Rand.Range(-def.initialSpread, def.initialSpread);
            destination += sideways * Rand.Range(-def.spread, def.spread);

            float positionPercent = Mathf.Sqrt(Rand.Range(0f, 1f));
            float position        = def.offset.LerpThroughRange(positionPercent);
            float scale           = def.scaleRange.RandomInRange;

            Vector3 dir         = destination - origin;
            Vector3 startOffset = dir * position;
            float   angle       = startOffset.AngleFlat();

            moteThrown.exactPosition = origin + startOffset;
            moteThrown.exactRotation = angle;
            moteThrown.reflectAt     = motesReflectAt;
            moteThrown.reflectChance = def.reflectChance;

            Rot4 rot = Rotation();

            if (rot.IsHorizontal)
            {
                moteThrown.deathLocation      = linked.ExactPosition().x;
                moteThrown.isHorizontal       = true;
                moteThrown.reflectIndex       = rot == Rot4.West ? 0 : motesReflectAt.Count() - 1;
                moteThrown.reflectIndexChange = rot == Rot4.West ? 1 : -1;
            }
            else
            {
                moteThrown.deathLocation      = linked.ExactPosition().z;
                moteThrown.isHorizontal       = false;
                moteThrown.reflectIndex       = rot == Rot4.North ? 0 : motesReflectAt.Count() - 1;
                moteThrown.reflectIndexChange = rot == Rot4.North ? 1 : -1;
            }


            moteThrown.exactScale = new Vector3(scale, scale, scale);
            moteThrown.SetVelocity(angle, def.speed.RandomInRange);
            GenSpawn.Spawn(moteThrown, parent.Position, parent.Map, WipeMode.Vanish);
        }