コード例 #1
0
 public NPCDataAnimator(IMyCubeGrid grid, IMySlimBlock npc, float moveSpeed)
 {
     this.grid      = grid;
     this.npc       = npc;
     this.moveSpeed = moveSpeed;
     top_left_leg   = npc.FatBlock.GetSubpart("leg_top_left");
     top_right_leg  = npc.FatBlock.GetSubpart("leg_top_right");
     //gun_muzzle = npc.FatBlock.GetSubpart("muzzle_projectile");
     bottom_left_leg  = top_left_leg.GetSubpart("leg_bottom_left");
     bottom_right_leg = top_right_leg.GetSubpart("leg_bottom_right");
 }
コード例 #2
0
        public IMyCubeGrid GetTarget()
        {
            //var turretBase = Entity as Sandbox.ModAPI.IMyLargeTurretBase;
            //var fixedWeapon = Entity as Sandbox.ModAPI.IMyUserControllableGun;

            //if (turretBase != null)
            //{
            //    target = turretBase.Target;
            //}

            try {
                MyEntitySubpart subpart1 = cubeBlock.GetSubpart("GatlingTurretBase1");
                MyEntitySubpart subpart2 = subpart1.GetSubpart("GatlingTurretBase2");

                if (cubeBlock == null || cubeBlock.CubeGrid == null || subpart1 == null || subpart2 == null || subpart1.WorldMatrix == null || subpart2.WorldMatrix == null)
                {
                    return(null);
                }

                var from = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 0.3d;
                var to   = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 800d;

                LineD ray = new LineD(from, to);
                List <MyLineSegmentOverlapResult <MyEntity> > result = new List <MyLineSegmentOverlapResult <MyEntity> >();
                MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref ray, result, MyEntityQueryType.Both);

                foreach (var resultItem in result)
                {
                    if (resultItem.Element == null)
                    {
                        continue;
                    }

                    if (resultItem.Element.EntityId != cubeBlock.CubeGrid.EntityId)
                    {
                        if (resultItem.Element is IMyCubeGrid)
                        {
                            return(resultItem.Element as IMyCubeGrid);
                        }
                    }
                }
            }
            catch (KeyNotFoundException)
            {
            }
            return(null);
        }
コード例 #3
0
        public override void UpdateBeforeSimulation()
        {
            if (UI == null || !UI.Initialized_Attractor)
            {
                return;
            }
            if (Entity == null)
            {
                return;
            }

            IMyCubeBlock cube   = Entity as IMyCubeBlock;
            var          target = GetTarget();


            var isShooting = (Entity as Sandbox.ModAPI.IMyUserControllableGun).IsShooting;

            if (isShooting && target != null && target.Physics != null)
            {
                var             grid     = target;
                MyEntitySubpart subpart1 = cubeBlock.GetSubpart("GatlingTurretBase1");
                MyEntitySubpart subpart2 = subpart1.GetSubpart("GatlingTurretBase2");

                if (subpart1 == null || subpart2 == null || subpart1.WorldMatrix == null || subpart2.WorldMatrix == null)
                {
                    return;
                }

                var from     = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 0.3d;
                var to       = target.Physics.CenterOfMassWorld;
                var toTarget = to - from;
                toTarget.Normalize();


                var distance    = Vector3D.Distance(from, to);
                var min         = UI.MinSlider.Getter(terminalBlock);
                var max         = UI.MaxSlider.Getter(terminalBlock);
                var force       = UI.StrengthSlider.Getter(terminalBlock);
                var forceVector = force * toTarget;

                if (distance > max)
                {
                    grid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, -forceVector, null, null);
                }
                else if (distance < min)
                {
                    var percentage      = 1 - (distance * distance) / (min * min);
                    var additionalForce = toTarget * percentage * (UI.StrengthSlider.Max - force);
                    var velocity        = new Vector3D(grid.Physics.LinearVelocity);
                    velocity.Normalize();
                    grid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, forceVector + additionalForce / 4, null, null);
                }
                else
                {
                    var velocity = new Vector3D(grid.Physics.LinearVelocity);
                    velocity.Normalize();
                    grid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, force * -velocity / 3, null, null);
                }

                DrawShootingEffect(from, to);
            }
            Recharge();
        }
コード例 #4
0
        public override void UpdateBeforeSimulation()
        {
            int chargesInInventory = (int)m_inventory.GetItemAmount(chargeDefinitionIds [damageUpgrades]);

            IMyCubeBlock cube = Entity as IMyCubeBlock;

            long currentShootTime = ((MyObjectBuilder_InteriorTurret)cube.GetObjectBuilderCubeBlock()).GunBase.LastShootTime;


            if (currentHeat > 0f)
            {
                if ((ticks - lastShootTimeTicks) > beamWeaponInfo.heatDissipationDelay)
                {
                    currentHeat -= beamWeaponInfo.heatDissipationPerTick;

                    if (currentHeat <= 0f)
                    {
                        currentHeat = 0f;

                        overheated = false;
                    }
                }
            }

            //MyAPIGateway.Utilities.ShowNotification("TIME: " + currentShootTime + " :: " + lastShootTime, 17, MyFontEnum.Red);


            if (currentShootTime != lastShootTime)
            {
                // test

                hitBool = false;

                MyEntitySubpart subpart1 = cubeBlock.GetSubpart("InteriorTurretBase1");
                MyEntitySubpart subpart2 = subpart1.GetSubpart("InteriorTurretBase2");;
                //MyAPIGateway.Utilities.ShowNotification("Dif: " + (currentShootTime - lastShootTime), 17, MyFontEnum.Blue);

                from = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 1.25d;
                to   = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 3000d;

                LineD testRay = new LineD(from, to);

                List <MyLineSegmentOverlapResult <MyEntity> > result = new List <MyLineSegmentOverlapResult <MyEntity> >();

                MyGamePruningStructure.GetAllEntitiesInRay(ref testRay, result);


                foreach (var resultItem in result)
                {
                    IMyCubeGrid grid = resultItem.Element as IMyCubeGrid;

                    IMyDestroyableObject destroyableEntity = resultItem.Element as IMyDestroyableObject;

                    if (grid != null)
                    {
                        IMySlimBlock slimblock;

                        double hitd;

                        Vector3D?resultVec = grid.GetLineIntersectionExactAll(ref testRay, out hitd, out slimblock);

                        if (resultVec != null)
                        {
                            hitBool = true;

                            toTarget = from + subpart2.WorldMatrix.Forward * hitd;

                            if (!MyAPIGateway.Session.CreativeMode)
                            {
                                slimblock.DoDamage(beamWeaponInfo.damage * (currentHeat / beamWeaponInfo.maxHeat + 0.2f), MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                            }
                            else
                            {
                                slimblock.DoDamage(beamWeaponInfo.damage * 1.2f, MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                            }
                            //MyAPIGateway.Utilities.ShowNotification("" + s.BlockDefinition.Id.SubtypeId + " ::: " + resultItem.Distance, 17);
                        }
                    }
                    if (destroyableEntity != null)
                    {
                        IMyEntity ent  = (IMyEntity)destroyableEntity;
                        double    hitd = (from - ent.WorldMatrix.Translation).Length();

                        toTarget = from + subpart2.WorldMatrix.Forward * hitd;

                        hitBool = true;

                        if (!MyAPIGateway.Session.CreativeMode)
                        {
                            destroyableEntity.DoDamage(beamWeaponInfo.damage * (currentHeat / beamWeaponInfo.maxHeat + 0.2f), MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                        }
                        else
                        {
                            destroyableEntity.DoDamage(beamWeaponInfo.damage * 1.2f, MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                        }
                    }
                }


                // test

                lastShootTime      = currentShootTime;
                lastShootTimeTicks = ticks;

                currentHeat += beamWeaponInfo.heatPerTick;

                if (currentHeat > beamWeaponInfo.maxHeat)
                {
                    currentHeat = beamWeaponInfo.maxHeat;

                    overheated = true;
                }
            }

            if (ticks - lastShootTimeTicks < 3)
            {
                var beamcolor     = Color.DodgerBlue;
                var beamcolor_aux = Color.LightSkyBlue;
                var maincolor     = new Vector4(beamcolor.X / 30, beamcolor.Y / 30, beamcolor.Z / 30, 1f);
                var auxcolor      = new Vector4(beamcolor_aux.X / 30, beamcolor_aux.Y / 30, beamcolor_aux.Z / 30, 1f);
                var material      = MyStringId.GetOrCompute("WeaponLaser");
                if (hitBool == false)
                {
                    if (!MyAPIGateway.Utilities.IsDedicated)
                    {
                        if (!MyAPIGateway.Session.CreativeMode)
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref auxcolor, 0.30f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref maincolor, 1.0f);
                        }
                        else
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref auxcolor, 0.30f * 1.2f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref maincolor, 1.0f * 1.2f);
                        }
                    }
                }
                else
                {
                    if (!MyAPIGateway.Utilities.IsDedicated)
                    {
                        if (!MyAPIGateway.Session.CreativeMode)
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref auxcolor, 0.30f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref maincolor, 1.0f);
                        }
                        else
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref auxcolor, 0.30f * 1.2f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref maincolor, 1.0f * 1.2f);
                        }
                    }
                }
            }

            if (chargesInInventory < beamWeaponInfo.keepAtCharge)
            {
                if (resourceSink.RequiredInputByType(electricityDefinition) != (beamWeaponInfo.powerUsage / efficiencyUpgrades))
                {
                    resourceSink.SetRequiredInputByType(electricityDefinition, (beamWeaponInfo.powerUsage / efficiencyUpgrades));

                    setPowerConsumption = (beamWeaponInfo.powerUsage / efficiencyUpgrades);
                    powerConsumption    = (beamWeaponInfo.powerUsage / efficiencyUpgrades);
                }
                else
                {
                    if (!functionalBlock.Enabled)
                    {
                        powerConsumption = 0.0001f;
                    }
                }

                if (resourceSink.CurrentInputByType(electricityDefinition) == (beamWeaponInfo.powerUsage / efficiencyUpgrades))
                {
                    if (!overheated)
                    {
                        m_inventory.AddItems((MyFixedPoint)(beamWeaponInfo.keepAtCharge - chargesInInventory), chargeObjectBuilders [damageUpgrades]);
                    }
                }
            }
            else if (chargesInInventory > beamWeaponInfo.keepAtCharge)
            {
                m_inventory.RemoveItemsOfType((MyFixedPoint)(chargesInInventory - beamWeaponInfo.keepAtCharge), chargeObjectBuilders [damageUpgrades]);
            }
            else
            {
                if (setPowerConsumption != 0.0001f)
                {
                    resourceSink.SetRequiredInputByType(electricityDefinition, 0.0001f);

                    setPowerConsumption = 0.0001f;
                    powerConsumption    = 0.0001f;
                }
            }

            terminalBlock.RefreshCustomInfo();

            ticks++;
        }