public void ReceiveNPCAction(int x, int y, int index, ActionType action, int data) { IndividualCard card = null; try { if (x != -1 && y != -1) { card = CardHandler.s.allCards[x, y]; } } catch { DataLogger.LogError("ReceiveNPCAction couldnt find the card " + x.ToString() + "-" + y.ToString()); } try { NPCBase myNPC = null; if (action != ActionType.Spawn) { myNPC = ActiveNPCS[index]; } switch (action) { case ActionType.Spawn: DataLogger.LogError("Customs NPCs are not implemented to spawn yet! Spawning default level npc"); myNPC = SpawnNPCAtLocation(card, GS.a.myNPCPrefab); ActiveNPCS.SetIndex(index, myNPC); break; case ActionType.Die: case ActionType.SelectCard: case ActionType.Activate: case ActionType.GoToPos: myNPC.ReceiveNPCAction(card, action, data); break; default: DataLogger.LogError("Unrecognized power up action PUF"); break; } } catch (System.Exception e) { DataLogger.LogError(this.name, e); } }
public static void OnNPCSaved(NPCBase npc, JSONNode node) { node.SetAs(GameLoader.SETTLER_INV, SettlerInventory.GetSettlerInventory(npc).ToJsonNode()); if (npc.NPCType.IsLaborer && npc.CustomData.TryGetAs(LEAVETIME_JOB, out double leave)) { node.SetAs(LEAVETIME_JOB, leave); } if (npc.CustomData.TryGetAs(GameLoader.ALL_SKILLS, out float allSkill)) { node.SetAs(GameLoader.ALL_SKILLS, allSkill); } if (npc.CustomData.TryGetAs(KNOWN_ITTERATIONS, out int itt)) { node.SetAs(KNOWN_ITTERATIONS, itt); } }
public static void GetBestArmorForNPC(Stockpile stockpile, NPCBase npc, SettlerInventory inv, int limit) { foreach (ArmorSlot slot in ArmorSlotEnum) { if (!inv.Armor[slot].IsEmpty() && ArmorLookup[inv.Armor[slot].Id].IsMagical) { continue; } var bestArmor = GetBestArmorFromStockpile(stockpile, slot, limit); if (bestArmor != default(ushort)) { if (!inv.Armor.ContainsKey(slot)) { inv.Armor.Add(slot, new ItemState()); } // 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 NPCBase NearestFreeAlly(Transform origin) { NPCBase target = null; foreach (NPCBase tmp in allies) { if (tmp.invincible) { continue; } if (tmp.target == null) { if (target == null || GetDistance(tmp.transform, origin) < GetDistance(target.transform, origin)) { target = tmp; } } } return(target); }
public static void GetSkillInformation(NPCBase npc, out int nextLevel, out int itt, out float allSkill) { if (!npc.CustomData.TryGetAs(KNOWN_ITTERATIONS, out itt)) { npc.CustomData.SetAs(KNOWN_ITTERATIONS, 1); itt = 1; } else { npc.CustomData.SetAs(KNOWN_ITTERATIONS, itt + 1); } if (!npc.CustomData.TryGetAs(GameLoader.ALL_SKILLS, out allSkill)) { npc.CustomData.SetAs(GameLoader.ALL_SKILLS, 0.005f); allSkill = 0.005f; } nextLevel = Pipliz.Math.RoundToInt(allSkill * 1000) * _NUMBEROFCRAFTSPERPERCENT; }
private bool MakeDamage(NPCBase offence, NPCBase defence) { //攻击方等级 × 2 ÷ 5 + 2) × 技能威力 × 攻击方攻击力 ÷ 防御方防御力 ÷ 50 + 2 float a = (offence.Attack / defence.Defense); a /= 50.0f; var damage = (offence.Lv * 2.0f / 5.0f + 2.0f) * 50.0f * (offence.Attack / defence.Defense / 50.0f) + 2.0f; //float damage = (offence.Lv * 2.0f / 5.0f + 2.0f) * 50.0f * a + 2.0f; if (defence.HP <= damage) { defence.HP = 0; return(true); } else { defence.HP -= damage; } return(false); }
public static void OnNPCSaved(NPCBase npc, JSONNode node) { var tmpVals = npc.GetTempValues(); node.SetAs(GameLoader.SETTLER_INV, SettlerInventory.GetSettlerInventory(npc).ToJsonNode()); if (npc.NPCType.IsLaborer && tmpVals.Contains(LEAVETIME_JOB)) { node.SetAs(LEAVETIME_JOB, tmpVals.Get <double>(LEAVETIME_JOB)); } if (tmpVals.Contains(GameLoader.ALL_SKILLS)) { node.SetAs(GameLoader.ALL_SKILLS, tmpVals.Get <float>(GameLoader.ALL_SKILLS)); } if (tmpVals.Contains(KNOWN_ITTERATIONS)) { node.SetAs(KNOWN_ITTERATIONS, tmpVals.Get <int>(KNOWN_ITTERATIONS)); } }
NPCBase SpawnNPCAtLocation(IndividualCard myCard, NPCBase myNPCPrefab) { if (myNPCPrefab == null) { DataLogger.LogError("Trying to spawn null npc"); return(null); } NPCBase myNPC = Instantiate(myNPCPrefab.gameObject, npcSpawnPos.position, Quaternion.identity).GetComponent <NPCBase> (); myNPC.transform.localScale = new Vector3(1, 1, 1) * GS.a.gridSettings.scaleMultiplier; myNPC.Spawn(myCard); if (DataHandler.s.myPlayerInteger == 0) { ActiveNPCS.Add(myNPC); SendNPCAction(myCard.x, myCard.y, myNPC.GetComponent <NPCBase> (), ActionType.Spawn, -1); } return(myNPC); }
public static void OnUpdate() { if (_updateTime < Pipliz.Time.SecondsSinceStartDouble && TimeCycle.IsDay) { Players.PlayerDatabase.ForeachValue(p => { var colony = Colony.Get(p); NPCBase lastNPC = null; foreach (var follower in colony.Followers) { if (lastNPC == null || (Vector3.Distance(lastNPC.Position.Vector, follower.Position.Vector) > 15 && Pipliz.Random.NextBool())) { lastNPC = follower; ServerManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + "TalkingAudio"); } } }); _updateTime = Pipliz.Time.SecondsSinceStartDouble + 10; } }
static bool Prefix(NPCBase __instance, ref Vector3Int __result, NPCBase.NPCGoal goal) { if (__instance == null || __instance.Colony == null || __instance.Colony.BedTracker == null) { return(true); } switch (goal) { case NPCBase.NPCGoal.Bed: { if (__instance.UsedBed != null && __instance.UsedBed.IsValid) { return(true); } if (__instance.Job == null) { return(true); } Vector3Int jobLocation; BedTracker.Bed bed; if (__instance.Colony.BedTracker.TryGetClosestUnused(__instance.Job.GetJobLocation(), out jobLocation, out bed, 200)) { ClassUtility.Call(__instance, "ClearBed", new object[] { }); ClassUtility.SetProperty(__instance, "UsedBed", bed); ClassUtility.SetProperty(__instance, "UsedBedLocation", jobLocation); bed.SetUseState(jobLocation, true); __result = jobLocation; return(false); } break; } } return(true); }
void Start() { IsNear = false; move = false; canStart = true; npc_start = true; MoveTiming = true; NPCCharacter = GetComponent<NPCBase>(); seekerIso = GetComponent<IsoObject>(); seekerRigidybody = GetComponent<IsoRigidbody>(); cachedSeekerPos = seekerIso.position; cachedTargetPos = _targetPos.GetComponent<IsoObject>().position; _targetIsoObject = _targetPos.GetComponent<IsoObject>(); world = GameObject.Find("Camera").GetComponent<IsoWorld>(); }
public ColonistInventory(JSONNode baseNode, NPCBase nPC) { if (baseNode.TryGetAs <int>(nameof(SettlerId), out var settlerId)) { NPC = nPC; SetupArmor(); SettlerId = settlerId; baseNode.TryGetAs <string>(nameof(ColonistsName), out var name); ColonistsName = name; if (baseNode.TryGetAs(nameof(BonusProcs), out JSONNode skills)) { foreach (var skill in skills.LoopObject()) { if (ushort.TryParse(skill.Key, out ushort item)) { BonusProcs[item] = skill.Value.GetAs <long>(); } } } if (baseNode.TryGetAs(nameof(Stats), out JSONNode itterations)) { foreach (var skill in itterations.LoopObject()) { Stats[skill.Key] = skill.Value.GetAs <double>(); } } foreach (ArmorFactory.ArmorSlot armorType in ArmorFactory.ArmorSlotEnum) { Armor[armorType].FromJsonNode(armorType.ToString(), baseNode); } } }
public static void OnNPCLoaded(NPCBase npc, JSONNode node) { if (node.TryGetAs <JSONNode>(GameLoader.SETTLER_INV, out var invNode)) { npc.GetTempValues(true).Set(GameLoader.SETTLER_INV, new SettlerInventory(invNode)); } var tmpVals = npc.GetTempValues(); if (node.TryGetAs <double>(LEAVETIME_JOB, out var leaveTime)) { tmpVals.Set(LEAVETIME_JOB, leaveTime); } if (node.TryGetAs <float>(GameLoader.ALL_SKILLS, out var skills)) { tmpVals.Set(GameLoader.ALL_SKILLS, skills); } if (node.TryGetAs <int>(KNOWN_ITTERATIONS, out var jobItterations)) { tmpVals.Set(KNOWN_ITTERATIONS, jobItterations); } }
static void Prefix(BlockFarmAreaJob __instance, ref NPCBase.NPCState state) { // Log.WriteWarning("BlockFarmAreaJobHookOnNPCAtJob::Prefix"); npc = __instance.NPC; }
static void Postfix(GuardJobSettings __instance, GuardJobInstance instance, ref NPCBase.NPCState state) { // Log.WriteWarning("GuardJobSettingsHookShootAtTarget::Postfix"); npc = null; }
static void Postfix(ScientistJobSettingsHookOnNPCAtJob __instance, BlockJobInstance blockJobInstance, ref NPCBase.NPCState state) { // Log.WriteWarning("ScientistJobSettingsHookOnNPCAtJob::Postfix"); npc = null; }
// Start is called before the first frame update void Start() { character = GetComponent <NPCBase>(); lifes = transform.Find("Lifes"); }
public static void OnUpdate() { if (ServerManager.ColonyTracker != null) { foreach (var colony in ServerManager.ColonyTracker.ColoniesByID.Values) { if (_magicUpdateTime < Time.SecondsSinceStartDouble) { foreach (var follower in colony.Followers) { var inv = SettlerInventory.GetSettlerInventory(follower); if (inv.MagicItemUpdateTime < Time.SecondsSinceStartDouble) { foreach (var item in inv.Armor) { if (item.Value.Id != 0 && ArmorFactory.ArmorLookup.TryGetValue(item.Value.Id, out var armor)) { armor.Update(); if (armor.HPTickRegen != 0) { follower.Heal(armor.HPTickRegen); } } } if (Items.Weapons.WeaponFactory.WeaponLookup.TryGetValue(inv.Weapon.Id, out var wep)) { wep.Update(); if (wep.HPTickRegen != 0) { follower.Heal(wep.HPTickRegen); } } 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.MagicItemUpdateTime += 5000; } } } if (_updateTime < Time.SecondsSinceStartDouble && colony.OwnerIsOnline()) { NPCBase lastNPC = null; foreach (var follower in colony.Followers) { if (TimeCycle.IsDay) { if (lastNPC == null || UnityEngine.Vector3.Distance(lastNPC.Position.Vector, follower.Position.Vector) > 15 && Random.NextBool()) { lastNPC = follower; AudioManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".TalkingAudio"); } } } } var cs = ColonyState.GetColonyState(colony); if (cs.SettlersEnabled) { if (EvaluateSettlers(cs) || EvaluateLaborers(cs) || EvaluateBeds(cs)) { colony.SendCommonData(); } } UpdateFoodUse(cs); } } if (_magicUpdateTime < Time.SecondsSinceStartDouble) { _magicUpdateTime = Time.SecondsSinceStartDouble + 1; } if (_updateTime < Time.SecondsSinceStartDouble && TimeCycle.IsDay) { _updateTime = Time.SecondsSinceStartDouble + _UPDATE_TIME; } }
static void Prefix(AbstractAreaJob __instance, ref NPCBase.NPCState state) { npc = __instance.NPC; }
public static void PressButton(ButtonPressCallbackData data) { if ((!data.ButtonIdentifier.Contains(".RecruitButton") && !data.ButtonIdentifier.Contains(".FireButton") && !data.ButtonIdentifier.Contains(".MoveFired") && !data.ButtonIdentifier.Contains(".ColonyToolMainMenu") && !data.ButtonIdentifier.Contains(".KillFired") && !data.ButtonIdentifier.Contains(".CallToArms")) || data.Player.ActiveColony == null) { return; } Dictionary <string, JobCounts> jobCounts = GetJobCounts(data.Player.ActiveColony); if (data.ButtonIdentifier.Contains(".ColonyToolMainMenu")) { NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0)); } else if (data.ButtonIdentifier.Contains(".FireButton")) { foreach (var job in jobCounts) { if (data.ButtonIdentifier.Contains(job.Key)) { var recruit = data.Storage.GetAs <int>(job.Key + ".Recruit"); var count = GetCountValue(recruit); var menu = BuildMenu(data.Player, jobCounts, true, job.Key, count); menu.LocalStorage.SetAs(GameInitializer.NAMESPACE + ".FiredJobName", job.Key); menu.LocalStorage.SetAs(GameInitializer.NAMESPACE + ".FiredJobCount", count); NetworkMenuManager.SendServerPopup(data.Player, menu); break; } } } else if (data.ButtonIdentifier.Contains(".KillFired")) { var firedJob = data.Storage.GetAs <string>(GameInitializer.NAMESPACE + ".FiredJobName"); var count = data.Storage.GetAs <int>(GameInitializer.NAMESPACE + ".FiredJobCount"); foreach (var job in jobCounts) { if (job.Key == firedJob) { if (count > job.Value.TakenCount) { count = job.Value.TakenCount; } for (int i = 0; i < count; i++) { var npc = job.Value.TakenJobs[i].NPC; npc.ClearJob(); npc.OnDeath(); } break; } } data.Player.ActiveColony.SendCommonData(); jobCounts = GetJobCounts(data.Player.ActiveColony); NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0)); } else if (data.ButtonIdentifier.Contains(".MoveFired")) { var firedJob = data.Storage.GetAs <string>(GameInitializer.NAMESPACE + ".FiredJobName"); var count = data.Storage.GetAs <int>(GameInitializer.NAMESPACE + ".FiredJobCount"); foreach (var job in jobCounts) { if (data.ButtonIdentifier.Contains(job.Key)) { if (count > job.Value.AvailableCount) { count = job.Value.AvailableCount; } if (jobCounts.TryGetValue(firedJob, out var firedJobCounts)) { for (int i = 0; i < count; i++) { if (firedJobCounts.TakenCount > i) { var npc = firedJobCounts.TakenJobs[i].NPC; npc.ClearJob(); npc.TakeJob(job.Value.AvailableJobs[i]); data.Player.ActiveColony.JobFinder.Remove(job.Value.AvailableJobs[i]); } else { break; } } } data.Player.ActiveColony.SendCommonData(); break; } } jobCounts = GetJobCounts(data.Player.ActiveColony); NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0)); } else if (data.ButtonIdentifier.Contains(".RecruitButton")) { foreach (var job in jobCounts) { if (data.ButtonIdentifier.Contains(job.Key)) { var recruit = data.Storage.GetAs <int>(job.Key + ".Recruit"); var count = GetCountValue(recruit); if (count > job.Value.AvailableCount) { count = job.Value.AvailableCount; } 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)) { PandaChat.Send(data.Player, _localizationHelper, "Notenoughfood", ChatColor.red); break; } else { var newGuy = new NPCBase(data.Player.ActiveColony, data.Player.ActiveColony.GetClosestBanner(new Vector3Int(data.Player.Position)).Position); newGuy.FoodHoursCarried = ServerManager.ServerSettings.NPCs.InitialFoodCarriedHours; data.Player.ActiveColony.RegisterNPC(newGuy); ColonistInventory.Get(newGuy); NPCTracker.Add(newGuy); ModLoader.Callbacks.OnNPCRecruited.Invoke(newGuy); if (newGuy.IsValid) { newGuy.TakeJob(job.Value.AvailableJobs[i]); data.Player.ActiveColony.JobFinder.Remove(job.Value.AvailableJobs[i]); } } } data.Player.ActiveColony.SendCommonData(); jobCounts = GetJobCounts(data.Player.ActiveColony); NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0)); } } } }
public DexterityStat(NPCBase owner) : base(owner) { }
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); }
public virtual void OnRemovedNPC() { usedNPC = null; JobTracker.Add(this); }
public virtual void OnAssignedNPC(NPCBase npc) { usedNPC = npc; }
static void Postfix(FarmAreaJob __instance, ref NPCBase.NPCState state) { // Log.WriteWarning("FarmAreaJobHookOnNPCAtJob::Postfix"); npc = null; }
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); } }
static void Postfix(BuilderBasic __instance, IIterationType iterationType, IAreaJob areaJob, ConstructionJobInstance job, ref NPCBase.NPCState state) { // Log.WriteWarning("BuilderBasicHookDoJob::Postfix"); npc = null; }
public static void OnNPCDied(NPCBase npc) { SettlerInventory.GetSettlerInventory(npc); UpdateFoodUse(ColonyState.GetColonyState(npc.Colony)); }
static void Postfix(AbstractAreaJob __instance, ref NPCBase.NPCState state) { npc = null; }
public static void OnUpdate() { Players.PlayerDatabase.ForeachValue(p => { var stockpile = Stockpile.GetStockPile(p); var colony = Colony.Get(p); var hasBandages = stockpile.Contains(TreatedBandage.Item.ItemIndex) || stockpile.Contains(Bandage.Item.ItemIndex); if (hasBandages) { foreach (var follower in colony.Followers) { if (follower.health < NPCBase.MaxHealth && !HealingOverTimeNPC.NPCIsBeingHealed(follower)) { var healing = false; if (NPCBase.MaxHealth - follower.health > TreatedBandage.INITIALHEAL) { stockpile.TryRemove(TreatedBandage.Item.ItemIndex); healing = true; ServerManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".Bandage"); var heal = new HealingOverTimeNPC(follower, TreatedBandage.INITIALHEAL, TreatedBandage.TOTALHOT, 5, TreatedBandage.Item.ItemIndex); } if (!healing) { stockpile.TryRemove(Bandage.Item.ItemIndex); healing = true; ServerManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".Bandage"); var heal = new HealingOverTimeNPC(follower, Bandage.INITIALHEAL, Bandage.TOTALHOT, 5, Bandage.Item.ItemIndex); } } } } if (_updateTime < Time.SecondsSinceStartDouble && TimeCycle.IsDay && p.IsConnected) { NPCBase lastNPC = null; foreach (var follower in colony.Followers) { if (lastNPC == null || Vector3.Distance(lastNPC.Position.Vector, follower.Position.Vector) > 15 && Random.NextBool()) { lastNPC = follower; ServerManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".TalkingAudio"); } } } var ps = PlayerState.GetPlayerState(p); if (ps.SettlersEnabled) { if (EvaluateSettlers(p) || EvaluateLaborers(p) || EvaluateBeds(p)) { colony.SendUpdate(); } } UpdateFoodUse(p); }); if (_updateTime < Time.SecondsSinceStartDouble && TimeCycle.IsDay) { _updateTime = Time.SecondsSinceStartDouble + 10; } }