示例#1
0
        public static void Heal(this NPCBase nPC, float heal)
        {
            nPC.health += heal;

            if (nPC.health > NPCBase.MaxHealth)
            {
                nPC.health = NPCBase.MaxHealth;
            }

            nPC.Update();
        }
示例#2
0
        public static void OnNPCRecruited(NPCBase npc)
        {
            try
            {
                var npcInv = ColonistInventory.Get(npc);
                if (npc.CustomData == null)
                {
                    npc.CustomData = new JSONNode();
                }

                if (npc.NPCType.IsLaborer)
                {
                    npcInv.UnemployedLeaveTime = TimeCycle.TotalHours + 48;
                }

                if (npc.CustomData.TryGetAs(ISSETTLER, out bool settler) && settler)
                {
                    return;
                }

                var ps = ColonyState.GetColonyState(npc.Colony);

                npc.FoodHoursCarried = ServerManager.ServerSettings.NPCs.InitialFoodCarriedHours;

                if (ps.SettlersEnabled != API.Models.SettlersState.Disabled)
                {
                    if (SettlersConfiguration.GetorDefault("ColonistsRecruitment", true))
                    {
                        if (npc.Colony.FollowerCount > MAX_BUYABLE)
                        {
                            if (!ColonistsBought.BoughtCount.ContainsKey(npc.Colony))
                            {
                                ColonistsBought.BoughtCount.Add(npc.Colony, new List <double>());
                            }

                            ColonistsBought.BoughtCount[npc.Colony].Add(TimeCycle.TotalHours + 24);
                        }

                        ColonistInventory.Get(npc);
                        UpdateFoodUse(ps);
                    }
                    else
                    {
                        PandaChat.Send(npc.Colony, _localizationHelper, "AdminDisabled", ChatColor.red);
                        npc.health = 0;
                        npc.Update();
                    }
                }
            }
            catch (Exception ex)
            {
                SettlersLogger.LogError(ex);
            }
        }
        public static void OnNPCRecruited(NPCBase npc)
        {
            if (npc.GetTempValues().TryGet(ISSETTLER, out bool settler) && settler)
            {
                return;
            }

            var ps = PlayerState.GetPlayerState(npc.Colony.Owner);

            if (ps.SettlersEnabled)
            {
                if (Configuration.GetorDefault("ColonistsRecruitment", true))
                {
                    if (ps.SettlersEnabled && npc.Colony.FollowerCount > MAX_BUYABLE)
                    {
                        var cost = Configuration.GetorDefault("CompoundingFoodRecruitmentCost", 5) * ps.ColonistsBought;
                        var num  = 0f;

                        if (cost < 1)
                        {
                            cost = 1;
                        }

                        if (npc.Colony.UsedStockpile.TotalFood < cost ||
                            !npc.Colony.UsedStockpile.TryRemoveFood(ref num, cost))
                        {
                            Chat.Send(npc.Colony.Owner,
                                      $"<color=red>Could not recruit a new colonist; not enough food in stockpile. {cost + ServerManager.ServerVariables.LaborerCost} food required.</color>",
                                      ChatSenderType.Server);

                            npc.Colony.UsedStockpile.Add(BuiltinBlocks.Bread,
                                                         (int)Math.Floor(ServerManager.ServerVariables.LaborerCost /
                                                                         3));

                            npc.health = 0;
                            npc.Update();
                            return;
                        }

                        ps.ColonistsBought++;
                        ps.NextColonistBuyTime = TimeCycle.TotalTime + 24;
                    }

                    SettlerInventory.GetSettlerInventory(npc);
                    UpdateFoodUse(npc.Colony.Owner);
                }
                else
                {
                    PandaChat.Send(npc.Colony.Owner,
                                   "The server administrator has disabled recruitment of colonists while settlers are enabled.");
                }
            }
        }
        public static void Heal(this NPCBase nPC, float heal)
        {
            if (nPC != null)
            {
                nPC.health += heal;

                if (nPC.health > nPC.Colony.NPCHealthMax)
                {
                    nPC.health = nPC.Colony.NPCHealthMax;
                }

                nPC.Update();
            }
        }
        public static void OnNPCRecruited(NPCBase npc)
        {
            try
            {
                if (npc.CustomData == null)
                {
                    npc.CustomData = new JSONNode();
                }

                if (npc.CustomData.TryGetAs(ISSETTLER, out bool settler) && settler)
                {
                    return;
                }

                var ps = ColonyState.GetColonyState(npc.Colony);

                npc.FoodHoursCarried = ServerManager.ServerSettings.NPCs.InitialFoodCarriedHours;

                if (ps.SettlersEnabled)
                {
                    if (SettlersConfiguration.GetorDefault("ColonistsRecruitment", true))
                    {
                        //if (ps.SettlersEnabled && npc.Colony.FollowerCount > MAX_BUYABLE)
                        //{
                        //    var cost = SettlersConfiguration.GetorDefault("CompoundingFoodRecruitmentCost", .25) * ps.ColonistsBought;
                        //    var num = 0f;

                        //    if (cost < 1)
                        //        cost = 1;

                        //    if (npc.Colony.Stockpile.TotalFood < cost ||
                        //        !npc.Colony.Stockpile.TryRemoveFood(ref num, cost))
                        //    {
                        //        PandaChat.Send(npc.Colony, $"Could not recruit a new colonist; not enough food in stockpile. {cost + ServerManager.ServerSettings.NPCs.RecruitmentCost} food required.", ChatColor.red);
                        //        npc.Colony.HappinessData.RecruitmentCostCalculator.GetCost(npc.Colony.HappinessData.CachedHappiness, npc.Colony, out float foodCost);

                        //        if (ItemTypes.TryGetType(ColonyBuiltIn.ItemTypes.BREAD.Name, out var bread))
                        //            npc.Colony.Stockpile.Add(ColonyBuiltIn.ItemTypes.BREAD, (int)Math.Floor(foodCost / bread.FoodValue));

                        //        npc.health = 0;
                        //        npc.Update();
                        //        return;
                        //    }

                        //    ps.ColonistsBought++;
                        //    ps.NextColonistBuyTime = TimeCycle.TotalTime.Value.Hours + 24;
                        //}

                        SettlerInventory.GetSettlerInventory(npc);
                        UpdateFoodUse(ps);
                    }
                    else
                    {
                        PandaChat.Send(npc.Colony, "The server administrator has disabled recruitment of colonists while settlers are enabled.");
                        npc.health = 0;
                        npc.Update();
                    }
                }
            }
            catch (Exception ex)
            {
                PandaLogger.LogError(ex);
            }
        }