Exemplo n.º 1
0
 private static void ProcessReactor(MyObjectBuilder_CubeBlock block, Options options, MyCubeSize size)
 {         // Has it's own inventory, but it doesn't work, so still needs supporting function to add inventory
     if (options.PowerDownGrid)
     {
         ((MyObjectBuilder_Reactor)block).Enabled = false;
     }
     if (!options.Restock)
     {
         return;
     }
     try
     {
         List <MyDefinitionId> fuelList = GetItemDefinitionList(block);
         if (fuelList == null)
         {
             return;
         }
         MyObjectBuilder_Ingot fuel = new MyObjectBuilder_Ingot {
             SubtypeName = fuelList[0].SubtypeName
         };
         MyPhysicalItemDefinition fuelDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(fuel.GetId());
         //AddToInventory(block.ComponentContainer, fuel, (int)(GetMaxVolume(block, size) / fuelDefinition.Volume), true);
         int amountToAdd = GetAmount(GetMaxVolume(block, size), fuelDefinition.Volume);
         if (options.MaxAmmo != 0 && amountToAdd > options.MaxUranium)
         {
             amountToAdd = options.MaxAmmo;
         }
         AddToInventory(block.ComponentContainer, fuel, amountToAdd, true);
     }
     catch (Exception e)
     {
         Core.GeneralLog.WriteToLog("MyObjectBuilder_Reactor", $"Exception! {e}");
     }
 }
Exemplo n.º 2
0
        public static int getitemidfromitemname(string itemname, ulong userID, ShopItem item)
        {
            var temp = new MyObjectBuilder_PhysicalObject();

            if (item != null)
            {
                if (item.ItemName == itemname)
                {
                    temp = new MyObjectBuilder_Ingot()
                    {
                        SubtypeName = itemname
                    };
                    ChatUtil.SendPrivateChat(userID, Convert.ToString(temp.GetHashCode()));
                    return(temp.GetHashCode());
                }
                else
                {
                    ChatUtil.SendPrivateChat(userID, "Please enter a valid item name.");
                }
            }


            return(0);
        }
Exemplo n.º 3
0
        private void AwardPoints(ZoneBlock zone, IMyFaction faction, int enemies, bool displayHeader)
        {
            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                return;
            }

            string planetName = zone.GetClosestPlanet();

            if (!Planets.Any(description => description.Name == planetName))
            {
                PlanetDescription p = new PlanetDescription()
                {
                    Name   = planetName,
                    Scores = new List <ScoreDescription>()
                };

                Planets.Add(p);
            }

            long facId = faction.FactionId;
            PlanetDescription planet   = Planets.Find(w => w.Name == planetName);
            IMyCubeGrid       kothGrid = (zone.Entity as IMyCubeBlock).CubeGrid;

            if (!planet.Scores.Any(s => s.FactionId == facId))
            {
                planet.Scores.Add(new ScoreDescription()
                {
                    FactionId   = facId,
                    FactionName = faction.Name,
                    FactionTag  = faction.Tag,
                    Points      = 1,
                    PlanetId    = planetName,
                    GridName    = kothGrid.DisplayName
                });
            }

            int total = GetTotalScore(planet);
            ScoreDescription score = planet.Scores.Find(s => s.FactionId == facId);
            int current            = score.Points;

            int points;

            if (zone.PointsOnCap.Value == 0)
            {
                points = (int)(((float)(total - current) / (float)total) * 5f * enemies) + 1 + enemies;
            }
            else
            {
                points = zone.PointsOnCap.Value;
            }

            planet.Scores.Find(s => s.FactionId == facId).Points += points;
            zone.PointsEarnedSincePrize += points;


            if (zone.AwardPointsAsCredits.Value)
            {
                faction.RequestChangeBalance(points * zone.CreditsPerPoint.Value);
            }


            if (zone.PointsEarnedSincePrize >= zone.PointsForPrize.Value)
            {
                zone.PointsEarnedSincePrize -= zone.PointsForPrize.Value;

                IMyCargoContainer   prizebox = null;
                List <IMySlimBlock> temp     = new List <IMySlimBlock>();
                kothGrid.GetBlocks(temp, s => {
                    if (prizebox == null &&
                        s.FatBlock != null &&
                        s.FatBlock is IMyCargoContainer &&
                        s.FatBlock.BlockDefinition.SubtypeId == "Prizebox")
                    {
                        prizebox = s.FatBlock as IMyCargoContainer;
                    }

                    return(false);
                });

                if (zone.UseComponentReward.Value)
                {
                    string prizeType = (zone.AdvancedComponentSelection.Value) ? zone.PrizeComponentSubtypeId.Value : zone.SelectedComponentString.Value;
                    int    amount    = zone.PrizeAmountComponent.Value;

                    MyDefinitionId                definitionId  = new MyDefinitionId(typeof(MyObjectBuilder_Component), prizeType);
                    MyObjectBuilder_Component     content       = (MyObjectBuilder_Component)MyObjectBuilderSerializer.CreateNewObject(definitionId);
                    MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                        Amount = amount, Content = content
                    };

                    if (zone.SpawnIntoPrizeBox.Value)
                    {
                        if (prizebox == null)
                        {
                            Tools.Log(MyLogSeverity.Error, $"Could not find prize box on grid: {kothGrid.DisplayName} - {kothGrid.EntityId}");
                        }
                        else if (prizebox.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            prizebox.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                    else
                    {
                        if (zone.Entity.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            zone.Entity.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                }

                if (zone.UseIngotReward.Value)
                {
                    string prizeType = (zone.AdvancedIngotSelection.Value) ? zone.PrizeIngotSubtypeId.Value : zone.SelectedIngotString.Value;
                    int    amount    = zone.PrizeAmountIngot.Value;

                    MyDefinitionId                definitionId  = new MyDefinitionId(typeof(MyObjectBuilder_Ingot), prizeType);
                    MyObjectBuilder_Ingot         content       = (MyObjectBuilder_Ingot)MyObjectBuilderSerializer.CreateNewObject(definitionId);
                    MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                        Amount = amount, Content = content
                    };

                    if (zone.SpawnIntoPrizeBox.Value)
                    {
                        if (prizebox == null)
                        {
                            Tools.Log(MyLogSeverity.Error, $"Could not find prize box on grid: {kothGrid.DisplayName} - {kothGrid.EntityId}");
                        }
                        else if (prizebox.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            prizebox.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                    else
                    {
                        if (zone.Entity.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            zone.Entity.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                }

                if (zone.UseOreReward.Value)
                {
                    string prizeType = (zone.AdvancedOreSelection.Value) ? zone.PrizeOreSubtypeId.Value : zone.SelectedOreString.Value;
                    int    amount    = zone.PrizeAmountOre.Value;

                    MyDefinitionId                definitionId  = new MyDefinitionId(typeof(MyObjectBuilder_Ore), prizeType);
                    MyObjectBuilder_Ore           content       = (MyObjectBuilder_Ore)MyObjectBuilderSerializer.CreateNewObject(definitionId);
                    MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                        Amount = amount, Content = content
                    };

                    if (zone.SpawnIntoPrizeBox.Value)
                    {
                        if (prizebox == null)
                        {
                            Tools.Log(MyLogSeverity.Error, $"Could not find prize box on grid: {kothGrid.DisplayName} - {kothGrid.EntityId}");
                        }
                        else if (prizebox.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            prizebox.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                    else
                    {
                        if (zone.Entity.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            zone.Entity.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                }
            }

            StringBuilder message = new StringBuilder();

            if (displayHeader && zone.IsLocationNamed.Value)
            {
                if (zone.EncampmentMode.Value)
                {
                    message.Append($"{kothGrid.DisplayName} on {planetName} Encampment Payout");
                }
                else
                {
                    message.Append($"{kothGrid.DisplayName} on {planetName} under attack");
                }
            }

            byte[] bytes = Encoding.ASCII.GetBytes(message.ToString());
            MyAPIGateway.Multiplayer.SendMessageToServer(8008, bytes);
            Network.Say(message.ToString());

            message.Clear();
            if (zone.AwardPointsAsCredits.Value)
            {
                message.Append($"{faction.Name} Scored {points} Points! ({points * zone.CreditsPerPoint.Value} credits)");
            }
            else
            {
                message.Append($"{faction.Name} Scored {points} Points!");
            }


            SaveData();

            //NEXUS: if nexus is initialized, broadcast the message to nexus (and all other sectors in that way)
            //NEXUS: KotH should work normally if nexus is not initialized
            if (nexusInit)
            {
                //NEXUS: sends the message this sector displays in the chat to all the other sectors
                byte[] nexMessage = Encoding.ASCII.GetBytes(message.ToString());
                Nexus.SendMessageToAllServers(nexMessage);

                //NEXUS: score is broadcasted to other sectors, this basically triggers the save not just on this sector but on all the others with the same score
                var serializedScore = MyAPIGateway.Utilities.SerializeToBinary <List <PlanetDescription> >(Planets);
                Nexus2.SendMessageToAllServers(serializedScore);
            }

            bytes = Encoding.ASCII.GetBytes(message.ToString());
            MyAPIGateway.Multiplayer.SendMessageToServer(8008, bytes);
            Network.Say(message.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Find the physical object of the specified name or partial name.
        /// </summary>
        /// <param name="itemName">The name of the physical object to find.</param>
        /// <param name="objectBuilder">The object builder of the physical object, ready for use.</param>
        /// <param name="options">Returns a list of potential matches if there was more than one of the same or partial name.</param>
        /// <returns>Returns true if a single exact match was found.</returns>

        public static bool FindPhysicalParts(string itemName, out MyObjectBuilder_Base objectBuilder, out Dictionary <string, MyDefinitionBase> options)
        {
            BuildComponentLists();
            itemName = itemName.Trim();
            var itemNames = itemName.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            // prefix the search term with 'ore' to find this ore name.
            if (itemNames.Length > 1 && itemNames[0].Equals("ore", StringComparison.InvariantCultureIgnoreCase))
            {
                var findName = itemName.Substring(4).Trim();

                var exactMatchOres = _oreList.Where(ore => ore.Value.Id.SubtypeName.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                if (exactMatchOres.Count == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ore()
                    {
                        SubtypeName = exactMatchOres.First().Value.Id.SubtypeName
                    };
                    options = new Dictionary <string, MyDefinitionBase>();
                    return(true);
                }
                if (exactMatchOres.Count > 1)
                {
                    objectBuilder = null;
                    options       = exactMatchOres;
                    return(false);
                }

                var partialMatchOres = _oreList.Where(ore => ore.Value.Id.SubtypeName.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                if (partialMatchOres.Count == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ore()
                    {
                        SubtypeName = partialMatchOres.First().Value.Id.SubtypeName
                    };
                    options = new Dictionary <string, MyDefinitionBase>();
                    return(true);
                }
                if (partialMatchOres.Count > 1)
                {
                    objectBuilder = null;
                    options       = partialMatchOres;
                    return(false);
                }

                objectBuilder = null;
                options       = new Dictionary <string, MyDefinitionBase>();
                return(false);
            }

            // prefix the search term with 'ingot' to find this ingot name.
            if (itemNames.Length > 1 && itemNames[0].Equals("ingot", StringComparison.InvariantCultureIgnoreCase))
            {
                var findName = itemName.Substring(6).Trim();

                var exactMatchIngots = _ingotList.Where(ingot => ingot.Value.Id.SubtypeName.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                if (exactMatchIngots.Count == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ingot()
                    {
                        SubtypeName = exactMatchIngots.First().Value.Id.SubtypeName
                    };
                    options = new Dictionary <string, MyDefinitionBase>();
                    return(true);
                }
                if (exactMatchIngots.Count > 1)
                {
                    objectBuilder = null;
                    options       = exactMatchIngots;
                    return(false);
                }

                var partialMatchIngots = _ingotList.Where(ingot => ingot.Value.Id.SubtypeName.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                if (partialMatchIngots.Count == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ingot()
                    {
                        SubtypeName = partialMatchIngots.First().Value.Id.SubtypeName
                    };
                    options = new Dictionary <string, MyDefinitionBase>();
                    return(true);
                }
                if (partialMatchIngots.Count > 1)
                {
                    objectBuilder = null;
                    options       = partialMatchIngots;
                    return(false);
                }

                objectBuilder = null;
                options       = new Dictionary <string, MyDefinitionBase>();
                return(false);
            }

            // full name match.
            var res = _physicalItemNames.FirstOrDefault(s => s.Key != null && s.Key.Equals(itemName, StringComparison.InvariantCultureIgnoreCase));

            // need a good method for finding partial name matches.
            if (res.Key == null)
            {
                var matches = _physicalItemNames.Where(s => s.Key != null && s.Key.StartsWith(itemName, StringComparison.InvariantCultureIgnoreCase)).Distinct().ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (matches.Count == 1)
                {
                    res = matches.FirstOrDefault();
                }
                else
                {
                    matches = _physicalItemNames.Where(s => s.Key != null && s.Key.IndexOf(itemName, StringComparison.InvariantCultureIgnoreCase) >= 0).Distinct().ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                    if (matches.Count == 1)
                    {
                        res = matches.FirstOrDefault();
                    }
                    else if (matches.Count > 1)
                    {
                        objectBuilder = null;
                        options       = matches;
                        return(false);
                    }
                }
            }

            if (res.Key != null)
            {
                if (res.Value != null)
                {
                    objectBuilder = MyObjectBuilderSerializer.CreateNewObject(res.Value.Id.TypeId, res.Value.Id.SubtypeName);
                    options       = new Dictionary <string, MyDefinitionBase>();
                    return(true);
                }
            }

            objectBuilder = null;
            options       = new Dictionary <string, MyDefinitionBase>();
            return(false);
        }
        /// <summary>
        /// Find the physical object of the specified name or partial name.
        /// </summary>
        /// <param name="itemName">The name of the physical object to find.</param>
        /// <param name="objectBuilder">The object builder of the physical object, ready for use.</param>
        /// <param name="options">Returns a list of potential matches if there was more than one of the same or partial name.</param>
        /// <returns>Returns true if a single exact match was found.</returns>
        public static bool FindPhysicalParts(string[] _oreNames, string[] _ingotNames, string[] _physicalItemNames, MyPhysicalItemDefinition[] _physicalItems, string itemName, out MyObjectBuilder_Base objectBuilder, out string[] options)
        {
            var itemNames = itemName.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            // prefix the search term with 'ore' to find this ore name.
            if (itemNames.Length > 1 && itemNames[0].Equals("ore", StringComparison.InvariantCultureIgnoreCase))
            {
                var findName = itemName.Substring(4).Trim();

                var exactMatchOres = _oreNames.Where(ore => ore.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToArray();
                if (exactMatchOres.Length == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = exactMatchOres[0] };
                    options = new string[0];
                    return true;
                }
                else if (exactMatchOres.Length > 1)
                {
                    objectBuilder = null;
                    options = exactMatchOres;
                    return false;
                }

                var partialMatchOres = _oreNames.Where(ore => ore.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToArray();
                if (partialMatchOres.Length == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = partialMatchOres[0] };
                    options = new string[0];
                    return true;
                }
                else if (partialMatchOres.Length > 1)
                {
                    objectBuilder = null;
                    options = partialMatchOres;
                    return false;
                }

                objectBuilder = null;
                options = new string[0];
                return false;
            }

            // prefix the search term with 'ingot' to find this ingot name.
            if (itemNames.Length > 1 && itemNames[0].Equals("ingot", StringComparison.InvariantCultureIgnoreCase))
            {
                var findName = itemName.Substring(6).Trim();

                var exactMatchIngots = _ingotNames.Where(ingot => ingot.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToArray();
                if (exactMatchIngots.Length == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = exactMatchIngots[0] };
                    options = new string[0];
                    return true;
                }
                else if (exactMatchIngots.Length > 1)
                {
                    objectBuilder = null;
                    options = exactMatchIngots;
                    return false;
                }

                var partialMatchIngots = _ingotNames.Where(ingot => ingot.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToArray();
                if (partialMatchIngots.Length == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = partialMatchIngots[0] };
                    options = new string[0];
                    return true;
                }
                else if (partialMatchIngots.Length > 1)
                {
                    objectBuilder = null;
                    options = partialMatchIngots;
                    return false;
                }

                objectBuilder = null;
                options = new string[0];
                return false;
            }

            // full name match.
            var res = _physicalItemNames.FirstOrDefault(s => s != null && s.Equals(itemName, StringComparison.InvariantCultureIgnoreCase));

            // need a good method for finding partial name matches.
            if (res == null)
            {
                var matches = _physicalItemNames.Where(s => s != null && s.StartsWith(itemName, StringComparison.InvariantCultureIgnoreCase)).Distinct().ToArray();

                if (matches.Length == 1)
                {
                    res = matches.FirstOrDefault();
                }
                else
                {
                    matches = _physicalItemNames.Where(s => s != null && s.IndexOf(itemName, StringComparison.InvariantCultureIgnoreCase) >= 0).Distinct().ToArray();
                    if (matches.Length == 1)
                    {
                        res = matches.FirstOrDefault();
                    }
                    else if (matches.Length > 1)
                    {
                        objectBuilder = null;
                        options = matches;
                        return false;
                    }
                }
            }

            if (res != null)
            {
                var item = _physicalItems[Array.IndexOf(_physicalItemNames, res)];
                if (item != null)
                {
                    objectBuilder = MyObjectBuilderSerializer.CreateNewObject(item.Id.TypeId, item.Id.SubtypeName);
                    options = new string[0];
                    return true;
                }
            }

            objectBuilder = null;
            options = new string[0];
            return false;
        }
Exemplo n.º 6
0
        private void UnmountInternal(float unmountAmount, MyConstructionStockpile outputStockpile = null, bool damageItems = false)
        {
            // We don't have to update functional state in this function, because it is done in the caller functions.
            // If you start using this function anywhere else, don't forget to update functional state yourself!

            float topIntegrity = GetTopComponentIntegrity();
            int   groupIndex   = (int)m_topGroupIndex;
            int   compIndex    = (int)m_topComponentIndex;

            // Continue removing components, until the to be removed component's health is larger than unmountAmount
            MyObjectBuilder_Component componentBuilder = null;
            MyObjectBuilder_Ingot     scrapBuilder     = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ingot>("Scrap");

            while (unmountAmount >= topIntegrity)
            {
                m_integrity   -= topIntegrity;
                unmountAmount -= topIntegrity;

                // In creative mode, the outputInventory should normally be null.
                // However, if we load the game from the realistic mode, it would not be necessarilly null.
                if (outputStockpile != null && MySession.Static.SurvivalMode)
                {
                    bool doDamage = damageItems && MyFakes.ENABLE_DAMAGED_COMPONENTS;
                    if (!damageItems || (doDamage && MyRandom.Instance.NextFloat() <= m_blockDefinition.Components[groupIndex].Definition.DropProbability))
                    {
                        componentBuilder             = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Component>();
                        componentBuilder.SubtypeName = m_blockDefinition.Components[groupIndex].Definition.Id.SubtypeName;
                        if (doDamage)
                        {
                            componentBuilder.Flags |= MyItemFlags.Damaged;
                        }
                        if (!outputStockpile.AddItems(1, componentBuilder))
                        {
                            // TODO: Throw the items into space (although this branch should probably not happen)
                        }
                    }

                    MyComponentDefinition destroyedComponentDefinition = m_blockDefinition.Components[groupIndex].Definition;
                    if (MyFakes.ENABLE_SCRAP && damageItems && (MyRandom.Instance.NextFloat() < destroyedComponentDefinition.DropProbability))
                    {
                        outputStockpile.AddItems((int)(0.8f * destroyedComponentDefinition.Mass), scrapBuilder);
                    }
                }

                compIndex--;
                if (compIndex < 0)
                {
                    groupIndex--;
                    if (groupIndex < 0)
                    {
                        SetTopIndex(0, 0);
                        m_integrity = 0.0f;
                        return;
                    }
                    else
                    {
                        compIndex = m_blockDefinition.Components[groupIndex].Count - 1;
                    }
                }


                topIntegrity = m_blockDefinition.Components[groupIndex].Definition.MaxIntegrity;
                SetTopIndex(groupIndex, compIndex);
            }

            // Damage the remaining component
            m_integrity  -= unmountAmount;
            topIntegrity -= unmountAmount;

            if (topIntegrity < MOUNT_THRESHOLD)
            {
                m_integrity += MOUNT_THRESHOLD - topIntegrity;
                topIntegrity = MOUNT_THRESHOLD;
            }

            Debug.Assert(m_integrity >= MOUNT_THRESHOLD, "Integrity inconsistent after a dismount of component stack");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Find the physical object of the specified name or partial name.
        /// </summary>
        /// <param name="itemName">The name of the physical object to find.</param>
        /// <param name="objectBuilder">The object builder of the physical object, ready for use.</param>
        /// <param name="options">Returns a list of potential matches if there was more than one of the same or partial name.</param>
        /// <returns>Returns true if a single exact match was found.</returns>
        public static bool FindPhysicalParts(string itemName, out MyObjectBuilder_Base objectBuilder, out Dictionary<string, MyPhysicalItemDefinition> options)
        {
            BuildComponentLists();
            itemName = itemName.Trim();
            var itemNames = itemName.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            // prefix the search term with 'ore' to find this ore name.
            if (itemNames.Length > 1 && itemNames[0].Equals("ore", StringComparison.InvariantCultureIgnoreCase))
            {
                var findName = itemName.Substring(4).Trim();

                var exactMatchOres = _oreList.Where(ore => ore.Value.Id.SubtypeName.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                if (exactMatchOres.Count == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = exactMatchOres.First().Value.Id.SubtypeName };
                    options = new Dictionary<string, MyPhysicalItemDefinition>();
                    return true;
                }
                if (exactMatchOres.Count > 1)
                {
                    objectBuilder = null;
                    options = exactMatchOres;
                    return false;
                }

                var partialMatchOres = _oreList.Where(ore => ore.Value.Id.SubtypeName.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                if (partialMatchOres.Count == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = partialMatchOres.First().Value.Id.SubtypeName };
                    options = new Dictionary<string, MyPhysicalItemDefinition>();
                    return true;
                }
                if (partialMatchOres.Count > 1)
                {
                    objectBuilder = null;
                    options = partialMatchOres;
                    return false;
                }

                objectBuilder = null;
                options = new Dictionary<string, MyPhysicalItemDefinition>();
                return false;
            }

            // prefix the search term with 'ingot' to find this ingot name.
            if (itemNames.Length > 1 && itemNames[0].Equals("ingot", StringComparison.InvariantCultureIgnoreCase))
            {
                var findName = itemName.Substring(6).Trim();

                var exactMatchIngots = _ingotList.Where(ingot => ingot.Value.Id.SubtypeName.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                if (exactMatchIngots.Count == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = exactMatchIngots.First().Value.Id.SubtypeName };
                    options = new Dictionary<string, MyPhysicalItemDefinition>();
                    return true;
                }
                if (exactMatchIngots.Count > 1)
                {
                    objectBuilder = null;
                    options = exactMatchIngots;
                    return false;
                }

                var partialMatchIngots = _ingotList.Where(ingot => ingot.Value.Id.SubtypeName.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                if (partialMatchIngots.Count == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = partialMatchIngots.First().Value.Id.SubtypeName };
                    options = new Dictionary<string, MyPhysicalItemDefinition>();
                    return true;
                }
                if (partialMatchIngots.Count > 1)
                {
                    objectBuilder = null;
                    options = partialMatchIngots;
                    return false;
                }

                objectBuilder = null;
                options = new Dictionary<string, MyPhysicalItemDefinition>();
                return false;
            }

            // full name match.
            var res = _physicalItemNames.FirstOrDefault(s => s.Key != null && s.Key.Equals(itemName, StringComparison.InvariantCultureIgnoreCase));

            // need a good method for finding partial name matches.
            if (res.Key == null)
            {
                var matches = _physicalItemNames.Where(s => s.Key != null && s.Key.StartsWith(itemName, StringComparison.InvariantCultureIgnoreCase)).Distinct().ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (matches.Count == 1)
                {
                    res = matches.FirstOrDefault();
                }
                else
                {
                    matches = _physicalItemNames.Where(s => s.Key != null && s.Key.IndexOf(itemName, StringComparison.InvariantCultureIgnoreCase) >= 0).Distinct().ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                    if (matches.Count == 1)
                    {
                        res = matches.FirstOrDefault();
                    }
                    else if (matches.Count > 1)
                    {
                        objectBuilder = null;
                        options = matches;
                        return false;
                    }
                }
            }

            if (res.Key != null)
            {
                if (res.Value != null)
                {
                    objectBuilder = MyObjectBuilderSerializer.CreateNewObject(res.Value.Id.TypeId, res.Value.Id.SubtypeName);
                    options = new Dictionary<string, MyPhysicalItemDefinition>();
                    return true;
                }
            }

            objectBuilder = null;
            options = new Dictionary<string, MyPhysicalItemDefinition>();
            return false;
        }
Exemplo n.º 8
0
        public static int getitemidfromitemname(string itemname,ulong userID, ShopItem item)
        {
            var temp = new MyObjectBuilder_PhysicalObject();

                if (item != null)
                {
                    
                    if (item.ItemName == itemname)
                    {
                        temp = new MyObjectBuilder_Ingot() { SubtypeName = itemname };
                        ChatUtil.SendPrivateChat(userID, Convert.ToString(temp.GetHashCode()));
                        return  temp.GetHashCode();
                        
                    }
                    else
                    {
                        ChatUtil.SendPrivateChat(userID, "Please enter a valid item name.");
                    }
                }
             
            
            return 0;
        }