コード例 #1
0
    //Split this up into multiple calculators
    public virtual void ProcessTerminalHit(TerminalBallisticsData penData)
    {
        //penData.projectile.physicsTransform.Position = penData.hitInfo.point;

        #region Projectile Hitable

        //If object is IProjectileHitable, then 'hit' it

        IProjectileHitable hitable = penData.hitInfo.collider.GetComponent <IProjectileHitable>();

        if (hitable != null)
        {
            hitable.Hit(penData.projectile, penData.hitInfo);

            //{TODO} Properly setup how much kinetic energy we lose to the impact
            if (hitable.recieveImpulse)
            {
                penData.hitInfo.collider.attachedRigidbody.AddForceAtPosition(
                    penData.projectile.physicsTransform.Velocity,
                    penData.projectile.physicsTransform.Position,
                    ForceMode.Impulse
                    );
            }
        }


        #endregion
    }
コード例 #2
0
ファイル: Cannon.cs プロジェクト: DaDevFox/KCModFramework
    public override void Tick(float dt)
    {
        try
        {
            this.veteranDecor.gameObject.SetActive(this.b.GetAvgSkill() > 0.5f);
            base.Tick(dt);
            float num = this.b.GetWorkerPercent() * (float)((!this.b.AreWorkersNear(this.b.jobs.Count)) ? 0 : 1);
            this.flag.SetActive(num > 0f);
            if (!this.b.IsBuilt() || num <= 0f)
            {
                this.pd.suppressFiring = true;
            }
            else
            {
                IProjectileHitable projectileHitable = this.pd.attackTarget;
                if (projectileHitable == null || projectileHitable.Equals(null))
                {
                    projectileHitable = this.pd.trackingTarget;
                }
                if (projectileHitable != null && !projectileHitable.Equals(null))
                {
                    Vector3    forward = this.RotateParent.position - projectileHitable.GetPredictedPosition(1f);
                    Quaternion to      = Quaternion.LookRotation(forward);

                    float num2 = Vector3.Dot(forward.normalized, this.RotateParent.forward);
                    this.pd.suppressFiring = (num2 < Mathf.Cos(0.017453292f * this.MinTargetAngleForFiring));


                    Quaternion baseAtPos = Quaternion.LookRotation(new Vector3(forward.x, 0, forward.z), Vector3.up);
                    cannon.rotation = Quaternion.RotateTowards(cannon.rotation, baseAtPos, Time.deltaTime * this.baseRotateSpeed);

                    to.y = 0f;
                    to.z = 0f;

                    this.RotateParent.localRotation = Quaternion.Slerp(this.RotateParent.localRotation, to, Time.deltaTime * this.barrelRotateSpeed);
                }
                if (this.state == Cannon.State.Reload)
                {
                    this.reloadTime += dt;
                    if (this.reloadTime > 2f)
                    {
                        this.reloadTime = 2f;
                    }

                    if (this.reloadTime <= 1f)
                    {
                        float t = Mathf.SmoothStep(0f, 1f, this.reloadTime);
                        this.SetRotationY(this.hatch, Mathf.Lerp(0f, this.reloadAngle, t));
                    }
                    else
                    {
                        float t = Mathf.SmoothStep(0f, 1f, this.reloadTime - 1f);
                        this.SetRotationY(this.hatch, Mathf.Lerp(this.reloadAngle, 0f, t));
                        this.cannonBall.gameObject.SetActive(true);

                        Vector3 localPosition = this.cannonBall.localPosition;
                        localPosition.z = Mathf.Lerp(.6f, .2f, t);
                        localPosition.y = Mathf.Lerp(0f, .3f, t);
                        this.cannonBall.localPosition = localPosition;
                    }
                }
                else if (this.state == Cannon.State.Firing)
                {
                    this.fireTime += dt * 5f;
                    if (this.fireTime > 1f)
                    {
                        this.fireTime = 1f;
                        this.state    = Cannon.State.Reload;
                        SfxSystem.inst.PlayFromBank("BuildingSelectCastleGate", base.transform.position, null);
                        this.reloadTime = 0f;
                    }
                }
            }
        }
        catch (Exception err)
        {
            ModMain.helper.Log(err.ToString());
        }
    }
コード例 #3
0
            static void Postfix(TroopTransportShip __instance, IMoveTarget target, List <IMoveableUnit> ___loadTarget)
            {
                if (__instance.TeamID() != 0 || target == null || target.TeamID() == 0 || target.TeamID() == -1)
                {
                    // Not an allied ship, no target, target is allied, or target is environment.
                    // Refer to UnitSystem::UpdatePathing for determining if target is an enemy.
                    return;
                }

                // Check if ship has archers.
                bool shipHasArchers = false;

                // Refer to TroopTransportShip::UpdateArmyPosition.
                for (int i = 0; i < ___loadTarget.Count(); i++)
                {
                    UnitSystem.Army army = ___loadTarget[i] as UnitSystem.Army;
                    if (army != null)
                    {
                        bool isArcher = army.armyType == UnitSystem.ArmyType.Archer;
                        if (isArcher)
                        {
                            shipHasArchers = true;
                            break;
                        }
                    }
                }

                if (shipHasArchers)
                {
                    IMoveTarget archersTarget = null;

                    if (target is SiegeMonster)
                    {
                        SiegeMonster ogre            = (SiegeMonster)target;
                        bool         ogreTargettable = !ogre.IsInvalid();
                        bool         ogreDead        = ogre.IsDead();

                        if (ogreTargettable)
                        {
                            // Ogre is on land.
                            archersTarget = target;
                        }
                        else if (!ogreTargettable && !ogreDead)
                        {
                            // Ogre is on a ship. Assumption is that the closest ship is the ship it's on.
                            Vector3 pos = ogre.GetPos();

                            // Refer to ProjectileDefense::GetTarget
                            IProjectileHitable closestShip = ShipSystem.inst.GetClosestShipToAttack(pos, 1, 1f);
                            ShipBase           shipBase    = closestShip as ShipBase;
                            if (shipBase != null)
                            {
                                archersTarget = shipBase.GetComponentInParent <TroopTransportShip>();
                            }
                        }
                    }
                    else if (target is TroopTransportShip || target is IProjectileHitable)
                    {
                        archersTarget = target;
                    }

                    // Set archer target.
                    if (archersTarget != null)
                    {
                        for (int i = 0; i < ___loadTarget.Count(); i++)
                        {
                            UnitSystem.Army army = ___loadTarget[i] as UnitSystem.Army;
                            if (army != null)
                            {
                                bool isArcher = army.armyType == UnitSystem.ArmyType.Archer;
                                if (isArcher)
                                {
                                    army.moveTarget = archersTarget;
                                }
                            }
                        }
                    }
                }
            }