public static void SendPacket(Players.Player player) { if (player.IsConnected) { int builder = player.GetTempValues(false).GetOrDefault("pipliz.builderlimit", 0); int digger = player.GetTempValues(false).GetOrDefault("pipliz.diggerlimit", 0); using (ByteBuilder b = ByteBuilder.Get()) { b.Write(General.Networking.ClientMessageType.ReceiveConstructionLimits); b.Write(builder); b.Write(digger); NetworkWrapper.Send(b.ToArray(), player); } } }
public static void UpdateFoodUse(Players.Player p) { if (TerrainGenerator.UsedGenerator != null && AIManager.NPCPathFinder != null && p.ID.type != NetworkID.IDType.Server) { var colony = Colony.Get(p); var 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(); } }
public static void OnPlayerRespawn(Players.Player p) { if (p.GetTempValues(true).GetOrDefault(GameLoader.NAMESPACE + ".Knights", 0f) == 1f) { GivePlayerPatrolTool(p); } }
public static void OnPlayerRespawn(Players.Player p) { if (p.GetTempValues(true).GetOrDefault(PandaResearch.GetResearchKey(PandaResearch.Knights), 0f) == 1f) { GivePlayerPatrolTool(p); } }
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); }