Example #1
0
        private void SpawnStanMinion(GameObject gameoObject, string masterName, Vector3 position)
        {
            CharacterBody characterBody = gameObject.GetComponent <CharacterBody>();

            if (NetworkServer.active)
            {
                CharacterMaster characterMaster = new MasterSummon
                {
                    masterPrefab          = MasterCatalog.FindMasterPrefab(masterName),
                    position              = position,
                    rotation              = characterBody.transform.rotation,
                    summonerBodyObject    = gameObject,
                    ignoreTeamMemberLimit = true,
                    teamIndexOverride     = new TeamIndex?(TeamIndex.Player)
                }.Perform();
                characterMaster.inventory.GiveItem(RoR2Content.Items.HealthDecay.itemIndex, 35);

                this.PlaySound(Assets.StrongStanSpawnSound, characterMaster.GetBodyObject());
            }
            else
            {
                NetworkIdentity networkIdentity = base.gameObject.GetComponent <NetworkIdentity>();
                if (networkIdentity)
                {
                    new NetMessages.SpawnStanMinonMessage(networkIdentity.netId, masterName, position, true, Assets.StrongStanSpawnSound)
                    .Send(NetworkDestination.Server);
                }
            }
        }
            public void OnReceived()
            {
                GameObject    gameObject    = Util.FindNetworkObject(this.targetId);
                CharacterBody characterBody = gameObject.GetComponent <CharacterBody>();

                if (!gameObject)
                {
                    StanWorshipperPlugin.logger.LogMessage("Error spawning stan fragment on client: target id was not found!");
                    return;
                }

                CharacterMaster characterMaster = new MasterSummon
                {
                    masterPrefab          = MasterCatalog.FindMasterPrefab(masterName),
                    position              = position,
                    rotation              = characterBody.transform.rotation,
                    summonerBodyObject    = gameObject,
                    ignoreTeamMemberLimit = true,
                    teamIndexOverride     = new TeamIndex?(TeamIndex.Player)
                }.Perform();

                characterMaster.inventory.GiveItem(RoR2Content.Items.HealthDecay.itemIndex, 30);

                if (this.playSound & this.soundName != "")
                {
                    new NetMessages.SoundMessage(characterMaster.GetBodyObject().GetComponent <NetworkIdentity>().netId, soundName)
                    .Send(NetworkDestination.Clients);
                }
            }
Example #3
0
        private void SummonDrone(CharacterBody ownerBody, GameObject droneMasterPrefab, int counter = 1)
        {
            if (!ownerBody || !droneMasterPrefab)
            {
                Log.Warning("Machines.SummonDrone: ownerBody or droneMasterPrefab is null. Cancel drone summon.");
                return;
            }
            CharacterMaster characterMaster = new MasterSummon
            {
                masterPrefab          = droneMasterPrefab,
                position              = ownerBody.transform.position - (ownerBody.transform.forward.normalized * counter) + (.25f * counter * Vector3.up),
                rotation              = ownerBody.transform.rotation,
                summonerBodyObject    = ownerBody.gameObject,
                ignoreTeamMemberLimit = true,
                useAmbientLevel       = true
            }.Perform();

            if (characterMaster)
            {
                GameObject bodyObject = characterMaster.GetBodyObject();
                if (bodyObject)
                {
                    ModelLocator component = bodyObject.GetComponent <ModelLocator>();
                    if (component && component.modelTransform)
                    {
                        TemporaryOverlay temporaryOverlay = component.modelTransform.gameObject.AddComponent <TemporaryOverlay>();
                        temporaryOverlay.duration              = 0.5f;
                        temporaryOverlay.animateShaderAlpha    = true;
                        temporaryOverlay.alphaCurve            = AnimationCurve.EaseInOut(0f, 1f, 1f, 0f);
                        temporaryOverlay.destroyComponentOnEnd = true;
                        temporaryOverlay.originalMaterial      = summonDroneMaterial;
                        temporaryOverlay.AddToCharacerModel(component.modelTransform.GetComponent <CharacterModel>());
                    }
                }
                RepositionGroundedDrones(characterMaster.GetBody(), ownerBody.transform.position);
            }
        }
        private bool PerformEquipmentActionInternal(EquipmentSlot slot)
        {
            var candidates = CharacterMaster.readOnlyInstancesList.Where(x => x.IsDeadAndOutOfLivesServer() && x.teamIndex == TeamIndex.Player);

            GameObject obj;
            GameObject podPrefab = LegacyResourcesAPI.Load <GameObject>("Prefabs/NetworkedObjects/RoboCratePod");

            var        nodeGraph = SceneInfo.instance.GetNodeGraph(MapNodeGroup.GraphType.Ground);
            var        nodeInd   = nodeGraph.FindClosestNodeWithFlagConditions(slot.transform.position, HullClassification.Human, NodeFlags.None, NodeFlags.None, false);
            Vector3    nodePos   = slot.transform.position;
            Quaternion nodeRot   = Quaternion.identity;

            if (nodeGraph.GetNodePosition(nodeInd, out nodePos))
            {
                var targPos = slot.transform.position;
                targPos.y = nodePos.y;
                nodeRot   = Util.QuaternionSafeLookRotation(nodePos - targPos);
            }

            if (candidates.Count() > 0)
            {
                var which   = rng.NextElementUniform(candidates.ToArray());
                var newBody = which.Respawn(nodePos, nodeRot);
                if (!newBody)
                {
                    return(false);
                }
                obj = newBody.gameObject;
                string rezTargetName = Language.GetString(newBody.baseNameToken);
                var    newBodyUser   = Util.LookUpBodyNetworkUser(newBody);
                if (newBodyUser)
                {
                    rezTargetName = newBodyUser.userName;
                }
                var rezzerName = slot.characterBody ? Language.GetString(slot.characterBody.baseNameToken) : "Someone";
                var rezzerUser = Util.LookUpBodyNetworkUser(slot.characterBody);
                if (rezzerUser)
                {
                    rezzerName = rezzerUser.userName;
                }
                NetUtil.ServerSendGlobalChatMsg($"{rezzerName} called down a clone of {rezTargetName}!");
            }
            else
            {
                var whichName  = rng.NextElementUniform(droneMasterPrefabNames.ToArray());
                var whichIndex = MasterCatalog.FindMasterIndex(whichName);
                var which      = MasterCatalog.GetMasterPrefab(whichIndex);
                if (!which)
                {
                    return(false);
                }
                var summon = new MasterSummon {
                    masterPrefab          = which,
                    position              = nodePos,
                    rotation              = nodeRot,
                    summonerBodyObject    = slot.characterBody ? slot.characterBody.gameObject : null,
                    ignoreTeamMemberLimit = true,
                    useAmbientLevel       = new bool?(true)
                }.Perform();
                if (!summon)
                {
                    return(false);
                }
                obj = summon.GetBodyObject();
                if (!obj)
                {
                    return(false);
                }
                if (obj.name == "EquipmentDroneBody(Clone)")
                {
                    var droneInv = obj.GetComponent <Inventory>();
                    if (droneInv)
                    {
                        var randomEqp = rng.NextElementUniform(RoR2.Artifacts.EnigmaArtifactManager.validEquipment);
                        droneInv.SetEquipment(new EquipmentState(randomEqp, Run.FixedTimeStamp.negativeInfinity, 1), 0);
                    }
                }
                else if (which == ItemDrone.instance.itemDroneMasterPrefab)
                {
                    var wardPersist = summon.GetComponent <ItemDroneWardPersist>();

                    var drops = LegacyResourcesAPI.Load <BasicPickupDropTable>("DropTables/dtSmallChest");
                    var drop  = drops.GenerateDrop(rng);
                    var pdef  = PickupCatalog.GetPickupDef(drop);
                    if (wardPersist && pdef != null && pdef.itemIndex != ItemIndex.None)
                    {
                        int remCount = 1;
                        if (pdef.itemTier == ItemTier.Tier2 || pdef.itemTier == ItemTier.VoidTier2)
                        {
                            remCount = 3;
                        }
                        if (pdef.itemTier == ItemTier.Tier1 || pdef.itemTier == ItemTier.VoidTier1)
                        {
                            remCount = 5;
                        }
                        wardPersist.index = pdef.itemIndex;
                        wardPersist.count = remCount;
                    }
                }
            }

            if (!obj)
            {
                return(false);
            }
            var objBody = obj.GetComponent <CharacterBody>();

            var podObj  = GameObject.Instantiate(podPrefab, nodePos, nodeRot);
            var podSeat = podObj.GetComponent <VehicleSeat>();

            if (podSeat)
            {
                podSeat.AssignPassenger(obj);
            }
            else
            {
                TinkersSatchelPlugin._logger.LogError($"Pod {podObj} spawned for revived prefab {obj} has no seat!");
            }
            NetworkServer.Spawn(podObj);
            objBody.SetBodyStateToPreferredInitialState();

            slot.inventory.SetEquipment(new EquipmentState(EquipmentIndex.None, Run.FixedTimeStamp.now + cooldown, 0), (uint)slot.inventory.activeEquipmentSlot);
            return(true);
        }