コード例 #1
0
        private static void CCModifyStat(ConCommandArgs args)
        {
            if (args.Count < 1)
            {
                TILER2Plugin._logger.LogError("t2_stat: missing argument 1 (stat ID)!");
                return;
            }
            if (args.Count < 2)
            {
                TILER2Plugin._logger.LogError("t2_stat: missing argument 2 (stat value)!");
                return;
            }
            var searchStr  = args.TryGetArgString(0);
            var searchList = debugStatArgsFields.Where(x => x.Name == searchStr);

            if (searchList.Count() == 0)
            {
                TILER2Plugin._logger.LogError($"t2_stat: could not find stat with name \"{searchStr}\"!");
                return;
            }
            float?setVal = args.TryGetArgFloat(1);

            if (!setVal.HasValue)
            {
                TILER2Plugin._logger.LogError($"t2_stat: argument 2 (stat value) is badly formatted!");
                return;
            }
            searchList.First().SetValue(fixedDebugStatArgs, setVal.Value);
        }
コード例 #2
0
        private static void ConCmdYeet(ConCommandArgs args)
        {
            if (!args.senderBody)
            {
                _logger.LogError("ConCmdYeet: called by nonexistent player!");
                return;
            }
            if (args.Count < 1)
            {
                _logger.LogError("ConCmdYeet: not enough arguments! Need at least 1 (item ID), received 0.");
                return;
            }

            bool isEquipment = args.TryGetArgBool(1) ?? false;

            if (isEquipment ? preventEquipment : preventItems)
            {
                return;
            }

            int    rawInd;
            string itemSearch = args.TryGetArgString(0);

            if (itemSearch == null)
            {
                _logger.LogError("ConCmdYeet: could not read first argument (item ID)!");
                return;
            }
            else if (int.TryParse(itemSearch, out rawInd))
            {
                if (isEquipment)
                {
                    if (!EquipmentCatalog.IsIndexValid((EquipmentIndex)rawInd))
                    {
                        _logger.LogError("ConCmdYeet: first argument (equipment ID as integer EquipmentIndex) is out of range; no equipment with that ID exists!");
                        return;
                    }
                }
                else
                {
                    if (!ItemCatalog.IsIndexValid((ItemIndex)rawInd))
                    {
                        _logger.LogError("ConCmdYeet: first argument (item ID as integer ItemIndex) is out of range; no item with that ID exists!");
                        return;
                    }
                }
            }
            else
            {
                if (isEquipment)
                {
                    var results = EquipmentCatalog.allEquipment.Where((searchInd) => {
                        var iNameToken = EquipmentCatalog.GetEquipmentDef(searchInd).nameToken;
                        var iName      = Language.GetString(iNameToken);
                        return(iName.ToUpper().Contains(itemSearch.ToUpper()));
                    });
                    if (results.Count() < 1)
                    {
                        _logger.LogError("ConCmdYeet: first argument (equipment ID as string EquipmentName) not found in EquipmentCatalog; no equipment with a name containing that string exists!");
                        return;
                    }
                    else
                    {
                        if (results.Count() > 1)
                        {
                            _logger.LogWarning("ConCmdYeet: first argument (item ID as string EquipmentName) matched multiple equipments; using first.");
                        }
                        rawInd = (int)results.First();
                    }
                }
                else
                {
                    var results = ItemCatalog.allItems.Where((searchInd) => {
                        var iNameToken = ItemCatalog.GetItemDef(searchInd).nameToken;
                        var iName      = Language.GetString(iNameToken);
                        return(iName.ToUpper().Contains(itemSearch.ToUpper()));
                    });
                    if (results.Count() < 1)
                    {
                        _logger.LogError("ConCmdYeet: first argument (item ID as string ItemName) not found in ItemCatalog; no item with a name containing that string exists!");
                        return;
                    }
                    else
                    {
                        if (results.Count() > 1)
                        {
                            _logger.LogWarning("ConCmdYeet: first argument (item ID as string ItemName) matched multiple items; using first.");
                        }
                        rawInd = (int)results.First();
                    }
                }
            }

            float throwForce = Mathf.Lerp(lowThrowForce, highThrowForce, Mathf.Clamp01(args.TryGetArgFloat(2) ?? 0f));

            if (isEquipment)
            {
                if (args.senderBody.inventory.GetEquipmentIndex() != (EquipmentIndex)rawInd)
                {
                    _logger.LogWarning("ConCmdYeet: someone's trying to drop an equipment they don't have");
                    return;
                }

                var edef = EquipmentCatalog.GetEquipmentDef((EquipmentIndex)rawInd);
                args.senderBody.inventory.SetEquipmentIndex(EquipmentIndex.None);
                args.senderBody.inventory.RemoveItem((ItemIndex)rawInd);

                PickupDropletController.CreatePickupDroplet(
                    PickupCatalog.FindPickupIndex((EquipmentIndex)rawInd),
                    args.senderBody.inputBank.aimOrigin,
                    args.senderBody.inputBank.aimDirection * throwForce);
            }
            else
            {
                int count;
                if (Compat_TILER2.enabled)
                {
                    count = Compat_TILER2.GetRealItemCount(args.senderBody.inventory, (ItemIndex)rawInd);
                }
                else
                {
                    count = args.senderBody.inventory.GetItemCount((ItemIndex)rawInd);
                }
                if (count < 1)
                {
                    _logger.LogWarning("ConCmdYeet: someone's trying to drop an item they don't have any of");
                    return;
                }

                var idef = ItemCatalog.GetItemDef((ItemIndex)rawInd);
                if (idef.hidden || !idef.canRemove || (idef.tier == ItemTier.Lunar && preventLunar) || idef.tier == ItemTier.NoTier)
                {
                    return;
                }
                args.senderBody.inventory.RemoveItem((ItemIndex)rawInd);

                var obj = GameObject.Instantiate(PickupDropletController.pickupDropletPrefab, args.senderBody.inputBank.aimOrigin, Quaternion.identity);
                obj.AddComponent <PickupDropletNoCommandFlag>();
                obj.GetComponent <PickupDropletController>().NetworkpickupIndex = PickupCatalog.FindPickupIndex((ItemIndex)rawInd);
                var rbdy = obj.GetComponent <Rigidbody>();
                rbdy.velocity = args.senderBody.inputBank.aimDirection * throwForce;
                rbdy.AddTorque(Random.Range(150f, 120f) * Random.onUnitSphere);
                NetworkServer.Spawn(obj);
            }
        }