示例#1
0
    public static BoltEntity AttachLocalPlayer(GameObject go, string name, bool attachToRespawn)
    {
        if (go.GetComponent <BoltEntity>() && go.GetComponent <BoltEntity>().isAttached)
        {
            return(go.GetComponent <BoltEntity>());
        }
        go.AddComponent <BoltPlayerSetup>();
        go.AddComponent <BoltEntity>();
        using (BoltEntitySettingsModifier boltEntitySettingsModifier = go.GetComponent <BoltEntity>().ModifySettings())
        {
            boltEntitySettingsModifier.prefabId                 = BoltPrefabs.player_net;
            boltEntitySettingsModifier.serializerId             = StateSerializerTypeIds.IPlayerState;
            boltEntitySettingsModifier.allowInstantiateOnClient = true;
            boltEntitySettingsModifier.persistThroughSceneLoads = true;
            boltEntitySettingsModifier.clientPredicted          = false;
            boltEntitySettingsModifier.updateRate               = 1;
        }
        BoltEntity component = BoltNetwork.Attach(go).GetComponent <BoltEntity>();

        component.GetState <IPlayerState>().name = ((!string.IsNullOrEmpty(name)) ? name : "UNKNOWN");
        LocalPlayer.Entity = component;
        LocalPlayer.State  = component.GetState <IPlayerState>();
        BoltNetwork.SetCanReceiveEntities(true);
        return(component);
    }
 public override void EntityAttached(BoltEntity entity)
 {
     if (entity.StateIs<ICoopServerInfo>())
     {
         entity.GetState<ICoopServerInfo>().AddCallback("PlanePosition", new PropertyCallbackSimple(this.PlanePositionArrived));
         entity.GetState<ICoopServerInfo>().AddCallback("PlaneRotation", new PropertyCallbackSimple(this.PlaneRotationArrived));
     }
 }
示例#3
0
 public override void EntityAttached(BoltEntity entity)
 {
     if (entity.StateIs <ICoopServerInfo>())
     {
         entity.GetState <ICoopServerInfo>().AddCallback("PlanePosition", new PropertyCallbackSimple(this.PlanePositionArrived));
         entity.GetState <ICoopServerInfo>().AddCallback("PlaneRotation", new PropertyCallbackSimple(this.PlaneRotationArrived));
     }
 }
示例#4
0
        protected override void SendVoiceData(byte[] voice, int size, BoltConnection sendTo)
        {
            var entity = GetComponent <BoltEntity>();

            if (entity == null || !entity.isAttached)
            {
                if (BoltNetwork.entities.Count() > 1)
                {
                    BoltEntity abused = null;
                    try
                    {
                        var ownerName = SteamFriends.GetFriendPersonaName(CoopLobby.Instance.Info.OwnerSteamId);
                        foreach (var boltEntity in BoltNetwork.entities)
                        {
                            if (boltEntity.isAttached && boltEntity.StateIs <IPlayerState>() && boltEntity.GetState <IPlayerState>().name != ownerName)
                            {
                                abused = boltEntity;
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Exception("Error while trying to get the user to abuse", e);
                    }

                    if (abused != null)
                    {
                        if (LastTalkedAs != abused.GetState <IPlayerState>().name)
                        {
                            LastTalkedAs = abused.GetState <IPlayerState>().name;
                            Logger.Info("Talking as {0}!", LastTalkedAs);
                        }

                        try
                        {
                            var num      = 0;
                            var numArray = new byte[size + 12];
                            Blit.PackU64(numArray, ref num, abused.networkId.PackedValue);
                            Blit.PackI32(numArray, ref num, size);
                            Blit.PackBytes(numArray, ref num, voice, 0, size);
                            sendTo.StreamBytes(VoiceChannel, numArray);
                        }
                        catch (Exception e)
                        {
                            Logger.Exception("Failed to send voice data to host!", e);
                        }
                    }
                }

                // Return because we are not attached
                return;
            }

            base.SendVoiceData(voice, size, sendTo);
        }
示例#5
0
        // PRIVATE

        private void InstantiateKart(BoltEntity kart)
        {
            var spawnPosition = transform.position + (5 * transform.forward);

            _lastInstantiatedDummy = BoltNetwork.Instantiate(kart, spawnPosition, transform.rotation);
            _lastInstantiatedDummy.GetState <IKartState>().Team         = (int)_playerSettings.ColorSettings.TeamEnum.OppositeTeam();
            _lastInstantiatedDummy.GetState <IKartState>().OwnerID      = -2;
            _lastInstantiatedDummy.GetComponent <PlayerInfo>().Nickname = "Dummy";
            ReleaseControlOfDummy();
        }
        public override void ControlOfEntityGained(BoltEntity entity)
        {
            // add audio listener to our character
            entity.gameObject.AddComponent <AudioListener>();

            // set camera callbacks
            PlayerCamera.instance.getAiming = () => entity.GetState <IPlayerState>().Aiming;
            PlayerCamera.instance.getHealth = () => entity.GetState <IPlayerState>().health;
            PlayerCamera.instance.getPitch  = () => entity.GetState <IPlayerState>().pitch;

            // set camera target
            PlayerCamera.instance.SetTarget(entity);
        }
示例#7
0
        private void IOnPlayerDisconnected(BoltConnection connection)
        {
            BoltEntity entity = Scene.SceneTracker.allPlayerEntities.FirstOrDefault(ent => ent.source.ConnectionId == connection.ConnectionId);

            if (entity == null)
            {
                return;
            }

            IPlayer player = entity.IPlayer;

            if (player == null)
            {
                return;
            }

            // Set player name if available
            player.Name = entity.GetState <IPlayerState>().name?.Sanitize() ?? (!string.IsNullOrEmpty(player.Name) ? player.Name : "Unnamed"); // TODO: Localization

            // Call hooks for plugins
            Interface.Call("OnUserDisconnected", player, "Unknown");   // TODO: Localization
            Interface.Call("OnPlayerDisconnected", entity, "Unknown"); // TODO: Localization

            // Handle universal player disconnecting
            Covalence.PlayerManager.PlayerDisconnected(entity);

            Interface.Oxide.LogInfo($"{player.Id}/{player.Name} quit"); // TODO: Localization
        }
示例#8
0
        private void OnPlayerConnected(BoltEntity entity)
        {
            var id   = entity.source.RemoteEndPoint.SteamId.Id.ToString();
            var name = entity.GetState <IPlayerState>().name;

            // Update player's permissions group and name
            if (permission.IsLoaded)
            {
                permission.UpdateNickname(id, name);
                var defaultGroups = Interface.Oxide.Config.Options.DefaultGroups;
                if (!permission.UserHasGroup(id, defaultGroups.Players))
                {
                    permission.AddUserGroup(id, defaultGroups.Players);
                }
                if (entity.source.IsDedicatedServerAdmin() && !permission.UserHasGroup(id, defaultGroups.Administrators))
                {
                    permission.AddUserGroup(id, defaultGroups.Administrators);
                }
            }

            Debug.Log($"{id}/{name} joined");

            // Let covalence know
            Covalence.PlayerManager.NotifyPlayerConnect(entity);
            var iplayer = Covalence.PlayerManager.FindPlayerById(id);

            if (iplayer != null)
            {
                Interface.Call("OnUserConnected", iplayer);
            }
        }
示例#9
0
        private IEnumerator UpdateSetups()
        {
            while (true)
            {
                yield return(null);

                if (Players.Any(x => x == null))
                {
                    Players.Clear();
                    AllPlayerEntities.Clear();
                    PlayerStates.Clear();
                    Players.AddRange(Scene.SceneTracker.allPlayers);
                    for (int i = 0; i < Scene.SceneTracker.allPlayers.Count; i++)
                    {
                        BoltEntity b = Scene.SceneTracker.allPlayers[i].GetComponent <BoltEntity>();
                        if (b != null)
                        {
                            AllPlayerEntities.Add(b);
                            PlayerStates.Add(b.GetState <IPlayerState>());
                        }
                    }
                }

                yield return(new WaitForSeconds(10));
            }
        }
示例#10
0
        public override void OnOwner(PlayerCommand cmd, BoltEntity entity)
        {
            if (entity.isOwner)
            {
                IPlayerState     state      = entity.GetState <IPlayerState>();
                PlayerController controller = entity.GetComponent <PlayerController>();

                Vector3    pos;
                Quaternion look;

                // this calculate the looking angle for this specific entity
                PlayerCamera.instance.CalculateCameraAimTransform(entity.transform, state.pitch, out pos, out look);

                // display debug
                Debug.DrawRay(pos, look * Vector3.forward);

                using (var hits = BoltNetwork.RaycastAll(new Ray(pos, look * Vector3.forward), cmd.ServerFrame))
                {
                    for (int i = 0; i < hits.count; ++i)
                    {
                        var hit        = hits.GetHit(i);
                        var serializer = hit.body.GetComponent <PlayerController>();

                        if ((serializer != null) && (serializer.state.team != state.team))
                        {
                            serializer.ApplyDamage(controller.activeWeapon.damagePerBullet);
                        }
                    }
                }
            }
        }
示例#11
0
        private void OnPlayerConnected(BoltEntity entity)
        {
            var id   = entity.source.RemoteEndPoint.SteamId.Id.ToString();
            var name = entity.GetState <IPlayerState>().name;

            if (permission.IsLoaded)
            {
                permission.UpdateNickname(id, name);
                if (!permission.UserHasGroup(id, DefaultGroups[0]))
                {
                    permission.AddUserGroup(id, DefaultGroups[0]);
                }
            }

            Debug.Log($"{id}/{name} joined");

            // Let covalence know
            Covalence.PlayerManager.NotifyPlayerConnect(entity);
            var iplayer = Covalence.PlayerManager.FindPlayerById(id);

            if (iplayer != null)
            {
                Interface.Call("OnUserConnected", iplayer);
            }
        }
示例#12
0
 public override void Execute(IGameState _)
 {
     if (gameInput.SelectedGolfBall.IsZero)
     {
         if (Input.GetMouseButtonDown(0))
         {
             selectedGolfBall = FindNearestGolfBall();
             if (selectedGolfBall != null)
             {
                 gameInput.SelectedGolfBall = selectedGolfBall.NetworkId;
             }
         }
     }
     else
     {
         if (Input.GetMouseButtonDown(1))
         {
             ClearSelection();
             if (BoltNetwork.IsServer)
             {
                 selectedGolfBall.GetState <IGolfBallState>().PreMove = Vector3.zero;
             }
         }
         else if (Input.GetMouseButtonDown(0))
         {
             HitSelectedGolfBall();
             ClearSelection();
         }
         else
         {
             gameInput.Direction = SelectedGolfBallToMouseVector.normalized;
             gameInput.Charge    = Mathf.PingPong(Time.time * hitChargeSpeed, 1);
         }
     }
 }
示例#13
0
 private void throwRocks()
 {
     if (BoltNetwork.isClient)
     {
         return;
     }
     for (int i = 0; i < this.ammoCount; i++)
     {
         Vector3 position = this.releasePos.position + this.releasePos.up * 2f + (this.releasePos.forward * UnityEngine.Random.Range(-0.6f, 0.6f) + this.releasePos.right * UnityEngine.Random.Range(-0.6f, 0.6f));
         MultiThrowerProjectile multiThrowerProjectile = UnityEngine.Object.Instantiate <MultiThrowerProjectile>(this.projectilePrefab, position, Quaternion.identity);
         Rigidbody rigidbody = multiThrowerProjectile._rigidbody;
         Vector2   vector    = this.randomCircle2(2.2f);
         Vector3   target    = new Vector3(this.landTarget.x + vector.x, this.landTarget.y, this.landTarget.z + vector.y);
         Vector3   a         = this.calculateBestThrowSpeed(this.releasePos.position, target, UnityEngine.Random.Range(2.4f, 2.6f));
         rigidbody.AddForce(a * (0.016666f / Time.fixedDeltaTime), ForceMode.VelocityChange);
         rigidbody.AddTorque(base.transform.right * UnityEngine.Random.Range(20f, 35f), ForceMode.VelocityChange);
         multiThrowerProjectile.InitProjectile(this.itemHolder.AmmoLoaded[i], (this.rockAmmo[i].transform.childCount <= 0) ? null : this.rockAmmo[i].transform.GetChild(0));
         if (BoltNetwork.isRunning)
         {
             BoltEntity component = multiThrowerProjectile.GetComponent <BoltEntity>();
             if (component)
             {
                 BoltNetwork.Attach(multiThrowerProjectile.gameObject);
                 IMultiThrowerProjectileState state = component.GetState <IMultiThrowerProjectileState>();
                 state.Thrower = this.entity;
                 state.AmmoId  = i + 1;
             }
         }
     }
     foreach (GameObject gameObject in this.rockAmmo)
     {
         gameObject.SetActive(false);
     }
 }
示例#14
0
 public override void Attached()
 {
     this.chunks = (from x in base.GetComponentsInChildren <TreeCutChunk>()
                    orderby int.Parse(x.transform.parent.gameObject.name)
                    select x).ToArray <TreeCutChunk>();
     base.state.AddCallback("TreeId", delegate
     {
         CoopTreeId coopTreeId = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId x) => x.Id == base.state.TreeId);
         if (coopTreeId)
         {
             LOD_Trees component = coopTreeId.GetComponent <LOD_Trees>();
             if (component)
             {
                 component.enabled   = false;
                 component.DontSpawn = true;
                 if (component.CurrentView)
                 {
                     component.Pool.Despawn(component.CurrentView.transform);
                     component.CurrentView         = null;
                     component.CurrentLodTransform = null;
                 }
             }
         }
     });
     base.state.AddCallback("Damage", delegate
     {
         if (base.entity.isOwner && base.state.Damage == 16f)
         {
             base.entity.DestroyDelayed(10f);
             BoltEntity boltEntity = BoltNetwork.Instantiate(this.CoopTree.NetworkFallPrefab, base.entity.transform.position, base.entity.transform.rotation);
             boltEntity.GetState <ITreeFallState>().CutTree = base.entity;
             boltEntity.GetComponent <Rigidbody>().AddForce(new Vector3(UnityEngine.Random.value * 0.01f, 0f, UnityEngine.Random.value * 0.01f), ForceMode.VelocityChange);
         }
     });
 }
示例#15
0
 private void GrabbedByChanged()
 {
     if (base.state.GrabbedBy)
     {
         if (base.state.GrabbedBy == LocalPlayer.Entity)
         {
             BoltEntity        boltEntity           = BoltNetwork.Instantiate(BoltPrefabs.MultiSledBuilt, base.transform.position, base.transform.rotation);
             IMultiHolderState state                = boltEntity.GetState <IMultiHolderState>();
             MultiHolder[]     componentsInChildren = boltEntity.GetComponentsInChildren <MultiHolder>(true);
             if (componentsInChildren.Length > 0)
             {
                 componentsInChildren[0]._contentActual     = base.state.LogCount;
                 componentsInChildren[0]._contentTypeActual = (MultiHolder.ContentTypes)base.state.ContentType;
                 componentsInChildren[0].ItemCountChangedMP();
                 state.Replaces = base.entity;
                 state.LogCount = base.state.LogCount;
                 state.Body0    = base.state.Body0;
                 state.Body1    = base.state.Body1;
                 state.Body2    = base.state.Body2;
             }
         }
     }
     else
     {
         MultiHolder[] componentsInChildren2 = base.GetComponentsInChildren <MultiHolder>(true);
         if (componentsInChildren2.Length > 0)
         {
             componentsInChildren2[0].ItemCountChangedMP();
         }
     }
 }
示例#16
0
    public override void DisplayEffects(BoltEntity entity)
    {
        Vector3    pos;
        Quaternion rot;         //TODO replace with the rotation of the right entity

        PlayerCamera.instance.CalculateCameraAimTransform(entity.transform, entity.GetState <ITicTacState> ().Pitch, out pos, out rot);

        Ray        r = new Ray(pos, rot * Vector3.forward);
        RaycastHit rh;

        if (Physics.Raycast(r, out rh) && impactPrefab)
        {
            var en  = rh.transform.GetComponent <BoltEntity>();
            var hit = GameObject.Instantiate(impactPrefab, rh.point, Quaternion.LookRotation(rh.normal)) as GameObject;

            if (en)
            {
                hit.GetComponent <RandomSound>().enabled = false;
            }

            if (trailPrefab)
            {
                var trailGo = GameObject.Instantiate(trailPrefab, muzzleFlash.position, Quaternion.identity) as GameObject;
                var trail   = trailGo.GetComponent <LineRenderer>();

                trail.SetPosition(0, muzzleFlash.position);
                trail.SetPosition(1, rh.point);
            }
        }

        GameObject go = (GameObject)GameObject.Instantiate(shellPrefab, shellEjector.position, shellEjector.rotation);

        go.GetComponent <Rigidbody>().AddRelativeForce(0, 0, 2, ForceMode.VelocityChange);
        go.GetComponent <Rigidbody>().AddTorque(new Vector3(Random.Range(-32f, +32f), Random.Range(-32f, +32f), Random.Range(-32f, +32f)), ForceMode.VelocityChange);
    }
示例#17
0
 internal TheForestPlayer(BoltEntity entity)
 {
     steamId     = entity.controller.RemoteEndPoint.SteamId.Id;
     cSteamId    = new CSteamID(steamId);
     Id          = steamId.ToString();
     Name        = entity.GetState <IPlayerState>().name;
     this.entity = entity;
 }
 public override void EntityDetached(BoltEntity entity)
 {
     if (entity.StateIs <IPlayerState>() && TheForest.Utils.Scene.SceneTracker && GameSetup.IsMpServer)
     {
         ModdedPlayer.instance.SendLeaveMessage(entity.GetState <IPlayerState>().name);
     }
     base.EntityDetached(entity);
 }
    public override void ControlOfEntityGained(BoltEntity entity)
    {
        // camera setup
        GameObject Camera = Instantiate(PlayerCamera);

        Camera.GetComponent <PlayerCamera>().getPitch = () => entity.GetState <IPlayerState>().Pitch;
        Camera.GetComponent <PlayerCamera>().SetTarget(entity);
    }
示例#20
0
 public override void ControlOfEntityGained(BoltEntity arg)
 {
     if (arg.GetComponent <PlayerController>())
     {
         me      = arg;
         meState = me.GetState <IPlayerState>();
     }
 }
示例#21
0
 internal TheForestPlayer(BoltEntity entity)
 {
     steamId     = entity.source.RemoteEndPoint.SteamId.Id;
     cSteamId    = new CSteamID(steamId);
     Id          = steamId.ToString();
     Name        = entity.GetState <IPlayerState>().name.Sanitize();
     this.entity = entity;
 }
        public override void EntityReceived(BoltEntity entity)
        {
            if (entity.StateIs <IPlayerState>() && GameSetup.IsMpServer)
            {
                NetworkManager.SendText("IIA champion approaches... \n" + entity.GetState <IPlayerState>().name, NetworkManager.Target.Everyone);
            }

            base.EntityReceived(entity);
        }
示例#23
0
 internal TheForestPlayer(BoltEntity entity)
 {
     cSteamId    = SteamDSConfig.clientConnectionInfo[entity.source.ConnectionId];
     steamId     = cSteamId.m_SteamID;
     Id          = steamId.ToString();
     Name        = (entity.GetState <IPlayerState>().name?.Sanitize() ?? Name) ?? "Unnamed";
     stats       = entity.GetComponentInChildren <PlayerStats>();
     this.entity = entity;
 }
 public override void EntityDetached(BoltEntity entity)
 {
     if (entity != null)
     {
         if (entity.StateIs <IPlayerState>() && TheForest.Utils.Scene.SceneTracker && GameSetup.IsMpServer)
         {
             if (entity.source.udpConnection.IsConnected)
             {
                 NetworkManager.SendText("II" + entity.GetState <IPlayerState>().name + " has died", NetworkManager.Target.Everyone);
             }
             else
             {
                 ModdedPlayer.instance.SendLeaveMessage(entity.GetState <IPlayerState>().name);
             }
         }
     }
     base.EntityDetached(entity);
 }
        public override void EntityReceived(BoltEntity entity)
        {
            if (entity.StateIs <IPlayerState>() && GameSetup.IsMpServer)
            {
                NetworkManager.SendLine("IIA NEW CHAMPION APPROACHES \n" + entity.GetState <IPlayerState>().name, NetworkManager.Target.Everyone);
            }

            base.EntityReceived(entity);
        }
示例#26
0
        private void HitHandler(BoltEntity targetEntity, int weaponAmount, WeaponType weaponType, Vector3 hit)
        {
            // If we are not the owner if the target entity, just return, we can do nothing
            if (targetEntity.IsOwner == false)
            {
                return;
            }

            // Ignore if we try to hit ourself
            if (targetEntity.Equals(entity))
            {
                return;
            }

            // Get Player State
            var moveAndShootPlayerState = targetEntity.GetState <IMoveAndShootPlayer>();
            var healthChange            = 0;

            switch (weaponType)
            {
            case WeaponType.HEAL:
                // Ignore if is the other Team
                if (moveAndShootPlayerState.Team != state.Team)
                {
                    return;
                }

                // Increase health
                healthChange = weaponAmount;
                break;

            case WeaponType.DAMAGE:
                // Ignore if is the same Team
                if (moveAndShootPlayerState.Team == state.Team)
                {
                    return;
                }

                // Decrease health
                healthChange = -weaponAmount;
                break;
            }

            // Get Current Health and Apply weapon change
            var targetHealth = moveAndShootPlayerState.Health + healthChange;

            // Clamp result value a put back on the state
            moveAndShootPlayerState.Health = Mathf.Clamp(targetHealth, 0, 100);

            // Send FX Event
            var hitInfoToken = ProtocolTokenUtils.GetToken <HitInfo>();

            hitInfoToken.hitPosition = hit;
            hitInfoToken.hitType     = healthChange > 0;

            MoveAndShootHitEvent.Post(GlobalTargets.Everyone, ReliabilityModes.ReliableOrdered, hitInfoToken);
        }
示例#27
0
 public override void EntityAttached(BoltEntity arg)
 {
     if (arg.StateIs <IPlayerState>())
     {
         if (arg.isOwner)
         {
             DebugInfo.Ignore(arg);
             TheForest.Utils.Scene.HudGui.Chatbox.RegisterPlayer("You", arg.networkId);
         }
         else
         {
             arg.source.UserData = arg;
             arg.GetState <IPlayerState>().AddCallback("name", delegate
             {
                 TheForest.Utils.Scene.HudGui.Chatbox.RegisterPlayer(arg.GetState <IPlayerState>().name, arg.networkId);
             });
         }
     }
 }
示例#28
0
        public void AttachMoveState(BoltEntity moveEntity)
        {
            clientMoveEntity = moveEntity;
            clientMoveState  = moveEntity.GetState <IMoveState>();
            clientMoveState.SetTransforms(clientMoveState.LocalTransform, moveEntity.transform);

            if (Unit.IsOwner)
            {
                clientMoveState.AddCallback(nameof(IUnitState.MovementFlags), OnLocalMoveStateFlagsChanged);
            }
        }
示例#29
0
    public override void ControlOfEntityGained(BoltEntity entity)
    {
        // give the camera our players pitch
        PlayerCamera.instance.getPitch = () => entity.GetState <ITicTacState>().Pitch;

        // this tells the player camera to look at the entity we are controlling
        PlayerCamera.instance.SetTarget(entity);

        // add an audio listener for our character
        entity.gameObject.AddComponent <AudioListener>();
    }
示例#30
0
        public override void ControlOfEntityGained(BoltEntity arg)
        {
            if (arg.GetComponent <PlayerController> ())
            {
                me      = arg;
                meState = me.GetState <IPlayerState> ();
                meState.AddCallback("health", HealthChanged);

                HealthChanged();
            }
        }
示例#31
0
    private bool CanGrabThisSled()
    {
        BoltEntity componentInParent = base.GetComponentInParent <BoltEntity>();

        if (componentInParent && componentInParent.isAttached && componentInParent.StateIs <IMultiHolderState>())
        {
            IMultiHolderState state = componentInParent.GetState <IMultiHolderState>();
            return(state.IsReal && !state.GrabbedBy);
        }
        return(false);
    }
 public static void AttachBuildingBoltEntity(BoltEntity entity)
 {
     if (!BoltNetwork.isServer)
     {
         return;
     }
     if (!CoopSteamServerStarter.SaveIsLoading)
     {
         return;
     }
     if (!entity)
     {
         return;
     }
     if (entity.IsAttached())
     {
         return;
     }
     BoltEntitySettingsModifier boltEntitySettingsModifier = entity.ModifySettings();
     BridgeArchitect component = entity.GetComponent<BridgeArchitect>();
     if (boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IFireState)
     {
         BoltNetwork.Attach(entity);
     }
     else if (boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IRaftState)
     {
         BoltNetwork.Attach(entity);
         if (entity && entity.isAttached && entity.StateIs<IRaftState>())
         {
             entity.GetState<IRaftState>().IsReal = true;
         }
     }
     else if (boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IMultiHolderState)
     {
         BoltNetwork.Attach(entity);
         if (entity && entity.isAttached && entity.StateIs<IMultiHolderState>())
         {
             entity.GetState<IMultiHolderState>().IsReal = true;
             MultiHolder[] componentsInChildren = entity.GetComponentsInChildren<MultiHolder>(true);
             if (componentsInChildren.Length > 0)
             {
                 componentsInChildren[0]._contentActual = componentsInChildren[0]._contentAmount;
                 componentsInChildren[0]._contentTypeActual = componentsInChildren[0]._content;
             }
         }
     }
     else if (component)
     {
         BoltNetwork.Attach(entity, component.CustomToken);
     }
     else if (boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IFoundationState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IBuildingState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IRabbitCage || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.ITreeBuildingState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.ITrapLargeState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IBuildingDestructibleState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IWallChunkBuildingState)
     {
         CoopBuildingEx component2 = entity.GetComponent<CoopBuildingEx>();
         WallChunkArchitect component3 = entity.GetComponent<WallChunkArchitect>();
         if (component3)
         {
             BoltNetwork.Attach(entity, component3.CustomToken);
         }
         else if (component2)
         {
             CoopConstructionExToken coopConstructionExToken = new CoopConstructionExToken();
             coopConstructionExToken.Architects = new CoopConstructionExToken.ArchitectData[component2.Architects.Length];
             for (int i = 0; i < component2.Architects.Length; i++)
             {
                 coopConstructionExToken.Architects[i].PointsCount = (component2.Architects[i] as ICoopStructure).MultiPointsCount;
                 coopConstructionExToken.Architects[i].PointsPositions = (component2.Architects[i] as ICoopStructure).MultiPointsPositions.ToArray();
                 coopConstructionExToken.Architects[i].CustomToken = (component2.Architects[i] as ICoopStructure).CustomToken;
                 if (component2.Architects[i] is FoundationArchitect)
                 {
                     coopConstructionExToken.Architects[i].AboveGround = ((FoundationArchitect)component2.Architects[i])._aboveGround;
                 }
                 if (component2.Architects[i] is RoofArchitect && (component2.Architects[i] as RoofArchitect).CurrentSupport != null)
                 {
                     coopConstructionExToken.Architects[i].Support = ((component2.Architects[i] as RoofArchitect).CurrentSupport as MonoBehaviour).GetComponent<BoltEntity>();
                 }
                 if (component2.Architects[i] is FloorArchitect && (component2.Architects[i] as FloorArchitect).CurrentSupport != null)
                 {
                     coopConstructionExToken.Architects[i].Support = ((component2.Architects[i] as FloorArchitect).CurrentSupport as MonoBehaviour).GetComponent<BoltEntity>();
                 }
                 CoopSteamServerStarter.AttachBuildingBoltEntity(coopConstructionExToken.Architects[i].Support);
             }
             BoltNetwork.Attach(entity, coopConstructionExToken);
         }
         else
         {
             BoltNetwork.Attach(entity);
         }
     }
     else if (boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IConstructionState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IWallChunkConstructionState)
     {
         CoopConstructionEx component4 = entity.GetComponent<CoopConstructionEx>();
         WallChunkArchitect component5 = entity.GetComponent<WallChunkArchitect>();
         if (component5)
         {
             BoltNetwork.Attach(entity, component5.CustomToken);
         }
         else if (component4)
         {
             CoopConstructionExToken coopConstructionExToken2 = new CoopConstructionExToken();
             coopConstructionExToken2.Architects = new CoopConstructionExToken.ArchitectData[component4.Architects.Length];
             for (int j = 0; j < component4.Architects.Length; j++)
             {
                 coopConstructionExToken2.Architects[j].PointsCount = (component4.Architects[j] as ICoopStructure).MultiPointsCount;
                 coopConstructionExToken2.Architects[j].PointsPositions = (component4.Architects[j] as ICoopStructure).MultiPointsPositions.ToArray();
                 coopConstructionExToken2.Architects[j].CustomToken = (component4.Architects[j] as ICoopStructure).CustomToken;
                 if (component4.Architects[j] is FoundationArchitect)
                 {
                     coopConstructionExToken2.Architects[j].AboveGround = ((FoundationArchitect)component4.Architects[j])._aboveGround;
                 }
                 if (component4.Architects[j] is RoofArchitect && (component4.Architects[j] as RoofArchitect).CurrentSupport != null)
                 {
                     coopConstructionExToken2.Architects[j].Support = ((component4.Architects[j] as RoofArchitect).CurrentSupport as MonoBehaviour).GetComponent<BoltEntity>();
                 }
                 if (component4.Architects[j] is FloorArchitect && (component4.Architects[j] as FloorArchitect).CurrentSupport != null)
                 {
                     coopConstructionExToken2.Architects[j].Support = ((component4.Architects[j] as FloorArchitect).CurrentSupport as MonoBehaviour).GetComponent<BoltEntity>();
                 }
                 CoopSteamServerStarter.AttachBuildingBoltEntity(coopConstructionExToken2.Architects[j].Support);
             }
             BoltNetwork.Attach(entity, coopConstructionExToken2);
         }
         else
         {
             BoltNetwork.Attach(entity);
         }
     }
 }
示例#33
0
 public static void KickPlayer(BoltEntity playerEntity, int duration, string message = "Host kicked you from the game")
 {
     if (BoltNetwork.isServer)
     {
         if (duration >= 0 && !CoopKick.IsBanned(playerEntity.source.RemoteEndPoint.SteamId))
         {
             CoopKick.Instance.kickedSteamIds.Add(new CoopKick.KickedPlayer
             {
                 Name = playerEntity.GetState<IPlayerState>().name,
                 SteamId = playerEntity.source.RemoteEndPoint.SteamId.Id,
                 BanEndTime = (duration <= 0) ? 0L : (DateTime.UtcNow.ToUnixTimestamp() + (long)duration)
             });
             CoopKick.SaveList();
         }
         playerEntity.source.Disconnect(new CoopKickToken
         {
             KickMessage = message,
             Banned = duration == 0
         });
     }
 }