public static void OnNPCDied(NPC.NPCBase colonist) { Colony colony = colonist.Colony; if (colony == null) { return; } foreach (var owner in colony.Owners) { if (owner.ConnectionState != Players.EConnectionState.Connected) { continue; } CompassWaypoints compassMarkers = Waypoints.GetValueOrDefault(owner.ID, null); if (compassMarkers == null) { compassMarkers = new CompassWaypoints(Vector3Int.invalidPos, colonist.Position, new List <WayPoint>()); Waypoints.Add(owner.ID, compassMarkers); } else { compassMarkers.colonistDeath = colonist.Position; } } }
public BlockJobBaseExtender(NPC.NPCBase npc, BlockJobBase job) { NPC = npc; blockJob = job; _timeJob = _type.GetField("timeJob", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); _overrideCooldown = _type.GetMethod("OverrideCooldown", BindingFlags.Instance | BindingFlags.NonPublic); }
public static void OnHit(NPC.NPCBase npc, ModLoader.OnHitData data) { if ((data.HitSourceType == ModLoader.OnHitData.EHitSourceType.PlayerClick || data.HitSourceType == ModLoader.OnHitData.EHitSourceType.PlayerProjectile) && !npc.Colony.Owners.Contains((Players.Player)data.HitSourceObject)) { var p = (Players.Player)data.HitSourceObject; if (_warnedPlayers.Contains(p)) { ServerManager.Disconnect(p); } else { _warnedPlayers.Add(p); NetworkMenu menu = new NetworkMenu(); menu.LocalStorage.SetAs("header", _LocalizationHelper.LocalizeOrDefault("warning", p)); menu.Width = 800; menu.Height = 600; menu.ForceClosePopups = true; menu.Items.Add(new Label(new LabelData(_LocalizationHelper.LocalizeOrDefault("KillingColonists", p), UnityEngine.Color.black))); NetworkMenuManager.SendServerPopup(p, menu); } data.HitDamage = 0; data.ResultDamage = 0; } }
public static void OnHit(NPC.NPCBase npc, ModLoader.OnHitData data) { if ((data.HitSourceType == ModLoader.OnHitData.EHitSourceType.PlayerClick || data.HitSourceType == ModLoader.OnHitData.EHitSourceType.PlayerProjectile) && !npc.Colony.Owners.Contains((Players.Player)data.HitSourceObject)) { var p = (Players.Player)data.HitSourceObject; if (_warnedPlayers.Contains(p)) { ServerManager.Disconnect(p); } else { _warnedPlayers.Add(p); NetworkMenu menu = new NetworkMenu(); menu.LocalStorage.SetAs("header", "WARNING"); menu.Width = 800; menu.Height = 600; menu.ForceClosePopups = true; menu.Items.Add(new Label(new LabelData("WARNING: Killing colonists that do not belong to you will result in a kick. This is your first and ONLY warning.", UnityEngine.Color.black))); NetworkMenuManager.SendServerPopup(p, menu); } data.HitDamage = 0; data.ResultDamage = 0; } }
public static void OnNPCDied(NPC.NPCBase nPC) { var cs = ColonyState.GetColonyState(nPC.Colony); if (!DieCount.ContainsKey(nPC.Colony)) { DieCount.Add(nPC.Colony, new List <double>()); } DieCount[nPC.Colony].Add(TimeCycle.TotalTime.Value.TotalSeconds + cs.Difficulty.TimeUnhappyAfterColonistDeathSeconds); }
public static SettlerInventory GetSettlerInventory(NPC.NPCBase npc) { var tempVals = npc.GetTempValues(true); if (!tempVals.TryGet(GameLoader.SETTLER_INV, out SettlerInventory inv)) { inv = new SettlerInventory(npc.ID); tempVals.Set(GameLoader.SETTLER_INV, inv); } return(inv); }
public static NPCModel MapNPC(NPC.NPCBase follower) { return(new NPCModel() { Health = follower.health, Id = follower.ID, NpcTypeJobId = follower.Job.NPCType.Type, NPCInventory = follower.Inventory, Position = new SerializableVector3(follower.Position), ColonistInventory = ColonistInventory.Get(follower) }); }
public static NPCModel MapNPC(NPC.NPCBase follower) { return(new NPCModel() { FoodHoursCarried = follower.FoodHoursCarried, GoalPosition = new SerializableVector3(follower.UsedPath.path?.Goal.Vector), Health = follower.health, Id = follower.ID, NpcTypeJobId = follower.Job.NPCType.Type, NPCInventory = follower.Inventory, Position = new SerializableVector3(follower.Position), ColonistInventory = ColonistInventory.Get(follower), BedPosition = new SerializableVector3(follower.UsedBedLocation) }); }
public static void OnNPCDied(NPC.NPCBase nPC) { var cs = ColonyState.GetColonyState(nPC.Colony); if (cs.Difficulty.Name == GameDifficulty.Normal.Name) { return; } if (!DieCount.ContainsKey(nPC.Colony)) { DieCount.Add(nPC.Colony, new List <double>()); } DieCount[nPC.Colony].Add(TimeCycle.TotalHours + 24); }
public static void OnNPCHit(NPC.NPCBase npc, ModLoader.OnHitData data) { if (!(data.HitSourceObject is Players.Player)) { return; } Players.Player killer = (Players.Player)data.HitSourceObject; foreach (Players.Player owner in npc.Colony.Owners) { if (owner == killer || PlayerTracker.IsFriendly(owner, killer)) { return; } } PlayerTracker.AddEnemy(npc.Colony, killer); }
public HealingOverTimeNPC(NPC.NPCBase nPC, float initialHeal, float totalHoT, int durationSeconds) { HealPerTic = totalHoT / durationSeconds; DurationSeconds = durationSeconds; InitialHeal = initialHeal; Target = nPC; TotalHoTTime = totalHoT; TicksLeft = durationSeconds; if (NewInstance != null) { NewInstance(this, null); } _instances.Add(this); Target.Heal(InitialHeal); Tick += HealingOverTimeNPC_Tick; }
public static void OnNPCHit(NPC.NPCBase npc, ModLoader.OnHitData data) { if (!IsKilled(npc, data) || !IsHitByPlayer(data.HitSourceType) || !(data.HitSourceObject is Players.Player)) { return; } Players.Player killer = (Players.Player)data.HitSourceObject; foreach (Players.Player owner in npc.Colony.Owners) { if (owner == killer) { return; } } int kills; if (!KillCounter.TryGetValue(killer, out kills)) { kills = 0; } KillCounter[killer] = ++kills; if (NpcKillsBanThreshold > 0 && kills >= NpcKillsBanThreshold) { Chat.SendToConnected($"{killer.Name} banned for killing too many colonists"); BlackAndWhitelisting.AddBlackList(killer.ID.steamID.m_SteamID); Players.Disconnect(killer); } else if (NpcKillsKickThreshold > 0 && kills >= NpcKillsKickThreshold) { Chat.SendToConnected($"{killer.Name} kicked for killing too many colonists"); Players.Disconnect(killer); } else if (NpcKillsJailThreshold > 0 && kills >= NpcKillsJailThreshold) { Chat.SendToConnected($"{killer.Name} put in Jail for killing too many colonists"); JailManager.jailPlayer(killer, null, "Killing Colonists", JailManager.DEFAULT_JAIL_TIME); } Log.Write($"{killer.Name} killed a colonist of {npc.Colony.ColonyID} at {npc.Position}"); int remainingJail = NpcKillsJailThreshold - kills; int remainingKick = NpcKillsKickThreshold - kills; Chat.Send(killer, $"You killed a colonist, remaining until jail: {remainingJail}, remaining until kick: {remainingKick}"); }
public static void GetBestArmorForNPC(Stockpile stockpile, NPC.NPCBase npc, SettlerInventory inv, int limit) { foreach (ArmorSlot slot in ArmorSlotEnum) { var bestArmor = GetBestArmorFromStockpile(stockpile, slot, limit); if (bestArmor != default(ushort)) { if (!inv.Armor.ContainsKey(slot)) { inv.Armor.Add(slot, new ArmorState()); } // Check if we need one or if there is an upgrade. if (inv.Armor[slot].IsEmpty()) { stockpile.TryRemove(bestArmor); inv.Armor[slot].Id = bestArmor; inv.Armor[slot].Durability = ArmorLookup[bestArmor].Durability; } else { var currentArmor = ArmorLookup[inv.Armor[slot].Id]; var stockpileArmor = ArmorLookup[bestArmor]; if (stockpileArmor.ArmorRating > currentArmor.ArmorRating) { // Upgrade armor. stockpile.TryRemove(bestArmor); stockpile.Add(inv.Armor[slot].Id); inv.Armor[slot].Id = bestArmor; inv.Armor[slot].Durability = stockpileArmor.Durability; } } } } }
public static void OnNPCHit(NPC.NPCBase npc, Pipliz.Box <float> box) { var inv = SettlerInventory.GetSettlerInventory(npc); DeductArmor(box, inv.Armor, npc.Colony.Owner, inv.SettlerName); }
public static bool TryGetNPCGuardDefaultSettings(this NPC.NPCBase npc, out GuardJobSettings settings) { return(TryGetNPCGuardDefaultSettings(npc.Job, out settings)); }
public static bool TryGetNPCCraftDefaultSettings(this NPC.NPCBase npc, out CraftingJobSettings settings) { return(TryGetNPCCraftDefaultSettings(npc.Job, out settings)); }
public static void ApplyJobResearch(this NPC.NPCBase npc) { ApplyJobResearch(npc?.Job); }
static bool IsKilled(NPC.NPCBase npc, ModLoader.OnHitData data) { return(npc.health - data.ResultDamage <= 0); }
public static void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data) { if (data.Player.ActiveColony == null) { return; } if (data.ButtonIdentifier.StartsWith("PG.") == false) { return; } Pipliz.Collections.SortedList <string, ColonyJobData> colonyinfo = ColonyManager.GetColonyInfo(data.Player.ActiveColony); if (data.ButtonIdentifier.Contains("PG.Colony.Management")) { ColonyManager.SendUI(data.Player); return; } else if (data.ButtonIdentifier.Contains("PG.Jobs.")) { NPCJobs.SendUI(data.Player, data.ButtonIdentifier.Split('.')[2]); return; } else if (data.ButtonIdentifier.Contains("PG.Colony.Itemcount")) { Itemcount.SendUI(data.Player); return; } else if (data.ButtonIdentifier.Contains("PG.Recruit.")) { foreach (var job in colonyinfo) { if (data.ButtonIdentifier.Contains(job.Key)) { int recruit = data.Storage.GetAs <int>("PG.Recruit." + job.Key); int count = ColonyManager.GetCountValue(recruit); if (count > job.Value.Avaible) { count = job.Value.Avaible; } for (int i = 0; i < count; i++) { var num = 0f; data.Player.ActiveColony.HappinessData.RecruitmentCostCalculator.GetCost(data.Player.ActiveColony.HappinessData.CachedHappiness, data.Player.ActiveColony, out float foodcost); if (data.Player.ActiveColony.Stockpile.TotalFood < foodcost || data.Player.ActiveColony.Stockpile.TryRemoveFood(ref num, foodcost) == false) { Helpers.Chat.Send(data.Player, "Colony does not have enough food!"); break; } if (data.Player.ActiveColony.CalculateBedCount() <= data.Player.ActiveColony.FollowerCount) { Helpers.Chat.Send(data.Player, "Colony does not have enough beds!"); break; } else { NPC.NPCBase newguy = new NPC.NPCBase(data.Player.ActiveColony, data.Player.ActiveColony.GetClosestBanner(new Pipliz.Vector3Int(data.Player.Position)).Position); data.Player.ActiveColony.RegisterNPC(newguy); NPC.NPCTracker.Add(newguy); if (newguy.IsValid) { newguy.TakeJob(job.Value.AvaibleJobs[i]); data.Player.ActiveColony.JobFinder.Remove(job.Value.AvaibleJobs[i]); } } } data.Player.ActiveColony.SendCommonData(); ColonyManager.SendUI(data.Player); } } return; } }
public ImprovedCraftingSettings(NPC.NPCBase npc, Jobs.CraftingJobSettings settings) : base(settings.BlockTypes[0].Name, settings.NPCTypeKey, settings.CraftingCooldown, settings.MaxCraftsPerHaul, settings.OnCraftedAudio) { this.npc = npc; }
public static void OnUpdate() { if (Configuration.AllowDehydration) { if (TimeCycle.TimeOfDay >= TimeCycle.SunSet && TimeCycle.TimeOfDay < TimeCycle.SunSet + 1) { if (!waterchecked) { waterchecked = true; List <Players.Player> players = Player.PlayerList(); foreach (Players.Player p in players) { Logger.Log("players {0}", p.Name); ushort type = ItemTypes.IndexLookup.GetIndex(Blocks.MOD_NAMESPACE + ".WaterBucket"); if (!waterConsumed.ContainsKey(p.Name)) { waterConsumed.Add(p.Name, false); } if (!waterConsumed[p.Name]) { var stockpile = Stockpile.GetStockPile(p); //Determine to total value if hydration available float totalHydrationValue = TotalHydrationInStockPile(stockpile); //Determine the total hydration value need to hydrate all the colonists float followerHydrationNeeded = TotalHydrationNeeded(p); //Remove the followedrHydrationNeeded amount, if this is greater then what is available then return the unhydrated colonist count. int colonistsDehydrated = UseHydration(followerHydrationNeeded, totalHydrationValue, stockpile); // for (int count = 0; count < colonistsDehydrated; count++) { NPC.NPCBase follower = Colony.Get(p).Followers.Last <NPC.NPCBase>(); if (follower == null) { break; } follower.OnDeath(); } if (colonistsDehydrated != 0) { Chat.Send(p, "You do not have enough water for {0} Colonist(s)!", ChatColor.red, colonistsDehydrated.ToString()); } waterConsumed[p.Name] = true; } else { waterConsumed[p.Name] = false; } } } } else { waterchecked = false; } } }
public static void OnNPCHit(NPC.NPCBase npc, Pipliz.Box <float> box) { var state = PlayerState.GetPlayerState(npc.Colony.Owner); box.Set(box.item1 + state.Difficulty.MonsterDamage); }