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(); }
private static void AddNewSettlers(double addCount, int numbSkilled, ColonyState state) { 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, _localizationHelper, reason, ChatColor.green); for (var i = 0; i < addCount; i++) { var newGuy = new NPCBase(state.ColonyRef, state.ColonyRef.GetRandomBanner().Position); NPCTracker.Add(newGuy); state.ColonyRef.RegisterNPC(newGuy); ColonistInventory.Get(newGuy); newGuy.CustomData.SetAs(ISSETTLER, true); if (i <= numbSkilled) { newGuy.CustomData.SetAs(GameLoader.ALL_SKILLS, Random.Next(5, 10) * 0.005f); } ModLoader.Callbacks.OnNPCRecruited.Invoke(newGuy); } }
private static bool EvaluateBeds(ColonyState state) { var update = false; try { if (!TimeCycle.IsDay && TimeCycle.TotalHours > state.NextBedTime) { var remainingBeds = state.ColonyRef.BedTracker.CalculateTotalBedCount() - state.ColonyRef.FollowerCount; var left = 0; if (remainingBeds >= 0) { state.NeedsABed = 0; } else { if (state.NeedsABed == 0) { state.NeedsABed = TimeCycle.TotalHours + 24; PandaChat.Send(state.ColonyRef, _localizationHelper, SettlerReasoning.GetNeedBed(), ChatColor.grey); } else if (state.NeedsABed <= TimeCycle.TotalHours) { List <NPCBase> leaving = new List <NPCBase>(); foreach (var follower in state.ColonyRef.Followers) { if (follower.UsedBed == null) { left++; leaving.Add(follower); } } state.NeedsABed = 0; foreach (var npc in leaving) { NPCLeaving(npc); } } if (left > 0) { PandaChat.Send(state.ColonyRef, _localizationHelper, string.Concat(SettlerReasoning.GetNoBed(), string.Format(" {0} colonists have left your colony.", left)), ChatColor.red); update = true; } state.ColonyRef.SendCommonData(); } state.NextBedTime = TimeCycle.TotalHours + Random.Next(5, 8); } } catch (Exception ex) { SettlersLogger.LogError(ex, "EvaluateBeds"); } return(update); }
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); }
private static void UpdateMagicItemms(ColonyState state) { try { if (state.HealingUpdateTime < Time.SecondsSinceStartDouble) { var colony = state.ColonyRef; foreach (var follower in colony.Followers) { var inv = ColonistInventory.Get(follower); if (inv.HealingItemUpdateTime < Time.SecondsSinceStartDouble) { var hasBandages = colony.Stockpile.Contains(TreatedBandage.Item.ItemIndex) || colony.Stockpile.Contains(Bandage.Item.ItemIndex); if (hasBandages && follower.health < follower.Colony.NPCHealthMax && !HealingOverTimeNPC.NPCIsBeingHealed(follower)) { var healing = false; if (follower.Colony.NPCHealthMax - follower.health > TreatedBandage.INITIALHEAL) { colony.Stockpile.TryRemove(TreatedBandage.Item.ItemIndex); healing = true; AudioManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".Bandage"); var heal = new HealingOverTimeNPC(follower, TreatedBandage.INITIALHEAL, TreatedBandage.TOTALHOT, 5, TreatedBandage.Item.ItemIndex); } if (!healing) { colony.Stockpile.TryRemove(Bandage.Item.ItemIndex); healing = true; AudioManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".Bandage"); var heal = new HealingOverTimeNPC(follower, Bandage.INITIALHEAL, Bandage.TOTALHOT, 5, Bandage.Item.ItemIndex); } } inv.HealingItemUpdateTime = Time.SecondsSinceStartDouble + Random.Next(3, 5); } } state.HealingUpdateTime = Time.SecondsSinceStartDouble + 5; } } catch (Exception ex) { SettlersLogger.LogError(ex); } }