Ejemplo n.º 1
0
	private bool Conscious(ObjectBehaviour playerMob)
	{
		var playerMind = playerMob.GetComponent<PlayerScript>().mind;
		var playerMobID = playerMob.GetComponent<LivingHealthBehaviour>().mobID;

		// If the mob IDs do not match, player is controlling a new mob, so we don't care about this old mob.
		if (playerMind.bodyMobID == playerMobID && playerMind.IsOnline()) return true;

		return false;
	}
Ejemplo n.º 2
0
    private void SetItemsAliveState(bool on)
    {
        if (!on)
        {
            heldItems = matrix.Get <ObjectBehaviour>(registerTile.Position, ObjectType.Item);
        }

        for (var i = 0; i < heldItems.Count; i++)
        {
            ObjectBehaviour    item         = heldItems[i];
            CustomNetTransform netTransform = item.GetComponent <CustomNetTransform>();
            if (@on)
            {
                //avoids blinking of premapped items when opening first time in another place:
                Vector3Int pos = registerTile.WorldPosition;
                netTransform.AppearAtPosition(pos);
                if (pushPull && pushPull.Pushable.IsMovingServer)
                {
                    netTransform.InertiaDrop(pos, pushPull.Pushable.MoveSpeedServer,
                                             pushPull.InheritedImpulse.To2Int());
                }
                else
                {
                    netTransform.AppearAtPositionServer(pos);
                }
            }
            else
            {
                netTransform.DisappearFromWorldServer();
            }

            item.visibleState = @on;
        }
    }
Ejemplo n.º 3
0
    private void SetPlayersAliveState(bool on)
    {
        if (!on)
        {
            heldPlayers = matrix.Get <ObjectBehaviour>(registerTile.Position, ObjectType.Player);
        }

        for (var i = 0; i < heldPlayers.Count; i++)
        {
            ObjectBehaviour player       = heldPlayers[i];
            var             playerScript = player.GetComponent <PlayerScript>();
            var             playerSync   = playerScript.PlayerSync;
            if (@on)
            {
                playerSync.AppearAtPositionServer(registerTile.WorldPosition);
                if (pushPull && pushPull.Pushable.IsMovingServer)
                {
                    playerScript.pushPull.TryPush(pushPull.InheritedImpulse.To2Int(), pushPull.Pushable.MoveSpeedServer);
                }
            }

            player.visibleState = @on;

            if (!@on)
            {
                playerSync.DisappearFromWorldServer();
                //Make sure a ClosetPlayerHandler is created on the client to monitor
                //the players input inside the storage. The handler also controls the camera follow targets:
                if (!playerScript.playerMove.isGhost)
                {
                    ClosetHandlerMessage.Send(player.gameObject, gameObject);
                }
            }
        }
    }
Ejemplo n.º 4
0
        private void PushPlayer(ObjectBehaviour player, Vector3 pushVector)
        {
            player.GetComponent <RegisterPlayer>()?.ServerStun();

            //Push Twice
            player.QueuePush(pushVector.NormalizeTo2Int());
            player.QueuePush(pushVector.NormalizeTo2Int());
        }
	/// <summary>
	/// Spits out ID card from console and updates login details.
	/// </summary>
	public void RemoveID()
	{
		ObjectBehaviour objBeh = IdCard.GetComponentInChildren<ObjectBehaviour>();
		Vector3Int pos = gameObject.RegisterTile().WorldPosition;
		CustomNetTransform netTransform = objBeh.GetComponent<CustomNetTransform>();
		netTransform.AppearAtPosition(pos);
		netTransform.AppearAtPositionServer(pos);
		IdCard = null;
	}
Ejemplo n.º 6
0
    /// <summary>
    /// Spits out ID card from console and updates login details.
    /// </summary>
    /// <param name="cardToEject">Card you want to eject</param>
    public void EjectCard(IDCard cardToEject)
    {
        ObjectBehaviour    objBeh       = cardToEject.GetComponentInChildren <ObjectBehaviour>();
        Vector3Int         pos          = gameObject.RegisterTile().WorldPosition;
        CustomNetTransform netTransform = objBeh.GetComponent <CustomNetTransform>();

        netTransform.AppearAtPosition(pos);
        netTransform.AppearAtPositionServer(pos);
        UpdateGUI();
    }
        void EjectItemOrObject(ObjectBehaviour entity)
        {
            if (entity == null)
            {
                return;
            }

            entity.parentContainer = null;
            entity.GetComponent <CustomNetTransform>()?.SetPosition(ContainerWorldPosition);
        }
Ejemplo n.º 8
0
    public virtual void TransportObjectsItems(ObjectBehaviour objectsitems)
    {
        var newPosition = selectedWorld.registerTile.WorldPosition;

        if (selectedWorld.OverrideCoord != Vector3Int.zero)
        {
            newPosition = selectedWorld.OverrideCoord;
        }
        //teleports objects/items to the front of the new gateway
        objectsitems.GetComponent <CustomNetTransform>().SetPosition(newPosition);
    }
        void EjectPlayer(ObjectBehaviour player)
        {
            if (player == null)
            {
                return;
            }

            player.parentContainer = null;
            player.GetComponent <PlayerSync>()?.SetPosition(ContainerWorldPosition);
            FollowCameraMessage.Send(player.gameObject, player.gameObject);
        }
Ejemplo n.º 10
0
    public virtual void TransportPlayers(ObjectBehaviour player)
    {
        var newPosition = selectedWorld.registerTile.WorldPosition;

        if (selectedWorld.OverrideCoord != Vector3Int.zero)
        {
            newPosition = selectedWorld.OverrideCoord;
        }

        //teleports player to the front of the new gateway
        player.GetComponent <PlayerSync>().SetPosition(newPosition);
    }
Ejemplo n.º 11
0
    public void StorePlayer(ObjectBehaviour player)
    {
        heldPlayers.Add(player);
        var playerScript = player.GetComponent <PlayerScript>();

        player.VisibleState    = false;
        player.parentContainer = PushPull;

        //Start tracking closet
        if (!playerScript.IsGhost)
        {
            FollowCameraMessage.Send(player.gameObject, gameObject);
        }
    }
Ejemplo n.º 12
0
    protected void ServerStorePlayer(ObjectBehaviour player)
    {
        serverHeldPlayers.Add(player);
        var playerScript = player.GetComponent <PlayerScript>();

        player.VisibleState = false;
        playerScript.playerMove.IsTrapped = true;
        player.parentContainer            = PushPull;

        //Start tracking closet
        if (!playerScript.IsGhost)
        {
            FollowCameraMessage.Send(player.gameObject, gameObject);
        }
    }
Ejemplo n.º 13
0
    public int GetSellPrice(ObjectBehaviour item)
    {
        if (!CustomNetworkManager.Instance._isServer)
        {
            return(0);
        }

        var attributes = item.GetComponent <Attributes>();

        if (attributes == null)
        {
            return(0);
        }

        return(attributes.ExportCost);
    }
Ejemplo n.º 14
0
    public void StorePlayer(ObjectBehaviour player)
    {
        heldPlayers.Add(player);
        var playerScript = player.GetComponent <PlayerScript>();
        var playerSync   = playerScript.PlayerSync;

        player.visibleState    = false;
        player.parentContainer = objectBehaviour;
        playerSync.DisappearFromWorldServer();
        //Make sure a ClosetPlayerHandler is created on the client to monitor
        //the players input inside the storage. The handler also controls the camera follow targets:
        if (!playerScript.IsGhost)
        {
            ClosetHandlerMessage.Send(player.gameObject, gameObject);
        }
    }
Ejemplo n.º 15
0
		private void ThrowItem(ObjectBehaviour item, Vector3 throwVector)
		{
			Vector3 vector = item.transform.rotation * throwVector;
			var spin = RandomSpin();
			ThrowInfo throwInfo = new ThrowInfo
			{
				ThrownBy = gameObject,
				Aim = BodyPartType.Chest,
				OriginWorldPos = transform.position,
				WorldTrajectory = vector,
				SpinMode = spin
			};

			CustomNetTransform itemTransform = item.GetComponent<CustomNetTransform>();
			if (itemTransform == null) return;
			itemTransform.Throw(throwInfo);
		}
        void ThrowItem(ObjectBehaviour item, Vector3 throwVector)
        {
            Vector3   vector    = item.transform.rotation * throwVector;
            ThrowInfo throwInfo = new ThrowInfo
            {
                ThrownBy        = Matrix.transform.parent.gameObject,
                Aim             = BodyPartType.Chest,
                OriginWorldPos  = ContainerWorldPosition,
                WorldTrajectory = vector,
                SpinMode        = SpinMode.Clockwise          // TODO: randomise this
            };

            CustomNetTransform itemTransform = item.GetComponent <CustomNetTransform>();

            if (itemTransform == null)
            {
                return;
            }
            itemTransform.Throw(throwInfo);
        }
Ejemplo n.º 17
0
    void PrepareNextObject2()
    {
        uint nextObjectHeight = (uint)Random.Range(1, (int)screwdriverController.totalHeights + 1);

        if (nextObjectHeight == objectBehaviour.height)
        {
            if (nextObjectHeight > 1)
            {
                --nextObjectHeight;
            }
            else
            {
                ++nextObjectHeight;
            }
        }
        objectBehaviour.height = nextObjectHeight;
        Debug.Log("Next object height: " + nextObjectHeight);
        switch (objectBehaviour.height)
        {
        case 1:
            objectBehaviour.GetComponent <MeshFilter>().mesh       = objectBehaviour.mesh1;
            objectBehaviour.GetComponent <MeshRenderer>().material = objectBehaviour.material1;
            break;

        case 2:
            objectBehaviour.GetComponent <MeshFilter>().mesh       = objectBehaviour.mesh2;
            objectBehaviour.GetComponent <MeshRenderer>().material = objectBehaviour.material2;
            break;

        case 3:
            objectBehaviour.GetComponent <MeshFilter>().mesh       = objectBehaviour.mesh3;
            objectBehaviour.GetComponent <MeshRenderer>().material = objectBehaviour.material3;
            break;
        }

        objectBehaviour.transform.gameObject.AddComponent <BoxCollider>();
        objectBehaviour.transform.gameObject.AddComponent <Rigidbody>();
        objectBehaviour.transform.rotation = Quaternion.AngleAxis(180.0f, Vector3.up);
        objectBehaviour.RecalculateSize();
        objectBehaviour.RemoveHoles();
        objectBehaviour.SpawnHoles();
        objectBehaviour.transform.gameObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
        objectBehaviour.transform.position = new Vector3(0.0f, objectInitialHeight, 0.0f); // TODO: finish positioning...

        gameState = GameState.moveObjectDown;
    }
Ejemplo n.º 18
0
 public virtual void TransportPlayers(ObjectBehaviour player)
 {
     //teleports player to the front of the new gateway
     player.GetComponent <PlayerSync>().SetPosition(selectedWorld.GetComponent <RegisterTile>().WorldPosition);
 }
Ejemplo n.º 19
0
 public override void TransportObjectsItems(ObjectBehaviour objectsitems)
 {
     objectsitems.GetComponent <CustomNetTransform>().SetPosition(StationGateway.GetComponent <RegisterTile>().WorldPosition);
 }
Ejemplo n.º 20
0
 public override void TransportPlayers(ObjectBehaviour player)
 {
     //teleports player to the front of the new gateway
     player.GetComponent <PlayerSync>().SetPosition(StationGateway.GetComponent <RegisterTile>().WorldPosition);
 }
Ejemplo n.º 21
0
 public virtual void TransportPlayers(ObjectBehaviour player)
 {
     //teleports player to the next tile
     player.GetComponent <PlayerSync>().SetPosition(registerTile.WorldPosition + position);
 }
Ejemplo n.º 22
0
 public void TransportPlayers(ObjectBehaviour player)
 {
     //teleports player to the front of the new gateway
     player.GetComponent <PlayerSync>().SetPosition(travelCoord, true);
 }
Ejemplo n.º 23
0
 public virtual void Transport(ObjectBehaviour toTransport)
 {
     toTransport.GetComponent <CustomNetTransform>().SetPosition(registerTile.WorldPosition + position);
 }
Ejemplo n.º 24
0
 public void TransportObjectsItems(ObjectBehaviour objectsItems)
 {
     objectsItems.GetComponent <CustomNetTransform>().SetPosition(travelCoord);
 }
Ejemplo n.º 25
0
    public void DestroyItem(ObjectBehaviour item, HashSet <GameObject> alreadySold)
    {
        //already sold this this sales cycle.
        if (alreadySold.Contains(item.gameObject))
        {
            return;
        }
        var storage = item.GetComponent <InteractableStorage>();

        if (storage)
        {
            foreach (var slot in storage.ItemStorage.GetItemSlots())
            {
                if (slot.Item)
                {
                    DestroyItem(slot.Item.GetComponent <ObjectBehaviour>(), alreadySold);
                }
            }
        }

        //note: it seems the held items are also detected in UnloadCargo as being on the matrix but only
        //when they were spawned or moved onto that cargo shuttle (outside of the crate) prior to being placed into the crate. If they
        //were instead placed into the crate and then the crate was moved onto the cargo shuttle, they
        //will only be found with this check and won't be found in UnloadCargo.
        //TODO: Better logic for ClosetControl updating its held items' parent matrix when crossing matrix with items inside.
        var closet = item.GetComponent <ClosetControl>();

        if (closet)
        {
            foreach (var closetItem in closet.ServerHeldItems)
            {
                DestroyItem(closetItem, alreadySold);
            }
        }

        // If there is no bounty for the item - we dont destroy it.
        var credits = Instance.GetSellPrice(item);

        Credits += credits;
        OnCreditsUpdate?.Invoke();

        var    attributes = item.gameObject.GetComponent <Attributes>();
        string exportName;

        if (attributes)
        {
            if (string.IsNullOrEmpty(attributes.ExportName))
            {
                exportName = attributes.ArticleName;
            }
            else
            {
                exportName = attributes.ExportName;
            }
        }
        else
        {
            exportName = item.gameObject.ExpensiveName();
        }
        ExportedItem export;

        if (exportedItems.ContainsKey(exportName))
        {
            export = exportedItems[exportName];
        }
        else
        {
            export = new ExportedItem
            {
                ExportMessage = attributes ? attributes.ExportMessage : "",
                ExportName    = attributes ? attributes.ExportName : ""              // Need to always use the given export name
            };
            exportedItems.Add(exportName, export);
        }

        var stackable = item.gameObject.GetComponent <Stackable>();
        var count     = 1;

        if (stackable)
        {
            count = stackable.Amount;
        }

        export.Count      += count;
        export.TotalValue += credits;

        var playerScript = item.GetComponent <PlayerScript>();

        if (playerScript != null)
        {
            playerScript.playerHealth.ServerGibPlayer();
        }

        item.registerTile.UnregisterClient();
        item.registerTile.UnregisterServer();
        alreadySold.Add(item.gameObject);
        Despawn.ServerSingle(item.gameObject);
    }
Ejemplo n.º 26
0
    public void DestroyItem(ObjectBehaviour item)
    {
        var storage = item.GetComponent <InteractableStorage>();

        if (storage)
        {
            foreach (var slot in storage.ItemStorage.GetItemSlots())
            {
                if (slot.Item)
                {
                    DestroyItem(slot.Item.GetComponent <ObjectBehaviour>());
                }
            }
        }

        var closet = item.GetComponent <ClosetControl>();

        if (closet)
        {
            foreach (var closetItem in closet.ServerHeldItems)
            {
                DestroyItem(closetItem);
            }
        }

        // If there is no bounty for the item - we dont destroy it.
        var credits = Instance.GetSellPrice(item);

        Credits += credits;
        OnCreditsUpdate?.Invoke();

        var    attributes = item.gameObject.GetComponent <Attributes>();
        string exportName;

        if (attributes)
        {
            if (string.IsNullOrEmpty(attributes.ExportName))
            {
                exportName = attributes.ArticleName;
            }
            else
            {
                exportName = attributes.ExportName;
            }
        }
        else
        {
            exportName = item.gameObject.ExpensiveName();
        }
        ExportedItem export;

        if (exportedItems.ContainsKey(exportName))
        {
            export = exportedItems[exportName];
        }
        else
        {
            export = new ExportedItem
            {
                ExportMessage = attributes ? attributes.ExportMessage : "",
                ExportName    = attributes ? attributes.ExportName : ""              // Need to always use the given export name
            };
            exportedItems.Add(exportName, export);
        }

        var stackable = item.gameObject.GetComponent <Stackable>();
        var count     = 1;

        if (stackable)
        {
            count = stackable.Amount;
        }

        export.Count      += count;
        export.TotalValue += credits;

        item.registerTile.UnregisterClient();
        item.registerTile.UnregisterServer();
        Despawn.ServerSingle(item.gameObject);
    }
Ejemplo n.º 27
0
 public virtual void TransportObjectsItems(ObjectBehaviour objectsitems)
 {
     objectsitems.GetComponent <CustomNetTransform>().SetPosition(selectedWorld.GetComponent <RegisterTile>().WorldPosition);
 }
Ejemplo n.º 28
0
        private void CheckPlayerCrawlState(ObjectBehaviour playerBehaviour)
        {
            var regPlayer = playerBehaviour.GetComponent <RegisterPlayer>();

            regPlayer.HandleGetupAnimation(!regPlayer.IsLayingDown);
        }