コード例 #1
0
        public void CalculateCurvePoints(Vector3 start, Vector3 end, float variance)
        {
            int     variancePoints = 20;
            Vector3 initialVector  = SPT_Utility.GetVector(start, end);

            initialVector.y = 0;
            float initialAngle = (initialVector).ToAngleFlat(); //Quaternion.AngleAxis(90, Vector3.up) *
            float curveAngle   = 0;

            if (Rand.Chance(.5f))
            {
                curveAngle = variance;
            }
            else
            {
                curveAngle = (-1) * variance;
            }
            //calculate extra distance bolt travels around the ellipse
            float a = .5f * Vector3.Distance(start, end);
            float b = a * Mathf.Sin(.5f * Mathf.Deg2Rad * variance);
            float p = .5f * Mathf.PI * (3 * (a + b) - (Mathf.Sqrt((3 * a + b) * (a + 3 * b))));

            float incrementalDistance = p / variancePoints;
            float incrementalAngle    = (curveAngle / variancePoints) * 2;

            this.curvePoints.Add(this.trueOrigin);
            for (int i = 1; i < variancePoints; i++)
            {
                this.curvePoints.Add(this.curvePoints[i - 1] + ((Quaternion.AngleAxis(curveAngle, Vector3.up) * initialVector) * incrementalDistance)); //(Quaternion.AngleAxis(curveAngle, Vector3.up) *
                curveAngle -= incrementalAngle;
            }
        }
コード例 #2
0
        protected virtual void Impact(Thing hitThing)
        {
            if (this.impactRadius > 0)
            {
                if (this.isExplosive)
                {
                    GenExplosion.DoExplosion(this.ExactPosition.ToIntVec3(), this.Map, this.impactRadius, this.impactDamageType, this.launcher as Pawn, this.explosionDamage, -1, this.impactDamageType.soundExplosion, def, null, null, null, 0f, 1, false, null, 0f, 0, 0.0f, true);
                }
                else
                {
                    this.impactCells = GenRadial.RadialCellsAround(this.Position, this.impactRadius, true).ToList();
                }
            }

            //From nanite to bench // not null
            //This.Launcher WHEN RETURNING HOME = Bench
            //This.LAUNCHER when being sent to job = NF

            Building_NaniteFactory factory       = this.launcher as Building_NaniteFactory; // NULL // THING
            Building_NaniteFactory returnFactory = hitThing as Building_NaniteFactory;


            Log.Message("1");
            if (!factory.DestroyedOrNull())
            {
                Log.Message("2");
                if (dispersalMethod == NaniteDispersal.Spray && !hitThing.DestroyedOrNull() && hitThing.Spawned)
                {
                    Log.Message("3");
                    this.sprayVec             = SPT_Utility.GetVector(this.curvePoints[this.curvePoints.Count - 1], hitThing.DrawPos);
                    this.impacted             = true;
                    this.ticksFollowingImpact = 35;
                    if (naniteAction == NaniteActions.Repair)
                    {
                        factory.RepairJobs.Add(hitThing);
                    }
                    else if (naniteAction == NaniteActions.Construct)
                    {
                        Frame constructFrame = hitThing as Frame;
                        factory.ConstructJobs.Add(constructFrame);
                    }
                    else if (naniteAction == NaniteActions.Deconstruct)
                    {
                        factory.DeconstructJobs.Add(hitThing);
                    }
                }
                else if (dispersalMethod == NaniteDispersal.ExplosionMist && !hitThing.DestroyedOrNull() && hitThing.Spawned)
                {
                    this.sprayVec             = SPT_Utility.GetVector(this.curvePoints[this.curvePoints.Count - 1], hitThing.DrawPos);
                    this.impacted             = true;
                    this.ticksFollowingImpact = 15;
                    if (naniteAction == NaniteActions.Repair)
                    {
                        factory.RepairJobs.Add(hitThing);
                    }
                    else if (naniteAction == NaniteActions.Construct)
                    {
                        Frame constructFrame = hitThing as Frame;
                        factory.ConstructJobs.Add(constructFrame);
                    }
                    else if (naniteAction == NaniteActions.Deconstruct)
                    {
                        factory.DeconstructJobs.Add(hitThing);
                    }
                }

                else
                {
                    Log.Message("5");

                    this.Destroy(DestroyMode.Vanish);
                }
            }
            else if (!returnFactory.DestroyedOrNull() && returnFactory.def == SPT_DefOf.SPT_NaniteFactory)
            {
                //if (naniteAction == NaniteActions.Return)
                //{
                returnFactory.nanitesTraveling = false;
                this.Destroy(DestroyMode.Vanish);
                //}
            }
            else
            {
                //FIRE FIRE FIRE
                this.Destroy(DestroyMode.Vanish);
            }
        }
コード例 #3
0
 private void DrawEffects(Vector3 effectVec)
 {
     effectVec.x += Rand.Range(-0.2f, 0.2f);
     effectVec.z += Rand.Range(-0.2f, 0.2f);
     SPT_Utility.ThrowGenericMote(this.moteDef, effectVec, this.Map, Rand.Range(.4f, .6f), Rand.Range(.05f, .1f), .03f, Rand.Range(.2f, .3f), Rand.Range(-200, 200), Rand.Range(.5f, 2f), Rand.Range(0, 360), Rand.Range(0, 360));
 }
コード例 #4
0
        public override void Tick()
        {
            base.Tick();
            if (!this.impacted)
            {
                Vector3 exactPosition = this.ExactPosition;
                if (this.ticksToImpact >= 0 && this.moteDef != null && Find.TickManager.TicksGame % this.moteFrequency == 0)
                {
                    DrawEffects(exactPosition);
                }
                this.ticksToImpact--;
                bool flag = !this.ExactPosition.InBounds(base.Map);
                if (flag)
                {
                    this.ticksToImpact++;
                    base.Position = this.ExactPosition.ToIntVec3();
                    this.Destroy(DestroyMode.Vanish);
                }
                else if (this.dispersalMethod == NaniteDispersal.Spray && !this.ExactPosition.ToIntVec3().GetTransmitter(this.Map).TransmitsPowerNow)
                {
                    this.earlyImpact = true;
                    this.impactForce = (this.DestinationCell - this.ExactPosition.ToIntVec3()).LengthHorizontal + (this.speed * .2f);
                    this.ImpactSomething();
                }
                else
                {
                    base.Position = this.ExactPosition.ToIntVec3();
                    //if (Find.TickManager.TicksGame % 3 == 0)
                    //{
                    //    MoteMaker.ThrowDustPuff(base.Position, base.Map, Rand.Range(0.6f, .8f));
                    //}

                    bool flag2 = this.ticksToImpact <= 0;
                    if (flag2)
                    {
                        if (this.curveVariance > 0)
                        {
                            if ((this.curvePoints.Count() - 1) > this.destinationCurvePoint)
                            {
                                this.origin = curvePoints[destinationCurvePoint];
                                this.destinationCurvePoint++;
                                this.destination   = this.curvePoints[this.destinationCurvePoint];
                                this.ticksToImpact = this.StartingTicksToImpact;
                            }
                            else
                            {
                                bool flag3 = this.DestinationCell.InBounds(base.Map);
                                if (flag3)
                                {
                                    base.Position = this.DestinationCell;
                                }
                                this.ImpactSomething();
                            }
                        }
                        else
                        {
                            bool flag3 = this.DestinationCell.InBounds(base.Map);
                            if (flag3)
                            {
                                base.Position = this.DestinationCell;
                            }
                            this.ImpactSomething();
                        }
                    }
                }
            }

            if (this.impacted)
            {
                if (this.ticksFollowingImpact > 0 && Find.TickManager.TicksGame % 2 == 0 && this.dispersalMethod == NaniteDispersal.Spray)
                {
                    //Spray nanites

                    SPT_Utility.ThrowGenericMote(SPT_DefOf.SPT_Mote_NanitesAir, this.ExactPosition, this.launcher.Map, Rand.Range(.8f, 1.2f), .3f, .01f, .3f, Rand.Range(-100, 100), 5, (Quaternion.AngleAxis(Rand.Range(80, 100), Vector3.up) * sprayVec).ToAngleFlat(), Rand.Range(0, 360));
                }

                if (this.ticksFollowingImpact > 0 && this.dispersalMethod == NaniteDispersal.ExplosionMist && this.impactRadius > 0 && Find.TickManager.TicksGame % 3 == 0)
                {
                    for (int i = 0; i < impactCells.Count; i++)
                    {
                        //Spray nanites

                        SPT_Utility.ThrowGenericMote(SPT_DefOf.SPT_Mote_NanitesAir, impactCells[i].ToVector3Shifted(), this.launcher.Map, Rand.Range(1.5f, 2f), .5f, .01f, Rand.Range(.5f, 1), Rand.Range(-500, 500), Rand.Range(2, 5), (Quaternion.AngleAxis(Rand.Range(80, 100), Vector3.up) * sprayVec).ToAngleFlat(), Rand.Range(0, 360));
                    }
                }

                this.ticksFollowingImpact--;

                if (this.ticksFollowingImpact < 0)
                {
                    this.Destroy(DestroyMode.Vanish);
                }
            }
        }