/// <summary> /// /// </summary> private void FixedUpdate() { if (m_navAgent.velocity.sqrMagnitude > float.Epsilon && m_state == MobState.Idle) { m_state = MobState.Walk; } if (this.IsServer) { switch (m_state) { case MobState.Idle: { if (UnityEngine.Random.Range(0, 100) == 0) { m_state = MobState.Walk; var target = GetRandomPointInSpawnArea(); m_navAgent.SetDestination(target); var mobMovePacket = new Realms.Server.Packet.MobMovePacket(this.ID, target); m_server.QueuePacketAll(mobMovePacket); } } break; case MobState.Walk: { if (m_navAgent.velocity.sqrMagnitude <= float.Epsilon) { m_state = MobState.Idle; } } break; case MobState.Attack: { if (Time.time - m_lastAttackTime >= 10.0f) { m_state = MobState.Idle; } } break; } } else { if (m_state == MobState.Attack) { // Do Attack animation } else if (m_navAgent.velocity.sqrMagnitude > float.Epsilon) { m_animator.SetBool("IsWalking", true); } else { m_animator.SetBool("IsWalking", false); } } }
public void MobDeathTest() { MobState mob = new MobState("test1", 1, 1, 100, 0, 0); mob.TakeDamage(1000, Enums.Mobs.eDamageTypes.NONE); Assert.AreEqual(false, mob.Alive); }
private void LookupMobs( RequestCache requestCache) { int mobCount = requestCache.GetMobs(m_room_key).Count(); int mobIndex = 0; m_mobs = new MobState[mobCount]; foreach (Mob mob in requestCache.GetMobs(m_room_key)) { m_mobs[mobIndex] = new MobState { mob_id = mob.ID, mob_type_name = mob.MobType.Name, health = mob.Health, energy = mob.Energy, game_id = mob.RoomKey.game_id, room_x = mob.RoomKey.x, room_y = mob.RoomKey.y, room_z = mob.RoomKey.z, x = mob.Position.x, y = mob.Position.y, z = mob.Position.z, angle = mob.Angle }; ++mobIndex; } }
void Start() { //if(rand.Next(0, 2) == 0) this.actualState = new FollowingPathState(this); // else // this.actualState = new FollowingPlayerState(this); this.changedState = this.actualState; // UnityEngine.Debug.Log("Start"); }
void Back() { transform.position -= transform.forward * m_fBackSpeed * Time.deltaTime; if (Vector3.Distance(CGameManager._instance._PlayerPos.position, transform.position) > m_fMaxDistance) { _MobState = MobState.Idle; } }
void AttackTarget() { if (target) { state = MobState.ATTACKING; attackTime = 1; target.TakeDamage(attackDamage); } }
IEnumerator IE_Walk() { yield return(new WaitForSeconds(1f)); nav.speed = 3f; yield return(new WaitForSeconds(0.5f)); _State = MobState.Walk; }
public void AddMob(MobState mob) { Mobs.Add(mob); if (IdsUsed.Contains(mob.Id)) { throw new OpenDiablo2Exception("Tried to insert an existing mob id!"); } IdsUsed.Add(mob.Id); }
public override void OnEnter(MobState priorState) { lastPos = self.transform.position; searchingTime = Time.time + EnemyProps.searchTime; //print("Searching"); motor.enabled = true; motor.input.isRunning = true; }
public void MobFlagsTest() { MobState mob = new MobState("test1", 1, 1, 100, 0, 0); mob.AddFlag(Enums.Mobs.eMobFlags.ENEMY); Assert.AreEqual(true, mob.HasFlag(Enums.Mobs.eMobFlags.ENEMY)); Assert.AreEqual(false, mob.HasFlag(Enums.Mobs.eMobFlags.INVULNERABLE)); mob.RemoveFlag(Enums.Mobs.eMobFlags.ENEMY); Assert.AreEqual(false, mob.HasFlag(Enums.Mobs.eMobFlags.ENEMY)); }
private async void Update() { while (alive && MyState != MobState.Sleeping) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { CharacterPlayer target = null;// new CharacterPlayer(new Canvas(), new Player("000000"), new Canvas());// = GetNearestPlayer(); if (target == null) { MyState = MobState.Alert; } else { distInitialToMob = GetDistance(FirstX, FirstY, xCharacVal, yCharacVal); distPlayer = GetDistance(target.xCharacVal + MainCamera.instance.CameraXOffSet * -1, target.yCharacVal + MainCamera.instance.CameraYOffSet * -1, xCharacVal + characT.Width / 2, FirstY + characT.Height / 2); if (distInitialToMob >= MaxDistance) { MyState = MobState.Alert; } else if (distPlayer < MinDistance && distInitialToMob < MinDistance / 2) { if (Mob.Meek && Mob.Hp == Mob.HpMax) { MyState = MobState.Alert; } else { MyState = MobState.Following; } } else if (distInitialToMob > ChunckDistance) { moveLeft = false; moveRight = false; MyState = MobState.Sleeping; } } switch (MyState) { case MobState.Alert: stats = "Alerta"; AlertState(); break; case MobState.Following: stats = "Seguindo"; FollowingState(target); break; } }); } }
void Update() { vPlayerPos = GameObject.FindWithTag("Player").transform.position; if (m_bLight) { vRand = new Vector3(Random.Range(-27, 27), 3f, Random.Range(-5, 10)); _State = MobState.LightRun; m_bLight = false; } MobStateFild(); }
private Mob() { MovingSpeed = 6; Removed = false; Netid = 0; State = MobState.Roaming; SenseDistance = 8; AttackDistance = 2; AttackSpeed = TimeSpan.FromSeconds(2); HeroTarget = null; ShapeManager.AddCircle(this); }
private void ServerRoaming() { //find target thats close enough ServerClient target = Room.Clients.FirstOrDefault(c => (Position - c.Hero.Position).LengthSquared() < SenseDistance * SenseDistance); if (target != null) { State = MobState.Chasing; HeroTarget = target; } }
public void Destroy() { State = MobState.Killed; if (Sprite != null) { SpriteManager.RemoveSprite(Sprite); } if (Label != null) { TextManager.RemoveText(Label); } ShapeManager.Remove(this); }
public override void OnEnter(MobState priorState) { //print("Recoil!"); //if self.health > 0 //endTime = Time.time + controller.recoilConfig.RecoilDuration; //Enemy health - damage done will go here. //else //Destroy(gameObject); endTime = Time.time + 2.0f; }
public void MobImmunityTest() { MobState mob = new MobState("test1", 1, 1, 100, 0, 0); mob.AddImmunitiy(eDamageTypes.COLD); int dam = mob.TakeDamage(100, eDamageTypes.COLD); // now try 100 cold damage Assert.AreEqual(0, dam); // b/c mob has immunity, should not take damage Assert.IsTrue(mob.Alive); // mob should not have taken enough damage to die int dam2 = mob.TakeDamage(100, eDamageTypes.FIRE); // now try 100 fire damage Assert.AreEqual(100, dam2); // b/c mob has no fire immunity, should take full damage Assert.IsFalse(mob.Alive); // mob should be dead }
private void attackRangeCheck() { if (Vector3.Distance(player.transform.position, this.transform.position) < attackRange && mobState != MobState.Attack01) { mobState = MobState.Attack01; anim.SetBool("Attack", true); speed = 0; } else { anim.SetBool("Attack", false); } }
private void UpdateState() { MobState nextStateByEnvironment = GetNextStateByEnvironment(); nextState = (nextState > nextStateByEnvironment ? nextState : nextStateByEnvironment); if (state != nextState) { state = nextState; UpdateAnimationState(state); } nextState = MobState.None; }
public void MobResistancesTest() { MobState mob = new MobState("test1", 1, 1, 100, 0, 0); mob.SetResistance(eDamageTypes.COLD, 0.5); int dam = mob.TakeDamage(100, eDamageTypes.COLD); // now try 100 cold damage Assert.AreEqual(50, dam); // b/c mob has 50% resistance, should only take 50 damage Assert.IsTrue(mob.Alive); // mob should not have taken enough damage to die int dam2 = mob.TakeDamage(100, eDamageTypes.FIRE); // now try 100 fire damage Assert.AreEqual(100, dam2); // b/c mob has no fire resistance, should take full damage Assert.IsFalse(mob.Alive); // mob should be dead }
private void distanceCheck() { if (Vector3.Distance(player.position, this.transform.position) >= findRange) { mobState = MobState.Idle; anim.SetBool("Run", false); speed = 0; } else { mobState = MobState.Run; anim.SetBool("Run", true); speed = moveSpeed; } }
void Come() { transform.position += transform.forward * m_fComeSpeed * Time.deltaTime; if (Vector3.Distance(CGameManager._instance._PlayerPos.position, transform.position) < m_fDistance + 0.5f) { CPlayerManager._instance._PlayerSwap.m_bSwapAttack = true; TimeScalManager._instance.m_fTimeScal = 0.1f; if (Vector3.Distance(CGameManager._instance._PlayerPos.position, transform.position) < m_fDistance) { _MobState = MobState.Idle; CPlayerManager._instance.PlayerHitCamera(5.0f); } } }
public override void OnDamaged(IInteractable attacker, int damage, Vector2 knockback) { base.OnDamaged(attacker, damage, knockback); if (attacker is Julia) { nextState = MobState.Pressed; } else { nextState = MobState.Hit; } stateEndTime = Time.time + .3f; UpdateState(); }
public void SaveState(Mob mob) { if (mob.CurrentState == mob.IdleState) { state = MobState.Idle; } else if (mob.CurrentState == mob.JumpState) { state = MobState.Jump; } else if (mob.CurrentState == mob.AttackState) { state = MobState.Attack; } }
void Update() { Vector3 curPos = transform.position; switch (m_state) { case MobState.ToTarget: { curPos = Vector3.MoveTowards(curPos, TargetPos, Time.deltaTime); Vector3 shootTarget = new Vector3(TargetPos.x, GameManager.instance.Target.transform.position.y, TargetPos.z); Vector3 dir = shootTarget - curPos; if (Physics.Raycast(curPos, dir, SettingsManager.ShootingRange, 1 << LayerMask.NameToLayer("Wall"))) { m_state = MobState.Throw; } if (Vector3.Distance(curPos, TargetPos) < 2.0f) { m_state = MobState.FromTarget; } } break; case MobState.Throw: { SpearBehavior spear = PoolManager.instance.SpearPool.SpawnObject(curPos + SettingsManager.ThrowingPoint, Quaternion.Euler(SettingsManager.ThrowingRotation)) as SpearBehavior; spear.Throw(); m_state = MobState.FromTarget; } break; case MobState.FromTarget: { curPos = Vector3.MoveTowards(curPos, StartPos, Time.deltaTime); if (Vector3.Distance(curPos, StartPos) < 2.0f) { m_state = MobState.ToTarget; } } break; } ; transform.position = curPos; }
public Mob(string Name, int X, int Y) : base(Name + ".png") { name = Name; this.x = X; this.y = Y; this.anchorX = 0; this.anchorY = 0; box.x = this.x + 4; box.y = this.y + 4; box.width = this.width - 8; box.height = this.height - 8; Facing = Direction.S; mobState = MobState.Wander; Alive = true; }
private void UpdateAnimationState(MobState state) { switch (state) { case MobState.Idle: spriteRenderer.sprite = MobIdle; break; case MobState.Pressed: spriteRenderer.sprite = MobPressed; break; case MobState.Hit: spriteRenderer.sprite = MobHit; break; // Use previous sprite on Dead state. } }
public override void OnEnter(MobState priorState) { //print("Attacking"); motor.enabled = false; //rand call to decide between attacks needs to go here //If attack 1 //endTime = Time.time + self.attackConfig.AttackDuration; //Player.Health --; //else if attack 2 //endTime = Time.time + controller.attackConfig.Attack2Duration; //Player.health -5; //Temp code... delayTime = Time.time + .5f; endTime = delayTime + 2.0f; }
private void ServerAttacking() { if (HeroTarget == null) { State = MobState.Roaming; Globals.EventManager.RemoveEvent($"attacking{Netid}"); return; } //stop attacking and start chasing if it's too far //*1.5f is there so mob doesnt attack from the border of its range but rather from inside //so player cant make a small step to force it to chase again else if ((Position - HeroTarget.Hero.Position).LengthSquared() > AttackDistance * AttackDistance * 1.5f) { Globals.EventManager.RemoveEvent($"attacking{Netid}"); State = MobState.Chasing; return; } }
void OnTriggerStay2D(Collider2D collision) //Collision + what happens when die { if (GameManager.GameState == State.Play) { if (collision.tag == "Player") { mobRb2D.drag = 10.0f; if (collision.GetComponent <PlayerController>().CatState == PlayerState.Attack) { GameManager.points++; EnemyState = MobState.Break; } else { GameManager.life--; EnemyState = MobState.Die; } } } }
private void ServerChasing() { Target = HeroTarget.Hero.Position; //stop chasing if it's too far if (HeroTarget == null || (Position - HeroTarget.Hero.Position).LengthSquared() > SenseDistance * SenseDistance) { State = MobState.Roaming; HeroTarget = null; return; } //start attacking if it's close enough else if ((Position - HeroTarget.Hero.Position).LengthSquared() < AttackDistance * AttackDistance) { State = MobState.Atacking; Target = Position; Globals.EventManager.AddEvent(AttackHero, $"attacking{Netid}", false, TimeSpan.Zero, TimeSpan.Zero, AttackSpeed); } }
public void FindMobsInRadiusTest() { MobManager mobman = new MobManager(); MobState mob1 = new MobState("test1", mobman.GetNextAvailableMobId(), 1, 100, 0, 0); mob1.AddFlag(eMobFlags.ENEMY); mobman.AddMob(mob1); MobState mob2 = new MobState("test2", mobman.GetNextAvailableMobId(), 1, 100, 10, 10); mob2.AddFlag(eMobFlags.ENEMY); mob2.AddFlag(eMobFlags.INVULNERABLE); mobman.AddMob(mob2); MobState mob3 = new MobState("test3", mobman.GetNextAvailableMobId(), 1, 100, 3, 1); mobman.AddMob(mob3); Assert.IsTrue(mobman.Mobs.FindInRadius(0, 0, 1).Count() == 1); Assert.IsTrue(mobman.Mobs.FindInRadius(0, 0, 7).Count() == 2); Assert.IsTrue(mobman.Mobs.FindInRadius(0, 0, 20).Count() == 3); Assert.IsTrue(mobman.Mobs.FindInRadius(10, 10, 1).Count() == 1); }
void Start() { m_defaultCooldown = m_cooldown; m_defaultFlyCooldown = m_flyCooldown; m_movement = GetComponent<Movement>(); m_mobState = GetComponent<MobState>(); }
public void setState(MobState state){ this.actualState = state; }
void Start() { m_maxLeftPosition = transform.position.x - (m_travelLength * GLOBALS.UNITS_TO_PIXELS); print (m_maxLeftPosition); m_maxRightPosition = transform.position.x + (m_travelLength * GLOBALS.UNITS_TO_PIXELS); print (m_maxRightPosition); m_defaultCooldown = m_cooldown; m_defaultFlyCooldown = m_flyCooldown; m_defaultGroundedCooldown = m_groundedCooldown; m_movement = GetComponent<Movement>(); m_mobState = GetComponent<MobState>(); }
void Update() { if (!this.actualState.Equals(changedState)) this.actualState = changedState; this.actualState.Update(); }
void OnTriggerEnter(Collider collision) { if (this.actualState != changedState) this.actualState = changedState; this.actualState.OnTriggerEnter(collision); }
public void setState(MobState state) { changedState = state; }
//Collision + what happens when die void OnTriggerStay2D(Collider2D collision) { if (GameManager.GameState == State.Play) { if (collision.tag == "Player") { mobRb2D.drag = 10.0f; if (collision.GetComponent<PlayerController>().CatState == PlayerState.Attack) { GameManager.points++; EnemyState = MobState.Break; } else { GameManager.life--; EnemyState = MobState.Die; } } } }
void Update() { if (state == MobState.ATTACKING) { attackTime -= Time.deltaTime; if (attackTime <= 0) { state = MobState.NEUTRAL; } } }
public void Destroy() { State = MobState.Killed; if(Sprite != null) SpriteManager.RemoveSprite(Sprite); if(Label != null) TextManager.RemoveText(Label); ShapeManager.Remove(this); }
void Start () { this.actualState = new FollowingPathState(this); UnityEngine.Debug.Log("Start"); }