Ejemplo n.º 1
0
        private static void NPCLeaving(NPCBase npc)
        {
            if (Random.NextFloat() > .49f)
            {
                float cost = ColonistManager.PenalizeFood(npc.Colony, 0.05f);

                PandaChat.Send(npc.Colony, _localizationHelper, "TakenFood", ChatColor.red);
            }
            else
            {
                var numberOfItems = Random.Next(1, 10);

                for (var i = 0; i < numberOfItems; i++)
                {
                    var randItem = Random.Next(npc.Colony.Stockpile.ItemCount);
                    var item     = npc.Colony.Stockpile.GetByIndex(randItem);

                    if (item.Type != ColonyBuiltIn.ItemTypes.AIR.Id && item.Amount != 0)
                    {
                        var leaveTax = Pipliz.Math.RoundToInt(item.Amount * .10);
                        npc.Colony.Stockpile.TryRemove(item.Type, leaveTax);

                        PandaChat.Send(npc.Colony, _localizationHelper, "LeavingTakingItems", ChatColor.red, leaveTax.ToString(), ItemId.GetItemId(item.Type).Name);
                    }
                }

                PandaChat.Send(npc.Colony, _localizationHelper, "LeavingNumberOfItems", ChatColor.red, numberOfItems.ToString());
            }

            npc.health = 0;
            npc.OnDeath();
        }
Ejemplo n.º 2
0
        public static bool EvaluateSettlers(ColonyState state)
        {
            var update = false;

            if (state.SettlersEnabled != SettlersState.Disabled && state.ColonyRef.OwnerIsOnline())
            {
                if (state.NextGenTime == 0)
                {
                    state.NextGenTime = TimeCycle.TotalHours + Random.Next(8, 16);
                }

                if (TimeCycle.TotalHours > state.NextGenTime && state.ColonyRef.FollowerCount >= MAX_BUYABLE)
                {
                    var chance =
                        state.ColonyRef.TemporaryData.GetAsOrDefault(GameLoader.NAMESPACE + ".SettlerChance", 0f) +
                        state.Difficulty.GetorDefault("AdditionalChance", 0);

                    chance += SettlerEvaluation.SpawnChance(state);

                    var rand = Random.NextFloat();

                    if (chance > rand)
                    {
                        var addCount = Math.Floor(SettlerManager.MaxPerSpawn(state.ColonyRef) * 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(GameLoader.NAMESPACE + ".SkilledLaborer", 0f) + SkilledSettlerChance.GetSkilledSettlerChance(state.ColonyRef);
                            var numbSkilled = 0;
                            rand = Random.NextFloat();

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


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

                                if (state.SettlersEnabled == SettlersState.AlwaysAccept)
                                {
                                    AddNewSettlers(addCount, numbSkilled, state);
                                }
                                else
                                {
                                    foreach (var p in state.ColonyRef.Owners)
                                    {
                                        if (p.IsConnected())
                                        {
                                            NetworkMenu menu = new NetworkMenu();
                                            menu.LocalStorage.SetAs("header", state.ColonyRef.Name + ": " + addCount + _localizationHelper.LocalizeOrDefault("NewSettlers", p));
                                            menu.Width  = 600;
                                            menu.Height = 300;

                                            menu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".NewSettlers." + state.ColonyRef.ColonyID + ".Accept." + addCount + "." + numbSkilled,
                                                                              new LabelData(_localizationHelper.GetLocalizationKey("Accept"),
                                                                                            UnityEngine.Color.black,
                                                                                            UnityEngine.TextAnchor.MiddleCenter)));

                                            menu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".NewSettlers." + state.ColonyRef.ColonyID + ".Decline",
                                                                              new LabelData(_localizationHelper.GetLocalizationKey("Decline"),
                                                                                            UnityEngine.Color.black,
                                                                                            UnityEngine.TextAnchor.MiddleCenter)));

                                            NetworkMenuManager.SendServerPopup(p, menu);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            SettlersLogger.Log("SkilledLaborer");
                            SettlersLogger.LogError(ex);
                        }

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


                    state.NextGenTime = TimeCycle.TotalHours + Random.Next(8, 16);

                    state.ColonyRef.SendCommonData();
                }
            }

            return(update);
        }