Example #1
0
        public static void TransportObject(PushPull pushPullObject, Vector3 transportTo)
        {
            if (pushPullObject == null)
            {
                return;                 //Don't even bother...
            }
            //Handle PlayerSync and CustomNetTransform (No shared base class, so terrible duping time)

            //Player objects get PlayerSync
            var playerSync = pushPullObject.GetComponent <PlayerSync>();

            if (playerSync != null)
            {
                playerSync.DisappearFromWorldServer();
                playerSync.AppearAtPositionServer(transportTo);
                playerSync.RollbackPrediction();
            }
            //Object and Item objects get CustomNetTransform
            var customNetTransform = pushPullObject.GetComponent <CustomNetTransform>();

            if (customNetTransform != null)
            {
                customNetTransform.DisappearFromWorldServer();
                customNetTransform.AppearAtPositionServer(transportTo);
                customNetTransform.RollbackPrediction();
            }
        }
Example #2
0
        public int GetSellPrice(PushPull item)
        {
            if (!CustomNetworkManager.Instance._isServer)
            {
                return(0);
            }

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

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

            return(attributes.ExportCost);
        }
Example #3
0
    public void CmdPullObject(GameObject obj)
    {
        if (isPulling)
        {
            GameObject cObj = gameObject.GetComponent <IPlayerSync>().PullingObject;
            cObj.GetComponent <PushPull>().pulledBy = null;
            gameObject.GetComponent <IPlayerSync>().PullObjectID = NetworkInstanceId.Invalid;
        }

        PushPull pulled = obj.GetComponent <PushPull>();

        //Stop CNT as the transform of the pulled obj is now handled by PlayerSync
        pulled.RpcToggleCnt(false);
        //Cache value for new players
        pulled.custNetActiveState = false;
        //check if the object you want to pull is another player
        if (pulled.isPlayer)
        {
            IPlayerSync playerS = obj.GetComponent <IPlayerSync>();
            //Anything that the other player is pulling should be stopped
            if (playerS.PullingObject != null)
            {
                PlayerNetworkActions otherPNA = obj.GetComponent <PlayerNetworkActions>();
                otherPNA.CmdStopOtherPulling(playerS.PullingObject);
            }
        }
        //Other player is pulling object, send stop on that player
        if (pulled.pulledBy != null)
        {
            if (pulled.pulledBy != gameObject)
            {
                pulled.GetComponent <PlayerNetworkActions>().CmdStopPulling(obj);
            }
        }

        if (pulled != null)
        {
            IPlayerSync pS = GetComponent <IPlayerSync>();
            pS.PullObjectID = pulled.netId;
            isPulling       = true;
        }
    }
Example #4
0
        private void ThrowItem(PushPull 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);
        }
Example #5
0
    public void CmdPullObject(GameObject obj)
    {
        if (isPulling)
        {
            GameObject cObj = gameObject.GetComponent <PlayerSync>().pullingObject;
            cObj.GetComponent <PushPull>().pulledBy             = null;
            gameObject.GetComponent <PlayerSync>().pullObjectID = NetworkInstanceId.Invalid;
        }

        PushPull pulled = obj.GetComponent <PushPull>();

        //check if the object you want to pull is another player
        if (pulled.isPlayer)
        {
            PlayerSync playerS = obj.GetComponent <PlayerSync>();
            //Anything that the other player is pulling should be stopped
            if (playerS.pullingObject != null)
            {
                PlayerNetworkActions otherPNA = obj.GetComponent <PlayerNetworkActions>();
                otherPNA.CmdStopOtherPulling(playerS.pullingObject);
            }
        }
        //Other player is pulling object, send stop on that player
        if (pulled.pulledBy != null)
        {
            if (pulled.pulledBy != gameObject)
            {
                pulled.GetComponent <PlayerNetworkActions>().CmdStopPulling(obj);
            }
        }



        if (pulled != null)
        {
            PlayerSync pS = GetComponent <PlayerSync>();
            pS.pullObjectID = pulled.netId;
            isPulling       = true;
        }
    }
Example #6
0
        public void ProcessCargo(PushPull item, HashSet <GameObject> alreadySold)
        {
            var wrappedItem = item.GetComponent <WrappedBase>();

            if (wrappedItem)
            {
                var wrappedContents = wrappedItem.GetOrGenerateContent().GetComponent <PushPull>();
                ProcessCargo(wrappedContents, alreadySold);
                DespawnItem(item, alreadySold);
                return;
            }

            //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)
                    {
                        ProcessCargo(slot.Item.GetComponent <PushPull>(), 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)
                {
                    ProcessCargo(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 = String.Empty;

            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 itemAttributes = item.GetComponent <ItemAttributesV2>();

            if (itemAttributes)
            {
                foreach (var itemTrait in itemAttributes.GetTraits())
                {
                    count = TryCompleteBounty(itemTrait, count);
                    if (count == 0)
                    {
                        break;
                    }
                }
            }

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

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

            DespawnItem(item, alreadySold);
        }
Example #7
0
        public void ProcessCargo(PushPull item, HashSet <GameObject> alreadySold)
        {
            var wrappedItem = item.GetComponent <WrappedBase>();

            if (wrappedItem)
            {
                var wrappedContents = wrappedItem.GetOrGenerateContent().GetComponent <PushPull>();
                ProcessCargo(wrappedContents, alreadySold);
                DespawnItem(item, alreadySold);
                return;
            }

            //already sold this this sales cycle.
            if (alreadySold.Contains(item.gameObject))
            {
                return;
            }
            var storage = item.GetComponent <InteractableStorage>();

            if (storage)
            {
                //Check to spawn initial contents, cant just use prefab data due to recursion
                if (storage.ItemStorage.ContentsSpawned == false)
                {
                    storage.ItemStorage.TrySpawnContents();
                }

                foreach (var slot in storage.ItemStorage.GetItemSlots())
                {
                    if (slot.Item)
                    {
                        ProcessCargo(slot.Item.GetComponent <PushPull>(), 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)
            {
                //Check to spawn initial contents, cant just use prefab data due to recursion
                if (closet.ContentsSpawned == false && closet.InitialContents != null)
                {
                    closet.TrySpawnContents(true);
                }

                foreach (var closetItem in closet.ServerHeldItems)
                {
                    ProcessCargo(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 = String.Empty;

            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 itemAttributes = item.GetComponent <ItemAttributesV2>();

            if (itemAttributes)
            {
                foreach (var itemTrait in itemAttributes.GetTraits())
                {
                    if (itemTrait == null)
                    {
                        Logger.LogError($"{itemAttributes.name} has null or empty item trait, please fix");
                        continue;
                    }
                    if (SoldHistory.ContainsKey(itemTrait) == false)
                    {
                        SoldHistory.Add(itemTrait, 0);
                    }
                    SoldHistory[itemTrait] += count;
                    count = TryCompleteBounty(itemTrait, count);
                    if (count == 0)
                    {
                        break;
                    }
                }
            }

            //Add value of mole inside gas container
            var gasContainer = item.GetComponent <GasContainer>();

            if (gasContainer)
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.Append(export.ExportMessage);

                foreach (var gas in gasContainer.GasMix.GasesArray)
                {
                    stringBuilder.AppendLine($"Exported {gas.Moles} moles of {gas.GasSO.Name} for {(int)gas.Moles * gas.GasSO.ExportPrice} credits");
                    export.TotalValue += (int)gas.Moles * gas.GasSO.ExportPrice;
                }

                export.ExportMessage = stringBuilder.ToString();
            }

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

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

            DespawnItem(item, alreadySold);
        }