Beispiel #1
0
    public void DoDeploy_Regular(Deployable deployable, Ray ray)
    {
        if (!HasItemAmount())
        {
            return;
        }
        BasePlayer ownerPlayer = GetOwnerPlayer();

        if (!ownerPlayer)
        {
            return;
        }
        if (!ownerPlayer.CanBuild())
        {
            ownerPlayer.ChatMessage("Building is blocked at player position!");
        }
        else if (ConVar.AntiHack.objectplacement && ownerPlayer.TriggeredAntiHack())
        {
            ownerPlayer.ChatMessage("AntiHack!");
        }
        else
        {
            RaycastHit hitInfo;
            if (!CheckPlacement(deployable, ray, 8f) || !UnityEngine.Physics.Raycast(ray, out hitInfo, 8f, 1235288065))
            {
                return;
            }
            Vector3           point            = hitInfo.point;
            Quaternion        deployedRotation = GetDeployedRotation(hitInfo.normal, ray.direction);
            Item              ownerItem        = GetOwnerItem();
            ItemModDeployable modDeployable    = GetModDeployable();
            if (ownerPlayer.Distance(point) > 3f)
            {
                ownerPlayer.ChatMessage("Too far away!");
                return;
            }
            if (!ownerPlayer.CanBuild(point, deployedRotation, deployable.bounds))
            {
                ownerPlayer.ChatMessage("Building is blocked at placement position!");
                return;
            }
            BaseEntity baseEntity = GameManager.server.CreateEntity(modDeployable.entityPrefab.resourcePath, point, deployedRotation);
            if (!baseEntity)
            {
                Debug.LogWarning("Couldn't create prefab:" + modDeployable.entityPrefab.resourcePath);
                return;
            }
            baseEntity.skinID = ownerItem.skin;
            baseEntity.SendMessage("SetDeployedBy", ownerPlayer, SendMessageOptions.DontRequireReceiver);
            baseEntity.OwnerID = ownerPlayer.userID;
            baseEntity.Spawn();
            modDeployable.OnDeployed(baseEntity, ownerPlayer);
            Interface.CallHook("OnItemDeployed", this, modDeployable, baseEntity);
            UseItemAmount(1);
        }
    }
Beispiel #2
0
    public Deployable GetDeployable()
    {
        ItemModDeployable modDeployable = this.GetModDeployable();

        if (modDeployable == null)
        {
            return(null);
        }
        return(modDeployable.GetDeployable(this));
    }
Beispiel #3
0
    public Deployable GetDeployable()
    {
        ItemModDeployable modDeployable = this.GetModDeployable();

        if (Object.op_Equality((Object)modDeployable, (Object)null))
        {
            return((Deployable)null);
        }
        return(modDeployable.GetDeployable((BaseEntity)this));
    }
Beispiel #4
0
    public void DoDeploy_Slot(Deployable deployable, Ray ray, uint entityID)
    {
        if (!base.HasItemAmount())
        {
            return;
        }
        BasePlayer ownerPlayer = base.GetOwnerPlayer();

        if (!ownerPlayer)
        {
            return;
        }
        if (!ownerPlayer.CanBuild())
        {
            return;
        }
        BaseEntity baseEntity = BaseNetworkable.serverEntities.Find(entityID) as BaseEntity;

        if (baseEntity == null)
        {
            return;
        }
        if (!baseEntity.HasSlot(deployable.slot))
        {
            return;
        }
        if (baseEntity.GetSlot(deployable.slot) != null)
        {
            return;
        }
        Item ownerItem = base.GetOwnerItem();
        ItemModDeployable modDeployable = this.GetModDeployable();
        GameManager       gameManager   = GameManager.server;
        string            str           = modDeployable.entityPrefab.resourcePath;
        Vector3           vector3       = new Vector3();
        Quaternion        quaternion    = new Quaternion();
        BaseEntity        baseEntity1   = gameManager.CreateEntity(str, vector3, quaternion, true);

        if (baseEntity1 != null)
        {
            baseEntity1.skinID = ownerItem.skin;
            baseEntity1.SetParent(baseEntity, baseEntity.GetSlotAnchorName(deployable.slot), false, false);
            baseEntity1.OwnerID = ownerPlayer.userID;
            baseEntity1.OnDeployed(baseEntity);
            baseEntity1.Spawn();
            baseEntity.SetSlot(deployable.slot, baseEntity1);
            if (deployable.placeEffect.isValid)
            {
                Effect.server.Run(deployable.placeEffect.resourcePath, baseEntity.transform.position, Vector3.up, null, false);
            }
        }
        modDeployable.OnDeployed(baseEntity1, ownerPlayer);
        Interface.CallHook("OnItemDeployed", this, baseEntity);
        base.UseItemAmount(1);
    }
Beispiel #5
0
    public void DoDeploy_Slot(Deployable deployable, Ray ray, uint entityID)
    {
        if (!HasItemAmount())
        {
            return;
        }
        BasePlayer ownerPlayer = GetOwnerPlayer();

        if (!ownerPlayer)
        {
            return;
        }
        if (!ownerPlayer.CanBuild())
        {
            ownerPlayer.ChatMessage("Building is blocked at player position!");
            return;
        }
        BaseEntity baseEntity = BaseNetworkable.serverEntities.Find(entityID) as BaseEntity;

        if (baseEntity == null || !baseEntity.HasSlot(deployable.slot) || baseEntity.GetSlot(deployable.slot) != null)
        {
            return;
        }
        if (ownerPlayer.Distance(baseEntity) > 3f)
        {
            ownerPlayer.ChatMessage("Too far away!");
            return;
        }
        if (!ownerPlayer.CanBuild(baseEntity.WorldSpaceBounds()))
        {
            ownerPlayer.ChatMessage("Building is blocked at placement position!");
            return;
        }
        Item ownerItem = GetOwnerItem();
        ItemModDeployable modDeployable = GetModDeployable();
        BaseEntity        baseEntity2   = GameManager.server.CreateEntity(modDeployable.entityPrefab.resourcePath);

        if (baseEntity2 != null)
        {
            baseEntity2.skinID = ownerItem.skin;
            baseEntity2.SetParent(baseEntity, baseEntity.GetSlotAnchorName(deployable.slot));
            baseEntity2.OwnerID = ownerPlayer.userID;
            baseEntity2.OnDeployed(baseEntity, ownerPlayer);
            baseEntity2.Spawn();
            baseEntity.SetSlot(deployable.slot, baseEntity2);
            if (deployable.placeEffect.isValid)
            {
                Effect.server.Run(deployable.placeEffect.resourcePath, baseEntity.transform.position, Vector3.up);
            }
        }
        modDeployable.OnDeployed(baseEntity2, ownerPlayer);
        Interface.CallHook("OnItemDeployed", this, baseEntity, baseEntity2);
        UseItemAmount(1);
    }
Beispiel #6
0
    public void DoDeploy_Regular(Deployable deployable, Ray ray)
    {
        RaycastHit raycastHit;

        if (!base.HasItemAmount())
        {
            return;
        }
        BasePlayer ownerPlayer = base.GetOwnerPlayer();

        if (!ownerPlayer)
        {
            return;
        }
        if (!ownerPlayer.CanBuild())
        {
            ownerPlayer.ChatMessage("Building is blocked!");
            return;
        }
        if (ConVar.AntiHack.objectplacement && ownerPlayer.TriggeredAntiHack(1f, Single.PositiveInfinity))
        {
            ownerPlayer.ChatMessage("AntiHack!");
            return;
        }
        if (!this.CheckPlacement(deployable, ray, 8f))
        {
            return;
        }
        if (!UnityEngine.Physics.Raycast(ray, out raycastHit, 8f, 1235288065))
        {
            return;
        }
        Quaternion        deployedRotation = this.GetDeployedRotation(raycastHit.normal, ray.direction);
        Item              ownerItem        = base.GetOwnerItem();
        ItemModDeployable modDeployable    = this.GetModDeployable();
        BaseEntity        baseEntity       = GameManager.server.CreateEntity(modDeployable.entityPrefab.resourcePath, raycastHit.point, deployedRotation, true);

        if (!baseEntity)
        {
            Debug.LogWarning(string.Concat("Couldn't create prefab:", modDeployable.entityPrefab.resourcePath));
            return;
        }
        baseEntity.skinID = ownerItem.skin;
        baseEntity.SendMessage("SetDeployedBy", ownerPlayer, SendMessageOptions.DontRequireReceiver);
        baseEntity.OwnerID = ownerPlayer.userID;
        baseEntity.Spawn();
        modDeployable.OnDeployed(baseEntity, ownerPlayer);
        Interface.CallHook("OnItemDeployed", this, baseEntity);
        base.UseItemAmount(1);
    }
Beispiel #7
0
 // build reference map of prefab IDs to item IDs
 void BuildDeployableLookups()
 {
     foreach (ItemDefinition i in ItemManager.GetItemDefinitions())
     {
         if (i == null)
         {
             continue;
         }
         ItemModDeployable m = i.GetComponent <ItemModDeployable>();
         if (m != null)
         {
             deployableLookup[m.entityPrefab.resourceID] = i.itemid;
         }
     }
 }
Beispiel #8
0
    public void DoDeploy_Regular(Deployable deployable, Ray ray)
    {
        if (!this.HasItemAmount())
        {
            return;
        }
        BasePlayer ownerPlayer = this.GetOwnerPlayer();

        if (!Object.op_Implicit((Object)ownerPlayer))
        {
            return;
        }
        if (!ownerPlayer.CanBuild())
        {
            ownerPlayer.ChatMessage("Building is blocked!");
        }
        else if (ConVar.AntiHack.objectplacement && ownerPlayer.TriggeredAntiHack(1f, float.PositiveInfinity))
        {
            ownerPlayer.ChatMessage("AntiHack!");
        }
        else
        {
            RaycastHit raycastHit;
            if (!this.CheckPlacement(deployable, ray, 8f) || !Physics.Raycast(ray, ref raycastHit, 8f, 1235288065))
            {
                return;
            }
            Quaternion        deployedRotation = this.GetDeployedRotation(((RaycastHit) ref raycastHit).get_normal(), ((Ray) ref ray).get_direction());
            Item              ownerItem        = this.GetOwnerItem();
            ItemModDeployable modDeployable    = this.GetModDeployable();
            BaseEntity        entity           = GameManager.server.CreateEntity(modDeployable.entityPrefab.resourcePath, ((RaycastHit) ref raycastHit).get_point(), deployedRotation, true);
            if (!Object.op_Implicit((Object)entity))
            {
                Debug.LogWarning((object)("Couldn't create prefab:" + modDeployable.entityPrefab.resourcePath));
            }
            else
            {
                entity.skinID = ownerItem.skin;
                ((Component)entity).SendMessage("SetDeployedBy", (object)ownerPlayer, (SendMessageOptions)1);
                entity.OwnerID = ownerPlayer.userID;
                entity.Spawn();
                modDeployable.OnDeployed(entity, ownerPlayer);
                Interface.CallHook("OnItemDeployed", (object)this, (object)entity);
                this.UseItemAmount(1);
            }
        }
    }
Beispiel #9
0
    public void DoDeploy_Slot(Deployable deployable, Ray ray, uint entityID)
    {
        if (!this.HasItemAmount())
        {
            return;
        }
        BasePlayer ownerPlayer = this.GetOwnerPlayer();

        if (!Object.op_Implicit((Object)ownerPlayer) || !ownerPlayer.CanBuild())
        {
            return;
        }
        BaseEntity baseEntity = BaseNetworkable.serverEntities.Find(entityID) as BaseEntity;

        if (Object.op_Equality((Object)baseEntity, (Object)null) || !baseEntity.HasSlot(deployable.slot) || Object.op_Inequality((Object)baseEntity.GetSlot(deployable.slot), (Object)null))
        {
            return;
        }
        ItemModDeployable modDeployable = this.GetModDeployable();
        BaseEntity        entity        = GameManager.server.CreateEntity(modDeployable.entityPrefab.resourcePath, (Vector3)null, (Quaternion)null, true);

        if (Object.op_Inequality((Object)entity, (Object)null))
        {
            entity.SetParent(baseEntity, baseEntity.GetSlotAnchorName(deployable.slot), false, false);
            entity.OwnerID = ownerPlayer.userID;
            entity.OnDeployed(baseEntity);
            entity.Spawn();
            baseEntity.SetSlot(deployable.slot, entity);
            if (deployable.placeEffect.isValid)
            {
                Effect.server.Run(deployable.placeEffect.resourcePath, ((Component)baseEntity).get_transform().get_position(), Vector3.get_up(), (Connection)null, false);
            }
        }
        modDeployable.OnDeployed(entity, ownerPlayer);
        Interface.CallHook("OnItemDeployed", (object)this, (object)baseEntity);
        this.UseItemAmount(1);
    }
Beispiel #10
0
    public void DoBuild(Construction.Target target, Construction component)
    {
        BasePlayer ownerPlayer = base.GetOwnerPlayer();

        if (!ownerPlayer)
        {
            return;
        }
        if (target.ray.IsNaNOrInfinity())
        {
            return;
        }
        if (target.position.IsNaNOrInfinity())
        {
            return;
        }
        if (target.normal.IsNaNOrInfinity())
        {
            return;
        }
        if (target.socket != null)
        {
            if (!target.socket.female)
            {
                ownerPlayer.ChatMessage(string.Concat("Target socket is not female. (", target.socket.socketName, ")"));
                return;
            }
            if (target.entity != null && target.entity.IsOccupied(target.socket))
            {
                ownerPlayer.ChatMessage(string.Concat("Target socket is occupied. (", target.socket.socketName, ")"));
                return;
            }
        }
        else if (ConVar.AntiHack.eye_protection >= 2 && !GamePhysics.LineOfSight(ownerPlayer.eyes.center, ownerPlayer.eyes.position, target.ray.origin, target.position, 2162688, 0.01f))
        {
            ownerPlayer.ChatMessage("Line of sight blocked.");
            return;
        }
        Construction.lastPlacementError = "No Error";
        GameObject gameObject = this.DoPlacement(target, component);

        if (gameObject == null)
        {
            ownerPlayer.ChatMessage(string.Concat("Can't place: ", Construction.lastPlacementError));
        }
        if (gameObject != null)
        {
            Interface.CallHook("OnEntityBuilt", this, gameObject);
            Deployable deployable = this.GetDeployable();
            if (deployable != null)
            {
                BaseEntity baseEntity = gameObject.ToBaseEntity();
                if (deployable.setSocketParent && target.entity != null && target.entity.SupportsChildDeployables() && baseEntity)
                {
                    baseEntity.SetParent(target.entity, true, false);
                }
                if (deployable.wantsInstanceData && base.GetOwnerItem().instanceData != null)
                {
                    (baseEntity as IInstanceDataReceiver).ReceiveInstanceData(base.GetOwnerItem().instanceData);
                }
                if (deployable.copyInventoryFromItem)
                {
                    StorageContainer storageContainer = baseEntity.GetComponent <StorageContainer>();
                    if (storageContainer)
                    {
                        storageContainer.ReceiveInventoryFromItem(base.GetOwnerItem());
                    }
                }
                ItemModDeployable modDeployable = this.GetModDeployable();
                if (modDeployable != null)
                {
                    modDeployable.OnDeployed(baseEntity, ownerPlayer);
                }
            }
            this.PayForPlacement(ownerPlayer, component);
        }
    }
Beispiel #11
0
    public void DoBuild(Construction.Target target, Construction component)
    {
        BasePlayer ownerPlayer = this.GetOwnerPlayer();

        if (!Object.op_Implicit((Object)ownerPlayer) || target.ray.IsNaNOrInfinity() || (Vector3Ex.IsNaNOrInfinity(target.position) || Vector3Ex.IsNaNOrInfinity(target.normal)))
        {
            return;
        }
        if ((PrefabAttribute)target.socket != (PrefabAttribute)null)
        {
            if (!target.socket.female)
            {
                ownerPlayer.ChatMessage("Target socket is not female. (" + target.socket.socketName + ")");
                return;
            }
            if (Object.op_Inequality((Object)target.entity, (Object)null) && target.entity.IsOccupied(target.socket))
            {
                ownerPlayer.ChatMessage("Target socket is occupied. (" + target.socket.socketName + ")");
                return;
            }
        }
        else if (ConVar.AntiHack.eye_protection >= 2)
        {
            Vector3 center    = ownerPlayer.eyes.center;
            Vector3 position1 = ownerPlayer.eyes.position;
            Vector3 origin    = ((Ray) ref target.ray).get_origin();
            Vector3 position2 = target.position;
            Vector3 p1        = position1;
            Vector3 p2        = origin;
            Vector3 p3        = position2;
            if (!GamePhysics.LineOfSight(center, p1, p2, p3, 2162688, 0.01f))
            {
                ownerPlayer.ChatMessage("Line of sight blocked.");
                return;
            }
        }
        Construction.lastPlacementError = "No Error";
        GameObject go = this.DoPlacement(target, component);

        if (Object.op_Equality((Object)go, (Object)null))
        {
            ownerPlayer.ChatMessage("Can't place: " + Construction.lastPlacementError);
        }
        if (!Object.op_Inequality((Object)go, (Object)null))
        {
            return;
        }
        Interface.CallHook("OnEntityBuilt", (object)this, (object)go);
        Deployable deployable = this.GetDeployable();

        if ((PrefabAttribute)deployable != (PrefabAttribute)null)
        {
            BaseEntity baseEntity = go.ToBaseEntity();
            if (deployable.setSocketParent && Object.op_Inequality((Object)target.entity, (Object)null) && (target.entity.SupportsChildDeployables() && Object.op_Implicit((Object)baseEntity)))
            {
                baseEntity.SetParent(target.entity, true, false);
            }
            if (deployable.wantsInstanceData && this.GetOwnerItem().instanceData != null)
            {
                (baseEntity as IInstanceDataReceiver).ReceiveInstanceData(this.GetOwnerItem().instanceData);
            }
            if (deployable.copyInventoryFromItem)
            {
                StorageContainer component1 = (StorageContainer)((Component)baseEntity).GetComponent <StorageContainer>();
                if (Object.op_Implicit((Object)component1))
                {
                    component1.ReceiveInventoryFromItem(this.GetOwnerItem());
                }
            }
            ItemModDeployable modDeployable = this.GetModDeployable();
            if (Object.op_Inequality((Object)modDeployable, (Object)null))
            {
                modDeployable.OnDeployed(baseEntity, ownerPlayer);
            }
        }
        this.PayForPlacement(ownerPlayer, component);
    }