public SleepAct(CreatureAI creature) : base(creature) { Name = "Sleep"; RechargeRate = 1.0f; Teleport = false; }
public FollowPathAct(CreatureAI agent, string pathName) : base(agent) { Name = "Follow path"; PathName = pathName; EnergyLoss = 10.0f; ValidPathTimer = new Timer(.75f, false); }
public FollowPathAnimationAct(CreatureAI agent, string pathName) : base(agent) { Name = "Follow path"; PathName = pathName; ValidPathTimer = new Timer(.75f, false); RandomTimeOffset = MathFunctions.Rand(0.0f, 0.1f); }
private void ReturnCreature(CreatureAI creature) { var owner = creature.World.Factions.Factions[OwnerFaction]; owner.Minions.Add(creature); creature.CancelCurrentTask(); creature.GetRoot().SetFlagRecursive(GameComponent.Flag.Active, true); creature.GetRoot().SetFlagRecursive(GameComponent.Flag.Visible, true); }
/// <summary> /// Constructor of the Behaviour Block /// </summary> /// <param name="owningCreatureAI">Reference to the creature owning the Behaviour Block.</param> /// <param name="behaviours">Parameterized Array of CreatureBehaviours that should be executed in order.</param> public BehaviourBlock(CreatureAI owningCreatureAI, params CreatureBehaviour[] behaviours) { m_OwningCreatureAI = owningCreatureAI; foreach (CreatureBehaviour cb in behaviours) { m_Behaviours.Enqueue(cb); } }
void MovementInform(Creature owner) { CreatureAI ai = owner.GetAI(); if (ai != null) { ai.MovementInform(MovementGeneratorType.Waypoint, (uint)_currentNode); } }
void Start() { creatureMotor = GetComponent <CreatureMotor>(); creatureAI = GetComponent <CreatureAI>(); behavior = creatureAI.creature.creatureBehavior; creatureHealth = creatureAI.creature.creatureHealth; }
private bool PassesFilter(CreatureAI Minion) { var filter = GetFilter(); if (String.IsNullOrEmpty(filter)) { return(true); } return(GetMinionDescriptorString(Minion).Contains(filter.ToUpper())); }
public bool EnqueuDwarf(CreatureAI Rider, ElevatorMoveState RidePlan) { RiderQueue.RemoveAll(r => Object.ReferenceEquals(Rider, r.Rider)); RiderQueue.Add(new EnqueuedRider { Rider = Rider, RidePlan = RidePlan }); return(true); }
private void Update() { #region AttackCooldown if (currentAttackCooldown > 0) { currentAttackCooldown -= Time.deltaTime; } #endregion #region CreatureDetection Collider[] result = Physics.OverlapSphere(transform.position, detectCreatureRange); attackables.Clear(); Player player = null; foreach (var item in result) { if (player == null) { player = item.GetComponentInParent <Player>(); if (player != null) { attackables.Add(player); continue; } } CreatureAI creature = item.GetComponent <CreatureAI>(); if (creature != null) { attackables.Add(creature); } } IAttackableByEnemy closest = null; float closestDistance = float.MaxValue; foreach (var item in attackables) { float distance = Vector3.Distance(transform.position, item.transform.position); if (distance < closestDistance) { closest = item; closestDistance = distance; } } if (closest != null) { StartCoroutine(Attack(closest)); } #endregion }
public void selectCreatureType(int _type) { CreatureAI cAI = createdCreature.GetComponent <CreatureAI>(); if (cAI.creature.creatureBehavior == CreatureBehavior.Passive) { if (GameController.instance.totalPassiveCreatures < GameController.instance.maxPassiveCreatures) { cAI.creature = creatureTypes[_type]; currentDelay = 0; GameController.instance.totalPassiveCreatures++; GameController.instance.totalActiveCreatures++; return; } } if (cAI.creature.creatureBehavior == CreatureBehavior.Neutral) { if (GameController.instance.totalNeutralCreatures < GameController.instance.maxNeutralCreatures) { cAI.creature = creatureTypes[_type]; currentDelay = 0; GameController.instance.totalNeutralCreatures++; GameController.instance.totalActiveCreatures++; return; } } if (cAI.creature.creatureBehavior == CreatureBehavior.Aggressive) { if (GameController.instance.totalAggressiveCreatures < GameController.instance.maxAggressiveCreatures) { cAI.creature = creatureTypes[_type]; currentDelay = 0; GameController.instance.totalAggressiveCreatures++; GameController.instance.totalActiveCreatures++; return; } } return; }
// Update is called once per frame void DoAIBehaviour() { //this part checks if the enemy type exists if (CreatureAI.creaturesByType.ContainsKey(enemyType) == false) { return; } //find the closest creature to us //set defaults CreatureAI closest = null; float distance = Mathf.Infinity; //Loop through all enemy to find the closest foreach (CreatureAI c in CreatureAI.creaturesByType[enemyType]) { // if the creature is dead, then move on if (c.health <= 0) { continue; } //get it's distance from us float dist = Vector3.Distance(this.transform.position, c.transform.position); //if it's closer that the current closest then it is the closest if (closest == null || dist < distance) { closest = c; distance = dist; } } //if there was no closest then do nothing //this part checks if any food in the types list exists //or if we need to worry if (closest == null || distance > lookOutRange) { return; } //if we get this far, there an enemy //if not closer move closer Vector3 dir = this.transform.position - closest.transform.position; //this form of calculation increases the importance the closer it gets //to the enemy float descisionmportance = 10 / (distance * distance); WeightedDirection wd = new WeightedDirection(dir, descisionmportance); creature.desiredDirections.Add(wd); }
public bool ReadyToBoard(CreatureAI Rider) { if (State != States.PickingUpRider) { return(false); } if (CurrentRider != null && Object.ReferenceEquals(Rider, CurrentRider.Rider)) { return(true); } return(false); }
public void WaitForMe(CreatureAI Rider) { if (State != States.PickingUpRider && State != States.DroppingOffRider) { return; } if (CurrentRider == null || !Object.ReferenceEquals(Rider, CurrentRider.Rider)) { return; } TimeoutTimer.Reset(); }
public bool AtDestination(CreatureAI Rider) { if (State != States.DroppingOffRider) { return(false); } if (CurrentRider != null && Object.ReferenceEquals(Rider, CurrentRider.Rider)) { return(true); } return(false); }
static void DoMovementInform(Unit owner, Unit target) { if (!owner.IsCreature()) { return; } CreatureAI ai = owner.ToCreature().GetAI(); if (ai != null) { ai.MovementInform(MovementGeneratorType.Chase, (uint)target.GetGUID().GetCounter()); } }
private void OnValidate() { if (myCollider == null) { myCollider = GetComponent <Collider>(); } if (myRigidbody == null) { myRigidbody = GetComponent <Rigidbody>(); } if (creatureAI == null) { creatureAI = GetComponent <CreatureAI>(); } }
private void CallCreatures() { GetComponent <PlayerMovement>().animator.SetTrigger(PlayerAnimations.ShoutTrigger); Collider[] result = Physics.OverlapSphere(transform.position, radius); foreach (Collider item in result) { CreatureAI creature = item.GetComponent <CreatureAI>(); if (creature == null) { continue; } creature.StartFollowing(transform); } }
float[] generateGenes()//generate random values on first generation { float Resilience_generated = Random.Range(0.0f, 2.0f); float Size_roo_generated = Random.Range(0.0f, 2.0f); //0.5 a 1.5 float Speed_generated = Random.Range(0.0f, 2.0f); //3.5 float FView_generated = Random.Range(0.0f, 2.0f); //2 a 5 float[] Genoma_generated = new float[4]; CreatureAI CreatureBrain = new CreatureAI(); Genoma_generated[0] = Mathf.Clamp(CreatureBrain.LerpValue((Resilience_minmax_Input[1] - Resilience_minmax_Input[0]), Resilience_minmax_BigInput[1] - Resilience_minmax_BigInput[0], Resilience_generated), Resilience_minmax_Input[0], Resilience_minmax_Input[1]); Genoma_generated[1] = Mathf.Clamp(CreatureBrain.LerpValue((Size_roo_minmax_Input[1] - Size_roo_minmax_Input[0]), Size_roo_minmax_BigInput[1] - Size_roo_minmax_BigInput[0], Size_roo_generated), Size_roo_minmax_Input[0], Size_roo_minmax_Input[1]); Genoma_generated[2] = Mathf.Clamp(CreatureBrain.LerpValue((Speed_minmax_Input[1] - Speed_minmax_Input[0]), Speed_minmax_BigInput[1] - Speed_minmax_BigInput[0], Speed_generated), Speed_minmax_Input[0], Speed_minmax_Input[1]); Genoma_generated[3] = Mathf.Clamp(CreatureBrain.LerpValue((FView_minmax_Input[1] - FView_minmax_Input[0]), FView_minmax_BigInput[1] - FView_minmax_BigInput[0], FView_generated), FView_minmax_Input[0], FView_minmax_Input[1]); return(Genoma_generated); }
private void DestroyCreature(CreatureAI creature) { if (!creature.Active) { return; } var owner = creature.World.Factions.Factions[OwnerFaction]; owner.Minions.Remove(creature); if (creature.World.Master.SelectedMinions.Contains(creature)) { creature.World.Master.SelectedMinions.Remove(creature); } creature.GetRoot().SetFlagRecursive(GameComponent.Flag.Active, false); creature.GetRoot().SetFlagRecursive(GameComponent.Flag.Visible, false); }
// Update is called once per frame void Update() { // raycast object and check if it has Think script, then set at target if (target == null && Input.GetMouseButtonUp(0)) // left click { RaycastHit hit; Ray ray = myCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { Transform objectHit = hit.transform; var creatureAI = objectHit.GetComponentInParent <CreatureAI>(); if (creatureAI != null) { target = creatureAI.gameObject; targetAI = target.GetComponent <CreatureAI>(); targetBT = creatureAI.Behaviour; m_StatsObj.SetActive(true); DrawTree(); } } } // turn off the overlay if active and no target if (target == null && LiveTreeOverlay.activeSelf) { LiveTreeOverlay.SetActive(false); m_StatsObj.SetActive(false); m_Core.GameState = Core.EGameState.Simulating; } // set overlay active and update if (target != null) { if (!LiveTreeOverlay.activeSelf) { LiveTreeOverlay.SetActive(true); m_StatsObj.SetActive(true); } UpdateTree(); UpdateStats(); } }
void OnRemove(AuraEffect aurEff, AuraEffectHandleModes mode) { Unit caster = GetCaster(); if (caster) { CreatureAI gormokAI = GetTarget().ToCreature().GetAI(); if (gormokAI != null) { Unit target = gormokAI.SelectTarget(SelectAggroTarget.Random, 0, new SnobolledTargetSelector(GetTarget())); if (target) { gormokAI.Talk(TextIds.EmoteSnobolled); caster.GetAI().DoAction(Actions.ActiveSnobold); caster.CastSpell(target, SpellIds.RidePlayer, true); } } } }
private void OnTriggerStay(Collider other) { if (brain.movement == null) { return; } if (brain.movement.imOn == false) { return; } if (other.gameObject.CompareTag("Food")) { Food f = other.gameObject.GetComponent <Food>(); if (f.TryCatchThisFood(brain)) { if (brain.movement != null) { brain.movement.Move(f.transform); } brain.movement.ChangeState(1); //eat method on CreatureAI } if (other.gameObject.CompareTag("Creature")) { if (brain.movement == null) { return; } if (brain.movement.imOn == false) { return; } CreatureAI c = other.gameObject.GetComponent <CreatureAI>(); if (brain.movement != null) { brain.movement.Move(c.transform); } brain.movement.ChangeState(1); //eat method on CreatureAI } } }
public bool TryCatchThisFood(CreatureAI candidate) { if (CreatureCandidate == null) { CreatureCandidate = candidate; return(true); } if (CreatureCandidate != null) { if (CreatureCandidate.Size > candidate.Size) { return(false); } else { CreatureCandidate = candidate; return(true); } } Debug.Log("Some Error Happened"); return(false); }
private void Update() { if (!activated) { return; } if (creatures.Count >= targetCreatureCount) { return; } int toSpawn = targetCreatureCount - creatures.Count; for (int i = 0; i < toSpawn; i++) { CreatureAI instance = Instantiate(creaturePrefab, transform.position + new Vector3(Random.value, 0, Random.value), Quaternion.identity); creatures.Add(instance); } }
private bool MovePlatform(ElevatorShaft Destination, CreatureAI Rider, DwarfTime Time) { var dest = Destination.Position - new Vector3(0, 0.5f, 0); var delta = dest - Platform.LocalPosition; if (delta.LengthSquared() < 0.05f) { return(true); } delta.Normalize(); delta *= (float)Time.ElapsedGameTime.TotalSeconds * ElevatorSpeed; Platform.LocalPosition = Platform.LocalPosition + delta; if (Rider != null) { Rider.Physics.LocalPosition = Platform.LocalPosition + new Vector3(0, Rider.Physics.BoundingBoxSize.Y, 0); Rider.Physics.Velocity = Vector3.Zero; Rider.Physics.PropogateTransforms(); } return(false); }
void HandleSpikes(uint effIndex) { PreventHitDefaultEffect(effIndex); Creature marrowgar = GetCaster().ToCreature(); if (marrowgar) { CreatureAI marrowgarAI = marrowgar.GetAI(); byte boneSpikeCount = (byte)(Convert.ToBoolean((int)GetCaster().GetMap().GetDifficultyID() & 1) ? 3 : 1); List <Unit> targets = marrowgarAI.SelectTargetList(boneSpikeCount, SelectAggroTarget.Random, 1, new BoneSpikeTargetSelector(marrowgarAI)); if (targets.Empty()) { return; } uint i = 0; foreach (var target in targets) { target.CastSpell(target, Misc.BoneSpikeSummonId[i], true); if (!target.IsAlive()) // make sure we don't get any stuck spikes on dead targets { Aura aura = target.GetAura(SpellIds.Impaled); if (aura != null) { Creature spike = ObjectAccessor.GetCreature(target, aura.GetCasterGUID()); if (spike != null) { spike.DespawnOrUnsummon(); } aura.Remove(); } } i++; } marrowgarAI.Talk(Texts.SayBonespike); } }
private void AddCreature(CreatureAI employee, WidgetListView column, List <CreatureAI> creaturesA, List <CreatureAI> creaturesB) { var bar = Root.ConstructWidget(new Widget { Background = new TileReference("basic", 0), TriggerOnChildClick = true, OnClick = (sender, args) => { creaturesA.Remove(employee); creaturesB.Add(employee); ReconstructColumns(); } }); var employeeSprite = employee.GetRoot().GetComponent <LayeredSprites.LayeredCharacterSprite>(); if (employeeSprite != null) { bar.AddChild(new EmployeePortrait { AutoLayout = AutoLayout.DockLeft, MinimumSize = new Point(48, 40), MaximumSize = new Point(48, 40), Sprite = employeeSprite.GetLayers(), AnimationPlayer = new AnimationPlayer(employeeSprite.Animations["IdleFORWARD"]) }); } var title = employee.Stats.Title ?? employee.Stats.CurrentLevel.Name; bar.AddChild(new Widget { AutoLayout = AutoLayout.DockFill, TextVerticalAlign = VerticalAlign.Center, MinimumSize = new Point(128, 64), Text = (employee.Stats.FullName) + " (" + title + ")" }); column.AddItem(bar); }
public void RefreshMainText() { if (selectedCreature.Equals(Entity.Null) || !em.Exists(selectedCreature)) { NativeArray <Entity> creatures = em.CreateEntityQuery(typeof(CreatureAI)). ToEntityArray(Allocator.TempJob); InitializeCreatureList(ref creatures); creatures.Dispose(); return; } //CreatureState state = em.GetComponentData<CreatureState>(selectedCreature); CreatureAI ai = em.GetComponentData <CreatureAI>(selectedCreature); Target target = em.GetComponentData <Target>(selectedCreature); /*NativeArray<Entity> areaArray = em.CreateEntityQuery(typeof(rak.ecs.area.Area)).ToEntityArray(Allocator.TempJob); * if(areaArray.Length == 0) * { * areaArray.Dispose(); * return; * } * ecs.area.Area area = em.GetComponentData<ecs.area.Area>(areaArray[0]); * Sun sun = em.GetComponentData<Sun>(areaArray[0]); * ecs.ThingComponents.Needs needs = em.GetComponentData<ecs.ThingComponents.Needs>(selectedCreature); * string text = DETAILTEXT.Replace("{name}",selectedCreature.ToString()); * text = text.Replace("{state}", state.Value.ToString()); * text = text.Replace("{task}", ai.CurrentTask.ToString()); * text = text.Replace("{taskTarget}", target.targetEntity.ToString()); * text = text.Replace("{currentAction}", ai.CurrentAction.ToString()); * text = text.Replace("{hunger}", needs.Hunger.ToString()); * text = text.Replace("{sleep}", needs.Sleep.ToString()); * detailText.text = text; * int cc = area.NumberOfCreatures; * int tc = 0; * clockText.text = "Creatures-" + cc + " Things-" + tc + " Time-" + sun.AreaLocalTime + * " Elapsed-" + sun.ElapsedHours + "\n";*/ // TODO this is ghetto // RefreshMemoryText(); //areaArray.Dispose(); }
public static List <CreatureAI> bubbleSort(List <CreatureAI> vetor) { int tamanho = vetor.Count; int comparacoes = 0; int trocas = 0; for (int i = tamanho - 1; i >= 1; i--) { for (int j = 0; j < i; j++) { comparacoes++; if (vetor[j].FinalFitness > vetor[j + 1].FinalFitness) { CreatureAI aux = vetor[j]; vetor[j] = vetor[j + 1]; vetor[j + 1] = aux; trocas++; } } } return(vetor); }
private string GetMinionDescriptorString(CreatureAI Minion) { var builder = new StringBuilder(); builder.Append(Minion.Stats.Species.Name); builder.Append(Minion.Stats.Gender); builder.Append(Minion.Stats.FullName); builder.Append(Minion.Stats.CurrentClass.Name); builder.Append(Minion.Stats.CurrentLevel.Name); builder.Append(Minion.Stats.Title); if (Minion.Stats.IsOverQualified) { builder.Append("wants promotion"); } if (Minion.Stats.IsOnStrike) { builder.Append("strike"); } if (Minion.Stats.IsAsleep) { builder.Append("asleeping"); } return(builder.ToString().ToUpper()); }
public FollowPathAnimationAct(CreatureAI agent, string pathName) : base(agent) { Name = "Follow path"; PathName = pathName; ValidPathTimer = new Timer(.75f, false); RandomTimeOffset = MathFunctions.Rand(0.0f, 0.1f); }
public FollowPathAct(CreatureAI agent, string pathName) : base(agent) { Name = "Follow path"; PathName = pathName; EnergyLoss = 10.0f; ValidPathTimer = new Timer(.75f, false); }