Exemplo n.º 1
0
        public override void Spawn(Map map, Vector3 origin)
        {
            for (int i = 0; i < moteCount; i++)
            {
                MoteThrown moteThrown = ThingMaker.MakeThing(mote, null) as MoteThrown;
                if (moteThrown == null)
                {
                    return;
                }

                float   angle = Rand.Range(0f, 360f);
                Vector3 dir   = new Vector3(1f, 0f, 0f).RotatedBy(angle);

                float magnitude   = Rand.Range(0f, 1f);
                float actualScale = scale.LerpThroughRange(magnitude);
                moteThrown.exactPosition = origin + dir * radius.LerpThroughRange(magnitude);
                moteThrown.exactRotation = angle + 90;
                moteThrown.exactScale    = new Vector3(actualScale, actualScale, actualScale);
                moteThrown.SetVelocity(angle + 90, magnitude * speed);
                GenSpawn.Spawn(moteThrown, origin.ToIntVec3(), map, WipeMode.Vanish);
                moteThrown.spawnTick -= (int)(magnitude * 0.75f * (mote.mote.fadeOutTime * 60));
            }
        }
Exemplo n.º 2
0
        protected void MakeMote(TargetInfo A, TargetInfo B)
        {
            Vector3 vector = Vector3.zero;

            switch (def.spawnLocType)
            {
            case MoteSpawnLocType.OnSource:
                vector = A.CenterVector3;
                break;

            case MoteSpawnLocType.BetweenPositions:
            {
                Vector3 vector2 = A.HasThing ? A.Thing.DrawPos : A.Cell.ToVector3Shifted();
                Vector3 vector3 = B.HasThing ? B.Thing.DrawPos : B.Cell.ToVector3Shifted();
                vector = ((A.HasThing && !A.Thing.Spawned) ? vector3 : ((!B.HasThing || B.Thing.Spawned) ? (vector2 * def.positionLerpFactor + vector3 * (1f - def.positionLerpFactor)) : vector2));
                break;
            }

            case MoteSpawnLocType.RandomCellOnTarget:
                vector = ((!B.HasThing) ? CellRect.CenteredOn(B.Cell, 0) : B.Thing.OccupiedRect()).RandomCell.ToVector3Shifted();
                break;

            case MoteSpawnLocType.BetweenTouchingCells:
                vector = A.Cell.ToVector3Shifted() + (B.Cell - A.Cell).ToVector3().normalized * 0.5f;
                break;
            }
            if (parent != null)
            {
                Rand.PushState(parent.GetHashCode());
                if (A.CenterVector3 != B.CenterVector3)
                {
                    vector += (B.CenterVector3 - A.CenterVector3).normalized * parent.def.offsetTowardsTarget.RandomInRange;
                }
                vector += Gen.RandomHorizontalVector(parent.def.positionRadius);
                Rand.PopState();
            }
            Map   map = A.Map ?? B.Map;
            float num = def.absoluteAngle ? 0f : (B.Cell - A.Cell).AngleFlat;

            if (map == null || !vector.ShouldSpawnMotesAt(map))
            {
                return;
            }
            int randomInRange = def.burstCount.RandomInRange;

            for (int i = 0; i < randomInRange; i++)
            {
                Mote obj = (Mote)ThingMaker.MakeThing(def.moteDef);
                GenSpawn.Spawn(obj, vector.ToIntVec3(), map);
                obj.Scale         = def.scale.RandomInRange;
                obj.exactPosition = vector + Gen.RandomHorizontalVector(def.positionRadius);
                obj.rotationRate  = def.rotationRate.RandomInRange;
                obj.exactRotation = def.rotation.RandomInRange + num;
                obj.instanceColor = def.color;
                MoteThrown moteThrown = obj as MoteThrown;
                if (moteThrown != null)
                {
                    moteThrown.airTimeLeft = def.airTime.RandomInRange;
                    moteThrown.SetVelocity(def.angle.RandomInRange + num, def.speed.RandomInRange);
                }
            }
        }
        protected void MakeMote(TargetInfo A, TargetInfo B)
        {
            Vector3 vector = Vector3.zero;

            switch (this.def.spawnLocType)
            {
            case MoteSpawnLocType.OnSource:
                vector = A.CenterVector3;
                break;

            case MoteSpawnLocType.BetweenPositions:
            {
                Vector3 vector2 = (!A.HasThing) ? A.Cell.ToVector3Shifted() : A.Thing.DrawPos;
                Vector3 vector3 = (!B.HasThing) ? B.Cell.ToVector3Shifted() : B.Thing.DrawPos;
                if (A.HasThing && !A.Thing.Spawned)
                {
                    vector = vector3;
                }
                else if (B.HasThing && !B.Thing.Spawned)
                {
                    vector = vector2;
                }
                else
                {
                    vector = vector2 * this.def.positionLerpFactor + vector3 * (1f - this.def.positionLerpFactor);
                }
                break;
            }

            case MoteSpawnLocType.BetweenTouchingCells:
                vector = A.Cell.ToVector3Shifted() + (B.Cell - A.Cell).ToVector3().normalized * 0.5f;
                break;

            case MoteSpawnLocType.RandomCellOnTarget:
            {
                CellRect cellRect;
                if (B.HasThing)
                {
                    cellRect = B.Thing.OccupiedRect();
                }
                else
                {
                    cellRect = CellRect.CenteredOn(B.Cell, 0);
                }
                vector = cellRect.RandomCell.ToVector3Shifted();
                break;
            }
            }
            if (this.parent != null)
            {
                Rand.PushState(this.parent.GetHashCode());
                if (A.CenterVector3 != B.CenterVector3)
                {
                    vector += (B.CenterVector3 - A.CenterVector3).normalized * this.parent.def.offsetTowardsTarget.RandomInRange;
                }
                vector += Gen.RandomHorizontalVector(this.parent.def.positionRadius);
                Rand.PopState();
            }
            Map   map = A.Map ?? B.Map;
            float num = (!this.def.absoluteAngle) ? (B.Cell - A.Cell).AngleFlat : 0f;

            if (map != null && vector.ShouldSpawnMotesAt(map))
            {
                int randomInRange = this.def.burstCount.RandomInRange;
                for (int i = 0; i < randomInRange; i++)
                {
                    Mote mote = (Mote)ThingMaker.MakeThing(this.def.moteDef, null);
                    GenSpawn.Spawn(mote, vector.ToIntVec3(), map, WipeMode.Vanish);
                    mote.Scale         = this.def.scale.RandomInRange;
                    mote.exactPosition = vector + Gen.RandomHorizontalVector(this.def.positionRadius);
                    mote.rotationRate  = this.def.rotationRate.RandomInRange;
                    mote.exactRotation = this.def.rotation.RandomInRange + num;
                    MoteThrown moteThrown = mote as MoteThrown;
                    if (moteThrown != null)
                    {
                        moteThrown.airTimeLeft = this.def.airTime.RandomInRange;
                        moteThrown.SetVelocity(this.def.angle.RandomInRange + num, this.def.speed.RandomInRange);
                    }
                }
            }
        }