public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } BaseNpc animal = null; float sqrDistance = Single.MaxValue; for (int i = 0; i < npcContext.AnimalsInRange.Count; i++) { AnimalInfo item = npcContext.AnimalsInRange[i]; if (item.Animal != null && item.SqrDistance < sqrDistance) { sqrDistance = item.SqrDistance; animal = item.Animal; } } if (!(animal != null) || !AnimalReasoner.IsNearby(npcContext.Domain, sqrDistance)) { npcContext.SetFact(Facts.NearbyAnimal, false, true, true, true); return; } npcContext.Memory.RememberPrimaryAnimal(animal); npcContext.SetFact(Facts.NearbyAnimal, true, true, true, true); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { NPCTurretContext npcContext = npc.AiDomain.NpcContext as NPCTurretContext; if (npcContext == null) { return; } BaseNpc animal = null; float sqrDistance = Single.MaxValue; for (int i = 0; i < npcContext.AnimalsInRange.Count; i++) { AnimalInfo item = npcContext.AnimalsInRange[i]; if (item.Animal != null && item.SqrDistance < sqrDistance) { sqrDistance = item.SqrDistance; animal = item.Animal; } } if (animal != null) { AttackEntity firearm = npcContext.Domain.GetFirearm(); if (sqrDistance < npc.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm)) { npcContext.Memory.RememberPrimaryAnimal(animal); npcContext.SetFact(Facts.NearbyAnimal, true, true, true, true); return; } } npcContext.SetFact(Facts.NearbyAnimal, false, true, true, true); }
public override bool Execute(SkillArgs Args) { Master_ = Args.Master; SkillID_ = Args.Skill.SkillID; EventManager.Register <NpcSkillEvent>(OnNpcSkillEvent); return(true); }
private GameObject CreateHeroItem(BaseNpc Npc) { var Obj = AssetManager.CreatePrefabSync(new AssetUri("prefabs/heroitem.prefab")); Obj.transform.SetParent(ListContent_, false); if (Current_ != null && Current_.ID == Npc.ID) { UIHelper.SetActive(Obj.transform, "Selected", true); } else { UIHelper.SetActive(Obj.transform, "Selected", false); } UIHelper.GetComponent <Text>(Obj.transform, "Name").text = Npc.Name; // temp head icon if (Npc.ID == PlayerManager.Master.ID) { UIHelper.GetComponent <Image>(Obj.transform, "Icon").sprite = AssetManager.CreateAssetSync <Sprite>(new AssetUri("textures/build.png")); } UIHelper.AddEvent(Obj.transform, () => { SetCurrent(Npc); }); /*Obj.GetComponent<Button>().onClick.AddListener(() => * { * SetCurrent(Npc); * });*/ return(Obj); }
private void Awake() { entity = GetComponent <BaseNpc>(); action = Act.Idle; targetIgnoreDistance = ins.configData.Options.AttackDistance; healthModifier = ins.configData.NPCMods.Health; speedModifier = ins.configData.NPCMods.Speed; attackModifier = ins.configData.NPCMods.Attack; nextMessageTime = UnityEngine.Time.realtimeSinceStartup; inventory = new ItemContainer(); inventory.ServerInitialize(null, 6); if ((int)inventory.uid == 0) { inventory.GiveUID(); } entity.enableSaving = false; BaseEntity.saveList.Remove(entity); entity.InitializeHealth(entity.Health() * healthModifier, entity.MaxHealth() * healthModifier); entity.AttackDamage *= attackModifier; entity.Stats.TurnSpeed *= speedModifier; entity.Stats.Speed *= speedModifier; }
bool TryDmg(BaseNpc npcs) { if (!Tools.InCube(new Rectangle((int)Position.X, (int)Position.Y, BulletSizeX, BulletSizeY), new Rectangle((int)npcs.Position.X, (int)npcs.Position.Y, npcs.Width, 18))) { return(false); } npcs.Hp -= 1; if (Velocity.X >= 0) { npcs.Velocity.X += MASS / 2; } else { npcs.Velocity.X -= MASS / 2; } if ((int)npcs.Hp > 0) { return(true); } if (npcs.Type == 5) { ((Boss)npcs).Kill(); } else { npcs.Kill(); } return(true); }
static AnimalConfig GetAnimalSpeed(BaseNpc npc) { if (npc.ShortPrefabName == "horse") { return(config.Horse); } if (npc.ShortPrefabName == "wolf") { return(config.Wolf); } if (npc.ShortPrefabName == "boar") { return(config.Boar); } if (npc.ShortPrefabName == "stag") { return(config.Stag); } if (npc.ShortPrefabName == "chicken") { return(config.Chicken); } if (npc.ShortPrefabName == "bear") { return(config.Bear); } if (npc.ShortPrefabName == "zombie") { return(config.Zombie); } return(config.Chicken); }
void TryGetNewPet(BaseNpc npcPet) { var ownedAi = npcPet.GetComponent <NpcAI>(); if (ownedAi != null && ownedAi.owner != this) { UserMessage(player, "isPet"); return; } if (nextControlTime >= UnityEngine.Time.realtimeSinceStartup) { UserMessage(player, "tooFast"); return; } if (usePermissions && !ins.permission.UserHasPermission(player.UserIDString, $"pets.{npcPet.ShortPrefabName}")) { UserMessage(player, "noPerms"); return; } nextControlTime = UnityEngine.Time.realtimeSinceStartup + tameTimer; npcAi = npcPet.gameObject.AddComponent <NpcAI>(); npcAi.owner = this; UserMessage(player, "petSet"); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } BaseNpc animal = (BaseNpc)null; float sqrDistance = float.MaxValue; for (int index = 0; index < npcContext.AnimalsInRange.Count; ++index) { AnimalInfo animalInfo = npcContext.AnimalsInRange[index]; if (Object.op_Inequality((Object)animalInfo.Animal, (Object)null) && (double)animalInfo.SqrDistance < (double)sqrDistance) { sqrDistance = animalInfo.SqrDistance; animal = animalInfo.Animal; } } if (Object.op_Inequality((Object)animal, (Object)null) && AnimalReasoner.IsNearby(npcContext.Domain, sqrDistance)) { npcContext.Memory.RememberPrimaryAnimal(animal); npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.NearbyAnimal, true, true, true, true); } else { npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.NearbyAnimal, false, true, true, true); } }
public static bool InAttackRange(BaseNpc Attacker, BaseNpc Target) { var Dist = Vector2.Distance(Attacker.Position, Target.Position); var Range = GetNpcAtkRange(Attacker) + GetNpcHitRange(Target); return(Dist <= Range); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { BearContext npcContext = npc.AiDomain.NpcContext as BearContext; if (npcContext == null) { return; } BaseNpc animal = null; float sqrDistance = Single.MaxValue; for (int i = 0; i < npcContext.AnimalsInRange.Count; i++) { AnimalInfo item = npcContext.AnimalsInRange[i]; if (item.Animal != null && item.SqrDistance < sqrDistance) { sqrDistance = item.SqrDistance; animal = item.Animal; } } if (!(animal != null) || sqrDistance >= npc.AiDefinition.Engagement.SqrMediumRange) { npcContext.SetFact(Facts.NearbyAnimal, false, true, true, true); return; } npcContext.Memory.RememberPrimaryAnimal(animal); npcContext.SetFact(Facts.NearbyAnimal, true, true, true, true); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext; if (npcContext == null) { return; } BaseNpc animal = (BaseNpc)null; float num = float.MaxValue; for (int index = 0; index < npcContext.AnimalsInRange.Count; ++index) { AnimalInfo animalInfo = npcContext.AnimalsInRange[index]; if (Object.op_Inequality((Object)animalInfo.Animal, (Object)null) && (double)animalInfo.SqrDistance < (double)num) { num = animalInfo.SqrDistance; animal = animalInfo.Animal; } } if (Object.op_Inequality((Object)animal, (Object)null)) { AttackEntity firearm = npcContext.Domain.GetFirearm(); if ((double)num < (double)npc.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm)) { npcContext.Memory.RememberPrimaryAnimal(animal); npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.NearbyAnimal, true, true, true, true); return; } } npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.NearbyAnimal, false, true, true, true); }
public override float GetScore(BaseContext c, Vector3 option) { BaseNpc aIAgent = c.AIAgent as BaseNpc; if (aIAgent == null) { return(0f); } if (float.IsInfinity(aIAgent.SecondsSinceLastHeardGunshot) || float.IsNaN(aIAgent.SecondsSinceLastHeardGunshot)) { return(0f); } if ((this.WithinSeconds - aIAgent.SecondsSinceLastHeardGunshot) / this.WithinSeconds <= 0f) { return(0f); } Vector3 vector3 = option - aIAgent.transform.localPosition; float single = Vector3.Dot(aIAgent.LastHeardGunshotDirection, vector3); if (this.Arc <= single) { return(0f); } return(1f); }
public void BindMaster(BaseNpc Master) { UnBindAll(); BindMove((IsStop, Dir, Strength) => { if (IsStop) { Master.Action.StopMove(); } else { Master.Action.MoveTo(Dir * 1000, true); } }); var BindIndex = 0u; var SkillList = Master.Skill.GetSkillList(); for (var Index = SkillList.Count - 1; Index >= 0; --Index) { if (SkillList[Index].Type == SkillType.Passive) { continue; } BindSkill(BindIndex++, SkillList[Index]); if (BindIndex >= 4) { break; } } }
public static BaseSfx PlayNpcSfx(BaseNpc Master, bool IsFront, string ResName) { var Sfx = CreateSfx(ResName); Sfx.Entity.SetParent(IsFront ? Master.FrontLayer : Master.BackLayer, false); return(Sfx); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { BearDomain aiDomain = npc.AiDomain as BearDomain; if (Object.op_Equality((Object)aiDomain, (Object)null) || aiDomain.BearContext == null) { return; } AnimalsInRangeSensor.QueryResultCount = BaseEntity.Query.Server.GetInSphere(npc.transform.get_position(), npc.AiDefinition.Engagement.MediumRange, (BaseEntity[])AnimalsInRangeSensor.QueryResults, (Func <BaseEntity, bool>)(entity => { BaseNpc baseNpc = entity as BaseNpc; return(!Object.op_Equality((Object)baseNpc, (Object)null) && baseNpc.isServer && (!baseNpc.IsDestroyed && !Object.op_Equality((Object)((Component)baseNpc).get_transform(), (Object)null)) && !baseNpc.IsDead()); })); List <AnimalInfo> animalsInRange = npc.AiDomain.NpcContext.AnimalsInRange; if (AnimalsInRangeSensor.QueryResultCount > 0) { for (int index1 = 0; index1 < AnimalsInRangeSensor.QueryResultCount; ++index1) { BaseNpc queryResult = AnimalsInRangeSensor.QueryResults[index1]; Vector3 vector3 = Vector3.op_Subtraction(((Component)queryResult).get_transform().get_position(), npc.transform.get_position()); float sqrMagnitude = ((Vector3) ref vector3).get_sqrMagnitude(); if ((double)sqrMagnitude <= (double)npc.AiDefinition.Engagement.SqrMediumRange) { bool flag = false; for (int index2 = 0; index2 < animalsInRange.Count; ++index2) { AnimalInfo animalInfo = animalsInRange[index2]; if (Object.op_Equality((Object)animalInfo.Animal, (Object)queryResult)) { animalInfo.Time = time; animalInfo.SqrDistance = sqrMagnitude; animalsInRange[index2] = animalInfo; flag = true; break; } } if (!flag) { animalsInRange.Add(new AnimalInfo() { Animal = queryResult, Time = time, SqrDistance = sqrMagnitude }); } } } } for (int index = 0; index < animalsInRange.Count; ++index) { AnimalInfo animalInfo = animalsInRange[index]; if ((double)time - (double)animalInfo.Time > (double)npc.AiDefinition.Memory.ForgetAnimalInRangeTime) { animalsInRange.RemoveAt(index); --index; } } }
public NpcActorModule(BaseNpc Master) : base(Master) { Animation_ = new NpcAnimation(Master.GetComponent <Animator>()); Fsm_ = new BaseFsm(Master); Direction = NpcDirection.Right; }
public NpcAttrChangedEvent(BaseNpc Master, NpcAttrIndex Index, float OldValue, float NewValue) : base(Master) { this.Index = Index; this.OldValue = OldValue; this.NewValue = NewValue; this.ChangeValue = NewValue - OldValue; }
private object OnNpcTarget(BaseNpc npc, BaseEntity entity) { if (entity.IsNpc || entity is BaseNpc) { return(true); } return(null); }
public NpcDamageEvent(BaseNpc Master, uint AttackerID, string SourceName, float Damage, float RealValue) : base(Master) { this.AttackerID = AttackerID; this.SourceName = SourceName; this.Damage = Damage; this.RealValue = RealValue; }
private object OnNpcTarget(BaseNpc npc, BaseEntity entity) { var player = entity as BasePlayer; return(player == null || player.IsNpc || player.net?.connection == null || !IsLimited(player) ? (object)null : false); }
public PassiveSkill(SkillDescriptor Desc, BaseNpc Master, float SustainTime) : base(Desc, Master) { IsSustain_ = false; SustainTime_ = SustainTime; PassiveExecutor_ = Executor_ as PassiveExecutor; Master_ = Master; }
public NpcActionModule(BaseNpc Master) : base(Master) { TargetNpc = null; AttackerNpc = null; EventManager.Register <NpcDamageEvent>(OnNpcDamageEvent); }
private object OnNpcTarget(BaseNpc npc, BaseEntity entity) { if (entity.IsNpc) { return(false); } return(null); }
public override bool Execute(SkillArgs Args) { Master_ = Args.Master; SkillID_ = Args.Skill.SkillID; var Level = Master_.Skill.GetSkillLevel(SkillID_); Master_.Data.Attr.ApplyBase(NpcAttrIndex.AddMp, Level * 10); return(true); }
private void Awake() { npc = GetComponent <BaseNpc>(); home = npc.transform.position; distance = config.distance; time = config.timer; InvokeRepeating("CheckDistance", 1f, time); }
object OnNpcTarget(BaseNpc npc, BaseEntity target) { if ((target as BaseNpc) == null || (target is NPCPlayer)) { return(null); } return(false); }
public bool IsTarget(BaseEntity entity) { BaseNpc baseNpc = entity as BaseNpc; if (baseNpc != null && baseNpc.Stats.Family == Stats.Family) { return(false); } return(!IsThreat(entity)); }
public override float GetScore(BaseContext c) { BaseNpc aiAgent = c.AIAgent as BaseNpc; if (Object.op_Equality((Object)aiAgent, (Object)null) || float.IsInfinity(aiAgent.SecondsSinceLastHeardGunshot) || float.IsNaN(aiAgent.SecondsSinceLastHeardGunshot)) { return(0.0f); } return((this.WithinSeconds - aiAgent.SecondsSinceLastHeardGunshot) / this.WithinSeconds); }
public override float GetScore(BaseContext c) { BaseNpc aIAgent = c.AIAgent as BaseNpc; if (aIAgent != null && (Mathf.Approximately(aIAgent.LastSetDestinationTime, 0f) || aIAgent.SecondsSinceLastSetDestination < this.Timeout)) { return(1f); } return(0f); }