예제 #1
0
        public static bool CheckIfCanUpgrade(PlayerAction_Build __instance, int objId, int grade, int upgrade, ref bool __result)
        {
            ItemProto itemProto = __instance.noneTool.GetItemProto(objId);

            if (itemProto.ID != GigaStationsPlugin.ils.ID && itemProto.ID != GigaStationsPlugin.pls.ID && itemProto.ID != GigaStationsPlugin.collector.ID) // not my stations
            {
                return(true);
            }

            if (grade == 1 || upgrade < 0)
            {
                __result = false;
                VFAudio.Create("ui-error", null, Vector3.zero, true, 5);
                if (VFInput._buildConfirm.onDown || GameMain.gameTick % 10L == 0L)
                {
                    UIRealtimeTip.Popup("CantDowngradeWarn".Translate(), false);
                }
                return(false);
            }

            return(true);
        }
            // This function is based on PlayerAction_Mine.GameTick
            public void DroneGameTick()
            {
                double        powerFactor = 0.01666666753590107;
                PlanetFactory factory     = this.player.factory;

                if (factory == null)
                {
                    // This has only been seen briefly when the Render Distance mod is transitioning to or from a planet view.
                    return;
                }
                double miningEnergyCost = this.player.mecha.miningPower * powerFactor;
                double energyAvailable;
                float  fractionOfEnergyAvailable;

                this.player.mecha.QueryEnergy(miningEnergyCost, out energyAvailable, out fractionOfEnergyAvailable);
                int miningTime = (int)(this.player.mecha.miningSpeed * configSpeedScaleFactor * fractionOfEnergyAvailable * 10000f + 0.49f);

                VegeData vegeData = factory.GetVegeData(this.miningId);

                this.miningProtoId = (int)vegeData.protoId;
                VegeProto vegeProto = LDB.veges.Select((int)vegeData.protoId);

                if (vegeProto != null)
                {
                    this.miningTick += miningTime;
                    this.player.mecha.coreEnergy -= energyAvailable;
                    this.player.mecha.MarkEnergyChange(5, -miningEnergyCost);
                    this.percent = Mathf.Clamp01((float)((double)this.miningTick / (double)(vegeProto.MiningTime * 10000)));
                    if (this.miningTick >= vegeProto.MiningTime * 10000)
                    {
                        System.Random random = new System.Random(vegeData.id + ((this.player.planetData.seed & 16383) << 14));
                        bool          inventoryOverflowFlag = false;
                        int           popupQueueIndex       = 0;
                        for (int itemIdx = 0; itemIdx < vegeProto.MiningItem.Length; itemIdx++)
                        {
                            float randomMiningChance = (float)random.NextDouble();
                            if (randomMiningChance < vegeProto.MiningChance[itemIdx])
                            {
                                int minedItem      = vegeProto.MiningItem[itemIdx];
                                int minedItemCount = (int)((float)vegeProto.MiningCount[itemIdx] * (vegeData.scl.y * vegeData.scl.y) + 0.5f);
                                if (minedItemCount > 0 && LDB.items.Select(minedItem) != null)
                                {
                                    int inventoryOverflowCount = this.player.package.AddItemStacked(minedItem, minedItemCount);
                                    if (inventoryOverflowCount != 0)
                                    {
                                        UIItemup.Up(minedItem, inventoryOverflowCount);
                                        UIRealtimeTip.PopupItemGet(minedItem, inventoryOverflowCount, vegeData.pos + vegeData.pos.normalized, popupQueueIndex++);
                                    }
                                    else  // Unable to fit all items
                                    {
                                        inventoryOverflowFlag = true;
                                    }
                                }
                            }
                        }
                        VFEffectEmitter.Emit(vegeProto.MiningEffect, vegeData.pos, vegeData.rot);
                        VFAudio.Create(vegeProto.MiningAudio, null, vegeData.pos, true);
                        factory.RemoveVegeWithComponents(vegeData.id);
                        GameMain.gameScenario.NotifyOnVegetableMined((int)vegeData.protoId);
                        this.miningType = EObjectType.Entity;  // This change will cause the mission to be completed.
                        this.miningId   = 0;
                        if (inventoryOverflowFlag)
                        {
                            //Logger.LogInfo("Inventory overflow detected.");
                        }
                        this.miningTick = 0;
                    }
                }
                else
                {
                    //Logger.LogInfo("null vegeProto.  Icarus likely removed clearing target.");
                    this.miningType = EObjectType.Entity;  // This change will cause the mission to be completed.
                    this.miningId   = 0;
                    this.miningTick = 0;
                    this.percent    = 0f;
                    factory.RemoveVegeWithComponents(vegeData.id);
                }
            }
예제 #3
0
        public static bool DetermineBuildPreviewsPrefix(ref PlayerAction_Build __instance)
        {
            CommandState cmd = __instance.controller.cmd;
            //__instance.waitConfirm = false;
            bool flag  = false;
            bool flag2 = false;

            if (__instance.handPrefabDesc == null)
            {
                if (cmd.mode == 4)
                {
                    int[] consumeRegister = GameMain.statistics.production.factoryStatPool[__instance.factory.index].consumeRegister;
                    if (__instance.reformSize < 1)
                    {
                        __instance.reformSize = 1;
                    }
                    else if (__instance.reformSize > 30)
                    {
                        __instance.reformSize = 30;
                    }
                    if ((__instance.reformCenterPoint - __instance.player.position).sqrMagnitude > __instance.player.mecha.buildArea * __instance.player.mecha.buildArea)
                    {
                        if (!VFInput.onGUI)
                        {
                            __instance.cursorText    = "目标超出范围".Translate();
                            __instance.cursorWarning = true;
                            UICursor.SetCursor(ECursor.Ban);
                        }
                    }
                    else
                    {
                        if (!VFInput.onGUI)
                        {
                            UICursor.SetCursor(ECursor.Reform);
                        }
                        bool flag24 = false;
                        if (VFInput._reformPlusKey.onDown)
                        {
                            if (__instance.reformSize < 30)
                            {
                                __instance.reformSize++;
                                flag24 = true;
                                for (int num61 = 0; num61 < __instance.reformSize * __instance.reformSize; num61++)
                                {
                                    __instance.reformIndices[num61] = -1;
                                }
                            }
                        }
                        else if (VFInput._reformMinusKey.onDown && __instance.reformSize > 1)
                        {
                            __instance.reformSize--;
                            flag24 = true;
                        }
                        float radius = 0.99094594f * (float)__instance.reformSize;
                        int   num62  = __instance.factory.ComputeFlattenTerrainReform(__instance.reformPoints, __instance.reformCenterPoint, radius, __instance.reformPointsCount, 3f, 1f);
                        if (__instance.cursorValid && !VFInput.onGUI)
                        {
                            if (num62 > 0)
                            {
                                string soilCount = num62.ToString();

                                if (FreeFoundationsFreeSoilPlugin.freeSoilEnabled)
                                {
                                    soilCount = "0";
                                }
                                //Debug.Log("IF");
                                __instance.cursorText = string.Concat(new string[]
                                {
                                    "沙土消耗".Translate(),
                                    " ",
                                    soilCount,
                                    " ",
                                    "个沙土".Translate(),
                                    "\n",
                                    "改造大小".Translate(),
                                    __instance.reformSize.ToString(),
                                    "x",
                                    __instance.reformSize.ToString(),
                                    (FreeFoundationsFreeSoilPlugin.freeSoilEnabled) ?       "\n       (Free Soil is Enabled)" : string.Empty,
                                    (FreeFoundationsFreeSoilPlugin.freeFoundationEnabled) ? "\n(Free Foundations is Enabled)" : string.Empty
                                });
                            }
                            else if (num62 == 0)
                            {
                                __instance.cursorText = "改造大小".Translate() + __instance.reformSize.ToString() + "x" + __instance.reformSize.ToString() +
                                                        ((FreeFoundationsFreeSoilPlugin.freeSoilEnabled) ?       "\n       (Free Soil is Enabled)" : string.Empty) +
                                                        ((FreeFoundationsFreeSoilPlugin.freeFoundationEnabled) ? "\n(Free Foundations is Enabled)" : string.Empty);
                            }
                            else
                            {
                                int num63 = -num62;



                                string soilCount = num63.ToString();

                                if (!FreeFoundationsFreeSoilPlugin.collectSoilEnabled)
                                {
                                    soilCount = "0";
                                }
                                //Debug.Log("ELSE");



                                __instance.cursorText = string.Concat(new string[]
                                {
                                    "沙土获得".Translate(),
                                    " ",
                                    soilCount,
                                    " ",
                                    "个沙土".Translate(),
                                    "\n",
                                    "改造大小".Translate(),
                                    __instance.reformSize.ToString(),
                                    "x",
                                    __instance.reformSize.ToString(),
                                    (FreeFoundationsFreeSoilPlugin.freeSoilEnabled) ?       "\n       (Free Soil is Enabled)" : string.Empty,
                                    (FreeFoundationsFreeSoilPlugin.freeFoundationEnabled) ? "\n(Free Foundations is Enabled)" : string.Empty
                                });
                            }
                            if (VFInput._buildConfirm.pressing)
                            {
                                bool flag25 = false;
                                if (VFInput._buildConfirm.onDown)
                                {
                                    flag25 = true;
                                    __instance.reformMouseOnDown = true;
                                }
                                if (__instance.reformMouseOnDown)
                                {
                                    __instance.inReformOperation = true;
                                    if (__instance.reformChangedPoint.x != __instance.reformCenterPoint.x || __instance.reformChangedPoint.y != __instance.reformCenterPoint.y || __instance.reformChangedPoint.z != __instance.reformCenterPoint.z || flag24)
                                    {
                                        bool doItFoundation = true;
                                        if (FreeFoundationsFreeSoilPlugin.freeFoundationEnabled)
                                        {
                                            doItFoundation = __instance.handItem.BuildMode == 4;
                                        }
                                        else
                                        {
                                            doItFoundation = __instance.handItem.BuildMode == 4 && __instance.player.package.GetItemCount(__instance.handItem.ID) + __instance.player.inhandItemCount >= __instance.reformPointsCount;
                                        }
                                        if (doItFoundation)
                                        {
                                            bool doItSoil = false;

                                            if (FreeFoundationsFreeSoilPlugin.freeSoilEnabled || !FreeFoundationsFreeSoilPlugin.collectSoilEnabled)
                                            {
                                                doItSoil = __instance.player.sandCount >= 0;
                                            }
                                            else
                                            {
                                                doItSoil = __instance.player.sandCount - num62 >= 0;
                                            }
                                            //num64 = 100000;
                                            if (doItSoil)
                                            {
                                                //Debug.Log(num62);
                                                __instance.factory.FlattenTerrainReform(__instance.reformCenterPoint, radius, __instance.reformSize, __instance.veinBuried, 3f);
                                                VFAudio.Create("reform-terrain", null, __instance.reformCenterPoint, true);

                                                if (num62 < 0)
                                                {
                                                    if (FreeFoundationsFreeSoilPlugin.collectSoilEnabled)
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount - num62);
                                                    }
                                                    else
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount);
                                                    }
                                                }
                                                else
                                                {
                                                    if (FreeFoundationsFreeSoilPlugin.freeSoilEnabled)
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount);
                                                    }
                                                    else
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount - num62);
                                                    }
                                                }

                                                int num65 = __instance.reformSize * __instance.reformSize;
                                                for (int num66 = 0; num66 < num65; num66++)
                                                {
                                                    int            num67          = __instance.reformIndices[num66];
                                                    PlatformSystem platformSystem = __instance.factory.platformSystem;
                                                    if (num67 >= 0)
                                                    {
                                                        int num68 = platformSystem.GetReformType(num67);
                                                        int num69 = platformSystem.GetReformColor(num67);
                                                        if (num68 != __instance.reformType || num69 != __instance.reformColor)
                                                        {
                                                            __instance.factory.platformSystem.SetReformType(num67, __instance.reformType);
                                                            __instance.factory.platformSystem.SetReformColor(num67, __instance.reformColor);
                                                        }
                                                    }
                                                }
                                                int num70 = __instance.reformPointsCount;
                                                if (__instance.player.inhandItemCount > 0)
                                                {
                                                    int num71 = (__instance.reformPointsCount >= __instance.player.inhandItemCount) ? __instance.player.inhandItemCount : __instance.reformPointsCount;
                                                    __instance.player.UseHandItems(num71);
                                                    num70 -= num71;
                                                }
                                                int id = __instance.handItem.ID;
                                                consumeRegister[id] += __instance.reformPointsCount;
                                                __instance.player.package.TakeTailItems(ref id, ref num70, false);
                                                GameMain.gameScenario.NotifyOnBuild(__instance.player.planetId, __instance.handItem.ID, 0);
                                            }
                                            else if (flag25)
                                            {
                                                //Debug.Log("No1");
                                                UIRealtimeTip.Popup("沙土不足".Translate(), true, 0);
                                            }
                                        }
                                        else if (flag25)
                                        {
                                            //Debug.Log("No2");
                                            UIRealtimeTip.Popup("物品不足".Translate(), true, 1);
                                        }
                                    }
                                }
                                else
                                {
                                    __instance.inReformOperation = false;
                                }
                                __instance.reformChangedPoint = __instance.reformCenterPoint;
                            }
                            else
                            {
                                __instance.inReformOperation  = false;
                                __instance.reformChangedPoint = Vector3.zero;
                                __instance.reformMouseOnDown  = false;
                            }
                        }
                    }
                }
                else
                {
                    // Just do original code instead
                    return(true);
                }
                __instance.ClearBuildPreviews();
            }
            else
            {
                return(true);
            }
            if (!flag)
            {
                UIRoot.instance.uiGame.CloseInserterBuildTip();
            }
            if (!flag2)
            {
                UIRoot.instance.uiGame.beltBuildTip.SetOutputEntity(0, -1);
                UIRoot.instance.uiGame.CloseBeltBuildTip();
            }


            // Don't execute original put original above instead?
            return(false);
        }
예제 #4
0
        public static bool CalculatePositions(BuildTool_BlueprintPaste tool, List <ReformData> reforms, Color[] colors)
        {
            ReformBPUtils.currentGrid = tool.factory.planet.aux.mainGrid;
            PlanetData     planet         = tool.factory.planet;
            PlatformSystem platformSystem = tool.factory.platformSystem;

            Vector3 center = Vector3.zero;

            tmpPoints.Clear();

            foreach (ReformData preview in reforms)
            {
                ReformBPUtils.GetSegmentCount(preview.latitude, preview.longitude, out float latCount, out float longCount, out int segmentCount);
                longCount = Mathf.Repeat(longCount, segmentCount);

                int reformIndex = platformSystem.GetReformIndexForSegment(latCount, longCount);
                if (reformIndex < 0)
                {
                    continue;
                }

                int type = platformSystem.GetReformType(reformIndex);
                if (platformSystem.IsTerrainReformed(type))
                {
                    continue;
                }

                Vector3 pos = BlueprintUtils.GetDir(preview.longitude, preview.latitude);
                pos *= planet.realRadius + 0.2f;
                tmpPoints.Add(pos);
                center += pos;
            }

            int cost = ReformBPUtils.ComputeFlattenTerrainReform(tool.factory, tmpPoints, center);

            if (NebulaModAPI.IsMultiplayerActive)
            {
                IMultiplayerSession session = NebulaModAPI.MultiplayerSession;
                if (!session.Factories.IsIncomingRequest.Value && !CheckItems(tool, cost, tmpPoints.Count))
                {
                    return(false);
                }

                if (session.LocalPlayer.IsHost)
                {
                    int planetId = session.Factories.EventFactory?.planetId ?? GameMain.localPlanet?.id ?? -1;
                    session.Network.SendPacketToStar(new ReformPasteEventPacket(planetId, reforms, colors, session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? session.LocalPlayer.Id : session.Factories.PacketAuthor), GameMain.galaxy.PlanetById(planetId).star.id);
                }

                //If client builds, he need to first send request to the host and wait for reply
                if (!session.LocalPlayer.IsHost && !session.Factories.IsIncomingRequest.Value)
                {
                    session.Network.SendPacket(new ReformPasteEventPacket(GameMain.localPlanet?.id ?? -1, reforms, colors, session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? session.LocalPlayer.Id : session.Factories.PacketAuthor));
                    return(true);
                }
            }
            else
            {
                if (!CheckItems(tool, cost, tmpPoints.Count))
                {
                    return(false);
                }
            }

            if (colors != null && colors.Length > 0)
            {
                ApplyColors(tool, colors);
            }

            ReformBPUtils.FlattenTerrainReform(tool.factory, tmpPoints, center);
            VFAudio.Create("reform-terrain", null, center, true, 4);

            foreach (ReformData preview in reforms)
            {
                ReformBPUtils.GetSegmentCount(preview.latitude, preview.longitude, out float latCount, out float longCount, out int segmentCount);
                longCount = Mathf.Repeat(longCount, segmentCount);

                int reformIndex = platformSystem.GetReformIndexForSegment(latCount, longCount);

                if (reformIndex < 0)
                {
                    continue;
                }

                int reformType  = platformSystem.GetReformType(reformIndex);
                int reformColor = platformSystem.GetReformColor(reformIndex);
                if (reformType == preview.type && reformColor == preview.color)
                {
                    continue;
                }

                platformSystem.SetReformType(reformIndex, preview.type);
                platformSystem.SetReformColor(reformIndex, preview.color);
            }

            return(true);
        }
예제 #5
0
        public static void Update()
        {
            if (buildMenu == null || !buildMenu.childGroup.gameObject.activeSelf)
            {
                return;
            }
            if (buildMenu.currentCategory < 1 || buildMenu.currentCategory >= 9)
            {
                return;
            }

            if (CustomKeyBindSystem.GetKeyBind("ClearBuildBar").keyValue)
            {
                for (int i = 1; i <= 10; i++)
                {
                    if (!buildMenu.childButtons[i].isPointerEnter)
                    {
                        continue;
                    }

                    int buildIndex = buildMenu.currentCategory * 100 + i;

                    ConfigEntry <int> result = customBarBind.Bind("BuildBarBinds",
                                                                  buildIndex.ToString(),
                                                                  0,
                                                                  "Cleared by player");
                    result.Value = 0;
                    UIBuildMenu.protos[buildMenu.currentCategory, i] = default;
                    buildMenu.SetCurrentCategory(buildMenu.currentCategory);
                    VFAudio.Create("ui-click-0", null, Vector3.zero, true);
                    return;
                }
            }

            if (!CustomKeyBindSystem.GetKeyBind("ReassignBuildBar").keyValue)
            {
                return;
            }

            for (int j = 1; j <= 10; j++)
            {
                if (Input.GetKeyDown(KeyCode.F1 + (j - 1)) && VFInput.inScreen && !VFInput.inputing)
                {
                    int buildIndex = buildMenu.currentCategory * 100 + j;

                    UIItemPickerExtension.Popup(pickerPos, proto =>
                    {
                        if (proto != null && proto.ID != 0)
                        {
                            ConfigEntry <int> result = customBarBind.Bind("BuildBarBinds",
                                                                          buildIndex.ToString(),
                                                                          proto.ID,
                                                                          $"Item: {proto.Name.Translate()}");
                            result.Value = proto.ID;
                            UIBuildMenu.protos[buildMenu.currentCategory, j] = proto;
                            buildMenu.SetCurrentCategory(buildMenu.currentCategory);
                            VFAudio.Create("ui-click-0", null, Vector3.zero, true);
                        }
                    }, true, proto => proto.ModelIndex != 0 && proto.CanBuild);
                    UIRoot.instance.uiGame.itemPicker.OnTypeButtonClick(2);
                    return;
                }
            }
        }
예제 #6
0
        public static void MineVegetable(VegeMined packet)
        {
            if (!remotePlayersModels.TryGetValue((ushort)packet.PlayerId, out RemotePlayerModel pModel))
            {
                Debug.Log("FAILED TO SYNC VEGE DATA");
            }
            PlanetData planet = GameMain.galaxy?.PlanetById(pModel.Movement.localPlanetId);

            if (planet == null)
            {
                return;
            }

            if (packet.isVegetable) // Trees, rocks, leaves, etc
            {
                VegeData  vData  = (VegeData)planet.factory?.GetVegeData(packet.MiningID);
                VegeProto vProto = LDB.veges.Select((int)vData.protoId);
                if (vProto != null && planet.id == GameMain.localPlanet?.id)
                {
                    VFEffectEmitter.Emit(vProto.MiningEffect, vData.pos, vData.rot);
                    VFAudio.Create(vProto.MiningAudio, null, vData.pos, true);
                }
                planet.factory?.RemoveVegeWithComponents(vData.id);
            }
            else // veins
            {
                VeinData  vData  = (VeinData)planet.factory?.GetVeinData(packet.MiningID);
                VeinProto vProto = LDB.veins.Select((int)vData.type);
                if (vProto != null)
                {
                    if (planet.factory?.veinPool[packet.MiningID].amount > 0)
                    {
                        VeinData[]             vPool   = planet.factory?.veinPool;
                        PlanetData.VeinGroup[] vGroups = planet.factory?.planet.veinGroups;
                        long[] vAmounts = planet.veinAmounts;
                        vPool[packet.MiningID].amount         -= 1;
                        vGroups[(int)vData.groupIndex].amount -= 1;
                        vAmounts[(int)vData.type]             -= 1;

                        if (planet.id == GameMain.localPlanet?.id)
                        {
                            VFEffectEmitter.Emit(vProto.MiningEffect, vData.pos, Maths.SphericalRotation(vData.pos, 0f));
                            VFAudio.Create(vProto.MiningAudio, null, vData.pos, true);
                        }
                    }
                    else
                    {
                        PlanetData.VeinGroup[] vGroups = planet.factory?.planet.veinGroups;
                        vGroups[vData.groupIndex].count -= 1;

                        if (planet.id == GameMain.localPlanet?.id)
                        {
                            VFEffectEmitter.Emit(vProto.MiningEffect, vData.pos, Maths.SphericalRotation(vData.pos, 0f));
                            VFAudio.Create(vProto.MiningAudio, null, vData.pos, true);
                        }

                        planet.factory?.RemoveVeinWithComponents(vData.id);
                    }
                }
            }
        }
예제 #7
0
        public void UpdateState(PlayerAnimationUpdate packet)
        {
            bool anyMovingAnimationActive = rootAnimation.RunSlow.enabled || rootAnimation.RunFast.enabled || rootAnimation.Fly.enabled || rootAnimation.Sail.enabled || rootAnimation.Drift.enabled || rootAnimation.DriftF.enabled || rootAnimation.DriftL.enabled || rootAnimation.DriftR.enabled || !IsGrounded();
            bool anyDriftActive           = rootAnimation.Drift.enabled || rootAnimation.DriftR.enabled || rootAnimation.DriftL.enabled || rootAnimation.DriftF.enabled;
            bool fireParticleOkay         = psys != null && psysr != null && (psys[0] != null && psys[1] != null && psysr[0] != null && psysr[1] != null);

            if (anyMovingAnimationActive)
            {
                UpdateExtraSoundEffects(packet);
                if (fireParticleOkay)
                {
                    if ((!rootAnimation.RunSlow.enabled && !rootAnimation.RunFast.enabled) || anyDriftActive || rootAnimation.Sail.enabled)
                    {
                        for (int i = 0; i < psys.Length; i++)
                        {
                            if (!psys[i].isPlaying)
                            {
                                psys[i].Play();
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < psys.Length; j++)
                        {
                            if (psys[j].isPlaying)
                            {
                                psys[j].Stop();
                            }
                        }
                        StopAllFlyAudio();
                        PlayFootsteps();
                    }
                    for (int i = 0; i < psysr.Length; i++)
                    {
                        if (rootAnimation.RunSlow.enabled || rootAnimation.RunFast.enabled)
                        {
                            if (rootAnimation.RunFast.weight != 0)
                            {
                                // when flying over the planet
                                psysr[i].lengthScale = Mathf.Lerp(-3.5f, -8f, Mathf.Max(packet.horzSpeed, packet.vertSpeed) * 0.04f);
                            }
                            else
                            {
                                // when "walking" over water and moving in air without button press or while "walking" over water
                                psysr[i].lengthScale = Mathf.Lerp(-3.5f, -8f, Mathf.Max(packet.horzSpeed, packet.vertSpeed) * 0.03f);
                            }
                        }
                        if (rootAnimation.Drift.enabled)
                        {
                            // when in air without pressing spacebar
                            psysr[i].lengthScale = -3.5f;
                            if (driftAudio == null)
                            {
                                driftAudio = VFAudio.Create("drift", base.transform, Vector3.zero, false);
                                driftAudio?.Play();
                            }
                        }
                        else
                        {
                            if (driftAudio != null)
                            {
                                driftAudio.Stop();
                                driftAudio = null;
                            }
                        }
                        if (rootAnimation.Fly.enabled)
                        {
                            // when pressing spacebar but also when landing (Drift is disabled when landing)
                            psysr[i].lengthScale = Mathf.Lerp(-3.5f, -10f, Mathf.Max(packet.horzSpeed, packet.vertSpeed) * 0.03f);
                            if (flyAudio0 == null)
                            {
                                flyAudio0 = VFAudio.Create("fly-atmos", base.transform, Vector3.zero, false);
                                flyAudio0.Play();
                            }
                        }
                        else
                        {
                            if (flyAudio0 != null)
                            {
                                flyAudio0.Stop();
                                flyAudio0 = null;
                            }
                        }
                        if (rootAnimation.Sail.enabled)
                        {
                            psysr[i].lengthScale = Mathf.Lerp(-3.5f, -10f, Mathf.Max(packet.horzSpeed, packet.vertSpeed) * 15f);
                            if (flyAudio1 == null)
                            {
                                flyAudio1 = VFAudio.Create("fly-space", base.transform, Vector3.zero, false);
                                flyAudio1.Play();
                            }
                        }
                        else
                        {
                            if (flyAudio1 != null)
                            {
                                flyAudio1.Stop();
                                flyAudio1 = null;
                            }
                        }
                    }
                }
            }
            else
            {
                if (fireParticleOkay)
                {
                    for (int i = 0; i < psys.Length; i++)
                    {
                        if (psys[i].isPlaying)
                        {
                            psys[i].Stop();
                        }
                    }
                    StopAllFlyAudio();
                }
            }

            if (torchEffect != null && rootAnimation.Mining0.weight > 0.99f)
            {
                if (!torchEffect.isPlaying && miningAudio == null)
                {
                    torchEffect.Play();
                    miningAudio = VFAudio.Create("mecha-mining", base.transform, Vector3.zero, false);
                    miningAudio?.Play();
                }
            }
            else if (torchEffect != null && rootAnimation.Mining0.weight <= 0.99f)
            {
                if (torchEffect.isPlaying)
                {
                    torchEffect.Stop();
                    miningAudio?.Stop();
                    miningAudio = null;
                }
            }
        }
예제 #8
0
        // collision with vegetation, landing sound effect
        private void UpdateExtraSoundEffects(PlayerAnimationUpdate packet)
        {
            if (localPlanetId < 0)
            {
                return;
            }

            if (localPlanetId > 0)
            {
                PlanetData    pData          = GameMain.galaxy.PlanetById(localPlanetId);
                PlanetPhysics pPhys          = (pData != null) ? pData.physics : null;
                PlanetFactory pFactory       = (pData != null) ? pData.factory : null;
                float         tmpMaxAltitude = rootTransform.localPosition.magnitude - pData.realRadius;
                if (tmpMaxAltitude > 1000f)
                {
                    tmpMaxAltitude = 1000f;
                }

                if (rootAnimation.RunSlow.enabled || rootAnimation.RunFast.enabled || rootAnimation.Drift.enabled || rootAnimation.DriftF.enabled || rootAnimation.DriftR.enabled || rootAnimation.DriftL.enabled)
                {
                    bool ground = IsGrounded();

                    if (DriftDetermineInWater(pData))
                    {
                        if (maxAltitude > 1f && pData.waterItemId > 0)
                        {
                            VFAudio audio = VFAudio.Create("landing-water", base.transform, Vector3.zero, false, 0);
                            audio.volumeMultiplier = Mathf.Clamp01(maxAltitude / 5f + 0.5f);
                            audio.Play();
                            PlayFootstepEffect(true, 0f, true);
                            PlayFootstepEffect(false, 0f, true);
                        }
                        maxAltitude = 0f;
                    }
                    if (ground && maxAltitude > 3f)
                    {
                        VFAudio audio = VFAudio.Create("landing", base.transform, Vector3.zero, false, 0);
                        audio.volumeMultiplier = Mathf.Clamp01(maxAltitude / 25f + 0.5f);
                        audio.Play();
                        maxAltitude = 0f;
                    }
                    if (!ground && tmpMaxAltitude > maxAltitude)
                    {
                        maxAltitude = tmpMaxAltitude;
                    }
                }
                else
                {
                    maxAltitude = 15f;
                }

                // NOTE: the pPhys can only be loaded if the player trying to load it has the planet actually loaded (meaning he is on the same planet or near it)
                if (pPhys != null && pFactory != null && packet.horzSpeed > 5f)
                {
                    int number = Physics.OverlapSphereNonAlloc(base.transform.localPosition, 1.8f, collider, 1024, QueryTriggerInteraction.Collide);
                    for (int i = 0; i < number; i++)
                    {
                        int          colId = pPhys.nearColliderLogic.FindColliderId(collider[i]);
                        ColliderData cData = pPhys.GetColliderData(colId);
                        if (cData.objType == EObjectType.Vegetable && cData.objId > 0)
                        {
                            VegeData  vData  = pFactory.vegePool[cData.objId];
                            VegeProto vProto = LDB.veges.Select((int)vData.protoId);
                            if (vProto != null && vProto.CollideAudio > 0 && vegeCollideColdTime <= 0)
                            {
                                VFAudio.Create(vProto.CollideAudio, base.transform, Vector3.zero, true, 0);
                                vegeCollideColdTime = UnityEngine.Random.value * 0.23f + 0.1f;
                            }
                        }
                    }
                }
            }

            if (vegeCollideColdTime > 0)
            {
                vegeCollideColdTime -= Time.deltaTime * 2;
            }
            else
            {
                vegeCollideColdTime = 0;
            }
        }
예제 #9
0
        public void Update()
        {
            if (isWarping)
            {
                WarpState += 0.0055655558f;
                if (WarpState > 1f)
                {
                    WarpState = 1f;
                }
            }
            else
            {
                WarpState -= 0.06667667f;
                if (WarpState < 0f)
                {
                    WarpState = 0f;
                }
            }

            Vector4 playerRot = new Vector4(rootTransform.rotation.x, rootTransform.rotation.y, rootTransform.rotation.z, rootTransform.rotation.w);

            if (WarpState > 0.001f && !warpEffectActivated)
            {
                for (int i = 0; i < warpRotations.Length; i++)
                {
                    warpRotations[i] = playerRot;
                }
                VFAudio.Create("warp-begin", base.transform, Vector3.zero, true, 0);
                ToggleEffect(true);
            }
            else if (WarpState == 0 && warpEffectActivated)
            {
                VFAudio.Create("warp-end", base.transform, Vector3.zero, true, 0);
                ToggleEffect(false);
            }

            Array.Copy(warpRotations, 0, warpRotations, 1, warpRotations.Length - 1);
            warpRotations[0] = playerRot;

            ParticleSystem.EmissionModule             emission         = astrosParticles.emission;
            ParticleSystem.VelocityOverLifetimeModule velocityOverTime = astrosParticles.velocityOverLifetime;
            ParticleSystem.ShapeModule shape = astrosParticles.shape;

            Vector3 lhs = velocity.normalized;

            // to compute the emission we would need to know the players local star, so default to this for now
            emission.rateOverTime = 120f;
            velocityOverTime.speedModifierMultiplier = 20000f;
            velocityOverTime.x = (float)lhs.x;
            velocityOverTime.y = (float)lhs.y;
            velocityOverTime.z = (float)lhs.z;
            shape.position     = lhs * 10000.0f;
            shape.rotation     = rootTransform.rotation.eulerAngles;

            distortRenderer.GetComponent <Transform>().localRotation = rootTransform.rotation;
            nebulasRenderer.GetComponent <Transform>().localRotation = rootTransform.rotation;
            float num1 = intensByState.Evaluate(WarpState);
            float num2 = intensByState_astro.Evaluate(WarpState);

            tunnelMat.SetFloat("_Multiplier", tunnelMul * num1);
            tunnelMat.SetVectorArray("_WarpRotations", warpRotations);
            distortMat.SetFloat("_DistortionStrength", distortMul * num1);
            astrosMat.SetFloat("_Multiplier", astrosMul * num2);
            nebulasMat.SetFloat("_Multiplier", nebulasMul * num2);
        }