Exemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     entity = this.gameObject.GetComponent<RPGEntity> ();
     if (entity == null) {
         Debug.LogWarning("[TestRPGEntity] No RPGEntity Component attachted to GameObject \"" + this.gameObject.name + "\"");
     }
 }
Exemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     entity = this.gameObject.GetComponent <RPGEntity> ();
     if (entity == null)
     {
         Debug.LogWarning("[TestRPGEntity] No RPGEntity Component attachted to GameObject \"" + this.gameObject.name + "\"");
     }
 }
Exemplo n.º 3
0
    public void Initialize(RPGEntity entity)
    {
        entity.OnEntityLevelChange += OnEntityLevelChanged;

        ValidateStats();
        ConfigureStats();
        InitializeStats(entity);
    }
Exemplo n.º 4
0
 public void Update(RPGEntity entity)
 {
     foreach (KeyValuePair <RPGStatType, RPGStat> pair in _stats)
     {
         var updateStat = pair.Value as IStatUpdatable;
         if (updateStat != null)
         {
             updateStat.OnUpdate(entity);
         }
     }
 }
Exemplo n.º 5
0
 private void InitializeStats(RPGEntity entity)
 {
     foreach (KeyValuePair <RPGStatType, RPGStat> pair in _stats)
     {
         var initStat = pair.Value as IStatInitalizable;
         if (initStat != null)
         {
             initStat.OnInitialize(entity);
         }
     }
 }
Exemplo n.º 6
0
        private void CombatDummy_Hit(RPGEntity sender, Entity invoker, GameTime gameTime, TeeEngine engine)
        {
            if (!CurrentDrawableState.Contains("Spin"))
            {
                CurrentDrawableState = "Spin_" + Direction;
                Drawables.ResetState(CurrentDrawableState, gameTime);
            }

            // Play random Hit Sound.
            int index = _randomGenerator.Next(3);
            _hitSounds[index].Play();

            this.HP = this.MaxHP;
        }
Exemplo n.º 7
0
        private void AggressiveNpcAI(GameTime gameTime, TeeEngine engine)
        {
            _target = GetHighestPriorityTarget(gameTime, engine, _agroDistance);

            if (CurrentState == EntityStates.Idle)
            {
                if (_target != null) CurrentState = EntityStates.Alert;
            }
            else if (CurrentState == EntityStates.Alert)
            {
                if (_target == null) CurrentState = EntityStates.Idle;
                else
                {
                    if (Vector2.Distance(this.Pos, _target.Pos) < _attackDistance)
                    {
                        // Only Attack during specific delayed intervals.
                        if (gameTime.TotalGameTime.TotalMilliseconds - _lastAttack > _attackDelay + _randomDelay)
                        {
                            _lastAttack = gameTime.TotalGameTime.TotalMilliseconds;
                            _randomDelay = RPGRandomGenerator.Next(1000);

                            CurrentDrawableState = "Slash_" + Direction;
                            CurrentState = EntityStates.Attacking;

                            ClearHitList();
                            Drawables.ResetState(CurrentDrawableState, gameTime);
                        }
                    }
                    else
                    {
                        Path path = engine.Pathfinding.GeneratePath(this.Pos, _target.Pos, engine, gameTime, PathfindingValidator);
                        FollowPath(path, engine);
                    }

                    Vector2 difference = this.Pos - _target.Pos;
                    if (Math.Abs(difference.X) > Math.Abs(difference.Y))
                        Direction = (difference.X > 0) ? Direction.Left : Direction.Right;
                    else
                        Direction = (difference.Y > 0) ? Direction.Up : Direction.Down;
                }
            }
            else if (CurrentState == EntityStates.Attacking)
            {
                PerformHitCheck(gameTime, engine);
                if (Drawables.IsStateFinished(CurrentDrawableState, gameTime))
                    CurrentState = EntityStates.Alert;
            }

            // Update Idle or Walking animations.
            if (CurrentState == EntityStates.Alert || CurrentState == EntityStates.Idle)
            {
                if (PrevPos != Pos)
                {
                    Vector2 difference = Pos - PrevPos;
                    if (Math.Abs(difference.X) > Math.Abs(difference.Y))
                        Direction = (difference.X > 0) ? Direction.Right : Direction.Left;
                    else
                        Direction = (difference.Y > 0) ? Direction.Down : Direction.Up;

                    CurrentDrawableState = "Walk_" + Direction;
                }
                else CurrentDrawableState = "Idle_" + Direction;
            }
        }
Exemplo n.º 8
0
        private void NPC_Interact(RPGEntity sender, Entity invoker, GameTime gameTime, TeeEngine engine)
        {
            SpeechBubble speech = new SpeechBubble(this, "Hello there Adventurer! Whats you're name?");

            engine.AddEntity(speech);

            Vector2 distance = this.Pos - invoker.Pos;
            if (distance.X > distance.Y)
                Direction = (distance.X > 0) ? Direction.Left : Direction.Right;
            else
                Direction = (distance.Y > 0) ? Direction.Up : Direction.Down;
        }
Exemplo n.º 9
0
        public void AggressiveBatAI(GameTime gameTime, TeeEngine engine)
        {
            _target = GetHighestPriorityTarget(gameTime, engine, _agroDistance);

            if (CurrentState == EntityStates.Idle)
            {
                if (_target != null) CurrentState = EntityStates.Alert;

                Pos.X += (float)(Math.Cos(gameTime.TotalGameTime.TotalSeconds - _randomModifier * 90) * 2);
            }
            else if (CurrentState == EntityStates.Alert)
            {
                if (_target == null) CurrentState = EntityStates.Idle;
                else
                {
                    if (Vector2.Distance(this.Pos, _target.Pos) < _attackDistance)
                        CurrentState = EntityStates.PrepareAttack;
                    else
                        Approach(_target.Pos);
                }
            }
            else if (CurrentState == EntityStates.PrepareAttack)
            {
                if (_target == null) CurrentState = EntityStates.Alert;
                else
                {
                    _attackHeight.Y -= 2;

                    if (_attackHeight.Y < -40)
                    {
                        _attackHeight.Y = -40;
                        _attackAngle = Math.Atan2(
                            this.Pos.Y - _target.Pos.Y,
                            this.Pos.X - _target.Pos.X
                            );
                        CurrentState = EntityStates.Attacking;
                        ClearHitList();
                        _attackCounter = 0;
                    }

                    Drawables.SetGroupProperty("Body", "Offset", _attackHeight);
                }
            }
            else if (CurrentState == EntityStates.Attacking)
            {
                this.Pos.X -= (float)(Math.Cos(_attackAngle) * _attackSpeed);
                this.Pos.Y -= (float)(Math.Sin(_attackAngle) * _attackSpeed);
                this._attackHeight.Y += 30.0f / ATTACK_COUNTER_LIMIT;
                this.Drawables.SetGroupProperty("Body", "Offset", _attackHeight);

                PerformHitCheck(gameTime, engine);

                if (_attackCounter++ == ATTACK_COUNTER_LIMIT)
                    CurrentState = EntityStates.Alert;
            }

            if (PrevPos != Pos)
            {
                Vector2 difference = Pos - PrevPos;
                if (Math.Abs(difference.X) > Math.Abs(difference.Y))
                    Direction = (difference.X > 0) ? Direction.Right : Direction.Left;
                else
                    Direction = (difference.Y > 0) ? Direction.Down : Direction.Up;

                CurrentDrawableState = "Fly_" + Direction;
            }
        }
Exemplo n.º 10
0
 private void Bat_Hit(RPGEntity sender, Entity invoker, GameTime gameTime, TeeEngine engine)
 {
     if (HP > 0)
     {
         _hitColor = Color.Red;
         _hitPercentage = 0.0f;
     }
 }
Exemplo n.º 11
0
 public RPGStats(RPGEntity entity)
 {
     Initialize(entity);
 }