public virtual void OnNPCAtStockpile(BlockJobInstance blockJobInstance, ref NPCBase.NPCState state) { GeneratorJobInstance instance = (GeneratorJobInstance)blockJobInstance; if (state.Inventory.IsEmpty == false) { state.Inventory.Dump(blockJobInstance.Owner.Stockpile); state.SetCooldown(0.3); } state.JobIsDone = true; if (instance.ShouldTakeItems == false) { return; } instance.ShouldTakeItems = false; if (state.Inventory.IsEmpty) { //Repeat till inventory is full! //Check if EnergyItem exists in the stockpile if (blockJobInstance.Owner.Stockpile.TryRemove(EnergyItem.Type, EnergyItem.Amount * 5)) { //Take item and increase wait counter state.Inventory.Add(EnergyItem.Type, EnergyItem.Amount * 5); } } //Make NPC wait 1 second state.SetCooldown(1); }
public virtual void TakeItems(ref NPCBase.NPCState state) { if (TryDumpNPCInventory(ref state)) { state.JobIsDone = true; } }
public void OnNPCAtJob(BlockJobInstance instance, ref NPCBase.NPCState state) { if (instance is RoamingJob roamingJob) { roamingJob.OnNPCAtJob(ref state); } }
public override void OnNPCAtJob(ref NPCBase.NPCState state) { Vector3 rotate = usedNPC.Position.Vector; if (type == BuiltinBlocks.MinerJobXN) { rotate += Vector3.left; } else if (type == BuiltinBlocks.MinerJobXP) { rotate += Vector3.right; } else if (type == BuiltinBlocks.MinerJobZP) { rotate += Vector3.forward; } else if (type == BuiltinBlocks.MinerJobZN) { rotate += Vector3.back; } usedNPC.LookAt(rotate); ServerManager.SendAudio(position.Vector, "stoneDelete"); var itemList = ItemTypes.GetType(typeBelow).OnRemoveItems; state.Inventory.Add(itemList); state.JobIsDone = true; state.SetIndicator(NPCIndicatorType.Crafted, cooldown, itemList[0].item.Type); }
public virtual void ShootAtTarget(GuardJobInstance instance, ref NPCBase.NPCState state) { if (state.Inventory.TryRemove(GuardSettings.ShootItem)) { if (GuardSettings.OnShootAudio != null) { AudioManager.SendAudio(instance.Position.Vector, GuardSettings.OnShootAudio); } if (GuardSettings.OnHitAudio != null) { AudioManager.SendAudio(instance.Target.PositionToAimFor, GuardSettings.OnHitAudio); } UnityEngine.Vector3 start = instance.Position.Add(0, 1, 0).Vector; UnityEngine.Vector3 end = instance.Target.PositionToAimFor; UnityEngine.Vector3 dirNormalized = (end - start).normalized; ServerManager.SendParticleTrail(start + dirNormalized * 0.15f, end - dirNormalized * 0.15f, Pipliz.Random.NextFloat(1.5f, 2.5f)); instance.Target.OnHit(GuardSettings.Damage, instance.NPC, ModLoader.OnHitData.EHitSourceType.NPC); state.SetIndicator(new IndicatorState(GuardSettings.CooldownShot, GuardSettings.ShootItem[0].Type)); if (GuardSettings.OnShootResultItem.item.Type > 0 && Pipliz.Random.NextDouble(0.0, 1.0) <= (double)GuardSettings.OnShootResultItem.chance) { state.Inventory.Add(GuardSettings.OnShootResultItem.item); } } else { Shop(instance, ref state); } }
public override void OnNPCAtStockpile(ref NPCBase.NPCState state) { storedItems = MaxStoredItems; state.JobIsDone = true; state.SetCooldown(0.2); state.Inventory.Dump(usedNPC.Colony.UsedStockpile); }
public virtual void DoJob(IJob job, ref NPCBase.NPCState state) { if (constructionType != null) { constructionType.DoJob(iterationType, this, ref state); } }
public void PerformGoal(ref NPCBase.NPCState state) { state.JobIsDone = true; if (!Foraging) { Foraging = true; var nextTime = Pipliz.Random.Next(ForagingTimeMinSec, ForagingTimeMaxSec); ForageEndTime = ServerTimeStamp.Now.Add(nextTime * 1000); state.SetCooldown(1, 2); state.SetIndicator(new Shared.IndicatorState(Pipliz.Random.NextFloat(1, 2), LootTable.LootPoolList.GetRandomItem().Item)); } else if (ForageEndTime.IsPassed) { var items = LootTable.GetDrops(LuckMod); foreach (var item in items) { Job.NPC.Inventory.Add(item.Key, item.Value); } state.SetCooldown(1); Foraging = false; PandaJobFactory.SetActiveGoal(Job, new PutItemsInCrateGoal(Job, JobPos, this, Job.NPC.Inventory.Inventory, this), ref state); Job.NPC.Inventory.Inventory.Clear(); } else { RandomizePos(); var nextTime = Pipliz.Random.Next(5, 7); state.SetCooldown(nextTime); state.SetIndicator(new Shared.IndicatorState(nextTime, LootTable.LootPoolList.GetRandomItem().Item)); } }
public virtual NPCBase.NPCGoal CalculateGoal(ref NPCBase.NPCState state) { NPCBase.NPCGoal newGoal; if (ToSleep) { if (!state.Inventory.IsEmpty) { newGoal = NPCBase.NPCGoal.Stockpile; } else { newGoal = NPCBase.NPCGoal.Bed; } } else { if (state.Inventory.Full || NeedsItems) { newGoal = NPCBase.NPCGoal.Stockpile; } else { newGoal = NPCBase.NPCGoal.Job; } } if (lastGoal != newGoal) { OnChangedGoal(lastGoal, newGoal); lastGoal = newGoal; } return(newGoal); }
public override void OnNPCAtStockpile(ref NPCBase.NPCState state) { if (state.Inventory.IsEmpty) { Assert.IsTrue(shouldTakeItems); } else { state.Inventory.Dump(usedNPC.Colony.UsedStockpile); } state.SetCooldown(0.5); state.JobIsDone = true; if (shouldTakeItems) { shouldTakeItems = false; ScienceManagerPlayer scienceManager; if (!ScienceManager.TryGetPlayerManager(owner, out scienceManager)) { return; } ResearchProgress active = scienceManager.ActiveResearch; if (active.research != null && !active.IsCompleted) { var requirements = active.research.GetScienceRequirements(); if (Stockpile.GetStockPile(owner).TryRemove(requirements)) { state.Inventory.Add(requirements); } } } }
public virtual void OnNPCAtStockpile(ref NPCBase.NPCState state) { if (CheckTime()) { OnNPCDoStockpile(ref state); } }
public virtual void OnNPCAtJob(ref NPCBase.NPCState state) { if (CheckTime()) { OnNPCDoJob(ref state); } }
// Do shoot public void ShootAtTarget(AngryGuardJobInstance instance, ref NPCBase.NPCState state) { if (!instance.Owner.Stockpile.TryRemove(this.ShootItem)) { state.SetIndicator(new IndicatorState(this.CooldownMissingItem, this.ShootItem[0].Type, true, false), true); return; } if (this.OnShootAudio != null) { AudioManager.SendAudio(instance.eyePosition, this.OnShootAudio); } if (this.OnHitAudio != null) { AudioManager.SendAudio(instance.target.Position, this.OnHitAudio); } Vector3 positionToAimFor = instance.target.Position; positionToAimFor[1] += 1; Vector3 normalized = Vector3.Normalize(positionToAimFor - instance.eyePosition); ServerManager.SendParticleTrail(instance.eyePosition + normalized * 0.15f, positionToAimFor - normalized * 0.15f, Pipliz.Random.NextFloat(1.5f, 2.5f)); Players.TakeHit(instance.target, (float)this.Damage, instance.NPC, ModLoader.OnHitData.EHitSourceType.NPC); state.SetIndicator(new IndicatorState(this.CooldownShot, this.ShootItem[0].Type, false, true), true); if (this.OnShootResultItem.item.Type > 0 && Pipliz.Random.NextDouble(0.0, 1.0) <= this.OnShootResultItem.chance) { instance.Owner.Stockpile.Add(this.OnShootResultItem.item); } }
public virtual void OnNPCAtStockpile(BlockJobInstance instance, ref NPCBase.NPCState state) { if (!state.Inventory.IsEmpty) // its a fallback { state.Inventory.Dump(instance.Owner.Stockpile); } }
public virtual void DoJob(ConstructionJobInstance job, ref NPCBase.NPCState state) { if (ConstructionType != null) { ConstructionType.DoJob(IterationType, this, job, ref state); } }
public override void OnNPCAtStockpile(ref NPCBase.NPCState state) { if (_weapon != null) { return; } if (_playerState.CallToArmsEnabled && Items.ItemFactory.WeaponGuardSettings.Count != 0) { _weapon = GetWeapon(usedNPC); if (_weapon == null) { foreach (var w in Items.ItemFactory.WeaponGuardSettings) { if (_stock.Contains(w.recruitmentItem)) { _stock.TryRemove(w.recruitmentItem); usedNPC.Inventory.Add(w.recruitmentItem); _weapon = w; break; } } } } }
public virtual void ShootAtTarget(GuardJobInstance instance, ref NPCBase.NPCState state) { if (state.Inventory.TryRemove(GuardSettings.ShootItem)) { if (GuardSettings.OnShootAudio != null) { AudioManager.SendAudio(instance.Position.Vector, GuardSettings.OnShootAudio); } if (GuardSettings.OnHitAudio != null) { AudioManager.SendAudio(instance.Target.PositionToAimFor, GuardSettings.OnHitAudio); } UnityEngine.Vector3 start = instance.Position.Add(0, 1, 0).Vector; UnityEngine.Vector3 end = instance.Target.PositionToAimFor; UnityEngine.Vector3 dirNormalized = (end - start).normalized; ServerManager.SendParticleTrail(start + dirNormalized * 0.15f, end - dirNormalized * 0.15f, Pipliz.Random.NextFloat(1.5f, 2.5f)); instance.Target.OnHit(GuardSettings.Damage, instance.NPC, ModLoader.OnHitData.EHitSourceType.NPC); state.SetIndicator(new IndicatorState(GuardSettings.CooldownShot, GuardSettings.ShootItem[0].Type)); if (GuardSettings.OnShootResultItem.item.Type > 0 && Pipliz.Random.NextDouble(0.0, 1.0) <= (double)GuardSettings.OnShootResultItem.chance) { instance.Owner.Stockpile.Add(GuardSettings.OnShootResultItem.item); } } else { var items = GuardSettings.ShootItem.Select(i => new StoredItem(i.Type, i.Amount * 50)).ToArray(); var getitemsfromCrate = new GetItemsFromCrateGoal(instance, JobSettings, this, items); JobSettings.SetGoal(instance, new PutItemsInCrateGoal(Job, JobSettings, getitemsfromCrate, state.Inventory.Inventory), ref state); state.Inventory.Add(items); } }
public void OnNPCAtStockpile(ref NPCBase.NPCState state) { if (_weapon != null) { return; } if (_colonyState.CallToArmsEnabled) { _weapon = GetWeapon(NPC); if (_weapon == null) { foreach (BlockJobManager <GuardJobInstance> w in ServerManager.BlockEntityCallbacks.AutoLoadedInstances.Where(t => t as BlockJobManager <GuardJobInstance> != null)) { if (_stock.Contains(w.Settings.RecruitmentItem)) { _stock.TryRemove(w.Settings.RecruitmentItem); NPC.Inventory.Add(w.Settings.RecruitmentItem); _weapon = w.Settings as GuardJobSettings; break; } } } } }
public override NPCBase.NPCGoal CalculateGoal(ref NPCBase.NPCState state) { //WriteLog("CalculateGoal"); //Always return Job, we can determine the jobLocation based on the time return(NPCBase.NPCGoal.Job); }
public override void OnNPCDoStockpile(ref NPCBase.NPCState state) { state.Inventory.TryDump(usedNPC.Colony.UsedStockpile); state.JobIsDone = true; if (shouldTakeItems) { shouldTakeItems = false; var recipeMatch = Recipe.MatchRecipe(GetPossibleRecipes, usedNPC.Colony.UsedStockpile); switch (recipeMatch.MatchType) { case Recipe.RecipeMatchType.FoundMissingRequirements: case Recipe.RecipeMatchType.AllDone: OverrideCooldown(0.5); recipesToCraft = 0; break; case Recipe.RecipeMatchType.FoundCraftable: selectedRecipe = recipeMatch.FoundRecipe; recipesToCraft = Math.Min(recipeMatch.FoundRecipeCount, MaxRecipeCraftsPerHaul); for (int i = 0; i < selectedRecipe.Requirements.Count; i++) { state.Inventory.Add(selectedRecipe.Requirements[i] * recipesToCraft); usedNPC.Colony.UsedStockpile.Remove(selectedRecipe.Requirements[i] * recipesToCraft); } OverrideCooldown(0.5); break; } } }
public override void OnNPCAtJob(ref NPCBase.NPCState state) { if (TimeCycle.TotalTime > SickTime + Configuration.LengthOfDiseaseInDays) { OnRemovedNPC(); } }
public void PerformGoal(ref NPCBase.NPCState state) { Pipliz.Vector3Int position = GuardJob.Position; state.SetCooldown(1); state.JobIsDone = true; if (!Job.NPC.Inventory.Contains(GuardSettings.ShootItem)) { Shop(Job, ref Job.NPC.state); return; } if (GuardJob.HasTarget) { UnityEngine.Vector3 npcPos = position.Add(0, 1, 0).Vector; UnityEngine.Vector3 targetPos = GuardJob.Target.PositionToAimFor; if (VoxelPhysics.CanSee(npcPos, targetPos)) { GuardJob.NPC.LookAt(targetPos); ShootAtTarget(GuardJob, ref state); return; } } GuardJob.Target = MonsterTracker.Find(position.Add(0, 1, 0), GuardSettings.Range, GuardSettings.Damage); if (GuardJob.HasTarget) { GuardJob.NPC.LookAt(GuardJob.Target.PositionToAimFor); ShootAtTarget(GuardJob, ref state); return; } state.SetCooldown(GuardSettings.CooldownSearchingTarget * Pipliz.Random.NextFloat(0.9f, 1.1f)); UnityEngine.Vector3 pos = GuardJob.NPC.Position.Vector; if (GuardSettings.BlockTypes.ContainsByReference(GuardJob.BlockType, out int index)) { switch (index) { case 1: pos.x += 1f; break; case 2: pos.x -= 1f; break; case 3: pos.z += 1f; break; case 4: pos.z -= 1f; break; } } GuardJob.NPC.LookAt(pos); }
protected bool TryDumpNPCInventory(ref NPCBase.NPCState npcState) { if (!npcState.Inventory.IsEmpty) { npcState.Inventory.Dump(usedNPC.Colony.UsedStockpile); } return(true); }
public virtual void GetItemsFromCrate(ref NPCBase.NPCState state) { if (recipeMatch.FoundRecipe != null) { state.SetCooldown(0.4, 0.6); state.Inventory.Add(recipeMatch.FoundRecipe.Requirements.ToList(), recipeMatch.FoundRecipeCount); PandaJobFactory.SetActiveGoal(Job, new GetItemsFromCrateGoal(Job, JobInstance.Position, this, recipeMatch.FoundRecipe.Requirements, this), ref state); } }
public override void OnNPCDoStockpile(ref NPCBase.NPCState state) { state.Inventory.TryDump(usedNPC.Colony.UsedStockpile); if (todoblocks.Count < 1) { ServerManager.TryChangeBlock(position, BlockTypes.Builtin.BuiltinBlocks.Air); return; } state.JobIsDone = true; if (!ToSleep) { shouldTakeItems = true; for (int i = todoblocks.Count - 1; i >= 0; i--) { BlueprintTodoBlock block = todoblocks[i]; if (!block.typename.Equals("air")) { ushort typeindex; if (ItemTypes.IndexLookup.TryGetIndex(TypeHelper.RotatableToBasetype(block.typename), out typeindex)) { if (usedNPC.Colony.UsedStockpile.TryRemove(typeindex, 1)) { shouldTakeItems = false; state.Inventory.Add(typeindex, 1); if (state.Inventory.UsedCapacity >= state.Inventory.Capacity) // workaround for capacity issue { if (state.Inventory.TryGetOneItem(typeindex)) { usedNPC.Colony.UsedStockpile.Add(typeindex, 1); } return; } } } else { Chat.Send(usedNPC.Colony.Owner, string.Format("Bob here from site at {0}, the item type '{1}' does not exist. Ignoring it...", position, block.typename)); todoblocks.RemoveAt(i); } } else { shouldTakeItems = false; } } } if (todoblocks.Count < 1) { ServerManager.TryChangeBlock(position, BlockTypes.Builtin.BuiltinBlocks.Air); return; } else if (shouldTakeItems) { state.JobIsDone = false; state.SetIndicator(NPCIndicatorType.MissingItem, 6f, ItemTypes.IndexLookup.GetIndex(todoblocks[todoblocks.Count - 1].typename)); } }
private void Shop(IJob instance, ref NPCBase.NPCState state) { var items = GuardSettings.ShootItem.Select(i => new StoredItem(i.Type, i.Amount * 50)).ToArray(); var getitemsfromCrate = new GetItemsFromCrateGoal(instance, GuardJob.Position, this, items, this); PandaJobFactory.SetActiveGoal(instance, new PutItemsInCrateGoal(Job, GuardJob.Position, getitemsfromCrate, state.Inventory.Inventory, this), ref state); state.Inventory.Inventory.Clear(); state.Inventory.Add(items); }
public NPCBase.NPCGoal CalculateGoal(ref NPCBase.NPCState state) { if (_weapon == null) { return(NPCBase.NPCGoal.Stockpile); } return(NPCBase.NPCGoal.Job); }
public void OnNPCAtStockpile(ref NPCBase.NPCState state) { bool hasItem = GetBestWeapon(); if (!hasItem) { state.SetIndicator(NPCIndicatorType.MissingItem, COOLDOWN, Items.ItemFactory.WeaponLookup.FirstOrDefault().Key); } }
public override void OnNPCDoJob(ref NPCBase.NPCState state) { if (target != null && target.IsValid) { Vector3 npcPos = usedNPC.Position + Vector3.up; Vector3 targetPos = target.Position + Vector3.up; if (General.Physics.Physics.CanSee(npcPos, targetPos)) { usedNPC.LookAt(targetPos); if (Stockpile.GetStockPile(owner).Remove(BuiltinBlocks.Arrow, 1)) { Arrow.New(npcPos, targetPos, target.Direction); AddXP(); OverrideCooldown(5.0); } else { state.SetIndicator(NPCIndicatorType.MissingItem, 1.5f, BuiltinBlocks.Arrow); OverrideCooldown(1.5); } } else { target = null; } } if (target == null || !target.IsValid) { target = ZombieTracker.Find(position.Add(0, 1, 0), 20); if (target == null) { Vector3 desiredPosition = usedNPC.Position; if (quiverType == BuiltinBlocks.QuiverXN) { desiredPosition += Vector3.left; } else if (quiverType == BuiltinBlocks.QuiverXP) { desiredPosition += Vector3.right; } else if (quiverType == BuiltinBlocks.QuiverZP) { desiredPosition += Vector3.forward; } else if (quiverType == BuiltinBlocks.QuiverZN) { desiredPosition += Vector3.back; } usedNPC.LookAt(desiredPosition); } else { OverrideCooldown(0.3); } } }
private NPCBase.NPCState DestoryJob(NPCBase.NPCState state, MinerJobInstance instance) { ThreadManager.InvokeOnMainThread(delegate { ServerManager.TryChangeBlock(instance.Position, instance.BlockType, BuiltinBlocks.Types.air, instance.Owner); }); instance.Owner.Stockpile.Add(MinerSettings.RecruitmentItem.Type, MinerSettings.RecruitmentItem.Amount); state.SetCooldown(2.5, 5.0); return(state); }