コード例 #1
0
        public static Boolean DoesGridHaveCaptureBlock(MyCubeGrid grid, KothConfig koth)
        {
            foreach (MyCubeBlock block in grid.GetFatBlocks())
            {
                if (block != null && block.BlockDefinition != null)
                {
                    Log.Info(block.BlockDefinition.Id.TypeId + " " + block.BlockDefinition.Id.SubtypeName);
                }
                else
                {
                    Log.Info("Null id for capture block");
                }

                if (block.OwnerId > 0 && block.BlockDefinition.Id.TypeId.ToString().Replace("MyObjectBuilder_", "").Equals(koth.captureBlockType) && block.BlockDefinition.Id.SubtypeName.Equals(koth.captureBlockSubtype))
                {
                    if (block.IsFunctional && block.IsWorking)
                    {
                        if (block is Sandbox.ModAPI.IMyFunctionalBlock bl)
                        {
                            bl.Enabled = true;
                        }

                        if (block is Sandbox.ModAPI.IMyBeacon beacon)
                        {
                            beacon.Radius = koth.captureBlockBroadcastDistance;
                        }

                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #2
0
        public static MyCubeGrid GetLootboxGrid(Vector3 position, KothConfig config)
        {
            if (MyAPIGateway.Entities.GetEntityById(config.LootboxGridEntityId) != null)
            {
                if (MyAPIGateway.Entities.GetEntityById(config.LootboxGridEntityId) is MyCubeGrid grid)
                {
                    return(grid);
                }
            }
            BoundingSphereD sphere = new BoundingSphereD(position, config.CaptureRadiusInMetre + 5000);

            foreach (MyCubeGrid grid in MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).OfType <MyCubeGrid>())
            {
                IMyFaction fac = FacUtils.GetPlayersFaction(FacUtils.GetOwner(grid));
                if (fac != null && fac.Tag.Equals(config.KothBuildingOwner))
                {
                    Sandbox.ModAPI.IMyGridTerminalSystem gridTerminalSys = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);

                    Sandbox.ModAPI.IMyTerminalBlock block = gridTerminalSys.GetBlockWithName(config.LootBoxTerminalName);
                    if (block != null)
                    {
                        return(grid);
                    }
                }
            }
            return(null);
        }
コード例 #3
0
        public static KothConfig SaveConfig(String name, KothConfig config)
        {
            FileUtils utils = new FileUtils();

            utils.WriteToXmlFile <KothConfig>(path + "//CrunchKOTH" + name + ".xml", config);

            return(config);
        }
コード例 #4
0
        public static void LoadConfig()
        {
            if (!Directory.Exists(path + "//CrunchKOTH"))
            {
                Directory.CreateDirectory(path + "//CrunchKOTH//");
            }
            FileUtils utils = new FileUtils();

            foreach (String s in Directory.GetFiles(path + "//CrunchKOTH//"))
            {
                KothConfig koth = utils.ReadFromXmlFile <KothConfig>(s);

                KOTHs.Add(koth);
            }
            Log.Info(KOTHs.Count);
        }
コード例 #5
0
 public static void SpawnCores(MyCubeGrid grid, KothConfig config)
 {
     if (grid != null)
     {
         Sandbox.ModAPI.IMyGridTerminalSystem gridTerminalSys = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);
         MyDefinitionId rewardItem             = getRewardItem(config);
         Sandbox.ModAPI.IMyTerminalBlock block = gridTerminalSys.GetBlockWithName(config.LootBoxTerminalName);
         if (block != null && rewardItem != null)
         {
             Log.Info("Should spawn item");
             MyItemType itemType = new MyInventoryItemFilter(rewardItem.TypeId + "/" + rewardItem.SubtypeName).ItemType;
             block.GetInventory().AddItems((MyFixedPoint)config.RewardAmount, (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(rewardItem));
         }
         else
         {
             Log.Info("Cant spawn item");
         }
         return;
     }
 }
コード例 #6
0
 public static Boolean IsContested(IMyFaction fac, KothConfig koth, string capturingNation)
 {
     if (GetNationTag(fac) != null)
     {
         if (capturingNation.Equals(GetNationTag(fac)) || capturingNation.Equals(""))
         {
             capturingNation = GetNationTag(fac);
         }
         else
         {
             return(true);
         }
     }
     else
     {
         //unaff cant capture
         return(true);
     }
     return(false);
 }
コード例 #7
0
        private void SetupConfig()
        {
            path = this.StoragePath;
            KothConfig config = new KothConfig();
            FileUtils  utils  = new FileUtils();

            if (!Directory.Exists(StoragePath + "//CrunchKOTH"))
            {
                Directory.CreateDirectory(StoragePath + "//CrunchKOTH");
            }
            if (File.Exists(this.StoragePath + "//CrunchKOTH//example.xml"))
            {
                config = utils.ReadFromXmlFile <KothConfig>(this.StoragePath + "//CrunchKOTH//example.xml");
                utils.WriteToXmlFile <KothConfig>(this.StoragePath + "//CrunchKOTH//example.xml", config, false);
            }
            else
            {
                config = new KothConfig();
                utils.WriteToXmlFile <KothConfig>(this.StoragePath + "//CrunchKOTH//example.xml", config, false);
            }
        }
コード例 #8
0
 public static MyDefinitionId getRewardItem(KothConfig config)
 {
     MyDefinitionId.TryParse("MyObjectBuilder_" + config.RewardTypeId, config.RewardSubTypeId, out MyDefinitionId id);
     return(id);
 }