private void FireAt(Comet comet, float dt)
        {
            float electricity_used = laser_electricity_consumption * dt;

            if (electricity_available < electricity_used)
            {
                return;
            }
            electricity_available -= electricity_used;

            var primary_element = comet.gameObject.GetComponent <PrimaryElement>();
            var heat_energy     = laser_heat_production * dt;

            if (primary_element.Mass > 100)
            {
                // HACK: Rock comets are hundreds of times more massive than iron comets. Even with the electricity to heat multiplier we couldn't affect them. Apply heat based on mass (Rock Comets are between 4000kg and 7200kg)
                heat_energy *= primary_element.Mass / 10;
            }
            // Use half the heat to ablate the meteor and the rest to warm it.
            var burn_heat_energy = 0.5f * heat_energy;
            var warm_heat_energy = heat_energy - burn_heat_energy;

            primary_element.Temperature += GameUtil.CalculateTemperatureChange(primary_element.Element.specificHeatCapacity, primary_element.Mass, warm_heat_energy / 1000 /*KJ*/);
            var mass_removed = burn_heat_energy / (1000 * primary_element.Element.specificHeatCapacity * (primary_element.Element.highTemp - primary_element.Temperature));

            if (primary_element.Temperature > primary_element.Element.highTemp || primary_element.Mass <= mass_removed)
            {
                ShowExplosion(comet);
                // Drop Resources! :D - If there is a better way to do this, I'm not surprised but I sure couldn't find it (outseeker)
                PrimaryElement component = comet.GetComponent <PrimaryElement>();
                component.Mass        = primary_element.Mass;
                component.Temperature = primary_element.Temperature;
                Element    element   = component.Element;
                Substance  substance = element.substance;
                GameObject go        = substance.SpawnResource(comet.transform.GetPosition(), component.Mass, component.Temperature, byte.MaxValue, 0);
                //Debug.Log("Spawned resource from destroyed comet");
                Util.KDestroyGameObject(comet.gameObject);
                kills += 1;
            }
            else
            {
                primary_element.SetMassTemperature(primary_element.Mass - mass_removed, primary_element.Temperature);
                ShowDamageFx(comet.transform.position);
            }

            float sqrMagnitude = (Vec3To2D(comet.transform.position) - Vec3To2D(transform.position)).sqrMagnitude;

            arm_anim_ctrl.GetBatchInstanceData().SetClipRadius(transform.position.x, transform.position.y, sqrMagnitude, do_clip: true);
            foreach (var beam_seg in beam_segs)
            {
                beam_seg.GetComponent <KBatchedAnimController>().GetBatchInstanceData().SetClipRadius(arm_anim_ctrl.transform.position.x, arm_anim_ctrl.transform.position.y, sqrMagnitude, do_clip: true);
            }
        }
Esempio n. 2
0
	private void RemovedFromStorage()
	{
		storage = null;
		UpdateCachedCell(Grid.PosToCell(this));
		RefreshStorageTags(null);
		AddFaller(Vector2.zero);
		KBatchedAnimController component = GetComponent<KBatchedAnimController>();
		component.enabled = true;
		base.gameObject.transform.rotation = Quaternion.identity;
		RegisterListeners();
		component.GetBatchInstanceData().ClearOverrideTransformMatrix();
	}
 public void UpdateDig(float dt)
 {
     if (HasDigCell && rotation_complete)
     {
         Diggable.DoDigTick(dig_cell, dt);
         float percentComplete = Grid.Damage[dig_cell];
         mining_sounds.SetPercentComplete(percentComplete);
         Vector3 a = Grid.CellToPosCCC(dig_cell, Grid.SceneLayer.FXFront2);
         a.z = 0f;
         Vector3 position = arm_go.transform.GetPosition();
         position.z = 0f;
         float sqrMagnitude = (a - position).sqrMagnitude;
         arm_anim_ctrl.GetBatchInstanceData().SetClipRadius(position.x, position.y, sqrMagnitude, true);
         if (!ValidDigCell(dig_cell))
         {
             dig_cell          = Grid.InvalidCell;
             rotation_complete = false;
         }
     }
 }
Esempio n. 4
0
    private void OnDepositObject(Pickupable pickupable)
    {
        SetPreview(Tag.Invalid, false);
        MaterialNeeds.Instance.UpdateNeed(requestedEntityTag, -1f);
        KBatchedAnimController component = pickupable.GetComponent <KBatchedAnimController>();

        if ((Object)component != (Object)null)
        {
            component.GetBatchInstanceData().ClearOverrideTransformMatrix();
        }
        occupyingObject = SpawnOccupyingObject(pickupable.gameObject);
        if ((Object)occupyingObject != (Object)null)
        {
            occupyingObject.SetActive(true);
            PositionOccupyingObject();
            SubscribeToOccupant();
        }
        else
        {
            Debug.LogWarning(base.gameObject.name + " EntityReceptacle did not spawn occupying entity.");
        }
        if (fetchChore != null)
        {
            fetchChore.Cancel("receptacle filled");
            fetchChore = null;
        }
        if (!autoReplaceEntity)
        {
            requestedEntityTag = Tag.Invalid;
        }
        UpdateActive();
        UpdateStatusItem();
        if (destroyEntityOnDeposit)
        {
            Util.KDestroyGameObject(pickupable.gameObject);
        }
        Trigger(-731304873, occupyingObject);
    }
Esempio n. 5
0
    private void UpdateFrame()
    {
        forceUpdate = false;
        bool symbolVisible = false;

        KAnim.Anim currentAnim = controller.CurrentAnim;
        if (currentAnim != null)
        {
            Matrix2x3 symbolLocalTransform = controller.GetSymbolLocalTransform(symbol, out symbolVisible);
            Vector3   position             = controller.transform.GetPosition();
            if (symbolVisible && (previousMatrix != symbolLocalTransform || position != previousPosition || useTargetPoint))
            {
                previousMatrix   = symbolLocalTransform;
                previousPosition = position;
                Matrix2x3 overrideTransformMatrix = controller.GetTransformMatrix() * symbolLocalTransform;
                Vector3   position2 = base.transform.GetPosition();
                float     z         = position2.z;
                base.transform.SetPosition(overrideTransformMatrix.MultiplyPoint(offset));
                if (useTargetPoint)
                {
                    Vector3 position3 = base.transform.GetPosition();
                    position3.z = 0f;
                    Vector3 from = targetPoint - position3;
                    float   num  = Vector3.Angle(from, Vector3.right);
                    if (from.y < 0f)
                    {
                        num = 360f - num;
                    }
                    base.transform.localRotation = Quaternion.identity;
                    base.transform.RotateAround(position3, new Vector3(0f, 0f, 1f), num);
                    float sqrMagnitude = from.sqrMagnitude;
                    KBatchedAnimInstanceData batchInstanceData = myAnim.GetBatchInstanceData();
                    Vector3 position4 = base.transform.GetPosition();
                    float   x         = position4.x;
                    Vector3 position5 = base.transform.GetPosition();
                    batchInstanceData.SetClipRadius(x, position5.y, sqrMagnitude, true);
                }
                else
                {
                    Vector3 v  = (!controller.FlipX) ? Vector3.right : Vector3.left;
                    Vector3 v2 = (!controller.FlipY) ? Vector3.up : Vector3.down;
                    base.transform.up    = overrideTransformMatrix.MultiplyVector(v2);
                    base.transform.right = overrideTransformMatrix.MultiplyVector(v);
                    if ((Object)myAnim != (Object)null)
                    {
                        myAnim.GetBatchInstanceData()?.SetOverrideTransformMatrix(overrideTransformMatrix);
                    }
                }
                Transform transform = base.transform;
                Vector3   position6 = base.transform.GetPosition();
                float     x2        = position6.x;
                Vector3   position7 = base.transform.GetPosition();
                transform.SetPosition(new Vector3(x2, position7.y, z));
                myAnim.SetDirty();
            }
        }
        if ((Object)myAnim != (Object)null && symbolVisible != myAnim.enabled)
        {
            myAnim.enabled = symbolVisible;
        }
    }
Esempio n. 6
0
        // This method syncs the object to the transform of the neck snap point in the dupe
        void LateUpdate()
        {
            bool symbolVisible = false;

            if (dupeAnim.CurrentAnim != null)
            {
                var batch = dupeAnim.GetBatch();
                var frame = batch.group.data.GetFrame(dupeAnim.GetCurrentFrameIndex());
                if (frame != KAnim.Anim.Frame.InvalidFrame)
                {
                    for (int i = 0; i < frame.numElements; i++)
                    {
                        int num = frame.firstElementIdx + i;
                        if (num < batch.group.data.frameElements.Count)
                        {
                            KAnim.Anim.FrameElement frameElement = batch.group.data.frameElements[num];
                            if (frameElement.symbol == symbol)
                            {
                                if (frameElement.frame == 0)
                                {
                                    if (facing <= 0)
                                    {
                                        myAnim.Play(front_anim);
                                        facing = 1;
                                    }
                                }
                                else
                                {
                                    if (facing >= 0)
                                    {
                                        myAnim.Play(back_anim);
                                        facing = -1;
                                    }
                                }
                            }
                        }
                    }
                }

                symbolVisible = dupeAnim.GetSymbolVisiblity(symbol);
                bool      unusedBool;
                Matrix2x3 symbolLocalTransform = dupeAnim.GetSymbolLocalTransform(symbol, out unusedBool);
                Vector3   position             = dupeAnim.transform.GetPosition();
                if (symbolVisible && (previousMatrix != symbolLocalTransform || position != previousPosition))
                {
                    previousMatrix   = symbolLocalTransform;
                    previousPosition = position;
                    Matrix2x3 overrideTransformMatrix = dupeAnim.GetTransformMatrix() * symbolLocalTransform;
                    float     z = base.transform.GetPosition().z;
                    base.transform.SetPosition(overrideTransformMatrix.MultiplyPoint(offset));

                    Vector3 v  = dupeAnim.FlipX ? Vector3.left : Vector3.right;
                    Vector3 v2 = dupeAnim.FlipY ? Vector3.down : Vector3.up;
                    base.transform.up    = overrideTransformMatrix.MultiplyVector(v2);
                    base.transform.right = overrideTransformMatrix.MultiplyVector(v);
                    if (myAnim != null)
                    {
                        myAnim.GetBatchInstanceData()?.SetOverrideTransformMatrix(overrideTransformMatrix);
                    }

                    base.transform.SetPosition(new Vector3(base.transform.GetPosition().x, base.transform.GetPosition().y, z));

                    myAnim.Offset = dupeAnim.Offset;
                    myAnim.SetDirty();
                }
            }
            if (myAnim != null && symbolVisible != myAnim.enabled)
            {
                myAnim.enabled = symbolVisible;
            }
        }