コード例 #1
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);
        }
コード例 #2
0
        public override void Update()
        {
            try
            {
                if (state1 != TorchSessionState.Loaded)
                {
                    return;
                }
                foreach (KothConfig config in KOTHs)
                {
                    if (!config.enabled)
                    {
                        continue;
                    }

                    bool    contested             = false;
                    Boolean hasActiveCaptureBlock = false;
                    // Log.Info("We capping?");
                    Vector3         position = new Vector3(config.x, config.y, config.z);
                    BoundingSphereD sphere   = new BoundingSphereD(position, config.CaptureRadiusInMetre);

                    if (DateTime.Now >= config.nextCaptureInterval)
                    {
                        //setup a time check for capture time
                        String capturingNation = "";

                        Boolean locked = false;

                        Log.Info("Yeah we capping");
                        //check grids first
                        List <MyCubeGrid> acmeGrids    = new List <MyCubeGrid>();
                        List <MyCubeGrid> NotAcmeGrids = new List <MyCubeGrid>();


                        int entitiesInCapPoint = 0;
                        foreach (MyCubeGrid grid in MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).OfType <MyCubeGrid>())
                        {
                            entitiesInCapPoint++;
                            if (!contested)
                            {
                                IMyFaction fac = FacUtils.GetPlayersFaction(FacUtils.GetOwner(grid));
                                if (fac != null && !fac.Tag.Equals(config.KothBuildingOwner))
                                {
                                    if (IsContested(fac, config, capturingNation))
                                    {
                                        contested = true;
                                        break;
                                    }
                                    else
                                    {
                                        capturingNation = GetNationTag(fac);
                                    }
                                }
                                hasActiveCaptureBlock = DoesGridHaveCaptureBlock(grid, config);
                            }
                        }

                        if (!contested)
                        {
                            //now check characters
                            foreach (MyCharacter character in MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).OfType <MyCharacter>())
                            {
                                entitiesInCapPoint++;
                                IMyFaction fac = FacUtils.GetPlayersFaction(character.GetPlayerIdentityId());
                                if (fac != null)
                                {
                                    float distance = Vector3.Distance(position, character.PositionComp.GetPosition());
                                    if (IsContested(fac, config, capturingNation))
                                    {
                                        contested = true;
                                        break;
                                    }
                                    else
                                    {
                                        capturingNation = GetNationTag(fac);
                                    }
                                }
                                else
                                {
                                    contested = true;
                                }
                            }
                        }

                        if (entitiesInCapPoint == 0 && config.IsDenialPoint)
                        {
                            if (denials.TryGetValue(config.DeniedKoth, out DenialPoint den))
                            {
                                den.RemoveCap(config.KothName);
                                SaveConfig(config.KothName, config);
                            }
                        }
                        if (!contested && hasActiveCaptureBlock && !config.CaptureStarted && !capturingNation.Equals(""))
                        {
                            config.CaptureStarted       = true;
                            config.nextCaptureAvailable = DateTime.Now.AddMinutes(config.MinutesBeforeCaptureStarts);
                            Log.Info("Can cap in 10 minutes");
                            config.capturingNation = capturingNation;
                            SendChatMessage("Can cap in however many minutes");
                        }
                        else
                        {
                            if (!contested && !capturingNation.Equals(""))
                            {
                                Log.Info("Got to the capping check and not contested");
                                if (DateTime.Now >= config.nextCaptureAvailable && config.CaptureStarted)
                                {
                                    if (config.capturingNation.Equals(capturingNation) && !config.capturingNation.Equals(""))
                                    {
                                        Log.Info("Is the same nation as whats capping");
                                        if (!hasActiveCaptureBlock)
                                        {
                                            Log.Info("Locking because no active cap block");
                                            config.capturingNation      = config.owner;
                                            config.nextCaptureAvailable = DateTime.Now.AddHours(1);
                                            //broadcast that its locked
                                            config.capturingNation = "";
                                            config.amountCaptured  = 0;
                                            SendChatMessage("Locked because capture blocks are dead");
                                        }
                                        else
                                        {
                                            config.nextCaptureInterval = DateTime.Now.AddSeconds(config.SecondsBetweenCaptureCheck);
                                            if (config.IsDenialPoint)
                                            {
                                                if (denials.TryGetValue(config.DeniedKoth, out DenialPoint den))
                                                {
                                                    den.AddCap(config.KothName);
                                                }
                                                else
                                                {
                                                    DenialPoint denial = new DenialPoint();
                                                    denial.AddCap(config.KothName);
                                                    denials.Add(config.DeniedKoth, denial);
                                                }
                                                //exit this one because its a denial point and continue to the next config
                                                continue;
                                            }
                                            config.amountCaptured += config.PointsPerCap;

                                            if (config.amountCaptured >= config.PointsToCap)
                                            {
                                                //lock
                                                Log.Info("Locking because points went over the threshold");
                                                locked = true;
                                                config.nextCaptureInterval = DateTime.Now.AddHours(config.hoursToLockAfterCap);
                                                config.capturingNation     = capturingNation;
                                                config.owner          = capturingNation;
                                                config.amountCaptured = 0;
                                                SendChatMessage(config.captureMessage.Replace("%NATION%", config.owner));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Log.Info("Locking because the capturing nation changed");
                                        config.capturingNation      = config.owner;
                                        config.nextCaptureAvailable = DateTime.Now.AddHours(1);
                                        //broadcast that its locked
                                        SendChatMessage("Locked because capturing nation has changed.");
                                        config.amountCaptured = 0;
                                    }
                                }
                                else
                                {
                                    SendChatMessage("Waiting to cap");
                                    Log.Info("Waiting to cap");
                                }
                            }
                            else
                            {
                                Log.Info("Its contested or the fuckers trying to cap have no nation");
                                //send contested message
                                SendChatMessage("Contested or unaff trying to cap");
                            }
                        }

                        if (!locked)
                        {
                            config.nextCaptureInterval = DateTime.Now.AddSeconds(config.SecondsBetweenCaptureCheck);
                        }
                        SaveConfig(config.KothName, config);
                    }


                    //if its not locked, check again for capture in a minute



                    if (DateTime.Now > config.nextCoreSpawn && !config.IsDenialPoint)
                    {
                        MyCubeGrid lootgrid = GetLootboxGrid(position, config);
                        //spawn the cores
                        foreach (MyCubeGrid grid in MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).OfType <MyCubeGrid>())
                        {
                            IMyFaction fac = FacUtils.GetPlayersFaction(FacUtils.GetOwner(grid));
                            if (fac != null)
                            {
                                if (GetNationTag(fac) != null && GetNationTag(fac).Equals(config.owner))
                                {
                                    hasActiveCaptureBlock = DoesGridHaveCaptureBlock(grid, config);
                                }
                            }
                        }
                        if (denials.TryGetValue(config.KothName, out DenialPoint den))
                        {
                            if (den.IsDenied())
                            {
                                SendChatMessage("Denied point, no core spawn");
                            }
                            continue;
                        }
                        if (!config.owner.Equals("NOBODY"))
                        {
                            if (hasActiveCaptureBlock)
                            {
                                Log.Info("The owner has an active block so reducing time between spawning");
                                SpawnCores(lootgrid, config);
                                config.nextCoreSpawn = DateTime.Now.AddSeconds(config.SecondsBetweenCoreSpawn / 2);
                                SendChatMessage("Capture block and owned, half spawn time");
                            }
                            else
                            {
                                Log.Info("No block");
                                SpawnCores(lootgrid, config);
                                SendChatMessage("No capture block and owned, normal spawn time");
                                config.nextCoreSpawn = DateTime.Now.AddSeconds(config.SecondsBetweenCoreSpawn);
                            }
                        }
                        else
                        {
                            Log.Info("No owner, normal spawn time");
                            SpawnCores(lootgrid, config);
                            config.nextCoreSpawn = DateTime.Now.AddSeconds(config.SecondsBetweenCoreSpawn);
                            SendChatMessage("No owner, normal spawn time");
                        }
                    }

                    contested             = false;
                    hasActiveCaptureBlock = false;
                }
            }
            catch (Exception ex)
            {
                Log.Error("koth error " + ex.ToString());
            }
        }