Ejemplo n.º 1
0
        public static bool Prefix(Collider other)
        {
            Shark shark = UWE.Utils.GetComponentInHierarchy <Shark>(other.gameObject);

            if (shark)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void Drill(Vector3 position, Shark shark, out GameObject hitObj)
        {
            float totalhp = 0f;

            foreach (float hp in drill.health)
            {
                totalhp += hp;
            }
            drillingShark = shark;
            int meshindex = drill.FindClosestMesh(position, out Vector3 zero);

            hitObj = drill.renderers[meshindex].gameObject;
            drill.timeLastDrilled = Time.time;
            if (totalhp > 0)
            {
                float meshhealth = drill.health[meshindex];
                drill.health[meshindex] = Mathf.Max(0f, drill.health[meshindex] - 5f);
                totalhp -= meshhealth - drill.health[meshindex];
                if (meshhealth > 0f && drill.health[meshindex] <= 0f)
                {
                    drill.renderers[meshindex].gameObject.SetActive(false);
                    drill.SpawnFX(drill.breakFX, zero);
                    if (UnityEngine.Random.value < drill.kChanceToSpawnResources)
                    {
                        drill.SpawnLoot(zero);
                    }
                }
                if (totalhp <= 0f)
                {
                    drill.SpawnFX(drill.breakAllFX, zero);
                    if (typeof(Drillable).GetField("onDrilled").GetValue(drill) is Drillable.OnDrilled onDrilled)
                    {
                        onDrilled(drill);
                    }
                    if (drill.deleteWhenDrilled)
                    {
                        float time = drill.lootPinataOnSpawn ? 6f : 0f;
                        drill.Invoke("DestroySelf", time);
                    }
                }
            }
            BehaviourUpdateUtils.Register(this);
        }
Ejemplo n.º 3
0
        public void AttemptBlink(Shark shark)
        {
            if (!shark.energyInterface.hasCharge && GameModeUtils.RequiresPower())
            {
                return;
            }

            Vector3 targetPos = Vector3.zero;

            if (GameInput.GetMoveDirection().magnitude > 0f)
            {
                targetPos = shark.transform.position + shark.useRigidbody.velocity.normalized * 25f;
            }
            else
            {
                targetPos = shark.transform.position + shark.transform.forward * 25f;
            }

            targetPos.y = Mathf.Clamp(targetPos.y, Ocean.main.GetOceanLevel() - 3000f, Ocean.main.GetOceanLevel());

            var hits = Physics.RaycastAll(shark.transform.position, shark.useRigidbody.velocity.normalized, 30f);

            foreach (RaycastHit hit in hits)
            {
                if (hit.transform.GetComponentInParent <Shark>())
                {
                    continue;
                }

                targetPos = hit.point + hit.normal.normalized * 5f;
                break;
            }

            shark.transform.position = targetPos;

            shark.fxControl.blinkFX.Play(true);

            Utils.PlayFMODAsset(blinkSound, transform);
        }
Ejemplo n.º 4
0
        public override GameObject GetGameObject()
        {
            if (sharkPrefabCache)
            {
                return(sharkPrefabCache);
            }

            Console.WriteLine("Beginning shark load");

            Exosuit    exo        = CraftData.GetPrefabForTechType(TechType.Exosuit).GetComponent <Exosuit>();
            SeaMoth    sea        = CraftData.GetPrefabForTechType(TechType.Seamoth).GetComponent <SeaMoth>();
            GameObject ionCrystal = CraftData.GetPrefabForTechType(TechType.PrecursorIonCrystal);

            GameObject shark = MainPatch.bundle.LoadAsset <GameObject>("SharkPrefab.prefab");

            List <string> exclusions = new List <string>
            {
                "Window",
                "Sonar",
                "EnergyBlade",
                "VolumeLight",
                "Shield"
            };

            Material newMat  = new Material(ionCrystal.GetComponentInChildren <MeshRenderer>().material);
            Vector4  fakesss = newMat.GetVector("_FakeSSSparams");

            fakesss.y = 0f;
            newMat.SetVector("_FakeSSSparams", fakesss);

            foreach (Renderer rend in shark.GetComponentsInChildren <MeshRenderer>())
            {
                if (exclusions.IndexOf(rend.name) == -1)
                {
                    rend.material.shader = Shader.Find("MarmosetUBER");
                }

                if (rend.name == "EnergyBlade")
                {
                    rend.material          = newMat;
                    rend.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                }
            }

            Console.WriteLine("Setting up component");

            Shark sharkComp = shark.EnsureComponent <Shark>();

            sharkComp.playerSits     = true;
            sharkComp.playerPosition = shark.transform.Find("Scaler/SeatPosition").gameObject;
            sharkComp.handLabel      = "Pilot 5H-4RK";
            sharkComp.controlSheme   = Vehicle.ControlSheme.Submersible;
            sharkComp.mainAnimator   = shark.EnsureComponent <Animator>();
            sharkComp.mainAnimator.runtimeAnimatorController = sea.mainAnimator.runtimeAnimatorController;
            sharkComp.oxygenEnergyCost = 0f;

            sharkComp.bladeControl = shark.EnsureComponent <SharkBladeControl>();

            while (shark.GetComponent <FMOD_CustomLoopingEmitter>())
            {
                GameObject.Destroy(shark.GetComponent <FMOD_CustomLoopingEmitter>());
            }

            sharkComp.chargeUp = shark.AddComponent <FMOD_CustomLoopingEmitter>();
            sharkComp.chargeUp.followParent = true;
            sharkComp.chargeUp.asset        = sea.pulseChargeSound.asset;
            sharkComp.boost = shark.AddComponent <FMOD_CustomLoopingEmitter>();
            sharkComp.boost.followParent      = true;
            sharkComp.boost.asset             = exo.loopingJetSound.asset;
            sharkComp.boost.assetStop         = exo.loopingJetSound.assetStop;
            sharkComp.normalMove              = shark.AddComponent <FMOD_CustomLoopingEmitter>();
            sharkComp.normalMove.followParent = true;
            sharkComp.normalMove.asset        = sea.engineSound.engineRpmSFX.asset;
            sharkComp.chargeFinished          = sea.seamothElectricalDefensePrefab.GetComponent <ElectricalDefense>().defenseSound;
            sharkComp.splash = sea.splashSound;

            sharkComp.welcomeNotification             = shark.EnsureComponent <VoiceNotification>();
            sharkComp.welcomeNotification.text        = "5H-4RK: Welcome aboard, Captain";
            sharkComp.welcomeNotification.minInterval = exo.welcomeNotification.minInterval;
            sharkComp.welcomeNotification.sound       = exo.welcomeNotification.sound;

            sharkComp.rightHandPlug = sharkComp.transform.Find("Scaler/HandTargets/Right");
            sharkComp.leftHandPlug  = sharkComp.transform.Find("Scaler/HandTargets/Left");
            sharkComp.window        = shark.transform.Find("Scaler/SharkMesh/Sonar").gameObject;

            Console.WriteLine("Adding control");

            SharkControl control = shark.EnsureComponent <SharkControl>();

            control.shark       = sharkComp;
            control.sound       = shark.EnsureComponent <SharkSound>();
            control.sound.shark = sharkComp;

            Console.WriteLine("Adding health");

            LiveMixin     mixin = shark.EnsureComponent <LiveMixin>();
            LiveMixinData data  = ScriptableObject.CreateInstance <LiveMixinData>();

            mixin.health              = 100f;
            data.maxHealth            = 100f;
            data.destroyOnDeath       = false;
            data.weldable             = true;
            data.canResurrect         = false;
            data.invincibleInCreative = true;
            mixin.data          = data;
            sharkComp.liveMixin = mixin;

            Console.WriteLine("Adding forces");

            WorldForces worldForces = shark.EnsureComponent <WorldForces>();

            worldForces.aboveWaterGravity = 9.8f;
            worldForces.underwaterDrag    = 1f;
            worldForces.underwaterGravity = 0f;
            worldForces.aboveWaterDrag    = 0.5f;
            worldForces.useRigidbody      = shark.GetComponent <Rigidbody>();

            sharkComp.worldForces = worldForces;

            Console.WriteLine("Setting up other components");

            shark.EnsureComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Global;
            shark.EnsureComponent <SkyApplier>().renderers       = shark.GetComponentsInChildren <Renderer>();
            shark.EnsureComponent <TechTag>().type             = TechType;
            shark.EnsureComponent <PrefabIdentifier>().ClassId = ClassID;
            var vfx        = shark.EnsureComponent <VFXConstructing>();
            var seamothvfx = sea.GetComponentInChildren <VFXConstructing>();

            vfx.blurOffset         = seamothvfx.blurOffset;
            vfx.lineWidth          = seamothvfx.lineWidth;
            vfx.alphaDetailTexture = seamothvfx.alphaDetailTexture;
            vfx.alphaEnd           = seamothvfx.alphaEnd;
            vfx.alphaScale         = seamothvfx.alphaScale;
            vfx.alphaTexture       = seamothvfx.alphaTexture;
            vfx.constructSound     = seamothvfx.constructSound;
            vfx.surfaceSplashSound = seamothvfx.surfaceSplashSound;
            vfx.delay                 = seamothvfx.delay;
            vfx.surfaceSplashFX       = seamothvfx.surfaceSplashFX;
            vfx.surfaceSplashVelocity = seamothvfx.surfaceSplashVelocity;

            var fx = sharkComp.fxControl = shark.EnsureComponent <SharkFXControl>();

            fx.shark   = sharkComp;
            fx.zoomFX  = shark.transform.Find("Scaler/FX/Boost").GetComponent <ParticleSystem>();
            fx.drillFX = shark.transform.Find("Scaler/FX/DrillParticleParent/DrillParticle").GetComponent <ParticleSystem>();
            fx.blinkFX = shark.transform.Find("Scaler/FX/BlinkParticles").GetComponent <ParticleSystem>();

            /*
             * VFXVolumetricLight lightfx = shark.EnsureComponent<VFXVolumetricLight>();
             * lightfx.volumGO = shark.transform.Find("Scaler/SharkMesh/VolumeLight").gameObject;
             * var seamothlight = sea.volumeticLights[0];
             * lightfx.coneMat = new Material(seamothlight.coneMat);
             * lightfx.sphereMat = new Material(seamothlight.sphereMat);
             * lightfx.volumGO.GetComponent<MeshRenderer>().material = lightfx.coneMat;
             * lightfx.intensity = seamothlight.intensity;
             * lightfx.startFallof = seamothlight.startFallof;
             * lightfx.startOffset = seamothlight.startOffset;
             * lightfx.softEdges = seamothlight.softEdges;
             * lightfx.nearClip = seamothlight.nearClip;
             * lightfx.lightSource = shark.transform.Find("Scaler/Headlights/Spot Light").GetComponent<Light>();
             */

            for (int i = 0; i < shark.transform.childCount; i++)
            {
                if (shark.transform.GetChild(i).name.Contains("buildbotpath"))
                {
                    GameObject.Destroy(shark.transform.GetChild(i).gameObject);
                }
            }

            foreach (BuildBotPath path in sea.GetComponentsInChildren <BuildBotPath>())
            {
                Transform newPathParent = new GameObject("buildbotpath").transform;
                newPathParent.parent           = shark.transform;
                newPathParent.localPosition    = Vector3.zero;
                newPathParent.localEulerAngles = Vector3.zero;
                BuildBotPath newPath = newPathParent.gameObject.AddComponent <BuildBotPath>();

                newPath.points = new Transform[path.points.Length];

                int num = 0;
                foreach (Transform trans in path.points)
                {
                    GameObject clone = new GameObject("pathnode" + num);
                    clone.transform.parent        = newPathParent;
                    clone.transform.localPosition = trans.localPosition;
                    clone.transform.localRotation = trans.localRotation;
                    newPath.points[num]           = clone.transform;
                    num++;
                }
            }

            Console.WriteLine("Setting up headlights");

            Transform headLightParent = shark.transform.Find("Scaler/Headlights");

            ToggleLights lights = shark.EnsureComponent <ToggleLights>();

            lights.lightsParent    = headLightParent.gameObject;
            lights.onSound         = sea.toggleLights.lightsOnSound.asset;
            lights.offSound        = sea.toggleLights.lightsOffSound.asset;
            lights.energyPerSecond = 0f;
            sharkComp.lights       = lights;

            Console.WriteLine("Adding smooth cam");

            SharkCameraSmooth camControl = shark.EnsureComponent <SharkCameraSmooth>();

            camControl.shark = sharkComp;
            control.cam      = camControl;

            Console.WriteLine("Adding battery power");

            Transform energyParent = shark.transform.Find("Scaler/BatteryPower").transform;



            sharkComp.energyInterface = shark.EnsureComponent <EnergyInterface>();

            EnergyMixin energy = energyParent.gameObject.EnsureComponent <EnergyMixin>();

            lights.energyMixin             = energy;
            energy.allowBatteryReplacement = true;
            energy.compatibleBatteries     = new List <TechType>
            {
                Shark.internalBattery
            };
            energy.defaultBattery = Shark.internalBattery;

            EnergyMixin.BatteryModels model = new EnergyMixin.BatteryModels();
            model.model = energyParent.Find("PowerCube").gameObject;
            model.model.GetComponent <MeshFilter>().mesh = MainPatch.bundle.LoadAsset <GameObject>("ioncube.obj").GetComponentInChildren <MeshFilter>().mesh;
            MeshRenderer meshRend = model.model.GetComponent <MeshRenderer>();

            meshRend.material = new Material(ionCrystal.GetComponentInChildren <MeshRenderer>().material);
            model.model.transform.localScale = ionCrystal.GetComponentInChildren <MeshFilter>().transform.lossyScale;
            model.techType       = Shark.internalBattery;
            energy.batteryModels = new EnergyMixin.BatteryModels[]
            {
                model,
            };

            energy.controlledObjects = new GameObject[] { };
            energy.storageRoot       = energyParent.gameObject.EnsureComponent <ChildObjectIdentifier>();

            sharkComp.energyInterface.sources = new EnergyMixin[]
            {
                energy
            };

            var energySlot = energyParent.Find("InteractionHandler").gameObject.EnsureComponent <SharkEnergySlot>();

            energySlot.shark = sharkComp;

            Console.WriteLine("Setting up upgrade modules");

            sharkComp.modulesRoot = shark.transform.Find("Scaler/UpgradeModules").gameObject.EnsureComponent <ChildObjectIdentifier>();

            sharkComp.weapons = shark.EnsureComponent <SharkGunControl>();
            sharkComp.weapons.weaponFXParent   = shark.transform.Find("Scaler/Weapons").gameObject;
            sharkComp.weapons.weaponModel      = shark.transform.Find("Scaler/SharkMesh/Lasers").gameObject;
            sharkComp.weapons.upgradeInstalled = false;

            sharkComp.blink                 = shark.EnsureComponent <SharkBlinkControl>();
            sharkComp.blink.blinkSound      = CraftData.GetPrefabForTechType(TechType.PropulsionCannon).GetComponent <PropulsionCannon>().shootSound;
            sharkComp.shield                = shark.EnsureComponent <SharkShieldControl>();
            sharkComp.shield.shieldRenderer = shark.transform.Find("Scaler/SharkMesh/Shield").gameObject;

            sharkComp.drill = shark.EnsureComponent <SharkDrillControl>();
            sharkComp.drill.upgradeModels = shark.transform.Find("Scaler/SharkMesh/DrillMeshes").gameObject;

            StorageContainer drillStorage = sharkComp.drill.storageContainer = shark.transform.Find("Scaler/StorageContainerParent").gameObject.EnsureComponent <StorageContainer>();

            drillStorage.storageRoot  = sharkComp.drill.storageContainer.gameObject.EnsureComponent <ChildObjectIdentifier>();
            drillStorage.width        = 4;
            drillStorage.height       = 5;
            drillStorage.storageLabel = "Drill Storage";
            drillStorage.hoverText    = "OpenStorage";
            drillStorage.container    = null;
            drillStorage.CreateContainer();

            var upgradeconsole = sharkComp.modulesRoot.gameObject.EnsureComponent <VehicleUpgradeConsoleInput>();

            sharkComp.upgradesInput = upgradeconsole;
            upgradeconsole.slots    = new VehicleUpgradeConsoleInput.Slot[4];

            Transform modules = sharkComp.modulesRoot.transform;

            upgradeconsole.flap      = modules.Find("Flap");
            upgradeconsole.collider  = modules.GetComponent <Collider>();
            upgradeconsole.timeClose = 0f;
            upgradeconsole.timeOpen  = 0f;

            int j = 0;

            foreach (string slot in sharkComp.slotIDs)
            {
                if (!Equipment.slotMapping.ContainsKey(slot))
                {
                    Equipment.slotMapping.Add(slot, (EquipmentType)MainPatch.sharkTech);
                }

                GameObject nextSlot = shark.transform.Find("Scaler/SharkMesh/Upgrades/Slot" + (j + 1)).gameObject;

                upgradeconsole.slots[j] = new VehicleUpgradeConsoleInput.Slot()
                {
                    id    = slot,
                    model = nextSlot
                };
                j++;
            }

            Console.WriteLine("Adding GUI");

            shark.EnsureComponent <SharkTestGUI>().shark = sharkComp;

            sharkComp.crushDamage                 = shark.EnsureComponent <CrushDamage>();
            sharkComp.crushDamage.crushDepth      = 500f;
            sharkComp.crushDamage.kBaseCrushDepth = 500f;
            sharkComp.crushDamage.liveMixin       = sharkComp.liveMixin;

            shark.EnsureComponent <SharkUIControl>().shark = sharkComp;

            sharkComp.impactdmg = shark.EnsureComponent <DealDamageOnImpact>();
            sharkComp.impactdmg.damageTerrain      = true;
            sharkComp.impactdmg.mirroredSelfDamage = true;

            Console.WriteLine("Beacon");

            PingType pingType = (PingType)MainPatch.sharkTech;

            GameObject   pingObj = Object.Instantiate(Resources.Load <GameObject>("VFX/xSignal"), shark.transform.position, Quaternion.identity);
            PingInstance ping    = pingObj.GetComponent <PingInstance>();

            ping.SetLabel("5H-4RK");
            ping.displayPingInManager = true;
            ping.pingType             = pingType;
            ping._label = "5H-4RK";
            ping.SetVisible(true);
            pingObj.transform.parent           = shark.transform;
            pingObj.transform.localPosition    = Vector3.zero;
            pingObj.transform.localEulerAngles = Vector3.zero;

            Console.WriteLine("Patching into cached pingtypestrings");

            if (!PingManager.sCachedPingTypeStrings.valueToString.ContainsKey(pingType))
            {
                PingManager.sCachedPingTypeStrings.valueToString.Add(pingType, "SharkPing");
            }

            sharkPrefabCache = shark;

            return(shark);
        }
Ejemplo n.º 5
0
 public void Awake()
 {
     shark = GetComponent <Shark>();
 }