Пример #1
0
 public static void OnPlayerRespawn(Players.Player p)
 {
     if (p.GetTempValues(true).GetOrDefault(PandaResearch.GetResearchKey(PandaResearch.Knights), 0f) == 1f)
     {
         GivePlayerPatrolTool(p);
     }
 }
Пример #2
0
        public static void UpdateFoodUse(ColonyState state)
        {
            if (ServerManager.TerrainGenerator != null &&
                AIManager.NPCPathFinder != null)
            {
                var food = _baseFoodPerHour;

                if (state.Difficulty != GameDifficulty.Normal && state.ColonyRef.FollowerCount > 10)
                {
                    var multiplier = .7 / state.ColonyRef.FollowerCount -
                                     state.ColonyRef.TemporaryData.GetAsOrDefault(PandaResearch.GetResearchKey(PandaResearch.ReducedWaste), 0f);

                    food += (float)(_baseFoodPerHour * multiplier);
                    food *= state.Difficulty.FoodMultiplier;
                }

                if (state.ColonyRef.InSiegeMode)
                {
                    food = food * ServerManager.ServerSettings.NPCs.FoodUseMultiplierSiegeMode;
                }

                if (food < _baseFoodPerHour)
                {
                    food = _baseFoodPerHour;
                }

                state.ColonyRef.FoodUsePerHour = food;
                state.ColonyRef.SendCommonData();
            }
        }
        public static void ApplyJobResearch(this IJob job)
        {
            if (job == null || !job.IsValid)
            {
                return;
            }

            job.Owner.TemporaryData.TryGetAs(PandaResearch.GetResearchKey(JobResearch.MasterOfAll), out float masterOfAll);

            if (job.TryGetNPCGuardSettings(out var guardSettings) && job.TryGetNPCGuardDefaultSettings(out var defaultGuardSettings))
            {
                var key = guardSettings.NPCTypeKey.Replace("day", "").Replace("night", "");
                job.Owner.TemporaryData.TryGetAs(PandaResearch.GetResearchKey(key), out float cooldownReduction);
                var total = masterOfAll + cooldownReduction;

                if (total != 0)
                {
                    guardSettings.CooldownShot = defaultGuardSettings.CooldownShot - defaultGuardSettings.CooldownShot * total;
                }
            }
Пример #4
0
        public static bool EvaluateSettlers(Players.Player p)
        {
            var update = false;

            if (p.IsConnected)
            {
                var colony = Colony.Get(p);
                var state  = PlayerState.GetPlayerState(p);

                if (state.NextGenTime == 0)
                {
                    state.NextGenTime = Time.SecondsSinceStartDouble +
                                        Random.Next(8,
                                                    16 - Pipliz.Math.RoundToInt(p.GetTempValues(true)
                                                                                .GetOrDefault(PandaResearch.GetResearchKey(PandaResearch.TimeBetween),
                                                                                              0f))) * TimeCycle
                                        .SecondsPerHour;
                }

                if (Time.SecondsSinceStartDouble > state.NextGenTime && colony.FollowerCount >= MAX_BUYABLE)
                {
                    var chance =
                        p.GetTempValues(true)
                        .GetOrDefault(PandaResearch.GetResearchKey(PandaResearch.SettlerChance), 0f) +
                        state.Difficulty.AdditionalChance;

                    chance += SettlerEvaluation.SpawnChance(p, colony, state);

                    var rand = Random.NextFloat();

                    if (chance > rand)
                    {
                        var addCount = Math.Floor(state.MaxPerSpawn * chance);

                        // if we lost alot of colonists add extra to help build back up.
                        if (colony.FollowerCount < state.HighestColonistCount)
                        {
                            var diff = state.HighestColonistCount - colony.FollowerCount;
                            addCount += Math.Floor(diff * .25);
                        }

                        try
                        {
                            var skillChance = p.GetTempValues(true)
                                              .GetOrDefault(PandaResearch.GetResearchKey(PandaResearch.SkilledLaborer),
                                                            0f);

                            var numbSkilled = 0;

                            rand = Random.NextFloat();

                            try
                            {
                                if (skillChance > rand)
                                {
                                    numbSkilled =
                                        state.Rand.Next(1,
                                                        2 + Pipliz.Math.RoundToInt(p.GetTempValues(true)
                                                                                   .GetOrDefault(PandaResearch.GetResearchKey(PandaResearch.NumberSkilledLaborer),
                                                                                                 0f)));
                                }
                            }
                            catch (Exception ex)
                            {
                                PandaLogger.Log("NumberSkilledLaborer");
                                PandaLogger.LogError(ex);
                            }


                            if (addCount > 0)
                            {
                                if (addCount > 30)
                                {
                                    addCount = 30;
                                }

                                var reason = string.Format(SettlerReasoning.GetSettleReason(), addCount);

                                if (numbSkilled > 0)
                                {
                                    if (numbSkilled == 1)
                                    {
                                        reason += string.Format(" {0} of them is skilled!", numbSkilled);
                                    }
                                    else
                                    {
                                        reason += string.Format(" {0} of them are skilled!", numbSkilled);
                                    }
                                }

                                PandaChat.Send(p, reason, ChatColor.magenta);
                                var playerPos = new Vector3Int(p.Position);

                                for (var i = 0; i < addCount; i++)
                                {
                                    var newGuy = new NPCBase(NPCType.GetByKeyNameOrDefault("pipliz.laborer"),
                                                             BannerTracker.GetClosest(p, playerPos).KeyLocation.Vector,
                                                             colony);

                                    SettlerInventory.GetSettlerInventory(newGuy);
                                    newGuy.GetTempValues().Set(ISSETTLER, true);

                                    if (i <= numbSkilled)
                                    {
                                        var npcTemp = newGuy.GetTempValues(true);
                                        npcTemp.Set(GameLoader.ALL_SKILLS, state.Rand.Next(1, 10) * 0.002f);
                                    }

                                    update = true;
                                    ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCRecruited, newGuy);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            PandaLogger.Log("SkilledLaborer");
                            PandaLogger.LogError(ex);
                        }

                        if (colony.FollowerCount > state.HighestColonistCount)
                        {
                            state.HighestColonistCount = colony.FollowerCount;
                        }
                    }


                    state.NextGenTime = Time.SecondsSinceStartDouble +
                                        Random.Next(8,
                                                    16 - Pipliz.Math.RoundToInt(p.GetTempValues(true)
                                                                                .GetOrDefault(PandaResearch.GetResearchKey(PandaResearch.TimeBetween),
                                                                                              0f))) * TimeCycle
                                        .SecondsPerHour;

                    colony.SendUpdate();
                }
            }

            return(update);
        }
Пример #5
0
        public static void EvaluateBanners()
        {
            if (!GameLoader.WorldLoaded)
            {
                return;
            }

            _bannerCounts.Clear();

            var banners = BannerTracker.GetCount();

            if (banners > 0)
            {
                for (var i = 0; i < banners; i++)
                {
                    if (BannerTracker.TryGetAtIndex(i, out var banner))
                    {
                        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);
                    }
                }
            }
        }
Пример #6
0
        public static void UpdateFoodUse(Players.Player p)
        {
            if (Server.TerrainGeneration.TerrainGenerator.UsedGenerator != null &&
                Server.AI.AIManager.NPCPathFinder != null &&
                p.ID.type != NetworkID.IDType.Server)
            {
                Colony      colony = Colony.Get(p);
                PlayerState ps     = PlayerState.GetPlayerState(p);
                var         food   = _baseFoodPerHour;

                if (ps.Difficulty != GameDifficulty.Normal && colony.FollowerCount > 10)
                {
                    var multiplier = (.7 / colony.FollowerCount) - p.GetTempValues(true).GetOrDefault(PandaResearch.GetResearchKey(PandaResearch.ReducedWaste), 0f);
                    food += (float)(_baseFoodPerHour * multiplier);
                    food *= ps.Difficulty.FoodMultiplier;
                }

                if (colony.InSiegeMode)
                {
                    food = food * ServerManager.ServerVariables.NPCfoodUseMultiplierSiegeMode;
                }

                if (food < _baseFoodPerHour)
                {
                    food = _baseFoodPerHour;
                }

                colony.FoodUsePerHour = food;
                colony.SendUpdate();
            }
        }
Пример #7
0
        public static bool EvaluateSettlers(ColonyState state)
        {
            var update = false;

            if (state.ColonyRef.OwnerIsOnline())
            {
                if (state.NextGenTime == 0)
                {
                    state.NextGenTime = Time.SecondsSinceStartDouble + Random.Next(8, 16) * IN_GAME_HOUR_IN_SECONDS;
                }

                if (Time.SecondsSinceStartDouble > state.NextGenTime && state.ColonyRef.FollowerCount >= MAX_BUYABLE)
                {
                    var chance =
                        state.ColonyRef.TemporaryData.GetAsOrDefault(PandaResearch.GetResearchKey(PandaResearch.SettlerChance), 0f) +
                        state.Difficulty.AdditionalChance;

                    chance += SettlerEvaluation.SpawnChance(state);

                    var rand = Random.NextFloat();

                    if (chance > rand)
                    {
                        var addCount = Math.Floor(state.MaxPerSpawn * chance);

                        // if we lost alot of colonists add extra to help build back up.
                        if (state.ColonyRef.FollowerCount < state.HighestColonistCount)
                        {
                            var diff = state.HighestColonistCount - state.ColonyRef.FollowerCount;
                            addCount += Math.Floor(diff * .25);
                        }

                        try
                        {
                            var skillChance = state.ColonyRef.TemporaryData.GetAsOrDefault(PandaResearch.GetResearchKey(PandaResearch.SkilledLaborer), 0f);
                            var numbSkilled = 0;
                            rand = Random.NextFloat();

                            try
                            {
                                if (skillChance > rand)
                                {
                                    numbSkilled = Pipliz.Random.Next(1,
                                                                     2 + Pipliz.Math.RoundToInt(state.ColonyRef.TemporaryData.GetAsOrDefault(PandaResearch.GetResearchKey(PandaResearch.NumberSkilledLaborer), 0f)));
                                }
                            }
                            catch (Exception ex)
                            {
                                PandaLogger.Log("NumberSkilledLaborer");
                                PandaLogger.LogError(ex);
                            }


                            if (addCount > 0)
                            {
                                if (addCount > 30)
                                {
                                    addCount = 30;
                                }

                                var reason = string.Format(SettlerReasoning.GetSettleReason(), addCount);

                                if (numbSkilled > 0)
                                {
                                    if (numbSkilled == 1)
                                    {
                                        reason += string.Format(" {0} of them is skilled!", numbSkilled);
                                    }
                                    else
                                    {
                                        reason += string.Format(" {0} of them are skilled!", numbSkilled);
                                    }
                                }

                                PandaChat.Send(state.ColonyRef, reason, ChatColor.magenta);

                                for (var i = 0; i < addCount; i++)
                                {
                                    var newGuy = new NPCBase(state.ColonyRef, state.ColonyRef.GetRandomBanner().Position);

                                    NPCTracker.Add(newGuy);
                                    state.ColonyRef.RegisterNPC(newGuy);
                                    SettlerInventory.GetSettlerInventory(newGuy);
                                    newGuy.CustomData.SetAs(ISSETTLER, true);

                                    if (i <= numbSkilled)
                                    {
                                        newGuy.CustomData.SetAs(GameLoader.ALL_SKILLS, Random.Next(1, 10) * 0.002f);
                                    }

                                    update = true;
                                    ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCRecruited, newGuy);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            PandaLogger.Log("SkilledLaborer");
                            PandaLogger.LogError(ex);
                        }

                        if (state.ColonyRef.FollowerCount > state.HighestColonistCount)
                        {
                            state.HighestColonistCount = state.ColonyRef.FollowerCount;
                        }
                    }


                    state.NextGenTime = Time.SecondsSinceStartDouble + Random.Next(8, 16) * IN_GAME_HOUR_IN_SECONDS;

                    state.ColonyRef.SendCommonData();
                }
            }

            return(update);
        }