void GetFood() { GameObject closestObj = memorySystem.FindNearestGameObjectInMemory("Food", transform); if (closestObj == null) { return; } // No need to look again. if (behaviorState == BehaviorStates.LookingForFood) { if (BehaviorHelper.AtEndOfPath(agent)) { int food = closestObj.GetComponent <Food>().value; memorySystem.RemoveGameObjectFromMemory(closestObj); agent.SetDestination(transform.position); hunger += food; behaviorState = BehaviorStates.Wandering; Destroy(closestObj); } return; } behaviorState = BehaviorStates.LookingForFood; agent.SetDestination(closestObj.transform.position); }
// -- MOVEMENT ---------- void GetWater() { GameObject closestObj = memorySystem.FindNearestGameObjectInMemory("Drink", transform); if (closestObj == null) { return; } // No need to look again. if (behaviorState == BehaviorStates.LookingForWater) { if (BehaviorHelper.AtEndOfPath(agent)) { int quench = closestObj.GetComponent <Drink>().value; memorySystem.RemoveGameObjectFromMemory(closestObj); agent.SetDestination(transform.position); thirst += quench; behaviorState = BehaviorStates.Wandering; Destroy(closestObj); } return; } behaviorState = BehaviorStates.LookingForWater; agent.SetDestination(closestObj.transform.position); }
// If a Being can perform a behavior (excludes pursuing the player) public static bool CanPerformBehavior(BehaviorStates desiredState, BehaviorStates currentState) { return(desiredState == currentState | currentState == BehaviorStates.Wandering); }
private void Init(GameObject p_object, int p_hitPoints, int delay, ActivationTypes p_activationType, FacePlayerBehavior p_fpBehavior) { this.actType = p_activationType; this.fpBehavior = p_fpBehavior; this.hitPoints = p_hitPoints; this.maxHitpoints = p_hitPoints; this.actionQueue = new Queue<GameAction>(); this.thisObject = p_object; this.nearEventResponse = new EventResponse(); this.farEventResponse = new EventResponse(); this.hitEventResponse = new EventResponse(); this.hitWallEventResponse = new EventResponse(); this.playerAttackEventResponse = new EventResponse(); this.itemDrops = new List<ItemDropProfile>(); this.TimerOffset = delay; if ((this.fpBehavior == FacePlayerBehavior.FaceWhenCreated) && (this.timerOffset <= 0)) { this.timerOffset = 1; } this.currentState = BehaviorStates.Start; if (this.thisObject.ObjClass == ObjectClass.Boss) { this.hitSound = SoundEffects.BossHit; this.dieSound = SoundEffects.BossDie; } else { this.hitSound = SoundEffects.HitEnemy; this.dieSound = SoundEffects.EnemyDie; } }
private void CheckProximity() { bool flag = false; if (((this.currentState == BehaviorStates.Near) && (this.actType == ActivationTypes.ActivateIfHorizontallyClose)) && this.inRange) { return; } if (this.actType == ActivationTypes.AlwaysActivated) { flag = true; } else if ((this.actType != ActivationTypes.ActivateIfHorizontallyClose) && (Math.Abs(this.yDist) > 150f)) { flag = false; } else { switch (this.actType) { case ActivationTypes.ActivateIfClose: case ActivationTypes.ActivateIfHorizontallyClose: flag = Math.Abs(this.xDist) < this.attackDistance; goto Label_011B; case ActivationTypes.ActivateIfAbove: flag = (this.yDist < 0f) && (Math.Abs(this.xDist) < this.attackDistance); goto Label_011B; case ActivationTypes.ActivateIfFacing: if (this.thisObject.CurrentDirection != Direction.Left) { if (this.thisObject.CurrentDirection == Direction.Right) { flag = (this.xDist < -16f) && ((-1f * this.xDist) <= this.attackDistance); } } else { flag = (this.xDist > 16f) && (this.xDist <= this.attackDistance); } goto Label_011B; } } Label_011B: if (this.currentState == BehaviorStates.Hit) { this.thisObject.CurrentAnimation = AnimType.Stopped; } if (!flag) { this.inRange = false; this.farEventResponse.CopyActions(ref this.actionQueue); this.currentState = BehaviorStates.Far; this.currentAction = this.actionQueue.Dequeue(); } else if (flag) { this.inRange = true; this.nearEventResponse.CopyActions(ref this.actionQueue); this.currentState = BehaviorStates.Near; this.currentAction = this.actionQueue.Dequeue(); } }
public bool Update(PointF screenPos) { GameObject player = GameEngine.Game.GetPlayer(); if (this.timerOffset > 0) { this.timerOffset--; if (this.fpBehavior == FacePlayerBehavior.FaceWhenCreated) { new FacePlayer().DoAction(this.thisObject); } return true; } if (this.timerOffset == 0) { this.timerOffset = -1; this.farEventResponse.CopyActions(ref this.actionQueue); this.currentState = BehaviorStates.Far; this.currentAction = this.actionQueue.Dequeue(); } this.xDist = this.thisObject.Location.X - player.Location.X; this.yDist = this.thisObject.Location.Y - player.Location.Y; if (this.fpBehavior == FacePlayerBehavior.FaceIfFar) { if ((Math.Abs(this.yDist) > 150f) || (Math.Abs(this.xDist) > 200f)) { new FacePlayer().DoAction(this.thisObject); } } else if ((this.fpBehavior == FacePlayerBehavior.AlwaysFace) && (this.hitPoints > 0)) { new FacePlayer().DoAction(this.thisObject); } if ((this.thisObject.CurAnimHitType != AnimHitType.Ghost) && (this.thisObject.CurAnimHitType != AnimHitType.Invincible)) { if (((this.damageToSuffer > 0) && (this.hitPoints > 0)) && (this.hitDelay == 0)) { this.Damage(this.damageToSuffer, true); this.damageToSuffer = 0; } if ((this.hitDelay == 0) && (player.CurAnimHitType == AnimHitType.Sword)) { if (this.thisObject.CurAnimHitType == AnimHitType.HeadOnly) { if (player.GetShieldSwordRectangle().IntersectsWith(this.thisObject.GetShieldSwordRectangle())) { this.HandleHit(player); } } else if (player.GetShieldSwordRectangle().IntersectsWith(this.thisObject.GetCollisionRectangle())) { this.HandleHit(player); } } } else if (((this.thisObject.Type == ObjectType.Crystal) && (this.damageToSuffer >= 0x270f)) && ((this.hitPoints > 0) && (this.hitDelay == 0))) { this.Damage(this.damageToSuffer, true); this.damageToSuffer = 0; } if (this.thisObject.CurAnimHitType != AnimHitType.Ghost) { if (this.hitDelay > 0) { this.hitDelay--; } else if ((!this.thisObject.IsBlinking && (this.hitPoints > 0)) && player.GetCollisionRectangle().IntersectsWith(this.thisObject.GetCollisionRectangle())) { player.ObjectBehavior.HandleHit(this.thisObject); } } if ((((this.hitPoints > 0) && (this.hitDelay == 0)) && ((GameEngine.Game.GetPlayer().CurrentAnimation == AnimType.Attacking) && !this.playerAttackEventResponse.IsEmpty)) && ((this.currentState == BehaviorStates.Near) && ((this.thisObject.X - player.X) <= (this.attackDistance / 2)))) { this.playerAttackEventResponse.CopyActions(ref this.actionQueue); this.currentState = BehaviorStates.PlayerAttacked; this.currentAction.Finish(); this.currentAction = this.actionQueue.Dequeue(); } if (this.thisObject.ObjClass == ObjectClass.Boss) { GameEngine.Game.BossHP = (int) ((((float) this.hitPoints) / ((float) this.maxHitpoints)) * 100f); } if (this.xDist <= this.awakenDistance) { this.awakenDistance = 0x270f; return this.HandleEvents(); } return true; }
public void HandleHitSurface(SurfaceType surfaceType, RectangleF block, Direction side) { bool flag = false; if ((side == Direction.Up) && (this.thisObject.CurrentAnimation == AnimType.Jump)) { this.thisObject.CurrentAnimation = AnimType.Stopped; } if (!this.ignoreHitFloor && ((side == Direction.Left) || (side == Direction.Right))) { flag = true; } if (this.ignoreHitFloor && ((side == Direction.Up) || (side == Direction.Down))) { flag = true; } if ((!flag && !this.hitWallEventResponse.IsEmpty) && ((this.currentState == BehaviorStates.Near) || (this.currentState == BehaviorStates.Far))) { switch (side) { case Direction.Left: if (this.thisObject.XSpeed.TargetSpeed > 0f) { break; } return; case Direction.Right: if (this.thisObject.XSpeed.TargetSpeed < 0f) { break; } return; case Direction.Up: if (this.thisObject.YSpeed.TargetSpeed > 0f) { break; } return; case Direction.Down: if (this.thisObject.YSpeed.TargetSpeed < 0f) { break; } return; } this.currentState = BehaviorStates.HitWall; this.hitWallEventResponse.CopyActions(ref this.actionQueue); this.currentAction.Finish(); this.currentAction = this.actionQueue.Dequeue(); this.HandleEvents(); } }
public void Damage(int amount, bool immediate) { if (!immediate) { this.damageToSuffer += amount; } else { this.hitDelay = 20; this.hitPoints -= amount; if (this.hitPoints <= 0) { if (this.thisObject.ObjClass == ObjectClass.Boss) { if (this.thisObject.Type != ObjectType.MechaDragonX) { GameEngine.Framework.SetMusicPaused(true); } } else { this.thisObject.Blink(60); } this.thisObject.XSpeed.SetSpeed((float) 0f); this.thisObject.YSpeed.SetSpeed((float) 0f); this.thisObject.CurrentAnimation = AnimType.Dying; GameEngine.Framework.PlaySound(this.dieSound); if (this.currentAction != null) { this.currentAction.Finish(); } this.currentAction = new Wait(60); } else { if (this.thisObject.ObjClass == ObjectClass.Boss) { GameEngine.Game.CurrentMap.BossHitFlash(); } this.thisObject.XSpeed.SetSpeed((float) 0f); this.thisObject.YSpeed.SetSpeed((float) 0f); this.thisObject.CurrentAnimation = AnimType.Hit; GameEngine.Framework.PlaySound(this.hitSound); this.hitEventResponse.CopyActions(ref this.actionQueue); this.currentState = BehaviorStates.Hit; if (this.currentAction != null) { this.currentAction.Finish(); } this.currentAction = this.actionQueue.Dequeue(); } } }