コード例 #1
0
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData userData)
        {
            Players.Player requestedBy = userData.requestedBy;
            Vector3Int     position    = userData.VoxelToChange;
            Vector3Int     spawn       = TerrainGenerator.GetSpawnLocation();
            int            ox          = position.x - spawn.x;
            int            oz          = position.z - spawn.z;

            if (((ox >= 0 && ox <= SpawnProtectionRangeXPos) || (ox < 0 && ox >= -SpawnProtectionRangeXNeg)) && ((oz >= 0 && oz <= SpawnProtectionRangeZPos) || (oz < 0 && oz >= -SpawnProtectionRangeZNeg)))
            {
                if (!PermissionsManager.HasPermission(requestedBy, PERMISSION_SPAWN_CHANGE))
                {
                    Chat.Send(requestedBy, "<color=red>You don't have permission to change the spawn area!</color>");
                    // TODO add counter and report to admins or auto-kick
                    return(false);
                }
            }
            else
            {
                Banner homeBanner = BannerTracker.Get(requestedBy);
                if (homeBanner != null)
                {
                    Vector3Int homeBannerLocation = homeBanner.KeyLocation;
                    if (System.Math.Abs(homeBannerLocation.x - position.x) <= BannerProtectionRangeX && System.Math.Abs(homeBannerLocation.z - position.z) <= BannerProtectionRangeZ)
                    {
                        return(true);
                    }
                }
                int checkRangeX = BannerProtectionRangeX;
                int checkRangeZ = BannerProtectionRangeZ;
                if (userData.typeToBuild == BlockTypes.Builtin.BuiltinBlocks.Banner)
                {
                    checkRangeX *= 2;
                    checkRangeZ *= 2;
                }
                foreach (Banner b in BannerTracker.GetBanners())
                {
                    Vector3Int bannerLocation = b.KeyLocation;
                    if (System.Math.Abs(bannerLocation.x - position.x) <= checkRangeX && System.Math.Abs(bannerLocation.z - position.z) <= checkRangeZ)
                    {
                        if (b.Owner != requestedBy && !PermissionsManager.HasPermission(requestedBy, PERMISSION_BANNER_PREFIX + b.Owner.ID.steamID))
                        {
                            Chat.Send(requestedBy, "<color=red>You don't have permission to change this area!</color>");
                            return(false);
                        }
                        break;
                    }
                }
            }
            return(true);
        }
コード例 #2
0
 private ITrackableBlock GetScoutBanner()
 {
     return(BannerTracker.Get(GetColonyOwner()));
 }
コード例 #3
0
        public override void OnNPCAtJob(ref NPCBase.NPCState state)
        {
            state.SetCooldown(2);

            getScoutChunkManager().RemoveDoublePositions();

            if (Activity == ScoutActivity.Scouting)
            {
                getScoutChunkManager().RegisterPositionScouted(currentDestination.ToChunk());
            }

            if (Activity == ScoutActivity.Walking)
            {
                SetActivity(ScoutActivity.Scouting);
                Vector3Int positionToScout = NPC.Position;
                getScoutChunkManager().RegisterPositionScouted(positionToScout);
                state.SetCooldown(2);
            }

            //WriteLog("OnNPCAtJob");

            if (!StockedUp)
            {
                StockedUp = true;
                SetActivity(ScoutActivity.Scouting);
            }

            var commenceBaseBuild = false;

            if (!IsOutsideMinimumRange(NPC.Position, BannerTracker.Get(GetColonyOwner())))
            {
                return;
            }

            //Check the surrounding area and calculate its average flatness, to determine if it's suitable for a base
            var suitability = calculateAreaSuitability();

            switch (suitability)
            {
            case Suitability.None:
                break;

            case Suitability.Bad:
                break;

            case Suitability.Decent:
                break;

            case Suitability.Good:
                WriteLog("Suitable location found for new base.");
                commenceBaseBuild = true;
                break;

            case Suitability.Excellent:
                break;

            default:
                Log.WriteWarning("Invalid Area Suitability received: {0}", suitability);
                break;
            }

            //Only actually build base if the area is suitable enough
            if (commenceBaseBuild)
            {
                PrepareBase();
            }
        }