public static Banner GetClosestBanner(Players.Player p, Vector3Int currentPos) { Banner closest = null; float distance = float.MaxValue; var banners = BannerTracker.GetBanners(); for (int i = 0; i < banners.Count; i++) { var banner = banners.GetValueAtIndex(i); if (banner.Owner == p) { var bannerDistance = Vector3.Distance(currentPos.Vector, banner.KeyLocation.Vector); if (closest == null) { closest = banner; distance = bannerDistance; } else { if (bannerDistance < distance) { closest = banner; distance = bannerDistance; } } } } return(closest); }
public void Update() { if (!World.Initialized || AIManager.IsBusy()) { return; } WorldSettings wsettings = ServerManager.WorldSettings; bool toSpawnZombies = wsettings.ZombiesEnabled && (TimeCycle.ShouldSpawnMonsters || wsettings.MonstersDayTime); int monsterMultiplier = wsettings.MonstersDoubled ? 2 : 1; double timeSinceStart = Pipliz.Time.SecondsSinceStartDouble; var banners = BannerTracker.GetBanners(); for (int i = 0; i < banners.Count; i++) { Banner banner = banners.GetValueAtIndex(i); if (banner == null || !banner.KeyLocation.IsValid) { continue; } Colony colony = Colony.Get(banner.Owner); if (toSpawnZombies) { float zombiesMax = GetMaxZombieCount(colony.FollowerCount) * monsterMultiplier; if (zombiesMax > 0f) { if (MonsterTracker.MonstersPerPlayer(banner.Owner) < zombiesMax) { if (colony.InSiegeMode) { if (timeSinceStart - colony.LastSiegeModeSpawn < siegeModeCooldown) { continue; } else { colony.LastSiegeModeSpawn = timeSinceStart; } } SpawnZombie(colony, banner, GetMosterType(colony.FollowerCount, zombiesMax)); } } else { colony.OnZombieSpawn(true); } } else { colony.OnZombieSpawn(true); } } }
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); }
protected override bool RunCommand(Players.Player ply, string[] args, NetworkID target) { if (PermissionsManager.CheckAndWarnPermission(ply, "locate")) { var player = Players.GetPlayer(target); var banner = (from b in BannerTracker.GetBanners() where b.Owner == player select b).FirstOrDefault(); Chat.sendSilent(ply, banner != null ? $"{player.Name} has a banner at x:{banner.KeyLocation.x} y:{banner.KeyLocation.y} z:{banner.KeyLocation.z}" : $"{player.Name} doesn't have a banner", Chat.ChatColour.magenta); } return(true); }
public static MonsterSpawner.ESpawnResult TryGetSpawnLocation(Banner primaryBanner, float maxSpawnWalkDistance, out Vector3Int positionFinal) { Vector3Int bannerPos = primaryBanner.KeyLocation; var bannerList = BannerTracker.GetBanners(); int safeRadius = primaryBanner.SafeRadius; int spawnRadius = Pipliz.Math.RoundToInt(Pipliz.Math.Min(maxSpawnWalkDistance, primaryBanner.MaxSpawnRadius)); positionFinal = Vector3Int.invalidPos; for (int spawnTry = 0; spawnTry < MAX_TRIES; spawnTry++) { Vector3Int possiblePosition; Vector3Int dif; while (true) { possiblePosition.x = bannerPos.x + Pipliz.Random.Next(-spawnRadius, spawnRadius); possiblePosition.z = bannerPos.z + Pipliz.Random.Next(-spawnRadius, spawnRadius); possiblePosition.y = Pipliz.Math.RoundToInt(TerrainGenerator.UsedGenerator.GetHeight(possiblePosition.x, possiblePosition.z)); dif = bannerPos - possiblePosition; if (dif.MaxPartAbs > safeRadius && Pipliz.Math.Abs(dif.x) + Pipliz.Math.Abs(dif.z) < spawnRadius) { break; } } for (int idxBanner = 0; idxBanner < bannerList.Count; idxBanner++) { var otherBanner = bannerList.GetValueAtIndex(idxBanner); Colony otherColony = Colony.Get(otherBanner.Owner); if (otherColony.FollowerCount > 0 && (otherBanner.KeyLocation - possiblePosition).MaxPartAbs <= otherBanner.SafeRadius) { goto NEXT_TRY; } } if (!AIManager.Loaded(possiblePosition)) { return(MonsterSpawner.ESpawnResult.NotLoaded); } for (int idxOffset = 0; idxOffset < offsets.Length; idxOffset++) { Vector3Int positionAITest = possiblePosition.Add(0, offsets[idxOffset], 0); if (AIManager.CanStandAt(positionAITest)) { positionFinal = positionAITest; return(MonsterSpawner.ESpawnResult.Success); } } NEXT_TRY: continue; } return(MonsterSpawner.ESpawnResult.Fail); }
public static void EvaluateBanners() { if (!GameLoader.WorldLoaded) { return; } _bannerCounts.Clear(); var banners = BannerTracker.GetBanners(); if (banners != null) { for (int i = 0; i < banners.Count; i++) { var banner = banners.GetValueAtIndex(i); if (banner != null) { if (!_bannerCounts.ContainsKey(banner.Owner)) { _bannerCounts.Add(banner.Owner, 1); } else { _bannerCounts[banner.Owner]++; } } } } foreach (var p in _bannerCounts) { var ps = PlayerState.GetPlayerState(p.Key); if (ps == null) { continue; } var numberOfBanners = p.Key.GetTempValues(true).GetOrDefault(PandaResearch.GetLevelKey(PandaResearch.Settlement), 0) + 1; var inv = Inventory.GetInventory(p.Key); var sockBanner = Stockpile.GetStockPile(p.Key).AmountContained(BuiltinBlocks.Banner); var inventoryBanners = 0; if (inv != null) { foreach (var item in inv.Items) { if (item.Type == BuiltinBlocks.Banner) { inventoryBanners = item.Amount; } } } var totalBanners = p.Value + sockBanner + inventoryBanners; #if Debug PandaLogger.Log($"Number of research banners: {numberOfBanners}"); PandaLogger.Log($"Number of banners: {p.Value}"); PandaLogger.Log($"Number of stockpile banners: {sockBanner}"); PandaLogger.Log($"Number of Inventory banners: {inventoryBanners}"); PandaLogger.Log($"Total banners: {totalBanners}"); PandaLogger.Log($"Add Banner: {totalBanners < numberOfBanners}"); #endif if (totalBanners < numberOfBanners) { if (!Inventory.GetInventory(p.Key).TryAdd(BuiltinBlocks.Banner)) { Stockpile.GetStockPile(p.Key).Add(BuiltinBlocks.Banner); } } } }