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); }
public override Vector3Int GetJobLocation() { var currentPos = usedNPC.Position; if (_playerState.CallToArmsEnabled && _weapon != null) { _target = MonsterTracker.Find(currentPos, _weapon.range, _weapon.shootDamage); if (_target != null) { return(currentPos); } else { _target = MonsterTracker.Find(currentPos, CALL_RAD, _weapon.shootDamage); if (_target != null) { var ranged = _weapon.range - 5; if (ranged < 0) { ranged = 1; } position = new Vector3Int(_target.Position).Add(ranged, 0, ranged); position = Server.AI.AIManager.ClosestPosition(position, currentPos); if (!Server.AI.AIManager.CanStandAt(position)) { _tmpVals.Set(COOLDOWN_KEY, _weapon.cooldownMissingItem); _waitingFor++; } else { return(position); } } else { _tmpVals.Set(COOLDOWN_KEY, _weapon.cooldownMissingItem); _waitingFor++; } } } if (_waitingFor > 10) { var banner = BannerManager.GetClosestBanner(usedNPC.Colony.Owner, currentPos); if (banner != null) { return(banner.KeyLocation); } } return(currentPos); }
public Vector3Int GetJobLocation() { var currentPos = NPC.Position; if (_colonyState.CallToArmsEnabled && _weapon != null) { _target = MonsterTracker.Find(currentPos, _weapon.Range, _weapon.Damage); if (_target != null) { return(currentPos); } _target = MonsterTracker.Find(currentPos, CALL_RAD, _weapon.Damage); if (_target != null) { var ranged = _weapon.Range - 5; if (ranged < 0) { ranged = 1; } Position = new Vector3Int(_target.Position).Add(ranged, 0, ranged); PathingManager.TryCanStandNear(Position, out var canStandNear, out var newPosition); if (!canStandNear || (!PathingManager.TryCanStandAt(newPosition, out var canStand) && canStand)) { _tmpVals.SetAs(COOLDOWN_KEY, _weapon.CooldownMissingItem); _waitingFor++; } else { return(Position); } } else { _tmpVals.SetAs(COOLDOWN_KEY, _weapon.CooldownMissingItem); _waitingFor++; } } if (_waitingFor > 10) { var banner = NPC.Colony.GetClosestBanner(currentPos); if (banner != null) { return(banner.Position); } } return(currentPos); }
public override void OnNPCAtJob(ref NPCBase.NPCState state) { if (TimeCycle.TotalTime > RecruitedTime + Configuration.MititiaTermOfDuty) { OnRemovedNPC(); } if (HasTarget) { Vector3 npcPos = position.Add(0, 1, 0).Vector; Vector3 targetPos = target.PositionToAimFor; if (General.Physics.Physics.CanSee(npcPos, targetPos)) { usedNPC.LookAt(targetPos); ShootAtTarget(ref state); // <- sets cooldown return; } else { target = null; } } target = MonsterTracker.Find(position.Add(0, 1, 0), guardsettings.range, guardsettings.shootDamage); if (HasTarget) { usedNPC.LookAt(target.PositionToAimFor); ShootAtTarget(ref state); // <- sets cooldown } else { state.SetCooldown(guardsettings.cooldownSearchingTarget); Vector3 pos = usedNPC.Position.Vector; if (blockType == guardsettings.typeXP) { pos += Vector3.right; } else if (blockType == guardsettings.typeXN) { pos += Vector3.left; } else if (blockType == guardsettings.typeZP) { pos += Vector3.forward; } else if (blockType == guardsettings.typeZN) { pos += Vector3.back; } usedNPC.LookAt(pos); } }
public override void OnNPCAtJob(ref NPCBase.NPCState state) { if (HasTarget) { Vector3 npcPos = position.Add(0, 1, 0).Vector; Vector3 targetPos = target.PositionToAimFor; if (General.Physics.Physics.CanSee(npcPos, targetPos)) { usedNPC.LookAt(targetPos); ShootAtTarget(ref state); // <- sets cooldown return; } else { target = null; } } target = MonsterTracker.Find(position.Add(0, 1, 0), guardSettings.range, guardSettings.shootDamage); if (HasTarget) { usedNPC.LookAt(target.PositionToAimFor); ShootAtTarget(ref state); // <- sets cooldown } else { state.SetCooldown(guardSettings.cooldownSearchingTarget); if (worldTypeChecked) { Vector3 pos = usedNPC.Position.Vector; if (worldType == guardSettings.typeXP) { pos += Vector3.right; } else if (worldType == guardSettings.typeXN) { pos += Vector3.left; } else if (worldType == guardSettings.typeZP) { pos += Vector3.forward; } else if (worldType == guardSettings.typeZN) { pos += Vector3.back; } usedNPC.LookAt(pos); } } }
public static void CheckIfMonstersNearby() { if (ServerManager.ColonyTracker != null) { var punchDamage = 30; foreach (var colony in ServerManager.ColonyTracker.ColoniesByID.Values) { if (colony.DifficultySetting.ShouldSpawnZombies(colony)) { foreach (var npc in colony.Followers) { var inv = Entities.ColonistInventory.Get(npc); if (inv.Weapon != null && !inv.Weapon.IsEmpty()) { var target = MonsterTracker.Find(npc.Position, 2, punchDamage); if (target != null && target.IsValid) { npc.LookAt(target.Position); AudioManager.SendAudio(target.PositionToAimFor, "punch"); if (inv.Weapon != null && !inv.Weapon.IsEmpty()) { target.OnHit(WeaponFactory.WeaponLookup[inv.Weapon.Id].Damage.TotalDamage()); } else { target.OnHit(punchDamage); } } } } } } } }
public void OnNPCAtJob(ref NPCBase.NPCState state) { if (CheckTime()) { Items.Armor.GetBestArmorForNPC(_stock, _usedNPC, _inv, 0); try { var currentposition = _usedNPC.Position; if (_target == null || !_target.IsValid || !General.Physics.Physics.CanSee(_usedNPC.Position.Vector, _target.Position)) { _target = MonsterTracker.Find(currentposition, 1, Items.ItemFactory.WeaponLookup[_inv.Weapon.Id].Damage); } if (_target != null && General.Physics.Physics.CanSee(_usedNPC.Position.Vector, _target.Position)) { state.SetIndicator(NPCIndicatorType.Crafted, COOLDOWN, _inv.Weapon.Id); _usedNPC.LookAt(_target.Position); ServerManager.SendAudio(_target.PositionToAimFor, "punch"); _target.OnHit(Items.ItemFactory.WeaponLookup[_inv.Weapon.Id].Damage); _waitingFor = 0; } else { state.SetIndicator(NPCIndicatorType.MissingItem, COOLDOWN, GameLoader.MissingMonster_Icon); _waitingFor++; _target = null; } } catch (Exception ex) { PandaLogger.LogError(ex); } } }
public static void DoWork(Players.Player player, MachineState machineState) { try { if (TurretSettings.ContainsKey(machineState.MachineType) && machineState.Durability > 0 && machineState.Fuel > 0 && machineState.NextTimeForWork < Time.SecondsSinceStartDouble) { var stockpile = Stockpile.GetStockPile(player); machineState.Durability -= TurretSettings[machineState.MachineType].DurabilityPerDoWork; machineState.Fuel -= TurretSettings[machineState.MachineType].FuelPerDoWork; if (machineState.Durability < 0) { machineState.Durability = 0; } if (machineState.Fuel <= 0) { machineState.Fuel = 0; } if (machineState.Load > 0) { var monster = MonsterTracker.Find(machineState.Position.Add(0, 1, 0), TurretSettings[machineState.MachineType].Range, TurretSettings[machineState.MachineType].Damage); if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(1, 0, 0), TurretSettings[machineState.MachineType].Range, TurretSettings[machineState.MachineType].Damage); } if (monster == null) { MonsterTracker.Find(machineState.Position.Add(-1, 0, 0), TurretSettings[machineState.MachineType].Range, TurretSettings[machineState.MachineType].Damage); } if (monster == null) { MonsterTracker.Find(machineState.Position.Add(0, -1, 0), TurretSettings[machineState.MachineType].Range, TurretSettings[machineState.MachineType].Damage); } if (monster == null) { MonsterTracker.Find(machineState.Position.Add(0, 0, 1), TurretSettings[machineState.MachineType].Range, TurretSettings[machineState.MachineType].Damage); } if (monster == null) { MonsterTracker.Find(machineState.Position.Add(0, 0, -1), TurretSettings[machineState.MachineType].Range, TurretSettings[machineState.MachineType].Damage); } if (monster != null) { machineState.Load -= TurretSettings[machineState.MachineType].AmmoValue; if (machineState.Load < 0) { machineState.Load = 0; } if (TurretSettings[machineState.MachineType].OnShootAudio != null) { ServerManager.SendAudio(machineState.Position.Vector, TurretSettings[machineState.MachineType].OnShootAudio); } if (TurretSettings[machineState.MachineType].OnHitAudio != null) { ServerManager.SendAudio(monster.PositionToAimFor, TurretSettings[machineState.MachineType].OnHitAudio); } TurretSettings[machineState.MachineType].ProjectileAnimation.SendMoveToInterpolatedOnce(machineState.Position.Vector, monster.PositionToAimFor); monster.OnHit(TurretSettings[machineState.MachineType].Damage); } } machineState.NextTimeForWork = machineState.MachineSettings.WorkTime + Time.SecondsSinceStartDouble; } } catch (Exception ex) { PandaLogger.LogError(ex, $"Turret shoot for {machineState.MachineType}"); } }
public static void DoWork(Players.Player player, MachineState machineState) { if (!player.IsConnected && Configuration.OfflineColonies || player.IsConnected) { try { if (TurretSettings.ContainsKey(machineState.MachineType) && machineState.Durability > 0 && machineState.Fuel > 0 && machineState.NextTimeForWork < Time.SecondsSinceStartDouble) { var stockpile = Stockpile.GetStockPile(player); machineState.Durability -= TurretSettings[machineState.MachineType].DurabilityPerDoWork; machineState.Fuel -= TurretSettings[machineState.MachineType].FuelPerDoWork; if (machineState.Durability < 0) { machineState.Durability = 0; } if (machineState.Fuel <= 0) { machineState.Fuel = 0; } if (machineState.Load > 0) { var totalDamage = TurretSettings[machineState.MachineType].TotalDamage; var monster = MonsterTracker.Find(machineState.Position.Add(0, 1, 0), TurretSettings[machineState.MachineType].Range, totalDamage); if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(1, 0, 0), TurretSettings[machineState.MachineType].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(-1, 0, 0), TurretSettings[machineState.MachineType].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(0, -1, 0), TurretSettings[machineState.MachineType].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(0, 0, 1), TurretSettings[machineState.MachineType].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(0, 0, -1), TurretSettings[machineState.MachineType].Range, totalDamage); } if (monster != null) { machineState.Load -= TurretSettings[machineState.MachineType].AmmoValue; Indicator.SendIconIndicatorNear(machineState.Position.Add(0, 1, 0).Vector, new IndicatorState(TurretSettings[machineState.MachineType].WorkTime, TurretSettings [machineState.MachineType] .Ammo.FirstOrDefault().Type)); if (machineState.Load < 0) { machineState.Load = 0; } if (TurretSettings[machineState.MachineType].OnShootAudio != null) { ServerManager.SendAudio(machineState.Position.Vector, TurretSettings[machineState.MachineType].OnShootAudio); } if (TurretSettings[machineState.MachineType].OnHitAudio != null) { ServerManager.SendAudio(monster.PositionToAimFor, TurretSettings[machineState.MachineType].OnHitAudio); } TurretSettings[machineState.MachineType] .ProjectileAnimation .SendMoveToInterpolatedOnce(machineState.Position.Vector, monster.PositionToAimFor); monster.OnHit(totalDamage, machineState, ModLoader.OnHitData.EHitSourceType.Misc); } } machineState.NextTimeForWork = machineState.MachineSettings.WorkTime + Time.SecondsSinceStartDouble; } } catch (Exception ex) { PandaLogger.LogError(ex, $"Turret shoot for {machineState.MachineType}"); } } }
public static void DoWork(Colony colony, RoamingJobState machineState) { try { if (TurretSettings.ContainsKey(machineState.RoamObjective) && machineState.GetActionEnergy(MachineConstants.REPAIR) > 0 && machineState.GetActionEnergy(MachineConstants.REFUEL) > 0 && machineState.NextTimeForWork < Time.SecondsSinceStartDouble) { var stockpile = colony.Stockpile; machineState.SubtractFromActionEnergy(MachineConstants.REPAIR, TurretSettings[machineState.RoamObjective].DurabilityPerDoWork); machineState.SubtractFromActionEnergy(MachineConstants.REFUEL, TurretSettings[machineState.RoamObjective].FuelPerDoWork); if (machineState.GetActionEnergy(MachineConstants.RELOAD) > 0) { var totalDamage = TurretSettings[machineState.RoamObjective].TotalDamage; var monster = MonsterTracker.Find(machineState.Position.Add(0, 1, 0), TurretSettings[machineState.RoamObjective].Range, totalDamage); if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(1, 0, 0), TurretSettings[machineState.RoamObjective].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(-1, 0, 0), TurretSettings[machineState.RoamObjective].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(0, -1, 0), TurretSettings[machineState.RoamObjective].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(0, 0, 1), TurretSettings[machineState.RoamObjective].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(0, 0, -1), TurretSettings[machineState.RoamObjective].Range, totalDamage); } if (monster != null) { machineState.SubtractFromActionEnergy(MachineConstants.RELOAD, TurretSettings[machineState.RoamObjective].AmmoValue); if (World.TryGetTypeAt(machineState.Position.Add(0, 1, 0), out ushort above) && above == ColonyBuiltIn.ItemTypes.AIR.Id) { Indicator.SendIconIndicatorNear(machineState.Position.Add(0, 1, 0).Vector, new IndicatorState(TurretSettings[machineState.RoamObjective].WorkTime, TurretSettings[machineState.RoamObjective].Ammo.FirstOrDefault().Type)); } if (TurretSettings[machineState.RoamObjective].OnShootAudio != null) { AudioManager.SendAudio(machineState.Position.Vector, TurretSettings[machineState.RoamObjective].OnShootAudio); } if (TurretSettings[machineState.RoamObjective].OnHitAudio != null) { AudioManager.SendAudio(monster.PositionToAimFor, TurretSettings[machineState.RoamObjective].OnHitAudio); } TurretSettings[machineState.RoamObjective] .ProjectileAnimation .SendMoveToInterpolated(machineState.Position.Vector, monster.PositionToAimFor); ServerManager.SendParticleTrail(machineState.Position.Vector, monster.PositionToAimFor, 2); monster.OnHit(totalDamage, machineState, ModLoader.OnHitData.EHitSourceType.Misc); } } machineState.NextTimeForWork = machineState.RoamingJobSettings.WorkTime + Time.SecondsSinceStartDouble; } } catch (Exception ex) { SettlersLogger.LogError(ex, $"Turret shoot for {machineState.RoamObjective}"); } }
public void OnNPCAtJob(ref NPCBase.NPCState state) { try { var currentposition = NPC.Position; _hadAmmo.Clear(); if (_inv.Weapon != null && !_inv.Weapon.IsEmpty()) { if (_target == null || !_target.IsValid) { _target = MonsterTracker.Find(currentposition, 100, WeaponFactory.WeaponLookup[_inv.Weapon.Id].Damage.TotalDamage()); } if (_target != null && _target.IsValid) { state.SetIndicator(new IndicatorState(COOLDOWN, _inv.Weapon.Id)); state.SetCooldown(COOLDOWN); NPC.LookAt(_target.Position); AudioManager.SendAudio(_target.PositionToAimFor, "punch"); _target.OnHit(WeaponFactory.WeaponLookup[_inv.Weapon.Id].Damage.TotalDamage()); _waitingFor = 0; } else { state.SetIndicator(new IndicatorState(COOLDOWN, ItemId.GetItemId(GameLoader.NAMESPACE + ".Monster").Id, true)); state.SetCooldown(COOLDOWN); _waitingFor++; _target = null; } } else { if (_target == null || !_target.IsValid || !VoxelPhysics.CanSee(NPC.Position.Vector, _target.Position)) { _target = MonsterTracker.Find(currentposition, _weapon.Range, _weapon.Damage); } if (_target != null && _target.IsValid && VoxelPhysics.CanSee(NPC.Position.Vector, _target.Position)) { foreach (var projectile in _weapon.ShootItem) { _hadAmmo[projectile] = false; if (NPC.Inventory.Contains(projectile)) { _hadAmmo[projectile] = true; continue; } if (_stock.Contains(projectile)) { _hadAmmo[projectile] = true; } } if (!_hadAmmo.Any(a => !a.Value)) { state.SetIndicator(new IndicatorState(_weapon.CooldownShot, _weapon.ShootItem[0].Type)); foreach (var ammo in _hadAmmo) { if (NPC.Inventory.Contains(ammo.Key)) { NPC.Inventory.TryRemove(ammo.Key); continue; } if (_stock.Contains(ammo.Key)) { _stock.TryRemove(ammo.Key); } } NPC.LookAt(_target.Position); if (_weapon.OnShootAudio != null) { AudioManager.SendAudio(Position.Vector, _weapon.OnShootAudio); } if (_weapon.OnHitAudio != null) { AudioManager.SendAudio(_target.PositionToAimFor, _weapon.OnHitAudio); } if (_weapon.ShootItem.Count > 0) { foreach (var proj in _weapon.ShootItem) { var projName = ItemTypes.IndexLookup.GetName(proj.Type); if (AnimationManager.AnimatedObjects.ContainsKey(projName)) { AnimationManager.AnimatedObjects[projName].SendMoveToInterpolated(Position.Vector, _target.PositionToAimFor); break; } } } ServerManager.SendParticleTrail(currentposition.Vector, _target.PositionToAimFor, 2); _target.OnHit(_weapon.Damage); state.SetCooldown(_weapon.CooldownShot); _waitingFor = 0; } else { state.SetIndicator(new IndicatorState(_weapon.CooldownMissingItem, _weapon.ShootItem[0].Type, true)); state.SetCooldown(_weapon.CooldownMissingItem); } } else { state.SetIndicator(new IndicatorState(_weapon.CooldownSearchingTarget, ItemId.GetItemId(GameLoader.NAMESPACE + ".Monster").Id, true)); state.SetCooldown(_weapon.CooldownMissingItem); _target = null; } } } catch (Exception) { state.SetIndicator(new IndicatorState(_weapon.CooldownSearchingTarget, ItemId.GetItemId(GameLoader.NAMESPACE + ".Monster").Id, true)); state.SetCooldown(_weapon.CooldownMissingItem); _target = null; } }
public override void OnNPCAtJob(ref NPCBase.NPCState state) { float cooldown = HeraldJob.StaticCraftingCooldown; ushort status = GameLoader.Waiting_Icon; if (PlayerState.GetPlayerState(player).EnableHeraldWarning) { IMonster monster = MonsterTracker.Find(originalPosition.Add(0, 1, 0), Configuration.HeraldWarningDistance, 500.0f); if (monster == null) { monster = MonsterTracker.Find(originalPosition.Add(1, 0, 0), Configuration.HeraldWarningDistance, 500.0f); } if (monster == null) { monster = MonsterTracker.Find(originalPosition.Add(-1, 0, 0), Configuration.HeraldWarningDistance, 500.0f); } if (monster == null) { monster = MonsterTracker.Find(originalPosition.Add(0, -1, 0), Configuration.HeraldWarningDistance, 500.0f); } if (monster == null) { monster = MonsterTracker.Find(originalPosition.Add(0, 0, 1), Configuration.HeraldWarningDistance, 500.0f); } if (monster == null) { monster = MonsterTracker.Find(originalPosition.Add(0, 0, -1), Configuration.HeraldWarningDistance, 500.0f); } if (monster != null) { if (General.Physics.Physics.CanSee(originalPosition.Add(0, 1, 0).Vector, monster.PositionToAimFor) && TimeCycle.TotalTime >= lastRally + Configuration.MilitiaRallyCooldown) { ServerManager.SendAudio(owner.Position, GameLoader.NAMESPACE + ".Rally"); status = GameLoader.Trumpeting_Icon; if (Configuration.AllowMilitiaToBeCalled && MilitiaList.Count == 0 && PlayerState.GetPlayerState(player).EnableMilitia) { lastRally = TimeCycle.TotalTime; ActivateMilitia(player, originalPosition); } } } } if (TimeCycle.IsDay) { if (PlayerState.GetPlayerState(player).EnableHeraldAnnouncingSunrise) { if (TimeCycle.TimeOfDay > TimeCycle.SunRise && TimeCycle.TimeOfDay < TimeCycle.SunRise + 1 && TimeCycle.TotalTime > lastDayTrumpeted + 1) { Logger.Log("SunRise trumpeted at {0} the Last Day Trumpeted at {1}", TimeCycle.TotalTime, lastDayTrumpeted); lastDayTrumpeted = TimeCycle.TotalTime + TimeCycle.DayLength; ServerManager.SendAudio(owner.Position, GameLoader.NAMESPACE + ".DayAudio"); cooldown = 20f; status = GameLoader.Trumpeting_Icon; } } } if (!TimeCycle.IsDay) { if (PlayerState.GetPlayerState(player).EnableHeraldAnnouncingSunset) { if (TimeCycle.TimeOfDay > TimeCycle.SunSet && TimeCycle.TimeOfDay < TimeCycle.SunSet + 1 && TimeCycle.TotalTime > lastNightTrumpeted + 1) { Logger.Log("SunSet trumpeted at {0} the Last Night Trumpeted at {1}", TimeCycle.TotalTime, lastNightTrumpeted); lastNightTrumpeted = TimeCycle.TotalTime + TimeCycle.DayLength; ServerManager.SendAudio(owner.Position, GameLoader.NAMESPACE + ".NightAudio"); cooldown = 20f; status = GameLoader.Trumpeting_Icon; } } } state.SetIndicator(new Shared.IndicatorState(cooldown, status)); }
public override void OnNPCAtJob(ref NPCBase.NPCState state) { try { var currentposition = usedNPC.Position; _hadAmmo.Clear(); if (_target == null || !_target.IsValid || !General.Physics.Physics.CanSee(usedNPC.Position.Vector, _target.Position)) { _target = MonsterTracker.Find(currentposition, _weapon.range, _weapon.shootDamage); } if (_target != null && General.Physics.Physics.CanSee(usedNPC.Position.Vector, _target.Position)) { foreach (var projectile in _weapon.shootItem) { _hadAmmo[projectile] = false; if (usedNPC.Inventory.Contains(projectile)) { _hadAmmo[projectile] = true; continue; } if (_stock.Contains(projectile)) { _hadAmmo[projectile] = true; } } if (!_hadAmmo.Any(a => !a.Value)) { state.SetIndicator(NPCIndicatorType.Crafted, _weapon.cooldownShot, _weapon.shootItem[0].Type); foreach (var ammo in _hadAmmo) { if (usedNPC.Inventory.Contains(ammo.Key)) { usedNPC.Inventory.TryRemove(ammo.Key); continue; } if (_stock.Contains(ammo.Key)) { _stock.TryRemove(ammo.Key); } } usedNPC.LookAt(_target.Position); if (_weapon.OnShootAudio != null) { ServerManager.SendAudio(position.Vector, _weapon.OnShootAudio); } if (_weapon.OnHitAudio != null) { ServerManager.SendAudio(_target.PositionToAimFor, _weapon.OnHitAudio); } if (_weapon.shootItem.Count > 0) { foreach (var proj in _weapon.shootItem) { string projName = ItemTypes.IndexLookup.GetName(proj.Type); if (AnimationManager.AnimatedObjects.ContainsKey(projName)) { AnimationManager.AnimatedObjects[projName].SendMoveToInterpolatedOnce(position.Vector, _target.PositionToAimFor); break; } } } _target.OnHit(_weapon.shootDamage); state.SetCooldown(_weapon.cooldownShot); _waitingFor = 0; } else { state.SetIndicator(NPCIndicatorType.MissingItem, _weapon.cooldownMissingItem, _weapon.shootItem[0].Type); state.SetCooldown(_weapon.cooldownMissingItem); } } else { state.SetIndicator(NPCIndicatorType.MissingItem, _weapon.cooldownSearchingTarget, GameLoader.MissingMonster_Icon); state.SetCooldown(_weapon.cooldownMissingItem); _target = null; } } catch (Exception ex) { #if DEBUG PandaLogger.LogError(ex); #endif state.SetIndicator(NPCIndicatorType.MissingItem, _weapon.cooldownSearchingTarget, GameLoader.MissingMonster_Icon); state.SetCooldown(_weapon.cooldownMissingItem); _target = null; } }
public Vector3Int GetJobLocation() { var currentPos = _usedNPC.Position; GetBestWeapon(); _target = MonsterTracker.Find(currentPos, 1, Items.ItemFactory.WeaponLookup[_inv.Weapon.Id].Damage); if (_target != null) { return(currentPos); } else { _target = MonsterTracker.Find(PatrolPoints[_currentPatrolPos], 10, Items.ItemFactory.WeaponLookup[_inv.Weapon.Id].Damage); if (_target != null) { _position = new Vector3Int(_target.Position).Add(1, 0, 0); _position = Server.AI.AIManager.ClosestPosition(_position, currentPos); if (!Server.AI.AIManager.CanStandAt(_position)) { _waitingFor++; } else { return(_position); } } else { _waitingFor++; } } if (_waitingFor > 1) { currentPos = PatrolPoints[_currentPatrolPos]; _timeAtPatrol++; _waitingFor = 0; } if (_timeAtPatrol > 1) { _timeAtPatrol = 0; _waitingFor = 0; if (PatrolPoints.Count > 1) { if (PatrolType == PatrolType.RoundRobin || (_forward && PatrolType == PatrolType.Zipper)) { _currentPatrolPos++; if (_currentPatrolPos > PatrolPoints.Count - 1) { if (_forward && PatrolType == PatrolType.Zipper) { _currentPatrolPos -= 2; _forward = false; } else { _currentPatrolPos = 0; } } } else { _currentPatrolPos--; if (_currentPatrolPos < 0) { _currentPatrolPos = 0; _currentPatrolPos++; _forward = true; } } } currentPos = PatrolPoints[_currentPatrolPos]; // if our flag is gone, remove the job. if (World.TryGetTypeAt(PatrolPoints[_currentPatrolPos], out var objType) && objType != PatrolTool.PatrolFlag.ItemIndex) { var stockPile = Stockpile.GetStockPile(Owner); UsedNPC.ClearJob(); Knights[Owner].Remove(this); if (((JobTracker.JobFinder)JobTracker.GetOrCreateJobFinder(Owner)).openJobs.Contains(this)) { ((JobTracker.JobFinder)JobTracker.GetOrCreateJobFinder(Owner)).openJobs.Remove(this); } foreach (var flagPoint in PatrolPoints) { if (World.TryGetTypeAt(flagPoint, out var flagType) && flagType == PatrolTool.PatrolFlag.ItemIndex) { ServerManager.TryChangeBlock(flagPoint, BuiltinBlocks.Air); stockPile.Add(PatrolTool.PatrolFlag.ItemIndex); } } } } return(currentPos); }